@mastra/ai-sdk 1.12.1-alpha.0 → 1.12.2-alpha.0

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.
@@ -1,6 +1,6 @@
1
- import type { UIMessageStreamOptions as UIMessageStreamOptionsV5 } from './_types/@internal_ai-sdk-v5@0.0.98/dist/index.js';
2
- import type { UIMessageStreamOptions as UIMessageStreamOptionsV6 } from './_types/@internal_ai-v6@0.0.98/dist/index.js';
3
- import type { UIMessageStreamOptions as UIMessageStreamOptionsV7 } from './_types/@internal_ai-v7@0.0.98/dist/index.js';
1
+ import type { UIMessageStreamOptions as UIMessageStreamOptionsV5 } from './_types/@internal_ai-sdk-v5@0.0.99/dist/index.js';
2
+ import type { UIMessageStreamOptions as UIMessageStreamOptionsV6 } from './_types/@internal_ai-v6@0.0.99/dist/index.js';
3
+ import type { UIMessageStreamOptions as UIMessageStreamOptionsV7 } from './_types/@internal_ai-v7@0.0.99/dist/index.js';
4
4
  import type { AgentExecutionOptions } from '@mastra/core/agent';
5
5
  import type { Mastra } from '@mastra/core/mastra';
6
6
  import { registerApiRoute } from '@mastra/core/server';
@@ -136,7 +136,7 @@ export type chatRouteOptions<OUTPUT = undefined, UI_MESSAGE extends SupportedUIM
136
136
  * @param {boolean} [options.sendSources=false] - Whether to include source citations in the stream
137
137
  * @param {boolean} [options.includeSubAgentMetadata=true] - Whether to emit `data-tool-agent` / `data-tool-agent-step` parts with sub-agent progress
138
138
  * @param {number} [options.heartbeatMs] - Target interval for periodic SSE comment heartbeats. Already-buffered source events and stream lifecycle signals take priority. Values up to 0 disable heartbeats. `NaN`, positive infinity, and values above 2,147,483,647 throw a `RangeError`.
139
- * @param {(error: unknown) => string} [options.onError] - Custom error serializer streamed to the client. When omitted, errors are passed through a default serializer that strips sensitive fields (e.g. `APICallError.requestBodyValues`, which holds the system prompt) before they reach the client.
139
+ * @param {(error: unknown) => string} [options.onError] - Custom error serializer streamed to the client. When omitted, the client receives only the error `name` and `message` plus safe fields (`code`, `id`, `domain`, `category`, `statusCode`, `isRetryable`, the provider error `type`, `status` and `param`, and a redacted `cause` or nested `error`); all other properties, including `stack`, `url`, and provider request/response payloads, are dropped. Values are not sanitized, so a `message` or nested `error` string can still contain a path or URL. A custom `onError` receives the full error.
140
140
  * @param {Function} [options.messageMetadata] - Maps stream parts to metadata attached to AI SDK start and finish message parts. Receives `{ part, traceId }`.
141
141
  *
142
142
  * @returns A POST route, or `[postRoute, reconnectRoute]` when `resumable: true`
@@ -1,6 +1,6 @@
1
- import type { InferUIMessageChunk as InferUIMessageChunkV5, UIMessage as UIMessageV5, UIMessageStreamOptions as UIMessageStreamOptionsV5 } from './_types/@internal_ai-sdk-v5@0.0.98/dist/index.js';
2
- import type { UIMessage as UIMessageV6, UIMessageStreamOptions as UIMessageStreamOptionsV6 } from './_types/@internal_ai-v6@0.0.98/dist/index.js';
3
- import type { UIMessage as UIMessageV7, UIMessageStreamOptions as UIMessageStreamOptionsV7 } from './_types/@internal_ai-v7@0.0.98/dist/index.js';
1
+ import type { InferUIMessageChunk as InferUIMessageChunkV5, UIMessage as UIMessageV5, UIMessageStreamOptions as UIMessageStreamOptionsV5 } from './_types/@internal_ai-sdk-v5@0.0.99/dist/index.js';
2
+ import type { UIMessage as UIMessageV6, UIMessageStreamOptions as UIMessageStreamOptionsV6 } from './_types/@internal_ai-v6@0.0.99/dist/index.js';
3
+ import type { UIMessage as UIMessageV7, UIMessageStreamOptions as UIMessageStreamOptionsV7 } from './_types/@internal_ai-v7@0.0.99/dist/index.js';
4
4
  import type { MastraModelOutput, MastraAgentNetworkStream, WorkflowRunOutput } from '@mastra/core/stream';
5
5
  import type { MastraWorkflowStream, Step, WorkflowResult } from '@mastra/core/workflows';
6
6
  import type { ZodObject, ZodType } from 'zod/v4';
@@ -3,7 +3,7 @@ name: mastra-ai-sdk
3
3
  description: Documentation for @mastra/ai-sdk. Use when working with @mastra/ai-sdk APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/ai-sdk"
