@mastra/ai-sdk 0.0.0-new-button-export-20251219133013 → 0.0.0-om-20260129012647

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +378 -6
  2. package/dist/chat-route.d.ts +7 -6
  3. package/dist/chat-route.d.ts.map +1 -1
  4. package/dist/{chunk-KYQEM4AK.js → chunk-AAQDCHJY.js} +10 -11
  5. package/dist/chunk-AAQDCHJY.js.map +1 -0
  6. package/dist/{chunk-TD7TJ4N5.cjs → chunk-CCJXHQQO.cjs} +10 -11
  7. package/dist/chunk-CCJXHQQO.cjs.map +1 -0
  8. package/dist/convert-streams.d.ts +4 -3
  9. package/dist/convert-streams.d.ts.map +1 -1
  10. package/dist/helpers.d.ts +3 -3
  11. package/dist/helpers.d.ts.map +1 -1
  12. package/dist/index.cjs +148 -217
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.js +149 -218
  15. package/dist/index.js.map +1 -1
  16. package/dist/middleware.d.ts.map +1 -1
  17. package/dist/network-route.d.ts +5 -6
  18. package/dist/network-route.d.ts.map +1 -1
  19. package/dist/{token-5ZTQBFQ6.cjs → token-36YTPVWD.cjs} +9 -9
  20. package/dist/token-36YTPVWD.cjs.map +1 -0
  21. package/dist/{token-UOO4N54I.js → token-ZFKXETJY.js} +7 -7
  22. package/dist/token-ZFKXETJY.js.map +1 -0
  23. package/dist/token-util-737PGIQA.cjs +9 -0
  24. package/dist/{token-util-DUN56AZR.cjs.map → token-util-737PGIQA.cjs.map} +1 -1
  25. package/dist/token-util-SD2EI4DD.js +7 -0
  26. package/dist/{token-util-JCUK3SCT.js.map → token-util-SD2EI4DD.js.map} +1 -1
  27. package/dist/transformers.d.ts +17 -15
  28. package/dist/transformers.d.ts.map +1 -1
  29. package/package.json +9 -9
  30. package/dist/chunk-KYQEM4AK.js.map +0 -1
  31. package/dist/chunk-TD7TJ4N5.cjs.map +0 -1
  32. package/dist/token-5ZTQBFQ6.cjs.map +0 -1
  33. package/dist/token-UOO4N54I.js.map +0 -1
  34. package/dist/token-util-DUN56AZR.cjs +0 -9
  35. package/dist/token-util-JCUK3SCT.js +0 -7
package/dist/index.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
  var server = require('@mastra/core/server');
4
4
  var z4 = require('zod/v4');
5
5
  var v3 = require('zod/v3');
6
+ var web = require('stream/web');
6
7
  var stream = require('@mastra/core/stream');
7
8
  var agent = require('@mastra/core/agent');
8
9
  var di = require('@mastra/core/di');
@@ -228,14 +229,18 @@ function filter(obj) {
228
229
  }
229
230
  function secureJsonParse(text2) {
230
231
  const { stackTraceLimit } = Error;
231
- Error.stackTraceLimit = 0;
232
+ try {
233
+ Error.stackTraceLimit = 0;
234
+ } catch (e) {
235
+ return _parse(text2);
236
+ }
232
237
  try {
233
238
  return _parse(text2);
234
239
  } finally {
235
240
  Error.stackTraceLimit = stackTraceLimit;
236
241
  }
237
242
  }
238
- var validatorSymbol = Symbol.for("vercel.ai.validator");
243
+ var validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
239
244
  function validator(validate) {
240
245
  return { [validatorSymbol]: true, validate };
241
246
  }
@@ -318,7 +323,7 @@ var getRelativePath = (pathA, pathB) => {
318
323
  }
319
324
  return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
320
325
  };
