Skip to content

Commit b0d6512

Browse files
committed
Don't enforce prompt response schema in client/sdk
1 parent e94ba41 commit b0d6512

File tree

2 files changed

+19
-36
lines changed

2 files changed

+19
-36
lines changed

npm-app/src/client.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,31 +1452,15 @@ export class Client {
14521452
unsubscribeComplete = this.webSocket.subscribe(
14531453
'prompt-response',
14541454
async (action) => {
1455-
const parsedAction = PromptResponseSchema.safeParse(action)
1456-
if (!parsedAction.success) {
1457-
const message = [
1458-
'Received invalid prompt response from server:',
1459-
JSON.stringify(parsedAction.error.issues),
1460-
'If this issues persists, please contact support@codebuff.com',
1461-
].join('\n')
1462-
console.error(message)
1463-
logger.error(
1464-
{
1465-
errorMessage: message,
1466-
action,
1467-
eventId: AnalyticsEvent.MALFORMED_PROMPT_RESPONSE,
1468-
},
1469-
'Malformed prompt response',
1470-
)
1471-
return
1472-
}
1455+
// Stop enforcing prompt response schema (e.g. PromptResponseSchema.parse(action))!
1456+
// It's a black box we will pass back to the server.
1457+
14731458
if (action.promptId !== userInputId) return
1474-
const a = parsedAction.data
14751459
this.responseComplete = true
14761460

14771461
Spinner.get().stop()
14781462

1479-
this.sessionState = a.sessionState
1463+
this.sessionState = action.sessionState
14801464
const toolResults: ToolResultPart[] = []
14811465

14821466
stepsCount++
@@ -1543,8 +1527,8 @@ Go to https://www.codebuff.com/config for more information.`) +
15431527
}
15441528

15451529
// Print structured output as JSON if available
1546-
if (a.output?.type === 'structuredOutput') {
1547-
console.log('\n' + JSON.stringify(a.output.value, null, 2))
1530+
if (action.output?.type === 'structuredOutput') {
1531+
console.log('\n' + JSON.stringify(action.output.value, null, 2))
15481532
}
15491533

15501534
if (DiffManager.getChanges().length > 0) {
@@ -1586,7 +1570,7 @@ Go to https://www.codebuff.com/config for more information.`) +
15861570
// Clear the onChunk callback when response is complete
15871571
this.currentOnChunk = undefined
15881572

1589-
resolveResponse({ ...a, wasStoppedByUser: false })
1573+
resolveResponse({ ...action, wasStoppedByUser: false })
15901574
},
15911575
)
15921576

sdk/src/run.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ import type {
3232
ToolResultPart,
3333
} from '../../common/src/types/messages/content-part'
3434
import type { PrintModeEvent } from '../../common/src/types/print-mode'
35-
import type { SessionState } from '../../common/src/types/session-state'
35+
import {
36+
AgentOutputSchema,
37+
type SessionState,
38+
} from '../../common/src/types/session-state'
3639

3740
export type CodebuffClientOptions = {
3841
// Provide an API key or set the CODEBUFF_API_KEY environment variable.
@@ -360,27 +363,23 @@ async function handlePromptResponse({
360363
},
361364
})
362365
} else if (action.type === 'prompt-response') {
363-
const parsedAction = PromptResponseSchema.safeParse(action)
364-
if (!parsedAction.success) {
366+
// Stop enforcing session state schema! It's a black box we will pass back to the server.
367+
// Only check the output schema.
368+
const parsedOutput = AgentOutputSchema.safeParse(action.output)
369+
if (!parsedOutput.success) {
365370
const message = [
366371
'Received invalid prompt response from server:',
367-
JSON.stringify(parsedAction.error.issues),
372+
JSON.stringify(parsedOutput.error.issues),
368373
'If this issues persists, please contact support@codebuff.com',
369374
].join('\n')
370-
onError({
371-
message: message,
372-
})
375+
onError({ message })
373376
resolve({
374377
sessionState: initialSessionState,
375-
output: {
376-
type: 'error',
377-
message: message,
378-
},
378+
output: { type: 'error', message },
379379
})
380380
return
381381
}
382-
383-
const { sessionState, output } = parsedAction.data
382+
const { sessionState, output } = action
384383
const state: RunState = {
385384
sessionState,
386385
output: output ?? {

0 commit comments

Comments
 (0)