mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
Use zod 4 JSON schema conversion
This commit is contained in:
3
package-lock.json
generated
3
package-lock.json
generated
@@ -38182,8 +38182,7 @@
|
||||
"uuid": "^9.0.1",
|
||||
"which": "^5.0.0",
|
||||
"ws": "^8.14.2",
|
||||
"zod": "^4.1.8",
|
||||
"zod-to-json-schema": "^3.25.1"
|
||||
"zod": "^4.1.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.56.1",
|
||||
|
||||
@@ -90,8 +90,7 @@
|
||||
"uuid": "^9.0.1",
|
||||
"which": "^5.0.0",
|
||||
"ws": "^8.14.2",
|
||||
"zod": "^4.1.8",
|
||||
"zod-to-json-schema": "^3.25.1"
|
||||
"zod": "^4.1.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.56.1",
|
||||
|
||||
@@ -2,7 +2,7 @@ import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
|
||||
import { zodToJsonSchema } from "zod-to-json-schema";
|
||||
import { z } from "zod";
|
||||
import { PersistedConfigSchema } from "../src/server/persisted-config.js";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
@@ -13,9 +13,10 @@ function main() {
|
||||
const outPath = path.join(repoRoot, "packages/website/public/schemas/paseo.config.v1.json");
|
||||
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
||||
|
||||
const schema = zodToJsonSchema(PersistedConfigSchema, {
|
||||
name: "PaseoConfigV1",
|
||||
});
|
||||
const schema = {
|
||||
...z.toJSONSchema(PersistedConfigSchema, { target: "draft-7" }),
|
||||
title: "PaseoConfigV1",
|
||||
};
|
||||
|
||||
fs.writeFileSync(outPath, JSON.stringify(schema, null, 2) + "\n", "utf8");
|
||||
process.stdout.write(`Wrote ${outPath}\n`);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { z } from "zod";
|
||||
import { zodToJsonSchema } from "zod-to-json-schema";
|
||||
import Ajv, { type ErrorObject, type Options as AjvOptions } from "ajv";
|
||||
import type { AgentProvider, AgentSessionConfig } from "./agent-sdk-types.js";
|
||||
import type { AgentManager } from "./agent-manager.js";
|
||||
@@ -111,11 +110,10 @@ function isZodSchema(value: unknown): value is z.ZodTypeAny {
|
||||
}
|
||||
|
||||
function buildZodValidator<T>(schema: z.ZodTypeAny, schemaName: string): SchemaValidator<T> {
|
||||
const zodToJsonSchemaAny = zodToJsonSchema as unknown as (
|
||||
input: z.ZodTypeAny,
|
||||
name?: string,
|
||||
) => JsonSchema;
|
||||
const jsonSchema = zodToJsonSchemaAny(schema, schemaName);
|
||||
const jsonSchema = {
|
||||
...z.toJSONSchema(schema, { target: "draft-7" }),
|
||||
title: schemaName,
|
||||
} as JsonSchema;
|
||||
return {
|
||||
jsonSchema,
|
||||
validate: (value) => {
|
||||
|
||||
@@ -6,7 +6,6 @@ import { join, resolve as resolvePath } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import Ajv from "ajv";
|
||||
import { z } from "zod";
|
||||
import { zodToJsonSchema } from "zod-to-json-schema";
|
||||
|
||||
import { createTestLogger } from "../../test-utils/test-logger.js";
|
||||
import { createAgentMcpServer } from "./mcp-server.js";
|
||||
@@ -112,7 +111,7 @@ async function invokeToolWithParsedInput(
|
||||
|
||||
function expectOutputSchemaAccepts(tool: RegisteredMcpTool, data: unknown): void {
|
||||
expect(tool.outputSchema).toBeDefined();
|
||||
const jsonSchema = zodToJsonSchema(tool.outputSchema as z.ZodTypeAny);
|
||||
const jsonSchema = z.toJSONSchema(tool.outputSchema as z.ZodTypeAny, { target: "draft-7" });
|
||||
const ajv = new Ajv({ allErrors: true, strict: false });
|
||||
const validate = ajv.compile(jsonSchema);
|
||||
expect(validate(data), JSON.stringify(validate.errors, null, 2)).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user