@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.
@@ -9,8 +9,8 @@ var __esm = (fn, res) => function __init() {
9
9
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
10
  };
11
11
  var __export = (target, all) => {
12
- for (var name21 in all)
13
- __defProp(target, name21, { get: all[name21], enumerable: true });
12
+ for (var name23 in all)
13
+ __defProp(target, name23, { get: all[name23], enumerable: true });
14
14
  };
15
15
  var __copyProps = (to, from, except, desc) => {
16
16
  if (from && typeof from === "object" || typeof from === "function") {
@@ -56,13 +56,13 @@ init_react_import();
56
56
  // src/api/chat.ts
57
57
  init_react_import();
58
58
 
59
- // ../../node_modules/.pnpm/ai@6.0.197_zod@4.3.6/node_modules/ai/dist/index.mjs
59
+ // ../../node_modules/.pnpm/ai@6.0.230_zod@4.3.6/node_modules/ai/dist/index.mjs
60
60
  init_react_import();
61
61
 
62
- // ../../node_modules/.pnpm/@ai-sdk+provider-utils@4.0.27_zod@4.3.6/node_modules/@ai-sdk/provider-utils/dist/index.mjs
62
+ // ../../node_modules/.pnpm/@ai-sdk+provider-utils@4.0.40_zod@4.3.6/node_modules/@ai-sdk/provider-utils/dist/index.mjs
63
63
  init_react_import();
64
64
 
65
- // ../../node_modules/.pnpm/@ai-sdk+provider@3.0.10/node_modules/@ai-sdk/provider/dist/index.mjs
65
+ // ../../node_modules/.pnpm/@ai-sdk+provider@3.0.14/node_modules/@ai-sdk/provider/dist/index.mjs
66
66
  init_react_import();
67
67
  var marker = "vercel.ai.error";
68
68
  var symbol = Symbol.for(marker);
@@ -942,7 +942,7 @@ var NEVER = Object.freeze({
942
942
  status: "aborted"
943
943
  });
944
944
  // @__NO_SIDE_EFFECTS__
945
- function $constructor(name21, initializer3, params) {
945
+ function $constructor(name23, initializer3, params) {
946
946
  function init(inst, def) {
947
947
  if (!inst._zod) {
948
948
  Object.defineProperty(inst, "_zod", {
@@ -954,10 +954,10 @@ function $constructor(name21, initializer3, params) {
954
954
  enumerable: false
955
955
  });
956
956
  }
957
- if (inst._zod.traits.has(name21)) {
957
+ if (inst._zod.traits.has(name23)) {
958
958
  return;
959
959
  }
960
- inst._zod.traits.add(name21);
960
+ inst._zod.traits.add(name23);
961
961
  initializer3(inst, def);
962
962
  const proto = _.prototype;
963
963
  const keys = Object.keys(proto);
@@ -971,12 +971,12 @@ function $constructor(name21, initializer3, params) {
971
971
  const Parent = params?.Parent ?? Object;
972
972
  class Definition extends Parent {
973
973
  }
974
- Object.defineProperty(Definition, "name", { value: name21 });
974
+ Object.defineProperty(Definition, "name", { value: name23 });
975
975
  function _(def) {
976
- var _a21;
976
+ var _a23;
977
977
  const inst = params?.Parent ? new Definition() : this;
978
978
  init(inst, def);
979
- (_a21 = inst._zod).deferred ?? (_a21.deferred = []);
979
+ (_a23 = inst._zod).deferred ?? (_a23.deferred = []);
980
980
  for (const fn of inst._zod.deferred) {
981
981
  fn();
982
982
  }
@@ -987,10 +987,10 @@ function $constructor(name21, initializer3, params) {
987
987
  value: (inst) => {
988
988
  if (params?.Parent && inst instanceof params.Parent)
989
989
  return true;
990
- return inst?._zod?.traits?.has(name21);
990
+ return inst?._zod?.traits?.has(name23);
991
991
  }
992
992
  });
993
- Object.defineProperty(_, "name", { value: name21 });
993
+ Object.defineProperty(_, "name", { value: name23 });
994
994
  return _;
995
995
  }
996
996
  var $brand = Symbol("zod_brand");
@@ -1000,8 +1000,8 @@ var $ZodAsyncError = class extends Error {
1000
1000
  }
1001
1001
  };
1002
1002
  var $ZodEncodeError = class extends Error {
1003
- constructor(name21) {
1004
- super(`Encountered unidirectional transform during encode: ${name21}`);
1003
+ constructor(name23) {
1004
+ super(`Encountered unidirectional transform during encode: ${name23}`);
1005
1005
  this.name = "ZodEncodeError";
1006
1006
  }
1007
1007
  };
@@ -1580,8 +1580,8 @@ function aborted(x, startIndex = 0) {
1580
1580
  }
1581
1581
  function prefixIssues(path, issues) {
1582
1582
  return issues.map((iss) => {
1583
- var _a21;
1584
- (_a21 = iss).path ?? (_a21.path = []);
1583
+ var _a23;
1584
+ (_a23 = iss).path ?? (_a23.path = []);
1585
1585
  iss.path.unshift(path);
1586
1586
  return iss;
1587
1587
  });
@@ -1766,7 +1766,7 @@ function formatError(error48, mapper = (issue2) => issue2.message) {
1766
1766
  function treeifyError(error48, mapper = (issue2) => issue2.message) {
1767
1767
  const result = { errors: [] };
1768
1768
  const processError = (error49, path = []) => {
1769
- var _a21, _b16;
1769
+ var _a23, _b16;
1770
1770
  for (const issue2 of error49.issues) {
1771
1771
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1772
1772
  issue2.errors.map((issues) => processError({ issues }, issue2.path));
@@ -1787,7 +1787,7 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
1787
1787
  const terminal = i === fullpath.length - 1;
1788
1788
  if (typeof el === "string") {
1789
1789
  curr.properties ?? (curr.properties = {});
1790
- (_a21 = curr.properties)[el] ?? (_a21[el] = { errors: [] });
1790
+ (_a23 = curr.properties)[el] ?? (_a23[el] = { errors: [] });
1791
1791
  curr = curr.properties[el];
1792
1792
  } else {
1793
1793
  curr.items ?? (curr.items = []);
@@ -2088,10 +2088,10 @@ var sha512_base64url = /* @__PURE__ */ fixedBase64url(86);
2088
2088
 
2089
2089
  // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.js
2090
2090
  var $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
2091
- var _a21;
2091
+ var _a23;
2092
2092
  inst._zod ?? (inst._zod = {});
2093
2093
  inst._zod.def = def;
2094
- (_a21 = inst._zod).onattach ?? (_a21.onattach = []);
2094
+ (_a23 = inst._zod).onattach ?? (_a23.onattach = []);
2095
2095
  });
2096
2096
  var numericOriginMap = {
2097
2097
  number: "number",
@@ -2157,8 +2157,8 @@ var $ZodCheckGreaterThan = /* @__PURE__ */ $constructor("$ZodCheckGreaterThan",
2157
2157
  var $ZodCheckMultipleOf = /* @__PURE__ */ $constructor("$ZodCheckMultipleOf", (inst, def) => {
2158
2158
  $ZodCheck.init(inst, def);
2159
2159
  inst._zod.onattach.push((inst2) => {
2160
- var _a21;
2161
- (_a21 = inst2._zod.bag).multipleOf ?? (_a21.multipleOf = def.value);
2160
+ var _a23;
2161
+ (_a23 = inst2._zod.bag).multipleOf ?? (_a23.multipleOf = def.value);
2162
2162
  });
2163
2163
  inst._zod.check = (payload) => {
2164
2164
  if (typeof payload.value !== typeof def.value)
@@ -2291,9 +2291,9 @@ var $ZodCheckBigIntFormat = /* @__PURE__ */ $constructor("$ZodCheckBigIntFormat"
2291
2291
  };
2292
2292
  });
2293
2293
  var $ZodCheckMaxSize = /* @__PURE__ */ $constructor("$ZodCheckMaxSize", (inst, def) => {
2294
- var _a21;
2294
+ var _a23;
2295
2295
  $ZodCheck.init(inst, def);
2296
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2296
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2297
2297
  const val = payload.value;
2298
2298
  return !nullish(val) && val.size !== void 0;
2299
2299
  });
@@ -2319,9 +2319,9 @@ var $ZodCheckMaxSize = /* @__PURE__ */ $constructor("$ZodCheckMaxSize", (inst, d
2319
2319
  };
2320
2320
  });
2321
2321
  var $ZodCheckMinSize = /* @__PURE__ */ $constructor("$ZodCheckMinSize", (inst, def) => {
2322
- var _a21;
2322
+ var _a23;
2323
2323
  $ZodCheck.init(inst, def);
2324
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2324
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2325
2325
  const val = payload.value;
2326
2326
  return !nullish(val) && val.size !== void 0;
2327
2327
  });
@@ -2347,9 +2347,9 @@ var $ZodCheckMinSize = /* @__PURE__ */ $constructor("$ZodCheckMinSize", (inst, d
2347
2347
  };
2348
2348
  });
2349
2349
  var $ZodCheckSizeEquals = /* @__PURE__ */ $constructor("$ZodCheckSizeEquals", (inst, def) => {
2350
- var _a21;
2350
+ var _a23;
2351
2351
  $ZodCheck.init(inst, def);
2352
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2352
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2353
2353
  const val = payload.value;
2354
2354
  return !nullish(val) && val.size !== void 0;
2355
2355
  });
@@ -2377,9 +2377,9 @@ var $ZodCheckSizeEquals = /* @__PURE__ */ $constructor("$ZodCheckSizeEquals", (i
2377
2377
  };
2378
2378
  });
2379
2379
  var $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
2380
- var _a21;
2380
+ var _a23;
2381
2381
  $ZodCheck.init(inst, def);
2382
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2382
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2383
2383
  const val = payload.value;
2384
2384
  return !nullish(val) && val.length !== void 0;
2385
2385
  });
@@ -2406,9 +2406,9 @@ var $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (ins
2406
2406
  };
2407
2407
  });
2408
2408
  var $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
2409
- var _a21;
2409
+ var _a23;
2410
2410
  $ZodCheck.init(inst, def);
2411
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2411
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2412
2412
  const val = payload.value;
2413
2413
  return !nullish(val) && val.length !== void 0;
2414
2414
  });
@@ -2435,9 +2435,9 @@ var $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (ins
2435
2435
  };
2436
2436
  });
2437
2437
  var $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
2438
- var _a21;
2438
+ var _a23;
2439
2439
  $ZodCheck.init(inst, def);
2440
- (_a21 = inst._zod.def).when ?? (_a21.when = (payload) => {
2440
+ (_a23 = inst._zod.def).when ?? (_a23.when = (payload) => {
2441
2441
  const val = payload.value;
2442
2442
  return !nullish(val) && val.length !== void 0;
2443
2443
  });
@@ -2466,7 +2466,7 @@ var $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals"
2466
2466
  };
2467
2467
  });
2468
2468
  var $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
2469
- var _a21, _b16;
2469
+ var _a23, _b16;
2470
2470
  $ZodCheck.init(inst, def);
2471
2471
  inst._zod.onattach.push((inst2) => {
2472
2472
  const bag = inst2._zod.bag;
@@ -2477,7 +2477,7 @@ var $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat"
2477
2477
  }
2478
2478
  });
2479
2479
  if (def.pattern)
2480
- (_a21 = inst._zod).check ?? (_a21.check = (payload) => {
2480
+ (_a23 = inst._zod).check ?? (_a23.check = (payload) => {
2481
2481
  def.pattern.lastIndex = 0;
2482
2482
  if (def.pattern.test(payload.value))
2483
2483
  return;
@@ -2681,7 +2681,7 @@ var version = {
2681
2681
 
2682
2682
  // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.js
2683
2683
  var $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
2684
- var _a21;
2684
+ var _a23;
2685
2685
  inst ?? (inst = {});
2686
2686
  inst._zod.def = def;
2687
2687
  inst._zod.bag = inst._zod.bag || {};
@@ -2696,7 +2696,7 @@ var $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
2696
2696
  }
2697
2697
  }
2698
2698
  if (checks.length === 0) {
2699
- (_a21 = inst._zod).deferred ?? (_a21.deferred = []);
2699
+ (_a23 = inst._zod).deferred ?? (_a23.deferred = []);
2700
2700
  inst._zod.deferred?.push(() => {
2701
2701
  inst._zod.run = inst._zod.parse;
2702
2702
  });
@@ -11396,7 +11396,7 @@ function initializeContext(params) {
11396
11396
  };
11397
11397
  }
11398
11398
  function process2(schema, ctx, _params = { path: [], schemaPath: [] }) {
11399
- var _a21;
11399
+ var _a23;
11400
11400
  const def = schema._zod.def;
11401
11401
  const seen = ctx.seen.get(schema);
11402
11402
  if (seen) {
@@ -11444,7 +11444,7 @@ function process2(schema, ctx, _params = { path: [], schemaPath: [] }) {
11444
11444
  delete result.schema.default;
11445
11445
  }
11446
11446
  if (ctx.io === "input" && result.schema._prefault)
11447
- (_a21 = result.schema).default ?? (_a21.default = result.schema._prefault);
11447
+ (_a23 = result.schema).default ?? (_a23.default = result.schema._prefault);
11448
11448
  delete result.schema._prefault;
11449
11449
  const _result = ctx.seen.get(schema);
11450
11450
  return _result.schema;
@@ -18179,8 +18179,15 @@ var nullableType = ZodNullable2.create;
18179
18179
  var preprocessType = ZodEffects.createWithPreprocess;
18180
18180
  var pipelineType = ZodPipeline.create;
18181
18181
 
18182
- // ../../node_modules/.pnpm/@ai-sdk+provider-utils@4.0.27_zod@4.3.6/node_modules/@ai-sdk/provider-utils/dist/index.mjs
18182
+ // ../../node_modules/.pnpm/@ai-sdk+provider-utils@4.0.40_zod@4.3.6/node_modules/@ai-sdk/provider-utils/dist/index.mjs
18183
18183
  var { btoa: btoa2, atob: atob2 } = globalThis;
18184
+ async function cancelResponseBody(response) {
18185
+ var _a23;
18186
+ try {
18187
+ await ((_a23 = response.body) == null ? void 0 : _a23.cancel());
18188
+ } catch (e) {
18189
+ }
18190
+ }
18184
18191
  var name14 = "AI_DownloadError";
18185
18192
  var marker15 = `vercel.ai.error.${name14}`;
18186
18193
  var symbol16 = Symbol.for(marker15);
@@ -18204,58 +18211,8 @@ var DownloadError = class extends (_b15 = AISDKError, _a16 = symbol16, _b15) {
18204
18211
  return AISDKError.hasMarker(error48, marker15);
18205
18212
  }
18206
18213
  };
18207
- var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
18208
- async function readResponseWithSizeLimit({
18209
- response,
18210
- url: url2,
18211
- maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
18212
- }) {
18213
- const contentLength = response.headers.get("content-length");
18214
- if (contentLength != null) {
18215
- const length = parseInt(contentLength, 10);
18216
- if (!isNaN(length) && length > maxBytes) {
18217
- throw new DownloadError({
18218
- url: url2,
18219
- message: `Download of ${url2} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
18220
- });
18221
- }
18222
- }
18223
- const body = response.body;
18224
- if (body == null) {
18225
- return new Uint8Array(0);
18226
- }
18227
- const reader = body.getReader();
18228
- const chunks = [];
18229
- let totalBytes = 0;
18230
- try {
18231
- while (true) {
18232
- const { done, value } = await reader.read();
18233
- if (done) {
18234
- break;
18235
- }
18236
- totalBytes += value.length;
18237
- if (totalBytes > maxBytes) {
18238
- throw new DownloadError({
18239
- url: url2,
18240
- message: `Download of ${url2} exceeded maximum size of ${maxBytes} bytes.`
18241
- });
18242
- }
18243
- chunks.push(value);
18244
- }
18245
- } finally {
18246
- try {
18247
- await reader.cancel();
18248
- } finally {
18249
- reader.releaseLock();
18250
- }
18251
- }
18252
- const result = new Uint8Array(totalBytes);
18253
- let offset = 0;
18254
- for (const chunk of chunks) {
18255
- result.set(chunk, offset);
18256
- offset += chunk.length;
18257
- }
18258
- return result;
18214
+ function isBrowserRuntime(globalThisAny = globalThis) {
18215
+ return globalThisAny.window != null;
18259
18216
  }
18260
18217
  function validateDownloadUrl(url2) {
18261
18218
  let parsed;
@@ -18276,7 +18233,7 @@ function validateDownloadUrl(url2) {
18276
18233
  message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
18277
18234
  });
18278
18235
  }
18279
- const hostname3 = parsed.hostname;
18236
+ const hostname3 = parsed.hostname.toLowerCase().replace(/\.+$/, "");
18280
18237
  if (!hostname3) {
18281
18238
  throw new DownloadError({
18282
18239
  url: url2,
@@ -18319,41 +18276,175 @@ function isIPv4(hostname3) {
18319
18276
  }
18320
18277
  function isPrivateIPv4(ip) {
18321
18278
  const parts = ip.split(".").map(Number);
18322
- const [a, b] = parts;
18279
+ const [a, b, c] = parts;
18323
18280
  if (a === 0) return true;
18324
18281
  if (a === 10) return true;
18282
+ if (a === 100 && b >= 64 && b <= 127) return true;
18325
18283
  if (a === 127) return true;
18326
18284
  if (a === 169 && b === 254) return true;
18327
18285
  if (a === 172 && b >= 16 && b <= 31) return true;
18286
+ if (a === 192 && b === 0 && c === 0) return true;
18328
18287
  if (a === 192 && b === 168) return true;
18288
+ if (a === 198 && (b === 18 || b === 19)) return true;
18289
+ if (a >= 240) return true;
18329
18290
  return false;
18330
18291
  }
18292
+ function parseIPv6(ip) {
18293
+ let address = ip.toLowerCase();
18294
+ const zoneIndex = address.indexOf("%");
18295
+ if (zoneIndex !== -1) {
18296
+ address = address.slice(0, zoneIndex);
18297
+ }
18298
+ const halves = address.split("::");
18299
+ if (halves.length > 2) return null;
18300
+ const toGroups = (segment) => {
18301
+ if (segment === "") return [];
18302
+ const groups = [];
18303
+ const parts = segment.split(":");
18304
+ for (let i = 0; i < parts.length; i++) {
18305
+ const part = parts[i];
18306
+ if (part.includes(".")) {
18307
+ if (i !== parts.length - 1 || !isIPv4(part)) return null;
18308
+ const [a, b, c, d] = part.split(".").map(Number);
18309
+ groups.push(a << 8 | b, c << 8 | d);
18310
+ continue;
18311
+ }
18312
+ if (!/^[0-9a-f]{1,4}$/.test(part)) return null;
18313
+ groups.push(parseInt(part, 16));
18314
+ }
18315
+ return groups;
18316
+ };
18317
+ const head = toGroups(halves[0]);
18318
+ if (head === null) return null;
18319
+ if (halves.length === 2) {
18320
+ const tail = toGroups(halves[1]);
18321
+ if (tail === null) return null;
18322
+ const fill = 8 - head.length - tail.length;
18323
+ if (fill < 0) return null;
18324
+ return [...head, ...new Array(fill).fill(0), ...tail];
18325
+ }
18326
+ return head.length === 8 ? head : null;
18327
+ }
18331
18328
  function isPrivateIPv6(ip) {
18332
- const normalized = ip.toLowerCase();
18333
- if (normalized === "::1") return true;
18334
- if (normalized === "::") return true;
18335
- if (normalized.startsWith("::ffff:")) {
18336
- const mappedPart = normalized.slice(7);
18337
- if (isIPv4(mappedPart)) {
18338
- return isPrivateIPv4(mappedPart);
18339
- }
18340
- const hexParts = mappedPart.split(":");
18341
- if (hexParts.length === 2) {
18342
- const high = parseInt(hexParts[0], 16);
18343
- const low = parseInt(hexParts[1], 16);
18344
- if (!isNaN(high) && !isNaN(low)) {
18345
- const a = high >> 8 & 255;
18346
- const b = high & 255;
18347
- const c = low >> 8 & 255;
18348
- const d = low & 255;
18349
- return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
18350
- }
18351
- }
18352
- }
18353
- if (normalized.startsWith("fc") || normalized.startsWith("fd")) return true;
18354
- if (normalized.startsWith("fe80")) return true;
18329
+ const groups = parseIPv6(ip);
18330
+ if (groups === null) return true;
18331
+ const topZero = (count) => groups.slice(0, count).every((group) => group === 0);
18332
+ if (topZero(7) && (groups[7] === 0 || groups[7] === 1)) return true;
18333
+ if ((groups[0] & 65024) === 64512) return true;
18334
+ if ((groups[0] & 65472) === 65152) return true;
18335
+ if ((groups[0] & 65472) === 65216) return true;
18336
+ if ((groups[0] & 65280) === 65280) return true;
18337
+ const embedsIPv4 = (
18338
+ // ::/96 IPv4-compatible (deprecated)
18339
+ topZero(6) || // ::ffff:0:0/96 — IPv4-mapped (ffff in group 5)
18340
+ topZero(5) && groups[5] === 65535 || // ::ffff:0:0/96 — IPv4-translated form (ffff in group 4, group 5 zero)
18341
+ topZero(4) && groups[4] === 65535 && groups[5] === 0 || // 64:ff9b::/96 — NAT64 well-known prefix
18342
+ 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
18343
+ groups[0] === 100 && groups[1] === 65435 && groups[2] === 1
18344
+ );
18345
+ if (embedsIPv4) {
18346
+ const a = groups[6] >> 8 & 255;
18347
+ const b = groups[6] & 255;
18348
+ const c = groups[7] >> 8 & 255;
18349
+ const d = groups[7] & 255;
18350
+ return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
18351
+ }
18355
18352
  return false;
18356
18353
  }
18354
+ var MAX_DOWNLOAD_REDIRECTS = 10;
18355
+ async function fetchWithValidatedRedirects({
18356
+ url: url2,
18357
+ headers,
18358
+ abortSignal,
18359
+ maxRedirects = MAX_DOWNLOAD_REDIRECTS
18360
+ }) {
18361
+ const baseInit = { signal: abortSignal };
18362
+ if (headers !== void 0) {
18363
+ baseInit.headers = headers;
18364
+ }
18365
+ let currentUrl = url2;
18366
+ for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
18367
+ validateDownloadUrl(currentUrl);
18368
+ const response = await fetch(currentUrl, {
18369
+ ...baseInit,
18370
+ redirect: "manual"
18371
+ });
18372
+ if (response.type === "opaqueredirect") {
18373
+ if (!isBrowserRuntime()) {
18374
+ throw new DownloadError({
18375
+ url: url2,
18376
+ message: `Redirect from ${currentUrl} could not be validated and was blocked`
18377
+ });
18378
+ }
18379
+ return await fetch(currentUrl, { ...baseInit, redirect: "follow" });
18380
+ }
18381
+ const location = response.headers.get("location");
18382
+ if (response.status >= 300 && response.status < 400 && location) {
18383
+ await cancelResponseBody(response);
18384
+ currentUrl = new URL(location, currentUrl).toString();
18385
+ continue;
18386
+ }
18387
+ return response;
18388
+ }
18389
+ throw new DownloadError({
18390
+ url: url2,
18391
+ message: `Too many redirects (max ${maxRedirects})`
18392
+ });
18393
+ }
18394
+ var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
18395
+ async function readResponseWithSizeLimit({
18396
+ response,
18397
+ url: url2,
18398
+ maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
18399
+ }) {
18400
+ const contentLength = response.headers.get("content-length");
18401
+ if (contentLength != null) {
18402
+ const length = parseInt(contentLength, 10);
18403
+ if (!isNaN(length) && length > maxBytes) {
18404
+ await cancelResponseBody(response);
18405
+ throw new DownloadError({
18406
+ url: url2,
18407
+ message: `Download of ${url2} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
18408
+ });
18409
+ }
18410
+ }
18411
+ const body = response.body;
18412
+ if (body == null) {
18413
+ return new Uint8Array(0);
18414
+ }
18415
+ const reader = body.getReader();
18416
+ const chunks = [];
18417
+ let totalBytes = 0;
18418
+ try {
18419
+ while (true) {
18420
+ const { done, value } = await reader.read();
18421
+ if (done) {
18422
+ break;
18423
+ }
18424
+ totalBytes += value.length;
18425
+ if (totalBytes > maxBytes) {
18426
+ throw new DownloadError({
18427
+ url: url2,
18428
+ message: `Download of ${url2} exceeded maximum size of ${maxBytes} bytes.`
18429
+ });
18430
+ }
18431
+ chunks.push(value);
18432
+ }
18433
+ } finally {
18434
+ try {
18435
+ await reader.cancel();
18436
+ } finally {
18437
+ reader.releaseLock();
18438
+ }
18439
+ }
18440
+ const result = new Uint8Array(totalBytes);
18441
+ let offset = 0;
18442
+ for (const chunk of chunks) {
18443
+ result.set(chunk, offset);
18444
+ offset += chunk.length;
18445
+ }
18446
+ return result;
18447
+ }
18357
18448
  var createIdGenerator = ({
18358
18449
  prefix,
18359
18450
  size = 16,
@@ -18380,18 +18471,6 @@ var createIdGenerator = ({
18380
18471
  return () => `${prefix}${separator}${generator()}`;
18381
18472
  };
18382
18473
  var generateId = createIdGenerator();
18383
- function getErrorMessage2(error48) {
18384
- if (error48 == null) {
18385
- return "unknown error";
18386
- }
18387
- if (typeof error48 === "string") {
18388
- return error48;
18389
- }
18390
- if (error48 instanceof Error) {
18391
- return error48.message;
18392
- }
18393
- return JSON.stringify(error48);
18394
- }
18395
18474
  function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
18396
18475
  var _a23, _b22, _c;
18397
18476
  if (globalThisAny.window) {
@@ -19648,15 +19727,26 @@ function isSchema(value) {
19648
19727
  return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
19649
19728
  }
19650
19729
  function asSchema(schema) {
19651
- return schema == null ? jsonSchema({ properties: {}, additionalProperties: false }) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
19730
+ return schema == null ? jsonSchema({
19731
+ type: "object",
19732
+ properties: {},
19733
+ additionalProperties: false
19734
+ }) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
19652
19735
  }
19653
19736
  function standardSchema(standardSchema2) {
19654
19737
  return jsonSchema(
19655
- () => addAdditionalPropertiesToJsonSchema(
19656
- standardSchema2["~standard"].jsonSchema.input({
19657
- target: "draft-07"
19658
- })
19659
- ),
19738
+ () => {
19739
+ if (!hasStandardJsonSchema(standardSchema2)) {
19740
+ throw new Error(
19741
+ `Standard schema vendor '${standardSchema2["~standard"].vendor}' does not support JSON Schema conversion.`
19742
+ );
19743
+ }
19744
+ return addAdditionalPropertiesToJsonSchema(
19745
+ standardSchema2["~standard"].jsonSchema.input({
19746
+ target: "draft-07"
19747
+ })
19748
+ );
19749
+ },
19660
19750
  {
19661
19751
  validate: async (value) => {
19662
19752
  const result = await standardSchema2["~standard"].validate(value);
@@ -19671,6 +19761,9 @@ function standardSchema(standardSchema2) {
19671
19761
  }
19672
19762
  );
19673
19763
  }
19764
+ function hasStandardJsonSchema(schema) {
19765
+ return schema["~standard"].jsonSchema != null;
19766
+ }
19674
19767
  function zod3Schema(zodSchema2, options) {
19675
19768
  var _a23;
19676
19769
  const useReferences = (_a23 = options == null ? void 0 : options.useReferences) != null ? _a23 : false;
@@ -19779,12 +19872,13 @@ async function resolve(value) {
19779
19872
  }
19780
19873
  return Promise.resolve(value);
19781
19874
  }
19875
+ var textDecoder = new TextDecoder();
19782
19876
 
19783
- // ../../node_modules/.pnpm/ai@6.0.197_zod@4.3.6/node_modules/ai/dist/index.mjs
19877
+ // ../../node_modules/.pnpm/ai@6.0.230_zod@4.3.6/node_modules/ai/dist/index.mjs
19784
19878
  var __defProp2 = Object.defineProperty;
19785
19879
  var __export2 = (target, all) => {
19786
- for (var name21 in all)
19787
- __defProp2(target, name21, { get: all[name21], enumerable: true });
19880
+ for (var name222 in all)
19881
+ __defProp2(target, name222, { get: all[name222], enumerable: true });
19788
19882
  };
19789
19883
  var name15 = "AI_InvalidArgumentError";
19790
19884
  var marker16 = `vercel.ai.error.${name15}`;
@@ -19801,30 +19895,35 @@ var marker32 = `vercel.ai.error.${name32}`;
19801
19895
  var symbol32 = Symbol.for(marker32);
19802
19896
  var _a32;
19803
19897
  _a32 = symbol32;
19804
- var name42 = "AI_InvalidToolInputError";
19898
+ var name42 = "AI_InvalidToolApprovalSignatureError";
19805
19899
  var marker42 = `vercel.ai.error.${name42}`;
19806
19900
  var symbol42 = Symbol.for(marker42);
19807
19901
  var _a42;
19808
19902
  _a42 = symbol42;
19809
- var name52 = "AI_ToolCallNotFoundForApprovalError";
19903
+ var name52 = "AI_InvalidToolInputError";
19810
19904
  var marker52 = `vercel.ai.error.${name52}`;
19811
19905
  var symbol52 = Symbol.for(marker52);
19812
19906
  var _a52;
19813
19907
  _a52 = symbol52;
19814
- var name62 = "AI_MissingToolResultsError";
19908
+ var name62 = "AI_ToolCallNotFoundForApprovalError";
19815
19909
  var marker62 = `vercel.ai.error.${name62}`;
19816
19910
  var symbol62 = Symbol.for(marker62);
19817
19911
  var _a62;
19818
19912
  _a62 = symbol62;
19819
- var name72 = "AI_NoImageGeneratedError";
19913
+ var name72 = "AI_MissingToolResultsError";
19820
19914
  var marker72 = `vercel.ai.error.${name72}`;
19821
19915
  var symbol72 = Symbol.for(marker72);
19822
19916
  var _a72;
19823
19917
  _a72 = symbol72;
19824
- var name82 = "AI_NoObjectGeneratedError";
19918
+ var name82 = "AI_NoImageGeneratedError";
19825
19919
  var marker82 = `vercel.ai.error.${name82}`;
19826
19920
  var symbol82 = Symbol.for(marker82);
19827
19921
  var _a82;
19922
+ _a82 = symbol82;
19923
+ var name92 = "AI_NoObjectGeneratedError";
19924
+ var marker92 = `vercel.ai.error.${name92}`;
19925
+ var symbol92 = Symbol.for(marker92);
19926
+ var _a92;
19828
19927
  var NoObjectGeneratedError = class extends AISDKError {
19829
19928
  constructor({
19830
19929
  message = "No object generated.",
@@ -19834,110 +19933,109 @@ var NoObjectGeneratedError = class extends AISDKError {
19834
19933
  usage,
19835
19934
  finishReason
19836
19935
  }) {
19837
- super({ name: name82, message, cause });
19838
- this[_a82] = true;
19936
+ super({ name: name92, message, cause });
19937
+ this[_a92] = true;
19839
19938
  this.text = text2;
19840
19939
  this.response = response;
19841
19940
  this.usage = usage;
19842
19941
  this.finishReason = finishReason;
19843
19942
  }
19844
19943
  static isInstance(error48) {
19845
- return AISDKError.hasMarker(error48, marker82);
19944
+ return AISDKError.hasMarker(error48, marker92);
19846
19945
  }
19847
19946
  };
19848
- _a82 = symbol82;
19849
- var name92 = "AI_NoOutputGeneratedError";
19850
- var marker92 = `vercel.ai.error.${name92}`;
19851
- var symbol92 = Symbol.for(marker92);
19852
- var _a92;
19853
19947
  _a92 = symbol92;
19854
- var name102 = "AI_NoSpeechGeneratedError";
19948
+ var name102 = "AI_NoOutputGeneratedError";
19855
19949
  var marker102 = `vercel.ai.error.${name102}`;
19856
19950
  var symbol102 = Symbol.for(marker102);
19857
19951
  var _a102;
19858
19952
  _a102 = symbol102;
19859
- var name112 = "AI_NoTranscriptGeneratedError";
19953
+ var name112 = "AI_NoSpeechGeneratedError";
19860
19954
  var marker112 = `vercel.ai.error.${name112}`;
19861
19955
  var symbol112 = Symbol.for(marker112);
19862
19956
  var _a112;
19863
19957
  _a112 = symbol112;
19864
- var name122 = "AI_NoVideoGeneratedError";
19958
+ var name122 = "AI_NoTranscriptGeneratedError";
19865
19959
  var marker122 = `vercel.ai.error.${name122}`;
19866
19960
  var symbol122 = Symbol.for(marker122);
19867
19961
  var _a122;
19868
19962
  _a122 = symbol122;
19869
- var name132 = "AI_NoSuchToolError";
19963
+ var name132 = "AI_NoVideoGeneratedError";
19870
19964
  var marker132 = `vercel.ai.error.${name132}`;
19871
19965
  var symbol132 = Symbol.for(marker132);
19872
19966
  var _a132;
19873
19967
  _a132 = symbol132;
19874
- var name142 = "AI_ToolCallRepairError";
19968
+ var name142 = "AI_NoSuchToolError";
19875
19969
  var marker142 = `vercel.ai.error.${name142}`;
19876
19970
  var symbol142 = Symbol.for(marker142);
19877
19971
  var _a142;
19878
19972
  _a142 = symbol142;
19879
- var name152 = "AI_UIMessageStreamError";
19973
+ var name152 = "AI_ToolCallRepairError";
19880
19974
  var marker152 = `vercel.ai.error.${name152}`;
19881
19975
  var symbol152 = Symbol.for(marker152);
19882
19976
  var _a152;
19977
+ _a152 = symbol152;
19978
+ var name16 = "AI_UIMessageStreamError";
19979
+ var marker162 = `vercel.ai.error.${name16}`;
19980
+ var symbol162 = Symbol.for(marker162);
19981
+ var _a162;
19883
19982
  var UIMessageStreamError = class extends AISDKError {
19884
19983
  constructor({
19885
19984
  chunkType,
19886
19985
  chunkId,
19887
19986
  message
19888
19987
  }) {
19889
- super({ name: name152, message });
19890
- this[_a152] = true;
19988
+ super({ name: name16, message });
19989
+ this[_a162] = true;
19891
19990
  this.chunkType = chunkType;
19892
19991
  this.chunkId = chunkId;
19893
19992
  }
19894
19993
  static isInstance(error48) {
19895
- return AISDKError.hasMarker(error48, marker152);
19994
+ return AISDKError.hasMarker(error48, marker162);
19896
19995
  }
19897
19996
  };
19898
- _a152 = symbol152;
19899
- var name16 = "AI_InvalidDataContentError";
19900
- var marker162 = `vercel.ai.error.${name16}`;
19901
- var symbol162 = Symbol.for(marker162);
19902
- var _a162;
19903
19997
  _a162 = symbol162;
19904
- var name17 = "AI_InvalidMessageRoleError";
19998
+ var name17 = "AI_InvalidDataContentError";
19905
19999
  var marker17 = `vercel.ai.error.${name17}`;
19906
20000
  var symbol172 = Symbol.for(marker17);
19907
20001
  var _a172;
19908
20002
  _a172 = symbol172;
19909
- var name18 = "AI_MessageConversionError";
20003
+ var name18 = "AI_InvalidMessageRoleError";
19910
20004
  var marker18 = `vercel.ai.error.${name18}`;
19911
20005
  var symbol18 = Symbol.for(marker18);
19912
20006
  var _a18;
19913
20007
  _a18 = symbol18;
19914
- var name19 = "AI_RetryError";
20008
+ var name19 = "AI_MessageConversionError";
19915
20009
  var marker19 = `vercel.ai.error.${name19}`;
19916
20010
  var symbol19 = Symbol.for(marker19);
19917
20011
  var _a19;
19918
20012
  _a19 = symbol19;
19919
- var VERSION = true ? "6.0.197" : "0.0.0-test";
20013
+ var name20 = "AI_RetryError";
20014
+ var marker20 = `vercel.ai.error.${name20}`;
20015
+ var symbol20 = Symbol.for(marker20);
20016
+ var _a20;
20017
+ _a20 = symbol20;
20018
+ var VERSION = true ? "6.0.230" : "0.0.0-test";
19920
20019
  var download = async ({
19921
20020
  url: url2,
19922
20021
  maxBytes,
19923
20022
  abortSignal
19924
20023
  }) => {
19925
- var _a21;
20024
+ var _a222;
19926
20025
  const urlText = url2.toString();
19927
- validateDownloadUrl(urlText);
19928
20026
  try {
19929
- const response = await fetch(urlText, {
19930
- headers: withUserAgentSuffix(
19931
- {},
19932
- `ai-sdk/${VERSION}`,
19933
- getRuntimeEnvironmentUserAgent()
19934
- ),
19935
- signal: abortSignal
20027
+ const headers = withUserAgentSuffix(
20028
+ {},
20029
+ `ai-sdk/${VERSION}`,
20030
+ getRuntimeEnvironmentUserAgent()
20031
+ );
20032
+ const response = await fetchWithValidatedRedirects({
20033
+ url: urlText,
20034
+ headers,
20035
+ abortSignal
19936
20036
  });
19937
- if (response.redirected) {
19938
- validateDownloadUrl(response.url);
19939
- }
19940
20037
  if (!response.ok) {
20038
+ await cancelResponseBody(response);
19941
20039
  throw new DownloadError({
19942
20040
  url: urlText,
19943
20041
  statusCode: response.status,
@@ -19951,7 +20049,7 @@ var download = async ({
19951
20049
  });
19952
20050
  return {
19953
20051
  data,
19954
- mediaType: (_a21 = response.headers.get("content-type")) != null ? _a21 : void 0
20052
+ mediaType: (_a222 = response.headers.get("content-type")) != null ? _a222 : void 0
19955
20053
  };
19956
20054
  } catch (error48) {
19957
20055
  if (DownloadError.isInstance(error48)) {
@@ -19967,8 +20065,8 @@ var dataContentSchema = external_exports.union([
19967
20065
  external_exports.custom(
19968
20066
  // Buffer might not be available in some environments such as CloudFlare:
19969
20067
  (value) => {
19970
- var _a21, _b16;
19971
- return (_b16 = (_a21 = globalThis.Buffer) == null ? void 0 : _a21.isBuffer(value)) != null ? _b16 : false;
20068
+ var _a222, _b16;
20069
+ return (_b16 = (_a222 = globalThis.Buffer) == null ? void 0 : _a222.isBuffer(value)) != null ? _b16 : false;
19972
20070
  },
19973
20071
  { message: "Must be a Buffer" }
19974
20072
  )
@@ -20197,6 +20295,7 @@ function mergeObjects(base, overrides) {
20197
20295
  }
20198
20296
  return result;
20199
20297
  }
20298
+ var encoder = new TextEncoder();
20200
20299
  var output_exports = {};
20201
20300
  __export2(output_exports, {
20202
20301
  array: () => array2,
@@ -20209,6 +20308,10 @@ function fixJson(input) {
20209
20308
  const stack = ["ROOT"];
20210
20309
  let lastValidIndex = -1;
20211
20310
  let literalStart = null;
20311
+ let unicodeEscapeDigits = 0;
20312
+ function isHexDigit(char) {
20313
+ return char >= "0" && char <= "9" || char >= "A" && char <= "F" || char >= "a" && char <= "f";
20314
+ }
20212
20315
  function processValueStart(char, i, swapState) {
20213
20316
  {
20214
20317
  switch (char) {
@@ -20413,7 +20516,22 @@ function fixJson(input) {
20413
20516
  }
20414
20517
  case "INSIDE_STRING_ESCAPE": {
20415
20518
  stack.pop();
20416
- lastValidIndex = i;
20519
+ if (char === "u") {
20520
+ unicodeEscapeDigits = 0;
20521
+ stack.push("INSIDE_STRING_UNICODE_ESCAPE");
20522
+ } else {
20523
+ lastValidIndex = i;
20524
+ }
20525
+ break;
20526
+ }
20527
+ case "INSIDE_STRING_UNICODE_ESCAPE": {
20528
+ if (isHexDigit(char)) {
20529
+ unicodeEscapeDigits++;
20530
+ if (unicodeEscapeDigits === 4) {
20531
+ stack.pop();
20532
+ lastValidIndex = i;
20533
+ }
20534
+ }
20417
20535
  break;
20418
20536
  }
20419
20537
  case "INSIDE_NUMBER": {
@@ -20550,7 +20668,7 @@ var text = () => ({
20550
20668
  });
20551
20669
  var object2 = ({
20552
20670
  schema: inputSchema,
20553
- name: name21,
20671
+ name: name222,
20554
20672
  description
20555
20673
  }) => {
20556
20674
  const schema = asSchema(inputSchema);
@@ -20559,7 +20677,7 @@ var object2 = ({
20559
20677
  responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
20560
20678
  type: "json",
20561
20679
  schema: jsonSchema2,
20562
- ...name21 != null && { name: name21 },
20680
+ ...name222 != null && { name: name222 },
20563
20681
  ...description != null && { description }
20564
20682
  })),
20565
20683
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -20613,7 +20731,7 @@ var object2 = ({
20613
20731
  };
20614
20732
  var array2 = ({
20615
20733
  element: inputElementSchema,
20616
- name: name21,
20734
+ name: name222,
20617
20735
  description
20618
20736
  }) => {
20619
20737
  const elementSchema = asSchema(inputElementSchema);
@@ -20633,7 +20751,7 @@ var array2 = ({
20633
20751
  required: ["elements"],
20634
20752
  additionalProperties: false
20635
20753
  },
20636
- ...name21 != null && { name: name21 },
20754
+ ...name222 != null && { name: name222 },
20637
20755
  ...description != null && { description }
20638
20756
  };
20639
20757
  }),
@@ -20663,6 +20781,7 @@ var array2 = ({
20663
20781
  finishReason: context2.finishReason
20664
20782
  });
20665
20783
  }
20784
+ const validatedElements = [];
20666
20785
  for (const element of outerValue.elements) {
20667
20786
  const validationResult = await safeValidateTypes({
20668
20787
  value: element,
@@ -20678,8 +20797,9 @@ var array2 = ({
20678
20797
  finishReason: context2.finishReason
20679
20798
  });
20680
20799
  }
20800
+ validatedElements.push(validationResult.value);
20681
20801
  }
20682
- return outerValue.elements;
20802
+ return validatedElements;
20683
20803
  },
20684
20804
  async parsePartialOutput({ text: text2 }) {
20685
20805
  const result = await parsePartialJson(text2);
@@ -20725,7 +20845,7 @@ var array2 = ({
20725
20845
  };
20726
20846
  var choice = ({
20727
20847
  options: choiceOptions,
20728
- name: name21,
20848
+ name: name222,
20729
20849
  description
20730
20850
  }) => {
20731
20851
  return {
@@ -20742,7 +20862,7 @@ var choice = ({
20742
20862
  required: ["result"],
20743
20863
  additionalProperties: false
20744
20864
  },
20745
- ...name21 != null && { name: name21 },
20865
+ ...name222 != null && { name: name222 },
20746
20866
  ...description != null && { description }
20747
20867
  }),
20748
20868
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -20803,14 +20923,14 @@ var choice = ({
20803
20923
  };
20804
20924
  };
20805
20925
  var json2 = ({
20806
- name: name21,
20926
+ name: name222,
20807
20927
  description
20808
20928
  } = {}) => {
20809
20929
  return {
20810
20930
  name: "json",
20811
20931
  responseFormat: Promise.resolve({
20812
20932
  type: "json",
20813
- ...name21 != null && { name: name21 },
20933
+ ...name222 != null && { name: name222 },
20814
20934
  ...description != null && { description }
20815
20935
  }),
20816
20936
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -20967,7 +21087,8 @@ var uiMessageChunkSchema = lazySchema(
20967
21087
  external_exports.strictObject({
20968
21088
  type: external_exports.literal("tool-approval-request"),
20969
21089
  approvalId: external_exports.string(),
20970
- toolCallId: external_exports.string()
21090
+ toolCallId: external_exports.string(),
21091
+ signature: external_exports.string().optional()
20971
21092
  }),
20972
21093
  external_exports.strictObject({
20973
21094
  type: external_exports.literal("tool-output-available"),
@@ -21075,6 +21196,9 @@ var uiMessageChunkSchema = lazySchema(
21075
21196
  function isDataUIMessageChunk(chunk) {
21076
21197
  return chunk.type.startsWith("data-");
21077
21198
  }
21199
+ function createIdMap() {
21200
+ return /* @__PURE__ */ Object.create(null);
21201
+ }
21078
21202
  function isStaticToolUIPart(part) {
21079
21203
  return part.type.startsWith("tool-");
21080
21204
  }
@@ -21098,9 +21222,9 @@ function createStreamingUIMessageState({
21098
21222
  role: "assistant",
21099
21223
  parts: []
21100
21224
  },
21101
- activeTextParts: {},
21102
- activeReasoningParts: {},
21103
- partialToolCalls: {}
21225
+ activeTextParts: createIdMap(),
21226
+ activeReasoningParts: createIdMap(),
21227
+ partialToolCalls: createIdMap()
21104
21228
  };
21105
21229
  }
21106
21230
  function processUIMessageStream({
@@ -21116,7 +21240,7 @@ function processUIMessageStream({
21116
21240
  new TransformStream({
21117
21241
  async transform(chunk, controller) {
21118
21242
  await runUpdateMessageJob(async ({ state, write }) => {
21119
- var _a21, _b16, _c, _d;
21243
+ var _a222, _b16, _c, _d;
21120
21244
  function getToolInvocation(toolCallId) {
21121
21245
  const toolInvocations = state.message.parts.filter(isToolUIPart);
21122
21246
  const toolInvocation = toolInvocations.find(
@@ -21132,7 +21256,7 @@ function processUIMessageStream({
21132
21256
  return toolInvocation;
21133
21257
  }
21134
21258
  function updateToolPart(options) {
21135
- var _a222;
21259
+ var _a23;
21136
21260
  const part = state.message.parts.find(
21137
21261
  (part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
21138
21262
  );
@@ -21151,7 +21275,7 @@ function processUIMessageStream({
21151
21275
  if (options.toolMetadata !== void 0) {
21152
21276
  anyPart.toolMetadata = options.toolMetadata;
21153
21277
  }
21154
- anyPart.providerExecuted = (_a222 = anyOptions.providerExecuted) != null ? _a222 : part.providerExecuted;
21278
+ anyPart.providerExecuted = (_a23 = anyOptions.providerExecuted) != null ? _a23 : part.providerExecuted;
21155
21279
  const providerMetadata = anyOptions.providerMetadata;
21156
21280
  if (providerMetadata != null) {
21157
21281
  if (options.state === "output-available" || options.state === "output-error") {
@@ -21180,7 +21304,7 @@ function processUIMessageStream({
21180
21304
  }
21181
21305
  }
21182
21306
  function updateDynamicToolPart(options) {
21183
- var _a222, _b22;
21307
+ var _a23, _b22;
21184
21308
  const part = state.message.parts.find(
21185
21309
  (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
21186
21310
  );
@@ -21192,7 +21316,7 @@ function processUIMessageStream({
21192
21316
  anyPart.input = anyOptions.input;
21193
21317
  anyPart.output = anyOptions.output;
21194
21318
  anyPart.errorText = anyOptions.errorText;
21195
- anyPart.rawInput = (_a222 = anyOptions.rawInput) != null ? _a222 : anyPart.rawInput;
21319
+ anyPart.rawInput = (_a23 = anyOptions.rawInput) != null ? _a23 : anyPart.rawInput;
21196
21320
  anyPart.preliminary = anyOptions.preliminary;
21197
21321
  if (options.title !== void 0) {
21198
21322
  anyPart.title = options.title;
@@ -21267,7 +21391,7 @@ function processUIMessageStream({
21267
21391
  });
21268
21392
  }
21269
21393
  textPart.text += chunk.delta;
21270
- textPart.providerMetadata = (_a21 = chunk.providerMetadata) != null ? _a21 : textPart.providerMetadata;
21394
+ textPart.providerMetadata = (_a222 = chunk.providerMetadata) != null ? _a222 : textPart.providerMetadata;
21271
21395
  write();
21272
21396
  break;
21273
21397
  }
@@ -21496,7 +21620,10 @@ function processUIMessageStream({
21496
21620
  case "tool-approval-request": {
21497
21621
  const toolInvocation = getToolInvocation(chunk.toolCallId);
21498
21622
  toolInvocation.state = "approval-requested";
21499
- toolInvocation.approval = { id: chunk.approvalId };
21623
+ toolInvocation.approval = {
21624
+ id: chunk.approvalId,
21625
+ ...chunk.signature != null ? { signature: chunk.signature } : {}
21626
+ };
21500
21627
  write();
21501
21628
  break;
21502
21629
  }
@@ -21574,8 +21701,8 @@ function processUIMessageStream({
21574
21701
  break;
21575
21702
  }
21576
21703
  case "finish-step": {
21577
- state.activeTextParts = {};
21578
- state.activeReasoningParts = {};
21704
+ state.activeTextParts = createIdMap();
21705
+ state.activeReasoningParts = createIdMap();
21579
21706
  break;
21580
21707
  }
21581
21708
  case "start": {
@@ -21757,7 +21884,8 @@ var originalGenerateId2 = createIdGenerator({
21757
21884
  });
21758
21885
  function createUIMessageStream({
21759
21886
  execute,
21760
- onError = getErrorMessage2,
21887
+ onError = () => "An error occurred.",
21888
+ // prevent leaking server error details to the client by default
21761
21889
  originalMessages,
21762
21890
  onStepFinish,
21763
21891
  onFinish,
@@ -21935,7 +22063,8 @@ var uiMessagesSchema = lazySchema(
21935
22063
  approval: external_exports.object({
21936
22064
  id: external_exports.string(),
21937
22065
  approved: external_exports.never().optional(),
21938
- reason: external_exports.never().optional()
22066
+ reason: external_exports.never().optional(),
22067
+ signature: external_exports.string().optional()
21939
22068
  })
21940
22069
  }),
21941
22070
  external_exports.object({
@@ -21952,7 +22081,8 @@ var uiMessagesSchema = lazySchema(
21952
22081
  approval: external_exports.object({
21953
22082
  id: external_exports.string(),
21954
22083
  approved: external_exports.boolean(),
21955
- reason: external_exports.string().optional()
22084
+ reason: external_exports.string().optional(),
22085
+ signature: external_exports.string().optional()
21956
22086
  })
21957
22087
  }),
21958
22088
  external_exports.object({
@@ -21971,7 +22101,8 @@ var uiMessagesSchema = lazySchema(
21971
22101
  approval: external_exports.object({
21972
22102
  id: external_exports.string(),
21973
22103
  approved: external_exports.literal(true),
21974
- reason: external_exports.string().optional()
22104
+ reason: external_exports.string().optional(),
22105
+ signature: external_exports.string().optional()
21975
22106
  }).optional()
21976
22107
  }),
21977
22108
  external_exports.object({
@@ -21990,7 +22121,8 @@ var uiMessagesSchema = lazySchema(
21990
22121
  approval: external_exports.object({
21991
22122
  id: external_exports.string(),
21992
22123
  approved: external_exports.literal(true),
21993
- reason: external_exports.string().optional()
22124
+ reason: external_exports.string().optional(),
22125
+ signature: external_exports.string().optional()
21994
22126
  }).optional()
21995
22127
  }),
21996
22128
  external_exports.object({
@@ -22007,7 +22139,8 @@ var uiMessagesSchema = lazySchema(
22007
22139
  approval: external_exports.object({
22008
22140
  id: external_exports.string(),
22009
22141
  approved: external_exports.literal(false),
22010
- reason: external_exports.string().optional()
22142
+ reason: external_exports.string().optional(),
22143
+ signature: external_exports.string().optional()
22011
22144
  })
22012
22145
  }),
22013
22146
  external_exports.object({
@@ -22047,7 +22180,8 @@ var uiMessagesSchema = lazySchema(
22047
22180
  approval: external_exports.object({
22048
22181
  id: external_exports.string(),
22049
22182
  approved: external_exports.never().optional(),
22050
- reason: external_exports.never().optional()
22183
+ reason: external_exports.never().optional(),
22184
+ signature: external_exports.string().optional()
22051
22185
  })
22052
22186
  }),
22053
22187
  external_exports.object({
@@ -22063,7 +22197,8 @@ var uiMessagesSchema = lazySchema(
22063
22197
  approval: external_exports.object({
22064
22198
  id: external_exports.string(),
22065
22199
  approved: external_exports.boolean(),
22066
- reason: external_exports.string().optional()
22200
+ reason: external_exports.string().optional(),
22201
+ signature: external_exports.string().optional()
22067
22202
  })
22068
22203
  }),
22069
22204
  external_exports.object({
@@ -22081,7 +22216,8 @@ var uiMessagesSchema = lazySchema(
22081
22216
  approval: external_exports.object({
22082
22217
  id: external_exports.string(),
22083
22218
  approved: external_exports.literal(true),
22084
- reason: external_exports.string().optional()
22219
+ reason: external_exports.string().optional(),
22220
+ signature: external_exports.string().optional()
22085
22221
  }).optional()
22086
22222
  }),
22087
22223
  external_exports.object({
@@ -22099,7 +22235,8 @@ var uiMessagesSchema = lazySchema(
22099
22235
  approval: external_exports.object({
22100
22236
  id: external_exports.string(),
22101
22237
  approved: external_exports.literal(true),
22102
- reason: external_exports.string().optional()
22238
+ reason: external_exports.string().optional(),
22239
+ signature: external_exports.string().optional()
22103
22240
  }).optional()
22104
22241
  }),
22105
22242
  external_exports.object({
@@ -22115,11 +22252,24 @@ var uiMessagesSchema = lazySchema(
22115
22252
  approval: external_exports.object({
22116
22253
  id: external_exports.string(),
22117
22254
  approved: external_exports.literal(false),
22118
- reason: external_exports.string().optional()
22255
+ reason: external_exports.string().optional(),
22256
+ signature: external_exports.string().optional()
22119
22257
  })
22120
22258
  })
22121
22259
  ])
22122
- ).nonempty("Message must contain at least one part")
22260
+ )
22261
+ }).superRefine((message, context2) => {
22262
+ if (message.role !== "assistant" && message.parts.length === 0) {
22263
+ context2.addIssue({
22264
+ origin: "array",
22265
+ code: "too_small",
22266
+ minimum: 1,
22267
+ inclusive: true,
22268
+ input: message.parts,
22269
+ path: ["parts"],
22270
+ message: "Message must contain at least one part"
22271
+ });
22272
+ }
22123
22273
  })
22124
22274
  ).nonempty("Messages array must not be empty")
22125
22275
  )
@@ -22130,11 +22280,11 @@ function createDownload(options) {
22130
22280
  }
22131
22281
  var originalGenerateId4 = createIdGenerator({ prefix: "aiobj", size: 24 });
22132
22282
  var defaultDownload = createDownload();
22133
- var name20 = "AI_NoSuchProviderError";
22134
- var marker20 = `vercel.ai.error.${name20}`;
22135
- var symbol20 = Symbol.for(marker20);
22136
- var _a20;
22137
- _a20 = symbol20;
22283
+ var name21 = "AI_NoSuchProviderError";
22284
+ var marker21 = `vercel.ai.error.${name21}`;
22285
+ var symbol21 = Symbol.for(marker21);
22286
+ var _a21;
22287
+ _a21 = symbol21;
22138
22288
  var defaultDownload2 = createDownload();
22139
22289
 
22140
22290
  // src/lib/cloud-api.ts
@@ -22197,15 +22347,15 @@ var sealProviderKey = async (providerApiKey, puckApiKey) => {
22197
22347
  "BYOK requires the WebCrypto API (Node 18+ or an edge runtime) to encrypt the provider key"
22198
22348
  );
22199
22349
  }
22200
- const encoder = new TextEncoder();
22201
- const plaintext = encoder.encode(providerApiKey);
22350
+ const encoder2 = new TextEncoder();
22351
+ const plaintext = encoder2.encode(providerApiKey);
22202
22352
  if (plaintext.length > MAX_PLAINTEXT_BYTES) {
22203
22353
  throw new Error(
22204
22354
  `Provider API key is too long to seal (${plaintext.length} bytes, max ${MAX_PLAINTEXT_BYTES})`
22205
22355
  );
22206
22356
  }
22207
22357
  const ciphertext = await crypto.subtle.encrypt(
22208
- { name: "RSA-OAEP", label: encoder.encode(puckApiKey) },
22358
+ { name: "RSA-OAEP", label: encoder2.encode(puckApiKey) },
22209
22359
  await importPublicKey(sealingKey.publicKey),
22210
22360
  plaintext
22211
22361
  );
@@ -22232,16 +22382,16 @@ var processUserTool = async ({
22232
22382
  }
22233
22383
  const responses = [];
22234
22384
  for (let i = 0; i < requestTools.length; i++) {
22235
- const { name: name21, input } = requestTools[i];
22236
- const tool2 = tools?.[name21];
22385
+ const { name: name23, input } = requestTools[i];
22386
+ const tool2 = tools?.[name23];
22237
22387
  if (!tool2) {
22238
- throw new Error(`An unknown tool was called: ${name21}`);
22388
+ throw new Error(`An unknown tool was called: ${name23}`);
22239
22389
  }
22240
22390
  if (!input) {
22241
22391
  throw new Error(`Input was not present in tool call: ${toolCallId}`);
22242
22392
  }
22243
22393
  const output = await tool2.execute(input);
22244
- responses.push({ name: name21, input, output });
22394
+ responses.push({ name: name23, input, output });
22245
22395
  }
22246
22396
  const res = await fetch(`${host}/tool`, {
22247
22397
  headers: { "x-api-key": apiKey },
@@ -22280,9 +22430,34 @@ async function* iterateSSE(body) {
22280
22430
  }
22281
22431
  }
22282
22432
 
22433
+ // src/lib/fetch-with-retry.ts
22434
+ init_react_import();
22435
+ var MAX_RETRIES = 2;
22436
+ var MAX_RETRY_AFTER_SECONDS = 10;
22437
+ var sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
22438
+ async function fetchWithRetry(input, init) {
22439
+ for (let attempt = 0; ; attempt++) {
22440
+ const res = await fetch(input, init);
22441
+ if (res.ok || res.status !== 429 || attempt >= MAX_RETRIES) {
22442
+ return res;
22443
+ }
22444
+ const retryAfter = Number(res.headers.get("Retry-After"));
22445
+ if (!Number.isFinite(retryAfter) || retryAfter <= 0 || retryAfter > MAX_RETRY_AFTER_SECONDS) {
22446
+ return res;
22447
+ }
22448
+ await res.body?.cancel().catch(() => {
22449
+ });
22450
+ await sleep(retryAfter * 1e3);
22451
+ }
22452
+ }
22453
+
22283
22454
  // src/lib/cloud-api.ts
22284
22455
  var DEFAULT_API_VERSION = "v2";
22285
- var CLOUD_CLIENT_VERSION = true ? "0.8.0-canary.fdb02235" : "unknown";
22456
+ var DEFAULT_V2_MODELS = {
22457
+ assembly: "openai/gpt-5.4-mini",
22458
+ design: "openai/gpt-5.6-luna"
22459
+ };
22460
+ var CLOUD_CLIENT_VERSION = true ? "0.8.0" : "unknown";
22286
22461
  var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22287
22462
  const {
22288
22463
  ai = {},
@@ -22295,15 +22470,13 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22295
22470
  "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
22296
22471
  );
22297
22472
  }
22298
- const { context, tools = {}, designMode, model, providerOptions } = ai;
22299
- const providerApiKey = model ? ai.providerApiKey ?? process.env.OPENAI_API_KEY : void 0;
22300
- if (model && !providerApiKey) {
22301
- throw new Error(
22302
- `No provider API key found for "${model}". Please provide one via the providerApiKey parameter.`
22303
- );
22304
- }
22473
+ const { context, tools = {}, designMode, providerOptions } = ai;
22474
+ const bodyMode = "mode" in body ? body.mode : void 0;
22475
+ const mode = bodyMode === "design" || bodyMode === void 0 && ai.mode === "design" ? "design" : "assembly";
22476
+ const model = ai.model ?? (apiVersion === DEFAULT_API_VERSION ? DEFAULT_V2_MODELS[mode] : void 0);
22477
+ const providerApiKey = ai.model || designMode?.model ? ai.providerApiKey ?? process.env.OPENAI_API_KEY : void 0;
22305
22478
  const sealedProviderKey = providerApiKey ? await sealProviderKey(providerApiKey, apiKey) : void 0;
22306
- const res = await fetch(`${host}/${path}`, {
22479
+ const res = await fetchWithRetry(`${host}/${path}`, {
22307
22480
  headers: {
22308
22481
  "x-api-key": apiKey,
22309
22482
  "puck-api-version": apiVersion,
@@ -22319,7 +22492,9 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22319
22492
  ...designMode ? {
22320
22493
  designMode
22321
22494
  } : {},
22322
- ...model ? { byok: { model, providerOptions } } : {}
22495
+ // "byok" is the historical wire slot for the model request; the
22496
+ // platform bills it Puck-hosted when no key header accompanies it.
22497
+ ...model || providerOptions ? { byok: { model, providerOptions } } : {}
22323
22498
  })
22324
22499
  });
22325
22500
  if (!res.body) {
@@ -22334,6 +22509,9 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22334
22509
  if (chunk.type === "data-user-tool") {
22335
22510
  await processUserTool({ data: chunk.data, tools, options });
22336
22511
  } else {
22512
+ if (chunk.type === "data-version-notice") {
22513
+ console.warn(chunk.data.message);
22514
+ }
22337
22515
  onChunk(chunk);
22338
22516
  }
22339
22517
  }
@@ -22341,9 +22519,14 @@ var cloudApi = async (path, body, options = {}, onChunk, forwardHeaders) => {
22341
22519
  };
22342
22520
 
22343
22521
  // src/api/chat.ts
22522
+ var handleStreamError = (error48) => {
22523
+ console.error(error48);
22524
+ return error48 instanceof Error ? error48.message : "An error occurred.";
22525
+ };
22344
22526
  function chatPrivate({ chatId, messages, config: config2, pageData, mode }, options = {}, forwardHeaders) {
22345
22527
  const resolvedMode = mode ?? options?.ai?.mode;
22346
22528
  const stream = createUIMessageStream({
22529
+ onError: handleStreamError,
22347
22530
  execute: async ({ writer }) => {
22348
22531
  await cloudApi(
22349
22532
  "chat",
@@ -22365,6 +22548,7 @@ function chatPrivate({ chatId, messages, config: config2, pageData, mode }, opti
22365
22548
  function chat({ chatId, messages, config: config2, pageData }, options = {}, forwardHeaders) {
22366
22549
  const resolvedMode = options?.ai?.mode;
22367
22550
  const stream = createUIMessageStream({
22551
+ onError: handleStreamError,
22368
22552
  execute: async ({ writer }) => {
22369
22553
  await cloudApi(
22370
22554
  "chat",
@@ -22893,20 +23077,25 @@ async function generate({
22893
23077
  apiKey,
22894
23078
  host
22895
23079
  };
22896
- await cloudApi(
22897
- "generate",
22898
- { prompt, config: config2, pageData, mode },
22899
- options,
22900
- (chunk) => {
22901
- if (chunk.type === "data-page") {
22902
- result = chunk.data;
22903
- } else if (chunk.type === "data-finish") {
22904
- onFinish?.(chunk.data);
22905
- } else if (chunk.type === "error") {
22906
- throw new Error(chunk.errorText);
23080
+ try {
23081
+ await cloudApi(
23082
+ "generate",
23083
+ { prompt, config: config2, pageData, mode },
23084
+ options,
23085
+ (chunk) => {
23086
+ if (chunk.type === "data-page") {
23087
+ result = chunk.data;
23088
+ } else if (chunk.type === "data-finish") {
23089
+ onFinish?.(chunk.data);
23090
+ } else if (chunk.type === "error") {
23091
+ throw new Error(chunk.errorText);
23092
+ }
22907
23093
  }
22908
- }
22909
- );
23094
+ );
23095
+ } catch (error48) {
23096
+ console.error(error48);
23097
+ throw error48;
23098
+ }
22910
23099
  return result;
22911
23100
  }
22912
23101