@puckeditor/cloud-client 0.8.0-canary.fdb02235 → 0.8.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.
@@ -13,13 +13,13 @@ var tool = (t) => t;
13
13
  // src/api/chat.ts
14
14
  init_react_import();
15
15
 
16
- // ../../node_modules/.pnpm/ai@6.0.197_zod@4.3.6/node_modules/ai/dist/index.mjs
16
+ // ../../node_modules/.pnpm/ai@6.0.230_zod@4.3.6/node_modules/ai/dist/index.mjs
17
17
  init_react_import();
18
18
 
19
- // ../../node_modules/.pnpm/@ai-sdk+provider-utils@4.0.27_zod@4.3.6/node_modules/@ai-sdk/provider-utils/dist/index.mjs
19
+ // ../../node_modules/.pnpm/@ai-sdk+provider-utils@4.0.40_zod@4.3.6/node_modules/@ai-sdk/provider-utils/dist/index.mjs
20
20
  init_react_import();
21
21
 
22
- // ../../node_modules/.pnpm/@ai-sdk+provider@3.0.10/node_modules/@ai-sdk/provider/dist/index.mjs
22
+ // ../../node_modules/.pnpm/@ai-sdk+provider@3.0.14/node_modules/@ai-sdk/provider/dist/index.mjs
23
23
  init_react_import();
24
24
  var marker = "vercel.ai.error";
25
25
  var symbol = Symbol.for(marker);
@@ -899,7 +899,7 @@ var NEVER = Object.freeze({
899
899
  status: "aborted"
900
900
  });
901
901
  // @__NO_SIDE_EFFECTS__
902
- function $constructor(name21, initializer3, params) {
902
+ function $constructor(name23, initializer3, params) {
903
903
  function init(inst, def) {
904
904
  if (!inst._zod) {
905
905
  Object.defineProperty(inst, "_zod", {
@@ -911,10 +911,10 @@ function $constructor(name21, initializer3, params) {
911
911
  enumerable: false
912
912
  });
913
913
  }
914
- if (inst._zod.traits.has(name21)) {
914
+ if (inst._zod.traits.has(name23)) {
915
915
  return;
916
916
  }
917
- inst._zod.traits.add(name21);
917
+ inst._zod.traits.add(name23);
918
918
  initializer3(inst, def);
919
919
  const proto = _.prototype;
920
920
  const keys = Object.keys(proto);
@@ -928,12 +928,12 @@ function $constructor(name21, initializer3, params) {
928
928
  const Parent = params?.Parent ?? Object;
929
929
  class Definition extends Parent {
930
930
  }
931
- Object.defineProperty(Definition, "name", { value: name21 });
931
+ Object.defineProperty(Definition, "name", { value: name23 });
932
932
  function _(def) {
933
- var _a21;
933
+ var _a23;
934
934
  const inst = params?.Parent ? new Definition() : this;
935
935
  init(inst, def);
936
- (_a21 = inst._zod).deferred ?? (_a21.deferred = []);
936
+ (_a23 = inst._zod).deferred ?? (_a23.deferred = []);
937
937
  for (const fn of inst._zod.deferred) {
938
938
  fn();
939
939
  }
@@ -944,10 +944,10 @@ function $constructor(name21, initializer3, params) {
944
944
  value: (inst) => {
945
945
  if (params?.Parent && inst instanceof params.Parent)
946
946
  return true;
947
- return inst?._zod?.traits?.has(name21);
947
+ return inst?._zod?.traits?.has(name23);
948
948
  }
949
949
  });
950
- Object.defineProperty(_, "name", { value: name21 });
950
+ Object.defineProperty(_, "name", { value: name23 });
951
951
  return _;
952
952
  }
953
953
  var $brand = Symbol("zod_brand");
@@ -957,8 +957,8 @@ var $ZodAsyncError = class extends Error {
957
957
  }
958
958
  };
959
959
  var $ZodEncodeError = class extends Error {
960
- constructor(name21) {
961
- super(`Encountered unidirectional transform during encode: ${name21}`);
960
+ constructor(name23) {
961
+ super(`Encountered unidirectional transform during encode: ${name23}`);
962
962
  this.name = "ZodEncodeError";
963
963
  }
964
964
  };
@@ -1537,8 +1537,8 @@ function aborted(x, startIndex = 0) {
1537
1537
  }
1538
1538
  function prefixIssues(path, issues) {
1539
1539
  return issues.map((iss) => {
1540
- var _a21;
1541
- (_a21 = iss).path ?? (_a21.path = []);
1540
+ var _a23;
1541
+ (_a23 = iss).path ?? (_a23.path = []);
1542
1542
  iss.path.unshift(path);
1543
1543
  return iss;
1544
1544
  });
@@ -1723,7 +1723,7 @@ function formatError(error48, mapper = (issue2) => issue2.message) {
1723
1723
  function treeifyError(error48, mapper = (issue2) => issue2.message) {
1724
1724
  const result = { errors: [] };
1725
1725
  const processError = (error49, path = []) => {
1726
- var _a21, _b16;
1726
+ var _a23, _b16;
1727
1727
  for (const issue2 of error49.issues) {
1728
1728
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1729
1729
  issue2.errors.map((issues) => processError({ issues }, issue2.path));
@@ -1744,7 +1744,7 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
1744
1744
  const terminal = i === fullpath.length - 1;
1745
1745
  if (typeof el === "string") {
1746
1746
  curr.properties ?? (curr.properties = {});
1747
- (_a21 = curr.properties)[el] ?? (_a21[el] = { errors: [] });
1747
+ (_a23 = curr.properties)[el] ?? (_a23[el] = { errors: [] });
1748
1748
  curr = curr.properties[el];
1749
1749
  } else {
1750
1750
  curr.items ?? (curr.items = []);
@@ -2045,10 +2045,10 @@ var sha512_base64url = /* @__PURE__ */ fixedBase64url(86);
2045
2045
 
2046
2046
  // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.js
2047
2047
  var $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
2048
- var _a21;
2048
+ var _a23;
2049
2049
  inst._zod ?? (inst._zod = {});
2050
2050
  inst._zod.def = def;
2051
- (_a21 = inst._zod).onattach ?? (_a21.onattach = []);
2051
+ (_a23 = inst._zod).onattach ?? (_a23.onattach = []);
2052
2052
  });
2053
2053
  var numericOriginMap = {
2054
2054
  number: "number",
@@ -2114,8 +2114,8 @@ var $ZodCheckGreaterThan = /* @__PURE__ */ $constructor("$ZodCheckGreaterThan",
2114
2114
  var $ZodCheckMultipleOf = /* @__PURE__ */ $constructor("$ZodCheckMultipleOf", (inst, def) => {
2115
2115
  $ZodCheck.init(inst, def);
2116
2116
  inst._zod.onattach.push((inst2) => {
2117
- var _a21;
2118
- (_a21 = inst2._zod.bag).multipleOf ?? (_a21.multipleOf = def.value);
2117
+ var _a23;
2118
+ (_a23 = inst2._zod.bag).multipleOf ?? (_a23.multipleOf = def.value);
2119
2119
  });
2120
2120
  inst._zod.check = (payload) => {
2121
2121
  if (typeof payload.value !== typeof def.value)
@@ -2248,9 +2248,9 @@ var $ZodCheckBigIntFormat = /* @__PURE__ */ $constructor("$ZodCheckBigIntFormat"
2248
2248
  };
2249
2249
  });
2250
2250
  var $ZodCheckMaxSize = /* @__PURE__ */ $constructor("$ZodCheckMaxSize", (inst, def) => {
2251
- var _a21;
2251
+ var _a23;
2252
2252
  $ZodCheck.init(inst, def);
2253
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2253
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2254
2254
  const val = payload.value;
2255
2255
  return !nullish(val) && val.size !== void 0;
2256
2256
  });
@@ -2276,9 +2276,9 @@ var $ZodCheckMaxSize = /* @__PURE__ */ $constructor("$ZodCheckMaxSize", (inst, d
2276
2276
  };
2277
2277
  });
2278
2278
  var $ZodCheckMinSize = /* @__PURE__ */ $constructor("$ZodCheckMinSize", (inst, def) => {
2279
- var _a21;
2279
+ var _a23;
2280
2280
  $ZodCheck.init(inst, def);
2281
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2281
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2282
2282
  const val = payload.value;
2283
2283
  return !nullish(val) && val.size !== void 0;
2284
2284
  });
@@ -2304,9 +2304,9 @@ var $ZodCheckMinSize = /* @__PURE__ */ $constructor("$ZodCheckMinSize", (inst, d
2304
2304
  };
2305
2305
  });
2306
2306
  var $ZodCheckSizeEquals = /* @__PURE__ */ $constructor("$ZodCheckSizeEquals", (inst, def) => {
2307
- var _a21;
2307
+ var _a23;
2308
2308
  $ZodCheck.init(inst, def);
2309
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2309
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2310
2310
  const val = payload.value;
2311
2311
  return !nullish(val) && val.size !== void 0;
2312
2312
  });
@@ -2334,9 +2334,9 @@ var $ZodCheckSizeEquals = /* @__PURE__ */ $constructor("$ZodCheckSizeEquals", (i
2334
2334
  };
2335
2335
  });
2336
2336
  var $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
2337
- var _a21;
2337
+ var _a23;
2338
2338
  $ZodCheck.init(inst, def);
2339
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2339
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2340
2340
  const val = payload.value;
2341
2341
  return !nullish(val) && val.length !== void 0;
2342
2342
  });
@@ -2363,9 +2363,9 @@ var $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (ins
2363
2363
  };
2364
2364
  });
2365
2365
  var $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
2366
- var _a21;
2366
+ var _a23;
2367
2367
  $ZodCheck.init(inst, def);
2368
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2368
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2369
2369
  const val = payload.value;
2370
2370
  return !nullish(val) && val.length !== void 0;
2371
2371
  });
@@ -2392,9 +2392,9 @@ var $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (ins
2392
2392
  };
2393
2393
  });
2394
2394
  var $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
2395
- var _a21;
2395
+ var _a23;
2396
2396
  $ZodCheck.init(inst, def);
2397
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2397
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2398
2398
  const val = payload.value;
2399
2399
  return !nullish(val) && val.length !== void 0;
2400
2400
  });
