@mastra/ai-sdk 1.9.0 → 1.9.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.
package/dist/index.js CHANGED
@@ -13962,6 +13962,7 @@ async function handleChatStream({ mastra, agentId, agentVersion, params, default
13962
13962
  * @param {boolean} [options.sendSources=false] - Whether to include source citations in the stream
13963
13963
  * @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`.
13964
13964
  * @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.
13965
+ * @param {Function} [options.messageMetadata] - Maps stream parts to metadata attached to AI SDK start and finish message parts.
13965
13966
  *
13966
13967
  * @returns {ReturnType<typeof registerApiRoute>} A registered API route handler
13967
13968
  *
@@ -13993,7 +13994,7 @@ async function handleChatStream({ mastra, agentId, agentVersion, params, default
13993
13994
  * - If both `agent` and `:agentId` are present, a warning is logged and the fixed `agent` takes precedence
13994
13995
  * - Request context from the incoming request overrides `defaultOptions.requestContext` if both are present
13995
13996
  */
13996
- function chatRoute({ path = "/chat/:agentId", agent, defaultOptions, experimentalTransform, version = "v5", agentVersion, sendStart = true, sendFinish = true, sendReasoning = false, sendSources = false, heartbeatMs, onError }) {
13997
+ function chatRoute({ path = "/chat/:agentId", agent, defaultOptions, experimentalTransform, version = "v5", agentVersion, sendStart = true, sendFinish = true, sendReasoning = false, sendSources = false, heartbeatMs, onError, messageMetadata }) {
13997
13998
  if (!agent && !path.includes("/:agentId")) throw new Error("Path must include :agentId to route to the correct agent or pass the agent explicitly");
13998
13999
  assertValidHeartbeatMs(heartbeatMs);
13999
14000
  return registerApiRoute(path, {
@@ -14127,13 +14128,18 @@ function chatRoute({ path = "/chat/:agentId", agent, defaultOptions, experimenta
14127
14128
  let response;
14128
14129
  if (version === "v7") response = createUIMessageStreamResponse({ stream: await handleChatStream({
14129
14130
  ...handlerOptions,
14130
- version: "v7"
14131
+ version: "v7",
14132
+ messageMetadata
14131
14133
  }) });
14132
14134
  else if (version === "v6") response = createUIMessageStreamResponse$1({ stream: await handleChatStream({
14133
14135
  ...handlerOptions,
14134
- version: "v6"
14136
+ version: "v6",
14137
+ messageMetadata
14138
+ }) });
14139
+ else response = createUIMessageStreamResponse$2({ stream: await handleChatStream({
14140
+ ...handlerOptions,
14141
+ messageMetadata
14135
14142
  }) });
14136
- else response = createUIMessageStreamResponse$2({ stream: await handleChatStream(handlerOptions) });
14137
14143
  return withSseHeartbeat(response, heartbeatMs);
14138
14144
  }
14139
14145
  });