@@ -6,33 +6,57 @@ import { useTasksApi } from "../hooks/useTasksApi";
66
77import { PromptInput } from "./PromptInput" ;
88
9- function getPlaceholder ( task : Task ) : string {
10- if ( task . status === "error" || task . current_state ?. state === "failed" ) {
11- return "Send a message to retry or give new instructions..." ;
12- }
13- if ( task . status === "paused" ) {
14- return "Send a message to resume the task..." ;
15- }
16- if ( task . status === "pending" || task . status === "initializing" ) {
17- return "Waiting for the agent to start..." ;
18- }
19- if ( task . current_state ?. state === "working" ) {
20- return "Agent is working — you can pause or wait for it to finish..." ;
21- }
22- if ( task . current_state ?. state === "complete" ) {
23- return "Task completed — send a follow-up message to continue..." ;
24- }
25- return "Send a message to the agent..." ;
9+ interface InputState {
10+ placeholder : string ;
11+ canSend : boolean ;
2612}
2713
28- function isInputEnabled ( task : Task ) : boolean {
14+ function getInputState ( task : Task ) : InputState {
2915 const state = task . current_state ?. state ;
30- return (
31- state === "idle" ||
32- state === "complete" ||
33- state === "failed" ||
34- task . status === "paused"
35- ) ;
16+
17+ switch ( task . status ) {
18+ case "paused" :
19+ return {
20+ placeholder : "Send a message to resume the task..." ,
21+ canSend : true ,
22+ } ;
23+ case "initializing" :
24+ case "pending" :
25+ return {
26+ placeholder : "Waiting for the agent to start..." ,
27+ canSend : false ,
28+ } ;
29+ case "active" :
30+ switch ( state ) {
31+ case "working" :
32+ return {
33+ placeholder :
34+ "Agent is working — you can pause or wait for it to finish..." ,
35+ canSend : false ,
36+ } ;
37+ case "complete" :
38+ return {
39+ placeholder : "Task completed — send a follow-up to continue..." ,
40+ canSend : true ,
41+ } ;
42+ case "failed" :
43+ return {
44+ placeholder : "Task failed — send a message to retry..." ,
45+ canSend : true ,
46+ } ;
47+ default :
48+ return {
49+ placeholder : "Send a message to the agent..." ,
50+ canSend : true ,
51+ } ;
52+ }
53+ case "error" :
54+ case "unknown" :
55+ return {
56+ placeholder : "Task is in an error state and cannot receive messages" ,
57+ canSend : false ,
58+ } ;
59+ }
3660}
3761
3862interface TaskMessageInputProps {
@@ -44,35 +68,37 @@ export function TaskMessageInput({ task }: TaskMessageInputProps) {
4468 const [ message , setMessage ] = useState ( "" ) ;
4569
4670 const { canPause } = getTaskPermissions ( task ) ;
47- const inputEnabled = isInputEnabled ( task ) ;
71+ const { placeholder , canSend } = getInputState ( task ) ;
4872 const showPauseButton = task . current_state ?. state === "working" && canPause ;
4973
50- const { mutate : sendMessage , isPending : isSending } = useMutation ( {
51- mutationFn : ( msg : string ) => api . sendTaskMessage ( task . id , msg ) ,
52- onSuccess : ( ) => setMessage ( "" ) ,
53- } ) ;
54-
5574 const { mutate : pauseTask , isPending : isPausing } = useMutation ( {
5675 mutationFn : ( ) =>
5776 api . pauseTask ( { taskId : task . id , taskName : getTaskLabel ( task ) } ) ,
5877 } ) ;
5978
60- const handleSend = ( ) => {
61- if ( ! message . trim ( ) || ! inputEnabled || isSending ) return ;
62- sendMessage ( message . trim ( ) ) ;
63- } ;
79+ const { mutate : sendMessage , isPending : isSending } = useMutation ( {
80+ mutationFn : ( ) => api . sendTaskMessage ( task . id , message ) ,
81+ onSuccess : ( ) => setMessage ( "" ) ,
82+ } ) ;
83+
84+ const canSubmitMessage = canSend && message . trim ( ) . length > 0 ;
6485
6586 return (
66- < PromptInput
67- placeholder = { getPlaceholder ( task ) }
68- value = { message }
69- onChange = { setMessage }
70- onSubmit = { showPauseButton ? pauseTask : handleSend }
71- disabled = { ! inputEnabled }
72- loading = { showPauseButton ? isPausing : isSending }
73- actionIcon = { showPauseButton ? "debug-pause" : "send" }
74- actionLabel = { showPauseButton ? "Pause task" : "Send message" }
75- actionDisabled = { ! showPauseButton && ( ! inputEnabled || ! message . trim ( ) ) }
76- />
87+ < >
88+ < div style = { { fontSize : "11px" , opacity : 0.6 , padding : "2px 8px" } } >
89+ status: { task . status } | state: { task . current_state ?. state ?? "none" }
90+ </ div >
91+ < PromptInput
92+ placeholder = { placeholder }
93+ value = { message }
94+ onChange = { setMessage }
95+ onSubmit = { showPauseButton ? pauseTask : sendMessage }
96+ disabled = { ! canSend && ! showPauseButton }
97+ loading = { showPauseButton ? isPausing : isSending }
98+ actionIcon = { showPauseButton ? "debug-pause" : "send" }
99+ actionLabel = { showPauseButton ? "Pause task" : "Send message" }
100+ actionDisabled = { showPauseButton ? false : ! canSubmitMessage }
101+ />
102+ </ >
77103 ) ;
78104}
0 commit comments