import { z } from "zod"; import type { RuleStore } from "../corpus/store.ts"; import type { TraceStep } from "./events.ts"; import { type Profile } from "./profile.ts"; /** * One tool, in the shape every runtime here accepts. * * This is deliberately the intersection of what the AI SDK and Eve both take: a * name, a description the model reads to choose it, a Zod schema for the input, * and an async function. Neither framework appears in this file, so a third * runtime needs no change here. */ export type RuleTool = { name: string; description: string; inputSchema: z.ZodTypeAny; execute: (input: never) => Promise; /** * Extra trace detail, read from the result the call returned. * * The trace is the only structured thing a browser sees from an agent turn: * the answer itself arrives as prose. A tool that did something a reader must * know about, such as a page outside the corpus, says so here. The interface * can then mark it. Returning nothing leaves the step as it was. */ describeResult?: (result: unknown) => Partial | undefined; /** * True when this tool deliberately takes the name of another one. * * Two tools of one name would otherwise throw. Set this to replace a built-in * on purpose: a corpus search of your own in place of `search_all`, for one. * The tool that sets it wins, and the one it replaced never reaches the model. */ replaces?: boolean; }; /** * One tool, before `defineTool` widens it. * * `S` is what gives `execute` its input type, and `R` is what `execute` returns. * `R` then types `describeResult`'s only argument, so a trace label is written * against the real result rather than against `unknown`. */ export type ToolSpec = { name: string; description: string; inputSchema: S; /** `input` is inferred from `inputSchema`, so the compiler checks this body. */ execute: (input: z.output) => Promise; /** `result` is what `execute` resolved to, so the compiler checks this body too. */ describeResult?: (result: R) => Partial | undefined; replaces?: boolean; }; /** * Define one tool, with `execute`'s input inferred from the schema. * * Write a tool this way rather than as a plain object. `RuleTool.execute` takes * `never` so that any concrete input type satisfies it, which means a plain * object gets NO inference: a hand-written `input:` annotation can disagree with * the schema beside it, and nothing reports that. The generic below is what * compares the two. * * It also checks the name, because a name is the one field with an outside * constraint. See `TOOL_NAME`. */ export declare function defineTool(spec: ToolSpec): RuleTool; /** The tools `defineReferenceTools` builds. A caller must not pass these by hand. */ export declare const REFERENCE_TOOL_NAMES: readonly ["list_references", "fetch_reference"]; /** * Refuse reference tools that arrived through `extraTools`. * * `createRulesAgent({ references })` adds two things: these tools, AND the * instruction block that makes the model name the site and mark the claim as * outside the rules data. Building the tools by hand gets the first and not the * second, and the answer then cites somebody's website as though it were the * rules. Nothing downstream can separate the two, which is why this throws * rather than warning. */ export declare function assertReferenceToolsAreConfigured(extraTools: RuleTool[], hasReferences: boolean): void; /** * Warn about a tool the model will never call. * * The instructions tell the assistant to decline whole subjects, and REGISTERING * A TOOL DOES NOT AMEND THAT LIST. A tool on a declined subject is wired * correctly, described correctly, and never called once: the model answers that * the subject is outside what it covers, and the tool records no calls. Every * check a caller can run by hand passes, so the cause is close to unfindable. * * A procedure naming the tool is the fix, so a caller who has written one gets * no warning. This warns rather than throwing: the match is a word search, and a * false positive must not stop an application that works. */ export declare function warnAboutDeclinedSubjects(tools: RuleTool[], skills: { requiresTool?: string; }[]): void; /** * Refuse a tool list that holds one name two times. * * The runtime builds its tool map with `Object.fromEntries`, and a repeated key * keeps the LAST entry. So a caller who adds a tool named `get_rule` through * `extraTools` silently removes the built-in `get_rule`, and the agent loses its * most-used lookup. Nothing failed, and the only symptom was a worse answer. * * A tool that sets `replaces` means to do this, and passes. */ export declare function assertUniqueToolNames(tools: RuleTool[]): void; /** * Every tool the assistant can call, reading one store. * * There is no HTTP here, no schema discovery, and no allow-list to police. A * tool that does not exist cannot be called, which is a stronger guarantee than * a list of operations somebody has to keep correct. */ /** * What a corpus actually holds, so a tool that can answer nothing is not offered. * * A game with no banned list still had a tool for one. The model spends a step * calling it, reads an empty list, and learns that this project's tools return * nothing. Chess, poker, and the property game each carried three such tools. */ export type CorpusContents = { errata: boolean; banlist: boolean; patchNotes: boolean; rulings: boolean; }; /** Read which collections hold anything. One cheap count each. */ export declare function corpusContents(store: RuleStore): Promise; export declare function defineRulesTools(store: RuleStore, profile: Profile, contents?: CorpusContents): RuleTool[]; /** Look one tool up by name. */ export declare function findTool(tools: RuleTool[], name: string): RuleTool | undefined; //# sourceMappingURL=tools.d.ts.map