Skip to content

Commit a00476c

Browse files
authored
move tool params to common (#225)
1 parent aaa5b57 commit a00476c

File tree

82 files changed

+1181
-1202
lines changed

Some content is hidden

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

82 files changed

+1181
-1202
lines changed

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { WebSocket } from 'ws'
1313
import { mainPrompt } from '../main-prompt'
1414

1515
// Mock imports needed for setup within the test
16-
import { getToolCallString } from '@codebuff/common/constants/tools'
16+
import { getToolCallString } from '@codebuff/common/tools/utils'
1717
import { PrintModeObject } from '@codebuff/common/types/print-mode'
1818
import { ProjectFileContext } from '@codebuff/common/util/file'
1919
import * as checkTerminalCommandModule from '../check-terminal-command'
@@ -325,13 +325,9 @@ export function getMessagesSubset(messages: Message[], otherTokens: number) {
325325
sessionState.mainAgentState.messageHistory.push(
326326
{
327327
role: 'assistant',
328-
content: getToolCallString(
329-
'read_files',
330-
{
331-
paths: 'src/util/messages.ts',
332-
},
333-
true
334-
),
328+
content: getToolCallString('read_files', {
329+
paths: 'src/util/messages.ts',
330+
}),
335331
},
336332
{
337333
role: 'user',
@@ -413,13 +409,9 @@ export function getMessagesSubset(messages: Message[], otherTokens: number) {
413409
sessionState.mainAgentState.messageHistory.push(
414410
{
415411
role: 'assistant',
416-
content: getToolCallString(
417-
'read_files',
418-
{
419-
paths: 'packages/backend/src/index.ts',
420-
},
421-
true
422-
),
412+
content: getToolCallString('read_files', {
413+
paths: 'packages/backend/src/index.ts',
414+
}),
423415
},
424416
{
425417
role: 'user',

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

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import * as aisdk from '../llm-apis/vercel-ai-sdk/ai-sdk'
2323
import { mainPrompt } from '../main-prompt'
2424
import * as processFileBlockModule from '../process-file-block'
2525

26-
import {
27-
getToolCallString,
28-
renderToolResults,
29-
} from '@codebuff/common/constants/tools'
3026
import {
3127
clearMockedModules,
3228
mockModule,
3329
} from '@codebuff/common/testing/mock-modules'
30+
import {
31+
getToolCallString,
32+
renderToolResults,
33+
} from '@codebuff/common/tools/utils'
3434
import { ProjectFileContext } from '@codebuff/common/util/file'
3535
import * as getDocumentationForQueryModule from '../get-documentation-for-query'
3636
import * as websocketAction from '../websockets/websocket-action'
@@ -303,15 +303,11 @@ describe('mainPrompt', () => {
303303
it('should handle write_file tool call', async () => {
304304
// Mock LLM to return a write_file tool call using getToolCallString
305305
const mockResponse =
306-
getToolCallString(
307-
'write_file',
308-
{
309-
path: 'new-file.txt',
310-
instructions: 'Added Hello World',
311-
content: 'Hello, world!',
312-
},
313-
false
314-
) + getToolCallString('end_turn', {}, true)
306+
getToolCallString('write_file', {
307+
path: 'new-file.txt',
308+
instructions: 'Added Hello World',
309+
content: 'Hello, world!',
310+
}) + getToolCallString('end_turn', {})
315311

316312
mockAgentStream(mockResponse)
317313

@@ -478,14 +474,10 @@ describe('mainPrompt', () => {
478474
const expectedCommand = 'cd backend && bun test'
479475

480476
const mockResponse =
481-
getToolCallString(
482-
'run_terminal_command',
483-
{
484-
command: escapedCommand,
485-
process_type: 'SYNC',
486-
},
487-
true
488-
) + getToolCallString('end_turn', {}, true)
477+
getToolCallString('run_terminal_command', {
478+
command: escapedCommand,
479+
process_type: 'SYNC',
480+
}) + getToolCallString('end_turn', {})
489481

490482
mockAgentStream(mockResponse)
491483

backend/src/__tests__/read-docs-tool.test.ts

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as bigquery from '@codebuff/bigquery'
22
import * as analytics from '@codebuff/common/analytics'
33
import { TEST_USER_ID } from '@codebuff/common/constants'
4-
import { getToolCallString } from '@codebuff/common/constants/tools'
54
import {
65
clearMockedModules,
76
mockModule,
87
} from '@codebuff/common/testing/mock-modules'
8+
import { getToolCallString } from '@codebuff/common/tools/utils'
99
import { getInitialSessionState } from '@codebuff/common/types/session-state'
1010
import {
1111
afterAll,
@@ -97,13 +97,9 @@ describe('read_docs tool with researcher agent', () => {
9797
)
9898

9999
const mockResponse =
100-
getToolCallString(
101-
'read_docs',
102-
{
103-
libraryTitle: 'React',
104-
},
105-
true
106-
) + getToolCallString('end_turn', {}, true)
100+
getToolCallString('read_docs', {
101+
libraryTitle: 'React',
102+
}) + getToolCallString('end_turn', {})
107103

108104
spyOn(aisdk, 'promptAiSdkStream').mockImplementation(async function* () {
109105
yield mockResponse
@@ -162,15 +158,11 @@ describe('read_docs tool with researcher agent', () => {
162158
)
163159

164160
const mockResponse =
165-
getToolCallString(
166-
'read_docs',
167-
{
168-
libraryTitle: 'React',
169-
topic: 'hooks',
170-
max_tokens: 5000,
171-
},
172-
true
173-
) + getToolCallString('end_turn', {}, true)
161+
getToolCallString('read_docs', {
162+
libraryTitle: 'React',
163+
topic: 'hooks',
164+
max_tokens: 5000,
165+
}) + getToolCallString('end_turn', {})
174166

175167
spyOn(aisdk, 'promptAiSdkStream').mockImplementation(async function* () {
176168
yield mockResponse
@@ -214,13 +206,9 @@ describe('read_docs tool with researcher agent', () => {
214206
)
215207

216208
const mockResponse =
217-
getToolCallString(
218-
'read_docs',
219-
{
220-
libraryTitle: 'NonExistentLibrary',
221-
},
222-
true
223-
) + getToolCallString('end_turn', {}, true)
209+
getToolCallString('read_docs', {
210+
libraryTitle: 'NonExistentLibrary',
211+
}) + getToolCallString('end_turn', {})
224212

225213
spyOn(aisdk, 'promptAiSdkStream').mockImplementation(async function* () {
226214
yield mockResponse
@@ -275,13 +263,9 @@ describe('read_docs tool with researcher agent', () => {
275263
)
276264

277265
const mockResponse =
278-
getToolCallString(
279-
'read_docs',
280-
{
281-
libraryTitle: 'React',
282-
},
283-
true
284-
) + getToolCallString('end_turn', {}, true)
266+
getToolCallString('read_docs', {
267+
libraryTitle: 'React',
268+
}) + getToolCallString('end_turn', {})
285269

286270
spyOn(aisdk, 'promptAiSdkStream').mockImplementation(async function* () {
287271
yield mockResponse
@@ -335,14 +319,10 @@ describe('read_docs tool with researcher agent', () => {
335319
)
336320

337321
const mockResponse =
338-
getToolCallString(
339-
'read_docs',
340-
{
341-
libraryTitle: 'React',
342-
topic: 'server-components',
343-
},
344-
true
345-
) + getToolCallString('end_turn', {}, true)
322+
getToolCallString('read_docs', {
323+
libraryTitle: 'React',
324+
topic: 'server-components',
325+
}) + getToolCallString('end_turn', {})
346326

347327
spyOn(aisdk, 'promptAiSdkStream').mockImplementation(async function* () {
348328
yield mockResponse
@@ -395,13 +375,9 @@ describe('read_docs tool with researcher agent', () => {
395375
)
396376

397377
const mockResponse =
398-
getToolCallString(
399-
'read_docs',
400-
{
401-
libraryTitle: 'React',
402-
},
403-
true
404-
) + getToolCallString('end_turn', {}, true)
378+
getToolCallString('read_docs', {
379+
libraryTitle: 'React',
380+
}) + getToolCallString('end_turn', {})
405381

406382
spyOn(aisdk, 'promptAiSdkStream').mockImplementation(async function* () {
407383
yield mockResponse

backend/src/__tests__/run-agent-step-tools.test.ts

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as bigquery from '@codebuff/bigquery'
22
import * as analytics from '@codebuff/common/analytics'
33
import { TEST_USER_ID } from '@codebuff/common/constants'
4-
import { getToolCallString } from '@codebuff/common/constants/tools'
4+
import { getToolCallString } from '@codebuff/common/tools/utils'
55
import { getInitialSessionState } from '@codebuff/common/types/session-state'
66
import { ProjectFileContext } from '@codebuff/common/util/file'
77
import {
@@ -135,15 +135,11 @@ describe('runAgentStep - set_output tool', () => {
135135

136136
it('should set output with simple key-value pair', async () => {
137137
const mockResponse =
138-
getToolCallString(
139-
'set_output',
140-
{
141-
message: 'Hi',
142-
},
143-
false
144-
) +
138+
getToolCallString('set_output', {
139+
message: 'Hi',
140+
}) +
145141
'\n\n' +
146-
getToolCallString('end_turn', {}, true)
142+
getToolCallString('end_turn', {})
147143

148144
spyOn(aisdk, 'promptAiSdkStream').mockImplementation(async function* () {
149145
yield mockResponse
@@ -180,15 +176,11 @@ describe('runAgentStep - set_output tool', () => {
180176

181177
it('should set output with complex data', async () => {
182178
const mockResponse =
183-
getToolCallString(
184-
'set_output',
185-
{
186-
message: 'Analysis complete',
187-
status: 'success',
188-
findings: ['Bug in auth.ts', 'Missing validation'],
189-
},
190-
false
191-
) + getToolCallString('end_turn', {}, true)
179+
getToolCallString('set_output', {
180+
message: 'Analysis complete',
181+
status: 'success',
182+
findings: ['Bug in auth.ts', 'Missing validation'],
183+
}) + getToolCallString('end_turn', {})
192184
console.log('mockResponse', mockResponse)
193185

194186
spyOn(aisdk, 'promptAiSdkStream').mockImplementation(async function* () {
@@ -228,14 +220,10 @@ describe('runAgentStep - set_output tool', () => {
228220

229221
it('should replace existing output data', async () => {
230222
const mockResponse =
231-
getToolCallString(
232-
'set_output',
233-
{
234-
newField: 'new value',
235-
existingField: 'updated value',
236-
},
237-
false
238-
) + getToolCallString('end_turn', {}, true)
223+
getToolCallString('set_output', {
224+
newField: 'new value',
225+
existingField: 'updated value',
226+
}) + getToolCallString('end_turn', {})
239227

240228
spyOn(aisdk, 'promptAiSdkStream').mockImplementation(async function* () {
241229
yield mockResponse
@@ -277,8 +265,7 @@ describe('runAgentStep - set_output tool', () => {
277265

278266
it('should handle empty output parameter', async () => {
279267
const mockResponse =
280-
getToolCallString('set_output', {}, false) +
281-
getToolCallString('end_turn', {}, true)
268+
getToolCallString('set_output', {}) + getToolCallString('end_turn', {})
282269

283270
spyOn(aisdk, 'promptAiSdkStream').mockImplementation(async function* () {
284271
yield mockResponse

backend/src/__tests__/run-programmatic-step.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import {
1818
} from 'bun:test'
1919
import { WebSocket } from 'ws'
2020

21-
import { renderToolResults } from '@codebuff/common/constants/tools'
2221
import {
2322
clearMockedModules,
2423
mockModule,
2524
} from '@codebuff/common/testing/mock-modules'
25+
import { renderToolResults } from '@codebuff/common/tools/utils'
2626
import {
2727
clearAgentGeneratorCache,
2828
runProgrammaticStep,

0 commit comments

Comments
 (0)