@mastra/ai-sdk 1.0.0-beta.7 → 1.0.0-beta.8

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,31 @@
1
1
  # @mastra/ai-sdk
2
2
 
3
+ ## 1.0.0-beta.8
4
+
5
+ ### Patch Changes
6
+
7
+ - Support new Workflow tripwire run status. Tripwires that are thrown from within a workflow will now bubble up and return a graceful state with information about tripwires. ([#10947](https://github.com/mastra-ai/mastra/pull/10947))
8
+
9
+ When a workflow contains an agent step that triggers a tripwire, the workflow returns with `status: 'tripwire'` and includes tripwire details:
10
+
11
+ ```typescript showLineNumbers copy
12
+ const run = await workflow.createRun();
13
+ const result = await run.start({ inputData: { message: 'Hello' } });
14
+
15
+ if (result.status === 'tripwire') {
16
+ console.log('Workflow terminated by tripwire:', result.tripwire?.reason);
17
+ console.log('Processor ID:', result.tripwire?.processorId);
18
+ console.log('Retry requested:', result.tripwire?.retry);
19
+ }
20
+ ```
21
+
22
+ Adds new UI state for tripwire in agent chat and workflow UI.
23
+
24
+ This is distinct from `status: 'failed'` which indicates an unexpected error. A tripwire status means a processor intentionally stopped execution (e.g., for content moderation).
25
+
26
+ - Updated dependencies [[`38380b6`](https://github.com/mastra-ai/mastra/commit/38380b60fca905824bdf6b43df307a58efb1aa15), [`798d0c7`](https://github.com/mastra-ai/mastra/commit/798d0c740232653b1d754870e6b43a55c364ffe2), [`ffe84d5`](https://github.com/mastra-ai/mastra/commit/ffe84d54f3b0f85167fe977efd027dba027eb998), [`2c212e7`](https://github.com/mastra-ai/mastra/commit/2c212e704c90e2db83d4109e62c03f0f6ebd2667), [`4ca4306`](https://github.com/mastra-ai/mastra/commit/4ca430614daa5fa04730205a302a43bf4accfe9f), [`3bf6c5f`](https://github.com/mastra-ai/mastra/commit/3bf6c5f104c25226cd84e0c77f9dec15f2cac2db)]:
27
+ - @mastra/core@1.0.0-beta.11
28
+
3
29
  ## 1.0.0-beta.7
4
30
 
5
31
  ### Patch Changes
package/dist/helpers.d.ts CHANGED
@@ -1,5 +1,11 @@
1
- import type { PartialSchemaOutput, OutputSchema, DataChunkType, ChunkType } from '@mastra/core/stream';
2
- import type { InferUIMessageChunk, ObjectStreamPart, TextStreamPart, ToolSet, UIMessage } from 'ai';
1
+ import type { PartialSchemaOutput, OutputSchema, DataChunkType, ChunkType, MastraFinishReason } from '@mastra/core/stream';
2
+ import type { InferUIMessageChunk, ObjectStreamPart, TextStreamPart, ToolSet, UIMessage, FinishReason } from 'ai';
3
+ /**
4
+ * Maps Mastra's extended finish reasons to AI SDK-compatible values.
5
+ * 'tripwire' and 'retry' are Mastra-specific reasons for processor scenarios,
6
+ * which are mapped to 'other' for AI SDK compatibility.
7
+ */
8
+ export declare function toAISDKFinishReason(reason: MastraFinishReason): FinishReason;
3
9
  export type OutputChunkType<OUTPUT extends OutputSchema = undefined> = TextStreamPart<ToolSet> | ObjectStreamPart<PartialSchemaOutput<OUTPUT>> | DataChunkType | undefined;
4
10
  export type ToolAgentChunkType = {
5
11
  type: 'tool-agent';
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEvG,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGpG,MAAM,MAAM,eAAe,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,IAC/D,cAAc,CAAC,OAAO,CAAC,GACvB,gBAAgB,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,GAC7C,aAAa,GACb,SAAS,CAAC;AAEd,MAAM,MAAM,kBAAkB,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAA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,CAoP1B;AAED,wBAAgB,uCAAuC,CAAC,UAAU,SAAS,SAAS,EAAE,EACpF,IAAI,EACJ,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,OAAO,EACP,SAAS,EACT,UAAU,EACV,iBAAiB,GAClB,EAAE;IAED,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,aAAa,GAAG;QAAE,IAAI,EAAE,aAAa,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,CAAC;IACzG,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,GAAG,mBAAmB,CAAC,UAAU,CAAC,GAAG,kBAAkB,GAAG,qBAAqB,GAAG,oBAAoB,GAAG,SAAS,CAyOlH"}
package/dist/index.cjs CHANGED
@@ -64,6 +64,12 @@ var isWorkflowExecutionDataChunkType = (chunk) => {
64
64
  };
65
65
 
66
66
  // src/helpers.ts
67
+ function toAISDKFinishReason(reason) {
68
+ if (reason === "tripwire" || reason === "retry") {
69
+ return "other";
70
+ }
71
+ return reason;
72
+ }
67
73
  function convertMastraChunkToAISDKv5({
68
74
  chunk,
69
75
  mode = "stream"
@@ -88,7 +94,7 @@ function convertMastraChunkToAISDKv5({
88
94
  case "finish": {
89
95
  return {
90
96
  type: "finish",
91
- finishReason: chunk.payload.stepResult.reason,
97
+ finishReason: toAISDKFinishReason(chunk.payload.stepResult.reason),
92
98
  totalUsage: chunk.payload.output.usage
93
99
  };
94
100
  }
@@ -227,7 +233,7 @@ function convertMastraChunkToAISDKv5({
227
233
  ...rest2
228
234
  },
229
235
  usage: chunk.payload.output.usage,
230
- finishReason: chunk.payload.stepResult.reason,
236
+ finishReason: toAISDKFinishReason(chunk.payload.stepResult.reason),
231
237
  providerMetadata
232
238
  };
233
239
  }
@@ -288,7 +294,10 @@ function convertMastraChunkToAISDKv5({
288
294
  return {
289
295
  type: "data-tripwire",
290
296
  data: {
291
- tripwireReason: chunk.payload.tripwireReason
297
+ reason: chunk.payload.reason,
298
+ retry: chunk.payload.retry,
299
+ metadata: chunk.payload.metadata,
300
+ processorId: chunk.payload.processorId
292
301
  }
293
302
  };
294
303
  default:
@@ -2108,7 +2117,7 @@ function convertMastraChunkToAISDKStreamPart(chunk) {
2108
2117
  const usage = chunk.payload.output?.usage;
2109
2118
  return {
2110
2119
  type: "finish",
2111
- finishReason: chunk.payload.stepResult?.reason || "stop",
2120
+ finishReason: toAISDKFinishReason(chunk.payload.stepResult?.reason || "stop"),
2112
2121
  usage: usage ? {
2113
2122
  inputTokens: usage.inputTokens || 0,
2114
2123
  outputTokens: usage.outputTokens || 0,