Skip to content

Commit 912f8fb

Browse files
authored
Tool tweaks (#380)
1 parent a224399 commit 912f8fb

File tree

99 files changed

+2523
-2652
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2523
-2652
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getToolCallString } from '@codebuff/common/tools/utils'
77
import { getInitialSessionState } from '@codebuff/common/types/session-state'
88
import {
99
assistantMessage,
10-
toolJsonContent,
10+
jsonToolResult,
1111
} from '@codebuff/common/util/messages'
1212
import { afterEach, beforeEach, describe, expect, it, mock } from 'bun:test'
1313

@@ -342,12 +342,10 @@ export function getMessagesSubset(messages: Message[], otherTokens: number) {
342342
role: 'tool',
343343
toolName: 'read_files',
344344
toolCallId: 'test-id',
345-
content: [
346-
toolJsonContent({
347-
path: 'src/util/messages.ts',
348-
content: initialContent,
349-
}),
350-
],
345+
content: jsonToolResult({
346+
path: 'src/util/messages.ts',
347+
content: initialContent,
348+
}),
351349
},
352350
)
353351

@@ -415,12 +413,10 @@ export function getMessagesSubset(messages: Message[], otherTokens: number) {
415413
role: 'tool',
416414
toolName: 'read_files',
417415
toolCallId: 'test-id',
418-
content: [
419-
toolJsonContent({
420-
path: 'packages/backend/src/index.ts',
421-
content: initialContent,
422-
}),
423-
],
416+
content: jsonToolResult({
417+
path: 'packages/backend/src/index.ts',
418+
content: initialContent,
419+
}),
424420
},
425421
)
426422

backend/src/websockets/server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { setSessionConnected } from '@codebuff/agent-runtime/live-user-inputs'
2-
import { CLIENT_MESSAGE_SCHEMA } from '@codebuff/common/websockets/websocket-schema'
32
import { isError } from 'lodash'
43
import { WebSocketServer } from 'ws'
54

@@ -50,7 +49,7 @@ async function processMessage(params: {
5049
}
5150

5251
try {
53-
const msg = CLIENT_MESSAGE_SCHEMA.parse(messageObj)
52+
const msg = messageObj
5453
const { type, txid } = msg
5554
switch (type) {
5655
case 'subscribe': {

backend/src/websockets/websocket-action.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import {
22
cancelUserInput,
33
startUserInput,
44
} from '@codebuff/agent-runtime/live-user-inputs'
5+
import { callMainPrompt } from '@codebuff/agent-runtime/main-prompt'
56
import { calculateUsageAndBalance } from '@codebuff/billing'
67
import { trackEvent } from '@codebuff/common/analytics'
78
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
9+
import { getErrorObject } from '@codebuff/common/util/error'
810
import db from '@codebuff/internal/db/index'
911
import * as schema from '@codebuff/internal/db/schema'
10-
import { getErrorObject } from '@codebuff/common/util/error'
1112
import { eq } from 'drizzle-orm'
1213

1314
import { protec } from './middleware'
@@ -22,7 +23,6 @@ import type { Logger } from '@codebuff/common/types/contracts/logger'
2223
import type { ParamsExcluding } from '@codebuff/common/types/function-params'
2324
import type { ClientMessage } from '@codebuff/common/websockets/websocket-schema'
2425
import type { WebSocket } from 'ws'
25-
import { callMainPrompt } from '@codebuff/agent-runtime/main-prompt'
2626

2727
/**
2828
* Generates a usage response object for the client
@@ -330,9 +330,12 @@ export const onWebsocketAction = async (params: {
330330
}
331331

332332
// Register action handlers
333-
subscribeToAction('prompt', protec.run({ baseAction: onPrompt }))
334-
subscribeToAction('init', protec.run({ baseAction: onInit, silent: true }))
333+
subscribeToAction('prompt', protec.run<'prompt'>({ baseAction: onPrompt }))
334+
subscribeToAction(
335+
'init',
336+
protec.run<'init'>({ baseAction: onInit, silent: true }),
337+
)
335338
subscribeToAction(
336339
'cancel-user-input',
337-
protec.run({ baseAction: onCancelUserInput }),
340+
protec.run<'cancel-user-input'>({ baseAction: onCancelUserInput }),
338341
)

0 commit comments

Comments
 (0)