@mastra/ai-sdk 1.0.0 → 1.0.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/CHANGELOG.md +58 -0
- package/dist/helpers.d.ts +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +23 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -1
- package/dist/transformers.d.ts.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
1
|
# @mastra/ai-sdk
|
|
2
2
|
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added support for tripwire data chunks in streaming responses. ([#10291](https://github.com/mastra-ai/mastra/pull/10291))
|
|
8
|
+
|
|
9
|
+
Tripwire chunks allow the AI SDK to emit special data events when certain conditions are triggered during stream processing. These chunks include a `tripwireReason` field explaining why the tripwire was activated.
|
|
10
|
+
|
|
11
|
+
#### Usage
|
|
12
|
+
|
|
13
|
+
When converting Mastra chunks to AI SDK v5 format, tripwire chunks are now automatically handled:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// Tripwire chunks are converted to data-tripwire format
|
|
17
|
+
const chunk = {
|
|
18
|
+
type: 'tripwire',
|
|
19
|
+
payload: { tripwireReason: 'Rate limit approaching' }
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Converts to:
|
|
23
|
+
{
|
|
24
|
+
type: 'data-tripwire',
|
|
25
|
+
data: { tripwireReason: 'Rate limit approaching' }
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [[`7491cc0`](https://github.com/mastra-ai/mastra/commit/7491cc0350b2ba067f98c4915bf607119bd0150f), [`0d10ac7`](https://github.com/mastra-ai/mastra/commit/0d10ac7b8efa03c2f0c330eb2520148bfa6091e9), [`e3e899c`](https://github.com/mastra-ai/mastra/commit/e3e899c650f4c435445303bd97a66f5840a52a1e)]:
|
|
30
|
+
- @mastra/core@0.24.3
|
|
31
|
+
|
|
32
|
+
## 1.0.1-alpha.0
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- Added support for tripwire data chunks in streaming responses. ([#10291](https://github.com/mastra-ai/mastra/pull/10291))
|
|
37
|
+
|
|
38
|
+
Tripwire chunks allow the AI SDK to emit special data events when certain conditions are triggered during stream processing. These chunks include a `tripwireReason` field explaining why the tripwire was activated.
|
|
39
|
+
|
|
40
|
+
#### Usage
|
|
41
|
+
|
|
42
|
+
When converting Mastra chunks to AI SDK v5 format, tripwire chunks are now automatically handled:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// Tripwire chunks are converted to data-tripwire format
|
|
46
|
+
const chunk = {
|
|
47
|
+
type: 'tripwire',
|
|
48
|
+
payload: { tripwireReason: 'Rate limit approaching' }
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Converts to:
|
|
52
|
+
{
|
|
53
|
+
type: 'data-tripwire',
|
|
54
|
+
data: { tripwireReason: 'Rate limit approaching' }
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- Updated dependencies [[`7491cc0`](https://github.com/mastra-ai/mastra/commit/7491cc0350b2ba067f98c4915bf607119bd0150f), [`0d10ac7`](https://github.com/mastra-ai/mastra/commit/0d10ac7b8efa03c2f0c330eb2520148bfa6091e9), [`e3e899c`](https://github.com/mastra-ai/mastra/commit/e3e899c650f4c435445303bd97a66f5840a52a1e)]:
|
|
59
|
+
- @mastra/core@0.24.3-alpha.0
|
|
60
|
+
|
|
3
61
|
## 1.0.0
|
|
4
62
|
|
|
5
63
|
### Major Changes
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ChunkType } from '@mastra/core';
|
|
2
2
|
import type { PartialSchemaOutput, OutputSchema, DataChunkType } from '@mastra/core/stream';
|
|
3
3
|
import type { InferUIMessageChunk, ObjectStreamPart, TextStreamPart, ToolSet, UIMessage } from 'ai';
|
|
4
|
-
export type OutputChunkType<OUTPUT extends OutputSchema = undefined> = TextStreamPart<ToolSet> | ObjectStreamPart<PartialSchemaOutput<OUTPUT>> | undefined;
|
|
4
|
+
export type OutputChunkType<OUTPUT extends OutputSchema = undefined> = TextStreamPart<ToolSet> | ObjectStreamPart<PartialSchemaOutput<OUTPUT>> | DataChunkType | undefined;
|
|
5
5
|
export type ToolAgentChunkType = {
|
|
6
6
|
type: 'tool-agent';
|
|
7
7
|
toolCallId: string;
|
package/dist/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE5F,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,SAAS,CAAC;AAEd,MAAM,MAAM,kBAAkB,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAC1F,MAAM,MAAM,qBAAqB,GAAG;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAChG,MAAM,MAAM,oBAAoB,G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AA;CAAE,CAAC;AAE9F,wBAAgB,2BAA2B,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,EAAE,EACnF,KAAK,EACL,IAAe,GAChB,EAAE;IACD,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACzB,IAAI,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;CAC9B,GAAG,eAAe,CAAC,MAAM,CAAC,CA2N1B;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,CAwOlH"}
|
package/dist/index.cjs
CHANGED
|
@@ -216,6 +216,13 @@ function convertMastraChunkToAISDKv5({
|
|
|
216
216
|
type: "object",
|
|
217
217
|
object: chunk.object
|
|
218
218
|
};
|
|
219
|
+
case "tripwire":
|
|
220
|
+
return {
|
|
221
|
+
type: "data-tripwire",
|
|
222
|
+
data: {
|
|
223
|
+
tripwireReason: chunk.payload.tripwireReason
|
|
224
|
+
}
|
|
225
|
+
};
|
|
219
226
|
default:
|
|
220
227
|
if (chunk.type && "payload" in chunk && chunk.payload) {
|
|
221
228
|
return {
|
|
@@ -494,8 +501,16 @@ function AgentStreamToAISDKTransformer({
|
|
|
494
501
|
sendSources
|
|
495
502
|
}) {
|
|
496
503
|
let bufferedSteps = /* @__PURE__ */ new Map();
|
|
504
|
+
let tripwireOccurred = false;
|
|
505
|
+
let finishEventSent = false;
|
|
497
506
|
return new TransformStream({
|
|
498
507
|
transform(chunk, controller) {
|
|
508
|
+
if (chunk.type === "tripwire") {
|
|
509
|
+
tripwireOccurred = true;
|
|
510
|
+
}
|
|
511
|
+
if (chunk.type === "finish") {
|
|
512
|
+
finishEventSent = true;
|
|
513
|
+
}
|
|
499
514
|
const part = convertMastraChunkToAISDKv5({ chunk, mode: "stream" });
|
|
500
515
|
const transformedChunk = convertFullStreamChunkToUIMessageStream({
|
|
501
516
|
part,
|
|
@@ -525,6 +540,14 @@ function AgentStreamToAISDKTransformer({
|
|
|
525
540
|
controller.enqueue(transformedChunk);
|
|
526
541
|
}
|
|
527
542
|
}
|
|
543
|
+
},
|
|
544
|
+
flush(controller) {
|
|
545
|
+
if (tripwireOccurred && !finishEventSent && sendFinish) {
|
|
546
|
+
controller.enqueue({
|
|
547
|
+
type: "finish",
|
|
548
|
+
finishReason: "other"
|
|
549
|
+
});
|
|
550
|
+
}
|
|
528
551
|
}
|
|
529
552
|
});
|
|
530
553
|
}
|