/** * A task id as hosts mint and accept it: a letter or digit, then up to 255 * letters, digits or `_ . : @ -`. `packages/agent/native-host/task-id.mjs` * holds the same rule for staged hosts that cannot import this package. */ export declare const TASK_ID_PATTERN: RegExp; declare const TASK_STATUSES: readonly ["active", "paused", "blocked", "waiting", "completed", "cancelled"]; export type TaskStatus = (typeof TASK_STATUSES)[number]; declare const TASK_OPERATION_STATUSES: readonly ["prepared", "dispatched", "succeeded", "failed", "cancelled", "unknown"]; export type TaskOperationStatus = (typeof TASK_OPERATION_STATUSES)[number]; interface TaskEventShape { /** The operation statuses this kind records, or null when it names no operation. */ operation: readonly TaskOperationStatus[] | null; origin: "none" | "optional" | "required"; } /** * Every event kind and the fields it carries: the one list the type and the * validator read. Operation kinds always name their operation and the status * the reducer left it in. */ export declare const TASK_EVENT_KINDS: { readonly create: { readonly operation: null; readonly origin: "none"; }; readonly checkpoint: { readonly operation: null; readonly origin: "none"; }; readonly observe: { readonly operation: null; readonly origin: "optional"; }; readonly resume: { readonly operation: null; readonly origin: "optional"; }; readonly rebind: { readonly operation: null; readonly origin: "none"; }; readonly pause: { readonly operation: null; readonly origin: "none"; }; readonly cancel: { readonly operation: null; readonly origin: "none"; }; readonly recover: { readonly operation: null; readonly origin: "none"; }; readonly revoke: { readonly operation: null; readonly origin: "none"; }; readonly complete: { readonly operation: null; readonly origin: "none"; }; readonly prepare: { readonly operation: readonly ["prepared"]; readonly origin: "none"; }; readonly dispatch: { readonly operation: readonly ["dispatched"]; readonly origin: "none"; }; readonly result: { readonly operation: readonly ["succeeded", "failed", "unknown"]; readonly origin: "none"; }; readonly reconcile: { readonly operation: readonly ["succeeded", "failed", "unknown"]; readonly origin: "none"; }; readonly "extend-origin": { readonly operation: null; readonly origin: "required"; }; readonly "retract-origin": { readonly operation: null; readonly origin: "required"; }; }; export type TaskEventKind = keyof typeof TASK_EVENT_KINDS; interface TaskEventBase { schemaVersion: 1; eventId: string; taskId: string; sequence: number; epoch: number; at: number; status: TaskStatus; } type OperationFields = S["operation"] extends readonly TaskOperationStatus[] ? { operationId: string; operationStatus: S["operation"][number]; } : { operationId?: never; operationStatus?: never; }; /** * Extended tasks: the origin granted or retracted, or the observed page's * origin. Never a path or query. */ type OriginFields = S["origin"] extends "required" ? { origin: string; } : S["origin"] extends "optional" ? { origin?: string; } : { origin?: never; }; export type TaskEvent = { [K in TaskEventKind]: TaskEventBase & { kind: K; } & OperationFields<(typeof TASK_EVENT_KINDS)[K]> & OriginFields<(typeof TASK_EVENT_KINDS)[K]>; }[TaskEventKind]; export declare function validateTaskEvent(value: unknown): asserts value is TaskEvent; /** Replayed pages are harmless; conflicting duplicates, wrong tasks and gaps reject. */ export declare function mergeTaskEvents(taskId: string, previous: readonly TaskEvent[], incoming: readonly unknown[]): TaskEvent[]; export interface TaskEventPage { events: TaskEvent[]; cursor: number; hasMore: boolean; task: { id: string; revision: number; epoch: number; status: TaskStatus; hasUnknownOutcome: boolean; }; } /** Admit a complete page against the last accepted history, without losing it on error. */ export declare function mergeTaskEventPage(taskId: string, previous: TaskEventPage | null, value: unknown): TaskEventPage; export interface TaskEventReaderState { page: TaskEventPage | null; pending: boolean; failed: boolean; } export interface TaskEventReaderOptions { /** Read only. Implementations must not dispatch or replay task actions. */ read: (taskId: string, after: number) => Promise; changed: (state: TaskEventReaderState) => void; pollIntervalMs?: number; } /** Read-only paged history with single-flight polling and stale-response fencing. */ export declare class TaskEventReader { private readonly options; private readonly interval; private generation; private taskId; private state; private timer; constructor(options: TaskEventReaderOptions); private publish; start(taskId: string): Promise; /** Detach without publishing. Safe for unmount and immediately reusable. */ stop(): void; refresh(): Promise; } export {};