@@ -7,6 +7,7 @@ import { getFiles } from './tools/read-files'
77import { runTerminalCommand } from './tools/run-terminal-command'
88import { WebSocketHandler } from './websocket-client'
99import { PromptResponseSchema } from '../../common/src/actions'
10+ import { MAX_AGENT_STEPS_DEFAULT } from '../../common/src/constants/agents'
1011import { toolNames } from '../../common/src/tools/constants'
1112import { clientToolCallSchema } from '../../common/src/tools/list'
1213
@@ -30,7 +31,6 @@ import type {
3031} from '../../common/src/types/messages/content-part'
3132import type { PrintModeEvent } from '../../common/src/types/print-mode'
3233import type { SessionState } from '../../common/src/types/session-state'
33- import { MAX_AGENT_STEPS_DEFAULT } from '../../common/src/constants/agents'
3434
3535export type CodebuffClientOptions = {
3636 // Provide an API key or set the CODEBUFF_API_KEY environment variable.
@@ -42,8 +42,8 @@ export type CodebuffClientOptions = {
4242 agentDefinitions ?: AgentDefinition [ ]
4343 maxAgentSteps ?: number
4444
45- handleEvent ?: ( event : PrintModeEvent ) => void
46- handleStreamChunk ?: ( chunk : string ) => void
45+ handleEvent ?: ( event : PrintModeEvent ) => void | Promise < void >
46+ handleStreamChunk ?: ( chunk : string ) => void | Promise < void >
4747
4848 overrideTools ?: Partial <
4949 {
@@ -95,9 +95,9 @@ export async function run({
9595 apiKey : string
9696 fingerprintId : string
9797 } ) : Promise < RunState > {
98- function onError ( error : { message : string } ) {
98+ async function onError ( error : { message : string } ) {
9999 if ( handleEvent ) {
100- handleEvent ( { type : 'error' , message : error . message } )
100+ await handleEvent ( { type : 'error' , message : error . message } )
101101 }
102102 }
103103
@@ -139,9 +139,9 @@ export async function run({
139139 onResponseChunk : async ( action ) => {
140140 const { userInputId, chunk } = action
141141 if ( typeof chunk === 'string' ) {
142- handleStreamChunk ?.( chunk )
142+ await handleStreamChunk ?.( chunk )
143143 } else {
144- handleEvent ?.( chunk )
144+ await handleEvent ?.( chunk )
145145 }
146146 } ,
147147 onSubagentResponseChunk : async ( ) => { } ,
0 commit comments