11import { createAsyncThunk } from "@reduxjs/toolkit" ;
22import posthog from "posthog-js" ;
3- import { cancelToolCall as cancelToolCallAction } from "../slices/sessionSlice" ;
3+ import {
4+ cancelToolCall as cancelToolCallAction ,
5+ updateToolCallOutput ,
6+ } from "../slices/sessionSlice" ;
47import { ThunkApiType } from "../store" ;
58import { findToolCallById } from "../util" ;
9+ import { streamResponseAfterToolCall } from "./streamResponseAfterToolCall" ;
10+
11+ const DEFAULT_USER_REJECTION_MESSAGE = `The user skipped the tool call.
12+ If the tool call is optional or non-critical to the main goal, skip it and continue with the next step.
13+ If the tool call is essential, try an alternative approach.
14+ If no alternatives exist, offer to pause here.` ;
615
716export const cancelToolCallThunk = createAsyncThunk <
817 void ,
918 { toolCallId : string } ,
1019 ThunkApiType
1120> ( "chat/cancelToolCall" , async ( { toolCallId } , { dispatch, getState } ) => {
1221 const state = getState ( ) ;
22+ const continueAfterToolRejection =
23+ state . config . config . ui ?. continueAfterToolRejection ;
1324 const toolCallState = findToolCallById ( state . session . history , toolCallId ) ;
1425
1526 if ( toolCallState ) {
@@ -21,6 +32,26 @@ export const cancelToolCallThunk = createAsyncThunk<
2132 } ) ;
2233 }
2334
35+ if ( continueAfterToolRejection ) {
36+ // Update tool call output with rejection message
37+ dispatch (
38+ updateToolCallOutput ( {
39+ toolCallId,
40+ contextItems : [
41+ {
42+ icon : "problems" ,
43+ name : "Tool Call Rejected" ,
44+ description : "User skipped the tool call" ,
45+ content : DEFAULT_USER_REJECTION_MESSAGE ,
46+ hidden : true ,
47+ } ,
48+ ] ,
49+ } ) ,
50+ ) ;
51+ }
52+
2453 // Dispatch the actual cancel action
2554 dispatch ( cancelToolCallAction ( { toolCallId } ) ) ;
55+
56+ void dispatch ( streamResponseAfterToolCall ( { toolCallId } ) ) ;
2657} ) ;
0 commit comments