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

main
tsx 79 lines 2.84 KB
Raw
1 import { useAtomValue } from "@effect/atom-react";
2 import type { EnvironmentId, OrchestrationV2Subagent } from "@t3tools/contracts";
3 import { useGT, useMessages } from "gt-react-native";
4 import { useState } from "react";
5 import { View } from "react-native";
6
7 import * as Dialog from "../../components/ui/Dialog";
8 import { IconButton } from "../../components/ui/IconButton";
9 import { orchestrationEnvironment } from "../../state/orchestration";
10 import { threadEnvironment } from "../../state/threads";
11 import { useAtomCommand } from "../../state/use-atom-command";
12 import {
13 resolveSubagentRowPresentation,
14 resolveSubagentStopTarget,
15 } from "./threadAgentsPresentation";
16
17 export function SubagentStopButton(props: {
18 readonly environmentId: EnvironmentId;
19 readonly subagent: OrchestrationV2Subagent;
20 readonly className?: string;
21 }) {
22 const gt = useGT();
23 const messages = useMessages();
24 const target = resolveSubagentStopTarget(props.subagent);
25 const canStop = useAtomValue(
26 orchestrationEnvironment.stopWorkflow.permissionAtom(props.environmentId),
27 );
28 const stopWorkflow = useAtomCommand(orchestrationEnvironment.stopWorkflow);
29 const interruptTurn = useAtomCommand(threadEnvironment.interruptTurn);
30 const [stopping, setStopping] = useState(false);
31
32 if (target === null || !canStop) return null;
33
34 const workflow = target.kind === "workflow";
35 const label =
36 props.subagent.workflow?.name ??
37 resolveSubagentRowPresentation(props.subagent, false, messages).title;
38 const stop = async () => {
39 setStopping(true);
40 const result = await (
41 target.kind === "workflow"
42 ? stopWorkflow({ environmentId: props.environmentId, input: target.input })
43 : interruptTurn({ environmentId: props.environmentId, input: target.input })
44 ).finally(() => setStopping(false));
45 if (result._tag === "Failure") {
46 Dialog.alert(workflow ? gt("Could not stop workflow") : gt("Could not stop agent"));
47 }
48 };
49
50 return (
51 <View className={props.className}>
52 <IconButton
53 icon="stop.fill"
54 variant="danger"
55 accessibilityLabel={
56 workflow
57 ? stopping
58 ? gt("Stopping workflow {label}", { label })
59 : gt("Stop workflow {label}", { label })
60 : stopping
61 ? gt("Stopping agent {label}", { label })
62 : gt("Stop agent {label}", { label })
63 }
64 disabled={stopping}
65 onPress={() =>
66 Dialog.confirm({
67 title: workflow ? gt("Stop workflow?") : gt("Stop agent?"),
68 message: workflow
69 ? gt("Every running agent in {label} stops.", { label })
70 : gt("Stop {label}?", { label }),
71 confirmText: gt("Stop", { $context: "verb, confirm button" }),
72 destructive: true,
73 onConfirm: () => void stop(),
74 })
75 }
76 />
77 </View>
78 );
79 }