@mastra/ai-sdk 1.4.4 → 1.4.5-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,14 @@
1
1
  # @mastra/ai-sdk
2
2
 
3
+ ## 1.4.5-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed client-side tool tracing for useChat by carrying observability context through AI SDK v6 `toolMetadata` on `tool-input-available` stream chunks. ([#17202](https://github.com/mastra-ai/mastra/pull/17202))
8
+
9
+ - Updated dependencies [[`34839c1`](https://github.com/mastra-ai/mastra/commit/34839c1910b6964bf59ed0cee58844efebbb684e), [`053735a`](https://github.com/mastra-ai/mastra/commit/053735a75c2c18e23ce34d9468007efa4a45f4c4), [`34839c1`](https://github.com/mastra-ai/mastra/commit/34839c1910b6964bf59ed0cee58844efebbb684e), [`34839c1`](https://github.com/mastra-ai/mastra/commit/34839c1910b6964bf59ed0cee58844efebbb684e), [`a952852`](https://github.com/mastra-ai/mastra/commit/a952852c971a21fb646cd907c75fcf4443cdc963)]:
10
+ - @mastra/core@1.42.0-alpha.3
11
+
3
12
  ## 1.4.4
4
13
 
5
14
  ### Patch Changes
@@ -1549,16 +1549,16 @@ declare interface EventSourceMessage {
1549
1549
  * implementation in that browsers will default this to `message`, whereas this parser will
1550
1550
  * leave this as `undefined` if not explicitly declared.
1551
1551
  */
1552
- event?: string | undefined
1552
+ event?: string | undefined;
1553
1553
  /**
1554
1554
  * ID of the message, if any was provided by the server. Can be used by clients to keep the
1555
1555
  * last received message ID in sync when reconnecting.
1556
1556
  */
1557
- id?: string | undefined
1557
+ id?: string | undefined;
1558
1558
  /**
1559
1559
  * The data received for this message
1560
1560
  */
1561
- data: string
1561
+ data: string;
1562
1562
  }
1563
1563
 
1564
1564
  /**
@@ -1582,8 +1582,11 @@ declare interface EventSourceMessage {
1582
1582
  *
1583
1583
  * @public
1584
1584
  */
1585
- declare class EventSourceParserStream extends TransformStream<string, EventSourceMessage> {
1586
- constructor({onError, onRetry, onComment}?: StreamOptions)
1585
+ declare class EventSourceParserStream extends TransformStream<
1586
+ string,
1587
+ EventSourceMessage
1588
+ > {
1589
+ constructor({ onError, onRetry, onComment }?: StreamOptions);
1587
1590
  }
1588
1591
 
1589
1592
  /**
@@ -6830,19 +6833,19 @@ declare interface StreamOptions {
6830
6833
  *
6831
6834
  * @defaultValue `undefined`
6832
6835
  */
6833
- onError?: ('terminate' | ((error: Error) => void)) | undefined
6836
+ onError?: ("terminate" | ((error: Error) => void)) | undefined;
6834
6837
  /**
6835
6838
  * Callback for when a reconnection interval is sent from the server.
6836
6839
  *
6837
6840
  * @param retry - The number of milliseconds to wait before reconnecting.
6838
6841
  */
6839
- onRetry?: ((retry: number) => void) | undefined
6842
+ onRetry?: ((retry: number) => void) | undefined;
6840
6843
  /**
6841
6844
  * Callback for when a comment is encountered in the stream.
6842
6845
  *
6843
6846
  * @param comment - The comment encountered in the stream.
6844
6847
  */
6845
- onComment?: ((comment: string) => void) | undefined
6848
+ onComment?: ((comment: string) => void) | undefined;
6846
6849
  }
6847
6850
 
6848
6851
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAEnB,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,SAAS,EACT,YAAY,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAEV,YAAY,IAAI,cAAc,EAC9B,mBAAmB,IAAI,qBAAqB,EAE5C,mBAAmB,EACnB,SAAS,IAAI,WAAW,EACzB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGxF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C;;;;GAIG;AACH,wBAAgB,mBAAmB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EACJ,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,OAAO,EACP,SAAS,EACT,UAAU,EACV,iBAAiB,GAClB,EAAE;IAED,IAAI,EACA,cAAc,CAAC,OAAO,CAAC,GACvB,aAAa,GACb,mBAAmB,GACnB;QAAE,IAAI,EAAE,aAAa,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,CAAC;IAC7D,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,GACG,mBAAmB,CAAC,UAAU,CAAC,GAC/B,qBAAqB,CAAC,WAAW,CAAC,GAClC,kBAAkB,GAClB,qBAAqB,GACrB,oBAAoB,GACpB,SAAS,CAsQZ"}
package/dist/index.cjs CHANGED
@@ -30,7 +30,7 @@ function _interopNamespace(e) {
30
30
 
31
31
  var z4__namespace = /*#__PURE__*/_interopNamespace(z4);
32
32
 
33
- // ../../packages/_vendored/ai_v5/dist/chunk-TQ7JQ3AX.js
33
+ // ../../packages/_vendored/ai_v5/dist/chunk-YVS43WX4.js
34
34
  var marker = "vercel.ai.error";
35
35
  var symbol = Symbol.for(marker);
36
36
  var _a;
@@ -209,6 +209,9 @@ var ParseError = class extends Error {
209
209
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
210
210
  }
211
211
  };
212
+ var LF = 10;
213
+ var CR = 13;
214
+ var SPACE = 32;
212
215
  function noop(_arg) {
213
216
  }
214
217
  function createParser(callbacks) {
@@ -216,39 +219,109 @@ function createParser(callbacks) {
216
219
  throw new TypeError(
217
220
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
218
221
  );
219
- const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
220
- let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
221
- function feed(newChunk) {
222
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
223
- for (const line of complete)
224
- parseLine(line);
225
- incompleteLine = incomplete, isFirstChunk = false;
226
- }
227
- function parseLine(line) {
228
- if (line === "") {
222
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks, pendingFragments = [];
223
+ let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
224
+ function feed(chunk) {
225
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
226
+ const trailing2 = processLines(chunk);
227
+ trailing2 !== "" && pendingFragments.push(trailing2);
228
+ return;
229
+ }
230
+ if (chunk.indexOf(`
231
+ `) === -1 && chunk.indexOf("\r") === -1) {
232
+ pendingFragments.push(chunk);
233
+ return;
234
+ }
235
+ pendingFragments.push(chunk);
236
+ const input = pendingFragments.join("");
237
+ pendingFragments.length = 0;
238
+ const trailing = processLines(input);
239
+ trailing !== "" && pendingFragments.push(trailing);
240
+ }
241
+ function processLines(chunk) {
242
+ let searchIndex = 0;
243
+ if (chunk.indexOf("\r") === -1) {
244
+ let lfIndex = chunk.indexOf(`
245
+ `, searchIndex);
246
+ for (; lfIndex !== -1; ) {
247
+ if (searchIndex === lfIndex) {
248
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
249
+ `, searchIndex);
250
+ continue;
251
+ }
252
+ const firstCharCode = chunk.charCodeAt(searchIndex);
253
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
254
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
255
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
256
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
257
+ `, searchIndex);
258
+ continue;
259
+ }
260
+ data = dataLines === 0 ? value : `${data}
261
+ ${value}`, dataLines++;
262
+ } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
263
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
264
+ lfIndex
265
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
266
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
267
+ `, searchIndex);
268
+ }
269
+ return chunk.slice(searchIndex);
270
+ }
271
+ for (; searchIndex < chunk.length; ) {
272
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
273
+ `, searchIndex);
274
+ let lineEnd = -1;
275
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
276
+ break;
277
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
278
+ }
279
+ return chunk.slice(searchIndex);
280
+ }
281
+ function parseLine(chunk, start, end) {
282
+ if (start === end) {
229
283
  dispatchEvent();
230
284
  return;
231
285
  }
232
- if (line.startsWith(":")) {
233
- onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
286
+ const firstCharCode = chunk.charCodeAt(start);
287
+ if (isDataPrefix(chunk, start, firstCharCode)) {
288
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
289
+ data = dataLines === 0 ? value2 : `${data}
290
+ ${value2}`, dataLines++;
234
291
  return;
235
292
  }
236
- const fieldSeparatorIndex = line.indexOf(":");
237
- if (fieldSeparatorIndex !== -1) {
238
- const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
239
- processField(field, value, line);
293
+ if (isEventPrefix(chunk, start, firstCharCode)) {
294
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
240
295
  return;
241
296
  }
242
- processField(line, "", line);
297
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
298
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
299
+ id = value2.includes("\0") ? void 0 : value2;
300
+ return;
301
+ }
302
+ if (firstCharCode === 58) {
303
+ if (onComment) {
304
+ const line2 = chunk.slice(start, end);
305
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
306
+ }
307
+ return;
308
+ }
309
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
310
+ if (fieldSeparatorIndex === -1) {
311
+ processField(line, "", line);
312
+ return;
313
+ }
314
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
315
+ processField(field, value, line);
243
316
  }
244
317
  function processField(field, value, line) {
245
318
  switch (field) {
246
319
  case "event":
247
- eventType = value;
320
+ eventType = value || void 0;
248
321
  break;
249
322
  case "data":
250
- data = `${data}${value}
251
- `;
323
+ data = dataLines === 0 ? value : `${data}
324
+ ${value}`, dataLines++;
252
325
  break;
253
326
  case "id":
254
327
  id = value.includes("\0") ? void 0 : value;
@@ -273,37 +346,26 @@ function createParser(callbacks) {
273
346
  }
274
347
  }
275
348
  function dispatchEvent() {
276
- data.length > 0 && onEvent({
349
+ dataLines > 0 && onEvent({
277
350
  id,
278
- event: eventType || void 0,
279
- // If the data buffer's last character is a U+000A LINE FEED (LF) character,
280
- // then remove the last character from the data buffer.
281
- data: data.endsWith(`
282
- `) ? data.slice(0, -1) : data
283
- }), id = void 0, data = "", eventType = "";
351
+ event: eventType,
352
+ data
353
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
284
354
  }
285
355
  function reset(options = {}) {
286
- incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
356
+ if (options.consume && pendingFragments.length > 0) {
357
+ const incompleteLine = pendingFragments.join("");
358
+ parseLine(incompleteLine, 0, incompleteLine.length);
359
+ }
360
+ isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
287
361
  }
288
362
  return { feed, reset };
289
363
  }
290
- function splitLines(chunk) {
291
- const lines = [];
292
- let incompleteLine = "", searchIndex = 0;
293
- for (; searchIndex < chunk.length; ) {
294
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
295
- `, searchIndex);
296
- let lineEnd = -1;
297
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
298
- incompleteLine = chunk.slice(searchIndex);
299
- break;
300
- } else {
301
- const line = chunk.slice(searchIndex, lineEnd);
302
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
303
- ` && searchIndex++;
304
- }
305
- }
306
- return [lines, incompleteLine];
364
+ function isDataPrefix(chunk, i, firstCharCode) {
365
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
366
+ }
367
+ function isEventPrefix(chunk, i, firstCharCode) {
368
+ return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
307
369
  }
308
370
  var EventSourceParserStream = class extends TransformStream {
309
371
  constructor({ onError, onRetry, onComment } = {}) {
@@ -5713,9 +5775,9 @@ var ParseError2 = class extends Error {
5713
5775
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
5714
5776
  }
5715
5777
  };
5716
- var LF = 10;
5717
- var CR = 13;
5718
- var SPACE = 32;
5778
+ var LF2 = 10;
5779
+ var CR2 = 13;
5780
+ var SPACE2 = 32;
5719
5781
  function noop2(_arg) {
5720
5782
  }
5721
5783
  function createParser2(callbacks) {
@@ -5754,17 +5816,17 @@ function createParser2(callbacks) {
5754
5816
  continue;
5755
5817
  }
5756
5818
  const firstCharCode = chunk.charCodeAt(searchIndex);
5757
- if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
5758
- const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
5759
- if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
5819
+ if (isDataPrefix2(chunk, searchIndex, firstCharCode)) {
5820
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE2 ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
5821
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF2) {
5760
5822
  onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
5761
5823
  `, searchIndex);
5762
5824
  continue;
5763
5825
  }
5764
5826
  data = dataLines === 0 ? value : `${data}
5765
5827
  ${value}`, dataLines++;
5766
- } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
5767
- chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
5828
+ } else isEventPrefix2(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
5829
+ chunk.charCodeAt(searchIndex + 6) === SPACE2 ? searchIndex + 7 : searchIndex + 6,
5768
5830
  lfIndex
5769
5831
  ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
5770
5832
  searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
@@ -5778,7 +5840,7 @@ ${value}`, dataLines++;
5778
5840
  let lineEnd = -1;
5779
5841
  if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
5780
5842
  break;
5781
- parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
5843
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR2 && chunk.charCodeAt(searchIndex) === LF2 && searchIndex++;
5782
5844
  }
5783
5845
  return chunk.slice(searchIndex);
5784
5846
  }
@@ -5788,25 +5850,25 @@ ${value}`, dataLines++;
5788
5850
  return;
5789
5851
  }
5790
5852
  const firstCharCode = chunk.charCodeAt(start);
5791
- if (isDataPrefix(chunk, start, firstCharCode)) {
5792
- const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
5853
+ if (isDataPrefix2(chunk, start, firstCharCode)) {
5854
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE2 ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
5793
5855
  data = dataLines === 0 ? value2 : `${data}
5794
5856
  ${value2}`, dataLines++;
5795
5857
  return;
5796
5858
  }
5797
- if (isEventPrefix(chunk, start, firstCharCode)) {
5798
- eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
5859
+ if (isEventPrefix2(chunk, start, firstCharCode)) {
5860
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE2 ? start + 7 : start + 6, end) || void 0;
5799
5861
  return;
5800
5862
  }
5801
5863
  if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
5802
- const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
5864
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE2 ? start + 4 : start + 3, end);
5803
5865
  id = value2.includes("\0") ? void 0 : value2;
5804
5866
  return;
5805
5867
  }
5806
5868
  if (firstCharCode === 58) {
5807
5869
  if (onComment) {
5808
5870
  const line2 = chunk.slice(start, end);
5809
- onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
5871
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE2 ? 2 : 1));
5810
5872
  }
5811
5873
  return;
5812
5874
  }
@@ -5815,7 +5877,7 @@ ${value2}`, dataLines++;
5815
5877
  processField(line, "", line);
5816
5878
  return;
5817
5879
  }
5818
- const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
5880
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE2 ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
5819
5881
  processField(field, value, line);
5820
5882
  }
5821
5883
  function processField(field, value, line) {
@@ -5865,10 +5927,10 @@ ${value}`, dataLines++;
5865
5927
  }
5866
5928
  return { feed, reset };
5867
5929
  }
5868
- function isDataPrefix(chunk, i, firstCharCode) {
5930
+ function isDataPrefix2(chunk, i, firstCharCode) {
5869
5931
  return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
5870
5932
  }
5871
- function isEventPrefix(chunk, i, firstCharCode) {
5933
+ function isEventPrefix2(chunk, i, firstCharCode) {
5872
5934
  return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
5873
5935
  }
5874
5936
  var EventSourceParserStream2 = class extends TransformStream {
@@ -12154,7 +12216,8 @@ function convertMastraChunkToAISDKBase({
12154
12216
  providerMetadata: chunk.payload.providerMetadata,
12155
12217
  providerExecuted: chunk.payload.providerExecuted,
12156
12218
  toolName: chunk.payload.toolName,
12157
- input: hasTransformedToolPayload(displayInputTransform) ? displayInputTransform.transformed : chunk.payload.args
12219
+ input: hasTransformedToolPayload(displayInputTransform) ? displayInputTransform.transformed : chunk.payload.args,
12220
+ ...chunk.payload.observability ? { observability: chunk.payload.observability } : {}
12158
12221
  };
12159
12222
  case "tool-call-approval":
12160
12223
  return {
@@ -12189,7 +12252,8 @@ function convertMastraChunkToAISDKBase({
12189
12252
  toolName: chunk.payload.toolName,
12190
12253
  dynamic: !!chunk.payload.dynamic,
12191
12254
  providerMetadata: chunk.payload.providerMetadata,
12192
- providerExecuted: chunk.payload.providerExecuted
12255
+ providerExecuted: chunk.payload.providerExecuted,
12256
+ ...chunk.payload.observability ? { observability: chunk.payload.observability } : {}
12193
12257
  };
12194
12258
  case "tool-call-input-streaming-end":
12195
12259
  return {
@@ -12516,6 +12580,7 @@ function convertFullStreamChunkToUIMessageStream({
12516
12580
  };
12517
12581
  }
12518
12582
  case "tool-call": {
12583
+ const observability = part.observability;
12519
12584
  return {
12520
12585
  type: "tool-input-available",
12521
12586
  toolCallId: part.toolCallId,
@@ -12523,7 +12588,12 @@ function convertFullStreamChunkToUIMessageStream({
12523
12588
  input: part.input,
12524
12589
  ...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
12525
12590
  ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
12526
- ...part.dynamic != null ? { dynamic: part.dynamic } : {}
12591
+ ...part.dynamic != null ? { dynamic: part.dynamic } : {},
12592
+ ...observability != null ? {
12593
+ toolMetadata: {
12594
+ __mastraObservability: observability
12595
+ }
12596
+ } : {}
12527
12597
  };
12528
12598
  }
12529
12599
  case "tool-approval-request": {