Open History to see the last commit
1import {
2 FULL_ACCESS_OVERRIDE_QUESTION,
3 fullAccessOverrideExplanation,
4} from "@t3tools/client-runtime/state/thread-requests";
5import { memo } from "react";
6import { type PendingApproval } from "../../session-logic";
7import { InlineButton } from "../ui/button";
8import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
9import { composerFloatingLayerProps } from "./composerEventScope";
10import { cn } from "~/lib/utils";
11
12interface ComposerPendingApprovalPanelProps {
13 approval: PendingApproval;
14 pendingCount: number;
15 className?: string;
16}
17
18export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprovalPanel({
19 approval,
20 pendingCount,
21 className,
22}: ComposerPendingApprovalPanelProps) {
23 const Detail = approval.requestKind === "mcp-elicitation" ? "span" : "code";
24 const fallbackLabel =
25 approval.requestKind === "mcp-elicitation"
26 ? "App access approval"
27 : approval.requestKind === "command"
28 ? "Command approval"
29 : approval.requestKind === "file-read"
30 ? "File read approval"
31 : approval.requestKind === "permission"
32 ? "App permission approval"
33 : "File change approval";
34 const detailAriaLabel =
35 approval.requestKind === "mcp-elicitation"
36 ? "App access request"
37 : approval.requestKind === "command"
38 ? "Command"
39 : approval.requestKind === "file-read"
40 ? "File to read"
41 : approval.requestKind === "permission"
42 ? "Permission request"
43 : "File change";
44
45 return (
46 <span
47 aria-label={fallbackLabel}
48 className={cn("flex min-w-0 flex-1 flex-col items-start gap-1", className)}
49 role="group"
50 >
51 <span className="flex w-full min-w-0 items-center gap-2 text-2xs text-muted-foreground">
52 <span className="shrink-0 font-medium text-warning">{fallbackLabel}</span>
53 {approval.appName ? <span className="min-w-0 truncate">{approval.appName}</span> : null}
54 {approval.fullAccessOverride ? (
55 <Popover>
56 <PopoverTrigger openOnHover render={<InlineButton tone="muted" />}>
57 {FULL_ACCESS_OVERRIDE_QUESTION}
58 </PopoverTrigger>
59 <PopoverPopup
60 {...composerFloatingLayerProps}
61 aria-label={FULL_ACCESS_OVERRIDE_QUESTION}
62 tooltipStyle
63 side="top"
64 className="max-w-[min(22rem,calc(100vw-2rem))] whitespace-normal"
65 >
66 {fullAccessOverrideExplanation(approval.fullAccessOverride)}
67 </PopoverPopup>
68 </Popover>
69 ) : null}
70 {pendingCount > 1 ? (
71 <span className="ml-auto shrink-0 tabular-nums">1/{pendingCount}</span>
72 ) : null}
73 </span>
74 <Detail
75 aria-label={detailAriaLabel}
76 className={cn(
77 "block w-full min-w-0 overflow-auto text-xs text-foreground [scrollbar-width:thin] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70 [&::-webkit-scrollbar]:h-1.5",
78 approval.requestKind === "mcp-elicitation"
79 ? "max-h-20 whitespace-pre-wrap font-sans wrap-break-word"
80 : "max-h-40 whitespace-pre-wrap font-mono wrap-anywhere",
81 )}
82 data-approval-detail="complete"
83 tabIndex={0}
84 >
85 {approval.responseCapability === "not_resumable"
86 ? "Provider process is gone. Interrupt or restart the run to respond."
87 : approval.detail || fallbackLabel}
88 </Detail>
89 {approval.reason ? (
90 <span className="w-full min-w-0 text-2xs text-muted-foreground wrap-break-word">
91 {approval.reason}
92 </span>
93 ) : null}
94 </span>
95 );
96});