Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProviderSubagentBar.tsx

89 lines3.7 KB

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 // Write timer labels to the DOM to avoid chat renders on each tick.
32 useLayoutEffect(() => {
33 const update = () => {
34 if (statusRef.current) {
35 statusRef.current.textContent = formatProviderSubagentStatus(status, Date.now());
36 }
37 };
38 update();
39 if (!live) return;
40 const id = setInterval(update, 1_000);
41 return () => clearInterval(id);
42 }, [live, status]);
43​
44 // Sized by the composer, not the viewport: a docked side panel narrows the
45 // chat column on a wide window, and one row there squeezes out the model
46 // and status, so the status drops to its own line instead.
47 return (
48 <div className="flex min-h-12 items-center gap-3 rounded-2xl py-2 ps-5 pe-2 text-sm">
49 <div className="flex min-w-0 flex-1 items-center gap-3 @max-[560px]/composer-surface:flex-col @max-[560px]/composer-surface:items-start @max-[560px]/composer-surface:gap-0.5">
50 <span className="flex min-w-0 max-w-full items-center gap-2">
51 {props.provider ? (
52 <ProviderInstanceIcon
53 driverKind={props.provider.driverKind}
54 displayName={props.provider.displayName}
55 accentColor={props.provider.accentColor}
56 acpRegistryAgentId={props.provider.acpRegistryAgentId}
57 acpRegistryIconUrl={props.provider.acpRegistryIconUrl}
58 showBadge={props.showInstanceBadge}
59 className="size-4 shrink-0"
60 iconClassName="size-4"
61 badgeClassName="right-[-0.125rem] bottom-[-0.125rem] h-3 min-w-3 px-0.5 text-5xs"
62 />
63 ) : null}
64 <span className="min-w-0 truncate font-medium text-foreground">{props.modelLabel}</span>
65 {props.effortLabel === null ? null : (
66 <span className="shrink-0 text-muted-foreground">{props.effortLabel}</span>
67 )}
68 </span>
69 <span
70 ref={statusRef}
71 aria-hidden
72 className="min-w-0 max-w-full truncate text-muted-foreground tabular-nums @max-[560px]/composer-surface:text-xs"
73 />
74 </div>
75 <span role="status" className="sr-only">
76 {`${modelDescription} subagent: ${announcement}`}
77 </span>
78 <span className="shrink-0 text-muted-foreground @max-[640px]/composer-surface:sr-only">
79 Runs on its own
80 </span>
81 {props.onOpenParent ? (
82 <Button size="sm" variant="ghost" onClick={props.onOpenParent}>
83 <ArrowUpLeftIcon />
84 <span className="@max-[320px]/composer-surface:sr-only">Open parent</span>
85 </Button>
86 ) : null}
87 </div>
88 );