diff --git a/packages/codemode/src/tool-runtime.ts b/packages/codemode/src/tool-runtime.ts index e30cb1108e7..e05e2090028 100644 --- a/packages/codemode/src/tool-runtime.ts +++ b/packages/codemode/src/tool-runtime.ts @@ -176,7 +176,7 @@ const describeTool = (visible: VisibleTool): ToolDescription => { // Joining the final fragments avoids retaining the rendering's intermediate string ropes in JSC. return (signature ??= [ toolExpression(visible.path), - isEmptyInput(visible.tool) ? "()" : `(input: ${inputTypeScript(visible.tool, true)})`, + isEmptyInput(visible.tool) ? "()" : `(${inputTypeScript(visible.tool, true)})`, `: Promise<${outputTypeScript(visible.tool, true)}>`, ].join("")) }, @@ -279,7 +279,7 @@ const makeSearchTool = (searchIndex: ReadonlyArray): Tool => ({ /** Exact callable signature of the built-in `search` function, for host-owned instructions. */ export const searchSignature = (() => { const tool = makeSearchTool([]) - return `search(input: ${inputTypeScript(tool, true)}): ${outputTypeScript(tool, true)}` + return `search(${inputTypeScript(tool, true)}): ${outputTypeScript(tool, true)}` })() const toSearchEntry = (visible: VisibleTool): SearchEntry => ({ diff --git a/packages/codemode/test/codemode.test.ts b/packages/codemode/test/codemode.test.ts index 1336a775bd3..24d7da80f21 100644 --- a/packages/codemode/test/codemode.test.ts +++ b/packages/codemode/test/codemode.test.ts @@ -581,7 +581,7 @@ describe("CodeMode schema flexibility", () => { { path: "adapter.call", description: "Call an adapter-described tool", - signature: "tools.adapter.call(input: {\n id: string,\n count?: number,\n}): Promise", + signature: "tools.adapter.call({\n id: string,\n count?: number,\n}): Promise", }, ]) @@ -664,7 +664,7 @@ describe("CodeMode schema flexibility", () => { { path: "users.lookup", description: "Look up a user", - signature: "tools.users.lookup(input: {\n login: string,\n}): Promise<{\n login: string,\n id: number,\n}>", + signature: "tools.users.lookup({\n login: string,\n}): Promise<{\n login: string,\n id: number,\n}>", }, ]) @@ -680,7 +680,7 @@ describe("CodeMode schema flexibility", () => { execute: () => Effect.succeed("pong"), }) const runtime = CodeMode.make({ tools: { net: { ping } } }) - expect(runtime.catalog[0]?.signature).toBe("tools.net.ping(input: {\n host: string,\n}): Promise") + expect(runtime.catalog[0]?.signature).toBe("tools.net.ping({\n host: string,\n}): Promise") const result = await Effect.runPromise(runtime.execute(`return await tools.net.ping({ host: "example.test" })`)) expect(result.ok).toBe(true) @@ -737,7 +737,7 @@ describe("CodeMode public contract", () => { { path: "orders.lookup", description: "Look up an order by ID", - signature: "tools.orders.lookup(input: {\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>", + signature: "tools.orders.lookup({\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>", }, ]) @@ -749,8 +749,7 @@ describe("CodeMode public contract", () => { { path: "tools.orders.lookup", description: "Look up an order by ID", - signature: - "tools.orders.lookup(input: {\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>", + signature: "tools.orders.lookup({\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>", }, ], remaining: 0, @@ -792,7 +791,7 @@ describe("CodeMode public contract", () => { { path: "context7.resolve-library-id", description: "Resolve a library ID", - signature: 'tools.context7["resolve-library-id"](input: {\n libraryName: string,\n}): Promise', + signature: 'tools.context7["resolve-library-id"]({\n libraryName: string,\n}): Promise', }, ]) @@ -804,7 +803,7 @@ describe("CodeMode public contract", () => { { path: 'tools.context7["resolve-library-id"]', description: "Resolve a library ID", - signature: 'tools.context7["resolve-library-id"](input: {\n libraryName: string,\n}): Promise', + signature: 'tools.context7["resolve-library-id"]({\n libraryName: string,\n}): Promise', }, ], remaining: 0, @@ -857,12 +856,12 @@ describe("CodeMode public contract", () => { { path: "tools.thread.uploadFile", description: "Upload one readable local file to the current Discord thread", - signature: "tools.thread.uploadFile(input: {\n path: string,\n}): Promise<{\n sent: boolean,\n}>", + signature: "tools.thread.uploadFile({\n path: string,\n}): Promise<{\n sent: boolean,\n}>", }, { path: "tools.thread.generateImage", description: "Generate an image and upload it to the current Discord thread", - signature: "tools.thread.generateImage(input: {\n prompt: string,\n}): Promise<{\n sent: boolean,\n}>", + signature: "tools.thread.generateImage({\n prompt: string,\n}): Promise<{\n sent: boolean,\n}>", }, ], remaining: 0, @@ -950,7 +949,7 @@ describe("CodeMode public contract", () => { { path: "tools.many.tool13", description: "Numbered tool 13", - signature: "tools.many.tool13(input: {\n id: string,\n}): Promise", + signature: "tools.many.tool13({\n id: string,\n}): Promise", }, ], remaining: 0, diff --git a/packages/codemode/test/signature.test.ts b/packages/codemode/test/signature.test.ts index 96d3122a3bf..5b9c98d1a6d 100644 --- a/packages/codemode/test/signature.test.ts +++ b/packages/codemode/test/signature.test.ts @@ -739,7 +739,7 @@ describe("JSDoc signatures in catalogs and search results", () => { " },", "}", ].join("\n") - const signature = `tools.constrained(input: ${type}): Promise<${type}>` + const signature = `tools.constrained(${type}): Promise<${type}>` expect(runtime.catalog[0]?.signature).toBe(signature) const result = await Effect.runPromise(runtime.execute('return search({ query: "tools.constrained" })')) expect(result.ok).toBe(true) @@ -761,7 +761,7 @@ describe("JSDoc signatures in catalogs and search results", () => { const item = items.find(({ path }) => path === "tools.github.list_issues")! expect(item.signature).toBe( [ - "tools.github.list_issues(input: {", + "tools.github.list_issues({", " /** Repository owner */", " owner: string,", " /** Cursor from the previous response's pageInfo */", @@ -782,7 +782,7 @@ describe("JSDoc signatures in catalogs and search results", () => { const item = items.find(({ path }) => path === "tools.orders.lookup")! expect(item.signature).toBe( [ - "tools.orders.lookup(input: {", + "tools.orders.lookup({", " /** Order identifier */", " id: string,", " verbose?: boolean,", @@ -825,7 +825,7 @@ describe("non-identifier tool paths", () => { test("catalog signatures use bracket notation for dashed tool names", () => { expect(runtime.catalog[0]?.signature).toBe( - 'tools.context7["resolve-library-id"](input: {\n query: string,\n libraryName: string,\n}): Promise', + 'tools.context7["resolve-library-id"]({\n query: string,\n libraryName: string,\n}): Promise', ) }) @@ -836,6 +836,6 @@ describe("non-identifier tool paths", () => { const value = result.value as { items: Array<{ path: string; signature: string }> } expect(value.items[0]?.path).toBe('tools.context7["resolve-library-id"]') - expect(value.items[0]?.signature).toContain('tools.context7["resolve-library-id"](input: {') + expect(value.items[0]?.signature).toContain('tools.context7["resolve-library-id"]({') }) }) diff --git a/packages/core/test/codemode.test.ts b/packages/core/test/codemode.test.ts index 8f94541bdca..59a26dbb08a 100644 --- a/packages/core/test/codemode.test.ts +++ b/packages/core/test/codemode.test.ts @@ -30,7 +30,7 @@ describe("CodeMode", () => { type: "tool", name: "echo", description: "Echo text", - signature: "tools.echo(input: {\n text: string,\n}): Promise", + signature: "tools.echo({\n text: string,\n}): Promise", pinned: true, }, { diff --git a/packages/core/test/codemode/catalog.test.ts b/packages/core/test/codemode/catalog.test.ts index c15fee05e12..520ae8e8960 100644 --- a/packages/core/test/codemode/catalog.test.ts +++ b/packages/core/test/codemode/catalog.test.ts @@ -6,14 +6,14 @@ const entry = (path: string, description: string, signature?: string, pinned = f type: "tool", name: path, description, - signature: signature ?? `tools.${path}(input: {\n q: string,\n}): Promise`, + signature: signature ?? `tools.${path}({\n q: string,\n}): Promise`, pinned, }) const lookup = entry( "orders.lookup", "Look up an order by ID", - "tools.orders.lookup(input: {\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>", + "tools.orders.lookup({\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>", ) const render = (tools: CodeModeCatalog.Inventory["tools"], budget?: number) => @@ -133,7 +133,7 @@ describe("CodeModeInstructions.render", () => { expect(partial).toContain( "The catalog is partial. Inside `execute`, use `search(...)` to find a tool, then call it by the `path` in the result. `search` is synchronous. Call it without `await`; it does not return a Promise.", ) - expect(partial).toContain("- search(input: {") + expect(partial).toContain("- search({") expect(partial).toContain(" /** @integer @exclusiveMinimum 0 */\n limit?: number,") expect(partial).toContain(" /** @integer @minimum 0 */\n offset?: number,") expect(partial).not.toContain("tools.orders.lookup(input:") @@ -145,7 +145,7 @@ describe("CodeModeInstructions.render", () => { const expensive = entry( "alpha.expensive", "Expensive", - `tools.alpha.expensive(input: {\n aVeryLongParameterName: string,\n anotherEvenLongerParameterName: number,\n yetAnotherExtremelyVerboseParameterName: string,\n}): Promise`, + `tools.alpha.expensive({\n aVeryLongParameterName: string,\n anotherEvenLongerParameterName: number,\n yetAnotherExtremelyVerboseParameterName: string,\n}): Promise`, ) // Round 1 places alpha.cheap and beta.cheap; in round 2 alpha.expensive does not fit, // which marks only alpha done - it must NOT prevent other namespaces from inlining. @@ -166,7 +166,7 @@ describe("CodeModeInstructions.render", () => { const documented = entry( "records.lookup", "Look up a record", - `tools.records.lookup(input: {\n /** ${"A detailed identifier description. ".repeat(20).trim()} */\n id: string,\n}): Promise`, + `tools.records.lookup({\n /** ${"A detailed identifier description. ".repeat(20).trim()} */\n id: string,\n}): Promise`, ) const instructions = render([documented], 40) expect(instructions).toContain("- records (1 tool, none shown)") @@ -184,7 +184,7 @@ describe("CodeModeInstructions.update", () => { const echo = entry("notes.echo", "Echo text") test("renders additions, changes, and removals as a compact semantic delta", () => { - const changed = { ...echo, signature: "tools.notes.echo(input: {\n text: string,\n}): Promise" } + const changed = { ...echo, signature: "tools.notes.echo({\n text: string,\n}): Promise" } const added = entry("notes.list", "List notes") const unchanged = Array.from({ length: 5 }, (_, index) => entry(`stable.tool${index}`, `Stable ${index}`)) const text = update([echo, lookup, ...unchanged], [changed, added, ...unchanged]) diff --git a/packages/core/test/codemode/instructions.test.ts b/packages/core/test/codemode/instructions.test.ts index 89270749316..5c6f760f403 100644 --- a/packages/core/test/codemode/instructions.test.ts +++ b/packages/core/test/codemode/instructions.test.ts @@ -13,14 +13,14 @@ const echo: CodeModeCatalog.Tool = { type: "tool", name: "notes.echo", description: "Echo text", - signature: "tools.notes.echo(input: {\n text: string,\n}): Promise", + signature: "tools.notes.echo({\n text: string,\n}): Promise", } const lookup: CodeModeCatalog.Tool = { type: "tool", name: "orders.lookup", description: "Look up an order", - signature: "tools.orders.lookup(input: {\n id: string,\n}): Promise", + signature: "tools.orders.lookup({\n id: string,\n}): Promise", } describe("CodeModeInstructions", () => {