Skip to content

Commit 3d29edc

Browse files
committed
allow async handlers for stream chunk and events
1 parent d6117c0 commit 3d29edc

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@codebuff/sdk",
33
"private": false,
4-
"version": "0.3.4",
4+
"version": "0.3.5",
55
"description": "Official SDK for Codebuff — AI coding agent & framework",
66
"license": "Apache-2.0",
77
"type": "module",

sdk/src/run.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getFiles } from './tools/read-files'
77
import { runTerminalCommand } from './tools/run-terminal-command'
88
import { WebSocketHandler } from './websocket-client'
99
import { PromptResponseSchema } from '../../common/src/actions'
10+
import { MAX_AGENT_STEPS_DEFAULT } from '../../common/src/constants/agents'
1011
import { toolNames } from '../../common/src/tools/constants'
1112
import { clientToolCallSchema } from '../../common/src/tools/list'
1213

@@ -30,7 +31,6 @@ import type {
3031
} from '../../common/src/types/messages/content-part'
3132
import type { PrintModeEvent } from '../../common/src/types/print-mode'
3233
import type { SessionState } from '../../common/src/types/session-state'
33-
import { MAX_AGENT_STEPS_DEFAULT } from '../../common/src/constants/agents'
3434

3535
export 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

Comments
 (0)