@mastra/ai-sdk 1.0.0-beta.4 → 1.0.0-beta.6
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 +75 -0
- 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-streams.d.ts +3 -2
- package/dist/convert-streams.d.ts.map +1 -1
- package/dist/index.cjs +185 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +183 -67
- package/dist/index.js.map +1 -1
- package/dist/network-route.d.ts +63 -2
- package/dist/network-route.d.ts.map +1 -1
- package/dist/transformers.d.ts +118 -7
- package/dist/transformers.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/workflow-route.d.ts +68 -1
- package/dist/workflow-route.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/network-route.d.ts
CHANGED
|
@@ -1,14 +1,75 @@
|
|
|
1
1
|
import type { AgentExecutionOptions } from '@mastra/core/agent';
|
|
2
|
+
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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A;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"}
|
package/dist/transformers.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { ChunkType, DataChunkType, NetworkChunkType } from '@mastra/core/st
|
|
|
3
3
|
import type { WorkflowRunStatus, WorkflowStepStatus } from '@mastra/core/workflows';
|
|
4
4
|
import type { InferUIMessageChunk, UIMessage, UIMessageStreamOptions } from 'ai';
|
|
5
5
|
import type { ZodType } from 'zod';
|
|
6
|
+
import type { ToolAgentChunkType, ToolWorkflowChunkType, ToolNetworkChunkType } from './helpers.js';
|
|
6
7
|
type LanguageModelV2Usage = {
|
|
7
8
|
/**
|
|
8
9
|
The number of input (prompt) tokens used.
|
|
@@ -68,14 +69,16 @@ export type AgentDataPart = {
|
|
|
68
69
|
data: LLMStepResult;
|
|
69
70
|
};
|
|
70
71
|
declare const PRIMITIVE_CACHE_SYMBOL: unique symbol;
|
|
71
|
-
export declare function WorkflowStreamToAISDKTransformer(
|
|
72
|
+
export declare function WorkflowStreamToAISDKTransformer({ includeTextStreamParts, }?: {
|
|
73
|
+
includeTextStreamParts?: boolean;
|
|
74
|
+
}): import("stream/web").TransformStream<ChunkType, ToolAgentChunkType | ToolWorkflowChunkType | ToolNetworkChunkType | WorkflowDataPart | ChunkType | {
|
|
72
75
|
data?: string;
|
|
73
76
|
type?: "start" | "finish";
|
|
74
|
-
}
|
|
75
|
-
export declare function AgentNetworkToAISDKTransformer(): import("stream/web").TransformStream<NetworkChunkType, DataChunkType | NetworkDataPart | {
|
|
77
|
+
} | InferUIMessageChunk<UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>>>;
|
|
78
|
+
export declare function AgentNetworkToAISDKTransformer(): import("stream/web").TransformStream<NetworkChunkType, DataChunkType | NetworkDataPart | InferUIMessageChunk<UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>> | {
|
|
76
79
|
data?: string;
|
|
77
80
|
type?: "start" | "finish";
|
|
78
|
-
}
|
|
81
|
+
}>;
|
|
79
82
|
export declare function AgentStreamToAISDKTransformer<TOutput extends ZodType<any>>({ lastMessageId, sendStart, sendFinish, sendReasoning, sendSources, messageMetadata, onError, }: {
|
|
80
83
|
lastMessageId?: string;
|
|
81
84
|
sendStart?: boolean;
|
|
@@ -93,12 +96,120 @@ export declare function transformAgent<TOutput extends ZodType<any>>(payload: Ch
|
|
|
93
96
|
export declare function transformWorkflow<TOutput extends ZodType<any>>(payload: ChunkType<TOutput>, bufferedWorkflows: Map<string, {
|
|
94
97
|
name: string;
|
|
95
98
|
steps: Record<string, StepResult>;
|
|
96
|
-
}>, isNested?: boolean): (DataChunkType & {
|
|
99
|
+
}>, isNested?: boolean, includeTextStreamParts?: boolean): (DataChunkType & {
|
|
97
100
|
from: never;
|
|
98
101
|
runId: never;
|
|
99
102
|
metadata?: Record<string, any> | undefined;
|
|
100
103
|
payload: never;
|
|
101
|
-
}) | {
|
|
104
|
+
}) | ToolAgentChunkType | ToolWorkflowChunkType | ToolNetworkChunkType | {
|
|
105
|
+
type: "text-start";
|
|
106
|
+
id: string;
|
|
107
|
+
providerMetadata?: import("ai").ProviderMetadata;
|
|
108
|
+
} | {
|
|
109
|
+
type: "text-delta";
|
|
110
|
+
delta: string;
|
|
111
|
+
id: string;
|
|
112
|
+
providerMetadata?: import("ai").ProviderMetadata;
|
|
113
|
+
} | {
|
|
114
|
+
type: "text-end";
|
|
115
|
+
id: string;
|
|
116
|
+
providerMetadata?: import("ai").ProviderMetadata;
|
|
117
|
+
} | {
|
|
118
|
+
type: "reasoning-start";
|
|
119
|
+
id: string;
|
|
120
|
+
providerMetadata?: import("ai").ProviderMetadata;
|
|
121
|
+
} | {
|
|
122
|
+
type: "reasoning-delta";
|
|
123
|
+
id: string;
|
|
124
|
+
delta: string;
|
|
125
|
+
providerMetadata?: import("ai").ProviderMetadata;
|
|
126
|
+
} | {
|
|
127
|
+
type: "reasoning-end";
|
|
128
|
+
id: string;
|
|
129
|
+
providerMetadata?: import("ai").ProviderMetadata;
|
|
130
|
+
} | {
|
|
131
|
+
type: "error";
|
|
132
|
+
errorText: string;
|
|
133
|
+
} | {
|
|
134
|
+
type: "tool-input-available";
|
|
135
|
+
toolCallId: string;
|
|
136
|
+
toolName: string;
|
|
137
|
+
input: unknown;
|
|
138
|
+
providerExecuted?: boolean;
|
|
139
|
+
providerMetadata?: import("ai").ProviderMetadata;
|
|
140
|
+
dynamic?: boolean;
|
|
141
|
+
} | {
|
|
142
|
+
type: "tool-input-error";
|
|
143
|
+
toolCallId: string;
|
|
144
|
+
toolName: string;
|
|
145
|
+
input: unknown;
|
|
146
|
+
providerExecuted?: boolean;
|
|
147
|
+
providerMetadata?: import("ai").ProviderMetadata;
|
|
148
|
+
dynamic?: boolean;
|
|
149
|
+
errorText: string;
|
|
150
|
+
} | {
|
|
151
|
+
type: "tool-output-available";
|
|
152
|
+
toolCallId: string;
|
|
153
|
+
output: unknown;
|
|
154
|
+
providerExecuted?: boolean;
|
|
155
|
+
dynamic?: boolean;
|
|
156
|
+
preliminary?: boolean;
|
|
157
|
+
} | {
|
|
158
|
+
type: "tool-output-error";
|
|
159
|
+
toolCallId: string;
|
|
160
|
+
errorText: string;
|
|
161
|
+
providerExecuted?: boolean;
|
|
162
|
+
dynamic?: boolean;
|
|
163
|
+
} | {
|
|
164
|
+
type: "tool-input-start";
|
|
165
|
+
toolCallId: string;
|
|
166
|
+
toolName: string;
|
|
167
|
+
providerExecuted?: boolean;
|
|
168
|
+
dynamic?: boolean;
|
|
169
|
+
} | {
|
|
170
|
+
type: "tool-input-delta";
|
|
171
|
+
toolCallId: string;
|
|
172
|
+
inputTextDelta: string;
|
|
173
|
+
} | {
|
|
174
|
+
type: "source-url";
|
|
175
|
+
sourceId: string;
|
|
176
|
+
url: string;
|
|
177
|
+
title?: string;
|
|
178
|
+
providerMetadata?: import("ai").ProviderMetadata;
|
|
179
|
+
} | {
|
|
180
|
+
type: "source-document";
|
|
181
|
+
sourceId: string;
|
|
182
|
+
mediaType: string;
|
|
183
|
+
title: string;
|
|
184
|
+
filename?: string;
|
|
185
|
+
providerMetadata?: import("ai").ProviderMetadata;
|
|
186
|
+
} | {
|
|
187
|
+
type: "file";
|
|
188
|
+
url: string;
|
|
189
|
+
mediaType: string;
|
|
190
|
+
providerMetadata?: import("ai").ProviderMetadata;
|
|
191
|
+
} | {
|
|
192
|
+
type: "start-step";
|
|
193
|
+
} | {
|
|
194
|
+
type: "finish-step";
|
|
195
|
+
} | {
|
|
196
|
+
type: "abort";
|
|
197
|
+
} | {
|
|
198
|
+
type: `data-${string}`;
|
|
199
|
+
id?: string;
|
|
200
|
+
data: unknown;
|
|
201
|
+
transient?: boolean;
|
|
202
|
+
} | {
|
|
203
|
+
type: "start";
|
|
204
|
+
messageId?: string;
|
|
205
|
+
messageMetadata?: unknown;
|
|
206
|
+
} | {
|
|
207
|
+
type: "finish";
|
|
208
|
+
messageMetadata?: unknown;
|
|
209
|
+
} | {
|
|
210
|
+
type: "message-metadata";
|
|
211
|
+
messageMetadata: unknown;
|
|
212
|
+
} | {
|
|
102
213
|
readonly type: "data-workflow" | "data-tool-workflow";
|
|
103
214
|
readonly id: string;
|
|
104
215
|
readonly data: {
|
|
@@ -131,7 +242,7 @@ export declare function transformWorkflow<TOutput extends ZodType<any>>(payload:
|
|
|
131
242
|
};
|
|
132
243
|
readonly status: WorkflowRunStatus;
|
|
133
244
|
};
|
|
134
|
-
} | null;
|
|
245
|
+
} | null | undefined;
|
|
135
246
|
export declare function transformNetwork(payload: NetworkChunkType, bufferedNetworks: Map<string, {
|
|
136
247
|
name: string;
|
|
137
248
|
steps: (StepResult & {
|
|
@@ -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,EAA2B,SAAS,EAAE,sBAAsB,EAAE,MAAM,IAAI,CAAC;AAC1G,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;
|
|
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,EAA2B,SAAS,EAAE,sBAAsB,EAAE,MAAM,IAAI,CAAC;AAC1G,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AASjG,KAAK,oBAAoB,GAAG;IAC1B;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC;;OAEG;IACH,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC;;;;OAIG;IACH,WAAW,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AO,CAAC,EAC3B,iBAAiB,EAAE,GAAG,CACpB,MAAM,EACN;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACnC,CACF,EACD,QAAQ,CAAC,EAAE,OAAO,EAClB,sBAAsB,CAAC,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAqIjC;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,CA0VzE"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { DataChunkType, NetworkChunkType } from '@mastra/core/stream';
|
|
1
|
+
import type { ChunkType, DataChunkType, NetworkChunkType, OutputSchema } from '@mastra/core/stream';
|
|
2
2
|
export declare const isDataChunkType: (chunk: any) => chunk is DataChunkType;
|
|
3
|
+
export declare const isMastraTextStreamChunk: (chunk: any) => chunk is ChunkType<OutputSchema>;
|
|
3
4
|
export declare function safeParseErrorObject(obj: unknown): string;
|
|
4
5
|
export declare const isAgentExecutionDataChunkType: (chunk: any) => chunk is Omit<NetworkChunkType, "payload"> & {
|
|
5
6
|
payload: DataChunkType;
|
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,aAAa,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;
|
|
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,CA8BnF,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,10 +1,77 @@
|
|
|
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;
|
|
47
|
+
includeTextStreamParts?: boolean;
|
|
5
48
|
} | {
|
|
6
49
|
path: string;
|
|
7
50
|
workflow: string;
|
|
51
|
+
includeTextStreamParts?: boolean;
|
|
8
52
|
};
|
|
9
|
-
|
|
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
|
+
*/
|
|
76
|
+
export declare function workflowRoute({ path, workflow, includeTextStreamParts, }: WorkflowRouteOptions): ReturnType<typeof registerApiRoute>;
|
|
10
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
|
+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C,EAAE,KAAK,CAAC;IAAC,sBAAsB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7F;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,sBAAsB,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,IAA0C,EAC1C,QAAQ,EACR,sBAA6B,GAC9B,EAAE,oBAAoB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CA6F5D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/ai-sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.6",
|
|
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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"zod": "^3.25.76",
|
|
47
47
|
"@internal/lint": "0.0.53",
|
|
48
48
|
"@internal/types-builder": "0.0.28",
|
|
49
|
-
"@mastra/core": "1.0.0-beta.
|
|
49
|
+
"@mastra/core": "1.0.0-beta.8"
|
|
50
50
|
},
|
|
51
51
|
"keywords": [
|
|
52
52
|
"mastra",
|