@hintergrund/ui 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/Builder-H8tY8V9I.js +14172 -0
  2. package/dist/admin.js +11160 -9739
  3. package/dist/{anthropic-UhrJpH25.js → anthropic-messages-C3hIUlsA.js} +1134 -1055
  4. package/dist/azure-openai-responses-t7u41KMr.js +222 -0
  5. package/dist/builder.js +2 -2
  6. package/dist/client-Cd7yMX39.js +7860 -0
  7. package/dist/deferred-tools-BZWMWBYN.js +28 -0
  8. package/dist/error-body-BUPcH4GF.js +71 -0
  9. package/dist/github-copilot-headers-B1RBGoZi.js +21 -0
  10. package/dist/{global-CFcrkAa3.js → global-Bk9T4Af5.js} +17896 -16508
  11. package/dist/google-generative-ai-6ZG79NDC.js +264 -0
  12. package/dist/{google-shared-BmdaIInh.js → google-shared-C6y4fA42.js} +1135 -1104
  13. package/dist/google-vertex-f2myaAmm.js +305 -0
  14. package/dist/headers-D4iLzGaS.js +21 -0
  15. package/dist/json-parse-LZdWp-Nd.js +232 -0
  16. package/dist/login.js +79 -75
  17. package/dist/mistral-conversations-D16H8Mgq.js +513 -0
  18. package/dist/openai-codex-responses-DIHPbnIS.js +947 -0
  19. package/dist/openai-completions-vDHGFsWV.js +741 -0
  20. package/dist/{headers-u7rXGJ9f.js → openai-prompt-cache-BJwqbEDx.js} +7 -6
  21. package/dist/openai-responses-B0rjAJxx.js +184 -0
  22. package/dist/openai-responses-shared-DqdzMfa_.js +477 -0
  23. package/dist/pi-messages-DB2BtH-g.js +251 -0
  24. package/dist/pi-user-agent-CUqx-qiX.js +13 -0
  25. package/dist/provider-env-D2VjEV3S.js +26 -0
  26. package/dist/provider-retry-BsigVlMg.js +67 -0
  27. package/dist/setup.js +275 -188
  28. package/dist/transform-messages-CsKsy6b4.js +398 -0
  29. package/package.json +4 -5
  30. package/dist/Builder-B0XYsyXe.js +0 -163449
  31. package/dist/azure-openai-responses-DAC03Qw1.js +0 -203
  32. package/dist/client-Sh7wNjbG.js +0 -5277
  33. package/dist/github-copilot-headers-DWh_6bE3.js +0 -35
  34. package/dist/google-CVz_TaG6.js +0 -248
  35. package/dist/google-vertex-C6GE41DE.js +0 -285
  36. package/dist/json-parse-DmJ6NiZE.js +0 -93
  37. package/dist/mistral-DqYbzWvv.js +0 -22932
  38. package/dist/openai-codex-responses-ZWuD9ryk.js +0 -700
  39. package/dist/openai-completions-B6B2OwYj.js +0 -535
  40. package/dist/openai-responses-D9Ip2Wgd.js +0 -142
  41. package/dist/openai-responses-shared-eUUJSL4D.js +0 -324
  42. package/dist/transform-messages-CkpQp6fJ.js +0 -132
@@ -1,12 +1,16 @@
1
- import { d as cs, e as rn, f as It } from "./Builder-B0XYsyXe.js";
2
- import { h as an } from "./headers-u7rXGJ9f.js";
3
- import { p as Ot, a as on } from "./json-parse-DmJ6NiZE.js";
4
- import { b as cn, a as ln, s as W, t as un } from "./transform-messages-CkpQp6fJ.js";
5
- import { h as hn, b as dn, r as fn } from "./github-copilot-headers-DWh_6bE3.js";
1
+ import { d as an, f as Ct } from "./Builder-H8tY8V9I.js";
2
+ import { s as on } from "./deferred-tools-BZWMWBYN.js";
3
+ import { h as cn } from "./headers-D4iLzGaS.js";
4
+ import { p as Ot, a as ln } from "./json-parse-LZdWp-Nd.js";
5
+ import { g as un } from "./pi-user-agent-CUqx-qiX.js";
6
+ import { g as hn } from "./provider-env-D2VjEV3S.js";
7
+ import { r as dn } from "./provider-retry-BsigVlMg.js";
8
+ import { b as fn, h as pn, i as gn, t as mn, s as N, d as _n, e as bn } from "./transform-messages-CsKsy6b4.js";
9
+ import { h as yn, b as wn } from "./github-copilot-headers-B1RBGoZi.js";
6
10
  typeof globalThis.process > "u" && (globalThis.process = { env: {}, platform: "browser", version: "", versions: {}, browser: !0, nextTick: function(r) {
7
11
  return Promise.resolve().then(r);
8
12
  } });
