Open History to see the last commit
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 | "remoteChild"
30>;
31
32export function SubagentRow(props: {
33 readonly environmentId: EnvironmentId;
34 readonly subagent: SubagentRowSubagent;
35 readonly elapsed: ReactNode;
36 /** The task runs in a linked environment this app is connected to. */
37 readonly canOpenRemote?: boolean;
38}) {
39 const presentation = resolveSubagentRowPresentation(props.subagent, props.canOpenRemote);
40 const detail = subagentCardDetail(presentation.detail);
41 return (
42 <View className="flex-row gap-3">
43 <View className="h-5 justify-center">
44 <SubagentStatusDot tone={presentation.tone} placement="sheet" />
45 </View>
46 <View className="min-w-0 flex-1 gap-1">
47 <View className="min-h-5 flex-row items-center gap-2">
48 <View className="min-w-0 flex-1 flex-row items-baseline gap-1.5">
49 <Text
50 numberOfLines={1}
51 className="min-w-0 shrink font-t3-medium text-sm text-foreground"
52 >
53 {presentation.title}
54 </Text>
55 <Text
56 accessibilityElementsHidden
57 importantForAccessibility="no"
58 className="shrink-0 text-xs text-foreground-muted"
59 >
60 ·
61 </Text>
62 <Text
63 className={cn(
64 "shrink-0 text-xs font-t3-medium",
65 SUBAGENT_TONE_TEXT_CLASS[presentation.tone],
66 )}
67 >
68 {presentation.statusLabel}
69 </Text>
70 {presentation.runsOn !== null ? (
71 <Text numberOfLines={1} className="shrink text-xs text-foreground-muted">
72 on {presentation.runsOn}
73 </Text>
74 ) : null}
75 </View>
76 {props.elapsed}
77 {presentation.canOpenThread ? (
78 <SymbolView name="chevron.right" size={12} tintColorClassName="accent-icon-subtle" />
79 ) : null}
80 </View>
81 <SubagentMetadata environmentId={props.environmentId} subagent={props.subagent} />
82 {detail ? (
83 <Text
84 numberOfLines={3}
85 className={cn(
86 "text-xs text-foreground-muted",
87 presentation.tone === "failed" && SUBAGENT_TONE_TEXT_CLASS.failed,
88 )}
89 >
90 {detail}
91 </Text>
92 ) : null}
93 </View>
94 </View>
95 );
96}
97
98function SubagentMetadata(props: {
99 readonly environmentId: EnvironmentId;
100 readonly subagent: SubagentRowSubagent;
101}) {
102 const { environmentId, subagent } = props;
103 // A task in a linked environment runs a provider instance of that environment.
104 const config = useEnvironmentServerConfig(subagent.remoteChild?.environmentId ?? environmentId);
105 const provider = config?.providers.find(
106 (candidate) => candidate.instanceId === subagent.providerInstanceId,
107 );
108 const parent = useThreadShell(scopeThreadRef(environmentId, subagent.threadId))?.source;
109 const child = useThreadShell(
110 subagent.childThreadId === null ? null : scopeThreadRef(environmentId, subagent.childThreadId),
111 )?.source;
112 const parentProject = useProject(
113 parent ? scopeProjectRef(environmentId, parent.projectId) : null,
114 );
115 const childProject = useProject(child ? scopeProjectRef(environmentId, child.projectId) : null);
116 const { modelLabel, workspace } = resolveSubagentMetadata({
117 model: subagent.model,
118 provider,
119 parentThread: parent,
120 childThread: child,
121 parentProject,
122 childProject,
123 });
124 return (
125 <View className="min-w-0 flex-row items-center gap-1.5">
126 <ProviderIcon
127 provider={provider?.driver ?? subagent.driver}
128 iconUrl={provider?.iconUrl}
129 size={12}
130 />
131 <Text className="min-w-0 shrink text-xs text-foreground-muted" numberOfLines={1}>
132 {provider ? `${resolveProviderInstanceDisplayName(provider)} · ` : ""}
133 {modelLabel}
134 </Text>
135 {workspace.map(({ label, value }) => (
136 // Preserve the label against flattening without making it a separate accessibility stop.
137 <View
138 key={label}
139 collapsable={false}
140 accessibilityLabel={`${label}: ${value}`}
141 className="min-w-0 shrink flex-row items-center gap-1.5"
142 >
143 <Text className="text-xs text-foreground-muted">·</Text>
144 <SymbolView
145 name={label === "Branch" ? "arrow.triangle.branch" : "folder"}
146 size={11}
147 tintColorClassName="accent-icon-muted"
148 />
149 <Text className="min-w-0 shrink text-xs text-foreground-muted" numberOfLines={1}>
150 {value}
151 </Text>
152 </View>
153 ))}
154 </View>
155 );
156}