UNPKG

@mastra/core

Version:

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

152 lines 6.08 kB
import type { ToolSet } from '../../../_types/@internal_ai-sdk-v5/dist/index.js'; import type { OuterLLMRun } from '../../types.js'; /** * Step that checks for pending background tasks after the LLM has responded. * * If there are pending background tasks: * 1. First invocation (retryCount === 0): returns immediately with backgroundTaskPending=true * so the loop can re-enter without blocking. * 2. Subsequent invocations: waits up to `waitTimeoutMs` for the NEXT task to complete * (Strategy B — process as they arrive). Emits progress chunks while waiting. * - If a task completes within the timeout: sets isContinued=true so the LLM processes it. * - If the timeout elapses: returns WITHOUT setting isContinued, allowing the loop to end * naturally. The background task continues running — its result will be picked up on * the next user message or stream. * * Result injection and stream chunk emission are handled by per-task hooks * registered via createBackgroundTask in tool-call-step. * * If no pending tasks: passes through unchanged with `backgroundTaskPending = false`. */ export declare function createBackgroundTaskCheckStep<Tools extends ToolSet = ToolSet, OUTPUT = undefined>({ _internal, controller, runId, agentId, }: OuterLLMRun<Tools, OUTPUT>): import("../../../workflows").Step<"backgroundTaskCheckStep", unknown, { messageId: string; messages: { all: any[]; user: any[]; nonUser: any[]; }; output: { usage: { inputTokens?: number | undefined; outputTokens?: number | undefined; totalTokens?: number | undefined; reasoningTokens?: number | undefined; cachedInputTokens?: number | undefined; cacheCreationInputTokens?: number | undefined; }; steps: any[]; text?: string | undefined; reasoning?: any[] | undefined; reasoningText?: string | undefined; files?: any[] | undefined; toolCalls?: any[] | undefined; toolResults?: any[] | undefined; sources?: any[] | undefined; staticToolCalls?: any[] | undefined; dynamicToolCalls?: any[] | undefined; staticToolResults?: any[] | undefined; dynamicToolResults?: any[] | undefined; }; metadata: { id?: string | undefined; model?: string | undefined; modelId?: string | undefined; modelMetadata?: { modelId: string; modelVersion: string; modelProvider: string; } | undefined; timestamp?: Date | undefined; providerMetadata?: Record<string, any> | undefined; headers?: Record<string, string> | undefined; request?: Record<string, any> | undefined; }; stepResult: { reason: string; warnings: any[]; isContinued: boolean; logprobs?: any; totalUsage?: { inputTokens?: number | undefined; outputTokens?: number | undefined; totalTokens?: number | undefined; reasoningTokens?: number | undefined; cachedInputTokens?: number | undefined; cacheCreationInputTokens?: number | undefined; } | undefined; headers?: Record<string, string> | undefined; messageId?: string | undefined; request?: Record<string, any> | undefined; }; processorRetryCount?: number | undefined; fallbackModelIndex?: number | undefined; processorRetryFeedback?: string | undefined; isTaskCompleteCheckFailed?: boolean | undefined; backgroundTaskPending?: boolean | undefined; }, { messageId: string; messages: { all: any[]; user: any[]; nonUser: any[]; }; output: { usage: { inputTokens?: number | undefined; outputTokens?: number | undefined; totalTokens?: number | undefined; reasoningTokens?: number | undefined; cachedInputTokens?: number | undefined; cacheCreationInputTokens?: number | undefined; }; steps: any[]; text?: string | undefined; reasoning?: any[] | undefined; reasoningText?: string | undefined; files?: any[] | undefined; toolCalls?: any[] | undefined; toolResults?: any[] | undefined; sources?: any[] | undefined; staticToolCalls?: any[] | undefined; dynamicToolCalls?: any[] | undefined; staticToolResults?: any[] | undefined; dynamicToolResults?: any[] | undefined; }; metadata: { id?: string | undefined; model?: string | undefined; modelId?: string | undefined; modelMetadata?: { modelId: string; modelVersion: string; modelProvider: string; } | undefined; timestamp?: Date | undefined; providerMetadata?: Record<string, any> | undefined; headers?: Record<string, string> | undefined; request?: Record<string, any> | undefined; }; stepResult: { reason: string; warnings: any[]; isContinued: boolean; logprobs?: any; totalUsage?: { inputTokens?: number | undefined; outputTokens?: number | undefined; totalTokens?: number | undefined; reasoningTokens?: number | undefined; cachedInputTokens?: number | undefined; cacheCreationInputTokens?: number | undefined; } | undefined; headers?: Record<string, string> | undefined; messageId?: string | undefined; request?: Record<string, any> | undefined; }; processorRetryCount?: number | undefined; fallbackModelIndex?: number | undefined; processorRetryFeedback?: string | undefined; isTaskCompleteCheckFailed?: boolean | undefined; backgroundTaskPending?: boolean | undefined; }, unknown, unknown, import("../../../workflows").DefaultEngineType, unknown>; //# sourceMappingURL=background-task-check-step.d.ts.map