@@ -15,13 +15,16 @@ import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subage
1515import { deriveProviderSubagentStatus } from "@t3tools/client-runtime/state/thread-execution" ;
1616import {
1717 deriveThreadRelationshipGraph ,
18+ groupWebThreadLineageRows ,
1819 immediateThreadRelationships ,
1920 isParentThreadRelationship ,
2021 threadRelationshipRowStatus ,
2122 orderWebThreadLineageRows ,
2223 resolveMergeBackTargetThreadId ,
24+ webThreadLineageRowStatus ,
25+ type RemoteSubagent ,
2326 type ThreadRelationshipEdge ,
24- type ThreadRelationshipWalkRow ,
27+ type WebThreadLineageRow ,
2528} from "@t3tools/client-runtime/state/thread-relationships" ;
2629import {
2730 canDetachThreadProviderSession ,
@@ -33,14 +36,12 @@ import {
3336 NodeId ,
3437 type EnvironmentId ,
3538 type OrchestrationV2DelegatedFrom ,
36- type OrchestrationV2RemoteTaskChild ,
3739 type OrchestrationV2Subagent ,
3840 type OrchestrationV2ThreadShell ,
3941 type ServerProvider ,
4042 type ThreadId ,
4143} from "@t3tools/contracts" ;
4244import { deriveSubagentElapsedMs } from "@t3tools/shared/orchestrationTiming" ;
43- import { groupBy } from "effect/Array" ;
4445import * as DateTime from "effect/DateTime" ;
4546import { useNavigate } from "@tanstack/react-router" ;
4647import {
@@ -127,15 +128,15 @@ function ThreadLineageRowList(props: {
127128
128129function ThreadLineageGroup ( props : {
129130 readonly label : string | null ;
130- readonly rows : ReadonlyArray < ThreadRelationshipWalkRow > ;
131+ readonly rows : ReadonlyArray < WebThreadLineageRow > ;
131132 readonly expanded : boolean ;
132- readonly children : ( rows : ReadonlyArray < ThreadRelationshipWalkRow > ) => ReactNode ;
133+ readonly children : ( rows : ReadonlyArray < WebThreadLineageRow > ) => ReactNode ;
133134} ) {
134135 const [ expanded , setExpanded ] = useState ( props . expanded ) ;
135136 const [ visibleCount , setVisibleCount ] = useState ( THREAD_LINEAGE_INITIAL_COUNT ) ;
136137 const { visibleRows, hiddenCount } = resolveThreadLineageWindow ( props . rows , visibleCount ) ;
137- const failedCount = props . rows . filter (
138- ( { edge } ) => edge . status === "failed" || edge . status === "error" ,
138+ const failedCount = props . rows . filter ( ( row ) =>
139+ [ "failed" , "error" ] . includes ( webThreadLineageRowStatus ( row ) ?? "" ) ,
139140 ) . length ;
140141 if ( props . rows . length === 0 ) return null ;
141142 return (
@@ -226,9 +227,7 @@ function currentSubagent<Agent extends RuntimeSubagent>(
226227 * the thread there, when this client is connected to that environment.
227228 */
228229function RemoteSubagentRow ( props : {
229- readonly agent : OrchestrationV2Subagent & {
230- readonly remoteChild : OrchestrationV2RemoteTaskChild ;
231- } ;
230+ readonly agent : RemoteSubagent ;
232231 readonly provider : ServerProvider | undefined ;
233232} ) {
234233 const navigate = useNavigate ( ) ;
@@ -443,33 +442,24 @@ export function ThreadRelationshipsPanel(props: {
443442 const canMerge = mergeTargetThreadId !== null && latestMergeBackRun !== null ;
444443 const canDetach = projection ? canDetachThreadProviderSession ( projection ) : false ;
445444
446- const {
447- related = [ ] ,
448- active = [ ] ,
449- previous = [ ] ,
450- } = groupBy ( relationshipRows , ( { edge } ) => {
451- if ( edge . kind !== "subagent" || isParentThreadRelationship ( edge , props . threadId ) )
452- return "related" ;
453- return [ "completed" , "failed" , "error" , "cancelled" , "interrupted" , "idle" ] . includes (
454- edge . status ?? "" ,
455- )
456- ? "previous"
457- : "active" ;
445+ const remoteSubagents = ( projection ?. subagents ?? [ ] ) . filter (
446+ ( agent ) : agent is RemoteSubagent => agent . remoteChild !== undefined ,
447+ ) ;
448+ const { related, active, previous } = groupWebThreadLineageRows ( {
449+ rows : relationshipRows ,
450+ remoteSubagents,
451+ currentThreadId : props . threadId ,
458452 } ) ;
459453 const groups = [
460454 { id : "related" , label : null , rows : related , expanded : true } ,
461455 { id : "active" , label : null , rows : active , expanded : true } ,
462456 { id : "previous" , label : "Previous agents" , rows : previous , expanded : false } ,
463457 ] ;
464- // Tasks running in a linked environment have no thread here; they get their own rows.
465- const remoteSubagents = ( projection ?. subagents ?? [ ] ) . filter (
466- ( agent ) : agent is OrchestrationV2Subagent & { remoteChild : OrchestrationV2RemoteTaskChild } =>
467- agent . remoteChild !== undefined ,
468- ) ;
469458 const runningCount =
470459 ( projection ?. subagents . filter (
471460 ( agent ) => agent . childThreadId === null && agent . status === "running" ,
472- ) . length ?? 0 ) + active . filter ( ( { edge } ) => edge . status === "running" ) . length ;
461+ ) . length ?? 0 ) +
462+ active . filter ( ( row ) => ! ( "remoteChild" in row ) && row . edge . status === "running" ) . length ;
473463
474464 // A linked environment's agent may have delegated this thread from there.
475465 const delegatedFrom = currentThread ?. delegatedFrom ;
@@ -599,7 +589,20 @@ export function ThreadRelationshipsPanel(props: {
599589 { groups . map ( ( group ) => (
600590 < ThreadLineageGroup key = { `${ scopedThreadKey ( ref ) } :${ group . id } ` } { ...group } >
601591 { ( visibleRows ) =>
602- visibleRows . map ( ( { threadId, edge } ) => {
592+ visibleRows . map ( ( row ) => {
593+ if ( "remoteChild" in row ) {
594+ return (
595+ < RemoteSubagentRow
596+ key = { row . id }
597+ agent = { row }
598+ // Its provider instance belongs to the environment it runs in.
599+ provider = { providersByEnvironment
600+ . get ( row . remoteChild . environmentId )
601+ ?. find ( ( entry ) => entry . instanceId === row . providerInstanceId ) }
602+ />
603+ ) ;
604+ }
605+ const { threadId, edge } = row ;
603606 const node = graph . nodes . get ( threadId ) ;
604607 const isSubagent = edge . kind === "subagent" ;
605608 const isMergeTarget = threadId === mergeTargetThreadId ;
@@ -856,20 +859,6 @@ export function ThreadRelationshipsPanel(props: {
856859 }
857860 </ ThreadLineageGroup >
858861 ) ) }
859- { remoteSubagents . length > 0 ? (
860- < ThreadLineageRowList hiddenCount = { 0 } onShowMore = { ( ) => { } } >
861- { remoteSubagents . map ( ( agent ) => (
862- < RemoteSubagentRow
863- key = { agent . id }
864- agent = { agent }
865- // Its provider instance belongs to the environment it runs in.
866- provider = { providersByEnvironment
867- . get ( agent . remoteChild . environmentId )
868- ?. find ( ( entry ) => entry . instanceId === agent . providerInstanceId ) }
869- />
870- ) ) }
871- </ ThreadLineageRowList >
872- ) : null }
873862 </ ThreadDetailsSection >
874863 ) ;
875864}
0 commit comments