11import path from 'path'
22
3- import { API_KEY_ENV_VAR } from '@codebuff/common/old-constants'
43import { MAX_AGENT_STEPS_DEFAULT } from '@codebuff/common/constants/agents'
4+ import { API_KEY_ENV_VAR } from '@codebuff/common/old-constants'
55import { loadLocalAgents } from '@codebuff/npm-app/agents/load-agents'
66import { getUserCredentials } from '@codebuff/npm-app/credentials'
77
@@ -41,9 +41,6 @@ export class CodebuffRunner implements Runner {
4141 const client = new CodebuffClient ( {
4242 apiKey,
4343 cwd : this . runState . sessionState . fileContext . cwd ,
44- onError : ( error ) => {
45- throw new Error ( error . message )
46- } ,
4744 } )
4845
4946 const agentsPath = path . join ( __dirname , '../../../.agents' )
@@ -57,13 +54,15 @@ export class CodebuffRunner implements Runner {
5754 localAgentDefinitions . map ( ( a ) => a . id ) ,
5855 )
5956
60- this . runState = await client . run ( {
57+ let lastErrorMessage = ''
58+ const run = await client . run ( {
6159 agent : this . agent ,
6260 previousRun : this . runState ,
6361 prompt,
6462 handleEvent : ( event ) => {
6563 if ( event . type === 'error' ) {
6664 console . log ( '\n\n' + JSON . stringify ( event , null , 2 ) )
65+ lastErrorMessage = event . message
6766 }
6867 if ( event . type === 'text' ) {
6968 if ( toolResults . length > 0 ) {
@@ -98,7 +97,11 @@ export class CodebuffRunner implements Runner {
9897 } )
9998 flushStep ( )
10099
101- client . closeConnection ( )
100+ if ( ! run ) {
101+ throw new Error ( `Failed to run Codebuff:\n${ lastErrorMessage } ` )
102+ }
103+
104+ this . runState = run
102105
103106 return {
104107 steps,
0 commit comments