321
- var ignoreOverride = Symbol(
326
+ var ignoreOverride = /* @__PURE__ */ Symbol(
322
327
  "Let zodToJsonSchema decide on which parser to use"
323
328
  );
324
329
  var defaultOptions = {
@@ -353,11 +358,11 @@ function parseAnyDef() {
353
358
  return {};
354
359
  }
355
360
  function parseArrayDef(def, refs) {
356
- var _a17, _b, _c;
361
+ var _a16, _b, _c;
357
362
  const res = {
358
363
  type: "array"
359
364
  };
360
- if (((_a17 = def.type) == null ? void 0 : _a17._def) && ((_c = (_b = def.type) == null ? void 0 : _b._def) == null ? void 0 : _c.typeName) !== v3.ZodFirstPartyTypeKind.ZodAny) {
365
+ if (((_a16 = def.type) == null ? void 0 : _a16._def) && ((_c = (_b = def.type) == null ? void 0 : _b._def) == null ? void 0 : _c.typeName) !== v3.ZodFirstPartyTypeKind.ZodAny) {
361
366
  res.items = parseDef(def.type._def, {
362
367
  ...refs,
363
368
  currentPath: [...refs.currentPath, "items"]
@@ -716,8 +721,8 @@ function escapeNonAlphaNumeric(source) {
716
721
  return result;
717
722
  }
718
723
  function addFormat(schema, value, message, refs) {
719
- var _a17;
720
- if (schema.format || ((_a17 = schema.anyOf) == null ? void 0 : _a17.some((x) => x.format))) {
724
+ var _a16;
725
+ if (schema.format || ((_a16 = schema.anyOf) == null ? void 0 : _a16.some((x) => x.format))) {
721
726
  if (!schema.anyOf) {
722
727
  schema.anyOf = [];
723
728
  }
@@ -736,8 +741,8 @@ function addFormat(schema, value, message, refs) {
736
741
  }
737
742
  }
738
743
  function addPattern(schema, regex, message, refs) {
739
- var _a17;
740
- if (schema.pattern || ((_a17 = schema.allOf) == null ? void 0 : _a17.some((x) => x.pattern))) {
744
+ var _a16;
745
+ if (schema.pattern || ((_a16 = schema.allOf) == null ? void 0 : _a16.some((x) => x.pattern))) {
741
746
  if (!schema.allOf) {
742
747
  schema.allOf = [];
743
748
  }
@@ -756,7 +761,7 @@ function addPattern(schema, regex, message, refs) {
756
761
  }
757
762
  }
758
763
  function stringifyRegExpWithFlags(regex, refs) {
759
- var _a17;
764
+ var _a16;
760
765
  if (!refs.applyRegexFlags || !regex.flags) {
761
766
  return regex.source;
762
767
  }
@@ -786,7 +791,7 @@ function stringifyRegExpWithFlags(regex, refs) {
786
791
  pattern += source[i];
787
792
  pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
788
793
  inCharRange = false;
789
- } else if (source[i + 1] === "-" && ((_a17 = source[i + 2]) == null ? void 0 : _a17.match(/[a-z]/))) {
794
+ } else if (source[i + 1] === "-" && ((_a16 = source[i + 2]) == null ? void 0 : _a16.match(/[a-z]/))) {
790
795
  pattern += source[i];
791
796
  inCharRange = true;
792
797
  } else {
@@ -828,13 +833,13 @@ function stringifyRegExpWithFlags(regex, refs) {
828
833
  return pattern;
829
834
  }
830
835
  function parseRecordDef(def, refs) {
831
- var _a17, _b, _c, _d, _e, _f;
836
+ var _a16, _b, _c, _d, _e, _f;
832
837
  const schema = {
833
838
  type: "object",
834
- additionalProperties: (_a17 = parseDef(def.valueType._def, {
839
+ additionalProperties: (_a16 = parseDef(def.valueType._def, {
835
840
  ...refs,
836
841
  currentPath: [...refs.currentPath, "additionalProperties"]
837
- })) != null ? _a17 : refs.allowedAdditionalProperties
842
+ })) != null ? _a16 : refs.allowedAdditionalProperties
838
843
  };
839
844
  if (((_b = def.keyType) == null ? void 0 : _b._def.typeName) === v3.ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
840
845
  const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
@@ -1091,8 +1096,8 @@ function safeIsOptional(schema) {
1091
1096
  }
1092
1097
  }
1093
1098
  var parseOptionalDef = (def, refs) => {
1094
- var _a17;
1095
- if (refs.currentPath.toString() === ((_a17 = refs.propertyPath) == null ? void 0 : _a17.toString())) {
1099
+ var _a16;
1100
+ if (refs.currentPath.toString() === ((_a16 = refs.propertyPath) == null ? void 0 : _a16.toString())) {
1096
1101
  return parseDef(def.innerType._def, refs);
1097
1102
  }
1098
1103
  const innerSchema = parseDef(def.innerType._def, {
@@ -1262,10 +1267,10 @@ var selectParser = (def, typeName, refs) => {
1262
1267
  }
1263
1268
  };
1264
1269
  function parseDef(def, refs, forceResolution = false) {
1265
- var _a17;
1270
+ var _a16;
1266
1271
  const seenItem = refs.seen.get(def);
1267
1272
  if (refs.override) {
1268
- const overrideResult = (_a17 = refs.override) == null ? void 0 : _a17.call(
1273
+ const overrideResult = (_a16 = refs.override) == null ? void 0 : _a16.call(
1269
1274
  refs,
1270
1275
  def,
1271
1276
  refs,
@@ -1331,11 +1336,11 @@ var getRefs = (options) => {
1331
1336
  currentPath,
1332
1337
  propertyPath: void 0,
1333
1338
  seen: new Map(
1334
- Object.entries(_options.definitions).map(([name17, def]) => [
1339
+ Object.entries(_options.definitions).map(([name16, def]) => [
1335
1340
  def._def,
1336
1341
  {
1337
1342
  def: def._def,
1338
- path: [..._options.basePath, _options.definitionPath, name17],
1343
+ path: [..._options.basePath, _options.definitionPath, name16],
1339
1344
  // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
1340
1345
  jsonSchema: void 0
1341
1346
  }
@@ -1344,7 +1349,7 @@ var getRefs = (options) => {
1344
1349
  };
1345
1350
  };
1346
1351
  var zodToJsonSchema = (schema, options) => {
1347
- var _a17;
1352
+ var _a16;
1348
1353
  const refs = getRefs(options);
1349
1354
  let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
1350
1355
  (acc, [name23, schema2]) => {
@@ -1363,31 +1368,31 @@ var zodToJsonSchema = (schema, options) => {
1363
1368
  },
1364
1369
  {}
1365
1370
  ) : void 0;
1366
- const name17 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
1367
- const main = (_a17 = parseDef(
1371
+ const name16 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
1372
+ const main = (_a16 = parseDef(
1368
1373
  schema._def,
1369
- name17 === void 0 ? refs : {
1374
+ name16 === void 0 ? refs : {
1370
1375
  ...refs,
1371
- currentPath: [...refs.basePath, refs.definitionPath, name17]
1376
+ currentPath: [...refs.basePath, refs.definitionPath, name16]
1372
1377
  },
1373
1378
  false
1374
- )) != null ? _a17 : parseAnyDef();
1379
+ )) != null ? _a16 : parseAnyDef();
1375
1380
  const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
1376
1381
  if (title !== void 0) {
1377
1382
  main.title = title;
1378
1383
  }
1379
- const combined = name17 === void 0 ? definitions ? {
1384
+ const combined = name16 === void 0 ? definitions ? {
1380
1385
  ...main,
1381
1386
  [refs.definitionPath]: definitions
1382
1387
  } : main : {
1383
1388
  $ref: [
1384
1389
  ...refs.$refStrategy === "relative" ? [] : refs.basePath,
1385
1390
  refs.definitionPath,
1386
- name17
1391
+ name16
1387
1392
  ].join("/"),
1388
1393
  [refs.definitionPath]: {
1389
1394
  ...definitions,
1390
- [name17]: main
1395
+ [name16]: main
1391
1396
  }
1392
1397
  };
1393
1398
  combined.$schema = "http://json-schema.org/draft-07/schema#";
@@ -1395,8 +1400,8 @@ var zodToJsonSchema = (schema, options) => {
1395
1400
  };
1396
1401
  var zod_to_json_schema_default = zodToJsonSchema;
1397
1402
  function zod3Schema(zodSchema2, options) {
1398
- var _a17;
1399
- const useReferences = (_a17 = void 0 ) != null ? _a17 : false;
1403
+ var _a16;
1404
+ const useReferences = (_a16 = void 0 ) != null ? _a16 : false;
1400
1405
  return jsonSchema(
1401
1406
  // defer json schema creation to avoid unnecessary computation when only validation is needed
1402
1407
  () => zod_to_json_schema_default(zodSchema2, {
@@ -1411,8 +1416,8 @@ function zod3Schema(zodSchema2, options) {
1411
1416
  );
1412
1417
  }
1413
1418
  function zod4Schema(zodSchema2, options) {
1414
- var _a17;
1415
- const useReferences = (_a17 = void 0 ) != null ? _a17 : false;
1419
+ var _a16;
1420
+ const useReferences = (_a16 = void 0 ) != null ? _a16 : false;
1416
1421
  return jsonSchema(
1417
1422
  // defer json schema creation to avoid unnecessary computation when only validation is needed
1418
1423
  () => z4__namespace.toJSONSchema(zodSchema2, {
@@ -1438,7 +1443,7 @@ function zodSchema(zodSchema2, options) {
1438
1443
  return zod3Schema(zodSchema2);
1439
1444
  }
1440
1445
  }
1441
- var schemaSymbol = Symbol.for("vercel.ai.schema");
1446
+ var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
1442
1447
  function jsonSchema(jsonSchema2, {
1443
1448
  validate
1444
1449
  } = {}) {
@@ -1467,13 +1472,13 @@ function asSchema(schema) {
1467
1472
  }
1468
1473
  var __defProp = Object.defineProperty;
1469
1474
  var __export = (target, all) => {
1470
- for (var name17 in all)
1471
- __defProp(target, name17, { get: all[name17], enumerable: true });
1475
+ for (var name16 in all)
1476
+ __defProp(target, name16, { get: all[name16], enumerable: true });
1472
1477
  };
1473
- var name72 = "AI_NoObjectGeneratedError";
1474
- var marker72 = `vercel.ai.error.${name72}`;
1475
- var symbol72 = Symbol.for(marker72);
1476
- var _a72;
1478
+ var name62 = "AI_NoObjectGeneratedError";
1479
+ var marker62 = `vercel.ai.error.${name62}`;
1480
+ var symbol62 = Symbol.for(marker62);
1481
+ var _a62;
1477
1482
  var NoObjectGeneratedError = class extends AISDKError {
1478
1483
  constructor({
1479
1484
  message = "No object generated.",
@@ -1483,18 +1488,18 @@ var NoObjectGeneratedError = class extends AISDKError {
1483
1488
  usage,
1484
1489
  finishReason
1485
1490
  }) {
1486
- super({ name: name72, message, cause });
1487
- this[_a72] = true;
1491
+ super({ name: name62, message, cause });
1492
+ this[_a62] = true;
1488
1493
  this.text = text2;
1489
1494
  this.response = response;
1490
1495
  this.usage = usage;
1491
1496
  this.finishReason = finishReason;
1492
1497
  }
1493
1498
  static isInstance(error) {
1494
- return AISDKError.hasMarker(error, marker72);
1499
+ return AISDKError.hasMarker(error, marker62);
1495
1500
  }
1496
1501
  };
1497
- _a72 = symbol72;
1502
+ _a62 = symbol62;
1498
1503
  var dataContentSchema = z4.z.union([
1499
1504
  z4.z.string(),
1500
1505
  z4.z.instanceof(Uint8Array),
@@ -1502,8 +1507,8 @@ var dataContentSchema = z4.z.union([
1502
1507
  z4.z.custom(
1503
1508
  // Buffer might not be available in some environments such as CloudFlare:
1504
1509
  (value) => {
1505
- var _a17, _b;
1506
- return (_b = (_a17 = globalThis.Buffer) == null ? void 0 : _a17.isBuffer(value)) != null ? _b : false;
1510
+ var _a16, _b;
1511
+ return (_b = (_a16 = globalThis.Buffer) == null ? void 0 : _a16.isBuffer(value)) != null ? _b : false;
1507
1512
  },
1508
1513
  { message: "Must be a Buffer" }
1509
1514
  )
@@ -2092,7 +2097,7 @@ function processUIMessageStream({
2092
2097
  new TransformStream({
2093
2098
  async transform(chunk, controller) {
2094
2099
  await runUpdateMessageJob(async ({ state, write }) => {
2095
- var _a17, _b, _c, _d;
2100
+ var _a16, _b, _c, _d;
2096
2101
  function getToolInvocation(toolCallId) {
2097
2102
  const toolInvocations = state.message.parts.filter(isToolUIPart);
2098
2103
  const toolInvocation = toolInvocations.find(
@@ -2120,7 +2125,7 @@ function processUIMessageStream({
2120
2125
  return toolInvocation;
2121
2126
  }
2122
2127
  function updateToolPart(options) {
2123
- var _a18;
2128
+ var _a17;
2124
2129
  const part = state.message.parts.find(
2125
2130
  (part2) => isToolUIPart(part2) && part2.toolCallId === options.toolCallId
2126
2131
  );
@@ -2133,7 +2138,7 @@ function processUIMessageStream({
2133
2138
  anyPart.errorText = anyOptions.errorText;
2134
2139
  anyPart.rawInput = anyOptions.rawInput;
2135
2140
  anyPart.preliminary = anyOptions.preliminary;
2136
- anyPart.providerExecuted = (_a18 = anyOptions.providerExecuted) != null ? _a18 : part.providerExecuted;
2141
+ anyPart.providerExecuted = (_a17 = anyOptions.providerExecuted) != null ? _a17 : part.providerExecuted;
2137
2142
  if (anyOptions.providerMetadata != null && part.state === "input-available") {
2138
2143
  part.callProviderMetadata = anyOptions.providerMetadata;
2139
2144
  }
@@ -2153,7 +2158,7 @@ function processUIMessageStream({
2153
2158
  }
2154
2159
  }
2155
2160
  function updateDynamicToolPart(options) {
2156
- var _a18;
2161
+ var _a17, _b2;
2157
2162
  const part = state.message.parts.find(
2158
2163
  (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
2159
2164
  );
@@ -2165,8 +2170,9 @@ function processUIMessageStream({
2165
2170
  anyPart.input = anyOptions.input;
2166
2171
  anyPart.output = anyOptions.output;
2167
2172
  anyPart.errorText = anyOptions.errorText;
2168
- anyPart.rawInput = (_a18 = anyOptions.rawInput) != null ? _a18 : anyPart.rawInput;
2173
+ anyPart.rawInput = (_a17 = anyOptions.rawInput) != null ? _a17 : anyPart.rawInput;
2169
2174
  anyPart.preliminary = anyOptions.preliminary;
2175
+ anyPart.providerExecuted = (_b2 = anyOptions.providerExecuted) != null ? _b2 : part.providerExecuted;
2170
2176
  if (anyOptions.providerMetadata != null && part.state === "input-available") {
2171
2177
  part.callProviderMetadata = anyOptions.providerMetadata;
2172
2178
  }
@@ -2180,6 +2186,7 @@ function processUIMessageStream({
2180
2186
  output: anyOptions.output,
2181
2187
  errorText: anyOptions.errorText,
2182
2188
  preliminary: anyOptions.preliminary,
2189
+ providerExecuted: anyOptions.providerExecuted,
2183
2190
  ...anyOptions.providerMetadata != null ? { callProviderMetadata: anyOptions.providerMetadata } : {}
2184
2191
  });
2185
2192
  }
@@ -2212,7 +2219,7 @@ function processUIMessageStream({
2212
2219
  case "text-delta": {
2213
2220
  const textPart = state.activeTextParts[chunk.id];
2214
2221
  textPart.text += chunk.delta;
2215
- textPart.providerMetadata = (_a17 = chunk.providerMetadata) != null ? _a17 : textPart.providerMetadata;
2222
+ textPart.providerMetadata = (_a16 = chunk.providerMetadata) != null ? _a16 : textPart.providerMetadata;
2216
2223
  write();
2217
2224
  break;
2218
2225
  }
@@ -2296,7 +2303,8 @@ function processUIMessageStream({
2296
2303
  toolCallId: chunk.toolCallId,
2297
2304
  toolName: chunk.toolName,
2298
2305
  state: "input-streaming",
2299
- input: void 0
2306
+ input: void 0,
2307
+ providerExecuted: chunk.providerExecuted
2300
2308
  });
2301
2309
  } else {
2302
2310
  updateToolPart({
@@ -2341,6 +2349,7 @@ function processUIMessageStream({
2341
2349
  toolName: chunk.toolName,
2342
2350
  state: "input-available",
2343
2351
  input: chunk.input,
2352
+ providerExecuted: chunk.providerExecuted,
2344
2353
  providerMetadata: chunk.providerMetadata
2345
2354
  });
2346
2355
  } else {
@@ -2369,6 +2378,7 @@ function processUIMessageStream({
2369
2378
  state: "output-error",
2370
2379
  input: chunk.input,
2371
2380
  errorText: chunk.errorText,
2381
+ providerExecuted: chunk.providerExecuted,
2372
2382
  providerMetadata: chunk.providerMetadata
2373
2383
  });
2374
2384
  } else {
@@ -2424,7 +2434,8 @@ function processUIMessageStream({
2424
2434
  toolName: toolInvocation.toolName,
2425
2435
  state: "output-error",
2426
2436
  input: toolInvocation.input,
2427
- errorText: chunk.errorText
2437
+ errorText: chunk.errorText,
2438
+ providerExecuted: chunk.providerExecuted
2428
2439
  });
2429
2440
  } else {
2430
2441
  const toolInvocation = getToolInvocation(chunk.toolCallId);
@@ -2434,7 +2445,8 @@ function processUIMessageStream({
2434
2445
  state: "output-error",
2435
2446
  input: toolInvocation.input,
2436
2447
  rawInput: toolInvocation.rawInput,
2437
- errorText: chunk.errorText
2448
+ errorText: chunk.errorText,
2449
+ providerExecuted: chunk.providerExecuted
2438
2450
  });
2439
2451
  }
2440
2452
  write();
@@ -2460,6 +2472,9 @@ function processUIMessageStream({
2460
2472
  break;
2461
2473
  }
2462
2474
  case "finish": {
2475
+ if (chunk.finishReason != null) {
2476
+ state.finishReason = chunk.finishReason;
2477
+ }
2463
2478
  await updateMessageMetadata(chunk.messageMetadata);
2464
2479
  if (chunk.messageMetadata != null) {
2465
2480
  write();
@@ -2565,7 +2580,8 @@ function handleUIMessageStreamFinish({
2565
2580
  messages: [
2566
2581
  ...isContinuation ? originalMessages.slice(0, -1) : originalMessages,
2567
2582
  state.message
2568
- ]
2583
+ ],
2584
+ finishReason: state.finishReason
2569
2585
  });
2570
2586
  };
2571
2587
  return processUIMessageStream({
@@ -2672,7 +2688,7 @@ var wrapLanguageModel = ({
2672
2688
  modelId,
2673
2689
  providerId
2674
2690
  }) => {
2675
- return asArray(middlewareArg).reverse().reduce((wrappedModel, middleware) => {
2691
+ return [...asArray(middlewareArg)].reverse().reduce((wrappedModel, middleware) => {
2676
2692
  return doWrap({ model: wrappedModel, middleware, modelId, providerId });
2677
2693
  }, model);
2678
2694
  };
@@ -2689,7 +2705,7 @@ var doWrap = ({
2689
2705
  modelId,
2690
2706
  providerId
2691
2707
  }) => {
2692
- var _a17, _b, _c;
2708
+ var _a16, _b, _c;
2693
2709
  async function doTransform({
2694
2710
  params,
2695
2711
  type
@@ -2698,7 +2714,7 @@ var doWrap = ({
2698
2714
  }
2699
2715
  return {
2700
2716
  specificationVersion: "v2",
2701
- provider: (_a17 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a17 : model.provider,
2717
+ provider: (_a16 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a16 : model.provider,
2702
2718
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
2703
2719
  supportedUrls: (_c = overrideSupportedUrls == null ? void 0 : overrideSupportedUrls({ model })) != null ? _c : model.supportedUrls,
2704
2720
  async doGenerate(params) {
@@ -2720,130 +2736,6 @@ var doWrap = ({
2720
2736
  }
2721
2737
  };
2722
2738
  };
2723
- var ClientOrServerImplementationSchema = z4.z.looseObject({
2724
- name: z4.z.string(),
2725
- version: z4.z.string()
2726
- });
2727
- var BaseParamsSchema = z4.z.looseObject({
2728
- _meta: z4.z.optional(z4.z.object({}).loose())
2729
- });
2730
- var ResultSchema = BaseParamsSchema;
2731
- var RequestSchema = z4.z.object({
2732
- method: z4.z.string(),
2733
- params: z4.z.optional(BaseParamsSchema)
2734
- });
2735
- var ServerCapabilitiesSchema = z4.z.looseObject({
2736
- experimental: z4.z.optional(z4.z.object({}).loose()),
2737
- logging: z4.z.optional(z4.z.object({}).loose()),
2738
- prompts: z4.z.optional(
2739
- z4.z.looseObject({
2740
- listChanged: z4.z.optional(z4.z.boolean())
2741
- })
2742
- ),
2743
- resources: z4.z.optional(
2744
- z4.z.looseObject({
2745
- subscribe: z4.z.optional(z4.z.boolean()),
2746
- listChanged: z4.z.optional(z4.z.boolean())
2747
- })
2748
- ),
2749
- tools: z4.z.optional(
2750
- z4.z.looseObject({
2751
- listChanged: z4.z.optional(z4.z.boolean())
2752
- })
2753
- )
2754
- });
2755
- ResultSchema.extend({
2756
- protocolVersion: z4.z.string(),
2757
- capabilities: ServerCapabilitiesSchema,
2758
- serverInfo: ClientOrServerImplementationSchema,
2759
- instructions: z4.z.optional(z4.z.string())
2760
- });
2761
- var PaginatedResultSchema = ResultSchema.extend({
2762
- nextCursor: z4.z.optional(z4.z.string())
2763
- });
2764
- var ToolSchema = z4.z.object({
2765
- name: z4.z.string(),
2766
- description: z4.z.optional(z4.z.string()),
2767
- inputSchema: z4.z.object({
2768
- type: z4.z.literal("object"),
2769
- properties: z4.z.optional(z4.z.object({}).loose())
2770
- }).loose()
2771
- }).loose();
2772
- PaginatedResultSchema.extend({
2773
- tools: z4.z.array(ToolSchema)
2774
- });
2775
- var TextContentSchema = z4.z.object({
2776
- type: z4.z.literal("text"),
2777
- text: z4.z.string()
2778
- }).loose();
2779
- var ImageContentSchema = z4.z.object({
2780
- type: z4.z.literal("image"),
2781
- data: z4.z.base64(),
2782
- mimeType: z4.z.string()
2783
- }).loose();
2784
- var ResourceContentsSchema = z4.z.object({
2785
- /**
2786
- * The URI of this resource.
2787
- */
2788
- uri: z4.z.string(),
2789
- /**
2790
- * The MIME type of this resource, if known.
2791
- */
2792
- mimeType: z4.z.optional(z4.z.string())
2793
- }).loose();
2794
- var TextResourceContentsSchema = ResourceContentsSchema.extend({
2795
- text: z4.z.string()
2796
- });
2797
- var BlobResourceContentsSchema = ResourceContentsSchema.extend({
2798
- blob: z4.z.base64()
2799
- });
2800
- var EmbeddedResourceSchema = z4.z.object({
2801
- type: z4.z.literal("resource"),
2802
- resource: z4.z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
2803
- }).loose();
2804
- ResultSchema.extend({
2805
- content: z4.z.array(
2806
- z4.z.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
2807
- ),
2808
- isError: z4.z.boolean().default(false).optional()
2809
- }).or(
2810
- ResultSchema.extend({
2811
- toolResult: z4.z.unknown()
2812
- })
2813
- );
2814
- var JSONRPC_VERSION = "2.0";
2815
- var JSONRPCRequestSchema = z4.z.object({
2816
- jsonrpc: z4.z.literal(JSONRPC_VERSION),
2817
- id: z4.z.union([z4.z.string(), z4.z.number().int()])
2818
- }).merge(RequestSchema).strict();
2819
- var JSONRPCResponseSchema = z4.z.object({
2820
- jsonrpc: z4.z.literal(JSONRPC_VERSION),
2821
- id: z4.z.union([z4.z.string(), z4.z.number().int()]),
2822
- result: ResultSchema
2823
- }).strict();
2824
- var JSONRPCErrorSchema = z4.z.object({
2825
- jsonrpc: z4.z.literal(JSONRPC_VERSION),
2826
- id: z4.z.union([z4.z.string(), z4.z.number().int()]),
2827
- error: z4.z.object({
2828
- code: z4.z.number().int(),
2829
- message: z4.z.string(),
2830
- data: z4.z.optional(z4.z.unknown())
2831
- })
2832
- }).strict();
2833
- var JSONRPCNotificationSchema = z4.z.object({
2834
- jsonrpc: z4.z.literal(JSONRPC_VERSION)
2835
- }).merge(
2836
- z4.z.object({
2837
- method: z4.z.string(),
2838
- params: z4.z.optional(BaseParamsSchema)
2839
- })
2840
- ).strict();
2841
- z4.z.union([
2842
- JSONRPCRequestSchema,
2843
- JSONRPCNotificationSchema,
2844
- JSONRPCResponseSchema,
2845
- JSONRPCErrorSchema
2846
- ]);
2847
2739
  function createUIMessageStream({
2848
2740
  execute,
2849
2741
  onError = getErrorMessage2,
@@ -3108,7 +3000,8 @@ function convertMastraChunkToAISDKv5({
3108
3000
  runId: chunk.runId,
3109
3001
  toolCallId: chunk.payload.toolCallId,
3110
3002
  toolName: chunk.payload.toolName,
3111
- args: chunk.payload.args
3003
+ args: chunk.payload.args,
3004
+ resumeSchema: chunk.payload.resumeSchema
3112
3005
  }
3113
3006
  };
3114
3007
  case "tool-call-suspended":
@@ -3119,7 +3012,8 @@ function convertMastraChunkToAISDKv5({
3119
3012
  runId: chunk.runId,
3120
3013
  toolCallId: chunk.payload.toolCallId,
3121
3014
  toolName: chunk.payload.toolName,
3122
- suspendPayload: chunk.payload.suspendPayload
3015
+ suspendPayload: chunk.payload.suspendPayload,
3016
+ resumeSchema: chunk.payload.resumeSchema
3123
3017
  }
3124
3018
  };
3125
3019
  case "tool-call-input-streaming-start":
@@ -3385,7 +3279,8 @@ function convertFullStreamChunkToUIMessageStream({
3385
3279
  ${JSON.stringify(part)}`
3386
3280
  );
3387
3281
  }
3388
- return part.output;
3282
+ const { type, data, id } = part.output;
3283
+ return { type, data, ...id !== void 0 && { id } };
3389
3284
  }
3390
3285
  return;
3391
3286
  }
@@ -3447,7 +3342,8 @@ function convertFullStreamChunkToUIMessageStream({
3447
3342
  ${JSON.stringify(part)}`
3448
3343
  );
3449
3344
  }
3450
- return part;
3345
+ const { type, data, id } = part;
3346
+ return { type, data, ...id !== void 0 && { id } };
3451
3347
  }
3452
3348
  return;
3453
3349
  }
@@ -3455,12 +3351,12 @@ function convertFullStreamChunkToUIMessageStream({
3455
3351
  }
3456
3352
 
3457
3353
  // src/transformers.ts
3458
- var PRIMITIVE_CACHE_SYMBOL = Symbol("primitive-cache");
3354
+ var PRIMITIVE_CACHE_SYMBOL = /* @__PURE__ */ Symbol("primitive-cache");
3459
3355
  function WorkflowStreamToAISDKTransformer({
3460
3356
  includeTextStreamParts
3461
3357
  } = {}) {
3462
3358
  const bufferedWorkflows = /* @__PURE__ */ new Map();
3463
- return new TransformStream({
3359
+ return new web.TransformStream({
3464
3360
  start(controller) {
3465
3361
  controller.enqueue({
3466
3362
  type: "start"
@@ -3479,7 +3375,7 @@ function WorkflowStreamToAISDKTransformer({
3479
3375
  }
3480
3376
  function AgentNetworkToAISDKTransformer() {
3481
3377
  const bufferedNetworks = /* @__PURE__ */ new Map();
3482
- return new TransformStream({
3378
+ return new web.TransformStream({
3483
3379
  start(controller) {
3484
3380
  controller.enqueue({
3485
3381
  type: "start"
@@ -3492,14 +3388,22 @@ function AgentNetworkToAISDKTransformer() {
3492
3388
  },
3493
3389
  transform(chunk, controller) {
3494
3390
  const transformed = transformNetwork(chunk, bufferedNetworks);
3495
- if (transformed) controller.enqueue(transformed);
3391
+ if (transformed) {
3392
+ if (Array.isArray(transformed)) {
3393
+ for (const item of transformed) {
3394
+ controller.enqueue(item);
3395
+ }
3396
+ } else {
3397
+ controller.enqueue(transformed);
3398
+ }
3399
+ }
3496
3400
  }
3497
3401
  });
3498
3402
  }
3499
3403
  function AgentStreamToAISDKTransformer({
3500
3404
  lastMessageId,
3501
- sendStart,
3502
- sendFinish,
3405
+ sendStart = true,
3406
+ sendFinish = true,
3503
3407
  sendReasoning,
3504
3408
  sendSources,
3505
3409
  messageMetadata,
@@ -3508,7 +3412,7 @@ function AgentStreamToAISDKTransformer({
3508
3412
  let bufferedSteps = /* @__PURE__ */ new Map();
3509
3413
  let tripwireOccurred = false;
3510
3414
  let finishEventSent = false;
3511
- return new TransformStream({
3415
+ return new web.TransformStream({
3512
3416
  transform(chunk, controller) {
3513
3417
  if (chunk.type === "tripwire") {
3514
3418
  tripwireOccurred = true;
@@ -3805,7 +3709,8 @@ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStre
3805
3709
  ${JSON.stringify(output)}`
3806
3710
  );
3807
3711
  }
3808
- return output;
3712
+ const { type, data, id } = output;
3713
+ return { type, data, ...id !== void 0 && { id } };
3809
3714
  }
3810
3715
  return null;
3811
3716
  }
@@ -3817,7 +3722,12 @@ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStre
3817
3722
  ${JSON.stringify(payload)}`
3818
3723
  );
3819
3724
  }
3820
- return payload;
3725
+ const { type, data, id } = payload;
3726
+ return {
3727
+ type,
3728
+ data,
3729
+ ...id !== void 0 && { id }
3730
+ };
3821
3731
  }
3822
3732
  return null;
3823
3733
  }
@@ -3831,7 +3741,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
3831
3741
  name: payload.payload.networkId,
3832
3742
  steps: [],
3833
3743
  usage: null,
3834
- output: null
3744
+ output: null,
3745
+ hasEmittedText: false
3835
3746
  });
3836
3747
  }
3837
3748
  const current = bufferedNetworks.get(payload.runId);
@@ -3866,6 +3777,7 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
3866
3777
  case "routing-agent-text-start": {
3867
3778
  const current = bufferedNetworks.get(payload.runId);
3868
3779
  if (!current) return null;
3780
+ current.hasEmittedText = true;
3869
3781
  return {
3870
3782
  type: "text-start",
3871
3783
  id: payload.runId
@@ -3874,6 +3786,7 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
3874
3786
  case "routing-agent-text-delta": {
3875
3787
  const current = bufferedNetworks.get(payload.runId);
3876
3788
  if (!current) return null;
3789
+ current.hasEmittedText = true;
3877
3790
  return {
3878
3791
  type: "text-delta",
3879
3792
  id: payload.runId,
@@ -4048,15 +3961,25 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
4048
3961
  case "network-execution-event-step-finish": {
4049
3962
  const current = bufferedNetworks.get(payload.runId);
4050
3963
  if (!current) return null;
4051
- return {
3964
+ const resultText = payload.payload?.result;
3965
+ const dataNetworkChunk = {
4052
3966
  type: isNested ? "data-tool-network" : "data-network",
4053
3967
  id: payload.runId,
4054
3968
  data: {
4055
3969
  ...current,
4056
3970
  status: "finished",
4057
- output: payload.payload?.result ?? current.output
3971
+ output: resultText ?? current.output
4058
3972
  }
4059
3973
  };
3974
+ if (!current.hasEmittedText && resultText && typeof resultText === "string" && resultText.length > 0) {
3975
+ current.hasEmittedText = true;
3976
+ return [
3977
+ { type: "text-start", id: payload.runId },
3978
+ { type: "text-delta", id: payload.runId, delta: resultText },
3979
+ dataNetworkChunk
3980
+ ];
3981
+ }
3982
+ return dataNetworkChunk;
4060
3983
  }
4061
3984
  case "network-execution-event-finish": {
4062
3985
  const current = bufferedNetworks.get(payload.runId);
@@ -4072,6 +3995,10 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
4072
3995
  }
4073
3996
  };
4074
3997
  }
3998
+ case "network-object":
3999
+ case "network-object-result": {
4000
+ return null;
4001
+ }
4075
4002
  default: {
4076
4003
  if (isAgentExecutionDataChunkType(payload)) {
4077
4004
  if (!("data" in payload.payload)) {
@@ -4080,8 +4007,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
4080
4007
  ${JSON.stringify(payload)}`
4081
4008
  );
4082
4009
  }
4083
- const { type, data } = payload.payload;
4084
- return { type, data };
4010
+ const { type, data, id } = payload.payload;
4011
+ return { type, data, ...id !== void 0 && { id } };
4085
4012
  }
4086
4013
  if (isWorkflowExecutionDataChunkType(payload)) {
4087
4014
  if (!("data" in payload.payload)) {
@@ -4090,8 +4017,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
4090
4017
  ${JSON.stringify(payload)}`
4091
4018
  );
4092
4019
  }
4093
- const { type, data } = payload.payload;
4094
- return { type, data };
4020
+ const { type, data, id } = payload.payload;
4021
+ return { type, data, ...id !== void 0 && { id } };
4095
4022
  }
4096
4023
  if (payload.type.startsWith("agent-execution-event-")) {
4097
4024
  const stepId = payload.payload.runId;
@@ -4151,8 +4078,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
4151
4078
  ${JSON.stringify(payload)}`
4152
4079
  );
4153
4080
  }
4154
- const { type, data } = payload;
4155
- return { type, data };
4081
+ const { type, data, id } = payload;
4082
+ return { type, data, ...id !== void 0 && { id } };
4156
4083
  }
4157
4084
  return null;
4158
4085
  }
@@ -4200,7 +4127,7 @@ async function handleChatStream({
4200
4127
  sendReasoning = false,
4201
4128
  sendSources = false
4202
4129
  }) {
4203
- const { messages, resumeData, runId, requestContext, ...rest } = params;
4130
+ const { messages, resumeData, runId, requestContext, trigger, ...rest } = params;
4204
4131
  if (resumeData && !runId) {
4205
4132
  throw new Error("runId is required when resumeData is provided");
4206
4133
  }
@@ -4211,20 +4138,24 @@ async function handleChatStream({
4211
4138
  if (!Array.isArray(messages)) {
4212
4139
  throw new Error("Messages must be an array of UIMessage objects");
4213
4140
  }
4214
- const mergedOptions = {
4215
- ...defaultOptions2,
4216
- ...rest,
4217
- ...runId && { runId },
4218
- requestContext: requestContext || defaultOptions2?.requestContext
4219
- };
4220
- const result = resumeData ? await agentObj.resumeStream(resumeData, mergedOptions) : await agentObj.stream(messages, mergedOptions);
4221
4141
  let lastMessageId;
4222
- if (messages.length) {
4142
+ let messagesToSend = messages;
4143
+ if (messages.length > 0) {
4223
4144
  const lastMessage = messages[messages.length - 1];
4224
4145
  if (lastMessage?.role === "assistant") {
4225
4146
  lastMessageId = lastMessage.id;
4147
+ if (trigger === "regenerate-message") {
4148
+ messagesToSend = messages.slice(0, -1);
4149
+ }
4226
4150
  }
4227
4151
  }
4152
+ const mergedOptions = {
4153
+ ...defaultOptions2,
4154
+ ...rest,
4155
+ ...runId && { runId },
4156
+ requestContext: requestContext || defaultOptions2?.requestContext
4157
+ };
4158
+ const result = resumeData ? await agentObj.resumeStream(resumeData, mergedOptions) : await agentObj.stream(messagesToSend, mergedOptions);
4228
4159
  return createUIMessageStream({
4229
4160
  originalMessages: messages,
4230
4161
  execute: async ({ writer }) => {
@@ -4731,7 +4662,7 @@ function createProcessorMiddleware(options) {
4731
4662
  }
4732
4663
  }
4733
4664
  }
4734
- const newPrompt = messageList.get.all.aiV5.prompt().map(agent.MessageList.aiV5ModelMessageToV2PromptMessage);
4665
+ const newPrompt = messageList.get.all.aiV5.prompt().map(agent.aiV5ModelMessageToV2PromptMessage);
4735
4666
  return {
4736
4667
  ...params,
4737
4668
  prompt: newPrompt
@@ -4823,7 +4754,7 @@ function createProcessorMiddleware(options) {
4823
4754
  const processorStates = /* @__PURE__ */ new Map();
4824
4755
  const runId = crypto.randomUUID();
4825
4756
  const transformedStream = stream$1.pipeThrough(
4826
- new TransformStream({
4757
+ new web.TransformStream({
4827
4758
  async transform(chunk, controller) {
4828
4759
  let mastraChunk = stream.convertFullStreamChunkToMastra(
4829
4760
  chunk,
@@ -4883,7 +4814,7 @@ function createProcessorMiddleware(options) {
4883
4814
  };
4884
4815
  }
4885
4816
  function createBlockedStream(reason) {
4886
- return new ReadableStream({
4817
+ return new web.ReadableStream({
4887
4818
  start(controller) {
4888
4819
  const id = crypto.randomUUID();
4889
4820
  controller.enqueue({