@@ -2,7 +2,11 @@ import * as Dialog from "../../components/ui/Dialog";
22import { useAtomValue } from "@effect/atom-react" ;
33import { scopeThreadRef } from "@t3tools/client-runtime/environment" ;
44import { resolveHandoffEndpoints , type HandoffEndpoints } from "@t3tools/client-runtime/handoff" ;
5- import { resolveProviderInstanceDisplayName } from "@t3tools/client-runtime/state/provider-instance-display" ;
5+ import {
6+ normalizeProviderAccentColor ,
7+ resolveProviderInstanceDisplayName ,
8+ shouldShowInstanceBadge ,
9+ } from "@t3tools/client-runtime/state/provider-instance-display" ;
610import type {
711 EnvironmentId ,
812 OrchestrationV2ProjectedTurnItem ,
@@ -14,11 +18,16 @@ import { useMemo } from "react";
1418import { Pressable , View , type ColorValue } from "react-native" ;
1519import { AppText as Text } from "../../components/ui/AppText" ;
1620import { SymbolView } from "../../components/ui/AppSymbol" ;
17- import { ProviderIcon } from "../../components/ProviderIcon" ;
21+ import { ProviderIcon , ProviderInstanceIcon } from "../../components/ProviderIcon" ;
1822import { environmentThreadDetails } from "../../state/threads" ;
1923import { serverEnvironment } from "../../state/server" ;
2024import { ThreadContextDivider } from "./thread-context-divider" ;
2125
26+ type HandoffProvider = ServerProvider & {
27+ readonly driverKind : ServerProvider [ "driver" ] ;
28+ readonly acpRegistryAgentId : string | undefined ;
29+ } ;
30+
2231function handoffEndpointsAtom (
2332 environmentId : EnvironmentId ,
2433 { item, sourceThreadId } : OrchestrationV2ProjectedTurnItem ,
@@ -39,6 +48,7 @@ export function ThreadHandoffRow(props: {
3948 environmentId : EnvironmentId ;
4049 projectedItem : OrchestrationV2ProjectedTurnItem ;
4150 iconColor : ColorValue ;
51+ surfaceColor : string ;
4252} ) {
4353 const { item } = props . projectedItem ;
4454 const endpointsAtom = useMemo (
@@ -53,6 +63,7 @@ export function ThreadHandoffRow(props: {
5363 environmentId = { props . environmentId }
5464 endpoints = { endpoints }
5565 iconColor = { color }
66+ surfaceColor = { props . surfaceColor }
5667 label = "Context handoff"
5768 failed = { item . status === "failed" }
5869 />
@@ -63,11 +74,29 @@ export function ThreadHandoffDivider(props: {
6374 environmentId : EnvironmentId ;
6475 endpoints : HandoffEndpoints ;
6576 iconColor : ColorValue ;
77+ surfaceColor : string ;
6678 label : string ;
6779 failed ?: boolean ;
6880} ) {
6981 const config = useAtomValue ( serverEnvironment . configValueAtom ( props . environmentId ) ) ;
7082 const { endpoints } = props ;
83+ const endpointProps = {
84+ providers : ( config ?. providers ?? [ ] ) . map ( ( provider ) => {
85+ const rawConfig = config ?. settings . providerInstances [ provider . instanceId ] ?. config ;
86+ const instanceConfig =
87+ rawConfig !== null && typeof rawConfig === "object"
88+ ? ( rawConfig as Readonly < Record < string , unknown > > )
89+ : null ;
90+ const agentId = instanceConfig ?. source === "local" ? undefined : instanceConfig ?. agentId ;
91+ return {
92+ ...provider ,
93+ driverKind : provider . driver ,
94+ accentColor : normalizeProviderAccentColor ( provider . accentColor ) ,
95+ acpRegistryAgentId : typeof agentId === "string" ? agentId . trim ( ) || undefined : undefined ,
96+ } ;
97+ } ) ,
98+ surfaceColor : props . surfaceColor ,
99+ } ;
71100 return (
72101 < ThreadContextDivider
73102 label = { props . label }
@@ -81,7 +110,7 @@ export function ThreadHandoffDivider(props: {
81110 key = { `${ endpoint . instanceId } :${ endpoint . model ?? "" } ` }
82111 className = "max-w-full flex-row items-center"
83112 >
84- < HandoffEndpoint { ...endpoint } providers = { config ?. providers ?? [ ] } />
113+ < HandoffEndpoint { ...endpoint } { ... endpointProps } />
85114 { index < endpoints . from . length - 1 ? (
86115 < Text accessible = { false } className = "text-xs text-foreground-muted" >
87116 ,
@@ -92,7 +121,7 @@ export function ThreadHandoffDivider(props: {
92121 { endpoints . from . length > 0 ? (
93122 < SymbolView name = "arrow.right" size = { 12 } tintColor = { props . iconColor } />
94123 ) : null }
95- < HandoffEndpoint { ...endpoints . to } providers = { config ?. providers ?? [ ] } />
124+ < HandoffEndpoint { ...endpoints . to } { ... endpointProps } />
96125 </ View >
97126 </ ThreadContextDivider >
98127 ) ;
@@ -101,7 +130,8 @@ export function ThreadHandoffDivider(props: {
101130function HandoffEndpoint ( props : {
102131 instanceId : ProviderInstanceId ;
103132 model ?: string | undefined ;
104- providers : ReadonlyArray < ServerProvider > ;
133+ providers : ReadonlyArray < HandoffProvider > ;
134+ surfaceColor : string ;
105135} ) {
106136 const provider = props . providers . find ( ( candidate ) => candidate . instanceId === props . instanceId ) ;
107137 const model = provider ?. models . find ( ( candidate ) => candidate . slug === props . model ) ;
@@ -110,12 +140,13 @@ function HandoffEndpoint(props: {
110140 model ?. name ??
111141 props . model ??
112142 ( provider ? resolveProviderInstanceDisplayName ( provider ) : props . instanceId ) ;
143+ const showBadge = provider !== undefined && shouldShowInstanceBadge ( provider , props . providers ) ;
113144 return (
114145 < Pressable
115146 accessibilityRole = "button"
116147 accessibilityLabel = { label }
117148 accessibilityHint = "Show provider account"
118- className = "min-h-6 max-w-full flex-row items-center justify-center gap-1"
149+ className = "min-h-6 max-w-full flex-row items-center justify-center gap-1.5 "
119150 hitSlop = { { top : 8 , bottom : 8 } }
120151 onPress = { ( ) =>
121152 Dialog . alert (
@@ -124,11 +155,23 @@ function HandoffEndpoint(props: {
124155 )
125156 }
126157 >
127- < ProviderIcon
128- provider = { provider ?. driver ?? props . instanceId }
129- iconUrl = { provider ?. iconUrl }
130- size = { 12 }
131- />
158+ { showBadge && provider !== undefined ? (
159+ < ProviderInstanceIcon
160+ provider = { provider . driver }
161+ iconUrl = { provider . iconUrl }
162+ size = { 14 }
163+ displayName = { resolveProviderInstanceDisplayName ( provider ) }
164+ accentColor = { provider . accentColor }
165+ showBadge
166+ surfaceColor = { props . surfaceColor }
167+ />
168+ ) : (
169+ < ProviderIcon
170+ provider = { provider ?. driver ?? props . instanceId }
171+ iconUrl = { provider ?. iconUrl }
172+ size = { 12 }
173+ />
174+ ) }
132175 < Text numberOfLines = { 1 } className = "shrink text-xs text-foreground-muted" >
133176 { label }
134177 </ Text >
0 commit comments