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
| 1 | import type { |
| 2 | EnvironmentId, |
| 3 | OrchestrationV2GetNativeChildWorkResult, |
| 4 | OrchestrationV2NativeChildWork, |
| 5 | ThreadId, |
| 6 | } from "@t3tools/contracts"; |
| 7 | import { T, useGT } from "gt-react-native"; |
| 8 | import { ScrollView, View } from "react-native"; |
| 9 | import { useSafeAreaInsets } from "react-native-safe-area-context"; |
| 10 | |
| 11 | import { AppText as Text } from "../../components/ui/AppText"; |
| 12 | import { Button } from "../../components/ui/Button"; |
| 13 | import { Sheet } from "../../components/ui/Sheet"; |
| 14 | import { orchestrationEnvironment } from "../../state/orchestration"; |
| 15 | import { useEnvironmentQuery } from "../../state/query"; |
| 16 | |
| 17 | const stepLabel = (type: string) => { |
| 18 | const words = type.toLowerCase().replaceAll("_", " "); |
| 19 | return words.charAt(0).toUpperCase() + words.slice(1); |
| 20 | }; |
| 21 | |
| 22 | /** Read-only view of what a provider-native subagent's children did. Mount only while open. */ |
| 23 | export function NativeChildWorkSheet(props: { |
| 24 | readonly environmentId: EnvironmentId; |
| 25 | readonly threadId: ThreadId; |
| 26 | readonly onClose: () => void; |
| 27 | }) { |
| 28 | const gt = useGT(); |
| 29 | const insets = useSafeAreaInsets(); |
| 30 | const query = useEnvironmentQuery<OrchestrationV2GetNativeChildWorkResult, unknown>( |
| 31 | orchestrationEnvironment.nativeChildWork({ |
| 32 | environmentId: props.environmentId, |
| 33 | input: { threadId: props.threadId }, |
| 34 | }), |
| 35 | ); |
| 36 | const children = query.data?.children; |
| 37 | return ( |
| 38 | <Sheet title={gt("Subagent work")} onClose={props.onClose}> |
| 39 | <ScrollView |
| 40 | contentInsetAdjustmentBehavior="automatic" |
| 41 | contentContainerStyle={{ |
| 42 | gap: 16, |
| 43 | paddingHorizontal: 20, |
| 44 | paddingTop: 12, |
| 45 | paddingBottom: Math.max(20, insets.bottom), |
| 46 | }} |
| 47 | > |
| 48 | <Text className="font-sans text-xs text-foreground-secondary"> |
| 49 | <T>Read only. These subagents cannot take messages.</T> |
| 50 | </Text> |
| 51 | {query.error !== null ? ( |
| 52 | <Text selectable className="font-sans text-sm text-danger-foreground"> |
| 53 | {query.error} |
| 54 | </Text> |
| 55 | ) : children === undefined ? ( |
| 56 | <Text className="font-sans text-sm text-foreground-secondary"> |
| 57 | <T>Loading…</T> |
| 58 | </Text> |
| 59 | ) : children.length === 0 ? ( |
| 60 | <Text className="font-sans text-sm text-foreground-secondary"> |
| 61 | <T>The provider has no record of which subagents this call started.</T> |
| 62 | </Text> |
| 63 | ) : ( |
| 64 | children.map((child) => <NativeChild key={child.conversationId} child={child} />) |
| 65 | )} |
| 66 | <View className="flex-row justify-end"> |
| 67 | <Button |
| 68 | label={gt("Refresh")} |
| 69 | tone="secondary" |
| 70 | disabled={query.isPending} |
| 71 | onPress={query.refresh} |
| 72 | /> |
| 73 | </View> |
| 74 | </ScrollView> |
| 75 | </Sheet> |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | function NativeChild(props: { readonly child: OrchestrationV2NativeChildWork }) { |
| 80 | const gt = useGT(); |
| 81 | const { child } = props; |
| 82 | return ( |
| 83 | <View className="gap-2"> |
| 84 | <Text className="font-t3-bold text-sm text-foreground">{child.role || gt("Subagent")}</Text> |
| 85 | <Text selectable className="font-sans text-sm text-foreground-secondary"> |
| 86 | {child.prompt} |
| 87 | </Text> |
| 88 | {child.truncated ? ( |
| 89 | <Text className="font-sans text-xs text-foreground-secondary"> |
| 90 | <T>Earlier steps are not shown.</T> |
| 91 | </Text> |
| 92 | ) : null} |
| 93 | {child.steps === null ? ( |
| 94 | <Text className="font-sans text-xs text-foreground-secondary"> |
| 95 | <T>No transcript yet.</T> |
| 96 | </Text> |
| 97 | ) : ( |
| 98 | <View className="gap-2 border-l border-border ps-3"> |
| 99 | {child.steps.map((step) => ( |
| 100 | <View key={step.index} className="gap-1"> |
| 101 | <Text className="font-t3-bold text-xs text-foreground-secondary"> |
| 102 | {stepLabel(step.type)} |
| 103 | {step.status !== null && step.status !== "DONE" |
| 104 | ? ` · ${stepLabel(step.status)}` |
| 105 | : ""} |
| 106 | </Text> |
| 107 | {step.toolCalls.length === 0 ? null : ( |
| 108 | <Text selectable className="font-mono text-xs text-foreground"> |
| 109 | {step.toolCalls.map((call) => `${call.name} ${call.input}`).join("\n")} |
| 110 | </Text> |
| 111 | )} |
| 112 | {step.text === null ? null : ( |
| 113 | <Text selectable className="font-mono text-xs text-foreground"> |
| 114 | {step.text} |
| 115 | </Text> |
| 116 | )} |
| 117 | </View> |
| 118 | ))} |
| 119 | </View> |
| 120 | )} |
| 121 | </View> |
| 122 | ); |
| 123 | } |