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

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.
@@ -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`
@@ -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"
6
+ version: "1.12.2-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,36 +1,36 @@
1
1
  {
2
- "version": "1.12.1",
2
+ "version": "1.12.2-alpha.1",
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": {}
@@ -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/index.cjs CHANGED
@@ -3283,7 +3283,7 @@ function createUIMessageStream$2({ execute, onError = () => "An error occurred."
3283
3283
  getOutcome: () => outcome
3284
3284
  });
3285
3285
  }
3286
- // ../../packages/_vendored/ai_v6/dist/dist-BoOIE3nE.js
3286
+ // ../../packages/_vendored/ai_v6/dist/dist-BHXUQYEB.js
3287
3287
  var marker$1$2 = "vercel.ai.error";
3288
3288
  var symbol$1$2 = Symbol.for(marker$1$2);
3289
3289
  var _a$1;
@@ -4398,7 +4398,7 @@ function standardSchema$1(standardSchema2) {
4398
4398
  return addAdditionalPropertiesToJsonSchema$1(standardSchema2["~standard"].jsonSchema.input({ target: "draft-07" }));
4399
4399
  }, { validate: async (value) => {
4400
4400
  const result = await standardSchema2["~standard"].validate(value);
4401
- return "value" in result ? {
4401
+ return result.issues === void 0 && "value" in result ? {
4402
4402
  success: true,
4403
4403
  value: result.value
4404
4404
  } : {
@@ -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
@@ -3260,7 +3260,7 @@ function createUIMessageStream$2({ execute, onError = () => "An error occurred."
3260
3260
  getOutcome: () => outcome
3261
3261
  });
3262
3262
  }
3263
- // ../../packages/_vendored/ai_v6/dist/dist-BoOIE3nE.js
3263
+ // ../../packages/_vendored/ai_v6/dist/dist-BHXUQYEB.js
3264
3264
  var marker$1$2 = "vercel.ai.error";
3265
3265
  var symbol$1$2 = Symbol.for(marker$1$2);
3266
3266
  var _a$1;
@@ -4375,7 +4375,7 @@ function standardSchema$1(standardSchema2) {
4375
4375
  return addAdditionalPropertiesToJsonSchema$1(standardSchema2["~standard"].jsonSchema.input({ target: "draft-07" }));
4376
4376
  }, { validate: async (value) => {
4377
4377
  const result = await standardSchema2["~standard"].validate(value);
4378
- return "value" in result ? {
4378
+ return result.issues === void 0 && "value" in result ? {
4379
4379
  success: true,
4380
4380
  value: result.value
4381
4381
  } : {
@@ -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;
package/dist/ui.cjs CHANGED
@@ -4,8 +4,32 @@ let _mastra_core_agent_message_list = require("@mastra/core/agent/message-list")
4
4
  function isSystemReminderUIMessage(message) {
5
5
  if (message.metadata?.systemReminder || message.metadata?.dynamicAgentsMdReminder) return true;
6
6
  if (message.role !== "user") return false;
7
- if (Array.isArray(message.parts)) return message.parts.some((part) => part.type === "text" && typeof part.text === "string" && part.text.includes("<system-reminder"));
8
- return typeof message.content === "string" && message.content.includes("<system-reminder");
7
+ if (Array.isArray(message.parts)) return isSystemReminderElement(message.parts.find((part) => part.type === "text")?.text);
8
+ return isSystemReminderElement(message.content);
9
+ }
10
+ const SYSTEM_REMINDER_OPEN = "<system-reminder";
11
+ const SYSTEM_REMINDER_ATTRIBUTE = / ([A-Za-z_][A-Za-z0-9_.-]*)="(?:[^"<>&]|&(?:amp|lt|gt|quot);)*"/y;
12
+ const SYSTEM_REMINDER_SELF_CLOSE = " />";
13
+ const SYSTEM_REMINDER_CLOSE = "</system-reminder>";
14
+ const SYSTEM_REMINDER_CLOSING_TAG = /<\/system-reminder\s*>/i;
15
+ function isSystemReminderElement(text) {
16
+ if (typeof text !== "string") return false;
17
+ const trimmed = text.trim();
18
+ if (!trimmed.startsWith(SYSTEM_REMINDER_OPEN)) return false;
19
+ const names = /* @__PURE__ */ new Set();
20
+ let index = 16;
21
+ for (;;) {
22
+ SYSTEM_REMINDER_ATTRIBUTE.lastIndex = index;
23
+ const attribute = SYSTEM_REMINDER_ATTRIBUTE.exec(trimmed);
24
+ if (!attribute) break;
25
+ if (names.has(attribute[1])) return false;
26
+ names.add(attribute[1]);
27
+ index = SYSTEM_REMINDER_ATTRIBUTE.lastIndex;
28
+ }
29
+ if (trimmed.startsWith(SYSTEM_REMINDER_SELF_CLOSE, index)) return index + 3 === trimmed.length;
30
+ if (trimmed[index] !== ">") return false;
31
+ const body = trimmed.slice(index + 1, -18);
32
+ return body.length > 0 && trimmed.endsWith(SYSTEM_REMINDER_CLOSE) && !SYSTEM_REMINDER_CLOSING_TAG.test(body);
9
33
  }
10
34
  function filterSystemReminderUIMessages(messages) {
11
35
  return messages.filter((message) => !isSystemReminderUIMessage(message));
package/dist/ui.js CHANGED
@@ -3,8 +3,32 @@ import { MessageList } from "@mastra/core/agent/message-list";
3
3
  function isSystemReminderUIMessage(message) {
4
4
  if (message.metadata?.systemReminder || message.metadata?.dynamicAgentsMdReminder) return true;
5
5
  if (message.role !== "user") return false;
6
- if (Array.isArray(message.parts)) return message.parts.some((part) => part.type === "text" && typeof part.text === "string" && part.text.includes("<system-reminder"));
7
- return typeof message.content === "string" && message.content.includes("<system-reminder");
6
+ if (Array.isArray(message.parts)) return isSystemReminderElement(message.parts.find((part) => part.type === "text")?.text);
7
+ return isSystemReminderElement(message.content);
8
+ }
9
+ const SYSTEM_REMINDER_OPEN = "<system-reminder";
10
+ const SYSTEM_REMINDER_ATTRIBUTE = / ([A-Za-z_][A-Za-z0-9_.-]*)="(?:[^"<>&]|&(?:amp|lt|gt|quot);)*"/y;
11
+ const SYSTEM_REMINDER_SELF_CLOSE = " />";
12
+ const SYSTEM_REMINDER_CLOSE = "</system-reminder>";
13
+ const SYSTEM_REMINDER_CLOSING_TAG = /<\/system-reminder\s*>/i;
14
+ function isSystemReminderElement(text) {
15
+ if (typeof text !== "string") return false;
16
+ const trimmed = text.trim();
17
+ if (!trimmed.startsWith(SYSTEM_REMINDER_OPEN)) return false;
18
+ const names = /* @__PURE__ */ new Set();
19
+ let index = 16;
20
+ for (;;) {
21
+ SYSTEM_REMINDER_ATTRIBUTE.lastIndex = index;
22
+ const attribute = SYSTEM_REMINDER_ATTRIBUTE.exec(trimmed);
23
+ if (!attribute) break;
24
+ if (names.has(attribute[1])) return false;
25
+ names.add(attribute[1]);
26
+ index = SYSTEM_REMINDER_ATTRIBUTE.lastIndex;
27
+ }
28
+ if (trimmed.startsWith(SYSTEM_REMINDER_SELF_CLOSE, index)) return index + 3 === trimmed.length;
29
+ if (trimmed[index] !== ">") return false;
30
+ const body = trimmed.slice(index + 1, -18);
31
+ return body.length > 0 && trimmed.endsWith(SYSTEM_REMINDER_CLOSE) && !SYSTEM_REMINDER_CLOSING_TAG.test(body);
8
32
  }
9
33
  function filterSystemReminderUIMessages(messages) {
10
34
  return messages.filter((message) => !isSystemReminderUIMessage(message));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/ai-sdk",
3
- "version": "1.12.1",
3
+ "version": "1.12.2-alpha.1",
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,16 +48,16 @@
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.99",
52
- "@internal/ai-v7": "0.0.99",
53
51
  "@internal/ai-sdk-v5": "0.0.99",
52
+ "@internal/ai-v7": "0.0.99",
54
53
  "@internal/lint": "0.0.152",
55
- "@internal/test-utils": "0.0.88",
56
- "@mastra/core": "1.86.0",
57
54
  "@internal/ai-v6": "0.0.99",
58
- "@internal/types-builder": "0.0.127",
59
- "@mastra/libsql": "1.32.0",
55
+ "@internal/ai-sdk-v4": "0.0.99",
60
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.2",
60
+ "@mastra/libsql": "1.33.0-alpha.0",
61
61
  "@mastra/memory": "1.41.3"
62
62
  },
63
63
  "keywords": [