9
- function d(r, e, t, s, n) {
13
+ function p(r, e, t, s, n) {
10
14
  if (typeof e == "function" ? r !== e || !0 : !e.has(r))
11
15
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
12
16
  return e.set(r, t), t;
@@ -25,12 +29,12 @@ let ls = function() {
25
29
  const e = new Uint8Array(1), t = r ? () => r.getRandomValues(e)[0] : () => Math.random() * 255 & 255;
26
30
  return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (s) => (+s ^ t() & 15 >> +s / 4).toString(16));
27
31
  };
28
- function we(r) {
32
+ function ke(r) {
29
33
  return typeof r == "object" && r !== null && // Spec-compliant fetch implementations
30
34
  ("name" in r && r.name === "AbortError" || // Expo fetch
31
35
  "message" in r && String(r.message).includes("FetchRequestCanceledException"));
32
36
  }
33
- const dt = (r) => {
37
+ const gt = (r) => {
34
38
  if (r instanceof Error)
35
39
  return r;
36
40
  if (typeof r == "object" && r !== null) {
@@ -60,7 +64,7 @@ class x extends b {
60
64
  }
61
65
  static generate(e, t, s, n) {
62
66
  if (!e || !n)
63
- return new ze({ message: s, cause: dt(t) });
67
+ return new ze({ message: s, cause: gt(t) });
64
68
  const a = t, i = a?.error?.type;
65
69
  return e === 400 ? new hs(e, a, s, n, i) : e === 401 ? new ds(e, a, s, n, i) : e === 403 ? new fs(e, a, s, n, i) : e === 404 ? new ps(e, a, s, n, i) : e === 409 ? new gs(e, a, s, n, i) : e === 422 ? new ms(e, a, s, n, i) : e === 429 ? new _s(e, a, s, n, i) : e >= 500 ? new bs(e, a, s, n, i) : new x(e, a, s, n, i);
66
70
  }
@@ -96,9 +100,9 @@ class _s extends x {
96
100
  }
97
101
  class bs extends x {
98
102
  }
99
- const pn = /^[a-z][a-z0-9+.-]*:/i, gn = (r) => pn.test(r);
100
- let ft = (r) => (ft = Array.isArray, ft(r)), Bt = ft;
101
- function pt(r) {
103
+ const kn = /^[a-z][a-z0-9+.-]*:/i, Sn = (r) => kn.test(r);
104
+ let mt = (r) => (mt = Array.isArray, mt(r)), Bt = mt;
105
+ function _t(r) {
102
106
  return typeof r != "object" ? {} : r ?? {};
103
107
  }
104
108
  function Lt(r) {
@@ -108,10 +112,10 @@ function Lt(r) {
108
112
  return !1;
109
113
  return !0;
110
114
  }
111
- function mn(r, e) {
115
+ function xn(r, e) {
112
116
  return Object.prototype.hasOwnProperty.call(r, e);
113
117
  }
114
- const _n = (r, e) => {
118
+ const vn = (r, e) => {
115
119
  if (typeof e != "number" || !Number.isInteger(e))
116
120
  throw new b(`${r} must be an integer`);
117
121
  if (e < 0)
@@ -123,30 +127,30 @@ const _n = (r, e) => {
123
127
  } catch {
124
128
  return;
125
129
  }
126
- }, bn = (r) => new Promise((e) => setTimeout(e, r)), Z = "0.91.1", yn = () => (
130
+ }, Rn = (r) => new Promise((e) => setTimeout(e, r)), ee = "0.91.1", Tn = () => (
127
131
  // @ts-ignore
128
132
  typeof window < "u" && // @ts-ignore
129
133
  typeof window.document < "u" && // @ts-ignore
130
134
  typeof navigator < "u"
131
135
  );
132
- function wn() {
136
+ function Mn() {
133
137
  return typeof Deno < "u" && Deno.build != null ? "deno" : typeof EdgeRuntime < "u" ? "edge" : Object.prototype.toString.call(typeof globalThis.process < "u" ? globalThis.process : 0) === "[object process]" ? "node" : "unknown";
134
138
  }
135
- const kn = () => {
136
- const r = wn();
139
+ const En = () => {
140
+ const r = Mn();
137
141
  if (r === "deno")
138
142
  return {
139
143
  "X-Stainless-Lang": "js",
140
- "X-Stainless-Package-Version": Z,
144
+ "X-Stainless-Package-Version": ee,
141
145
  "X-Stainless-OS": jt(Deno.build.os),
142
- "X-Stainless-Arch": Ct(Deno.build.arch),
146
+ "X-Stainless-Arch": Nt(Deno.build.arch),
143
147
  "X-Stainless-Runtime": "deno",
144
148
  "X-Stainless-Runtime-Version": typeof Deno.version == "string" ? Deno.version : Deno.version?.deno ?? "unknown"
145
149
  };
146
150
  if (typeof EdgeRuntime < "u")
147
151
  return {
148
152
  "X-Stainless-Lang": "js",
149
- "X-Stainless-Package-Version": Z,
153
+ "X-Stainless-Package-Version": ee,
150
154
  "X-Stainless-OS": "Unknown",
151
155
  "X-Stainless-Arch": `other:${EdgeRuntime}`,
152
156
  "X-Stainless-Runtime": "edge",
@@ -155,30 +159,30 @@ const kn = () => {
155
159
  if (r === "node")
156
160
  return {
157
161
  "X-Stainless-Lang": "js",
158
- "X-Stainless-Package-Version": Z,
162
+ "X-Stainless-Package-Version": ee,
159
163
  "X-Stainless-OS": jt(globalThis.process.platform ?? "unknown"),
160
- "X-Stainless-Arch": Ct(globalThis.process.arch ?? "unknown"),
164
+ "X-Stainless-Arch": Nt(globalThis.process.arch ?? "unknown"),
161
165
  "X-Stainless-Runtime": "node",
162
166
  "X-Stainless-Runtime-Version": globalThis.process.version ?? "unknown"
163
167
  };
164
- const e = Sn();
168
+ const e = Pn();
165
169
  return e ? {
166
170
  "X-Stainless-Lang": "js",
167
- "X-Stainless-Package-Version": Z,
171
+ "X-Stainless-Package-Version": ee,
168
172
  "X-Stainless-OS": "Unknown",
169
173
  "X-Stainless-Arch": "unknown",
170
174
  "X-Stainless-Runtime": `browser:${e.browser}`,
171
175
  "X-Stainless-Runtime-Version": e.version
172
176
  } : {
173
177
  "X-Stainless-Lang": "js",
174
- "X-Stainless-Package-Version": Z,
178
+ "X-Stainless-Package-Version": ee,
175
179
  "X-Stainless-OS": "Unknown",
176
180
  "X-Stainless-Arch": "unknown",
177
181
  "X-Stainless-Runtime": "unknown",
178
182
  "X-Stainless-Runtime-Version": "unknown"
179
183
  };
180
184
  };
181
- function Sn() {
185
+ function Pn() {
182
186
  if (typeof navigator > "u" || !navigator)
183
187
  return null;
184
188
  const r = [
@@ -198,10 +202,10 @@ function Sn() {
198
202
  }
199
203
  return null;
200
204
  }
201
- const Ct = (r) => r === "x32" ? "x32" : r === "x86_64" || r === "x64" ? "x64" : r === "arm" ? "arm" : r === "aarch64" || r === "arm64" ? "arm64" : r ? `other:${r}` : "unknown", jt = (r) => (r = r.toLowerCase(), r.includes("ios") ? "iOS" : r === "android" ? "Android" : r === "darwin" ? "MacOS" : r === "win32" ? "Windows" : r === "freebsd" ? "FreeBSD" : r === "openbsd" ? "OpenBSD" : r === "linux" ? "Linux" : r ? `Other:${r}` : "Unknown");
202
- let Nt;
203
- const xn = () => Nt ?? (Nt = kn());
204
- function vn() {
205
+ const Nt = (r) => r === "x32" ? "x32" : r === "x86_64" || r === "x64" ? "x64" : r === "arm" ? "arm" : r === "aarch64" || r === "arm64" ? "arm64" : r ? `other:${r}` : "unknown", jt = (r) => (r = r.toLowerCase(), r.includes("ios") ? "iOS" : r === "android" ? "Android" : r === "darwin" ? "MacOS" : r === "win32" ? "Windows" : r === "freebsd" ? "FreeBSD" : r === "openbsd" ? "OpenBSD" : r === "linux" ? "Linux" : r ? `Other:${r}` : "Unknown");
206
+ let qt;
207
+ const An = () => qt ?? (qt = En());
208
+ function $n() {
205
209
  if (typeof fetch < "u")
206
210
  return fetch;
207
211
  throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new Anthropic({ fetch })` or polyfill the global, `globalThis.fetch = fetch`");
@@ -226,7 +230,7 @@ function ks(r) {
226
230
  }
227
231
  });
228
232
  }
229
- function yt(r) {
233
+ function St(r) {
230
234
  if (r[Symbol.asyncIterator])
231
235
  return r;
232
236
  const e = r.getReader();
@@ -248,7 +252,7 @@ function yt(r) {
248
252
  }
249
253
  };
250
254
  }
251
- async function Mn(r) {
255
+ async function In(r) {
252
256
  if (r === null || typeof r != "object")
253
257
  return;
254
258
  if (r[Symbol.asyncIterator]) {
@@ -258,13 +262,13 @@ async function Mn(r) {
258
262
  const e = r.getReader(), t = e.cancel();
259
263
  e.releaseLock(), await t;
260
264
  }
261
- const Rn = ({ headers: r, body: e }) => ({
265
+ const Cn = ({ headers: r, body: e }) => ({
262
266
  bodyHeaders: {
263
267
  "content-type": "application/json"
264
268
  },
265
269
  body: JSON.stringify(e)
266
270
  });
267
- function Tn(r) {
271
+ function On(r) {
268
272
  return Object.entries(r).filter(([e, t]) => typeof t < "u").map(([e, t]) => {
269
273
  if (typeof t == "string" || typeof t == "number" || typeof t == "boolean")
270
274
  return `${encodeURIComponent(e)}=${encodeURIComponent(t)}`;
@@ -273,7 +277,7 @@ function Tn(r) {
273
277
  throw new b(`Cannot stringify type ${typeof t}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`);
274
278
  }).join("&");
275
279
  }
276
- function En(r) {
280
+ function Bn(r) {
277
281
  let e = 0;
278
282
  for (const n of r)
279
283
  e += n.length;
@@ -283,39 +287,39 @@ function En(r) {
283
287
  t.set(n, s), s += n.length;
284
288
  return t;
285
289
  }
286
- let qt;
287
- function wt(r) {
290
+ let Wt;
291
+ function xt(r) {
288
292
  let e;
289
- return (qt ?? (e = new globalThis.TextEncoder(), qt = e.encode.bind(e)))(r);
293
+ return (Wt ?? (e = new globalThis.TextEncoder(), Wt = e.encode.bind(e)))(r);
290
294
  }
291
- let Wt;
292
- function Ut(r) {
295
+ let Ut;
296
+ function Ft(r) {
293
297
  let e;
294
- return (Wt ?? (e = new globalThis.TextDecoder(), Wt = e.decode.bind(e)))(r);
298
+ return (Ut ?? (e = new globalThis.TextDecoder(), Ut = e.decode.bind(e)))(r);
295
299
  }
296
300
  var P, A;
297
- class ke {
301
+ class Se {
298
302
  constructor() {
299
- P.set(this, void 0), A.set(this, void 0), d(this, P, new Uint8Array()), d(this, A, null);
303
+ P.set(this, void 0), A.set(this, void 0), p(this, P, new Uint8Array()), p(this, A, null);
300
304
  }
301
305
  decode(e) {
302
306
  if (e == null)
303
307
  return [];
304
- const t = e instanceof ArrayBuffer ? new Uint8Array(e) : typeof e == "string" ? wt(e) : e;
305
- d(this, P, En([o(this, P, "f"), t]));
308
+ const t = e instanceof ArrayBuffer ? new Uint8Array(e) : typeof e == "string" ? xt(e) : e;
309
+ p(this, P, Bn([o(this, P, "f"), t]));
306
310
  const s = [];
307
311
  let n;
308
- for (; (n = Pn(o(this, P, "f"), o(this, A, "f"))) != null; ) {
312
+ for (; (n = Ln(o(this, P, "f"), o(this, A, "f"))) != null; ) {
309
313
  if (n.carriage && o(this, A, "f") == null) {
310
- d(this, A, n.index);
314
+ p(this, A, n.index);
311
315
  continue;
312
316
  }
313
317
  if (o(this, A, "f") != null && (n.index !== o(this, A, "f") + 1 || n.carriage)) {
314
- s.push(Ut(o(this, P, "f").subarray(0, o(this, A, "f") - 1))), d(this, P, o(this, P, "f").subarray(o(this, A, "f"))), d(this, A, null);
318
+ s.push(Ft(o(this, P, "f").subarray(0, o(this, A, "f") - 1))), p(this, P, o(this, P, "f").subarray(o(this, A, "f"))), p(this, A, null);
315
319
  continue;
316
320
  }
317
- const a = o(this, A, "f") !== null ? n.preceding - 1 : n.preceding, i = Ut(o(this, P, "f").subarray(0, a));
318
- s.push(i), d(this, P, o(this, P, "f").subarray(n.index)), d(this, A, null);
321
+ const a = o(this, A, "f") !== null ? n.preceding - 1 : n.preceding, i = Ft(o(this, P, "f").subarray(0, a));
322
+ s.push(i), p(this, P, o(this, P, "f").subarray(n.index)), p(this, A, null);
319
323
  }
320
324
  return s;
321
325
  }
@@ -325,10 +329,10 @@ class ke {
325
329
  }
326
330
  }
327
331
  P = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap();
328
- ke.NEWLINE_CHARS = /* @__PURE__ */ new Set([`
332
+ Se.NEWLINE_CHARS = /* @__PURE__ */ new Set([`
329
333
  `, "\r"]);
330
- ke.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
331
- function Pn(r, e) {
334
+ Se.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
335
+ function Ln(r, e) {
332
336
  for (let n = e ?? 0; n < r.length; n++) {
333
337
  if (r[n] === 10)
334
338
  return { preceding: n, index: n + 1, carriage: !1 };
@@ -337,7 +341,7 @@ function Pn(r, e) {
337
341
  }
338
342
  return null;
339
343
  }
340
- function An(r) {
344
+ function Nn(r) {
341
345
  for (let s = 0; s < r.length - 1; s++) {
342
346
  if (r[s] === 10 && r[s + 1] === 10 || r[s] === 13 && r[s + 1] === 13)
343
347
  return s + 2;
@@ -352,86 +356,86 @@ const Xe = {
352
356
  warn: 300,
353
357
  info: 400,
354
358
  debug: 500
355
- }, Ft = (r, e, t) => {
359
+ }, Ht = (r, e, t) => {
356
360
  if (r) {
357
- if (mn(Xe, r))
361
+ if (xn(Xe, r))
358
362
  return r;
359
- M(t).warn(`${e} was set to ${JSON.stringify(r)}, expected one of ${JSON.stringify(Object.keys(Xe))}`);
363
+ R(t).warn(`${e} was set to ${JSON.stringify(r)}, expected one of ${JSON.stringify(Object.keys(Xe))}`);
360
364
  }
361
365
  };
362
- function _e() {
366
+ function be() {
363
367
  }
364
- function Me(r, e, t) {
365
- return !e || Xe[r] > Xe[t] ? _e : e[r].bind(e);
368
+ function Te(r, e, t) {
369
+ return !e || Xe[r] > Xe[t] ? be : e[r].bind(e);
366
370
  }
367
- const $n = {
368
- error: _e,
369
- warn: _e,
370
- info: _e,
371
- debug: _e
371
+ const jn = {
372
+ error: be,
373
+ warn: be,
374
+ info: be,
375
+ debug: be
372
376
  };
373
377
  let Dt = /* @__PURE__ */ new WeakMap();
374
- function M(r) {
378
+ function R(r) {
375
379
  const e = r.logger, t = r.logLevel ?? "off";
376
380
  if (!e)
377
- return $n;
381
+ return jn;
378
382
  const s = Dt.get(e);
379
383
  if (s && s[0] === t)
380
384
  return s[1];
381
385
  const n = {
382
- error: Me("error", e, t),
383
- warn: Me("warn", e, t),
384
- info: Me("info", e, t),
385
- debug: Me("debug", e, t)
386
+ error: Te("error", e, t),
387
+ warn: Te("warn", e, t),
388
+ info: Te("info", e, t),
389
+ debug: Te("debug", e, t)
386
390
  };
387
391
  return Dt.set(e, [t, n]), n;
388
392
  }
389
- const z = (r) => (r.options && (r.options = { ...r.options }, delete r.options.headers), r.headers && (r.headers = Object.fromEntries((r.headers instanceof Headers ? [...r.headers] : Object.entries(r.headers)).map(([e, t]) => [
393
+ const K = (r) => (r.options && (r.options = { ...r.options }, delete r.options.headers), r.headers && (r.headers = Object.fromEntries((r.headers instanceof Headers ? [...r.headers] : Object.entries(r.headers)).map(([e, t]) => [
390
394
  e,
391
395
  e.toLowerCase() === "x-api-key" || e.toLowerCase() === "authorization" || e.toLowerCase() === "cookie" || e.toLowerCase() === "set-cookie" ? "***" : t
392
396
  ]))), "retryOfRequestLogID" in r && (r.retryOfRequestLogID && (r.retryOf = r.retryOfRequestLogID), delete r.retryOfRequestLogID), r);
393
- var se;
394
- class C {
397
+ var ne;
398
+ class j {
395
399
  constructor(e, t, s) {
396
- this.iterator = e, se.set(this, void 0), this.controller = t, d(this, se, s);
400
+ this.iterator = e, ne.set(this, void 0), this.controller = t, p(this, ne, s);
397
401
  }
398
402
  static fromSSEResponse(e, t, s) {
399
403
  let n = !1;
400
- const a = s ? M(s) : console;
404
+ const a = s ? R(s) : console;
401
405
  async function* i() {
402
406
  if (n)
403
407
  throw new b("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");
404
408
  n = !0;
405
- let c = !1;
409
+ let l = !1;
406
410
  try {
407
- for await (const l of In(e, t)) {
408
- if (l.event === "completion")
411
+ for await (const c of qn(e, t)) {
412
+ if (c.event === "completion")
409
413
  try {
410
- yield JSON.parse(l.data);
411
- } catch (h) {
412
- throw a.error("Could not parse message into JSON:", l.data), a.error("From chunk:", l.raw), h;
414
+ yield JSON.parse(c.data);
415
+ } catch (f) {
416
+ throw a.error("Could not parse message into JSON:", c.data), a.error("From chunk:", c.raw), f;
413
417
  }
414
- if (l.event === "message_start" || l.event === "message_delta" || l.event === "message_stop" || l.event === "content_block_start" || l.event === "content_block_delta" || l.event === "content_block_stop" || l.event === "message" || l.event === "user.message" || l.event === "user.interrupt" || l.event === "user.tool_confirmation" || l.event === "user.custom_tool_result" || l.event === "agent.message" || l.event === "agent.thinking" || l.event === "agent.tool_use" || l.event === "agent.tool_result" || l.event === "agent.mcp_tool_use" || l.event === "agent.mcp_tool_result" || l.event === "agent.custom_tool_use" || l.event === "agent.thread_context_compacted" || l.event === "session.status_running" || l.event === "session.status_idle" || l.event === "session.status_rescheduled" || l.event === "session.status_terminated" || l.event === "session.error" || l.event === "session.deleted" || l.event === "span.model_request_start" || l.event === "span.model_request_end")
418
+ if (c.event === "message_start" || c.event === "message_delta" || c.event === "message_stop" || c.event === "content_block_start" || c.event === "content_block_delta" || c.event === "content_block_stop" || c.event === "message" || c.event === "user.message" || c.event === "user.interrupt" || c.event === "user.tool_confirmation" || c.event === "user.custom_tool_result" || c.event === "agent.message" || c.event === "agent.thinking" || c.event === "agent.tool_use" || c.event === "agent.tool_result" || c.event === "agent.mcp_tool_use" || c.event === "agent.mcp_tool_result" || c.event === "agent.custom_tool_use" || c.event === "agent.thread_context_compacted" || c.event === "session.status_running" || c.event === "session.status_idle" || c.event === "session.status_rescheduled" || c.event === "session.status_terminated" || c.event === "session.error" || c.event === "session.deleted" || c.event === "span.model_request_start" || c.event === "span.model_request_end")
415
419
  try {
416
- yield JSON.parse(l.data);
417
- } catch (h) {
418
- throw a.error("Could not parse message into JSON:", l.data), a.error("From chunk:", l.raw), h;
420
+ yield JSON.parse(c.data);
421
+ } catch (f) {
422
+ throw a.error("Could not parse message into JSON:", c.data), a.error("From chunk:", c.raw), f;
419
423
  }
420
- if (l.event !== "ping" && l.event === "error") {
421
- const h = ys(l.data) ?? l.data, _ = h?.error?.type;
422
- throw new x(void 0, h, void 0, e.headers, _);
424
+ if (c.event !== "ping" && c.event === "error") {
425
+ const f = ys(c.data) ?? c.data, _ = f?.error?.type;
426
+ throw new x(void 0, f, void 0, e.headers, _);
423
427
  }
424
428
  }
425
- c = !0;
426
- } catch (l) {
427
- if (we(l))
429
+ l = !0;
430
+ } catch (c) {
431
+ if (ke(c))
428
432
  return;
429
- throw l;
433
+ throw c;
430
434
  } finally {
431
- c || t.abort();
435
+ l || t.abort();
432
436
  }
433
437
  }
434
- return new C(i, t, s);
438
+ return new j(i, t, s);
435
439
  }
436
440
  /**
437
441
  * Generates a Stream from a newline-separated ReadableStream
@@ -440,33 +444,33 @@ class C {
440
444
  static fromReadableStream(e, t, s) {
441
445
  let n = !1;
442
446
  async function* a() {
443
- const c = new ke(), l = yt(e);
444
- for await (const h of l)
445
- for (const _ of c.decode(h))
447
+ const l = new Se(), c = St(e);
448
+ for await (const f of c)
449
+ for (const _ of l.decode(f))
446
450
  yield _;
447
- for (const h of c.flush())
448
- yield h;
451
+ for (const f of l.flush())
452
+ yield f;
449
453
  }
450
454
  async function* i() {
451
455
  if (n)
452
456
  throw new b("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");
453
457
  n = !0;
454
- let c = !1;
458
+ let l = !1;
455
459
  try {
456
- for await (const l of a())
457
- c || l && (yield JSON.parse(l));
458
- c = !0;
459
- } catch (l) {
460
- if (we(l))
460
+ for await (const c of a())
461
+ l || c && (yield JSON.parse(c));
462
+ l = !0;
463
+ } catch (c) {
464
+ if (ke(c))
461
465
  return;
462
- throw l;
466
+ throw c;
463
467
  } finally {
464
- c || t.abort();
468
+ l || t.abort();
465
469
  }
466
470
  }
467
- return new C(i, t, s);
471
+ return new j(i, t, s);
468
472
  }
469
- [(se = /* @__PURE__ */ new WeakMap(), Symbol.asyncIterator)]() {
473
+ [(ne = /* @__PURE__ */ new WeakMap(), Symbol.asyncIterator)]() {
470
474
  return this.iterator();
471
475
  }
472
476
  /**
@@ -484,8 +488,8 @@ class C {
484
488
  }
485
489
  });
486
490
  return [
487
- new C(() => n(e), this.controller, o(this, se, "f")),
488
- new C(() => n(t), this.controller, o(this, se, "f"))
491
+ new j(() => n(e), this.controller, o(this, ne, "f")),
492
+ new j(() => n(t), this.controller, o(this, ne, "f"))
489
493
  ];
490
494
  }
491
495
  /**
@@ -505,7 +509,7 @@ class C {
505
509
  const { value: n, done: a } = await t.next();
506
510
  if (a)
507
511
  return s.close();
508
- const i = wt(JSON.stringify(n) + `
512
+ const i = xt(JSON.stringify(n) + `
509
513
  `);
510
514
  s.enqueue(i);
511
515
  } catch (n) {
@@ -518,35 +522,35 @@ class C {
518
522
  });
519
523
  }
520
524
  }
521
- async function* In(r, e) {
525
+ async function* qn(r, e) {
522
526
  if (!r.body)
523
527
  throw e.abort(), typeof globalThis.navigator < "u" && globalThis.navigator.product === "ReactNative" ? new b("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api") : new b("Attempted to iterate over a response with no body");
524
- const t = new Bn(), s = new ke(), n = yt(r.body);
525
- for await (const a of On(n))
528
+ const t = new Un(), s = new Se(), n = St(r.body);
529
+ for await (const a of Wn(n))
526
530
  for (const i of s.decode(a)) {
527
- const c = t.decode(i);
528
- c && (yield c);
531
+ const l = t.decode(i);
532
+ l && (yield l);
529
533
  }
530
534
  for (const a of s.flush()) {
531
535
  const i = t.decode(a);
532
536
  i && (yield i);
533
537
  }
534
538
  }
535
- async function* On(r) {
539
+ async function* Wn(r) {
536
540
  let e = new Uint8Array();
537
541
  for await (const t of r) {
538
542
  if (t == null)
539
543
  continue;
540
- const s = t instanceof ArrayBuffer ? new Uint8Array(t) : typeof t == "string" ? wt(t) : t;
544
+ const s = t instanceof ArrayBuffer ? new Uint8Array(t) : typeof t == "string" ? xt(t) : t;
541
545
  let n = new Uint8Array(e.length + s.length);
542
546
  n.set(e), n.set(s, e.length), e = n;
543
547
  let a;
544
- for (; (a = An(e)) !== -1; )
548
+ for (; (a = Nn(e)) !== -1; )
545
549
  yield e.slice(0, a), e = e.slice(a);
546
550
  }
547
551
  e.length > 0 && (yield e);
548
552
  }
549
- class Bn {
553
+ class Un {
550
554
  constructor() {
551
555
  this.event = null, this.data = [], this.chunks = [];
552
556
  }
@@ -564,32 +568,32 @@ class Bn {
564
568
  }
565
569
  if (this.chunks.push(e), e.startsWith(":"))
566
570
  return null;
567
- let [t, s, n] = Ln(e, ":");
571
+ let [t, s, n] = Fn(e, ":");
568
572
  return n.startsWith(" ") && (n = n.substring(1)), t === "event" ? this.event = n : t === "data" && this.data.push(n), null;
569
573
  }
570
574
  }
571
- function Ln(r, e) {
575
+ function Fn(r, e) {
572
576
  const t = r.indexOf(e);
573
577
  return t !== -1 ? [r.substring(0, t), e, r.substring(t + e.length)] : [r, "", ""];
574
578
  }
575
579
  async function Ss(r, e) {
576
580
  const { response: t, requestLogID: s, retryOfRequestLogID: n, startTime: a } = e, i = await (async () => {
577
581
  if (e.options.stream)
578
- return M(r).debug("response", t.status, t.url, t.headers, t.body), e.options.__streamClass ? e.options.__streamClass.fromSSEResponse(t, e.controller) : C.fromSSEResponse(t, e.controller);
582
+ return R(r).debug("response", t.status, t.url, t.headers, t.body), e.options.__streamClass ? e.options.__streamClass.fromSSEResponse(t, e.controller) : j.fromSSEResponse(t, e.controller);
579
583
  if (t.status === 204)
580
584
  return null;
581
585
  if (e.options.__binaryResponse)
582
586
  return t;
583
- const l = t.headers.get("content-type")?.split(";")[0]?.trim();
584
- if (l?.includes("application/json") || l?.endsWith("+json")) {
587
+ const c = t.headers.get("content-type")?.split(";")[0]?.trim();
588
+ if (c?.includes("application/json") || c?.endsWith("+json")) {
585
589
  if (t.headers.get("content-length") === "0")
586
590
  return;
587
- const p = await t.json();
588
- return xs(p, t);
591
+ const u = await t.json();
592
+ return xs(u, t);
589
593
  }
590
594
  return await t.text();
591
595
  })();
592
- return M(r).debug(`[${s}] response parsed`, z({
596
+ return R(r).debug(`[${s}] response parsed`, K({
593
597
  retryOfRequestLogID: n,
594
598
  url: t.url,
595
599
  status: t.status,
@@ -603,15 +607,15 @@ function xs(r, e) {
603
607
  enumerable: !1
604
608
  });
605
609
  }
606
- var be;
610
+ var ye;
607
611
  class Ge extends Promise {
608
612
  constructor(e, t, s = Ss) {
609
613
  super((n) => {
610
614
  n(null);
611
- }), this.responsePromise = t, this.parseResponse = s, be.set(this, void 0), d(this, be, e);
615
+ }), this.responsePromise = t, this.parseResponse = s, ye.set(this, void 0), p(this, ye, e);
612
616
  }
613
617
  _thenUnwrap(e) {
614
- return new Ge(o(this, be, "f"), this.responsePromise, async (t, s) => xs(e(await this.parseResponse(t, s), s), s.response));
618
+ return new Ge(o(this, ye, "f"), this.responsePromise, async (t, s) => xs(e(await this.parseResponse(t, s), s), s.response));
615
619
  }
616
620
  /**
617
621
  * Gets the raw `Response` instance instead of parsing the response
@@ -644,7 +648,7 @@ class Ge extends Promise {
644
648
  return { data: e, response: t, request_id: t.headers.get("request-id") };
645
649
  }
646
650
  parse() {
647
- return this.parsedPromise || (this.parsedPromise = this.responsePromise.then((e) => this.parseResponse(o(this, be, "f"), e))), this.parsedPromise;
651
+ return this.parsedPromise || (this.parsedPromise = this.responsePromise.then((e) => this.parseResponse(o(this, ye, "f"), e))), this.parsedPromise;
648
652
  }
649
653
  then(e, t) {
650
654
  return this.parse().then(e, t);
@@ -656,11 +660,11 @@ class Ge extends Promise {
656
660
  return this.parse().finally(e);
657
661
  }
658
662
  }
659
- be = /* @__PURE__ */ new WeakMap();
660
- var Re;
663
+ ye = /* @__PURE__ */ new WeakMap();
664
+ var Me;
661
665
  class vs {
662
666
  constructor(e, t, s, n) {
663
- Re.set(this, void 0), d(this, Re, e), this.options = n, this.response = t, this.body = s;
667
+ Me.set(this, void 0), p(this, Me, e), this.options = n, this.response = t, this.body = s;
664
668
  }
665
669
  hasNextPage() {
666
670
  return this.getPaginatedItems().length ? this.nextPageRequestOptions() != null : !1;
@@ -669,20 +673,20 @@ class vs {
669
673
  const e = this.nextPageRequestOptions();
670
674
  if (!e)
671
675
  throw new b("No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.");
672
- return await o(this, Re, "f").requestAPIList(this.constructor, e);
676
+ return await o(this, Me, "f").requestAPIList(this.constructor, e);
673
677
  }
674
678
  async *iterPages() {
675
679
  let e = this;
676
680
  for (yield e; e.hasNextPage(); )
677
681
  e = await e.getNextPage(), yield e;
678
682
  }
679
- async *[(Re = /* @__PURE__ */ new WeakMap(), Symbol.asyncIterator)]() {
683
+ async *[(Me = /* @__PURE__ */ new WeakMap(), Symbol.asyncIterator)]() {
680
684
  for await (const e of this.iterPages())
681
685
  for (const t of e.getPaginatedItems())
682
686
  yield t;
683
687
  }
684
688
  }
685
- class Cn extends Ge {
689
+ class Hn extends Ge {
686
690
  constructor(e, t, s) {
687
691
  super(e, t, async (n, a) => new s(n, a.response, await Ss(n, a), a.options));
688
692
  }
@@ -699,7 +703,7 @@ class Cn extends Ge {
699
703
  yield t;
700
704
  }
701
705
  }
702
- class Se extends vs {
706
+ class xe extends vs {
703
707
  constructor(e, t, s, n) {
704
708
  super(e, t, s, n), this.data = s.data || [], this.has_more = s.has_more || !1, this.first_id = s.first_id || null, this.last_id = s.last_id || null;
705
709
  }
@@ -715,7 +719,7 @@ class Se extends vs {
715
719
  return t ? {
716
720
  ...this.options,
717
721
  query: {
718
- ...pt(this.options.query),
722
+ ..._t(this.options.query),
719
723
  before_id: t
720
724
  }
721
725
  } : null;
@@ -724,13 +728,13 @@ class Se extends vs {
724
728
  return e ? {
725
729
  ...this.options,
726
730
  query: {
727
- ...pt(this.options.query),
731
+ ..._t(this.options.query),
728
732
  after_id: e
729
733
  }
730
734
  } : null;
731
735
  }
732
736
  }
733
- class T extends vs {
737
+ class M extends vs {
734
738
  constructor(e, t, s, n) {
735
739
  super(e, t, s, n), this.data = s.data || [], this.next_page = s.next_page || null;
736
740
  }
@@ -742,28 +746,28 @@ class T extends vs {
742
746
  return e ? {
743
747
  ...this.options,
744
748
  query: {
745
- ...pt(this.options.query),
749
+ ..._t(this.options.query),
746
750
  page: e
747
751
  }
748
752
  } : null;
749
753
  }
750
754
  }
751
- const Ms = () => {
755
+ const Rs = () => {
752
756
  if (typeof File > "u") {
753
757
  const { process: r } = globalThis, e = typeof r?.versions?.node == "string" && parseInt(r.versions.node.split(".")) < 20;
754
758
  throw new Error("`File` is not defined as a global, which is required for file uploads." + (e ? " Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`." : ""));
755
759
  }
756
760
  };
757
- function te(r, e, t) {
758
- return Ms(), new File(r, e ?? "unknown_file", t);
761
+ function se(r, e, t) {
762
+ return Rs(), new File(r, e ?? "unknown_file", t);
759
763
  }
760
- function De(r, e) {
764
+ function He(r, e) {
761
765
  const t = typeof r == "object" && r !== null && ("name" in r && r.name && String(r.name) || "url" in r && r.url && String(r.url) || "filename" in r && r.filename && String(r.filename) || "path" in r && r.path && String(r.path)) || "";
762
766
  return e ? t.split(/[\\/]/).pop() || void 0 : t;
763
767
  }
764
- const Rs = (r) => r != null && typeof r == "object" && typeof r[Symbol.asyncIterator] == "function", kt = async (r, e, t = !0) => ({ ...r, body: await Nn(r.body, e, t) }), Ht = /* @__PURE__ */ new WeakMap();
765
- function jn(r) {
766
- const e = typeof r == "function" ? r : r.fetch, t = Ht.get(e);
768
+ const Ts = (r) => r != null && typeof r == "object" && typeof r[Symbol.asyncIterator] == "function", vt = async (r, e, t = !0) => ({ ...r, body: await Jn(r.body, e, t) }), Jt = /* @__PURE__ */ new WeakMap();
769
+ function Dn(r) {
770
+ const e = typeof r == "function" ? r : r.fetch, t = Jt.get(e);
767
771
  if (t)
768
772
  return t;
769
773
  const s = (async () => {
@@ -774,14 +778,14 @@ function jn(r) {
774
778
  return !0;
775
779
  }
776
780
  })();
777
- return Ht.set(e, s), s;
781
+ return Jt.set(e, s), s;
778
782
  }
779
- const Nn = async (r, e, t = !0) => {
780
- if (!await jn(e))
783
+ const Jn = async (r, e, t = !0) => {
784
+ if (!await Dn(e))
781
785
  throw new TypeError("The provided fetch function does not support file uploads with the current global FormData class.");
782
786
  const s = new FormData();
783
- return await Promise.all(Object.entries(r || {}).map(([n, a]) => gt(s, n, a, t))), s;
784
- }, qn = (r) => r instanceof Blob && "name" in r, gt = async (r, e, t, s) => {
787
+ return await Promise.all(Object.entries(r || {}).map(([n, a]) => bt(s, n, a, t))), s;
788
+ }, Xn = (r) => r instanceof Blob && "name" in r, bt = async (r, e, t, s) => {
785
789
  if (t !== void 0) {
786
790
  if (t == null)
787
791
  throw new TypeError(`Received null for "${e}"; to pass null in FormData, you must use the string 'null'`);
@@ -790,54 +794,54 @@ const Nn = async (r, e, t = !0) => {
790
794
  else if (t instanceof Response) {
791
795
  let n = {};
792
796
  const a = t.headers.get("Content-Type");
793
- a && (n = { type: a }), r.append(e, te([await t.blob()], De(t, s), n));
794
- } else if (Rs(t))
795
- r.append(e, te([await new Response(ks(t)).blob()], De(t, s)));
796
- else if (qn(t))
797
- r.append(e, te([t], De(t, s), { type: t.type }));
797
+ a && (n = { type: a }), r.append(e, se([await t.blob()], He(t, s), n));
798
+ } else if (Ts(t))
799
+ r.append(e, se([await new Response(ks(t)).blob()], He(t, s)));
800
+ else if (Xn(t))
801
+ r.append(e, se([t], He(t, s), { type: t.type }));
798
802
  else if (Array.isArray(t))
799
- await Promise.all(t.map((n) => gt(r, e + "[]", n, s)));
803
+ await Promise.all(t.map((n) => bt(r, e + "[]", n, s)));
800
804
  else if (typeof t == "object")
801
- await Promise.all(Object.entries(t).map(([n, a]) => gt(r, `${e}[${n}]`, a, s)));
805
+ await Promise.all(Object.entries(t).map(([n, a]) => bt(r, `${e}[${n}]`, a, s)));
802
806
  else
803
807
  throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${t} instead`);
804
808
  }
805
- }, Ts = (r) => r != null && typeof r == "object" && typeof r.size == "number" && typeof r.type == "string" && typeof r.text == "function" && typeof r.slice == "function" && typeof r.arrayBuffer == "function", Wn = (r) => r != null && typeof r == "object" && typeof r.name == "string" && typeof r.lastModified == "number" && Ts(r), Un = (r) => r != null && typeof r == "object" && typeof r.url == "string" && typeof r.blob == "function";
806
- async function Fn(r, e, t) {
807
- if (Ms(), r = await r, e || (e = De(r, !0)), Wn(r))
808
- return r instanceof File && e == null && t == null ? r : te([await r.arrayBuffer()], e ?? r.name, {
809
+ }, Ms = (r) => r != null && typeof r == "object" && typeof r.size == "number" && typeof r.type == "string" && typeof r.text == "function" && typeof r.slice == "function" && typeof r.arrayBuffer == "function", Vn = (r) => r != null && typeof r == "object" && typeof r.name == "string" && typeof r.lastModified == "number" && Ms(r), Kn = (r) => r != null && typeof r == "object" && typeof r.url == "string" && typeof r.blob == "function";
810
+ async function zn(r, e, t) {
811
+ if (Rs(), r = await r, e || (e = He(r, !0)), Vn(r))
812
+ return r instanceof File && e == null && t == null ? r : se([await r.arrayBuffer()], e ?? r.name, {
809
813
  type: r.type,
810
814
  lastModified: r.lastModified,
811
815
  ...t
812
816
  });
813
- if (Un(r)) {
817
+ if (Kn(r)) {
814
818
  const n = await r.blob();
815
- return e || (e = new URL(r.url).pathname.split(/[\\/]/).pop()), te(await mt(n), e, t);
819
+ return e || (e = new URL(r.url).pathname.split(/[\\/]/).pop()), se(await yt(n), e, t);
816
820
  }
817
- const s = await mt(r);
821
+ const s = await yt(r);
818
822
  if (!t?.type) {
819
823
  const n = s.find((a) => typeof a == "object" && "type" in a && a.type);
820
824
  typeof n == "string" && (t = { ...t, type: n });
821
825
  }
822
- return te(s, e, t);
826
+ return se(s, e, t);
823
827
  }
824
- async function mt(r) {
828
+ async function yt(r) {
825
829
  let e = [];
826
830
  if (typeof r == "string" || ArrayBuffer.isView(r) || // includes Uint8Array, Buffer, etc.
827
831
  r instanceof ArrayBuffer)
828
832
  e.push(r);
829
- else if (Ts(r))
833
+ else if (Ms(r))
830
834
  e.push(r instanceof Blob ? r : await r.arrayBuffer());
831
- else if (Rs(r))
835
+ else if (Ts(r))
832
836
  for await (const t of r)
833
- e.push(...await mt(t));
837
+ e.push(...await yt(t));
834
838
  else {
835
839
  const t = r?.constructor?.name;
836
- throw new Error(`Unexpected data type: ${typeof r}${t ? `; constructor: ${t}` : ""}${Dn(r)}`);
840
+ throw new Error(`Unexpected data type: ${typeof r}${t ? `; constructor: ${t}` : ""}${Gn(r)}`);
837
841
  }
838
842
  return e;
839
843
  }
840
- function Dn(r) {
844
+ function Gn(r) {
841
845
  return typeof r != "object" || r === null ? "" : `; props: [${Object.getOwnPropertyNames(r).map((t) => `"${t}"`).join(", ")}]`;
842
846
  }
843
847
  class w {
@@ -846,7 +850,7 @@ class w {
846
850
  }
847
851
  }
848
852
  const Es = /* @__PURE__ */ Symbol.for("brand.privateNullableHeaders");
849
- function* Hn(r) {
853
+ function* Qn(r) {
850
854
  if (!r)
851
855
  return;
852
856
  if (Es in r) {
@@ -864,17 +868,17 @@ function* Hn(r) {
864
868
  throw new TypeError("expected header name to be a string");
865
869
  const a = Bt(s[1]) ? s[1] : [s[1]];
866
870
  let i = !1;
867
- for (const c of a)
868
- c !== void 0 && (e && !i && (i = !0, yield [n, null]), yield [n, c]);
871
+ for (const l of a)
872
+ l !== void 0 && (e && !i && (i = !0, yield [n, null]), yield [n, l]);
869
873
  }
870
874
  }
871
- const u = (r) => {
875
+ const d = (r) => {
872
876
  const e = new Headers(), t = /* @__PURE__ */ new Set();
873
877
  for (const s of r) {
874
878
  const n = /* @__PURE__ */ new Set();
875
- for (const [a, i] of Hn(s)) {
876
- const c = a.toLowerCase();
877
- n.has(c) || (e.delete(a), n.add(c)), i === null ? (e.delete(a), t.add(c)) : (e.append(a, i), t.delete(c));
879
+ for (const [a, i] of Qn(s)) {
880
+ const l = a.toLowerCase();
881
+ n.has(l) || (e.delete(a), n.add(l)), i === null ? (e.delete(a), t.add(l)) : (e.append(a, i), t.delete(l));
878
882
  }
879
883
  }
880
884
  return { [Es]: !0, values: e, nulls: t };
@@ -882,42 +886,42 @@ const u = (r) => {
882
886
  function Ps(r) {
883
887
  return r.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
884
888
  }
885
- const Jt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null)), Jn = (r = Ps) => function(t, ...s) {
889
+ const Xt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null)), Yn = (r = Ps) => function(t, ...s) {
886
890
  if (t.length === 1)
887
891
  return t[0];
888
892
  let n = !1;
889
- const a = [], i = t.reduce((_, y, p) => {
890
- /[?#]/.test(y) && (n = !0);
891
- const f = s[p];
892
- let m = (n ? encodeURIComponent : r)("" + f);
893
- return p !== s.length && (f == null || typeof f == "object" && // handle values from other realms
894
- f.toString === Object.getPrototypeOf(Object.getPrototypeOf(f.hasOwnProperty ?? Jt) ?? Jt)?.toString) && (m = f + "", a.push({
895
- start: _.length + y.length,
896
- length: m.length,
897
- error: `Value of type ${Object.prototype.toString.call(f).slice(8, -1)} is not a valid path parameter`
898
- })), _ + y + (p === s.length ? "" : m);
899
- }, ""), c = i.split(/[?#]/, 1)[0], l = new RegExp("(?<=^|\\/)(?:\\.|%2e){1,2}(?=\\/|$)", "gi");
900
- let h;
901
- for (; (h = l.exec(c)) !== null; )
893
+ const a = [], i = t.reduce((_, g, u) => {
894
+ /[?#]/.test(g) && (n = !0);
895
+ const h = s[u];
896
+ let y = (n ? encodeURIComponent : r)("" + h);
897
+ return u !== s.length && (h == null || typeof h == "object" && // handle values from other realms
898
+ h.toString === Object.getPrototypeOf(Object.getPrototypeOf(h.hasOwnProperty ?? Xt) ?? Xt)?.toString) && (y = h + "", a.push({
899
+ start: _.length + g.length,
900
+ length: y.length,
901
+ error: `Value of type ${Object.prototype.toString.call(h).slice(8, -1)} is not a valid path parameter`
902
+ })), _ + g + (u === s.length ? "" : y);
903
+ }, ""), l = i.split(/[?#]/, 1)[0], c = new RegExp("(?<=^|\\/)(?:\\.|%2e){1,2}(?=\\/|$)", "gi");
904
+ let f;
905
+ for (; (f = c.exec(l)) !== null; )
902
906
  a.push({
903
- start: h.index,
904
- length: h[0].length,
905
- error: `Value "${h[0]}" can't be safely passed as a path parameter`
907
+ start: f.index,
908
+ length: f[0].length,
909
+ error: `Value "${f[0]}" can't be safely passed as a path parameter`
906
910
  });
907
- if (a.sort((_, y) => _.start - y.start), a.length > 0) {
911
+ if (a.sort((_, g) => _.start - g.start), a.length > 0) {
908
912
  let _ = 0;
909
- const y = a.reduce((p, f) => {
910
- const m = " ".repeat(f.start - _), v = "^".repeat(f.length);
911
- return _ = f.start + f.length, p + m + v;
913
+ const g = a.reduce((u, h) => {
914
+ const y = " ".repeat(h.start - _), v = "^".repeat(h.length);
915
+ return _ = h.start + h.length, u + y + v;
912
916
  }, "");
913
917
  throw new b(`Path parameters result in path with invalid segments:
914
- ${a.map((p) => p.error).join(`
918
+ ${a.map((u) => u.error).join(`
915
919
  `)}
916
920
  ${i}
917
- ${y}`);
921
+ ${g}`);
918
922
  }
919
923
  return i;
920
- }, g = /* @__PURE__ */ Jn(Ps);
924
+ }, m = /* @__PURE__ */ Yn(Ps);
921
925
  class As extends w {
922
926
  /**
923
927
  * Create a new environment with the specified configuration.
@@ -935,7 +939,7 @@ class As extends w {
935
939
  return this._client.post("/v1/environments?beta=true", {
936
940
  body: n,
937
941
  ...t,
938
- headers: u([
942
+ headers: d([
939
943
  { "anthropic-beta": [...s ?? [], "managed-agents-2026-04-01"].toString() },
940
944
  t?.headers
941
945
  ])
@@ -954,9 +958,9 @@ class As extends w {
954
958
  */
955
959
  retrieve(e, t = {}, s) {
956
960
  const { betas: n } = t ?? {};
957
- return this._client.get(g`/v1/environments/${e}?beta=true`, {
961
+ return this._client.get(m`/v1/environments/${e}?beta=true`, {
958
962
  ...s,
959
- headers: u([
963
+ headers: d([
960
964
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
961
965
  s?.headers
962
966
  ])
@@ -975,10 +979,10 @@ class As extends w {
975
979
  */
976
980
  update(e, t, s) {
977
981
  const { betas: n, ...a } = t;
978
- return this._client.post(g`/v1/environments/${e}?beta=true`, {
982
+ return this._client.post(m`/v1/environments/${e}?beta=true`, {
979
983
  body: a,
980
984
  ...s,
981
- headers: u([
985
+ headers: d([
982
986
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
983
987
  s?.headers
984
988
  ])
@@ -997,10 +1001,10 @@ class As extends w {
997
1001
  */
998
1002
  list(e = {}, t) {
999
1003
  const { betas: s, ...n } = e ?? {};
1000
- return this._client.getAPIList("/v1/environments?beta=true", T, {
1004
+ return this._client.getAPIList("/v1/environments?beta=true", M, {
1001
1005
  query: n,
1002
1006
  ...t,
1003
- headers: u([
1007
+ headers: d([
1004
1008
  { "anthropic-beta": [...s ?? [], "managed-agents-2026-04-01"].toString() },
1005
1009
  t?.headers
1006
1010
  ])
@@ -1019,9 +1023,9 @@ class As extends w {
1019
1023
  */
1020
1024
  delete(e, t = {}, s) {
1021
1025
  const { betas: n } = t ?? {};
1022
- return this._client.delete(g`/v1/environments/${e}?beta=true`, {
1026
+ return this._client.delete(m`/v1/environments/${e}?beta=true`, {
1023
1027
  ...s,
1024
- headers: u([
1028
+ headers: d([
1025
1029
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1026
1030
  s?.headers
1027
1031
  ])
@@ -1041,29 +1045,29 @@ class As extends w {
1041
1045
  */
1042
1046
  archive(e, t = {}, s) {
1043
1047
  const { betas: n } = t ?? {};
1044
- return this._client.post(g`/v1/environments/${e}/archive?beta=true`, {
1048
+ return this._client.post(m`/v1/environments/${e}/archive?beta=true`, {
1045
1049
  ...s,
1046
- headers: u([
1050
+ headers: d([
1047
1051
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1048
1052
  s?.headers
1049
1053
  ])
1050
1054
  });
1051
1055
  }
1052
1056
  }
1053
- const ye = /* @__PURE__ */ Symbol("anthropic.sdk.stainlessHelper");
1054
- function He(r) {
1055
- return typeof r == "object" && r !== null && ye in r;
1057
+ const we = /* @__PURE__ */ Symbol("anthropic.sdk.stainlessHelper");
1058
+ function De(r) {
1059
+ return typeof r == "object" && r !== null && we in r;
1056
1060
  }
1057
1061
  function $s(r, e) {
1058
1062
  const t = /* @__PURE__ */ new Set();
1059
1063
  if (r)
1060
1064
  for (const s of r)
1061
- He(s) && t.add(s[ye]);
1065
+ De(s) && t.add(s[we]);
1062
1066
  if (e) {
1063
1067
  for (const s of e)
1064
- if (He(s) && t.add(s[ye]), Array.isArray(s.content))
1068
+ if (De(s) && t.add(s[we]), Array.isArray(s.content))
1065
1069
  for (const n of s.content)
1066
- He(n) && t.add(n[ye]);
1070
+ De(n) && t.add(n[we]);
1067
1071
  }
1068
1072
  return Array.from(t);
1069
1073
  }
@@ -1071,10 +1075,10 @@ function Is(r, e) {
1071
1075
  const t = $s(r, e);
1072
1076
  return t.length === 0 ? {} : { "x-stainless-helper": t.join(", ") };
1073
1077
  }
1074
- function Xn(r) {
1075
- return He(r) ? { "x-stainless-helper": r[ye] } : {};
1078
+ function Zn(r) {
1079
+ return De(r) ? { "x-stainless-helper": r[we] } : {};
1076
1080
  }
1077
- class Os extends w {
1081
+ class Cs extends w {
1078
1082
  /**
1079
1083
  * List Files
1080
1084
  *
@@ -1088,10 +1092,10 @@ class Os extends w {
1088
1092
  */
1089
1093
  list(e = {}, t) {
1090
1094
  const { betas: s, ...n } = e ?? {};
1091
- return this._client.getAPIList("/v1/files?beta=true", Se, {
1095
+ return this._client.getAPIList("/v1/files?beta=true", xe, {
1092
1096
  query: n,
1093
1097
  ...t,
1094
- headers: u([
1098
+ headers: d([
1095
1099
  { "anthropic-beta": [...s ?? [], "files-api-2025-04-14"].toString() },
1096
1100
  t?.headers
1097
1101
  ])
@@ -1109,9 +1113,9 @@ class Os extends w {
1109
1113
  */
1110
1114
  delete(e, t = {}, s) {
1111
1115
  const { betas: n } = t ?? {};
1112
- return this._client.delete(g`/v1/files/${e}?beta=true`, {
1116
+ return this._client.delete(m`/v1/files/${e}?beta=true`, {
1113
1117
  ...s,
1114
- headers: u([
1118
+ headers: d([
1115
1119
  { "anthropic-beta": [...n ?? [], "files-api-2025-04-14"].toString() },
1116
1120
  s?.headers
1117
1121
  ])
@@ -1132,9 +1136,9 @@ class Os extends w {
1132
1136
  */
1133
1137
  download(e, t = {}, s) {
1134
1138
  const { betas: n } = t ?? {};
1135
- return this._client.get(g`/v1/files/${e}/content?beta=true`, {
1139
+ return this._client.get(m`/v1/files/${e}/content?beta=true`, {
1136
1140
  ...s,
1137
- headers: u([
1141
+ headers: d([
1138
1142
  {
1139
1143
  "anthropic-beta": [...n ?? [], "files-api-2025-04-14"].toString(),
1140
1144
  Accept: "application/binary"
@@ -1155,9 +1159,9 @@ class Os extends w {
1155
1159
  */
1156
1160
  retrieveMetadata(e, t = {}, s) {
1157
1161
  const { betas: n } = t ?? {};
1158
- return this._client.get(g`/v1/files/${e}?beta=true`, {
1162
+ return this._client.get(m`/v1/files/${e}?beta=true`, {
1159
1163
  ...s,
1160
- headers: u([
1164
+ headers: d([
1161
1165
  { "anthropic-beta": [...n ?? [], "files-api-2025-04-14"].toString() },
1162
1166
  s?.headers
1163
1167
  ])
@@ -1175,18 +1179,18 @@ class Os extends w {
1175
1179
  */
1176
1180
  upload(e, t) {
1177
1181
  const { betas: s, ...n } = e;
1178
- return this._client.post("/v1/files?beta=true", kt({
1182
+ return this._client.post("/v1/files?beta=true", vt({
1179
1183
  body: n,
1180
1184
  ...t,
1181
- headers: u([
1185
+ headers: d([
1182
1186
  { "anthropic-beta": [...s ?? [], "files-api-2025-04-14"].toString() },
1183
- Xn(n.file),
1187
+ Zn(n.file),
1184
1188
  t?.headers
1185
1189
  ])
1186
1190
  }, this._client));
1187
1191
  }
1188
1192
  }
1189
- let Bs = class extends w {
1193
+ let Os = class extends w {
1190
1194
  /**
1191
1195
  * Get a specific model.
1192
1196
  *
@@ -1202,9 +1206,9 @@ let Bs = class extends w {
1202
1206
  */
1203
1207
  retrieve(e, t = {}, s) {
1204
1208
  const { betas: n } = t ?? {};
1205
- return this._client.get(g`/v1/models/${e}?beta=true`, {
1209
+ return this._client.get(m`/v1/models/${e}?beta=true`, {
1206
1210
  ...s,
1207
- headers: u([
1211
+ headers: d([
1208
1212
  { ...n?.toString() != null ? { "anthropic-beta": n?.toString() } : void 0 },
1209
1213
  s?.headers
1210
1214
  ])
@@ -1226,17 +1230,17 @@ let Bs = class extends w {
1226
1230
  */
1227
1231
  list(e = {}, t) {
1228
1232
  const { betas: s, ...n } = e ?? {};
1229
- return this._client.getAPIList("/v1/models?beta=true", Se, {
1233
+ return this._client.getAPIList("/v1/models?beta=true", xe, {
1230
1234
  query: n,
1231
1235
  ...t,
1232
- headers: u([
1236
+ headers: d([
1233
1237
  { ...s?.toString() != null ? { "anthropic-beta": s?.toString() } : void 0 },
1234
1238
  t?.headers
1235
1239
  ])
1236
1240
  });
1237
1241
  }
1238
1242
  };
1239
- class Ls extends w {
1243
+ class Bs extends w {
1240
1244
  /**
1241
1245
  * Create User Profile
1242
1246
  *
@@ -1251,7 +1255,7 @@ class Ls extends w {
1251
1255
  return this._client.post("/v1/user_profiles?beta=true", {
1252
1256
  body: n,
1253
1257
  ...t,
1254
- headers: u([
1258
+ headers: d([
1255
1259
  { "anthropic-beta": [...s ?? [], "user-profiles-2026-03-24"].toString() },
1256
1260
  t?.headers
1257
1261
  ])
@@ -1270,9 +1274,9 @@ class Ls extends w {
1270
1274
  */
1271
1275
  retrieve(e, t = {}, s) {
1272
1276
  const { betas: n } = t ?? {};
1273
- return this._client.get(g`/v1/user_profiles/${e}?beta=true`, {
1277
+ return this._client.get(m`/v1/user_profiles/${e}?beta=true`, {
1274
1278
  ...s,
1275
- headers: u([
1279
+ headers: d([
1276
1280
  { "anthropic-beta": [...n ?? [], "user-profiles-2026-03-24"].toString() },
1277
1281
  s?.headers
1278
1282
  ])
@@ -1291,10 +1295,10 @@ class Ls extends w {
1291
1295
  */
1292
1296
  update(e, t, s) {
1293
1297
  const { betas: n, ...a } = t;
1294
- return this._client.post(g`/v1/user_profiles/${e}?beta=true`, {
1298
+ return this._client.post(m`/v1/user_profiles/${e}?beta=true`, {
1295
1299
  body: a,
1296
1300
  ...s,
1297
- headers: u([
1301
+ headers: d([
1298
1302
  { "anthropic-beta": [...n ?? [], "user-profiles-2026-03-24"].toString() },
1299
1303
  s?.headers
1300
1304
  ])
@@ -1313,10 +1317,10 @@ class Ls extends w {
1313
1317
  */
1314
1318
  list(e = {}, t) {
1315
1319
  const { betas: s, ...n } = e ?? {};
1316
- return this._client.getAPIList("/v1/user_profiles?beta=true", T, {
1320
+ return this._client.getAPIList("/v1/user_profiles?beta=true", M, {
1317
1321
  query: n,
1318
1322
  ...t,
1319
- headers: u([
1323
+ headers: d([
1320
1324
  { "anthropic-beta": [...s ?? [], "user-profiles-2026-03-24"].toString() },
1321
1325
  t?.headers
1322
1326
  ])
@@ -1335,16 +1339,16 @@ class Ls extends w {
1335
1339
  */
1336
1340
  createEnrollmentURL(e, t = {}, s) {
1337
1341
  const { betas: n } = t ?? {};
1338
- return this._client.post(g`/v1/user_profiles/${e}/enrollment_url?beta=true`, {
1342
+ return this._client.post(m`/v1/user_profiles/${e}/enrollment_url?beta=true`, {
1339
1343
  ...s,
1340
- headers: u([
1344
+ headers: d([
1341
1345
  { "anthropic-beta": [...n ?? [], "user-profiles-2026-03-24"].toString() },
1342
1346
  s?.headers
1343
1347
  ])
1344
1348
  });
1345
1349
  }
1346
1350
  }
1347
- let Cs = class extends w {
1351
+ let Ls = class extends w {
1348
1352
  /**
1349
1353
  * List Agent Versions
1350
1354
  *
@@ -1360,19 +1364,19 @@ let Cs = class extends w {
1360
1364
  */
1361
1365
  list(e, t = {}, s) {
1362
1366
  const { betas: n, ...a } = t ?? {};
1363
- return this._client.getAPIList(g`/v1/agents/${e}/versions?beta=true`, T, {
1367
+ return this._client.getAPIList(m`/v1/agents/${e}/versions?beta=true`, M, {
1364
1368
  query: a,
1365
1369
  ...s,
1366
- headers: u([
1370
+ headers: d([
1367
1371
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1368
1372
  s?.headers
1369
1373
  ])
1370
1374
  });
1371
1375
  }
1372
1376
  };
1373
- class St extends w {
1377
+ class Rt extends w {
1374
1378
  constructor() {
1375
- super(...arguments), this.versions = new Cs(this._client);
1379
+ super(...arguments), this.versions = new Ls(this._client);
1376
1380
  }
1377
1381
  /**
1378
1382
  * Create Agent
@@ -1391,7 +1395,7 @@ class St extends w {
1391
1395
  return this._client.post("/v1/agents?beta=true", {
1392
1396
  body: n,
1393
1397
  ...t,
1394
- headers: u([
1398
+ headers: d([
1395
1399
  { "anthropic-beta": [...s ?? [], "managed-agents-2026-04-01"].toString() },
1396
1400
  t?.headers
1397
1401
  ])
@@ -1410,10 +1414,10 @@ class St extends w {
1410
1414
  */
1411
1415
  retrieve(e, t = {}, s) {
1412
1416
  const { betas: n, ...a } = t ?? {};
1413
- return this._client.get(g`/v1/agents/${e}?beta=true`, {
1417
+ return this._client.get(m`/v1/agents/${e}?beta=true`, {
1414
1418
  query: a,
1415
1419
  ...s,
1416
- headers: u([
1420
+ headers: d([
1417
1421
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1418
1422
  s?.headers
1419
1423
  ])
@@ -1433,10 +1437,10 @@ class St extends w {
1433
1437
  */
1434
1438
  update(e, t, s) {
1435
1439
  const { betas: n, ...a } = t;
1436
- return this._client.post(g`/v1/agents/${e}?beta=true`, {
1440
+ return this._client.post(m`/v1/agents/${e}?beta=true`, {
1437
1441
  body: a,
1438
1442
  ...s,
1439
- headers: u([
1443
+ headers: d([
1440
1444
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1441
1445
  s?.headers
1442
1446
  ])
@@ -1455,10 +1459,10 @@ class St extends w {
1455
1459
  */
1456
1460
  list(e = {}, t) {
1457
1461
  const { betas: s, ...n } = e ?? {};
1458
- return this._client.getAPIList("/v1/agents?beta=true", T, {
1462
+ return this._client.getAPIList("/v1/agents?beta=true", M, {
1459
1463
  query: n,
1460
1464
  ...t,
1461
- headers: u([
1465
+ headers: d([
1462
1466
  { "anthropic-beta": [...s ?? [], "managed-agents-2026-04-01"].toString() },
1463
1467
  t?.headers
1464
1468
  ])
@@ -1477,17 +1481,17 @@ class St extends w {
1477
1481
  */
1478
1482
  archive(e, t = {}, s) {
1479
1483
  const { betas: n } = t ?? {};
1480
- return this._client.post(g`/v1/agents/${e}/archive?beta=true`, {
1484
+ return this._client.post(m`/v1/agents/${e}/archive?beta=true`, {
1481
1485
  ...s,
1482
- headers: u([
1486
+ headers: d([
1483
1487
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1484
1488
  s?.headers
1485
1489
  ])
1486
1490
  });
1487
1491
  }
1488
1492
  }
1489
- St.Versions = Cs;
1490
- class js extends w {
1493
+ Rt.Versions = Ls;
1494
+ class Ns extends w {
1491
1495
  /**
1492
1496
  * CreateMemory
1493
1497
  *
@@ -1502,11 +1506,11 @@ class js extends w {
1502
1506
  */
1503
1507
  create(e, t, s) {
1504
1508
  const { view: n, betas: a, ...i } = t;
1505
- return this._client.post(g`/v1/memory_stores/${e}/memories?beta=true`, {
1509
+ return this._client.post(m`/v1/memory_stores/${e}/memories?beta=true`, {
1506
1510
  query: { view: n },
1507
1511
  body: i,
1508
1512
  ...s,
1509
- headers: u([
1513
+ headers: d([
1510
1514
  { "anthropic-beta": [...a ?? [], "managed-agents-2026-04-01"].toString() },
1511
1515
  s?.headers
1512
1516
  ])
@@ -1526,10 +1530,10 @@ class js extends w {
1526
1530
  */
1527
1531
  retrieve(e, t, s) {
1528
1532
  const { memory_store_id: n, betas: a, ...i } = t;
1529
- return this._client.get(g`/v1/memory_stores/${n}/memories/${e}?beta=true`, {
1533
+ return this._client.get(m`/v1/memory_stores/${n}/memories/${e}?beta=true`, {
1530
1534
  query: i,
1531
1535
  ...s,
1532
- headers: u([
1536
+ headers: d([
1533
1537
  { "anthropic-beta": [...a ?? [], "managed-agents-2026-04-01"].toString() },
1534
1538
  s?.headers
1535
1539
  ])
@@ -1548,12 +1552,12 @@ class js extends w {
1548
1552
  * ```
1549
1553
  */
1550
1554
  update(e, t, s) {
1551
- const { memory_store_id: n, view: a, betas: i, ...c } = t;
1552
- return this._client.post(g`/v1/memory_stores/${n}/memories/${e}?beta=true`, {
1555
+ const { memory_store_id: n, view: a, betas: i, ...l } = t;
1556
+ return this._client.post(m`/v1/memory_stores/${n}/memories/${e}?beta=true`, {
1553
1557
  query: { view: a },
1554
- body: c,
1558
+ body: l,
1555
1559
  ...s,
1556
- headers: u([
1560
+ headers: d([
1557
1561
  { "anthropic-beta": [...i ?? [], "managed-agents-2026-04-01"].toString() },
1558
1562
  s?.headers
1559
1563
  ])
@@ -1574,10 +1578,10 @@ class js extends w {
1574
1578
  */
1575
1579
  list(e, t = {}, s) {
1576
1580
  const { betas: n, ...a } = t ?? {};
1577
- return this._client.getAPIList(g`/v1/memory_stores/${e}/memories?beta=true`, T, {
1581
+ return this._client.getAPIList(m`/v1/memory_stores/${e}/memories?beta=true`, M, {
1578
1582
  query: a,
1579
1583
  ...s,
1580
- headers: u([
1584
+ headers: d([
1581
1585
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1582
1586
  s?.headers
1583
1587
  ])
@@ -1597,17 +1601,17 @@ class js extends w {
1597
1601
  */
1598
1602
  delete(e, t, s) {
1599
1603
  const { memory_store_id: n, expected_content_sha256: a, betas: i } = t;
1600
- return this._client.delete(g`/v1/memory_stores/${n}/memories/${e}?beta=true`, {
1604
+ return this._client.delete(m`/v1/memory_stores/${n}/memories/${e}?beta=true`, {
1601
1605
  query: { expected_content_sha256: a },
1602
1606
  ...s,
1603
- headers: u([
1607
+ headers: d([
1604
1608
  { "anthropic-beta": [...i ?? [], "managed-agents-2026-04-01"].toString() },
1605
1609
  s?.headers
1606
1610
  ])
1607
1611
  });
1608
1612
  }
1609
1613
  }
1610
- class Ns extends w {
1614
+ class js extends w {
1611
1615
  /**
1612
1616
  * GetMemoryVersion
1613
1617
  *
@@ -1622,10 +1626,10 @@ class Ns extends w {
1622
1626
  */
1623
1627
  retrieve(e, t, s) {
1624
1628
  const { memory_store_id: n, betas: a, ...i } = t;
1625
- return this._client.get(g`/v1/memory_stores/${n}/memory_versions/${e}?beta=true`, {
1629
+ return this._client.get(m`/v1/memory_stores/${n}/memory_versions/${e}?beta=true`, {
1626
1630
  query: i,
1627
1631
  ...s,
1628
- headers: u([
1632
+ headers: d([
1629
1633
  { "anthropic-beta": [...a ?? [], "managed-agents-2026-04-01"].toString() },
1630
1634
  s?.headers
1631
1635
  ])
@@ -1646,10 +1650,10 @@ class Ns extends w {
1646
1650
  */
1647
1651
  list(e, t = {}, s) {
1648
1652
  const { betas: n, ...a } = t ?? {};
1649
- return this._client.getAPIList(g`/v1/memory_stores/${e}/memory_versions?beta=true`, T, {
1653
+ return this._client.getAPIList(m`/v1/memory_stores/${e}/memory_versions?beta=true`, M, {
1650
1654
  query: a,
1651
1655
  ...s,
1652
- headers: u([
1656
+ headers: d([
1653
1657
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1654
1658
  s?.headers
1655
1659
  ])
@@ -1669,9 +1673,9 @@ class Ns extends w {
1669
1673
  */
1670
1674
  redact(e, t, s) {
1671
1675
  const { memory_store_id: n, betas: a } = t;
1672
- return this._client.post(g`/v1/memory_stores/${n}/memory_versions/${e}/redact?beta=true`, {
1676
+ return this._client.post(m`/v1/memory_stores/${n}/memory_versions/${e}/redact?beta=true`, {
1673
1677
  ...s,
1674
- headers: u([
1678
+ headers: d([
1675
1679
  { "anthropic-beta": [...a ?? [], "managed-agents-2026-04-01"].toString() },
1676
1680
  s?.headers
1677
1681
  ])
@@ -1680,7 +1684,7 @@ class Ns extends w {
1680
1684
  }
1681
1685
  class Qe extends w {
1682
1686
  constructor() {
1683
- super(...arguments), this.memories = new js(this._client), this.memoryVersions = new Ns(this._client);
1687
+ super(...arguments), this.memories = new Ns(this._client), this.memoryVersions = new js(this._client);
1684
1688
  }
1685
1689
  /**
1686
1690
  * CreateMemoryStore
@@ -1696,7 +1700,7 @@ class Qe extends w {
1696
1700
  return this._client.post("/v1/memory_stores?beta=true", {
1697
1701
  body: n,
1698
1702
  ...t,
1699
- headers: u([
1703
+ headers: d([
1700
1704
  { "anthropic-beta": [...s ?? [], "managed-agents-2026-04-01"].toString() },
1701
1705
  t?.headers
1702
1706
  ])
@@ -1715,9 +1719,9 @@ class Qe extends w {
1715
1719
  */
1716
1720
  retrieve(e, t = {}, s) {
1717
1721
  const { betas: n } = t ?? {};
1718
- return this._client.get(g`/v1/memory_stores/${e}?beta=true`, {
1722
+ return this._client.get(m`/v1/memory_stores/${e}?beta=true`, {
1719
1723
  ...s,
1720
- headers: u([
1724
+ headers: d([
1721
1725
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1722
1726
  s?.headers
1723
1727
  ])
@@ -1734,10 +1738,10 @@ class Qe extends w {
1734
1738
  */
1735
1739
  update(e, t, s) {
1736
1740
  const { betas: n, ...a } = t;
1737
- return this._client.post(g`/v1/memory_stores/${e}?beta=true`, {
1741
+ return this._client.post(m`/v1/memory_stores/${e}?beta=true`, {
1738
1742
  body: a,
1739
1743
  ...s,
1740
- headers: u([
1744
+ headers: d([
1741
1745
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1742
1746
  s?.headers
1743
1747
  ])
@@ -1756,10 +1760,10 @@ class Qe extends w {
1756
1760
  */
1757
1761
  list(e = {}, t) {
1758
1762
  const { betas: s, ...n } = e ?? {};
1759
- return this._client.getAPIList("/v1/memory_stores?beta=true", T, {
1763
+ return this._client.getAPIList("/v1/memory_stores?beta=true", M, {
1760
1764
  query: n,
1761
1765
  ...t,
1762
- headers: u([
1766
+ headers: d([
1763
1767
  { "anthropic-beta": [...s ?? [], "managed-agents-2026-04-01"].toString() },
1764
1768
  t?.headers
1765
1769
  ])
@@ -1776,9 +1780,9 @@ class Qe extends w {
1776
1780
  */
1777
1781
  delete(e, t = {}, s) {
1778
1782
  const { betas: n } = t ?? {};
1779
- return this._client.delete(g`/v1/memory_stores/${e}?beta=true`, {
1783
+ return this._client.delete(m`/v1/memory_stores/${e}?beta=true`, {
1780
1784
  ...s,
1781
- headers: u([
1785
+ headers: d([
1782
1786
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1783
1787
  s?.headers
1784
1788
  ])
@@ -1795,17 +1799,17 @@ class Qe extends w {
1795
1799
  */
1796
1800
  archive(e, t = {}, s) {
1797
1801
  const { betas: n } = t ?? {};
1798
- return this._client.post(g`/v1/memory_stores/${e}/archive?beta=true`, {
1802
+ return this._client.post(m`/v1/memory_stores/${e}/archive?beta=true`, {
1799
1803
  ...s,
1800
- headers: u([
1804
+ headers: d([
1801
1805
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
1802
1806
  s?.headers
1803
1807
  ])
1804
1808
  });
1805
1809
  }
1806
1810
  }
1807
- Qe.Memories = js;
1808
- Qe.MemoryVersions = Ns;
1811
+ Qe.Memories = Ns;
1812
+ Qe.MemoryVersions = js;
1809
1813
  const qs = {
1810
1814
  "claude-opus-4-20250514": 8192,
1811
1815
  "claude-opus-4-0": 8192,
@@ -1819,7 +1823,7 @@ const qs = {
1819
1823
  function Ws(r) {
1820
1824
  return r?.output_format ?? r?.output_config?.format;
1821
1825
  }
1822
- function Xt(r, e, t) {
1826
+ function Vt(r, e, t) {
1823
1827
  const s = Ws(e);
1824
1828
  return !e || !("parse" in (s ?? {})) ? {
1825
1829
  ...r,
@@ -1845,13 +1849,13 @@ function Us(r, e, t) {
1845
1849
  let s = null;
1846
1850
  const n = r.content.map((a) => {
1847
1851
  if (a.type === "text") {
1848
- const i = Vn(e, a.text);
1852
+ const i = er(e, a.text);
1849
1853
  s === null && (s = i);
1850
- const c = Object.defineProperty({ ...a }, "parsed_output", {
1854
+ const l = Object.defineProperty({ ...a }, "parsed_output", {
1851
1855
  value: i,
1852
1856
  enumerable: !1
1853
1857
  });
1854
- return Object.defineProperty(c, "parsed", {
1858
+ return Object.defineProperty(l, "parsed", {
1855
1859
  get() {
1856
1860
  return t.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead."), i;
1857
1861
  },
@@ -1866,7 +1870,7 @@ function Us(r, e, t) {
1866
1870
  parsed_output: s
1867
1871
  };
1868
1872
  }
1869
- function Vn(r, e) {
1873
+ function er(r, e) {
1870
1874
  const t = Ws(r);
1871
1875
  if (t?.type !== "json_schema")
1872
1876
  return null;
@@ -1876,7 +1880,7 @@ function Vn(r, e) {
1876
1880
  throw new b(`Failed to parse structured output: ${s}`);
1877
1881
  }
1878
1882
  }
1879
- const Kn = (r) => {
1883
+ const tr = (r) => {
1880
1884
  let e = 0, t = [];
1881
1885
  for (; e < r.length; ) {
1882
1886
  let s = r[e];
@@ -1927,24 +1931,24 @@ const Kn = (r) => {
1927
1931
  continue;
1928
1932
  }
1929
1933
  if (s === '"') {
1930
- let c = "", l = !1;
1934
+ let l = "", c = !1;
1931
1935
  for (s = r[++e]; s !== '"'; ) {
1932
1936
  if (e === r.length) {
1933
- l = !0;
1937
+ c = !0;
1934
1938
  break;
1935
1939
  }
1936
1940
  if (s === "\\") {
1937
1941
  if (e++, e === r.length) {
1938
- l = !0;
1942
+ c = !0;
1939
1943
  break;
1940
1944
  }
1941
- c += s + r[e], s = r[++e];
1945
+ l += s + r[e], s = r[++e];
1942
1946
  } else
1943
- c += s, s = r[++e];
1947
+ l += s, s = r[++e];
1944
1948
  }
1945
- s = r[++e], l || t.push({
1949
+ s = r[++e], c || t.push({
1946
1950
  type: "string",
1947
- value: c
1951
+ value: l
1948
1952
  });
1949
1953
  continue;
1950
1954
  }
@@ -1954,24 +1958,24 @@ const Kn = (r) => {
1954
1958
  }
1955
1959
  let a = /[0-9]/;
1956
1960
  if (s && a.test(s) || s === "-" || s === ".") {
1957
- let c = "";
1958
- for (s === "-" && (c += s, s = r[++e]); s && a.test(s) || s === "."; )
1959
- c += s, s = r[++e];
1961
+ let l = "";
1962
+ for (s === "-" && (l += s, s = r[++e]); s && a.test(s) || s === "."; )
1963
+ l += s, s = r[++e];
1960
1964
  t.push({
1961
1965
  type: "number",
1962
- value: c
1966
+ value: l
1963
1967
  });
1964
1968
  continue;
1965
1969
  }
1966
1970
  let i = /[a-z]/i;
1967
1971
  if (s && i.test(s)) {
1968
- let c = "";
1972
+ let l = "";
1969
1973
  for (; s && i.test(s) && e !== r.length; )
1970
- c += s, s = r[++e];
1971
- if (c == "true" || c == "false" || c === "null")
1974
+ l += s, s = r[++e];
1975
+ if (l == "true" || l == "false" || l === "null")
1972
1976
  t.push({
1973
1977
  type: "name",
1974
- value: c
1978
+ value: l
1975
1979
  });
1976
1980
  else {
1977
1981
  e++;
@@ -1982,29 +1986,29 @@ const Kn = (r) => {
1982
1986
  e++;
1983
1987
  }
1984
1988
  return t;
1985
- }, ee = (r) => {
1989
+ }, te = (r) => {
1986
1990
  if (r.length === 0)
1987
1991
  return r;
1988
1992
  let e = r[r.length - 1];
1989
1993
  switch (e.type) {
1990
1994
  case "separator":
1991
- return r = r.slice(0, r.length - 1), ee(r);
1995
+ return r = r.slice(0, r.length - 1), te(r);
1992
1996
  case "number":
1993
1997
  let t = e.value[e.value.length - 1];
1994
1998
  if (t === "." || t === "-")
1995
- return r = r.slice(0, r.length - 1), ee(r);
1999
+ return r = r.slice(0, r.length - 1), te(r);
1996
2000
  case "string":
1997
2001
  let s = r[r.length - 2];
1998
2002
  if (s?.type === "delimiter")
1999
- return r = r.slice(0, r.length - 1), ee(r);
2003
+ return r = r.slice(0, r.length - 1), te(r);
2000
2004
  if (s?.type === "brace" && s.value === "{")
2001
- return r = r.slice(0, r.length - 1), ee(r);
2005
+ return r = r.slice(0, r.length - 1), te(r);
2002
2006
  break;
2003
2007
  case "delimiter":
2004
- return r = r.slice(0, r.length - 1), ee(r);
2008
+ return r = r.slice(0, r.length - 1), te(r);
2005
2009
  }
2006
2010
  return r;
2007
- }, zn = (r) => {
2011
+ }, sr = (r) => {
2008
2012
  let e = [];
2009
2013
  return r.map((t) => {
2010
2014
  t.type === "brace" && (t.value === "{" ? e.push("}") : e.splice(e.lastIndexOf("}"), 1)), t.type === "paren" && (t.value === "[" ? e.push("]") : e.splice(e.lastIndexOf("]"), 1));
@@ -2017,26 +2021,26 @@ const Kn = (r) => {
2017
2021
  value: "]"
2018
2022
  });
2019
2023
  }), r;
2020
- }, Gn = (r) => {
2024
+ }, nr = (r) => {
2021
2025
  let e = "";
2022
2026
  return r.map((t) => {
2023
2027
  t.type === "string" ? e += '"' + t.value + '"' : e += t.value;
2024
2028
  }), e;
2025
- }, Fs = (r) => JSON.parse(Gn(zn(ee(Kn(r)))));
2026
- var $, F, G, ne, Te, re, ae, Ee, ie, N, oe, Pe, Ae, X, $e, Ie, ce, tt, Vt, Oe, st, nt, rt, Kt;
2027
- const zt = "__json_buf";
2028
- function Gt(r) {
2029
+ }, Fs = (r) => JSON.parse(nr(sr(te(tr(r)))));
2030
+ var $, F, Q, re, Ee, ae, ie, Pe, oe, q, ce, Ae, $e, J, Ie, Ce, le, st, Kt, Oe, nt, rt, at, zt;
2031
+ const Gt = "__json_buf";
2032
+ function Qt(r) {
2029
2033
  return r.type === "tool_use" || r.type === "server_tool_use" || r.type === "mcp_tool_use";
2030
2034
  }
2031
2035
  class Ve {
2032
2036
  constructor(e, t) {
2033
- $.add(this), this.messages = [], this.receivedMessages = [], F.set(this, void 0), G.set(this, null), this.controller = new AbortController(), ne.set(this, void 0), Te.set(this, () => {
2034
- }), re.set(this, () => {
2035
- }), ae.set(this, void 0), Ee.set(this, () => {
2036
- }), ie.set(this, () => {
2037
- }), N.set(this, {}), oe.set(this, !1), Pe.set(this, !1), Ae.set(this, !1), X.set(this, !1), $e.set(this, void 0), Ie.set(this, void 0), ce.set(this, void 0), Oe.set(this, (s) => {
2038
- if (d(this, Pe, !0), we(s) && (s = new B()), s instanceof B)
2039
- return d(this, Ae, !0), this._emit("abort", s);
2037
+ $.add(this), this.messages = [], this.receivedMessages = [], F.set(this, void 0), Q.set(this, null), this.controller = new AbortController(), re.set(this, void 0), Ee.set(this, () => {
2038
+ }), ae.set(this, () => {
2039
+ }), ie.set(this, void 0), Pe.set(this, () => {
2040
+ }), oe.set(this, () => {
2041
+ }), q.set(this, {}), ce.set(this, !1), Ae.set(this, !1), $e.set(this, !1), J.set(this, !1), Ie.set(this, void 0), Ce.set(this, void 0), le.set(this, void 0), Oe.set(this, (s) => {
2042
+ if (p(this, Ae, !0), ke(s) && (s = new B()), s instanceof B)
2043
+ return p(this, $e, !0), this._emit("abort", s);
2040
2044
  if (s instanceof b)
2041
2045
  return this._emit("error", s);
2042
2046
  if (s instanceof Error) {
@@ -2044,19 +2048,19 @@ class Ve {
2044
2048
  return n.cause = s, this._emit("error", n);
2045
2049
  }
2046
2050
  return this._emit("error", new b(String(s)));
2047
- }), d(this, ne, new Promise((s, n) => {
2048
- d(this, Te, s, "f"), d(this, re, n, "f");
2049
- })), d(this, ae, new Promise((s, n) => {
2050
- d(this, Ee, s, "f"), d(this, ie, n, "f");
2051
- })), o(this, ne, "f").catch(() => {
2052
- }), o(this, ae, "f").catch(() => {
2053
- }), d(this, G, e), d(this, ce, t?.logger ?? console);
2051
+ }), p(this, re, new Promise((s, n) => {
2052
+ p(this, Ee, s, "f"), p(this, ae, n, "f");
2053
+ })), p(this, ie, new Promise((s, n) => {
2054
+ p(this, Pe, s, "f"), p(this, oe, n, "f");
2055
+ })), o(this, re, "f").catch(() => {
2056
+ }), o(this, ie, "f").catch(() => {
2057
+ }), p(this, Q, e), p(this, le, t?.logger ?? console);
2054
2058
  }
2055
2059
  get response() {
2056
- return o(this, $e, "f");
2060
+ return o(this, Ie, "f");
2057
2061
  }
2058
2062
  get request_id() {
2059
- return o(this, Ie, "f");
2063
+ return o(this, Ce, "f");
2060
2064
  }
2061
2065
  /**
2062
2066
  * Returns the `MessageStream` data, the raw `Response` instance and the ID of the request,
@@ -2069,8 +2073,8 @@ class Ve {
2069
2073
  * as no `Response` is available.
2070
2074
  */
2071
2075
  async withResponse() {
2072
- d(this, X, !0);
2073
- const e = await o(this, ne, "f");
2076
+ p(this, J, !0);
2077
+ const e = await o(this, re, "f");
2074
2078
  if (!e)
2075
2079
  throw new Error("Could not resolve a `Response` object");
2076
2080
  return {
@@ -2094,7 +2098,7 @@ class Ve {
2094
2098
  const a = new Ve(t, { logger: n });
2095
2099
  for (const i of t.messages)
2096
2100
  a._addMessageParam(i);
2097
- return d(a, G, { ...t, stream: !0 }), a._run(() => a._createMessage(e, { ...t, stream: !0 }, { ...s, headers: { ...s?.headers, "X-Stainless-Helper-Method": "stream" } })), a;
2101
+ return p(a, Q, { ...t, stream: !0 }), a._run(() => a._createMessage(e, { ...t, stream: !0 }, { ...s, headers: { ...s?.headers, "X-Stainless-Helper-Method": "stream" } })), a;
2098
2102
  }
2099
2103
  _run(e) {
2100
2104
  e().then(() => {
@@ -2112,29 +2116,29 @@ class Ve {
2112
2116
  let a;
2113
2117
  n && (n.aborted && this.controller.abort(), a = this.controller.abort.bind(this.controller), n.addEventListener("abort", a));
2114
2118
  try {
2115
- o(this, $, "m", st).call(this);
2116
- const { response: i, data: c } = await e.create({ ...t, stream: !0 }, { ...s, signal: this.controller.signal }).withResponse();
2119
+ o(this, $, "m", nt).call(this);
2120
+ const { response: i, data: l } = await e.create({ ...t, stream: !0 }, { ...s, signal: this.controller.signal }).withResponse();
2117
2121
  this._connected(i);
2118
- for await (const l of c)
2119
- o(this, $, "m", nt).call(this, l);
2120
- if (c.controller.signal?.aborted)
2122
+ for await (const c of l)
2123
+ o(this, $, "m", rt).call(this, c);
2124
+ if (l.controller.signal?.aborted)
2121
2125
  throw new B();
2122
- o(this, $, "m", rt).call(this);
2126
+ o(this, $, "m", at).call(this);
2123
2127
  } finally {
2124
2128
  n && a && n.removeEventListener("abort", a);
2125
2129
  }
2126
2130
  }
2127
2131
  _connected(e) {
2128
- this.ended || (d(this, $e, e), d(this, Ie, e?.headers.get("request-id")), o(this, Te, "f").call(this, e), this._emit("connect"));
2132
+ this.ended || (p(this, Ie, e), p(this, Ce, e?.headers.get("request-id")), o(this, Ee, "f").call(this, e), this._emit("connect"));
2129
2133
  }
2130
2134
  get ended() {
2131
- return o(this, oe, "f");
2135
+ return o(this, ce, "f");
2132
2136
  }
2133
2137
  get errored() {
2134
- return o(this, Pe, "f");
2138
+ return o(this, Ae, "f");
2135
2139
  }
2136
2140
  get aborted() {
2137
- return o(this, Ae, "f");
2141
+ return o(this, $e, "f");
2138
2142
  }
2139
2143
  abort() {
2140
2144
  this.controller.abort();
@@ -2147,7 +2151,7 @@ class Ve {
2147
2151
  * @returns this MessageStream, so that calls can be chained
2148
2152
  */
2149
2153
  on(e, t) {
2150
- return (o(this, N, "f")[e] || (o(this, N, "f")[e] = [])).push({ listener: t }), this;
2154
+ return (o(this, q, "f")[e] || (o(this, q, "f")[e] = [])).push({ listener: t }), this;
2151
2155
  }
2152
2156
  /**
2153
2157
  * Removes the specified listener from the listener array for the event.
@@ -2157,7 +2161,7 @@ class Ve {
2157
2161
  * @returns this MessageStream, so that calls can be chained
2158
2162
  */
2159
2163
  off(e, t) {
2160
- const s = o(this, N, "f")[e];
2164
+ const s = o(this, q, "f")[e];
2161
2165
  if (!s)
2162
2166
  return this;
2163
2167
  const n = s.findIndex((a) => a.listener === t);
@@ -2169,7 +2173,7 @@ class Ve {
2169
2173
  * @returns this MessageStream, so that calls can be chained
2170
2174
  */
2171
2175
  once(e, t) {
2172
- return (o(this, N, "f")[e] || (o(this, N, "f")[e] = [])).push({ listener: t, once: !0 }), this;
2176
+ return (o(this, q, "f")[e] || (o(this, q, "f")[e] = [])).push({ listener: t, once: !0 }), this;
2173
2177
  }
2174
2178
  /**
2175
2179
  * This is similar to `.once()`, but returns a Promise that resolves the next time
@@ -2184,11 +2188,11 @@ class Ve {
2184
2188
  */
2185
2189
  emitted(e) {
2186
2190
  return new Promise((t, s) => {
2187
- d(this, X, !0), e !== "error" && this.once("error", s), this.once(e, t);
2191
+ p(this, J, !0), e !== "error" && this.once("error", s), this.once(e, t);
2188
2192
  });
2189
2193
  }
2190
2194
  async done() {
2191
- d(this, X, !0), await o(this, ae, "f");
2195
+ p(this, J, !0), await o(this, ie, "f");
2192
2196
  }
2193
2197
  get currentMessage() {
2194
2198
  return o(this, F, "f");
@@ -2199,7 +2203,7 @@ class Ve {
2199
2203
  * If structured outputs were used, this will be a ParsedMessage with a `parsed` field.
2200
2204
  */
2201
2205
  async finalMessage() {
2202
- return await this.done(), o(this, $, "m", tt).call(this);
2206
+ return await this.done(), o(this, $, "m", st).call(this);
2203
2207
  }
2204
2208
  /**
2205
2209
  * @returns a promise that resolves with the the final assistant Message's text response, concatenated
@@ -2207,59 +2211,59 @@ class Ve {
2207
2211
  * Rejects if an error occurred or the stream ended prematurely without producing a Message.
2208
2212
  */
2209
2213
  async finalText() {
2210
- return await this.done(), o(this, $, "m", Vt).call(this);
2214
+ return await this.done(), o(this, $, "m", Kt).call(this);
2211
2215
  }
2212
2216
  _emit(e, ...t) {
2213
- if (o(this, oe, "f"))
2217
+ if (o(this, ce, "f"))
2214
2218
  return;
2215
- e === "end" && (d(this, oe, !0), o(this, Ee, "f").call(this));
2216
- const s = o(this, N, "f")[e];
2217
- if (s && (o(this, N, "f")[e] = s.filter((n) => !n.once), s.forEach(({ listener: n }) => n(...t))), e === "abort") {
2219
+ e === "end" && (p(this, ce, !0), o(this, Pe, "f").call(this));
2220
+ const s = o(this, q, "f")[e];
2221
+ if (s && (o(this, q, "f")[e] = s.filter((n) => !n.once), s.forEach(({ listener: n }) => n(...t))), e === "abort") {
2218
2222
  const n = t[0];
2219
- !o(this, X, "f") && !s?.length && Promise.reject(n), o(this, re, "f").call(this, n), o(this, ie, "f").call(this, n), this._emit("end");
2223
+ !o(this, J, "f") && !s?.length && Promise.reject(n), o(this, ae, "f").call(this, n), o(this, oe, "f").call(this, n), this._emit("end");
2220
2224
  return;
2221
2225
  }
2222
2226
  if (e === "error") {
2223
2227
  const n = t[0];
2224
- !o(this, X, "f") && !s?.length && Promise.reject(n), o(this, re, "f").call(this, n), o(this, ie, "f").call(this, n), this._emit("end");
2228
+ !o(this, J, "f") && !s?.length && Promise.reject(n), o(this, ae, "f").call(this, n), o(this, oe, "f").call(this, n), this._emit("end");
2225
2229
  }
2226
2230
  }
2227
2231
  _emitFinal() {
2228
- this.receivedMessages.at(-1) && this._emit("finalMessage", o(this, $, "m", tt).call(this));
2232
+ this.receivedMessages.at(-1) && this._emit("finalMessage", o(this, $, "m", st).call(this));
2229
2233
  }
2230
2234
  async _fromReadableStream(e, t) {
2231
2235
  const s = t?.signal;
2232
2236
  let n;
2233
2237
  s && (s.aborted && this.controller.abort(), n = this.controller.abort.bind(this.controller), s.addEventListener("abort", n));
2234
2238
  try {
2235
- o(this, $, "m", st).call(this), this._connected(null);
2236
- const a = C.fromReadableStream(e, this.controller);
2239
+ o(this, $, "m", nt).call(this), this._connected(null);
2240
+ const a = j.fromReadableStream(e, this.controller);
2237
2241
  for await (const i of a)
2238
- o(this, $, "m", nt).call(this, i);
2242
+ o(this, $, "m", rt).call(this, i);
2239
2243
  if (a.controller.signal?.aborted)
2240
2244
  throw new B();
2241
- o(this, $, "m", rt).call(this);
2245
+ o(this, $, "m", at).call(this);
2242
2246
  } finally {
2243
2247
  s && n && s.removeEventListener("abort", n);
2244
2248
  }
2245
2249
  }
2246
- [(F = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), ne = /* @__PURE__ */ new WeakMap(), Te = /* @__PURE__ */ new WeakMap(), re = /* @__PURE__ */ new WeakMap(), ae = /* @__PURE__ */ new WeakMap(), Ee = /* @__PURE__ */ new WeakMap(), ie = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap(), oe = /* @__PURE__ */ new WeakMap(), Pe = /* @__PURE__ */ new WeakMap(), Ae = /* @__PURE__ */ new WeakMap(), X = /* @__PURE__ */ new WeakMap(), $e = /* @__PURE__ */ new WeakMap(), Ie = /* @__PURE__ */ new WeakMap(), ce = /* @__PURE__ */ new WeakMap(), Oe = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new WeakSet(), tt = function() {
2250
+ [(F = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakMap(), re = /* @__PURE__ */ new WeakMap(), Ee = /* @__PURE__ */ new WeakMap(), ae = /* @__PURE__ */ new WeakMap(), ie = /* @__PURE__ */ new WeakMap(), Pe = /* @__PURE__ */ new WeakMap(), oe = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), ce = /* @__PURE__ */ new WeakMap(), Ae = /* @__PURE__ */ new WeakMap(), $e = /* @__PURE__ */ new WeakMap(), J = /* @__PURE__ */ new WeakMap(), Ie = /* @__PURE__ */ new WeakMap(), Ce = /* @__PURE__ */ new WeakMap(), le = /* @__PURE__ */ new WeakMap(), Oe = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new WeakSet(), st = function() {
2247
2251
  if (this.receivedMessages.length === 0)
2248
2252
  throw new b("stream ended without producing a Message with role=assistant");
2249
2253
  return this.receivedMessages.at(-1);
2250
- }, Vt = function() {
2254
+ }, Kt = function() {
2251
2255
  if (this.receivedMessages.length === 0)
2252
2256
  throw new b("stream ended without producing a Message with role=assistant");
2253
2257
  const t = this.receivedMessages.at(-1).content.filter((s) => s.type === "text").map((s) => s.text);
2254
2258
  if (t.length === 0)
2255
2259
  throw new b("stream ended without producing a content block with type=text");
2256
2260
  return t.join(" ");
2257
- }, st = function() {
2258
- this.ended || d(this, F, void 0);
2259
- }, nt = function(t) {
2261
+ }, nt = function() {
2262
+ this.ended || p(this, F, void 0);
2263
+ }, rt = function(t) {
2260
2264
  if (this.ended)
2261
2265
  return;
2262
- const s = o(this, $, "m", Kt).call(this, t);
2266
+ const s = o(this, $, "m", zt).call(this, t);
2263
2267
  switch (this._emit("streamEvent", t, s), t.type) {
2264
2268
  case "content_block_delta": {
2265
2269
  const n = s.content.at(-1);
@@ -2273,7 +2277,7 @@ class Ve {
2273
2277
  break;
2274
2278
  }
2275
2279
  case "input_json_delta": {
2276
- Gt(n) && n.input && this._emit("inputJson", t.delta.partial_json, n.input);
2280
+ Qt(n) && n.input && this._emit("inputJson", t.delta.partial_json, n.input);
2277
2281
  break;
2278
2282
  }
2279
2283
  case "thinking_delta": {
@@ -2294,7 +2298,7 @@ class Ve {
2294
2298
  break;
2295
2299
  }
2296
2300
  case "message_stop": {
2297
- this._addMessageParam(s), this._addMessage(Xt(s, o(this, G, "f"), { logger: o(this, ce, "f") }), !0);
2301
+ this._addMessageParam(s), this._addMessage(Vt(s, o(this, Q, "f"), { logger: o(this, le, "f") }), !0);
2298
2302
  break;
2299
2303
  }
2300
2304
  case "content_block_stop": {
@@ -2302,18 +2306,18 @@ class Ve {
2302
2306
  break;
2303
2307
  }
2304
2308
  case "message_start": {
2305
- d(this, F, s);
2309
+ p(this, F, s);
2306
2310
  break;
2307
2311
  }
2308
2312
  }
2309
- }, rt = function() {
2313
+ }, at = function() {
2310
2314
  if (this.ended)
2311
2315
  throw new b("stream has ended, this shouldn't happen");
2312
2316
  const t = o(this, F, "f");
2313
2317
  if (!t)
2314
2318
  throw new b("request ended without sending any chunks");
2315
- return d(this, F, void 0), Xt(t, o(this, G, "f"), { logger: o(this, ce, "f") });
2316
- }, Kt = function(t) {
2319
+ return p(this, F, void 0), Vt(t, o(this, Q, "f"), { logger: o(this, le, "f") });
2320
+ }, zt = function(t) {
2317
2321
  let s = o(this, F, "f");
2318
2322
  if (t.type === "message_start") {
2319
2323
  if (s)
@@ -2347,20 +2351,20 @@ class Ve {
2347
2351
  break;
2348
2352
  }
2349
2353
  case "input_json_delta": {
2350
- if (n && Gt(n)) {
2351
- let a = n[zt] || "";
2354
+ if (n && Qt(n)) {
2355
+ let a = n[Gt] || "";
2352
2356
  a += t.delta.partial_json;
2353
2357
  const i = { ...n };
2354
- if (Object.defineProperty(i, zt, {
2358
+ if (Object.defineProperty(i, Gt, {
2355
2359
  value: a,
2356
2360
  enumerable: !1,
2357
2361
  writable: !0
2358
2362
  }), a)
2359
2363
  try {
2360
2364
  i.input = Fs(a);
2361
- } catch (c) {
2362
- const l = new b(`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${c}. JSON: ${a}`);
2363
- o(this, Oe, "f").call(this, l);
2365
+ } catch (l) {
2366
+ const c = new b(`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${l}. JSON: ${a}`);
2367
+ o(this, Oe, "f").call(this, c);
2364
2368
  }
2365
2369
  s.content[t.index] = i;
2366
2370
  }
@@ -2422,16 +2426,16 @@ class Ve {
2422
2426
  };
2423
2427
  }
2424
2428
  toReadableStream() {
2425
- return new C(this[Symbol.asyncIterator].bind(this), this.controller).toReadableStream();
2429
+ return new j(this[Symbol.asyncIterator].bind(this), this.controller).toReadableStream();
2426
2430
  }
2427
2431
  }
2428
- class Ds extends Error {
2432
+ class Hs extends Error {
2429
2433
  constructor(e) {
2430
2434
  const t = typeof e == "string" ? e : e.map((s) => s.type === "text" ? s.text : `[${s.type}]`).join(" ");
2431
2435
  super(t), this.name = "ToolError", this.content = e;
2432
2436
  }
2433
2437
  }
2434
- const Qn = 1e5, Yn = `You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
2438
+ const rr = 1e5, ar = `You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
2435
2439
  1. Task Overview
2436
2440
  The user's core request and success criteria
2437
2441
  Any clarifications or constraints they specified
@@ -2454,16 +2458,16 @@ Domain-specific details that aren't obvious
2454
2458
  Any promises made to the user
2455
2459
  Be concise but complete—err on the side of including information that would prevent duplicate work or repeated mistakes. Write in a way that enables immediate resumption of the task.
2456
2460
  Wrap your summary in <summary></summary> tags.`;
2457
- var le, Q, V, S, R, E, U, D, ue, Qt, _t;
2458
- function Yt() {
2461
+ var ue, Y, X, S, T, E, U, H, he, Yt, wt;
2462
+ function Zt() {
2459
2463
  let r, e;
2460
2464
  return { promise: new Promise((s, n) => {
2461
2465
  r = s, e = n;
2462
2466
  }), resolve: r, reject: e };
2463
2467
  }
2464
- class Hs {
2468
+ class Ds {
2465
2469
  constructor(e, t, s) {
2466
- le.add(this), this.client = e, Q.set(this, !1), V.set(this, !1), S.set(this, void 0), R.set(this, void 0), E.set(this, void 0), U.set(this, void 0), D.set(this, void 0), ue.set(this, 0), d(this, S, {
2470
+ ue.add(this), this.client = e, Y.set(this, !1), X.set(this, !1), S.set(this, void 0), T.set(this, void 0), E.set(this, void 0), U.set(this, void 0), H.set(this, void 0), he.set(this, 0), p(this, S, {
2467
2471
  params: {
2468
2472
  // You can't clone the entire params since there are functions as handlers.
2469
2473
  // You also don't really need to clone params.messages, but it probably will prevent a foot gun
@@ -2473,38 +2477,38 @@ class Hs {
2473
2477
  }
2474
2478
  });
2475
2479
  const a = ["BetaToolRunner", ...$s(t.tools, t.messages)].join(", ");
2476
- d(this, R, {
2480
+ p(this, T, {
2477
2481
  ...s,
2478
- headers: u([{ "x-stainless-helper": a }, s?.headers])
2479
- }), d(this, D, Yt()), t.compactionControl?.enabled && console.warn('Anthropic: The `compactionControl` parameter is deprecated and will be removed in a future version. Use server-side compaction instead by passing `edits: [{ type: "compact_20260112" }]` in the params passed to `toolRunner()`. See https://platform.claude.com/docs/en/build-with-claude/compaction');
2482
+ headers: d([{ "x-stainless-helper": a }, s?.headers])
2483
+ }), p(this, H, Zt()), t.compactionControl?.enabled && console.warn('Anthropic: The `compactionControl` parameter is deprecated and will be removed in a future version. Use server-side compaction instead by passing `edits: [{ type: "compact_20260112" }]` in the params passed to `toolRunner()`. See https://platform.claude.com/docs/en/build-with-claude/compaction');
2480
2484
  }
2481
- async *[(Q = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), ue = /* @__PURE__ */ new WeakMap(), le = /* @__PURE__ */ new WeakSet(), Qt = async function() {
2485
+ async *[(Y = /* @__PURE__ */ new WeakMap(), X = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), he = /* @__PURE__ */ new WeakMap(), ue = /* @__PURE__ */ new WeakSet(), Yt = async function() {
2482
2486
  const t = o(this, S, "f").params.compactionControl;
2483
2487
  if (!t || !t.enabled)
2484
2488
  return !1;
2485
2489
  let s = 0;
2486
2490
  if (o(this, E, "f") !== void 0)
2487
2491
  try {
2488
- const h = await o(this, E, "f");
2489
- s = h.usage.input_tokens + (h.usage.cache_creation_input_tokens ?? 0) + (h.usage.cache_read_input_tokens ?? 0) + h.usage.output_tokens;
2492
+ const f = await o(this, E, "f");
2493
+ s = f.usage.input_tokens + (f.usage.cache_creation_input_tokens ?? 0) + (f.usage.cache_read_input_tokens ?? 0) + f.usage.output_tokens;
2490
2494
  } catch {
2491
2495
  return !1;
2492
2496
  }
2493
- const n = t.contextTokenThreshold ?? Qn;
2497
+ const n = t.contextTokenThreshold ?? rr;
2494
2498
  if (s < n)
2495
2499
  return !1;
2496
- const a = t.model ?? o(this, S, "f").params.model, i = t.summaryPrompt ?? Yn, c = o(this, S, "f").params.messages;
2497
- if (c[c.length - 1].role === "assistant") {
2498
- const h = c[c.length - 1];
2499
- if (Array.isArray(h.content)) {
2500
- const _ = h.content.filter((y) => y.type !== "tool_use");
2501
- _.length === 0 ? c.pop() : h.content = _;
2500
+ const a = t.model ?? o(this, S, "f").params.model, i = t.summaryPrompt ?? ar, l = o(this, S, "f").params.messages;
2501
+ if (l[l.length - 1].role === "assistant") {
2502
+ const f = l[l.length - 1];
2503
+ if (Array.isArray(f.content)) {
2504
+ const _ = f.content.filter((g) => g.type !== "tool_use");
2505
+ _.length === 0 ? l.pop() : f.content = _;
2502
2506
  }
2503
2507
  }
2504
- const l = await this.client.beta.messages.create({
2508
+ const c = await this.client.beta.messages.create({
2505
2509
  model: a,
2506
2510
  messages: [
2507
- ...c,
2511
+ ...l,
2508
2512
  {
2509
2513
  role: "user",
2510
2514
  content: [
@@ -2517,40 +2521,40 @@ class Hs {
2517
2521
  ],
2518
2522
  max_tokens: o(this, S, "f").params.max_tokens
2519
2523
  }, {
2520
- signal: o(this, R, "f").signal,
2521
- headers: u([o(this, R, "f").headers, { "x-stainless-helper": "compaction" }])
2524
+ signal: o(this, T, "f").signal,
2525
+ headers: d([o(this, T, "f").headers, { "x-stainless-helper": "compaction" }])
2522
2526
  });
2523
- if (l.content[0]?.type !== "text")
2527
+ if (c.content[0]?.type !== "text")
2524
2528
  throw new b("Expected text response for compaction");
2525
2529
  return o(this, S, "f").params.messages = [
2526
2530
  {
2527
2531
  role: "user",
2528
- content: l.content
2532
+ content: c.content
2529
2533
  }
2530
2534
  ], !0;
2531
2535
  }, Symbol.asyncIterator)]() {
2532
2536
  var e;
2533
- if (o(this, Q, "f"))
2537
+ if (o(this, Y, "f"))
2534
2538
  throw new b("Cannot iterate over a consumed stream");
2535
- d(this, Q, !0), d(this, V, !0), d(this, U, void 0);
2539
+ p(this, Y, !0), p(this, X, !0), p(this, U, void 0);
2536
2540
  try {
2537
2541
  for (; ; ) {
2538
2542
  let t;
2539
2543
  try {
2540
- if (o(this, S, "f").params.max_iterations && o(this, ue, "f") >= o(this, S, "f").params.max_iterations)
2544
+ if (o(this, S, "f").params.max_iterations && o(this, he, "f") >= o(this, S, "f").params.max_iterations)
2541
2545
  break;
2542
- d(this, V, !1, "f"), d(this, U, void 0, "f"), d(this, ue, (e = o(this, ue, "f"), e++, e), "f"), d(this, E, void 0, "f");
2546
+ p(this, X, !1, "f"), p(this, U, void 0, "f"), p(this, he, (e = o(this, he, "f"), e++, e), "f"), p(this, E, void 0, "f");
2543
2547
  const { max_iterations: s, compactionControl: n, ...a } = o(this, S, "f").params;
2544
- if (a.stream ? (t = this.client.beta.messages.stream({ ...a }, o(this, R, "f")), d(this, E, t.finalMessage(), "f"), o(this, E, "f").catch(() => {
2545
- }), yield t) : (d(this, E, this.client.beta.messages.create({ ...a, stream: !1 }, o(this, R, "f")), "f"), yield o(this, E, "f")), !await o(this, le, "m", Qt).call(this)) {
2546
- if (!o(this, V, "f")) {
2547
- const { role: l, content: h } = await o(this, E, "f");
2548
- o(this, S, "f").params.messages.push({ role: l, content: h });
2548
+ if (a.stream ? (t = this.client.beta.messages.stream({ ...a }, o(this, T, "f")), p(this, E, t.finalMessage(), "f"), o(this, E, "f").catch(() => {
2549
+ }), yield t) : (p(this, E, this.client.beta.messages.create({ ...a, stream: !1 }, o(this, T, "f")), "f"), yield o(this, E, "f")), !await o(this, ue, "m", Yt).call(this)) {
2550
+ if (!o(this, X, "f")) {
2551
+ const { role: c, content: f } = await o(this, E, "f");
2552
+ o(this, S, "f").params.messages.push({ role: c, content: f });
2549
2553
  }
2550
- const c = await o(this, le, "m", _t).call(this, o(this, S, "f").params.messages.at(-1));
2551
- if (c)
2552
- o(this, S, "f").params.messages.push(c);
2553
- else if (!o(this, V, "f"))
2554
+ const l = await o(this, ue, "m", wt).call(this, o(this, S, "f").params.messages.at(-1));
2555
+ if (l)
2556
+ o(this, S, "f").params.messages.push(l);
2557
+ else if (!o(this, X, "f"))
2554
2558
  break;
2555
2559
  }
2556
2560
  } finally {
@@ -2559,17 +2563,17 @@ class Hs {
2559
2563
  }
2560
2564
  if (!o(this, E, "f"))
2561
2565
  throw new b("ToolRunner concluded without a message from the server");
2562
- o(this, D, "f").resolve(await o(this, E, "f"));
2566
+ o(this, H, "f").resolve(await o(this, E, "f"));
2563
2567
  } catch (t) {
2564
- throw d(this, Q, !1), o(this, D, "f").promise.catch(() => {
2565
- }), o(this, D, "f").reject(t), d(this, D, Yt()), t;
2568
+ throw p(this, Y, !1), o(this, H, "f").promise.catch(() => {
2569
+ }), o(this, H, "f").reject(t), p(this, H, Zt()), t;
2566
2570
  }
2567
2571
  }
2568
2572
  setMessagesParams(e) {
2569
- typeof e == "function" ? o(this, S, "f").params = e(o(this, S, "f").params) : o(this, S, "f").params = e, d(this, V, !0), d(this, U, void 0);
2573
+ typeof e == "function" ? o(this, S, "f").params = e(o(this, S, "f").params) : o(this, S, "f").params = e, p(this, X, !0), p(this, U, void 0);
2570
2574
  }
2571
2575
  setRequestOptions(e) {
2572
- typeof e == "function" ? d(this, R, e(o(this, R, "f"))) : d(this, R, { ...o(this, R, "f"), ...e });
2576
+ typeof e == "function" ? p(this, T, e(o(this, T, "f"))) : p(this, T, { ...o(this, T, "f"), ...e });
2573
2577
  }
2574
2578
  /**
2575
2579
  * Get the tool response for the last message from the assistant.
@@ -2583,9 +2587,9 @@ class Hs {
2583
2587
  * console.log('Tool results:', toolResponse.content);
2584
2588
  * }
2585
2589
  */
2586
- async generateToolResponse(e = o(this, R, "f").signal) {
2590
+ async generateToolResponse(e = o(this, T, "f").signal) {
2587
2591
  const t = await o(this, E, "f") ?? this.params.messages.at(-1);
2588
- return t ? o(this, le, "m", _t).call(this, t, e) : null;
2592
+ return t ? o(this, ue, "m", wt).call(this, t, e) : null;
2589
2593
  }
2590
2594
  /**
2591
2595
  * Wait for the async iterator to complete. This works even if the async iterator hasn't yet started, and
@@ -2604,7 +2608,7 @@ class Hs {
2604
2608
  * console.log('Final response:', finalMessage.content);
2605
2609
  */
2606
2610
  done() {
2607
- return o(this, D, "f").promise;
2611
+ return o(this, H, "f").promise;
2608
2612
  }
2609
2613
  /**
2610
2614
  * Returns a promise indicating that the stream is done. Unlike .done(), this will eagerly read the stream:
@@ -2620,7 +2624,7 @@ class Hs {
2620
2624
  * console.log('Final response:', finalMessage.content);
2621
2625
  */
2622
2626
  async runUntilDone() {
2623
- if (!o(this, Q, "f"))
2627
+ if (!o(this, Y, "f"))
2624
2628
  for await (const e of this)
2625
2629
  ;
2626
2630
  return this.done();
@@ -2669,20 +2673,20 @@ class Hs {
2669
2673
  return this.runUntilDone().then(e, t);
2670
2674
  }
2671
2675
  }
2672
- _t = async function(e, t = o(this, R, "f").signal) {
2673
- return o(this, U, "f") !== void 0 ? o(this, U, "f") : (d(this, U, Zn(o(this, S, "f").params, e, {
2674
- ...o(this, R, "f"),
2676
+ wt = async function(e, t = o(this, T, "f").signal) {
2677
+ return o(this, U, "f") !== void 0 ? o(this, U, "f") : (p(this, U, ir(o(this, S, "f").params, e, {
2678
+ ...o(this, T, "f"),
2675
2679
  signal: t
2676
2680
  })), o(this, U, "f"));
2677
2681
  };
2678
- async function Zn(r, e = r.messages.at(-1), t) {
2682
+ async function ir(r, e = r.messages.at(-1), t) {
2679
2683
  if (!e || e.role !== "assistant" || !e.content || typeof e.content == "string")
2680
2684
  return null;
2681
2685
  const s = e.content.filter((a) => a.type === "tool_use");
2682
2686
  return s.length === 0 ? null : {
2683
2687
  role: "user",
2684
2688
  content: await Promise.all(s.map(async (a) => {
2685
- const i = r.tools.find((c) => ("name" in c ? c.name : c.mcp_server_name) === a.name);
2689
+ const i = r.tools.find((l) => ("name" in l ? l.name : l.mcp_server_name) === a.name);
2686
2690
  if (!i || !("run" in i))
2687
2691
  return {
2688
2692
  type: "tool_result",
@@ -2691,22 +2695,22 @@ async function Zn(r, e = r.messages.at(-1), t) {
2691
2695
  is_error: !0
2692
2696
  };
2693
2697
  try {
2694
- let c = a.input;
2695
- "parse" in i && i.parse && (c = i.parse(c));
2696
- const l = await i.run(c, {
2698
+ let l = a.input;
2699
+ "parse" in i && i.parse && (l = i.parse(l));
2700
+ const c = await i.run(l, {
2697
2701
  toolUseBlock: a,
2698
2702
  signal: t?.signal
2699
2703
  });
2700
2704
  return {
2701
2705
  type: "tool_result",
2702
2706
  tool_use_id: a.id,
2703
- content: l
2707
+ content: c
2704
2708
  };
2705
- } catch (c) {
2709
+ } catch (l) {
2706
2710
  return {
2707
2711
  type: "tool_result",
2708
2712
  tool_use_id: a.id,
2709
- content: c instanceof Ds ? c.content : `Error: ${c instanceof Error ? c.message : String(c)}`,
2713
+ content: l instanceof Hs ? l.content : `Error: ${l instanceof Error ? l.message : String(l)}`,
2710
2714
  is_error: !0
2711
2715
  };
2712
2716
  }
@@ -2718,7 +2722,7 @@ class Ye {
2718
2722
  this.iterator = e, this.controller = t;
2719
2723
  }
2720
2724
  async *decoder() {
2721
- const e = new ke();
2725
+ const e = new Se();
2722
2726
  for await (const t of this.iterator)
2723
2727
  for (const s of e.decode(t))
2724
2728
  yield JSON.parse(s);
@@ -2731,7 +2735,7 @@ class Ye {
2731
2735
  static fromResponse(e, t) {
2732
2736
  if (!e.body)
2733
2737
  throw t.abort(), typeof globalThis.navigator < "u" && globalThis.navigator.product === "ReactNative" ? new b("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api") : new b("Attempted to iterate over a response with no body");
2734
- return new Ye(yt(e.body), t);
2738
+ return new Ye(St(e.body), t);
2735
2739
  }
2736
2740
  }
2737
2741
  let Js = class extends w {
@@ -2769,7 +2773,7 @@ let Js = class extends w {
2769
2773
  return this._client.post("/v1/messages/batches?beta=true", {
2770
2774
  body: n,
2771
2775
  ...t,
2772
- headers: u([
2776
+ headers: d([
2773
2777
  { "anthropic-beta": [...s ?? [], "message-batches-2024-09-24"].toString() },
2774
2778
  t?.headers
2775
2779
  ])
@@ -2793,9 +2797,9 @@ let Js = class extends w {
2793
2797
  */
2794
2798
  retrieve(e, t = {}, s) {
2795
2799
  const { betas: n } = t ?? {};
2796
- return this._client.get(g`/v1/messages/batches/${e}?beta=true`, {
2800
+ return this._client.get(m`/v1/messages/batches/${e}?beta=true`, {
2797
2801
  ...s,
2798
- headers: u([
2802
+ headers: d([
2799
2803
  { "anthropic-beta": [...n ?? [], "message-batches-2024-09-24"].toString() },
2800
2804
  s?.headers
2801
2805
  ])
@@ -2818,10 +2822,10 @@ let Js = class extends w {
2818
2822
  */
2819
2823
  list(e = {}, t) {
2820
2824
  const { betas: s, ...n } = e ?? {};
2821
- return this._client.getAPIList("/v1/messages/batches?beta=true", Se, {
2825
+ return this._client.getAPIList("/v1/messages/batches?beta=true", xe, {
2822
2826
  query: n,
2823
2827
  ...t,
2824
- headers: u([
2828
+ headers: d([
2825
2829
  { "anthropic-beta": [...s ?? [], "message-batches-2024-09-24"].toString() },
2826
2830
  t?.headers
2827
2831
  ])
@@ -2846,9 +2850,9 @@ let Js = class extends w {
2846
2850
  */
2847
2851
  delete(e, t = {}, s) {
2848
2852
  const { betas: n } = t ?? {};
2849
- return this._client.delete(g`/v1/messages/batches/${e}?beta=true`, {
2853
+ return this._client.delete(m`/v1/messages/batches/${e}?beta=true`, {
2850
2854
  ...s,
2851
- headers: u([
2855
+ headers: d([
2852
2856
  { "anthropic-beta": [...n ?? [], "message-batches-2024-09-24"].toString() },
2853
2857
  s?.headers
2854
2858
  ])
@@ -2878,9 +2882,9 @@ let Js = class extends w {
2878
2882
  */
2879
2883
  cancel(e, t = {}, s) {
2880
2884
  const { betas: n } = t ?? {};
2881
- return this._client.post(g`/v1/messages/batches/${e}/cancel?beta=true`, {
2885
+ return this._client.post(m`/v1/messages/batches/${e}/cancel?beta=true`, {
2882
2886
  ...s,
2883
- headers: u([
2887
+ headers: d([
2884
2888
  { "anthropic-beta": [...n ?? [], "message-batches-2024-09-24"].toString() },
2885
2889
  s?.headers
2886
2890
  ])
@@ -2911,7 +2915,7 @@ let Js = class extends w {
2911
2915
  const { betas: a } = t ?? {};
2912
2916
  return this._client.get(n.results_url, {
2913
2917
  ...s,
2914
- headers: u([
2918
+ headers: d([
2915
2919
  {
2916
2920
  "anthropic-beta": [...a ?? [], "message-batches-2024-09-24"].toString(),
2917
2921
  Accept: "application/binary"
@@ -2920,10 +2924,10 @@ let Js = class extends w {
2920
2924
  ]),
2921
2925
  stream: !0,
2922
2926
  __binaryResponse: !0
2923
- })._thenUnwrap((i, c) => Ye.fromResponse(c.response, c.controller));
2927
+ })._thenUnwrap((i, l) => Ye.fromResponse(l.response, l.controller));
2924
2928
  }
2925
2929
  };
2926
- const Zt = {
2930
+ const es = {
2927
2931
  "claude-1.3": "November 6th, 2024",
2928
2932
  "claude-1.3-100k": "November 6th, 2024",
2929
2933
  "claude-instant-1.1": "November 6th, 2024",
@@ -2935,28 +2939,28 @@ const Zt = {
2935
2939
  "claude-2.0": "July 21st, 2025",
2936
2940
  "claude-3-7-sonnet-latest": "February 19th, 2026",
2937
2941
  "claude-3-7-sonnet-20250219": "February 19th, 2026"
2938
- }, er = ["claude-mythos-preview", "claude-opus-4-6"];
2939
- let xe = class extends w {
2942
+ }, or = ["claude-mythos-preview", "claude-opus-4-6"];
2943
+ let ve = class extends w {
2940
2944
  constructor() {
2941
2945
  super(...arguments), this.batches = new Js(this._client);
2942
2946
  }
2943
2947
  create(e, t) {
2944
- const s = es(e), { betas: n, ...a } = s;
2945
- a.model in Zt && console.warn(`The model '${a.model}' is deprecated and will reach end-of-life on ${Zt[a.model]}
2946
- Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`), er.includes(a.model) && a.thinking && a.thinking.type === "enabled" && console.warn(`Using Claude with ${a.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
2948
+ const s = ts(e), { betas: n, ...a } = s;
2949
+ a.model in es && console.warn(`The model '${a.model}' is deprecated and will reach end-of-life on ${es[a.model]}
2950
+ Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`), or.includes(a.model) && a.thinking && a.thinking.type === "enabled" && console.warn(`Using Claude with ${a.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
2947
2951
  let i = this._client._options.timeout;
2948
2952
  if (!a.stream && i == null) {
2949
- const l = qs[a.model] ?? void 0;
2950
- i = this._client.calculateNonstreamingTimeout(a.max_tokens, l);
2953
+ const c = qs[a.model] ?? void 0;
2954
+ i = this._client.calculateNonstreamingTimeout(a.max_tokens, c);
2951
2955
  }
2952
- const c = Is(a.tools, a.messages);
2956
+ const l = Is(a.tools, a.messages);
2953
2957
  return this._client.post("/v1/messages?beta=true", {
2954
2958
  body: a,
2955
2959
  timeout: i ?? 6e5,
2956
2960
  ...t,
2957
- headers: u([
2961
+ headers: d([
2958
2962
  { ...n?.toString() != null ? { "anthropic-beta": n?.toString() } : void 0 },
2959
- c,
2963
+ l,
2960
2964
  t?.headers
2961
2965
  ]),
2962
2966
  stream: s.stream ?? !1
@@ -2981,7 +2985,7 @@ Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resour
2981
2985
  parse(e, t) {
2982
2986
  return t = {
2983
2987
  ...t,
2984
- headers: u([
2988
+ headers: d([
2985
2989
  { "anthropic-beta": [...e.betas ?? [], "structured-outputs-2025-12-15"].toString() },
2986
2990
  t?.headers
2987
2991
  ])
@@ -3012,21 +3016,21 @@ Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resour
3012
3016
  * ```
3013
3017
  */
3014
3018
  countTokens(e, t) {
3015
- const s = es(e), { betas: n, ...a } = s;
3019
+ const s = ts(e), { betas: n, ...a } = s;
3016
3020
  return this._client.post("/v1/messages/count_tokens?beta=true", {
3017
3021
  body: a,
3018
3022
  ...t,
3019
- headers: u([
3023
+ headers: d([
3020
3024
  { "anthropic-beta": [...n ?? [], "token-counting-2024-11-01"].toString() },
3021
3025
  t?.headers
3022
3026
  ])
3023
3027
  });
3024
3028
  }
3025
3029
  toolRunner(e, t) {
3026
- return new Hs(this._client, e, t);
3030
+ return new Ds(this._client, e, t);
3027
3031
  }
3028
3032
  };
3029
- function es(r) {
3033
+ function ts(r) {
3030
3034
  if (!r.output_format)
3031
3035
  return r;
3032
3036
  if (r.output_config?.format)
@@ -3040,9 +3044,9 @@ function es(r) {
3040
3044
  }
3041
3045
  };
3042
3046
  }
3043
- xe.Batches = Js;
3044
- xe.BetaToolRunner = Hs;
3045
- xe.ToolError = Ds;
3047
+ ve.Batches = Js;
3048
+ ve.BetaToolRunner = Ds;
3049
+ ve.ToolError = Hs;
3046
3050
  class Xs extends w {
3047
3051
  /**
3048
3052
  * List Events
@@ -3059,10 +3063,10 @@ class Xs extends w {
3059
3063
  */
3060
3064
  list(e, t = {}, s) {
3061
3065
  const { betas: n, ...a } = t ?? {};
3062
- return this._client.getAPIList(g`/v1/sessions/${e}/events?beta=true`, T, {
3066
+ return this._client.getAPIList(m`/v1/sessions/${e}/events?beta=true`, M, {
3063
3067
  query: a,
3064
3068
  ...s,
3065
- headers: u([
3069
+ headers: d([
3066
3070
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3067
3071
  s?.headers
3068
3072
  ])
@@ -3094,10 +3098,10 @@ class Xs extends w {
3094
3098
  */
3095
3099
  send(e, t, s) {
3096
3100
  const { betas: n, ...a } = t;
3097
- return this._client.post(g`/v1/sessions/${e}/events?beta=true`, {
3101
+ return this._client.post(m`/v1/sessions/${e}/events?beta=true`, {
3098
3102
  body: a,
3099
3103
  ...s,
3100
- headers: u([
3104
+ headers: d([
3101
3105
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3102
3106
  s?.headers
3103
3107
  ])
@@ -3116,9 +3120,9 @@ class Xs extends w {
3116
3120
  */
3117
3121
  stream(e, t = {}, s) {
3118
3122
  const { betas: n } = t ?? {};
3119
- return this._client.get(g`/v1/sessions/${e}/events/stream?beta=true`, {
3123
+ return this._client.get(m`/v1/sessions/${e}/events/stream?beta=true`, {
3120
3124
  ...s,
3121
- headers: u([
3125
+ headers: d([
3122
3126
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3123
3127
  s?.headers
3124
3128
  ]),
@@ -3141,9 +3145,9 @@ class Vs extends w {
3141
3145
  */
3142
3146
  retrieve(e, t, s) {
3143
3147
  const { session_id: n, betas: a } = t;
3144
- return this._client.get(g`/v1/sessions/${n}/resources/${e}?beta=true`, {
3148
+ return this._client.get(m`/v1/sessions/${n}/resources/${e}?beta=true`, {
3145
3149
  ...s,
3146
- headers: u([
3150
+ headers: d([
3147
3151
  { "anthropic-beta": [...a ?? [], "managed-agents-2026-04-01"].toString() },
3148
3152
  s?.headers
3149
3153
  ])
@@ -3166,10 +3170,10 @@ class Vs extends w {
3166
3170
  */
3167
3171
  update(e, t, s) {
3168
3172
  const { session_id: n, betas: a, ...i } = t;
3169
- return this._client.post(g`/v1/sessions/${n}/resources/${e}?beta=true`, {
3173
+ return this._client.post(m`/v1/sessions/${n}/resources/${e}?beta=true`, {
3170
3174
  body: i,
3171
3175
  ...s,
3172
- headers: u([
3176
+ headers: d([
3173
3177
  { "anthropic-beta": [...a ?? [], "managed-agents-2026-04-01"].toString() },
3174
3178
  s?.headers
3175
3179
  ])
@@ -3190,10 +3194,10 @@ class Vs extends w {
3190
3194
  */
3191
3195
  list(e, t = {}, s) {
3192
3196
  const { betas: n, ...a } = t ?? {};
3193
- return this._client.getAPIList(g`/v1/sessions/${e}/resources?beta=true`, T, {
3197
+ return this._client.getAPIList(m`/v1/sessions/${e}/resources?beta=true`, M, {
3194
3198
  query: a,
3195
3199
  ...s,
3196
- headers: u([
3200
+ headers: d([
3197
3201
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3198
3202
  s?.headers
3199
3203
  ])
@@ -3213,9 +3217,9 @@ class Vs extends w {
3213
3217
  */
3214
3218
  delete(e, t, s) {
3215
3219
  const { session_id: n, betas: a } = t;
3216
- return this._client.delete(g`/v1/sessions/${n}/resources/${e}?beta=true`, {
3220
+ return this._client.delete(m`/v1/sessions/${n}/resources/${e}?beta=true`, {
3217
3221
  ...s,
3218
- headers: u([
3222
+ headers: d([
3219
3223
  { "anthropic-beta": [...a ?? [], "managed-agents-2026-04-01"].toString() },
3220
3224
  s?.headers
3221
3225
  ])
@@ -3238,10 +3242,10 @@ class Vs extends w {
3238
3242
  */
3239
3243
  add(e, t, s) {
3240
3244
  const { betas: n, ...a } = t;
3241
- return this._client.post(g`/v1/sessions/${e}/resources?beta=true`, {
3245
+ return this._client.post(m`/v1/sessions/${e}/resources?beta=true`, {
3242
3246
  body: a,
3243
3247
  ...s,
3244
- headers: u([
3248
+ headers: d([
3245
3249
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3246
3250
  s?.headers
3247
3251
  ])
@@ -3269,7 +3273,7 @@ class Ze extends w {
3269
3273
  return this._client.post("/v1/sessions?beta=true", {
3270
3274
  body: n,
3271
3275
  ...t,
3272
- headers: u([
3276
+ headers: d([
3273
3277
  { "anthropic-beta": [...s ?? [], "managed-agents-2026-04-01"].toString() },
3274
3278
  t?.headers
3275
3279
  ])
@@ -3288,9 +3292,9 @@ class Ze extends w {
3288
3292
  */
3289
3293
  retrieve(e, t = {}, s) {
3290
3294
  const { betas: n } = t ?? {};
3291
- return this._client.get(g`/v1/sessions/${e}?beta=true`, {
3295
+ return this._client.get(m`/v1/sessions/${e}?beta=true`, {
3292
3296
  ...s,
3293
- headers: u([
3297
+ headers: d([
3294
3298
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3295
3299
  s?.headers
3296
3300
  ])
@@ -3309,10 +3313,10 @@ class Ze extends w {
3309
3313
  */
3310
3314
  update(e, t, s) {
3311
3315
  const { betas: n, ...a } = t;
3312
- return this._client.post(g`/v1/sessions/${e}?beta=true`, {
3316
+ return this._client.post(m`/v1/sessions/${e}?beta=true`, {
3313
3317
  body: a,
3314
3318
  ...s,
3315
- headers: u([
3319
+ headers: d([
3316
3320
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3317
3321
  s?.headers
3318
3322
  ])
@@ -3331,10 +3335,10 @@ class Ze extends w {
3331
3335
  */
3332
3336
  list(e = {}, t) {
3333
3337
  const { betas: s, ...n } = e ?? {};
3334
- return this._client.getAPIList("/v1/sessions?beta=true", T, {
3338
+ return this._client.getAPIList("/v1/sessions?beta=true", M, {
3335
3339
  query: n,
3336
3340
  ...t,
3337
- headers: u([
3341
+ headers: d([
3338
3342
  { "anthropic-beta": [...s ?? [], "managed-agents-2026-04-01"].toString() },
3339
3343
  t?.headers
3340
3344
  ])
@@ -3353,9 +3357,9 @@ class Ze extends w {
3353
3357
  */
3354
3358
  delete(e, t = {}, s) {
3355
3359
  const { betas: n } = t ?? {};
3356
- return this._client.delete(g`/v1/sessions/${e}?beta=true`, {
3360
+ return this._client.delete(m`/v1/sessions/${e}?beta=true`, {
3357
3361
  ...s,
3358
- headers: u([
3362
+ headers: d([
3359
3363
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3360
3364
  s?.headers
3361
3365
  ])
@@ -3374,9 +3378,9 @@ class Ze extends w {
3374
3378
  */
3375
3379
  archive(e, t = {}, s) {
3376
3380
  const { betas: n } = t ?? {};
3377
- return this._client.post(g`/v1/sessions/${e}/archive?beta=true`, {
3381
+ return this._client.post(m`/v1/sessions/${e}/archive?beta=true`, {
3378
3382
  ...s,
3379
- headers: u([
3383
+ headers: d([
3380
3384
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3381
3385
  s?.headers
3382
3386
  ])
@@ -3398,10 +3402,10 @@ class Ks extends w {
3398
3402
  */
3399
3403
  create(e, t = {}, s) {
3400
3404
  const { betas: n, ...a } = t ?? {};
3401
- return this._client.post(g`/v1/skills/${e}/versions?beta=true`, kt({
3405
+ return this._client.post(m`/v1/skills/${e}/versions?beta=true`, vt({
3402
3406
  body: a,
3403
3407
  ...s,
3404
- headers: u([
3408
+ headers: d([
3405
3409
  { "anthropic-beta": [...n ?? [], "skills-2025-10-02"].toString() },
3406
3410
  s?.headers
3407
3411
  ])
@@ -3420,9 +3424,9 @@ class Ks extends w {
3420
3424
  */
3421
3425
  retrieve(e, t, s) {
3422
3426
  const { skill_id: n, betas: a } = t;
3423
- return this._client.get(g`/v1/skills/${n}/versions/${e}?beta=true`, {
3427
+ return this._client.get(m`/v1/skills/${n}/versions/${e}?beta=true`, {
3424
3428
  ...s,
3425
- headers: u([
3429
+ headers: d([
3426
3430
  { "anthropic-beta": [...a ?? [], "skills-2025-10-02"].toString() },
3427
3431
  s?.headers
3428
3432
  ])
@@ -3443,10 +3447,10 @@ class Ks extends w {
3443
3447
  */
3444
3448
  list(e, t = {}, s) {
3445
3449
  const { betas: n, ...a } = t ?? {};
3446
- return this._client.getAPIList(g`/v1/skills/${e}/versions?beta=true`, T, {
3450
+ return this._client.getAPIList(m`/v1/skills/${e}/versions?beta=true`, M, {
3447
3451
  query: a,
3448
3452
  ...s,
3449
- headers: u([
3453
+ headers: d([
3450
3454
  { "anthropic-beta": [...n ?? [], "skills-2025-10-02"].toString() },
3451
3455
  s?.headers
3452
3456
  ])
@@ -3465,16 +3469,16 @@ class Ks extends w {
3465
3469
  */
3466
3470
  delete(e, t, s) {
3467
3471
  const { skill_id: n, betas: a } = t;
3468
- return this._client.delete(g`/v1/skills/${n}/versions/${e}?beta=true`, {
3472
+ return this._client.delete(m`/v1/skills/${n}/versions/${e}?beta=true`, {
3469
3473
  ...s,
3470
- headers: u([
3474
+ headers: d([
3471
3475
  { "anthropic-beta": [...a ?? [], "skills-2025-10-02"].toString() },
3472
3476
  s?.headers
3473
3477
  ])
3474
3478
  });
3475
3479
  }
3476
3480
  }
3477
- class xt extends w {
3481
+ class Tt extends w {
3478
3482
  constructor() {
3479
3483
  super(...arguments), this.versions = new Ks(this._client);
3480
3484
  }
@@ -3488,10 +3492,10 @@ class xt extends w {
3488
3492
  */
3489
3493
  create(e = {}, t) {
3490
3494
  const { betas: s, ...n } = e ?? {};
3491
- return this._client.post("/v1/skills?beta=true", kt({
3495
+ return this._client.post("/v1/skills?beta=true", vt({
3492
3496
  body: n,
3493
3497
  ...t,
3494
- headers: u([
3498
+ headers: d([
3495
3499
  { "anthropic-beta": [...s ?? [], "skills-2025-10-02"].toString() },
3496
3500
  t?.headers
3497
3501
  ])
@@ -3507,9 +3511,9 @@ class xt extends w {
3507
3511
  */
3508
3512
  retrieve(e, t = {}, s) {
3509
3513
  const { betas: n } = t ?? {};
3510
- return this._client.get(g`/v1/skills/${e}?beta=true`, {
3514
+ return this._client.get(m`/v1/skills/${e}?beta=true`, {
3511
3515
  ...s,
3512
- headers: u([
3516
+ headers: d([
3513
3517
  { "anthropic-beta": [...n ?? [], "skills-2025-10-02"].toString() },
3514
3518
  s?.headers
3515
3519
  ])
@@ -3528,10 +3532,10 @@ class xt extends w {
3528
3532
  */
3529
3533
  list(e = {}, t) {
3530
3534
  const { betas: s, ...n } = e ?? {};
3531
- return this._client.getAPIList("/v1/skills?beta=true", T, {
3535
+ return this._client.getAPIList("/v1/skills?beta=true", M, {
3532
3536
  query: n,
3533
3537
  ...t,
3534
- headers: u([
3538
+ headers: d([
3535
3539
  { "anthropic-beta": [...s ?? [], "skills-2025-10-02"].toString() },
3536
3540
  t?.headers
3537
3541
  ])
@@ -3547,16 +3551,16 @@ class xt extends w {
3547
3551
  */
3548
3552
  delete(e, t = {}, s) {
3549
3553
  const { betas: n } = t ?? {};
3550
- return this._client.delete(g`/v1/skills/${e}?beta=true`, {
3554
+ return this._client.delete(m`/v1/skills/${e}?beta=true`, {
3551
3555
  ...s,
3552
- headers: u([
3556
+ headers: d([
3553
3557
  { "anthropic-beta": [...n ?? [], "skills-2025-10-02"].toString() },
3554
3558
  s?.headers
3555
3559
  ])
3556
3560
  });
3557
3561
  }
3558
3562
  }
3559
- xt.Versions = Ks;
3563
+ Tt.Versions = Ks;
3560
3564
  class zs extends w {
3561
3565
  /**
3562
3566
  * Create Credential
@@ -3579,10 +3583,10 @@ class zs extends w {
3579
3583
  */
3580
3584
  create(e, t, s) {
3581
3585
  const { betas: n, ...a } = t;
3582
- return this._client.post(g`/v1/vaults/${e}/credentials?beta=true`, {
3586
+ return this._client.post(m`/v1/vaults/${e}/credentials?beta=true`, {
3583
3587
  body: a,
3584
3588
  ...s,
3585
- headers: u([
3589
+ headers: d([
3586
3590
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3587
3591
  s?.headers
3588
3592
  ])
@@ -3602,9 +3606,9 @@ class zs extends w {
3602
3606
  */
3603
3607
  retrieve(e, t, s) {
3604
3608
  const { vault_id: n, betas: a } = t;
3605
- return this._client.get(g`/v1/vaults/${n}/credentials/${e}?beta=true`, {
3609
+ return this._client.get(m`/v1/vaults/${n}/credentials/${e}?beta=true`, {
3606
3610
  ...s,
3607
- headers: u([
3611
+ headers: d([
3608
3612
  { "anthropic-beta": [...a ?? [], "managed-agents-2026-04-01"].toString() },
3609
3613
  s?.headers
3610
3614
  ])
@@ -3624,10 +3628,10 @@ class zs extends w {
3624
3628
  */
3625
3629
  update(e, t, s) {
3626
3630
  const { vault_id: n, betas: a, ...i } = t;
3627
- return this._client.post(g`/v1/vaults/${n}/credentials/${e}?beta=true`, {
3631
+ return this._client.post(m`/v1/vaults/${n}/credentials/${e}?beta=true`, {
3628
3632
  body: i,
3629
3633
  ...s,
3630
- headers: u([
3634
+ headers: d([
3631
3635
  { "anthropic-beta": [...a ?? [], "managed-agents-2026-04-01"].toString() },
3632
3636
  s?.headers
3633
3637
  ])
@@ -3648,10 +3652,10 @@ class zs extends w {
3648
3652
  */
3649
3653
  list(e, t = {}, s) {
3650
3654
  const { betas: n, ...a } = t ?? {};
3651
- return this._client.getAPIList(g`/v1/vaults/${e}/credentials?beta=true`, T, {
3655
+ return this._client.getAPIList(m`/v1/vaults/${e}/credentials?beta=true`, M, {
3652
3656
  query: a,
3653
3657
  ...s,
3654
- headers: u([
3658
+ headers: d([
3655
3659
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3656
3660
  s?.headers
3657
3661
  ])
@@ -3671,9 +3675,9 @@ class zs extends w {
3671
3675
  */
3672
3676
  delete(e, t, s) {
3673
3677
  const { vault_id: n, betas: a } = t;
3674
- return this._client.delete(g`/v1/vaults/${n}/credentials/${e}?beta=true`, {
3678
+ return this._client.delete(m`/v1/vaults/${n}/credentials/${e}?beta=true`, {
3675
3679
  ...s,
3676
- headers: u([
3680
+ headers: d([
3677
3681
  { "anthropic-beta": [...a ?? [], "managed-agents-2026-04-01"].toString() },
3678
3682
  s?.headers
3679
3683
  ])
@@ -3693,16 +3697,16 @@ class zs extends w {
3693
3697
  */
3694
3698
  archive(e, t, s) {
3695
3699
  const { vault_id: n, betas: a } = t;
3696
- return this._client.post(g`/v1/vaults/${n}/credentials/${e}/archive?beta=true`, {
3700
+ return this._client.post(m`/v1/vaults/${n}/credentials/${e}/archive?beta=true`, {
3697
3701
  ...s,
3698
- headers: u([
3702
+ headers: d([
3699
3703
  { "anthropic-beta": [...a ?? [], "managed-agents-2026-04-01"].toString() },
3700
3704
  s?.headers
3701
3705
  ])
3702
3706
  });
3703
3707
  }
3704
3708
  }
3705
- class vt extends w {
3709
+ class Mt extends w {
3706
3710
  constructor() {
3707
3711
  super(...arguments), this.credentials = new zs(this._client);
3708
3712
  }
@@ -3722,7 +3726,7 @@ class vt extends w {
3722
3726
  return this._client.post("/v1/vaults?beta=true", {
3723
3727
  body: n,
3724
3728
  ...t,
3725
- headers: u([
3729
+ headers: d([
3726
3730
  { "anthropic-beta": [...s ?? [], "managed-agents-2026-04-01"].toString() },
3727
3731
  t?.headers
3728
3732
  ])
@@ -3741,9 +3745,9 @@ class vt extends w {
3741
3745
  */
3742
3746
  retrieve(e, t = {}, s) {
3743
3747
  const { betas: n } = t ?? {};
3744
- return this._client.get(g`/v1/vaults/${e}?beta=true`, {
3748
+ return this._client.get(m`/v1/vaults/${e}?beta=true`, {
3745
3749
  ...s,
3746
- headers: u([
3750
+ headers: d([
3747
3751
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3748
3752
  s?.headers
3749
3753
  ])
@@ -3762,10 +3766,10 @@ class vt extends w {
3762
3766
  */
3763
3767
  update(e, t, s) {
3764
3768
  const { betas: n, ...a } = t;
3765
- return this._client.post(g`/v1/vaults/${e}?beta=true`, {
3769
+ return this._client.post(m`/v1/vaults/${e}?beta=true`, {
3766
3770
  body: a,
3767
3771
  ...s,
3768
- headers: u([
3772
+ headers: d([
3769
3773
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3770
3774
  s?.headers
3771
3775
  ])
@@ -3784,10 +3788,10 @@ class vt extends w {
3784
3788
  */
3785
3789
  list(e = {}, t) {
3786
3790
  const { betas: s, ...n } = e ?? {};
3787
- return this._client.getAPIList("/v1/vaults?beta=true", T, {
3791
+ return this._client.getAPIList("/v1/vaults?beta=true", M, {
3788
3792
  query: n,
3789
3793
  ...t,
3790
- headers: u([
3794
+ headers: d([
3791
3795
  { "anthropic-beta": [...s ?? [], "managed-agents-2026-04-01"].toString() },
3792
3796
  t?.headers
3793
3797
  ])
@@ -3806,9 +3810,9 @@ class vt extends w {
3806
3810
  */
3807
3811
  delete(e, t = {}, s) {
3808
3812
  const { betas: n } = t ?? {};
3809
- return this._client.delete(g`/v1/vaults/${e}?beta=true`, {
3813
+ return this._client.delete(m`/v1/vaults/${e}?beta=true`, {
3810
3814
  ...s,
3811
- headers: u([
3815
+ headers: d([
3812
3816
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3813
3817
  s?.headers
3814
3818
  ])
@@ -3827,31 +3831,31 @@ class vt extends w {
3827
3831
  */
3828
3832
  archive(e, t = {}, s) {
3829
3833
  const { betas: n } = t ?? {};
3830
- return this._client.post(g`/v1/vaults/${e}/archive?beta=true`, {
3834
+ return this._client.post(m`/v1/vaults/${e}/archive?beta=true`, {
3831
3835
  ...s,
3832
- headers: u([
3836
+ headers: d([
3833
3837
  { "anthropic-beta": [...n ?? [], "managed-agents-2026-04-01"].toString() },
3834
3838
  s?.headers
3835
3839
  ])
3836
3840
  });
3837
3841
  }
3838
3842
  }
3839
- vt.Credentials = zs;
3840
- class O extends w {
3843
+ Mt.Credentials = zs;
3844
+ class C extends w {
3841
3845
  constructor() {
3842
- super(...arguments), this.models = new Bs(this._client), this.messages = new xe(this._client), this.agents = new St(this._client), this.environments = new As(this._client), this.sessions = new Ze(this._client), this.vaults = new vt(this._client), this.memoryStores = new Qe(this._client), this.files = new Os(this._client), this.skills = new xt(this._client), this.userProfiles = new Ls(this._client);
3846
+ super(...arguments), this.models = new Os(this._client), this.messages = new ve(this._client), this.agents = new Rt(this._client), this.environments = new As(this._client), this.sessions = new Ze(this._client), this.vaults = new Mt(this._client), this.memoryStores = new Qe(this._client), this.files = new Cs(this._client), this.skills = new Tt(this._client), this.userProfiles = new Bs(this._client);
3843
3847
  }
3844
3848
  }
3845
- O.Models = Bs;
3846
- O.Messages = xe;
3847
- O.Agents = St;
3848
- O.Environments = As;
3849
- O.Sessions = Ze;
3850
- O.Vaults = vt;
3851
- O.MemoryStores = Qe;
3852
- O.Files = Os;
3853
- O.Skills = xt;
3854
- O.UserProfiles = Ls;
3849
+ C.Models = Os;
3850
+ C.Messages = ve;
3851
+ C.Agents = Rt;
3852
+ C.Environments = As;
3853
+ C.Sessions = Ze;
3854
+ C.Vaults = Mt;
3855
+ C.MemoryStores = Qe;
3856
+ C.Files = Cs;
3857
+ C.Skills = Tt;
3858
+ C.UserProfiles = Bs;
3855
3859
  class Gs extends w {
3856
3860
  create(e, t) {
3857
3861
  const { betas: s, ...n } = e;
@@ -3859,7 +3863,7 @@ class Gs extends w {
3859
3863
  body: n,
3860
3864
  timeout: this._client._options.timeout ?? 6e5,
3861
3865
  ...t,
3862
- headers: u([
3866
+ headers: d([
3863
3867
  { ...s?.toString() != null ? { "anthropic-beta": s?.toString() } : void 0 },
3864
3868
  t?.headers
3865
3869
  ]),
@@ -3870,7 +3874,7 @@ class Gs extends w {
3870
3874
  function Qs(r) {
3871
3875
  return r?.output_config?.format;
3872
3876
  }
3873
- function ts(r, e, t) {
3877
+ function ss(r, e, t) {
3874
3878
  const s = Qs(e);
3875
3879
  return !e || !("parse" in (s ?? {})) ? {
3876
3880
  ...r,
@@ -3885,7 +3889,7 @@ function Ys(r, e, t) {
3885
3889
  let s = null;
3886
3890
  const n = r.content.map((a) => {
3887
3891
  if (a.type === "text") {
3888
- const i = tr(e, a.text);
3892
+ const i = cr(e, a.text);
3889
3893
  return s === null && (s = i), Object.defineProperty({ ...a }, "parsed_output", {
3890
3894
  value: i,
3891
3895
  enumerable: !1
@@ -3899,7 +3903,7 @@ function Ys(r, e, t) {
3899
3903
  parsed_output: s
3900
3904
  };
3901
3905
  }
3902
- function tr(r, e) {
3906
+ function cr(r, e) {
3903
3907
  const t = Qs(r);
3904
3908
  if (t?.type !== "json_schema")
3905
3909
  return null;
@@ -3909,20 +3913,20 @@ function tr(r, e) {
3909
3913
  throw new b(`Failed to parse structured output: ${s}`);
3910
3914
  }
3911
3915
  }
3912
- var I, H, Y, he, Be, de, fe, Le, pe, q, ge, Ce, je, K, Ne, qe, me, at, ss, it, ot, ct, lt, ns;
3913
- const rs = "__json_buf";
3914
- function as(r) {
3916
+ var I, D, Z, de, Be, fe, pe, Le, ge, W, me, Ne, je, V, qe, We, _e, it, ns, ot, ct, lt, ut, rs;
3917
+ const as = "__json_buf";
3918
+ function is(r) {
3915
3919
  return r.type === "tool_use" || r.type === "server_tool_use";
3916
3920
  }
3917
3921
  class Ke {
3918
3922
  constructor(e, t) {
3919
- I.add(this), this.messages = [], this.receivedMessages = [], H.set(this, void 0), Y.set(this, null), this.controller = new AbortController(), he.set(this, void 0), Be.set(this, () => {
3920
- }), de.set(this, () => {
3921
- }), fe.set(this, void 0), Le.set(this, () => {
3922
- }), pe.set(this, () => {
3923
- }), q.set(this, {}), ge.set(this, !1), Ce.set(this, !1), je.set(this, !1), K.set(this, !1), Ne.set(this, void 0), qe.set(this, void 0), me.set(this, void 0), it.set(this, (s) => {
3924
- if (d(this, Ce, !0), we(s) && (s = new B()), s instanceof B)
3925
- return d(this, je, !0), this._emit("abort", s);
3923
+ I.add(this), this.messages = [], this.receivedMessages = [], D.set(this, void 0), Z.set(this, null), this.controller = new AbortController(), de.set(this, void 0), Be.set(this, () => {
3924
+ }), fe.set(this, () => {
3925
+ }), pe.set(this, void 0), Le.set(this, () => {
3926
+ }), ge.set(this, () => {
3927
+ }), W.set(this, {}), me.set(this, !1), Ne.set(this, !1), je.set(this, !1), V.set(this, !1), qe.set(this, void 0), We.set(this, void 0), _e.set(this, void 0), ot.set(this, (s) => {
3928
+ if (p(this, Ne, !0), ke(s) && (s = new B()), s instanceof B)
3929
+ return p(this, je, !0), this._emit("abort", s);
3926
3930
  if (s instanceof b)
3927
3931
  return this._emit("error", s);
3928
3932
  if (s instanceof Error) {
@@ -3930,19 +3934,19 @@ class Ke {
3930
3934
  return n.cause = s, this._emit("error", n);
3931
3935
  }
3932
3936
  return this._emit("error", new b(String(s)));
3933
- }), d(this, he, new Promise((s, n) => {
3934
- d(this, Be, s, "f"), d(this, de, n, "f");
3935
- })), d(this, fe, new Promise((s, n) => {
3936
- d(this, Le, s, "f"), d(this, pe, n, "f");
3937
- })), o(this, he, "f").catch(() => {
3938
- }), o(this, fe, "f").catch(() => {
3939
- }), d(this, Y, e), d(this, me, t?.logger ?? console);
3937
+ }), p(this, de, new Promise((s, n) => {
3938
+ p(this, Be, s, "f"), p(this, fe, n, "f");
3939
+ })), p(this, pe, new Promise((s, n) => {
3940
+ p(this, Le, s, "f"), p(this, ge, n, "f");
3941
+ })), o(this, de, "f").catch(() => {
3942
+ }), o(this, pe, "f").catch(() => {
3943
+ }), p(this, Z, e), p(this, _e, t?.logger ?? console);
3940
3944
  }
3941
3945
  get response() {
3942
- return o(this, Ne, "f");
3946
+ return o(this, qe, "f");
3943
3947
  }
3944
3948
  get request_id() {
3945
- return o(this, qe, "f");
3949
+ return o(this, We, "f");
3946
3950
  }
3947
3951
  /**
3948
3952
  * Returns the `MessageStream` data, the raw `Response` instance and the ID of the request,
@@ -3955,8 +3959,8 @@ class Ke {
3955
3959
  * as no `Response` is available.
3956
3960
  */
3957
3961
  async withResponse() {
3958
- d(this, K, !0);
3959
- const e = await o(this, he, "f");
3962
+ p(this, V, !0);
3963
+ const e = await o(this, de, "f");
3960
3964
  if (!e)
3961
3965
  throw new Error("Could not resolve a `Response` object");
3962
3966
  return {
@@ -3980,12 +3984,12 @@ class Ke {
3980
3984
  const a = new Ke(t, { logger: n });
3981
3985
  for (const i of t.messages)
3982
3986
  a._addMessageParam(i);
3983
- return d(a, Y, { ...t, stream: !0 }), a._run(() => a._createMessage(e, { ...t, stream: !0 }, { ...s, headers: { ...s?.headers, "X-Stainless-Helper-Method": "stream" } })), a;
3987
+ return p(a, Z, { ...t, stream: !0 }), a._run(() => a._createMessage(e, { ...t, stream: !0 }, { ...s, headers: { ...s?.headers, "X-Stainless-Helper-Method": "stream" } })), a;
3984
3988
  }
3985
3989
  _run(e) {
3986
3990
  e().then(() => {
3987
3991
  this._emitFinal(), this._emit("end");
3988
- }, o(this, it, "f"));
3992
+ }, o(this, ot, "f"));
3989
3993
  }
3990
3994
  _addMessageParam(e) {
3991
3995
  this.messages.push(e);
@@ -3998,26 +4002,26 @@ class Ke {
3998
4002
  let a;
3999
4003
  n && (n.aborted && this.controller.abort(), a = this.controller.abort.bind(this.controller), n.addEventListener("abort", a));
4000
4004
  try {
4001
- o(this, I, "m", ot).call(this);
4002
- const { response: i, data: c } = await e.create({ ...t, stream: !0 }, { ...s, signal: this.controller.signal }).withResponse();
4005
+ o(this, I, "m", ct).call(this);
4006
+ const { response: i, data: l } = await e.create({ ...t, stream: !0 }, { ...s, signal: this.controller.signal }).withResponse();
4003
4007
  this._connected(i);
4004
- for await (const l of c)
4005
- o(this, I, "m", ct).call(this, l);
4006
- if (c.controller.signal?.aborted)
4008
+ for await (const c of l)
4009
+ o(this, I, "m", lt).call(this, c);
4010
+ if (l.controller.signal?.aborted)
4007
4011
  throw new B();
4008
- o(this, I, "m", lt).call(this);
4012
+ o(this, I, "m", ut).call(this);
4009
4013
  } finally {
4010
4014
  n && a && n.removeEventListener("abort", a);
4011
4015
  }
4012
4016
  }
4013
4017
  _connected(e) {
4014
- this.ended || (d(this, Ne, e), d(this, qe, e?.headers.get("request-id")), o(this, Be, "f").call(this, e), this._emit("connect"));
4018
+ this.ended || (p(this, qe, e), p(this, We, e?.headers.get("request-id")), o(this, Be, "f").call(this, e), this._emit("connect"));
4015
4019
  }
4016
4020
  get ended() {
4017
- return o(this, ge, "f");
4021
+ return o(this, me, "f");
4018
4022
  }
4019
4023
  get errored() {
4020
- return o(this, Ce, "f");
4024
+ return o(this, Ne, "f");
4021
4025
  }
4022
4026
  get aborted() {
4023
4027
  return o(this, je, "f");
@@ -4033,7 +4037,7 @@ class Ke {
4033
4037
  * @returns this MessageStream, so that calls can be chained
4034
4038
  */
4035
4039
  on(e, t) {
4036
- return (o(this, q, "f")[e] || (o(this, q, "f")[e] = [])).push({ listener: t }), this;
4040
+ return (o(this, W, "f")[e] || (o(this, W, "f")[e] = [])).push({ listener: t }), this;
4037
4041
  }
4038
4042
  /**
4039
4043
  * Removes the specified listener from the listener array for the event.
@@ -4043,7 +4047,7 @@ class Ke {
4043
4047
  * @returns this MessageStream, so that calls can be chained
4044
4048
  */
4045
4049
  off(e, t) {
4046
- const s = o(this, q, "f")[e];
4050
+ const s = o(this, W, "f")[e];
4047
4051
  if (!s)
4048
4052
  return this;
4049
4053
  const n = s.findIndex((a) => a.listener === t);
@@ -4055,7 +4059,7 @@ class Ke {
4055
4059
  * @returns this MessageStream, so that calls can be chained
4056
4060
  */
4057
4061
  once(e, t) {
4058
- return (o(this, q, "f")[e] || (o(this, q, "f")[e] = [])).push({ listener: t, once: !0 }), this;
4062
+ return (o(this, W, "f")[e] || (o(this, W, "f")[e] = [])).push({ listener: t, once: !0 }), this;
4059
4063
  }
4060
4064
  /**
4061
4065
  * This is similar to `.once()`, but returns a Promise that resolves the next time
@@ -4070,14 +4074,14 @@ class Ke {
4070
4074
  */
4071
4075
  emitted(e) {
4072
4076
  return new Promise((t, s) => {
4073
- d(this, K, !0), e !== "error" && this.once("error", s), this.once(e, t);
4077
+ p(this, V, !0), e !== "error" && this.once("error", s), this.once(e, t);
4074
4078
  });
4075
4079
  }
4076
4080
  async done() {
4077
- d(this, K, !0), await o(this, fe, "f");
4081
+ p(this, V, !0), await o(this, pe, "f");
4078
4082
  }
4079
4083
  get currentMessage() {
4080
- return o(this, H, "f");
4084
+ return o(this, D, "f");
4081
4085
  }
4082
4086
  /**
4083
4087
  * @returns a promise that resolves with the the final assistant Message response,
@@ -4085,7 +4089,7 @@ class Ke {
4085
4089
  * If structured outputs were used, this will be a ParsedMessage with a `parsed_output` field.
4086
4090
  */
4087
4091
  async finalMessage() {
4088
- return await this.done(), o(this, I, "m", at).call(this);
4092
+ return await this.done(), o(this, I, "m", it).call(this);
4089
4093
  }
4090
4094
  /**
4091
4095
  * @returns a promise that resolves with the the final assistant Message's text response, concatenated
@@ -4093,59 +4097,59 @@ class Ke {
4093
4097
  * Rejects if an error occurred or the stream ended prematurely without producing a Message.
4094
4098
  */
4095
4099
  async finalText() {
4096
- return await this.done(), o(this, I, "m", ss).call(this);
4100
+ return await this.done(), o(this, I, "m", ns).call(this);
4097
4101
  }
4098
4102
  _emit(e, ...t) {
4099
- if (o(this, ge, "f"))
4103
+ if (o(this, me, "f"))
4100
4104
  return;
4101
- e === "end" && (d(this, ge, !0), o(this, Le, "f").call(this));
4102
- const s = o(this, q, "f")[e];
4103
- if (s && (o(this, q, "f")[e] = s.filter((n) => !n.once), s.forEach(({ listener: n }) => n(...t))), e === "abort") {
4105
+ e === "end" && (p(this, me, !0), o(this, Le, "f").call(this));
4106
+ const s = o(this, W, "f")[e];
4107
+ if (s && (o(this, W, "f")[e] = s.filter((n) => !n.once), s.forEach(({ listener: n }) => n(...t))), e === "abort") {
4104
4108
  const n = t[0];
4105
- !o(this, K, "f") && !s?.length && Promise.reject(n), o(this, de, "f").call(this, n), o(this, pe, "f").call(this, n), this._emit("end");
4109
+ !o(this, V, "f") && !s?.length && Promise.reject(n), o(this, fe, "f").call(this, n), o(this, ge, "f").call(this, n), this._emit("end");
4106
4110
  return;
4107
4111
  }
4108
4112
  if (e === "error") {
4109
4113
  const n = t[0];
4110
- !o(this, K, "f") && !s?.length && Promise.reject(n), o(this, de, "f").call(this, n), o(this, pe, "f").call(this, n), this._emit("end");
4114
+ !o(this, V, "f") && !s?.length && Promise.reject(n), o(this, fe, "f").call(this, n), o(this, ge, "f").call(this, n), this._emit("end");
4111
4115
  }
4112
4116
  }
4113
4117
  _emitFinal() {
4114
- this.receivedMessages.at(-1) && this._emit("finalMessage", o(this, I, "m", at).call(this));
4118
+ this.receivedMessages.at(-1) && this._emit("finalMessage", o(this, I, "m", it).call(this));
4115
4119
  }
4116
4120
  async _fromReadableStream(e, t) {
4117
4121
  const s = t?.signal;
4118
4122
  let n;
4119
4123
  s && (s.aborted && this.controller.abort(), n = this.controller.abort.bind(this.controller), s.addEventListener("abort", n));
4120
4124
  try {
4121
- o(this, I, "m", ot).call(this), this._connected(null);
4122
- const a = C.fromReadableStream(e, this.controller);
4125
+ o(this, I, "m", ct).call(this), this._connected(null);
4126
+ const a = j.fromReadableStream(e, this.controller);
4123
4127
  for await (const i of a)
4124
- o(this, I, "m", ct).call(this, i);
4128
+ o(this, I, "m", lt).call(this, i);
4125
4129
  if (a.controller.signal?.aborted)
4126
4130
  throw new B();
4127
- o(this, I, "m", lt).call(this);
4131
+ o(this, I, "m", ut).call(this);
4128
4132
  } finally {
4129
4133
  s && n && s.removeEventListener("abort", n);
4130
4134
  }
4131
4135
  }
4132
- [(H = /* @__PURE__ */ new WeakMap(), Y = /* @__PURE__ */ new WeakMap(), he = /* @__PURE__ */ new WeakMap(), Be = /* @__PURE__ */ new WeakMap(), de = /* @__PURE__ */ new WeakMap(), fe = /* @__PURE__ */ new WeakMap(), Le = /* @__PURE__ */ new WeakMap(), pe = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), ge = /* @__PURE__ */ new WeakMap(), Ce = /* @__PURE__ */ new WeakMap(), je = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), Ne = /* @__PURE__ */ new WeakMap(), qe = /* @__PURE__ */ new WeakMap(), me = /* @__PURE__ */ new WeakMap(), it = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakSet(), at = function() {
4136
+ [(D = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap(), de = /* @__PURE__ */ new WeakMap(), Be = /* @__PURE__ */ new WeakMap(), fe = /* @__PURE__ */ new WeakMap(), pe = /* @__PURE__ */ new WeakMap(), Le = /* @__PURE__ */ new WeakMap(), ge = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), me = /* @__PURE__ */ new WeakMap(), Ne = /* @__PURE__ */ new WeakMap(), je = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), qe = /* @__PURE__ */ new WeakMap(), We = /* @__PURE__ */ new WeakMap(), _e = /* @__PURE__ */ new WeakMap(), ot = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakSet(), it = function() {
4133
4137
  if (this.receivedMessages.length === 0)
4134
4138
  throw new b("stream ended without producing a Message with role=assistant");
4135
4139
  return this.receivedMessages.at(-1);
4136
- }, ss = function() {
4140
+ }, ns = function() {
4137
4141
  if (this.receivedMessages.length === 0)
4138
4142
  throw new b("stream ended without producing a Message with role=assistant");
4139
4143
  const t = this.receivedMessages.at(-1).content.filter((s) => s.type === "text").map((s) => s.text);
4140
4144
  if (t.length === 0)
4141
4145
  throw new b("stream ended without producing a content block with type=text");
4142
4146
  return t.join(" ");
4143
- }, ot = function() {
4144
- this.ended || d(this, H, void 0);
4145
- }, ct = function(t) {
4147
+ }, ct = function() {
4148
+ this.ended || p(this, D, void 0);
4149
+ }, lt = function(t) {
4146
4150
  if (this.ended)
4147
4151
  return;
4148
- const s = o(this, I, "m", ns).call(this, t);
4152
+ const s = o(this, I, "m", rs).call(this, t);
4149
4153
  switch (this._emit("streamEvent", t, s), t.type) {
4150
4154
  case "content_block_delta": {
4151
4155
  const n = s.content.at(-1);
@@ -4159,7 +4163,7 @@ class Ke {
4159
4163
  break;
4160
4164
  }
4161
4165
  case "input_json_delta": {
4162
- as(n) && n.input && this._emit("inputJson", t.delta.partial_json, n.input);
4166
+ is(n) && n.input && this._emit("inputJson", t.delta.partial_json, n.input);
4163
4167
  break;
4164
4168
  }
4165
4169
  case "thinking_delta": {
@@ -4176,7 +4180,7 @@ class Ke {
4176
4180
  break;
4177
4181
  }
4178
4182
  case "message_stop": {
4179
- this._addMessageParam(s), this._addMessage(ts(s, o(this, Y, "f"), { logger: o(this, me, "f") }), !0);
4183
+ this._addMessageParam(s), this._addMessage(ss(s, o(this, Z, "f"), { logger: o(this, _e, "f") }), !0);
4180
4184
  break;
4181
4185
  }
4182
4186
  case "content_block_stop": {
@@ -4184,19 +4188,19 @@ class Ke {
4184
4188
  break;
4185
4189
  }
4186
4190
  case "message_start": {
4187
- d(this, H, s);
4191
+ p(this, D, s);
4188
4192
  break;
4189
4193
  }
4190
4194
  }
4191
- }, lt = function() {
4195
+ }, ut = function() {
4192
4196
  if (this.ended)
4193
4197
  throw new b("stream has ended, this shouldn't happen");
4194
- const t = o(this, H, "f");
4198
+ const t = o(this, D, "f");
4195
4199
  if (!t)
4196
4200
  throw new b("request ended without sending any chunks");
4197
- return d(this, H, void 0), ts(t, o(this, Y, "f"), { logger: o(this, me, "f") });
4198
- }, ns = function(t) {
4199
- let s = o(this, H, "f");
4201
+ return p(this, D, void 0), ss(t, o(this, Z, "f"), { logger: o(this, _e, "f") });
4202
+ }, rs = function(t) {
4203
+ let s = o(this, D, "f");
4200
4204
  if (t.type === "message_start") {
4201
4205
  if (s)
4202
4206
  throw new b(`Unexpected event order, got ${t.type} before receiving "message_stop"`);
@@ -4229,11 +4233,11 @@ class Ke {
4229
4233
  break;
4230
4234
  }
4231
4235
  case "input_json_delta": {
4232
- if (n && as(n)) {
4233
- let a = n[rs] || "";
4236
+ if (n && is(n)) {
4237
+ let a = n[as] || "";
4234
4238
  a += t.delta.partial_json;
4235
4239
  const i = { ...n };
4236
- Object.defineProperty(i, rs, {
4240
+ Object.defineProperty(i, as, {
4237
4241
  value: a,
4238
4242
  enumerable: !1,
4239
4243
  writable: !0
@@ -4290,7 +4294,7 @@ class Ke {
4290
4294
  };
4291
4295
  }
4292
4296
  toReadableStream() {
4293
- return new C(this[Symbol.asyncIterator].bind(this), this.controller).toReadableStream();
4297
+ return new j(this[Symbol.asyncIterator].bind(this), this.controller).toReadableStream();
4294
4298
  }
4295
4299
  }
4296
4300
  class Zs extends w {
@@ -4341,7 +4345,7 @@ class Zs extends w {
4341
4345
  * ```
4342
4346
  */
4343
4347
  retrieve(e, t) {
4344
- return this._client.get(g`/v1/messages/batches/${e}`, t);
4348
+ return this._client.get(m`/v1/messages/batches/${e}`, t);
4345
4349
  }
4346
4350
  /**
4347
4351
  * List all Message Batches within a Workspace. Most recently created batches are
@@ -4359,7 +4363,7 @@ class Zs extends w {
4359
4363
  * ```
4360
4364
  */
4361
4365
  list(e = {}, t) {
4362
- return this._client.getAPIList("/v1/messages/batches", Se, { query: e, ...t });
4366
+ return this._client.getAPIList("/v1/messages/batches", xe, { query: e, ...t });
4363
4367
  }
4364
4368
  /**
4365
4369
  * Delete a Message Batch.
@@ -4377,7 +4381,7 @@ class Zs extends w {
4377
4381
  * ```
4378
4382
  */
4379
4383
  delete(e, t) {
4380
- return this._client.delete(g`/v1/messages/batches/${e}`, t);
4384
+ return this._client.delete(m`/v1/messages/batches/${e}`, t);
4381
4385
  }
4382
4386
  /**
4383
4387
  * Batches may be canceled any time before processing ends. Once cancellation is
@@ -4401,7 +4405,7 @@ class Zs extends w {
4401
4405
  * ```
4402
4406
  */
4403
4407
  cancel(e, t) {
4404
- return this._client.post(g`/v1/messages/batches/${e}/cancel`, t);
4408
+ return this._client.post(m`/v1/messages/batches/${e}/cancel`, t);
4405
4409
  }
4406
4410
  /**
4407
4411
  * Streams the results of a Message Batch as a `.jsonl` file.
@@ -4425,19 +4429,19 @@ class Zs extends w {
4425
4429
  throw new b(`No batch \`results_url\`; Has it finished processing? ${s.processing_status} - ${s.id}`);
4426
4430
  return this._client.get(s.results_url, {
4427
4431
  ...t,
4428
- headers: u([{ Accept: "application/binary" }, t?.headers]),
4432
+ headers: d([{ Accept: "application/binary" }, t?.headers]),
4429
4433
  stream: !0,
4430
4434
  __binaryResponse: !0
4431
4435
  })._thenUnwrap((n, a) => Ye.fromResponse(a.response, a.controller));
4432
4436
  }
4433
4437
  }
4434
- class Mt extends w {
4438
+ class Et extends w {
4435
4439
  constructor() {
4436
4440
  super(...arguments), this.batches = new Zs(this._client);
4437
4441
  }
4438
4442
  create(e, t) {
4439
- e.model in is && console.warn(`The model '${e.model}' is deprecated and will reach end-of-life on ${is[e.model]}
4440
- Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`), sr.includes(e.model) && e.thinking && e.thinking.type === "enabled" && console.warn(`Using Claude with ${e.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
4443
+ e.model in os && console.warn(`The model '${e.model}' is deprecated and will reach end-of-life on ${os[e.model]}
4444
+ Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`), lr.includes(e.model) && e.thinking && e.thinking.type === "enabled" && console.warn(`Using Claude with ${e.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
4441
4445
  let s = this._client._options.timeout;
4442
4446
  if (!e.stream && s == null) {
4443
4447
  const a = qs[e.model] ?? void 0;
@@ -4448,7 +4452,7 @@ Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resour
4448
4452
  body: e,
4449
4453
  timeout: s ?? 6e5,
4450
4454
  ...t,
4451
- headers: u([n, t?.headers]),
4455
+ headers: d([n, t?.headers]),
4452
4456
  stream: e.stream ?? !1
4453
4457
  });
4454
4458
  }
@@ -4519,7 +4523,7 @@ Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resour
4519
4523
  return this._client.post("/v1/messages/count_tokens", { body: e, ...t });
4520
4524
  }
4521
4525
  }
4522
- const is = {
4526
+ const os = {
4523
4527
  "claude-1.3": "November 6th, 2024",
4524
4528
  "claude-1.3-100k": "November 6th, 2024",
4525
4529
  "claude-instant-1.1": "November 6th, 2024",
@@ -4537,8 +4541,8 @@ const is = {
4537
4541
  "claude-opus-4-20250514": "June 15th, 2026",
4538
4542
  "claude-sonnet-4-0": "June 15th, 2026",
4539
4543
  "claude-sonnet-4-20250514": "June 15th, 2026"
4540
- }, sr = ["claude-mythos-preview", "claude-opus-4-6"];
4541
- Mt.Batches = Zs;
4544
+ }, lr = ["claude-mythos-preview", "claude-opus-4-6"];
4545
+ Et.Batches = Zs;
4542
4546
  class en extends w {
4543
4547
  /**
4544
4548
  * Get a specific model.
@@ -4548,9 +4552,9 @@ class en extends w {
4548
4552
  */
4549
4553
  retrieve(e, t = {}, s) {
4550
4554
  const { betas: n } = t ?? {};
4551
- return this._client.get(g`/v1/models/${e}`, {
4555
+ return this._client.get(m`/v1/models/${e}`, {
4552
4556
  ...s,
4553
- headers: u([
4557
+ headers: d([
4554
4558
  { ...n?.toString() != null ? { "anthropic-beta": n?.toString() } : void 0 },
4555
4559
  s?.headers
4556
4560
  ])
@@ -4564,24 +4568,24 @@ class en extends w {
4564
4568
  */
4565
4569
  list(e = {}, t) {
4566
4570
  const { betas: s, ...n } = e ?? {};
4567
- return this._client.getAPIList("/v1/models", Se, {
4571
+ return this._client.getAPIList("/v1/models", xe, {
4568
4572
  query: n,
4569
4573
  ...t,
4570
- headers: u([
4574
+ headers: d([
4571
4575
  { ...s?.toString() != null ? { "anthropic-beta": s?.toString() } : void 0 },
4572
4576
  t?.headers
4573
4577
  ])
4574
4578
  });
4575
4579
  }
4576
4580
  }
4577
- const We = (r) => {
4581
+ const Ue = (r) => {
4578
4582
  if (typeof globalThis.process < "u")
4579
4583
  return globalThis.process.env?.[r]?.trim() || void 0;
4580
4584
  if (typeof globalThis.Deno < "u")
4581
4585
  return globalThis.Deno.env?.get?.(r)?.trim() || void 0;
4582
4586
  };
4583
- var bt, Rt, Je, tn;
4584
- const nr = "\\n\\nHuman:", rr = "\\n\\nAssistant:";
4587
+ var kt, Pt, Je, tn;
4588
+ const ur = "\\n\\nHuman:", hr = "\\n\\nAssistant:";
4585
4589
  class k {
4586
4590
  /**
4587
4591
  * API Client for interfacing with the Anthropic API.
@@ -4597,15 +4601,15 @@ class k {
4597
4601
  * @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
4598
4602
  * @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
4599
4603
  */
4600
- constructor({ baseURL: e = We("ANTHROPIC_BASE_URL"), apiKey: t = We("ANTHROPIC_API_KEY") ?? null, authToken: s = We("ANTHROPIC_AUTH_TOKEN") ?? null, ...n } = {}) {
4601
- bt.add(this), Je.set(this, void 0);
4604
+ constructor({ baseURL: e = Ue("ANTHROPIC_BASE_URL"), apiKey: t = Ue("ANTHROPIC_API_KEY") ?? null, authToken: s = Ue("ANTHROPIC_AUTH_TOKEN") ?? null, ...n } = {}) {
4605
+ kt.add(this), Je.set(this, void 0);
4602
4606
  const a = {
4603
4607
  apiKey: t,
4604
4608
  authToken: s,
4605
4609
  ...n,
4606
4610
  baseURL: e || "https://api.anthropic.com"
4607
4611
  };
4608
- if (!a.dangerouslyAllowBrowser && yn())
4612
+ if (!a.dangerouslyAllowBrowser && Tn())
4609
4613
  throw new b(`It looks like you're running in a browser-like environment.
4610
4614
 
4611
4615
  This is disabled by default, as it risks exposing your secret API credentials to attackers.
@@ -4614,9 +4618,9 @@ you can set the \`dangerouslyAllowBrowser\` option to \`true\`, e.g.,
4614
4618
 
4615
4619
  new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
4616
4620
  `);
4617
- this.baseURL = a.baseURL, this.timeout = a.timeout ?? Rt.DEFAULT_TIMEOUT, this.logger = a.logger ?? console;
4621
+ this.baseURL = a.baseURL, this.timeout = a.timeout ?? Pt.DEFAULT_TIMEOUT, this.logger = a.logger ?? console;
4618
4622
  const i = "warn";
4619
- this.logLevel = i, this.logLevel = Ft(a.logLevel, "ClientOptions.logLevel", this) ?? Ft(We("ANTHROPIC_LOG"), "process.env['ANTHROPIC_LOG']", this) ?? i, this.fetchOptions = a.fetchOptions, this.maxRetries = a.maxRetries ?? 2, this.fetch = a.fetch ?? vn(), d(this, Je, Rn), this._options = a, this.apiKey = typeof t == "string" ? t : null, this.authToken = s;
4623
+ this.logLevel = i, this.logLevel = Ht(a.logLevel, "ClientOptions.logLevel", this) ?? Ht(Ue("ANTHROPIC_LOG"), "process.env['ANTHROPIC_LOG']", this) ?? i, this.fetchOptions = a.fetchOptions, this.maxRetries = a.maxRetries ?? 2, this.fetch = a.fetch ?? $n(), p(this, Je, Cn), this._options = a, this.apiKey = typeof t == "string" ? t : null, this.authToken = s;
4620
4624
  }
4621
4625
  /**
4622
4626
  * Create a new client instance re-using the same options given to the current client with optional overriding.
@@ -4644,24 +4648,24 @@ new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
4644
4648
  throw new Error('Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted');
4645
4649
  }
4646
4650
  async authHeaders(e) {
4647
- return u([await this.apiKeyAuth(e), await this.bearerAuth(e)]);
4651
+ return d([await this.apiKeyAuth(e), await this.bearerAuth(e)]);
4648
4652
  }
4649
4653
  async apiKeyAuth(e) {
4650
4654
  if (this.apiKey != null)
4651
- return u([{ "X-Api-Key": this.apiKey }]);
4655
+ return d([{ "X-Api-Key": this.apiKey }]);
4652
4656
  }
4653
4657
  async bearerAuth(e) {
4654
4658
  if (this.authToken != null)
4655
- return u([{ Authorization: `Bearer ${this.authToken}` }]);
4659
+ return d([{ Authorization: `Bearer ${this.authToken}` }]);
4656
4660
  }
4657
4661
  /**
4658
4662
  * Basic re-implementation of `qs.stringify` for primitive types.
4659
4663
  */
4660
4664
  stringifyQuery(e) {
4661
- return Tn(e);
4665
+ return On(e);
4662
4666
  }
4663
4667
  getUserAgent() {
4664
- return `${this.constructor.name}/JS ${Z}`;
4668
+ return `${this.constructor.name}/JS ${ee}`;
4665
4669
  }
4666
4670
  defaultIdempotencyKey() {
4667
4671
  return `stainless-node-retry-${ls()}`;
@@ -4670,8 +4674,8 @@ new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
4670
4674
  return x.generate(e, t, s, n);
4671
4675
  }
4672
4676
  buildURL(e, t, s) {
4673
- const n = !o(this, bt, "m", tn).call(this) && s || this.baseURL, a = gn(e) ? new URL(e) : new URL(n + (n.endsWith("/") && e.startsWith("/") ? e.slice(1) : e)), i = this.defaultQuery(), c = Object.fromEntries(a.searchParams);
4674
- return (!Lt(i) || !Lt(c)) && (t = { ...c, ...i, ...t }), typeof t == "object" && t && !Array.isArray(t) && (a.search = this.stringifyQuery(t)), a.toString();
4677
+ const n = !o(this, kt, "m", tn).call(this) && s || this.baseURL, a = Sn(e) ? new URL(e) : new URL(n + (n.endsWith("/") && e.startsWith("/") ? e.slice(1) : e)), i = this.defaultQuery(), l = Object.fromEntries(a.searchParams);
4678
+ return (!Lt(i) || !Lt(l)) && (t = { ...l, ...i, ...t }), typeof t == "object" && t && !Array.isArray(t) && (a.search = this.stringifyQuery(t)), a.toString();
4675
4679
  }
4676
4680
  _calculateNonstreamingTimeout(e) {
4677
4681
  if (3600 * e / 128e3 > 600)
@@ -4715,93 +4719,93 @@ new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
4715
4719
  async makeRequest(e, t, s) {
4716
4720
  const n = await e, a = n.maxRetries ?? this.maxRetries;
4717
4721
  t == null && (t = a), await this.prepareOptions(n);
4718
- const { req: i, url: c, timeout: l } = await this.buildRequest(n, {
4722
+ const { req: i, url: l, timeout: c } = await this.buildRequest(n, {
4719
4723
  retryCount: a - t
4720
4724
  });
4721
- await this.prepareRequest(i, { url: c, options: n });
4722
- const h = "log_" + (Math.random() * (1 << 24) | 0).toString(16).padStart(6, "0"), _ = s === void 0 ? "" : `, retryOf: ${s}`, y = Date.now();
4723
- if (M(this).debug(`[${h}] sending request`, z({
4725
+ await this.prepareRequest(i, { url: l, options: n });
4726
+ const f = "log_" + (Math.random() * (1 << 24) | 0).toString(16).padStart(6, "0"), _ = s === void 0 ? "" : `, retryOf: ${s}`, g = Date.now();
4727
+ if (R(this).debug(`[${f}] sending request`, K({
4724
4728
  retryOfRequestLogID: s,
4725
4729
  method: n.method,
4726
- url: c,
4730
+ url: l,
4727
4731
  options: n,
4728
4732
  headers: i.headers
4729
4733
  })), n.signal?.aborted)
4730
4734
  throw new B();
4731
- const p = new AbortController(), f = await this.fetchWithTimeout(c, i, l, p).catch(dt), m = Date.now();
4732
- if (f instanceof globalThis.Error) {
4733
- const j = `retrying, ${t} attempts remaining`;
4735
+ const u = new AbortController(), h = await this.fetchWithTimeout(l, i, c, u).catch(gt), y = Date.now();
4736
+ if (h instanceof globalThis.Error) {
4737
+ const O = `retrying, ${t} attempts remaining`;
4734
4738
  if (n.signal?.aborted)
4735
4739
  throw new B();
4736
- const L = we(f) || /timed? ?out/i.test(String(f) + ("cause" in f ? String(f.cause) : ""));
4740
+ const L = ke(h) || /timed? ?out/i.test(String(h) + ("cause" in h ? String(h.cause) : ""));
4737
4741
  if (t)
4738
- return M(this).info(`[${h}] connection ${L ? "timed out" : "failed"} - ${j}`), M(this).debug(`[${h}] connection ${L ? "timed out" : "failed"} (${j})`, z({
4742
+ return R(this).info(`[${f}] connection ${L ? "timed out" : "failed"} - ${O}`), R(this).debug(`[${f}] connection ${L ? "timed out" : "failed"} (${O})`, K({
4739
4743
  retryOfRequestLogID: s,
4740
- url: c,
4741
- durationMs: m - y,
4742
- message: f.message
4743
- })), this.retryRequest(n, t, s ?? h);
4744
- throw M(this).info(`[${h}] connection ${L ? "timed out" : "failed"} - error; no more retries left`), M(this).debug(`[${h}] connection ${L ? "timed out" : "failed"} (error; no more retries left)`, z({
4744
+ url: l,
4745
+ durationMs: y - g,
4746
+ message: h.message
4747
+ })), this.retryRequest(n, t, s ?? f);
4748
+ throw R(this).info(`[${f}] connection ${L ? "timed out" : "failed"} - error; no more retries left`), R(this).debug(`[${f}] connection ${L ? "timed out" : "failed"} (error; no more retries left)`, K({
4745
4749
  retryOfRequestLogID: s,
4746
- url: c,
4747
- durationMs: m - y,
4748
- message: f.message
4749
- })), L ? new us() : new ze({ cause: f });
4750
+ url: l,
4751
+ durationMs: y - g,
4752
+ message: h.message
4753
+ })), L ? new us() : new ze({ cause: h });
4750
4754
  }
4751
- const v = [...f.headers.entries()].filter(([j]) => j === "request-id").map(([j, L]) => ", " + j + ": " + JSON.stringify(L)).join(""), et = `[${h}${_}${v}] ${i.method} ${c} ${f.ok ? "succeeded" : "failed"} with status ${f.status} in ${m - y}ms`;
4752
- if (!f.ok) {
4753
- const j = await this.shouldRetry(f);
4754
- if (t && j) {
4755
- const ve = `retrying, ${t} attempts remaining`;
4756
- return await Mn(f.body), M(this).info(`${et} - ${ve}`), M(this).debug(`[${h}] response error (${ve})`, z({
4755
+ const v = [...h.headers.entries()].filter(([O]) => O === "request-id").map(([O, L]) => ", " + O + ": " + JSON.stringify(L)).join(""), G = `[${f}${_}${v}] ${i.method} ${l} ${h.ok ? "succeeded" : "failed"} with status ${h.status} in ${y - g}ms`;
4756
+ if (!h.ok) {
4757
+ const O = await this.shouldRetry(h);
4758
+ if (t && O) {
4759
+ const Re = `retrying, ${t} attempts remaining`;
4760
+ return await In(h.body), R(this).info(`${G} - ${Re}`), R(this).debug(`[${f}] response error (${Re})`, K({
4757
4761
  retryOfRequestLogID: s,
4758
- url: f.url,
4759
- status: f.status,
4760
- headers: f.headers,
4761
- durationMs: m - y
4762
- })), this.retryRequest(n, t, s ?? h, f.headers);
4762
+ url: h.url,
4763
+ status: h.status,
4764
+ headers: h.headers,
4765
+ durationMs: y - g
4766
+ })), this.retryRequest(n, t, s ?? f, h.headers);
4763
4767
  }
4764
- const L = j ? "error; no more retries left" : "error; not retryable";
4765
- M(this).info(`${et} - ${L}`);
4766
- const Pt = await f.text().catch((ve) => dt(ve).message), At = ys(Pt), $t = At ? void 0 : Pt;
4767
- throw M(this).debug(`[${h}] response error (${L})`, z({
4768
+ const L = O ? "error; no more retries left" : "error; not retryable";
4769
+ R(this).info(`${G} - ${L}`);
4770
+ const At = await h.text().catch((Re) => gt(Re).message), $t = ys(At), It = $t ? void 0 : At;
4771
+ throw R(this).debug(`[${f}] response error (${L})`, K({
4768
4772
  retryOfRequestLogID: s,
4769
- url: f.url,
4770
- status: f.status,
4771
- headers: f.headers,
4772
- message: $t,
4773
- durationMs: Date.now() - y
4774
- })), this.makeStatusError(f.status, At, $t, f.headers);
4773
+ url: h.url,
4774
+ status: h.status,
4775
+ headers: h.headers,
4776
+ message: It,
4777
+ durationMs: Date.now() - g
4778
+ })), this.makeStatusError(h.status, $t, It, h.headers);
4775
4779
  }
4776
- return M(this).info(et), M(this).debug(`[${h}] response start`, z({
4780
+ return R(this).info(G), R(this).debug(`[${f}] response start`, K({
4777
4781
  retryOfRequestLogID: s,
4778
- url: f.url,
4779
- status: f.status,
4780
- headers: f.headers,
4781
- durationMs: m - y
4782
- })), { response: f, options: n, controller: p, requestLogID: h, retryOfRequestLogID: s, startTime: y };
4782
+ url: h.url,
4783
+ status: h.status,
4784
+ headers: h.headers,
4785
+ durationMs: y - g
4786
+ })), { response: h, options: n, controller: u, requestLogID: f, retryOfRequestLogID: s, startTime: g };
4783
4787
  }
4784
4788
  getAPIList(e, t, s) {
4785
4789
  return this.requestAPIList(t, s && "then" in s ? s.then((n) => ({ method: "get", path: e, ...n })) : { method: "get", path: e, ...s });
4786
4790
  }
4787
4791
  requestAPIList(e, t) {
4788
4792
  const s = this.makeRequest(t, null, void 0);
4789
- return new Cn(this, s, e);
4793
+ return new Hn(this, s, e);
4790
4794
  }
4791
4795
  async fetchWithTimeout(e, t, s, n) {
4792
- const { signal: a, method: i, ...c } = t || {}, l = this._makeAbort(n);
4793
- a && a.addEventListener("abort", l, { once: !0 });
4794
- const h = setTimeout(l, s), _ = globalThis.ReadableStream && c.body instanceof globalThis.ReadableStream || typeof c.body == "object" && c.body !== null && Symbol.asyncIterator in c.body, y = {
4796
+ const { signal: a, method: i, ...l } = t || {}, c = this._makeAbort(n);
4797
+ a && a.addEventListener("abort", c, { once: !0 });
4798
+ const f = setTimeout(c, s), _ = globalThis.ReadableStream && l.body instanceof globalThis.ReadableStream || typeof l.body == "object" && l.body !== null && Symbol.asyncIterator in l.body, g = {
4795
4799
  signal: n.signal,
4796
4800
  ..._ ? { duplex: "half" } : {},
4797
4801
  method: "GET",
4798
- ...c
4802
+ ...l
4799
4803
  };
4800
- i && (y.method = i.toUpperCase());
4804
+ i && (g.method = i.toUpperCase());
4801
4805
  try {
4802
- return await this.fetch.call(void 0, e, y);
4806
+ return await this.fetch.call(void 0, e, g);
4803
4807
  } finally {
4804
- clearTimeout(h);
4808
+ clearTimeout(f);
4805
4809
  }
4806
4810
  }
4807
4811
  async shouldRetry(e) {
@@ -4812,23 +4816,23 @@ new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
4812
4816
  let a;
4813
4817
  const i = n?.get("retry-after-ms");
4814
4818
  if (i) {
4815
- const l = parseFloat(i);
4816
- Number.isNaN(l) || (a = l);
4819
+ const c = parseFloat(i);
4820
+ Number.isNaN(c) || (a = c);
4817
4821
  }
4818
- const c = n?.get("retry-after");
4819
- if (c && !a) {
4820
- const l = parseFloat(c);
4821
- Number.isNaN(l) ? a = Date.parse(c) - Date.now() : a = l * 1e3;
4822
+ const l = n?.get("retry-after");
4823
+ if (l && !a) {
4824
+ const c = parseFloat(l);
4825
+ Number.isNaN(c) ? a = Date.parse(l) - Date.now() : a = c * 1e3;
4822
4826
  }
4823
4827
  if (a === void 0) {
4824
- const l = e.maxRetries ?? this.maxRetries;
4825
- a = this.calculateDefaultRetryTimeoutMillis(t, l);
4828
+ const c = e.maxRetries ?? this.maxRetries;
4829
+ a = this.calculateDefaultRetryTimeoutMillis(t, c);
4826
4830
  }
4827
- return await bn(a), this.makeRequest(e, t - 1, s);
4831
+ return await Rn(a), this.makeRequest(e, t - 1, s);
4828
4832
  }
4829
4833
  calculateDefaultRetryTimeoutMillis(e, t) {
4830
- const a = t - e, i = Math.min(0.5 * Math.pow(2, a), 8), c = 1 - Math.random() * 0.25;
4831
- return i * c * 1e3;
4834
+ const a = t - e, i = Math.min(0.5 * Math.pow(2, a), 8), l = 1 - Math.random() * 0.25;
4835
+ return i * l * 1e3;
4832
4836
  }
4833
4837
  calculateNonstreamingTimeout(e, t) {
4834
4838
  if (36e5 * e / 128e3 > 6e5 || t != null && e > t)
@@ -4836,30 +4840,30 @@ new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
4836
4840
  return 6e5;
4837
4841
  }
4838
4842
  async buildRequest(e, { retryCount: t = 0 } = {}) {
4839
- const s = { ...e }, { method: n, path: a, query: i, defaultBaseURL: c } = s, l = this.buildURL(a, i, c);
4840
- "timeout" in s && _n("timeout", s.timeout), s.timeout = s.timeout ?? this.timeout;
4841
- const { bodyHeaders: h, body: _ } = this.buildBody({ options: s }), y = await this.buildHeaders({ options: e, method: n, bodyHeaders: h, retryCount: t });
4843
+ const s = { ...e }, { method: n, path: a, query: i, defaultBaseURL: l } = s, c = this.buildURL(a, i, l);
4844
+ "timeout" in s && vn("timeout", s.timeout), s.timeout = s.timeout ?? this.timeout;
4845
+ const { bodyHeaders: f, body: _ } = this.buildBody({ options: s }), g = await this.buildHeaders({ options: e, method: n, bodyHeaders: f, retryCount: t });
4842
4846
  return { req: {
4843
4847
  method: n,
4844
- headers: y,
4848
+ headers: g,
4845
4849
  ...s.signal && { signal: s.signal },
4846
4850
  ...globalThis.ReadableStream && _ instanceof globalThis.ReadableStream && { duplex: "half" },
4847
4851
  ..._ && { body: _ },
4848
4852
  ...this.fetchOptions ?? {},
4849
4853
  ...s.fetchOptions ?? {}
4850
- }, url: l, timeout: s.timeout };
4854
+ }, url: c, timeout: s.timeout };
4851
4855
  }
4852
4856
  async buildHeaders({ options: e, method: t, bodyHeaders: s, retryCount: n }) {
4853
4857
  let a = {};
4854
4858
  this.idempotencyHeader && t !== "get" && (e.idempotencyKey || (e.idempotencyKey = this.defaultIdempotencyKey()), a[this.idempotencyHeader] = e.idempotencyKey);
4855
- const i = u([
4859
+ const i = d([
4856
4860
  a,
4857
4861
  {
4858
4862
  Accept: "application/json",
4859
4863
  "User-Agent": this.getUserAgent(),
4860
4864
  "X-Stainless-Retry-Count": String(n),
4861
4865
  ...e.timeout ? { "X-Stainless-Timeout": String(Math.trunc(e.timeout / 1e3)) } : {},
4862
- ...xn(),
4866
+ ...An(),
4863
4867
  ...this._options.dangerouslyAllowBrowser ? { "anthropic-dangerous-direct-browser-access": "true" } : void 0,
4864
4868
  "anthropic-version": "2023-06-01"
4865
4869
  },
@@ -4876,7 +4880,7 @@ new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
4876
4880
  buildBody({ options: { body: e, headers: t } }) {
4877
4881
  if (!e)
4878
4882
  return { bodyHeaders: void 0, body: void 0 };
4879
- const s = u([t]);
4883
+ const s = d([t]);
4880
4884
  return (
4881
4885
  // Pass raw type verbatim
4882
4886
  ArrayBuffer.isView(e) || e instanceof ArrayBuffer || e instanceof DataView || typeof e == "string" && // Preserve legacy string encoding behavior for now
@@ -4891,12 +4895,12 @@ new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
4891
4895
  );
4892
4896
  }
4893
4897
  }
4894
- Rt = k, Je = /* @__PURE__ */ new WeakMap(), bt = /* @__PURE__ */ new WeakSet(), tn = function() {
4898
+ Pt = k, Je = /* @__PURE__ */ new WeakMap(), kt = /* @__PURE__ */ new WeakSet(), tn = function() {
4895
4899
  return this.baseURL !== "https://api.anthropic.com";
4896
4900
  };
4897
- k.Anthropic = Rt;
4898
- k.HUMAN_PROMPT = nr;
4899
- k.AI_PROMPT = rr;
4901
+ k.Anthropic = Pt;
4902
+ k.HUMAN_PROMPT = ur;
4903
+ k.AI_PROMPT = hr;
4900
4904
  k.DEFAULT_TIMEOUT = 6e5;
4901
4905
  k.AnthropicError = b;
4902
4906
  k.APIError = x;
@@ -4911,30 +4915,30 @@ k.AuthenticationError = ds;
4911
4915
  k.InternalServerError = bs;
4912
4916
  k.PermissionDeniedError = fs;
4913
4917
  k.UnprocessableEntityError = ms;
4914
- k.toFile = Fn;
4915
- class J extends k {
4918
+ k.toFile = zn;
4919
+ class z extends k {
4916
4920
  constructor() {
4917
- super(...arguments), this.completions = new Gs(this), this.messages = new Mt(this), this.models = new en(this), this.beta = new O(this);
4921
+ super(...arguments), this.completions = new Gs(this), this.messages = new Et(this), this.models = new en(this), this.beta = new C(this);
4918
4922
  }
4919
4923
  }
4920
- J.Completions = Gs;
4921
- J.Messages = Mt;
4922
- J.Models = en;
4923
- J.Beta = O;
4924
- function ar(r) {
4925
- return r || (typeof process < "u" && process.env.PI_CACHE_RETENTION === "long" ? "long" : "short");
4924
+ z.Completions = Gs;
4925
+ z.Messages = Et;
4926
+ z.Models = en;
4927
+ z.Beta = C;
4928
+ function sn(r, e) {
4929
+ return r || (hn("PI_CACHE_RETENTION", e) === "long" ? "long" : "short");
4926
4930
  }
4927
- function ir(r, e) {
4928
- const t = ar(e);
4929
- if (t === "none")
4930
- return { retention: t };
4931
- const s = t === "long" && Tt(r).supportsLongCacheRetention ? "1h" : void 0;
4931
+ function dr(r, e, t) {
4932
+ const s = sn(e, t);
4933
+ if (s === "none")
4934
+ return { retention: s };
4935
+ const n = s === "long" && tt(r).supportsLongCacheRetention ? "1h" : void 0;
4932
4936
  return {
4933
- retention: t,
4934
- cacheControl: { type: "ephemeral", ...s && { ttl: s } }
4937
+ retention: s,
4938
+ cacheControl: { type: "ephemeral", ...n && { ttl: n } }
4935
4939
  };
4936
4940
  }
4937
- const or = "2.1.75", cr = [
4941
+ const fr = "2.1.75", pr = [
4938
4942
  "Read",
4939
4943
  "Write",
4940
4944
  "Edit",
@@ -4952,7 +4956,7 @@ const or = "2.1.75", cr = [
4952
4956
  "TodoWrite",
4953
4957
  "WebFetch",
4954
4958
  "WebSearch"
4955
- ], lr = new Map(cr.map((r) => [r.toLowerCase(), r])), sn = (r) => lr.get(r.toLowerCase()) ?? r, ur = (r, e) => {
4959
+ ], gr = new Map(pr.map((r) => [r.toLowerCase(), r])), et = (r) => gr.get(r.toLowerCase()) ?? r, mr = (r, e) => {
4956
4960
  if (e && e.length > 0) {
4957
4961
  const t = r.toLowerCase(), s = e.find((n) => n.name.toLowerCase() === t);
4958
4962
  if (s)
@@ -4960,13 +4964,13 @@ const or = "2.1.75", cr = [
4960
4964
  }
4961
4965
  return r;
4962
4966
  };
4963
- function os(r) {
4967
+ function _r(r) {
4964
4968
  if (!r.some((n) => n.type === "image"))
4965
- return W(r.map((n) => n.text).join(`
4969
+ return N(r.map((n) => n.text).join(`
4966
4970
  `));
4967
4971
  const t = r.map((n) => n.type === "text" ? {
4968
4972
  type: "text",
4969
- text: W(n.text)
4973
+ text: N(n.text)
4970
4974
  } : {
4971
4975
  type: "image",
4972
4976
  source: {
@@ -4980,20 +4984,57 @@ function os(r) {
4980
4984
  text: "(see attached image)"
4981
4985
  }), t;
4982
4986
  }
4983
- const hr = "fine-grained-tool-streaming-2025-05-14", dr = "interleaved-thinking-2025-05-14";
4984
- function Tt(r) {
4987
+ const br = "fine-grained-tool-streaming-2025-05-14", yr = "interleaved-thinking-2025-05-14";
4988
+ function tt(r) {
4985
4989
  return {
4986
4990
  supportsEagerToolInputStreaming: r.compat?.supportsEagerToolInputStreaming ?? !0,
4987
- supportsLongCacheRetention: r.compat?.supportsLongCacheRetention ?? !0
4991
+ supportsLongCacheRetention: r.compat?.supportsLongCacheRetention ?? !0,
4992
+ sendSessionAffinityHeaders: r.compat?.sendSessionAffinityHeaders ?? !1,
4993
+ supportsCacheControlOnTools: r.compat?.supportsCacheControlOnTools ?? !0,
4994
+ supportsTemperature: r.compat?.supportsTemperature ?? !0,
4995
+ allowEmptySignature: r.compat?.allowEmptySignature ?? !1,
4996
+ supportsStrictTools: r.compat?.supportsStrictTools ?? !1,
4997
+ supportsToolReferences: r.compat?.supportsToolReferences ?? wr(r)
4988
4998
  };
4989
4999
  }
4990
- function Ue(...r) {
5000
+ function wr(r) {
5001
+ if (r.provider !== "anthropic" || r.id.includes("haiku"))
5002
+ return !1;
5003
+ const e = r.id.match(/^claude-(?:opus|sonnet|fable)-(\d+)(?:-(\d+))?(?:-|$)/);
5004
+ if (!e)
5005
+ return !1;
5006
+ const t = Number(e[1]), s = e[2] && e[2].length < 8 ? Number(e[2]) : 0;
5007
+ return t > 4 || t === 4 && s >= 5;
5008
+ }
5009
+ function kr(...r) {
4991
5010
  const e = {};
4992
5011
  for (const t of r)
4993
5012
  t && Object.assign(e, t);
4994
5013
  return e;
4995
5014
  }
4996
- const fr = /* @__PURE__ */ new Set([
5015
+ function ht(r, ...e) {
5016
+ const t = kr(...e);
5017
+ if (r.provider === "kimi-coding") {
5018
+ for (const s of Object.keys(t))
5019
+ s.toLowerCase() === "user-agent" && delete t[s];
5020
+ t["User-Agent"] = un();
5021
+ }
5022
+ return t;
5023
+ }
5024
+ function dt(r, e) {
5025
+ if (!r)
5026
+ return !1;
5027
+ const t = e.toLowerCase();
5028
+ for (const [s, n] of Object.entries(r))
5029
+ if (s.toLowerCase() === t && n !== null && n.trim().length > 0)
5030
+ return !0;
5031
+ return !1;
5032
+ }
5033
+ function nn(r, e, t) {
5034
+ if (!e && !(dt(t, "authorization") || dt(t, "x-api-key") || dt(t, "cf-aig-authorization")))
5035
+ throw new Error(`No API key for provider: ${r}`);
5036
+ }
5037
+ const Sr = /* @__PURE__ */ new Set([
4997
5038
  "message_start",
4998
5039
  "message_delta",
4999
5040
  "message_stop",
@@ -5001,7 +5042,7 @@ const fr = /* @__PURE__ */ new Set([
5001
5042
  "content_block_delta",
5002
5043
  "content_block_stop"
5003
5044
  ]);
5004
- function nn(r) {
5045
+ function rn(r) {
5005
5046
  if (!r.event && r.data.length === 0)
5006
5047
  return null;
5007
5048
  const e = {
@@ -5012,22 +5053,22 @@ function nn(r) {
5012
5053
  };
5013
5054
  return r.event = null, r.data = [], r.raw = [], e;
5014
5055
  }
5015
- function ut(r, e) {
5056
+ function ft(r, e) {
5016
5057
  if (r === "")
5017
- return nn(e);
5058
+ return rn(e);
5018
5059
  if (e.raw.push(r), r.startsWith(":"))
5019
5060
  return null;
5020
5061
  const t = r.indexOf(":"), s = t === -1 ? r : r.slice(0, t);
5021
5062
  let n = t === -1 ? "" : r.slice(t + 1);
5022
5063
  return n.startsWith(" ") && (n = n.slice(1)), s === "event" ? e.event = n : s === "data" && e.data.push(n), null;
5023
5064
  }
5024
- function pr(r) {
5065
+ function xr(r) {
5025
5066
  const e = r.indexOf("\r"), t = r.indexOf(`
5026
5067
  `);
5027
5068
  return e === -1 ? t : t === -1 ? e : Math.min(e, t);
5028
5069
  }
5029
5070
  function Fe(r) {
5030
- const e = pr(r);
5071
+ const e = xr(r);
5031
5072
  if (e === -1)
5032
5073
  return null;
5033
5074
  let t = e + 1;
@@ -5037,51 +5078,51 @@ function Fe(r) {
5037
5078
  rest: r.slice(t)
5038
5079
  };
5039
5080
  }
5040
- async function* gr(r, e) {
5081
+ async function* vr(r, e) {
5041
5082
  const t = r.getReader(), s = new TextDecoder(), n = { event: null, data: [], raw: [] };
5042
5083
  let a = "";
5043
5084
  try {
5044
5085
  for (; ; ) {
5045
5086
  if (e?.aborted)
5046
5087
  throw new Error("Request was aborted");
5047
- const { value: l, done: h } = await t.read();
5048
- if (h)
5088
+ const { value: c, done: f } = await t.read();
5089
+ if (f)
5049
5090
  break;
5050
- a += s.decode(l, { stream: !0 });
5091
+ a += s.decode(c, { stream: !0 });
5051
5092
  let _ = Fe(a);
5052
5093
  for (; _; ) {
5053
5094
  a = _.rest;
5054
- const y = ut(_.line, n);
5055
- y && (yield y), _ = Fe(a);
5095
+ const g = ft(_.line, n);
5096
+ g && (yield g), _ = Fe(a);
5056
5097
  }
5057
5098
  }
5058
5099
  a += s.decode();
5059
5100
  let i = Fe(a);
5060
5101
  for (; i; ) {
5061
5102
  a = i.rest;
5062
- const l = ut(i.line, n);
5063
- l && (yield l), i = Fe(a);
5103
+ const c = ft(i.line, n);
5104
+ c && (yield c), i = Fe(a);
5064
5105
  }
5065
5106
  if (a.length > 0) {
5066
- const l = ut(a, n);
5067
- l && (yield l);
5107
+ const c = ft(a, n);
5108
+ c && (yield c);
5068
5109
  }
5069
- const c = nn(n);
5070
- c && (yield c);
5110
+ const l = rn(n);
5111
+ l && (yield l);
5071
5112
  } finally {
5072
5113
  t.releaseLock();
5073
5114
  }
5074
5115
  }
5075
- async function* mr(r, e) {
5116
+ async function* Rr(r, e) {
5076
5117
  if (!r.body)
5077
5118
  throw new Error("Attempted to iterate over an Anthropic response with no body");
5078
5119
  let t = !1, s = !1;
5079
- for await (const n of gr(r.body, e)) {
5120
+ for await (const n of vr(r.body, e)) {
5080
5121
  if (n.event === "error")
5081
5122
  throw new Error(n.data);
5082
- if (fr.has(n.event ?? ""))
5123
+ if (Sr.has(n.event ?? ""))
5083
5124
  try {
5084
- const a = on(n.data);
5125
+ const a = ln(n.data);
5085
5126
  a.type === "message_start" ? t = !0 : a.type === "message_stop" && (s = !0), yield a;
5086
5127
  } catch (a) {
5087
5128
  const i = a instanceof Error ? a.message : String(a);
@@ -5091,8 +5132,8 @@ async function* mr(r, e) {
5091
5132
  if (t && !s)
5092
5133
  throw new Error("Anthropic stream ended before message_stop");
5093
5134
  }
5094
- const ht = (r, e, t) => {
5095
- const s = new rn();
5135
+ const pt = (r, e, t) => {
5136
+ const s = new an();
5096
5137
  return (async () => {
5097
5138
  const n = {
5098
5139
  role: "assistant",
@@ -5108,7 +5149,7 @@ const ht = (r, e, t) => {
5108
5149
  totalTokens: 0,
5109
5150
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
5110
5151
  },
5111
- stopReason: "stop",
5152
+ stopReason: "pending",
5112
5153
  timestamp: Date.now()
5113
5154
  };
5114
5155
  try {
@@ -5116,119 +5157,138 @@ const ht = (r, e, t) => {
5116
5157
  if (t?.client)
5117
5158
  a = t.client, i = !1;
5118
5159
  else {
5119
- const p = t?.apiKey ?? cs(r.provider) ?? "";
5120
- let f;
5160
+ const u = t?.apiKey;
5161
+ nn(r.provider, u, t?.headers);
5162
+ let h;
5121
5163
  if (r.provider === "github-copilot") {
5122
- const v = hn(e.messages);
5123
- f = dn({
5164
+ const O = yn(e.messages);
5165
+ h = wn({
5124
5166
  messages: e.messages,
5125
- hasImages: v
5167
+ hasImages: O
5126
5168
  });
5127
5169
  }
5128
- const m = yr(r, p, t?.interleavedThinking ?? !0, xr(r, e), t?.headers, f);
5129
- a = m.client, i = m.isOAuthToken;
5170
+ const v = sn(t?.cacheRetention, t?.env) === "none" ? void 0 : t?.sessionId, G = Er(r, u, t?.interleavedThinking ?? !0, Cr(r, e), t?.headers, t?.fetch, h, v);
5171
+ a = G.client, i = G.isOAuthToken;
5130
5172
  }
5131
- let c = wr(r, e, i, t);
5132
- const l = await t?.onPayload?.(c, r);
5133
- l !== void 0 && (c = l);
5134
- const h = {
5173
+ let l = Pr(r, e, i, t);
5174
+ const c = await t?.onPayload?.(l, r);
5175
+ c !== void 0 && (l = c);
5176
+ const f = {
5135
5177
  ...t?.signal ? { signal: t.signal } : {},
5136
5178
  ...t?.timeoutMs !== void 0 ? { timeout: t.timeoutMs } : {},
5137
- ...t?.maxRetries !== void 0 ? { maxRetries: t.maxRetries } : {}
5138
- }, _ = await a.messages.create({ ...c, stream: !0 }, h).asResponse();
5139
- await t?.onResponse?.({ status: _.status, headers: an(_.headers) }, r), s.push({ type: "start", partial: n });
5140
- const y = n.content;
5141
- for await (const p of mr(_, t?.signal))
5142
- if (p.type === "message_start")
5143
- n.responseId = p.message.id, n.usage.input = p.message.usage.input_tokens || 0, n.usage.output = p.message.usage.output_tokens || 0, n.usage.cacheRead = p.message.usage.cache_read_input_tokens || 0, n.usage.cacheWrite = p.message.usage.cache_creation_input_tokens || 0, n.usage.totalTokens = n.usage.input + n.usage.output + n.usage.cacheRead + n.usage.cacheWrite, It(r, n.usage);
5144
- else if (p.type === "content_block_start") {
5145
- if (p.content_block.type === "text") {
5146
- const f = {
5179
+ maxRetries: 0
5180
+ }, _ = await dn(() => a.messages.create({ ...l, stream: !0 }, f).asResponse(), {
5181
+ maxRetries: t?.maxRetries,
5182
+ maxRetryDelayMs: t?.maxRetryDelayMs,
5183
+ signal: t?.signal
5184
+ });
5185
+ await t?.onResponse?.({ status: _.status, headers: cn(_.headers) }, r), s.push({ type: "start", partial: n });
5186
+ const g = n.content;
5187
+ for await (const u of Rr(_, t?.signal))
5188
+ if (u.type === "message_start")
5189
+ n.responseId = u.message.id, n.usage.input = u.message.usage.input_tokens || 0, n.usage.output = u.message.usage.output_tokens || 0, n.usage.cacheRead = u.message.usage.cache_read_input_tokens || 0, n.usage.cacheWrite = u.message.usage.cache_creation_input_tokens || 0, n.usage.cacheWrite1h = u.message.usage.cache_creation?.ephemeral_1h_input_tokens || 0, n.usage.totalTokens = n.usage.input + n.usage.output + n.usage.cacheRead + n.usage.cacheWrite, Ct(r, n.usage);
5190
+ else if (u.type === "content_block_start") {
5191
+ if (u.content_block.type === "text") {
5192
+ const h = {
5147
5193
  type: "text",
5148
- text: "",
5149
- index: p.index
5194
+ text: u.content_block.text ?? "",
5195
+ index: u.index
5150
5196
  };
5151
- n.content.push(f), s.push({ type: "text_start", contentIndex: n.content.length - 1, partial: n });
5152
- } else if (p.content_block.type === "thinking") {
5153
- const f = {
5197
+ n.content.push(h), s.push({ type: "text_start", contentIndex: n.content.length - 1, partial: n });
5198
+ } else if (u.content_block.type === "thinking") {
5199
+ const h = {
5154
5200
  type: "thinking",
5155
- thinking: "",
5156
- thinkingSignature: "",
5157
- index: p.index
5201
+ thinking: u.content_block.thinking ?? "",
5202
+ thinkingSignature: u.content_block.signature ?? "",
5203
+ index: u.index
5158
5204
  };
5159
- n.content.push(f), s.push({ type: "thinking_start", contentIndex: n.content.length - 1, partial: n });
5160
- } else if (p.content_block.type === "redacted_thinking") {
5161
- const f = {
5205
+ n.content.push(h), s.push({ type: "thinking_start", contentIndex: n.content.length - 1, partial: n });
5206
+ } else if (u.content_block.type === "redacted_thinking") {
5207
+ const h = {
5162
5208
  type: "thinking",
5163
5209
  thinking: "[Reasoning redacted]",
5164
- thinkingSignature: p.content_block.data,
5210
+ thinkingSignature: u.content_block.data,
5165
5211
  redacted: !0,
5166
- index: p.index
5212
+ index: u.index
5167
5213
  };
5168
- n.content.push(f), s.push({ type: "thinking_start", contentIndex: n.content.length - 1, partial: n });
5169
- } else if (p.content_block.type === "tool_use") {
5170
- const f = {
5214
+ n.content.push(h), s.push({ type: "thinking_start", contentIndex: n.content.length - 1, partial: n });
5215
+ } else if (u.content_block.type === "tool_use") {
5216
+ const h = {
5171
5217
  type: "toolCall",
5172
- id: p.content_block.id,
5173
- name: i ? ur(p.content_block.name, e.tools) : p.content_block.name,
5174
- arguments: p.content_block.input ?? {},
5218
+ id: u.content_block.id,
5219
+ name: i ? mr(u.content_block.name, e.tools) : u.content_block.name,
5220
+ arguments: u.content_block.input ?? {},
5175
5221
  partialJson: "",
5176
- index: p.index
5222
+ index: u.index
5177
5223
  };
5178
- n.content.push(f), s.push({ type: "toolcall_start", contentIndex: n.content.length - 1, partial: n });
5224
+ n.content.push(h), s.push({ type: "toolcall_start", contentIndex: n.content.length - 1, partial: n });
5179
5225
  }
5180
- } else if (p.type === "content_block_delta") {
5181
- if (p.delta.type === "text_delta") {
5182
- const f = y.findIndex((v) => v.index === p.index), m = y[f];
5183
- m && m.type === "text" && (m.text += p.delta.text, s.push({
5226
+ } else if (u.type === "content_block_delta") {
5227
+ if (u.delta.type === "text_delta") {
5228
+ const h = g.findIndex((v) => v.index === u.index), y = g[h];
5229
+ y && y.type === "text" && (y.text += u.delta.text, s.push({
5184
5230
  type: "text_delta",
5185
- contentIndex: f,
5186
- delta: p.delta.text,
5231
+ contentIndex: h,
5232
+ delta: u.delta.text,
5187
5233
  partial: n
5188
5234
  }));
5189
- } else if (p.delta.type === "thinking_delta") {
5190
- const f = y.findIndex((v) => v.index === p.index), m = y[f];
5191
- m && m.type === "thinking" && (m.thinking += p.delta.thinking, s.push({
5235
+ } else if (u.delta.type === "thinking_delta") {
5236
+ const h = g.findIndex((v) => v.index === u.index), y = g[h];
5237
+ y && y.type === "thinking" && (y.thinking += u.delta.thinking, s.push({
5192
5238
  type: "thinking_delta",
5193
- contentIndex: f,
5194
- delta: p.delta.thinking,
5239
+ contentIndex: h,
5240
+ delta: u.delta.thinking,
5195
5241
  partial: n
5196
5242
  }));
5197
- } else if (p.delta.type === "input_json_delta") {
5198
- const f = y.findIndex((v) => v.index === p.index), m = y[f];
5199
- m && m.type === "toolCall" && (m.partialJson += p.delta.partial_json, m.arguments = Ot(m.partialJson), s.push({
5243
+ } else if (u.delta.type === "input_json_delta") {
5244
+ const h = g.findIndex((v) => v.index === u.index), y = g[h];
5245
+ y && y.type === "toolCall" && (y.partialJson += u.delta.partial_json, y.arguments = Ot(y.partialJson), s.push({
5200
5246
  type: "toolcall_delta",
5201
- contentIndex: f,
5202
- delta: p.delta.partial_json,
5247
+ contentIndex: h,
5248
+ delta: u.delta.partial_json,
5203
5249
  partial: n
5204
5250
  }));
5205
- } else if (p.delta.type === "signature_delta") {
5206
- const f = y.findIndex((v) => v.index === p.index), m = y[f];
5207
- m && m.type === "thinking" && (m.thinkingSignature = m.thinkingSignature || "", m.thinkingSignature += p.delta.signature);
5251
+ } else if (u.delta.type === "signature_delta") {
5252
+ const h = g.findIndex((v) => v.index === u.index), y = g[h];
5253
+ y && y.type === "thinking" && (y.thinkingSignature = y.thinkingSignature || "", y.thinkingSignature += u.delta.signature);
5208
5254
  }
5209
- } else if (p.type === "content_block_stop") {
5210
- const f = y.findIndex((v) => v.index === p.index), m = y[f];
5211
- m && (delete m.index, m.type === "text" ? s.push({
5255
+ } else if (u.type === "content_block_stop") {
5256
+ const h = g.findIndex((v) => v.index === u.index), y = g[h];
5257
+ y && (delete y.index, y.type === "text" ? s.push({
5212
5258
  type: "text_end",
5213
- contentIndex: f,
5214
- content: m.text,
5259
+ contentIndex: h,
5260
+ content: y.text,
5215
5261
  partial: n
5216
- }) : m.type === "thinking" ? s.push({
5262
+ }) : y.type === "thinking" ? s.push({
5217
5263
  type: "thinking_end",
5218
- contentIndex: f,
5219
- content: m.thinking,
5264
+ contentIndex: h,
5265
+ content: y.thinking,
5220
5266
  partial: n
5221
- }) : m.type === "toolCall" && (m.arguments = Ot(m.partialJson), delete m.partialJson, s.push({
5267
+ }) : y.type === "toolCall" && (y.arguments = Ot(y.partialJson), delete y.partialJson, s.push({
5222
5268
  type: "toolcall_end",
5223
- contentIndex: f,
5224
- toolCall: m,
5269
+ contentIndex: h,
5270
+ toolCall: y,
5225
5271
  partial: n
5226
5272
  })));
5227
- } else p.type === "message_delta" && (p.delta.stop_reason && (n.stopReason = Mr(p.delta.stop_reason)), p.usage.input_tokens != null && (n.usage.input = p.usage.input_tokens), p.usage.output_tokens != null && (n.usage.output = p.usage.output_tokens), p.usage.cache_read_input_tokens != null && (n.usage.cacheRead = p.usage.cache_read_input_tokens), p.usage.cache_creation_input_tokens != null && (n.usage.cacheWrite = p.usage.cache_creation_input_tokens), n.usage.totalTokens = n.usage.input + n.usage.output + n.usage.cacheRead + n.usage.cacheWrite, It(r, n.usage));
5273
+ } else if (u.type === "message_delta") {
5274
+ if (u.delta.stop_reason) {
5275
+ n.rawStopReason = u.delta.stop_reason;
5276
+ const h = Or(u.delta.stop_reason, u.delta.stop_details);
5277
+ n.stopReason = h.stopReason, h.errorMessage && (n.errorMessage = h.errorMessage);
5278
+ }
5279
+ if (u.usage) {
5280
+ u.usage.input_tokens != null && (n.usage.input = u.usage.input_tokens), u.usage.output_tokens != null && (n.usage.output = u.usage.output_tokens), u.usage.cache_read_input_tokens != null && (n.usage.cacheRead = u.usage.cache_read_input_tokens), u.usage.cache_creation_input_tokens != null && (n.usage.cacheWrite = u.usage.cache_creation_input_tokens);
5281
+ const h = u.usage.output_tokens_details?.thinking_tokens;
5282
+ h != null && (n.usage.reasoning = h);
5283
+ }
5284
+ n.usage.totalTokens = n.usage.input + n.usage.output + n.usage.cacheRead + n.usage.cacheWrite, Ct(r, n.usage);
5285
+ }
5228
5286
  if (t?.signal?.aborted)
5229
5287
  throw new Error("Request was aborted");
5288
+ if (n.stopReason === "pending")
5289
+ throw new Error("Anthropic stream ended without a stop reason");
5230
5290
  if (n.stopReason === "aborted" || n.stopReason === "error")
5231
- throw new Error("An unknown error occurred");
5291
+ throw new Error(n.errorMessage || "An unknown error occurred");
5232
5292
  s.push({ type: "done", reason: n.stopReason, message: n }), s.end();
5233
5293
  } catch (a) {
5234
5294
  for (const i of n.content)
@@ -5237,10 +5297,7 @@ const ht = (r, e, t) => {
5237
5297
  }
5238
5298
  })(), s;
5239
5299
  };
5240
- function Et(r) {
5241
- return r.includes("opus-4-6") || r.includes("opus-4.6") || r.includes("opus-4-7") || r.includes("opus-4.7") || r.includes("sonnet-4-6") || r.includes("sonnet-4.6");
5242
- }
5243
- function _r(r, e) {
5300
+ function Tr(r, e) {
5244
5301
  const t = e ? r.thinkingLevelMap?.[e] : void 0;
5245
5302
  if (typeof t == "string")
5246
5303
  return t;
@@ -5256,271 +5313,293 @@ function _r(r, e) {
5256
5313
  return "high";
5257
5314
  }
5258
5315
  }
5259
- const Cr = (r, e, t) => {
5260
- const s = t?.apiKey || cs(r.provider);
5261
- if (!s)
5262
- throw new Error(`No API key for provider: ${r.provider}`);
5263
- const n = cn(r, t, s);
5316
+ const zr = (r, e, t) => {
5317
+ nn(r.provider, t?.apiKey, t?.headers);
5318
+ const s = fn(r, e, t, t?.apiKey);
5264
5319
  if (!t?.reasoning)
5265
- return ht(r, e, { ...n, thinkingEnabled: !1 });
5266
- if (Et(r.id)) {
5267
- const i = _r(r, t.reasoning);
5268
- return ht(r, e, {
5269
- ...n,
5320
+ return pt(r, e, { ...s, thinkingEnabled: !1 });
5321
+ if (r.compat?.forceAdaptiveThinking === !0) {
5322
+ const i = Tr(r, t.reasoning);
5323
+ return pt(r, e, {
5324
+ ...s,
5270
5325
  thinkingEnabled: !0,
5271
5326
  effort: i
5272
5327
  });
5273
5328
  }
5274
- const a = ln(n.maxTokens || 0, r.maxTokens, t.reasoning, t.thinkingBudgets);
5275
- return ht(r, e, {
5276
- ...n,
5277
- maxTokens: a.maxTokens,
5329
+ const n = pn(s.maxTokens, r.maxTokens, t.reasoning, t.thinkingBudgets), a = gn(r, e, n.maxTokens);
5330
+ return pt(r, e, {
5331
+ ...s,
5332
+ maxTokens: a,
5278
5333
  thinkingEnabled: !0,
5279
- thinkingBudgetTokens: a.thinkingBudget
5334
+ thinkingBudgetTokens: Math.min(n.thinkingBudget, Math.max(0, a - 1024))
5280
5335
  });
5281
5336
  };
5282
- function br(r) {
5337
+ function Mr(r) {
5283
5338
  return r.includes("sk-ant-oat");
5284
5339
  }
5285
- function yr(r, e, t, s, n, a) {
5286
- const i = t && !Et(r.id), c = [];
5287
- return s && c.push(hr), i && c.push(dr), r.provider === "cloudflare-ai-gateway" ? { client: new J({
5288
- apiKey: null,
5340
+ function Er(r, e, t, s, n, a, i, l) {
5341
+ const c = t && r.compat?.forceAdaptiveThinking !== !0, f = [];
5342
+ if (s && f.push(br), c && f.push(yr), r.provider === "github-copilot")
5343
+ return { client: new z({
5344
+ apiKey: null,
5345
+ authToken: e ?? null,
5346
+ baseURL: r.baseUrl,
5347
+ dangerouslyAllowBrowser: !0,
5348
+ fetch: a,
5349
+ defaultHeaders: ht(r, {
5350
+ accept: "application/json",
5351
+ "anthropic-dangerous-direct-browser-access": "true",
5352
+ ...f.length > 0 ? { "anthropic-beta": f.join(",") } : {}
5353
+ }, r.headers, i, n)
5354
+ }), isOAuthToken: !1 };
5355
+ if (e && Mr(e))
5356
+ return { client: new z({
5357
+ apiKey: null,
5358
+ authToken: e,
5359
+ baseURL: r.baseUrl,
5360
+ dangerouslyAllowBrowser: !0,
5361
+ fetch: a,
5362
+ defaultHeaders: ht(r, {
5363
+ accept: "application/json",
5364
+ "anthropic-dangerous-direct-browser-access": "true",
5365
+ "anthropic-beta": ["claude-code-20250219", "oauth-2025-04-20", ...f].join(","),
5366
+ "user-agent": `claude-cli/${fr}`,
5367
+ "x-app": "cli"
5368
+ }, r.headers, n)
5369
+ }), isOAuthToken: !0 };
5370
+ const _ = l && tt(r).sendSessionAffinityHeaders ? { "x-session-affinity": l } : {}, g = ht(r, {
5371
+ accept: "application/json",
5372
+ "anthropic-dangerous-direct-browser-access": "true",
5373
+ ...f.length > 0 ? { "anthropic-beta": f.join(",") } : {}
5374
+ }, _, r.headers, n);
5375
+ return { client: new z({
5376
+ apiKey: e ?? null,
5289
5377
  authToken: null,
5290
- baseURL: fn(r),
5291
- dangerouslyAllowBrowser: !0,
5292
- defaultHeaders: Ue({
5293
- accept: "application/json",
5294
- "anthropic-dangerous-direct-browser-access": "true",
5295
- "cf-aig-authorization": `Bearer ${e}`,
5296
- "x-api-key": null,
5297
- Authorization: null,
5298
- ...c.length > 0 ? { "anthropic-beta": c.join(",") } : {}
5299
- }, r.headers, n)
5300
- }), isOAuthToken: !1 } : r.provider === "github-copilot" ? { client: new J({
5301
- apiKey: null,
5302
- authToken: e,
5303
- baseURL: r.baseUrl,
5304
- dangerouslyAllowBrowser: !0,
5305
- defaultHeaders: Ue({
5306
- accept: "application/json",
5307
- "anthropic-dangerous-direct-browser-access": "true",
5308
- ...c.length > 0 ? { "anthropic-beta": c.join(",") } : {}
5309
- }, r.headers, a, n)
5310
- }), isOAuthToken: !1 } : br(e) ? { client: new J({
5311
- apiKey: null,
5312
- authToken: e,
5313
5378
  baseURL: r.baseUrl,
5314
5379
  dangerouslyAllowBrowser: !0,
5315
- defaultHeaders: Ue({
5316
- accept: "application/json",
5317
- "anthropic-dangerous-direct-browser-access": "true",
5318
- "anthropic-beta": ["claude-code-20250219", "oauth-2025-04-20", ...c].join(","),
5319
- "user-agent": `claude-cli/${or}`,
5320
- "x-app": "cli"
5321
- }, r.headers, n)
5322
- }), isOAuthToken: !0 } : { client: new J({
5323
- apiKey: e,
5324
- baseURL: r.baseUrl,
5325
- dangerouslyAllowBrowser: !0,
5326
- defaultHeaders: Ue({
5327
- accept: "application/json",
5328
- "anthropic-dangerous-direct-browser-access": "true",
5329
- ...c.length > 0 ? { "anthropic-beta": c.join(",") } : {}
5330
- }, r.headers, n)
5380
+ fetch: a,
5381
+ defaultHeaders: g
5331
5382
  }), isOAuthToken: !1 };
5332
5383
  }
5333
- function wr(r, e, t, s) {
5334
- const { cacheControl: n } = ir(r, s?.cacheRetention), a = {
5384
+ function Pr(r, e, t, s) {
5385
+ const { cacheControl: n } = dr(r, s?.cacheRetention, s?.env), a = tt(r), i = mn(e.messages, r, Ar), l = t ? et : (h) => h, c = on({ ...e, messages: i }, a.supportsToolReferences, l);
5386
+ let f = c.immediate, _ = [...c.deferred.values()];
5387
+ f.length === 0 && _.length > 0 && (f = _, _ = []);
5388
+ const g = new Set(_.map((h) => l(h.name))), u = {
5335
5389
  model: r.id,
5336
- messages: Sr(e.messages, r, t, n),
5337
- max_tokens: s?.maxTokens || r.maxTokens / 3 | 0,
5390
+ messages: Ir(i, t, n, a.allowEmptySignature, g, l),
5391
+ max_tokens: s?.maxTokens ?? r.maxTokens,
5338
5392
  stream: !0
5339
5393
  };
5340
- if (t ? (a.system = [
5394
+ if (t ? (u.system = [
5341
5395
  {
5342
5396
  type: "text",
5343
5397
  text: "You are Claude Code, Anthropic's official CLI for Claude.",
5344
5398
  ...n ? { cache_control: n } : {}
5345
5399
  }
5346
- ], e.systemPrompt && a.system.push({
5400
+ ], e.systemPrompt && u.system.push({
5347
5401
  type: "text",
5348
- text: W(e.systemPrompt),
5402
+ text: N(e.systemPrompt),
5349
5403
  ...n ? { cache_control: n } : {}
5350
- })) : e.systemPrompt && (a.system = [
5404
+ })) : e.systemPrompt && (u.system = [
5351
5405
  {
5352
5406
  type: "text",
5353
- text: W(e.systemPrompt),
5407
+ text: N(e.systemPrompt),
5354
5408
  ...n ? { cache_control: n } : {}
5355
5409
  }
5356
- ]), s?.temperature !== void 0 && !s?.thinkingEnabled && (a.temperature = s.temperature), e.tools && e.tools.length > 0 && (a.tools = vr(e.tools, t, Tt(r).supportsEagerToolInputStreaming, n)), r.reasoning)
5410
+ ]), s?.temperature !== void 0 && !s?.thinkingEnabled && a.supportsTemperature && (u.temperature = s.temperature), (f.length > 0 || _.length > 0) && (u.tools = [
5411
+ ...cs(f, t, a.supportsEagerToolInputStreaming, a.supportsStrictTools, a.supportsCacheControlOnTools ? n : void 0),
5412
+ ...cs(_, t, a.supportsEagerToolInputStreaming, a.supportsStrictTools, void 0, !0)
5413
+ ]), r.reasoning)
5357
5414
  if (s?.thinkingEnabled) {
5358
- const i = s.thinkingDisplay ?? "summarized";
5359
- Et(r.id) ? (a.thinking = { type: "adaptive", display: i }, s.effort && (a.output_config = s.effort === "xhigh" ? { effort: s.effort } : { effort: s.effort })) : a.thinking = {
5415
+ const h = s.thinkingDisplay ?? "summarized";
5416
+ r.compat?.forceAdaptiveThinking === !0 ? (u.thinking = { type: "adaptive", display: h }, s.effort && (u.output_config = s.effort === "xhigh" ? { effort: s.effort } : { effort: s.effort })) : u.thinking = {
5360
5417
  type: "enabled",
5361
5418
  budget_tokens: s.thinkingBudgetTokens || 1024,
5362
- display: i
5419
+ display: h
5363
5420
  };
5364
- } else s?.thinkingEnabled === !1 && (a.thinking = { type: "disabled" });
5421
+ } else s?.thinkingEnabled === !1 && r.thinkingLevelMap?.off !== null && (u.thinking = { type: "disabled" });
5365
5422
  if (s?.metadata) {
5366
- const i = s.metadata.user_id;
5367
- typeof i == "string" && (a.metadata = { user_id: i });
5423
+ const h = s.metadata.user_id;
5424
+ typeof h == "string" && (u.metadata = { user_id: h });
5368
5425
  }
5369
- return s?.toolChoice && (typeof s.toolChoice == "string" ? a.tool_choice = { type: s.toolChoice } : a.tool_choice = s.toolChoice), a;
5426
+ return s?.toolChoice && (typeof s.toolChoice == "string" ? u.tool_choice = { type: s.toolChoice } : u.tool_choice = s.toolChoice), u;
5370
5427
  }
5371
- function kr(r) {
5428
+ function Ar(r) {
5372
5429
  return r.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
5373
5430
  }
5374
- function Sr(r, e, t, s) {
5375
- const n = [], a = un(r, e, kr);
5376
- for (let i = 0; i < a.length; i++) {
5377
- const c = a[i];
5378
- if (c.role === "user")
5379
- if (typeof c.content == "string")
5380
- c.content.trim().length > 0 && n.push({
5431
+ function $r(r, e, t, s, n) {
5432
+ const a = [];
5433
+ for (const l of r.addedToolNames ?? []) {
5434
+ const c = n(l);
5435
+ !t.has(c) || s.has(c) || (s.add(c), a.push({
5436
+ type: "tool_reference",
5437
+ tool_name: e ? et(l) : l
5438
+ }));
5439
+ }
5440
+ const i = _r(r.content);
5441
+ return {
5442
+ toolResult: {
5443
+ type: "tool_result",
5444
+ tool_use_id: r.toolCallId,
5445
+ content: a.length > 0 ? a : i,
5446
+ is_error: r.isError
5447
+ },
5448
+ siblingContent: a.length === 0 ? [] : typeof i == "string" ? [{ type: "text", text: i }] : i
5449
+ };
5450
+ }
5451
+ function Ir(r, e, t, s = !1, n = /* @__PURE__ */ new Set(), a = (i) => i) {
5452
+ const i = [], l = /* @__PURE__ */ new Set();
5453
+ for (let c = 0; c < r.length; c++) {
5454
+ const f = r[c];
5455
+ if (f.role === "user")
5456
+ if (typeof f.content == "string")
5457
+ f.content.trim().length > 0 && i.push({
5381
5458
  role: "user",
5382
- content: W(c.content)
5459
+ content: N(f.content)
5383
5460
  });
5384
5461
  else {
5385
- const h = c.content.map((_) => _.type === "text" ? {
5462
+ const g = f.content.map((u) => u.type === "text" ? {
5386
5463
  type: "text",
5387
- text: W(_.text)
5464
+ text: N(u.text)
5388
5465
  } : {
5389
5466
  type: "image",
5390
5467
  source: {
5391
5468
  type: "base64",
5392
- media_type: _.mimeType,
5393
- data: _.data
5469
+ media_type: u.mimeType,
5470
+ data: u.data
5394
5471
  }
5395
- }).filter((_) => _.type === "text" ? _.text.trim().length > 0 : !0);
5396
- if (h.length === 0)
5472
+ }).filter((u) => u.type === "text" ? u.text.trim().length > 0 : !0);
5473
+ if (g.length === 0)
5397
5474
  continue;
5398
- n.push({
5475
+ i.push({
5399
5476
  role: "user",
5400
- content: h
5477
+ content: g
5401
5478
  });
5402
5479
  }
5403
- else if (c.role === "assistant") {
5404
- const l = [];
5405
- for (const h of c.content)
5406
- if (h.type === "text") {
5407
- if (h.text.trim().length === 0)
5480
+ else if (f.role === "assistant") {
5481
+ const _ = [];
5482
+ for (const g of f.content)
5483
+ if (g.type === "text") {
5484
+ if (g.text.trim().length === 0)
5408
5485
  continue;
5409
- l.push({
5486
+ _.push({
5410
5487
  type: "text",
5411
- text: W(h.text)
5488
+ text: N(g.text)
5412
5489
  });
5413
- } else if (h.type === "thinking") {
5414
- if (h.redacted) {
5415
- l.push({
5490
+ } else if (g.type === "thinking") {
5491
+ if (g.redacted) {
5492
+ _.push({
5416
5493
  type: "redacted_thinking",
5417
- data: h.thinkingSignature
5494
+ data: g.thinkingSignature
5418
5495
  });
5419
5496
  continue;
5420
5497
  }
5421
- if (h.thinking.trim().length === 0)
5498
+ const u = g.thinkingSignature, h = !!u && u.trim().length > 0;
5499
+ if (g.thinking.trim().length === 0 && !h)
5422
5500
  continue;
5423
- !h.thinkingSignature || h.thinkingSignature.trim().length === 0 ? l.push({
5424
- type: "text",
5425
- text: W(h.thinking)
5426
- }) : l.push({
5501
+ h ? _.push({
5502
+ type: "thinking",
5503
+ thinking: N(g.thinking),
5504
+ signature: u
5505
+ }) : _.push(s ? {
5427
5506
  type: "thinking",
5428
- thinking: W(h.thinking),
5429
- signature: h.thinkingSignature
5507
+ thinking: N(g.thinking),
5508
+ signature: ""
5509
+ } : {
5510
+ type: "text",
5511
+ text: N(g.thinking)
5430
5512
  });
5431
- } else h.type === "toolCall" && l.push({
5513
+ } else g.type === "toolCall" && _.push({
5432
5514
  type: "tool_use",
5433
- id: h.id,
5434
- name: t ? sn(h.name) : h.name,
5435
- input: h.arguments ?? {}
5515
+ id: g.id,
5516
+ name: e ? et(g.name) : g.name,
5517
+ input: g.arguments ?? {}
5436
5518
  });
5437
- if (l.length === 0)
5519
+ if (_.length === 0)
5438
5520
  continue;
5439
- n.push({
5521
+ i.push({
5440
5522
  role: "assistant",
5441
- content: l
5442
- });
5443
- } else if (c.role === "toolResult") {
5444
- const l = [];
5445
- l.push({
5446
- type: "tool_result",
5447
- tool_use_id: c.toolCallId,
5448
- content: os(c.content),
5449
- is_error: c.isError
5523
+ content: _
5450
5524
  });
5451
- let h = i + 1;
5452
- for (; h < a.length && a[h].role === "toolResult"; ) {
5453
- const _ = a[h];
5454
- l.push({
5455
- type: "tool_result",
5456
- tool_use_id: _.toolCallId,
5457
- content: os(_.content),
5458
- is_error: _.isError
5459
- }), h++;
5525
+ } else if (f.role === "toolResult") {
5526
+ const _ = [], g = [];
5527
+ let u = c;
5528
+ for (; u < r.length && r[u].role === "toolResult"; ) {
5529
+ const h = $r(r[u], e, n, l, a);
5530
+ _.push(h.toolResult), g.push(...h.siblingContent), u++;
5460
5531
  }
5461
- i = h - 1, n.push({
5532
+ c = u - 1, i.push({
5462
5533
  role: "user",
5463
- content: l
5534
+ content: [..._, ...g]
5464
5535
  });
5465
5536
  }
5466
5537
  }
5467
- if (s && n.length > 0) {
5468
- const i = n[n.length - 1];
5469
- if (i.role === "user")
5470
- if (Array.isArray(i.content)) {
5471
- const c = i.content[i.content.length - 1];
5472
- c && (c.type === "text" || c.type === "image" || c.type === "tool_result") && (c.cache_control = s);
5473
- } else typeof i.content == "string" && (i.content = [
5538
+ if (t && i.length > 0) {
5539
+ const c = i[i.length - 1];
5540
+ if (c.role === "user")
5541
+ if (Array.isArray(c.content)) {
5542
+ const f = c.content[c.content.length - 1];
5543
+ f && (f.type === "text" || f.type === "image" || f.type === "tool_result") && (f.cache_control = t);
5544
+ } else typeof c.content == "string" && (c.content = [
5474
5545
  {
5475
5546
  type: "text",
5476
- text: i.content,
5477
- cache_control: s
5547
+ text: c.content,
5548
+ cache_control: t
5478
5549
  }
5479
5550
  ]);
5480
5551
  }
5481
- return n;
5552
+ return i;
5482
5553
  }
5483
- function xr(r, e) {
5484
- return !!e.tools?.length && !Tt(r).supportsEagerToolInputStreaming;
5554
+ function Cr(r, e) {
5555
+ return !!e.tools?.length && !tt(r).supportsEagerToolInputStreaming;
5485
5556
  }
5486
- function vr(r, e, t, s) {
5487
- return r ? r.map((n, a) => {
5488
- const i = n.parameters;
5557
+ function cs(r, e, t, s, n, a = !1) {
5558
+ return r ? r.map((i, l) => {
5559
+ const c = _n(i, s), f = bn(i, c), _ = f, g = {
5560
+ type: "object",
5561
+ properties: _.properties ?? {},
5562
+ required: _.required ?? []
5563
+ }, u = c === !0 ? {
5564
+ ...f,
5565
+ ...g
5566
+ } : g;
5489
5567
  return {
5490
- name: e ? sn(n.name) : n.name,
5491
- description: n.description,
5568
+ name: e ? et(i.name) : i.name,
5569
+ description: i.description,
5492
5570
  ...t ? { eager_input_streaming: !0 } : {},
5493
- input_schema: {
5494
- type: "object",
5495
- properties: i.properties ?? {},
5496
- required: i.required ?? []
5497
- },
5498
- ...s && a === r.length - 1 ? { cache_control: s } : {}
5571
+ ...c === !0 ? { strict: !0 } : {},
5572
+ input_schema: u,
5573
+ ...a ? { defer_loading: !0 } : {},
5574
+ ...n && l === r.length - 1 ? { cache_control: n } : {}
5499
5575
  };
5500
5576
  }) : [];
5501
5577
  }
5502
- function Mr(r) {
5578
+ function Or(r, e) {
5503
5579
  switch (r) {
5504
5580
  case "end_turn":
5505
- return "stop";
5581
+ return { stopReason: "stop" };
5506
5582
  case "max_tokens":
5507
- return "length";
5583
+ return { stopReason: "length" };
5508
5584
  case "tool_use":
5509
- return "toolUse";
5585
+ return { stopReason: "toolUse" };
5510
5586
  case "refusal":
5511
- return "error";
5587
+ return {
5588
+ stopReason: "error",
5589
+ errorMessage: e?.explanation || "The model refused to complete the request"
5590
+ };
5512
5591
  case "pause_turn":
5513
- return "stop";
5592
+ return { stopReason: "stop" };
5514
5593
  case "stop_sequence":
5515
- return "stop";
5594
+ return { stopReason: "stop" };
5516
5595
  // We don't supply stop sequences, so this should never happen
5517
5596
  case "sensitive":
5518
- return "error";
5597
+ return { stopReason: "error", errorMessage: "Provider stopped with: sensitive" };
5519
5598
  default:
5520
5599
  throw new Error(`Unhandled stop reason: ${r}`);
5521
5600
  }
5522
5601
  }
5523
5602
  export {
5524
- ht as streamAnthropic,
5525
- Cr as streamSimpleAnthropic
5603
+ pt as stream,
5604
+ zr as streamSimple
5526
5605
  };