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

ProviderSubagentBar.tsx

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