UNPKG

@mastra/core

Version:
49 lines • 2.15 kB
import type { BackgroundTaskManager } from '../../../background-tasks/index.js'; export type BackgroundTaskCheckOutcome = /** No manager, or no running tasks — pass through unchanged. */ { status: 'pass-through'; } /** Tasks are running but this site doesn't wait — flag pending only. */ | { status: 'pending'; } /** Waited, but no task completed in time — pass through so the loop can end. */ | { status: 'timeout'; } /** A task completed — flag pending and force continuation so the LLM sees it. */ | { status: 'completed'; }; /** * Shared background-task-check behavior: after the LLM has * responded, look for still-running background tasks and decide whether to * wait for the next completion, signal pending without blocking, or pass * through. Progress chunks are emitted while waiting; result injection is * handled by per-task hooks registered at dispatch time. * * The wait gate is engine-owned via `resolveWaitMs` (deliberate divergence, * not drift): the main loop never waits without an explicit timeout because * background results reach its live stream controller even after the run * ends; the durable loop must always wait (1s default) because its pubsub * subscription is torn down when the workflow finishes, so returning early * would drop the task's result chunks. Returning `undefined` means "signal * pending, don't block"; a number is the wait timeout in ms. * * Emission is best-effort: transport failures (closed controller/pubsub) are * swallowed and never affect the wait outcome. */ export declare function checkBackgroundTasks(deps: { bgManager: Pick<BackgroundTaskManager, 'listTasks' | 'waitForNextTask'> | undefined; runId: string; agentId?: string; threadId?: string; resourceId?: string; /** Outer caller (e.g. `streamUntilIdle`) drives continuation — never wait in-loop. */ skipWait?: boolean; retryCount: number; resolveWaitMs: (retryCount: number) => number | undefined; emitChunk: (chunk: unknown) => void | Promise<void>; }): Promise<BackgroundTaskCheckOutcome>; //# sourceMappingURL=background-task-check-core.d.ts.map