From 0acee70595b879a47677b336e615abb74534b584 Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Mon, 2 Nov 2026 22:53:39 +0000 Subject: [PATCH 01/13] chore(deps): move the workspace to zod 4.6.7 from one pnpm catalog [SAP-4718] Every workspace package now takes zod from a single `catalog:` entry, and a root override keeps transitive dependencies on it. Record schemas use the two-argument form zod 4 requires. Tests pin the schemas clients see: the sandbox env record, the project scan, the MCP tool JSON Schemas and the agent map bootstrap. The introspection test accepts both shapes zod emits for an object intersection, since the agent peer range covers zod 3.25 and 4. Co-Authored-By: Claude Opus 5.5 (1M context) --- .changeset/zod-4.md | 14 ++ packages/agent-core/package.json | 2 +- packages/agent-map/package.json | 2 +- .../src/shared/host-protocol.test.ts | 6 + packages/agent-runtime/package.json | 2 +- packages/agent/package.json | 2 +- packages/agent/src/introspection.spec.ts | 8 +- packages/cli/package.json | 2 +- packages/harness/package.json | 2 +- packages/langchain-classic/package.json | 2 +- packages/langchain/package.json | 2 +- packages/mcp/package.json | 2 +- packages/mcp/src/map/scan-project.test.ts | 20 ++ packages/mcp/src/map/scan-project.ts | 3 +- packages/mcp/src/tools/tool-schemas.test.ts | 108 +++++++++ packages/sandbox-preview/package.json | 2 +- packages/sandbox-preview/src/config.spec.ts | 22 ++ packages/sandbox-preview/src/schema.ts | 2 +- pnpm-lock.yaml | 211 ++++++++---------- pnpm-workspace.yaml | 9 + 20 files changed, 290 insertions(+), 133 deletions(-) create mode 100644 .changeset/zod-4.md create mode 100644 packages/mcp/src/tools/tool-schemas.test.ts diff --git a/.changeset/zod-4.md b/.changeset/zod-4.md new file mode 100644 index 000000000..4200159b5 --- /dev/null +++ b/.changeset/zod-4.md @@ -0,0 +1,14 @@ +--- +"@sapiom/sandbox-preview": minor +"@sapiom/agent-map": minor +"@sapiom/mcp": patch +"@sapiom/harness": patch +"@sapiom/cli": patch +"@sapiom/agent-core": patch +--- + +Upgrade zod to 4.6.7. + +`@sapiom/sandbox-preview` (`sandboxConfigBodySchema` and the other exported schemas) and `@sapiom/agent-map` (`./host-protocol`) now export zod 4 schemas. Compose them with zod 4: `import { z } from "zod"` on zod 4, or `import { z } from "zod/v4"` on zod 3.25. + +Projects scaffolded by `sapiom agents init` now pin zod 4.6.7. diff --git a/packages/agent-core/package.json b/packages/agent-core/package.json index cbfeec7aa..4ff0640e2 100644 --- a/packages/agent-core/package.json +++ b/packages/agent-core/package.json @@ -68,7 +68,7 @@ "prettier": "^3.2.5", "ts-jest": "^29.1.2", "typescript": "^5.4.2", - "zod": "^3.25.0" + "zod": "catalog:" }, "engines": { "node": ">=18.0.0" diff --git a/packages/agent-map/package.json b/packages/agent-map/package.json index a9014c565..572781873 100644 --- a/packages/agent-map/package.json +++ b/packages/agent-map/package.json @@ -89,7 +89,7 @@ "access": "public" }, "dependencies": { - "zod": "^3.25.0", + "zod": "catalog:", "uuid": "^10.0.0" } } diff --git a/packages/agent-map/src/shared/host-protocol.test.ts b/packages/agent-map/src/shared/host-protocol.test.ts index 24f7010ce..8ae0c73f5 100644 --- a/packages/agent-map/src/shared/host-protocol.test.ts +++ b/packages/agent-map/src/shared/host-protocol.test.ts @@ -83,5 +83,11 @@ describe("host protocol", () => { projectId: context.projectId, }).success, ).toBe(false); + expect( + StudioHostBootstrapSchema.safeParse({ + ...bootstrap, + contextUrl: "not a url", + }).success, + ).toBe(false); }); }); diff --git a/packages/agent-runtime/package.json b/packages/agent-runtime/package.json index 014031538..53e471e90 100644 --- a/packages/agent-runtime/package.json +++ b/packages/agent-runtime/package.json @@ -64,7 +64,7 @@ "prettier": "^3.2.5", "ts-jest": "^29.1.2", "typescript": "^5.4.2", - "zod": "^4.1.0" + "zod": "catalog:" }, "engines": { "node": ">=18.0.0" diff --git a/packages/agent/package.json b/packages/agent/package.json index 401c437cb..ed0b58b1b 100644 --- a/packages/agent/package.json +++ b/packages/agent/package.json @@ -65,7 +65,7 @@ "prettier": "^3.2.5", "ts-jest": "^29.1.2", "typescript": "^5.4.2", - "zod": "^3.25.76" + "zod": "catalog:" }, "engines": { "node": ">=18.0.0" diff --git a/packages/agent/src/introspection.spec.ts b/packages/agent/src/introspection.spec.ts index b8952e308..c95b52121 100644 --- a/packages/agent/src/introspection.spec.ts +++ b/packages/agent/src/introspection.spec.ts @@ -80,9 +80,11 @@ describe('zodToJsonSchema', () => { z.object({ id: z.string() }).and(z.object({ retries: z.number().default(0) })), ); - const branches = schema.allOf as Record[]; - expect(requiredOf(branches[0])).toEqual(['id']); - expect(requiredOf(branches[1])).toEqual([]); + // Older zod emits one `allOf` branch per object, newer zod merges them into + // one object; the peer range accepts both. + const nodes = (schema.allOf as Record[] | undefined) ?? [schema]; + expect(nodes.flatMap(requiredOf)).toEqual(['id']); + expect(nodes.some((node) => propAt(node, 'retries')?.default === 0)).toBe(true); }); it('treats .prefault() like .default(): the field is optional and carries the value', () => { diff --git a/packages/cli/package.json b/packages/cli/package.json index 77eaa3d9a..cbde75058 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -43,7 +43,7 @@ "@sapiom/analytics-core": "workspace:^", "@sapiom/sandbox-preview": "workspace:^", "commander": "^14.0.2", - "zod": "^3.25.76" + "zod": "catalog:" }, "peerDependencies": { "@sapiom/harness": ">=0.22.1" diff --git a/packages/harness/package.json b/packages/harness/package.json index debc0d23a..b6ac96074 100644 --- a/packages/harness/package.json +++ b/packages/harness/package.json @@ -77,7 +77,7 @@ "typescript": "~5.9.3", "uuid": "^10.0.0", "ws": "^8.18.0", - "zod": "^3.25.0", + "zod": "catalog:", "@sapiom/agent-map": "workspace:^" }, "devDependencies": { diff --git a/packages/langchain-classic/package.json b/packages/langchain-classic/package.json index 4baf6f42f..4b9a3ba64 100644 --- a/packages/langchain-classic/package.json +++ b/packages/langchain-classic/package.json @@ -69,7 +69,7 @@ "prettier": "^3.2.5", "ts-jest": "^29.1.2", "typescript": "^5.4.2", - "zod": "^4.1.12" + "zod": "catalog:" }, "dependencies": { "@sapiom/analytics-core": "workspace:*", diff --git a/packages/langchain/package.json b/packages/langchain/package.json index 83c5cf2f2..4ad3a729e 100644 --- a/packages/langchain/package.json +++ b/packages/langchain/package.json @@ -67,7 +67,7 @@ "prettier": "^3.2.5", "ts-jest": "^29.1.2", "typescript": "^5.4.2", - "zod": "^3.23.0" + "zod": "catalog:" }, "dependencies": { "@sapiom/analytics-core": "workspace:*", diff --git a/packages/mcp/package.json b/packages/mcp/package.json index 23ab3fb72..a02bdb361 100644 --- a/packages/mcp/package.json +++ b/packages/mcp/package.json @@ -63,7 +63,7 @@ "@sapiom/agent-core": "workspace:^", "@sapiom/analytics-core": "workspace:^", "@sapiom/sandbox-preview": "workspace:^", - "zod": "^3.25.0", + "zod": "catalog:", "@sapiom/agent-map": "workspace:^", "typescript": "^5.4.2" }, diff --git a/packages/mcp/src/map/scan-project.test.ts b/packages/mcp/src/map/scan-project.test.ts index 75cd58f0a..26eca2919 100644 --- a/packages/mcp/src/map/scan-project.test.ts +++ b/packages/mcp/src/map/scan-project.test.ts @@ -311,6 +311,26 @@ export async function b(ctx: any, id: string) { await ctx.sapiom.agents.run({ de expect(map.edges.map((edge) => edge.evidence[0]!.text)).toEqual(['"WORKER_SLUG": "worker"']); }); + it("reads a sapiom.json env record and a manifest steps record together", async () => { + const root = await project({ + "door/sapiom.json": '{ "resources": { "web": { "env": { "A": "b", "WORKER_SLUG": "worker" } } } }', + "door/index.ts": agentSource("door"), + "worker/index.ts": agentSource("worker"), + }); + const steps: StepSource = async (dir) => + path.basename(dir) === "door" + ? { manifest: { entry: "work", steps: { work: {}, done: { transitions: [{ kind: "terminate" }] } } } } + : { unavailable: "not this agent" }; + + const map = await mapOf(root, { steps }); + + expect(edgesOf(map)).toEqual(["door->worker"]); + expect(map.agents.find((agent) => agent.slug === "door")!.steps).toMatchObject({ + entry: "work", + transitions: [], + }); + }); + it("uses a zod default only for the input the step itself reads", async () => { const root = await project({ "caller/index.ts": agentSource( diff --git a/packages/mcp/src/map/scan-project.ts b/packages/mcp/src/map/scan-project.ts index cfeaeadf7..63edd43ef 100644 --- a/packages/mcp/src/map/scan-project.ts +++ b/packages/mcp/src/map/scan-project.ts @@ -89,7 +89,7 @@ const sapiomJsonSchema = z name: z.string().optional(), definitionId: z.union([z.string(), z.number()]).optional(), resources: z - .record(z.object({ env: z.record(z.string()).optional() }).passthrough()) + .record(z.string(), z.object({ env: z.record(z.string(), z.string()).optional() }).passthrough()) .optional(), }) .passthrough(); @@ -238,6 +238,7 @@ function manifestToSteps( .object({ entry: z.string(), steps: z.record( + z.string(), z .object({ transitions: z diff --git a/packages/mcp/src/tools/tool-schemas.test.ts b/packages/mcp/src/tools/tool-schemas.test.ts new file mode 100644 index 000000000..561af22e2 --- /dev/null +++ b/packages/mcp/src/tools/tool-schemas.test.ts @@ -0,0 +1,108 @@ +/** + * The JSON Schemas MCP clients see for tools built from zod shapes. The SDK + * converts a shape at `tools/list` time, so this pins the fields clients rely on + * (properties, required, types) whatever zod version produces them. + */ +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +import { afterEach, describe, expect, it } from "vitest"; +import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; +import { Client } from "@modelcontextprotocol/sdk/client/index.js"; +import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js"; + +import type { ResolvedEnvironment } from "../credentials.js"; +import { register as registerFeedback } from "./feedback.js"; +import { register as registerSandbox } from "./sandbox.js"; + +const env: ResolvedEnvironment = { + name: "production", + appURL: "https://app.sapiom.ai", + apiURL: "https://api.sapiom.ai", + services: {}, + credentials: null, +}; + +const temps: string[] = []; +afterEach(() => { + for (const dir of temps.splice(0)) + rmSync(dir, { recursive: true, force: true }); +}); + +async function connect(): Promise { + const server = new McpServer({ name: "sapiom-dev", version: "0.0.0" }); + registerSandbox(server, env); + registerFeedback(server, env); + const client = new Client({ name: "test-client", version: "0.0.0" }); + const [clientTransport, serverTransport] = + InMemoryTransport.createLinkedPair(); + await Promise.all([ + server.connect(serverTransport), + client.connect(clientTransport), + ]); + return client; +} + +describe("tool input schemas over tools/list", () => { + it("sapiom_dev_sandbox_configure exposes the sandbox body as a JSON Schema object", async () => { + const { tools } = await (await connect()).listTools(); + const configure = tools.find( + (tool) => tool.name === "sapiom_dev_sandbox_configure", + )!; + const schema = configure.inputSchema as { + type: string; + properties: Record< + string, + { type?: string; additionalProperties?: { type?: string } } + >; + required?: string[]; + }; + + expect(schema.type).toBe("object"); + expect(Object.keys(schema.properties).sort()).toEqual([ + "build", + "dir", + "env", + "name", + "port", + "source", + "start", + "tier", + "ttl", + ]); + expect(schema.required).toEqual( + expect.arrayContaining(["name", "source", "start", "port"]), + ); + expect(schema.properties.env).toMatchObject({ + type: "object", + additionalProperties: { type: "string" }, + }); + + const feedback = tools.find( + (tool) => tool.name === "sapiom_send_feedback", + )!; + expect(feedback.inputSchema.type).toBe("object"); + expect(feedback.inputSchema.required).toEqual(["message"]); + }); + + it("answers an argument of the wrong type with an error result", async () => { + const dir = mkdtempSync(path.join(tmpdir(), "mcp-tool-schemas-")); + temps.push(dir); + + const result = await ( + await connect() + ).callTool({ + name: "sapiom_dev_sandbox_configure", + arguments: { + dir, + name: "web", + source: { kind: "upload" }, + start: "node server.js", + port: "x", + }, + }); + + expect(result.isError).toBe(true); + }); +}); diff --git a/packages/sandbox-preview/package.json b/packages/sandbox-preview/package.json index b9094b51e..631a37200 100644 --- a/packages/sandbox-preview/package.json +++ b/packages/sandbox-preview/package.json @@ -51,7 +51,7 @@ }, "dependencies": { "@sapiom/tools": "workspace:^", - "zod": "^3.25.76" + "zod": "catalog:" }, "devDependencies": { "@types/jest": "^29.5.14", diff --git a/packages/sandbox-preview/src/config.spec.ts b/packages/sandbox-preview/src/config.spec.ts index fffb2b57c..cb22e6ef7 100644 --- a/packages/sandbox-preview/src/config.spec.ts +++ b/packages/sandbox-preview/src/config.spec.ts @@ -120,6 +120,28 @@ describe('config — writeSandbox / configureSandbox', () => { rmSync(dir, { recursive: true, force: true }); } }); + + it('stores an env map of strings and rejects a non-string value by its key', () => { + const dir = tmpProject(); + try { + const env = { API_URL: 'https://x' }; + configureSandbox(dir, 'web', { source: { kind: 'upload' }, start: 'node server.js', port: 3000, env }); + expect(getSandbox(dir, 'web').env).toEqual(env); + + let caught: unknown; + try { + // @ts-expect-error: deliberately invalid env value to exercise record validation + configureSandbox(dir, 'api', { source: { kind: 'upload' }, start: 'node server.js', port: 3000, env: { PORT: 1 } }); + } catch (e) { + caught = e; + } + expect(caught).toBeInstanceOf(PreviewOperationError); + expect((caught as PreviewOperationError).code).toBe('INVALID_SANDBOX'); + expect((caught as PreviewOperationError).hint).toContain('env.PORT'); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + }); }); describe('config — validation on read', () => { diff --git a/packages/sandbox-preview/src/schema.ts b/packages/sandbox-preview/src/schema.ts index 68b833dd4..d4304eedd 100644 --- a/packages/sandbox-preview/src/schema.ts +++ b/packages/sandbox-preview/src/schema.ts @@ -37,7 +37,7 @@ export const sandboxConfigBodySchema = z.object({ port: z.number().int().min(1).max(65535), tier: z.enum(['xs', 's', 'm', 'l', 'xl']).optional(), ttl: z.string().optional(), - env: z.record(z.string()).optional(), + env: z.record(z.string(), z.string()).optional(), }); export type SandboxConfigBody = z.infer; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 50da7ad70..458f5f50a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,7 @@ settings: overrides: '@electron/rebuild': ^3.7.0 + zod: ^4.6.7 patchedDependencies: '@assistant-ui/react-opencode@0.2.22': @@ -81,8 +82,8 @@ importers: specifier: ^5.4.2 version: 5.9.3 zod: - specifier: ^3.25.76 - version: 3.25.76 + specifier: ^4.6.7 + version: 4.6.7 packages/agent-core: dependencies: @@ -130,8 +131,8 @@ importers: specifier: ^5.4.2 version: 5.9.3 zod: - specifier: ^3.25.0 - version: 3.25.76 + specifier: ^4.6.7 + version: 4.6.7 packages/agent-map: dependencies: @@ -139,8 +140,8 @@ importers: specifier: ^10.0.0 version: 10.0.0 zod: - specifier: ^3.25.0 - version: 3.25.76 + specifier: ^4.6.7 + version: 4.6.7 devDependencies: '@types/node': specifier: ^20.11.30 @@ -195,8 +196,8 @@ importers: specifier: ^5.4.2 version: 5.9.3 zod: - specifier: ^4.1.0 - version: 4.4.3 + specifier: ^4.6.7 + version: 4.6.7 packages/agent-studio: dependencies: @@ -344,8 +345,8 @@ importers: specifier: ^14.0.2 version: 14.0.3 zod: - specifier: ^3.25.76 - version: 3.25.76 + specifier: ^4.6.7 + version: 4.6.7 devDependencies: '@types/jest': specifier: ^29.5.14 @@ -453,7 +454,7 @@ importers: dependencies: '@modelcontextprotocol/sdk': specifier: ^1.26.0 - version: 1.29.0(@cfworker/json-schema@4.1.1)(zod@3.25.76) + version: 1.29.0(@cfworker/json-schema@4.1.1)(zod@4.6.7) '@sapiom/agent': specifier: workspace:^ version: link:../agent @@ -497,8 +498,8 @@ importers: specifier: ^8.18.0 version: 8.21.0 zod: - specifier: ^3.25.0 - version: 3.25.76 + specifier: ^4.6.7 + version: 4.6.7 devDependencies: '@assistant-ui/react': specifier: 0.15.18 @@ -624,7 +625,7 @@ importers: devDependencies: '@langchain/core': specifier: ~1.2.1 - version: 1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0) + version: 1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0) '@types/jest': specifier: ^29.5.14 version: 29.5.14 @@ -645,7 +646,7 @@ importers: version: 29.7.0(@types/node@20.19.43) langchain: specifier: ~1.5.3 - version: 1.5.3(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0))(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(ws@8.21.0) + version: 1.5.3(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0))(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(ws@8.21.0) prettier: specifier: ^3.2.5 version: 3.8.4 @@ -656,8 +657,8 @@ importers: specifier: ^5.4.2 version: 5.9.3 zod: - specifier: ^3.23.0 - version: 3.25.76 + specifier: ^4.6.7 + version: 4.6.7 packages/langchain-classic: dependencies: @@ -670,16 +671,16 @@ importers: devDependencies: '@langchain/anthropic': specifier: ^0.3.30 - version: 0.3.34(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)))(zod@4.4.3) + version: 0.3.34(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(zod@4.6.7) '@langchain/core': specifier: ^0.3.78 - version: 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)) + version: 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)) '@langchain/langgraph': specifier: ^0.2.74 - version: 0.2.74(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod-to-json-schema@3.25.2(zod@4.4.3)) + version: 0.2.74(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod-to-json-schema@3.25.2(zod@4.6.7)) '@langchain/openai': specifier: ~1.1.0 - version: 1.1.3(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)))(ws@8.21.0) + version: 1.1.3(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(ws@8.21.0) '@types/jest': specifier: ^29.5.14 version: 29.5.14 @@ -708,14 +709,14 @@ importers: specifier: ^5.4.2 version: 5.9.3 zod: - specifier: ^4.1.12 - version: 4.4.3 + specifier: ^4.6.7 + version: 4.6.7 packages/mcp: dependencies: '@modelcontextprotocol/sdk': specifier: ^1.26.0 - version: 1.29.0(@cfworker/json-schema@4.1.1)(zod@3.25.76) + version: 1.29.0(@cfworker/json-schema@4.1.1)(zod@4.6.7) '@sapiom/agent-core': specifier: workspace:^ version: link:../agent-core @@ -732,8 +733,8 @@ importers: specifier: ^5.4.2 version: 5.9.3 zod: - specifier: ^3.25.0 - version: 3.25.76 + specifier: ^4.6.7 + version: 4.6.7 devDependencies: '@types/node': specifier: ^20.11.30 @@ -862,8 +863,8 @@ importers: specifier: workspace:^ version: link:../tools zod: - specifier: ^3.25.76 - version: 3.25.76 + specifier: ^4.6.7 + version: 4.6.7 devDependencies: '@types/jest': specifier: ^29.5.14 @@ -943,7 +944,7 @@ packages: resolution: {integrity: sha512-zIdPOcrCVEI8t3Di40nH4z9EoeyGZfXbYSvWdDLsB/KkaSYMnEgC7gmcgWu83g2NTn1ZTpbMvpdttWDGGIk6zw==} hasBin: true peerDependencies: - zod: ^3.25.0 || ^4.0.0 + zod: ^4.6.7 peerDependenciesMeta: zod: optional: true @@ -1333,7 +1334,7 @@ packages: engines: {node: '>=12'} '@electron/node-gyp@https://codeload.github.com/electron/node-gyp/tar.gz/06b29aafb7708acef8b3669835c8a7857ebc92d2': - resolution: {gitHosted: true, integrity: sha512-MXgzlTDEEndJB3TBbvd5uFQO/8gaINo1Hfen8vef5rq/VHVPeB63uuv/uO5+8GFsAJ/rauu6XB79S6K4+aXc+w==, tarball: https://codeload.github.com/electron/node-gyp/tar.gz/06b29aafb7708acef8b3669835c8a7857ebc92d2} + resolution: {gitHosted: true, tarball: https://codeload.github.com/electron/node-gyp/tar.gz/06b29aafb7708acef8b3669835c8a7857ebc92d2} version: 10.2.0-electron.1 engines: {node: '>=12.13.0'} hasBin: true @@ -2040,7 +2041,7 @@ packages: engines: {node: '>=18'} peerDependencies: '@langchain/core': ^1.1.48 - zod: ^3.25.32 || ^4.2.0 + zod: ^4.6.7 '@langchain/openai@1.1.3': resolution: {integrity: sha512-p+xR+4HRms5Ozjf5miC6U2AYRyNVSTdO7AMBkMYs1Tp6DWHBd+mQ72H8Ogd2dKrPuS5UDJ5dbpI1fS+OrTbgQQ==} @@ -2070,7 +2071,7 @@ packages: engines: {node: '>=18'} peerDependencies: '@cfworker/json-schema': ^4.1.1 - zod: ^3.25 || ^4.0 + zod: ^4.6.7 peerDependenciesMeta: '@cfworker/json-schema': optional: true @@ -5558,7 +5559,7 @@ packages: '@smithy/hash-node': '>=4.3.0 <5' '@smithy/signature-v4': '>=5.4.0 <6' ws: ^8.18.0 - zod: ^3.25 || ^4.0 + zod: ^4.6.7 peerDependenciesMeta: '@aws-sdk/credential-provider-node': optional: true @@ -6852,19 +6853,10 @@ packages: zod-to-json-schema@3.25.2: resolution: {integrity: sha512-O/PgfnpT1xKSDeQYSCfRI5Gy3hPf91mKVDuYLUHZJMiDFptvP41MSnWofm8dnCm0256ZNfZIM7DSzuSMAFnjHA==} peerDependencies: - zod: ^3.25.28 || ^4 + zod: ^4.6.7 - zod@3.25.76: - resolution: {integrity: sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==} - - zod@4.1.8: - resolution: {integrity: sha512-5R1P+WwQqmmMIEACyzSvo4JXHY5WiAFHRMg+zBZKgKS+Q1viRa0C1hmUKtHltoIFKtIdki3pRxkmpP74jnNYHQ==} - - zod@4.4.3: - resolution: {integrity: sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==} - - zod@4.6.1: - resolution: {integrity: sha512-341aRWQsve0rvronKNTqZpjmzdbUDlFuzHaI/XLg/Ej82qffDJRRfBTCuv7+9q/rMjB6LSLyEBnW4InJeMtt/Q==} + zod@4.6.7: + resolution: {integrity: sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==} zustand@5.0.15: resolution: {integrity: sha512-MpSEjRiBkA9crSYeOUH32rJC7SVqAbm0Fqcqge/bUi2PPoLcBWKOsG+C8mevmpr8TwXHBVkChbbJiyvkE+i/3A==} @@ -6892,11 +6884,11 @@ snapshots: dependencies: json-schema: 0.4.0 - '@anthropic-ai/sdk@0.65.0(zod@4.4.3)': + '@anthropic-ai/sdk@0.65.0(zod@4.6.7)': dependencies: json-schema-to-ts: 3.1.1 optionalDependencies: - zod: 4.4.3 + zod: 4.6.7 '@assistant-ui/core@0.3.17(@assistant-ui/store@0.3.12(@assistant-ui/tap@0.9.16(@types/react@19.2.17)(react@19.2.7))(@types/react@19.2.17)(react@19.2.7))(@assistant-ui/tap@0.9.16(@types/react@19.2.17)(react@19.2.7))(@types/react@19.2.17)(assistant-cloud@0.1.43)(react@19.2.7)': dependencies: @@ -6939,7 +6931,7 @@ snapshots: react-dom: 19.2.7(react@19.2.7) react-textarea-autosize: 8.5.9(@types/react@19.2.17)(react@19.2.7) safe-content-frame: 0.0.29 - zod: 4.6.1 + zod: 4.6.7 zustand: 5.0.15(@types/react@19.2.17)(react@19.2.7) optionalDependencies: '@types/react': 19.2.17 @@ -8050,43 +8042,43 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.5 - '@langchain/anthropic@0.3.34(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)))(zod@4.4.3)': + '@langchain/anthropic@0.3.34(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(zod@4.6.7)': dependencies: - '@anthropic-ai/sdk': 0.65.0(zod@4.4.3) - '@langchain/core': 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)) + '@anthropic-ai/sdk': 0.65.0(zod@4.6.7) + '@langchain/core': 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)) fast-xml-parser: 4.5.7 transitivePeerDependencies: - zod - '@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3))': + '@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7))': dependencies: '@cfworker/json-schema': 4.1.1 ansi-styles: 5.2.0 camelcase: 6.3.0 decamelize: 1.2.0 js-tiktoken: 1.0.21 - langsmith: 0.3.87(openai@6.45.0(ws@8.21.0)(zod@4.4.3)) + langsmith: 0.3.87(openai@6.45.0(ws@8.21.0)(zod@4.6.7)) mustache: 4.2.0 p-queue: 6.6.2 p-retry: 4.6.2 uuid: 10.0.0 - zod: 3.25.76 - zod-to-json-schema: 3.25.2(zod@3.25.76) + zod: 4.6.7 + zod-to-json-schema: 3.25.2(zod@4.6.7) transitivePeerDependencies: - '@opentelemetry/api' - '@opentelemetry/exporter-trace-otlp-proto' - '@opentelemetry/sdk-trace-base' - openai - '@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0)': + '@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0)': dependencies: '@cfworker/json-schema': 4.1.1 '@standard-schema/spec': 1.1.0 js-tiktoken: 1.0.21 - langsmith: 0.8.0(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0) + langsmith: 0.8.0(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0) mustache: 4.2.0 p-queue: 6.6.2 - zod: 3.25.76 + zod: 4.6.7 transitivePeerDependencies: - '@opentelemetry/api' - '@opentelemetry/exporter-trace-otlp-proto' @@ -8094,29 +8086,29 @@ snapshots: - openai - ws - '@langchain/langgraph-checkpoint@0.0.18(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)))': + '@langchain/langgraph-checkpoint@0.0.18(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))': dependencies: - '@langchain/core': 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)) + '@langchain/core': 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)) uuid: 10.0.0 - '@langchain/langgraph-checkpoint@1.1.3(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0))': + '@langchain/langgraph-checkpoint@1.1.3(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0))': dependencies: - '@langchain/core': 1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0) + '@langchain/core': 1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0) - '@langchain/langgraph-sdk@0.0.112(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)': + '@langchain/langgraph-sdk@0.0.112(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)': dependencies: '@types/json-schema': 7.0.15 p-queue: 6.6.2 p-retry: 4.6.2 uuid: 9.0.1 optionalDependencies: - '@langchain/core': 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)) + '@langchain/core': 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)) react: 19.2.7 react-dom: 19.2.7(react@19.2.7) - '@langchain/langgraph-sdk@1.9.25(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)': + '@langchain/langgraph-sdk@1.9.25(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)': dependencies: - '@langchain/core': 1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0) + '@langchain/core': 1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0) '@langchain/protocol': 0.0.18 '@types/json-schema': 7.0.15 p-queue: 9.3.1 @@ -8125,39 +8117,39 @@ snapshots: react: 19.2.7 react-dom: 19.2.7(react@19.2.7) - '@langchain/langgraph@0.2.74(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod-to-json-schema@3.25.2(zod@4.4.3))': + '@langchain/langgraph@0.2.74(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod-to-json-schema@3.25.2(zod@4.6.7))': dependencies: - '@langchain/core': 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)) - '@langchain/langgraph-checkpoint': 0.0.18(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3))) - '@langchain/langgraph-sdk': 0.0.112(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7) + '@langchain/core': 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)) + '@langchain/langgraph-checkpoint': 0.0.18(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7))) + '@langchain/langgraph-sdk': 0.0.112(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7) uuid: 10.0.0 - zod: 3.25.76 + zod: 4.6.7 optionalDependencies: - zod-to-json-schema: 3.25.2(zod@4.4.3) + zod-to-json-schema: 3.25.2(zod@4.6.7) transitivePeerDependencies: - react - react-dom - '@langchain/langgraph@1.4.7(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod@3.25.76)': + '@langchain/langgraph@1.4.7(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod@4.6.7)': dependencies: - '@langchain/core': 1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0) - '@langchain/langgraph-checkpoint': 1.1.3(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0)) - '@langchain/langgraph-sdk': 1.9.25(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0))(react-dom@19.2.7(react@19.2.7))(react@19.2.7) + '@langchain/core': 1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0) + '@langchain/langgraph-checkpoint': 1.1.3(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0)) + '@langchain/langgraph-sdk': 1.9.25(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0))(react-dom@19.2.7(react@19.2.7))(react@19.2.7) '@langchain/protocol': 0.0.18 '@standard-schema/spec': 1.1.0 - zod: 3.25.76 + zod: 4.6.7 transitivePeerDependencies: - react - react-dom - svelte - vue - '@langchain/openai@1.1.3(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)))(ws@8.21.0)': + '@langchain/openai@1.1.3(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(ws@8.21.0)': dependencies: - '@langchain/core': 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.4.3)) + '@langchain/core': 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)) js-tiktoken: 1.0.21 - openai: 6.45.0(ws@8.21.0)(zod@3.25.76) - zod: 3.25.76 + openai: 6.45.0(ws@8.21.0)(zod@4.6.7) + zod: 4.6.7 transitivePeerDependencies: - '@aws-sdk/credential-provider-node' - '@smithy/hash-node' @@ -8195,7 +8187,7 @@ snapshots: globby: 11.1.0 read-yaml-file: 1.1.0 - '@modelcontextprotocol/sdk@1.29.0(@cfworker/json-schema@4.1.1)(zod@3.25.76)': + '@modelcontextprotocol/sdk@1.29.0(@cfworker/json-schema@4.1.1)(zod@4.6.7)': dependencies: '@hono/node-server': 1.19.14(hono@4.12.25) ajv: 8.20.0 @@ -8212,8 +8204,8 @@ snapshots: json-schema-typed: 8.0.2 pkce-challenge: 5.0.1 raw-body: 3.0.2 - zod: 3.25.76 - zod-to-json-schema: 3.25.2(zod@3.25.76) + zod: 4.6.7 + zod-to-json-schema: 3.25.2(zod@4.6.7) optionalDependencies: '@cfworker/json-schema': 4.1.1 transitivePeerDependencies: @@ -8282,7 +8274,7 @@ snapshots: '@ai-sdk/provider': 3.0.8 '@opencode-ai/sdk': 1.18.29 effect: 4.0.0-beta.83 - zod: 4.1.8 + zod: 4.6.7 '@opencode-ai/sdk@1.18.29': dependencies: @@ -11760,13 +11752,13 @@ snapshots: kubernetes-types@1.30.0: {} - langchain@1.5.3(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0))(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(ws@8.21.0): + langchain@1.5.3(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0))(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(ws@8.21.0): dependencies: - '@langchain/core': 1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0) - '@langchain/langgraph': 1.4.7(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod@3.25.76) - '@langchain/langgraph-checkpoint': 1.1.3(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0)) - langsmith: 0.8.0(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0) - zod: 3.25.76 + '@langchain/core': 1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0) + '@langchain/langgraph': 1.4.7(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod@4.6.7) + '@langchain/langgraph-checkpoint': 1.1.3(@langchain/core@1.2.1(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0)) + langsmith: 0.8.0(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0) + zod: 4.6.7 transitivePeerDependencies: - '@opentelemetry/api' - '@opentelemetry/exporter-trace-otlp-proto' @@ -11778,7 +11770,7 @@ snapshots: - vue - ws - langsmith@0.3.87(openai@6.45.0(ws@8.21.0)(zod@4.4.3)): + langsmith@0.3.87(openai@6.45.0(ws@8.21.0)(zod@4.6.7)): dependencies: '@types/uuid': 10.0.0 chalk: 4.1.2 @@ -11787,13 +11779,13 @@ snapshots: semver: 7.8.4 uuid: 10.0.0 optionalDependencies: - openai: 6.45.0(ws@8.21.0)(zod@4.4.3) + openai: 6.45.0(ws@8.21.0)(zod@4.6.7) - langsmith@0.8.0(openai@6.45.0(ws@8.21.0)(zod@3.25.76))(ws@8.21.0): + langsmith@0.8.0(openai@6.45.0(ws@8.21.0)(zod@4.6.7))(ws@8.21.0): dependencies: p-queue: 6.6.2 optionalDependencies: - openai: 6.45.0(ws@8.21.0)(zod@3.25.76) + openai: 6.45.0(ws@8.21.0)(zod@4.6.7) ws: 8.21.0 lazy-val@1.0.5: {} @@ -12039,7 +12031,7 @@ snapshots: mutation-server-protocol@0.4.1: dependencies: - zod: 4.6.1 + zod: 4.6.7 mutation-testing-elements@3.7.3: {} @@ -12148,16 +12140,10 @@ snapshots: is-inside-container: 1.0.0 wsl-utils: 0.1.0 - openai@6.45.0(ws@8.21.0)(zod@3.25.76): + openai@6.45.0(ws@8.21.0)(zod@4.6.7): optionalDependencies: ws: 8.21.0 - zod: 3.25.76 - - openai@6.45.0(ws@8.21.0)(zod@4.4.3): - optionalDependencies: - ws: 8.21.0 - zod: 4.4.3 - optional: true + zod: 4.6.7 opencode-ai@1.18.29: optionalDependencies: @@ -13407,22 +13393,11 @@ snapshots: compress-commons: 4.1.2 readable-stream: 3.6.2 - zod-to-json-schema@3.25.2(zod@3.25.76): + zod-to-json-schema@3.25.2(zod@4.6.7): dependencies: - zod: 3.25.76 - - zod-to-json-schema@3.25.2(zod@4.4.3): - dependencies: - zod: 4.4.3 - optional: true - - zod@3.25.76: {} - - zod@4.1.8: {} - - zod@4.4.3: {} + zod: 4.6.7 - zod@4.6.1: {} + zod@4.6.7: {} zustand@5.0.15(@types/react@19.2.17)(react@19.2.7): optionalDependencies: diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index e275e3c54..e07967099 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -21,5 +21,14 @@ onlyBuiltDependencies: # cross-platform rebuild HANG that the bare node-gyp override caused. overrides: "@electron/rebuild": ^3.7.0 + # Transitive deps pin or range below the catalog (exact pins, zod 3 ranges); + # forcing the catalog keeps every resolved zod at or above it. + zod: "catalog:" + +# Single source of the zod version for every workspace package (`"zod": "catalog:"`); +# pnpm publish writes the range into each published package.json. examples/ install +# with npm outside the workspace, so scripts/zod-floor.test.mjs checks them against it. +catalog: + zod: ^4.6.7 patchedDependencies: "@assistant-ui/react-opencode@0.2.22": patches/@assistant-ui__react-opencode@0.2.22.patch From 2b8f6a6b5b4c04e849f21b41540c2507fa792bea Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Mon, 2 Nov 2026 22:53:39 +0000 Subject: [PATCH 02/13] feat(agent-core): scaffold projects with the catalog's zod [SAP-4718] The scaffold's zod pin is generated from the pnpm catalog with the other offline fallbacks, so new projects get the version the SDK is built against. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../scripts/gen-version-fallback.mjs | 30 ++++++++-- packages/agent-core/src/scaffold.spec.ts | 56 +++++++++++++++++++ packages/agent-core/src/scaffold.ts | 11 ++-- .../src/version-fallback.generated.ts | 5 +- 4 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 packages/agent-core/src/scaffold.spec.ts diff --git a/packages/agent-core/scripts/gen-version-fallback.mjs b/packages/agent-core/scripts/gen-version-fallback.mjs index dc9547a6c..d070cc9f3 100644 --- a/packages/agent-core/scripts/gen-version-fallback.mjs +++ b/packages/agent-core/scripts/gen-version-fallback.mjs @@ -1,6 +1,7 @@ #!/usr/bin/env node // Generates src/version-fallback.generated.ts from the workspace's own -// @sapiom/agent + @sapiom/tools package.json versions. +// @sapiom/agent + @sapiom/tools package.json versions, and the zod version from +// the pnpm catalog in pnpm-workspace.yaml. // // Why this exists: scaffold.ts needs an OFFLINE fallback version to stamp into // a scaffolded project when the live npm lookup fails. That value must always be @@ -28,17 +29,38 @@ const versionOf = (pkgDir) => const agent = versionOf("agent"); const tools = versionOf("tools"); +// The default catalog is the repo's single source of the zod version; the scaffold +// pins its floor so new projects install the version the SDK is built against. +// Line-based read: the root has no YAML parser, and the block is flat `name: range`. +const catalogZod = () => { + const yaml = readFileSync( + resolve(here, "..", "..", "..", "pnpm-workspace.yaml"), + "utf8", + ); + const block = /^catalog:\n((?:[ \t]+.*\n?)*)/m.exec(yaml)?.[1] ?? ""; + const range = /^[ \t]+["']?zod["']?:[ \t]*["']?([^"'\s#]+)/m.exec(block)?.[1]; + const version = range?.replace(/^[\^~]/, ""); + if (!version || !/^\d+\.\d+\.\d+$/.test(version)) { + throw new Error( + `gen-version-fallback: no plain zod range in the pnpm-workspace.yaml catalog (got ${range})`, + ); + } + return version; +}; +const zod = catalogZod(); + const out = `// AUTO-GENERATED by packages/agent-core/scripts/gen-version-fallback.mjs. // Do NOT edit by hand. Regenerated on every build (agent-core \`prebuild\`) and in // the release \`version-packages\` step, so it always matches the workspace's -// @sapiom/agent + @sapiom/tools versions and the offline scaffold fallback can no -// longer drift. +// @sapiom/agent + @sapiom/tools versions and the zod catalog entry, and the +// offline scaffold fallback can no longer drift. export const VERSION_FALLBACK = { agent: ${JSON.stringify(agent)}, tools: ${JSON.stringify(tools)}, + zod: ${JSON.stringify(zod)}, } as const; `; const outPath = resolve(here, "..", "src", "version-fallback.generated.ts"); writeFileSync(outPath, out); -console.log(`gen-version-fallback: agent=${agent} tools=${tools}`); +console.log(`gen-version-fallback: agent=${agent} tools=${tools} zod=${zod}`); diff --git a/packages/agent-core/src/scaffold.spec.ts b/packages/agent-core/src/scaffold.spec.ts new file mode 100644 index 000000000..71bd5ca68 --- /dev/null +++ b/packages/agent-core/src/scaffold.spec.ts @@ -0,0 +1,56 @@ +/** + * Unit tests for the zod version a scaffolded project pins (SAP-4718). + * + * Fully offline: global.fetch rejects, so `resolveVersions` takes the generated + * fallback, which is where the pnpm catalog's zod reaches new projects. + */ +import { mkdtempSync, readFileSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +import { resolveVersions, scaffold } from "./scaffold"; + +const TEMPLATES_DIR = path.resolve(__dirname, "..", "templates"); + +/** Lowest zod the repo accepts, same floor as scripts/zod-floor.test.mjs. */ +const PATCHED_ZOD = [4, 6, 6]; + +function atLeast(version: string, floor: number[]): boolean { + const parts = version.split(".").map(Number); + for (let i = 0; i < floor.length; i++) { + if (parts[i] !== floor[i]) return parts[i] > floor[i]; + } + return true; +} + +describe("scaffolded zod version", () => { + let dir: string; + + beforeEach(() => { + dir = mkdtempSync(path.join(tmpdir(), "scaffold-zod-")); + jest + .spyOn(global, "fetch" as never) + .mockRejectedValue(new Error("offline") as never); + }); + + afterEach(() => { + jest.restoreAllMocks(); + rmSync(dir, { recursive: true, force: true }); + }); + + it("resolves a zod at or above the floor when the registry is unreachable", async () => { + const { zod } = await resolveVersions(); + expect(zod).toMatch(/^\d+\.\d+\.\d+$/); + expect(atLeast(zod, PATCHED_ZOD)).toBe(true); + }); + + it("stamps that zod into the default template's package.json", async () => { + const { zod } = await resolveVersions(); + const targetDir = path.join(dir, "proj"); + await scaffold({ targetDir, templatesDir: TEMPLATES_DIR }); + + const raw = readFileSync(path.join(targetDir, "package.json"), "utf8"); + expect(raw).not.toContain("__ZOD_VERSION__"); + expect(JSON.parse(raw).dependencies.zod).toBe(zod); + }); +}); diff --git a/packages/agent-core/src/scaffold.ts b/packages/agent-core/src/scaffold.ts index 1e6f286f0..e7b271be7 100644 --- a/packages/agent-core/src/scaffold.ts +++ b/packages/agent-core/src/scaffold.ts @@ -88,12 +88,9 @@ const DEFAULT_REGISTRY = "https://registry.npmjs.org"; // `VERSION_FALLBACK` (the offline fallback stamped into a scaffolded project when // the live npm lookup below fails) is imported from `version-fallback.generated.ts`, // which is generated from the workspace's own @sapiom/agent + @sapiom/tools -// package.json on every build and in the release `version-packages` step. It used -// to be a hand-maintained constant here and drifted on every SDK bump; deriving it -// from the published packages means it can never go stale again. - -/** The zod major the authoring SDK is built against. */ -const ZOD_VERSION = "4.1.12"; +// package.json and the pnpm catalog's zod on every build and in the release +// `version-packages` step. It used to be hand-maintained constants here that +// drifted on every bump; deriving them means they can never go stale again. export interface ResolvedVersions { agent: string; @@ -148,7 +145,7 @@ export async function resolveVersions(): Promise { return { agent: agent ?? VERSION_FALLBACK.agent, tools: tools ?? VERSION_FALLBACK.tools, - zod: ZOD_VERSION, + zod: VERSION_FALLBACK.zod, }; } diff --git a/packages/agent-core/src/version-fallback.generated.ts b/packages/agent-core/src/version-fallback.generated.ts index 74c9188f2..16f9dcfc9 100644 --- a/packages/agent-core/src/version-fallback.generated.ts +++ b/packages/agent-core/src/version-fallback.generated.ts @@ -1,9 +1,10 @@ // AUTO-GENERATED by packages/agent-core/scripts/gen-version-fallback.mjs. // Do NOT edit by hand. Regenerated on every build (agent-core `prebuild`) and in // the release `version-packages` step, so it always matches the workspace's -// @sapiom/agent + @sapiom/tools versions and the offline scaffold fallback can no -// longer drift. +// @sapiom/agent + @sapiom/tools versions and the zod catalog entry, and the +// offline scaffold fallback can no longer drift. export const VERSION_FALLBACK = { agent: "0.14.13", tools: "0.49.0", + zod: "4.6.7", } as const; From 230e3b4a925d56564de7d006a56594867532b5dc Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Mon, 2 Nov 2026 22:53:39 +0000 Subject: [PATCH 03/13] chore(examples): move examples to zod 4.6.7 and check zod against the catalog [SAP-4718] Examples install with npm outside the workspace, so scripts/zod-floor.test.mjs compares their zod, both lockfiles and the scaffold fallback with the catalog. examples/langchain-classic overrides zod for its LangChain dependencies. Co-Authored-By: Claude Opus 5.5 (1M context) --- examples/approval-chain/package.json | 2 +- examples/autonomous-pr/package.json | 2 +- examples/cold-outreach-engine/package.json | 2 +- .../content-repurposing-pipeline/package.json | 2 +- examples/creative-studio/package.json | 2 +- examples/dependency-upgrade/package.json | 2 +- examples/durable-backfill/package.json | 2 +- examples/error-triage-digest/package.json | 2 +- examples/eval-gate/package.json | 2 +- examples/fan-out-and-combine/package.json | 2 +- examples/fintech-exec-radar/package.json | 2 +- examples/hello-agent/package.json | 2 +- examples/human-in-the-loop/package.json | 2 +- examples/langchain-classic/package-lock.json | 8 +- examples/langchain-classic/package.json | 5 +- examples/langchain/package.json | 2 +- examples/logged-in-screenshots/package.json | 2 +- examples/managed-loop-with-mcp/package.json | 2 +- examples/meeting-notes-crm/package.json | 2 +- examples/news-roundup/package-lock.json | 8 +- examples/news-roundup/package.json | 2 +- examples/newsletter-autopilot/package.json | 2 +- examples/nl-db-query-endpoint/package.json | 2 +- .../personalized-media-at-scale/package.json | 2 +- examples/pr-review-bot/package.json | 2 +- examples/proposal-generator/package.json | 2 +- examples/research-to-microsite/package.json | 2 +- examples/scene-to-video/package.json | 2 +- .../scheduled-compliance-audit/package.json | 2 +- .../scheduled-db-insight-report/package.json | 2 +- .../scheduled-research-brief/package.json | 2 +- examples/slack-notifier/package.json | 2 +- .../agents/controller/package.json | 2 +- .../support-desk/agents/copilot/package.json | 2 +- .../support-desk/agents/digest/package.json | 2 +- .../agents/escalation/package.json | 2 +- .../support-desk/agents/intake/package.json | 2 +- .../support-desk/agents/setup/package.json | 2 +- .../agents/smoke-consume/package.json | 2 +- .../agents/smoke-ingest/package.json | 2 +- .../agents/urgent-pager/package.json | 2 +- .../support-desk/agents/watchdog/package.json | 2 +- examples/support-desk/package.json | 2 +- examples/the-brain/package.json | 2 +- examples/wait-for-webhook/package.json | 2 +- examples/web-research-digest/package.json | 2 +- scripts/zod-floor.test.mjs | 160 ++++++++++++++++++ 47 files changed, 215 insertions(+), 52 deletions(-) create mode 100644 scripts/zod-floor.test.mjs diff --git a/examples/approval-chain/package.json b/examples/approval-chain/package.json index d9f6cd986..c342c1d53 100644 --- a/examples/approval-chain/package.json +++ b/examples/approval-chain/package.json @@ -13,7 +13,7 @@ "@sapiom/agent": "^0.8.0", "@sapiom/tools": "^0.20.0", "postgres": "^3.4.5", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/autonomous-pr/package.json b/examples/autonomous-pr/package.json index 43d212574..030fed59e 100644 --- a/examples/autonomous-pr/package.json +++ b/examples/autonomous-pr/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/cold-outreach-engine/package.json b/examples/cold-outreach-engine/package.json index 6a82240ca..f881aab27 100644 --- a/examples/cold-outreach-engine/package.json +++ b/examples/cold-outreach-engine/package.json @@ -14,7 +14,7 @@ "@sapiom/agent": "^0.14.9", "@sapiom/tools": "^0.45.0", "postgres": "^3.4.5", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/content-repurposing-pipeline/package.json b/examples/content-repurposing-pipeline/package.json index 2cbc1e034..b35c8c13a 100644 --- a/examples/content-repurposing-pipeline/package.json +++ b/examples/content-repurposing-pipeline/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/creative-studio/package.json b/examples/creative-studio/package.json index 5ed8a60ed..b4bfce6c0 100644 --- a/examples/creative-studio/package.json +++ b/examples/creative-studio/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.14.3", "@sapiom/tools": "^0.39.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/dependency-upgrade/package.json b/examples/dependency-upgrade/package.json index 3a1608934..608f0187d 100644 --- a/examples/dependency-upgrade/package.json +++ b/examples/dependency-upgrade/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/durable-backfill/package.json b/examples/durable-backfill/package.json index 22dc9cfdd..56aa7ce0a 100644 --- a/examples/durable-backfill/package.json +++ b/examples/durable-backfill/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.6.5", "@sapiom/tools": "^0.20.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/error-triage-digest/package.json b/examples/error-triage-digest/package.json index badf209eb..04a857168 100644 --- a/examples/error-triage-digest/package.json +++ b/examples/error-triage-digest/package.json @@ -14,7 +14,7 @@ "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", "postgres": "^3.4.5", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/eval-gate/package.json b/examples/eval-gate/package.json index 7a7d64059..47f284ae2 100644 --- a/examples/eval-gate/package.json +++ b/examples/eval-gate/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/fan-out-and-combine/package.json b/examples/fan-out-and-combine/package.json index f893557ce..c8688ac8a 100644 --- a/examples/fan-out-and-combine/package.json +++ b/examples/fan-out-and-combine/package.json @@ -12,7 +12,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/fintech-exec-radar/package.json b/examples/fintech-exec-radar/package.json index 4d51eaf62..de2056eab 100644 --- a/examples/fintech-exec-radar/package.json +++ b/examples/fintech-exec-radar/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/hello-agent/package.json b/examples/hello-agent/package.json index 4800cb2d9..64ca1bb3c 100644 --- a/examples/hello-agent/package.json +++ b/examples/hello-agent/package.json @@ -12,7 +12,7 @@ "dependencies": { "@sapiom/agent": "^0.5.0", "@sapiom/tools": "^0.16.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/human-in-the-loop/package.json b/examples/human-in-the-loop/package.json index 45b5fa667..c194cc2c0 100644 --- a/examples/human-in-the-loop/package.json +++ b/examples/human-in-the-loop/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/langchain-classic/package-lock.json b/examples/langchain-classic/package-lock.json index ceb1fdfa9..70478ed54 100644 --- a/examples/langchain-classic/package-lock.json +++ b/examples/langchain-classic/package-lock.json @@ -14,7 +14,7 @@ "@langchain/openai": "^1.2.2", "@sapiom/langchain-classic": "latest", "dotenv": "^16.4.5", - "zod": "^3.22.4" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", @@ -1172,9 +1172,9 @@ } }, "node_modules/zod": { - "version": "3.25.76", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", - "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", + "version": "4.6.7", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz", + "integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==", "license": "MIT", "funding": { "url": "https://github.com/sponsors/colinhacks" diff --git a/examples/langchain-classic/package.json b/examples/langchain-classic/package.json index 06a7bf07f..66985dc59 100644 --- a/examples/langchain-classic/package.json +++ b/examples/langchain-classic/package.json @@ -14,11 +14,14 @@ "@langchain/openai": "^1.2.2", "@sapiom/langchain-classic": "latest", "dotenv": "^16.4.5", - "zod": "^3.22.4" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", "tsx": "^4.7.0", "typescript": "^5.4.2" + }, + "overrides": { + "zod": "$zod" } } diff --git a/examples/langchain/package.json b/examples/langchain/package.json index 5a3598894..b4298eb06 100644 --- a/examples/langchain/package.json +++ b/examples/langchain/package.json @@ -13,7 +13,7 @@ "@langchain/core": "~1.2.1", "dotenv": "^16.4.5", "langchain": "~1.5.3", - "zod": "^3.22.4" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/logged-in-screenshots/package.json b/examples/logged-in-screenshots/package.json index 9ba9c1b0f..c55f2d85b 100644 --- a/examples/logged-in-screenshots/package.json +++ b/examples/logged-in-screenshots/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/managed-loop-with-mcp/package.json b/examples/managed-loop-with-mcp/package.json index c6722b8b2..dca1dea43 100644 --- a/examples/managed-loop-with-mcp/package.json +++ b/examples/managed-loop-with-mcp/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.14.8", "@sapiom/tools": "^0.44.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/meeting-notes-crm/package.json b/examples/meeting-notes-crm/package.json index 8b28cd2a5..f01993723 100644 --- a/examples/meeting-notes-crm/package.json +++ b/examples/meeting-notes-crm/package.json @@ -14,7 +14,7 @@ "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", "postgres": "^3.4.5", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/news-roundup/package-lock.json b/examples/news-roundup/package-lock.json index 1b32ceee6..3b858b515 100644 --- a/examples/news-roundup/package-lock.json +++ b/examples/news-roundup/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "4.1.12" + "zod": "4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", @@ -1382,9 +1382,9 @@ } }, "node_modules/zod": { - "version": "4.1.12", - "resolved": "https://registry.npmjs.org/zod/-/zod-4.1.12.tgz", - "integrity": "sha512-JInaHOamG8pt5+Ey8kGmdcAcg3OL9reK8ltczgHTAwNhMys/6ThXHityHxVV2p3fkw/c+MAvBHFVYHFZDmjMCQ==", + "version": "4.6.7", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz", + "integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==", "license": "MIT", "funding": { "url": "https://github.com/sponsors/colinhacks" diff --git a/examples/news-roundup/package.json b/examples/news-roundup/package.json index 4a017ab34..31a1fb895 100644 --- a/examples/news-roundup/package.json +++ b/examples/news-roundup/package.json @@ -12,7 +12,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "4.1.12" + "zod": "4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/newsletter-autopilot/package.json b/examples/newsletter-autopilot/package.json index 767b04f8b..f5708f457 100644 --- a/examples/newsletter-autopilot/package.json +++ b/examples/newsletter-autopilot/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/nl-db-query-endpoint/package.json b/examples/nl-db-query-endpoint/package.json index 05d95ee98..d112b8770 100644 --- a/examples/nl-db-query-endpoint/package.json +++ b/examples/nl-db-query-endpoint/package.json @@ -13,7 +13,7 @@ "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", "postgres": "^3.4.5", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/personalized-media-at-scale/package.json b/examples/personalized-media-at-scale/package.json index 45d89512c..ab5afd138 100644 --- a/examples/personalized-media-at-scale/package.json +++ b/examples/personalized-media-at-scale/package.json @@ -13,7 +13,7 @@ "@sapiom/agent": "^0.9.3", "@sapiom/tools": "^0.28.0", "postgres": "^3.4.5", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/pr-review-bot/package.json b/examples/pr-review-bot/package.json index 5fac71086..6cd660a70 100644 --- a/examples/pr-review-bot/package.json +++ b/examples/pr-review-bot/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/proposal-generator/package.json b/examples/proposal-generator/package.json index da8149875..740455adb 100644 --- a/examples/proposal-generator/package.json +++ b/examples/proposal-generator/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/research-to-microsite/package.json b/examples/research-to-microsite/package.json index eca82a39a..115af457c 100644 --- a/examples/research-to-microsite/package.json +++ b/examples/research-to-microsite/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/scene-to-video/package.json b/examples/scene-to-video/package.json index 28540a3e0..26b7099fd 100644 --- a/examples/scene-to-video/package.json +++ b/examples/scene-to-video/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.14.3", "@sapiom/tools": "^0.39.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/scheduled-compliance-audit/package.json b/examples/scheduled-compliance-audit/package.json index 9db54d457..cc92f86cf 100644 --- a/examples/scheduled-compliance-audit/package.json +++ b/examples/scheduled-compliance-audit/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/scheduled-db-insight-report/package.json b/examples/scheduled-db-insight-report/package.json index f93fcb76b..d88385cd7 100644 --- a/examples/scheduled-db-insight-report/package.json +++ b/examples/scheduled-db-insight-report/package.json @@ -14,7 +14,7 @@ "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", "postgres": "^3.4.5", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/scheduled-research-brief/package.json b/examples/scheduled-research-brief/package.json index 1cdc8ff89..e86336924 100644 --- a/examples/scheduled-research-brief/package.json +++ b/examples/scheduled-research-brief/package.json @@ -12,7 +12,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/slack-notifier/package.json b/examples/slack-notifier/package.json index 3454b6ba8..d266a150f 100644 --- a/examples/slack-notifier/package.json +++ b/examples/slack-notifier/package.json @@ -14,7 +14,7 @@ "@sapiom/agent": "^0.6.5", "@sapiom/fetch": "^0.5.0", "@sapiom/tools": "^0.20.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/support-desk/agents/controller/package.json b/examples/support-desk/agents/controller/package.json index 7710f2ae0..2b242dcf5 100644 --- a/examples/support-desk/agents/controller/package.json +++ b/examples/support-desk/agents/controller/package.json @@ -9,6 +9,6 @@ "@sapiom/tools": "^0.41.0", "pg-mem": "^3.0.14", "postgres": "^3.4.9", - "zod": "^4.1.12" + "zod": "^4.6.7" } } diff --git a/examples/support-desk/agents/copilot/package.json b/examples/support-desk/agents/copilot/package.json index 7db1a9a83..b2e37f6de 100644 --- a/examples/support-desk/agents/copilot/package.json +++ b/examples/support-desk/agents/copilot/package.json @@ -9,6 +9,6 @@ "@sapiom/tools": "^0.41.0", "pg-mem": "^3.0.14", "postgres": "^3.4.9", - "zod": "^4.1.12" + "zod": "^4.6.7" } } diff --git a/examples/support-desk/agents/digest/package.json b/examples/support-desk/agents/digest/package.json index 9932fadfd..b89254d83 100644 --- a/examples/support-desk/agents/digest/package.json +++ b/examples/support-desk/agents/digest/package.json @@ -9,6 +9,6 @@ "@sapiom/tools": "^0.41.0", "pg-mem": "^3.0.14", "postgres": "^3.4.9", - "zod": "^4.1.12" + "zod": "^4.6.7" } } diff --git a/examples/support-desk/agents/escalation/package.json b/examples/support-desk/agents/escalation/package.json index 2835c7273..298f8742f 100644 --- a/examples/support-desk/agents/escalation/package.json +++ b/examples/support-desk/agents/escalation/package.json @@ -9,6 +9,6 @@ "@sapiom/tools": "^0.41.0", "pg-mem": "^3.0.14", "postgres": "^3.4.9", - "zod": "^4.1.12" + "zod": "^4.6.7" } } diff --git a/examples/support-desk/agents/intake/package.json b/examples/support-desk/agents/intake/package.json index 87ed570ac..ca89c8d89 100644 --- a/examples/support-desk/agents/intake/package.json +++ b/examples/support-desk/agents/intake/package.json @@ -9,6 +9,6 @@ "@sapiom/tools": "^0.41.0", "pg-mem": "^3.0.14", "postgres": "^3.4.9", - "zod": "^4.1.12" + "zod": "^4.6.7" } } diff --git a/examples/support-desk/agents/setup/package.json b/examples/support-desk/agents/setup/package.json index 5da5f5e59..d0d289c81 100644 --- a/examples/support-desk/agents/setup/package.json +++ b/examples/support-desk/agents/setup/package.json @@ -9,6 +9,6 @@ "@sapiom/tools": "^0.41.0", "pg-mem": "^3.0.14", "postgres": "^3.4.9", - "zod": "^4.1.12" + "zod": "^4.6.7" } } diff --git a/examples/support-desk/agents/smoke-consume/package.json b/examples/support-desk/agents/smoke-consume/package.json index 6973276f5..c4f0b0c0d 100644 --- a/examples/support-desk/agents/smoke-consume/package.json +++ b/examples/support-desk/agents/smoke-consume/package.json @@ -9,6 +9,6 @@ "@sapiom/tools": "^0.41.0", "pg-mem": "^3.0.14", "postgres": "^3.4.9", - "zod": "^4.1.12" + "zod": "^4.6.7" } } diff --git a/examples/support-desk/agents/smoke-ingest/package.json b/examples/support-desk/agents/smoke-ingest/package.json index 4f2bfef0d..a50528ad9 100644 --- a/examples/support-desk/agents/smoke-ingest/package.json +++ b/examples/support-desk/agents/smoke-ingest/package.json @@ -9,6 +9,6 @@ "@sapiom/tools": "^0.41.0", "pg-mem": "^3.0.14", "postgres": "^3.4.9", - "zod": "^4.1.12" + "zod": "^4.6.7" } } diff --git a/examples/support-desk/agents/urgent-pager/package.json b/examples/support-desk/agents/urgent-pager/package.json index 84808c761..efc9a6a32 100644 --- a/examples/support-desk/agents/urgent-pager/package.json +++ b/examples/support-desk/agents/urgent-pager/package.json @@ -9,6 +9,6 @@ "@sapiom/tools": "^0.41.0", "pg-mem": "^3.0.14", "postgres": "^3.4.9", - "zod": "^4.1.12" + "zod": "^4.6.7" } } diff --git a/examples/support-desk/agents/watchdog/package.json b/examples/support-desk/agents/watchdog/package.json index af0962a44..c3bec661b 100644 --- a/examples/support-desk/agents/watchdog/package.json +++ b/examples/support-desk/agents/watchdog/package.json @@ -9,6 +9,6 @@ "@sapiom/tools": "^0.41.0", "pg-mem": "^3.0.14", "postgres": "^3.4.9", - "zod": "^4.1.12" + "zod": "^4.6.7" } } diff --git a/examples/support-desk/package.json b/examples/support-desk/package.json index e7c844c7a..2a496be03 100644 --- a/examples/support-desk/package.json +++ b/examples/support-desk/package.json @@ -21,7 +21,7 @@ "@sapiom/tools": "^0.41.0", "pg-mem": "^3.0.14", "postgres": "^3.4.9", - "zod": "^4.1.12" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/the-brain/package.json b/examples/the-brain/package.json index c030a9c14..61ca31eab 100644 --- a/examples/the-brain/package.json +++ b/examples/the-brain/package.json @@ -14,7 +14,7 @@ "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", "postgres": "^3.4.5", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/wait-for-webhook/package.json b/examples/wait-for-webhook/package.json index c70f82255..e3fc35597 100644 --- a/examples/wait-for-webhook/package.json +++ b/examples/wait-for-webhook/package.json @@ -13,7 +13,7 @@ "dependencies": { "@sapiom/agent": "^0.12.0", "@sapiom/tools": "^0.31.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/examples/web-research-digest/package.json b/examples/web-research-digest/package.json index fa224a094..6209dcde7 100644 --- a/examples/web-research-digest/package.json +++ b/examples/web-research-digest/package.json @@ -12,7 +12,7 @@ "dependencies": { "@sapiom/agent": "^0.5.0", "@sapiom/tools": "^0.16.0", - "zod": "^3.25.76 || ^4.0.0" + "zod": "^4.6.7" }, "devDependencies": { "@types/node": "^20.11.30", diff --git a/scripts/zod-floor.test.mjs b/scripts/zod-floor.test.mjs new file mode 100644 index 000000000..92d81f25a --- /dev/null +++ b/scripts/zod-floor.test.mjs @@ -0,0 +1,160 @@ +// ============================================================================= +// scripts/zod-floor.test.mjs +// +// Keeps every zod this repository declares or resolves on the version set once in +// the pnpm catalog (pnpm-workspace.yaml), and that version at or above the floor. +// Workspace packages reference the catalog; examples install with npm outside the +// workspace and the scaffold fallback is generated, so both are compared to it here. +// +// Run: pnpm examples:check:test (node --test) +// ============================================================================= + +import assert from "node:assert/strict"; +import { readdirSync, readFileSync } from "node:fs"; +import path from "node:path"; +import test from "node:test"; +import { fileURLToPath } from "node:url"; + +const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); +const FLOOR = "4.6.6"; +const DEP_FIELDS = ["dependencies", "devDependencies"]; + +const read = (file) => readFileSync(path.join(ROOT, file), "utf8"); +const readJson = (file) => JSON.parse(read(file)); + +const compare = (left, right) => { + const a = left.split(".").map(Number); + const b = right.split(".").map(Number); + for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] - b[i]; + return 0; +}; +const minimumOf = (range) => /^[\^~]?(\d+\.\d+\.\d+)$/.exec(range)?.[1] ?? null; + +function catalogRange() { + const block = + /^catalog:\n((?:[ \t]+.*\n?)*)/m.exec(read("pnpm-workspace.yaml"))?.[1] ?? + ""; + return /^[ \t]+["']?zod["']?:[ \t]*["']?([^"'\s#]+)/m.exec(block)?.[1]; +} + +function packageJsons(dir) { + const found = []; + for (const entry of readdirSync(path.join(ROOT, dir), { + withFileTypes: true, + })) { + if (entry.name === "node_modules" || entry.name.startsWith(".")) continue; + const rel = path.join(dir, entry.name); + if (entry.isDirectory()) found.push(...packageJsons(rel)); + else if (entry.name === "package.json") found.push(rel); + } + return found; +} + +const zodDeclarations = (manifest) => + DEP_FIELDS.filter((field) => manifest[field]?.zod !== undefined).map( + (field) => [field, manifest[field].zod], + ); + +const catalog = catalogRange(); +const catalogMinimum = catalog && minimumOf(catalog); + +test("the pnpm catalog sets one zod at or above the floor, enforced by an override", () => { + assert.ok( + catalogMinimum, + `pnpm-workspace.yaml catalog zod is not a plain range: ${catalog}`, + ); + assert.ok( + compare(catalogMinimum, FLOOR) >= 0, + `pnpm-workspace.yaml catalog zod ${catalog} is below ${FLOOR}`, + ); + assert.match( + read("pnpm-workspace.yaml"), + /^overrides:\n(?:[ \t]+.*\n|[ \t]*#.*\n)*?[ \t]+["']?zod["']?:[ \t]*["']catalog:["']/m, + "pnpm-workspace.yaml overrides must force zod to catalog:", + ); +}); + +test("workspace packages take zod from the catalog", () => { + const packages = readdirSync(path.join(ROOT, "packages"), { + withFileTypes: true, + }) + .filter((entry) => entry.isDirectory()) + .map((entry) => path.join("packages", entry.name, "package.json")) + .filter((file) => { + try { + read(file); + return true; + } catch { + return false; + } + }); + const offenders = packages.flatMap((file) => + zodDeclarations(readJson(file)) + .filter(([, range]) => range !== "catalog:") + .map(([field, range]) => `${file} ${field}.zod = ${range}`), + ); + assert.deepEqual(offenders, []); +}); + +test("examples declare the catalog's zod", () => { + const offenders = []; + for (const file of packageJsons("examples")) { + const manifest = readJson(file); + for (const [field, range] of zodDeclarations(manifest)) { + if (range === "__ZOD_VERSION__") continue; + if (minimumOf(range) !== catalogMinimum) + offenders.push(`${file} ${field}.zod = ${range}`); + } + const override = manifest.overrides?.zod; + if ( + override !== undefined && + override !== "$zod" && + minimumOf(override) !== catalogMinimum + ) { + offenders.push(`${file} overrides.zod = ${override}`); + } + } + assert.deepEqual(offenders, []); +}); + +test("lockfiles resolve no zod below the floor", () => { + const offenders = []; + for (const match of read("pnpm-lock.yaml").matchAll( + /(? + path.join(path.dirname(file), "package-lock.json"), + ); + for (const file of npmLocks) { + let lock; + try { + lock = readJson(file); + } catch { + continue; + } + for (const [key, entry] of Object.entries(lock.packages ?? {})) { + if ( + /(?:^|\/)node_modules\/zod$/.test(key) && + compare(entry.version, FLOOR) < 0 + ) { + offenders.push(`${file} ${key}@${entry.version}`); + } + } + } + assert.deepEqual(offenders, []); +}); + +test("the scaffold fallback pins the catalog's zod", () => { + const generated = read( + "packages/agent-core/src/version-fallback.generated.ts", + ); + const zod = /\bzod:\s*"([^"]+)"/.exec(generated)?.[1]; + assert.equal( + zod, + catalogMinimum, + "packages/agent-core/src/version-fallback.generated.ts: run the agent-core prebuild", + ); +}); From 31f40e8ce79ee42217776ef4409785aa987ae6d2 Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Mon, 2 Nov 2026 23:16:33 +0000 Subject: [PATCH 04/13] fix: keep emit_event payload optional on zod 4 and read a CRLF catalog [SAP-4718] zod 4.6 treats a `z.unknown()` object key as required, so `sapiom_dev_agents_emit_event` without a payload failed MCP argument validation and listed `payload` as required. It is now explicitly optional, with a boundary test over an in-memory MCP client. The catalog readers in the scaffold generator and the zod floor check now accept CRLF, which a Windows checkout can produce; a test runs the generator on a CRLF copy. Two comments are reworded to state what they check. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../scripts/gen-version-fallback.mjs | 4 +- packages/agent-core/src/scaffold.ts | 7 +- packages/mcp/src/tools/agents.ts | 5 +- packages/mcp/src/tools/tool-schemas.test.ts | 25 ++++++- scripts/zod-floor.test.mjs | 66 ++++++++++++++++--- 5 files changed, 89 insertions(+), 18 deletions(-) diff --git a/packages/agent-core/scripts/gen-version-fallback.mjs b/packages/agent-core/scripts/gen-version-fallback.mjs index d070cc9f3..d45a0952b 100644 --- a/packages/agent-core/scripts/gen-version-fallback.mjs +++ b/packages/agent-core/scripts/gen-version-fallback.mjs @@ -33,10 +33,12 @@ const tools = versionOf("tools"); // pins its floor so new projects install the version the SDK is built against. // Line-based read: the root has no YAML parser, and the block is flat `name: range`. const catalogZod = () => { + // A Windows checkout can turn LF into CRLF, which the line patterns below + // would not match. const yaml = readFileSync( resolve(here, "..", "..", "..", "pnpm-workspace.yaml"), "utf8", - ); + ).replace(/\r\n/g, "\n"); const block = /^catalog:\n((?:[ \t]+.*\n?)*)/m.exec(yaml)?.[1] ?? ""; const range = /^[ \t]+["']?zod["']?:[ \t]*["']?([^"'\s#]+)/m.exec(block)?.[1]; const version = range?.replace(/^[\^~]/, ""); diff --git a/packages/agent-core/src/scaffold.ts b/packages/agent-core/src/scaffold.ts index e7b271be7..8d51c098c 100644 --- a/packages/agent-core/src/scaffold.ts +++ b/packages/agent-core/src/scaffold.ts @@ -87,10 +87,9 @@ const DEFAULT_REGISTRY = "https://registry.npmjs.org"; // `VERSION_FALLBACK` (the offline fallback stamped into a scaffolded project when // the live npm lookup below fails) is imported from `version-fallback.generated.ts`, -// which is generated from the workspace's own @sapiom/agent + @sapiom/tools -// package.json and the pnpm catalog's zod on every build and in the release -// `version-packages` step. It used to be hand-maintained constants here that -// drifted on every bump; deriving them means they can never go stale again. +// which agent-core prebuild and the release `version-packages` step derive from the +// @sapiom/agent and @sapiom/tools package.json files and the pnpm catalog's zod, so +// offline scaffolds track the workspace. export interface ResolvedVersions { agent: string; diff --git a/packages/mcp/src/tools/agents.ts b/packages/mcp/src/tools/agents.ts index b2f90c59d..a68bd1e93 100644 --- a/packages/mcp/src/tools/agents.ts +++ b/packages/mcp/src/tools/agents.ts @@ -685,12 +685,13 @@ export function register(server: McpServer, env: ResolvedEnvironment): void { // other object arg in this module gets. `asEventPayload` re-imposes the // object rule after decoding, so nothing is loosened. // - // `z.unknown()` also advertises as NOT required in `tools/list`, which is - // why an omitted payload defaults to `{}` below rather than failing: the + // `.optional()` keeps it out of `required` in `tools/list`, which is why + // an omitted payload defaults to `{}` below rather than failing: the // schema an agent reads has to be the schema the handler honors, and an // event carrying no data is legitimate. Same `?? {}` as the run tool. payload: z .unknown() + .optional() .describe( "Event data, as a JSON object. It becomes the top layer of the run input, folded over each matched trigger's configured input (the payload wins on a key conflict). Keys the target agent's entry step does not declare are NOT dropped for agents built with @sapiom/agent (buildManifest strips the marker the engine's filter keys off), so they reach the run input and the author's own parse decides: a z.object() entry ignores them, a z.strictObject() entry rejects them and the step fails. Match the entry schema when you can. Omit it for an event that carries no data.", ), diff --git a/packages/mcp/src/tools/tool-schemas.test.ts b/packages/mcp/src/tools/tool-schemas.test.ts index 561af22e2..fc1493ba7 100644 --- a/packages/mcp/src/tools/tool-schemas.test.ts +++ b/packages/mcp/src/tools/tool-schemas.test.ts @@ -7,15 +7,21 @@ import { mkdtempSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; -import { afterEach, describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js"; import type { ResolvedEnvironment } from "../credentials.js"; +import { register as registerAgents } from "./agents.js"; import { register as registerFeedback } from "./feedback.js"; import { register as registerSandbox } from "./sandbox.js"; +// Signed out: a tool that passes argument validation answers NOT_AUTHENTICATED. +vi.mock("../credentials.js", () => ({ + readCredentials: vi.fn(async () => null), +})); + const env: ResolvedEnvironment = { name: "production", appURL: "https://app.sapiom.ai", @@ -34,6 +40,7 @@ async function connect(): Promise { const server = new McpServer({ name: "sapiom-dev", version: "0.0.0" }); registerSandbox(server, env); registerFeedback(server, env); + registerAgents(server, env); const client = new Client({ name: "test-client", version: "0.0.0" }); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); @@ -105,4 +112,20 @@ describe("tool input schemas over tools/list", () => { expect(result.isError).toBe(true); }); + + it("sapiom_dev_agents_emit_event accepts an omitted payload", async () => { + const client = await connect(); + const { tools } = await client.listTools(); + const emit = tools.find( + (tool) => tool.name === "sapiom_dev_agents_emit_event", + )!; + expect(emit.inputSchema.required).toEqual(["type"]); + + const result = await client.callTool({ + name: "sapiom_dev_agents_emit_event", + arguments: { type: "heartbeat.tick" }, + }); + const text = (result.content as Array<{ text: string }>)[0]!.text; + expect(JSON.parse(text).error.code).toBe("NOT_AUTHENTICATED"); + }); }); diff --git a/scripts/zod-floor.test.mjs b/scripts/zod-floor.test.mjs index 92d81f25a..fc8f8a25b 100644 --- a/scripts/zod-floor.test.mjs +++ b/scripts/zod-floor.test.mjs @@ -1,16 +1,27 @@ // ============================================================================= // scripts/zod-floor.test.mjs // -// Keeps every zod this repository declares or resolves on the version set once in -// the pnpm catalog (pnpm-workspace.yaml), and that version at or above the floor. -// Workspace packages reference the catalog; examples install with npm outside the -// workspace and the scaffold fallback is generated, so both are compared to it here. +// The pnpm catalog (pnpm-workspace.yaml) is the one place the zod version is set. +// Workspace dependencies must reference it (peer ranges are excluded). Examples +// install with npm outside the workspace and the scaffold pin is generated, so both +// must match the catalog minimum. The catalog and every lockfile resolution must +// meet FLOOR. // // Run: pnpm examples:check:test (node --test) // ============================================================================= import assert from "node:assert/strict"; -import { readdirSync, readFileSync } from "node:fs"; +import { execFileSync } from "node:child_process"; +import { + copyFileSync, + mkdirSync, + mkdtempSync, + readdirSync, + readFileSync, + rmSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; @@ -19,7 +30,10 @@ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const FLOOR = "4.6.6"; const DEP_FIELDS = ["dependencies", "devDependencies"]; -const read = (file) => readFileSync(path.join(ROOT, file), "utf8"); +// A Windows checkout can turn LF into CRLF, which the line patterns below would +// not match. +const read = (file) => + readFileSync(path.join(ROOT, file), "utf8").replace(/\r\n/g, "\n"); const readJson = (file) => JSON.parse(read(file)); const compare = (left, right) => { @@ -30,10 +44,9 @@ const compare = (left, right) => { }; const minimumOf = (range) => /^[\^~]?(\d+\.\d+\.\d+)$/.exec(range)?.[1] ?? null; -function catalogRange() { - const block = - /^catalog:\n((?:[ \t]+.*\n?)*)/m.exec(read("pnpm-workspace.yaml"))?.[1] ?? - ""; +function catalogRange(yaml = read("pnpm-workspace.yaml")) { + const lf = yaml.replace(/\r\n/g, "\n"); + const block = /^catalog:\n((?:[ \t]+.*\n?)*)/m.exec(lf)?.[1] ?? ""; return /^[ \t]+["']?zod["']?:[ \t]*["']?([^"'\s#]+)/m.exec(block)?.[1]; } @@ -74,6 +87,39 @@ test("the pnpm catalog sets one zod at or above the floor, enforced by an overri ); }); +test("a CRLF checkout yields the same catalog zod, here and in the scaffold generator", () => { + const crlf = read("pnpm-workspace.yaml").replace(/\n/g, "\r\n"); + assert.equal(catalogRange(crlf), catalog); + + const tree = mkdtempSync(path.join(tmpdir(), "zod-floor-crlf-")); + try { + writeFileSync(path.join(tree, "pnpm-workspace.yaml"), crlf); + for (const pkg of ["agent", "tools"]) { + mkdirSync(path.join(tree, "packages", pkg), { recursive: true }); + copyFileSync( + path.join(ROOT, "packages", pkg, "package.json"), + path.join(tree, "packages", pkg, "package.json"), + ); + } + mkdirSync(path.join(tree, "packages/agent-core/scripts"), { + recursive: true, + }); + mkdirSync(path.join(tree, "packages/agent-core/src")); + const script = "packages/agent-core/scripts/gen-version-fallback.mjs"; + copyFileSync(path.join(ROOT, script), path.join(tree, script)); + execFileSync(process.execPath, [path.join(tree, script)], { + stdio: "ignore", + }); + const generated = readFileSync( + path.join(tree, "packages/agent-core/src/version-fallback.generated.ts"), + "utf8", + ); + assert.equal(/\bzod:\s*"([^"]+)"/.exec(generated)?.[1], catalogMinimum); + } finally { + rmSync(tree, { recursive: true, force: true }); + } +}); + test("workspace packages take zod from the catalog", () => { const packages = readdirSync(path.join(ROOT, "packages"), { withFileTypes: true, From 0ec4544733b167f5ad0d90191c7856b4331e4d5b Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Mon, 2 Nov 2026 23:21:56 +0000 Subject: [PATCH 05/13] docs(mcp): state the emit_event payload default precisely [SAP-4718] Co-Authored-By: Claude Opus 5.5 (1M context) --- packages/mcp/src/tools/agents.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/mcp/src/tools/agents.ts b/packages/mcp/src/tools/agents.ts index a68bd1e93..99d7c7900 100644 --- a/packages/mcp/src/tools/agents.ts +++ b/packages/mcp/src/tools/agents.ts @@ -685,10 +685,9 @@ export function register(server: McpServer, env: ResolvedEnvironment): void { // other object arg in this module gets. `asEventPayload` re-imposes the // object rule after decoding, so nothing is loosened. // - // `.optional()` keeps it out of `required` in `tools/list`, which is why - // an omitted payload defaults to `{}` below rather than failing: the - // schema an agent reads has to be the schema the handler honors, and an - // event carrying no data is legitimate. Same `?? {}` as the run tool. + // `.optional()` keeps payload out of `required` in `tools/list`: the advertised + // schema must match the handler's `{}` default for an omitted payload, since an + // event may carry no data. Explicit `null` still fails the object rule. payload: z .unknown() .optional() From bf35ebe120fca2dfccbcb28720992d98e5e99215 Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Tue, 3 Nov 2026 00:36:07 +0000 Subject: [PATCH 06/13] test(scripts): read pnpm-workspace.yaml blocks line by line in the zod floor check [SAP-4718] The block regexes could backtrack heavily on long runs of blank indented lines; a line scan has no such case. Co-Authored-By: Claude Opus 5.5 (1M context) --- scripts/zod-floor.test.mjs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/zod-floor.test.mjs b/scripts/zod-floor.test.mjs index fc8f8a25b..a091d4625 100644 --- a/scripts/zod-floor.test.mjs +++ b/scripts/zod-floor.test.mjs @@ -44,12 +44,23 @@ const compare = (left, right) => { }; const minimumOf = (range) => /^[\^~]?(\d+\.\d+\.\d+)$/.exec(range)?.[1] ?? null; -function catalogRange(yaml = read("pnpm-workspace.yaml")) { - const lf = yaml.replace(/\r\n/g, "\n"); - const block = /^catalog:\n((?:[ \t]+.*\n?)*)/m.exec(lf)?.[1] ?? ""; - return /^[ \t]+["']?zod["']?:[ \t]*["']?([^"'\s#]+)/m.exec(block)?.[1]; +// The zod value under a top-level YAML key, read line by line: the root has no +// YAML parser, and the blocks are flat `name: value`. +function zodUnder(key, yaml) { + const lines = yaml.split(/\r?\n/); + const start = lines.indexOf(`${key}:`); + if (start === -1) return undefined; + for (const line of lines.slice(start + 1)) { + if (!/^[ \t]/.test(line)) break; + const value = /^[ \t]+["']?zod["']?:[ \t]*["']?([^"'\s#]+)/.exec(line)?.[1]; + if (value) return value; + } + return undefined; } +const catalogRange = (yaml = read("pnpm-workspace.yaml")) => + zodUnder("catalog", yaml); + function packageJsons(dir) { const found = []; for (const entry of readdirSync(path.join(ROOT, dir), { @@ -80,9 +91,9 @@ test("the pnpm catalog sets one zod at or above the floor, enforced by an overri compare(catalogMinimum, FLOOR) >= 0, `pnpm-workspace.yaml catalog zod ${catalog} is below ${FLOOR}`, ); - assert.match( - read("pnpm-workspace.yaml"), - /^overrides:\n(?:[ \t]+.*\n|[ \t]*#.*\n)*?[ \t]+["']?zod["']?:[ \t]*["']catalog:["']/m, + assert.equal( + zodUnder("overrides", read("pnpm-workspace.yaml")), + "catalog:", "pnpm-workspace.yaml overrides must force zod to catalog:", ); }); From c3ac453ad82a350a26b94cd245df041fe3512052 Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Tue, 10 Nov 2026 19:36:32 +0000 Subject: [PATCH 07/13] test(mcp): ignore a sapiom.json whose env holds a non-string value [SAP-4718] The map scan reads sapiom.json through `sapiomJsonSchema`, whose `env` is `z.record(z.string(), z.string())`. Every env fixture in scan-project.test.ts held strings, so loosening the value type to `z.unknown()` passed the whole file while the scan started reading launch keys from a file it used to reject. The new case puts a numeric `PORT` beside `WORKER_SLUG` and expects both agents mapped with no launch edge. It fails when the value type is loosened. Raised by CodeRabbit on the zod 4 change. Co-Authored-By: Claude Fable 5.2 --- packages/mcp/src/map/scan-project.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/mcp/src/map/scan-project.test.ts b/packages/mcp/src/map/scan-project.test.ts index 26eca2919..4d8c8977e 100644 --- a/packages/mcp/src/map/scan-project.test.ts +++ b/packages/mcp/src/map/scan-project.test.ts @@ -331,6 +331,19 @@ export async function b(ctx: any, id: string) { await ctx.sapiom.agents.run({ de }); }); + it("ignores a sapiom.json whose env holds a non-string value", async () => { + const root = await project({ + "door/sapiom.json": '{ "resources": { "web": { "env": { "PORT": 8080, "WORKER_SLUG": "worker" } } } }', + "door/index.ts": agentSource("door"), + "worker/index.ts": agentSource("worker"), + }); + + const map = await mapOf(root); + + expect(map.agents.map((agent) => agent.slug)).toEqual(["door", "worker"]); + expect(edgesOf(map)).toEqual([]); + }); + it("uses a zod default only for the input the step itself reads", async () => { const root = await project({ "caller/index.ts": agentSource( From f067e6e5a73e4b6878ffa738bf6b0a61f6f5fdb4 Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:30:05 +0000 Subject: [PATCH 08/13] test(langchain-classic): run LangGraph's zod state API on the workspace zod [SAP-4718] The workspace zod override also replaces the zod inside @langchain/langgraph. LangGraph 0.2.74 declares zod ^3.23.8 and cannot read a zod 4 schema, so new StateGraph(MessagesZodState) throws "Invalid StateGraph input." The other langchain-classic tests mock LangGraph and do not see this. This test uses the real LangGraph. It fails on this commit and passes once LangGraph is upgraded in the next one. Co-Authored-By: Claude Fable 5.2 --- .../src/langgraph-zod-state.test.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 packages/langchain-classic/src/langgraph-zod-state.test.ts diff --git a/packages/langchain-classic/src/langgraph-zod-state.test.ts b/packages/langchain-classic/src/langgraph-zod-state.test.ts new file mode 100644 index 000000000..16d3a5428 --- /dev/null +++ b/packages/langchain-classic/src/langgraph-zod-state.test.ts @@ -0,0 +1,27 @@ +/** + * The workspace forces every zod onto the catalog version, LangGraph's own + * copy included. This runs the real LangGraph (no mock) on its zod state API, + * so a LangGraph that cannot read that zod fails here. + */ +import { END, MessagesZodState, START, StateGraph } from "@langchain/langgraph"; + +describe("LangGraph zod state on the workspace zod", () => { + it("builds StateGraph(MessagesZodState) and runs one step", async () => { + const graph = new StateGraph(MessagesZodState) + .addNode("echo", (state) => ({ + messages: [{ role: "ai", content: `seen ${state.messages.length}` }], + })) + .addEdge(START, "echo") + .addEdge("echo", END) + .compile(); + + const result = await graph.invoke({ + messages: [{ role: "user", content: "hi" }], + }); + + expect(result.messages.map((message) => message.content)).toEqual([ + "hi", + "seen 1", + ]); + }); +}); From 2d7a8d74e49a62357ce884c3b14d0d2e62ead07c Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:31:34 +0000 Subject: [PATCH 09/13] fix(langchain-classic): test against LangGraph 0.3.12, which reads zod 4 [SAP-4718] LangGraph 0.2.74 declares zod ^3.23.8. The workspace zod override puts it on zod 4.6.7, and its zod state API then rejects every schema: new StateGraph(MessagesZodState) throws "Invalid StateGraph input." LangGraph 0.3.12 accepts zod 4 schemas and stays inside this package's peer range (>=0.2.0 <1.0.0). It reuses the langgraph-checkpoint and langgraph-sdk versions already in the lockfile, so the lockfile changes one package. Narrowing the override instead would bring zod 3.25.76 back into pnpm-lock.yaml. GHSA-mrhx-c7xc-m3w5 covers every zod below 4.6.6, so the lockfile alert would stay open. Co-Authored-By: Claude Fable 5.2 --- packages/langchain-classic/package.json | 2 +- pnpm-lock.yaml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/langchain-classic/package.json b/packages/langchain-classic/package.json index 4b9a3ba64..977066330 100644 --- a/packages/langchain-classic/package.json +++ b/packages/langchain-classic/package.json @@ -58,7 +58,7 @@ "devDependencies": { "@langchain/anthropic": "^0.3.30", "@langchain/core": "^0.3.78", - "@langchain/langgraph": "^0.2.74", + "@langchain/langgraph": "^0.3.12", "@langchain/openai": "~1.1.0", "@types/jest": "^29.5.14", "@types/node": "^20.11.30", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 458f5f50a..ad5e3b64f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -676,8 +676,8 @@ importers: specifier: ^0.3.78 version: 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)) '@langchain/langgraph': - specifier: ^0.2.74 - version: 0.2.74(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod-to-json-schema@3.25.2(zod@4.6.7)) + specifier: ^0.3.12 + version: 0.3.12(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod-to-json-schema@3.25.2(zod@4.6.7)) '@langchain/openai': specifier: ~1.1.0 version: 1.1.3(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(ws@8.21.0) @@ -2026,11 +2026,11 @@ packages: vue: optional: true - '@langchain/langgraph@0.2.74': - resolution: {integrity: sha512-oHpEi5sTZTPaeZX1UnzfM2OAJ21QGQrwReTV6+QnX7h8nDCBzhtipAw1cK616S+X8zpcVOjgOtJuaJhXa4mN8w==} + '@langchain/langgraph@0.3.12': + resolution: {integrity: sha512-4jKvfmxxgQyKnCvXdFbcKt6MdfaJoQ2WWqBR16o2E6D2RxqHvnLMMClZh4FSd6WYw39z5LGWvzRapFbRMqxu1A==} engines: {node: '>=18'} peerDependencies: - '@langchain/core': '>=0.2.36 <0.3.0 || >=0.3.40 < 0.4.0' + '@langchain/core': '>=0.3.58 < 0.4.0' zod-to-json-schema: ^3.x peerDependenciesMeta: zod-to-json-schema: @@ -8117,7 +8117,7 @@ snapshots: react: 19.2.7 react-dom: 19.2.7(react@19.2.7) - '@langchain/langgraph@0.2.74(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod-to-json-schema@3.25.2(zod@4.6.7))': + '@langchain/langgraph@0.3.12(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod-to-json-schema@3.25.2(zod@4.6.7))': dependencies: '@langchain/core': 0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7)) '@langchain/langgraph-checkpoint': 0.0.18(@langchain/core@0.3.80(openai@6.45.0(ws@8.21.0)(zod@4.6.7))) From 8248019bec468643eb1402db5d6f13a6289f252d Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:32:25 +0000 Subject: [PATCH 10/13] fix(examples): move the langchain-classic example to LangGraph 0.3.12 [SAP-4718] The example overrides zod to its own zod 4.6.7, which also replaces the zod inside LangGraph. With LangGraph 0.2.74 locked, a reader who adds new StateGraph(MessagesZodState) to the example gets "Invalid StateGraph input.", the same failure as in the workspace. LangGraph 0.3.12 accepts zod 4 schemas. The lockfile is regenerated with --legacy-peer-deps, like the committed one, and changes only the LangGraph entry. Co-Authored-By: Claude Fable 5.2 --- examples/langchain-classic/package-lock.json | 16 ++++++++-------- examples/langchain-classic/package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/langchain-classic/package-lock.json b/examples/langchain-classic/package-lock.json index 70478ed54..e0d2e1705 100644 --- a/examples/langchain-classic/package-lock.json +++ b/examples/langchain-classic/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@langchain/anthropic": "^0.3.0", "@langchain/core": "^0.3.0", - "@langchain/langgraph": "^0.2.0", + "@langchain/langgraph": "^0.3.12", "@langchain/openai": "^1.2.2", "@sapiom/langchain-classic": "latest", "dotenv": "^16.4.5", @@ -539,21 +539,21 @@ } }, "node_modules/@langchain/langgraph": { - "version": "0.2.74", - "resolved": "https://registry.npmjs.org/@langchain/langgraph/-/langgraph-0.2.74.tgz", - "integrity": "sha512-oHpEi5sTZTPaeZX1UnzfM2OAJ21QGQrwReTV6+QnX7h8nDCBzhtipAw1cK616S+X8zpcVOjgOtJuaJhXa4mN8w==", + "version": "0.3.12", + "resolved": "https://registry.npmjs.org/@langchain/langgraph/-/langgraph-0.3.12.tgz", + "integrity": "sha512-4jKvfmxxgQyKnCvXdFbcKt6MdfaJoQ2WWqBR16o2E6D2RxqHvnLMMClZh4FSd6WYw39z5LGWvzRapFbRMqxu1A==", "license": "MIT", "dependencies": { - "@langchain/langgraph-checkpoint": "~0.0.17", - "@langchain/langgraph-sdk": "~0.0.32", + "@langchain/langgraph-checkpoint": "~0.0.18", + "@langchain/langgraph-sdk": "~0.0.102", "uuid": "^10.0.0", - "zod": "^3.23.8" + "zod": "^3.25.32" }, "engines": { "node": ">=18" }, "peerDependencies": { - "@langchain/core": ">=0.2.36 <0.3.0 || >=0.3.40 < 0.4.0", + "@langchain/core": ">=0.3.58 < 0.4.0", "zod-to-json-schema": "^3.x" }, "peerDependenciesMeta": { diff --git a/examples/langchain-classic/package.json b/examples/langchain-classic/package.json index 66985dc59..ffc1734f4 100644 --- a/examples/langchain-classic/package.json +++ b/examples/langchain-classic/package.json @@ -10,7 +10,7 @@ "dependencies": { "@langchain/anthropic": "^0.3.0", "@langchain/core": "^0.3.0", - "@langchain/langgraph": "^0.2.0", + "@langchain/langgraph": "^0.3.12", "@langchain/openai": "^1.2.2", "@sapiom/langchain-classic": "latest", "dotenv": "^16.4.5", From 80d0c68146810a1a0d07b3a3ec05ec2c329e39a1 Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:37:38 +0000 Subject: [PATCH 11/13] test(agent): type-check the packed package on each supported zod [SAP-4718] @sapiom/agent accepts zod ^3.25.76 || ^4.0.0 as a peer, and is now built against zod 4.6.7. Nothing checked that the declarations it publishes still compile on the older end of that range. `pnpm --filter @sapiom/agent test:package` packs the package and its workspace dependencies, installs them outside the workspace on zod 3.25.76, 4.0.0 and the workspace's zod, runs tsc with skipLibCheck off, and builds an agent manifest through the ESM and CJS entry points. The Test workflow runs it on Node 20 and 22. It fails on this commit, on zod 3.25.76: manifest.d.ts(46,33): error TS2707: Generic type 'ZodDiscriminatedUnion' requires between 0 and 1 type arguments. The next commit fixes the declaration. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/test.yml | 6 + packages/agent/package.json | 1 + packages/agent/scripts/check-package.mjs | 147 +++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 packages/agent/scripts/check-package.mjs diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0be454b92..d5a7cb4d2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,6 +52,12 @@ jobs: - name: Verify installed MCP host contract run: pnpm --filter @sapiom/mcp test:package + # Type-checks the packed @sapiom/agent declarations (skipLibCheck off) and + # imports it, on each lower bound of its zod peer range and on the + # workspace's zod. + - name: Verify installed Agent package on each supported zod + run: pnpm --filter @sapiom/agent test:package + - name: Type check run: pnpm typecheck diff --git a/packages/agent/package.json b/packages/agent/package.json index ed0b58b1b..aa42312d6 100644 --- a/packages/agent/package.json +++ b/packages/agent/package.json @@ -42,6 +42,7 @@ "dev": "tsc --watch --project tsconfig.cjs.json", "test": "jest", "test:coverage": "jest --coverage", + "test:package": "pnpm --filter \"@sapiom/agent...\" build && node scripts/check-package.mjs", "test:watch": "jest --watch", "typecheck": "tsc --noEmit", "lint": "eslint src --ext .ts", diff --git a/packages/agent/scripts/check-package.mjs b/packages/agent/scripts/check-package.mjs new file mode 100644 index 000000000..7b7f7f95c --- /dev/null +++ b/packages/agent/scripts/check-package.mjs @@ -0,0 +1,147 @@ +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; +import { createRequire } from "node:module"; +import { tmpdir } from "node:os"; +import { join, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +const packageRoot = fileURLToPath(new URL("../", import.meta.url)); +const repo = resolve(packageRoot, "../.."); +const pnpm = process.env.npm_execpath; +assert(pnpm && /pnpm(?:\.c?js)?$/.test(pnpm), "Run with pnpm test:package"); +const workspaceVersion = (name) => + createRequire(packageRoot)(`${name}/package.json`).version; +const run = (file, args, cwd) => + execFileSync(process.execPath, [file, ...args], { + cwd, + stdio: "inherit", + windowsHide: true, + timeout: 300_000, + env: { ...process.env, SAPIOM_TELEMETRY_DISABLED: "1" }, + }); + +const scratch = await mkdtemp(join(tmpdir(), "agent-zod-peers-")); +try { + // Pack the local production closure, so a workspace range never resolves to + // an older registry package. Declarations are checked with skipLibCheck off, + // so the consumer also installs each packed package's peers, optional ones + // included, and Node's types: a missing one would fail the check for an + // unrelated reason. + const overrides = {}; + const peers = {}; + const pack = async (name) => { + if (overrides[name]) return; + const root = join(repo, "packages", name.slice("@sapiom/".length)); + const pkg = JSON.parse(await readFile(join(root, "package.json"), "utf8")); + overrides[name] = + `file:${join(scratch, `${name.replace("@", "").replace("/", "-")}-${pkg.version}.tgz`)}`; + run(pnpm, ["pack", "--pack-destination", scratch], root); + Object.assign(peers, pkg.peerDependencies); + for (const [dependency, range] of Object.entries(pkg.dependencies ?? {})) { + if (String(range).startsWith("workspace:")) await pack(dependency); + } + return pkg; + }; + const agent = await pack("@sapiom/agent"); + + // Every lower bound of the zod peer range, and the zod this build used. + const zodVersions = new Set([ + ...agent.peerDependencies.zod + .split("||") + .map((alternative) => alternative.match(/\d+\.\d+\.\d+/)[0]), + workspaceVersion("zod"), + ]); + + for (const zod of zodVersions) { + const consumer = join(scratch, `zod-${zod}`); + await mkdir(consumer); + await writeFile( + join(consumer, "package.json"), + JSON.stringify({ + private: true, + type: "module", + dependencies: { + ...peers, + "@sapiom/agent": overrides["@sapiom/agent"], + "@types/node": workspaceVersion("@types/node"), + typescript: workspaceVersion("typescript"), + zod, + }, + pnpm: { overrides }, + }), + ); + await writeFile( + join(consumer, "tsconfig.json"), + JSON.stringify({ + compilerOptions: { + strict: true, + noEmit: true, + skipLibCheck: false, + module: "NodeNext", + target: "ES2022", + }, + files: ["consumer.ts"], + }), + ); + await writeFile( + join(consumer, "consumer.ts"), + ` +import { z } from "zod/v4"; +import { type AgentManifest, agentManifestSchema, defineAgent, defineStep, terminate } from "@sapiom/agent"; + +const greet = defineStep({ + name: "greet", + terminal: true, + inputSchema: z.object({ name: z.string() }), + run: async (input: { name: string }) => terminate({ greeting: input.name }), +}); +export const agent = defineAgent({ name: "consumer", entry: "greet", steps: { greet } }); +export const parseManifest = (value: unknown): AgentManifest => agentManifestSchema.parse(value); +`, + ); + await writeFile( + join(consumer, "consumer.mjs"), + ` +import assert from "node:assert/strict"; +import { createRequire } from "node:module"; +import { z } from "zod/v4"; +import * as esm from "@sapiom/agent"; + +const require = createRequire(import.meta.url); +assert.equal(require("zod/package.json").version, ${JSON.stringify(zod)}); +for (const { buildManifest, defineAgent, defineStep, terminate, agentManifestSchema } of [esm, require("@sapiom/agent")]) { + const greet = defineStep({ + name: "greet", + terminal: true, + inputSchema: z.object({ name: z.string() }), + run: async (input) => terminate({ greeting: input.name }), + }); + const agent = defineAgent({ name: "consumer", entry: "greet", steps: { greet } }); + const manifest = agentManifestSchema.parse( + buildManifest(agent, { sdkVersion: "0.0.0", artifact: { sha256: "0".repeat(64), entryFile: "index.js" } }), + ); + assert.deepEqual(manifest.steps.greet.transitions, [{ kind: "terminate" }]); + assert.deepEqual(manifest.steps.greet.inputSchema.required, ["name"]); +} +`, + ); + run( + pnpm, + [ + "install", + "--prefer-offline", + "--ignore-scripts", + "--no-frozen-lockfile", + ], + consumer, + ); + run(join(consumer, "node_modules/typescript/bin/tsc"), [], consumer); + run(join(consumer, "consumer.mjs"), [], consumer); + console.log( + `@sapiom/agent declarations and both entry points pass on zod ${zod}.`, + ); + } +} finally { + await rm(scratch, { recursive: true, force: true }); +} From 0505fc86ab027cc72d671f9252986f031d18de91 Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:38:01 +0000 Subject: [PATCH 12/13] fix(agent): keep the manifest schema declaration valid on zod 3.25 and 4.0 [SAP-4718] The package is built against zod 4.6.7, where ZodDiscriminatedUnion takes two type arguments. tsc wrote both into the declaration of agentManifestSchema. The zod/v4 types in zod 3.25.76 and 4.0.0 take one, so a consumer on those versions with skipLibCheck off got TS2707, although the peer range allows them. The transitions element is now annotated as a ZodUnion of the same four objects, which has the same shape on every supported zod. The runtime schema is still the discriminated union, and the parsed type is unchanged. The published type loses the discriminator, so the changeset records it as a patch. `pnpm --filter @sapiom/agent test:package` now passes on zod 3.25.76, 4.0.0 and 4.6.7. Co-Authored-By: Claude Fable 5.2 --- .changeset/agent-zod-peer-declarations.md | 7 +++++++ packages/agent/src/manifest.ts | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/agent-zod-peer-declarations.md diff --git a/.changeset/agent-zod-peer-declarations.md b/.changeset/agent-zod-peer-declarations.md new file mode 100644 index 000000000..f99e1a594 --- /dev/null +++ b/.changeset/agent-zod-peer-declarations.md @@ -0,0 +1,7 @@ +--- +"@sapiom/agent": minor +--- + +Keep the type declarations valid on the zod versions the peer range starts from. + +The package is now built with zod 4.6.7. To keep its declarations compiling on zod 3.25 and zod 4.0 with `skipLibCheck: false`, `agentManifestSchema` types the `transitions` element as a `ZodUnion` of the same four objects, where it was a `ZodDiscriminatedUnion`. Validation and the parsed type are unchanged. Code that reads that nested schema as a `ZodDiscriminatedUnion`, or reads its `discriminator`, no longer type-checks, so this is a minor release. diff --git a/packages/agent/src/manifest.ts b/packages/agent/src/manifest.ts index 1d0da0fbd..4f4282feb 100644 --- a/packages/agent/src/manifest.ts +++ b/packages/agent/src/manifest.ts @@ -83,13 +83,18 @@ export interface AgentManifest { // Zod schema — used by the engine to validate manifests it receives // --------------------------------------------------------------------------- -const manifestTransitionSchema = z.discriminatedUnion('kind', [ +const manifestTransitionUnion = z.discriminatedUnion('kind', [ z.object({ kind: z.literal('continue'), target: z.string().min(1) }), z.object({ kind: z.literal('terminate') }), z.object({ kind: z.literal('fail') }), z.object({ kind: z.literal('pause'), signal: z.string().min(1), resumeStep: z.string().min(1) }), ]); +// Typed as a `ZodUnion` so the declaration file compiles on every zod the peer +// range allows: zod 4.6 gives `ZodDiscriminatedUnion` a second type argument, +// which the `zod/v4` types of zod 3.25 and zod 4.0 reject. +const manifestTransitionSchema: z.ZodUnion = manifestTransitionUnion; + const workflowStepManifestSchema = z.object({ timeoutMs: z.union([z.number().int().positive(), z.null()]), inputSchema: z.union([z.record(z.string(), z.unknown()), z.null()]), From 62d5078442084bd70975083cd4774957c88310bb Mon Sep 17 00:00:00 2001 From: Antoine Berger <64917674+antoine-berger@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:02:15 +0000 Subject: [PATCH 13/13] docs(agent-map,sandbox-preview): say how zod 3.25 code composes the zod 4 schemas [SAP-4718] The host-protocol schemas and the sandbox config schemas are zod 4 now. A project on zod 3.25 gets zod 3 from the bare `zod` entry, so it has to import `z` from `zod/v4` to compose them. The changeset said so; the package docs now say it where a consumer reads them. Co-Authored-By: Claude Opus 5.5 --- packages/agent-map/README.md | 2 ++ packages/sandbox-preview/src/schema.ts | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/agent-map/README.md b/packages/agent-map/README.md index f2cba69a6..8f237fe6c 100644 --- a/packages/agent-map/README.md +++ b/packages/agent-map/README.md @@ -19,4 +19,6 @@ Studio owns discovery and calls the catalog's `reconcile` with the complete root Exports under `/node/*` provide the catalog, file locks, state paths and hashing for trusted host code. All other exports are browser-safe contracts and pure helpers. +`@sapiom/agent-map/host-protocol` exports zod 4 schemas. Compose them with zod 4 (`import { z } from "zod"`). On zod 3.25, import `z` from `"zod/v4"`, because the bare `zod` entry there is zod 3. + Run `pnpm --filter @sapiom/agent-map test:package` after installing dependencies. It packs and installs the library outside the workspace, verifies every export and declaration, bundles all browser exports without tree shaking, and exercises the catalog without Studio or MCP installed. The check rejects Studio/MCP anywhere in the installed dependency graph. diff --git a/packages/sandbox-preview/src/schema.ts b/packages/sandbox-preview/src/schema.ts index d4304eedd..3a393a7c0 100644 --- a/packages/sandbox-preview/src/schema.ts +++ b/packages/sandbox-preview/src/schema.ts @@ -29,6 +29,9 @@ const sourceSchema = z.discriminatedUnion('kind', [ /** * The sandbox resource body (without the `name`, which is the map key). This is * also the shape the MCP `configure` tool accepts as typed args. + * + * A zod 4 schema: compose it with zod 4's `z`, or with `import { z } from "zod/v4"` + * on zod 3.25, whose bare `zod` entry is zod 3. */ export const sandboxConfigBodySchema = z.object({ source: sourceSchema, @@ -42,5 +45,8 @@ export const sandboxConfigBodySchema = z.object({ export type SandboxConfigBody = z.infer; -/** The stored on-disk sandbox entry (adds the `type` discriminant). */ +/** + * The stored on-disk sandbox entry (adds the `type` discriminant). A zod 4 + * schema, composed like `sandboxConfigBodySchema`. + */ export const storedSandboxSchema = sandboxConfigBodySchema.extend({ type: z.literal('sandbox') });