6
- version: "1.12.1-alpha.0"
6
+ version: "1.12.2-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,36 +1,36 @@
1
1
  {
2
- "version": "1.12.1-alpha.0",
2
+ "version": "1.12.2-alpha.0",
3
3
  "package": "@mastra/ai-sdk",
4
4
  "exports": {
5
5
  "assertValidHeartbeatMs": {
6
6
  "types": "dist/sse-heartbeat.d.ts",
7
7
  "implementation": "dist/index.js",
8
- "line": 11770
8
+ "line": 11794
9
9
  },
10
10
  "chatRoute": {
11
11
  "types": "dist/chat-route.d.ts",
12
12
  "implementation": "dist/index.js",
13
- "line": 12178
13
+ "line": 12218
14
14
  },
15
15
  "handleChatStream": {
16
16
  "types": "dist/chat-route.d.ts",
17
17
  "implementation": "dist/index.js",
18
- "line": 12099
18
+ "line": 12139
19
19
  },
20
20
  "handleNetworkStream": {
21
21
  "types": "dist/network-route.d.ts",
22
22
  "implementation": "dist/index.js",
23
- "line": 12573
23
+ "line": 12620
24
24
  },
25
25
  "handleWorkflowStream": {
26
26
  "types": "dist/workflow-route.d.ts",
27
27
  "implementation": "dist/index.js",
28
- "line": 12421
28
+ "line": 12468
29
29
  },
30
30
  "networkRoute": {
31
31
  "types": "dist/network-route.d.ts",
32
32
  "implementation": "dist/index.js",
33
- "line": 12644
33
+ "line": 12691
34
34
  },
35
35
  "smoothStream": {
36
36
  "types": "dist/smooth-stream.d.ts",
@@ -40,37 +40,37 @@
40
40
  "toAISdkFormat": {
41
41
  "types": "dist/to-ai-sdk-format.d.ts",
42
42
  "implementation": "dist/index.js",
43
- "line": 13498
43
+ "line": 13545
44
44
  },
45
45
  "toAISdkStream": {
46
46
  "types": "dist/convert-streams.d.ts",
47
47
  "implementation": "dist/index.js",
48
- "line": 11717
48
+ "line": 11741
49
49
  },
50
50
  "toAISdkV5Stream": {
51
51
  "types": "dist/convert-streams.d.ts",
52
52
  "implementation": "dist/index.js",
53
- "line": 11691
53
+ "line": 11715
54
54
  },
55
55
  "withMastra": {
56
56
  "types": "dist/middleware.d.ts",
57
57
  "implementation": "dist/index.js",
58
- "line": 12841
58
+ "line": 12888
59
59
  },
60
60
  "withSseHeartbeat": {
61
61
  "types": "dist/sse-heartbeat.d.ts",
62
62
  "implementation": "dist/index.js",
63
- "line": 11783
63
+ "line": 11807
64
64
  },
65
65
  "workflowRoute": {
66
66
  "types": "dist/workflow-route.d.ts",
67
67
  "implementation": "dist/index.js",
68
- "line": 12491
68
+ "line": 12538
69
69
  },
70
70
  "workflowSnapshotToStream": {
71
71
  "types": "dist/convert-snapshot.d.ts",
72
72
  "implementation": "dist/index.js",
73
- "line": 12786
73
+ "line": 12833
74
74
  }
75
75
  },
76
76
  "modules": {}
@@ -59,7 +59,7 @@ export const mastra = new Mastra({
59
59
 
60
60
  **agentVersion** (`{ versionId: string } | { status?: 'draft' | 'published' }`): Selects a specific agent version. Pass { versionId: '\<id>' } to target an exact version, or { status: 'draft' } / { status: 'published' } to resolve by status. When the route is called, query parameters ?versionId=\<id> or ?status=draft|published take precedence over this static value. Requires the Editor to be configured.
61
61
 
62
- **defaultOptions** (`AgentExecutionOptions`): Default options passed to agent execution. These can include instructions, memory configuration, maxSteps, and other execution settings.
62
+ **defaultOptions** (`NetworkOptions`): Default options passed to agent.network(). These can include memory configuration, maxSteps, modelSettings, routing, and completion settings.
63
63
 
64
64
  ## Additional configuration
65
65
 
@@ -56,7 +56,7 @@ const { text } = await generateText({
56
56
 
57
57
  **options.memory.workingMemory** (`MemoryConfig['workingMemory']`): Working memory configuration (persistent user data).
58
58
 
59
- **options.memory.readOnly** (`boolean`): Read-only mode - prevents saving new messages.
59
+ **options.memory.readOnly** (`boolean`): Accepted for compatibility but not currently applied. When lastMessages is set, new messages are still saved.
60
60
 
61
61
  ## Returns
62
62
 
@@ -55,7 +55,7 @@ export const mastra = new Mastra({
55
55
 
56
56
  **version** (`'v5' | 'v6' | 'v7'`): Selects the AI SDK stream contract to emit. Omit it or pass 'v5' for the existing default behavior. Pass 'v6' when your app is typed against AI SDK v6 response helpers. Pass 'v7' when your app is typed against AI SDK v7. (Default: `'v5'`)
57
57
 
58
- **path** (`string`): The route path (e.g., /workflow or /workflow/:workflowId). Include :workflowId for dynamic workflow routing. (Default: `'/api/workflows/:workflowId/stream'`)
58
+ **path** (`string`): The route path (e.g., /workflow or /workflow/:workflowId). Include :workflowId for dynamic workflow routing.
59
59
 
60
60
  **workflow** (`string`): Fixed workflow ID when not using dynamic routing. (Default: `undefined`)
61
61
 
@@ -916,7 +916,7 @@ const agent = await mastraClient.createStoredAgent({
916
916
 
917
917
  #### Resumable streams for stored agents
918
918
 
919
- Set `durable` to configure [resumable streams](https://mastra.ai/docs/agents/resumable-streams) on the hydrated plain agent. Pass `true` to enable streams, `false` to disable them, or an object to tune stream cleanup:
919
+ Set `durable` to configure [resumable streams](https://mastra.ai/docs/agents/resumable-streams) for the stored agent. Pass `true` to enable streams, `false` to disable them, or an object to tune stream cleanup:
920
920
 
921
921
  ```typescript
922
922
  const agent = await mastraClient.createStoredAgent({
@@ -931,7 +931,7 @@ const agent = await mastraClient.createStoredAgent({
931
931
  })
932
932
  ```
933
933
 
934
- Only serializable options are accepted, with cache and pubsub inherited from the server's `Mastra` instance. Existing stored agents with `durable: true` also use this field for resumable streams only. To retain durable execution and checkpoint recovery, register a code agent wrapped with `createDurableAgent({ agent })`.
934
+ Stored agents accept only serializable options and inherit the server's cache and PubSub settings. You can't select an execution engine through `createStoredAgent()`, but stored agents can inherit the [server's engine default](https://mastra.ai/docs/harness/durable-agents).
935
935
 
936
936
  ### `getStoredAgent()`
937
937
 
@@ -202,6 +202,8 @@ const stream = await agent.stream('message for agent')
202
202
 
203
203
  **options.tracingContext.currentSpan** (`Span`): Current span for creating child spans and adding metadata. Use this to create custom child spans or update span attributes during execution.
204
204
 
205
+ **options.disableBackgroundTasks** (`boolean`): Disables background-task dispatch for this run. Background-eligible tools run inline instead. See BackgroundTaskWorker.
206
+
205
207
  **options.tracingOptions** (`TracingOptions`): Options for Tracing configuration.
206
208
 
207
209
  **options.tracingOptions.rootSpanName** (`string`): Display name for the root span of this trace, replacing the default workflow run: '\<id>' or agent run: '\<id>' name. Use it to tell runs apart in trace lists.
package/dist/helpers.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { InferUIMessageChunk, ObjectStreamPart, TextStreamPart, ToolSet, UIMessage, FinishReason } from './_types/@internal_ai-sdk-v5@0.0.98/dist/index.js';
2
- import type { FinishReason as FinishReasonV6, InferUIMessageChunk as InferUIMessageChunkV6, ToolApprovalRequest, UIMessage as UIMessageV6 } from './_types/@internal_ai-v6@0.0.98/dist/index.js';
1
+ import type { InferUIMessageChunk, ObjectStreamPart, TextStreamPart, ToolSet, UIMessage, FinishReason } from './_types/@internal_ai-sdk-v5@0.0.99/dist/index.js';
2
+ import type { FinishReason as FinishReasonV6, InferUIMessageChunk as InferUIMessageChunkV6, ToolApprovalRequest, UIMessage as UIMessageV6 } from './_types/@internal_ai-v6@0.0.99/dist/index.js';
3
3
  import type { DataChunkType, ChunkType, MastraFinishReason } from '@mastra/core/stream';
4
4
  /**
5
5
  * Separator used to encode both runId and toolCallId into a single approvalId string.
package/dist/index.cjs CHANGED
@@ -9992,21 +9992,45 @@ const isMastraTextStreamChunk = (chunk) => {
9992
9992
  "raw"
9993
9993
  ].includes(chunk.type) || chunk.type.startsWith("background-task-"));
9994
9994
  };
9995
- const REDACTED_ERROR_FIELDS = /* @__PURE__ */ new Set([
9996
- "requestBodyValues",
9997
- "responseBody",
9998
- "responseHeaders",
9999
- "data",
10000
- "prompt"
10001
- ]);
9995
+ const SAFE_ERROR_FIELDS = [
9996
+ "name",
9997
+ "message",
9998
+ "code",
9999
+ "id",
10000
+ "domain",
10001
+ "category",
10002
+ "statusCode",
10003
+ "isRetryable",
10004
+ "type",
10005
+ "status",
10006
+ "param"
10007
+ ];
10008
+ const NESTED_ERROR_FIELDS = ["cause", "error"];
10009
+ const MAX_CAUSE_DEPTH = 3;
10010
+ function pickSafeErrorFields(error, depth) {
10011
+ const safe = {};
10012
+ for (const field of SAFE_ERROR_FIELDS) {
10013
+ const value = error[field];
10014
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") safe[field] = value;
10015
+ }
10016
+ for (const field of NESTED_ERROR_FIELDS) {
10017
+ const nested = error[field];
10018
+ if (field === "error" && typeof nested === "string") safe[field] = nested;
10019
+ else if (typeof nested === "object" && nested !== null && depth < MAX_CAUSE_DEPTH) {
10020
+ const safeNested = pickSafeErrorFields(nested, depth + 1);
10021
+ if (Object.keys(safeNested).length > 0) safe[field] = safeNested;
10022
+ }
10023
+ }
10024
+ return safe;
10025
+ }
10002
10026
  function safeParseErrorObject(obj) {
10003
10027
  if (typeof obj !== "object" || obj === null) return String(obj);
10004
10028
  try {
10005
- const stringified = JSON.stringify(obj, (key, value) => REDACTED_ERROR_FIELDS.has(key) ? void 0 : value);
10006
- if (stringified === "{}" || stringified === void 0) return String(obj);
10007
- return stringified;
10029
+ const safe = pickSafeErrorFields(obj, 0);
10030
+ if (obj instanceof Error && typeof obj.toJSON !== "function" && Object.keys(safe).every((key) => key === "name" || key === "message")) return `${obj.name}: ${obj.message}`;
10031
+ return Object.keys(safe).length > 0 ? JSON.stringify(safe) : "Unknown error";
10008
10032
  } catch {
10009
- return String(obj);
10033
+ return "Unknown error";
10010
10034
  }
10011
10035
  }
10012
10036
  const isAgentExecutionDataChunkType = (chunk) => {
@@ -12021,6 +12045,22 @@ function resolveAgentVersionFromQuery(query, fallback) {
12021
12045
  if (status && status !== "draft" && status !== "published") throw new Error("Query parameter \"status\" must be \"draft\" or \"published\"");
12022
12046
  return versionId ? { versionId } : status ? { status } : fallback;
12023
12047
  }
12048
+ const MEMORY_RESOURCE_REQUIRED_MESSAGE = "A resource ID is required when using memory. Provide memory.resource in the request body, or configure server auth with mapUserToResourceId to derive it from the authenticated user.";
12049
+ /**
12050
+ * The agent resolves the resource ID itself (request context, memory.resource, agent defaults)
12051
+ * and fails with AGENT_MEMORY_MISSING_RESOURCE_ID when memory is on but none resolves. Matching that
12052
+ * error keeps chatRoute's check identical to the agent's. The agent wraps it in AGENT_STREAM_FAILED,
12053
+ * and the original arrives as a deserialized cause carrying `code`, so walk the cause chain.
12054
+ * A missing thread with a resource present is a different problem and is left alone.
12055
+ */
12056
+ function isMissingMemoryResourceError(error) {
12057
+ for (let current = error, depth = 0; current && depth < 5; depth++) {
12058
+ const { id, code, details, cause } = current;
12059
+ if (id === "AGENT_MEMORY_MISSING_RESOURCE_ID" || code === "AGENT_MEMORY_MISSING_RESOURCE_ID") return !details?.resourceId && !!details?.threadId;
12060
+ current = cause;
12061
+ }
12062
+ return false;
12063
+ }
12024
12064
  /** Wraps a UI message stream in the response implementation for its AI SDK version. */
12025
12065
  function createChatUIMessageStreamResponse(stream, version) {
12026
12066
  if (version === "v7") return createUIMessageStreamResponse({ stream });
@@ -12337,18 +12377,25 @@ function chatRoute({ path = "/chat/:agentId", agent, defaultOptions, experimenta
12337
12377
  includeSubAgentMetadata,
12338
12378
  onError
12339
12379
  };
12340
- return withSseHeartbeat(createChatUIMessageStreamResponse(version === "v7" ? await handleChatStream({
12341
- ...handlerOptions,
12342
- version: "v7",
12343
- messageMetadata
12344
- }) : version === "v6" ? await handleChatStream({
12345
- ...handlerOptions,
12346
- version: "v6",
12347
- messageMetadata
12348
- }) : await handleChatStream({
12349
- ...handlerOptions,
12350
- messageMetadata
12351
- }), version), heartbeatMs);
12380
+ let uiMessageStream;
12381
+ try {
12382
+ uiMessageStream = version === "v7" ? await handleChatStream({
12383
+ ...handlerOptions,
12384
+ version: "v7",
12385
+ messageMetadata
12386
+ }) : version === "v6" ? await handleChatStream({
12387
+ ...handlerOptions,
12388
+ version: "v6",
12389
+ messageMetadata
12390
+ }) : await handleChatStream({
12391
+ ...handlerOptions,
12392
+ messageMetadata
12393
+ });
12394
+ } catch (error) {
12395
+ if (isMissingMemoryResourceError(error)) return c.json({ error: MEMORY_RESOURCE_REQUIRED_MESSAGE }, 400);
12396
+ throw error;
12397
+ }
12398
+ return withSseHeartbeat(createChatUIMessageStreamResponse(uiMessageStream, version), heartbeatMs);
12352
12399
  }
12353
12400
  });
12354
12401
  if (!resumable) return postRoute;
package/dist/index.js CHANGED
@@ -9969,21 +9969,45 @@ const isMastraTextStreamChunk = (chunk) => {
9969
9969
  "raw"
9970
9970
  ].includes(chunk.type) || chunk.type.startsWith("background-task-"));
9971
9971
  };
9972
- const REDACTED_ERROR_FIELDS = /* @__PURE__ */ new Set([
9973
- "requestBodyValues",
9974
- "responseBody",
9975
- "responseHeaders",
9976
- "data",
9977
- "prompt"
9978
- ]);
9972
+ const SAFE_ERROR_FIELDS = [
9973
+ "name",
9974
+ "message",
9975
+ "code",
9976
+ "id",
9977
+ "domain",
9978
+ "category",
9979
+ "statusCode",
9980
+ "isRetryable",
9981
+ "type",
9982
+ "status",
9983
+ "param"
9984
+ ];
9985
+ const NESTED_ERROR_FIELDS = ["cause", "error"];
9986
+ const MAX_CAUSE_DEPTH = 3;
9987
+ function pickSafeErrorFields(error, depth) {
9988
+ const safe = {};
9989
+ for (const field of SAFE_ERROR_FIELDS) {
9990
+ const value = error[field];
9991
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") safe[field] = value;
9992
+ }
9993
+ for (const field of NESTED_ERROR_FIELDS) {
9994
+ const nested = error[field];
9995
+ if (field === "error" && typeof nested === "string") safe[field] = nested;
9996
+ else if (typeof nested === "object" && nested !== null && depth < MAX_CAUSE_DEPTH) {
9997
+ const safeNested = pickSafeErrorFields(nested, depth + 1);
9998
+ if (Object.keys(safeNested).length > 0) safe[field] = safeNested;
9999
+ }
10000
+ }
10001
+ return safe;
10002
+ }
9979
10003
  function safeParseErrorObject(obj) {
9980
10004
  if (typeof obj !== "object" || obj === null) return String(obj);
9981
10005
  try {
9982
- const stringified = JSON.stringify(obj, (key, value) => REDACTED_ERROR_FIELDS.has(key) ? void 0 : value);
9983
- if (stringified === "{}" || stringified === void 0) return String(obj);
9984
- return stringified;
10006
+ const safe = pickSafeErrorFields(obj, 0);
10007
+ if (obj instanceof Error && typeof obj.toJSON !== "function" && Object.keys(safe).every((key) => key === "name" || key === "message")) return `${obj.name}: ${obj.message}`;
10008
+ return Object.keys(safe).length > 0 ? JSON.stringify(safe) : "Unknown error";
9985
10009
  } catch {
9986
- return String(obj);
10010
+ return "Unknown error";
9987
10011
  }
9988
10012
  }
9989
10013
  const isAgentExecutionDataChunkType = (chunk) => {
@@ -11998,6 +12022,22 @@ function resolveAgentVersionFromQuery(query, fallback) {
11998
12022
  if (status && status !== "draft" && status !== "published") throw new Error("Query parameter \"status\" must be \"draft\" or \"published\"");
11999
12023
  return versionId ? { versionId } : status ? { status } : fallback;
12000
12024
  }
12025
+ const MEMORY_RESOURCE_REQUIRED_MESSAGE = "A resource ID is required when using memory. Provide memory.resource in the request body, or configure server auth with mapUserToResourceId to derive it from the authenticated user.";
12026
+ /**
12027
+ * The agent resolves the resource ID itself (request context, memory.resource, agent defaults)
12028
+ * and fails with AGENT_MEMORY_MISSING_RESOURCE_ID when memory is on but none resolves. Matching that
12029
+ * error keeps chatRoute's check identical to the agent's. The agent wraps it in AGENT_STREAM_FAILED,
12030
+ * and the original arrives as a deserialized cause carrying `code`, so walk the cause chain.
12031
+ * A missing thread with a resource present is a different problem and is left alone.
12032
+ */
12033
+ function isMissingMemoryResourceError(error) {
12034
+ for (let current = error, depth = 0; current && depth < 5; depth++) {
12035
+ const { id, code, details, cause } = current;
12036
+ if (id === "AGENT_MEMORY_MISSING_RESOURCE_ID" || code === "AGENT_MEMORY_MISSING_RESOURCE_ID") return !details?.resourceId && !!details?.threadId;
12037
+ current = cause;
12038
+ }
12039
+ return false;
12040
+ }
12001
12041
  /** Wraps a UI message stream in the response implementation for its AI SDK version. */
12002
12042
  function createChatUIMessageStreamResponse(stream, version) {
12003
12043
  if (version === "v7") return createUIMessageStreamResponse({ stream });
@@ -12314,18 +12354,25 @@ function chatRoute({ path = "/chat/:agentId", agent, defaultOptions, experimenta
12314
12354
  includeSubAgentMetadata,
12315
12355
  onError
12316
12356
  };
12317
- return withSseHeartbeat(createChatUIMessageStreamResponse(version === "v7" ? await handleChatStream({
12318
- ...handlerOptions,
12319
- version: "v7",
12320
- messageMetadata
12321
- }) : version === "v6" ? await handleChatStream({
12322
- ...handlerOptions,
12323
- version: "v6",
12324
- messageMetadata
12325
- }) : await handleChatStream({
12326
- ...handlerOptions,
12327
- messageMetadata
12328
- }), version), heartbeatMs);
12357
+ let uiMessageStream;
12358
+ try {
12359
+ uiMessageStream = version === "v7" ? await handleChatStream({
12360
+ ...handlerOptions,
12361
+ version: "v7",
12362
+ messageMetadata
12363
+ }) : version === "v6" ? await handleChatStream({
12364
+ ...handlerOptions,
12365
+ version: "v6",
12366
+ messageMetadata
12367
+ }) : await handleChatStream({
12368
+ ...handlerOptions,
12369
+ messageMetadata
12370
+ });
12371
+ } catch (error) {
12372
+ if (isMissingMemoryResourceError(error)) return c.json({ error: MEMORY_RESOURCE_REQUIRED_MESSAGE }, 400);
12373
+ throw error;
12374
+ }
12375
+ return withSseHeartbeat(createChatUIMessageStreamResponse(uiMessageStream, version), heartbeatMs);
12329
12376
  }
12330
12377
  });
12331
12378
  if (!resumable) return postRoute;
@@ -1,5 +1,5 @@
1
1
  import type { LanguageModelV2, LanguageModelV2Middleware } from './_types/@ai-sdk_provider@2.0.5/dist/index.js';
2
- import type { LanguageModelV3 } from './_types/@internal_ai-v6@0.0.98/dist/index.js';
2
+ import type { LanguageModelV3 } from './_types/@internal_ai-v6@0.0.99/dist/index.js';
3
3
  import type { MemoryConfig, SemanticRecall as SemanticRecallConfig } from '@mastra/core/memory';
4
4
  import type { InputProcessor, OutputProcessor } from '@mastra/core/processors';
5
5
  import type { MemoryStorage } from '@mastra/core/storage';
@@ -1,6 +1,6 @@
1
- import type { InferUIMessageChunk as InferUIMessageChunkV5, UIMessage as UIMessageV5 } from './_types/@internal_ai-sdk-v5@0.0.98/dist/index.js';
2
- import type { InferUIMessageChunk as InferUIMessageChunkV6, UIMessage as UIMessageV6 } from './_types/@internal_ai-v6@0.0.98/dist/index.js';
3
- import type { InferUIMessageChunk as InferUIMessageChunkV7, UIMessage as UIMessageV7 } from './_types/@internal_ai-v7@0.0.98/dist/index.js';
1
+ import type { InferUIMessageChunk as InferUIMessageChunkV5, UIMessage as UIMessageV5 } from './_types/@internal_ai-sdk-v5@0.0.99/dist/index.js';
2
+ import type { InferUIMessageChunk as InferUIMessageChunkV6, UIMessage as UIMessageV6 } from './_types/@internal_ai-v6@0.0.99/dist/index.js';
3
+ import type { InferUIMessageChunk as InferUIMessageChunkV7, UIMessage as UIMessageV7 } from './_types/@internal_ai-v7@0.0.99/dist/index.js';
4
4
  /**
5
5
  * Adds the run's `traceId` to the options an AI SDK `messageMetadata` callback receives, so the callback can put it
6
6
  * in message metadata (e.g. `({ part, traceId }) => (part.type === 'start' ? { traceId } : undefined)`).
@@ -1,6 +1,6 @@
1
1
  import { TransformStream } from 'node:stream/web';
2
- import type { InferUIMessageChunk, UIMessage, UIMessageStreamOptions } from './_types/@internal_ai-sdk-v5@0.0.98/dist/index.js';
3
- import type { InferUIMessageChunk as InferUIMessageChunkV6, UIMessage as UIMessageV6, UIMessageStreamOptions as UIMessageStreamOptionsV6 } from './_types/@internal_ai-v6@0.0.98/dist/index.js';
2
+ import type { InferUIMessageChunk, UIMessage, UIMessageStreamOptions } from './_types/@internal_ai-sdk-v5@0.0.99/dist/index.js';
3
+ import type { InferUIMessageChunk as InferUIMessageChunkV6, UIMessage as UIMessageV6, UIMessageStreamOptions as UIMessageStreamOptionsV6 } from './_types/@internal_ai-v6@0.0.99/dist/index.js';
4
4
  import type { LLMStepResult } from '@mastra/core/agent';
5
5
  import type { ChunkType, DataChunkType, NetworkChunkType } from '@mastra/core/stream';
6
6
  import type { WorkflowRunStatus, WorkflowStepStatus } from '@mastra/core/workflows';
@@ -164,7 +164,7 @@ export declare function WorkflowStreamToAISDKTransformer({ includeTextStreamPart
164
164
  }): TransformStream<ChunkType<any>, ToolAgentChunkType | ToolNetworkChunkType | ToolWorkflowChunkType | WorkflowDataPart | WorkflowStepDataPart | {
165
165
  data?: string;
166
166
  type?: 'start' | 'finish';
167
- } | ChunkType | InferUIMessageChunk<UIMessage<unknown, import("./_types/@internal_ai-sdk-v5@0.0.98/dist/index.js").UIDataTypes, import("./_types/@internal_ai-sdk-v5@0.0.98/dist/index.js").UITools>>>;
167
+ } | ChunkType | InferUIMessageChunk<UIMessage<unknown, import("./_types/@internal_ai-sdk-v5@0.0.99/dist/index.js").UIDataTypes, import("./_types/@internal_ai-sdk-v5@0.0.99/dist/index.js").UITools>>>;
168
168
  export declare function WorkflowStreamToAISDKV6Transformer({ includeTextStreamParts, sendReasoning, sendSources, }?: {
169
169
  includeTextStreamParts?: boolean;
170
170
  sendReasoning?: boolean;
@@ -172,7 +172,7 @@ export declare function WorkflowStreamToAISDKV6Transformer({ includeTextStreamPa
172
172
  }): TransformStream<ChunkType<any>, ToolAgentChunkType | ToolNetworkChunkType | ToolWorkflowChunkType | WorkflowDataPart | WorkflowStepDataPart | {
173
173
  data?: string;
174
174
  type?: 'start' | 'finish';
175
- } | ChunkType | InferUIMessageChunkV6<UIMessageV6<unknown, import("./_types/@internal_ai-v6@0.0.98/dist/index.js").UIDataTypes, import("./_types/@internal_ai-v6@0.0.98/dist/index.js").UITools>>>;
175
+ } | ChunkType | InferUIMessageChunkV6<UIMessageV6<unknown, import("./_types/@internal_ai-v6@0.0.99/dist/index.js").UIDataTypes, import("./_types/@internal_ai-v6@0.0.99/dist/index.js").UITools>>>;
176
176
  export declare function createAgentNetworkToAISDKTransformer<UI_CHUNK>(): TransformStream<NetworkChunkType, UI_CHUNK | DataChunkType | NetworkDataPart | {
177
177
  data?: string;
178
178
  type?: 'start' | 'finish';
@@ -180,11 +180,11 @@ export declare function createAgentNetworkToAISDKTransformer<UI_CHUNK>(): Transf
180
180
  export declare function AgentNetworkToAISDKTransformer(): TransformStream<NetworkChunkType, DataChunkType | NetworkDataPart | {
181
181
  data?: string;
182
182
  type?: 'start' | 'finish';
183
- } | InferUIMessageChunk<UIMessage<unknown, import("./_types/@internal_ai-sdk-v5@0.0.98/dist/index.js").UIDataTypes, import("./_types/@internal_ai-sdk-v5@0.0.98/dist/index.js").UITools>>>;
183
+ } | InferUIMessageChunk<UIMessage<unknown, import("./_types/@internal_ai-sdk-v5@0.0.99/dist/index.js").UIDataTypes, import("./_types/@internal_ai-sdk-v5@0.0.99/dist/index.js").UITools>>>;
184
184
  export declare function AgentNetworkToAISDKV6Transformer(): TransformStream<NetworkChunkType, DataChunkType | NetworkDataPart | {
185
185
  data?: string;
186
186
  type?: 'start' | 'finish';
187
- } | InferUIMessageChunkV6<UIMessageV6<unknown, import("./_types/@internal_ai-v6@0.0.98/dist/index.js").UIDataTypes, import("./_types/@internal_ai-v6@0.0.98/dist/index.js").UITools>>>;
187
+ } | InferUIMessageChunkV6<UIMessageV6<unknown, import("./_types/@internal_ai-v6@0.0.99/dist/index.js").UIDataTypes, import("./_types/@internal_ai-v6@0.0.99/dist/index.js").UITools>>>;
188
188
  export declare function createAgentStreamToAISDKTransformer<OUTPUT>(convertMastraChunkToAISDK: ConvertMastraChunkToAISDK, { lastMessageId, sendStart, sendFinish, sendReasoning, sendSources, messageMetadata, onError, includeSubAgentMetadata, }: {
189
189
  lastMessageId?: string;
190
190
  sendStart?: boolean;
@@ -222,7 +222,7 @@ export declare function transformAgent<OUTPUT>(payload: ChunkType<OUTPUT>, buffe
222
222
  export declare function transformWorkflow<OUTPUT>(payload: ChunkType<OUTPUT>, bufferedWorkflows: Map<string, BufferedWorkflowState>, isNested?: boolean, includeTextStreamParts?: boolean, streamOptions?: {
223
223
  sendReasoning?: boolean;
224
224
  sendSources?: boolean;
225
- }, convertMastraChunkToAISDK?: ConvertMastraChunkToAISDK): (ToolAgentChunkType | ToolNetworkChunkType | ToolWorkflowChunkType | InferUIMessageChunk<UIMessage<unknown, import("./_types/@internal_ai-sdk-v5@0.0.98/dist/index.js").UIDataTypes, import("./_types/@internal_ai-sdk-v5@0.0.98/dist/index.js").UITools>> | InferUIMessageChunkV6<UIMessageV6<unknown, import("./_types/@internal_ai-v6@0.0.98/dist/index.js").UIDataTypes, import("./_types/@internal_ai-v6@0.0.98/dist/index.js").UITools>> | undefined)[] | DataChunkType | ToolAgentChunkType | ToolNetworkChunkType | ToolWorkflowChunkType | WorkflowDataPart | {
225
+ }, convertMastraChunkToAISDK?: ConvertMastraChunkToAISDK): (ToolAgentChunkType | ToolNetworkChunkType | ToolWorkflowChunkType | InferUIMessageChunk<UIMessage<unknown, import("./_types/@internal_ai-sdk-v5@0.0.99/dist/index.js").UIDataTypes, import("./_types/@internal_ai-sdk-v5@0.0.99/dist/index.js").UITools>> | InferUIMessageChunkV6<UIMessageV6<unknown, import("./_types/@internal_ai-v6@0.0.99/dist/index.js").UIDataTypes, import("./_types/@internal_ai-v6@0.0.99/dist/index.js").UITools>> | undefined)[] | DataChunkType | ToolAgentChunkType | ToolNetworkChunkType | ToolWorkflowChunkType | WorkflowDataPart | {
226
226
  type: `data-${string}`;
227
227
  id?: string;
228
228
  data: unknown;
@@ -236,7 +236,7 @@ export declare function transformWorkflow<OUTPUT>(payload: ChunkType<OUTPUT>, bu
236
236
  toolName: string;
237
237
  input: unknown;
238
238
  providerExecuted?: boolean;
239
- providerMetadata?: import("./_types/@internal_ai-sdk-v5@0.0.98/dist/index.js").ProviderMetadata;
239
+ providerMetadata?: import("./_types/@internal_ai-sdk-v5@0.0.99/dist/index.js").ProviderMetadata;
240
240
  dynamic?: boolean;
241
241
  } | {
242
242
  type: 'tool-input-error';
@@ -244,7 +244,7 @@ export declare function transformWorkflow<OUTPUT>(payload: ChunkType<OUTPUT>, bu
244
244
  toolName: string;
245
245
  input: unknown;
246
246
  providerExecuted?: boolean;
247
- providerMetadata?: import("./_types/@internal_ai-sdk-v5@0.0.98/dist/index.js").ProviderMetadata;
247
+ providerMetadata?: import("./_types/@internal_ai-sdk-v5@0.0.99/dist/index.js").ProviderMetadata;
248
248
  dynamic?: boolean;
249
249
  errorText: string;
250
250
  } | {
@@ -280,7 +280,7 @@ export declare function transformWorkflow<OUTPUT>(payload: ChunkType<OUTPUT>, bu
280
280
  messageMetadata?: unknown;
281
281
  } | {
282
282
  type: 'finish';
283
- finishReason?: import("./_types/@internal_ai-sdk-v5@0.0.98/dist/index.js").FinishReason;
283
+ finishReason?: import("./_types/@internal_ai-sdk-v5@0.0.99/dist/index.js").FinishReason;
284
284
  messageMetadata?: unknown;
285
285
  } | {
286
286
  type: 'abort';
@@ -290,37 +290,37 @@ export declare function transformWorkflow<OUTPUT>(payload: ChunkType<OUTPUT>, bu
290
290
  } | {
291
291
  type: 'text-start';
292
292
  id: string;
293
- providerMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").ProviderMetadata;
293
+ providerMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").ProviderMetadata;
294
294
  } | {
295
295
  type: 'text-delta';
296
296
  delta: string;
297
297
  id: string;
298
- providerMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").ProviderMetadata;
298
+ providerMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").ProviderMetadata;
299
299
  } | {
300
300
  type: 'text-end';
301
301
  id: string;
302
- providerMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").ProviderMetadata;
302
+ providerMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").ProviderMetadata;
303
303
  } | {
304
304
  type: 'reasoning-start';
305
305
  id: string;
306
- providerMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").ProviderMetadata;
306
+ providerMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").ProviderMetadata;
307
307
  } | {
308
308
  type: 'reasoning-delta';
309
309
  id: string;
310
310
  delta: string;
311
- providerMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").ProviderMetadata;
311
+ providerMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").ProviderMetadata;
312
312
  } | {
313
313
  type: 'reasoning-end';
314
314
  id: string;
315
- providerMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").ProviderMetadata;
315
+ providerMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").ProviderMetadata;
316
316
  } | {
317
317
  type: 'tool-input-available';
318
318
  toolCallId: string;
319
319
  toolName: string;
320
320
  input: unknown;
321
321
  providerExecuted?: boolean;
322
- providerMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").ProviderMetadata;
323
- toolMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").JSONObject;
322
+ providerMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").ProviderMetadata;
323
+ toolMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").JSONObject;
324
324
  dynamic?: boolean;
325
325
  title?: string;
326
326
  } | {
@@ -329,8 +329,8 @@ export declare function transformWorkflow<OUTPUT>(payload: ChunkType<OUTPUT>, bu
329
329
  toolName: string;
330
330
  input: unknown;
331
331
  providerExecuted?: boolean;
332
- providerMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").ProviderMetadata;
333
- toolMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").JSONObject;
332
+ providerMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").ProviderMetadata;
333
+ toolMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").JSONObject;
334
334
  dynamic?: boolean;
335
335
  errorText: string;
336
336
  title?: string;
@@ -349,19 +349,19 @@ export declare function transformWorkflow<OUTPUT>(payload: ChunkType<OUTPUT>, bu
349
349
  sourceId: string;
350
350
  url: string;
351
351
  title?: string;
352
- providerMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").ProviderMetadata;
352
+ providerMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").ProviderMetadata;
353
353
  } | {
354
354
  type: 'source-document';
355
355
  sourceId: string;
356
356
  mediaType: string;
357
357
  title: string;
358
358
  filename?: string;
359
- providerMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").ProviderMetadata;
359
+ providerMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").ProviderMetadata;
360
360
  } | {
361
361
  type: 'file';
362
362
  url: string;
363
363
  mediaType: string;
364
- providerMetadata?: import("./_types/@internal_ai-v6@0.0.98/dist/index.js").ProviderMetadata;
364
+ providerMetadata?: import("./_types/@internal_ai-v6@0.0.99/dist/index.js").ProviderMetadata;
365
365
  } | readonly [WorkflowDataPart, WorkflowStepDataPart] | null | undefined;
366
366
  type TransformNetworkResult = InferUIMessageChunk<UIMessage> | NetworkDataPart | DataChunkType | WorkflowStepDataPart;
367
367
  export declare function transformNetwork(payload: NetworkChunkType, bufferedNetworks: Map<string, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/ai-sdk",
3
- "version": "1.12.1-alpha.0",
3
+ "version": "1.12.2-alpha.0",
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",
@@ -48,17 +48,17 @@
48
48
  "typescript": "^7.0.2",
49
49
  "vitest": "5.1.0",
50
50
  "zod": "^4.6.7",
51
- "@internal/ai-sdk-v4": "0.0.98",
52
- "@internal/ai-sdk-v5": "0.0.98",
53
- "@internal/ai-v6": "0.0.98",
54
- "@internal/ai-v7": "0.0.98",
55
- "@internal/lint": "0.0.151",
56
- "@internal/llm-recorder": "0.0.87",
57
- "@internal/test-utils": "0.0.87",
58
- "@internal/types-builder": "0.0.126",
59
- "@mastra/core": "1.86.0-alpha.6",
60
- "@mastra/libsql": "1.32.0-alpha.0",
61
- "@mastra/memory": "1.41.3-alpha.2"
51
+ "@internal/ai-sdk-v4": "0.0.99",
52
+ "@internal/ai-sdk-v5": "0.0.99",
53
+ "@internal/ai-v6": "0.0.99",
54
+ "@internal/ai-v7": "0.0.99",
55
+ "@internal/lint": "0.0.152",
56
+ "@internal/llm-recorder": "0.0.88",
57
+ "@internal/test-utils": "0.0.88",
58
+ "@internal/types-builder": "0.0.127",
59
+ "@mastra/core": "1.87.0-alpha.0",
60
+ "@mastra/libsql": "1.33.0-alpha.0",
61
+ "@mastra/memory": "1.41.3"
62
62
  },
63
63
  "keywords": [
64
64
  "mastra",