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