@@ -2423,7 +2423,7 @@ var $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals"
2423
2423
  };
2424
2424
  });
2425
2425
  var $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
2426
- var _a21, _b16;
2426
+ var _a23, _b16;
2427
2427
  $ZodCheck.init(inst, def);
2428
2428
  inst._zod.onattach.push((inst2) => {
2429
2429
  const bag = inst2._zod.bag;
@@ -2434,7 +2434,7 @@ var $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat"
2434
2434
  }
2435
2435
  });
2436
2436
  if (def.pattern)
2437
- (_a21 = inst._zod).check ?? (_a21.check = (payload) => {
2437
+ (_a23 = inst._zod).check ?? (_a23.check = (payload) => {
2438
2438
  def.pattern.lastIndex = 0;
2439
2439
  if (def.pattern.test(payload.value))
2440
2440
  return;
@@ -2638,7 +2638,7 @@ var version = {
2638
2638
 
2639
2639
  // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.js
2640
2640
  var $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
2641
- var _a21;
2641
+ var _a23;
2642
2642
  inst ?? (inst = {});
2643
2643
  inst._zod.def = def;
2644
2644
  inst._zod.bag = inst._zod.bag || {};
@@ -2653,7 +2653,7 @@ var $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
2653
2653
  }
2654
2654
  }
2655
2655
  if (checks.length === 0) {
2656
- (_a21 = inst._zod).deferred ?? (_a21.deferred = []);
2656
+ (_a23 = inst._zod).deferred ?? (_a23.deferred = []);
2657
2657
  inst._zod.deferred?.push(() => {
2658
2658
  inst._zod.run = inst._zod.parse;
2659
2659
  });
@@ -11353,7 +11353,7 @@ function initializeContext(params) {
11353
11353
  };
11354
11354
  }
11355
11355
  function process2(schema, ctx, _params = { path: [], schemaPath: [] }) {
11356
- var _a21;
11356
+ var _a23;
11357
11357
  const def = schema._zod.def;
11358
11358
  const seen = ctx.seen.get(schema);
11359
11359
  if (seen) {
@@ -11401,7 +11401,7 @@ function process2(schema, ctx, _params = { path: [], schemaPath: [] }) {
11401
11401
  delete result.schema.default;
11402
11402
  }
11403
11403
  if (ctx.io === "input" && result.schema._prefault)
11404
- (_a21 = result.schema).default ?? (_a21.default = result.schema._prefault);
11404
+ (_a23 = result.schema).default ?? (_a23.default = result.schema._prefault);
11405
11405
  delete result.schema._prefault;
11406
11406
  const _result = ctx.seen.get(schema);
11407
11407
  return _result.schema;
@@ -18136,8 +18136,15 @@ var nullableType = ZodNullable2.create;
18136
18136
  var preprocessType = ZodEffects.createWithPreprocess;
18137
18137
  var pipelineType = ZodPipeline.create;
18138
18138
 
18139
- // ../../node_modules/.pnpm/@ai-sdk+provider-utils@4.0.27_zod@4.3.6/node_modules/@ai-sdk/provider-utils/dist/index.mjs
18139
+ // ../../node_modules/.pnpm/@ai-sdk+provider-utils@4.0.40_zod@4.3.6/node_modules/@ai-sdk/provider-utils/dist/index.mjs
18140
18140
  var { btoa: btoa2, atob: atob2 } = globalThis;
18141
+ async function cancelResponseBody(response) {
18142
+ var _a23;
18143
+ try {
18144
+ await ((_a23 = response.body) == null ? void 0 : _a23.cancel());
18145
+ } catch (e) {
18146
+ }
18147
+ }
18141
18148
  var name14 = "AI_DownloadError";
18142
18149
  var marker15 = `vercel.ai.error.${name14}`;
18143
18150
  var symbol16 = Symbol.for(marker15);
@@ -18161,58 +18168,8 @@ var DownloadError = class extends (_b15 = AISDKError, _a16 = symbol16, _b15) {
18161
18168
  return AISDKError.hasMarker(error48, marker15);
18162
18169
  }
18163
18170
  };
18164
- var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
18165
- async function readResponseWithSizeLimit({
18166
- response,
18167
- url: url2,
18168
- maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
18169
- }) {
18170
- const contentLength = response.headers.get("content-length");
18171
- if (contentLength != null) {
18172
- const length = parseInt(contentLength, 10);
18173
- if (!isNaN(length) && length > maxBytes) {
18174
- throw new DownloadError({
18175
- url: url2,
18176
- message: `Download of ${url2} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
18177
- });
18178
- }
18179
- }
18180
- const body = response.body;
18181
- if (body == null) {
18182
- return new Uint8Array(0);
18183
- }
18184
- const reader = body.getReader();
18185
- const chunks = [];
18186
- let totalBytes = 0;
18187
- try {
18188
- while (true) {
18189
- const { done, value } = await reader.read();
18190
- if (done) {
18191
- break;
18192
- }
18193
- totalBytes += value.length;
18194
- if (totalBytes > maxBytes) {
18195
- throw new DownloadError({
18196
- url: url2,
18197
- message: `Download of ${url2} exceeded maximum size of ${maxBytes} bytes.`
18198
- });
18199
- }
18200
- chunks.push(value);
18201
- }
18202
- } finally {
18203
- try {
18204
- await reader.cancel();
18205
- } finally {
18206
- reader.releaseLock();
18207
- }
18208
- }
18209
- const result = new Uint8Array(totalBytes);
18210
- let offset = 0;
18211
- for (const chunk of chunks) {
18212
- result.set(chunk, offset);
18213
- offset += chunk.length;
18214
- }
18215
- return result;
18171
+ function isBrowserRuntime(globalThisAny = globalThis) {
18172
+ return globalThisAny.window != null;
18216
18173
  }
18217
18174
  function validateDownloadUrl(url2) {
18218
18175
  let parsed;
@@ -18233,7 +18190,7 @@ function validateDownloadUrl(url2) {
18233
18190
  message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
18234
18191
  });
18235
18192
  }
18236
- const hostname3 = parsed.hostname;
18193
+ const hostname3 = parsed.hostname.toLowerCase().replace(/\.+$/, "");
18237
18194
  if (!hostname3) {
18238
18195
  throw new DownloadError({
18239
18196
  url: url2,
@@ -18276,41 +18233,175 @@ function isIPv4(hostname3) {
18276
18233
  }
18277
18234
  function isPrivateIPv4(ip) {
18278
18235
  const parts = ip.split(".").map(Number);
18279
- const [a, b] = parts;
18236
+ const [a, b, c] = parts;
18280
18237
  if (a === 0) return true;
18281
18238
  if (a === 10) return true;
18239
+ if (a === 100 && b >= 64 && b <= 127) return true;
18282
18240
  if (a === 127) return true;
18283
18241
  if (a === 169 && b === 254) return true;
18284
18242
  if (a === 172 && b >= 16 && b <= 31) return true;
18243
+ if (a === 192 && b === 0 && c === 0) return true;
18285
18244
  if (a === 192 && b === 168) return true;
18245
+ if (a === 198 && (b === 18 || b === 19)) return true;
18246
+ if (a >= 240) return true;
18286
18247
  return false;
18287
18248
  }
18249
+ function parseIPv6(ip) {
18250
+ let address = ip.toLowerCase();
18251
+ const zoneIndex = address.indexOf("%");
18252
+ if (zoneIndex !== -1) {
18253
+ address = address.slice(0, zoneIndex);
18254
+ }
18255
+ const halves = address.split("::");
18256
+ if (halves.length > 2) return null;
18257
+ const toGroups = (segment) => {
18258
+ if (segment === "") return [];
18259
+ const groups = [];
18260
+ const parts = segment.split(":");
18261
+ for (let i = 0; i < parts.length; i++) {
18262
+ const part = parts[i];
18263
+ if (part.includes(".")) {
18264
+ if (i !== parts.length - 1 || !isIPv4(part)) return null;
18265
+ const [a, b, c, d] = part.split(".").map(Number);
18266
+ groups.push(a << 8 | b, c << 8 | d);
18267
+ continue;
18268
+ }
18269
+ if (!/^[0-9a-f]{1,4}$/.test(part)) return null;
18270
+ groups.push(parseInt(part, 16));
18271
+ }
18272
+ return groups;
18273
+ };
18274
+ const head = toGroups(halves[0]);
18275
+ if (head === null) return null;
18276
+ if (halves.length === 2) {
18277
+ const tail = toGroups(halves[1]);
18278
+ if (tail === null) return null;
18279
+ const fill = 8 - head.length - tail.length;
18280
+ if (fill < 0) return null;
18281
+ return [...head, ...new Array(fill).fill(0), ...tail];
18282
+ }
18283
+ return head.length === 8 ? head : null;
18284
+ }
18288
18285
  function isPrivateIPv6(ip) {
18289
- const normalized = ip.toLowerCase();
18290
- if (normalized === "::1") return true;
18291
- if (normalized === "::") return true;
18292
- if (normalized.startsWith("::ffff:")) {
18293
- const mappedPart = normalized.slice(7);
18294
- if (isIPv4(mappedPart)) {
18295
- return isPrivateIPv4(mappedPart);
18296
- }
18297
- const hexParts = mappedPart.split(":");
18298
- if (hexParts.length === 2) {
18299
- const high = parseInt(hexParts[0], 16);
18300
- const low = parseInt(hexParts[1], 16);
18301
- if (!isNaN(high) && !isNaN(low)) {
18302
- const a = high >> 8 & 255;
18303
- const b = high & 255;
18304
- const c = low >> 8 & 255;
18305
- const d = low & 255;
18306
- return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
18307
- }
18308
- }
18309
- }
18310
- if (normalized.startsWith("fc") || normalized.startsWith("fd")) return true;
18311
- if (normalized.startsWith("fe80")) return true;
18286
+ const groups = parseIPv6(ip);
18287
+ if (groups === null) return true;
18288
+ const topZero = (count) => groups.slice(0, count).every((group) => group === 0);
18289
+ if (topZero(7) && (groups[7] === 0 || groups[7] === 1)) return true;
18290
+ if ((groups[0] & 65024) === 64512) return true;
18291
+ if ((groups[0] & 65472) === 65152) return true;
18292
+ if ((groups[0] & 65472) === 65216) return true;
18293
+ if ((groups[0] & 65280) === 65280) return true;
18294
+ const embedsIPv4 = (
18295
+ // ::/96 IPv4-compatible (deprecated)
18296
+ topZero(6) || // ::ffff:0:0/96 — IPv4-mapped (ffff in group 5)
18297
+ topZero(5) && groups[5] === 65535 || // ::ffff:0:0/96 — IPv4-translated form (ffff in group 4, group 5 zero)
18298
+ topZero(4) && groups[4] === 65535 && groups[5] === 0 || // 64:ff9b::/96 — NAT64 well-known prefix
18299
+ groups[0] === 100 && groups[1] === 65435 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 0 || // 64:ff9b:1::/48 — NAT64 local-use prefix
18300
+ groups[0] === 100 && groups[1] === 65435 && groups[2] === 1
18301
+ );
18302
+ if (embedsIPv4) {
18303
+ const a = groups[6] >> 8 & 255;
18304
+ const b = groups[6] & 255;
18305
+ const c = groups[7] >> 8 & 255;
18306
+ const d = groups[7] & 255;
18307
+ return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
18308
+ }
18312
18309
  return false;
18313
18310
  }
18311
+ var MAX_DOWNLOAD_REDIRECTS = 10;
18312
+ async function fetchWithValidatedRedirects({
18313
+ url: url2,
18314
+ headers,
18315
+ abortSignal,
18316
+ maxRedirects = MAX_DOWNLOAD_REDIRECTS
18317
+ }) {
18318
+ const baseInit = { signal: abortSignal };
18319
+ if (headers !== void 0) {
18320
+ baseInit.headers = headers;
18321
+ }
18322
+ let currentUrl = url2;
18323
+ for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
18324
+ validateDownloadUrl(currentUrl);
18325
+ const response = await fetch(currentUrl, {
18326
+ ...baseInit,
18327
+ redirect: "manual"
18328
+ });
18329
+ if (response.type === "opaqueredirect") {
18330
+ if (!isBrowserRuntime()) {
18331
+ throw new DownloadError({
18332
+ url: url2,
18333
+ message: `Redirect from ${currentUrl} could not be validated and was blocked`
18334
+ });
18335
+ }
18336
+ return await fetch(currentUrl, { ...baseInit, redirect: "follow" });
18337
+ }
18338
+ const location = response.headers.get("location");
18339
+ if (response.status >= 300 && response.status < 400 && location) {
18340
+ await cancelResponseBody(response);
18341
+ currentUrl = new URL(location, currentUrl).toString();
18342
+ continue;
18343
+ }
18344
+ return response;
18345
+ }
18346
+ throw new DownloadError({
18347
+ url: url2,
18348
+ message: `Too many redirects (max ${maxRedirects})`
18349
+ });
18350
+ }
18351
+ var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
18352
+ async function readResponseWithSizeLimit({
18353
+ response,
18354
+ url: url2,
18355
+ maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
18356
+ }) {
18357
+ const contentLength = response.headers.get("content-length");
18358
+ if (contentLength != null) {
18359
+ const length = parseInt(contentLength, 10);
18360
+ if (!isNaN(length) && length > maxBytes) {
18361
+ await cancelResponseBody(response);
18362
+ throw new DownloadError({
18363
+ url: url2,
18364
+ message: `Download of ${url2} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
18365
+ });
18366
+ }
18367
+ }
18368
+ const body = response.body;
18369
+ if (body == null) {
18370
+ return new Uint8Array(0);
18371
+ }
18372
+ const reader = body.getReader();
18373
+ const chunks = [];
18374
+ let totalBytes = 0;
18375
+ try {
18376
+ while (true) {
18377
+ const { done, value } = await reader.read();
18378
+ if (done) {
18379
+ break;
18380
+ }
18381
+ totalBytes += value.length;
18382
+ if (totalBytes > maxBytes) {
18383
+ throw new DownloadError({
18384
+ url: url2,
18385
+ message: `Download of ${url2} exceeded maximum size of ${maxBytes} bytes.`
18386
+ });
18387
+ }
18388
+ chunks.push(value);
18389
+ }
18390
+ } finally {
18391
+ try {
18392
+ await reader.cancel();
18393
+ } finally {
18394
+ reader.releaseLock();
18395
+ }
18396
+ }
18397
+ const result = new Uint8Array(totalBytes);
18398
+ let offset = 0;
18399
+ for (const chunk of chunks) {
18400
+ result.set(chunk, offset);
18401
+ offset += chunk.length;
18402
+ }
18403
+ return result;
18404
+ }
18314
18405
  var createIdGenerator = ({
18315
18406
  prefix,
18316
18407
  size = 16,
@@ -18337,18 +18428,6 @@ var createIdGenerator = ({
18337
18428
  return () => `${prefix}${separator}${generator()}`;
18338
18429
  };
18339
18430
  var generateId = createIdGenerator();
18340
- function getErrorMessage2(error48) {
18341
- if (error48 == null) {
18342
- return "unknown error";
18343
- }
18344
- if (typeof error48 === "string") {
18345
- return error48;
18346
- }
18347
- if (error48 instanceof Error) {
18348
- return error48.message;
18349
- }
18350
- return JSON.stringify(error48);
18351
- }
18352
18431
  function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
18353
18432
  var _a23, _b22, _c;
18354
18433
  if (globalThisAny.window) {
@@ -19605,15 +19684,26 @@ function isSchema(value) {
19605
19684
  return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
19606
19685
  }
19607
19686
  function asSchema(schema) {
19608
- return schema == null ? jsonSchema({ properties: {}, additionalProperties: false }) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
19687
+ return schema == null ? jsonSchema({
19688
+ type: "object",
19689
+ properties: {},
19690
+ additionalProperties: false
19691
+ }) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
19609
19692
  }
19610
19693
  function standardSchema(standardSchema2) {
19611
19694
  return jsonSchema(
19612
- () => addAdditionalPropertiesToJsonSchema(
19613
- standardSchema2["~standard"].jsonSchema.input({
19614
- target: "draft-07"
19615
- })
19616
- ),
19695
+ () => {
19696
+ if (!hasStandardJsonSchema(standardSchema2)) {
19697
+ throw new Error(
19698
+ `Standard schema vendor '${standardSchema2["~standard"].vendor}' does not support JSON Schema conversion.`
19699
+ );
19700
+ }
19701
+ return addAdditionalPropertiesToJsonSchema(
19702
+ standardSchema2["~standard"].jsonSchema.input({
19703
+ target: "draft-07"
19704
+ })
19705
+ );
19706
+ },
19617
19707
  {
19618
19708
  validate: async (value) => {
19619
19709
  const result = await standardSchema2["~standard"].validate(value);
@@ -19628,6 +19718,9 @@ function standardSchema(standardSchema2) {
19628
19718
  }
19629
19719
  );
19630
19720
  }
19721
+ function hasStandardJsonSchema(schema) {
19722
+ return schema["~standard"].jsonSchema != null;
19723
+ }
19631
19724
  function zod3Schema(zodSchema2, options) {
19632
19725
  var _a23;
19633
19726
  const useReferences = (_a23 = options == null ? void 0 : options.useReferences) != null ? _a23 : false;
@@ -19736,12 +19829,13 @@ async function resolve(value) {
19736
19829
  }
19737
19830
  return Promise.resolve(value);
19738
19831
  }
19832
+ var textDecoder = new TextDecoder();
19739
19833
 
19740
- // ../../node_modules/.pnpm/ai@6.0.197_zod@4.3.6/node_modules/ai/dist/index.mjs
19834
+ // ../../node_modules/.pnpm/ai@6.0.230_zod@4.3.6/node_modules/ai/dist/index.mjs
19741
19835
  var __defProp = Object.defineProperty;
19742
19836
  var __export2 = (target, all) => {
19743
- for (var name21 in all)
19744
- __defProp(target, name21, { get: all[name21], enumerable: true });
19837
+ for (var name222 in all)
19838
+ __defProp(target, name222, { get: all[name222], enumerable: true });
19745
19839
  };
19746
19840
  var name15 = "AI_InvalidArgumentError";
19747
19841
  var marker16 = `vercel.ai.error.${name15}`;
@@ -19758,30 +19852,35 @@ var marker32 = `vercel.ai.error.${name32}`;
19758
19852
  var symbol32 = Symbol.for(marker32);
19759
19853
  var _a32;
19760
19854
  _a32 = symbol32;
19761
- var name42 = "AI_InvalidToolInputError";
19855
+ var name42 = "AI_InvalidToolApprovalSignatureError";
19762
19856
  var marker42 = `vercel.ai.error.${name42}`;
19763
19857
  var symbol42 = Symbol.for(marker42);
19764
19858
  var _a42;
19765
19859
  _a42 = symbol42;
19766
- var name52 = "AI_ToolCallNotFoundForApprovalError";
19860
+ var name52 = "AI_InvalidToolInputError";
19767
19861
  var marker52 = `vercel.ai.error.${name52}`;
19768
19862
  var symbol52 = Symbol.for(marker52);
19769
19863
  var _a52;
19770
19864
  _a52 = symbol52;
19771
- var name62 = "AI_MissingToolResultsError";
19865
+ var name62 = "AI_ToolCallNotFoundForApprovalError";
19772
19866
  var marker62 = `vercel.ai.error.${name62}`;
19773
19867
  var symbol62 = Symbol.for(marker62);
19774
19868
  var _a62;
19775
19869
  _a62 = symbol62;
19776
- var name72 = "AI_NoImageGeneratedError";
19870
+ var name72 = "AI_MissingToolResultsError";
19777
19871
  var marker72 = `vercel.ai.error.${name72}`;
19778
19872
  var symbol72 = Symbol.for(marker72);
19779
19873
  var _a72;
19780
19874
  _a72 = symbol72;
19781
- var name82 = "AI_NoObjectGeneratedError";
19875
+ var name82 = "AI_NoImageGeneratedError";
19782
19876
  var marker82 = `vercel.ai.error.${name82}`;
19783
19877
  var symbol82 = Symbol.for(marker82);
19784
19878
  var _a82;
19879
+ _a82 = symbol82;
19880
+ var name92 = "AI_NoObjectGeneratedError";
19881
+ var marker92 = `vercel.ai.error.${name92}`;
19882
+ var symbol92 = Symbol.for(marker92);
19883
+ var _a92;
19785
19884
  var NoObjectGeneratedError = class extends AISDKError {
19786
19885
  constructor({
19787
19886
  message = "No object generated.",
@@ -19791,110 +19890,109 @@ var NoObjectGeneratedError = class extends AISDKError {
19791
19890
  usage,
19792
19891
  finishReason
19793
19892
  }) {
19794
- super({ name: name82, message, cause });
19795
- this[_a82] = true;
19893
+ super({ name: name92, message, cause });
19894
+ this[_a92] = true;
19796
19895
  this.text = text2;
19797
19896
  this.response = response;
19798
19897
  this.usage = usage;
19799
19898
  this.finishReason = finishReason;
19800
19899
  }
19801
19900
  static isInstance(error48) {
19802
- return AISDKError.hasMarker(error48, marker82);
19901
+ return AISDKError.hasMarker(error48, marker92);
19803
19902
  }
19804
19903
  };
19805
- _a82 = symbol82;
19806
- var name92 = "AI_NoOutputGeneratedError";
19807
- var marker92 = `vercel.ai.error.${name92}`;
19808
- var symbol92 = Symbol.for(marker92);
19809
- var _a92;
19810
19904
  _a92 = symbol92;
19811
- var name102 = "AI_NoSpeechGeneratedError";
19905
+ var name102 = "AI_NoOutputGeneratedError";
19812
19906
  var marker102 = `vercel.ai.error.${name102}`;
19813
19907
  var symbol102 = Symbol.for(marker102);
19814
19908
  var _a102;
19815
19909
  _a102 = symbol102;
19816
- var name112 = "AI_NoTranscriptGeneratedError";
19910
+ var name112 = "AI_NoSpeechGeneratedError";
19817
19911
  var marker112 = `vercel.ai.error.${name112}`;
19818
19912
  var symbol112 = Symbol.for(marker112);
19819
19913
  var _a112;
19820
19914
  _a112 = symbol112;
19821
- var name122 = "AI_NoVideoGeneratedError";
19915
+ var name122 = "AI_NoTranscriptGeneratedError";
19822
19916
  var marker122 = `vercel.ai.error.${name122}`;
19823
19917
  var symbol122 = Symbol.for(marker122);
19824
19918
  var _a122;
19825
19919
  _a122 = symbol122;
19826
- var name132 = "AI_NoSuchToolError";
19920
+ var name132 = "AI_NoVideoGeneratedError";
19827
19921
  var marker132 = `vercel.ai.error.${name132}`;
19828
19922
  var symbol132 = Symbol.for(marker132);
19829
19923
  var _a132;
19830
19924
  _a132 = symbol132;
19831
- var name142 = "AI_ToolCallRepairError";
19925
+ var name142 = "AI_NoSuchToolError";
19832
19926
  var marker142 = `vercel.ai.error.${name142}`;
19833
19927
  var symbol142 = Symbol.for(marker142);
19834
19928
  var _a142;
19835
19929
  _a142 = symbol142;
19836
- var name152 = "AI_UIMessageStreamError";
19930
+ var name152 = "AI_ToolCallRepairError";
19837
19931
  var marker152 = `vercel.ai.error.${name152}`;
19838
19932
  var symbol152 = Symbol.for(marker152);
19839
19933
  var _a152;
19934
+ _a152 = symbol152;
19935
+ var name16 = "AI_UIMessageStreamError";
19936
+ var marker162 = `vercel.ai.error.${name16}`;
19937
+ var symbol162 = Symbol.for(marker162);
19938
+ var _a162;
19840
19939
  var UIMessageStreamError = class extends AISDKError {
19841
19940
  constructor({
19842
19941
  chunkType,
19843
19942
  chunkId,
19844
19943
  message
19845
19944
  }) {
19846
- super({ name: name152, message });
19847
- this[_a152] = true;
19945
+ super({ name: name16, message });
19946
+ this[_a162] = true;
19848
19947
  this.chunkType = chunkType;
19849
19948
  this.chunkId = chunkId;
19850
19949
  }
19851
19950
  static isInstance(error48) {
19852
- return AISDKError.hasMarker(error48, marker152);
19951
+ return AISDKError.hasMarker(error48, marker162);
19853
19952
  }
19854
19953
  };
19855
- _a152 = symbol152;
19856
- var name16 = "AI_InvalidDataContentError";
19857
- var marker162 = `vercel.ai.error.${name16}`;
19858
- var symbol162 = Symbol.for(marker162);
19859
- var _a162;
19860
19954
  _a162 = symbol162;
19861
- var name17 = "AI_InvalidMessageRoleError";
19955
+ var name17 = "AI_InvalidDataContentError";
19862
19956
  var marker17 = `vercel.ai.error.${name17}`;
19863
19957
  var symbol172 = Symbol.for(marker17);
19864
19958
  var _a172;
19865
19959
  _a172 = symbol172;
19866
- var name18 = "AI_MessageConversionError";
19960
+ var name18 = "AI_InvalidMessageRoleError";
19867
19961
  var marker18 = `vercel.ai.error.${name18}`;
19868
19962
  var symbol18 = Symbol.for(marker18);
19869
19963
  var _a18;
19870
19964
  _a18 = symbol18;
19871
- var name19 = "AI_RetryError";
19965
+ var name19 = "AI_MessageConversionError";
19872
19966
  var marker19 = `vercel.ai.error.${name19}`;
19873
19967
  var symbol19 = Symbol.for(marker19);
19874
19968
  var _a19;
19875
19969
  _a19 = symbol19;
19876
- var VERSION = true ? "6.0.197" : "0.0.0-test";
19970
+ var name20 = "AI_RetryError";
19971
+ var marker20 = `vercel.ai.error.${name20}`;
19972
+ var symbol20 = Symbol.for(marker20);
19973
+ var _a20;
19974
+ _a20 = symbol20;
19975
+ var VERSION = true ? "6.0.230" : "0.0.0-test";
19877
19976
  var download = async ({
19878
19977
  url: url2,
19879
19978
  maxBytes,
19880
19979
  abortSignal
19881
19980
  }) => {
19882
- var _a21;
19981
+ var _a222;
19883
19982
  const urlText = url2.toString();
19884
- validateDownloadUrl(urlText);
19885
19983
  try {
19886
- const response = await fetch(urlText, {
19887
- headers: withUserAgentSuffix(
19888
- {},
19889
- `ai-sdk/${VERSION}`,
19890
- getRuntimeEnvironmentUserAgent()
19891
- ),
19892
- signal: abortSignal
19984
+ const headers = withUserAgentSuffix(
19985
+ {},
19986
+ `ai-sdk/${VERSION}`,
19987
+ getRuntimeEnvironmentUserAgent()
19988
+ );
19989
+ const response = await fetchWithValidatedRedirects({
19990
+ url: urlText,
19991
+ headers,
19992
+ abortSignal
19893
19993
  });
19894
- if (response.redirected) {
19895
- validateDownloadUrl(response.url);
19896
- }
19897
19994
  if (!response.ok) {
19995
+ await cancelResponseBody(response);
19898
19996
  throw new DownloadError({
19899
19997
  url: urlText,
19900
19998
  statusCode: response.status,
@@ -19908,7 +20006,7 @@ var download = async ({
19908
20006
  });
19909
20007
  return {
19910
20008
  data,
19911
- mediaType: (_a21 = response.headers.get("content-type")) != null ? _a21 : void 0
20009
+ mediaType: (_a222 = response.headers.get("content-type")) != null ? _a222 : void 0
19912
20010
  };
19913
20011
  } catch (error48) {
19914
20012
  if (DownloadError.isInstance(error48)) {
@@ -19924,8 +20022,8 @@ var dataContentSchema = external_exports.union([
19924
20022
  external_exports.custom(
19925
20023
  // Buffer might not be available in some environments such as CloudFlare:
19926
20024
  (value) => {
19927
- var _a21, _b16;
19928
- return (_b16 = (_a21 = globalThis.Buffer) == null ? void 0 : _a21.isBuffer(value)) != null ? _b16 : false;
20025
+ var _a222, _b16;
20026
+ return (_b16 = (_a222 = globalThis.Buffer) == null ? void 0 : _a222.isBuffer(value)) != null ? _b16 : false;
19929
20027
  },
19930
20028
  { message: "Must be a Buffer" }
19931
20029
  )
@@ -20154,6 +20252,7 @@ function mergeObjects(base, overrides) {
20154
20252
  }
20155
20253
  return result;
20156
20254
  }
20255
+ var encoder = new TextEncoder();
20157
20256
  var output_exports = {};
20158
20257
  __export2(output_exports, {
20159
20258
  array: () => array2,
@@ -20166,6 +20265,10 @@ function fixJson(input) {
20166
20265
  const stack = ["ROOT"];
20167
20266
  let lastValidIndex = -1;
20168
20267
  let literalStart = null;
20268
+ let unicodeEscapeDigits = 0;
20269
+ function isHexDigit(char) {
20270
+ return char >= "0" && char <= "9" || char >= "A" && char <= "F" || char >= "a" && char <= "f";
20271
+ }
20169
20272
  function processValueStart(char, i, swapState) {
20170
20273
  {
20171
20274
  switch (char) {
@@ -20370,7 +20473,22 @@ function fixJson(input) {
20370
20473
  }
20371
20474
  case "INSIDE_STRING_ESCAPE": {
20372
20475
  stack.pop();
20373
- lastValidIndex = i;
20476
+ if (char === "u") {
20477
+ unicodeEscapeDigits = 0;
20478
+ stack.push("INSIDE_STRING_UNICODE_ESCAPE");
20479
+ } else {
20480
+ lastValidIndex = i;
20481
+ }
20482
+ break;
20483
+ }
20484
+ case "INSIDE_STRING_UNICODE_ESCAPE": {
20485
+ if (isHexDigit(char)) {
20486
+ unicodeEscapeDigits++;
20487
+ if (unicodeEscapeDigits === 4) {
20488
+ stack.pop();
20489
+ lastValidIndex = i;
20490
+ }
20491
+ }
20374
20492
  break;
20375
20493
  }
20376
20494
  case "INSIDE_NUMBER": {
@@ -20507,7 +20625,7 @@ var text = () => ({
20507
20625
  });
20508
20626
  var object2 = ({
20509
20627
  schema: inputSchema,
20510
- name: name21,
20628
+ name: name222,
20511
20629
  description
20512
20630
  }) => {
20513
20631
  const schema = asSchema(inputSchema);
@@ -20516,7 +20634,7 @@ var object2 = ({
20516
20634
  responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
20517
20635
  type: "json",
20518
20636
  schema: jsonSchema2,
20519
- ...name21 != null && { name: name21 },
20637
+ ...name222 != null && { name: name222 },
20520
20638
  ...description != null && { description }
20521
20639
  })),
20522
20640
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -20570,7 +20688,7 @@ var object2 = ({
20570
20688
  };
20571
20689
  var array2 = ({
20572
20690
  element: inputElementSchema,
20573
- name: name21,
20691
+ name: name222,
20574
20692
  description
20575
20693
  }) => {
20576
20694
  const elementSchema = asSchema(inputElementSchema);
@@ -20590,7 +20708,7 @@ var array2 = ({
20590
20708
  required: ["elements"],
20591
20709
  additionalProperties: false
20592
20710
  },
20593
- ...name21 != null && { name: name21 },
20711
+ ...name222 != null && { name: name222 },
20594
20712
  ...description != null && { description }
20595
20713
  };
20596
20714
  }),
@@ -20620,6 +20738,7 @@ var array2 = ({
20620
20738
  finishReason: context2.finishReason
20621
20739
  });
20622
20740
  }
20741
+ const validatedElements = [];
20623
20742
  for (const element of outerValue.elements) {
20624
20743
  const validationResult = await safeValidateTypes({
20625
20744
  value: element,
@@ -20635,8 +20754,9 @@ var array2 = ({
20635
20754
  finishReason: context2.finishReason
20636
20755
  });
20637
20756
  }
20757
+ validatedElements.push(validationResult.value);
20638
20758
  }
20639
- return outerValue.elements;
20759
+ return validatedElements;
20640
20760
  },
20641
20761
  async parsePartialOutput({ text: text2 }) {
20642
20762
  const result = await parsePartialJson(text2);
@@ -20682,7 +20802,7 @@ var array2 = ({
20682
20802
  };
20683
20803
  var choice = ({
20684
20804
  options: choiceOptions,
20685
- name: name21,
20805
+ name: name222,
20686
20806
  description
20687
20807
  }) => {
20688
20808
  return {
@@ -20699,7 +20819,7 @@ var choice = ({
20699
20819
  required: ["result"],
20700
20820
  additionalProperties: false
20701
20821
  },
20702
- ...name21 != null && { name: name21 },
20822
+ ...name222 != null && { name: name222 },
20703
20823
  ...description != null && { description }
20704
20824
  }),
20705
20825
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -20760,14 +20880,14 @@ var choice = ({
20760
20880
  };
20761
20881
  };
20762
20882
  var json2 = ({
20763
- name: name21,
20883
+ name: name222,
20764
20884
  description
20765
20885
  } = {}) => {
20766
20886
  return {
20767
20887
  name: "json",
20768
20888
  responseFormat: Promise.resolve({
20769
20889
  type: "json",
20770
- ...name21 != null && { name: name21 },
20890
+ ...name222 != null && { name: name222 },
20771
20891
  ...description != null && { description }
20772
20892
  }),
20773
20893
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -20924,7 +21044,8 @@ var uiMessageChunkSchema = lazySchema(
20924
21044
  external_exports.strictObject({
20925
21045
  type: external_exports.literal("tool-approval-request"),
20926
21046
  approvalId: external_exports.string(),
20927
- toolCallId: external_exports.string()
21047
+ toolCallId: external_exports.string(),
21048
+ signature: external_exports.string().optional()
20928
21049
  }),
20929
21050
  external_exports.strictObject({
20930
21051
  type: external_exports.literal("tool-output-available"),
@@ -21032,6 +21153,9 @@ var uiMessageChunkSchema = lazySchema(
21032
21153
  function isDataUIMessageChunk(chunk) {
21033
21154
  return chunk.type.startsWith("data-");
21034
21155
  }
21156
+ function createIdMap() {
21157
+ return /* @__PURE__ */ Object.create(null);
21158
+ }
21035
21159
  function isStaticToolUIPart(part) {
21036
21160
  return part.type.startsWith("tool-");
21037
21161
  }
@@ -21055,9 +21179,9 @@ function createStreamingUIMessageState({
21055
21179
  role: "assistant",
21056
21180
  parts: []
21057
21181
  },
21058
- activeTextParts: {},
21059
- activeReasoningParts: {},
21060
- partialToolCalls: {}
21182
+ activeTextParts: createIdMap(),
21183
+ activeReasoningParts: createIdMap(),
21184
+ partialToolCalls: createIdMap()
21061
21185
  };
21062
21186
  }
21063
21187
  function processUIMessageStream({
@@ -21073,7 +21197,7 @@ function processUIMessageStream({
21073
21197
  new TransformStream({
21074
21198
  async transform(chunk, controller) {
21075
21199
  await runUpdateMessageJob(async ({ state, write }) => {
21076
- var _a21, _b16, _c, _d;
21200
+ var _a222, _b16, _c, _d;
21077
21201
  function getToolInvocation(toolCallId) {
21078
21202
  const toolInvocations = state.message.parts.filter(isToolUIPart);
21079
21203
  const toolInvocation = toolInvocations.find(
@@ -21089,7 +21213,7 @@ function processUIMessageStream({
21089
21213
  return toolInvocation;
21090
21214
  }
21091
21215
  function updateToolPart(options) {
21092
- var _a222;
21216
+ var _a23;
21093
21217
  const part = state.message.parts.find(
21094
21218
  (part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
21095
21219
  );
@@ -21108,7 +21232,7 @@ function processUIMessageStream({
21108
21232
  if (options.toolMetadata !== void 0) {
21109
21233
  anyPart.toolMetadata = options.toolMetadata;
21110
21234
  }
21111
- anyPart.providerExecuted = (_a222 = anyOptions.providerExecuted) != null ? _a222 : part.providerExecuted;
21235
+ anyPart.providerExecuted = (_a23 = anyOptions.providerExecuted) != null ? _a23 : part.providerExecuted;
21112
21236
  const providerMetadata = anyOptions.providerMetadata;
21113
21237
  if (providerMetadata != null) {
21114
21238
  if (options.state === "output-available" || options.state === "output-error") {
@@ -21137,7 +21261,7 @@ function processUIMessageStream({
21137
21261
  }
21138
21262
  }
21139
21263
  function updateDynamicToolPart(options) {
21140
- var _a222, _b22;
21264
+ var _a23, _b22;
21141
21265
  const part = state.message.parts.find(
21142
21266
  (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
21143
21267
  );
@@ -21149,7 +21273,7 @@ function processUIMessageStream({
21149
21273
  anyPart.input = anyOptions.input;
21150
21274
  anyPart.output = anyOptions.output;
21151
21275
  anyPart.errorText = anyOptions.errorText;
21152
- anyPart.rawInput = (_a222 = anyOptions.rawInput) != null ? _a222 : anyPart.rawInput;
21276
+ anyPart.rawInput = (_a23 = anyOptions.rawInput) != null ? _a23 : anyPart.rawInput;
21153
21277
  anyPart.preliminary = anyOptions.preliminary;
21154
21278
  if (options.title !== void 0) {
21155
21279
  anyPart.title = options.title;
@@ -21224,7 +21348,7 @@ function processUIMessageStream({
21224
21348
  });
21225
21349
  }
21226
21350
  textPart.text += chunk.delta;
21227
- textPart.providerMetadata = (_a21 = chunk.providerMetadata) != null ? _a21 : textPart.providerMetadata;
21351
+ textPart.providerMetadata = (_a222 = chunk.providerMetadata) != null ? _a222 : textPart.providerMetadata;
21228
21352
  write();
21229
21353
  break;
21230
21354
  }
@@ -21453,7 +21577,10 @@ function processUIMessageStream({
21453
21577
  case "tool-approval-request": {
21454
21578
  const toolInvocation = getToolInvocation(chunk.toolCallId);
21455
21579
  toolInvocation.state = "approval-requested";
21456
- toolInvocation.approval = { id: chunk.approvalId };
21580
+ toolInvocation.approval = {
21581
+ id: chunk.approvalId,
21582
+ ...chunk.signature != null ? { signature: chunk.signature } : {}
21583
+ };
21457
21584
  write();
21458
21585
  break;
21459
21586
  }
@@ -21531,8 +21658,8 @@ function processUIMessageStream({
21531
21658
  break;
21532
21659
  }
21533
21660
  case "finish-step": {
21534
- state.activeTextParts = {};
21535
- state.activeReasoningParts = {};
21661
+ state.activeTextParts = createIdMap();
21662
+ state.activeReasoningParts = createIdMap();
21536
21663
  break;
21537
21664
  }
21538
21665
  case "start": {
@@ -21714,7 +21841,8 @@ var originalGenerateId2 = createIdGenerator({
21714
21841
  });
21715
21842
  function createUIMessageStream({
21716
21843
  execute,
21717
- onError = getErrorMessage2,
21844
+ onError = () => "An error occurred.",
21845
+ // prevent leaking server error details to the client by default
21718
21846
  originalMessages,
21719
21847
  onStepFinish,
21720
21848
  onFinish,
@@ -21892,7 +22020,8 @@ var uiMessagesSchema = lazySchema(
21892
22020
  approval: external_exports.object({
21893
22021
  id: external_exports.string(),
21894
22022
  approved: external_exports.never().optional(),
21895
- reason: external_exports.never().optional()
22023
+ reason: external_exports.never().optional(),
22024
+ signature: external_exports.string().optional()
21896
22025
  })
21897
22026
  }),
21898
22027
  external_exports.object({
@@ -21909,7 +22038,8 @@ var uiMessagesSchema = lazySchema(
21909
22038
  approval: external_exports.object({
21910
22039
  id: external_exports.string(),
21911
22040
  approved: external_exports.boolean(),
21912
- reason: external_exports.string().optional()
22041
+ reason: external_exports.string().optional(),
22042
+ signature: external_exports.string().optional()
21913
22043
  })
21914
22044
  }),
21915
22045
  external_exports.object({
@@ -21928,7 +22058,8 @@ var uiMessagesSchema = lazySchema(
21928
22058
  approval: external_exports.object({
21929
22059
  id: external_exports.string(),
21930
22060
  approved: external_exports.literal(true),
21931
- reason: external_exports.string().optional()
22061
+ reason: external_exports.string().optional(),
22062
+ signature: external_exports.string().optional()
21932
22063
  }).optional()
21933
22064
  }),
21934
22065
  external_exports.object({
@@ -21947,7 +22078,8 @@ var uiMessagesSchema = lazySchema(
21947
22078
  approval: external_exports.object({
21948
22079
  id: external_exports.string(),
21949
22080
  approved: external_exports.literal(true),
21950
- reason: external_exports.string().optional()
22081
+ reason: external_exports.string().optional(),
22082
+ signature: external_exports.string().optional()
21951
22083
  }).optional()
21952
22084
  }),
21953
22085
  external_exports.object({
@@ -21964,7 +22096,8 @@ var uiMessagesSchema = lazySchema(
21964
22096
  approval: external_exports.object({
21965
22097
  id: external_exports.string(),
21966
22098
  approved: external_exports.literal(false),
21967
- reason: external_exports.string().optional()
22099
+ reason: external_exports.string().optional(),
22100
+ signature: external_exports.string().optional()
21968
22101
  })
21969
22102
  }),
21970
22103
  external_exports.object({
@@ -22004,7 +22137,8 @@ var uiMessagesSchema = lazySchema(
22004
22137
  approval: external_exports.object({
22005
22138
  id: external_exports.string(),
22006
22139
  approved: external_exports.never().optional(),
22007
- reason: external_exports.never().optional()
22140
+ reason: external_exports.never().optional(),
22141
+ signature: external_exports.string().optional()
22008
22142
  })
22009
22143
  }),
22010
22144
  external_exports.object({
@@ -22020,7 +22154,8 @@ var uiMessagesSchema = lazySchema(
22020
22154
  approval: external_exports.object({
22021
22155
  id: external_exports.string(),
22022
22156
  approved: external_exports.boolean(),
22023
- reason: external_exports.string().optional()
22157
+ reason: external_exports.string().optional(),
22158
+ signature: external_exports.string().optional()
22024
22159
  })
22025
22160
  }),
22026
22161
  external_exports.object({
@@ -22038,7 +22173,8 @@ var uiMessagesSchema = lazySchema(
22038
22173
  approval: external_exports.object({
22039
22174
  id: external_exports.string(),
22040
22175
  approved: external_exports.literal(true),
22041
- reason: external_exports.string().optional()
22176
+ reason: external_exports.string().optional(),
22177
+ signature: external_exports.string().optional()
22042
22178
  }).optional()
22043
22179
  }),
22044
22180
  external_exports.object({
@@ -22056,7 +22192,8 @@ var uiMessagesSchema = lazySchema(
22056
22192
  approval: external_exports.object({
22057
22193
  id: external_exports.string(),
22058
22194
  approved: external_exports.literal(true),
22059
- reason: external_exports.string().optional()
22195
+ reason: external_exports.string().optional(),
22196
+ signature: external_exports.string().optional()
22060
22197
  }).optional()
22061
22198
  }),
22062
22199
  external_exports.object({
@@ -22072,11 +22209,24 @@ var uiMessagesSchema = lazySchema(
22072
22209
  approval: external_exports.object({
22073
22210
  id: external_exports.string(),
22074
22211
  approved: external_exports.literal(false),
22075
- reason: external_exports.string().optional()
22212
+ reason: external_exports.string().optional(),
22213
+ signature: external_exports.string().optional()
22076
22214
  })
22077
22215
  })
22078
22216
  ])
22079
- ).nonempty("Message must contain at least one part")
22217
+ )
22218
+ }).superRefine((message, context2) => {
22219
+ if (message.role !== "assistant" && message.parts.length === 0) {
22220
+ context2.addIssue({
22221
+ origin: "array",
22222
+ code: "too_small",
22223
+ minimum: 1,
22224
+ inclusive: true,
22225
+ input: message.parts,
22226
+ path: ["parts"],
22227
+ message: "Message must contain at least one part"
22228
+ });
22229
+ }
22080
22230
  })
22081
22231
  ).nonempty("Messages array must not be empty")
22082
22232
  )
@@ -22087,11 +22237,11 @@ function createDownload(options) {
22087
22237
  }
22088
22238
  var originalGenerateId4 = createIdGenerator({ prefix: "aiobj", size: 24 });
22089
22239
  var defaultDownload = createDownload();
22090
- var name20 = "AI_NoSuchProviderError";
22091
- var marker20 = `vercel.ai.error.${name20}`;
22092
- var symbol20 = Symbol.for(marker20);
22093
- var _a20;
22094
- _a20 = symbol20;
22240
+ var name21 = "AI_NoSuchProviderError";
22241
+ var marker21 = `vercel.ai.error.${name21}`;
22242
+ var symbol21 = Symbol.for(marker21);
22243
+ var _a21;
22244
+ _a21 = symbol21;
22095
22245
  var defaultDownload2 = createDownload();
22096
22246
 
22097
22247
  // src/lib/cloud-api.ts
@@ -22154,15 +22304,15 @@ var sealProviderKey = async (providerApiKey, puckApiKey) => {
22154
22304
  "BYOK requires the WebCrypto API (Node 18+ or an edge runtime) to encrypt the provider key"
22155
22305
  );
22156
22306
  }
22157
- const encoder = new TextEncoder();
22158
- const plaintext = encoder.encode(providerApiKey);
22307
+ const encoder2 = new TextEncoder();
22308
+ const plaintext = encoder2.encode(providerApiKey);
22159
22309
  if (plaintext.length > MAX_PLAINTEXT_BYTES) {
22160
22310
  throw new Error(
22161
22311
  `Provider API key is too long to seal (${plaintext.length} bytes, max ${MAX_PLAINTEXT_BYTES})`
22162
22312
  );
22163
22313
  }
22164
22314
  const ciphertext = await crypto.subtle.encrypt(
22165
- { name: "RSA-OAEP", label: encoder.encode(puckApiKey) },
22315
+ { name: "RSA-OAEP", label: encoder2.encode(puckApiKey) },
22166
22316
  await importPublicKey(sealingKey.publicKey),
22167
22317
  plaintext
22168
22318
  );
@@ -22189,16 +22339,16 @@ var processUserTool = async ({
22189
22339
  }
22190
22340
  const responses = [];
22191
22341
  for (let i = 0; i < requestTools.length; i++) {
22192
- const { name: name21, input } = requestTools[i];
22193
- const tool2 = tools?.[name21];
22342
+ const { name: name23, input } = requestTools[i];
22343
+ const tool2 = tools?.[name23];
22194
22344
  if (!tool2) {
22195
- throw new Error(`An unknown tool was called: ${name21}`);
22345
+ throw new Error(`An unknown tool was called: ${name23}`);
22196
22346
  }
22197
22347
  if (!input) {
22198
22348
  throw new Error(`Input was not present in tool call: ${toolCallId}`);
22199
22349
  }
22200
22350
  const output = await tool2.execute(input);
22201
- responses.push({ name: name21, input, output });
22351
+ responses.push({ name: name23, input, output });
22202
22352
  }
22203
22353
  const res = await fetch(`${host}/tool`, {
22204
22354
  headers: { "x-api-key": apiKey },
@@ -22237,9 +22387,34 @@ async function* iterateSSE(body) {
22237
22387
  }
22238
22388
  }
22239
22389
 
22390
+ // src/lib/fetch-with-retry.ts
22391
+ init_react_import();
22392
+ var MAX_RETRIES = 2;
22393
+ var MAX_RETRY_AFTER_SECONDS = 10;
22394
+ var sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
22395
+ async function fetchWithRetry(input, init) {
22396
+ for (let attempt = 0; ; attempt++) {
22397
+ const res = await fetch(input, init);
22398
+ if (res.ok || res.status !== 429 || attempt >= MAX_RETRIES) {
22399
+ return res;
22400
+ }
22401
+ const retryAfter = Number(res.headers.get("Retry-After"));
22402
+ if (!Number.isFinite(retryAfter) || retryAfter <= 0 || retryAfter > MAX_RETRY_AFTER_SECONDS) {
22403
+ return res;
22404
+ }
22405
+ await res.body?.cancel().catch(() => {
22406
+ });
22407
+ await sleep(retryAfter * 1e3);
22408
+ }
22409
+ }
22410
+
22240
22411
  // src/lib/cloud-api.ts
22241
22412
  var DEFAULT_API_VERSION = "v2";
22242
- var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.fdb02235" : "unknown";
22413
+ var DEFAULT_V2_MODELS = {
22414
+ assembly: "openai/gpt-5.4-mini",
22415
+ design: "openai/gpt-5.6-luna"
22416
+ };
22417
+ var CLOUD_CLIENT_VERSION = true ? "0.8.0" : "unknown";
22243
22418
  var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22244
22419
  const {
22245
22420
  ai = {},
@@ -22252,15 +22427,13 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22252
22427
  "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
22253
22428
  );
22254
22429
  }
22255
- const { context, tools = {}, designMode, model, providerOptions } = ai;
22256
- const providerApiKey = model ? ai.providerApiKey ?? process.env.OPENAI_API_KEY : void 0;
22257
- if (model && !providerApiKey) {
22258
- throw new Error(
22259
- `No provider API key found for "${model}". Please provide one via the providerApiKey parameter.`
22260
- );
22261
- }
22430
+ const { context, tools = {}, designMode, providerOptions } = ai;
22431
+ const bodyMode = "mode" in body ? body.mode : void 0;
22432
+ const mode = bodyMode === "design" || bodyMode === void 0 && ai.mode === "design" ? "design" : "assembly";
22433
+ const model = ai.model ?? (apiVersion === DEFAULT_API_VERSION ? DEFAULT_V2_MODELS[mode] : void 0);
22434
+ const providerApiKey = ai.model || designMode?.model ? ai.providerApiKey ?? process.env.OPENAI_API_KEY : void 0;
22262
22435
  const sealedProviderKey = providerApiKey ? await sealProviderKey(providerApiKey, apiKey) : void 0;
22263
- const res = await fetch(`${host}/${path}`, {
22436
+ const res = await fetchWithRetry(`${host}/${path}`, {
22264
22437
  headers: {
22265
22438
  "x-api-key": apiKey,
22266
22439
  "puck-api-version": apiVersion,
@@ -22276,7 +22449,9 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22276
22449
  ...designMode ? {
22277
22450
  designMode
22278
22451
  } : {},
22279
- ...model ? { byok: { model, providerOptions } } : {}
22452
+ // "byok" is the historical wire slot for the model request; the
22453
+ // platform bills it Puck-hosted when no key header accompanies it.
22454
+ ...model || providerOptions ? { byok: { model, providerOptions } } : {}
22280
22455
  })
22281
22456
  });
22282
22457
  if (!res.body) {
@@ -22291,6 +22466,9 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22291
22466
  if (chunk.type === "data-user-tool") {
22292
22467
  await processUserTool({ data: chunk.data, tools, options });
22293
22468
  } else {
22469
+ if (chunk.type === "data-version-notice") {
22470
+ console.warn(chunk.data.message);
22471
+ }
22294
22472
  onChunk(chunk);
22295
22473
  }
22296
22474
  }
@@ -22298,9 +22476,14 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22298
22476
  };
22299
22477
 
22300
22478
  // src/api/chat.ts
22479
+ var handleStreamError = (error48) => {
22480
+ console.error(error48);
22481
+ return error48 instanceof Error ? error48.message : "An error occurred.";
22482
+ };
22301
22483
  function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
22302
22484
  const resolvedMode = mode ?? options?.ai?.mode;
22303
22485
  const stream = createUIMessageStream({
22486
+ onError: handleStreamError,
22304
22487
  execute: async ({ writer }) => {
22305
22488
  await cloudApi(
22306
22489
  "chat",
@@ -22322,6 +22505,7 @@ function chatPrivate({ chatId, messages, config: config2, pageData, mode }, opti
22322
22505
  function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
22323
22506
  const resolvedMode = options?.ai?.mode;
22324
22507
  const stream = createUIMessageStream({
22508
+ onError: handleStreamError,
22325
22509
  execute: async ({ writer }) => {
22326
22510
  await cloudApi(
22327
22511
  "chat",
@@ -22364,20 +22548,25 @@ async function generate({
22364
22548
  apiKey,
22365
22549
  host
22366
22550
  };
22367
- await cloudApi(
22368
- "generate",
22369
- { prompt, config: config2, pageData, mode },
22370
- options,
22371
- (chunk) => {
22372
- if (chunk.type === "data-page") {
22373
- result = chunk.data;
22374
- } else if (chunk.type === "data-finish") {
22375
- onFinish?.(chunk.data);
22376
- } else if (chunk.type === "error") {
22377
- throw new Error(chunk.errorText);
22551
+ try {
22552
+ await cloudApi(
22553
+ "generate",
22554
+ { prompt, config: config2, pageData, mode },
22555
+ options,
22556
+ (chunk) => {
22557
+ if (chunk.type === "data-page") {
22558
+ result = chunk.data;
22559
+ } else if (chunk.type === "data-finish") {
22560
+ onFinish?.(chunk.data);
22561
+ } else if (chunk.type === "error") {
22562
+ throw new Error(chunk.errorText);
22563
+ }
22378
22564
  }
22379
- }
22380
- );
22565
+ );
22566
+ } catch (error48) {
22567
+ console.error(error48);
22568
+ throw error48;
22569
+ }
22381
22570
  return result;
22382
22571
  }
22383
22572