UNPKG

@mastra/core

Version:

Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.

29 lines 1.73 kB
/** * Implementation of `DurableAgent.streamUntilIdle`. Mirrors the regular * agent's `stream-until-idle.ts` but adapted for durable execution: * - `DurableAgent.stream()` returns `DurableAgentStreamResult` (not `MastraModelOutput`) * - Each continuation starts a new durable workflow (new runId) * - Cleanup functions from each inner stream are tracked and called on close * * High-level flow: * 1. Resolve memory scope (threadId, resourceId) -- falls through to plain * `agent.stream` if no memory or bgManager. * 2. Register this call as the active wrapper for the scope, aborting any * prior wrapper. * 3. Run initial turn via `agent.stream(messages, { _skipBgTaskWait: true })` * and pipe its `fullStream` into a combined outer stream. * 4. Subscribe to `bgManager.stream(...)` for background task lifecycle * events. On terminal events, queue a continuation. * 5. `maxIdleMs` fires only between turns when nothing is happening. */ import type { BackgroundTaskManager } from '../../background-tasks/manager.js'; import type { MessageListInput } from '../message-list/index.js'; import type { DurableAgent, DurableAgentStreamOptions, DurableAgentStreamResult } from './durable-agent.js'; export interface DurableStreamUntilIdleDeps { activeStreams: Map<string, () => void>; bgManager: BackgroundTaskManager | undefined; } export declare function runDurableStreamUntilIdle<OUTPUT = undefined>(agent: DurableAgent<any, any, OUTPUT>, messages: MessageListInput, streamOptions: (DurableAgentStreamOptions<OUTPUT> & { maxIdleMs?: number; }) | undefined, deps: DurableStreamUntilIdleDeps): Promise<DurableAgentStreamResult<OUTPUT>>; //# sourceMappingURL=durable-stream-until-idle.d.ts.map