diff --git a/README.md b/README.md index 32f7059..874a4ee 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ const triage = agent({ ``` Rig defaults agent tools to `skipPermission: true`, and you can also place plain tool objects in `tools`; rig will convert `s.*` parameter schemas into JSON Schema before creating the Copilot session. +When `parameters` uses `s.*` schemas, `handler` args are inferred automatically; for plain JSON Schema, pass an explicit generic like `defineTool<{ issue: string }>(...)`. ## Evaluating agentic performance diff --git a/skills/rig/SKILL.md b/skills/rig/SKILL.md index 84b8b1c..010b41a 100644 --- a/skills/rig/SKILL.md +++ b/skills/rig/SKILL.md @@ -170,6 +170,7 @@ s.nonEmptyArray(s.string) // string[] with at least one element ## Tools Register custom tools with `defineTool` using an SDK-neutral tool shape. Use `s.*` schemas for `parameters`. Rig defaults tools to `skipPermission: true`. +When `parameters` uses `s.*` schemas, `handler` args are inferred automatically; for plain JSON Schema, pass an explicit generic like `defineTool<{ issue: string }>(...)`. ```ts import { agent, defineTool, s } from "rig"; diff --git a/skills/rig/rig.ts b/skills/rig/rig.ts index 00746cd..db0c02b 100644 --- a/skills/rig/rig.ts +++ b/skills/rig/rig.ts @@ -540,8 +540,14 @@ export type ToolConfig = { overridesBuiltInTool?: boolean; skipPermission?: boolean; }; - -export function defineTool(name: string, config: ToolConfig): Tool { +type InferToolArgs = TParameters extends Schema ? InferSchema : unknown; + +export function defineTool( + name: string, + config: Omit>, "parameters"> & { parameters: TParameters }, +): Tool>; +export function defineTool(name: string, config: ToolConfig): Tool; +export function defineTool(name: string, config: ToolConfig): Tool { return { name, ...normalizeToolConfig(config), diff --git a/src/rig.test.ts b/src/rig.test.ts index 9a53d28..b302ad7 100644 --- a/src/rig.test.ts +++ b/src/rig.test.ts @@ -52,6 +52,7 @@ vi.mock("@github/copilot-sdk", () => ({ })); import { AgentError, PromptBuilder, agent, analyzeResponse, configureAgent, copilotEngine, defineTool, p, s, toJsonSchema } from "rig"; +import type { Tool } from "rig"; import { oncePerAgent, repair, steering, timeout } from "rig/addons"; beforeEach(() => { @@ -537,18 +538,19 @@ describe("agent invocation", () => { }); it("defines tools with rig schemas using the Copilot SDK helper shape", () => { - const handler = vi.fn(async ({ issue }: { issue: string }) => `Issue ${issue}`); const lookupIssue = defineTool("lookup_issue", { description: "Look up an issue by id.", parameters: s.object({ issue: s.string }), - handler, + handler: vi.fn(async ({ issue }) => `Issue ${issue}`), }); + const expectIssueTool = (_tool: Tool<{ issue: string }>) => true; + expect(expectIssueTool(lookupIssue)).toBe(true); expect(lookupIssue).toEqual({ name: "lookup_issue", description: "Look up an issue by id.", parameters: toJsonSchema(s.object({ issue: s.string })), - handler, + handler: expect.any(Function), skipPermission: true, }); });