Skip to content

Commit 0ea4893

Browse files
committed
change z.toJSONSchema to use input schema
1 parent db0de5c commit 0ea4893

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

backend/src/templates/strings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ export async function getAgentPrompt<T extends StringField>(
188188
addendum += '```json\n'
189189
try {
190190
// Convert Zod schema to JSON schema for display
191-
const jsonSchema = z.toJSONSchema(agentTemplate.outputSchema)
191+
const jsonSchema = z.toJSONSchema(agentTemplate.outputSchema, {
192+
io: 'input',
193+
})
192194
delete jsonSchema['$schema'] // Remove the $schema field for cleaner display
193195
addendum += JSON.stringify(jsonSchema, null, 2)
194196
} catch {

backend/src/tools/prompts.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ function paramsSection(schema: z.ZodObject, endsAgentStep: boolean) {
1515
.describe('Easp flag must be set to true'),
1616
})
1717
: schema
18-
const jsonSchema = z.toJSONSchema(schemaWithEndsAgentStepParam)
18+
const jsonSchema = z.toJSONSchema(schemaWithEndsAgentStepParam, {
19+
io: 'input',
20+
})
1921
delete jsonSchema.description
2022
delete jsonSchema['$schema']
2123
const paramsDescription = Object.keys(jsonSchema.properties ?? {}).length

common/src/tools/compile-tool-definitions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import z from 'zod/v4'
22

3-
import { llmToolCallSchema } from './list'
43
import { publishedTools } from './constants'
4+
import { llmToolCallSchema } from './list'
55

66
/**
77
* Compiles all tool definitions into a single TypeScript definition file content.
@@ -19,7 +19,7 @@ export function compileToolDefinitions(): string {
1919
// Convert Zod schema to TypeScript interface using JSON schema
2020
let typeDefinition: string
2121
try {
22-
const jsonSchema = z.toJSONSchema(parameterSchema)
22+
const jsonSchema = z.toJSONSchema(parameterSchema, { io: 'input' })
2323
typeDefinition = jsonSchemaToTypeScript(jsonSchema)
2424
} catch (error) {
2525
console.warn(`Failed to convert schema for ${toolName}:`, error)

common/src/util/zod-schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import z from 'zod/v4'
55
*/
66
export function schemaToJsonStr(
77
schema: z.ZodTypeAny | undefined | Record<string, any>,
8+
options?: Parameters<typeof z.toJSONSchema>[1],
89
): string {
910
if (!schema) return 'None'
1011

1112
try {
1213
// Handle Zod schemas
1314
if (schema instanceof z.ZodType) {
14-
const jsonSchema = z.toJSONSchema(schema)
15+
const jsonSchema = z.toJSONSchema(schema, options)
1516
delete jsonSchema['$schema']
1617
return JSON.stringify(jsonSchema, null, 2)
1718
}

web/src/components/docs/mdx/schema-display.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { DynamicAgentTemplateSchema } from '@codebuff/common/types/dynamic-agent
77
import { CodeDemo } from './code-demo'
88

99
export function SchemaDisplay() {
10-
const schemaString = schemaToJsonStr(CodebuffConfigSchema)
10+
const schemaString = schemaToJsonStr(CodebuffConfigSchema, {io: 'input'})
1111
return <CodeDemo language="json">{schemaString}</CodeDemo>
1212
}
1313

1414
export function AgentTemplateSchemaDisplay() {
15-
const schemaString = schemaToJsonStr(DynamicAgentTemplateSchema)
15+
const schemaString = schemaToJsonStr(DynamicAgentTemplateSchema, {io: 'input'})
1616
return <CodeDemo language="json">{schemaString}</CodeDemo>
1717
}

0 commit comments

Comments
 (0)