@sema-agent/core
Version:
Stateless, task-oriented AI agent core
102 lines (101 loc) • 8.46 kB
TypeScript
/**
* The one mint of the notice a host raises when an entry of the user's own MCP injection (a `.mcp.json` row handed to the
* engine through the host's request lane) was NOT mounted for the leg — `config.entries_not_applied`, kind
* `mcp_injection_dropped` (7.70.0; before it, its own code `mcp.injection_dropped`, now retired: the entry the person wrote
* did not apply, the fact the merged code tells for every kind of entry). L-167: three drop sites in the host's intake and one cap site each produced
* their own wording and none reached the user; the engine did not see the entry at all (it never
* reached `prepareTask`), so no core-side notice could stand for it.
*
* Division of labour, the settlement pattern (`settlement.single_mint`): the HOST supplies FACTS
* (which session, which server name, which of the closed reasons, optionally which field was bad) and
* CORE composes the notice — the code word, the audience row, the message text per reason. A host
* never spells the code or the text itself: a second wording is a second source that drifts, and a
* host-spelled code is not in {@link import("./governance-codes.js").ENGINE_NOTICE_CODES}'s
* mint scan, so its audience row could silently rot.
*
* Audience `"user"`: the dropped entry is the user's own configuration and the recovery (rename the
* server, fix the field, trim the list) is in their hands — an operator channel does not reach them.
* `sessionId` is therefore REQUIRED at the mint (the routing half of a user row: a user disclosure
* that cannot name its session has nowhere to be delivered) — a host with no session has no user to
* tell and must not mint. Dedup unit: per leg per server name — the HOST's obligation (it owns the
* leg's intake loop); this module is pure.
*/
import type { AssertAllKeysHandled } from "./ask-origin.js";
import type { EngineNotice } from "./engine-notice.js";
/**
* The closed set of drop reasons ({@link McpInjectionDropFacts.reason}) — the host's intake
* enumerates exactly these, and a consumer rendering the notice keys on the word:
* · `malformed_entry` — the entry did not parse as a server declaration (a missing
* `command`/`url`, a `toolFaces` value of the wrong shape, …);
* `field` names the offending key when the host knows it;
* · `name_reserved_by_deployment` — the entry's server name collides with one the deployment
* itself mounts, and the deployment's wins;
* · `gate_closed` — the deployment does not accept request-lane MCP injection on
* this leg at all (a multi-tenant posture): the whole list is
* ignored, one notice per entry;
* · `over_cap` — the entry sits beyond the deployment's injection cap;
* · `key_retired` — the entry carries a key this service no longer accepts (an older
* client wrote it while it was still valid): the person's recovery
* is to update that client or delete the key; `field` names the key
* when the host knows it;
* · `credentials_not_carried` — a request does not carry an MCP server's credentials, so the
* deployment has to mount this server itself: the recovery is the
* administrator's configuration or the entry without its credentials;
* `field` names the credentials key when the host knows it;
* · `name_already_mounted` — an agent definition declared an MCP server whose normalized
* namespace is already mounted on the run (the run's server stays
* in use; the agent's duplicate entry was not mounted).
*/
export declare const MCP_INJECTION_DROP_REASONS: readonly ["malformed_entry", "name_reserved_by_deployment", "gate_closed", "over_cap", "key_retired", "credentials_not_carried", "name_already_mounted"];
export type McpInjectionDropReason = (typeof MCP_INJECTION_DROP_REASONS)[number];
/**
* The user-facing sentence per reason — the disposition table over {@link MCP_INJECTION_DROP_REASONS}
* (one reason, one wording; a consumer that wants its own phrasing keys on `detail.reason`, never on
* this text). Each names the recovery, because the reader is the person who can perform it.
*/
export declare const MCP_INJECTION_DROP_TEXT: {
readonly malformed_entry: "its declaration could not be read — fix the entry and start a new session";
readonly name_reserved_by_deployment: "the deployment mounts its own server of that name, and that server is the one in use — keep using it under this name; rename this entry only to add a second, different server";
readonly gate_closed: "this deployment does not accept MCP servers from the request on this leg — ask the operator, or use the deployment's servers";
readonly over_cap: "the request named more MCP servers than this deployment mounts per leg — trim the list";
readonly key_retired: "its declaration carries a configuration key this service no longer accepts — update the application that sent this entry, or remove that key from the entry, then start a new session";
readonly credentials_not_carried: "requests do not carry credentials for MCP servers, so the deployment has to mount this one — ask an administrator to configure it in the deployment, or remove the credentials from this entry";
readonly name_already_mounted: "another server of that name is already mounted on this run and stays in use — rename the server in this agent's configuration, or remove the duplicate";
};
export type DropTextCoversEveryReason = AssertAllKeysHandled<Exclude<McpInjectionDropReason, keyof typeof MCP_INJECTION_DROP_TEXT>>;
/** What a host (or spawn merge) knows at the drop site — facts only, no words of the engine's vocabulary composed. */
export interface McpInjectionDropFacts {
/** The session whose injection carried the entry — the notice's routing key, required (see module note). */
readonly sessionId: string;
/** The entry's server name as the user spelled it (the message quotes it verbatim). */
readonly server: string;
readonly reason: McpInjectionDropReason;
/**
* Optional: the key the host found bad, so the user knows what to edit. The sentence names it for
* `malformed_entry`, `key_retired` and `credentials_not_carried`; for the other reasons it is a fact
* carried in `detail` only.
*/
readonly field?: string;
/**
* Optional: the agent definition that declared this server entry (for drops in host intake of
* agent-level MCP declarations and spawn-time collisions with a server already mounted on the run).
* Carried in `detail.entries[0].agent` and named in the message when non-empty.
*/
readonly agent?: string;
}
/**
* Compose the notice for one MCP server declaration that was not mounted, from drop facts: `config.entries_not_applied`,
* kind `mcp_injection_dropped` (until 7.70.0 its own code, `mcp.injection_dropped`).
*
* @contract mcp.injection_dropped.single_mint — the notice for a dropped MCP server declaration is composed by CORE
* from drop FACTS (session, server name, one of the closed reasons, optionally the bad field and declaring agent); a
* caller never spells the code, the audience or the sentence, and a fact outside the vocabulary (an
* unlisted reason word, an empty session or server name) is refused at the mint with a `TypeError`
* rather than shaped into a notice that would route nowhere or read as an unknown word downstream.
*
* `detail: { kind: "mcp_injection_dropped", entries: [{ entry, reason, field?, agent? }], count: 1, identity, sessionId }` — `entry` is the
* server's name as spelled, `reason` one of {@link MCP_INJECTION_DROP_REASONS}, `field` and `agent` present only when supplied as
* non-empty strings; `sessionId` is lifted onto the typed key by {@link import("./engine-notice.js").deliverEngineNotice},
* the one throat, so the two spellings cannot disagree.
*/
export declare function mcpInjectionDroppedNotice(facts: McpInjectionDropFacts): EngineNotice;