From d10c993904eb80ab6fd676a6ab29ac8b3ef1936f Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Wed, 4 Nov 2026 10:01:19 -0600 Subject: [PATCH] fix(core): normalize and validate tool input schemas at registration (#61537) --- packages/core/src/tool.ts | 9 ++++++++- packages/core/test/tool-registry.test.ts | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/core/src/tool.ts b/packages/core/src/tool.ts index ad4357a029f..463723972d6 100644 --- a/packages/core/src/tool.ts +++ b/packages/core/src/tool.ts @@ -361,7 +361,9 @@ const layer = Layer.effect( ) /** Store a valid tool under its effective name, or record why it was skipped. */ -function commit(editor: Data, id: string, tool: Tool.Info & { readonly id: string }) { +function commit(editor: Data, id: string, input: Tool.Info & { readonly id: string }) { + // JavaScript plugins may leave out `input` for a tool that takes none. + const tool = input.input === undefined || input.input === null ? { ...input, input: {} } : input const registered = register(tool) if (Result.isFailure(registered)) { editor.errors.push({ @@ -400,6 +402,11 @@ function register(tool: Tool.Info): Result.Result ToolDefinition.make(definition(tool)), catch: (error) => diff --git a/packages/core/test/tool-registry.test.ts b/packages/core/test/tool-registry.test.ts index 3e68b22c4e9..d16e3722284 100644 --- a/packages/core/test/tool-registry.test.ts +++ b/packages/core/test/tool-registry.test.ts @@ -609,6 +609,7 @@ describe("Tool", () => { execute: () => Effect.succeed({ content: "ok" }), options: { codemode: false }, } as unknown as Info) + editor.add({ ...make(), name: "boolean_input", input: true, options: { codemode: false } } as unknown as Info) editor.add({ ...make(), name: "codemode" }) }) @@ -621,6 +622,14 @@ describe("Tool", () => { error: expect.stringContaining('Expected string\n at ["description"]'), }, ], + [ + "Skipping invalid tool registration", + { + name: "boolean_input", + namespace: undefined, + error: "Invalid tool definition boolean_input: input must be a schema", + }, + ], ]) const snapshot = yield* service.snapshot() expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["healthy", "execute"]) @@ -688,10 +697,14 @@ describe("Tool", () => { input: undefined, } as unknown as Info), ) + yield* service.transform((editor) => + editor.add({ ...make(), name: "direct", input: null, options: { codemode: false } } as unknown as Info), + ) const snapshot = yield* service.snapshot() - expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["execute"]) + expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["direct", "execute"]) expect(codeModeListings(snapshot.codeModeCatalog!)[0]?.line).toContain("tools.echo") + expect((yield* snapshot.execute(call("direct"))).output).toEqual({ text: "direct" }) }), )