diff --git a/packages/core/src/codemode/tool.ts b/packages/core/src/codemode/tool.ts index 6125b8e3b89..df51bb26957 100644 --- a/packages/core/src/codemode/tool.ts +++ b/packages/core/src/codemode/tool.ts @@ -305,9 +305,7 @@ function inventoryTools(inventory: Inventory) { getNode(root, qualifiedName(registration)).tool = Tool.make({ description: child.description, input: child.inputSchema, - flat: - registration.options?.flat ?? - (child.freeform !== undefined && ToolDefinition.freeformField(child.inputSchema) !== undefined), + flat: child.freeform !== undefined && ToolDefinition.freeformField(child.inputSchema) !== undefined, output: child.outputSchema ?? Schema.NullOr(Schema.String), execute: (input) => Run.use((run) => run.executeTool(name, registration, input)), }) diff --git a/packages/core/test/tool-execute.test.ts b/packages/core/test/tool-execute.test.ts index 7d727f603ed..691e61b1f6e 100644 --- a/packages/core/test/tool-execute.test.ts +++ b/packages/core/test/tool-execute.test.ts @@ -50,20 +50,23 @@ test("Code Mode lists one string argument for freeform tools and executes both i expect((await run('return await tools.echo("object required")')).error).toBe(true) }) -test("Core tools can opt into positional Code Mode calls with multiple fields", async () => { +test("a freeform declaration on a multi-field Core tool keeps the named input", async () => { const tool = { name: "scan", description: "Scan a path", - options: { flat: true }, + freeform: { type: "text" }, input: Schema.Struct({ path: Schema.String, options: Schema.Struct({ recursive: Schema.Boolean }) }), output: Schema.String, execute: ({ path, options }) => Effect.succeed({ output: `${path}:${options.recursive}` }), } satisfies Info const tools = new Map([[tool.name, tool]]) - const signature = "tools.scan(path: string, options: { recursive: boolean }): Promise" - expect(CodeModeTool.catalog({ tools }).tools).toContainEqual(expect.objectContaining({ signature })) + const codeMode = createCodeMode(tools) + const positional = await Effect.runPromise( + codeMode.execute({ code: 'return await tools.scan("src", {recursive:true})' }, context), + ) + expect(positional.output.error).toBe(true) const result = await Effect.runPromise( - createCodeMode(tools).execute({ code: 'return await tools.scan("src", {recursive:true})' }, context), + codeMode.execute({ code: 'return await tools.scan({path:"src", options:{recursive:true}})' }, context), ) expect(result.output).toMatchObject({ output: "src:true", diff --git a/packages/schema/src/tool.ts b/packages/schema/src/tool.ts index ad9768918d0..d07b52dc5a5 100644 --- a/packages/schema/src/tool.ts +++ b/packages/schema/src/tool.ts @@ -47,13 +47,10 @@ export type Options = BaseOptions & | { readonly codemode?: true readonly pinned?: boolean - /** Offer top-level fields as positional arguments in Code Mode. */ - readonly flat?: boolean } | { readonly codemode: boolean readonly pinned?: never - readonly flat?: never } ) diff --git a/services/www/src/docs/content/build/plugins/server.mdx b/services/www/src/docs/content/build/plugins/server.mdx index a684f2407ab..e219a4cb6b3 100644 --- a/services/www/src/docs/content/build/plugins/server.mdx +++ b/services/www/src/docs/content/build/plugins/server.mdx @@ -1029,16 +1029,6 @@ If the selected model's API lists `regex` in models.dev, the model can write `OP If you expose the same tool inside Code Mode (`codemode: true`), its JavaScript signature takes one string: `await tools.ticket("OPS-42")`. Code Mode also accepts `await tools.ticket({ id: "OPS-42" })` for existing scripts. Both forms work independently of the model's freeform support. -#### Positional arguments in Code Mode - -Set `options: { flat: true }` to expose a tool's top-level fields as positional arguments in schema order. For example, `input: Schema.Struct({ path: Schema.String, options: Schema.Struct({ recursive: Schema.Boolean }) })` becomes: - -```js -await tools.scan("src", { recursive: true }) -``` - -The executor receives `{ path: "src", options: { recursive: true } }`. Named-object calls also work and take precedence when a single object fits both forms. Code Mode enables `flat` by default for eligible freeform tools; set `options.flat` to `false` to use the object signature. - Call `reload()` after changing source data captured by the callback. Reload replays the active transforms without changing their order; it does not rerun plugin setup.