UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

43 lines (42 loc) • 3.95 kB
import { type McpServerSpec } from "./mcp-server-spec.js"; /** Every member name a face declaration has, at any depth — the words a `toolFaces` refusal's member path spells (derived from the tables above). */ export declare const TOOL_FACE_WORDS: ReadonlySet<string>; /** * {@link readToolFaces}'s answer. `ok: true` hands back a copy of the faces that the reader itself built, plain data and none of the caller's own * objects; `faces` is absent when nothing is declared (no key at all, or an empty record). `ok: false` carries one sentence (its detail cut at * 240 characters) pointing at the tool and the member that did not fit. It says the face's own member names, the closed words a member takes, * kinds, counts and bounds; it never says the declaration's content — a tool name, a word a closed table refuses, a parameter name, a list * entry, display text: each is shown in the one caller's-text shape (`callerText`: the redaction mark and its length). An unknown member's * name is the name of a member the face does not take, and the sentence names it (`callerKey`: as written, on one line, bounded). * These are the mount's judge's own sentences, the ones it announces at the listing, so the reader and the mount tell one operator one thing — * but for one: a `hostTarget` slot, which the reader (an MCP entry, no tool in hand) answers with the MCP sentence and the judge answers for a tool * in hand with the sentence about the tool's name. `readToolAxes` refuses in the same sentence shape. */ export type ToolFacesRead = { ok: true; faces?: NonNullable<McpServerSpec["toolFaces"]>; } | { ok: false; problem: string; }; /** * The one reader of a raw `toolFaces` declaration — {@link McpServerSpec.toolFaces}, the per-tool FACE overlay — and the face-side sibling of * `readToolAxes` (the safety axes `effect` / `egress` / `irreversibility` are that declaration's, read once, there). The preparation door asks it * for every MCP server of a task (`config.tool_face_invalid` refuses the whole prepare — the code a caller tool's bad face has at the caller door; * a declaration the entry's own plain-data receipt refuses first keeps `config.invalid_argument`), `materializeMcpTools` asks it per server (that * server's dial fails, the same code), and a host that assembles the field from JSON asks it at its own door and hands the engine what it answered. * * It judges the declaration alone, which is everything the declaration can say without the tool's schema: the receipt of a plain-data * declaration (`receiveDeclaration`: a Proxy, a map, a class instance, a getter that throws, a cycle, a nesting past the engine's one * depth, a tool named `__proto__` are refusals that say where they sit), the shape of each face (the members the types have, each of its * kind), then the very judge the mount runs (`toolFaceProblem`) minus the checks that need the schema — the five closed words * (`family`, `pathTarget.access` / `base` / `absent`, `renderHints.approvalCard`), the bounds, and the cross-member rules (a write path * target's `base: "root"` / `absent: "base"`, an inert `patternParam`). The checks that read the schema (a `param` that is a top-level * property, the keys an approval card needs, the names a summary or a rule face lists) and the one that reads the minted tool (a result card * lives under the tool's own namespace) stay with the listing, where the schema and the tool are known. * * Any one face that does not fit refuses the WHOLE declaration (`ok: false`): a face is an overlay applied whole or not at all, and a * dropped face is a tool mounted without the protection its operator declared. Absent ⇒ `{ ok: true }`. An empty record is no declaration * either; an empty face `{}` under a tool name is kept as written. An empty tool name is refused (no tool answers to it). */ export declare function readToolFaces(declared: unknown): ToolFacesRead;