import type { Operation } from "effection"; import type { AgentCue, CueEmission } from "../core/cues.js"; import { Deck } from "../core/deck.js"; import type { CueSink } from "./cue-runtime.js"; import type { Hab, Habery } from "./habbing.js"; /** * One queued query request awaiting honest habitat/attester resolution. * * These requests are intentionally portable: the coordinator may defer them * across runtime turns until enough local knowledge exists to emit a real wire * query without guessing. */ interface QueryRequest { pre: string; route: string; query: Record; hab?: Hab; src?: string; wits?: string[]; } /** * Runtime continuation contract for query-driven follow-on work. * * Each continuation: * - observes emitted cues for relevant state transitions * - can enqueue additional queries when local or remote state requires it * - exposes `done` so the runtime can include it in convergence checks */ interface QueryContinuation { readonly done: boolean; observe(cue: AgentCue, coordinator: QueryCoordinator): void; tick(coordinator: QueryCoordinator): void; } /** * KERIpy-style noticer that starts with a `ksn` query and upgrades to a * `logs` query when the remote key state is ahead of local accepted state. * * Start condition: * - caller wants authoritative remote key state for one AID * * Completion condition: * - accepted local key state is at or beyond the remote `ksn.s` * * Emitted query shape: * - first `ksn` with `{ fn: "0", s: "0" }` * - later `logs` through `LogQuerier` if remote state is ahead */ export declare class KeyStateNoticer implements QueryContinuation { readonly pre: string; readonly hab?: Hab; readonly wits?: string[]; done: boolean; private queried; private logQuerier; constructor(pre: string, { hab, wits }?: { hab?: Hab; wits?: string[]; }); observe(cue: AgentCue, coordinator: QueryCoordinator): void; tick(coordinator: QueryCoordinator): void; } /** * KERIpy-style log querier that waits until local accepted key state reaches a * target sequence number. * * Start condition: * - caller already knows the remote target sequence number * * Completion condition: * - local accepted key state reaches `targetSn` * * Emitted query shape: * - `logs` with `{ fn: "0", s: "0" }` */ export declare class LogQuerier implements QueryContinuation { readonly pre: string; readonly targetSn: number; readonly hab?: Hab; readonly wits?: string[]; done: boolean; private queried; constructor(pre: string, targetSn: number, { hab, wits }?: { hab?: Hab; wits?: string[]; }); observe(_cue: AgentCue, _coordinator: QueryCoordinator): void; tick(coordinator: QueryCoordinator): void; } /** * Query helper that waits until local accepted key state reaches one sequence * number threshold. * * Start condition: * - caller wants logs replayed until local state reaches `targetSn` * * Completion condition: * - local accepted key state reaches `targetSn` * * Emitted query shape: * - `logs` with explicit `fn` and `s` */ export declare class SeqNoQuerier implements QueryContinuation { readonly pre: string; readonly targetSn: number; readonly fn: number; readonly hab?: Hab; readonly wits?: string[]; done: boolean; private queried; constructor(pre: string, targetSn: number, { fn, hab, wits, }?: { fn?: number; hab?: Hab; wits?: string[]; }); observe(_cue: AgentCue, _coordinator: QueryCoordinator): void; tick(coordinator: QueryCoordinator): void; } /** * Query helper that waits until local state contains an anchored event seal. * * Start condition: * - caller needs proof of one anchored seal in the queried prefix's KEL * * Completion condition: * - local DB can resolve a sealing event for the requested anchor * * Emitted query shape: * - `logs` from `{ fn: "0", s: "0", a: anchor }` */ export declare class AnchorQuerier implements QueryContinuation { readonly pre: string; readonly anchor: Record; readonly hab?: Hab; readonly wits?: string[]; done: boolean; private queried; constructor(pre: string, anchor: Record, { hab, wits }?: { hab?: Hab; wits?: string[]; }); observe(_cue: AgentCue, _coordinator: QueryCoordinator): void; tick(coordinator: QueryCoordinator): void; } /** * Runtime query side-effect owner. * * Responsibilities: * - turn incomplete portable `query` cues into honest outbound `qry` wire * emissions when a local habitat and remote attester can be resolved * - host KERIpy-style query continuations such as `KeyStateNoticer` * - forward all other cue emissions unchanged to the configured downstream sink */ export declare class QueryCoordinator implements CueSink { readonly hby: Habery; readonly pending: Deck; private sink; private hab; private continuations; constructor(hby: Habery, { sink, hab }?: { sink?: CueSink; hab?: Hab | null; }); /** Rebind the active downstream sink and optional local habitat hint. */ configure({ sink, hab }?: { sink?: CueSink; hab?: Hab | null; }): void; /** Register one persistent key-state continuation. */ watchKeyState(pre: string, options?: { hab?: Hab; wits?: string[]; }): KeyStateNoticer; /** Register one persistent logs-until-sequence continuation. */ watchSeqNo(pre: string, sn: number, options?: { fn?: number; hab?: Hab; wits?: string[]; }): SeqNoQuerier; /** Register one persistent logs-until-anchor continuation. */ watchAnchor(pre: string, anchor: Record, options?: { hab?: Hab; wits?: string[]; }): AnchorQuerier; /** Return true while continuations or unsent queries are still pending. */ hasPendingWork(): boolean; /** Queue one continuation-owned query for later resolution and delivery. */ enqueue(request: QueryRequest): void; /** * Consume one emitted cue, synthesizing any broader query/reply side effects * before forwarding to the configured downstream sink. */ send(emission: CueEmission): Operation; /** * Drain one bounded pass of continuation-owned query work. * * This is the Effection analogue of the KERIpy query/noticer doers: inspect * local state, emit any initial or follow-on queries that can honestly be * constructed, and retain unresolved work for later turns. */ processPending(): Operation; /** Continuous background query worker for long-lived runtime hosts. */ queryDo(): Operation; /** * Resolve the habitat that is allowed to sign the outbound query. * * Resolution order: * - request-specific habitat * - runtime-configured habitat * - sole local habitat */ private configuredHab; private observeContinuations; private tickContinuations; private compactContinuations; /** * Convert one incomplete portable query cue into a wire-ready request when * runtime can honestly resolve its queried prefix. */ private transientQueryEmission; /** * Build one outbound wire emission after habitat and attester resolution. * * Returned `null` means runtime still lacks honest information and should * defer the request rather than manufacture a query from guesswork. */ private wireEmissionForRequest; private resolveAttester; } export {}; //# sourceMappingURL=querying.d.ts.map