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

TimelinePendingApprovalRow.tsx

122 lines4.6 KB

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