Skip to content

Commit 5cbe9d4

Browse files
authored
[Render Preview] Zod 4 & AI SDK 5 (#239)
1 parent 845b985 commit 5cbe9d4

File tree

146 files changed

+1054
-5795
lines changed

Some content is hidden

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

146 files changed

+1054
-5795
lines changed

.agents/changes-reviewer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Use the following guidelines to review the changes and suggest improvements:
4747
// Step 1: Get list of changed files from git diff
4848
const { toolResult: gitDiffResult } = yield {
4949
toolName: 'run_terminal_command',
50-
args: {
50+
input: {
5151
command: 'git diff HEAD --name-only',
5252
process_type: 'SYNC',
5353
timeout_seconds: 30,
@@ -57,7 +57,7 @@ Use the following guidelines to review the changes and suggest improvements:
5757
// Step 2: Get untracked files from git status
5858
const { toolResult: gitStatusResult } = yield {
5959
toolName: 'run_terminal_command',
60-
args: {
60+
input: {
6161
command: 'git status --porcelain',
6262
process_type: 'SYNC',
6363
timeout_seconds: 30,
@@ -67,7 +67,7 @@ Use the following guidelines to review the changes and suggest improvements:
6767
// Step 3: Run full git diff to see the actual changes
6868
yield {
6969
toolName: 'run_terminal_command',
70-
args: {
70+
input: {
7171
command: 'git diff HEAD',
7272
process_type: 'SYNC',
7373
timeout_seconds: 30,
@@ -97,7 +97,7 @@ Use the following guidelines to review the changes and suggest improvements:
9797
if (allFilesToRead.length > 0) {
9898
yield {
9999
toolName: 'read_files',
100-
args: {
100+
input: {
101101
paths: allFilesToRead,
102102
},
103103
}
@@ -106,7 +106,7 @@ Use the following guidelines to review the changes and suggest improvements:
106106
// Step 5: Put words in the AI's mouth to get it to spawn the file explorer.
107107
yield {
108108
toolName: 'add_message',
109-
args: {
109+
input: {
110110
role: 'assistant',
111111
content:
112112
'Now I will spawn a file explorer to find any missing codebase context, and then review the changes.',

.agents/claude4-gemini-thinking.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ User cwd: {CODEBUFF_USER_CWD}
324324
while (true) {
325325
yield {
326326
toolName: 'spawn_agents',
327-
args: {
327+
input: {
328328
agents: [
329329
{
330330
agent_type: 'thinker',

.agents/file-explorer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const definition: AgentDefinition = {
5858
),
5959
{ toolResult: spawnResult } = yield {
6060
toolName: 'spawn_agents',
61-
args: {
61+
input: {
6262
agents: filePickerPrompts.map((promptText) => ({
6363
agent_type: 'file-picker',
6464
prompt: promptText,
@@ -67,7 +67,7 @@ const definition: AgentDefinition = {
6767
}
6868
yield {
6969
toolName: 'set_output',
70-
args: {
70+
input: {
7171
results: spawnResult,
7272
},
7373
}

.agents/file-picker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { publisher, version } from './constants'
22

3-
import type { AgentDefinition } from './types/agent-definition'
3+
import type { AgentDefinition, ToolCall } from './types/agent-definition'
44

55
const definition: AgentDefinition = {
66
id: 'file-picker',
@@ -37,8 +37,8 @@ In your report, please give an analysis that includes the full paths of files th
3737
handleSteps: function* ({ agentState, prompt, params }) {
3838
yield {
3939
toolName: 'find_files',
40-
args: { prompt: prompt ?? '' },
41-
}
40+
input: { prompt: prompt ?? '' },
41+
} satisfies ToolCall
4242
yield 'STEP_ALL'
4343
},
4444
}

.agents/opensource/file-picker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AgentDefinition } from '../types/agent-definition'
1+
import type { AgentDefinition, ToolCall } from '../types/agent-definition'
22

33
const definition: AgentDefinition = {
44
id: 'oss-model-file-picker',
@@ -36,8 +36,8 @@ In your report, please give an analysis that includes the full paths of files th
3636
handleSteps: function* ({ agentState, prompt, params }) {
3737
yield {
3838
toolName: 'find_files',
39-
args: { prompt: prompt ?? "Find files related to the user's request" },
40-
}
39+
input: { prompt: prompt ?? "Find files related to the user's request" },
40+
} satisfies ToolCall
4141
yield 'STEP_ALL'
4242
},
4343
}

.agents/researcher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { publisher, version } from './constants'
22

3-
import type { AgentDefinition } from './types/agent-definition'
3+
import type { AgentDefinition, ToolCall } from './types/agent-definition'
44

55
const definition: AgentDefinition = {
66
id: 'researcher',
@@ -37,8 +37,8 @@ Always end your response with the end_turn tool.`,
3737
handleSteps: function* ({ agentState, prompt, params }) {
3838
yield {
3939
toolName: 'web_search',
40-
args: { query: prompt ?? '', depth: 'standard' },
41-
}
40+
input: { query: prompt ?? '', depth: 'standard' },
41+
} satisfies ToolCall
4242
yield 'STEP_ALL'
4343
},
4444
}

.agents/types/agent-definition.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export interface AgentDefinition {
116116
/** Programmatically step the agent forward and run tools.
117117
*
118118
* You can either yield:
119-
* - A tool call object with toolName and args properties.
119+
* - A tool call object with toolName and input properties.
120120
* - 'STEP' to run agent's model and generate one assistant message.
121121
* - 'STEP_ALL' to run the agent's model until it uses the end_turn tool or stops includes no tool calls in a message.
122122
*
@@ -126,7 +126,7 @@ export interface AgentDefinition {
126126
* function* handleSteps({ agentStep, prompt, params}) {
127127
* const { toolResult } = yield {
128128
* toolName: 'read_files',
129-
* args: { paths: ['file1.txt', 'file2.txt'] }
129+
* input: { paths: ['file1.txt', 'file2.txt'] }
130130
* }
131131
* yield 'STEP_ALL'
132132
* }
@@ -136,7 +136,7 @@ export interface AgentDefinition {
136136
* while (true) {
137137
* yield {
138138
* toolName: 'spawn_agents',
139-
* args: {
139+
* input: {
140140
* agents: [
141141
* {
142142
* agent_type: 'thinker',
@@ -191,7 +191,7 @@ export interface AgentStepContext {
191191
export type ToolCall<T extends ToolName = ToolName> = {
192192
[K in T]: {
193193
toolName: K
194-
args?: Tools.GetToolParams<K>
194+
input?: Tools.GetToolParams<K>
195195
}
196196
}[T]
197197

backend/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,28 @@
2424
"bun": ">=1.2.11"
2525
},
2626
"dependencies": {
27-
"@ai-sdk/google-vertex": "2.2.24",
28-
"@ai-sdk/openai": "1.3.22",
27+
"@ai-sdk/google-vertex": "3.0.6",
28+
"@ai-sdk/openai": "2.0.11",
2929
"@codebuff/billing": "workspace:*",
3030
"@codebuff/common": "workspace:*",
3131
"@codebuff/internal": "workspace:*",
3232
"@google-cloud/vertexai": "1.10.0",
3333
"@google/generative-ai": "0.24.1",
34-
"ai": "4.3.16",
34+
"@jitl/quickjs-wasmfile-release-sync": "0.31.0",
35+
"@openrouter/ai-sdk-provider": "1.1.2",
36+
"ai": "5.0.0",
3537
"cors": "^2.8.5",
3638
"diff": "5.2.0",
3739
"dotenv": "16.4.5",
3840
"express": "4.19.2",
3941
"gpt-tokenizer": "2.8.1",
4042
"ignore": "5.3.2",
41-
"@jitl/quickjs-wasmfile-release-sync": "0.31.0",
42-
"quickjs-emscripten-core": "0.31.0",
4343
"lodash": "*",
4444
"openai": "^4.78.1",
4545
"pino": "9.4.0",
4646
"postgres": "3.4.4",
4747
"posthog-node": "^4.14.0",
48+
"quickjs-emscripten-core": "0.31.0",
4849
"ts-pattern": "5.3.1",
4950
"ws": "8.18.0",
5051
"zod": "3.25.67",

backend/src/__tests__/agent-registry.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,57 @@ const mockStaticTemplates: Record<string, AgentTemplate> = {
6060
// We'll spy on the validation functions instead of mocking the entire module
6161

6262
describe('Agent Registry', () => {
63+
beforeAll(() => {
64+
// Mock the database module
65+
mockModule('@codebuff/common/db', () => ({
66+
default: {
67+
select: () => ({
68+
from: () => ({
69+
where: () => ({
70+
orderBy: () => ({
71+
limit: () => Promise.resolve([]),
72+
}),
73+
then: (fn: (rows: any[]) => any) => fn([]),
74+
}),
75+
}),
76+
}),
77+
},
78+
}))
79+
80+
// Mock the schema module
81+
mockModule('@codebuff/common/db/schema', () => ({
82+
agentConfig: {
83+
id: 'id',
84+
publisher_id: 'publisher_id',
85+
version: 'version',
86+
major: 'major',
87+
minor: 'minor',
88+
patch: 'patch',
89+
data: 'data',
90+
},
91+
}))
92+
93+
// Mock drizzle-orm
94+
mockModule('drizzle-orm', () => ({
95+
and: (...args: any[]) => ({ type: 'and', args }),
96+
desc: (field: any) => ({ type: 'desc', field }),
97+
eq: (field: any, value: any) => ({ type: 'eq', field, value }),
98+
}))
99+
100+
// Mock logger
101+
mockModule('../util/logger', () => ({
102+
logger: {
103+
debug: () => {},
104+
error: () => {},
105+
warn: () => {},
106+
},
107+
}))
108+
109+
// Mock static agent templates
110+
mockModule('@codebuff/backend/templates/agent-list', () => ({
111+
agentTemplates: mockStaticTemplates,
112+
}))
113+
})
63114
let mockFileContext: ProjectFileContext
64115

65116
beforeAll(() => {

backend/src/__tests__/loop-agent-steps.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ describe('loopAgentSteps STEP behavior', () => {
193193

194194
if (stepCount === 1) {
195195
// First call: Execute a tool, then STEP
196-
yield { toolName: 'read_files', args: { paths: ['file1.txt'] } }
196+
yield { toolName: 'read_files', input: { paths: ['file1.txt'] } }
197197
yield 'STEP' // Should pause here
198198
} else if (stepCount === 2) {
199199
// Second call: Should continue from here, not call LLM
200200
yield {
201201
toolName: 'write_file',
202-
args: { path: 'output.txt', content: 'test' },
202+
input: { path: 'output.txt', content: 'test' },
203203
}
204-
yield { toolName: 'end_turn', args: {} }
204+
yield { toolName: 'end_turn', input: {} }
205205
}
206206
})() as StepGenerator
207207

@@ -258,12 +258,12 @@ describe('loopAgentSteps STEP behavior', () => {
258258
// it should complete without calling the LLM at all (since it ends with end_turn)
259259

260260
const mockGenerator = (function* () {
261-
yield { toolName: 'read_files', args: { paths: ['file1.txt'] } }
261+
yield { toolName: 'read_files', input: { paths: ['file1.txt'] } }
262262
yield {
263263
toolName: 'write_file',
264-
args: { path: 'output.txt', content: 'test' },
264+
input: { path: 'output.txt', content: 'test' },
265265
}
266-
yield { toolName: 'end_turn', args: {} }
266+
yield { toolName: 'end_turn', input: {} }
267267
})() as StepGenerator
268268

269269
mockTemplate.handleSteps = () => mockGenerator

0 commit comments

Comments
 (0)