Open History to see the last commit
1import {
2 formatProviderSubagentStatus,
3 type ProviderSubagentStatus,
4} from "@t3tools/client-runtime/state/thread-execution";
5import { isOrchestrationV2WorkActive } from "@t3tools/contracts";
6import { ArrowUpLeftIcon } from "lucide-react";
7import { useLayoutEffect, useRef } from "react";
8
9import type { ProviderInstanceEntry } from "../../providerInstances";
10import { Button } from "../ui/button";
11import { ProviderInstanceIcon } from "./ProviderInstanceIcon";
12
13/**
14 * Stands in for the composer on a provider-native subagent thread. The
15 * provider runs that conversation, so there is nothing to send; the bar says
16 * which model is working, for how long, and leads back to the parent.
17 */
18export function ProviderSubagentBar(props: {
19 /** The provider running the subagent; no icon while its catalog loads. */
20 readonly provider: ProviderInstanceEntry | null;
21 readonly modelLabel: string;
22 /** Reasoning effort as the composer names it, when the subagent has one. */
23 readonly effortLabel: string | null;
24 /** Null until the subagent's root turn arrives. */
25 readonly status: ProviderSubagentStatus | null;
26 readonly onOpenParent: (() => void) | null;
27}) {
28 const statusRef = useRef<HTMLSpanElement>(null);
29 const { status } = props;
30 const live = status !== null && isOrchestrationV2WorkActive(status.status);
31 const modelDescription =
32 props.effortLabel === null ? props.modelLabel : `${props.modelLabel}, ${props.effortLabel}`;
33 // Announced once per transition; the ticking label below is not.
34 const announcement = formatProviderSubagentStatus(
35 status === null ? null : { ...status, startedAt: null },
36 0,
37 );
38
39 // The label is written from an effect, and live bars tick through DOM
40 // writes, so a running timer never re-renders the chat view.
41 useLayoutEffect(() => {
42 const update = () => {
43 if (statusRef.current) {
44 statusRef.current.textContent = formatProviderSubagentStatus(status, Date.now());
45 }
46 };
47 update();
48 if (!live) return;
49 const id = setInterval(update, 1_000);
50 return () => clearInterval(id);
51 }, [live, status]);
52
53 return (
54 <div className="flex min-h-12 items-center gap-3 rounded-3xl py-2 ps-5 pe-2 text-sm">
55 <span className="flex min-w-0 items-center gap-2">
56 {props.provider ? (
57 <ProviderInstanceIcon
58 driverKind={props.provider.driverKind}
59 displayName={props.provider.displayName}
60 accentColor={props.provider.accentColor}
61 acpRegistryAgentId={props.provider.acpRegistryAgentId}
62 acpRegistryIconUrl={props.provider.acpRegistryIconUrl}
63 className="size-4 shrink-0"
64 iconClassName="size-4"
65 />
66 ) : null}
67 <span className="min-w-0 truncate font-medium text-foreground">{props.modelLabel}</span>
68 {props.effortLabel === null ? null : (
69 <span className="shrink-0 text-muted-foreground">{props.effortLabel}</span>
70 )}
71 </span>
72 <span
73 ref={statusRef}
74 aria-hidden
75 className="min-w-0 truncate text-muted-foreground tabular-nums"
76 />
77 <span role="status" className="sr-only">
78 {`${modelDescription} subagent: ${announcement}`}
79 </span>
80 <span className="ms-auto shrink-0 text-muted-foreground max-sm:hidden">Runs on its own</span>
81 {props.onOpenParent ? (
82 <Button size="sm" variant="ghost" onClick={props.onOpenParent}>
83 <ArrowUpLeftIcon />
84 Open parent
85 </Button>
86 ) : null}
87 </div>
88 );
89}