import { type Operation } from "effection"; import type { AgentCue } from "../core/cues.js"; import { Deck } from "../core/deck.js"; import type { KeriDispatchEnvelope, TransIdxSigGroup } from "../core/dispatch.js"; import type { OobiRecord } from "../core/records.js"; import type { Mailboxer } from "../db/mailboxing.js"; import type { Noter } from "../db/noting.js"; import { Authenticator } from "./authenticating.js"; import { type CueSink } from "./cue-runtime.js"; import { Anchorer } from "./delegating.js"; import { type MailboxPollBatch, MailboxPoller, type MailboxPollTransport, Poster } from "./forwarding.js"; import type { Hab, Habery } from "./habbing.js"; import { MailboxDirector } from "./mailbox-director.js"; import { Notifier } from "./notifying.js"; import { Oobiery, type OobiJob } from "./oobiery.js"; import { QueryCoordinator } from "./querying.js"; import { Reactor, type VdrRuntimeServices } from "./reactor.js"; import { Respondant } from "./respondant.js"; import { type RuntimeServices } from "./runtime-services.js"; import { Signaler } from "./signaling.js"; /** * Shared runtime host mode. * * These modes describe where the same `AgentRuntime` bundle is being hosted, * not different implementations. Gate E uses `local` for command-hosted work * and `indirect` for the long-lived HTTP OOBI host. */ export type AgentMode = "local" | "indirect" | "direct" | "both"; export type { KeriDispatchEnvelope, OobiJob, TransIdxSigGroup }; export type { CueSink }; /** * Shared runtime composition root owned by one `Habery`. * * Ownership model: * - the root keeps only truly shared state: `hby`, host `mode`, and the shared * cue deck * - topic-local state belongs to the component that owns that flow * - `Reactor` owns parser ingress/routing/escrow work * - `Oobiery` owns durable OOBI queue processing * - `Authenticator` owns well-known auth convergence * * KERIpy mental model: * - this is the closest local analogue to a composition root that assembles * multiple doer-owning components, not a bag of every runtime queue */ export interface AgentRuntime { hby: Habery; mode: AgentMode; mailboxer: Mailboxer | null; noter: Noter | null; notifier: Notifier | null; signaler: Signaler | null; cues: Deck; reactor: Reactor; oobiery: Oobiery; authenticator: Authenticator; mailboxDirector: MailboxDirector; respondant: Respondant; mailboxPoller: MailboxPoller; poster: Poster; delegating: Anchorer; querying: QueryCoordinator; vdr: VdrRuntimeServices; services: RuntimeServices; /** Close only runtime-owned sidecars; caller-injected resources stay caller-owned. */ close(): Operation; } /** * Construction options for the shared `AgentRuntime` bundle. * * The runtime intentionally has a small option surface in Gate E so command- * local hosting and long-lived hosting stay behaviorally aligned. */ export interface AgentRuntimeOptions { mode?: AgentMode; mailboxer?: Mailboxer; noter?: Noter; signaler?: Signaler; notifier?: Notifier; enableMailboxStore?: boolean; services?: Partial; mailboxPollTransport?: MailboxPollTransport; vdr?: VdrRuntimeServices; } /** Summary of pending runtime-backed durable work for bounded command hosts. */ export interface RuntimePendingState { ingress: boolean; cues: boolean; replyEscrow: boolean; oobiQueued: boolean; oobiInFlight: boolean; multiPending: boolean; authQueued: boolean; authInFlight: boolean; outboxPending: boolean; delegationPending: boolean; /** True when query continuations or deferred correspondence requests remain. */ queriesPending: boolean; } export interface RuntimeOobiTerminalState { status: "pending" | "resolved" | "failed"; via: "none" | "roobi" | "eoobi" | "rmfa"; record: OobiRecord | null; } /** * Create the shared runtime composition root used by CLI commands and * `tufa agent`. * * Construction rule: * - every host mode uses the same shared cue deck and the same component * classes * - hosting style changes where the runtime is run, not what it is */ export declare function createAgentRuntime(hby: Habery, options?: AgentRuntimeOptions): Operation; /** * Queue one CESR/KERI message byte sequence for runtime parsing. * * This is the supported ingress seam for both local synthetic messages and * remotely fetched OOBI material. */ export declare function ingestKeriBytes(runtime: AgentRuntime, bytes: Uint8Array): void; /** * Queue one OOBI resolution job through the durable OOBI component. * * Unlike the older bootstrap runtime, this no longer stages jobs on a root * in-memory deck. The authoritative queue is the `oobis.` database family. */ export declare function enqueueOobi(runtime: AgentRuntime, job: OobiJob): void; /** * Parse and settle one or more newly arrived KERI/CESR messages immediately. * * This is the shared ingress-settlement seam for mailbox-delivered batches and * HTTP request payloads that should advance parser and escrow state together. * * Maintainer mental model: * - this helper is intentionally route-policy-free * - callers decide whether a message should be treated as `local` or ordinary * remote ingress before calling it * - once called, it always does the same two things: feed the parser and run * one escrow replay turn * * Why `local` matters: * - `local` is not an HTTP transport detail * - it is a parser/runtime semantic switch used when the host is acting as the * local controller or local witness for the received message * - witness hosting relies on that distinction so accepted witness-targeted * events emit witness cues rather than ordinary remote receipt cues */ export declare function settleRuntimeIngress(runtime: AgentRuntime, messages: Iterable, { local, }?: { local?: boolean; }): void; /** * Settle one mailbox retrieval batch while preserving per-source boundaries. * * Local and remote poll results are intentionally processed batch-by-batch so * follow-on escrow progress can occur before the next source is consumed. */ export declare function settleMailboxPollBatch(runtime: AgentRuntime, batch: MailboxPollBatch): void; /** * Drain one bounded mailbox polling turn and settle each returned batch. * * This keeps mailbox polling ownership inside the shared runtime surface so * commands do not need to know how mailbox ingress is parsed and escrowed. */ export declare function processMailboxTurn(runtime: AgentRuntime, options?: { hab?: Hab; budgetMs?: number; }): Operation; /** * Drain one bounded runtime turn by delegating to component-owned flows. * * Turn order: * 1. `Reactor.processOnce()` drains queued ingress * 2. `Oobiery.processOnce()` resolves at most one durable OOBI record * 3. `Authenticator.processOnce()` advances one well-known auth step * 4. `processCuesOnce()` emits cues from fresh ingress/OOBI work into * `QueryCoordinator` * 5. `QueryCoordinator.processPending()` resolves any newly correspondence-ready * query work * 6. `Reactor.processEscrowsOnce()` runs KEL and reply escrow passes * 7. `processCuesOnce()` emits cues created during escrow progress * 8. `QueryCoordinator.processPending()` resolves any follow-on query work * * This helper remains because command-local CLI flows and focused tests need a * single deterministic step without having to spawn the long-lived doers. */ export declare function processRuntimeTurn(runtime: AgentRuntime, options?: { hab?: Hab; sink?: CueSink; pollMailbox?: boolean; }): Operation; /** * Return the current pending-work summary for bounded command-local hosts. * * `queriesPending` is part of convergence because query continuations may still * owe a follow-on `logs` query or local catch-up wait after normal cue decks * and ingress have drained. */ export declare function runtimePendingState(runtime: AgentRuntime): RuntimePendingState; /** Return true when any command-local runtime work remains in flight. */ export declare function runtimeHasPendingWork(runtime: AgentRuntime): boolean; /** Return true when a well-known URL has been authorized into `wkas.`. */ export declare function runtimeHasWellKnownAuth(runtime: AgentRuntime, url: string): boolean; /** Return the current terminal state projection for one requested OOBI URL. */ export declare function runtimeOobiTerminalState(runtime: AgentRuntime, url: string): RuntimeOobiTerminalState; /** * Return true once one requested OOBI has reached a terminal state and all * related runtime work has drained. */ export declare function runtimeOobiConverged(runtime: AgentRuntime, url: string): boolean; /** * Drive the shared runtime until the caller-provided completion predicate * succeeds or the bounded turn budget is exhausted. */ export declare function processRuntimeUntil(runtime: AgentRuntime, done: () => boolean, options?: { hab?: Hab; sink?: CueSink; maxTurns?: number; pollMailbox?: boolean; }): Operation; /** * Yield cooperatively back to the host scheduler between runtime turns. * * Re-exported here because earlier Gate E helpers imported the scheduler * boundary from `agent-runtime.ts`, and the boundary still conceptually belongs * to the shared runtime surface even though components use it internally too. */ export { runtimeTurn } from "./runtime-turn.js"; /** * Run the shared runtime continuously until the surrounding host halts it. * * Component/doer model: * - `Reactor.msgDo()` owns continuous ingress draining * - `Reactor.escrowDo()` owns continuous escrow reprocessing * - `Oobiery.oobiDo()` owns durable OOBI resolution * - `Authenticator.authDo()` owns well-known auth convergence * - `QueryCoordinator.queryDo()` owns deferred query correspondence work * * The root itself now acts as a composition host: it starts the component * doers and stays alive until the surrounding Effection scope halts. */ export declare function runAgentRuntime(runtime: AgentRuntime, options?: { hab?: Hab; sink?: CueSink; }): Operation; //# sourceMappingURL=agent-runtime.d.ts.map