/** A vendor-agnostic bag of facts about one request, produced by the pack's adapter. Powers * matching context, miss records (the authoring signal), and the self-teaching stub text. */ export type ScenarioFeatures = Record; /** One matcher: does THIS request satisfy `condition`? Pure — no state, no IO. */ export type ScenarioMatcher = (req: Req, condition: unknown) => boolean; /** The pack's declaration of its vocabulary — the ONLY vendor-specific surface. */ export type PackScenarioAdapter = { /** Vendor key, e.g. "anthropic" — used in errors and the manifest. */ vendor: string; /** Extract the feature bag for miss records / stub teaching. Pure. */ features: (req: Req) => ScenarioFeatures; /** The legal `on` keys and their per-request semantics. Pure. */ matchers: Record>; /** Validate `on` CONDITION VALUES at load (key membership is the kernel's; VALUE typing is * the pack's — a mistyped value silently never matching is the misfire strict loading exists * to prevent). Return an error string to refuse. */ validateOn?: (on: Record) => string | null; /** Validate a handler's `respond` payload at load; return an error string to refuse. * This is ALSO where a pack refuses success-shaped handlers on stateful routes * ("seed that through the vendor's API instead"). */ validateRespond?: (respond: unknown, handler: ScenarioHandler) => string | null; /** Whether the request admits a handler's answer (OpenAI's `tool_choice: 'none'` admits no tool call): a handler whose * answer it does not admit is passed over, and the next that matches answers, else the stub. Absent, every answer. */ admits?: (req: Req, respond: unknown) => boolean; /** Opt-in scope check for post-admission model generation failures; absent rejects them. */ validateGenerationFault?: (fault: ScenarioGenerationFault, handler: ScenarioHandler) => string | null; /** The VENDOR'S error envelope for a `status` fault — a 429 from this vendor looks like this * vendor's 429. Omitted → the kernel's envelope `{ error: { message, type: "twin_fault" } }`. */ renderFault?: (fault: ScenarioStatusFault, req: Req) => { body: unknown; headers?: Record; }; }; /** THE FAULT VOCABULARY (runtime contract R15 — outage rehearsal as a world-level value). One * grammar every pack's engine honors, so a 429 or a hung request is authored the same way for * every vendor instead of improvised per realizer: * slow — hold the answer `ms` before serving it (the response is whatever the handler's * `respond` or the twin's own path produces; timing is not content, R9 holds); * status — answer this HTTP status instead of serving: a 4xx/5xx the vendor's own envelope * (the pack's adapter renders it; a kernel envelope when it declares none), with * `Retry-After` when `retryAfterSeconds` is set; * generation — opt-in post-admission compute failure, carried to the handler for its SDK error wire; * drop — never answer: the request hangs until the client's own timeout ends it (what an * outage looks like from the client; a TCP reset is not something a fetch can do), * released after `holdMs` (default 300 000) so a socket is not held forever. */ export type ScenarioFault = { kind: "slow"; ms: number; } | { kind: "status"; status: number; retryAfterSeconds?: number; message?: string; errorType?: string; metadata?: Record; } | { kind: "generation"; status: number; message: string; errorType: string; metadata?: Record; partialText?: string; event?: string; } | { kind: "drop"; holdMs?: number; }; export type ScenarioGenerationFault = Extract; export type ScenarioStatusFault = Extract; /** What a `status` fault serves: the pack's rendered envelope, or the kernel's. */ export type ScenarioFaultResult = { status: number; headers: Record; body: unknown; }; export type ScenarioHandler = { /** The rule's id: `entry-`, the placement it came from. */ id?: string; /** Conditions — ALL must hold. `{}` matches every request. */ on: Record; /** The turn's answer, which the pack realizes into the vendor's envelope; absent on a fault. */ respond?: unknown; /** The fault that answers the turn instead (ScenarioFault). */ fault?: ScenarioFault; }; /** The ordered rules of one turn. */ export type ScenarioDocument = { handlers: ScenarioHandler[]; }; export type ScenarioMissRecord = { features: ScenarioFeatures; }; export type ScenarioDecision = { kind: "handler"; handler: ScenarioHandler; respond: unknown; ruleId: string; fault?: ScenarioFault; } | { kind: "miss"; miss: ScenarioMissRecord; }; export declare class ScenarioError extends Error { } /** Strict-loud parse of a turn's rules. Every refusal names the valid vocabulary. */ export declare function parseScenarioDocument(raw: ScenarioDocument, adapter: PackScenarioAdapter): ScenarioDocument; /** The engine over one turn's rules: pure, the same rules and request giving the same decision. */ export declare class ScenarioEngine { private readonly adapter; private readonly document; constructor(adapter: PackScenarioAdapter, document: ScenarioDocument); /** Decide one request: the first rule that matches and whose answer the request admits, else the miss. */ next(req: Req): ScenarioDecision; } export declare function scenarioFaultResult(fault: ScenarioFault, render?: () => { body: unknown; headers?: Record; } | undefined, signal?: AbortSignal): Promise; export declare function statefulTwinManifest(input: { vendor: string; twinOf: string; stores: string; identity?: string; behavior?: string; notes?: string; doors?: ReadonlyArray<{ method: string; path: string; note?: string; }>; }): Record; /** The GET /twin manifest — the discovery door's body. Education ships INSIDE the twin: * in-world agents have no repos or skills, only HTTP. */ export declare function twinManifest(input: { vendor: string; twinOf: string; stateSentence: string; behaviorSentence: string; exampleHandler: ScenarioHandler | null; }): Record;