The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 132 lines 4.88 KB
Raw
1 import {
2 FULL_ACCESS_OVERRIDE_QUESTION,
3 fullAccessOverrideExplanation,
4 } from "@t3tools/client-runtime/state/thread-requests";
5 import { msg, T, useMessages } from "gt-react";
6 import { ShieldIcon } from "lucide-react";
7 import { memo, use } from "react";
8 import { type PendingApproval } from "../../session-logic";
9 import { InlineButton } from "../ui/button";
10 import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
11 import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions";
12 import { ToolActivityIconView, type WorkEntryIconName } from "./TimelineToolActivityIcon";
13 import { TimelineRowCtx } from "./timelineRowContext";
14 import { WorkLogRow } from "./WorkLog";
15
16 const APPROVAL_PRESENTATION = {
17 command: {
18 icon: "terminal",
19 label: msg("Command approval"),
20 detailLabel: msg("Command", { $context: "noun, shell command awaiting approval" }),
21 },
22 "file-change": {
23 icon: "square-pen",
24 label: msg("File change approval"),
25 detailLabel: msg("File change"),
26 },
27 "file-read": { icon: "eye", label: msg("File read approval"), detailLabel: msg("File to read") },
28 permission: {
29 icon: "wrench",
30 label: msg("App permission approval"),
31 detailLabel: msg("Permission request"),
32 },
33 "mcp-elicitation": {
34 icon: "hammer",
35 label: msg("App access approval"),
36 detailLabel: msg("App access request"),
37 },
38 } satisfies Record<
39 PendingApproval["requestKind"],
40 { icon: WorkEntryIconName; label: string; detailLabel: string }
41 >;
42
43 export const TimelinePendingApprovalRow = memo(function TimelinePendingApprovalRow({
44 approval,
45 }: {
46 approval: PendingApproval;
47 }) {
48 const { respondingRequestIds, canOperateThread, onRespondToApproval } = use(TimelineRowCtx);
49 const m = useMessages();
50 const presentation = APPROVAL_PRESENTATION[approval.requestKind];
51 const canRespond = approval.responseCapability === "live";
52 return (
53 <WorkLogRow
54 role="group"
55 aria-label={m(presentation.label)}
56 data-v2-item-type="approval_request"
57 wrapLabel
58 icon={
59 <ToolActivityIconView
60 icon={undefined}
61 fallbackName={presentation.icon}
62 className="block size-4 shrink-0 stroke-2 text-icon-muted"
63 muted
64 />
65 }
66 label={
67 <code
68 aria-label={m(presentation.detailLabel)}
69 className="block max-h-40 min-w-0 overflow-auto whitespace-pre-wrap font-mono text-xs leading-5 text-foreground select-text! wrap-anywhere [scrollbar-width:thin] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
70 data-approval-detail="complete"
71 tabIndex={0}
72 >
73 {approval.detail || m(presentation.label)}
74 </code>
75 }
76 >
77 <div className="ms-7.5 flex min-w-0 flex-col gap-1 pb-1 text-xs">
78 {approval.appName ? (
79 <span className="text-muted-foreground wrap-anywhere">{approval.appName}</span>
80 ) : null}
81 {approval.reason ? (
82 <span className="text-muted-foreground select-text wrap-anywhere">{approval.reason}</span>
83 ) : null}
84 <div className="flex flex-wrap items-center gap-x-2 gap-y-1">
85 {canRespond ? (
86 <>
87 <span className="inline-flex items-center gap-1 text-warning">
88 <ShieldIcon aria-hidden className="size-3 shrink-0" />
89 <T>Waiting for approval</T>
90 </span>
91 {onRespondToApproval ? (
92 <>
93 <span aria-hidden className="text-muted-foreground">
94 ·
95 </span>
96 <ComposerPendingApprovalActions
97 presentation="inline"
98 requestId={approval.requestId}
99 disabled={!canOperateThread}
100 isResponding={respondingRequestIds.includes(approval.requestId)}
101 canRespond={canRespond}
102 options={approval.options}
103 onRespondToApproval={onRespondToApproval}
104 />
105 </>
106 ) : null}
107 </>
108 ) : (
109 <span className="text-warning">
110 <T>Provider process is gone. Interrupt or restart the run to respond.</T>
111 </span>
112 )}
113 {approval.fullAccessOverride ? (
114 <Popover>
115 <PopoverTrigger openOnHover render={<InlineButton tone="muted" />}>
116 {m(FULL_ACCESS_OVERRIDE_QUESTION)}
117 </PopoverTrigger>
118 <PopoverPopup
119 aria-label={m(FULL_ACCESS_OVERRIDE_QUESTION)}
120 tooltipStyle
121 side="top"
122 className="max-w-[min(22rem,calc(100vw-2rem))] whitespace-normal"
123 >
124 {fullAccessOverrideExplanation(approval.fullAccessOverride, m)}
125 </PopoverPopup>
126 </Popover>
127 ) : null}
128 </div>
129 </div>
130 </WorkLogRow>
131 );
132 });