@mastra/ai-sdk 0.0.0-fix-backport-setserver-20251201151948 → 0.0.0-fix-request-context-as-query-key-20251209093005
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +332 -145
- package/README.md +60 -0
- package/dist/chat-route.d.ts +42 -5
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/convert-messages.d.ts +10 -0
- package/dist/convert-messages.d.ts.map +1 -0
- package/dist/convert-streams.d.ts +81 -0
- package/dist/convert-streams.d.ts.map +1 -0
- package/dist/helpers.d.ts +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +646 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +644 -89
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts +157 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/network-route.d.ts +63 -2
- package/dist/network-route.d.ts.map +1 -1
- package/dist/to-ai-sdk-format.d.ts +11 -78
- package/dist/to-ai-sdk-format.d.ts.map +1 -1
- package/dist/transformers.d.ts.map +1 -1
- package/dist/ui.cjs +16 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.ts +2 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +13 -0
- package/dist/ui.js.map +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/workflow-route.d.ts +65 -0
- package/dist/workflow-route.d.ts.map +1 -1
- package/package.json +22 -12
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { LanguageModelV2, LanguageModelV2Middleware } from '@ai-sdk/provider';
|
|
2
|
+
import type { MemoryConfig, SemanticRecall as SemanticRecallConfig } from '@mastra/core/memory';
|
|
3
|
+
import type { InputProcessor, OutputProcessor } from '@mastra/core/processors';
|
|
4
|
+
import type { MemoryStorage } from '@mastra/core/storage';
|
|
5
|
+
import type { MastraEmbeddingModel, MastraVector } from '@mastra/core/vector';
|
|
6
|
+
/**
|
|
7
|
+
* Memory context for processors that need thread/resource info
|
|
8
|
+
*/
|
|
9
|
+
export interface ProcessorMemoryContext {
|
|
10
|
+
/** Thread ID for conversation persistence */
|
|
11
|
+
threadId?: string;
|
|
12
|
+
/** Resource ID (user/session identifier) */
|
|
13
|
+
resourceId?: string;
|
|
14
|
+
/** Memory configuration options */
|
|
15
|
+
config?: MemoryConfig;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Options for creating processor middleware
|
|
19
|
+
*/
|
|
20
|
+
export interface ProcessorMiddlewareOptions {
|
|
21
|
+
/** Input processors to run before the LLM call */
|
|
22
|
+
inputProcessors?: InputProcessor[];
|
|
23
|
+
/** Output processors to run on the LLM response */
|
|
24
|
+
outputProcessors?: OutputProcessor[];
|
|
25
|
+
/** Memory context for processors that need thread/resource info */
|
|
26
|
+
memory?: ProcessorMemoryContext;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Semantic recall configuration with required vector and embedder.
|
|
30
|
+
* Inherits JSDoc from SemanticRecall type in memory/types.ts.
|
|
31
|
+
*/
|
|
32
|
+
export type WithMastraSemanticRecallOptions = SemanticRecallConfig & {
|
|
33
|
+
/** Vector store for semantic search (required) */
|
|
34
|
+
vector: MastraVector;
|
|
35
|
+
/** Embedder for generating query embeddings (required) */
|
|
36
|
+
embedder: MastraEmbeddingModel<string>;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Memory configuration for withMastra
|
|
40
|
+
*/
|
|
41
|
+
export interface WithMastraMemoryOptions {
|
|
42
|
+
/** Storage adapter for message persistence (required) */
|
|
43
|
+
storage: MemoryStorage;
|
|
44
|
+
/** Thread ID for conversation persistence (required) */
|
|
45
|
+
threadId: string;
|
|
46
|
+
/** Resource ID (user/session identifier) */
|
|
47
|
+
resourceId?: string;
|
|
48
|
+
/** Number of recent messages to retrieve, or false to disable */
|
|
49
|
+
lastMessages?: number | false;
|
|
50
|
+
/** Semantic recall configuration (RAG-based memory retrieval) */
|
|
51
|
+
semanticRecall?: WithMastraSemanticRecallOptions;
|
|
52
|
+
/** Working memory configuration (persistent user data) */
|
|
53
|
+
workingMemory?: MemoryConfig['workingMemory'];
|
|
54
|
+
/** Read-only mode - prevents saving new messages */
|
|
55
|
+
readOnly?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Options for withMastra wrapper
|
|
59
|
+
*/
|
|
60
|
+
export interface WithMastraOptions {
|
|
61
|
+
/** Memory configuration - enables automatic message history persistence */
|
|
62
|
+
memory?: WithMastraMemoryOptions;
|
|
63
|
+
/** Input processors to run before the LLM call */
|
|
64
|
+
inputProcessors?: InputProcessor[];
|
|
65
|
+
/** Output processors to run on the LLM response */
|
|
66
|
+
outputProcessors?: OutputProcessor[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Wraps a language model with Mastra capabilities including memory and processors.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* // With message history (auto-creates MessageHistory processor)
|
|
74
|
+
* import { openai } from '@ai-sdk/openai';
|
|
75
|
+
* import { withMastra } from '@mastra/ai-sdk';
|
|
76
|
+
* import { LibSQLStore } from '@mastra/libsql';
|
|
77
|
+
*
|
|
78
|
+
* const storage = new LibSQLStore({ url: 'file:memory.db' });
|
|
79
|
+
* await storage.init();
|
|
80
|
+
*
|
|
81
|
+
* const model = withMastra(openai('gpt-4o'), {
|
|
82
|
+
* memory: {
|
|
83
|
+
* storage,
|
|
84
|
+
* threadId: 'thread-123',
|
|
85
|
+
* resourceId: 'user-456',
|
|
86
|
+
* lastMessages: 10,
|
|
87
|
+
* },
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* const { text } = await generateText({ model, prompt: 'Hello' });
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // With semantic recall (RAG-based memory)
|
|
96
|
+
* const model = withMastra(openai('gpt-4o'), {
|
|
97
|
+
* memory: {
|
|
98
|
+
* storage,
|
|
99
|
+
* threadId: 'thread-123',
|
|
100
|
+
* semanticRecall: {
|
|
101
|
+
* vector: pinecone,
|
|
102
|
+
* embedder: openai.embedding('text-embedding-3-small'),
|
|
103
|
+
* topK: 5,
|
|
104
|
+
* messageRange: 2, // Include 2 messages before/after each match
|
|
105
|
+
* },
|
|
106
|
+
* },
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* // With working memory (persistent user data)
|
|
113
|
+
* const model = withMastra(openai('gpt-4o'), {
|
|
114
|
+
* memory: {
|
|
115
|
+
* storage,
|
|
116
|
+
* threadId: 'thread-123',
|
|
117
|
+
* workingMemory: {
|
|
118
|
+
* enabled: true,
|
|
119
|
+
* template: '# User Profile\n- **Name**:\n- **Preferences**:',
|
|
120
|
+
* },
|
|
121
|
+
* },
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* // With custom processors
|
|
128
|
+
* const model = withMastra(openai('gpt-4o'), {
|
|
129
|
+
* inputProcessors: [myInputProcessor],
|
|
130
|
+
* outputProcessors: [myOutputProcessor],
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function withMastra(model: LanguageModelV2, options?: WithMastraOptions): LanguageModelV2;
|
|
135
|
+
/**
|
|
136
|
+
* Creates AI SDK middleware that runs Mastra processors on input/output.
|
|
137
|
+
* For a simpler API, use `withMastra` instead.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* import { wrapLanguageModel, generateText } from 'ai';
|
|
142
|
+
* import { openai } from '@ai-sdk/openai';
|
|
143
|
+
* import { createProcessorMiddleware } from '@mastra/ai-sdk';
|
|
144
|
+
*
|
|
145
|
+
* const model = wrapLanguageModel({
|
|
146
|
+
* model: openai('gpt-4o'),
|
|
147
|
+
* middleware: createProcessorMiddleware({
|
|
148
|
+
* inputProcessors: [myProcessor],
|
|
149
|
+
* outputProcessors: [myProcessor],
|
|
150
|
+
* }),
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* const { text } = await generateText({ model, prompt: 'Hello' });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export declare function createProcessorMiddleware(options: ProcessorMiddlewareOptions): LanguageModelV2Middleware;
|
|
157
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,yBAAyB,EAG1B,MAAM,kBAAkB,CAAC;AAI1B,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,IAAI,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhG,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EAIhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAG9E;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kDAAkD;IAClD,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;IACnC,mDAAmD;IACnD,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;IACrC,mEAAmE;IACnE,MAAM,CAAC,EAAE,sBAA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+
import type { MessageListInput } from '@mastra/core/agent/message-list';
|
|
3
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
2
4
|
import { registerApiRoute } from '@mastra/core/server';
|
|
3
5
|
import type { OutputSchema } from '@mastra/core/stream';
|
|
6
|
+
import type { InferUIMessageChunk, UIMessage } from 'ai';
|
|
7
|
+
export type NetworkStreamHandlerParams<OUTPUT extends OutputSchema = undefined> = AgentExecutionOptions<OUTPUT, 'mastra'> & {
|
|
8
|
+
messages: MessageListInput;
|
|
9
|
+
};
|
|
10
|
+
export type NetworkStreamHandlerOptions<OUTPUT extends OutputSchema = undefined> = {
|
|
11
|
+
mastra: Mastra;
|
|
12
|
+
agentId: string;
|
|
13
|
+
params: NetworkStreamHandlerParams<OUTPUT>;
|
|
14
|
+
defaultOptions?: AgentExecutionOptions<OUTPUT, 'mastra'>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Framework-agnostic handler for streaming agent network execution in AI SDK-compatible format.
|
|
18
|
+
* Use this function directly when you need to handle network streaming outside of Hono or Mastra's own apiRoutes feature.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* // Next.js App Router
|
|
23
|
+
* import { handleNetworkStream } from '@mastra/ai-sdk';
|
|
24
|
+
* import { createUIMessageStreamResponse } from 'ai';
|
|
25
|
+
* import { mastra } from '@/src/mastra';
|
|
26
|
+
*
|
|
27
|
+
* export async function POST(req: Request) {
|
|
28
|
+
* const params = await req.json();
|
|
29
|
+
* const stream = await handleNetworkStream({
|
|
30
|
+
* mastra,
|
|
31
|
+
* agentId: 'routingAgent',
|
|
32
|
+
* params,
|
|
33
|
+
* });
|
|
34
|
+
* return createUIMessageStreamResponse({ stream });
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function handleNetworkStream<UI_MESSAGE extends UIMessage, OUTPUT extends OutputSchema = undefined>({ mastra, agentId, params, defaultOptions, }: NetworkStreamHandlerOptions<OUTPUT>): Promise<ReadableStream<InferUIMessageChunk<UI_MESSAGE>>>;
|
|
4
39
|
export type NetworkRouteOptions<OUTPUT extends OutputSchema = undefined> = {
|
|
5
40
|
path: `${string}:agentId${string}`;
|
|
6
41
|
agent?: never;
|
|
7
|
-
defaultOptions?: AgentExecutionOptions<OUTPUT, '
|
|
42
|
+
defaultOptions?: AgentExecutionOptions<OUTPUT, 'mastra'>;
|
|
8
43
|
} | {
|
|
9
44
|
path: string;
|
|
10
45
|
agent: string;
|
|
11
|
-
defaultOptions?: AgentExecutionOptions<OUTPUT, '
|
|
46
|
+
defaultOptions?: AgentExecutionOptions<OUTPUT, 'mastra'>;
|
|
12
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Creates a network route handler for streaming agent network execution using the AI SDK-compatible format.
|
|
50
|
+
*
|
|
51
|
+
* This function registers an HTTP POST endpoint that accepts messages, executes an agent network, and streams the response back to the client in AI SDK-compatible format. Agent networks allow a routing agent to delegate tasks to other agents.
|
|
52
|
+
*
|
|
53
|
+
* @param {NetworkRouteOptions} options - Configuration options for the network route
|
|
54
|
+
* @param {string} [options.path='/network/:agentId'] - The route path. Include `:agentId` for dynamic routing
|
|
55
|
+
* @param {string} [options.agent] - Fixed agent ID when not using dynamic routing
|
|
56
|
+
* @param {AgentExecutionOptions} [options.defaultOptions] - Default options passed to agent execution
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Dynamic agent routing
|
|
60
|
+
* networkRoute({
|
|
61
|
+
* path: '/network/:agentId',
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Fixed agent with custom path
|
|
66
|
+
* networkRoute({
|
|
67
|
+
* path: '/api/orchestrator',
|
|
68
|
+
* agent: 'router-agent',
|
|
69
|
+
* defaultOptions: {
|
|
70
|
+
* maxSteps: 10,
|
|
71
|
+
* },
|
|
72
|
+
* });
|
|
73
|
+
*/
|
|
13
74
|
export declare function networkRoute<OUTPUT extends OutputSchema = undefined>({ path, agent, defaultOptions, }: NetworkRouteOptions<OUTPUT>): ReturnType<typeof registerApiRoute>;
|
|
14
75
|
//# sourceMappingURL=network-route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-route.d.ts","sourceRoot":"","sources":["../src/network-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"network-route.d.ts","sourceRoot":"","sources":["../src/network-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGzD,MAAM,MAAM,0BAA0B,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,IAAI,qBAAqB,CACrG,MAAM,EACN,QAAQ,CACT,GAAG;IACF,QAAQ,EAAE,gBAAgB,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,2BAA2B,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,IAAI;IACjF,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,0BAA0B,CAAC,MAAM,CAAC,CAAC;IAC3C,cAAc,CAAC,EAAE,qBAAqB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAC1D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,mBAAmB,CAAC,UAAU,SAAS,SAAS,EAAE,MAAM,SAAS,YAAY,GAAG,SAAS,EAAE,EAC/G,MAAM,EACN,OAAO,EACP,MAAM,EACN,cAAc,GACf,EAAE,2BAA2B,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC,CAqBhG;AAED,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,IACnE;IAAE,IAAI,EAAE,GAAG,MAAM,WAAW,MAAM,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,cAAc,CAAC,EAAE,qBAAqB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;CAAE,GAC/G;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,qBAAqB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;CAAE,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,EAAE,EACpE,IAA0B,EAC1B,KAAK,EACL,cAAc,GACf,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAwFnE"}
|
|
@@ -1,83 +1,16 @@
|
|
|
1
|
-
import type { MastraModelOutput, OutputSchema, MastraAgentNetworkStream, WorkflowRunOutput } from '@mastra/core/stream';
|
|
2
|
-
import type { MastraWorkflowStream, Step, WorkflowResult } from '@mastra/core/workflows';
|
|
3
|
-
import type { InferUIMessageChunk, UIMessage, UIMessageStreamOptions } from 'ai';
|
|
4
|
-
import type { ZodObject, ZodType } from 'zod';
|
|
5
1
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* This function transforms various Mastra stream types into ReadableStream objects that are compatible
|
|
9
|
-
* with the AI SDK v5, enabling seamless integration with AI SDK's streaming capabilities.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @param {MastraWorkflowStream | WorkflowRunOutput | MastraAgentNetworkStream | MastraModelOutput} stream
|
|
13
|
-
* The Mastra stream to convert. Can be one of:
|
|
14
|
-
* - MastraWorkflowStream: A workflow execution stream
|
|
15
|
-
* - WorkflowRunOutput: The output of a workflow run
|
|
16
|
-
* - MastraAgentNetworkStream: An agent network execution stream
|
|
17
|
-
* - MastraModelOutput: An agent model output stream
|
|
18
|
-
*
|
|
19
|
-
* @param {Object} options - Conversion options
|
|
20
|
-
* @param {'workflow' | 'network' | 'agent'} options.from - The type of stream being converted. Defaults to 'agent'
|
|
21
|
-
* @param {boolean} [options.includeTextStreamParts=true] - (Workflow only) Whether to include text stream parts from agent outputs. Defaults to true
|
|
22
|
-
* @param {string} [options.lastMessageId] - (Agent only) The ID of the last message in the conversation
|
|
23
|
-
* @param {boolean} [options.sendStart=true] - (Agent only) Whether to send start events. Defaults to true
|
|
24
|
-
* @param {boolean} [options.sendFinish=true] - (Agent only) Whether to send finish events. Defaults to true
|
|
25
|
-
* @param {boolean} [options.sendReasoning] - (Agent only) Whether to include reasoning in the output
|
|
26
|
-
* @param {boolean} [options.sendSources] - (Agent only) Whether to include sources in the output
|
|
27
|
-
* @param {Function} [options.messageMetadata] - (Agent only) A function that receives the current stream part and returns metadata to attach to start and finish chunks
|
|
28
|
-
* @param {Function} [options.onError] - (Agent only) A function to handle errors during stream conversion. Receives the error and should return a string representation
|
|
29
|
-
*
|
|
30
|
-
* @returns {ReadableStream<InferUIMessageChunk<UIMessage>>} A ReadableStream compatible with AI SDK v5
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* // Convert a workflow stream
|
|
34
|
-
* const workflowStream = await workflowRun.stream(...);
|
|
35
|
-
* const aiSDKStream = toAISdkFormat(workflowStream, { from: 'workflow' });
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* // Convert an agent network stream
|
|
39
|
-
* const networkStream = await agentNetwork.network(...);
|
|
40
|
-
* const aiSDKStream = toAISdkFormat(networkStream, { from: 'network' });
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* // Convert an agent stream with custom options
|
|
44
|
-
* const agentStream = await agent.stream(...);
|
|
45
|
-
* const aiSDKStream = toAISdkFormat(agentStream, {
|
|
46
|
-
* from: 'agent',
|
|
47
|
-
* lastMessageId: 'msg-123',
|
|
48
|
-
* sendReasoning: true,
|
|
49
|
-
* sendSources: true
|
|
50
|
-
* });
|
|
2
|
+
* @deprecated Use `toAISdkStream` instead. This function has been renamed for clarity.
|
|
51
3
|
*
|
|
52
4
|
* @example
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* });
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // Old (deprecated):
|
|
7
|
+
* import { toAISdkFormat } from '@mastra/ai-sdk';
|
|
8
|
+
* const stream = toAISdkFormat(agentStream, { from: 'agent' });
|
|
9
|
+
*
|
|
10
|
+
* // New:
|
|
11
|
+
* import { toAISdkStream } from '@mastra/ai-sdk';
|
|
12
|
+
* const stream = toAISdkStream(agentStream, { from: 'agent' });
|
|
13
|
+
* ```
|
|
61
14
|
*/
|
|
62
|
-
export declare function toAISdkFormat
|
|
63
|
-
from: 'workflow';
|
|
64
|
-
includeTextStreamParts?: boolean;
|
|
65
|
-
}): ReadableStream<InferUIMessageChunk<UIMessage>>;
|
|
66
|
-
export declare function toAISdkFormat<TOutput extends ZodType<any>, TInput extends ZodType<any>, TSteps extends Step<string, any, any, any, any, any>[], TState extends ZodObject<any>>(stream: WorkflowRunOutput<WorkflowResult<TState, TInput, TOutput, TSteps>>, options: {
|
|
67
|
-
from: 'workflow';
|
|
68
|
-
includeTextStreamParts?: boolean;
|
|
69
|
-
}): ReadableStream<InferUIMessageChunk<UIMessage>>;
|
|
70
|
-
export declare function toAISdkFormat(stream: MastraAgentNetworkStream, options: {
|
|
71
|
-
from: 'network';
|
|
72
|
-
}): ReadableStream<InferUIMessageChunk<UIMessage>>;
|
|
73
|
-
export declare function toAISdkFormat<TOutput extends OutputSchema>(stream: MastraModelOutput<TOutput>, options: {
|
|
74
|
-
from: 'agent';
|
|
75
|
-
lastMessageId?: string;
|
|
76
|
-
sendStart?: boolean;
|
|
77
|
-
sendFinish?: boolean;
|
|
78
|
-
sendReasoning?: boolean;
|
|
79
|
-
sendSources?: boolean;
|
|
80
|
-
messageMetadata?: UIMessageStreamOptions<UIMessage>['messageMetadata'];
|
|
81
|
-
onError?: UIMessageStreamOptions<UIMessage>['onError'];
|
|
82
|
-
}): ReadableStream<InferUIMessageChunk<UIMessage>>;
|
|
15
|
+
export declare function toAISdkFormat(): never;
|
|
83
16
|
//# sourceMappingURL=to-ai-sdk-format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-ai-sdk-format.d.ts","sourceRoot":"","sources":["../src/to-ai-sdk-format.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"to-ai-sdk-format.d.ts","sourceRoot":"","sources":["../src/to-ai-sdk-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,IAAI,KAAK,CASrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../src/transformers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAuB,MAAM,wBAAwB,CAAC;AACzG,OAAO,KAAK,EAAE,mBAAmB,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jC;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,gBAAgB,EACzB,gBAAgB,EAAE,GAAG,CACnB,MAAM,EACN;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,CAAC,UAAU,GAAG;QACnB,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACrC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC,sBAAsB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC5C,CAAC,EAAE,CAAC;IACL,KAAK,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACnC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;CACxB,CACF,EACD,QAAQ,CAAC,EAAE,OAAO,GACjB,mBAAmB,CAAC,SAAS,CAAC,GAAG,eAAe,GAAG,aAAa,GAAG,IAAI,CAgXzE"}
|
package/dist/ui.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var messageList = require('@mastra/core/agent/message-list');
|
|
4
|
+
|
|
5
|
+
// src/convert-messages.ts
|
|
6
|
+
function toAISdkV5Messages(messages) {
|
|
7
|
+
return new messageList.MessageList().add(messages, `memory`).get.all.aiV5.ui();
|
|
8
|
+
}
|
|
9
|
+
function toAISdkV4Messages(messages) {
|
|
10
|
+
return new messageList.MessageList().add(messages, `memory`).get.all.aiV4.ui();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.toAISdkV4Messages = toAISdkV4Messages;
|
|
14
|
+
exports.toAISdkV5Messages = toAISdkV5Messages;
|
|
15
|
+
//# sourceMappingURL=ui.cjs.map
|
|
16
|
+
//# sourceMappingURL=ui.cjs.map
|
package/dist/ui.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/convert-messages.ts"],"names":["MessageList"],"mappings":";;;;;AAMO,SAAS,kBAAkB,QAAA,EAA4B;AAC5D,EAAA,OAAO,IAAIA,uBAAA,EAAY,CAAE,GAAA,CAAI,QAAA,EAAU,QAAQ,CAAA,CAAE,GAAA,CAAI,GAAA,CAAI,IAAA,CAAK,EAAA,EAAG;AACnE;AAKO,SAAS,kBAAkB,QAAA,EAA4B;AAC5D,EAAA,OAAO,IAAIA,uBAAA,EAAY,CAAE,GAAA,CAAI,QAAA,EAAU,QAAQ,CAAA,CAAE,GAAA,CAAI,GAAA,CAAI,IAAA,CAAK,EAAA,EAAG;AACnE","file":"ui.cjs","sourcesContent":["import { MessageList } from '@mastra/core/agent/message-list';\nimport type { MessageListInput } from '@mastra/core/agent/message-list';\n\n/**\n * Converts messages to AI SDK V5 UI format\n */\nexport function toAISdkV5Messages(messages: MessageListInput) {\n return new MessageList().add(messages, `memory`).get.all.aiV5.ui();\n}\n\n/**\n * Converts messages to AI SDK V4 UI format\n */\nexport function toAISdkV4Messages(messages: MessageListInput) {\n return new MessageList().add(messages, `memory`).get.all.aiV4.ui();\n}\n"]}
|
package/dist/ui.d.ts
ADDED
package/dist/ui.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/ui.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MessageList } from '@mastra/core/agent/message-list';
|
|
2
|
+
|
|
3
|
+
// src/convert-messages.ts
|
|
4
|
+
function toAISdkV5Messages(messages) {
|
|
5
|
+
return new MessageList().add(messages, `memory`).get.all.aiV5.ui();
|
|
6
|
+
}
|
|
7
|
+
function toAISdkV4Messages(messages) {
|
|
8
|
+
return new MessageList().add(messages, `memory`).get.all.aiV4.ui();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { toAISdkV4Messages, toAISdkV5Messages };
|
|
12
|
+
//# sourceMappingURL=ui.js.map
|
|
13
|
+
//# sourceMappingURL=ui.js.map
|
package/dist/ui.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/convert-messages.ts"],"names":[],"mappings":";;;AAMO,SAAS,kBAAkB,QAAA,EAA4B;AAC5D,EAAA,OAAO,IAAI,WAAA,EAAY,CAAE,GAAA,CAAI,QAAA,EAAU,QAAQ,CAAA,CAAE,GAAA,CAAI,GAAA,CAAI,IAAA,CAAK,EAAA,EAAG;AACnE;AAKO,SAAS,kBAAkB,QAAA,EAA4B;AAC5D,EAAA,OAAO,IAAI,WAAA,EAAY,CAAE,GAAA,CAAI,QAAA,EAAU,QAAQ,CAAA,CAAE,GAAA,CAAI,GAAA,CAAI,IAAA,CAAK,EAAA,EAAG;AACnE","file":"ui.js","sourcesContent":["import { MessageList } from '@mastra/core/agent/message-list';\nimport type { MessageListInput } from '@mastra/core/agent/message-list';\n\n/**\n * Converts messages to AI SDK V5 UI format\n */\nexport function toAISdkV5Messages(messages: MessageListInput) {\n return new MessageList().add(messages, `memory`).get.all.aiV5.ui();\n}\n\n/**\n * Converts messages to AI SDK V4 UI format\n */\nexport function toAISdkV4Messages(messages: MessageListInput) {\n return new MessageList().add(messages, `memory`).get.all.aiV4.ui();\n}\n"]}
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEpG,eAAO,MAAM,eAAe,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,aAErD,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,SAAS,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEpG,eAAO,MAAM,eAAe,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,aAErD,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,SAAS,CAAC,YAAY,CAkCnF,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAgBzD;AAED,eAAO,MAAM,6BAA6B,GACxC,OAAO,GAAG,KACT,KAAK,IAAI,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,GAAG;IAAE,OAAO,EAAE,aAAa,CAAA;CAWvE,CAAC;AAEF,eAAO,MAAM,gCAAgC,GAC3C,OAAO,GAAG,KACT,KAAK,IAAI,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,GAAG;IAAE,OAAO,EAAE,aAAa,CAAA;CAWvE,CAAC"}
|
package/dist/workflow-route.d.ts
CHANGED
|
@@ -1,4 +1,46 @@
|
|
|
1
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
2
|
+
import type { TracingOptions } from '@mastra/core/observability';
|
|
3
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
1
4
|
import { registerApiRoute } from '@mastra/core/server';
|
|
5
|
+
import type { InferUIMessageChunk, UIMessage } from 'ai';
|
|
6
|
+
export type WorkflowStreamHandlerParams = {
|
|
7
|
+
runId?: string;
|
|
8
|
+
resourceId?: string;
|
|
9
|
+
inputData?: Record<string, any>;
|
|
10
|
+
resumeData?: Record<string, any>;
|
|
11
|
+
requestContext?: RequestContext;
|
|
12
|
+
tracingOptions?: TracingOptions;
|
|
13
|
+
step?: string;
|
|
14
|
+
};
|
|
15
|
+
export type WorkflowStreamHandlerOptions = {
|
|
16
|
+
mastra: Mastra;
|
|
17
|
+
workflowId: string;
|
|
18
|
+
params: WorkflowStreamHandlerParams;
|
|
19
|
+
includeTextStreamParts?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Framework-agnostic handler for streaming workflow execution in AI SDK-compatible format.
|
|
23
|
+
* Use this function directly when you need to handle workflow streaming outside of Hono or Mastra's own apiRoutes feature.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* // Next.js App Router
|
|
28
|
+
* import { handleWorkflowStream } from '@mastra/ai-sdk';
|
|
29
|
+
* import { createUIMessageStreamResponse } from 'ai';
|
|
30
|
+
* import { mastra } from '@/src/mastra';
|
|
31
|
+
*
|
|
32
|
+
* export async function POST(req: Request) {
|
|
33
|
+
* const params = await req.json();
|
|
34
|
+
* const stream = await handleWorkflowStream({
|
|
35
|
+
* mastra,
|
|
36
|
+
* workflowId: 'weatherWorkflow',
|
|
37
|
+
* params,
|
|
38
|
+
* });
|
|
39
|
+
* return createUIMessageStreamResponse({ stream });
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function handleWorkflowStream<UI_MESSAGE extends UIMessage>({ mastra, workflowId, params, includeTextStreamParts, }: WorkflowStreamHandlerOptions): Promise<ReadableStream<InferUIMessageChunk<UI_MESSAGE>>>;
|
|
2
44
|
export type WorkflowRouteOptions = {
|
|
3
45
|
path: `${string}:workflowId${string}`;
|
|
4
46
|
workflow?: never;
|
|
@@ -8,5 +50,28 @@ export type WorkflowRouteOptions = {
|
|
|
8
50
|
workflow: string;
|
|
9
51
|
includeTextStreamParts?: boolean;
|
|
10
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* Creates a workflow route handler for streaming workflow execution using the AI SDK format.
|
|
55
|
+
*
|
|
56
|
+
* This function registers an HTTP POST endpoint that accepts input data, executes a workflow, and streams the response back to the client in AI SDK-compatible format.
|
|
57
|
+
*
|
|
58
|
+
* @param {WorkflowRouteOptions} options - Configuration options for the workflow route
|
|
59
|
+
* @param {string} [options.path='/api/workflows/:workflowId/stream'] - The route path. Include `:workflowId` for dynamic routing
|
|
60
|
+
* @param {string} [options.workflow] - Fixed workflow ID when not using dynamic routing
|
|
61
|
+
* @param {boolean} [options.includeTextStreamParts=true] - Whether to include text stream parts in the output
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Dynamic workflow routing
|
|
65
|
+
* workflowRoute({
|
|
66
|
+
* path: '/api/workflows/:workflowId/stream',
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Fixed workflow with custom path
|
|
71
|
+
* workflowRoute({
|
|
72
|
+
* path: '/api/data-pipeline/stream',
|
|
73
|
+
* workflow: 'data-processing-workflow',
|
|
74
|
+
* });
|
|
75
|
+
*/
|
|
11
76
|
export declare function workflowRoute({ path, workflow, includeTextStreamParts, }: WorkflowRouteOptions): ReturnType<typeof registerApiRoute>;
|
|
12
77
|
//# sourceMappingURL=workflow-route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-route.d.ts","sourceRoot":"","sources":["../src/workflow-route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow-route.d.ts","sourceRoot":"","sources":["../src/workflow-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGzD,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;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"@mastra/ai-sdk",
|
|
3
|
-
"version": "0.0.0-fix-
|
|
3
|
+
"version": "0.0.0-fix-request-context-as-query-key-20251209093005",
|
|
4
4
|
"description": "Adds custom API routes to be compatible with the AI SDK UI parts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,6 +15,16 @@
|
|
|
15
15
|
"default": "./dist/index.cjs"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
|
+
"./ui": {
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/ui.d.ts",
|
|
21
|
+
"default": "./dist/ui.js"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./dist/ui.d.ts",
|
|
25
|
+
"default": "./dist/ui.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
18
28
|
"./package.json": "./package.json"
|
|
19
29
|
},
|
|
20
30
|
"files": [
|
|
@@ -23,18 +33,21 @@
|
|
|
23
33
|
],
|
|
24
34
|
"peerDependencies": {
|
|
25
35
|
"zod": "^3.25.0 || ^4.0.0",
|
|
26
|
-
"@mastra/core": "0.0.0-fix-
|
|
36
|
+
"@mastra/core": "0.0.0-fix-request-context-as-query-key-20251209093005"
|
|
27
37
|
},
|
|
28
38
|
"devDependencies": {
|
|
29
39
|
"@types/json-schema": "^7.0.15",
|
|
40
|
+
"@vitest/coverage-v8": "4.0.12",
|
|
41
|
+
"@vitest/ui": "4.0.12",
|
|
30
42
|
"eslint": "^9.37.0",
|
|
31
43
|
"tsup": "^8.5.0",
|
|
32
44
|
"typescript": "^5.8.3",
|
|
33
|
-
"vitest": "
|
|
45
|
+
"vitest": "4.0.12",
|
|
34
46
|
"zod": "^3.25.76",
|
|
35
|
-
"@internal/
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
47
|
+
"@internal/lint": "0.0.0-fix-request-context-as-query-key-20251209093005",
|
|
48
|
+
"@internal/types-builder": "0.0.0-fix-request-context-as-query-key-20251209093005",
|
|
49
|
+
"@mastra/core": "0.0.0-fix-request-context-as-query-key-20251209093005",
|
|
50
|
+
"@mastra/libsql": "0.0.0-fix-request-context-as-query-key-20251209093005"
|
|
38
51
|
},
|
|
39
52
|
"keywords": [
|
|
40
53
|
"mastra",
|
|
@@ -52,14 +65,11 @@
|
|
|
52
65
|
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
53
66
|
},
|
|
54
67
|
"dependencies": {
|
|
68
|
+
"@ai-sdk/provider": "^2.0.0",
|
|
55
69
|
"ai": "^5.0.60"
|
|
56
70
|
},
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"publish-branch": [
|
|
60
|
-
"main",
|
|
61
|
-
"0.x"
|
|
62
|
-
]
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=22.13.0"
|
|
63
73
|
},
|
|
64
74
|
"scripts": {
|
|
65
75
|
"lint": "eslint .",
|