@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

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