Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

LinkedEnvironmentsSettings.tsx

676 lines26.2 KB

1import { useAtomValue } from "@effect/atom-react";
2import {
3 linkBackBlockLabel,
4 linkBatchFailureLabel,
5 linkWithMintedCode,
6} from "@t3tools/client-runtime/link-batch";
7import { ANOTHER_ADDRESS, linkRequestFailureMessage } from "@t3tools/client-runtime/link-request";
8import {
9 AuthAccessWriteScope,
10 type AuthMcpClientAccess,
11 type EnvironmentId,
12 type PeerLinkSummary,
13} from "@t3tools/contracts";
14import {
15 isAtomCommandInterrupted,
16 squashAtomCommandFailure,
17} from "@t3tools/client-runtime/state/runtime";
18import { peerLinkHealth, type PeerLinkHealth } from "@t3tools/client-runtime/state/peerLinks";
19import * as DateTime from "effect/DateTime";
20import * as Option from "effect/Option";
21import * as Result from "effect/Result";
22import { PlusIcon } from "lucide-react";
23import { T, useGT, useMessages, Var } from "gt-react";
24import { type ReactNode, useId, useRef, useState } from "react";
25​
26import { requestConfirmDialog } from "~/confirmDialog";
27import { useEnvironment } from "~/state/environments";
28import { mintPairingCodeOn } from "~/state/peerPairingCode";
29import {
30 peerLinkEnvironment,
31 useLinkableMachines,
32 useLinkBackOffers,
33 useLinkThroughRoutes,
34} from "~/state/peerLinks";
35import { useEnvironments } from "~/state/environments";
36import { useEnvironmentQuery } from "~/state/query";
37import { useEnvironmentScope, usePreparedConnection } from "~/state/session";
38import { useAtomCommand } from "~/state/use-atom-command";
39import { accessConfig } from "../auth/ConnectAgentSurface";
40import { ConnectionStatusDot } from "../ConnectionStatusDot";
41import { Button } from "../ui/button";
42import { Checkbox } from "../ui/checkbox";
43import {
44 Dialog,
45 DialogClose,
46 DialogDescription,
47 DialogFooter,
48 DialogHeader,
49 DialogPanel,
50 DialogPopup,
51 DialogTitle,
52 DialogTrigger,
53} from "../ui/dialog";
54import { Input } from "../ui/input";
55import { stackedThreadToast, toastManager } from "../ui/toast";
56import { ITEM_ROW_CLASSNAME, ITEM_ROW_INNER_CLASSNAME } from "./itemRows";
57import { LinkAccessPicker } from "./LinkAccessPicker";
58import { LinkAddressWarning, LinkMachineSelect } from "./LinkMachineSelect";
59import { LinkSeveralEnvironmentsAction } from "./LinkSeveralEnvironments";
60import { SettingsRow, SettingsSection } from "./settingsLayout";
61import { useLiveRefresh } from "../../hooks/useLiveRefresh";
62import { m as resolveMessage } from "../../i18n/messages";
63import { useNowMinute } from "../../hooks/useNowMinute";
64import { useSearchableSetting } from "./settingsSearch";
65​
66// Console log labels for the atom commands.
67const UNLINK_COMMAND_LABEL = "unlink environment";
68const LINK_COMMAND_LABEL = "link environment";
69​
70const failureToast = (title: string, description: string) =>
71 toastManager.add(stackedThreadToast({ type: "error", title, description }));
72​
73export function LinkedEnvironmentsSettings({
74 environmentId,
75 environmentLabel,
76 isSearchTarget,
77}: {
78 readonly environmentId: EnvironmentId;
79 readonly environmentLabel: string | null;
80 readonly isSearchTarget: boolean;
81}) {
82 const searchableSetting = useSearchableSetting();
83 const gt = useGT();
84 const links = useEnvironmentQuery(
85 peerLinkEnvironment.list({ environmentId, input: {} }),
86 useMessages(),
87 );
88 // Links made outside this client bump nothing the shared list reads, so showing the panel
89 // asks again. Listing probes every linked environment, too costly for a timer nobody asked for.
90 // A list still loading counts as read now, so the next return to the window asks again.
91 useLiveRefresh(
92 () => {
93 if (!links.isPending) links.refresh();
94 },
95 {
96 key: `linked-environments:${environmentId}`,
97 intervalMs: null,
98 refreshOnShow: true,
99 },
100 );
101 const canLink = useAtomValue(peerLinkEnvironment.link.permissionAtom(environmentId));
102 const search = searchableSetting("linked-environments");
103 // A batch needs at least two other machines this app has saved.
104 const otherMachines = useEnvironments().environments.length - 1;
105 return (
106 <SettingsSection
107 {...(isSearchTarget ? { id: search.id } : {})}
108 title={environmentLabel === null ? search.title : `${search.title} · ${environmentLabel}`}
109 headerAction={
110 canLink ? (
111 <div className="flex items-center gap-2">
112 {otherMachines > 1 ? (
113 <LinkSeveralEnvironmentsAction environmentId={environmentId} />
114 ) : null}
115 <LinkEnvironmentAction environmentId={environmentId} />
116 </div>
117 ) : null
118 }
119 >
120 {links.error ? (
121 <SettingsRow title={gt("Could not load linked environments")} description={links.error} />
122 ) : !links.data ? (
123 <SettingsRow title={gt("Loading linked environments…")} role="status" />
124 ) : links.data.links.length === 0 ? (
125 <SettingsRow
126 title={gt("No linked environments")}
127 description={gt(
128 "Link another machine running T3 Code, such as a VPS, so agents here can launch and drive threads there.",
129 )}
130 />
131 ) : (
132 links.data.links.map((link) => (
133 <LinkedEnvironmentRow
134 key={link.environmentId}
135 environmentId={environmentId}
136 link={link}
137 />
138 ))
139 )}
140 </SettingsSection>
141 );
143​
144function LinkedEnvironmentRow({
145 environmentId,
146 link,
147}: {
148 readonly environmentId: EnvironmentId;
149 readonly link: PeerLinkSummary;
150}) {
151 const gt = useGT();
152 const m = useMessages();
153 const nowMinute = useNowMinute();
154 const health = peerLinkHealth(link, DateTime.makeUnsafe(nowMinute));
155 const canUnlink = useAtomValue(peerLinkEnvironment.unlink.permissionAtom(environmentId));
156 const { busy, forget } = useForgetPeerLink(environmentId, link);
157 const status = peerLinkStatusText(health, gt);
158 return (
159 <div className={ITEM_ROW_CLASSNAME}>
160 <div className={ITEM_ROW_INNER_CLASSNAME}>
161 <div className="min-w-0 flex-1 space-y-1">
162 <div className="flex min-h-5 items-center gap-1.5">
163 <ConnectionStatusDot
164 tooltipText={status}
165 dotClassName={
166 health.kind === "reachable"
167 ? health.expiresInDays === null
168 ? "bg-success"
169 : "bg-warning"
170 : health.kind === "expired" || health.kind === "failing"
171 ? "bg-destructive"
172 : "bg-muted-foreground/30"
173 }
174 pingClassName={null}
175 />
176 <h3 className="text-sm font-medium text-foreground">{link.label}</h3>
177 </div>
178 <p className="text-xs text-muted-foreground">
179 {m(accessConfig[link.access].label)} · {status}
180 </p>
181 <p className="truncate text-xs text-muted-foreground/80">{link.urls.join(", ")}</p>
182 </div>
183 {canUnlink ? (
184 <div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
185 <Button
186 size="xs"
187 variant="destructive-outline"
188 disabled={busy}
189 onClick={() => void forget()}
190 >
191 {busy ? gt("Forgetting…") : gt("Forget")}
192 </Button>
193 </div>
194 ) : null}
195 </div>
196 </div>
197 );
199​
200function LinkEnvironmentAction({ environmentId }: { readonly environmentId: EnvironmentId }) {
201 const gt = useGT();
202 const [open, setOpen] = useState(false);
203 return (
204 <LinkEnvironmentDialog
205 environmentId={environmentId}
206 open={open}
207 onOpenChange={setOpen}
208 trigger={
209 <DialogTrigger
210 render={
211 <Button size="xs" variant="default">
212 <PlusIcon className="size-3" />
213 {gt("Link", { $context: "verb, links an environment" })}
214 </Button>
215 }
216 />
217 }
218 />
219 );
221​
222/** What the link dialog opens with when something other than its own button opened it. */
223export interface LinkEnvironmentPrefill {
224 /** The machine to link to, by environment id, or `ANOTHER_ADDRESS` with `address`. */
225 readonly choice: string | null;
226 readonly address?: string;
227 /**
228 * With `address`: the machine there, and one of this app's that links to it at full access and
229 * so can get the pairing code from it.
230 */
231 readonly through?: {
232 readonly viaEnvironmentId: EnvironmentId;
233 readonly environmentId: EnvironmentId;
234 readonly label: string;
235 };
237​
238/**
239 * The one link flow. When this client is connected to the picked machine and may create pairing
240 * links there, it mints the code itself; otherwise it asks for one.
241 */
242export function LinkEnvironmentDialog({
243 environmentId,
244 open,
245 onOpenChange,
246 trigger = null,
247 prefill,
248}: {
249 readonly environmentId: EnvironmentId;
250 readonly open: boolean;
251 readonly onOpenChange: (open: boolean) => void;
252 readonly trigger?: ReactNode;
253 readonly prefill?: LinkEnvironmentPrefill;
254}) {
255 const gt = useGT();
256 const m = useMessages();
257 const setOpen = onOpenChange;
258 // Named in the title: from the map, nothing else on screen says which machine is linking.
259 const source = useEnvironment(environmentId);
260 const saved = useLinkableMachines(environmentId, open);
261 const routes = useLinkThroughRoutes(environmentId, open);
262 // Machines this app has no entry for are still pickable when one of its environments links
263 // to them at full access.
264 const machines = [
265 ...saved,
266 ...[...routes.values()]
267 .filter((route) => saved.every((machine) => machine.environmentId !== route.environmentId))
268 .map((route) => ({
269 environmentId: route.environmentId,
270 label: route.label,
271 machine: "server" as const,
272 connected: false,
273 connectOnly: false,
274 linked: false,
275 urls: route.urls,
276 })),
277 ];
278 // Null until the user picks; with no other machines known, only an address is left.
279 const [choice, setChoice] = useState<string | null>(prefill?.choice ?? null);
280 const [address, setAddress] = useState(prefill?.address ?? "");
281 const [pairingCode, setPairingCode] = useState("");
282 const [access, setAccess] = useState<AuthMcpClientAccess>("approval-required");
283 const [busy, setBusy] = useState(false);
284 // Machines whose minting already failed, so the dialog asks for a code instead.
285 const [mintFailed, setMintFailed] = useState<ReadonlySet<EnvironmentId>>(new Set());
286 // Enter then a click can both run before a re-render; this guard is synchronous.
287 const inFlight = useRef(false);
288 const formId = useId();
289 const link = useAtomCommand(peerLinkEnvironment.link, { label: LINK_COMMAND_LABEL });
290 const linkOnTarget = useAtomCommand(peerLinkEnvironment.link, {
291 label: "link environment back",
292 // The failure cause holds the request, and with it the code; keep it out of the console.
293 reportFailure: false,
294 reportDefect: false,
295 });
296 const pairThrough = useAtomCommand(peerLinkEnvironment.pairLink, {
297 label: "pair link through a linked environment",
298 // The answer is a credential; keep it out of the console.
299 reportFailure: false,
300 reportDefect: false,
301 });
302 // Machines that would not give a code through a link, so the dialog asks for one instead.
303 const [throughFailed, setThroughFailed] = useState<ReadonlySet<EnvironmentId>>(new Set());
304 const [alsoLinkBack, setAlsoLinkBack] = useState(false);
305 const selected = choice ?? (machines.length === 0 ? ANOTHER_ADDRESS : null);
306 // Only for the machine the dialog opened for: another choice or address is another machine.
307 const prefilledThrough =
308 prefill?.through !== undefined &&
309 selected === ANOTHER_ADDRESS &&
310 address === (prefill.address ?? "")
311 ? prefill.through
312 : null;
313 const machine = machines.find((candidate) => candidate.environmentId === selected) ?? null;
314 const targetId = machine?.environmentId ?? null;
315 const connected = usePreparedConnection(targetId);
316 const mayMint = useEnvironmentScope(targetId, AuthAccessWriteScope);
317 // A picked machine that left the list has no address here either.
318 const needsAddress = selected !== null && (machine === null || machine.urls.length === 0);
319 // This client mints a code there when it is connected with a session that may
320 // create pairing links, and only for its own addresses: anything can answer
321 // as that machine at one typed in, so that one gets a code the user fetched.
322 const canMint =
323 targetId !== null &&
324 !needsAddress &&
325 Option.isSome(connected) &&
326 mayMint &&
327 !mintFailed.has(targetId);
328 // Minting with this client's own session there comes first: it needs no third machine.
329 const throughCandidate =
330 prefilledThrough ?? (targetId === null || canMint ? null : (routes.get(targetId) ?? null));
331 const via = useEnvironment(throughCandidate?.viaEnvironmentId ?? null);
332 const through =
333 throughCandidate !== null && via !== null && !throughFailed.has(throughCandidate.environmentId)
334 ? throughCandidate
335 : null;
336 const linkBack = useLinkBackOffers(environmentId, targetId === null ? [] : [targetId], open);
337 const backOffer = linkBack.offerFor(targetId);
338 const ready =
339 through !== null ||
340 (selected !== null &&
341 (!needsAddress || address.trim().length > 0) &&
342 (canMint || pairingCode.trim().length > 0));
343 const handleOpenChange = (next: boolean) => {
344 setOpen(next);
345 if (!next) {
346 setChoice(prefill?.choice ?? null);
347 setAddress(prefill?.address ?? "");
348 setPairingCode("");
349 setAccess("approval-required");
350 setMintFailed(new Set());
351 setThroughFailed(new Set());
352 setAlsoLinkBack(false);
353 }
354 };
355 // Settles to what to link with, or null after reporting why the linked machine gave no code.
356 const resolveThrough = async (target: NonNullable<typeof through>) => {
357 const asked = await pairThrough({
358 environmentId: target.viaEnvironmentId,
359 input: { environmentId: target.environmentId, access },
360 });
361 if (asked._tag === "Success" && asked.value.type === "credential") {
362 const [url, ...alternateUrls] = asked.value.urls;
363 if (url !== undefined) {
364 return {
365 url,
366 ...(alternateUrls.length > 0 ? { alternateUrls } : {}),
367 expectedEnvironmentId: asked.value.environmentId,
368 expectedLabel: asked.value.label,
369 pairingCode: asked.value.credential,
370 };
371 }
372 }
373 if (asked._tag === "Failure" && isAtomCommandInterrupted(asked)) return null;
374 setThroughFailed((failed) => new Set(failed).add(target.environmentId));
375 failureToast(
376 gt("{via} could not get a pairing code from {target}", {
377 via: via?.label ?? "",
378 target: target.label,
379 }),
380 gt("Enter its address and a pairing code from it instead."),
381 );
382 return null;
383 };
384 // Settles to the code to link with, or null after reporting why there is none.
385 const resolvePairingCode = async () => {
386 if (!canMint || targetId === null) return pairingCode.trim();
387 const minted = await mintPairingCodeOn(targetId, access);
388 if (Result.isSuccess(minted)) return minted.success;
389 setMintFailed((failed) => new Set(failed).add(targetId));
390 failureToast(
391 gt("Could not link the environment"),
392 linkRequestFailureMessage(minted.failure, resolveMessage),
393 );
394 return null;
395 };
396 const submit = async () => {
397 const [url, ...alternateUrls] =
398 machine === null || needsAddress ? [address.trim()] : machine.urls;
399 if (inFlight.current || !ready || url === undefined) return;
400 inFlight.current = true;
401 setBusy(true);
402 const throughInput = through === null ? null : await resolveThrough(through);
403 const code = through === null ? await resolvePairingCode() : null;
404 const result =
405 through !== null
406 ? throughInput === null
407 ? null
408 : await link({ environmentId, input: { ...throughInput, access } })
409 : code === null
410 ? null
411 : await link({
412 environmentId,
413 input: {
414 url,
415 ...(alternateUrls.length > 0 ? { alternateUrls } : {}),
416 // A typed address links alone: only this app's own addresses name a machine.
417 ...(machine === null || needsAddress
418 ? {}
419 : { expectedEnvironmentId: machine.environmentId, expectedLabel: machine.label }),
420 pairingCode: code,
421 access,
422 },
423 });
424 // The link back is its own link, made on the other machine: it never undoes this one.
425 const back =
426 result?._tag === "Success" &&
427 alsoLinkBack &&
428 backOffer.kind === "offered" &&
429 linkBack.source !== null &&
430 targetId !== null &&
431 // A typed address can answer as another machine: the picked one links back only if it did.
432 result.value.environmentId === targetId
433 ? await linkWithMintedCode({
434 machine: linkBack.source,
435 access,
436 mint: mintPairingCodeOn,
437 link: async (input) => {
438 const reverse = await linkOnTarget({ environmentId: targetId, input });
439 return reverse._tag === "Success"
440 ? Result.succeed(reverse.value)
441 : Result.fail(squashAtomCommandFailure(reverse));
442 },
443 })
444 : null;
445 inFlight.current = false;
446 setBusy(false);
447 if (result === null) return;
448 if (result._tag === "Success") {
449 const names = { source: source?.label ?? "", target: result.value.label };
450 toastManager.add({
451 type: "success",
452 title:
453 back?.kind === "linked"
454 ? gt("Linked {source} and {target} both ways", names)
455 : gt("Linked {label}", { label: result.value.label }),
456 });
457 if (back?.kind === "failed") {
458 failureToast(
459 gt("Could not link {target} back to {source}", names),
460 back.detail ?? linkBatchFailureLabel(back.failure, m),
461 );
462 }
463 handleOpenChange(false);
464 } else if (!isAtomCommandInterrupted(result)) {
465 failureToast(gt("Could not link the environment"), String(squashAtomCommandFailure(result)));
466 }
467 };
468 return (
469 <Dialog
470 open={open}
471 onOpenChange={(next) => {
472 if (!next && busy) return;
473 handleOpenChange(next);
474 }}
475 >
476 {trigger}
477 <DialogPopup className="max-w-md">
478 <DialogHeader>
479 <DialogTitle>
480 {source === null ? (
481 <T>Link an environment</T>
482 ) : through !== null ? (
483 gt("Link {source} to {target}", { source: source.label, target: through.label })
484 ) : machine === null ? (
485 gt("Link {label} to another machine", { label: source.label })
486 ) : (
487 gt("Link {source} to {target}", { source: source.label, target: machine.label })
488 )}
489 </DialogTitle>
490 <DialogDescription>
491 <T>
492 Agents here can then launch, message and wait on threads there. It appears under
493 Authorized clients in that environment's Sharing & access, where it can be revoked.
494 </T>
495 </DialogDescription>
496 </DialogHeader>
497 <DialogPanel>
498 <form
499 id={formId}
500 className="space-y-4"
501 autoComplete="off"
502 onSubmit={(event) => {
503 event.preventDefault();
504 void submit();
505 }}
506 >
507 {machines.length > 0 && (through === null || through !== prefilledThrough) ? (
508 <LinkMachineSelect
509 machines={machines}
510 value={selected}
511 disabled={busy}
512 onChange={(next) => {
513 // The opt-in names one machine: it does not carry over to another.
514 if (next !== selected) setAlsoLinkBack(false);
515 setChoice(next);
516 }}
517 />
518 ) : null}
519 {machine?.linked ? (
520 <p className="text-xs text-muted-foreground">
521 <T>Already linked. Linking again renews it with the access you pick.</T>
522 </p>
523 ) : null}
524 {through !== null ? (
525 <p className="text-xs text-muted-foreground">
526 {gt(
527 "{via} links to {target} at full access, so it gets the pairing code. No code to paste.",
528 { via: via?.label ?? "", target: through.label },
529 )}
530 </p>
531 ) : null}
532 {needsAddress && through === null ? (
533 <label className="block space-y-1.5">
534 <span className="block text-xs font-medium text-foreground">
535 <T>Address</T>
536 </span>
537 <Input
538 value={address}
539 onChange={(event) => {
540 setAddress(event.target.value);
541 // Machines found after typing began must not hide the address being typed.
542 if (choice === null) setChoice(ANOTHER_ADDRESS);
543 }}
544 placeholder="https://box.example.ts.net"
545 disabled={busy}
546 autoFocus={machines.length === 0}
547 nativeInput
548 spellCheck={false}
549 />
550 {machine !== null ? (
551 <span className="block text-xs text-muted-foreground">
552 <T>
553 This app has no address for <Var>{machine.label}</Var> that another machine
554 can reach. Enter its https or Tailscale address.
555 </T>
556 </span>
557 ) : null}
558 </label>
559 ) : null}
560 {needsAddress && through === null && address.trim() ? (
561 <LinkAddressWarning address={address} />
562 ) : null}
563 {selected === null || canMint || through !== null ? null : (
564 <label className="block space-y-1.5">
565 <span className="block text-xs font-medium text-foreground">
566 <T>Pairing code</T>
567 </span>
568 <Input
569 value={pairingCode}
570 onChange={(event) => setPairingCode(event.target.value)}
571 placeholder={
572 machine === null
573 ? gt("From Sharing & access there, or t3 pair")
574 : gt("Paste the code")
575 }
576 disabled={busy}
577 autoComplete="one-time-code"
578 nativeInput
579 spellCheck={false}
580 />
581 {machine !== null ? (
582 <span className="block text-xs text-muted-foreground">
583 <T>
584 Create a link on <Var>{machine.label}</Var>: Settings → Sharing & access →
585 Authorized clients → Create link, then paste its code here.
586 </T>
587 </span>
588 ) : null}
589 </label>
590 )}
591 <LinkAccessPicker value={access} onChange={setAccess} disabled={busy} />
592 {machine === null || source === null ? null : backOffer.kind === "offered" ? (
593 <label className="flex cursor-pointer items-start gap-2.5 text-sm has-data-disabled:cursor-default">
594 <Checkbox
595 checked={alsoLinkBack}
596 disabled={busy}
597 onCheckedChange={setAlsoLinkBack}
598 />
599 <span className="min-w-0 space-y-0.5">
600 <span className="block font-medium text-foreground">
601 {gt("Also link {target} back to {source}", {
602 source: source.label,
603 target: machine.label,
604 })}
605 </span>
606 <span className="block text-xs text-muted-foreground">
607 {gt("Agents on {target} can then work on {source} too.", {
608 source: source.label,
609 target: machine.label,
610 })}
611 </span>
612 </span>
613 </label>
614 ) : backOffer.kind === "blocked" ? (
615 <p className="text-xs text-muted-foreground">
616 {linkBackBlockLabel(
617 backOffer.reason,
618 { source: source.label, target: machine.label },
619 m,
620 )}
621 </p>
622 ) : null}
623 </form>
624 </DialogPanel>
625 <DialogFooter variant="bare">
626 <DialogClose disabled={busy} render={<Button variant="outline" type="button" />}>
627 <T>Cancel</T>
628 </DialogClose>
629 <Button form={formId} type="submit" disabled={busy || !ready}>
630 {busy ? gt("Linking…") : gt("Link", { $context: "verb, links an environment" })}
631 </Button>
632 </DialogFooter>
633 </DialogPopup>
634 </Dialog>
635 );
637​
638/** What a link's health means for the user, in a sentence. */
639export function peerLinkStatusText(health: PeerLinkHealth, gt: ReturnType<typeof useGT>): string {
640 return health.kind === "expired"
641 ? gt("Expired. Link it again with a new pairing code.")
642 : health.kind === "unreachable"
643 ? (health.detail ?? gt("Not answering right now."))
644 : health.kind === "failing"
645 ? health.detail
646 : health.expiresInDays !== null
647 ? gt(
648 "{days, plural, one {Expires in {days} day. Link it again to renew.} other {Expires in {days} days. Link it again to renew.}}",
649 { days: health.expiresInDays },
650 )
651 : gt("Reachable");
653​
654/** Forgets `link` from `environmentId` after the user confirms. */
655export function useForgetPeerLink(environmentId: EnvironmentId, link: PeerLinkSummary) {
656 const gt = useGT();
657 const unlink = useAtomCommand(peerLinkEnvironment.unlink, { label: UNLINK_COMMAND_LABEL });
658 const [busy, setBusy] = useState(false);
659 const forget = async () => {
660 const confirmed = await (requestConfirmDialog(
661 gt(
662 "Forget {label}? Agents here stop working there. Revoke \"T3 Code · …\" in {label}''s Sharing & access to end the session there too.",
663 { label: link.label },
664 ),
665 { variant: "destructive" },
666 ) ?? Promise.resolve(false));
667 if (!confirmed) return;
668 setBusy(true);
669 const result = await unlink({ environmentId, input: { environmentId: link.environmentId } });
670 setBusy(false);
671 if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
672 failureToast(gt("Could not forget the link"), String(squashAtomCommandFailure(result)));
673 }
674 };
675 return { busy, forget };