UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

111 lines (110 loc) • 9.1 kB
/** * Which declaration a request goes to, as the ledger is asked about it: the protocol, and the declaration's name in that protocol's own * namespace (an MCP server named "x" and an A2A peer named "x" are two declarations). `fingerprint` is present exactly when the * declaration carries one (`McpServerSpec.fingerprint`, `A2aServerSpec.fingerprint`), so the host can tell one registration of a * name from another — an A2A peer whose identity changed under the same name is the next registration, not the last one. */ export type ProtocolRevocationTarget = { readonly protocol: "mcp"; readonly server: string; readonly fingerprint?: string; } | { readonly protocol: "a2a"; readonly peer: string; readonly fingerprint?: string; }; /** The host's revocation ledger ({@link RunnerDeps.protocolRevocations}): `revoked` answers, synchronously, whether the deployment has * withdrawn the declaration the target names. */ export interface ProtocolRevocationLedger { revoked(target: ProtocolRevocationTarget): boolean; } /** The code a request refused because its target was revoked is answered with, per protocol: each protocol's own namespace. */ export declare const REVOKED_PEER_CODES: Readonly<{ readonly mcp: "mcp.server_revoked"; readonly a2a: "a2a.peer_revoked"; }>; export type RevokedPeerCode = (typeof REVOKED_PEER_CODES)[keyof typeof REVOKED_PEER_CODES]; /** The code a request to an A2A peer registered inside the trust boundary is answered with when the revocation ledger could not be read * for it: not sent, and not said to be revoked. */ export declare const A2A_REVOCATION_UNREADABLE_CODE = "a2a.revocation_unreadable"; /** Why the revocation door stopped a request: the ledger withdrew its target, or (an inside A2A peer only) the ledger could not be read. */ export type RevocationStopCause = "revoked" | "unreadable"; /** The code the revocation door gives an A2A peer's stopped request, by cause: the one word a tool result (`details.code`), a peer's status * row (`A2aPeerStatus.code`) and the wiring manifest's entry (`WiringManifestA2aEntry.code`) all carry — the failure kind on a row says * `revoked` for both causes, this tells them apart. */ export type A2aRevocationStopCode = (typeof REVOKED_PEER_CODES)["a2a"] | typeof A2A_REVOCATION_UNREADABLE_CODE; /** The declaration's name as the target carries it. */ export declare function revocationTargetName(target: ProtocolRevocationTarget): string; /** * A request the revocation ledger stopped at the request exit: nothing of it was sent. Thrown by the exits only; every outlet that answers * the model maps it to its own result form (mcp-server-link.ts `revokedCallResult`), and the failure classifier reads it as `revoked` * (mcp-failure.ts). Its code comes from {@link REVOKED_PEER_CODES} and nowhere else. `afterSentHop`: the door stopped a REDIRECT of a * request whose earlier hop was already sent (an A2A hop judge), so what the peer did with that hop is unknown. Its `details` say what * any failure record says of it — `delivered: "no"` when nothing of the request was sent, `"unknown"` after a sent hop — so a re-send * the door stopped does not speak for a call whose first attempt was sent (the peer seat's re-send rule, `sentOnceMore`): that call * answers what its first attempt met. `why` is why the door stopped it: `revoked` (the ledger withdrew the target; the code is the * protocol's {@link REVOKED_PEER_CODES} word) or `unreadable` (an A2A peer registered inside the trust boundary whose ledger answer could * not be read; the code is {@link A2A_REVOCATION_UNREADABLE_CODE}) — the same "not sent" on every outlet, never the same words. */ export declare class ProtocolRevokedRefusal extends Error { readonly code: RevokedPeerCode | typeof A2A_REVOCATION_UNREADABLE_CODE; readonly target: ProtocolRevocationTarget; readonly afterSentHop: boolean; readonly why: RevocationStopCause; readonly details: { readonly code: RevokedPeerCode | typeof A2A_REVOCATION_UNREADABLE_CODE; readonly delivered: "no" | "unknown"; }; constructor(target: ProtocolRevocationTarget, afterSentHop?: boolean, why?: RevocationStopCause); } /** * A revocation question, carried from the door that let a request through (or the dial gate that opened a connection) to the exit where * bytes leave — past the step that takes the pieces from the peer seat, which may wait on the host: over http every send leaves through * the seat's fetch (`peer-seat.ts` `peerFetch`), a stdio child and a host's pipe at their dial (mcp.ts `connectServer`). Over http every * send is asked — a request, a notification, an answer to the peer's own request, the receive stream and its resumption, the session end: * the question the send carries, else the one its connection was opened under ({@link openingQuestion}). A revoked server is sent nothing. * A question counts only for the registration it asks about (`about`, the ledger's own target: the name, and the fingerprint when the * declaration carries one): a send made in the scope of another registration's question — a host's seat answer for X that lets go of Y, * a second registration of the same name — is asked its own connection's. */ export interface RevocationQuestion { readonly about: ProtocolRevocationTarget; readonly ask: () => ProtocolRevokedRefusal | undefined; } /** The ledger's target for an MCP declaration — what its question asks about: the name, and the fingerprint exactly when it carries one. */ export declare function mcpRevocationTarget(spec: { readonly name: string; readonly fingerprint?: unknown; }): ProtocolRevocationTarget; /** Run `send` carrying the revocation question to its exit ({@link askCarriedRevocation}). */ export declare function carryRevocation<T>(question: RevocationQuestion, send: () => Promise<T>): Promise<T>; /** The question a connection to `about` is opened under — read where the connection is built, inside its dial's gate; `undefined` when no ledger is wired. */ export declare function openingQuestion(about: ProtocolRevocationTarget): RevocationQuestion | undefined; /** At an exit, after the pieces were taken and before anything is sent: the question the send carries when it asks about `about`, else * `opened` (its connection's {@link openingQuestion}), asked; its refusal is thrown. Nothing to ask ⇒ nothing is asked. An exit that * names no server (a stdio child's or a host pipe's dial) asks the question it carries. */ export declare function askCarriedRevocation(opened?: RevocationQuestion, about?: ProtocolRevocationTarget): void; /** What one question to the ledger read: `revoked` (it answered `true`), `standing` (it answered `false`) or `unreadable` (it threw, or * answered anything that is not a boolean). Each request exit decides what an unreadable answer stops: an MCP request and a request to * an A2A peer outside the trust boundary go out; a request to an A2A peer registered inside it does not. */ export type RevocationReading = "revoked" | "standing" | "unreadable"; /** One question to the ledger as a materialization asks it, read into a {@link RevocationReading}; a broken answer is told once (see {@link revocationProbe}). */ export type RevocationProbe = (target: ProtocolRevocationTarget) => RevocationReading; /** * The one reader of a revocation seat handed to the engine (`new Runner`, the two library materializations): absent ⇒ `undefined`; else * an object whose `revoked` member is a function, read once and kept bound to that object in a frozen copy — or refused * (`config.invalid_argument`) naming what does not fit. The form before this seat (`{ isRevoked(serverName, mount?) }`) is refused by * name with the form that replaced it: a ledger of that form, handed a target object, would answer "not revoked" for every request. */ export declare function receiveProtocolRevocations(raw: unknown, subject: string): ProtocolRevocationLedger | undefined; /** The revocation argument of a library materialization: the seat ({@link receiveProtocolRevocations}) and, beside it, the optional * `onProbeFailure` that hears a broken probe once per call of the entrance. */ export declare function libraryRevocationProbe(raw: unknown, subject: string): RevocationProbe | undefined; /** * THE probe over one ledger, for one leg (the runner builds one per leg and hands it to both materializations; a library entrance builds * one per call): each question asks the ledger again — the answer is never kept — and an answer that is not a boolean, or a throw, is a * broken probe read `unreadable` (which request it stops is the exit's: {@link RevocationReading}). The first broken answer is told to * `onProbeFailure` once; later ones stay quiet (the condition is standing, not news per request). A sink that throws is not a second * fault source. */ export declare function revocationProbe(ledger: ProtocolRevocationLedger | undefined, onProbeFailure: ((error: unknown) => void) | undefined): RevocationProbe | undefined;