UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

68 lines (67 loc) • 5.05 kB
/** * The MCP `toolFaces` OVERLAY and protocol-tool undeclared-key announcements: a deployment's per-tool * face declaration for a protocol tool that has no `ToolSpec` of its own (`McpServerSpec.toolFaces`, keyed by * the server's RAW tool name like `allowTools` / `toolAxes`), plus undeclared-key checks for `McpServerSpec.toolAxes` * and `A2aServerSpec.toolAxes`. Validated against the MATERIALIZED schema at every listing * (the first mount and every RefreshMcpTools): `pathTarget.param` / `hostTarget.param` must be a top-level property (and a * face declares at most one of the two); an * `approvalCard` must find the keys the card needs; a `ruleFace` may only name scalar keys; `family` * must be a member of the closed set; every `resultCards` entry must live under the tool's own card namespace. * A failing overlay does NOT mount, and neither does its tool (mounted bare it would drop the protection the overlay declares) — * the leg announces `config.tool_face_invalid` once per tool, to the person whose session is short of it (audience `user`); a `toolFaces` or `toolAxes` key naming a * tool or A2A skill the complete listing does not carry announces `config.tool_face_undeclared` once per key (with a raw-name * hint when the key equals the minted wire name of a kept entry). Never a silent partial application: an overlay is one * declaration, applied whole or not at all. * * Prepare-path machinery (layer 1): pure over the tool objects and the server/peer specs; the notice sink * is a parameter. The declaration itself is read once, by `readToolFaces` (`core/tool-face-reader.ts`), at the preparation door and at the * materialization entrance; the specs this file consumes carry that reader's copy, never the caller's object. */ import type { AgentTool } from "../../internal/harness-types.js"; import type { McpServerSpec } from "../mcp-server-spec.js"; import type { A2aServerSpec, RunnerDeps } from "../types.js"; import type { A2aPeerStatus } from "../a2a.js"; import { type ToolApprovalCard } from "../tool-face.js"; import { type EngineNotice } from "../engine-notice.js"; /** The keys each specialised approval card needs on the call (the SHELL owns the * card's full schema; this is the pre-filter the overlay is validated against). */ export declare const APPROVAL_CARD_REQUIRED_KEYS: Readonly<Record<ToolApprovalCard, readonly string[]>>; export type McpToolFace = NonNullable<McpServerSpec["toolFaces"]>[string]; /** The tool a face rides on, as far as the judge needs to know it: its name (a reserved approval card belongs to the engine's own tool of that * name) and, when the caller holds the tool's card namespace, the `cardId` its `resultCards` must live under (`<cardId>/<card>`). */ export interface FaceTool { readonly toolName: string; readonly cardId?: string; } /** Why an overlay is refused — a closed reason list, each a distinct declaration mistake. */ export declare function toolFaceProblem(face: McpToolFace, schema: AgentTool["parameters"], tool?: FaceTool): string | undefined; export declare function faceProblem(face: McpToolFace, schema: AgentTool["parameters"] | undefined, tool?: FaceTool): string | undefined; export interface ApplyToolFacesInput { /** The materialized tools of ONE server (namespaced names). */ tools: readonly AgentTool[]; server: Pick<McpServerSpec, "name" | "toolFaces" | "toolAxes">; /** Every name the server's `tools/list` answered with, on a walk that reached its end — reported by the listing's producer, the tools * `allowTools`, the intake or the valve kept from `tools` included. Only against it is a key announced as naming no listed tool; * absent (a dial that failed, a server that serves no tools, a walk that stopped early, a caller that holds no listing), no key is. */ listed?: ReadonlySet<string>; /** The leg's notice sink and its once-per-leg ledger (keys: `invalid:<name>` / `undeclared:<json([server,raw])>` / * `undeclared-axis:<json([server,raw])>` / `undeclared-a2a-axis:<json([peer,raw])>`). */ onNotice: ((notice: EngineNotice) => void) | undefined; /** Optional operator error sink (`{ phase: "mcp", sessionId }`) for the validator's diagnosis. */ onError?: RunnerDeps["onError"]; announced: Set<string>; sessionId: string; runId: string; } export interface AnnounceA2aToolAxesInput { peers: readonly Pick<A2aServerSpec, "name" | "toolAxes" | "allowSkills">[]; statuses: readonly A2aPeerStatus[]; onNotice: ((notice: EngineNotice) => void) | undefined; announced: Set<string>; sessionId: string; runId: string; } /** Announce every `A2aServerSpec.toolAxes` key naming a skill id the peer's complete agent card does not carry, * through the same `config.tool_face_undeclared` notice MCP uses (`detail.server` carries the peer's declared name). */ export declare function announceA2aUndeclaredToolAxes(input: AnnounceA2aToolAxesInput): void; export declare function applyMcpToolFaces(input: ApplyToolFacesInput): AgentTool[];