import type { JobStore } from "./jobs.js"; import type { BodyKind } from "./payload.js"; export type DeliveryOutcome = "accepted" | "duplicate" | "in_flight" | "skipped" | "rejected" | "challenge" | "error"; export declare const DELIVERY_OUTCOMES: DeliveryOutcome[]; export interface DeliveryRecord { id: string; /** The skill named in the URL, as requested (also when no such skill exists). */ skill: string; received_at: string; outcome: DeliveryOutcome; /** What the sender was answered at decision time (a `?wait=` request may end as `200` with the result instead of `202`). */ http_status: number; /** The error code of a rejected delivery; `duplicate`, `in_flight`, `skipped`, `challenge` or `internal_error` otherwise; absent when accepted. */ code?: string; reason?: string; /** Provider delivery id or `dedupe` value, when one was found. */ delivery_id?: string; /** The job created (accepted) or the one the delivery was folded into (duplicate, in_flight). */ job_id?: string; ip: string; method: string; path: string; /** `token` and `wait` removed. */ query: Record; /** Redacted like `event.json`; long values shortened. */ headers: Record; user_agent?: string; content_type: string | null; bytes: number; body_kind?: BodyKind; body_stored: boolean; body_truncated?: boolean; /** Milliseconds from arrival to the decision (a `?wait=` is not counted). */ duration_ms: number; /** `ingress`: handed over by the cloud link from a hosted URL (docs/cloud.md); `http` (or absent) otherwise. */ via?: "http" | "ingress"; /** The cloud's id of a hosted-ingress delivery. */ ingress_id?: string; } export type DeliveryInput = Omit & { rawBody?: Buffer; }; export interface DeliveryLogOptions { max: number; store_bodies: boolean; body_max_bytes: number; } export interface DeliveryFilter { skill?: string; outcome?: DeliveryOutcome | DeliveryOutcome[]; /** Only deliveries received at or after this instant (ISO-8601). */ since?: string; /** Only deliveries older than the one with this id (the `next_after` of the previous page). */ after?: string; limit?: number; } export interface DeliveryPage { deliveries: DeliveryRecord[]; next_after: string | null; } export interface DeliveryBody { encoding: "utf8" | "base64"; text: string; truncated: boolean; /** `log`: kept by the delivery log; `job`: the accepted delivery's payload in its job directory. */ source: "log" | "job"; } export declare function deliveryLogDir(jobsDir: string): string; export declare class DeliveryLog { private readonly options; readonly dir: string; private readonly file; private readonly bodiesDir; private records; /** `options` is a getter so a live configuration change applies to the next record. */ constructor(jobsDir: string, options: () => DeliveryLogOptions); private load; private bodyFile; /** Appends one record (and its body when the outcome and the options say so); compacts the file when it grew past 1.5× `max`. */ record(input: DeliveryInput): DeliveryRecord; /** Newest first. `after` continues a page (by position in the log; by id order when that record is gone). */ list(filter?: DeliveryFilter): DeliveryPage; get(id: string): DeliveryRecord | undefined; /** The body kept for a refused delivery, if any. */ readBody(id: string): { bytes: Buffer; truncated: boolean; } | undefined; count(): number; /** What `GET /health` shows. */ stats(): { total: number; last_received_at: string | null; }; /** Keeps the newest `keep` records, rewrites the file atomically and deletes the bodies of dropped records. Returns how many were dropped. */ compact(keep?: number): number; } /** The body of a delivery: what the log kept for a refused one, or the payload of the job an accepted one created. */ export declare function readDeliveryBody(log: DeliveryLog, store: Pick, delivery: DeliveryRecord): DeliveryBody | undefined;