Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
fix(lmstudio-plugin): pin zod to the SDK's major so tool arguments parse
Barack Sokullu48e41ea2370e
diff --git a/lmstudio-plugin/package-lock.json b/lmstudio-plugin/package-lock.jsonindex fe0f0f175..91394b3b0 100644--- a/lmstudio-plugin/package-lock.json+++ b/lmstudio-plugin/package-lock.json@@ -11,7 +11,7 @@"dependencies": {"@lmstudio/sdk": "^1.0.0","ws": "^8.18.0",- "zod": "^4.6.6"+ "zod": "^3.25.76"},"devDependencies": {"@types/node": "^20.11.0",@@ -44,15 +44,6 @@"zod-to-json-schema": "^3.22.5"}},- "node_modules/@lmstudio/sdk/node_modules/zod": {- "version": "3.25.76",- "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",- "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",- "license": "MIT",- "funding": {- "url": "https://github.com/sponsors/colinhacks"- }- },"node_modules/@types/node": {"version": "20.19.39","resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.39.tgz",@@ -195,9 +186,9 @@}},"node_modules/zod": {- "version": "4.6.6",- "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.6.tgz",- "integrity": "sha512-4UmzQUF5fxvfcYHlbjBmejU+w+hbDnWFx4aS8kBx7nPBHcO2SqPbpAG8snbdg+Xse4pRefR98hgjFgIMCI/UhA==",+ "version": "3.25.76",+ "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",+ "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==","license": "MIT","funding": {"url": "https://github.com/sponsors/colinhacks"diff --git a/lmstudio-plugin/package.json b/lmstudio-plugin/package.jsonindex 095e49478..a1f17b052 100644--- a/lmstudio-plugin/package.json+++ b/lmstudio-plugin/package.json@@ -15,7 +15,7 @@"scripts": {"build": "tsc","dev": "tsc --watch",- "test": "npm run build && node --test test/browserTask.test.mjs",+ "test": "npm run build && node --test test/browserTask.test.mjs test/toolParameters.test.mjs","clean": "rm -rf dist"},"keywords": [@@ -33,7 +33,7 @@"dependencies": {"@lmstudio/sdk": "^1.0.0","ws": "^8.18.0",- "zod": "^4.6.6"+ "zod": "^3.25.76"},"devDependencies": {"typescript": "^5.5.0",diff --git a/lmstudio-plugin/test/toolParameters.test.mjs b/lmstudio-plugin/test/toolParameters.test.mjsnew file mode 100644index 000000000..b426eb625--- /dev/null+++ b/lmstudio-plugin/test/toolParameters.test.mjs@@ -0,0 +1,116 @@+/**+ * Tool arguments are parsed by the zod bundled with @lmstudio/sdk, not only+ * by the one this plugin imports: `tool()` wraps our per-field schemas in its+ * own `z.object(...)`, and LM Studio's plugin host turns that object into the+ * JSON schema the model sees. Both copies must be the same zod major. With+ * zod 4 fields inside the SDK's zod 3 object, every call failed with+ * "keyValidator._parse is not a function" and the model was shown tools with+ * no parameters at all.+ */+import assert from "node:assert/strict";+import { once } from "node:events";+import { createRequire } from "node:module";+import { createServer } from "node:net";+import { after, before, test } from "node:test";++import { main } from "../dist/index.js";+import { sharedBridge } from "../dist/util/bridgeClient.js";++// Resolve zod-to-json-schema from the SDK's own location, so the conversion+// below uses the copy LM Studio's plugin host uses for tool definitions.+const require = createRequire(import.meta.url);+const { zodToJsonSchema } = createRequire(require.resolve("@lmstudio/sdk"))(+ "zod-to-json-schema",+);++// One valid call per registered tool, touching each validator it declares.+const VALID_ARGS = {+ fetch_url: {+ url: "https://example.com/data.json",+ method: "POST",+ headers: { accept: "application/json" },+ body: "{}",+ timeout: 5000,+ maxChars: 1000,+ compact: false,+ },+ research_url: { url: "https://example.com/post", timeout: 5000, maxChars: 1000, compact: true },+ browser_task: { task: "List unread messages.", mode: "act", timeout: 60_000, allowApiMutations: false },+ browser_status: { runId: "run-1" },+ browser_respond: { runId: "run-1", clarifyId: "clarify-1", answer: "work account", timeout: 5000 },+ browser_abort: { runId: "run-1" },+};++const INVALID_ARGS = {+ fetch_url: { url: "not a url" },+ research_url: { url: "https://example.com/post", timeout: "soon" },+ browser_task: { task: "List unread messages.", mode: "delete" },+ browser_status: { runId: 42 },+ browser_respond: { runId: "run-1", clarifyId: "clarify-1", answer: "" },+ browser_abort: {},+};++let tools;++async function freePort() {+ const server = createServer();+ server.listen(0, "127.0.0.1");+ await once(server, "listening");+ const address = server.address();+ const port = typeof address === "object" && address ? address.port : 0;+ server.close();+ await once(server, "close");+ return port;+}++before(async () => {+ process.env.WEBBRAIN_BRIDGE_PORT = String(await freePort());+ let toolsProvider;+ const context = {+ withConfigSchematics() {+ return context;+ },+ withToolsProvider(provider) {+ toolsProvider = provider;+ return context;+ },+ };+ await main(context);+ tools = new Map((await toolsProvider()).map((registeredTool) => [registeredTool.name, registeredTool]));+});++after(async () => {+ await sharedBridge().stop();+});++test("valid arguments pass the SDK's parameter check", () => {+ for (const [name, registeredTool] of tools) {+ assert.ok(VALID_ARGS[name], `add a VALID_ARGS entry for ${name}`);+ assert.doesNotThrow(() => registeredTool.checkParameters(VALID_ARGS[name]), name);+ }+});++test("invalid arguments are rejected with the SDK's readable error", () => {+ for (const [name, registeredTool] of tools) {+ assert.ok(INVALID_ARGS[name], `add an INVALID_ARGS entry for ${name}`);+ const expected = new RegExp(`Failed to parse arguments for tool "${name}"`);+ assert.throws(() => registeredTool.checkParameters(INVALID_ARGS[name]), expected);+ // The plugin host calls implementation() directly; it parses the same way.+ assert.throws(() => registeredTool.implementation(INVALID_ARGS[name], {}), expected);+ }+});++test("the tool definition sent to the model lists every parameter", () => {+ for (const [name, registeredTool] of tools) {+ const schema = zodToJsonSchema(registeredTool.parametersSchema);+ assert.deepEqual(+ Object.keys(schema.properties ?? {}),+ Object.keys(registeredTool.parametersSchema.shape),+ name,+ );+ }+ const fetchSchema = zodToJsonSchema(tools.get("fetch_url").parametersSchema);+ assert.deepEqual(fetchSchema.required, ["url"]);+ assert.equal(fetchSchema.properties.url.format, "uri");+ assert.equal(fetchSchema.properties.url.description, "Absolute http(s) URL to fetch.");+});