11import { useAtomValue } from "@effect/atom-react" ;
2+ import {
3+ deriveWorkflowGroups ,
4+ projectedSubagentsToRuntime ,
5+ } from "@t3tools/client-runtime/state/subagentRuntime" ;
26import type { ThreadTurnSubagents } from "@t3tools/client-runtime/state/thread-subagents" ;
37import {
48 isOrchestrationV2WorkActive ,
@@ -11,6 +15,7 @@ import { StackActions, useNavigation, type StaticScreenProps } from "@react-navi
1115import * as DateTime from "effect/DateTime" ;
1216import { Atom } from "effect/reactivity" ;
1317import * as Haptics from "expo-haptics" ;
18+ import { useMemo } from "react" ;
1419import { Platform , Pressable , ScrollView , View } from "react-native" ;
1520import { ScreenStack } from "react-native-screens" ;
1621import { useSafeAreaInsets } from "react-native-safe-area-context" ;
@@ -23,6 +28,8 @@ import { NativeHeader, NativeScreen } from "../../native/ThemedScreenStack";
2328import { useEnvironments } from "../../state/environments" ;
2429import { SubagentRow } from "./SubagentRow" ;
2530import { useVisibleSecondClock } from "./use-visible-second-clock" ;
31+ import { SubagentStopButton } from "./SubagentStopButton" ;
32+ import { ThreadWorkflowGroup } from "./ThreadWorkflowGroup" ;
2633import { ScreenContent } from "../../components/ui/ScreenContent" ;
2734import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout" ;
2835import { subagentThreadTarget } from "./threadAgentsPresentation" ;
@@ -54,6 +61,16 @@ export function ThreadAgentsSheet({ route }: StaticScreenProps<AgentsTarget>) {
5461 const turn = useThreadTurnSubagents ( target ) ;
5562 const subagents = turn ?. subagents ?? [ ] ;
5663 const hasLiveAgent = ( turn ?. liveCount ?? 0 ) > 0 ;
64+ const workflowGroups = useMemo (
65+ ( ) =>
66+ new Map (
67+ deriveWorkflowGroups ( projectedSubagentsToRuntime ( subagents ) ) . map ( ( group ) => [
68+ group . workflow . id ,
69+ group ,
70+ ] ) ,
71+ ) ,
72+ [ subagents ] ,
73+ ) ;
5774
5875 const openChildThread = ( child : { environmentId : EnvironmentId ; threadId : ThreadId } ) => {
5976 void Haptics . selectionAsync ( ) ;
@@ -88,15 +105,29 @@ export function ThreadAgentsSheet({ route }: StaticScreenProps<AgentsTarget>) {
88105 No agents in this turn.
89106 </ Text >
90107 ) : (
91- subagents . map ( ( subagent ) => (
92- < AgentRow
93- key = { subagent . id }
94- subagent = { subagent }
95- environmentId = { target . environmentId }
96- tickSeconds = { hasLiveAgent }
97- onOpen = { openChildThread }
98- />
99- ) )
108+ subagents . map ( ( subagent ) => {
109+ const group = workflowGroups . get ( subagent . id ) ;
110+ return group === undefined ? (
111+ < View key = { subagent . id } className = "border-b border-border" >
112+ < AgentRow
113+ subagent = { subagent }
114+ environmentId = { target . environmentId }
115+ tickSeconds = { hasLiveAgent }
116+ onOpen = { openChildThread }
117+ />
118+ </ View >
119+ ) : (
120+ < ThreadWorkflowGroup
121+ key = { subagent . id }
122+ environmentId = { target . environmentId }
123+ subagent = { subagent }
124+ group = { group }
125+ onOpen = { ( threadId ) =>
126+ openChildThread ( { environmentId : target . environmentId , threadId } )
127+ }
128+ />
129+ ) ;
130+ } )
100131 ) }
101132 </ ScrollView >
102133 ) ;
@@ -154,7 +185,7 @@ function AgentRow(props: {
154185 ) ;
155186
156187 const row = (
157- < View className = "border-b border-border py-3.5" >
188+ < View className = "py-3.5" >
158189 < SubagentRow
159190 environmentId = { props . environmentId }
160191 subagent = { subagent }
@@ -164,10 +195,11 @@ function AgentRow(props: {
164195 </ View >
165196 ) ;
166197
167- if ( target === null ) {
168- return (
198+ const content =
199+ target === null ? (
169200 < View
170201 accessible
202+ className = "min-w-0 flex-1"
171203 accessibilityHint = {
172204 subagent . remoteChild === undefined
173205 ? "Provider-managed agent. Its work appears in the transcript."
@@ -176,18 +208,22 @@ function AgentRow(props: {
176208 >
177209 { row }
178210 </ View >
211+ ) : (
212+ < Pressable
213+ accessibilityRole = "link"
214+ accessibilityHint = "Opens this agent's thread"
215+ onPress = { ( ) => props . onOpen ( target ) }
216+ className = "min-w-0 flex-1 active:opacity-70"
217+ >
218+ { row }
219+ </ Pressable >
179220 ) ;
180- }
181221
182222 return (
183- < Pressable
184- accessibilityRole = "link"
185- accessibilityHint = "Opens this agent's thread"
186- onPress = { ( ) => props . onOpen ( target ) }
187- className = "active:opacity-70"
188- >
189- { row }
190- </ Pressable >
223+ < View className = "flex-row items-center" >
224+ { content }
225+ < SubagentStopButton environmentId = { props . environmentId } subagent = { subagent } />
226+ </ View >
191227 ) ;
192228}
193229
0 commit comments