Skip to content

Commit e106c6d

Browse files
committed
No null return from sdk.run()
1 parent b40c698 commit e106c6d

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

sdk/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class CodebuffClient {
5656
*/
5757
public async run(
5858
options: RunOptions & CodebuffClientOptions,
59-
): Promise<RunState | null> {
59+
): Promise<RunState> {
6060
return run({ ...this.options, ...options })
6161
}
6262
}

sdk/src/run.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export async function run({
9292
}: RunOptions &
9393
Required<CodebuffClientOptions> & {
9494
fingerprintId: string
95-
}): Promise<RunState | null> {
95+
}): Promise<RunState> {
9696
function onError(error: { message: string }) {
9797
handleEvent({ type: 'error', message: error.message })
9898
}
@@ -137,9 +137,19 @@ export async function run({
137137
onSubagentResponseChunk: async () => {},
138138

139139
onPromptResponse: (action) =>
140-
handlePromptResponse({ action, resolve, onError }),
140+
handlePromptResponse({
141+
action,
142+
resolve,
143+
onError,
144+
initialSessionState: sessionState,
145+
}),
141146
onPromptError: (action) =>
142-
handlePromptResponse({ action, resolve, onError }),
147+
handlePromptResponse({
148+
action,
149+
resolve,
150+
onError,
151+
initialSessionState: sessionState,
152+
}),
143153
})
144154

145155
// Init session state
@@ -306,14 +316,22 @@ async function handlePromptResponse({
306316
action,
307317
resolve,
308318
onError,
319+
initialSessionState,
309320
}: {
310321
action: ServerAction<'prompt-response'> | ServerAction<'prompt-error'>
311322
resolve: (value: RunReturnType) => any
312323
onError: (error: { message: string }) => void
324+
initialSessionState: SessionState
313325
}) {
314326
if (action.type === 'prompt-error') {
315327
onError({ message: action.message })
316-
resolve(null)
328+
resolve({
329+
sessionState: initialSessionState,
330+
output: {
331+
type: 'error',
332+
message: action.message,
333+
},
334+
})
317335
} else if (action.type === 'prompt-response') {
318336
const parsedAction = PromptResponseSchema.safeParse(action)
319337
if (!parsedAction.success) {
@@ -325,7 +343,13 @@ async function handlePromptResponse({
325343
onError({
326344
message: message,
327345
})
328-
resolve(null)
346+
resolve({
347+
sessionState: initialSessionState,
348+
output: {
349+
type: 'error',
350+
message: message,
351+
},
352+
})
329353
return
330354
}
331355

@@ -343,6 +367,12 @@ async function handlePromptResponse({
343367
onError({
344368
message: 'Internal error: prompt response type not handled',
345369
})
346-
resolve(null)
370+
resolve({
371+
sessionState: initialSessionState,
372+
output: {
373+
type: 'error',
374+
message: 'Internal error: prompt response type not handled',
375+
},
376+
})
347377
}
348378
}

0 commit comments

Comments
 (0)