/** * HookService — passive lifecycle-event ingestion (Phase 3, G1). * * Accepts six lifecycle event kinds, validates/normalizes them, persists each * as an Observation via the single-writer WriterQueue, emits * `observation:ingested`, and (debounce) triggers the consolidation bridge. * * Contract (spec.md): * - Fire-and-forget: a validated+admitted event returns 202 with its id; the * actual persist runs on the writer turn. * - 429 on saturation: when `WriterQueue.saturated`, `ingestOne`/`ingestBatch` * throw QueueSaturatedError and the route maps to HTTP 429 (no admission). * - 400/413 on validation failure (before admission). * - LLM-free: ingestion has no LLM dependency; the bridge is the only * LLM-touching stage and it silent-degrades. */ import { type LifecycleEventKind, type ObservationStore } from "../../data/memory/observation-repository.js"; import { WriterQueue } from "./writer-queue.js"; /** Incoming wire shape (before normalization). `event` validated case-insensitively. */ export interface IncomingEvent { event: string; projectId: string; sessionId?: string; payload: Record; importance?: number; agentId?: string; ts?: number; } /** Normalized event ready to persist. */ export interface NormalizedEvent { event: LifecycleEventKind; projectId: string; sessionId: string | null; payload: Record; importance: number; agentId: string | null; ts: number; } export type ValidationResult = { ok: true; event: NormalizedEvent; } | { ok: false; code: 400 | 413; error: string; }; /** Bridge seam — implemented by ObservationConsolidationJob. Injected for tests. */ export interface BridgeTrigger { maybeRun(projectId: string): void; } /** * Validate + normalize a single incoming event. Pure (no IO). Returns a * discriminated union; `{ok:false}` carries the HTTP-ish code. */ export declare function validateEvent(raw: IncomingEvent, maxPayloadBytes: number): ValidationResult; export interface HookServiceOptions { store?: ObservationStore; maxPending?: number; maxPayloadBytes?: number; bridge?: BridgeTrigger; /** Override id factory (deterministic tests). */ idFactory?: () => string; } export declare class HookService { readonly store: ObservationStore; readonly queue: WriterQueue; readonly bridge: BridgeTrigger; private readonly maxPayloadBytes; private readonly idFactory; constructor(opts?: HookServiceOptions); validate(raw: IncomingEvent): ValidationResult; /** * Validate, admit, and enqueue a single event. Resolves with the observation * id (the persist itself runs on the writer turn — fire-and-forget from the * caller's perspective, but the id is returned synchronously on admission). * * Throws QueueSaturatedError → route maps to 429. */ ingestOne(raw: IncomingEvent): Promise; /** * Validate the whole batch atomically, then admit all. Returns the array of * ids in input order. Throws ValidationError (400/413) if ANY event is bad, * before persisting anything; throws QueueSaturatedError if the queue cannot * admit the full batch. */ ingestBatch(raws: IncomingEvent[]): Promise; private ingestOneNormalized; } export declare class ValidationError extends Error { readonly code: 400 | 413; constructor(code: 400 | 413, message: string); } export declare function getHookService(): HookService; /** Test hook: reset the cached service (and the underlying observation store). */ export declare function resetHookService(): void; //# sourceMappingURL=hook-service.d.ts.map