11import { useAtomValue } from "@effect/atom-react" ;
22import type { EnvironmentId , OrchestrationV2Subagent } from "@t3tools/contracts" ;
33import { useState } from "react" ;
4- import { Alert , Pressable , View } from "react-native" ;
4+ import { View } from "react-native" ;
55
6- import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator" ;
7- import { SymbolView } from "../../components/ui/AppSymbol" ;
8- import { cn } from "../../lib/cn" ;
6+ import * as Dialog from "../../components/ui/Dialog" ;
7+ import { IconButton } from "../../components/ui/IconButton" ;
98import { orchestrationEnvironment } from "../../state/orchestration" ;
109import { threadEnvironment } from "../../state/threads" ;
1110import { useAtomCommand } from "../../state/use-atom-command" ;
@@ -32,55 +31,38 @@ export function SubagentStopButton(props: {
3231 const workflow = target . kind === "workflow" ;
3332 const label =
3433 props . subagent . workflow ?. name ?? resolveSubagentRowPresentation ( props . subagent ) . title ;
35- const confirmStop = ( ) =>
36- Alert . alert (
37- workflow ? "Stop workflow?" : "Stop agent?" ,
38- workflow ? `Every running agent in ${ label } stops.` : `Stop ${ label } ?` ,
39- [
40- { text : "Cancel" , style : "cancel" } ,
41- {
42- text : "Stop" ,
43- style : "destructive" ,
44- onPress : async ( ) => {
45- setStopping ( true ) ;
46- try {
47- const result =
48- target . kind === "workflow"
49- ? await stopWorkflow ( { environmentId : props . environmentId , input : target . input } )
50- : await interruptTurn ( {
51- environmentId : props . environmentId ,
52- input : target . input ,
53- } ) ;
54- if ( result . _tag === "Failure" ) {
55- Alert . alert ( workflow ? "Could not stop workflow" : "Could not stop agent" ) ;
56- }
57- } finally {
58- setStopping ( false ) ;
59- }
60- } ,
61- } ,
62- ] ,
63- ) ;
34+ const stop = async ( ) => {
35+ setStopping ( true ) ;
36+ try {
37+ const result =
38+ target . kind === "workflow"
39+ ? await stopWorkflow ( { environmentId : props . environmentId , input : target . input } )
40+ : await interruptTurn ( { environmentId : props . environmentId , input : target . input } ) ;
41+ if ( result . _tag === "Failure" ) {
42+ Dialog . alert ( workflow ? "Could not stop workflow" : "Could not stop agent" ) ;
43+ }
44+ } finally {
45+ setStopping ( false ) ;
46+ }
47+ } ;
6448
6549 return (
66- < Pressable
67- accessibilityRole = "button"
68- accessibilityLabel = { `Stop ${ workflow ? "workflow" : "agent" } ${ label } ` }
69- accessibilityState = { { disabled : stopping , busy : stopping } }
70- disabled = { stopping }
71- onPress = { confirmStop }
72- className = { cn (
73- "size-11 items-center justify-center active:opacity-70 disabled:opacity-50" ,
74- props . className ,
75- ) }
76- >
77- < View className = "size-6 items-center justify-center rounded-full bg-danger" >
78- { stopping ? (
79- < AppActivityIndicator size = "small" />
80- ) : (
81- < SymbolView name = "stop.fill" size = { 9 } tintColorClassName = "accent-danger-foreground" />
82- ) }
83- </ View >
84- </ Pressable >
50+ < View className = { props . className } >
51+ < IconButton
52+ icon = "stop.fill"
53+ variant = "danger"
54+ accessibilityLabel = { `${ stopping ? "Stopping" : "Stop" } ${ workflow ? "workflow" : "agent" } ${ label } ` }
55+ disabled = { stopping }
56+ onPress = { ( ) =>
57+ Dialog . confirm ( {
58+ title : workflow ? "Stop workflow?" : "Stop agent?" ,
59+ message : workflow ? `Every running agent in ${ label } stops.` : `Stop ${ label } ?` ,
60+ confirmText : "Stop" ,
61+ destructive : true ,
62+ onConfirm : ( ) => void stop ( ) ,
63+ } )
64+ }
65+ />
66+ </ View >
8567 ) ;
8668}
0 commit comments