Skip to content

Commit 43a1cd4

Browse files
authored
SDK (#231)
1 parent 8df365e commit 43a1cd4

File tree

16 files changed

+183
-41
lines changed

16 files changed

+183
-41
lines changed

backend/src/__tests__/main-prompt.integration.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { logger } from '../util/logger'
2121
import { renderReadFilesResult } from '../util/parse-tool-call-xml'
2222
import * as websocketAction from '../websockets/websocket-action'
2323

24-
import type { PrintModeObject } from '@codebuff/common/types/print-mode'
24+
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
2525
import type { ProjectFileContext } from '@codebuff/common/util/file'
2626
import type { WebSocket } from 'ws'
2727

@@ -383,7 +383,7 @@ export function getMessagesSubset(messages: Message[], otherTokens: number) {
383383
userId: TEST_USER_ID,
384384
clientSessionId: 'test-session-delete-function-integration',
385385
localAgentTemplates: mockLocalAgentTemplates,
386-
onResponseChunk: (chunk: string | PrintModeObject) => {
386+
onResponseChunk: (chunk: string | PrintModeEvent) => {
387387
if (typeof chunk !== 'string') {
388388
return
389389
}
@@ -479,7 +479,7 @@ export function getMessagesSubset(messages: Message[], otherTokens: number) {
479479
stepPrompt: '',
480480
},
481481
},
482-
onResponseChunk: (chunk: string | PrintModeObject) => {
482+
onResponseChunk: (chunk: string | PrintModeEvent) => {
483483
if (typeof chunk !== 'string') {
484484
return
485485
}

backend/src/main-prompt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { requestToolCall } from './websockets/websocket-action'
1414
import type { ClientToolCall } from './tools/constants'
1515
import type { ClientAction } from '@codebuff/common/actions'
1616
import type { CostMode } from '@codebuff/common/constants'
17-
import type { PrintModeObject } from '@codebuff/common/types/print-mode'
17+
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
1818
import type {
1919
SessionState,
2020
ToolResult,
@@ -25,7 +25,7 @@ import { AgentTemplate } from './templates/types'
2525
export interface MainPromptOptions {
2626
userId: string | undefined
2727
clientSessionId: string
28-
onResponseChunk: (chunk: string | PrintModeObject) => void
28+
onResponseChunk: (chunk: string | PrintModeEvent) => void
2929
localAgentTemplates: Record<string, AgentTemplate>
3030
}
3131

backend/src/run-agent-step.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { getRequestContext } from './websockets/request-context'
4040
import type { AgentTemplate } from '@codebuff/common/types/agent-template'
4141
import type { AgentResponseTrace } from '@codebuff/bigquery'
4242
import type { CodebuffMessage } from '@codebuff/common/types/message'
43-
import type { PrintModeObject } from '@codebuff/common/types/print-mode'
43+
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
4444
import type {
4545
AgentTemplateType,
4646
AgentState,
@@ -54,7 +54,7 @@ export interface AgentOptions {
5454
userInputId: string
5555
clientSessionId: string
5656
fingerprintId: string
57-
onResponseChunk: (chunk: string | PrintModeObject) => void
57+
onResponseChunk: (chunk: string | PrintModeEvent) => void
5858

5959
agentType: AgentTemplateType
6060
fileContext: ProjectFileContext
@@ -516,7 +516,7 @@ export const loopAgentSteps = async (
516516

517517
userId: string | undefined
518518
clientSessionId: string
519-
onResponseChunk: (chunk: string | PrintModeObject) => void
519+
onResponseChunk: (chunk: string | PrintModeEvent) => void
520520
},
521521
) => {
522522
const agentTemplate = await getAgentTemplate(agentType, localAgentTemplates)

backend/src/run-programmatic-step.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
StepGenerator,
1313
} from '@codebuff/common/types/agent-template'
1414
import type { CodebuffToolCall } from './tools/constants'
15-
import type { PrintModeObject } from '@codebuff/common/types/print-mode'
15+
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
1616
import type {
1717
AgentState,
1818
AgentTemplateType,
@@ -63,7 +63,7 @@ export async function runProgrammaticStep(
6363
userInputId: string
6464
clientSessionId: string
6565
fingerprintId: string
66-
onResponseChunk: (chunk: string | PrintModeObject) => void
66+
onResponseChunk: (chunk: string | PrintModeEvent) => void
6767
agentType: AgentTemplateType
6868
fileContext: ProjectFileContext
6969
ws: WebSocket

backend/src/tools/handlers/tool/spawn-agents-async.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { CodebuffToolCall } from '../../constants'
1111
import type { CodebuffToolHandlerFunction } from '../handler-function-type'
1212
import type { SendSubagentChunk } from './spawn-agents'
1313
import type { CodebuffMessage } from '@codebuff/common/types/message'
14-
import type { PrintModeObject } from '@codebuff/common/types/print-mode'
14+
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
1515
import type {
1616
AgentState,
1717
AgentTemplateType,
@@ -129,7 +129,10 @@ export const handleSpawnAgentsAsync = ((params: {
129129
for (const { agent_type: agentTypeStr, prompt, params } of agents) {
130130
try {
131131
const agentType = agentTypeStr as AgentTemplateType
132-
const agentTemplate = await getAgentTemplate(agentType, localAgentTemplates)
132+
const agentTemplate = await getAgentTemplate(
133+
agentType,
134+
localAgentTemplates,
135+
)
133136

134137
if (!agentTemplate) {
135138
throw new Error(`Agent type ${agentTypeStr} not found.`)
@@ -205,7 +208,7 @@ export const handleSpawnAgentsAsync = ((params: {
205208
toolResults: [],
206209
userId,
207210
clientSessionId,
208-
onResponseChunk: (chunk: string | PrintModeObject) => {
211+
onResponseChunk: (chunk: string | PrintModeEvent) => {
209212
if (typeof chunk !== 'string') {
210213
return
211214
}

backend/src/tools/handlers/tool/spawn-agents.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { AgentTemplate } from '@codebuff/common/types/agent-template'
77
import type { CodebuffToolCall } from '../../constants'
88
import type { CodebuffToolHandlerFunction } from '../handler-function-type'
99
import type { CodebuffMessage } from '@codebuff/common/types/message'
10-
import type { PrintModeObject } from '@codebuff/common/types/print-mode'
10+
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
1111
import type {
1212
AgentState,
1313
AgentTemplateType,
@@ -113,7 +113,10 @@ export const handleSpawnAgents = ((params: {
113113
const results = await Promise.allSettled(
114114
agents.map(async ({ agent_type: agentTypeStr, prompt, params }) => {
115115
const agentType = agentTypeStr as AgentTemplateType
116-
const agentTemplate = await getAgentTemplate(agentType, localAgentTemplates)
116+
const agentTemplate = await getAgentTemplate(
117+
agentType,
118+
localAgentTemplates,
119+
)
117120

118121
if (!agentTemplate) {
119122
throw new Error(`Agent type ${agentTypeStr} not found.`)
@@ -191,7 +194,7 @@ export const handleSpawnAgents = ((params: {
191194
toolResults: [],
192195
userId,
193196
clientSessionId,
194-
onResponseChunk: (chunk: string | PrintModeObject) => {
197+
onResponseChunk: (chunk: string | PrintModeEvent) => {
195198
if (typeof chunk !== 'string') {
196199
return
197200
}

backend/src/tools/stream-parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { CodebuffToolCall } from './constants'
1111
import type { AgentTemplate } from '../templates/types'
1212
import type { ToolName } from '@codebuff/common/tools/constants'
1313
import type { CodebuffMessage } from '@codebuff/common/types/message'
14-
import type { PrintModeObject } from '@codebuff/common/types/print-mode'
14+
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
1515
import type {
1616
AgentState,
1717
Subgoal,
@@ -42,7 +42,7 @@ export async function processStreamWithTools<T extends string>(options: {
4242
messages: CodebuffMessage[]
4343
agentState: AgentState
4444
agentContext: Record<string, Subgoal>
45-
onResponseChunk: (chunk: string | PrintModeObject) => void
45+
onResponseChunk: (chunk: string | PrintModeEvent) => void
4646
fullResponse: string
4747
}) {
4848
const {

backend/src/tools/tool-executor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { ClientToolCall, CodebuffToolCall } from './constants'
1414
import type { CodebuffToolHandlerFunction } from './handlers/handler-function-type'
1515
import type { AgentTemplate } from '../templates/types'
1616
import type { ToolName } from '@codebuff/common/tools/constants'
17-
import type { PrintModeObject } from '@codebuff/common/types/print-mode'
17+
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
1818
import type { ToolResult } from '@codebuff/common/types/session-state'
1919
import type { ProjectFileContext } from '@codebuff/common/util/file'
2020
import type { WebSocket } from 'ws'
@@ -105,7 +105,7 @@ export interface ExecuteToolCallParams<T extends ToolName = ToolName> {
105105
clientSessionId: string
106106
userInputId: string
107107
fullResponse: string
108-
onResponseChunk: (chunk: string | PrintModeObject) => void
108+
onResponseChunk: (chunk: string | PrintModeEvent) => void
109109
state: Record<string, any>
110110
userId: string | undefined
111111
autoInsertEndStepParam?: boolean

common/src/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { z } from 'zod'
22

33
import { costModes } from './constants'
44
import { GrantTypeValues } from './types/grant'
5-
import { printModeObjectSchema } from './types/print-mode'
5+
import { printModeEventSchema } from './types/print-mode'
66
import {
77
SessionStateSchema,
88
toolCallSchema,
@@ -132,7 +132,7 @@ export const SERVER_ACTION_SCHEMA = z.discriminatedUnion('type', [
132132
z.object({
133133
type: z.literal('response-chunk'),
134134
userInputId: z.string(),
135-
chunk: z.union([z.string(), printModeObjectSchema]),
135+
chunk: z.union([z.string(), printModeEventSchema]),
136136
}),
137137
z.object({
138138
type: z.literal('subagent-response-chunk'),

common/src/types/print-mode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const printModeFinishSchema = z.object({
4343
})
4444
export type PrintModeFinish = z.infer<typeof printModeFinishSchema>
4545

46-
export const printModeObjectSchema = z.discriminatedUnion('type', [
46+
export const printModeEventSchema = z.discriminatedUnion('type', [
4747
printModeErrorSchema,
4848
printModeDownloadStatusSchema,
4949
printModeFinishSchema,
@@ -52,4 +52,4 @@ export const printModeObjectSchema = z.discriminatedUnion('type', [
5252
printModeToolResultSchema,
5353
])
5454

55-
export type PrintModeObject = z.infer<typeof printModeObjectSchema>
55+
export type PrintModeEvent = z.infer<typeof printModeEventSchema>

0 commit comments

Comments
 (0)