Skip to content

Commit da15b39

Browse files
Merge branch 'main' into andrew/hold-queued-message-edits
2 parents 4d0cd58 + 36f91c4 commit da15b39

59 files changed

Lines changed: 2339 additions & 462 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import {
5555
} from "@t3tools/client-runtime/markdown-images";
5656
import { resolveViewedImageAsset } from "@t3tools/client-runtime/work-log/presentation";
5757
import {
58-
renderCodexFileCitationsAsMarkdown,
58+
renderCodexInlineDirectivesAsMarkdown,
5959
splitCodexArtifactTemplateMarkdown,
6060
} from "@t3tools/shared/codexMarkdownDirectives";
6161
import { CHAT_LIST_ANCHOR_OFFSET, resolveChatListAnchoredEndSpace } from "@t3tools/shared/chatList";
@@ -837,7 +837,7 @@ const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: {
837837
}
838838
if (segment.markdown.trim().length === 0) return null;
839839

840-
const markdown = renderCodexFileCitationsAsMarkdown(segment.markdown);
840+
const markdown = renderCodexInlineDirectivesAsMarkdown(segment.markdown);
841841
return (
842842
<SelectableMarkdownText
843843
key={`markdown:${segment.sourceOffset}`}

‎apps/server/src/cli/connect.ts‎

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import * as CliState from "../cloud/CliState.ts";
3131
import * as CliTokenManager from "../cloud/CliTokenManager.ts";
3232
import { filterRelayResponse } from "../cloud/relayResponse.ts";
3333
import {
34+
CLOUD_LINK_REVOKED,
3435
CLOUD_LINKED_USER_ID,
3536
isAgentActivityPublishingEnabledValue,
3637
PUBLISH_AGENT_ACTIVITY_SECRET,
@@ -140,6 +141,8 @@ interface CloudCliStatus {
140141
readonly desired: boolean;
141142
readonly authenticated: boolean;
142143
readonly linked: boolean;
144+
// The relay rejected the stored link, usually after a Deregister.
145+
readonly revoked: boolean;
143146
readonly cloudUserId: string | null;
144147
readonly relayUrl: string | null;
145148
readonly publishAgentActivity: boolean;
@@ -176,18 +179,22 @@ function formatCloudStatus(status: CloudCliStatus, options?: { readonly json?: b
176179
return JSON.stringify(status, null, 2);
177180
}
178181

179-
const provisioned = status.linked
180-
? "provisioned"
181-
: status.desired && status.authenticated
182-
? "pending server startup"
183-
: "not provisioned";
182+
const provisioned = status.revoked
183+
? "removed from T3 Connect"
184+
: status.linked
185+
? "provisioned"
186+
: status.desired && status.authenticated
187+
? "pending server startup"
188+
: "not provisioned";
184189
const nextStep = !status.authenticated
185190
? "Run `t3 connect link` to authorize and enable T3 Connect."
186-
: !status.desired
187-
? "Run `t3 connect link` to enable T3 Connect."
188-
: !status.linked
189-
? "Start T3 to provision the environment link and launch its managed tunnel."
190-
: undefined;
191+
: status.revoked
192+
? "Run `t3 connect link` to link this environment again."
193+
: !status.desired
194+
? "Run `t3 connect link` to enable T3 Connect."
195+
: !status.linked
196+
? "Start T3 to provision the environment link and launch its managed tunnel."
197+
: undefined;
191198

192199
return [
193200
"T3 Connect",
@@ -477,6 +484,11 @@ const linkEnvironmentForConnect = Effect.fn("cloud.cli.link_environment")(functi
477484

478485
const identity = yield* authorizeCli(options);
479486
yield* CliState.setCliDesiredCloudLink(true, publishOnly ? "publish_only" : "managed");
487+
if (yield* CliState.dropRevokedCloudLink) {
488+
yield* Console.log(
489+
"Removed the link T3 Connect no longer accepts. The next start links this environment again.",
490+
);
491+
}
480492
if (publishOnly) {
481493
const secrets = yield* ServerSecretStore.ServerSecretStore;
482494
yield* secrets.set(PUBLISH_AGENT_ACTIVITY_SECRET, stringToBytes("true"));
@@ -543,22 +555,31 @@ const connectStatusCommand = Command.make("status", {
543555
const secrets = yield* ServerSecretStore.ServerSecretStore;
544556
const relayClient = yield* RelayClient.RelayClient;
545557
const tokens = yield* CliTokenManager.CloudCliTokenManager;
546-
const [desired, authenticated, cloudUserId, relayUrl, publishAgentActivity, executable] =
547-
yield* Effect.all(
548-
[
549-
CliState.readCliDesiredCloudLink,
550-
tokens.hasCredential,
551-
secrets.get(CLOUD_LINKED_USER_ID),
552-
secrets.get(RELAY_URL_SECRET),
553-
secrets.get(PUBLISH_AGENT_ACTIVITY_SECRET),
554-
relayClient.resolve,
555-
],
556-
{ concurrency: "unbounded" },
557-
);
558+
const [
559+
desired,
560+
authenticated,
561+
cloudUserId,
562+
relayUrl,
563+
publishAgentActivity,
564+
revoked,
565+
executable,
566+
] = yield* Effect.all(
567+
[
568+
CliState.readCliDesiredCloudLink,
569+
tokens.hasCredential,
570+
secrets.get(CLOUD_LINKED_USER_ID),
571+
secrets.get(RELAY_URL_SECRET),
572+
secrets.get(PUBLISH_AGENT_ACTIVITY_SECRET),
573+
secrets.get(CLOUD_LINK_REVOKED),
574+
relayClient.resolve,
575+
],
576+
{ concurrency: "unbounded" },
577+
);
558578
const status: CloudCliStatus = {
559579
desired,
560580
authenticated,
561581
linked: Option.isSome(cloudUserId),
582+
revoked: Option.isSome(cloudUserId) && Option.isSome(revoked),
562583
cloudUserId: Option.isSome(cloudUserId) ? bytesToString(cloudUserId.value) : null,
563584
relayUrl: Option.isSome(relayUrl) ? bytesToString(relayUrl.value) : null,
564585
publishAgentActivity: isAgentActivityPublishingEnabledValue(

‎apps/server/src/cloud/CliState.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as CliState from "./CliState.ts";
1010
import {
1111
CLOUD_ENDPOINT_CONFIRMED_ORIGIN,
1212
CLOUD_ENDPOINT_RUNTIME_CONFIG,
13+
CLOUD_LINK_REVOKED,
1314
CLOUD_LINKED_USER_ID,
1415
CLOUD_MINT_PUBLIC_KEY,
1516
PUBLISH_AGENT_ACTIVITY_SECRET,
@@ -59,6 +60,37 @@ it.layer(NodeServices.layer)("CliState", (it) => {
5960
}).pipe(Effect.provide(layerTest())),
6061
);
6162

63+
it.effect("drops only a revoked link, keeping the sign-in and preferences", () =>
64+
Effect.gen(function* () {
65+
const secrets = yield* ServerSecretStore.ServerSecretStore;
66+
const dropped = [
67+
CLOUD_LINKED_USER_ID,
68+
RELAY_ENVIRONMENT_CREDENTIAL_SECRET,
69+
CLOUD_MINT_PUBLIC_KEY,
70+
CLOUD_ENDPOINT_RUNTIME_CONFIG,
71+
CLOUD_ENDPOINT_CONFIRMED_ORIGIN,
72+
];
73+
const kept = [RELAY_URL_SECRET, PUBLISH_AGENT_ACTIVITY_SECRET];
74+
for (const name of [...dropped, ...kept]) {
75+
yield* secrets.set(name, new TextEncoder().encode(name));
76+
}
77+
yield* CliState.setCliDesiredCloudLink(true);
78+
79+
assert.isFalse(yield* CliState.dropRevokedCloudLink);
80+
assert.isTrue(Option.isSome(yield* secrets.get(CLOUD_LINKED_USER_ID)));
81+
82+
yield* secrets.set(CLOUD_LINK_REVOKED, new TextEncoder().encode("true"));
83+
assert.isTrue(yield* CliState.dropRevokedCloudLink);
84+
for (const name of [...dropped, CLOUD_LINK_REVOKED]) {
85+
assert.isTrue(Option.isNone(yield* secrets.get(name)));
86+
}
87+
for (const name of kept) {
88+
assert.isTrue(Option.isSome(yield* secrets.get(name)));
89+
}
90+
assert.isTrue(yield* CliState.readCliDesiredCloudLink);
91+
}).pipe(Effect.provide(layerTest())),
92+
);
93+
6294
it.effect("round-trips the desired link mode and defaults legacy links to managed", () =>
6395
Effect.gen(function* () {
6496
const secrets = yield* ServerSecretStore.ServerSecretStore;

‎apps/server/src/cloud/CliState.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
55
import {
66
CLOUD_ENDPOINT_CONFIRMED_ORIGIN,
77
CLOUD_ENDPOINT_RUNTIME_CONFIG,
8+
CLOUD_LINK_REVOKED,
89
CLOUD_LINKED_USER_ID,
910
CLOUD_MINT_PUBLIC_KEY,
1011
PUBLISH_AGENT_ACTIVITY_SECRET,
@@ -57,6 +58,31 @@ export const setCliDesiredCloudLink = Effect.fn("cloud.cli_state.set_desired")(f
5758
}
5859
});
5960

61+
/**
62+
* Drops a link the relay rejected, keeping the sign-in and preferences, so the
63+
* next start links this environment again. `t3 connect link` calls it: the
64+
* server never relinks a revoked link on its own. Returns whether it dropped one.
65+
*/
66+
export const dropRevokedCloudLink = Effect.gen(function* () {
67+
const secrets = yield* ServerSecretStore.ServerSecretStore;
68+
if (Option.isNone(yield* secrets.get(CLOUD_LINK_REVOKED))) {
69+
return false;
70+
}
71+
yield* Effect.all(
72+
[
73+
secrets.remove(CLOUD_LINKED_USER_ID),
74+
secrets.remove(RELAY_ENVIRONMENT_CREDENTIAL_SECRET),
75+
secrets.remove(CLOUD_MINT_PUBLIC_KEY),
76+
secrets.remove(CLOUD_ENDPOINT_RUNTIME_CONFIG),
77+
secrets.remove(CLOUD_ENDPOINT_CONFIRMED_ORIGIN),
78+
],
79+
{ concurrency: "unbounded" },
80+
);
81+
// Last, so a failed removal above leaves the mark for the next attempt.
82+
yield* secrets.remove(CLOUD_LINK_REVOKED);
83+
return true;
84+
});
85+
6086
export const clearPersistedCloudLink = Effect.gen(function* () {
6187
const secrets = yield* ServerSecretStore.ServerSecretStore;
6288
yield* Effect.all(
@@ -70,6 +96,7 @@ export const clearPersistedCloudLink = Effect.gen(function* () {
7096
secrets.remove(CLOUD_ENDPOINT_RUNTIME_CONFIG),
7197
secrets.remove(CLOUD_ENDPOINT_CONFIRMED_ORIGIN),
7298
secrets.remove(PUBLISH_AGENT_ACTIVITY_SECRET),
99+
secrets.remove(CLOUD_LINK_REVOKED),
73100
],
74101
{ concurrency: "unbounded" },
75102
);

0 commit comments

Comments
 (0)