import { AbstractAgent, AgentConfig, BaseEvent, Message, RunAgentInput } from "@ag-ui/client"; import { RequestContext } from "@mastra/core/request-context"; import { Observable } from "rxjs"; import { Agent } from "@mastra/core/agent"; import { MastraClient } from "@mastra/client-js"; import { Mastra } from "@mastra/core"; import { CoreMessage } from "@mastra/core/llm"; //#region src/utils.d.ts declare function convertAGUIMessagesToMastra(messages: Message[]): CoreMessage[]; interface GetRemoteAgentsOptions { mastraClient: MastraClient; resourceId: string; } declare function getRemoteAgents({ mastraClient, resourceId }: GetRemoteAgentsOptions): Promise>; interface GetLocalAgentsOptions { mastra: Mastra; resourceId: string; requestContext?: RequestContext; } declare function getLocalAgents({ mastra, resourceId, requestContext }: GetLocalAgentsOptions): Record; interface GetLocalAgentOptions { mastra: Mastra; agentId: string; resourceId: string; requestContext?: RequestContext; } declare function getLocalAgent({ mastra, agentId, resourceId, requestContext }: GetLocalAgentOptions): AbstractAgent; interface GetNetworkOptions { mastra: Mastra; networkId: string; resourceId: string; requestContext?: RequestContext; } declare function getNetwork({ mastra, networkId, resourceId, requestContext }: GetNetworkOptions): AbstractAgent; //#endregion //#region src/mastra.d.ts type RemoteMastraAgent = ReturnType; interface MastraAgentConfig extends AgentConfig { agent: Agent | RemoteMastraAgent; resourceId?: string; requestContext?: RequestContext; } declare class MastraAgent extends AbstractAgent { private config; agent: Agent | RemoteMastraAgent; resourceId?: string; requestContext?: RequestContext; headers?: Record; constructor(config: MastraAgentConfig); clone(): MastraAgent; run(input: RunAgentInput): Observable; isLocalMastraAgent(agent: Agent | RemoteMastraAgent): agent is Agent; /** * Fetches working memory from a local agent and emits a STATE_SNAPSHOT event * if valid working memory is available. * * Best-effort: logs a warning and returns gracefully on failure so callers * can proceed with RUN_FINISHED even when the snapshot could not be delivered. */ private emitWorkingMemorySnapshot; /** * Creates the callback set used by processFullStream to emit AG-UI events. * messageId is accessed/mutated via getter/setter closures so that when * onFinishMessagePart replaces the ID with a new UUID, subsequent callbacks * in the same run() invocation see the updated value. */ private makeStreamCallbacks; /** * Creates a stateful chunk processor that maps Mastra stream chunks to * AG-UI events via callbacks. Buffers tool-call chunks: if followed by * tool-call-suspended, the TOOL_CALL_* events are suppressed (the tool * hasn't executed yet — emitting them confuses CopilotKit's orchestration * which expects a TOOL_CALL_RESULT to follow). * * Used by both the local agent path (async iterable) and the remote agent * path (processDataStream callback) — single source of truth for chunk * handling and buffering logic. * * @returns An object with two methods: * - `handleChunk`: processes a single chunk; returns `true` if processing should stop (error or malformed chunk). * - `flush`: emits any buffered tool-call (call at end of stream). */ private createChunkProcessor; /** * Processes a Mastra fullStream (async iterable) using createChunkProcessor. * @returns true if processing stopped early (error chunk or malformed chunk). */ private processFullStream; /** * Streams a local or remote Mastra agent, emitting AG-UI events via callbacks. * For local agents, iterates fullStream with processFullStream. * For remote agents, uses processDataStream with createChunkProcessor. * Calls onRunFinished on success. For errors, onError is called either from * within stream processing (error chunks) or from the catch block (thrown exceptions). */ private streamMastraAgent; static getRemoteAgents(options: GetRemoteAgentsOptions): Promise>; static getLocalAgents(options: GetLocalAgentsOptions): Record; static getLocalAgent(options: GetLocalAgentOptions): AbstractAgent; static getNetwork(options: GetNetworkOptions): AbstractAgent; } //#endregion export { GetLocalAgentOptions, GetLocalAgentsOptions, GetNetworkOptions, GetRemoteAgentsOptions, MastraAgent, MastraAgentConfig, convertAGUIMessagesToMastra, getLocalAgent, getLocalAgents, getNetwork, getRemoteAgents }; //# sourceMappingURL=index.d.mts.map