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