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

ProviderSubagentBar.tsx

80 lines3.1 KB

1import {
2 formatProviderSubagentStatus,
3 type ProviderSubagentStatus,
4} from "@t3tools/client-runtime/state/thread-execution";
5import { isOrchestrationV2WorkActive } from "@t3tools/contracts";
6import { useEffect, useState } from "react";
7import { View } from "react-native";
8​
9import { AppText as Text } from "../../components/AppText";
10import { ProviderIcon } from "../../components/ProviderIcon";
11import { RequestActionButton } from "./RequestActionButton";
12​
13/**
14 * Replaces the composer on a provider-native subagent thread. The provider
15 * runs that conversation, so there is nothing to send; the bar says which
16 * model is working, for how long, and leads back to the parent.
17 */
18export function ProviderSubagentBar(props: {
19 /** Driver and catalog icon of the provider running the subagent. */
20 readonly provider: { readonly driver: string; readonly iconUrl?: string | undefined } | null;
21 readonly modelLabel: string;
22 /** Reasoning effort as the composer names it, when the subagent has one. */
23 readonly effortLabel: string | null;
24 /** Null until the subagent's root turn arrives. */
25 readonly status: ProviderSubagentStatus | null;
26 readonly onOpenParent: (() => void) | null;
27}) {
28 const live = props.status !== null && isOrchestrationV2WorkActive(props.status.status);
29 const [nowMs, setNowMs] = useState(() => Date.now());
30 useEffect(() => {
31 if (!live) return;
32 const id = setInterval(() => setNowMs(Date.now()), 1_000);
33 return () => clearInterval(id);
34 }, [live]);
35 const statusLabel = formatProviderSubagentStatus(props.status, nowMs);
36 const modelDescription =
37 props.effortLabel === null ? props.modelLabel : `${props.modelLabel}, ${props.effortLabel}`;
38​
39 return (
40 <View className="flex-row items-center gap-3 rounded-[20px] border border-border-subtle bg-card-alt py-2 pe-2 ps-4">
41 {/* Only the text is one element, so "Open parent" stays reachable. */}
42 <View
43 accessible
44 accessibilityLabel={`${modelDescription} subagent, ${statusLabel}. It runs on its own and cannot take messages.`}
45 className="min-w-0 flex-1 gap-0.5"
46 >
47 <View className="min-w-0 flex-row items-center gap-1.5">
48 {props.provider ? (
49 <ProviderIcon
50 iconUrl={props.provider.iconUrl}
51 provider={props.provider.driver}
52 size={16}
53 />
54 ) : null}
55 <Text numberOfLines={1} className="min-w-0 shrink font-t3-bold text-sm text-foreground">
56 {props.modelLabel}
57 </Text>
58 {props.effortLabel === null ? null : (
59 <Text
60 numberOfLines={1}
61 className="shrink-0 font-sans text-sm text-foreground-secondary"
62 >
63 {props.effortLabel}
64 </Text>
65 )}
66 </View>
67 <Text
68 numberOfLines={1}
69 className="font-sans text-xs text-foreground-secondary"
70 style={{ fontVariant: ["tabular-nums"] }}
71 >
72 {statusLabel} · Runs on its own
73 </Text>
74 </View>
75 {props.onOpenParent ? (
76 <RequestActionButton label="Open parent" tone="secondary" onPress={props.onOpenParent} />
77 ) : null}
78 </View>
79 );