import type { Action } from "../types/components.js"; import type { JSONSchema, ToolDefinition } from "../types/model.js"; import { type ActionParametersJsonSchema, type JsonSchema } from "./action-schema.js"; export declare const NATIVE_TOOL_NAME_PATTERN: RegExp; /** * Canonical Stage 1 tool name. * * - HANDLE_RESPONSE: stage 1, called once per inbound message. The model * declares intent (RESPOND / IGNORE / STOP), picks contexts to engage, * may emit a simple-mode reply directly, and may extract durable * facts / relationships for the memory pipeline. * * Stage 2 (planning) does not go through a single wrapper tool. Each * Action is exposed to the LLM as its own native tool whose name is the * action name and whose `parameters` is the action's parameter JSONSchema. * The model picks the action by name and calls it directly. */ export declare const HANDLE_RESPONSE_TOOL_NAME: "HANDLE_RESPONSE"; /** Reserved planner protocol for loading authorized schemas without domain effects. */ export declare const DISCOVER_ACTIONS_NAME: "DISCOVER_ACTIONS"; /** Declared discovery simile for the canonical action. */ export declare const DISCOVER_TOOLS_NAME: "DISCOVER_TOOLS"; /** Recognizes planner discovery calls by their declared names. */ export declare function isDiscoveryActionName(name: string): boolean; /** Shared should-respond contract for static and registry-composed schemas. */ export declare const SHOULD_RESPOND_SCHEMA_DESCRIPTION = "RESPOND=reply/run actions when the current message addresses you, assigns you work, clearly continues a question you asked, or needs a concrete correction or action specifically from you. A question broadcast to a group is not by itself a reason to interrupt; apply any ambient-turn policy in the prompt. IGNORE=silent for acknowledgements/reactions, side chatter, feeds, or messages directed to other people. STOP=explicit user stop."; /** * Canonical Stage-1 HANDLE_RESPONSE parameters. This mirrors the builtin * ResponseHandlerFieldRegistry field order used in production. Plugin callers * may still pass an explicit `parameters` object to `createHandleResponseTool`; * callers that omit it get the same builtin field shape. */ export declare const HANDLE_RESPONSE_SCHEMA: JSONSchema; export interface PlannerToolDefinition { type: "function"; function: { name: string; description: string; parameters: ActionParametersJsonSchema | JsonSchema; strict: boolean; strictWithOptionalProperties?: boolean; }; } export declare function assertNativeToolName(name: string): void; /** * Build the Stage 1 tool definition. Pass `directMessage: true` for DM / * API / SELF channels to use the direct-message description. The schema stays * canonical and still includes `shouldRespond`; the field evaluator decides the * value, and direct-message defaults are handled by prompt/parse policy. */ export declare function createHandleResponseTool(options?: { directMessage?: boolean; parameters?: JSONSchema; description?: string; }): ToolDefinition; /** * Stage 1 tool. The model uses this once per inbound message to declare * how it wants to handle the turn. Output drives the rest of the pipeline: * * shouldRespond = "RESPOND" → engage `contexts`, run planner against the per-action tools * shouldRespond = "IGNORE" → terminate silently * shouldRespond = "STOP" → terminate with terminal stop signal * * `replyText` is always present (the user-facing reply). For trivially simple * replies that don't need action planning the model sets `contexts = ["simple"]` * (or leaves it empty) and `replyText` is the whole answer — the runtime emits * it without invoking the planner. Otherwise planning runs against `contexts` * and the planner produces the final message; `replyText` then serves as the * early acknowledgement. */ export declare const HANDLE_RESPONSE_TOOL: ToolDefinition; /** Minimal Action shape consumed by the planner-tool conversion helpers. */ export type PlannerToolActionShape = Pick & { subActions?: Action["subActions"]; }; /** * Build a per-turn list of `ToolDefinition`s from the complete Stage 2 * action surface. Each action becomes a native tool whose name is the * action name and whose `parameters` is the action's parameter * JSONSchema, so the LLM calls each action directly by name. * * Tool description is composed from (in order): * - the action's `routingHint` (if present, on its own line) * - the complete `description` (short descriptions are fallback-only) * * The order of `actions` is preserved in the output (callers control * tool ordering by ordering the input). Names are validated against * {@link NATIVE_TOOL_NAME_PATTERN}; an invalid name throws. */ export declare function buildPlannerToolsFromActions(actions: ReadonlyArray): ToolDefinition[]; /** * Options accepted by {@link buildPlannerToolsFromTieredActions}. */ export interface BuildPlannerToolsFromTieredActionsOptions { /** * Resolves string child references. Unresolved references are omitted; inline children must * resolve to registered actions when a lookup is supplied. */ actionLookup?: ReadonlyMap | Readonly>; /** * Optional callback invoked when a string sub-action reference could not * be resolved through `actionLookup`. Defaults to skipped. Useful for * threading log messages without coupling the helper to a logger. */ onUnresolvedSubAction?: (info: { parentName: string; subActionName: string; }) => void; /** * Expand registered child actions into first-class native tools. Defaults to * true. A caller may disable expansion only when it still exposes every * authorized umbrella parent and keeps independently implemented children * direct; the parent schema plus its alias contracts remain the lossless * dispatch surface for its promoted children. */ expandSubActions?: boolean; } /** * Build a per-turn list of `ToolDefinition`s from a tier-aware Stage 2 action * surface. Every input parent's sub-actions are expanded into first-class tools * alongside the parent, so relevance metadata cannot hide a callable action. * * Sub-action resolution: * - Inline `Action` sub-actions are resolved through an explicitly supplied * authorized lookup before expansion; standalone callers without a lookup * retain the inline object. * - String-only sub-action references are resolved through `actionLookup` * when provided; references that cannot be resolved are skipped silently * (the parent's handler can still route to them). * * The output is deduplicated by tool `name` — if a child appears both as a * top-level entry in `actions` AND as a sub-action under a tier-A parent, it * is emitted only once. Input order is preserved: each parent is followed by * its expanded children (in `subActions` declaration order) before the next * parent in `actions`. */ export declare function buildPlannerToolsFromTieredActions(actions: ReadonlyArray, options?: BuildPlannerToolsFromTieredActionsOptions): ToolDefinition[]; /** * Universal terminal-sentinel tools. Always exposed to the planner regardless * of action narrowing so the model can end the turn with a stable, known * surface. REPLY emits the final user-facing message; IGNORE / STOP terminate * without a reply. * * Built once at module load from plain data; no action runtime is involved. */ export declare const CORE_PLANNER_TERMINALS: ReadonlyArray; /** * Build a per-action tool definition. Retained for internal renderers and * external callers (e.g. local-AI grammar wiring) that still want the * `{type, function: {...}}` envelope shape. Stage 2 planning itself uses * {@link buildPlannerToolsFromActions} instead — that shape is the flat * `ToolDefinition` accepted by the provider plumbing. */ export declare function actionToTool(action: Action): PlannerToolDefinition;