Open History to see the last commit
1import { AuthMcpClientAccess } from "@t3tools/contracts";
2import { T, useMessages } from "gt-react";
3import { useId } from "react";
4
5import { accessConfig } from "../auth/ConnectAgentSurface";
6import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
7
8/** What agents here may do in an environment being linked, with what that does not allow. */
9export function LinkAccessPicker({
10 value,
11 onChange,
12 disabled = false,
13 forWriting = false,
14}: {
15 readonly value: AuthMcpClientAccess;
16 readonly onChange: (access: AuthMcpClientAccess) => void;
17 readonly disabled?: boolean;
18 /** The link is being made to send work over it, which read-only cannot take. */
19 readonly forWriting?: boolean;
20}) {
21 const labelId = useId();
22 const m = useMessages();
23 const selected = accessConfig[value];
24 return (
25 <div className="space-y-1.5">
26 <span id={labelId} className="block text-xs font-medium">
27 <T>What agents here may do there</T>
28 </span>
29 <Select
30 value={value}
31 disabled={disabled}
32 onValueChange={(next) => {
33 if (next !== null) onChange(next as AuthMcpClientAccess);
34 }}
35 >
36 <SelectTrigger aria-labelledby={labelId}>
37 <SelectValue>
38 <span className="flex items-center gap-2">
39 <selected.icon aria-hidden className="size-4" />
40 {m(selected.label)}
41 </span>
42 </SelectValue>
43 </SelectTrigger>
44 <SelectPopup alignItemWithTrigger={false}>
45 {AuthMcpClientAccess.literals
46 .filter((option) => !forWriting || option !== "read-only")
47 .map((option) => {
48 const { label, description, icon: Icon } = accessConfig[option];
49 return (
50 <SelectItem key={option} value={option} hideIndicator>
51 <span className="grid min-w-0 gap-0.5 py-0.5">
52 <span className="inline-flex items-center gap-1.5 font-medium text-foreground">
53 <Icon aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />
54 {m(label)}
55 </span>
56 <span className="text-xs leading-4 text-muted-foreground">
57 {m(description)}
58 </span>
59 </span>
60 </SelectItem>
61 );
62 })}
63 </SelectPopup>
64 </Select>
65 <p className="text-xs text-muted-foreground">
66 {m(selected.description)}{" "}
67 <T>
68 An agent never gets more access there than its own mode here. Below full access, it can
69 change only threads this link started, not that machine's own threads, projects or
70 settings.
71 </T>
72 </p>
73 </div>
74 );
75}