@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
30 lines • 1.12 kB
TypeScript
import type { BackgroundTaskManager } from './manager.js';
import type { BackgroundTaskHandle, CreateBackgroundTaskOptions } from './types.js';
/**
* Creates a self-contained background task handle.
*
* Bundles the task payload with per-stream hooks (executor, onChunk, onResult)
* so each dispatch is fully isolated — no shared mutable state on the manager.
*
* @example
* ```ts
* const bgTask = createBackgroundTask(manager, {
* toolName: 'research',
* toolCallId: 'call-1',
* args: { query: 'solana' },
* agentId: 'agent-1',
* runId: 'run-1',
* context: {
* executor: { execute: (args, opts) => tool.execute(args, opts) },
* onChunk: (chunk) => controller.enqueue(chunk),
* onResult: (params) => messageList.addToolResult(params),
* },
* });
*
* const { task, fallbackToSync } = await bgTask.dispatch();
* const completed = await bgTask.waitForCompletion();
* await bgTask.cancel();
* ```
*/
export declare function createBackgroundTask(manager: BackgroundTaskManager, options: CreateBackgroundTaskOptions): BackgroundTaskHandle;
//# sourceMappingURL=create.d.ts.map