Skip to content

Commit 0e1e1b2

Browse files
committed
fix(web): simplify agent approval prompts
1 parent ccf220b commit 0e1e1b2

5 files changed

Lines changed: 89 additions & 87 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,7 @@ import {
930930
PaperclipIcon,
931931
PencilRulerIcon,
932932
PlayIcon,
933+
ShieldIcon,
933934
XIcon,
934935
} from "lucide-react";
935936
import { proposedPlanTitle } from "../../proposedPlan";
@@ -6003,20 +6004,27 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
60036004
<ComposerBanner.Root
60046005
data-chat-composer-top-drawer="true"
60056006
variant={activePendingApproval ? "warning" : "info"}
6007+
className={
6008+
activePendingApproval
6009+
? "px-3 [--composer-banner-padding-block:--spacing(3)]"
6010+
: undefined
6011+
}
60066012
>
60076013
{activePendingApproval ? (
60086014
<ComposerBanner.Row
6009-
layout="wrap-actions"
6015+
className="items-start gap-x-2 gap-y-3"
60106016
data-chat-composer-collapsed-controls="true"
60116017
>
6012-
<ComposerBanner.Icon />
6013-
<ComposerBanner.Content>
6018+
<ComposerBanner.Icon className="pt-0.5 text-warning [&>svg]:size-4">
6019+
<ShieldIcon />
6020+
</ComposerBanner.Icon>
6021+
<ComposerBanner.Content className="@max-[560px]:col-end-4">
60146022
<ComposerPendingApprovalPanel
60156023
approval={activePendingApproval}
60166024
pendingCount={pendingApprovals.length}
60176025
/>
60186026
</ComposerBanner.Content>
6019-
<ComposerBanner.Actions>
6027+
<ComposerBanner.Actions className="gap-1.5 @max-[560px]:col-start-2 @max-[560px]:col-end-4 @max-[560px]:row-start-2 @max-[560px]:justify-start">
60206028
<ComposerPendingApprovalActions
60216029
requestId={activePendingApproval.requestId}
60226030
isResponding={respondingRequestIds.includes(
@@ -6673,6 +6681,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
66736681
showMobilePendingAnswerActions && "max-sm:pb-11",
66746682
isComposerResting &&
66756683
"max-h-8 min-h-8 overflow-hidden whitespace-pre! leading-8",
6684+
isComposerApprovalState && "min-h-8",
66766685
)}
66776686
placeholderClassName={cn(
66786687
isComposerResting &&
@@ -6688,8 +6697,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
66886697
onPaste={onComposerPaste}
66896698
placeholder={
66906699
isComposerApprovalState
6691-
? (activePendingApproval?.detail ??
6692-
"Resolve this approval request to continue")
6700+
? "Resolve this approval request to continue"
66936701
: activePendingProgress
66946702
? isChoiceOnlyPendingQuestion
66956703
? "Choose an option above"

‎apps/web/src/components/chat/ComposerPendingApprovalActions.test.tsx‎

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { describe, expect, it } from "vite-plus/test";
55
import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions";
66

77
describe("ComposerPendingApprovalActions", () => {
8-
it("states that the persistent approval lasts for this session", () => {
8+
it("keeps the main decisions visible and secondary decisions in the menu", () => {
99
const markup = renderToStaticMarkup(
1010
<ComposerPendingApprovalActions
1111
requestId={ApprovalRequestId.make("approval-1")}
@@ -14,12 +14,10 @@ describe("ComposerPendingApprovalActions", () => {
1414
/>,
1515
);
1616

17-
expect(markup).toContain(">Cancel<");
18-
expect(markup).toContain("Always allow this session");
19-
expect(markup).not.toContain(">Always allow<");
20-
expect(markup).toContain("h-5");
21-
expect(markup).toContain("sm:text-[11px]");
22-
expect(markup).not.toContain("sm:h-6");
17+
expect(markup).toContain(">Decline<");
18+
expect(markup).toContain(">Approve<");
19+
expect(markup).not.toContain(">Cancel<");
20+
expect(markup).not.toContain("Always allow this session");
2321
});
2422

2523
it("shows only the approval choices advertised by an MCP server", () => {
@@ -36,48 +34,27 @@ describe("ComposerPendingApprovalActions", () => {
3634
/>,
3735
);
3836

39-
expect(markup).toContain("Always allow Safari");
37+
expect(markup).not.toContain("Always allow Safari");
4038
expect(markup).toContain(">Approve<");
4139
expect(markup).not.toContain("Always allow this session");
4240
});
4341

44-
it("marks an option that carries a provider warning", () => {
42+
it("preserves provider labels for the main decisions", () => {
4543
const markup = renderToStaticMarkup(
4644
<ComposerPendingApprovalActions
4745
requestId={ApprovalRequestId.make("approval-1")}
4846
isResponding={false}
4947
options={[
5048
{ decision: "accept", label: "Allow once" },
51-
{
52-
decision: "acceptForSession",
53-
label: "Allow for this thread",
54-
warning: "Untrusted files could re-run this action without asking.",
55-
},
5649
{ decision: "decline", label: "Deny" },
5750
]}
5851
onRespondToApproval={async () => undefined}
5952
/>,
6053
);
6154

62-
expect(markup).toContain(
63-
'aria-description="Untrusted files could re-run this action without asking."',
64-
);
65-
expect(markup).toContain("text-warning");
66-
expect(markup).toContain("Allow for this thread");
67-
});
68-
69-
it("limits provider-supplied approval labels so narrow rows can wrap", () => {
70-
const label = "Allow ".repeat(40).trim();
71-
const markup = renderToStaticMarkup(
72-
<ComposerPendingApprovalActions
73-
requestId={ApprovalRequestId.make("approval-long-label")}
74-
isResponding={false}
75-
options={[{ decision: "acceptAlways", label }]}
76-
onRespondToApproval={async () => undefined}
77-
/>,
78-
);
79-
80-
expect(markup).toContain('class="max-w-40 truncate"');
81-
expect(markup).toContain(label);
55+
expect(markup).toContain("Allow once");
56+
expect(markup).toContain("Deny");
57+
expect(markup).not.toContain(">Approve<");
58+
expect(markup).not.toContain(">Decline<");
8259
});
8360
});

‎apps/web/src/components/chat/ComposerPendingApprovalActions.tsx‎

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import {
44
type ProviderApprovalOption,
55
} from "@t3tools/contracts";
66
import { memo } from "react";
7-
import { TriangleAlertIcon } from "lucide-react";
7+
import { ChevronDownIcon, TriangleAlertIcon } from "lucide-react";
88
import { Button } from "../ui/button";
9+
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
910
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
11+
import { composerFloatingLayerProps } from "./composerEventScope";
1012

1113
interface ComposerPendingApprovalActionsProps {
1214
requestId: ApprovalRequestId;
@@ -18,7 +20,6 @@ interface ComposerPendingApprovalActionsProps {
1820
) => Promise<unknown>;
1921
}
2022

21-
const APPROVAL_ACTION_CLASS_NAME = "font-normal";
2223
const DEFAULT_APPROVAL_OPTIONS = [
2324
{ decision: "cancel", label: "Cancel" },
2425
{ decision: "decline", label: "Decline" },
@@ -32,23 +33,21 @@ export const ComposerPendingApprovalActions = memo(function ComposerPendingAppro
3233
options = DEFAULT_APPROVAL_OPTIONS,
3334
onRespondToApproval,
3435
}: ComposerPendingApprovalActionsProps) {
36+
const primaryOptions = options.filter(
37+
(option) => option.decision === "decline" || option.decision === "accept",
38+
);
39+
const moreOptions = options.filter(
40+
(option) => option.decision !== "decline" && option.decision !== "accept",
41+
);
42+
3543
return (
3644
<>
37-
{options.map((option) => {
45+
{primaryOptions.map((option) => {
3846
const button = (
3947
<Button
4048
key={option.decision}
41-
size="micro"
42-
variant="ghost-muted"
43-
className={`${APPROVAL_ACTION_CLASS_NAME}${
44-
option.decision === "decline"
45-
? " text-destructive-foreground [:hover,[data-pressed]]:text-destructive-foreground"
46-
: option.decision === "accept"
47-
? " text-foreground"
48-
: option.warning
49-
? " text-warning"
50-
: ""
51-
}`}
49+
size="xs"
50+
variant={option.decision === "accept" ? "default" : "outline"}
5251
disabled={isResponding}
5352
aria-description={option.warning}
5453
onClick={() => void onRespondToApproval(requestId, option.decision)}
@@ -57,8 +56,6 @@ export const ComposerPendingApprovalActions = memo(function ComposerPendingAppro
5756
<span className="max-w-40 truncate">{option.label}</span>
5857
</Button>
5958
);
60-
// A provider caution, such as a prompt injection warning on "allow
61-
// always", rides along as a tooltip so the row stays one line.
6259
return option.warning ? (
6360
<Tooltip key={option.decision}>
6461
<TooltipTrigger render={button} />
@@ -70,6 +67,39 @@ export const ComposerPendingApprovalActions = memo(function ComposerPendingAppro
7067
button
7168
);
7269
})}
70+
{moreOptions.length > 0 ? (
71+
<Menu>
72+
<MenuTrigger
73+
disabled={isResponding}
74+
render={<Button size="icon-xs" variant="outline" aria-label="More approval options" />}
75+
>
76+
<ChevronDownIcon />
77+
</MenuTrigger>
78+
<MenuPopup
79+
{...composerFloatingLayerProps}
80+
side="top"
81+
align="end"
82+
className="max-w-[min(22rem,calc(100vw-2rem))]"
83+
>
84+
{moreOptions.map((option) => (
85+
<MenuItem
86+
key={option.decision}
87+
disabled={isResponding}
88+
onClick={() => void onRespondToApproval(requestId, option.decision)}
89+
className="items-start"
90+
>
91+
{option.warning ? <TriangleAlertIcon className="mt-0.5 text-warning" /> : null}
92+
<span className="min-w-0 whitespace-normal wrap-break-word">
93+
{option.label}
94+
{option.warning ? (
95+
<span className="mt-1 block text-xs text-warning">{option.warning}</span>
96+
) : null}
97+
</span>
98+
</MenuItem>
99+
))}
100+
</MenuPopup>
101+
</Menu>
102+
) : null}
73103
</>
74104
);
75105
});

‎apps/web/src/components/chat/ComposerPendingApprovalPanel.test.tsx‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,7 @@ describe("ComposerPendingApprovalPanel", () => {
1919
/>,
2020
);
2121

22-
expect(markup).toContain('data-approval-detail="complete"');
23-
expect(markup).toContain('aria-label="Command"');
24-
expect(markup).toContain('role="group"');
25-
expect(markup).toContain('tabindex="0"');
2622
expect(markup).toContain(detail);
27-
expect(markup).toContain("max-h-20");
28-
expect(markup).toContain("overflow-auto");
29-
expect(markup).toContain("whitespace-pre");
30-
expect(markup).toContain("[scrollbar-width:thin]");
31-
expect(markup).toContain("[&amp;::-webkit-scrollbar]:h-1.5");
32-
expect(markup).not.toContain("truncate");
33-
expect(markup).not.toContain("line-clamp");
34-
expect(markup).toContain("min-w-0");
3523
expect(markup).not.toContain("Command approval requested");
3624
});
3725

@@ -65,13 +53,11 @@ describe("ComposerPendingApprovalPanel", () => {
6553
/>,
6654
);
6755

68-
expect(markup).toContain('aria-label="App access approval"');
69-
expect(markup).toContain('aria-label="App access request"');
7056
expect(markup).toContain(">Safari<");
7157
expect(markup).toContain("Allow ChatGPT to use Safari?");
7258
});
7359

74-
it("limits long app names so the complete approval message stays readable", () => {
60+
it("preserves the full app name and approval message", () => {
7561
const appName = "A".repeat(200);
7662
const detail = "Allow ChatGPT to access the selected application?";
7763
const markup = renderToStaticMarkup(
@@ -87,9 +73,7 @@ describe("ComposerPendingApprovalPanel", () => {
8773
/>,
8874
);
8975

90-
expect(markup).toContain("max-w-32 shrink truncate");
9176
expect(markup).toContain(appName);
92-
expect(markup).toContain('data-approval-detail="complete"');
9377
expect(markup).toContain(detail);
9478
});
9579
});

‎apps/web/src/components/chat/ComposerPendingApprovalPanel.tsx‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprova
1313
pendingCount,
1414
className,
1515
}: ComposerPendingApprovalPanelProps) {
16+
const Detail = approval.requestKind === "mcp-elicitation" ? "span" : "code";
1617
const fallbackLabel =
1718
approval.requestKind === "mcp-elicitation"
1819
? "App access approval"
@@ -33,27 +34,29 @@ export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprova
3334
return (
3435
<span
3536
aria-label={fallbackLabel}
36-
className={cn("flex min-w-0 flex-1 items-center gap-2", className)}
37+
className={cn("flex min-w-0 flex-1 flex-col items-start gap-1", className)}
3738
role="group"
3839
>
39-
{approval.appName ? (
40-
<span className="max-w-32 shrink truncate text-[11px] font-medium text-foreground">
41-
{approval.appName}
42-
</span>
43-
) : null}
44-
<code
40+
<span className="flex w-full min-w-0 items-center gap-2 text-[11px] text-muted-foreground">
41+
<span className="shrink-0 font-medium text-warning">{fallbackLabel}</span>
42+
{approval.appName ? <span className="min-w-0 truncate">{approval.appName}</span> : null}
43+
{pendingCount > 1 ? (
44+
<span className="ml-auto shrink-0 tabular-nums">1/{pendingCount}</span>
45+
) : null}
46+
</span>
47+
<Detail
4548
aria-label={detailAriaLabel}
46-
className="block max-h-20 min-w-0 flex-1 overflow-auto whitespace-pre font-mono text-[11px] text-foreground/85 [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"
49+
className={cn(
50+
"block max-h-20 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",
51+
approval.requestKind === "mcp-elicitation"
52+
? "whitespace-pre-wrap font-sans wrap-break-word"
53+
: "whitespace-pre font-mono",
54+
)}
4755
data-approval-detail="complete"
4856
tabIndex={0}
4957
>
5058
{approval.detail || fallbackLabel}
51-
</code>
52-
{pendingCount > 1 ? (
53-
<span className="shrink-0 text-[10px] font-medium text-muted-foreground tabular-nums">
54-
1/{pendingCount}
55-
</span>
56-
) : null}
59+
</Detail>
5760
</span>
5861
);
5962
});

0 commit comments

Comments
 (0)