Open History to see the last commit
1import { RequestActionButton } from "./RequestActionButton";
2import type {
3 ProviderApprovalDecision,
4 ProviderApprovalOption,
5 RuntimeRequestId,
6} from "@t3tools/contracts";
7import { View } from "react-native";
8
9import { AppText as Text } from "../../components/AppText";
10import type { PendingApproval } from "../../lib/threadActivity";
11
12export interface PendingApprovalCardProps {
13 readonly approval: PendingApproval;
14 readonly respondingApprovalId: RuntimeRequestId | null;
15 readonly onRespond: (
16 requestId: RuntimeRequestId,
17 decision: ProviderApprovalDecision,
18 ) => Promise<unknown>;
19}
20
21const DEFAULT_APPROVAL_OPTIONS: ReadonlyArray<ProviderApprovalOption> = [
22 { decision: "accept", label: "Allow once" },
23 { decision: "acceptForSession", label: "Allow session" },
24 { decision: "decline", label: "Decline" },
25];
26
27export function PendingApprovalCard(props: PendingApprovalCardProps) {
28 const options: ReadonlyArray<ProviderApprovalOption> =
29 props.approval.options ?? DEFAULT_APPROVAL_OPTIONS;
30 const warning = options.find((option) => option.warning)?.warning;
31 // Opaque for the same reason as PendingUserInputCard: nothing blurs the feed
32 // behind this card, so a translucent surface bleeds messages through it.
33 const canRespond = props.approval.responseCapability === "live";
34 const disabled = !canRespond || props.respondingApprovalId === props.approval.requestId;
35 return (
36 <View className="gap-2.5 rounded-[20px] border border-border bg-card-alt p-4">
37 <Text className="font-t3-bold text-2xs uppercase tracking-[1.1px] text-foreground-secondary">
38 Approval needed
39 </Text>
40 <Text className="font-t3-bold text-lg text-foreground">
41 {props.approval.appName ?? props.approval.requestKind}
42 </Text>
43 {props.approval.detail ? (
44 <Text className="font-sans text-sm leading-normal text-foreground-secondary">
45 {props.approval.detail}
46 </Text>
47 ) : null}
48 {!canRespond ? (
49 <Text className="font-sans text-sm leading-5 text-adaptive-neutral-600-400">
50 The provider process for this request is no longer available. Interrupt or restart the run
51 to continue.
52 </Text>
53 ) : null}
54 {warning ? (
55 <Text className="font-sans text-xs leading-normal text-warning-foreground">{warning}</Text>
56 ) : null}
57 <View className="flex-row flex-wrap gap-2.5">
58 {options.map((option) => (
59 <RequestActionButton
60 key={option.decision}
61 label={option.label}
62 tone={
63 option.decision === "accept"
64 ? "primary"
65 : option.decision === "decline"
66 ? "danger"
67 : "secondary"
68 }
69 disabled={disabled}
70 onPress={() => void props.onRespond(props.approval.requestId, option.decision)}
71 />
72 ))}
73 </View>
74 </View>
75 );
76}