-
Notifications
You must be signed in to change notification settings - Fork 99
Replace custom jsonSchemaToZod implementation with Zod's native z.fromJSONSchema() method
#1735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
96fe940
c8fc0b8
207666f
6bef309
f9a0c49
d8821b8
f5de369
2232e41
68471b6
e9d6af3
9a282d1
39ccf59
c572bd7
b68a294
c1c46eb
7ec3606
b703149
1f39d29
3063376
fdbe15d
a736a90
beb813c
f7c705c
fc8e1d6
96fbe28
af84da3
0b4d47c
0398815
9cca3ea
11f869f
c04dcda
756adf7
eb3c969
8031b8e
0f87f6a
372bab8
6f8f73d
45d6053
0f8b1d3
1804941
67702a8
6eac16a
0a1c828
8087665
91b79a0
2a071c1
5f33745
3a52f97
f9a57a2
9d9a440
a29ccd5
92e2946
11260e1
b9452b8
1928059
5a2153a
990bf13
274011d
0a98b3f
95facf0
d5b3ece
c500854
f5ccb4f
7af0a13
6bbb8b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@inkeep/agents-api": patch | ||
| "@inkeep/agents-core": patch | ||
| --- | ||
|
|
||
| Replace custom jsonSchemaToZod implementation with Zod's native z.fromJSONSchema() method |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,7 +14,6 @@ import { | |||||||||||||||||||||||||
| getLedgerArtifacts, | ||||||||||||||||||||||||||
| isGithubWorkAppTool, | ||||||||||||||||||||||||||
| JsonTransformer, | ||||||||||||||||||||||||||
| jsonSchemaToZod, | ||||||||||||||||||||||||||
| listTaskIdsByContextId, | ||||||||||||||||||||||||||
| MCPServerType, | ||||||||||||||||||||||||||
| type MCPToolConfig, | ||||||||||||||||||||||||||
|
|
@@ -1393,7 +1392,9 @@ export class Agent { | |||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const zodSchema = jsonSchemaToZod(functionData.inputSchema); | ||||||||||||||||||||||||||
| const zodSchema = functionData.inputSchema | ||||||||||||||||||||||||||
| ? z.fromJSONSchema(functionData.inputSchema) | ||||||||||||||||||||||||||
| : z.string(); | ||||||||||||||||||||||||||
|
Comment on lines
+1395
to
+1397
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MAJOR Missing try-catch for user-controlled inputSchema
The same codebase has proper error handling at line 2198-2214 for the exact same reason.
Suggested change
|
||||||||||||||||||||||||||
| const toolPolicies = (functionToolDef as any).toolPolicies as | ||||||||||||||||||||||||||
| | Record<string, { needsApproval?: boolean }> | ||||||||||||||||||||||||||
| | null | ||||||||||||||||||||||||||
|
|
@@ -1575,7 +1576,7 @@ export class Agent { | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const result = await sandboxExecutor.executeFunctionTool( | ||||||||||||||||||||||||||
| functionToolDef.id, | ||||||||||||||||||||||||||
| finalArgs, | ||||||||||||||||||||||||||
| finalArgs as Record<string, unknown>, | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| description: functionToolDef.description || functionToolDef.name, | ||||||||||||||||||||||||||
| inputSchema: functionData.inputSchema || {}, | ||||||||||||||||||||||||||
|
|
@@ -2196,7 +2197,7 @@ export class Agent { | |||||||||||||||||||||||||
| let inputSchema: any; | ||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||
| inputSchema = override.schema | ||||||||||||||||||||||||||
| ? jsonSchemaToZod(override.schema) | ||||||||||||||||||||||||||
| ? z.fromJSONSchema(override.schema) | ||||||||||||||||||||||||||
| : (toolDef as any).inputSchema; | ||||||||||||||||||||||||||
| } catch (schemaError) { | ||||||||||||||||||||||||||
| logger.error( | ||||||||||||||||||||||||||
|
|
@@ -3654,18 +3655,16 @@ ${output}${structureHintsFormatted}`; | |||||||||||||||||||||||||
| private buildDataComponentsSchema() { | ||||||||||||||||||||||||||
| const componentSchemas: z.ZodType<any>[] = []; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (this.config.dataComponents && this.config.dataComponents.length > 0) { | ||||||||||||||||||||||||||
| this.config.dataComponents.forEach((dc) => { | ||||||||||||||||||||||||||
| const propsSchema = jsonSchemaToZod(dc.props); | ||||||||||||||||||||||||||
| componentSchemas.push( | ||||||||||||||||||||||||||
| z.object({ | ||||||||||||||||||||||||||
| id: z.string(), | ||||||||||||||||||||||||||
| name: z.literal(dc.name), | ||||||||||||||||||||||||||
| props: propsSchema, | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| this.config.dataComponents?.forEach((dc) => { | ||||||||||||||||||||||||||
| const propsSchema = dc.props ? z.fromJSONSchema(dc.props) : z.string(); | ||||||||||||||||||||||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||
| componentSchemas.push( | ||||||||||||||||||||||||||
| z.object({ | ||||||||||||||||||||||||||
| id: z.string(), | ||||||||||||||||||||||||||
| name: z.literal(dc.name), | ||||||||||||||||||||||||||
| props: propsSchema, | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (this.artifactComponents.length > 0) { | ||||||||||||||||||||||||||
| const artifactCreateSchemas = ArtifactCreateSchema.getSchemas(this.artifactComponents); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| * 4. Streams NDJSON response back to client | ||
| */ | ||
|
|
||
| import { jsonSchemaToZod, ModelFactory } from '@inkeep/agents-core'; | ||
| import { ModelFactory } from '@inkeep/agents-core'; | ||
| import { Output, streamText } from 'ai'; | ||
| import type { NextRequest } from 'next/server'; | ||
| import { z } from 'zod'; | ||
|
|
@@ -68,7 +68,9 @@ export async function POST( | |
| const modelConfig = ModelFactory.prepareGenerationConfig(project.models?.base as any); | ||
|
|
||
| // Define schema for generated output | ||
| const mockDataSchema = jsonSchemaToZod(artifactComponent.props); | ||
| const mockDataSchema = artifactComponent.props | ||
| ? z.fromJSONSchema(artifactComponent.props) | ||
| : z.string(); | ||
|
Comment on lines
+71
to
+73
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const renderSchema = z.object({ | ||
| component: z.string().describe('The React component code'), | ||
| mockData: mockDataSchema.describe('Sample data matching the props schema'), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backward compatibility, previous
jsonSchemaToZodreturnsz.stringfor falsy values