@mastra/ai-sdk 1.5.0 → 1.5.1-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.
package/dist/index.js CHANGED
@@ -5,11 +5,12 @@ import { z as z$1 } from 'zod';
5
5
  import { registerApiRoute } from '@mastra/core/server';
6
6
  import { TransformStream as TransformStream$1, ReadableStream as ReadableStream$1 } from 'stream/web';
7
7
  import { convertFullStreamChunkToMastra, DefaultGeneratedFile, DefaultGeneratedFileWithType } from '@mastra/core/stream';
8
+ import { MASTRA_RESOURCE_ID_KEY } from '@mastra/core/request-context';
8
9
  import { TripWire, MessageList, aiV5ModelMessageToV2PromptMessage } from '@mastra/core/agent';
9
10
  import { RequestContext } from '@mastra/core/di';
10
11
  import { WorkingMemory, MessageHistory, SemanticRecall } from '@mastra/core/processors';
11
12
 
12
- // ../../packages/_vendored/ai_v5/dist/chunk-OMTTDYJT.js
13
+ // ../../packages/_vendored/ai_v5/dist/chunk-I2JBSJEA.js
13
14
  var marker = "vercel.ai.error";
14
15
  var symbol = Symbol.for(marker);
15
16
  var _a;
@@ -12028,13 +12029,14 @@ var isMastraTextStreamChunk = (chunk) => {
12028
12029
  "raw"
12029
12030
  ].includes(chunk.type);
12030
12031
  };
12032
+ var REDACTED_ERROR_FIELDS = /* @__PURE__ */ new Set(["requestBodyValues", "responseBody", "responseHeaders", "data", "prompt"]);
12031
12033
  function safeParseErrorObject(obj) {
12032
12034
  if (typeof obj !== "object" || obj === null) {
12033
12035
  return String(obj);
12034
12036
  }
12035
12037
  try {
12036
- const stringified = JSON.stringify(obj);
12037
- if (stringified === "{}") {
12038
+ const stringified = JSON.stringify(obj, (key, value) => REDACTED_ERROR_FIELDS.has(key) ? void 0 : value);
12039
+ if (stringified === "{}" || stringified === void 0) {
12038
12040
  return String(obj);
12039
12041
  }
12040
12042
  return stringified;
@@ -13981,7 +13983,8 @@ function chatRoute({
13981
13983
  sendStart = true,
13982
13984
  sendFinish = true,
13983
13985
  sendReasoning = false,
13984
- sendSources = false
13986
+ sendSources = false,
13987
+ onError
13985
13988
  }) {
13986
13989
  if (!agent && !path.includes("/:agentId")) {
13987
13990
  throw new Error("Path must include :agentId to route to the correct agent or pass the agent explicitly");
@@ -14150,7 +14153,8 @@ function chatRoute({
14150
14153
  sendStart,
14151
14154
  sendFinish,
14152
14155
  sendReasoning,
14153
- sendSources
14156
+ sendSources,
14157
+ onError
14154
14158
  };
14155
14159
  if (version === "v6") {
14156
14160
  const uiMessageStream2 = await handleChatStream({
@@ -14173,7 +14177,17 @@ async function handleWorkflowStream({
14173
14177
  sendReasoning = false,
14174
14178
  sendSources = false
14175
14179
  }) {
14176
- const { runId, resourceId, inputData, initialState, resumeData, requestContext, ...rest } = params;
14180
+ const {
14181
+ runId,
14182
+ resourceId: resourceIdFromParams,
14183
+ inputData,
14184
+ initialState,
14185
+ resumeData,
14186
+ requestContext,
14187
+ ...rest
14188
+ } = params;
14189
+ const resourceIdFromContext = requestContext?.get(MASTRA_RESOURCE_ID_KEY);
14190
+ const resourceId = resourceIdFromContext ?? resourceIdFromParams;
14177
14191
  const workflowObj = mastra.getWorkflowById(workflowId);
14178
14192
  if (!workflowObj) {
14179
14193
  throw new Error(`Workflow ${workflowId} not found`);