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