UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

74 lines (73 loc) • 7.53 kB
/** * The person-facing half of an MCP server that could not be reached (`mcp.server_unavailable`, audience `user`). A server that fails to * connect or to list its tools is SKIPPED (fail-open: one bad server never bricks the task), and the run completes with the other * servers' tools; the operator hears it on `onError` (`{ phase: "mcp" }`), the wiring manifest's row and the materialization's status read * `failed`, and this notice is what the session's user hears — where, before it, they heard nothing and found the server's tools missing. * * It is derived from the SAME warning object the operator lane carries (`MaterializedMcp.warnings`, minted by `asServerWarning` in * mcp.ts), where the Runner drains that lane — so the operator's line and the person's notice are one fact, and there is no second source: * the server is read off the warning's `server` member, never parsed out of its sentence. A server whose dial failed `unauthorized` in a way * the user owes ({@link owesAuthorization}) is NOT told here: `mcp.authorization_required` already tells the user that fact, with the way to fix it, and says the * server's tools are unavailable until then — two notices for one fact would be two readings. One whose failure is `unauthorized` with * reason `seat_unavailable` owes the user nothing and IS told here, as the unreachable server it is. * * Dedup unit: once per session per (server, memory) — the delivery throat's fact key, judged against the leg's own session's told * record (the operator's half of the same warning is once per session already). A failure the session's pool keeps (`memory: "kept"`: * one that waited out the startup bound) is not tried again by the session, so it is said with the way back (change the server's * configuration, have it reconnected, or give a server that is only slow to start a longer startup timeout); a later leg answered * from that memory (`memory: "recalled"`) dialed nothing and says nothing — the pool's memory is what makes a kept failure one fact * per session, so a leg whose dial made a kept failure afresh (after a forget, or under a changed declaration) tells it again. A * failure that is not kept is worded from engine-classified producer structure: explicit host-seat refusal (`delivered: "no"`), * host-seat/pipe fault, missing host seat, deployment host-floor URL block, or unsupported URL protocol each get a fixed engine sentence * with a way out (never any host condition, thrown text, or URL), while other failures (including `delivered: "unknown"` host-seat * verdicts) use the generic unreachable sentence; all are said once until the server * connects, and their words say that they are said once per session. What ends either is {@link endMcpServerUnavailable}, through the * throat's one end of a fact. Never folded across servers (a second server's notice must not be hidden behind the first's). * * `detail` carries the declared server's name, `memory: "kept"` when the pool keeps the failure (absent when it does not), the session * whose pool holds the attempt (`leg.sessionId` — for a child or a workflow agent, which leases from its session tree's pool, the * tree's root session) and the leg's run — never the failure's text (the server's own words are the operator's) and never a URL, * command or path. */ import { type EngineNotice, type NoticeTold } from "./engine-notice.js"; import type { McpServerStatus } from "./mcp.js"; /** The warning code the materialization mints for a server it skipped, and the notice's own: one word, two faces. */ export declare const MCP_SERVER_UNAVAILABLE: "mcp.server_unavailable"; /** Engine-classified causes that replace the generic unreachable sentence with a cause-specific fixed message and way out. */ export type McpUnavailableCause = "host_seat_refused" | "host_seat_fault" | "host_seat_missing" | "host_floor_refused" | "unsupported_url_scheme"; /** What `asServerWarning` mints: the operator warning, carrying the declared server it is about, and — on a pooled dial — what the * session's pool did with the failure: `kept` (this leg's attempt failed and the session remembers it) or `recalled` (this leg * dialed nothing: the session's memory of an earlier attempt answered). Absent: the failure is not remembered. */ export type McpServerWarning = Error & { code: typeof MCP_SERVER_UNAVAILABLE | "mcp.authorization_required"; server: string; memory?: "kept" | "recalled"; }; /** Classify an MCP dial failure into one of the engine-owned user-notice causes, read off producer structure only (never message text). */ export declare function mcpUnavailableCauseOf(err: unknown): McpUnavailableCause | undefined; /** Attach the classified user-notice cause non-enumerably to a server warning so `onError` consumers see no extra enumerable keys. */ export declare function attachUnavailableCause(warning: McpServerWarning, err: unknown): McpServerWarning; /** Whether the session's pool remembers `server`'s failure, read off the materialization's warnings — the one carrier of that fact * (`memory`, kept or recalled); the model's frame asks it as the person's notice does. */ export declare function mcpFailureRemembered(warnings: readonly Error[]): (server: string) => boolean; /** The notice a materialization warning stands for, or `undefined` when it stands for none: a warning of another code, one that names no * server, one about a server whose failure was an authorization the user owes (told by `mcp.authorization_required`), or one a leg * answered from the session's memory (told when that attempt failed). */ export declare function mcpServerUnavailableNotice(warning: Error, statuses: readonly Pick<McpServerStatus, "name" | "authorization">[], leg: { sessionId: string; runId: string; }): EngineNotice | undefined; /** The notice that the leg's wait for its MCP servers, before the leg's first model request (a root's, a child's, a workflow member's alike), is waiting for `server` (`waitedMs` so far, its startup * bound `boundMs`): `mcp.server_connecting`. The words name the server and the two times, never its command, URL or path. */ export declare function mcpServerConnectingNotice(server: string, waitedMs: number, boundMs: number, leg: { sessionId: string; runId: string; }): EngineNotice; /** What this leg's dial read about each server's unreachable fact, said to the throat before the leg's notices are told ({@link endNoticeFact}, * the one end of a fact): a server that CONNECTED no longer fails, and one whose ENDPOINT ANSWERED with a refusal the user owes an authorization for * (a 401 or a 403 — `rejected`, `scope`; `mcp.authorization_required` is its notice) is reachable, so its next failure to be reached is told * again; a failure this leg's dial made that the pool now KEEPS (`memory: "kept"` — never `recalled`) was dialed because the session did not * remember the server (a forget, or a changed declaration), so whatever the session had been told of its failing is over and the new one is * told. A server that stays down ends nothing: its fact holds, and is told once; nor does one the seat held no credential for (`none`: nothing * was sent, so nothing was learned of the endpoint) or could not answer for (`seat_unavailable`, told here as unreachable). */ export declare function endMcpServerUnavailable(told: NoticeTold, statuses: readonly Pick<McpServerStatus, "name" | "status" | "authorization">[], warnings: readonly Error[]): void;