Open History to see the last commit
1import { ThreadHoverCardPopup } from "../ThreadHoverCard";
2import { AgentElapsed } from "./AgentElapsed";
3import { projectedSubagentsToRuntime } from "@t3tools/client-runtime/state/subagentRuntime";
4import type { ReactNode } from "react";
5import { useThreadShell, useProject } from "../../state/entities";
6import { useEnvironment } from "../../state/environments";
7import { buildThreadRouteParams } from "../../threadRoutes";
8import { useNavigate } from "@tanstack/react-router";
9import { SubagentTooltipContent } from "./SubagentTooltipContent";
10import { useAtomValue } from "@effect/atom-react";
11import { scopeThreadRef, scopeProjectRef } from "@t3tools/client-runtime/environment";
12import { environmentThreadDetails } from "../../state/threads";
13import { EMPTY_SERVER_PROVIDERS, serverEnvironment } from "../../state/server";
14import { MiddleTruncate } from "../ui/middle-truncate";
15import * as DateTime from "effect/DateTime";
16import { WorkLogRow } from "./WorkLog";
17import {
18 resolveHandoffEndpoints,
19 type HandoffEndpoints,
20 type HandoffTimelineRun,
21 resolveModelSwitchChange,
22} from "@t3tools/client-runtime/handoff";
23import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subagent-display";
24import {
25 ProviderDriverKind,
26 type ModelSelection,
27 type OrchestrationV2ModelSwitch,
28 type OrchestrationV2Notification,
29 type OrchestrationV2TurnItem,
30 type OrchestrationV2RemoteTaskChild,
31 type OrchestrationV2Subagent,
32 type ProviderInstanceId,
33 type ServerProvider,
34 type ThreadId,
35 type EnvironmentId,
36 type NodeId,
37 type ScopedThreadRef,
38} from "@t3tools/contracts";
39import type { TimestampFormat } from "@t3tools/contracts/settings";
40import {
41 BotIcon,
42 ChevronRightIcon,
43 CircleStopIcon,
44 ArrowRightLeftIcon,
45 ArrowRightIcon,
46 GitForkIcon,
47 MessageSquareIcon,
48} from "lucide-react";
49
50import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip";
51import {
52 applyProviderInstanceSettings,
53 brandProviderInstanceEntries,
54 deriveProviderInstanceEntries,
55 shouldShowInstanceBadge,
56 type ProviderInstanceEntry,
57} from "../../providerInstances";
58import { formatShortTimestamp } from "../../timestampFormat";
59import { getTriggerDisplayModelName } from "./providerIconUtils";
60import { ProviderInstanceIcon, providerTextColor } from "./ProviderInstanceIcon";
61import { cn } from "~/lib/utils";
62import { TimelineSystemDivider } from "./TimelineSystemDivider";
63import { subagentResumedSince } from "./V2LifecycleRow.logic";
64import { Button, InlineButton } from "../ui/button";
65import { T3Wordmark } from "../T3Wordmark";
66
67export type { HandoffTimelineRun } from "@t3tools/client-runtime/handoff";
68
69export function V2LifecycleRow(props: {
70 readonly item: OrchestrationV2TurnItem;
71 readonly environmentId: EnvironmentId;
72 readonly resourceSummary?: boolean | undefined;
73 readonly runs: ReadonlyArray<HandoffTimelineRun>;
74 readonly onOpenThread: (threadId: ThreadId) => void;
75}) {
76 const { item } = props;
77 if (item.type === "run_interrupt_result") {
78 return (
79 <TimelineSystemDivider
80 label="Run interrupted"
81 detail={item.message}
82 icon={CircleStopIcon}
83 wrapDetail
84 />
85 );
86 }
87 if (item.type === "handoff") {
88 return (
89 <EnvironmentHandoffRow
90 environmentId={props.environmentId}
91 endpoints={resolveHandoffEndpoints(item, props.runs)}
92 failed={item.status === "failed"}
93 />
94 );
95 }
96 if (item.type === "fork") {
97 const relatedThreadId = item.source.type === "run" ? item.source.threadId : item.targetThreadId;
98 return (
99 <TimelineSystemDivider
100 label={item.source.type === "run" ? "Forked from conversation" : "Conversation fork"}
101 icon={GitForkIcon}
102 actionLabel={item.source.type === "run" ? "Open source conversation" : "Open fork"}
103 onAction={() => props.onOpenThread(relatedThreadId)}
104 />
105 );
106 }
107 if (item.type === "thread_created") {
108 if (props.resourceSummary) {
109 return (
110 <div
111 data-v2-item-type={item.type}
112 className="flex min-w-0 items-center gap-3 rounded-lg border border-border/60 p-3"
113 >
114 <span className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-muted/60">
115 <MessageSquareIcon className="size-4 text-secondary-label" aria-hidden />
116 </span>
117 <span className="min-w-0 flex-1 truncate text-sm font-medium">
118 {item.title ?? "Created thread"}
119 </span>
120 <Button
121 size="xs"
122 variant="outline"
123 aria-label={`Open ${item.title ?? "created thread"}`}
124 onClick={() => props.onOpenThread(item.targetThreadId)}
125 >
126 Open chat
127 </Button>
128 </div>
129 );
130 }
131 return (
132 <WorkLogRow
133 data-v2-item-type={item.type}
134 icon={<T3Wordmark className="size-4 text-icon-muted" aria-hidden />}
135 label={<>Created thread{item.title ? ` · ${item.title}` : ""}</>}
136 trailing={
137 <InlineButton
138 aria-label={`Open ${item.title ?? "created thread"}`}
139 onClick={() => props.onOpenThread(item.targetThreadId)}
140 >
141 Open chat
142 </InlineButton>
143 }
144 />
145 );
146 }
147 if (item.type === "subagent") {
148 return (
149 <SubagentTimelineLink
150 parentRef={scopeThreadRef(props.environmentId, item.threadId)}
151 subagentId={item.subagentId}
152 providerInstanceId={item.providerInstanceId}
153 origin={item.origin}
154 status={item.status}
155 driver={item.driver}
156 title={formatSubagentDisplayTitle(item.title ?? "Subagent")}
157 result={item.result}
158 progress={item.progress}
159 startedAt={item.startedAt}
160 completedAt={item.completedAt}
161 threadId={item.childThreadId}
162 remote={item.remoteChild}
163 onOpenThread={props.onOpenThread}
164 />
165 );
166 }
167 return null;
168}
169
170const STATUS_VISUALS: Record<
171 OrchestrationV2TurnItem["status"],
172 { dotClass: string; label: string }
173> = {
174 pending: { dotClass: "bg-info", label: "Queued" },
175 running: { dotClass: "bg-info", label: "Running" },
176 waiting: { dotClass: "bg-info", label: "Waiting" },
177 idle: { dotClass: "bg-muted-foreground/50", label: "Idle · resumable" },
178 completed: { dotClass: "bg-success", label: "Completed" },
179 failed: { dotClass: "bg-destructive", label: "Failed" },
180 cancelled: { dotClass: "bg-muted-foreground/60", label: "Stopped" },
181 interrupted: { dotClass: "bg-muted-foreground/60", label: "Stopped" },
182};
183
184function subagentStatusVisual(status: OrchestrationV2TurnItem["status"]) {
185 return STATUS_VISUALS[status];
186}
187
188const SETTLED_SUBAGENT_STATUSES = new Set<OrchestrationV2TurnItem["status"]>([
189 "completed",
190 "failed",
191 "cancelled",
192 "interrupted",
193]);
194
195const GENERIC_CHILD_END = /^Child task ended with status\b/i;
196
197function plainDetail(text: string): string {
198 return text
199 .replace(/\[([^\]]+)\]\([^)]*\)/g, "$1")
200 .replace(/`/g, "")
201 .replace(/^[ \t]*[-*][ \t]+/gm, "")
202 .replace(/\s+/g, " ")
203 .trim();
204}
205
206function isoOrNull(value: DateTime.Utc | null | undefined): string | null {
207 return value ? DateTime.formatIso(value) : null;
208}
209
210export function SubagentElapsed({ agent }: { agent: Parameters<typeof AgentElapsed>[0]["agent"] }) {
211 return <AgentElapsed agent={agent} />;
212}
213
214function SubagentAvatar({
215 driver,
216 displayName,
217 iconUrl,
218 accentColor,
219 showBadge,
220 status,
221 className,
222}: {
223 driver?: ProviderDriverKind | undefined;
224 displayName?: string | undefined;
225 iconUrl?: string | undefined;
226 accentColor?: string | undefined;
227 showBadge: boolean;
228 status?: OrchestrationV2TurnItem["status"] | undefined;
229 className?: string;
230}) {
231 return (
232 <span
233 aria-hidden
234 className={cn(
235 "relative inline-flex size-6 shrink-0 items-center justify-center rounded-full border border-border/70 bg-muted ring-2 ring-background",
236 className,
237 )}
238 >
239 {driver ? (
240 <ProviderInstanceIcon
241 driverKind={driver}
242 displayName={displayName ?? driver}
243 accentColor={accentColor}
244 acpRegistryIconUrl={iconUrl}
245 showBadge={showBadge}
246 size="compact"
247 className="z-auto"
248 iconClassName="size-3.5"
249 />
250 ) : (
251 <BotIcon className="size-3.5 text-muted-foreground" />
252 )}
253 {status ? (
254 <span
255 className={cn(
256 "absolute size-2 rounded-full ring-2 ring-background",
257 showBadge ? "-left-px -top-px" : "-right-px -bottom-px",
258 subagentStatusVisual(status).dotClass,
259 )}
260 />
261 ) : null}
262 </span>
263 );
264}
265
266// Select strings; status pushes replace providers even when avatar fields are unchanged.
267export function EnvironmentSubagentAvatar({
268 environmentId,
269 providerInstanceId,
270 driver,
271 remote,
272 ...props
273}: {
274 environmentId: EnvironmentId;
275 providerInstanceId: ProviderInstanceId;
276 driver?: ProviderDriverKind | undefined;
277 /** A task in a linked environment runs a provider instance there; its driver here is only a label. */
278 remote?: OrchestrationV2RemoteTaskChild | undefined;
279 status?: OrchestrationV2TurnItem["status"] | undefined;
280}) {
281 const providerEnvironmentId = remote?.environmentId ?? environmentId;
282 const providersAtom = serverEnvironment.providersValueAtom(providerEnvironmentId);
283 const settings = useAtomValue(serverEnvironment.settingsValueAtom(providerEnvironmentId));
284 const entries = (providers: ReadonlyArray<ServerProvider> | null | undefined) => {
285 const derived = deriveProviderInstanceEntries(providers ?? []);
286 return settings ? brandProviderInstanceEntries(derived, settings) : derived;
287 };
288 const providerDriver = useAtomValue(
289 providersAtom,
290 (providers) =>
291 providers?.find((provider) => provider.instanceId === providerInstanceId)?.driver,
292 );
293 const displayName = useAtomValue(
294 providersAtom,
295 (providers) =>
296 entries(providers).find((entry) => entry.instanceId === providerInstanceId)?.displayName,
297 );
298 const accentColor = useAtomValue(
299 providersAtom,
300 (providers) =>
301 entries(providers).find((entry) => entry.instanceId === providerInstanceId)?.accentColor,
302 );
303 const showBadge = useAtomValue(providersAtom, (providers) => {
304 const all = entries(providers);
305 const entry = all.find((candidate) => candidate.instanceId === providerInstanceId);
306 return entry !== undefined && shouldShowInstanceBadge(entry, all);
307 });
308 const iconUrl = useAtomValue(
309 providersAtom,
310 (providers) =>
311 providers?.find((provider) => provider.instanceId === providerInstanceId)?.iconUrl,
312 );
313 return (
314 <SubagentAvatar
315 {...props}
316 driver={providerDriver ?? (remote === undefined ? driver : undefined)}
317 displayName={displayName}
318 iconUrl={iconUrl}
319 accentColor={accentColor}
320 showBadge={showBadge}
321 />
322 );
323}
324
325const NOTIFICATION_OUTCOME_STATUS: Record<
326 OrchestrationV2Notification["outcome"],
327 OrchestrationV2TurnItem["status"] | null
328> = {
329 completed: "completed",
330 failed: "failed",
331 cancelled: "cancelled",
332 updated: null,
333 unknown: null,
334};
335
336const NOTIFICATION_OUTCOME_LABEL: Record<OrchestrationV2Notification["outcome"], string> = {
337 completed: "Finished",
338 failed: "Failed",
339 cancelled: "Stopped",
340 updated: "Updated",
341 unknown: "Finished",
342};
343
344export function SubagentNotificationLink(props: {
345 readonly parentRef: ScopedThreadRef;
346 readonly childThreadId: ThreadId;
347 readonly taskIds?: ReadonlyArray<NodeId> | undefined;
348 readonly outcome: OrchestrationV2Notification["outcome"];
349 readonly createdAt: string;
350 readonly timestampFormat: TimestampFormat;
351 readonly onOpenThread: (threadId: ThreadId) => void;
352 readonly fallback: ReactNode;
353}) {
354 // Follow-up tasks share a child conversation; this notice reports a particular task result.
355 const agent = useAtomValue(
356 environmentThreadDetails.threadAtom(props.parentRef),
357 (thread) =>
358 thread?.projection.subagents.find((agent) =>
359 props.taskIds === undefined
360 ? agent.childThreadId === props.childThreadId
361 : props.taskIds.includes(agent.id),
362 ) ?? null,
363 );
364 if (agent === null) return props.fallback;
365 const resumed =
366 NOTIFICATION_OUTCOME_STATUS[props.outcome] !== null &&
367 subagentResumedSince(agent, props.createdAt);
368 return (
369 <SubagentTimelineLink
370 parentRef={props.parentRef}
371 subagentId={agent.id}
372 providerInstanceId={agent.providerInstanceId}
373 origin={agent.origin}
374 status={agent.status}
375 driver={agent.driver}
376 title={formatSubagentDisplayTitle(agent.title ?? "Subagent")}
377 result={agent.result}
378 progress={agent.progress}
379 startedAt={agent.startedAt}
380 completedAt={agent.completedAt}
381 threadId={props.childThreadId}
382 onOpenThread={props.onOpenThread}
383 {...(resumed
384 ? {}
385 : {
386 event: {
387 status: NOTIFICATION_OUTCOME_STATUS[props.outcome],
388 label: NOTIFICATION_OUTCOME_LABEL[props.outcome],
389 timestamp: formatShortTimestamp(props.createdAt, props.timestampFormat),
390 },
391 })}
392 />
393 );
394}
395
396function SubagentTimelineLink(props: {
397 readonly parentRef: ScopedThreadRef;
398 readonly subagentId: NodeId;
399 readonly providerInstanceId: ProviderInstanceId;
400 readonly origin: OrchestrationV2Subagent["origin"];
401 readonly driver: ProviderDriverKind;
402 readonly title: string;
403 readonly result: string | null;
404 readonly progress: string | undefined;
405 readonly status: OrchestrationV2TurnItem["status"];
406 readonly startedAt: DateTime.Utc | null;
407 readonly completedAt: DateTime.Utc | null;
408 readonly threadId: ThreadId | null;
409 /** The thread in a linked environment that runs this task, when it runs there. */
410 readonly remote?: OrchestrationV2RemoteTaskChild | undefined;
411 readonly onOpenThread: (threadId: ThreadId) => void;
412 readonly event?: {
413 readonly status: OrchestrationV2TurnItem["status"] | null;
414 readonly label: string;
415 readonly timestamp: string;
416 };
417}) {
418 const agent = useAtomValue(
419 environmentThreadDetails.threadAtom(props.parentRef),
420 (thread) => thread?.projection.subagents.find((agent) => agent.id === props.subagentId) ?? null,
421 );
422 const remote = props.remote ?? agent?.remoteChild;
423 const remoteEnvironment = useEnvironment(remote?.environmentId ?? null);
424 const navigate = useNavigate();
425 const threadId = props.threadId;
426 // A task in a linked environment opens there, if this client is connected to it.
427 const open =
428 threadId !== null
429 ? () => props.onOpenThread(threadId)
430 : remote !== undefined && remoteEnvironment !== null
431 ? () =>
432 void navigate({
433 to: "/$environmentId/$threadId",
434 params: buildThreadRouteParams(scopeThreadRef(remote.environmentId, remote.threadId)),
435 })
436 : null;
437 const liveStatus = agent?.status ?? props.status;
438 const status = props.event ? props.event.status : liveStatus;
439 const statusLabel = props.event?.label ?? subagentStatusVisual(liveStatus).label;
440 const result = (agent?.result ?? props.result)?.trim();
441 const progress = (agent?.progress ?? props.progress)?.trim();
442 const settled = SETTLED_SUBAGENT_STATUSES.has(status ?? liveStatus);
443 const rawDetail = settled ? result || progress : progress || result;
444 const detail =
445 rawDetail && !GENERIC_CHILD_END.test(rawDetail) ? plainDetail(rawDetail) || null : null;
446 const failed = status === "failed";
447 const timing = {
448 status: liveStatus,
449 startedAt: isoOrNull(agent?.startedAt ?? props.startedAt),
450 completedAt: isoOrNull(agent?.completedAt ?? props.completedAt),
451 };
452 const content = (
453 <>
454 <EnvironmentSubagentAvatar
455 environmentId={props.parentRef.environmentId}
456 providerInstanceId={props.providerInstanceId}
457 driver={props.driver}
458 remote={remote}
459 status={status ?? undefined}
460 />
461 <span className="min-w-0 flex-1">
462 <span className="flex items-baseline gap-2">
463 <span className="min-w-0 truncate text-xs font-medium text-foreground">
464 {props.title}
465 </span>
466 {remote !== undefined ? (
467 <span className="shrink-0 text-xs text-muted-foreground">on {remote.label}</span>
468 ) : null}
469 </span>
470 <span
471 className={cn(
472 "block text-2xs leading-relaxed",
473 failed ? "text-destructive" : "text-muted-foreground",
474 )}
475 >
476 {detail === null ? (
477 statusLabel
478 ) : detail.includes("/") && !detail.includes(" ") ? (
479 <MiddleTruncate value={detail} showTitle={false} className="flex" />
480 ) : (
481 <span className="block truncate">{detail}</span>
482 )}
483 </span>
484 </span>
485 {detail !== null && (props.event !== undefined || status !== "completed") ? (
486 <span
487 className={cn("shrink-0 text-xs", failed ? "text-destructive" : "text-muted-foreground")}
488 >
489 {statusLabel}
490 </span>
491 ) : null}
492 <span className="shrink-0 text-xs text-muted-foreground tabular-nums">
493 {props.event ? props.event.timestamp : <SubagentElapsed agent={timing} />}
494 </span>
495 {open !== null ? (
496 <ChevronRightIcon
497 aria-hidden
498 className="size-3.5 shrink-0 text-muted-foreground/60 transition-colors group-hover/subagent:text-foreground"
499 />
500 ) : null}
501 </>
502 );
503 const className =
504 "group/subagent flex w-full min-w-0 items-center gap-2.5 rounded-md px-2 py-1.5 text-left";
505 return (
506 <Tooltip>
507 <TooltipTrigger
508 delay={200}
509 render={
510 open === null ? (
511 <div data-v2-item-type="subagent" aria-description={statusLabel} className={className}>
512 {content}
513 </div>
514 ) : (
515 <button
516 type="button"
517 data-v2-item-type="subagent"
518 aria-label={`Open ${props.title}`}
519 aria-description={statusLabel}
520 onClick={open}
521 className={cn(
522 className,
523 "cursor-pointer transition-colors hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
524 )}
525 >
526 {content}
527 </button>
528 )
529 }
530 />
531 <ThreadHoverCardPopup>
532 <SubagentTimelineTooltip
533 {...props}
534 elapsed={agent ? <AgentElapsed agent={projectedSubagentsToRuntime([agent])[0]!} /> : null}
535 model={agent?.model ?? null}
536 modelSelection={agent?.modelSelection}
537 status={liveStatus}
538 result={agent?.result ?? props.result}
539 progress={agent?.progress ?? props.progress}
540 />
541 </ThreadHoverCardPopup>
542 </Tooltip>
543 );
544}
545
546function SubagentTimelineTooltip(
547 props: Parameters<typeof SubagentTimelineLink>[0] & {
548 model: string | null;
549 modelSelection: OrchestrationV2Subagent["modelSelection"];
550 elapsed: ReactNode;
551 },
552) {
553 const environmentId = props.parentRef.environmentId;
554 // Read providers only in the open popup to avoid per-row subscriptions.
555 const providers =
556 useAtomValue(serverEnvironment.providersValueAtom(environmentId)) ?? EMPTY_SERVER_PROVIDERS;
557 const parent = useThreadShell(props.parentRef)?.source;
558 const child = useThreadShell(
559 props.threadId ? scopeThreadRef(environmentId, props.threadId) : null,
560 )?.source;
561 const parentProject = useProject(
562 parent ? scopeProjectRef(environmentId, parent.projectId) : null,
563 );
564 const childProject = useProject(child ? scopeProjectRef(environmentId, child.projectId) : null);
565 return (
566 <SubagentTooltipContent
567 title={formatSubagentDisplayTitle(child?.title ?? props.title)}
568 model={props.model}
569 providerInstanceId={props.providerInstanceId}
570 origin={props.origin}
571 modelSelection={props.modelSelection}
572 provider={providers.find((provider) => provider.instanceId === props.providerInstanceId)}
573 providers={providers}
574 driver={props.driver}
575 elapsed={props.elapsed}
576 status={props.status}
577 result={props.result}
578 progress={props.progress}
579 parentThread={parent}
580 childThread={child}
581 parentProject={parentProject ?? undefined}
582 childProject={childProject ?? undefined}
583 />
584 );
585}
586
587function EnvironmentHandoffRow({
588 environmentId,
589 ...props
590}: {
591 readonly environmentId: EnvironmentId;
592 readonly endpoints: HandoffEndpoints;
593 readonly failed: boolean;
594}) {
595 const providers =
596 useAtomValue(serverEnvironment.providersValueAtom(environmentId)) ?? EMPTY_SERVER_PROVIDERS;
597 return <HandoffRow {...props} environmentId={environmentId} providers={providers} />;
598}
599
600/** A same-harness model or effort change. Shows only what changed. */
601export function ModelSwitchRow(props: {
602 readonly environmentId: EnvironmentId;
603 readonly modelSwitch: OrchestrationV2ModelSwitch;
604}) {
605 const providers =
606 useAtomValue(serverEnvironment.providersValueAtom(props.environmentId)) ??
607 EMPTY_SERVER_PROVIDERS;
608 const change = resolveModelSwitchChange(props.modelSwitch, providers);
609 if (change === null) return null;
610 const describe = (selection: ModelSelection, effort: string | undefined) => {
611 const provider = providers.find((candidate) => candidate.instanceId === selection.instanceId);
612 const model = provider?.models.find((candidate) => candidate.slug === selection.model);
613 const modelName = model ? getTriggerDisplayModelName(model, provider?.driver) : selection.model;
614 return [change.modelChanged ? modelName : null, effort].filter(Boolean).join(" ");
615 };
616 const { from, to } = props.modelSwitch;
617 return (
618 <TimelineSystemDivider
619 label={`${describe(from, change.effort?.from)} → ${describe(to, change.effort?.to)}`}
620 />
621 );
622}
623
624export function HandoffRow(props: {
625 readonly environmentId: EnvironmentId;
626 readonly endpoints: HandoffEndpoints;
627 readonly providers: ReadonlyArray<ServerProvider>;
628 readonly pending?: boolean;
629 readonly failed?: boolean;
630}) {
631 const { from: fromEndpoints, to } = props.endpoints;
632 const settings = useAtomValue(serverEnvironment.settingsValueAtom(props.environmentId));
633 const derived = deriveProviderInstanceEntries(props.providers);
634 const entries = settings ? applyProviderInstanceSettings(derived, settings, null) : derived;
635 return (
636 <TimelineSystemDivider
637 label={props.pending ? "Context handoff pending" : "Context handoff"}
638 icon={ArrowRightLeftIcon}
639 showDetailSeparator={false}
640 tone={props.failed ? "danger" : "neutral"}
641 detail={
642 <span className="inline-flex min-w-0 flex-wrap items-center justify-center gap-1.5">
643 {fromEndpoints.map((endpoint, index) => (
644 <span
645 key={`${endpoint.instanceId}:${endpoint.model ?? ""}`}
646 className="inline-flex min-w-0 items-center"
647 >
648 <HandoffEndpoint
649 entries={entries}
650 instanceId={endpoint.instanceId}
651 model={endpoint.model}
652 />
653 {index < fromEndpoints.length - 1 ? (
654 <span aria-hidden="true" className="ml-0.5">
655 ,
656 </span>
657 ) : null}
658 </span>
659 ))}
660 {fromEndpoints.length > 0 ? (
661 <ArrowRightIcon aria-hidden="true" className="size-3 shrink-0" />
662 ) : null}
663 <HandoffEndpoint entries={entries} instanceId={to.instanceId} model={to.model} />
664 </span>
665 }
666 />
667 );
668}
669
670function HandoffEndpoint(props: {
671 readonly entries: ReadonlyArray<ProviderInstanceEntry>;
672 readonly instanceId: ProviderInstanceId;
673 readonly model?: string | undefined;
674}) {
675 const entry = props.entries.find((candidate) => candidate.instanceId === props.instanceId);
676 const showBadge = entry !== undefined && shouldShowInstanceBadge(entry, props.entries);
677 const model = props.model?.trim();
678 const providerModel =
679 model === undefined || model.length === 0
680 ? undefined
681 : entry?.models.find((candidate) => candidate.slug === model);
682 const label =
683 providerModel !== undefined
684 ? getTriggerDisplayModelName(providerModel, entry?.driverKind)
685 : model !== undefined && model.length > 0
686 ? model
687 : (entry?.displayName ?? props.instanceId);
688 const labelColor = providerTextColor(
689 entry?.driverKind ?? ProviderDriverKind.make(props.instanceId),
690 );
691 return (
692 <Tooltip>
693 <TooltipTrigger
694 render={
695 <span
696 tabIndex={0}
697 className="inline-flex min-w-0 items-center gap-1.5 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
698 >
699 <ProviderInstanceIcon
700 driverKind={entry?.driverKind ?? ProviderDriverKind.make(props.instanceId)}
701 displayName={entry?.displayName ?? props.instanceId}
702 accentColor={entry?.accentColor}
703 acpRegistryAgentId={entry?.acpRegistryAgentId}
704 acpRegistryIconUrl={entry?.acpRegistryIconUrl}
705 showBadge={showBadge}
706 size="compact"
707 iconClassName={cn(showBadge && "opacity-60")}
708 indicatorBackground="var(--background)"
709 />
710 <span
711 className={cn("truncate font-medium", labelColor.className)}
712 style={labelColor.style}
713 >
714 {label}
715 </span>
716 </span>
717 }
718 />
719 <TooltipPopup>
720 {entry?.displayName ?? props.instanceId} · {label}
721 </TooltipPopup>
722 </Tooltip>
723 );
724}