@@ -30,6 +30,7 @@ import type {
3030} from '../../common/src/types/messages/content-part'
3131import type { PrintModeEvent } from '../../common/src/types/print-mode'
3232import type { SessionState } from '../../common/src/types/session-state'
33+ import { MAX_AGENT_STEPS_DEFAULT } from '../../common/src/constants/agents'
3334
3435export type CodebuffClientOptions = {
3536 // Provide an API key or set the CODEBUFF_API_KEY environment variable.
@@ -72,11 +73,11 @@ export async function run({
7273 apiKey,
7374 fingerprintId,
7475
75- cwd,
76+ cwd = process . cwd ( ) ,
7677 projectFiles,
7778 knowledgeFiles,
7879 agentDefinitions,
79- maxAgentSteps,
80+ maxAgentSteps = MAX_AGENT_STEPS_DEFAULT ,
8081
8182 handleEvent,
8283 handleStreamChunk,
@@ -90,11 +91,14 @@ export async function run({
9091 previousRun,
9192 extraToolResults,
9293} : RunOptions &
93- Required < CodebuffClientOptions > & {
94+ CodebuffClientOptions & {
95+ apiKey : string
9496 fingerprintId : string
9597 } ) : Promise < RunState > {
9698 function onError ( error : { message : string } ) {
97- handleEvent ( { type : 'error' , message : error . message } )
99+ if ( handleEvent ) {
100+ handleEvent ( { type : 'error' , message : error . message } )
101+ }
98102 }
99103
100104 let resolve : ( value : RunReturnType ) => any = ( ) => { }
@@ -114,24 +118,26 @@ export async function run({
114118 onError ( { message : error . message } )
115119 } ,
116120 readFiles : ( { filePaths } ) =>
117- readFiles ( { filePaths, override : overrideTools . read_files , cwd } ) ,
121+ readFiles ( { filePaths, override : overrideTools ? .read_files , cwd } ) ,
118122 handleToolCall : ( action ) =>
119123 handleToolCall ( {
120124 action,
121- overrides : overrideTools ,
122- customToolDefinitions : Object . fromEntries (
123- customToolDefinitions . map ( ( def ) => [ def . toolName , def ] ) ,
124- ) ,
125+ overrides : overrideTools ?? { } ,
126+ customToolDefinitions : customToolDefinitions
127+ ? Object . fromEntries (
128+ customToolDefinitions . map ( ( def ) => [ def . toolName , def ] ) ,
129+ )
130+ : { } ,
125131 cwd,
126132 } ) ,
127133 onCostResponse : async ( ) => { } ,
128134
129135 onResponseChunk : async ( action ) => {
130136 const { userInputId, chunk } = action
131137 if ( typeof chunk === 'string' ) {
132- handleStreamChunk ( chunk )
138+ handleStreamChunk ?. ( chunk )
133139 } else {
134- handleEvent ( chunk )
140+ handleEvent ?. ( chunk )
135141 }
136142 } ,
137143 onSubagentResponseChunk : async ( ) => { } ,
0 commit comments