UNPKG

@mastra/core

Version:
72 lines 4.59 kB
import type { PubSub } from '../events/pubsub.js'; import type { RequestContext } from '../request-context/index.js'; import type { MastraModelOutput } from '../stream/base/output.js'; import type { Agent } from './agent.js'; import type { AgentExecutionOptions } from './agent.types.js'; import type { MessageListInput } from './message-list/index.js'; import type { AgentMessageInput, AgentStateSignalInput, CreatedAgentSignal } from './signals.js'; import type { AgentSignal, AgentSubscribeToThreadOptions, AgentThreadSubscription, QueueAgentMessageOptions, QueueAgentMessageResult, SendAgentMessageOptions, SendAgentMessageResult, SendAgentSignalOptions, SendAgentSignalResult, SendAgentStateSignalOptions, SendAgentStateSignalResult } from './types.js'; export declare let defaultAgentThreadPubSub: PubSub; export type AgentThreadState = 'active' | 'idle'; export declare class AgentThreadStreamRuntime { #private; getThreadState(options: { resourceId?: string; threadId: string; }, pubsub?: PubSub): AgentThreadState; prepareRunOptions<OUTPUT>(options: AgentExecutionOptions<OUTPUT>, pubsub?: PubSub): AgentExecutionOptions<OUTPUT>; abortRun(runId: string, pubsub?: PubSub): boolean; getActiveThreadRunId(options: AgentSubscribeToThreadOptions, pubsub?: PubSub): string | undefined; getResumableThreadRun(options: AgentSubscribeToThreadOptions & { runId: string; toolCallId?: string; }, pubsub?: PubSub): { runId: string; toolCallId?: string; } | undefined; abortThread(options: AgentSubscribeToThreadOptions, pubsub?: PubSub): boolean; /** @internal */ resetForTests(): void; registerRun<OUTPUT>(agent: Agent<any, any, any, any>, output: MastraModelOutput<OUTPUT>, streamOptions: AgentExecutionOptions<OUTPUT>, pubsub?: PubSub): Promise<void> | undefined; continueWithMessages<OUTPUT = unknown>(agent: Agent<any, any, any, any>, messages: MessageListInput, target: { resourceId: string; threadId: string; streamOptions?: AgentExecutionOptions<OUTPUT>; runId?: string; }, pubsub?: PubSub): { accepted: true; runId: string; }; /** * Drains queued signals for a run. * * - `scope: 'pending'` (default) returns active-run follow-up signals — each * becomes its own model turn via `signalDrainStep`. * - `scope: 'pre-run'` returns signals queued before the run's first model * request — the first LLM step folds these into that request. */ drainPendingSignals(runId: string, pubsub?: PubSub, scope?: 'pending' | 'pre-run'): CreatedAgentSignal[]; waitForCrossAgentThreadRun(agent: Agent<any, any, any, any>, options: { memory?: AgentExecutionOptions<any>['memory']; requestContext?: RequestContext; }, pubsub?: PubSub): Promise<void>; subscribeToThread<OUTPUT = unknown>(agent: Agent<any, any, any, any>, options: AgentSubscribeToThreadOptions, pubsub?: PubSub): Promise<AgentThreadSubscription<OUTPUT>>; sendMessage<OUTPUT = unknown>(agent: Agent<any, any, any, any>, message: AgentMessageInput, target: SendAgentMessageOptions<OUTPUT>, pubsub?: PubSub): SendAgentMessageResult<OUTPUT>; queueMessage<OUTPUT = unknown>(agent: Agent<any, any, any, any>, message: AgentMessageInput, target: QueueAgentMessageOptions<OUTPUT>, pubsub?: PubSub): QueueAgentMessageResult<OUTPUT>; sendStateSignal<OUTPUT = unknown>(agent: Agent<any, any, any, any>, stateInput: AgentStateSignalInput, target: SendAgentStateSignalOptions<OUTPUT>, pubsub?: PubSub): Promise<SendAgentStateSignalResult<OUTPUT>>; /** * Routes a signal to an agent thread. * * Signals can land in three places: * - an active same-agent run, where they are queued for the execution loop to drain; * - a reserved thread run that has not registered its stream record yet; * - a new idle-started run, when the caller opts into `ifIdle`. * * Cross-agent active runs are intentionally not interrupted here. They either finish first * through `waitForCrossAgentThreadRun()` on the stream path, or this method falls through to * the idle-start path when the caller provided a resource/thread target and `ifIdle` options. */ sendSignal<OUTPUT = unknown>(agent: Agent<any, any, any, any>, signalInput: AgentSignal, target: SendAgentSignalOptions<OUTPUT>, pubsub?: PubSub): SendAgentSignalResult<OUTPUT>; } export declare const agentThreadStreamRuntime: AgentThreadStreamRuntime; //# sourceMappingURL=thread-stream-runtime.d.ts.map