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

SubagentRow.tsx

149 lines5.3 KB

1import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
2import { resolveProviderInstanceDisplayName } from "@t3tools/client-runtime/state/provider-instance-display";
3import { resolveSubagentMetadata } from "@t3tools/client-runtime/state/subagent-display";
4import type { EnvironmentId, OrchestrationV2Subagent } from "@t3tools/contracts";
5import type { ReactNode } from "react";
6import { View } from "react-native";
7​
8import { AppText as Text } from "../../components/ui/AppText";
9import { SymbolView } from "../../components/ui/AppSymbol";
10import { ProviderIcon } from "../../components/ProviderIcon";
11import { cn } from "../../lib/cn";
12import { useEnvironmentServerConfig, useProject, useThreadShell } from "../../state/entities";
13import { subagentCardDetail } from "./subagent-card-presentation";
14import { SUBAGENT_TONE_TEXT_CLASS, SubagentStatusDot } from "./SubagentStatusDot";
15import { resolveSubagentRowPresentation } from "./threadAgentsPresentation";
16​
17type SubagentRowSubagent = Pick<
18 OrchestrationV2Subagent,
19 | "threadId"
20 | "childThreadId"
21 | "model"
22 | "driver"
23 | "providerInstanceId"
24 | "title"
25 | "prompt"
26 | "status"
27 | "progress"
28 | "result"
29>;
30​
31export function SubagentRow(props: {
32 readonly environmentId: EnvironmentId;
33 readonly subagent: SubagentRowSubagent;
34 readonly elapsed: ReactNode;
35}) {
36 const presentation = resolveSubagentRowPresentation(props.subagent);
37 const detail = subagentCardDetail(presentation.detail);
38 return (
39 <View className="flex-row gap-3">
40 <View className="h-5 justify-center">
41 <SubagentStatusDot tone={presentation.tone} placement="sheet" />
42 </View>
43 <View className="min-w-0 flex-1 gap-1">
44 <View className="min-h-5 flex-row items-center gap-2">
45 <View className="min-w-0 flex-1 flex-row items-baseline gap-1.5">
46 <Text
47 numberOfLines={1}
48 className="min-w-0 shrink font-t3-medium text-sm text-foreground"
49 >
50 {presentation.title}
51 </Text>
52 <Text
53 accessibilityElementsHidden
54 importantForAccessibility="no"
55 className="shrink-0 text-xs text-foreground-muted"
56 >
57 ·
58 </Text>
59 <Text
60 className={cn(
61 "shrink-0 text-xs font-t3-medium",
62 SUBAGENT_TONE_TEXT_CLASS[presentation.tone],
63 )}
64 >
65 {presentation.statusLabel}
66 </Text>
67 </View>
68 {props.elapsed}
69 {presentation.canOpenThread ? (
70 <SymbolView name="chevron.right" size={12} tintColorClassName="accent-icon-subtle" />
71 ) : null}
72 </View>
73 <SubagentMetadata environmentId={props.environmentId} subagent={props.subagent} />
74 {detail ? (
75 <Text
76 numberOfLines={3}
77 className={cn(
78 "text-xs text-foreground-muted",
79 presentation.tone === "failed" && SUBAGENT_TONE_TEXT_CLASS.failed,
80 )}
81 >
82 {detail}
83 </Text>
84 ) : null}
85 </View>
86 </View>
87 );
89​
90function SubagentMetadata(props: {
91 readonly environmentId: EnvironmentId;
92 readonly subagent: SubagentRowSubagent;
93}) {
94 const { environmentId, subagent } = props;
95 const config = useEnvironmentServerConfig(environmentId);
96 const provider = config?.providers.find(
97 (candidate) => candidate.instanceId === subagent.providerInstanceId,
98 );
99 const parent = useThreadShell(scopeThreadRef(environmentId, subagent.threadId))?.source;
100 const child = useThreadShell(
101 subagent.childThreadId === null ? null : scopeThreadRef(environmentId, subagent.childThreadId),
102 )?.source;
103 const parentProject = useProject(
104 parent ? scopeProjectRef(environmentId, parent.projectId) : null,
105 );
106 const childProject = useProject(child ? scopeProjectRef(environmentId, child.projectId) : null);
107 const { modelLabel, workspace } = resolveSubagentMetadata({
108 model: subagent.model,
109 provider,
110 parentThread: parent,
111 childThread: child,
112 parentProject,
113 childProject,
114 });
115 return (
116 <View className="min-w-0 flex-row items-center gap-1.5">
117 <ProviderIcon
118 provider={provider?.driver ?? subagent.driver}
119 iconUrl={provider?.iconUrl}
120 size={12}
121 />
122 <Text className="min-w-0 shrink text-xs text-foreground-muted" numberOfLines={1}>
123 {provider ? `${resolveProviderInstanceDisplayName(provider)} · ` : ""}
124 {modelLabel}
125 </Text>
126 {workspace.map(({ label, value }) => (
127 // The row reads this label in place of the icon. collapsable keeps the
128 // view (and label) from being flattened away without making it a
129 // separate accessibility stop.
130 <View
131 key={label}
132 collapsable={false}
133 accessibilityLabel={`${label}: ${value}`}
134 className="min-w-0 shrink flex-row items-center gap-1.5"
135 >
136 <Text className="text-xs text-foreground-muted">·</Text>
137 <SymbolView
138 name={label === "Branch" ? "arrow.triangle.branch" : "folder"}
139 size={11}
140 tintColorClassName="accent-icon-muted"
141 />
142 <Text className="min-w-0 shrink text-xs text-foreground-muted" numberOfLines={1}>
143 {value}
144 </Text>
145 </View>
146 ))}
147 </View>
148 );