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
13export function ProviderSubagentBar(props: {
14 readonly provider: ProviderInstanceEntry | null;
15 readonly showInstanceBadge: boolean;
16 readonly modelLabel: string;
17 readonly effortLabel: string | null;
18 readonly status: ProviderSubagentStatus | null;
19 readonly onOpenParent: (() => void) | null;
20}) {
21 const statusRef = useRef<HTMLSpanElement>(null);
22 const { status } = props;
23 const live = status !== null && isOrchestrationV2WorkActive(status.status);
24 const modelDescription =
25 props.effortLabel === null ? props.modelLabel : `${props.modelLabel}, ${props.effortLabel}`;
26 const announcement = formatProviderSubagentStatus(
27 status === null ? null : { ...status, startedAt: null },
28 0,
29 );
30
31 // The label is written from an effect, and live bars tick through DOM
32 // writes, so a running timer never re-renders the chat view.
33 useLayoutEffect(() => {
34 const update = () => {
35 if (statusRef.current) {
36 statusRef.current.textContent = formatProviderSubagentStatus(status, Date.now());
37 }
38 };
39 update();
40 if (!live) return;
41 const id = setInterval(update, 1_000);
42 return () => clearInterval(id);
43 }, [live, status]);
44
45 return (
46 <div className="flex min-h-12 items-center gap-3 rounded-3xl py-2 ps-5 pe-2 text-sm">
47 <span className="flex min-w-0 items-center gap-2">
48 {props.provider ? (
49 <ProviderInstanceIcon
50 driverKind={props.provider.driverKind}
51 displayName={props.provider.displayName}
52 accentColor={props.provider.accentColor}
53 acpRegistryAgentId={props.provider.acpRegistryAgentId}
54 acpRegistryIconUrl={props.provider.acpRegistryIconUrl}
55 showBadge={props.showInstanceBadge}
56 className="size-4 shrink-0"
57 iconClassName="size-4"
58 badgeClassName="right-[-0.125rem] bottom-[-0.125rem] h-3 min-w-3 px-0.5 text-5xs"
59 />
60 ) : null}
61 <span className="min-w-0 truncate font-medium text-foreground">{props.modelLabel}</span>
62 {props.effortLabel === null ? null : (
63 <span className="shrink-0 text-muted-foreground">{props.effortLabel}</span>
64 )}
65 </span>
66 <span
67 ref={statusRef}
68 aria-hidden
69 className="min-w-0 truncate text-muted-foreground tabular-nums"
70 />
71 <span role="status" className="sr-only">
72 {`${modelDescription} subagent: ${announcement}`}
73 </span>
74 <span className="ms-auto shrink-0 text-muted-foreground max-sm:hidden">Runs on its own</span>
75 {props.onOpenParent ? (
76 <Button size="sm" variant="ghost" onClick={props.onOpenParent}>
77 <ArrowUpLeftIcon />
78 Open parent
79 </Button>
80 ) : null}
81 </div>
82 );
83}