@mastra/ai-sdk 1.6.2-alpha.2 → 1.6.3-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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @mastra/ai-sdk
2
2
 
3
+ ## 1.6.3-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed the AI SDK v6 native approval flow in handleChatStream so approval responses are collected across all assistant messages instead of only the final message. Approving a tool call now resumes its exact run and tool call, multiple approval responses in one request resume sequentially in a single framed response stream, and already-resolved responses from history are safely skipped instead of executing again. ([#19528](https://github.com/mastra-ai/mastra/pull/19528))
8
+
9
+ - Updated dependencies [[`1426af2`](https://github.com/mastra-ai/mastra/commit/1426af24975879c000d13ac75673f630fcc970c1), [`975295d`](https://github.com/mastra-ai/mastra/commit/975295d418552f0d46a59edfef4c3ee555f9930a), [`85e4fb5`](https://github.com/mastra-ai/mastra/commit/85e4fb50087a81c74df3a762f53b56373db0b912), [`ef03c0c`](https://github.com/mastra-ai/mastra/commit/ef03c0cfc62367a458e4cc56462e2148b35681c5), [`4fb4d88`](https://github.com/mastra-ai/mastra/commit/4fb4d881bc107acee13890ad4d78661016c510ed), [`4eba27a`](https://github.com/mastra-ai/mastra/commit/4eba27adcf60f991df0e62f94b3e75b4e67f3b4b), [`c701be3`](https://github.com/mastra-ai/mastra/commit/c701be32d7d9aa94a66da8c6cc38dcac6856f464)]:
10
+ - @mastra/core@1.52.0-alpha.3
11
+
12
+ ## 1.6.2
13
+
14
+ ### Patch Changes
15
+
16
+ - Fixed AI SDK v6 native tool approvals resuming the wrong tool call. When multiple tool calls were awaiting approval, approving one could execute a different one. The approval response now carries the answered tool call's ID through to the resume, so the approved tool call is the one that runs. ([#19266](https://github.com/mastra-ai/mastra/pull/19266))
17
+
18
+ - Fixed a crash in the AI SDK stream transformer when a supervisor agent delegates to a remote A2A agent (A2AAgent) through chatRoute() or handleChatStream. A2A sub-agent streams do not emit a start chunk and use a flat finish payload, which caused the UI stream to end with "Cannot read properties of undefined" errors. The remote agent's answer now streams to the client correctly. ([#19443](https://github.com/mastra-ai/mastra/pull/19443))
19
+
20
+ The same guard now also covers resumed sub-agent streams, which skip the start chunk as well and could crash or corrupt the delegation state on tool calls and structured output.
21
+
22
+ - Fixed background task chunks being dropped from AI SDK UI streams. ([#18628](https://github.com/mastra-ai/mastra/pull/18628))
23
+
24
+ - Updated dependencies [[`bd6d240`](https://github.com/mastra-ai/mastra/commit/bd6d2402db93dddaef0721667e7e8a030e7c6e16), [`0111486`](https://github.com/mastra-ai/mastra/commit/01114867612593eef5cfa2fda6a1194dfedda841), [`96a3749`](https://github.com/mastra-ai/mastra/commit/96a37492235f5b8076b3e3177d83ed5a5e44a640), [`fe1bda0`](https://github.com/mastra-ai/mastra/commit/fe1bda06f6af92a694a51712db747cda1e7185f0), [`25e7c12`](https://github.com/mastra-ai/mastra/commit/25e7c126a770069ae7fb7ecf1d2adb40e017b009), [`1ce5121`](https://github.com/mastra-ai/mastra/commit/1ce512155d122bb21f47d98383e82ffbf84b39e8), [`fb8aea3`](https://github.com/mastra-ai/mastra/commit/fb8aea384291e77311be3a64ee1717320d5c3c73), [`4adc391`](https://github.com/mastra-ai/mastra/commit/4adc3911075249c352bb4832d2471922826344de), [`a5c6337`](https://github.com/mastra-ai/mastra/commit/a5c6337d23c7686c81a32ce62f550f610543a240), [`3cfc47a`](https://github.com/mastra-ai/mastra/commit/3cfc47a6b89940aadd0f46fb01ae9624a73a865d), [`2bb7817`](https://github.com/mastra-ai/mastra/commit/2bb78176112fde628483de2830528f7eee911e56), [`51d9870`](https://github.com/mastra-ai/mastra/commit/51d987032c689c2855374d0f244f5d654da809d1), [`5cab274`](https://github.com/mastra-ai/mastra/commit/5cab2744250e22d12fefa7b32637dce224233cee), [`7fa27d3`](https://github.com/mastra-ai/mastra/commit/7fa27d3b6f5ed68cd34e454a4d3ad9c482a0cfbc), [`8b97958`](https://github.com/mastra-ai/mastra/commit/8b979589f9aa59ba67cac565949475f2ffeb4ac3), [`8410541`](https://github.com/mastra-ai/mastra/commit/84105412c60ecd3bb33a9838146f59c4b588228f), [`a58dcbb`](https://github.com/mastra-ai/mastra/commit/a58dcbb546d7e1d65ebdc1f39e55f0908fcd9391), [`aa38805`](https://github.com/mastra-ai/mastra/commit/aa38805b878b827403be785eb90688d7172f5a40), [`153bd3b`](https://github.com/mastra-ai/mastra/commit/153bd3b396bdfed6b74cf43de12db8fd2d83c04a), [`45a8e65`](https://github.com/mastra-ai/mastra/commit/45a8e65e1556d1362cb3f25187023c36de26661d), [`e955965`](https://github.com/mastra-ai/mastra/commit/e955965dce575a903e37cf054d28ea99aa48785e), [`2d22570`](https://github.com/mastra-ai/mastra/commit/2d22570c7dfdd02123d0ecc529efb05ccba2d9fc), [`07bb863`](https://github.com/mastra-ai/mastra/commit/07bb8631919c6f7cf377dccd45b096e0f17fbed0), [`c8ed116`](https://github.com/mastra-ai/mastra/commit/c8ed11699f62bcac70102ab4ec84d80d20541da6), [`01b338c`](https://github.com/mastra-ai/mastra/commit/01b338c56271f0219606710e3e8b26dee27ac6c2), [`a99eae8`](https://github.com/mastra-ai/mastra/commit/a99eae8908e500c1b2d12f9d277be616b98617a5), [`860ef7e`](https://github.com/mastra-ai/mastra/commit/860ef7e77d92b63469cbe5857aa1e626197e43e9), [`17e818c`](https://github.com/mastra-ai/mastra/commit/17e818c51a958ba90641b1a959dc38faf8c034e9), [`edce8d2`](https://github.com/mastra-ai/mastra/commit/edce8d2769f19e27a05737c627af2d765472a4f8), [`8a586ec`](https://github.com/mastra-ai/mastra/commit/8a586eca9a4914f31dff6140d0d45ac375b00669), [`4451dfe`](https://github.com/mastra-ai/mastra/commit/4451dfe857428e7abcc0261a507a2e186dae6d47), [`8b7361d`](https://github.com/mastra-ai/mastra/commit/8b7361d35de68b80d05d30a74e0c69e7218fd612), [`1d39058`](https://github.com/mastra-ai/mastra/commit/1d39058e548efd691799985d5c8af2737f1c3bd2), [`3927473`](https://github.com/mastra-ai/mastra/commit/392747323ddb10c643d12be7b9ae913159dfaeed), [`dce50dc`](https://github.com/mastra-ai/mastra/commit/dce50dc9a1c1fcd0f427bb5f6250ec74910cb04b), [`fd13f8e`](https://github.com/mastra-ai/mastra/commit/fd13f8e21990f9904c3eedba3a626bb4a929cdb8), [`634caff`](https://github.com/mastra-ai/mastra/commit/634caff29a9200ad058b67d53f96d9e5832fb8a2), [`f703f87`](https://github.com/mastra-ai/mastra/commit/f703f878de072d51fda557f9c50867d8252bef05), [`3e26c87`](https://github.com/mastra-ai/mastra/commit/3e26c87de0c5bc2583b795ce6ca5889b6b161acb), [`33f2b88`](https://github.com/mastra-ai/mastra/commit/33f2b88842c09a567f906fac4cb61cd5277ced59), [`177010f`](https://github.com/mastra-ai/mastra/commit/177010ff096d2e4b28d89803be5b1a4cad2a0d6b), [`0ad646f`](https://github.com/mastra-ai/mastra/commit/0ad646f71a530f2454664299e5e01bfd13fa12e5), [`b486abf`](https://github.com/mastra-ai/mastra/commit/b486abfa2a7528c6f527e4015c819ea9fa54aaad), [`54a51e0`](https://github.com/mastra-ai/mastra/commit/54a51e0a484fe1ebad3fb1f7ef5282a075709eb7), [`c43f3a9`](https://github.com/mastra-ai/mastra/commit/c43f3a9d1efde99b38789364ba4d0ba670f430e3), [`a5008f2`](https://github.com/mastra-ai/mastra/commit/a5008f22ae710ad9402ea9f2547d8c02f74d384b), [`e2d5f37`](https://github.com/mastra-ai/mastra/commit/e2d5f373bd289be534d5f8694d34465010533df6), [`4ce0163`](https://github.com/mastra-ai/mastra/commit/4ce0163dc86e675a86809685c8ce6c49f1aeb87e), [`4378341`](https://github.com/mastra-ai/mastra/commit/43783412df5ea3dd35f5b1f6e4851e79c346fc89)]:
25
+ - @mastra/core@1.51.0
26
+
3
27
  ## 1.6.2-alpha.2
4
28
 
5
29
  ### Patch Changes
@@ -4,25 +4,17 @@ import type { AgentExecutionOptions } from '@mastra/core/agent';
4
4
  import type { Mastra } from '@mastra/core/mastra';
5
5
  import { registerApiRoute } from '@mastra/core/server';
6
6
  import type { SupportedUIMessage, V5UIMessage, V5UIMessageStream, V6UIMessage, V6UIMessageStream } from './public-types.js';
7
- /**
8
- * Scans a v6 UIMessage array for the most recent 'approval-responded' tool
9
- * part in the last trailing assistant message only. When found, splits the
10
- * composite approvalId ("${runId}::${toolCallId}") to recover the runId and
11
- * toolCallId needed for a targeted resumeStream.
12
- *
13
- * Only the last trailing assistant message is inspected so that approval
14
- * responses from earlier turns are never re-processed. Within that message,
15
- * parts are scanned in reverse so the decision the user just acted on wins
16
- * over any earlier 'approval-responded' parts that have not yet transitioned
17
- * to 'output-available'.
18
- *
19
- * Returns null when no approval response is present (normal chat turn).
20
- */
21
- export declare function extractV6NativeApproval(messages: V6UIMessage[]): {
7
+ export interface V6NativeApprovalResponse {
22
8
  resumeData: Record<string, unknown>;
23
9
  runId: string;
24
10
  toolCallId: string;
25
- } | null;
11
+ }
12
+ /**
13
+ * Collects every approval response across all assistant messages in a v6
14
+ * request. Responses are deduplicated by their composite run/tool-call target,
15
+ * with the most recent part winning when history contains repeated copies.
16
+ */
17
+ export declare function extractV6NativeApprovals(messages: V6UIMessage[]): V6NativeApprovalResponse[];
26
18
  export type ChatStreamHandlerParams<UI_MESSAGE extends SupportedUIMessage = SupportedUIMessage, OUTPUT = undefined> = AgentExecutionOptions<OUTPUT> & {
27
19
  messages: UI_MESSAGE[];
28
20
  resumeData?: Record<string, any>;
@@ -1 +1 @@
1
- {"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAM9F,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,KAAK,EAAE,qBAAqB,EAA6B,MAAM,oBAAoB,CAAC;AAC3F,OAAO,KAAK,EAAE,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Ac,EACd,YAAY,EACZ,SAAgB,EAChB,UAAiB,EACjB,aAAqB,EACrB,WAAmB,EACnB,OAAO,GACR,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAmNhE"}
package/dist/index.cjs CHANGED
@@ -31,7 +31,7 @@ function _interopNamespace(e) {
31
31
 
32
32
  var z4__namespace = /*#__PURE__*/_interopNamespace(z4);
33
33
 
34
- // ../../packages/_vendored/ai_v5/dist/chunk-ZMFCHGXT.js
34
+ // ../../packages/_vendored/ai_v5/dist/chunk-G6L5YOWM.js
35
35
  var marker = "vercel.ai.error";
36
36
  var symbol = Symbol.for(marker);
37
37
  var _a;
@@ -11610,28 +11610,95 @@ function toAISdkStream(stream, options = {
11610
11610
  }
11611
11611
 
11612
11612
  // src/chat-route.ts
11613
- function extractV6NativeApproval(messages) {
11614
- const lastAssistantMsg = messages.at(-1);
11615
- if (!lastAssistantMsg || lastAssistantMsg.role !== "assistant") return null;
11616
- const parts = lastAssistantMsg.parts ?? [];
11617
- for (let i = parts.length - 1; i >= 0; i--) {
11618
- const part = parts[i];
11619
- if (!isToolUIPart2(part) || part.state !== "approval-responded") continue;
11620
- const lastSep = part.approval.id.lastIndexOf(APPROVAL_ID_SEPARATOR);
11621
- if (lastSep === -1) continue;
11622
- const runId = part.approval.id.slice(0, lastSep);
11623
- const toolCallId = part.approval.id.slice(lastSep + APPROVAL_ID_SEPARATOR.length);
11624
- if (!runId || !toolCallId) continue;
11625
- return {
11626
- resumeData: {
11627
- approved: part.approval.approved,
11628
- ...part.approval.reason != null ? { reason: part.approval.reason } : {}
11629
- },
11630
- runId,
11631
- toolCallId
11632
- };
11613
+ function extractV6NativeApprovals(messages) {
11614
+ const byTarget = /* @__PURE__ */ new Map();
11615
+ const separator = APPROVAL_ID_SEPARATOR;
11616
+ for (const message of messages) {
11617
+ if (message.role !== "assistant") continue;
11618
+ for (const part of message.parts ?? []) {
11619
+ if (!isToolUIPart2(part) || part.state !== "approval-responded") continue;
11620
+ const lastSep = part.approval.id.lastIndexOf(separator);
11621
+ if (lastSep === -1) continue;
11622
+ const runId = part.approval.id.slice(0, lastSep);
11623
+ const toolCallId = part.approval.id.slice(lastSep + separator.length);
11624
+ if (!runId || !toolCallId) continue;
11625
+ if (toolCallId !== part.toolCallId) continue;
11626
+ byTarget.set(`${runId}${separator}${toolCallId}`, {
11627
+ resumeData: {
11628
+ approved: part.approval.approved,
11629
+ ...part.approval.reason != null ? { reason: part.approval.reason } : {}
11630
+ },
11631
+ runId,
11632
+ toolCallId
11633
+ });
11634
+ }
11633
11635
  }
11634
- return null;
11636
+ return [...byTarget.values()];
11637
+ }
11638
+ function streamV6ApprovalResumes(args) {
11639
+ const { agent, approvals, baseOptions, structuredOutput, messages, lastMessageId } = args;
11640
+ const { sendStart, sendFinish, sendReasoning, sendSources, onError, messageMetadata } = args;
11641
+ return createUIMessageStream2({
11642
+ originalMessages: messages,
11643
+ onError,
11644
+ execute: async ({ writer }) => {
11645
+ let startWritten = false;
11646
+ let successfulLegs = 0;
11647
+ let firstResolvedTargetError;
11648
+ let finalFinish;
11649
+ for (const approval of approvals) {
11650
+ try {
11651
+ const result = await agent.resumeStream(approval.resumeData, {
11652
+ ...baseOptions,
11653
+ runId: approval.runId,
11654
+ toolCallId: approval.toolCallId,
11655
+ ...structuredOutput ? { structuredOutput } : {}
11656
+ });
11657
+ for await (const part of toAISdkStream(result, {
11658
+ from: "agent",
11659
+ version: "v6",
11660
+ lastMessageId,
11661
+ sendStart,
11662
+ sendFinish,
11663
+ sendReasoning,
11664
+ sendSources,
11665
+ onError,
11666
+ messageMetadata
11667
+ })) {
11668
+ if (part.type === "start") {
11669
+ if (startWritten) continue;
11670
+ startWritten = true;
11671
+ writer.write(part);
11672
+ continue;
11673
+ }
11674
+ if (!startWritten && sendStart) {
11675
+ writer.write({ type: "start", ...lastMessageId ? { messageId: lastMessageId } : {} });
11676
+ startWritten = true;
11677
+ }
11678
+ if (part.type === "finish") {
11679
+ finalFinish = part;
11680
+ continue;
11681
+ }
11682
+ writer.write(part);
11683
+ }
11684
+ successfulLegs++;
11685
+ } catch (error) {
11686
+ const id = error?.id;
11687
+ if (id !== "AGENT_RESUME_TOOL_CALL_NOT_SUSPENDED" && id !== "AGENT_RESUME_NO_SNAPSHOT_FOUND") {
11688
+ throw error;
11689
+ }
11690
+ firstResolvedTargetError ??= error;
11691
+ }
11692
+ }
11693
+ if (successfulLegs === 0 && firstResolvedTargetError) throw firstResolvedTargetError;
11694
+ if (!startWritten && sendStart) {
11695
+ writer.write({ type: "start", ...lastMessageId ? { messageId: lastMessageId } : {} });
11696
+ }
11697
+ if (sendFinish) {
11698
+ writer.write(finalFinish ?? { type: "finish" });
11699
+ }
11700
+ }
11701
+ });
11635
11702
  }
11636
11703
  async function handleChatStream({
11637
11704
  mastra,
@@ -11669,9 +11736,6 @@ async function handleChatStream({
11669
11736
  if (!Array.isArray(messages)) {
11670
11737
  throw new Error("Messages must be an array of UIMessage objects");
11671
11738
  }
11672
- const nativeApproval = version === "v6" && !resumeData ? extractV6NativeApproval(messages) : null;
11673
- const effectiveResumeData = nativeApproval?.resumeData ?? resumeData;
11674
- const effectiveRunId = nativeApproval?.runId ?? runId;
11675
11739
  let lastMessageId;
11676
11740
  let messagesToSend = messages;
11677
11741
  if (messages.length > 0) {
@@ -11693,12 +11757,30 @@ async function handleChatStream({
11693
11757
  const baseOptions = {
11694
11758
  ...defaultOptionsRest,
11695
11759
  ...restOptions,
11696
- ...effectiveRunId && { runId: effectiveRunId },
11697
- ...nativeApproval?.toolCallId && { toolCallId: nativeApproval.toolCallId },
11760
+ ...runId && { runId },
11698
11761
  requestContext: requestContext || defaultOptions3?.requestContext,
11699
11762
  ...Object.keys(mergedProviderOptions).length > 0 && { providerOptions: mergedProviderOptions }
11700
11763
  };
11701
- const result = effectiveResumeData ? structuredOutput ? await agentObj.resumeStream(effectiveResumeData, { ...baseOptions, structuredOutput }) : await agentObj.resumeStream(effectiveResumeData, baseOptions) : structuredOutput ? await agentObj.stream(messagesToSend, { ...baseOptions, structuredOutput }) : await agentObj.stream(messagesToSend, baseOptions);
11764
+ if (version === "v6" && !resumeData && trigger !== "regenerate-message" && messages.at(-1)?.role === "assistant") {
11765
+ const approvals = extractV6NativeApprovals(messages);
11766
+ if (approvals.length > 0) {
11767
+ return streamV6ApprovalResumes({
11768
+ agent: agentObj,
11769
+ approvals,
11770
+ baseOptions,
11771
+ structuredOutput,
11772
+ messages,
11773
+ lastMessageId,
11774
+ sendStart,
11775
+ sendFinish,
11776
+ sendReasoning,
11777
+ sendSources,
11778
+ onError,
11779
+ messageMetadata
11780
+ });
11781
+ }
11782
+ }
11783
+ const result = resumeData ? structuredOutput ? await agentObj.resumeStream(resumeData, { ...baseOptions, structuredOutput }) : await agentObj.resumeStream(resumeData, baseOptions) : structuredOutput ? await agentObj.stream(messagesToSend, { ...baseOptions, structuredOutput }) : await agentObj.stream(messagesToSend, baseOptions);
11702
11784
  if (version === "v6") {
11703
11785
  return createUIMessageStream2({
11704
11786
  originalMessages: messages,