import type { UUID } from "../types/primitives.js"; import type { IAgentRuntime } from "../types/runtime.js"; /** * Creates a serialised (sequential) promise queue. * * Each call to the returned function chains the provided async `fn` after * the previous one completes, ensuring only one operation runs at a time. * * Usage: * const run = createSerialise(); * await run(async () => {... }); */ export declare function createSerialise(): (fn: () => Promise) => Promise; /** Browser-safe task scheduling primitives; hosts supply the runtime. */ /** FIFO permit admission shared by asynchronous task processors. */ export declare class Semaphore { private permits; private waiters; constructor(count: number); /** Number of currently available permits. */ get availablePermits(): number; /** Number of tasks currently queued waiting for a permit. */ get queueLength(): number; /** Cancelled waiters own no permit; callers release only after admission. */ acquire(signal?: AbortSignal): Promise; release(): void; } export interface TaskDrainOptions { taskName: string; /** Initial interval for repeat task metadata. */ intervalMs: number; /** Optional DB task description (e.g. affinity label). */ description?: string; /** Extra metadata merged into the repeat task (e.g. `{ affinityKey: "default" }`). */ taskMetadata?: Record; /** * When true, does not call `runtime.registerTaskWorker` — use when a global worker * already handles this task name (e.g. `BATCHER_DRAIN` in the assistant plugin). */ skipRegisterWorker?: boolean; /** * Required unless `skipRegisterWorker` is true. Invoked when the repeat task * fires; may return how many items it processed so an idle queue can back off. */ onDrain?: (runtime: IAgentRuntime) => Promise | Promise; /** * Cadence while the last drain processed nothing. EMBEDDING_DRAIN and * PII_SCRUB_DRAIN rewrote public.tasks every second around the clock while * idle (audit 2026-09-13); the next non-empty drain restores `intervalMs`. */ idleIntervalMs?: number; } export declare class TaskDrain { private readonly taskName; private readonly taskMetadata; private readonly skipRegisterWorker; private readonly onDrain?; private readonly idleIntervalMs?; private intervalMs; private taskId; private disposed; private readonly description; constructor(options: TaskDrainOptions, initialIntervalMs?: number); get id(): UUID | null; /** * Register worker (unless skipped) and ensure the repeat task exists for this agent. */ start(runtime: IAgentRuntime): Promise; /** Match agent + every key in `taskMetadata` (e.g. affinityKey for batcher drains). */ private matchesTask; private ensureTask; /** * Update repeat interval in DB when scheduling changes (e.g. batcher ideal tick). */ updateInterval(runtime: IAgentRuntime, newIntervalMs: number): Promise; getIntervalMs(): number; dispose(runtime: IAgentRuntime): Promise; }