Open History to see the last commit
1import type {
2 EnvironmentId,
3 OrchestrationV2GetNativeChildWorkResult,
4 OrchestrationV2NativeChildStep,
5 OrchestrationV2NativeChildWork,
6 ThreadId,
7} from "@t3tools/contracts";
8import { ListTreeIcon } from "lucide-react";
9import { useState } from "react";
10
11import { orchestrationEnvironment } from "../../state/orchestration";
12import { useEnvironmentQuery } from "../../state/query";
13import { Button } from "../ui/button";
14import {
15 Dialog,
16 DialogDescription,
17 DialogFooter,
18 DialogHeader,
19 DialogPanel,
20 DialogPopup,
21 DialogTitle,
22} from "../ui/dialog";
23
24const stepLabel = (type: string) => {
25 const words = type.toLowerCase().replaceAll("_", " ");
26 return words.charAt(0).toUpperCase() + words.slice(1);
27};
28
29/** Read-only view of what a provider-native subagent's children did. Loads only while open. */
30export function NativeChildWorkDialog(props: {
31 readonly environmentId: EnvironmentId;
32 readonly threadId: ThreadId;
33}) {
34 const [open, setOpen] = useState(false);
35 return (
36 <Dialog open={open} onOpenChange={setOpen}>
37 <Button size="sm" variant="ghost" onClick={() => setOpen(true)}>
38 <ListTreeIcon />
39 <span className="@max-[420px]/composer-surface:sr-only">Subagent work</span>
40 </Button>
41 <DialogPopup className="max-w-2xl">
42 <DialogHeader>
43 <DialogTitle>Subagent work</DialogTitle>
44 <DialogDescription>Read only. These subagents cannot take messages.</DialogDescription>
45 </DialogHeader>
46 {open ? <NativeChildWorkContent {...props} /> : null}
47 </DialogPopup>
48 </Dialog>
49 );
50}
51
52function NativeChildWorkContent(props: {
53 readonly environmentId: EnvironmentId;
54 readonly threadId: ThreadId;
55}) {
56 const query = useEnvironmentQuery<OrchestrationV2GetNativeChildWorkResult, unknown>(
57 orchestrationEnvironment.nativeChildWork({
58 environmentId: props.environmentId,
59 input: { threadId: props.threadId },
60 }),
61 );
62 const children = query.data?.children;
63 return (
64 <>
65 <DialogPanel>
66 {query.error !== null ? (
67 <p className="text-sm text-destructive-foreground">{query.error}</p>
68 ) : children === undefined ? (
69 <p className="text-sm text-muted-foreground">Loading…</p>
70 ) : children.length === 0 ? (
71 <p className="text-sm text-muted-foreground">
72 The provider has no record of which subagents this call started.
73 </p>
74 ) : (
75 children.map((child) => <NativeChild key={child.conversationId} child={child} />)
76 )}
77 </DialogPanel>
78 <DialogFooter variant="bare">
79 <Button size="sm" variant="outline" disabled={query.isPending} onClick={query.refresh}>
80 Refresh
81 </Button>
82 </DialogFooter>
83 </>
84 );
85}
86
87function NativeChild(props: { readonly child: OrchestrationV2NativeChildWork }) {
88 const { child } = props;
89 return (
90 <section aria-label={child.role || "Subagent"} className="flex min-w-0 flex-col gap-2">
91 <h3 className="text-sm font-medium text-foreground">{child.role || "Subagent"}</h3>
92 <p className="whitespace-pre-wrap break-words text-sm text-muted-foreground">
93 {child.prompt}
94 </p>
95 {child.truncated ? (
96 <p className="text-xs text-muted-foreground">Earlier steps are not shown.</p>
97 ) : null}
98 {child.steps === null ? (
99 <p className="text-xs text-muted-foreground">No transcript yet.</p>
100 ) : (
101 <ol className="m-0 flex list-none flex-col gap-2 border-s ps-3">
102 {child.steps.map((step) => (
103 <NativeChildStep key={step.index} step={step} />
104 ))}
105 </ol>
106 )}
107 </section>
108 );
109}
110
111function NativeChildStep(props: { readonly step: OrchestrationV2NativeChildStep }) {
112 const { step } = props;
113 return (
114 <li className="flex min-w-0 flex-col gap-1">
115 <span className="text-xs font-medium text-muted-foreground">
116 {stepLabel(step.type)}
117 {step.status !== null && step.status !== "DONE" ? ` · ${stepLabel(step.status)}` : ""}
118 </span>
119 {step.toolCalls.length === 0 ? null : (
120 <code className="whitespace-pre-wrap break-all text-xs text-foreground">
121 {step.toolCalls.map((call) => `${call.name} ${call.input}`).join("\n")}
122 </code>
123 )}
124 {step.text === null ? null : (
125 <pre className="max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-xs text-foreground">
126 {step.text}
127 </pre>
128 )}
129 </li>
130 );
131}