feat(connections): manage T3 Connect environments #13058
ClosedBrechard(GitHub profile, opens in a new tab)wants to merge 18 commits into
main fromrefs/pull/13058/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- packages/client-runtime/src/connection/onboarding.ts line 264OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -215,0 +244,21 @@244+ detail: "Only saved remote environments can be renamed.",245+ });246+ }247+ const label = yield* renamedLabel(options.input.label);248+249+ switch (entry.target._tag) {250+ case "RelayConnectionTarget":251+ return new RelayConnectionRegistration({252+ target: new RelayConnectionTarget({253+ environmentId: entry.target.environmentId,254+ label,255+ }),256+ });257+ case "BearerConnectionTarget": {258+ if (Option.isNone(entry.profile) || !isBearerProfile(entry.profile.value)) {259+ return yield* new ConnectionBlockedError({260+ reason: "configuration",261+ detail: "The saved environment details are unavailable.",262+ });263+ }264+ return yield* prepareBearerConnectionUpdate({apps/web/src/components/settings/ConnectionsSettings.tsx line 2706OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2547,0 +2686,21 @@2686+ const accountId = managedRelayAccountId;2687+ if (!accountId) {2688+ toastManager.add({2689+ type: "error",2690+ title: "Sign in required",2691+ description: "Sign in to T3 Connect before deleting this environment.",2692+ });2693+ return;2694+ }2695+ const confirmed = await requestConfirmDialog(2696+ `Delete ${environment.label} from T3 Connect?\nThis revokes its T3 Connect access and removes any managed tunnel. The environment must be linked again to restore it.`,2697+ { variant: "destructive" },2698+ );2699+ if (confirmed !== true) return;2700+2701+ const environmentId = environment.environmentId;2702+ setMutatingSavedEnvironmentId(environmentId);2703+ setSavedBackendError(null);2704+ const result = await deregisterEnvironment({ accountId, environmentId });2705+ if (result._tag === "Success") {2706+ const saved = environments.some((candidate) => candidate.environmentId === environmentId);apps/web/src/components/settings/ConnectionsSettings.tsx line 2719OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2547,0 +2699,21 @@2699+ if (confirmed !== true) return;2700+2701+ const environmentId = environment.environmentId;2702+ setMutatingSavedEnvironmentId(environmentId);2703+ setSavedBackendError(null);2704+ const result = await deregisterEnvironment({ accountId, environmentId });2705+ if (result._tag === "Success") {2706+ const saved = environments.some((candidate) => candidate.environmentId === environmentId);2707+ if (saved) {2708+ const removeResult = await removeEnvironment(environmentId);2709+ if (removeResult._tag === "Failure" && !isAtomCommandInterrupted(removeResult)) {2710+ const error = squashAtomCommandFailure(removeResult);2711+ console.error("[t3-connect] Environment deregistered but local cleanup failed", {2712+ environmentId,2713+ error,2714+ });2715+ }2716+ }2717+ refreshManagedRelayEnvironmentList();2718+ await refreshRelayEnvironments();2719+ setMutatingSavedEnvironmentId(null);
- apps/web/src/components/settings/ConnectionsSettings.tsx lines 1521 to 1523OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1475,0 +1503,21 @@1503+ };1504+1505+ return (1506+ <Dialog open onOpenChange={(open) => !open && onClose()}>1507+ <DialogPopup className="sm:max-w-md">1508+ <DialogHeader>1509+ <DialogTitle>Rename environment</DialogTitle>1510+ <DialogDescription>1511+ Choose a name that makes this machine easy to recognize on this device.1512+ </DialogDescription>1513+ </DialogHeader>1514+ <DialogPanel>1515+ <label className="block">1516+ <span className="mb-1.5 block text-xs font-medium text-foreground">Name</span>1517+ <Input1518+ value={label}1519+ onChange={(event) => setLabel(event.target.value)}1520+ onKeyDown={(event) => {1521+ if (event.key === "Enter" && label.trim() !== "") {1522+ event.preventDefault();1523+ void submit();packages/client-runtime/src/connection/onboarding.ts line 326OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -215,0 +306,21 @@306+ }),307+ });308+ }309+ }310+});311+312+const renameConnection = Effect.fn("clientRuntime.connection.onboarding.renameConnection")(313+ function* (input: ConnectionRenameInput) {314+ const registry = yield* EnvironmentRegistry.EnvironmentRegistry;315+ const credentials = yield* ConnectionCredentialStore.ConnectionCredentialStore;316+ const entry = (yield* SubscriptionRef.get(registry.entries)).get(input.environmentId);317+ const credential =318+ entry?.target._tag === "BearerConnectionTarget"319+ ? yield* credentials.get(entry.target.connectionId)320+ : Option.none();321+ const registration = yield* prepareConnectionRename({322+ input,323+ entry: Option.fromUndefinedOr(entry),324+ credential,325+ });326+ yield* registry.register(registration);
- apps/web/src/connection/onboarding.ts lines 48 to 48OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -36,3 +36,13 @@3636 execute: (input: { readonly target: DesktopSshEnvironmentTarget; readonly label?: string }) =>3737 ConnectionOnboarding.pipe(Effect.flatMap((onboarding) => onboarding.registerSsh(input))),3838 });39+40+export const renameEnvironment = createRuntimeCommand(connectionAtomRuntime, {41+ label: "web:connection:rename-environment",42+ scheduler: onboardingScheduler,43+ concurrency: {44+ mode: "serial",45+ key: (input: { readonly environmentId: EnvironmentId }) => input.environmentId,46+ },47+ execute: (input: { readonly environmentId: EnvironmentId; readonly label: string }) =>48+ ConnectionOnboarding.pipe(Effect.flatMap((onboarding) => onboarding.rename(input))),
- apps/web/src/components/settings/ConnectionsSettings.tsx lines 2693 to 2696Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2539,3 +2687,18 @@25392687 [removeEnvironment],25402688 );254126892690+ const handleDeregisterEnvironment = useCallback(2691+ async (environment: RelayClientEnvironmentRecord | EnvironmentPresentation) => {2692+ const accountId = managedRelayAccountId;2693+ if (!accountId) {2694+ toastManager.add({2695+ type: "error",2696+ title: "Sign in required",2697+ description: "Sign in to T3 Connect before deleting this environment.",2698+ });2699+ return;2700+ }2701+ const confirmed = await requestConfirmDialog(2702+ `Delete ${environment.label} from T3 Connect?\nThis revokes its T3 Connect access and removes any managed tunnel. The environment must be linked again to restore it.`,2703+ { variant: "destructive" },2704+ );
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx line 528OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -469,0 +508,21 @@508+ <Button size="sm" variant="outline" disabled>509+ {savedConnection.buttonLabel}510+ </Button>511+ ) : (512+ <Button513+ size="sm"514+ disabled={connectingEnvironmentIds.size > 0}515+ onClick={() => void connectEnvironment(environment)}516+ >517+ {connectingEnvironmentIds.has(environment.environmentId) ? "Adding…" : "Add"}518+ </Button>519+ )}520+ {onDeregister ? (521+ <Menu>522+ <MenuTrigger523+ render={524+ <Button525+ type="button"526+ variant="ghost-muted"527+ size="icon-xs"528+ disabled={deregisteringEnvironmentIds?.has(environment.environmentId)}
- apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx lines 210 to 211Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -182,3 +201,6 @@182201 return false;183202 };184203204+ const renameDiscoveredEnvironment = async () => {205+ if (renamingEnvironment === null || renameLabel.trim() === "") return;206+ const environment = renamingEnvironment;
- apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx line 573OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -470 +553,21 @@553+ onClick={() => {554+ setRenameLabel(environment.label);555+ setRenamingEnvironment(environment);556+ }}557+ >558+ <PencilIcon className="size-3.5" />559+ Rename…560+ </MenuItem>561+ ) : null}562+ <MenuItem variant="destructive" onClick={() => onDeregister(environment)}>563+ {deregisteringEnvironmentIds?.has(environment.environmentId)564+ ? "Deleting…"565+ : "Delete from T3 Connect…"}566+ </MenuItem>567+ </MenuPopup>568+ </Menu>569+ ) : null}570+ </div>470571 </div>572+ {renamingEnvironment?.environmentId === environment.environmentId ? (573+ <Dialog open onOpenChange={(open) => !open && setRenamingEnvironment(null)}>
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- @@ -215,0 +314,21 @@314+const renameConnection = Effect.fn("clientRuntime.connection.onboarding.renameConnection")(315+ function* (input: ConnectionRenameInput) {316+ const registry = yield* EnvironmentRegistry.EnvironmentRegistry;317+ const credentials = yield* ConnectionCredentialStore.ConnectionCredentialStore;318+ const entry = (yield* SubscriptionRef.get(registry.entries)).get(input.environmentId);319+ const scopeChanged =320+ entry?.target._tag === "RelayConnectionTarget" &&321+ (input.localOnly === false322+ ? entry.target.localLabelOverride === true323+ : entry.target.localLabelOverride !== true);324+ if (entry !== undefined && input.label.trim() === entry.target.label && !scopeChanged) return;325+ const credential =326+ entry?.target._tag === "BearerConnectionTarget"327+ ? yield* credentials.get(entry.target.connectionId)328+ : Option.none();329+ const registration = yield* prepareConnectionRename({330+ input,331+ entry: Option.fromUndefinedOr(entry),332+ credential,333+ });334+ yield* registry.register(registration);apps/web/src/components/settings/ConnectionsSettings.tsx line 1662Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1623,11 +1715,18 @@16231715 type="button"16241716 variant="ghost-muted"16251717 size="icon-xs"1626- disabled={isRemoving}1718+ disabled={isRemoving || isMutating}16271719 aria-label={`More actions for ${environment.label}`}16281720 />16291721 }16301722 >16311723 <EllipsisIcon className="size-3.5" />16321724 </MenuTrigger>1633- <MenuPopup align="end">1725+ <MenuPopup align="end" className="min-w-52">1726+ {environment.entry.target._tag === "RelayConnectionTarget" ? (1727+ <>1728+ <MenuItem onClick={() => setRenameScope("global")}>1729+ <PencilIcon className="size-3.5" />1730+ Rename for all devices…1731+ </MenuItem>1732+ <MenuItem onClick={() => void onRenameGlobally(environmentId, null)}>
- packages/client-runtime/src/connection/layer.ts line 44OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -32,4 +32,13 @@3232 if (!current.environments.has(environmentId)) seenChecks.delete(environmentId);3333 }3434 }35+ const saved = yield* SubscriptionRef.get(registry.entries);3536 for (const entry of current.environments.values()) {37+ const environmentId = entry.environment.environmentId;38+ const target = saved.get(environmentId)?.target;39+ if (40+ target?._tag === "RelayConnectionTarget" &&41+ target.localLabelOverride !== true &&42+ target.label !== entry.environment.label43+ ) {44+ yield* registry.syncRelayLabel(environmentId, entry.environment.label);packages/contracts/src/relay.ts lines 767 to 769Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -764,3 +764,6 @@764764 });765765 export type RelayEnvironmentUnlinkParams = typeof RelayEnvironmentUnlinkParams.Type;766766767+export const RelayEnvironmentRenameRequest = Schema.Struct({768+ label: Schema.NullOr(TrimmedNonEmptyString),769+});
- packages/client-runtime/src/connection/layer.ts line 47OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -32,4 +32,16 @@3232 if (!current.environments.has(environmentId)) seenChecks.delete(environmentId);3333 }3434 }35+ const saved = yield* SubscriptionRef.get(registry.entries);3536 for (const entry of current.environments.values()) {37+ const environmentId = entry.environment.environmentId;38+ const target = saved.get(environmentId)?.target;39+ if (40+ target?._tag === "RelayConnectionTarget" &&41+ (target.label !== entry.environment.label || target.localLabelOverride === true)42+ ) {43+ yield* registry.syncRelayLabel(environmentId, entry.environment.label).pipe(44+ Effect.catch((error) =>45+ Effect.logWarning("Could not sync discovered environment label.", {46+ environmentId,47+ error,
- packages/client-runtime/src/connection/registry.ts line 383OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -373,16 +379,5 @@373- Stream.switchMap(374- Option.match({375- onNone: () => Stream.empty,376- onSome: () =>377- Stream.unwrap(378- acquireSupervisor(environmentId).pipe(379- Effect.match({380- onFailure: () => Stream.empty,381- onSuccess: (supervisor) =>382- Stream.provideService(383- stream,384- EnvironmentSupervisor.EnvironmentSupervisor,385- supervisor,386- ),387- }),388- ),379+ Stream.mapEffect((entry) =>380+ Option.isNone(entry)381+ ? Effect.succeed(null)382+ : acquireSupervisor(environmentId).pipe(383+ Effect.catchTag("EnvironmentNotRegisteredError", () => Effect.succeed(null)),
Brechard(GitHub profile, opens in a new tab) changed the title
juliusmarminge closed this
Sign in to join this conversation.




macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed