@mastra/ai-sdk 1.0.0-beta.0 → 1.0.0-beta.10
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 +325 -0
- package/README.md +60 -0
- package/dist/__tests__/__fixtures__/network.stream.d.ts +2329 -0
- package/dist/__tests__/__fixtures__/network.stream.d.ts.map +1 -0
- package/dist/_types/@ai-sdk_provider/dist/index.d.ts +1719 -0
- package/dist/chat-route.d.ts +90 -3
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/chunk-DES3K4SD.cjs +17 -0
- package/dist/chunk-DES3K4SD.cjs.map +1 -0
- package/dist/chunk-KYQEM4AK.js +294 -0
- package/dist/chunk-KYQEM4AK.js.map +1 -0
- package/dist/chunk-TD7TJ4N5.cjs +297 -0
- package/dist/chunk-TD7TJ4N5.cjs.map +1 -0
- package/dist/chunk-VUNV25KB.js +14 -0
- package/dist/chunk-VUNV25KB.js.map +1 -0
- package/dist/convert-messages.d.ts +83 -3
- package/dist/convert-messages.d.ts.map +1 -1
- package/dist/convert-streams.d.ts +64 -1
- package/dist/convert-streams.d.ts.map +1 -1
- package/dist/helpers.d.ts +9 -3
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +3872 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3848 -117
- 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/token-5ZTQBFQ6.cjs +63 -0
- package/dist/token-5ZTQBFQ6.cjs.map +1 -0
- package/dist/token-UOO4N54I.js +61 -0
- package/dist/token-UOO4N54I.js.map +1 -0
- package/dist/token-util-DUN56AZR.cjs +9 -0
- package/dist/token-util-DUN56AZR.cjs.map +1 -0
- package/dist/token-util-JCUK3SCT.js +7 -0
- package/dist/token-util-JCUK3SCT.js.map +1 -0
- package/dist/transformers.d.ts +136 -10
- package/dist/transformers.d.ts.map +1 -1
- package/dist/ui.cjs +0 -1
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.js +0 -1
- package/dist/ui.js.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 +9 -7
package/dist/ui.js
CHANGED
package/dist/ui.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/convert-messages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/convert-messages.ts"],"names":[],"mappings":";;AA4CO,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;AA+CO,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 from various input formats to AI SDK V5 UI message format.\n *\n * This function accepts messages in multiple formats (strings, AI SDK V4/V5 messages, Mastra DB messages, etc.) and normalizes them to the AI SDK V5 UIMessage format, which is suitable for use with AI SDK V5 UI components like `useChat()`.\n *\n * @param messages - Messages to convert. Accepts:\n * - `string` - A single text message (treated as user role)\n * - `string[]` - Multiple text messages\n * - `MessageInput` - A single message object in any supported format:\n * - AI SDK V5 UIMessage or ModelMessage\n * - AI SDK V4 UIMessage or CoreMessage\n * - MastraDBMessage (internal storage format)\n * - MastraMessageV1 (legacy format)\n * - `MessageInput[]` - Array of message objects\n *\n * @returns An array of AI SDK V5 UIMessage objects with:\n * - `id` - Unique message identifier\n * - `role` - 'user' | 'assistant' | 'system'\n * - `parts` - Array of UI parts (text, tool results, files, reasoning, etc.)\n * - `metadata` - Optional metadata including createdAt, threadId, resourceId\n *\n * @example\n * ```typescript\n * import { toAISdkV5Messages } from '@mastra/ai-sdk';\n *\n * // Convert simple text messages\n * const messages = toAISdkV5Messages(['Hello', 'How can I help?']);\n *\n * // Convert AI SDK V4 messages to V5 format\n * const v4Messages = [\n * { id: '1', role: 'user', content: 'Hello', parts: [{ type: 'text', text: 'Hello' }] },\n * { id: '2', role: 'assistant', content: 'Hi!', parts: [{ type: 'text', text: 'Hi!' }] }\n * ];\n * const v5Messages = toAISdkV5Messages(v4Messages);\n *\n * // Use with useChat or similar AI SDK V5 hooks\n * const { messages: chatMessages } = useChat({\n * initialMessages: toAISdkV5Messages(storedMessages)\n * });\n * ```\n */\nexport function toAISdkV5Messages(messages: MessageListInput) {\n return new MessageList().add(messages, `memory`).get.all.aiV5.ui();\n}\n\n/**\n * Converts messages from various input formats to AI SDK V4 UI message format.\n *\n * This function accepts messages in multiple formats (strings, AI SDK V4/V5 messages, Mastra DB messages, etc.) and normalizes them to the AI SDK V4 UIMessage format, which is suitable for use with AI SDK V4 UI components.\n *\n * @param messages - Messages to convert. Accepts:\n * - `string` - A single text message (treated as user role)\n * - `string[]` - Multiple text messages\n * - `MessageInput` - A single message object in any supported format:\n * - AI SDK V5 UIMessage or ModelMessage\n * - AI SDK V4 UIMessage or CoreMessage\n * - MastraDBMessage (internal storage format)\n * - MastraMessageV1 (legacy format)\n * - `MessageInput[]` - Array of message objects\n *\n * @returns An array of AI SDK V4 UIMessage objects with:\n * - `id` - Unique message identifier\n * - `role` - 'user' | 'assistant' | 'system'\n * - `content` - Text content of the message\n * - `parts` - Array of UI parts (text, tool-invocation, file, reasoning, etc.)\n * - `createdAt` - Message creation timestamp\n * - `toolInvocations` - Optional array of tool invocations (for assistant messages)\n * - `experimental_attachments` - Optional file attachments\n * - `metadata` - Optional custom metadata\n *\n * @example\n * ```typescript\n * import { toAISdkV4Messages } from '@mastra/ai-sdk';\n *\n * // Convert simple text messages\n * const messages = toAISdkV4Messages(['Hello', 'How can I help?']);\n *\n * // Convert AI SDK V5 messages to V4 format for legacy compatibility\n * const v5Messages = [\n * { id: '1', role: 'user', parts: [{ type: 'text', text: 'Hello' }] },\n * { id: '2', role: 'assistant', parts: [{ type: 'text', text: 'Hi!' }] }\n * ];\n * const v4Messages = toAISdkV4Messages(v5Messages);\n *\n * // Use with AI SDK V4 useChat hook\n * const { messages: chatMessages } = useChat({\n * initialMessages: toAISdkV4Messages(storedMessages)\n * });\n * ```\n */\nexport function toAISdkV4Messages(messages: MessageListInput) {\n return new MessageList().add(messages, `memory`).get.all.aiV4.ui();\n}\n"]}
|
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,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,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
|
+
{"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;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EA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+
"version": "1.0.0-beta.10",
|
|
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",
|
|
@@ -36,15 +36,20 @@
|
|
|
36
36
|
"zod": "^3.25.0 || ^4.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
+
"@ai-sdk/provider": "^2.0.0",
|
|
39
40
|
"@types/json-schema": "^7.0.15",
|
|
41
|
+
"@vitest/coverage-v8": "4.0.12",
|
|
42
|
+
"@vitest/ui": "4.0.12",
|
|
43
|
+
"ai": "^5.0.60",
|
|
40
44
|
"eslint": "^9.37.0",
|
|
41
45
|
"tsup": "^8.5.0",
|
|
42
46
|
"typescript": "^5.8.3",
|
|
43
|
-
"vitest": "
|
|
47
|
+
"vitest": "4.0.12",
|
|
44
48
|
"zod": "^3.25.76",
|
|
45
49
|
"@internal/lint": "0.0.53",
|
|
46
|
-
"@
|
|
47
|
-
"@mastra/
|
|
50
|
+
"@mastra/core": "1.0.0-beta.14",
|
|
51
|
+
"@mastra/libsql": "1.0.0-beta.8",
|
|
52
|
+
"@internal/types-builder": "0.0.28"
|
|
48
53
|
},
|
|
49
54
|
"keywords": [
|
|
50
55
|
"mastra",
|
|
@@ -61,9 +66,6 @@
|
|
|
61
66
|
"bugs": {
|
|
62
67
|
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
63
68
|
},
|
|
64
|
-
"dependencies": {
|
|
65
|
-
"ai": "^5.0.60"
|
|
66
|
-
},
|
|
67
69
|
"engines": {
|
|
68
70
|
"node": ">=22.13.0"
|
|
69
71
|
},
|