import type { InvocationLevel } from '@substrat-run/contracts/invocation-record'; import { type AsyncInvocationKind, type AsyncOutcome, type InvocationLogLine } from './invocation-line.js'; import type { EmittedReport } from './scope-host.js'; /** One unit of async work, as the host saw it end. */ export interface AsyncUnit { kind: AsyncInvocationKind; tenantId: string; scopeId: string; /** * The id the unit's `ctx.log` lines and the line itself share. The call's own id when the * unit ran in a call's tail, so the call's drill-down shows it; otherwise one minted for * the unit ({@link asyncInvocationId}). */ invocationId: string; /** A consumer's name (its module, or `executor:`), or a schedule's operation. */ operation: string; /** `Date.now()` when the unit started — host code, so the real clock. */ startedAt: number; outcome: Exclude; /** The handler threw. Only its `errorCode` is kept; see the header. */ error?: unknown; eventType?: string; eventId?: string; attempt?: number; dueAt?: string | null; latenessMs?: number | null; /** Who the work ran as. A consumer and a schedule run as `system`; an import as its peer. */ principalKind?: string; emitted?: EmittedReport; versionId?: string | null; } /** Where a host sends an async line. The default writes it to the runtime's console. */ export type InvocationLineSink = (line: InvocationLogLine) => void; /** The default sink: one JSON line, as the request line is written. */ export declare const consoleInvocationLineSink: InvocationLineSink; /** The most unit lines one pass writes before it starts counting instead. */ export declare const ASYNC_LINES_PER_PASS = 100; /** * The level of an async unit. A thrown handler is an error whatever happens next — it broke, * retry or not. A unit that ended without its handler doing the work — dead-lettered without * a throw, held inert on a copy, refused by a schedule — is a warning: nothing broke, and it * is still not success. Everything else is info. */ export declare function asyncLevelOf(outcome: AsyncOutcome, threw: boolean): InvocationLevel; /** The invocation id for a unit: the call it ran in, or a fresh one. */ export declare function asyncInvocationId(callId: string | null | undefined): string; /** The line for one unit — through the request line's own builder. */ export declare function asyncInvocationLine(unit: AsyncUnit): InvocationLogLine; /** One pass's writer: the cap, and the line that stands in for what the cap withheld. */ export interface AsyncLinePass { /** Write a unit's line, or count it once the pass is over its cap. Never throws. */ write(unit: AsyncUnit): void; /** Write the `suppressed` line, if anything was withheld. Call once, when the pass ends. */ end(): void; } /** * Open a pass. Every write is swallowed on failure: a line that cannot be written is one * missing line, never a failed delivery — the delivery has already been journaled. */ export declare function asyncLinePass(sink?: InvocationLineSink, cap?: number): AsyncLinePass; //# sourceMappingURL=async-invocation-log.d.ts.map