The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | formatProviderSubagentStatus, |
| 3 | type ProviderSubagentStatus, |
| 4 | } from "@t3tools/client-runtime/state/thread-execution"; |
| 5 | import { isOrchestrationV2WorkActive } from "@t3tools/contracts"; |
| 6 | import { T, useGT, useMessages } from "gt-react"; |
| 7 | import { ArrowUpLeftIcon } from "lucide-react"; |
| 8 | import type { ReactNode } from "react"; |
| 9 | |
| 10 | import { tickTextContent } from "~/lib/tickTextContent"; |
| 11 | import type { ProviderInstanceEntry } from "../../providerInstances"; |
| 12 | import { Button } from "../ui/button"; |
| 13 | import { ProviderInstanceIcon } from "./ProviderInstanceIcon"; |
| 14 | import { |
| 15 | ReadOnlyComposerBar, |
| 16 | ReadOnlyComposerLead, |
| 17 | ReadOnlyComposerStatus, |
| 18 | } from "./ReadOnlyComposerBar"; |
| 19 | |
| 20 | export function ProviderSubagentBar(props: { |
| 21 | readonly provider: ProviderInstanceEntry | null; |
| 22 | readonly showInstanceBadge: boolean; |
| 23 | readonly modelLabel: string; |
| 24 | readonly effortLabel: string | null; |
| 25 | readonly status: ProviderSubagentStatus | null; |
| 26 | readonly onOpenParent: (() => void) | null; |
| 27 | readonly actions?: ReactNode; |
| 28 | }) { |
| 29 | const { status } = props; |
| 30 | const gt = useGT(); |
| 31 | const messages = useMessages(); |
| 32 | const live = status !== null && isOrchestrationV2WorkActive(status.status); |
| 33 | const modelDescription = |
| 34 | props.effortLabel === null ? props.modelLabel : `${props.modelLabel}, ${props.effortLabel}`; |
| 35 | const announcement = formatProviderSubagentStatus( |
| 36 | status === null ? null : { ...status, startedAt: null }, |
| 37 | 0, |
| 38 | messages, |
| 39 | ); |
| 40 | |
| 41 | return ( |
| 42 | <ReadOnlyComposerBar |
| 43 | actions={ |
| 44 | <> |
| 45 | <span role="status" className="sr-only"> |
| 46 | {gt("{model} subagent: {status}", { model: modelDescription, status: announcement })} |
| 47 | </span> |
| 48 | <span className="shrink-0 text-muted-foreground @max-[640px]/composer-surface:sr-only"> |
| 49 | <T>Runs on its own</T> |
| 50 | </span> |
| 51 | {props.actions} |
| 52 | {props.onOpenParent ? ( |
| 53 | <Button size="sm" variant="ghost" onClick={props.onOpenParent}> |
| 54 | <ArrowUpLeftIcon /> |
| 55 | <span className="@max-[320px]/composer-surface:sr-only"> |
| 56 | <T>Open parent</T> |
| 57 | </span> |
| 58 | </Button> |
| 59 | ) : null} |
| 60 | </> |
| 61 | } |
| 62 | > |
| 63 | <ReadOnlyComposerLead> |
| 64 | {props.provider ? ( |
| 65 | <ProviderInstanceIcon |
| 66 | driverKind={props.provider.driverKind} |
| 67 | displayName={props.provider.displayName} |
| 68 | accentColor={props.provider.accentColor} |
| 69 | acpRegistryAgentId={props.provider.acpRegistryAgentId} |
| 70 | acpRegistryIconUrl={props.provider.acpRegistryIconUrl} |
| 71 | showBadge={props.showInstanceBadge} |
| 72 | className="size-4 shrink-0" |
| 73 | iconClassName="size-4" |
| 74 | badgeClassName="right-[-0.125rem] bottom-[-0.125rem] h-3 min-w-3 px-0.5 text-5xs" |
| 75 | /> |
| 76 | ) : null} |
| 77 | <span className="min-w-0 truncate font-medium text-foreground">{props.modelLabel}</span> |
| 78 | {props.effortLabel === null ? null : ( |
| 79 | <span className="shrink-0 text-muted-foreground">{props.effortLabel}</span> |
| 80 | )} |
| 81 | </ReadOnlyComposerLead> |
| 82 | <ReadOnlyComposerStatus |
| 83 | ref={tickTextContent( |
| 84 | (nowMs) => formatProviderSubagentStatus(status, nowMs, messages), |
| 85 | live, |
| 86 | )} |
| 87 | aria-hidden |
| 88 | /> |
| 89 | </ReadOnlyComposerBar> |
| 90 | ); |
| 91 | } |