@gram-ai/elements 1.15.0 → 1.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -1,45 +1,113 @@
1
- import { gc as mt, fe as se, gd as Rn, ge as En, fr as d, gf as ye, fs as S, fM as s, ev as v, ez as X, fZ as D, f_ as ne, fd as E, fB as Be, gg as gt, gh as ft, gi as De, ew as _t, fq as k, eu as vt, dR as Cn, aQ as xn, eS as Je, gj as In, gk as Pn, gl as On, ga as An } from "./index-cubKOZsm.js";
2
- var Un = (e) => Object.fromEntries(
3
- Object.entries(e).map(([t, n]) => [
4
- t,
5
- {
6
- ...n.description ? { description: n.description } : void 0,
7
- inputSchema: mt(n.parameters)
8
- }
9
- ])
1
+ import { go as Rn, gp as En, fo as le, fC as d, gq as be, fD as E, fX as s, eG as y, eK as X, g8 as j, g9 as oe, fn as x, fM as ze, gr as He, eH as gt, fB as k, eF as K, d$ as Cn, aV as xn, f1 as Ge, gs as In, gt as On, gu as Pn, gm as An } from "./index-CVZt-xeH.js";
2
+ const $n = (e) => Object.fromEntries(Object.entries(e).map(([t, n]) => [
3
+ t,
4
+ {
5
+ ...n.description ? { description: n.description } : void 0,
6
+ inputSchema: Rn(n.parameters)
7
+ }
8
+ ]));
9
+ var Un = ({
10
+ prefix: e,
11
+ size: t = 16,
12
+ alphabet: n = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
13
+ separator: r = "-"
14
+ } = {}) => {
15
+ const o = () => {
16
+ const a = n.length, i = new Array(t);
17
+ for (let c = 0; c < t; c++)
18
+ i[c] = n[Math.random() * a | 0];
19
+ return i.join("");
20
+ };
21
+ if (e == null)
22
+ return o;
23
+ if (n.includes(r))
24
+ throw new En({
25
+ argument: "separator",
26
+ message: `The separator "${r}" must not be part of the alphabet "${n}".`
27
+ });
28
+ return () => `${e}${r}${o()}`;
29
+ };
30
+ Un();
31
+ function _t(e = globalThis) {
32
+ var t, n, r;
33
+ return e.window ? "runtime/browser" : (t = e.navigator) != null && t.userAgent ? `runtime/${e.navigator.userAgent.toLowerCase()}` : (r = (n = e.process) == null ? void 0 : n.versions) != null && r.node ? `runtime/node.js/${e.process.version.substring(0)}` : e.EdgeRuntime ? "runtime/vercel-edge" : "runtime/unknown";
34
+ }
35
+ function Mn(e) {
36
+ if (e == null)
37
+ return {};
38
+ const t = {};
39
+ if (e instanceof Headers)
40
+ e.forEach((n, r) => {
41
+ t[r.toLowerCase()] = n;
42
+ });
43
+ else {
44
+ Array.isArray(e) || (e = Object.entries(e));
45
+ for (const [n, r] of e)
46
+ r != null && (t[n.toLowerCase()] = r);
47
+ }
48
+ return t;
49
+ }
50
+ function vt(e, ...t) {
51
+ const n = new Headers(Mn(e)), r = n.get("user-agent") || "";
52
+ return n.set(
53
+ "user-agent",
54
+ [r, ...t].filter(Boolean).join(" ")
55
+ ), Object.fromEntries(n.entries());
56
+ }
57
+ var Nn = Symbol.for("vercel.ai.validator");
58
+ function jn(e) {
59
+ return { ...e, type: "dynamic" };
60
+ }
61
+ new Set(
62
+ "ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
10
63
  );
11
- let ze;
12
- ze = globalThis.crypto;
13
- async function $n(e) {
14
- return (await ze).getRandomValues(new Uint8Array(e));
15
- }
16
- async function Mn(e) {
17
- const t = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", n = Math.pow(2, 8) - Math.pow(2, 8) % t.length;
18
- let r = "";
19
- for (; r.length < e; ) {
20
- const o = await $n(e - r.length);
21
- for (const a of o)
22
- a < n && (r += t[a % t.length]);
23
- }
24
- return r;
25
- }
26
- async function Nn(e) {
27
- return await Mn(e);
28
- }
29
- async function Dn(e) {
30
- const t = await (await ze).subtle.digest("SHA-256", new TextEncoder().encode(e));
64
+ var Dn = Symbol.for("vercel.ai.schema");
65
+ function Hn(e, {
66
+ validate: t
67
+ } = {}) {
68
+ return {
69
+ [Dn]: !0,
70
+ _type: void 0,
71
+ // should never be used directly
72
+ [Nn]: !0,
73
+ get jsonSchema() {
74
+ return typeof e == "function" && (e = e()), e;
75
+ },
76
+ validate: t
77
+ };
78
+ }
79
+ let We;
80
+ We = globalThis.crypto;
81
+ async function Ln(e) {
82
+ return (await We).getRandomValues(new Uint8Array(e));
83
+ }
84
+ async function qn(e) {
85
+ const t = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
86
+ let n = "";
87
+ const r = await Ln(e);
88
+ for (let o = 0; o < e; o++) {
89
+ const a = r[o] % t.length;
90
+ n += t[a];
91
+ }
92
+ return n;
93
+ }
94
+ async function Vn(e) {
95
+ return await qn(e);
96
+ }
97
+ async function Bn(e) {
98
+ const t = await (await We).subtle.digest("SHA-256", new TextEncoder().encode(e));
31
99
  return btoa(String.fromCharCode(...new Uint8Array(t))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
32
100
  }
33
- async function jn(e) {
101
+ async function Jn(e) {
34
102
  if (e || (e = 43), e < 43 || e > 128)
35
103
  throw `Expected a length between 43 and 128. Received ${e}.`;
36
- const t = await Nn(e), n = await Dn(t);
104
+ const t = await Vn(e), n = await Bn(t);
37
105
  return {
38
106
  code_verifier: t,
39
107
  code_challenge: n
40
108
  };
41
109
  }
42
- var qn = "AI_MCPClientError", yt = `vercel.ai.error.${qn}`, Hn = Symbol.for(yt), tt, nt, P = class extends (nt = ye, tt = Hn, nt) {
110
+ var zn = "AI_MCPClientError", yt = `vercel.ai.error.${zn}`, Gn = Symbol.for(yt), rt, ot, O = class extends (ot = be, rt = Gn, ot) {
43
111
  constructor({
44
112
  name: e = "MCPClientError",
45
113
  message: t,
@@ -47,81 +115,81 @@ var qn = "AI_MCPClientError", yt = `vercel.ai.error.${qn}`, Hn = Symbol.for(yt),
47
115
  data: r,
48
116
  code: o
49
117
  }) {
50
- super({ name: e, message: t, cause: n }), this[tt] = !0, this.data = r, this.code = o;
118
+ super({ name: e, message: t, cause: n }), this[rt] = !0, this.data = r, this.code = o;
51
119
  }
52
120
  static isInstance(e) {
53
- return ye.hasMarker(e, yt);
121
+ return be.hasMarker(e, yt);
54
122
  }
55
- }, ie = "2025-06-18", Ln = [
56
- ie,
123
+ }, ue = "2025-06-18", Wn = [
124
+ ue,
57
125
  "2025-03-26",
58
126
  "2024-11-05"
59
- ], Vn = se({
127
+ ], Fn = le({
60
128
  name: s(),
61
129
  version: s()
62
- }), Ie = se({
63
- _meta: S(d({}).loose())
64
- }), Y = Ie, wt = d({
130
+ }), Pe = le({
131
+ _meta: E(d({}).loose())
132
+ }), Y = Pe, wt = d({
65
133
  method: s(),
66
- params: S(Ie)
134
+ params: E(Pe)
67
135
  }), bt = d({
68
- applyDefaults: S(X())
69
- }).loose(), Bn = se({
70
- experimental: S(d({}).loose()),
71
- logging: S(d({}).loose()),
72
- prompts: S(
73
- se({
74
- listChanged: S(X())
136
+ applyDefaults: E(X())
137
+ }).loose(), Kn = le({
138
+ experimental: E(d({}).loose()),
139
+ logging: E(d({}).loose()),
140
+ prompts: E(
141
+ le({
142
+ listChanged: E(X())
75
143
  })
76
144
  ),
77
- resources: S(
78
- se({
79
- subscribe: S(X()),
80
- listChanged: S(X())
145
+ resources: E(
146
+ le({
147
+ subscribe: E(X()),
148
+ listChanged: E(X())
81
149
  })
82
150
  ),
83
- tools: S(
84
- se({
85
- listChanged: S(X())
151
+ tools: E(
152
+ le({
153
+ listChanged: E(X())
86
154
  })
87
155
  ),
88
- elicitation: S(bt)
156
+ elicitation: E(bt)
89
157
  });
90
158
  d({
91
- elicitation: S(bt)
159
+ elicitation: E(bt)
92
160
  }).loose();
93
- var Jn = Y.extend({
161
+ var Zn = Y.extend({
94
162
  protocolVersion: s(),
95
- capabilities: Bn,
96
- serverInfo: Vn,
97
- instructions: S(s())
98
- }), We = Y.extend({
99
- nextCursor: S(s())
100
- }), zn = d({
163
+ capabilities: Kn,
164
+ serverInfo: Fn,
165
+ instructions: E(s())
166
+ }), Fe = Y.extend({
167
+ nextCursor: E(s())
168
+ }), Xn = d({
101
169
  name: s(),
102
- description: S(s()),
170
+ description: E(s()),
103
171
  inputSchema: d({
104
- type: E("object"),
105
- properties: S(d({}).loose())
172
+ type: x("object"),
173
+ properties: E(d({}).loose())
106
174
  }).loose()
107
- }).loose(), Wn = We.extend({
108
- tools: v(zn)
175
+ }).loose(), Yn = Fe.extend({
176
+ tools: y(Xn)
109
177
  }), kt = d({
110
- type: E("text"),
178
+ type: x("text"),
111
179
  text: s()
112
180
  }).loose(), Tt = d({
113
- type: E("image"),
114
- data: _t(),
181
+ type: x("image"),
182
+ data: gt(),
115
183
  mimeType: s()
116
- }).loose(), Gn = d({
184
+ }).loose(), Qn = d({
117
185
  uri: s(),
118
186
  name: s(),
119
- title: S(s()),
120
- description: S(s()),
121
- mimeType: S(s()),
122
- size: S(k())
123
- }).loose(), Fn = We.extend({
124
- resources: v(Gn)
187
+ title: E(s()),
188
+ description: E(s()),
189
+ mimeType: E(s()),
190
+ size: E(k())
191
+ }).loose(), er = Fe.extend({
192
+ resources: y(Qn)
125
193
  }), St = d({
126
194
  /**
127
195
  * The URI of this resource.
@@ -130,104 +198,104 @@ var Jn = Y.extend({
130
198
  /**
131
199
  * Optional display name of the resource content.
132
200
  */
133
- name: S(s()),
201
+ name: E(s()),
134
202
  /**
135
203
  * Optional human readable title.
136
204
  */
137
- title: S(s()),
205
+ title: E(s()),
138
206
  /**
139
207
  * The MIME type of this resource, if known.
140
208
  */
141
- mimeType: S(s())
209
+ mimeType: E(s())
142
210
  }).loose(), Rt = St.extend({
143
211
  text: s()
144
212
  }), Et = St.extend({
145
- blob: _t()
213
+ blob: gt()
146
214
  }), Ct = d({
147
- type: E("resource"),
148
- resource: D([Rt, Et])
149
- }).loose(), Kn = Y.extend({
150
- content: v(
151
- D([kt, Tt, Ct])
215
+ type: x("resource"),
216
+ resource: j([Rt, Et])
217
+ }).loose(), tr = Y.extend({
218
+ content: y(
219
+ j([kt, Tt, Ct])
152
220
  ),
153
221
  isError: X().default(!1).optional()
154
222
  }).or(
155
223
  Y.extend({
156
- toolResult: ne()
224
+ toolResult: oe()
157
225
  })
158
- ), Zn = d({
226
+ ), nr = d({
159
227
  uriTemplate: s(),
160
228
  name: s(),
161
- title: S(s()),
162
- description: S(s()),
163
- mimeType: S(s())
164
- }).loose(), Xn = Y.extend({
165
- resourceTemplates: v(Zn)
166
- }), Yn = Y.extend({
167
- contents: v(
168
- D([Rt, Et])
229
+ title: E(s()),
230
+ description: E(s()),
231
+ mimeType: E(s())
232
+ }).loose(), rr = Y.extend({
233
+ resourceTemplates: y(nr)
234
+ }), or = Y.extend({
235
+ contents: y(
236
+ j([Rt, Et])
169
237
  )
170
- }), Qn = d({
238
+ }), sr = d({
171
239
  name: s(),
172
- description: S(s()),
173
- required: S(X())
174
- }).loose(), er = d({
240
+ description: E(s()),
241
+ required: E(X())
242
+ }).loose(), ar = d({
175
243
  name: s(),
176
- title: S(s()),
177
- description: S(s()),
178
- arguments: S(v(Qn))
179
- }).loose(), tr = We.extend({
180
- prompts: v(er)
181
- }), nr = d({
182
- role: D([E("user"), E("assistant")]),
183
- content: D([
244
+ title: E(s()),
245
+ description: E(s()),
246
+ arguments: E(y(sr))
247
+ }).loose(), ir = Fe.extend({
248
+ prompts: y(ar)
249
+ }), lr = d({
250
+ role: j([x("user"), x("assistant")]),
251
+ content: j([
184
252
  kt,
185
253
  Tt,
186
254
  Ct
187
255
  ])
188
- }).loose(), rr = Y.extend({
189
- description: S(s()),
190
- messages: v(nr)
191
- }), or = Ie.extend({
256
+ }).loose(), cr = Y.extend({
257
+ description: E(s()),
258
+ messages: y(lr)
259
+ }), ur = Pe.extend({
192
260
  message: s(),
193
- requestedSchema: ne()
194
- }), rt = wt.extend({
195
- method: E("elicitation/create"),
196
- params: or
197
- }), sr = Y.extend({
198
- action: D([
199
- E("accept"),
200
- E("decline"),
201
- E("cancel")
261
+ requestedSchema: oe()
262
+ }), st = wt.extend({
263
+ method: x("elicitation/create"),
264
+ params: ur
265
+ }), dr = Y.extend({
266
+ action: j([
267
+ x("accept"),
268
+ x("decline"),
269
+ x("cancel")
202
270
  ]),
203
- content: S(Be(s(), ne()))
204
- }), Pe = "2.0", ar = d({
205
- jsonrpc: E(Pe),
206
- id: D([s(), k().int()])
207
- }).merge(wt).strict(), ir = d({
208
- jsonrpc: E(Pe),
209
- id: D([s(), k().int()]),
271
+ content: E(ze(s(), oe()))
272
+ }), Ae = "2.0", pr = d({
273
+ jsonrpc: x(Ae),
274
+ id: j([s(), k().int()])
275
+ }).merge(wt).strict(), hr = d({
276
+ jsonrpc: x(Ae),
277
+ id: j([s(), k().int()]),
210
278
  result: Y
211
- }).strict(), lr = d({
212
- jsonrpc: E(Pe),
213
- id: D([s(), k().int()]),
279
+ }).strict(), mr = d({
280
+ jsonrpc: x(Ae),
281
+ id: j([s(), k().int()]),
214
282
  error: d({
215
283
  code: k().int(),
216
284
  message: s(),
217
- data: S(ne())
285
+ data: E(oe())
218
286
  })
219
- }).strict(), cr = d({
220
- jsonrpc: E(Pe)
287
+ }).strict(), fr = d({
288
+ jsonrpc: x(Ae)
221
289
  }).merge(
222
290
  d({
223
291
  method: s(),
224
- params: S(Ie)
292
+ params: E(Pe)
225
293
  })
226
- ).strict(), ce = D([
227
- ar,
228
- cr,
229
- ir,
230
- lr
294
+ ).strict(), pe = j([
295
+ pr,
296
+ fr,
297
+ hr,
298
+ mr
231
299
  ]), xt = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test", It = d({
232
300
  access_token: s(),
233
301
  id_token: s().optional(),
@@ -236,7 +304,7 @@ var Jn = Y.extend({
236
304
  expires_in: k().optional(),
237
305
  scope: s().optional(),
238
306
  refresh_token: s().optional()
239
- }).strip(), J = s().url().superRefine((e, t) => {
307
+ }).strip(), B = s().url().superRefine((e, t) => {
240
308
  if (!URL.canParse(e))
241
309
  return t.addIssue({
242
310
  code: Cn.custom,
@@ -249,112 +317,112 @@ var Jn = Y.extend({
249
317
  return t.protocol !== "javascript:" && t.protocol !== "data:" && t.protocol !== "vbscript:";
250
318
  },
251
319
  { message: "URL cannot use javascript:, data:, or vbscript: scheme" }
252
- ), ur = d({
320
+ ), gr = d({
253
321
  resource: s().url(),
254
- authorization_servers: v(J).optional(),
322
+ authorization_servers: y(B).optional(),
255
323
  jwks_uri: s().url().optional(),
256
- scopes_supported: v(s()).optional(),
257
- bearer_methods_supported: v(s()).optional(),
258
- resource_signing_alg_values_supported: v(s()).optional(),
324
+ scopes_supported: y(s()).optional(),
325
+ bearer_methods_supported: y(s()).optional(),
326
+ resource_signing_alg_values_supported: y(s()).optional(),
259
327
  resource_name: s().optional(),
260
328
  resource_documentation: s().optional(),
261
329
  resource_policy_uri: s().url().optional(),
262
330
  resource_tos_uri: s().url().optional(),
263
331
  tls_client_certificate_bound_access_tokens: X().optional(),
264
- authorization_details_types_supported: v(s()).optional(),
265
- dpop_signing_alg_values_supported: v(s()).optional(),
332
+ authorization_details_types_supported: y(s()).optional(),
333
+ dpop_signing_alg_values_supported: y(s()).optional(),
266
334
  dpop_bound_access_tokens_required: X().optional()
267
- }).passthrough(), Pt = d({
335
+ }).passthrough(), Ot = d({
268
336
  issuer: s(),
269
- authorization_endpoint: J,
270
- token_endpoint: J,
271
- registration_endpoint: J.optional(),
272
- scopes_supported: v(s()).optional(),
273
- response_types_supported: v(s()),
274
- grant_types_supported: v(s()).optional(),
275
- code_challenge_methods_supported: v(s()),
276
- token_endpoint_auth_methods_supported: v(s()).optional(),
277
- token_endpoint_auth_signing_alg_values_supported: v(s()).optional()
278
- }).passthrough(), dr = d({
337
+ authorization_endpoint: B,
338
+ token_endpoint: B,
339
+ registration_endpoint: B.optional(),
340
+ scopes_supported: y(s()).optional(),
341
+ response_types_supported: y(s()),
342
+ grant_types_supported: y(s()).optional(),
343
+ code_challenge_methods_supported: y(s()),
344
+ token_endpoint_auth_methods_supported: y(s()).optional(),
345
+ token_endpoint_auth_signing_alg_values_supported: y(s()).optional()
346
+ }).passthrough(), _r = d({
279
347
  issuer: s(),
280
- authorization_endpoint: J,
281
- token_endpoint: J,
282
- userinfo_endpoint: J.optional(),
283
- jwks_uri: J,
284
- registration_endpoint: J.optional(),
285
- scopes_supported: v(s()).optional(),
286
- response_types_supported: v(s()),
287
- grant_types_supported: v(s()).optional(),
288
- subject_types_supported: v(s()),
289
- id_token_signing_alg_values_supported: v(s()),
290
- claims_supported: v(s()).optional(),
291
- token_endpoint_auth_methods_supported: v(s()).optional()
292
- }).passthrough(), pr = dr.merge(
293
- Pt.pick({
348
+ authorization_endpoint: B,
349
+ token_endpoint: B,
350
+ userinfo_endpoint: B.optional(),
351
+ jwks_uri: B,
352
+ registration_endpoint: B.optional(),
353
+ scopes_supported: y(s()).optional(),
354
+ response_types_supported: y(s()),
355
+ grant_types_supported: y(s()).optional(),
356
+ subject_types_supported: y(s()),
357
+ id_token_signing_alg_values_supported: y(s()),
358
+ claims_supported: y(s()).optional(),
359
+ token_endpoint_auth_methods_supported: y(s()).optional()
360
+ }).passthrough(), vr = _r.merge(
361
+ Ot.pick({
294
362
  code_challenge_methods_supported: !0
295
363
  })
296
- ), hr = d({
364
+ ), yr = d({
297
365
  client_id: s(),
298
366
  client_secret: s().optional(),
299
367
  client_id_issued_at: k().optional(),
300
368
  client_secret_expires_at: k().optional()
301
- }).strip(), mr = d({
302
- redirect_uris: v(J),
369
+ }).strip(), wr = d({
370
+ redirect_uris: y(B),
303
371
  token_endpoint_auth_method: s().optional(),
304
- grant_types: v(s()).optional(),
305
- response_types: v(s()).optional(),
372
+ grant_types: y(s()).optional(),
373
+ response_types: y(s()).optional(),
306
374
  client_name: s().optional(),
307
- client_uri: J.optional(),
308
- logo_uri: J.optional(),
375
+ client_uri: B.optional(),
376
+ logo_uri: B.optional(),
309
377
  scope: s().optional(),
310
- contacts: v(s()).optional(),
311
- tos_uri: J.optional(),
378
+ contacts: y(s()).optional(),
379
+ tos_uri: B.optional(),
312
380
  policy_uri: s().optional(),
313
- jwks_uri: J.optional(),
314
- jwks: vt().optional(),
381
+ jwks_uri: B.optional(),
382
+ jwks: K().optional(),
315
383
  software_id: s().optional(),
316
384
  software_version: s().optional(),
317
385
  software_statement: s().optional()
318
- }).strip(), gr = d({
386
+ }).strip(), br = d({
319
387
  error: s(),
320
388
  error_description: s().optional(),
321
389
  error_uri: s().optional()
322
- }), fr = mr.merge(
323
- hr
324
- ), _r = "AI_MCPClientOAuthError", Ot = `vercel.ai.error.${_r}`, vr = Symbol.for(Ot), ot, st, me = class extends (st = ye, ot = vr, st) {
390
+ }), kr = wr.merge(
391
+ yr
392
+ ), Tr = "AI_MCPClientOAuthError", Pt = `vercel.ai.error.${Tr}`, Sr = Symbol.for(Pt), at, it, _e = class extends (it = be, at = Sr, it) {
325
393
  constructor({
326
394
  name: e = "MCPClientOAuthError",
327
395
  message: t,
328
396
  cause: n
329
397
  }) {
330
- super({ name: e, message: t, cause: n }), this[ot] = !0;
398
+ super({ name: e, message: t, cause: n }), this[at] = !0;
331
399
  }
332
400
  static isInstance(e) {
333
- return ye.hasMarker(e, Ot);
401
+ return be.hasMarker(e, Pt);
334
402
  }
335
- }, ae = class extends me {
403
+ }, ce = class extends _e {
336
404
  };
337
- ae.errorCode = "server_error";
338
- var we = class extends me {
405
+ ce.errorCode = "server_error";
406
+ var ke = class extends _e {
339
407
  };
340
- we.errorCode = "invalid_client";
341
- var be = class extends me {
408
+ ke.errorCode = "invalid_client";
409
+ var Te = class extends _e {
342
410
  };
343
- be.errorCode = "invalid_grant";
344
- var ke = class extends me {
411
+ Te.errorCode = "invalid_grant";
412
+ var Se = class extends _e {
345
413
  };
346
- ke.errorCode = "unauthorized_client";
347
- var yr = {
348
- [ae.errorCode]: ae,
349
- [we.errorCode]: we,
350
- [be.errorCode]: be,
351
- [ke.errorCode]: ke
414
+ Se.errorCode = "unauthorized_client";
415
+ var Rr = {
416
+ [ce.errorCode]: ce,
417
+ [ke.errorCode]: ke,
418
+ [Te.errorCode]: Te,
419
+ [Se.errorCode]: Se
352
420
  };
353
- function wr(e) {
421
+ function Er(e) {
354
422
  const t = typeof e == "string" ? new URL(e) : new URL(e.href);
355
423
  return t.hash = "", t;
356
424
  }
357
- function br({
425
+ function Cr({
358
426
  requestedResource: e,
359
427
  configuredResource: t
360
428
  }) {
@@ -364,12 +432,12 @@ function br({
364
432
  const o = n.pathname.endsWith("/") ? n.pathname : n.pathname + "/", a = r.pathname.endsWith("/") ? r.pathname : r.pathname + "/";
365
433
  return o.startsWith(a);
366
434
  }
367
- var Te = class extends Error {
435
+ var Re = class extends Error {
368
436
  constructor(e = "Unauthorized") {
369
437
  super(e), this.name = "UnauthorizedError";
370
438
  }
371
439
  };
372
- function Se(e) {
440
+ function Ee(e) {
373
441
  var t;
374
442
  const n = (t = e.headers.get("www-authenticate")) != null ? t : e.headers.get("WWW-Authenticate");
375
443
  if (!n)
@@ -377,53 +445,53 @@ function Se(e) {
377
445
  const [r, o] = n.split(" ");
378
446
  if (r.toLowerCase() !== "bearer" || !o)
379
447
  return;
380
- const a = /resource_metadata="([^"]*)"/, l = n.match(a);
381
- if (l)
448
+ const a = /resource_metadata="([^"]*)"/, i = n.match(a);
449
+ if (i)
382
450
  try {
383
- return new URL(l[1]);
451
+ return new URL(i[1]);
384
452
  } catch {
385
453
  return;
386
454
  }
387
455
  }
388
- function kr(e, t = "", n = {}) {
456
+ function xr(e, t = "", n = {}) {
389
457
  return t.endsWith("/") && (t = t.slice(0, -1)), n.prependPathname ? `${t}/.well-known/${e}` : `/.well-known/${e}${t}`;
390
458
  }
391
- async function Ge(e, t, n = fetch) {
459
+ async function Ke(e, t, n = fetch) {
392
460
  try {
393
461
  return await n(e, { headers: t });
394
462
  } catch (r) {
395
463
  if (r instanceof TypeError)
396
- return t ? Ge(e, void 0, n) : void 0;
464
+ return t ? Ke(e, void 0, n) : void 0;
397
465
  throw r;
398
466
  }
399
467
  }
400
- async function at(e, t, n = fetch) {
401
- return await Ge(e, {
468
+ async function lt(e, t, n = fetch) {
469
+ return await Ke(e, {
402
470
  "MCP-Protocol-Version": t
403
471
  }, n);
404
472
  }
405
- function Tr(e, t) {
473
+ function Ir(e, t) {
406
474
  return !e || e.status >= 400 && e.status < 500 && t !== "/";
407
475
  }
408
- async function Sr(e, t, n, r) {
476
+ async function Or(e, t, n, r) {
409
477
  var o, a;
410
- const l = new URL(e), c = (o = r?.protocolVersion) != null ? o : ie;
411
- let i;
478
+ const i = new URL(e), c = (o = r?.protocolVersion) != null ? o : ue;
479
+ let l;
412
480
  if (r?.metadataUrl)
413
- i = new URL(r.metadataUrl);
481
+ l = new URL(r.metadataUrl);
414
482
  else {
415
- const h = kr(t, l.pathname);
416
- i = new URL(h, (a = r?.metadataServerUrl) != null ? a : l), i.search = l.search;
483
+ const h = xr(t, i.pathname);
484
+ l = new URL(h, (a = r?.metadataServerUrl) != null ? a : i), l.search = i.search;
417
485
  }
418
- let u = await at(i, c, n);
419
- if (!r?.metadataUrl && Tr(u, l.pathname)) {
420
- const h = new URL(`/.well-known/${t}`, l);
421
- u = await at(h, c, n);
486
+ let u = await lt(l, c, n);
487
+ if (!r?.metadataUrl && Ir(u, i.pathname)) {
488
+ const h = new URL(`/.well-known/${t}`, i);
489
+ u = await lt(h, c, n);
422
490
  }
423
491
  return u;
424
492
  }
425
- async function Rr(e, t, n = fetch) {
426
- const r = await Sr(
493
+ async function Pr(e, t, n = fetch) {
494
+ const r = await Or(
427
495
  e,
428
496
  "oauth-protected-resource",
429
497
  n,
@@ -440,9 +508,9 @@ async function Rr(e, t, n = fetch) {
440
508
  throw new Error(
441
509
  `HTTP ${r.status} trying to load well-known OAuth protected resource metadata.`
442
510
  );
443
- return ur.parse(await r.json());
511
+ return gr.parse(await r.json());
444
512
  }
445
- function Er(e) {
513
+ function Ar(e) {
446
514
  const t = typeof e == "string" ? new URL(e) : e, n = t.pathname !== "/", r = [];
447
515
  if (!n)
448
516
  return r.push({
@@ -470,85 +538,85 @@ function Er(e) {
470
538
  type: "oidc"
471
539
  }), r;
472
540
  }
473
- async function Cr(e, {
541
+ async function $r(e, {
474
542
  fetchFn: t = fetch,
475
- protocolVersion: n = ie
543
+ protocolVersion: n = ue
476
544
  } = {}) {
477
545
  var r;
478
- const o = { "MCP-Protocol-Version": n }, a = Er(e);
479
- for (const { url: l, type: c } of a) {
480
- const i = await Ge(l, o, t);
481
- if (i) {
482
- if (!i.ok) {
483
- if (i.status >= 400 && i.status < 500)
546
+ const o = { "MCP-Protocol-Version": n }, a = Ar(e);
547
+ for (const { url: i, type: c } of a) {
548
+ const l = await Ke(i, o, t);
549
+ if (l) {
550
+ if (!l.ok) {
551
+ if (l.status >= 400 && l.status < 500)
484
552
  continue;
485
553
  throw new Error(
486
- `HTTP ${i.status} trying to load ${c === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${l}`
554
+ `HTTP ${l.status} trying to load ${c === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${i}`
487
555
  );
488
556
  }
489
557
  if (c === "oauth")
490
- return Pt.parse(await i.json());
558
+ return Ot.parse(await l.json());
491
559
  {
492
- const u = pr.parse(
493
- await i.json()
560
+ const u = vr.parse(
561
+ await l.json()
494
562
  );
495
563
  if (!((r = u.code_challenge_methods_supported) != null && r.includes("S256")))
496
564
  throw new Error(
497
- `Incompatible OIDC provider at ${l}: does not support S256 code challenge method required by MCP specification`
565
+ `Incompatible OIDC provider at ${i}: does not support S256 code challenge method required by MCP specification`
498
566
  );
499
567
  return u;
500
568
  }
501
569
  }
502
570
  }
503
571
  }
504
- async function xr(e, {
572
+ async function Ur(e, {
505
573
  metadata: t,
506
574
  clientInformation: n,
507
575
  redirectUrl: r,
508
576
  scope: o,
509
577
  state: a,
510
- resource: l
578
+ resource: i
511
579
  }) {
512
- const c = "code", i = "S256";
580
+ const c = "code", l = "S256";
513
581
  let u;
514
582
  if (t) {
515
583
  if (u = new URL(t.authorization_endpoint), !t.response_types_supported.includes(c))
516
584
  throw new Error(
517
585
  `Incompatible auth server: does not support response type ${c}`
518
586
  );
519
- if (!t.code_challenge_methods_supported || !t.code_challenge_methods_supported.includes(i))
587
+ if (!t.code_challenge_methods_supported || !t.code_challenge_methods_supported.includes(l))
520
588
  throw new Error(
521
- `Incompatible auth server: does not support code challenge method ${i}`
589
+ `Incompatible auth server: does not support code challenge method ${l}`
522
590
  );
523
591
  } else
524
592
  u = new URL("/authorize", e);
525
- const h = await jn(), f = h.code_verifier, m = h.code_challenge;
526
- return u.searchParams.set("response_type", c), u.searchParams.set("client_id", n.client_id), u.searchParams.set("code_challenge", m), u.searchParams.set(
593
+ const h = await Jn(), g = h.code_verifier, f = h.code_challenge;
594
+ return u.searchParams.set("response_type", c), u.searchParams.set("client_id", n.client_id), u.searchParams.set("code_challenge", f), u.searchParams.set(
527
595
  "code_challenge_method",
528
- i
529
- ), u.searchParams.set("redirect_uri", String(r)), a && u.searchParams.set("state", a), o && u.searchParams.set("scope", o), o?.includes("offline_access") && u.searchParams.append("prompt", "consent"), l && u.searchParams.set("resource", l.href), { authorizationUrl: u, codeVerifier: f };
596
+ l
597
+ ), u.searchParams.set("redirect_uri", String(r)), a && u.searchParams.set("state", a), o && u.searchParams.set("scope", o), o?.includes("offline_access") && u.searchParams.append("prompt", "consent"), i && u.searchParams.set("resource", i.href), { authorizationUrl: u, codeVerifier: g };
530
598
  }
531
599
  function At(e, t) {
532
600
  const n = e.client_secret !== void 0;
533
601
  return t.length === 0 ? n ? "client_secret_post" : "none" : n && t.includes("client_secret_basic") ? "client_secret_basic" : n && t.includes("client_secret_post") ? "client_secret_post" : t.includes("none") ? "none" : n ? "client_secret_post" : "none";
534
602
  }
535
- function Ut(e, t, n, r) {
603
+ function $t(e, t, n, r) {
536
604
  const { client_id: o, client_secret: a } = t;
537
605
  switch (e) {
538
606
  case "client_secret_basic":
539
- Ir(o, a, n);
607
+ Mr(o, a, n);
540
608
  return;
541
609
  case "client_secret_post":
542
- Pr(o, a, r);
610
+ Nr(o, a, r);
543
611
  return;
544
612
  case "none":
545
- Or(o, r);
613
+ jr(o, r);
546
614
  return;
547
615
  default:
548
616
  throw new Error(`Unsupported client authentication method: ${e}`);
549
617
  }
550
618
  }
551
- function Ir(e, t, n) {
619
+ function Mr(e, t, n) {
552
620
  if (!t)
553
621
  throw new Error(
554
622
  "client_secret_basic authentication requires a client_secret"
@@ -556,116 +624,116 @@ function Ir(e, t, n) {
556
624
  const r = btoa(`${e}:${t}`);
557
625
  n.set("Authorization", `Basic ${r}`);
558
626
  }
559
- function Pr(e, t, n) {
627
+ function Nr(e, t, n) {
560
628
  n.set("client_id", e), t && n.set("client_secret", t);
561
629
  }
562
- function Or(e, t) {
630
+ function jr(e, t) {
563
631
  t.set("client_id", e);
564
632
  }
565
- async function Fe(e) {
633
+ async function Ze(e) {
566
634
  const t = e instanceof Response ? e.status : void 0, n = e instanceof Response ? await e.text() : e;
567
635
  try {
568
- const r = gr.parse(JSON.parse(n)), { error: o, error_description: a, error_uri: l } = r, c = yr[o] || ae;
636
+ const r = br.parse(JSON.parse(n)), { error: o, error_description: a, error_uri: i } = r, c = Rr[o] || ce;
569
637
  return new c({
570
638
  message: a || "",
571
- cause: l
639
+ cause: i
572
640
  });
573
641
  } catch (r) {
574
642
  const o = `${t ? `HTTP ${t}: ` : ""}Invalid OAuth error response: ${r}. Raw body: ${n}`;
575
- return new ae({ message: o });
643
+ return new ce({ message: o });
576
644
  }
577
645
  }
578
- async function Ar(e, {
646
+ async function Dr(e, {
579
647
  metadata: t,
580
648
  clientInformation: n,
581
649
  authorizationCode: r,
582
650
  codeVerifier: o,
583
651
  redirectUri: a,
584
- resource: l,
652
+ resource: i,
585
653
  addClientAuthentication: c,
586
- fetchFn: i
654
+ fetchFn: l
587
655
  }) {
588
656
  var u;
589
- const h = "authorization_code", f = t?.token_endpoint ? new URL(t.token_endpoint) : new URL("/token", e);
657
+ const h = "authorization_code", g = t?.token_endpoint ? new URL(t.token_endpoint) : new URL("/token", e);
590
658
  if (t?.grant_types_supported && !t.grant_types_supported.includes(h))
591
659
  throw new Error(
592
660
  `Incompatible auth server: does not support grant type ${h}`
593
661
  );
594
- const m = new Headers({
662
+ const f = new Headers({
595
663
  "Content-Type": "application/x-www-form-urlencoded",
596
664
  Accept: "application/json"
597
- }), _ = new URLSearchParams({
665
+ }), v = new URLSearchParams({
598
666
  grant_type: h,
599
667
  code: r,
600
668
  code_verifier: o,
601
669
  redirect_uri: String(a)
602
670
  });
603
671
  if (c)
604
- c(m, _, e, t);
672
+ c(f, v, e, t);
605
673
  else {
606
- const p = (u = t?.token_endpoint_auth_methods_supported) != null ? u : [], b = At(
674
+ const p = (u = t?.token_endpoint_auth_methods_supported) != null ? u : [], w = At(
607
675
  n,
608
676
  p
609
677
  );
610
- Ut(b, n, m, _);
678
+ $t(w, n, f, v);
611
679
  }
612
- l && _.set("resource", l.href);
613
- const g = await (i ?? fetch)(f, {
680
+ i && v.set("resource", i.href);
681
+ const m = await (l ?? fetch)(g, {
614
682
  method: "POST",
615
- headers: m,
616
- body: _
683
+ headers: f,
684
+ body: v
617
685
  });
618
- if (!g.ok)
619
- throw await Fe(g);
620
- return It.parse(await g.json());
686
+ if (!m.ok)
687
+ throw await Ze(m);
688
+ return It.parse(await m.json());
621
689
  }
622
- async function Ur(e, {
690
+ async function Hr(e, {
623
691
  metadata: t,
624
692
  clientInformation: n,
625
693
  refreshToken: r,
626
694
  resource: o,
627
695
  addClientAuthentication: a,
628
- fetchFn: l
696
+ fetchFn: i
629
697
  }) {
630
698
  var c;
631
- const i = "refresh_token";
699
+ const l = "refresh_token";
632
700
  let u;
633
701
  if (t) {
634
- if (u = new URL(t.token_endpoint), t.grant_types_supported && !t.grant_types_supported.includes(i))
702
+ if (u = new URL(t.token_endpoint), t.grant_types_supported && !t.grant_types_supported.includes(l))
635
703
  throw new Error(
636
- `Incompatible auth server: does not support grant type ${i}`
704
+ `Incompatible auth server: does not support grant type ${l}`
637
705
  );
638
706
  } else
639
707
  u = new URL("/token", e);
640
708
  const h = new Headers({
641
709
  "Content-Type": "application/x-www-form-urlencoded"
642
- }), f = new URLSearchParams({
643
- grant_type: i,
710
+ }), g = new URLSearchParams({
711
+ grant_type: l,
644
712
  refresh_token: r
645
713
  });
646
714
  if (a)
647
- a(h, f, e, t);
715
+ a(h, g, e, t);
648
716
  else {
649
- const _ = (c = t?.token_endpoint_auth_methods_supported) != null ? c : [], g = At(
717
+ const v = (c = t?.token_endpoint_auth_methods_supported) != null ? c : [], m = At(
650
718
  n,
651
- _
719
+ v
652
720
  );
653
- Ut(g, n, h, f);
721
+ $t(m, n, h, g);
654
722
  }
655
- o && f.set("resource", o.href);
656
- const m = await (l ?? fetch)(u, {
723
+ o && g.set("resource", o.href);
724
+ const f = await (i ?? fetch)(u, {
657
725
  method: "POST",
658
726
  headers: h,
659
- body: f
727
+ body: g
660
728
  });
661
- if (!m.ok)
662
- throw await Fe(m);
729
+ if (!f.ok)
730
+ throw await Ze(f);
663
731
  return It.parse({
664
732
  refresh_token: r,
665
- ...await m.json()
733
+ ...await f.json()
666
734
  });
667
735
  }
668
- async function $r(e, {
736
+ async function Lr(e, {
669
737
  metadata: t,
670
738
  clientMetadata: n,
671
739
  fetchFn: r
@@ -687,30 +755,30 @@ async function $r(e, {
687
755
  body: JSON.stringify(n)
688
756
  });
689
757
  if (!a.ok)
690
- throw await Fe(a);
691
- return fr.parse(await a.json());
758
+ throw await Ze(a);
759
+ return kr.parse(await a.json());
692
760
  }
693
- async function Re(e, t) {
761
+ async function Ce(e, t) {
694
762
  var n, r;
695
763
  try {
696
- return await Ue(e, t);
764
+ return await Me(e, t);
697
765
  } catch (o) {
698
- if (o instanceof we || o instanceof ke)
699
- return await ((n = e.invalidateCredentials) == null ? void 0 : n.call(e, "all")), await Ue(e, t);
700
- if (o instanceof be)
701
- return await ((r = e.invalidateCredentials) == null ? void 0 : r.call(e, "tokens")), await Ue(e, t);
766
+ if (o instanceof ke || o instanceof Se)
767
+ return await ((n = e.invalidateCredentials) == null ? void 0 : n.call(e, "all")), await Me(e, t);
768
+ if (o instanceof Te)
769
+ return await ((r = e.invalidateCredentials) == null ? void 0 : r.call(e, "tokens")), await Me(e, t);
702
770
  throw o;
703
771
  }
704
772
  }
705
- async function Mr(e, t, n) {
706
- const r = wr(e);
773
+ async function qr(e, t, n) {
774
+ const r = Er(e);
707
775
  if (t.validateResourceURL)
708
776
  return await t.validateResourceURL(
709
777
  r,
710
778
  n?.resource
711
779
  );
712
780
  if (n) {
713
- if (!br({
781
+ if (!Cr({
714
782
  requestedResource: r,
715
783
  configuredResource: n.resource
716
784
  }))
@@ -720,28 +788,28 @@ async function Mr(e, t, n) {
720
788
  return new URL(n.resource);
721
789
  }
722
790
  }
723
- async function Ue(e, {
791
+ async function Me(e, {
724
792
  serverUrl: t,
725
793
  authorizationCode: n,
726
794
  scope: r,
727
795
  resourceMetadataUrl: o,
728
796
  fetchFn: a
729
797
  }) {
730
- let l, c;
798
+ let i, c;
731
799
  try {
732
- l = await Rr(
800
+ i = await Pr(
733
801
  t,
734
802
  { resourceMetadataUrl: o },
735
803
  a
736
- ), l.authorization_servers && l.authorization_servers.length > 0 && (c = l.authorization_servers[0]);
804
+ ), i.authorization_servers && i.authorization_servers.length > 0 && (c = i.authorization_servers[0]);
737
805
  } catch {
738
806
  }
739
807
  c || (c = t);
740
- const i = await Mr(
808
+ const l = await qr(
741
809
  t,
742
810
  e,
743
- l
744
- ), u = await Cr(
811
+ i
812
+ ), u = await $r(
745
813
  c,
746
814
  {
747
815
  fetchFn: a
@@ -757,7 +825,7 @@ async function Ue(e, {
757
825
  throw new Error(
758
826
  "OAuth client information must be saveable for dynamic registration"
759
827
  );
760
- const p = await $r(c, {
828
+ const p = await Lr(c, {
761
829
  metadata: u,
762
830
  clientMetadata: e.clientMetadata,
763
831
  fetchFn: a
@@ -765,26 +833,26 @@ async function Ue(e, {
765
833
  await e.saveClientInformation(p), h = p;
766
834
  }
767
835
  if (n !== void 0) {
768
- const p = await e.codeVerifier(), b = await Ar(c, {
836
+ const p = await e.codeVerifier(), w = await Dr(c, {
769
837
  metadata: u,
770
838
  clientInformation: h,
771
839
  authorizationCode: n,
772
840
  codeVerifier: p,
773
841
  redirectUri: e.redirectUrl,
774
- resource: i,
842
+ resource: l,
775
843
  addClientAuthentication: e.addClientAuthentication,
776
844
  fetchFn: a
777
845
  });
778
- return await e.saveTokens(b), "AUTHORIZED";
846
+ return await e.saveTokens(w), "AUTHORIZED";
779
847
  }
780
- const f = await e.tokens();
781
- if (f?.refresh_token)
848
+ const g = await e.tokens();
849
+ if (g?.refresh_token)
782
850
  try {
783
- const p = await Ur(c, {
851
+ const p = await Hr(c, {
784
852
  metadata: u,
785
853
  clientInformation: h,
786
- refreshToken: f.refresh_token,
787
- resource: i,
854
+ refreshToken: g.refresh_token,
855
+ resource: l,
788
856
  addClientAuthentication: e.addClientAuthentication,
789
857
  fetchFn: a
790
858
  });
@@ -792,23 +860,23 @@ async function Ue(e, {
792
860
  } catch (p) {
793
861
  if (
794
862
  // If this is a ServerError, or an unknown type, log it out and try to continue. Otherwise, escalate so we can fix things and retry.
795
- !(!(p instanceof me) || p instanceof ae)
863
+ !(!(p instanceof _e) || p instanceof ce)
796
864
  ) throw p;
797
865
  }
798
- const m = e.state ? await e.state() : void 0, { authorizationUrl: _, codeVerifier: g } = await xr(
866
+ const f = e.state ? await e.state() : void 0, { authorizationUrl: v, codeVerifier: m } = await Ur(
799
867
  c,
800
868
  {
801
869
  metadata: u,
802
870
  clientInformation: h,
803
- state: m,
871
+ state: f,
804
872
  redirectUrl: e.redirectUrl,
805
873
  scope: r || e.clientMetadata.scope,
806
- resource: i
874
+ resource: l
807
875
  }
808
876
  );
809
- return await e.saveCodeVerifier(g), await e.redirectToAuthorization(_), "REDIRECT";
877
+ return await e.saveCodeVerifier(m), await e.redirectToAuthorization(v), "REDIRECT";
810
878
  }
811
- var Nr = class {
879
+ var Vr = class {
812
880
  constructor({
813
881
  url: e,
814
882
  headers: t,
@@ -820,16 +888,16 @@ var Nr = class {
820
888
  const t = {
821
889
  ...this.headers,
822
890
  ...e,
823
- "mcp-protocol-version": ie
891
+ "mcp-protocol-version": ue
824
892
  };
825
893
  if (this.authProvider) {
826
894
  const n = await this.authProvider.tokens();
827
895
  n?.access_token && (t.Authorization = `Bearer ${n.access_token}`);
828
896
  }
829
- return gt(
897
+ return vt(
830
898
  t,
831
899
  `ai-sdk/${xt}`,
832
- ft()
900
+ _t()
833
901
  );
834
902
  }
835
903
  async start() {
@@ -838,7 +906,7 @@ var Nr = class {
838
906
  return e();
839
907
  this.abortController = new AbortController();
840
908
  const n = async (r = !1) => {
841
- var o, a, l, c, i;
909
+ var o, a, i, c, l;
842
910
  try {
843
911
  const u = await this.commonHeaders({
844
912
  Accept: "text/event-stream"
@@ -847,74 +915,74 @@ var Nr = class {
847
915
  signal: (o = this.abortController) == null ? void 0 : o.signal
848
916
  });
849
917
  if (h.status === 401 && this.authProvider && !r) {
850
- this.resourceMetadataUrl = Se(h);
918
+ this.resourceMetadataUrl = Ee(h);
851
919
  try {
852
- if (await Re(this.authProvider, {
920
+ if (await Ce(this.authProvider, {
853
921
  serverUrl: this.url,
854
922
  resourceMetadataUrl: this.resourceMetadataUrl
855
923
  }) !== "AUTHORIZED") {
856
- const p = new Te();
924
+ const p = new Re();
857
925
  return (a = this.onerror) == null || a.call(this, p), t(p);
858
926
  }
859
- } catch (g) {
860
- return (l = this.onerror) == null || l.call(this, g), t(g);
927
+ } catch (m) {
928
+ return (i = this.onerror) == null || i.call(this, m), t(m);
861
929
  }
862
930
  return n(!0);
863
931
  }
864
932
  if (!h.ok || !h.body) {
865
- let g = `MCP SSE Transport Error: ${h.status} ${h.statusText}`;
866
- h.status === 405 && (g += ". This server does not support SSE transport. Try using `http` transport instead");
867
- const p = new P({
868
- message: g
933
+ let m = `MCP SSE Transport Error: ${h.status} ${h.statusText}`;
934
+ h.status === 405 && (m += ". This server does not support SSE transport. Try using `http` transport instead");
935
+ const p = new O({
936
+ message: m
869
937
  });
870
938
  return (c = this.onerror) == null || c.call(this, p), t(p);
871
939
  }
872
- const m = h.body.pipeThrough(new TextDecoderStream()).pipeThrough(new De()).getReader(), _ = async () => {
873
- var g, p, b;
940
+ const f = h.body.pipeThrough(new TextDecoderStream()).pipeThrough(new He()).getReader(), v = async () => {
941
+ var m, p, w;
874
942
  try {
875
943
  for (; ; ) {
876
- const { done: y, value: T } = await m.read();
877
- if (y) {
944
+ const { done: b, value: R } = await f.read();
945
+ if (b) {
878
946
  if (this.connected)
879
- throw this.connected = !1, new P({
947
+ throw this.connected = !1, new O({
880
948
  message: "MCP SSE Transport Error: Connection closed unexpectedly"
881
949
  });
882
950
  return;
883
951
  }
884
- const { event: w, data: A } = T;
885
- if (w === "endpoint") {
886
- if (this.endpoint = new URL(A, this.url), this.endpoint.origin !== this.url.origin)
887
- throw new P({
952
+ const { event: T, data: S } = R;
953
+ if (T === "endpoint") {
954
+ if (this.endpoint = new URL(S, this.url), this.endpoint.origin !== this.url.origin)
955
+ throw new O({
888
956
  message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${this.endpoint.origin}`
889
957
  });
890
958
  this.connected = !0, e();
891
- } else if (w === "message")
959
+ } else if (T === "message")
892
960
  try {
893
- const x = ce.parse(
894
- JSON.parse(A)
961
+ const M = pe.parse(
962
+ JSON.parse(S)
895
963
  );
896
- (g = this.onmessage) == null || g.call(this, x);
897
- } catch (x) {
898
- const $ = new P({
964
+ (m = this.onmessage) == null || m.call(this, M);
965
+ } catch (M) {
966
+ const $ = new O({
899
967
  message: "MCP SSE Transport Error: Failed to parse message",
900
- cause: x
968
+ cause: M
901
969
  });
902
970
  (p = this.onerror) == null || p.call(this, $);
903
971
  }
904
972
  }
905
- } catch (y) {
906
- if (y instanceof Error && y.name === "AbortError")
973
+ } catch (b) {
974
+ if (b instanceof Error && b.name === "AbortError")
907
975
  return;
908
- (b = this.onerror) == null || b.call(this, y), t(y);
976
+ (w = this.onerror) == null || w.call(this, b), t(b);
909
977
  }
910
978
  };
911
979
  this.sseConnection = {
912
- close: () => m.cancel()
913
- }, _();
980
+ close: () => f.cancel()
981
+ }, v();
914
982
  } catch (u) {
915
983
  if (u instanceof Error && u.name === "AbortError")
916
984
  return;
917
- (i = this.onerror) == null || i.call(this, u), t(u);
985
+ (l = this.onerror) == null || l.call(this, u), t(u);
918
986
  }
919
987
  };
920
988
  n();
@@ -926,11 +994,11 @@ var Nr = class {
926
994
  }
927
995
  async send(e) {
928
996
  if (!this.endpoint || !this.connected)
929
- throw new P({
997
+ throw new O({
930
998
  message: "MCP SSE Transport Error: Not connected"
931
999
  });
932
1000
  const t = this.endpoint, n = async (r = !1) => {
933
- var o, a, l, c, i;
1001
+ var o, a, i, c, l;
934
1002
  try {
935
1003
  const h = {
936
1004
  method: "POST",
@@ -939,39 +1007,39 @@ var Nr = class {
939
1007
  }),
940
1008
  body: JSON.stringify(e),
941
1009
  signal: (o = this.abortController) == null ? void 0 : o.signal
942
- }, f = await fetch(t, h);
943
- if (f.status === 401 && this.authProvider && !r) {
944
- this.resourceMetadataUrl = Se(f);
1010
+ }, g = await fetch(t, h);
1011
+ if (g.status === 401 && this.authProvider && !r) {
1012
+ this.resourceMetadataUrl = Ee(g);
945
1013
  try {
946
- if (await Re(this.authProvider, {
1014
+ if (await Ce(this.authProvider, {
947
1015
  serverUrl: this.url,
948
1016
  resourceMetadataUrl: this.resourceMetadataUrl
949
1017
  }) !== "AUTHORIZED") {
950
- const _ = new Te();
951
- (a = this.onerror) == null || a.call(this, _);
1018
+ const v = new Re();
1019
+ (a = this.onerror) == null || a.call(this, v);
952
1020
  return;
953
1021
  }
954
- } catch (m) {
955
- (l = this.onerror) == null || l.call(this, m);
1022
+ } catch (f) {
1023
+ (i = this.onerror) == null || i.call(this, f);
956
1024
  return;
957
1025
  }
958
1026
  return n(!0);
959
1027
  }
960
- if (!f.ok) {
961
- const m = await f.text().catch(() => null), _ = new P({
962
- message: `MCP SSE Transport Error: POSTing to endpoint (HTTP ${f.status}): ${m}`
1028
+ if (!g.ok) {
1029
+ const f = await g.text().catch(() => null), v = new O({
1030
+ message: `MCP SSE Transport Error: POSTing to endpoint (HTTP ${g.status}): ${f}`
963
1031
  });
964
- (c = this.onerror) == null || c.call(this, _);
1032
+ (c = this.onerror) == null || c.call(this, v);
965
1033
  return;
966
1034
  }
967
1035
  } catch (u) {
968
- (i = this.onerror) == null || i.call(this, u);
1036
+ (l = this.onerror) == null || l.call(this, u);
969
1037
  return;
970
1038
  }
971
1039
  };
972
1040
  await n();
973
1041
  }
974
- }, Dr = class {
1042
+ }, Br = class {
975
1043
  constructor({
976
1044
  url: e,
977
1045
  headers: t,
@@ -988,21 +1056,21 @@ var Nr = class {
988
1056
  const t = {
989
1057
  ...this.headers,
990
1058
  ...e,
991
- "mcp-protocol-version": ie
1059
+ "mcp-protocol-version": ue
992
1060
  };
993
1061
  if (this.sessionId && (t["mcp-session-id"] = this.sessionId), this.authProvider) {
994
1062
  const n = await this.authProvider.tokens();
995
1063
  n?.access_token && (t.Authorization = `Bearer ${n.access_token}`);
996
1064
  }
997
- return gt(
1065
+ return vt(
998
1066
  t,
999
1067
  `ai-sdk/${xt}`,
1000
- ft()
1068
+ _t()
1001
1069
  );
1002
1070
  }
1003
1071
  async start() {
1004
1072
  if (this.abortController)
1005
- throw new P({
1073
+ throw new O({
1006
1074
  message: "MCP HTTP Transport Error: Transport already started. Note: client.connect() calls start() automatically."
1007
1075
  });
1008
1076
  this.abortController = new AbortController(), this.openInboundSse();
@@ -1026,9 +1094,9 @@ var Nr = class {
1026
1094
  }
1027
1095
  async send(e) {
1028
1096
  const t = async (n = !1) => {
1029
- var r, o, a, l, c, i, u;
1097
+ var r, o, a, i, c, l, u;
1030
1098
  try {
1031
- const f = {
1099
+ const g = {
1032
1100
  method: "POST",
1033
1101
  headers: await this.commonHeaders({
1034
1102
  "Content-Type": "application/json",
@@ -1036,78 +1104,78 @@ var Nr = class {
1036
1104
  }),
1037
1105
  body: JSON.stringify(e),
1038
1106
  signal: (r = this.abortController) == null ? void 0 : r.signal
1039
- }, m = await fetch(this.url, f), _ = m.headers.get("mcp-session-id");
1040
- if (_ && (this.sessionId = _), m.status === 401 && this.authProvider && !n) {
1041
- this.resourceMetadataUrl = Se(m);
1107
+ }, f = await fetch(this.url, g), v = f.headers.get("mcp-session-id");
1108
+ if (v && (this.sessionId = v), f.status === 401 && this.authProvider && !n) {
1109
+ this.resourceMetadataUrl = Ee(f);
1042
1110
  try {
1043
- if (await Re(this.authProvider, {
1111
+ if (await Ce(this.authProvider, {
1044
1112
  serverUrl: this.url,
1045
1113
  resourceMetadataUrl: this.resourceMetadataUrl
1046
1114
  }) !== "AUTHORIZED")
1047
- throw new Te();
1048
- } catch (b) {
1049
- throw (o = this.onerror) == null || o.call(this, b), b;
1115
+ throw new Re();
1116
+ } catch (w) {
1117
+ throw (o = this.onerror) == null || o.call(this, w), w;
1050
1118
  }
1051
1119
  return t(!0);
1052
1120
  }
1053
- if (m.status === 202) {
1121
+ if (f.status === 202) {
1054
1122
  this.inboundSseConnection || this.openInboundSse();
1055
1123
  return;
1056
1124
  }
1057
- if (!m.ok) {
1058
- const b = await m.text().catch(() => null);
1059
- let y = `MCP HTTP Transport Error: POSTing to endpoint (HTTP ${m.status}): ${b}`;
1060
- m.status === 404 && (y += ". This server does not support HTTP transport. Try using `sse` transport instead");
1061
- const T = new P({
1062
- message: y
1125
+ if (!f.ok) {
1126
+ const w = await f.text().catch(() => null);
1127
+ let b = `MCP HTTP Transport Error: POSTing to endpoint (HTTP ${f.status}): ${w}`;
1128
+ f.status === 404 && (b += ". This server does not support HTTP transport. Try using `sse` transport instead");
1129
+ const R = new O({
1130
+ message: b
1063
1131
  });
1064
- throw (a = this.onerror) == null || a.call(this, T), T;
1132
+ throw (a = this.onerror) == null || a.call(this, R), R;
1065
1133
  }
1066
- const g = m.headers.get("content-type") || "";
1067
- if (g.includes("application/json")) {
1068
- const b = await m.json(), y = Array.isArray(b) ? b.map((T) => ce.parse(T)) : [ce.parse(b)];
1069
- for (const T of y) (l = this.onmessage) == null || l.call(this, T);
1134
+ const m = f.headers.get("content-type") || "";
1135
+ if (m.includes("application/json")) {
1136
+ const w = await f.json(), b = Array.isArray(w) ? w.map((R) => pe.parse(R)) : [pe.parse(w)];
1137
+ for (const R of b) (i = this.onmessage) == null || i.call(this, R);
1070
1138
  return;
1071
1139
  }
1072
- if (g.includes("text/event-stream")) {
1073
- if (!m.body) {
1074
- const w = new P({
1140
+ if (m.includes("text/event-stream")) {
1141
+ if (!f.body) {
1142
+ const T = new O({
1075
1143
  message: "MCP HTTP Transport Error: text/event-stream response without body"
1076
1144
  });
1077
- throw (c = this.onerror) == null || c.call(this, w), w;
1145
+ throw (c = this.onerror) == null || c.call(this, T), T;
1078
1146
  }
1079
- const y = m.body.pipeThrough(new TextDecoderStream()).pipeThrough(new De()).getReader();
1147
+ const b = f.body.pipeThrough(new TextDecoderStream()).pipeThrough(new He()).getReader();
1080
1148
  (async () => {
1081
- var w, A, x;
1149
+ var T, S, M;
1082
1150
  try {
1083
1151
  for (; ; ) {
1084
- const { done: $, value: M } = await y.read();
1152
+ const { done: $, value: A } = await b.read();
1085
1153
  if ($) return;
1086
- const { event: H, data: W } = M;
1087
- if (H === "message")
1154
+ const { event: I, data: z } = A;
1155
+ if (I === "message")
1088
1156
  try {
1089
- const z = ce.parse(JSON.parse(W));
1090
- (w = this.onmessage) == null || w.call(this, z);
1091
- } catch (z) {
1092
- const G = new P({
1157
+ const J = pe.parse(JSON.parse(z));
1158
+ (T = this.onmessage) == null || T.call(this, J);
1159
+ } catch (J) {
1160
+ const G = new O({
1093
1161
  message: "MCP HTTP Transport Error: Failed to parse message",
1094
- cause: z
1162
+ cause: J
1095
1163
  });
1096
- (A = this.onerror) == null || A.call(this, G);
1164
+ (S = this.onerror) == null || S.call(this, G);
1097
1165
  }
1098
1166
  }
1099
1167
  } catch ($) {
1100
1168
  if ($ instanceof Error && $.name === "AbortError")
1101
1169
  return;
1102
- (x = this.onerror) == null || x.call(this, $);
1170
+ (M = this.onerror) == null || M.call(this, $);
1103
1171
  }
1104
1172
  })();
1105
1173
  return;
1106
1174
  }
1107
- const p = new P({
1108
- message: `MCP HTTP Transport Error: Unexpected content type: ${g}`
1175
+ const p = new O({
1176
+ message: `MCP HTTP Transport Error: Unexpected content type: ${m}`
1109
1177
  });
1110
- throw (i = this.onerror) == null || i.call(this, p), p;
1178
+ throw (l = this.onerror) == null || l.call(this, p), p;
1111
1179
  } catch (h) {
1112
1180
  throw (u = this.onerror) == null || u.call(this, h), h;
1113
1181
  }
@@ -1131,7 +1199,7 @@ var Nr = class {
1131
1199
  if (t > 0 && this.inboundReconnectAttempts >= t) {
1132
1200
  (e = this.onerror) == null || e.call(
1133
1201
  this,
1134
- new P({
1202
+ new O({
1135
1203
  message: `MCP HTTP Transport Error: Maximum reconnection attempts (${t}) exceeded.`
1136
1204
  })
1137
1205
  );
@@ -1145,30 +1213,30 @@ var Nr = class {
1145
1213
  }
1146
1214
  // Open optional inbound SSE stream; best-effort and resumable
1147
1215
  async openInboundSse(e = !1, t) {
1148
- var n, r, o, a, l, c;
1216
+ var n, r, o, a, i, c;
1149
1217
  try {
1150
- const i = await this.commonHeaders({
1218
+ const l = await this.commonHeaders({
1151
1219
  Accept: "text/event-stream"
1152
1220
  });
1153
- t && (i["last-event-id"] = t);
1221
+ t && (l["last-event-id"] = t);
1154
1222
  const u = await fetch(this.url.href, {
1155
1223
  method: "GET",
1156
- headers: i,
1224
+ headers: l,
1157
1225
  signal: (n = this.abortController) == null ? void 0 : n.signal
1158
1226
  }), h = u.headers.get("mcp-session-id");
1159
1227
  if (h && (this.sessionId = h), u.status === 401 && this.authProvider && !e) {
1160
- this.resourceMetadataUrl = Se(u);
1228
+ this.resourceMetadataUrl = Ee(u);
1161
1229
  try {
1162
- if (await Re(this.authProvider, {
1230
+ if (await Ce(this.authProvider, {
1163
1231
  serverUrl: this.url,
1164
1232
  resourceMetadataUrl: this.resourceMetadataUrl
1165
1233
  }) !== "AUTHORIZED") {
1166
- const p = new Te();
1234
+ const p = new Re();
1167
1235
  (r = this.onerror) == null || r.call(this, p);
1168
1236
  return;
1169
1237
  }
1170
- } catch (g) {
1171
- (o = this.onerror) == null || o.call(this, g);
1238
+ } catch (m) {
1239
+ (o = this.onerror) == null || o.call(this, m);
1172
1240
  return;
1173
1241
  }
1174
1242
  return this.openInboundSse(!0, t);
@@ -1176,79 +1244,79 @@ var Nr = class {
1176
1244
  if (u.status === 405)
1177
1245
  return;
1178
1246
  if (!u.ok || !u.body) {
1179
- const g = new P({
1247
+ const m = new O({
1180
1248
  message: `MCP HTTP Transport Error: GET SSE failed: ${u.status} ${u.statusText}`
1181
1249
  });
1182
- (a = this.onerror) == null || a.call(this, g);
1250
+ (a = this.onerror) == null || a.call(this, m);
1183
1251
  return;
1184
1252
  }
1185
- const m = u.body.pipeThrough(new TextDecoderStream()).pipeThrough(new De()).getReader(), _ = async () => {
1186
- var g, p, b, y;
1253
+ const f = u.body.pipeThrough(new TextDecoderStream()).pipeThrough(new He()).getReader(), v = async () => {
1254
+ var m, p, w, b;
1187
1255
  try {
1188
1256
  for (; ; ) {
1189
- const { done: T, value: w } = await m.read();
1190
- if (T) return;
1191
- const { event: A, data: x, id: $ } = w;
1192
- if ($ && (this.lastInboundEventId = $), A === "message")
1257
+ const { done: R, value: T } = await f.read();
1258
+ if (R) return;
1259
+ const { event: S, data: M, id: $ } = T;
1260
+ if ($ && (this.lastInboundEventId = $), S === "message")
1193
1261
  try {
1194
- const M = ce.parse(JSON.parse(x));
1195
- (g = this.onmessage) == null || g.call(this, M);
1196
- } catch (M) {
1197
- const H = new P({
1262
+ const A = pe.parse(JSON.parse(M));
1263
+ (m = this.onmessage) == null || m.call(this, A);
1264
+ } catch (A) {
1265
+ const I = new O({
1198
1266
  message: "MCP HTTP Transport Error: Failed to parse message",
1199
- cause: M
1267
+ cause: A
1200
1268
  });
1201
- (p = this.onerror) == null || p.call(this, H);
1269
+ (p = this.onerror) == null || p.call(this, I);
1202
1270
  }
1203
1271
  }
1204
- } catch (T) {
1205
- if (T instanceof Error && T.name === "AbortError")
1272
+ } catch (R) {
1273
+ if (R instanceof Error && R.name === "AbortError")
1206
1274
  return;
1207
- (b = this.onerror) == null || b.call(this, T), (y = this.abortController) != null && y.signal.aborted || this.scheduleInboundSseReconnection();
1275
+ (w = this.onerror) == null || w.call(this, R), (b = this.abortController) != null && b.signal.aborted || this.scheduleInboundSseReconnection();
1208
1276
  }
1209
1277
  };
1210
1278
  this.inboundSseConnection = {
1211
- close: () => m.cancel()
1212
- }, this.inboundReconnectAttempts = 0, _();
1213
- } catch (i) {
1214
- if (i instanceof Error && i.name === "AbortError")
1279
+ close: () => f.cancel()
1280
+ }, this.inboundReconnectAttempts = 0, v();
1281
+ } catch (l) {
1282
+ if (l instanceof Error && l.name === "AbortError")
1215
1283
  return;
1216
- (l = this.onerror) == null || l.call(this, i), (c = this.abortController) != null && c.signal.aborted || this.scheduleInboundSseReconnection();
1284
+ (i = this.onerror) == null || i.call(this, l), (c = this.abortController) != null && c.signal.aborted || this.scheduleInboundSseReconnection();
1217
1285
  }
1218
1286
  }
1219
1287
  };
1220
- function jr(e) {
1288
+ function Jr(e) {
1221
1289
  switch (e.type) {
1222
1290
  case "sse":
1223
- return new Nr(e);
1291
+ return new Vr(e);
1224
1292
  case "http":
1225
- return new Dr(e);
1293
+ return new Br(e);
1226
1294
  default:
1227
- throw new P({
1295
+ throw new O({
1228
1296
  message: "Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."
1229
1297
  });
1230
1298
  }
1231
1299
  }
1232
- function qr(e) {
1300
+ function zr(e) {
1233
1301
  return "start" in e && typeof e.start == "function" && "send" in e && typeof e.send == "function" && "close" in e && typeof e.close == "function";
1234
1302
  }
1235
- var Hr = "1.0.0";
1236
- async function Lr(e) {
1237
- const t = new Vr(e);
1303
+ var Gr = "1.0.0";
1304
+ async function Wr(e) {
1305
+ const t = new Fr(e);
1238
1306
  return await t.init(), t;
1239
1307
  }
1240
- var Vr = class {
1308
+ var Fr = class {
1241
1309
  constructor({
1242
1310
  transport: e,
1243
1311
  name: t = "ai-sdk-mcp-client",
1244
- version: n = Hr,
1312
+ version: n = Gr,
1245
1313
  onUncaughtError: r,
1246
1314
  capabilities: o
1247
1315
  }) {
1248
- this.requestMessageId = 0, this.responseHandlers = /* @__PURE__ */ new Map(), this.serverCapabilities = {}, this.isClosed = !0, this.onUncaughtError = r, this.clientCapabilities = o ?? {}, qr(e) ? this.transport = e : this.transport = jr(e), this.transport.onclose = () => this.onClose(), this.transport.onerror = (a) => this.onError(a), this.transport.onmessage = (a) => {
1316
+ this.requestMessageId = 0, this.responseHandlers = /* @__PURE__ */ new Map(), this.serverCapabilities = {}, this.isClosed = !0, this.onUncaughtError = r, this.clientCapabilities = o ?? {}, zr(e) ? this.transport = e : this.transport = Jr(e), this.transport.onclose = () => this.onClose(), this.transport.onerror = (a) => this.onError(a), this.transport.onmessage = (a) => {
1249
1317
  if ("method" in a) {
1250
1318
  "id" in a ? this.onRequestMessage(a) : this.onError(
1251
- new P({
1319
+ new O({
1252
1320
  message: "Unsupported message type"
1253
1321
  })
1254
1322
  );
@@ -1267,19 +1335,19 @@ var Vr = class {
1267
1335
  request: {
1268
1336
  method: "initialize",
1269
1337
  params: {
1270
- protocolVersion: ie,
1338
+ protocolVersion: ue,
1271
1339
  capabilities: this.clientCapabilities,
1272
1340
  clientInfo: this.clientInfo
1273
1341
  }
1274
1342
  },
1275
- resultSchema: Jn
1343
+ resultSchema: Zn
1276
1344
  });
1277
1345
  if (e === void 0)
1278
- throw new P({
1346
+ throw new O({
1279
1347
  message: "Server sent invalid initialize result"
1280
1348
  });
1281
- if (!Ln.includes(e.protocolVersion))
1282
- throw new P({
1349
+ if (!Wn.includes(e.protocolVersion))
1350
+ throw new O({
1283
1351
  message: `Server's protocol version is not supported: ${e.protocolVersion}`
1284
1352
  });
1285
1353
  return this.serverCapabilities = e.capabilities, await this.notification({
@@ -1300,7 +1368,7 @@ var Vr = class {
1300
1368
  case "tools/list":
1301
1369
  case "tools/call":
1302
1370
  if (!this.serverCapabilities.tools)
1303
- throw new P({
1371
+ throw new O({
1304
1372
  message: "Server does not support tools"
1305
1373
  });
1306
1374
  break;
@@ -1308,19 +1376,19 @@ var Vr = class {
1308
1376
  case "resources/read":
1309
1377
  case "resources/templates/list":
1310
1378
  if (!this.serverCapabilities.resources)
1311
- throw new P({
1379
+ throw new O({
1312
1380
  message: "Server does not support resources"
1313
1381
  });
1314
1382
  break;
1315
1383
  case "prompts/list":
1316
1384
  case "prompts/get":
1317
1385
  if (!this.serverCapabilities.prompts)
1318
- throw new P({
1386
+ throw new O({
1319
1387
  message: "Server does not support prompts"
1320
1388
  });
1321
1389
  break;
1322
1390
  default:
1323
- throw new P({
1391
+ throw new O({
1324
1392
  message: `Unsupported method: ${e}`
1325
1393
  });
1326
1394
  }
@@ -1333,24 +1401,24 @@ var Vr = class {
1333
1401
  return new Promise((r, o) => {
1334
1402
  if (this.isClosed)
1335
1403
  return o(
1336
- new P({
1404
+ new O({
1337
1405
  message: "Attempted to send a request from a closed client"
1338
1406
  })
1339
1407
  );
1340
1408
  this.assertCapability(e.method);
1341
1409
  const a = n?.signal;
1342
1410
  a?.throwIfAborted();
1343
- const l = this.requestMessageId++, c = {
1411
+ const i = this.requestMessageId++, c = {
1344
1412
  ...e,
1345
1413
  jsonrpc: "2.0",
1346
- id: l
1347
- }, i = () => {
1348
- this.responseHandlers.delete(l);
1414
+ id: i
1415
+ }, l = () => {
1416
+ this.responseHandlers.delete(i);
1349
1417
  };
1350
- this.responseHandlers.set(l, (u) => {
1418
+ this.responseHandlers.set(i, (u) => {
1351
1419
  if (a?.aborted)
1352
1420
  return o(
1353
- new P({
1421
+ new O({
1354
1422
  message: "Request was aborted",
1355
1423
  cause: a.reason
1356
1424
  })
@@ -1361,14 +1429,14 @@ var Vr = class {
1361
1429
  const h = t.parse(u.result);
1362
1430
  r(h);
1363
1431
  } catch (h) {
1364
- const f = new P({
1432
+ const g = new O({
1365
1433
  message: "Failed to parse server response",
1366
1434
  cause: h
1367
1435
  });
1368
- o(f);
1436
+ o(g);
1369
1437
  }
1370
1438
  }), this.transport.send(c).catch((u) => {
1371
- i(), o(u);
1439
+ l(), o(u);
1372
1440
  });
1373
1441
  });
1374
1442
  }
@@ -1379,7 +1447,7 @@ var Vr = class {
1379
1447
  try {
1380
1448
  return this.request({
1381
1449
  request: { method: "tools/list", params: e },
1382
- resultSchema: Wn,
1450
+ resultSchema: Yn,
1383
1451
  options: t
1384
1452
  });
1385
1453
  } catch (n) {
@@ -1394,7 +1462,7 @@ var Vr = class {
1394
1462
  try {
1395
1463
  return this.request({
1396
1464
  request: { method: "tools/call", params: { name: e, arguments: t } },
1397
- resultSchema: Kn,
1465
+ resultSchema: tr,
1398
1466
  options: {
1399
1467
  signal: n?.abortSignal
1400
1468
  }
@@ -1410,7 +1478,7 @@ var Vr = class {
1410
1478
  try {
1411
1479
  return this.request({
1412
1480
  request: { method: "resources/list", params: e },
1413
- resultSchema: Fn,
1481
+ resultSchema: er,
1414
1482
  options: t
1415
1483
  });
1416
1484
  } catch (n) {
@@ -1424,7 +1492,7 @@ var Vr = class {
1424
1492
  try {
1425
1493
  return this.request({
1426
1494
  request: { method: "resources/read", params: { uri: e } },
1427
- resultSchema: Yn,
1495
+ resultSchema: or,
1428
1496
  options: t
1429
1497
  });
1430
1498
  } catch (n) {
@@ -1437,7 +1505,7 @@ var Vr = class {
1437
1505
  try {
1438
1506
  return this.request({
1439
1507
  request: { method: "resources/templates/list" },
1440
- resultSchema: Xn,
1508
+ resultSchema: rr,
1441
1509
  options: e
1442
1510
  });
1443
1511
  } catch (t) {
@@ -1451,7 +1519,7 @@ var Vr = class {
1451
1519
  try {
1452
1520
  return this.request({
1453
1521
  request: { method: "prompts/list", params: e },
1454
- resultSchema: tr,
1522
+ resultSchema: ir,
1455
1523
  options: t
1456
1524
  });
1457
1525
  } catch (n) {
@@ -1466,7 +1534,7 @@ var Vr = class {
1466
1534
  try {
1467
1535
  return this.request({
1468
1536
  request: { method: "prompts/get", params: { name: e, arguments: t } },
1469
- resultSchema: rr,
1537
+ resultSchema: cr,
1470
1538
  options: n
1471
1539
  });
1472
1540
  } catch (r) {
@@ -1491,25 +1559,25 @@ var Vr = class {
1491
1559
  const n = {};
1492
1560
  try {
1493
1561
  const r = await this.listTools();
1494
- for (const { name: o, description: a, inputSchema: l } of r.tools) {
1562
+ for (const { name: o, description: a, inputSchema: i } of r.tools) {
1495
1563
  if (e !== "automatic" && !(o in e))
1496
1564
  continue;
1497
- const c = this, i = async (h, f) => {
1498
- var m;
1499
- return (m = f?.abortSignal) == null || m.throwIfAborted(), c.callTool({ name: o, args: h, options: f });
1500
- }, u = e === "automatic" ? Rn({
1565
+ const c = this, l = async (h, g) => {
1566
+ var f;
1567
+ return (f = g?.abortSignal) == null || f.throwIfAborted(), c.callTool({ name: o, args: h, options: g });
1568
+ }, u = e === "automatic" ? jn({
1501
1569
  description: a,
1502
- inputSchema: mt({
1503
- ...l,
1504
- properties: (t = l.properties) != null ? t : {},
1570
+ inputSchema: Hn({
1571
+ ...i,
1572
+ properties: (t = i.properties) != null ? t : {},
1505
1573
  additionalProperties: !1
1506
1574
  }),
1507
- execute: i
1508
- }) : En({
1575
+ execute: l
1576
+ }) : {
1509
1577
  description: a,
1510
1578
  inputSchema: e[o].inputSchema,
1511
- execute: i
1512
- });
1579
+ execute: l
1580
+ };
1513
1581
  n[o] = u;
1514
1582
  }
1515
1583
  return n;
@@ -1548,8 +1616,8 @@ var Vr = class {
1548
1616
  return this.getPromptInternal({ name: e, args: t, options: n });
1549
1617
  }
1550
1618
  onElicitationRequest(e, t) {
1551
- if (e !== rt)
1552
- throw new P({
1619
+ if (e !== st)
1620
+ throw new O({
1553
1621
  message: "Unsupported request schema. Only ElicitationRequestSchema is supported."
1554
1622
  });
1555
1623
  this.elicitationRequestHandler = t;
@@ -1578,7 +1646,7 @@ var Vr = class {
1578
1646
  });
1579
1647
  return;
1580
1648
  }
1581
- const t = rt.safeParse({
1649
+ const t = st.safeParse({
1582
1650
  method: e.method,
1583
1651
  params: e.params
1584
1652
  });
@@ -1595,7 +1663,7 @@ var Vr = class {
1595
1663
  return;
1596
1664
  }
1597
1665
  try {
1598
- const n = await this.elicitationRequestHandler(t.data), r = sr.parse(n);
1666
+ const n = await this.elicitationRequestHandler(t.data), r = dr.parse(n);
1599
1667
  await this.transport.send({
1600
1668
  jsonrpc: "2.0",
1601
1669
  id: e.id,
@@ -1618,7 +1686,7 @@ var Vr = class {
1618
1686
  onClose() {
1619
1687
  if (this.isClosed) return;
1620
1688
  this.isClosed = !0;
1621
- const e = new P({
1689
+ const e = new O({
1622
1690
  message: "Connection closed"
1623
1691
  });
1624
1692
  for (const t of this.responseHandlers.values())
@@ -1631,13 +1699,13 @@ var Vr = class {
1631
1699
  onResponse(e) {
1632
1700
  const t = Number(e.id), n = this.responseHandlers.get(t);
1633
1701
  if (n === void 0)
1634
- throw new P({
1702
+ throw new O({
1635
1703
  message: `Protocol error: Received a response for an unknown message ID: ${JSON.stringify(
1636
1704
  e
1637
1705
  )}`
1638
1706
  });
1639
1707
  this.responseHandlers.delete(t), n(
1640
- "result" in e ? e : new P({
1708
+ "result" in e ? e : new O({
1641
1709
  message: e.error.message,
1642
1710
  code: e.error.code,
1643
1711
  data: e.error.data,
@@ -1645,14 +1713,14 @@ var Vr = class {
1645
1713
  })
1646
1714
  );
1647
1715
  }
1648
- }, Br = Object.defineProperty, Jr = Object.defineProperties, zr = Object.getOwnPropertyDescriptors, it = Object.getOwnPropertySymbols, Wr = Object.prototype.hasOwnProperty, Gr = Object.prototype.propertyIsEnumerable, lt = (e, t, n) => t in e ? Br(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, O = (e, t) => {
1716
+ }, Kr = Object.defineProperty, Zr = Object.defineProperties, Xr = Object.getOwnPropertyDescriptors, ct = Object.getOwnPropertySymbols, Yr = Object.prototype.hasOwnProperty, Qr = Object.prototype.propertyIsEnumerable, ut = (e, t, n) => t in e ? Kr(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, P = (e, t) => {
1649
1717
  for (var n in t || (t = {}))
1650
- Wr.call(t, n) && lt(e, n, t[n]);
1651
- if (it)
1652
- for (var n of it(t))
1653
- Gr.call(t, n) && lt(e, n, t[n]);
1718
+ Yr.call(t, n) && ut(e, n, t[n]);
1719
+ if (ct)
1720
+ for (var n of ct(t))
1721
+ Qr.call(t, n) && ut(e, n, t[n]);
1654
1722
  return e;
1655
- }, Ee = (e, t) => Jr(e, zr(t)), $t = "vercel.ai.error", Fr = Symbol.for($t), Mt, Kr = class Nt extends Error {
1723
+ }, xe = (e, t) => Zr(e, Xr(t)), Ut = "vercel.ai.error", eo = Symbol.for(Ut), Mt, to = class Nt extends Error {
1656
1724
  /**
1657
1725
  * Creates an AI SDK Error.
1658
1726
  *
@@ -1674,15 +1742,15 @@ var Vr = class {
1674
1742
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
1675
1743
  */
1676
1744
  static isInstance(t) {
1677
- return Nt.hasMarker(t, $t);
1745
+ return Nt.hasMarker(t, Ut);
1678
1746
  }
1679
1747
  static hasMarker(t, n) {
1680
1748
  const r = Symbol.for(n);
1681
1749
  return t != null && typeof t == "object" && r in t && typeof t[r] == "boolean" && t[r] === !0;
1682
1750
  }
1683
1751
  };
1684
- Mt = Fr;
1685
- var q = Kr, Dt = "AI_APICallError", jt = `vercel.ai.error.${Dt}`, Zr = Symbol.for(jt), qt, K = class extends q {
1752
+ Mt = eo;
1753
+ var L = to, jt = "AI_APICallError", Dt = `vercel.ai.error.${jt}`, no = Symbol.for(Dt), Ht, F = class extends L {
1686
1754
  constructor({
1687
1755
  message: e,
1688
1756
  url: t,
@@ -1690,48 +1758,48 @@ var q = Kr, Dt = "AI_APICallError", jt = `vercel.ai.error.${Dt}`, Zr = Symbol.fo
1690
1758
  statusCode: r,
1691
1759
  responseHeaders: o,
1692
1760
  responseBody: a,
1693
- cause: l,
1761
+ cause: i,
1694
1762
  isRetryable: c = r != null && (r === 408 || // request timeout
1695
1763
  r === 409 || // conflict
1696
1764
  r === 429 || // too many requests
1697
1765
  r >= 500),
1698
1766
  // server error
1699
- data: i
1767
+ data: l
1700
1768
  }) {
1701
- super({ name: Dt, message: e, cause: l }), this[qt] = !0, this.url = t, this.requestBodyValues = n, this.statusCode = r, this.responseHeaders = o, this.responseBody = a, this.isRetryable = c, this.data = i;
1769
+ super({ name: jt, message: e, cause: i }), this[Ht] = !0, this.url = t, this.requestBodyValues = n, this.statusCode = r, this.responseHeaders = o, this.responseBody = a, this.isRetryable = c, this.data = l;
1702
1770
  }
1703
1771
  static isInstance(e) {
1704
- return q.hasMarker(e, jt);
1772
+ return L.hasMarker(e, Dt);
1705
1773
  }
1706
1774
  };
1707
- qt = Zr;
1708
- var Ht = "AI_EmptyResponseBodyError", Lt = `vercel.ai.error.${Ht}`, Xr = Symbol.for(Lt), Vt, Yr = class extends q {
1775
+ Ht = no;
1776
+ var Lt = "AI_EmptyResponseBodyError", qt = `vercel.ai.error.${Lt}`, ro = Symbol.for(qt), Vt, oo = class extends L {
1709
1777
  // used in isInstance
1710
1778
  constructor({ message: e = "Empty response body" } = {}) {
1711
- super({ name: Ht, message: e }), this[Vt] = !0;
1779
+ super({ name: Lt, message: e }), this[Vt] = !0;
1712
1780
  }
1713
1781
  static isInstance(e) {
1714
- return q.hasMarker(e, Lt);
1782
+ return L.hasMarker(e, qt);
1715
1783
  }
1716
1784
  };
1717
- Vt = Xr;
1785
+ Vt = ro;
1718
1786
  function Bt(e) {
1719
1787
  return e == null ? "unknown error" : typeof e == "string" ? e : e instanceof Error ? e.message : JSON.stringify(e);
1720
1788
  }
1721
- var Jt = "AI_InvalidArgumentError", zt = `vercel.ai.error.${Jt}`, Qr = Symbol.for(zt), Wt, Gt = class extends q {
1789
+ var Jt = "AI_InvalidArgumentError", zt = `vercel.ai.error.${Jt}`, so = Symbol.for(zt), Gt, Wt = class extends L {
1722
1790
  constructor({
1723
1791
  message: e,
1724
1792
  cause: t,
1725
1793
  argument: n
1726
1794
  }) {
1727
- super({ name: Jt, message: e, cause: t }), this[Wt] = !0, this.argument = n;
1795
+ super({ name: Jt, message: e, cause: t }), this[Gt] = !0, this.argument = n;
1728
1796
  }
1729
1797
  static isInstance(e) {
1730
- return q.hasMarker(e, zt);
1798
+ return L.hasMarker(e, zt);
1731
1799
  }
1732
1800
  };
1733
- Wt = Qr;
1734
- var Ft = "AI_InvalidPromptError", Kt = `vercel.ai.error.${Ft}`, eo = Symbol.for(Kt), Zt, to = class extends q {
1801
+ Gt = so;
1802
+ var Ft = "AI_InvalidPromptError", Kt = `vercel.ai.error.${Ft}`, ao = Symbol.for(Kt), Zt, io = class extends L {
1735
1803
  constructor({
1736
1804
  prompt: e,
1737
1805
  message: t,
@@ -1740,11 +1808,11 @@ var Ft = "AI_InvalidPromptError", Kt = `vercel.ai.error.${Ft}`, eo = Symbol.for(
1740
1808
  super({ name: Ft, message: `Invalid prompt: ${t}`, cause: n }), this[Zt] = !0, this.prompt = e;
1741
1809
  }
1742
1810
  static isInstance(e) {
1743
- return q.hasMarker(e, Kt);
1811
+ return L.hasMarker(e, Kt);
1744
1812
  }
1745
1813
  };
1746
- Zt = eo;
1747
- var Xt = "AI_InvalidResponseDataError", Yt = `vercel.ai.error.${Xt}`, no = Symbol.for(Yt), Qt, le = class extends q {
1814
+ Zt = ao;
1815
+ var Xt = "AI_InvalidResponseDataError", Yt = `vercel.ai.error.${Xt}`, lo = Symbol.for(Yt), Qt, de = class extends L {
1748
1816
  constructor({
1749
1817
  data: e,
1750
1818
  message: t = `Invalid response data: ${JSON.stringify(e)}.`
@@ -1752,11 +1820,11 @@ var Xt = "AI_InvalidResponseDataError", Yt = `vercel.ai.error.${Xt}`, no = Symbo
1752
1820
  super({ name: Xt, message: t }), this[Qt] = !0, this.data = e;
1753
1821
  }
1754
1822
  static isInstance(e) {
1755
- return q.hasMarker(e, Yt);
1823
+ return L.hasMarker(e, Yt);
1756
1824
  }
1757
1825
  };
1758
- Qt = no;
1759
- var en = "AI_JSONParseError", tn = `vercel.ai.error.${en}`, ro = Symbol.for(tn), nn, Ce = class extends q {
1826
+ Qt = lo;
1827
+ var en = "AI_JSONParseError", tn = `vercel.ai.error.${en}`, co = Symbol.for(tn), nn, Ie = class extends L {
1760
1828
  constructor({ text: e, cause: t }) {
1761
1829
  super({
1762
1830
  name: en,
@@ -1766,21 +1834,21 @@ Error message: ${Bt(t)}`,
1766
1834
  }), this[nn] = !0, this.text = e;
1767
1835
  }
1768
1836
  static isInstance(e) {
1769
- return q.hasMarker(e, tn);
1837
+ return L.hasMarker(e, tn);
1770
1838
  }
1771
1839
  };
1772
- nn = ro;
1773
- var rn = "AI_LoadAPIKeyError", on = `vercel.ai.error.${rn}`, oo = Symbol.for(on), sn, _e = class extends q {
1840
+ nn = co;
1841
+ var rn = "AI_LoadAPIKeyError", on = `vercel.ai.error.${rn}`, uo = Symbol.for(on), sn, ye = class extends L {
1774
1842
  // used in isInstance
1775
1843
  constructor({ message: e }) {
1776
1844
  super({ name: rn, message: e }), this[sn] = !0;
1777
1845
  }
1778
1846
  static isInstance(e) {
1779
- return q.hasMarker(e, on);
1847
+ return L.hasMarker(e, on);
1780
1848
  }
1781
1849
  };
1782
- sn = oo;
1783
- var an = "AI_NoContentGeneratedError", ln = `vercel.ai.error.${an}`, so = Symbol.for(ln), cn, un = class extends q {
1850
+ sn = uo;
1851
+ var an = "AI_NoContentGeneratedError", ln = `vercel.ai.error.${an}`, po = Symbol.for(ln), cn, un = class extends L {
1784
1852
  // used in isInstance
1785
1853
  constructor({
1786
1854
  message: e = "No content generated."
@@ -1788,11 +1856,11 @@ var an = "AI_NoContentGeneratedError", ln = `vercel.ai.error.${an}`, so = Symbol
1788
1856
  super({ name: an, message: e }), this[cn] = !0;
1789
1857
  }
1790
1858
  static isInstance(e) {
1791
- return q.hasMarker(e, ln);
1859
+ return L.hasMarker(e, ln);
1792
1860
  }
1793
1861
  };
1794
- cn = so;
1795
- var dn = "AI_TypeValidationError", pn = `vercel.ai.error.${dn}`, ao = Symbol.for(pn), hn, io = class je extends q {
1862
+ cn = po;
1863
+ var dn = "AI_TypeValidationError", pn = `vercel.ai.error.${dn}`, ho = Symbol.for(pn), hn, mo = class Le extends L {
1796
1864
  constructor({ value: t, cause: n }) {
1797
1865
  super({
1798
1866
  name: dn,
@@ -1802,7 +1870,7 @@ Error message: ${Bt(n)}`,
1802
1870
  }), this[hn] = !0, this.value = t;
1803
1871
  }
1804
1872
  static isInstance(t) {
1805
- return q.hasMarker(t, pn);
1873
+ return L.hasMarker(t, pn);
1806
1874
  }
1807
1875
  /**
1808
1876
  * Wraps an error into a TypeValidationError.
@@ -1818,129 +1886,129 @@ Error message: ${Bt(n)}`,
1818
1886
  value: t,
1819
1887
  cause: n
1820
1888
  }) {
1821
- return je.isInstance(n) && n.value === t ? n : new je({ value: t, cause: n });
1889
+ return Le.isInstance(n) && n.value === t ? n : new Le({ value: t, cause: n });
1822
1890
  }
1823
1891
  };
1824
- hn = ao;
1825
- var ue = io, mn = "AI_UnsupportedFunctionalityError", gn = `vercel.ai.error.${mn}`, lo = Symbol.for(gn), fn, ee = class extends q {
1892
+ hn = ho;
1893
+ var he = mo, mn = "AI_UnsupportedFunctionalityError", fn = `vercel.ai.error.${mn}`, fo = Symbol.for(fn), gn, te = class extends L {
1826
1894
  constructor({
1827
1895
  functionality: e,
1828
1896
  message: t = `'${e}' functionality not supported.`
1829
1897
  }) {
1830
- super({ name: mn, message: t }), this[fn] = !0, this.functionality = e;
1898
+ super({ name: mn, message: t }), this[gn] = !0, this.functionality = e;
1831
1899
  }
1832
1900
  static isInstance(e) {
1833
- return q.hasMarker(e, gn);
1901
+ return L.hasMarker(e, fn);
1834
1902
  }
1835
1903
  };
1836
- fn = lo;
1837
- var ct = class extends Error {
1904
+ gn = fo;
1905
+ var dt = class extends Error {
1838
1906
  constructor(e, t) {
1839
1907
  super(e), this.name = "ParseError", this.type = t.type, this.field = t.field, this.value = t.value, this.line = t.line;
1840
1908
  }
1841
1909
  };
1842
- function $e(e) {
1910
+ function Ne(e) {
1843
1911
  }
1844
- function co(e) {
1912
+ function go(e) {
1845
1913
  if (typeof e == "function")
1846
1914
  throw new TypeError(
1847
1915
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
1848
1916
  );
1849
- const { onEvent: t = $e, onError: n = $e, onRetry: r = $e, onComment: o } = e;
1850
- let a = "", l = !0, c, i = "", u = "";
1917
+ const { onEvent: t = Ne, onError: n = Ne, onRetry: r = Ne, onComment: o } = e;
1918
+ let a = "", i = !0, c, l = "", u = "";
1851
1919
  function h(p) {
1852
- const b = l ? p.replace(/^\xEF\xBB\xBF/, "") : p, [y, T] = uo(`${a}${b}`);
1853
- for (const w of y)
1854
- f(w);
1855
- a = T, l = !1;
1920
+ const w = i ? p.replace(/^\xEF\xBB\xBF/, "") : p, [b, R] = _o(`${a}${w}`);
1921
+ for (const T of b)
1922
+ g(T);
1923
+ a = R, i = !1;
1856
1924
  }
1857
- function f(p) {
1925
+ function g(p) {
1858
1926
  if (p === "") {
1859
- _();
1927
+ v();
1860
1928
  return;
1861
1929
  }
1862
1930
  if (p.startsWith(":")) {
1863
1931
  o && o(p.slice(p.startsWith(": ") ? 2 : 1));
1864
1932
  return;
1865
1933
  }
1866
- const b = p.indexOf(":");
1867
- if (b !== -1) {
1868
- const y = p.slice(0, b), T = p[b + 1] === " " ? 2 : 1, w = p.slice(b + T);
1869
- m(y, w, p);
1934
+ const w = p.indexOf(":");
1935
+ if (w !== -1) {
1936
+ const b = p.slice(0, w), R = p[w + 1] === " " ? 2 : 1, T = p.slice(w + R);
1937
+ f(b, T, p);
1870
1938
  return;
1871
1939
  }
1872
- m(p, "", p);
1940
+ f(p, "", p);
1873
1941
  }
1874
- function m(p, b, y) {
1942
+ function f(p, w, b) {
1875
1943
  switch (p) {
1876
1944
  case "event":
1877
- u = b;
1945
+ u = w;
1878
1946
  break;
1879
1947
  case "data":
1880
- i = `${i}${b}
1948
+ l = `${l}${w}
1881
1949
  `;
1882
1950
  break;
1883
1951
  case "id":
1884
- c = b.includes("\0") ? void 0 : b;
1952
+ c = w.includes("\0") ? void 0 : w;
1885
1953
  break;
1886
1954
  case "retry":
1887
- /^\d+$/.test(b) ? r(parseInt(b, 10)) : n(
1888
- new ct(`Invalid \`retry\` value: "${b}"`, {
1955
+ /^\d+$/.test(w) ? r(parseInt(w, 10)) : n(
1956
+ new dt(`Invalid \`retry\` value: "${w}"`, {
1889
1957
  type: "invalid-retry",
1890
- value: b,
1891
- line: y
1958
+ value: w,
1959
+ line: b
1892
1960
  })
1893
1961
  );
1894
1962
  break;
1895
1963
  default:
1896
1964
  n(
1897
- new ct(
1965
+ new dt(
1898
1966
  `Unknown field "${p.length > 20 ? `${p.slice(0, 20)}…` : p}"`,
1899
- { type: "unknown-field", field: p, value: b, line: y }
1967
+ { type: "unknown-field", field: p, value: w, line: b }
1900
1968
  )
1901
1969
  );
1902
1970
  break;
1903
1971
  }
1904
1972
  }
1905
- function _() {
1906
- i.length > 0 && t({
1973
+ function v() {
1974
+ l.length > 0 && t({
1907
1975
  id: c,
1908
1976
  event: u || void 0,
1909
1977
  // If the data buffer's last character is a U+000A LINE FEED (LF) character,
1910
1978
  // then remove the last character from the data buffer.
1911
- data: i.endsWith(`
1912
- `) ? i.slice(0, -1) : i
1913
- }), c = void 0, i = "", u = "";
1979
+ data: l.endsWith(`
1980
+ `) ? l.slice(0, -1) : l
1981
+ }), c = void 0, l = "", u = "";
1914
1982
  }
1915
- function g(p = {}) {
1916
- a && p.consume && f(a), l = !0, c = void 0, i = "", u = "", a = "";
1983
+ function m(p = {}) {
1984
+ a && p.consume && g(a), i = !0, c = void 0, l = "", u = "", a = "";
1917
1985
  }
1918
- return { feed: h, reset: g };
1986
+ return { feed: h, reset: m };
1919
1987
  }
1920
- function uo(e) {
1988
+ function _o(e) {
1921
1989
  const t = [];
1922
1990
  let n = "", r = 0;
1923
1991
  for (; r < e.length; ) {
1924
1992
  const o = e.indexOf("\r", r), a = e.indexOf(`
1925
1993
  `, r);
1926
- let l = -1;
1927
- if (o !== -1 && a !== -1 ? l = Math.min(o, a) : o !== -1 ? l = o : a !== -1 && (l = a), l === -1) {
1994
+ let i = -1;
1995
+ if (o !== -1 && a !== -1 ? i = Math.min(o, a) : o !== -1 ? i = o : a !== -1 && (i = a), i === -1) {
1928
1996
  n = e.slice(r);
1929
1997
  break;
1930
1998
  } else {
1931
- const c = e.slice(r, l);
1932
- t.push(c), r = l + 1, e[r - 1] === "\r" && e[r] === `
1999
+ const c = e.slice(r, i);
2000
+ t.push(c), r = i + 1, e[r - 1] === "\r" && e[r] === `
1933
2001
  ` && r++;
1934
2002
  }
1935
2003
  }
1936
2004
  return [t, n];
1937
2005
  }
1938
- var po = class extends TransformStream {
2006
+ var vo = class extends TransformStream {
1939
2007
  constructor({ onError: e, onRetry: t, onComment: n } = {}) {
1940
2008
  let r;
1941
2009
  super({
1942
2010
  start(o) {
1943
- r = co({
2011
+ r = go({
1944
2012
  onEvent: (a) => {
1945
2013
  o.enqueue(a);
1946
2014
  },
@@ -1958,52 +2026,52 @@ var po = class extends TransformStream {
1958
2026
  }
1959
2027
  };
1960
2028
  new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
1961
- function de(...e) {
2029
+ function me(...e) {
1962
2030
  return e.reduce(
1963
- (t, n) => O(O({}, t), n ?? {}),
2031
+ (t, n) => P(P({}, t), n ?? {}),
1964
2032
  {}
1965
2033
  );
1966
2034
  }
1967
- function Oe(e) {
2035
+ function $e(e) {
1968
2036
  return Object.fromEntries([...e.headers]);
1969
2037
  }
1970
- var ho = ({
2038
+ var yo = ({
1971
2039
  prefix: e,
1972
2040
  size: t = 16,
1973
2041
  alphabet: n = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
1974
2042
  separator: r = "-"
1975
2043
  } = {}) => {
1976
2044
  const o = () => {
1977
- const a = n.length, l = new Array(t);
2045
+ const a = n.length, i = new Array(t);
1978
2046
  for (let c = 0; c < t; c++)
1979
- l[c] = n[Math.random() * a | 0];
1980
- return l.join("");
2047
+ i[c] = n[Math.random() * a | 0];
2048
+ return i.join("");
1981
2049
  };
1982
2050
  if (e == null)
1983
2051
  return o;
1984
2052
  if (n.includes(r))
1985
- throw new Gt({
2053
+ throw new Wt({
1986
2054
  argument: "separator",
1987
2055
  message: `The separator "${r}" must not be part of the alphabet "${n}".`
1988
2056
  });
1989
2057
  return () => `${e}${r}${o()}`;
1990
- }, F = ho();
2058
+ }, W = yo();
1991
2059
  function qe(e) {
1992
2060
  return (e instanceof Error || e instanceof DOMException) && (e.name === "AbortError" || e.name === "ResponseAborted" || // Next.js
1993
2061
  e.name === "TimeoutError");
1994
2062
  }
1995
- var mo = ["fetch failed", "failed to fetch"];
1996
- function go({
2063
+ var wo = ["fetch failed", "failed to fetch"];
2064
+ function bo({
1997
2065
  error: e,
1998
2066
  url: t,
1999
2067
  requestBodyValues: n
2000
2068
  }) {
2001
2069
  if (qe(e))
2002
2070
  return e;
2003
- if (e instanceof TypeError && mo.includes(e.message.toLowerCase())) {
2071
+ if (e instanceof TypeError && wo.includes(e.message.toLowerCase())) {
2004
2072
  const r = e.cause;
2005
2073
  if (r != null)
2006
- return new K({
2074
+ return new F({
2007
2075
  message: `Cannot connect to API: ${r.message}`,
2008
2076
  cause: r,
2009
2077
  url: t,
@@ -2014,12 +2082,12 @@ function go({
2014
2082
  }
2015
2083
  return e;
2016
2084
  }
2017
- function fo(e) {
2085
+ function ko(e) {
2018
2086
  return Object.fromEntries(
2019
2087
  Object.entries(e).filter(([t, n]) => n != null)
2020
2088
  );
2021
2089
  }
2022
- function _o({
2090
+ function To({
2023
2091
  apiKey: e,
2024
2092
  environmentVariableName: t,
2025
2093
  apiKeyParameterName: n = "apiKey",
@@ -2028,29 +2096,29 @@ function _o({
2028
2096
  if (typeof e == "string")
2029
2097
  return e;
2030
2098
  if (e != null)
2031
- throw new _e({
2099
+ throw new ye({
2032
2100
  message: `${r} API key must be a string.`
2033
2101
  });
2034
2102
  if (typeof process > "u")
2035
- throw new _e({
2103
+ throw new ye({
2036
2104
  message: `${r} API key is missing. Pass it using the '${n}' parameter. Environment variables is not supported in this environment.`
2037
2105
  });
2038
2106
  if (e = process.env[t], e == null)
2039
- throw new _e({
2107
+ throw new ye({
2040
2108
  message: `${r} API key is missing. Pass it using the '${n}' parameter or the ${t} environment variable.`
2041
2109
  });
2042
2110
  if (typeof e != "string")
2043
- throw new _e({
2111
+ throw new ye({
2044
2112
  message: `${r} API key must be a string. The value of the ${t} environment variable is not a string.`
2045
2113
  });
2046
2114
  return e;
2047
2115
  }
2048
- var vo = /"__proto__"\s*:/, yo = /"constructor"\s*:/;
2049
- function wo(e) {
2116
+ var So = /"__proto__"\s*:/, Ro = /"constructor"\s*:/;
2117
+ function Eo(e) {
2050
2118
  const t = JSON.parse(e);
2051
- return t === null || typeof t != "object" || vo.test(e) === !1 && yo.test(e) === !1 ? t : bo(t);
2119
+ return t === null || typeof t != "object" || So.test(e) === !1 && Ro.test(e) === !1 ? t : Co(t);
2052
2120
  }
2053
- function bo(e) {
2121
+ function Co(e) {
2054
2122
  let t = [e];
2055
2123
  for (; t.length; ) {
2056
2124
  const n = t;
@@ -2068,77 +2136,77 @@ function bo(e) {
2068
2136
  }
2069
2137
  return e;
2070
2138
  }
2071
- function Ke(e) {
2139
+ function Xe(e) {
2072
2140
  const { stackTraceLimit: t } = Error;
2073
2141
  Error.stackTraceLimit = 0;
2074
2142
  try {
2075
- return wo(e);
2143
+ return Eo(e);
2076
2144
  } finally {
2077
2145
  Error.stackTraceLimit = t;
2078
2146
  }
2079
2147
  }
2080
- var He = Symbol.for("vercel.ai.validator");
2081
- function ko(e) {
2082
- return { [He]: !0, validate: e };
2148
+ var Ve = Symbol.for("vercel.ai.validator");
2149
+ function xo(e) {
2150
+ return { [Ve]: !0, validate: e };
2083
2151
  }
2084
- function To(e) {
2085
- return typeof e == "object" && e !== null && He in e && e[He] === !0 && "validate" in e;
2152
+ function Io(e) {
2153
+ return typeof e == "object" && e !== null && Ve in e && e[Ve] === !0 && "validate" in e;
2086
2154
  }
2087
- function So(e) {
2088
- return To(e) ? e : Ro(e);
2155
+ function Oo(e) {
2156
+ return Io(e) ? e : Po(e);
2089
2157
  }
2090
- function Ro(e) {
2091
- return ko(async (t) => {
2158
+ function Po(e) {
2159
+ return xo(async (t) => {
2092
2160
  const n = await e["~standard"].validate(t);
2093
2161
  return n.issues == null ? { success: !0, value: n.value } : {
2094
2162
  success: !1,
2095
- error: new ue({
2163
+ error: new he({
2096
2164
  value: t,
2097
2165
  cause: n.issues
2098
2166
  })
2099
2167
  };
2100
2168
  });
2101
2169
  }
2102
- async function Eo({
2170
+ async function Ao({
2103
2171
  value: e,
2104
2172
  schema: t
2105
2173
  }) {
2106
2174
  const n = await _n({ value: e, schema: t });
2107
2175
  if (!n.success)
2108
- throw ue.wrap({ value: e, cause: n.error });
2176
+ throw he.wrap({ value: e, cause: n.error });
2109
2177
  return n.value;
2110
2178
  }
2111
2179
  async function _n({
2112
2180
  value: e,
2113
2181
  schema: t
2114
2182
  }) {
2115
- const n = So(t);
2183
+ const n = Oo(t);
2116
2184
  try {
2117
2185
  if (n.validate == null)
2118
2186
  return { success: !0, value: e, rawValue: e };
2119
2187
  const r = await n.validate(e);
2120
2188
  return r.success ? { success: !0, value: r.value, rawValue: e } : {
2121
2189
  success: !1,
2122
- error: ue.wrap({ value: e, cause: r.error }),
2190
+ error: he.wrap({ value: e, cause: r.error }),
2123
2191
  rawValue: e
2124
2192
  };
2125
2193
  } catch (r) {
2126
2194
  return {
2127
2195
  success: !1,
2128
- error: ue.wrap({ value: e, cause: r }),
2196
+ error: he.wrap({ value: e, cause: r }),
2129
2197
  rawValue: e
2130
2198
  };
2131
2199
  }
2132
2200
  }
2133
- async function Co({
2201
+ async function $o({
2134
2202
  text: e,
2135
2203
  schema: t
2136
2204
  }) {
2137
2205
  try {
2138
- const n = Ke(e);
2139
- return t == null ? n : Eo({ value: n, schema: t });
2206
+ const n = Xe(e);
2207
+ return t == null ? n : Ao({ value: n, schema: t });
2140
2208
  } catch (n) {
2141
- throw Ce.isInstance(n) || ue.isInstance(n) ? n : new Ce({ text: e, cause: n });
2209
+ throw Ie.isInstance(n) || he.isInstance(n) ? n : new Ie({ text: e, cause: n });
2142
2210
  }
2143
2211
  }
2144
2212
  async function vn({
@@ -2146,28 +2214,28 @@ async function vn({
2146
2214
  schema: t
2147
2215
  }) {
2148
2216
  try {
2149
- const n = Ke(e);
2217
+ const n = Xe(e);
2150
2218
  return t == null ? { success: !0, value: n, rawValue: n } : await _n({ value: n, schema: t });
2151
2219
  } catch (n) {
2152
2220
  return {
2153
2221
  success: !1,
2154
- error: Ce.isInstance(n) ? n : new Ce({ text: e, cause: n }),
2222
+ error: Ie.isInstance(n) ? n : new Ie({ text: e, cause: n }),
2155
2223
  rawValue: void 0
2156
2224
  };
2157
2225
  }
2158
2226
  }
2159
- function Me(e) {
2227
+ function je(e) {
2160
2228
  try {
2161
- return Ke(e), !0;
2229
+ return Xe(e), !0;
2162
2230
  } catch {
2163
2231
  return !1;
2164
2232
  }
2165
2233
  }
2166
- function xo({
2234
+ function Uo({
2167
2235
  stream: e,
2168
2236
  schema: t
2169
2237
  }) {
2170
- return e.pipeThrough(new TextDecoderStream()).pipeThrough(new po()).pipeThrough(
2238
+ return e.pipeThrough(new TextDecoderStream()).pipeThrough(new vo()).pipeThrough(
2171
2239
  new TransformStream({
2172
2240
  async transform({ data: n }, r) {
2173
2241
  n !== "[DONE]" && r.enqueue(await vn({ text: n, schema: t }));
@@ -2175,17 +2243,17 @@ function xo({
2175
2243
  })
2176
2244
  );
2177
2245
  }
2178
- var Io = () => globalThis.fetch, pe = async ({
2246
+ var Mo = () => globalThis.fetch, fe = async ({
2179
2247
  url: e,
2180
2248
  headers: t,
2181
2249
  body: n,
2182
2250
  failedResponseHandler: r,
2183
2251
  successfulResponseHandler: o,
2184
2252
  abortSignal: a,
2185
- fetch: l
2186
- }) => Po({
2253
+ fetch: i
2254
+ }) => No({
2187
2255
  url: e,
2188
- headers: O({
2256
+ headers: P({
2189
2257
  "Content-Type": "application/json"
2190
2258
  }, t),
2191
2259
  body: {
@@ -2195,23 +2263,23 @@ var Io = () => globalThis.fetch, pe = async ({
2195
2263
  failedResponseHandler: r,
2196
2264
  successfulResponseHandler: o,
2197
2265
  abortSignal: a,
2198
- fetch: l
2199
- }), Po = async ({
2266
+ fetch: i
2267
+ }), No = async ({
2200
2268
  url: e,
2201
2269
  headers: t = {},
2202
2270
  body: n,
2203
2271
  successfulResponseHandler: r,
2204
2272
  failedResponseHandler: o,
2205
2273
  abortSignal: a,
2206
- fetch: l = Io()
2274
+ fetch: i = Mo()
2207
2275
  }) => {
2208
2276
  try {
2209
- const c = await l(e, {
2277
+ const c = await i(e, {
2210
2278
  method: "POST",
2211
- headers: fo(t),
2279
+ headers: ko(t),
2212
2280
  body: n.content,
2213
2281
  signal: a
2214
- }), i = Oe(c);
2282
+ }), l = $e(c);
2215
2283
  if (!c.ok) {
2216
2284
  let u;
2217
2285
  try {
@@ -2221,12 +2289,12 @@ var Io = () => globalThis.fetch, pe = async ({
2221
2289
  requestBodyValues: n.values
2222
2290
  });
2223
2291
  } catch (h) {
2224
- throw qe(h) || K.isInstance(h) ? h : new K({
2292
+ throw qe(h) || F.isInstance(h) ? h : new F({
2225
2293
  message: "Failed to process error response",
2226
2294
  cause: h,
2227
2295
  statusCode: c.status,
2228
2296
  url: e,
2229
- responseHeaders: i,
2297
+ responseHeaders: l,
2230
2298
  requestBodyValues: n.values
2231
2299
  });
2232
2300
  }
@@ -2239,212 +2307,212 @@ var Io = () => globalThis.fetch, pe = async ({
2239
2307
  requestBodyValues: n.values
2240
2308
  });
2241
2309
  } catch (u) {
2242
- throw u instanceof Error && (qe(u) || K.isInstance(u)) ? u : new K({
2310
+ throw u instanceof Error && (qe(u) || F.isInstance(u)) ? u : new F({
2243
2311
  message: "Failed to process successful response",
2244
2312
  cause: u,
2245
2313
  statusCode: c.status,
2246
2314
  url: e,
2247
- responseHeaders: i,
2315
+ responseHeaders: l,
2248
2316
  requestBodyValues: n.values
2249
2317
  });
2250
2318
  }
2251
2319
  } catch (c) {
2252
- throw go({ error: c, url: e, requestBodyValues: n.values });
2320
+ throw bo({ error: c, url: e, requestBodyValues: n.values });
2253
2321
  }
2254
- }, Oo = ({
2322
+ }, jo = ({
2255
2323
  errorSchema: e,
2256
2324
  errorToMessage: t,
2257
2325
  isRetryable: n
2258
2326
  }) => async ({ response: r, url: o, requestBodyValues: a }) => {
2259
- const l = await r.text(), c = Oe(r);
2260
- if (l.trim() === "")
2327
+ const i = await r.text(), c = $e(r);
2328
+ if (i.trim() === "")
2261
2329
  return {
2262
2330
  responseHeaders: c,
2263
- value: new K({
2331
+ value: new F({
2264
2332
  message: r.statusText,
2265
2333
  url: o,
2266
2334
  requestBodyValues: a,
2267
2335
  statusCode: r.status,
2268
2336
  responseHeaders: c,
2269
- responseBody: l,
2337
+ responseBody: i,
2270
2338
  isRetryable: n?.(r)
2271
2339
  })
2272
2340
  };
2273
2341
  try {
2274
- const i = await Co({
2275
- text: l,
2342
+ const l = await $o({
2343
+ text: i,
2276
2344
  schema: e
2277
2345
  });
2278
2346
  return {
2279
2347
  responseHeaders: c,
2280
- value: new K({
2281
- message: t(i),
2348
+ value: new F({
2349
+ message: t(l),
2282
2350
  url: o,
2283
2351
  requestBodyValues: a,
2284
2352
  statusCode: r.status,
2285
2353
  responseHeaders: c,
2286
- responseBody: l,
2287
- data: i,
2288
- isRetryable: n?.(r, i)
2354
+ responseBody: i,
2355
+ data: l,
2356
+ isRetryable: n?.(r, l)
2289
2357
  })
2290
2358
  };
2291
2359
  } catch {
2292
2360
  return {
2293
2361
  responseHeaders: c,
2294
- value: new K({
2362
+ value: new F({
2295
2363
  message: r.statusText,
2296
2364
  url: o,
2297
2365
  requestBodyValues: a,
2298
2366
  statusCode: r.status,
2299
2367
  responseHeaders: c,
2300
- responseBody: l,
2368
+ responseBody: i,
2301
2369
  isRetryable: n?.(r)
2302
2370
  })
2303
2371
  };
2304
2372
  }
2305
2373
  }, yn = (e) => async ({ response: t }) => {
2306
- const n = Oe(t);
2374
+ const n = $e(t);
2307
2375
  if (t.body == null)
2308
- throw new Yr({});
2376
+ throw new oo({});
2309
2377
  return {
2310
2378
  responseHeaders: n,
2311
- value: xo({
2379
+ value: Uo({
2312
2380
  stream: t.body,
2313
2381
  schema: e
2314
2382
  })
2315
2383
  };
2316
- }, Ze = (e) => async ({ response: t, url: n, requestBodyValues: r }) => {
2384
+ }, Ye = (e) => async ({ response: t, url: n, requestBodyValues: r }) => {
2317
2385
  const o = await t.text(), a = await vn({
2318
2386
  text: o,
2319
2387
  schema: e
2320
- }), l = Oe(t);
2388
+ }), i = $e(t);
2321
2389
  if (!a.success)
2322
- throw new K({
2390
+ throw new F({
2323
2391
  message: "Invalid JSON response",
2324
2392
  cause: a.error,
2325
2393
  statusCode: t.status,
2326
- responseHeaders: l,
2394
+ responseHeaders: i,
2327
2395
  responseBody: o,
2328
2396
  url: n,
2329
2397
  requestBodyValues: r
2330
2398
  });
2331
2399
  return {
2332
- responseHeaders: l,
2400
+ responseHeaders: i,
2333
2401
  value: a.value,
2334
2402
  rawValue: a.rawValue
2335
2403
  };
2336
- }, { btoa: Ao } = globalThis;
2337
- function Uo(e) {
2404
+ }, { btoa: Do } = globalThis;
2405
+ function Ho(e) {
2338
2406
  let t = "";
2339
2407
  for (let n = 0; n < e.length; n++)
2340
2408
  t += String.fromCodePoint(e[n]);
2341
- return Ao(t);
2409
+ return Do(t);
2342
2410
  }
2343
- function $o(e) {
2411
+ function Lo(e) {
2344
2412
  return e?.replace(/\/$/, "");
2345
2413
  }
2346
- function Ne(e) {
2414
+ function De(e) {
2347
2415
  return e != null;
2348
2416
  }
2349
- var wn = /* @__PURE__ */ ((e) => (e.Unknown = "unknown", e.OpenAIResponsesV1 = "openai-responses-v1", e.XAIResponsesV1 = "xai-responses-v1", e.AnthropicClaudeV1 = "anthropic-claude-v1", e.GoogleGeminiV1 = "google-gemini-v1", e))(wn || {}), Xe = d({
2417
+ var wn = /* @__PURE__ */ ((e) => (e.Unknown = "unknown", e.OpenAIResponsesV1 = "openai-responses-v1", e.XAIResponsesV1 = "xai-responses-v1", e.AnthropicClaudeV1 = "anthropic-claude-v1", e.GoogleGeminiV1 = "google-gemini-v1", e))(wn || {}), Qe = d({
2350
2418
  id: s().nullish(),
2351
- format: Je(wn).nullish(),
2419
+ format: Ge(wn).nullish(),
2352
2420
  index: k().optional()
2353
- }).loose(), Mo = d({
2354
- type: E(
2421
+ }).loose(), qo = d({
2422
+ type: x(
2355
2423
  "reasoning.summary"
2356
2424
  /* Summary */
2357
2425
  ),
2358
2426
  summary: s()
2359
- }).extend(Xe.shape), No = d({
2360
- type: E(
2427
+ }).extend(Qe.shape), Vo = d({
2428
+ type: x(
2361
2429
  "reasoning.encrypted"
2362
2430
  /* Encrypted */
2363
2431
  ),
2364
2432
  data: s()
2365
- }).extend(Xe.shape), Do = d({
2366
- type: E(
2433
+ }).extend(Qe.shape), Bo = d({
2434
+ type: x(
2367
2435
  "reasoning.text"
2368
2436
  /* Text */
2369
2437
  ),
2370
2438
  text: s().nullish(),
2371
2439
  signature: s().nullish()
2372
- }).extend(Xe.shape), Ye = D([
2373
- Mo,
2374
- No,
2375
- Do
2376
- ]), ve = D([
2377
- Ye,
2378
- ne().transform(() => null)
2379
- ]), Qe = v(ve).transform((e) => e.filter((t) => !!t));
2380
- D([
2440
+ }).extend(Qe.shape), et = j([
2441
+ qo,
2442
+ Vo,
2443
+ Bo
2444
+ ]), we = j([
2445
+ et,
2446
+ oe().transform(() => null)
2447
+ ]), tt = y(we).transform((e) => e.filter((t) => !!t));
2448
+ j([
2381
2449
  d({
2382
2450
  delta: d({
2383
- reasoning_details: v(ve)
2451
+ reasoning_details: y(we)
2384
2452
  })
2385
2453
  }).transform(
2386
- (e) => e.delta.reasoning_details.filter(Ne)
2454
+ (e) => e.delta.reasoning_details.filter(De)
2387
2455
  ),
2388
2456
  d({
2389
2457
  message: d({
2390
- reasoning_details: v(ve)
2458
+ reasoning_details: y(we)
2391
2459
  })
2392
2460
  }).transform(
2393
- (e) => e.message.reasoning_details.filter(Ne)
2461
+ (e) => e.message.reasoning_details.filter(De)
2394
2462
  ),
2395
2463
  d({
2396
2464
  text: s(),
2397
- reasoning_details: v(ve)
2398
- }).transform((e) => e.reasoning_details.filter(Ne))
2465
+ reasoning_details: y(we)
2466
+ }).transform((e) => e.reasoning_details.filter(De))
2399
2467
  ]);
2400
- var Ae = d({
2468
+ var Ue = d({
2401
2469
  error: d({
2402
- code: D([s(), k()]).nullable().optional().default(null),
2470
+ code: j([s(), k()]).nullable().optional().default(null),
2403
2471
  message: s(),
2404
2472
  type: s().nullable().optional().default(null),
2405
- param: vt().nullable().optional().default(null)
2473
+ param: K().nullable().optional().default(null)
2406
2474
  }).passthrough()
2407
- }).passthrough(), he = Oo({
2408
- errorSchema: Ae,
2475
+ }).passthrough(), ge = jo({
2476
+ errorSchema: Ue,
2409
2477
  errorToMessage: (e) => e.error.message
2410
2478
  }), bn = d({
2411
- type: E("file"),
2479
+ type: x("file"),
2412
2480
  file: d({
2413
2481
  hash: s(),
2414
2482
  name: s(),
2415
- content: v(
2483
+ content: y(
2416
2484
  d({
2417
2485
  type: s(),
2418
2486
  text: s().optional()
2419
- }).passthrough()
2487
+ }).catchall(K())
2420
2488
  ).optional()
2421
- }).passthrough()
2422
- }), jo = d({
2489
+ }).catchall(K())
2490
+ }).catchall(K()), Jo = d({
2423
2491
  provider: s(),
2424
- reasoning_details: v(Ye).optional(),
2425
- annotations: v(bn).optional(),
2492
+ reasoning_details: y(et).optional(),
2493
+ annotations: y(bn).optional(),
2426
2494
  usage: d({
2427
2495
  promptTokens: k(),
2428
2496
  promptTokensDetails: d({
2429
2497
  cachedTokens: k()
2430
- }).passthrough().optional(),
2498
+ }).catchall(K()).optional(),
2431
2499
  completionTokens: k(),
2432
2500
  completionTokensDetails: d({
2433
2501
  reasoningTokens: k()
2434
- }).passthrough().optional(),
2502
+ }).catchall(K()).optional(),
2435
2503
  totalTokens: k(),
2436
2504
  cost: k().optional(),
2437
2505
  costDetails: d({
2438
2506
  upstreamInferenceCost: k()
2439
- }).passthrough().optional()
2440
- }).passthrough()
2441
- }).passthrough(), ut = d({
2507
+ }).catchall(K()).optional()
2508
+ }).catchall(K())
2509
+ }).catchall(K()), pt = d({
2442
2510
  openrouter: d({
2443
- reasoning_details: v(Ye).optional(),
2444
- annotations: v(bn).optional()
2511
+ reasoning_details: y(et).optional(),
2512
+ annotations: y(bn).optional()
2445
2513
  }).optional()
2446
2514
  }).optional();
2447
- function xe(e) {
2515
+ function Oe(e) {
2448
2516
  switch (e) {
2449
2517
  case "stop":
2450
2518
  return "stop";
@@ -2459,7 +2527,18 @@ function xe(e) {
2459
2527
  return "unknown";
2460
2528
  }
2461
2529
  }
2462
- function et({
2530
+ var zo = [
2531
+ "wav",
2532
+ "mp3",
2533
+ "aiff",
2534
+ "aac",
2535
+ "ogg",
2536
+ "flac",
2537
+ "m4a",
2538
+ "pcm16",
2539
+ "pcm24"
2540
+ ];
2541
+ function nt({
2463
2542
  url: e,
2464
2543
  protocols: t
2465
2544
  }) {
@@ -2470,36 +2549,64 @@ function et({
2470
2549
  return !1;
2471
2550
  }
2472
2551
  }
2473
- function Le({
2552
+ function Be({
2474
2553
  part: e,
2475
2554
  defaultMediaType: t
2476
2555
  }) {
2477
2556
  var n, r;
2478
2557
  if (e.data instanceof Uint8Array) {
2479
- const a = Uo(e.data);
2558
+ const a = Ho(e.data);
2480
2559
  return `data:${(n = e.mediaType) != null ? n : t};base64,${a}`;
2481
2560
  }
2482
2561
  const o = e.data.toString();
2483
- return et({
2562
+ return nt({
2484
2563
  url: o,
2485
2564
  protocols: /* @__PURE__ */ new Set(["http:", "https:"])
2486
2565
  }) || o.startsWith("data:") ? o : `data:${(r = e.mediaType) != null ? r : t};base64,${o}`;
2487
2566
  }
2488
- function dt(e, t) {
2567
+ function ht(e, t) {
2489
2568
  var n;
2490
2569
  const r = e.match(/^data:([^;]+)/);
2491
2570
  return r && (n = r[1]) != null ? n : t;
2492
2571
  }
2493
- function Ve(e) {
2572
+ function Je(e) {
2494
2573
  const t = e.match(/^data:[^;]*;base64,(.+)$/);
2495
2574
  return t ? t[1] : e;
2496
2575
  }
2497
- function qo(e) {
2498
- const t = Le({
2576
+ var Go = {
2577
+ // MP3 variants
2578
+ mpeg: "mp3",
2579
+ mp3: "mp3",
2580
+ // WAV variants
2581
+ "x-wav": "wav",
2582
+ wave: "wav",
2583
+ wav: "wav",
2584
+ // OGG variants
2585
+ ogg: "ogg",
2586
+ vorbis: "ogg",
2587
+ // AAC variants
2588
+ aac: "aac",
2589
+ "x-aac": "aac",
2590
+ // M4A variants
2591
+ m4a: "m4a",
2592
+ "x-m4a": "m4a",
2593
+ mp4: "m4a",
2594
+ // AIFF variants
2595
+ aiff: "aiff",
2596
+ "x-aiff": "aiff",
2597
+ // FLAC
2598
+ flac: "flac",
2599
+ "x-flac": "flac",
2600
+ // PCM variants
2601
+ pcm16: "pcm16",
2602
+ pcm24: "pcm24"
2603
+ };
2604
+ function Wo(e) {
2605
+ const t = Be({
2499
2606
  part: e,
2500
2607
  defaultMediaType: "audio/mpeg"
2501
2608
  });
2502
- if (et({
2609
+ if (nt({
2503
2610
  url: t,
2504
2611
  protocols: /* @__PURE__ */ new Set(["http:", "https:"])
2505
2612
  }))
@@ -2515,197 +2622,196 @@ The AI SDK will automatically handle base64 encoding.
2515
2622
 
2516
2623
  Learn more: https://openrouter.ai/docs/features/multimodal/audio`
2517
2624
  );
2518
- const n = Ve(t), r = e.mediaType || "audio/mpeg";
2519
- let o = r.replace("audio/", "");
2520
- if (o === "mpeg" || o === "mp3" ? o = "mp3" : (o === "x-wav" || o === "wave" || o === "wav") && (o = "wav"), o !== "mp3" && o !== "wav")
2625
+ const n = Je(t), r = e.mediaType || "audio/mpeg", o = r.replace("audio/", ""), a = Go[o];
2626
+ if (a === void 0) {
2627
+ const i = zo.join(", ");
2521
2628
  throw new Error(
2522
2629
  `Unsupported audio format: "${r}"
2523
2630
 
2524
- OpenRouter only supports MP3 and WAV audio formats.
2525
- • For MP3: use "audio/mpeg" or "audio/mp3"
2526
- • For WAV: use "audio/wav" or "audio/x-wav"
2631
+ OpenRouter supports the following audio formats: ${i}
2527
2632
 
2528
2633
  Learn more: https://openrouter.ai/docs/features/multimodal/audio`
2529
2634
  );
2530
- return { data: n, format: o };
2635
+ }
2636
+ return { data: n, format: a };
2531
2637
  }
2532
- function Q(e) {
2638
+ function ee(e) {
2533
2639
  var t, n, r;
2534
2640
  const o = e?.anthropic, a = e?.openrouter;
2535
2641
  return (r = (n = (t = a?.cacheControl) != null ? t : a?.cache_control) != null ? n : o?.cacheControl) != null ? r : o?.cache_control;
2536
2642
  }
2537
- function Ho(e) {
2538
- var t, n, r, o, a, l, c, i, u, h;
2539
- const f = [];
2540
- for (const { role: m, content: _, providerOptions: g } of e)
2541
- switch (m) {
2643
+ function Fo(e) {
2644
+ var t, n, r, o, a, i, c, l, u, h;
2645
+ const g = [];
2646
+ for (const { role: f, content: v, providerOptions: m } of e)
2647
+ switch (f) {
2542
2648
  case "system": {
2543
- f.push({
2649
+ g.push({
2544
2650
  role: "system",
2545
- content: _,
2546
- cache_control: Q(g)
2651
+ content: v,
2652
+ cache_control: ee(m)
2547
2653
  });
2548
2654
  break;
2549
2655
  }
2550
2656
  case "user": {
2551
- if (_.length === 1 && ((t = _[0]) == null ? void 0 : t.type) === "text") {
2552
- const y = (n = Q(g)) != null ? n : Q(_[0].providerOptions), T = y ? [
2657
+ if (v.length === 1 && ((t = v[0]) == null ? void 0 : t.type) === "text") {
2658
+ const b = (n = ee(m)) != null ? n : ee(v[0].providerOptions), R = b ? [
2553
2659
  {
2554
2660
  type: "text",
2555
- text: _[0].text,
2556
- cache_control: y
2661
+ text: v[0].text,
2662
+ cache_control: b
2557
2663
  }
2558
- ] : _[0].text;
2559
- f.push({
2664
+ ] : v[0].text;
2665
+ g.push({
2560
2666
  role: "user",
2561
- content: T
2667
+ content: R
2562
2668
  });
2563
2669
  break;
2564
2670
  }
2565
- const p = Q(g), b = _.map(
2566
- (y) => {
2567
- var T, w, A, x, $, M, H;
2568
- const W = (T = Q(y.providerOptions)) != null ? T : p;
2569
- switch (y.type) {
2671
+ const p = ee(m), w = v.map(
2672
+ (b) => {
2673
+ var R, T, S, M, $, A, I;
2674
+ const z = (R = ee(b.providerOptions)) != null ? R : p;
2675
+ switch (b.type) {
2570
2676
  case "text":
2571
2677
  return {
2572
2678
  type: "text",
2573
- text: y.text,
2679
+ text: b.text,
2574
2680
  // For text parts, only use part-specific cache control
2575
- cache_control: W
2681
+ cache_control: z
2576
2682
  };
2577
2683
  case "file": {
2578
- if ((w = y.mediaType) != null && w.startsWith("image/"))
2684
+ if ((T = b.mediaType) != null && T.startsWith("image/"))
2579
2685
  return {
2580
2686
  type: "image_url",
2581
2687
  image_url: {
2582
- url: Le({
2583
- part: y,
2688
+ url: Be({
2689
+ part: b,
2584
2690
  defaultMediaType: "image/jpeg"
2585
2691
  })
2586
2692
  },
2587
2693
  // For image parts, use part-specific or message-level cache control
2588
- cache_control: W
2694
+ cache_control: z
2589
2695
  };
2590
- if ((A = y.mediaType) != null && A.startsWith("audio/"))
2696
+ if ((S = b.mediaType) != null && S.startsWith("audio/"))
2591
2697
  return {
2592
2698
  type: "input_audio",
2593
- input_audio: qo(y),
2594
- cache_control: W
2699
+ input_audio: Wo(b),
2700
+ cache_control: z
2595
2701
  };
2596
- const z = String(
2597
- (H = (M = ($ = (x = y.providerOptions) == null ? void 0 : x.openrouter) == null ? void 0 : $.filename) != null ? M : y.filename) != null ? H : ""
2598
- ), G = Le({
2599
- part: y,
2702
+ const J = String(
2703
+ (I = (A = ($ = (M = b.providerOptions) == null ? void 0 : M.openrouter) == null ? void 0 : $.filename) != null ? A : b.filename) != null ? I : ""
2704
+ ), G = Be({
2705
+ part: b,
2600
2706
  defaultMediaType: "application/pdf"
2601
2707
  });
2602
- return et({
2708
+ return nt({
2603
2709
  url: G,
2604
2710
  protocols: /* @__PURE__ */ new Set(["http:", "https:"])
2605
2711
  }) ? {
2606
2712
  type: "file",
2607
2713
  file: {
2608
- filename: z,
2714
+ filename: J,
2609
2715
  file_data: G
2610
2716
  }
2611
2717
  } : {
2612
2718
  type: "file",
2613
2719
  file: {
2614
- filename: z,
2720
+ filename: J,
2615
2721
  file_data: G
2616
2722
  },
2617
- cache_control: W
2723
+ cache_control: z
2618
2724
  };
2619
2725
  }
2620
2726
  default:
2621
2727
  return {
2622
2728
  type: "text",
2623
2729
  text: "",
2624
- cache_control: W
2730
+ cache_control: z
2625
2731
  };
2626
2732
  }
2627
2733
  }
2628
2734
  );
2629
- f.push({
2735
+ g.push({
2630
2736
  role: "user",
2631
- content: b
2737
+ content: w
2632
2738
  });
2633
2739
  break;
2634
2740
  }
2635
2741
  case "assistant": {
2636
- let p = "", b = "";
2637
- const y = [], T = [];
2638
- for (const M of _)
2639
- switch (M.type) {
2742
+ let p = "", w = "";
2743
+ const b = [], R = [];
2744
+ for (const A of v)
2745
+ switch (A.type) {
2640
2746
  case "text": {
2641
- p += M.text;
2747
+ p += A.text;
2642
2748
  break;
2643
2749
  }
2644
2750
  case "tool-call": {
2645
- const H = (r = M.providerOptions) == null ? void 0 : r.openrouter;
2646
- H?.reasoning_details && Array.isArray(H.reasoning_details) && T.push(
2647
- ...H.reasoning_details
2648
- ), y.push({
2649
- id: M.toolCallId,
2751
+ const I = (r = A.providerOptions) == null ? void 0 : r.openrouter;
2752
+ I?.reasoning_details && Array.isArray(I.reasoning_details) && R.push(
2753
+ ...I.reasoning_details
2754
+ ), b.push({
2755
+ id: A.toolCallId,
2650
2756
  type: "function",
2651
2757
  function: {
2652
- name: M.toolName,
2653
- arguments: JSON.stringify(M.input)
2758
+ name: A.toolName,
2759
+ arguments: JSON.stringify(A.input)
2654
2760
  }
2655
2761
  });
2656
2762
  break;
2657
2763
  }
2658
2764
  case "reasoning": {
2659
- b += M.text;
2660
- const H = ut.safeParse(M.providerOptions);
2661
- H.success && ((a = (o = H.data) == null ? void 0 : o.openrouter) != null && a.reasoning_details) && T.push(
2662
- ...H.data.openrouter.reasoning_details
2765
+ w += A.text;
2766
+ const I = pt.safeParse(A.providerOptions);
2767
+ I.success && ((a = (o = I.data) == null ? void 0 : o.openrouter) != null && a.reasoning_details) && R.push(
2768
+ ...I.data.openrouter.reasoning_details
2663
2769
  );
2664
2770
  break;
2665
2771
  }
2666
2772
  }
2667
- const w = ut.safeParse(g), A = w.success ? (c = (l = w.data) == null ? void 0 : l.openrouter) == null ? void 0 : c.reasoning_details : void 0, x = w.success ? (u = (i = w.data) == null ? void 0 : i.openrouter) == null ? void 0 : u.annotations : void 0, $ = A && Array.isArray(A) && A.length > 0 ? A : T.length > 0 ? T : void 0;
2668
- f.push({
2773
+ const T = pt.safeParse(m), S = T.success ? (c = (i = T.data) == null ? void 0 : i.openrouter) == null ? void 0 : c.reasoning_details : void 0, M = T.success ? (u = (l = T.data) == null ? void 0 : l.openrouter) == null ? void 0 : u.annotations : void 0, $ = S && Array.isArray(S) && S.length > 0 ? S : R.length > 0 ? R : void 0;
2774
+ g.push({
2669
2775
  role: "assistant",
2670
2776
  content: p,
2671
- tool_calls: y.length > 0 ? y : void 0,
2672
- reasoning: b || void 0,
2777
+ tool_calls: b.length > 0 ? b : void 0,
2778
+ reasoning: w || void 0,
2673
2779
  reasoning_details: $,
2674
- annotations: x,
2675
- cache_control: Q(g)
2780
+ annotations: M,
2781
+ cache_control: ee(m)
2676
2782
  });
2677
2783
  break;
2678
2784
  }
2679
2785
  case "tool": {
2680
- for (const p of _) {
2681
- const b = Lo(p);
2682
- f.push({
2786
+ for (const p of v) {
2787
+ const w = Ko(p);
2788
+ g.push({
2683
2789
  role: "tool",
2684
2790
  tool_call_id: p.toolCallId,
2685
- content: b,
2686
- cache_control: (h = Q(g)) != null ? h : Q(p.providerOptions)
2791
+ content: w,
2792
+ cache_control: (h = ee(m)) != null ? h : ee(p.providerOptions)
2687
2793
  });
2688
2794
  }
2689
2795
  break;
2690
2796
  }
2691
2797
  }
2692
- return f;
2798
+ return g;
2693
2799
  }
2694
- function Lo(e) {
2800
+ function Ko(e) {
2695
2801
  return e.output.type === "text" ? e.output.value : JSON.stringify(e.output.value);
2696
2802
  }
2697
- D([
2698
- E("auto"),
2699
- E("none"),
2700
- E("required"),
2803
+ j([
2804
+ x("auto"),
2805
+ x("none"),
2806
+ x("required"),
2701
2807
  d({
2702
- type: E("function"),
2808
+ type: x("function"),
2703
2809
  function: d({
2704
2810
  name: s()
2705
2811
  })
2706
2812
  })
2707
2813
  ]);
2708
- function Vo(e) {
2814
+ function Zo(e) {
2709
2815
  switch (e.type) {
2710
2816
  case "auto":
2711
2817
  case "none":
@@ -2717,21 +2823,21 @@ function Vo(e) {
2717
2823
  function: { name: e.toolName }
2718
2824
  };
2719
2825
  default:
2720
- throw new Gt({
2826
+ throw new Wt({
2721
2827
  argument: "toolChoice",
2722
2828
  message: `Invalid tool choice type: ${JSON.stringify(e)}`
2723
2829
  });
2724
2830
  }
2725
2831
  }
2726
- var Bo = d({
2727
- type: E("image_url"),
2832
+ var Xo = d({
2833
+ type: x("image_url"),
2728
2834
  image_url: d({
2729
2835
  url: s()
2730
2836
  }).passthrough()
2731
- }).passthrough(), Jo = D([
2732
- Bo,
2733
- ne().transform(() => null)
2734
- ]), kn = v(Jo).transform((e) => e.filter((t) => !!t)), Tn = d({
2837
+ }).passthrough(), Yo = j([
2838
+ Xo,
2839
+ oe().transform(() => null)
2840
+ ]), kn = y(Yo).transform((e) => e.filter((t) => !!t)), Tn = d({
2735
2841
  id: s().optional(),
2736
2842
  model: s().optional(),
2737
2843
  provider: s().optional(),
@@ -2750,32 +2856,32 @@ var Bo = d({
2750
2856
  upstream_inference_cost: k().nullish()
2751
2857
  }).passthrough().nullish()
2752
2858
  }).passthrough().nullish()
2753
- }).passthrough(), zo = D([
2859
+ }).passthrough(), Qo = j([
2754
2860
  // Success response with choices
2755
2861
  Tn.extend({
2756
- choices: v(
2862
+ choices: y(
2757
2863
  d({
2758
2864
  message: d({
2759
- role: E("assistant"),
2865
+ role: x("assistant"),
2760
2866
  content: s().nullable().optional(),
2761
2867
  reasoning: s().nullable().optional(),
2762
- reasoning_details: Qe.nullish(),
2868
+ reasoning_details: tt.nullish(),
2763
2869
  images: kn.nullish(),
2764
- tool_calls: v(
2870
+ tool_calls: y(
2765
2871
  d({
2766
2872
  id: s().optional().nullable(),
2767
- type: E("function"),
2873
+ type: x("function"),
2768
2874
  function: d({
2769
2875
  name: s(),
2770
2876
  arguments: s()
2771
2877
  }).passthrough()
2772
2878
  }).passthrough()
2773
2879
  ).optional(),
2774
- annotations: v(
2775
- D([
2880
+ annotations: y(
2881
+ j([
2776
2882
  // URL citation from web search
2777
2883
  d({
2778
- type: E("url_citation"),
2884
+ type: x("url_citation"),
2779
2885
  url_citation: d({
2780
2886
  end_index: k(),
2781
2887
  start_index: k(),
@@ -2786,7 +2892,7 @@ var Bo = d({
2786
2892
  }).passthrough(),
2787
2893
  // File annotation from FileParserPlugin (old format)
2788
2894
  d({
2789
- type: E("file_annotation"),
2895
+ type: x("file_annotation"),
2790
2896
  file_annotation: d({
2791
2897
  file_id: s(),
2792
2898
  quote: s().optional()
@@ -2794,11 +2900,11 @@ var Bo = d({
2794
2900
  }).passthrough(),
2795
2901
  // File annotation from FileParserPlugin (new format)
2796
2902
  d({
2797
- type: E("file"),
2903
+ type: x("file"),
2798
2904
  file: d({
2799
2905
  hash: s(),
2800
2906
  name: s(),
2801
- content: v(
2907
+ content: y(
2802
2908
  d({
2803
2909
  type: s(),
2804
2910
  text: s().optional()
@@ -2811,11 +2917,11 @@ var Bo = d({
2811
2917
  }).passthrough(),
2812
2918
  index: k().nullish(),
2813
2919
  logprobs: d({
2814
- content: v(
2920
+ content: y(
2815
2921
  d({
2816
2922
  token: s(),
2817
2923
  logprob: k(),
2818
- top_logprobs: v(
2924
+ top_logprobs: y(
2819
2925
  d({
2820
2926
  token: s(),
2821
2927
  logprob: k()
@@ -2829,35 +2935,35 @@ var Bo = d({
2829
2935
  )
2830
2936
  }),
2831
2937
  // Error response (HTTP 200 with error payload)
2832
- Ae.extend({
2938
+ Ue.extend({
2833
2939
  user_id: s().optional()
2834
2940
  })
2835
- ]), Wo = D([
2941
+ ]), es = j([
2836
2942
  Tn.extend({
2837
- choices: v(
2943
+ choices: y(
2838
2944
  d({
2839
2945
  delta: d({
2840
- role: Je(["assistant"]).optional(),
2946
+ role: Ge(["assistant"]).optional(),
2841
2947
  content: s().nullish(),
2842
2948
  reasoning: s().nullish().optional(),
2843
- reasoning_details: Qe.nullish(),
2949
+ reasoning_details: tt.nullish(),
2844
2950
  images: kn.nullish(),
2845
- tool_calls: v(
2951
+ tool_calls: y(
2846
2952
  d({
2847
2953
  index: k().nullish(),
2848
2954
  id: s().nullish(),
2849
- type: E("function").optional(),
2955
+ type: x("function").optional(),
2850
2956
  function: d({
2851
2957
  name: s().nullish(),
2852
2958
  arguments: s().nullish()
2853
2959
  }).passthrough()
2854
2960
  }).passthrough()
2855
2961
  ).nullish(),
2856
- annotations: v(
2857
- D([
2962
+ annotations: y(
2963
+ j([
2858
2964
  // URL citation from web search
2859
2965
  d({
2860
- type: E("url_citation"),
2966
+ type: x("url_citation"),
2861
2967
  url_citation: d({
2862
2968
  end_index: k(),
2863
2969
  start_index: k(),
@@ -2868,7 +2974,7 @@ var Bo = d({
2868
2974
  }).passthrough(),
2869
2975
  // File annotation from FileParserPlugin (old format)
2870
2976
  d({
2871
- type: E("file_annotation"),
2977
+ type: x("file_annotation"),
2872
2978
  file_annotation: d({
2873
2979
  file_id: s(),
2874
2980
  quote: s().optional()
@@ -2876,11 +2982,11 @@ var Bo = d({
2876
2982
  }).passthrough(),
2877
2983
  // File annotation from FileParserPlugin (new format)
2878
2984
  d({
2879
- type: E("file"),
2985
+ type: x("file"),
2880
2986
  file: d({
2881
2987
  hash: s(),
2882
2988
  name: s(),
2883
- content: v(
2989
+ content: y(
2884
2990
  d({
2885
2991
  type: s(),
2886
2992
  text: s().optional()
@@ -2892,11 +2998,11 @@ var Bo = d({
2892
2998
  ).nullish()
2893
2999
  }).passthrough().nullish(),
2894
3000
  logprobs: d({
2895
- content: v(
3001
+ content: y(
2896
3002
  d({
2897
3003
  token: s(),
2898
3004
  logprob: k(),
2899
- top_logprobs: v(
3005
+ top_logprobs: y(
2900
3006
  d({
2901
3007
  token: s(),
2902
3008
  logprob: k()
@@ -2910,8 +3016,8 @@ var Bo = d({
2910
3016
  }).passthrough()
2911
3017
  )
2912
3018
  }),
2913
- Ae
2914
- ]), Go = class {
3019
+ Ue
3020
+ ]), ts = class {
2915
3021
  constructor(e, t, n) {
2916
3022
  this.specificationVersion = "v2", this.provider = "openrouter", this.defaultObjectGenerationMode = "tool", this.supportsImageUrls = !0, this.supportedUrls = {
2917
3023
  "image/*": [
@@ -2929,15 +3035,15 @@ var Bo = d({
2929
3035
  topP: r,
2930
3036
  frequencyPenalty: o,
2931
3037
  presencePenalty: a,
2932
- seed: l,
3038
+ seed: i,
2933
3039
  stopSequences: c,
2934
- responseFormat: i,
3040
+ responseFormat: l,
2935
3041
  topK: u,
2936
3042
  tools: h,
2937
- toolChoice: f
3043
+ toolChoice: g
2938
3044
  }) {
2939
- var m;
2940
- const _ = O(O({
3045
+ var f;
3046
+ const v = P(P({
2941
3047
  // model id:
2942
3048
  model: this.modelId,
2943
3049
  models: this.settings.models,
@@ -2953,21 +3059,21 @@ var Bo = d({
2953
3059
  top_p: r,
2954
3060
  frequency_penalty: o,
2955
3061
  presence_penalty: a,
2956
- seed: l,
3062
+ seed: i,
2957
3063
  stop: c,
2958
- response_format: i?.type === "json" ? i.schema != null ? {
3064
+ response_format: l?.type === "json" ? l.schema != null ? {
2959
3065
  type: "json_schema",
2960
- json_schema: O({
2961
- schema: i.schema,
3066
+ json_schema: P({
3067
+ schema: l.schema,
2962
3068
  strict: !0,
2963
- name: (m = i.name) != null ? m : "response"
2964
- }, i.description && {
2965
- description: i.description
3069
+ name: (f = l.name) != null ? f : "response"
3070
+ }, l.description && {
3071
+ description: l.description
2966
3072
  })
2967
3073
  } : { type: "json_object" } : void 0,
2968
3074
  top_k: u,
2969
3075
  // messages:
2970
- messages: Ho(e),
3076
+ messages: Fo(e),
2971
3077
  // OpenRouter specific settings:
2972
3078
  include_reasoning: this.settings.includeReasoning,
2973
3079
  reasoning: this.settings.reasoning,
@@ -2981,7 +3087,7 @@ var Bo = d({
2981
3087
  debug: this.settings.debug
2982
3088
  }, this.config.extraBody), this.settings.extraBody);
2983
3089
  if (h && h.length > 0) {
2984
- const g = h.filter(
3090
+ const m = h.filter(
2985
3091
  (p) => p.type === "function"
2986
3092
  ).map((p) => ({
2987
3093
  type: "function",
@@ -2991,96 +3097,96 @@ var Bo = d({
2991
3097
  parameters: p.inputSchema
2992
3098
  }
2993
3099
  }));
2994
- return Ee(O({}, _), {
2995
- tools: g,
2996
- tool_choice: f ? Vo(f) : void 0
3100
+ return xe(P({}, v), {
3101
+ tools: m,
3102
+ tool_choice: g ? Zo(g) : void 0
2997
3103
  });
2998
3104
  }
2999
- return _;
3105
+ return v;
3000
3106
  }
3001
3107
  async doGenerate(e) {
3002
- var t, n, r, o, a, l, c, i, u, h, f, m, _, g, p, b, y, T, w, A, x, $, M;
3003
- const W = (e.providerOptions || {}).openrouter || {}, z = O(O({}, this.getArgs(e)), W), { value: G, responseHeaders: re } = await pe({
3108
+ var t, n, r, o, a, i, c, l, u, h, g, f, v, m, p, w, b, R, T, S, M, $, A;
3109
+ const z = (e.providerOptions || {}).openrouter || {}, J = P(P({}, this.getArgs(e)), z), { value: G, responseHeaders: se } = await fe({
3004
3110
  url: this.config.url({
3005
3111
  path: "/chat/completions",
3006
3112
  modelId: this.modelId
3007
3113
  }),
3008
- headers: de(this.config.headers(), e.headers),
3009
- body: z,
3010
- failedResponseHandler: he,
3011
- successfulResponseHandler: Ze(
3012
- zo
3114
+ headers: me(this.config.headers(), e.headers),
3115
+ body: J,
3116
+ failedResponseHandler: ge,
3117
+ successfulResponseHandler: Ye(
3118
+ Qo
3013
3119
  ),
3014
3120
  abortSignal: e.abortSignal,
3015
3121
  fetch: this.config.fetch
3016
3122
  });
3017
3123
  if ("error" in G) {
3018
- const R = G.error;
3019
- throw new K({
3020
- message: R.message,
3124
+ const _ = G.error;
3125
+ throw new F({
3126
+ message: _.message,
3021
3127
  url: this.config.url({
3022
3128
  path: "/chat/completions",
3023
3129
  modelId: this.modelId
3024
3130
  }),
3025
- requestBodyValues: z,
3131
+ requestBodyValues: J,
3026
3132
  statusCode: 200,
3027
- responseHeaders: re,
3028
- data: R
3133
+ responseHeaders: se,
3134
+ data: _
3029
3135
  });
3030
3136
  }
3031
- const j = G, L = j.choices[0];
3032
- if (!L)
3137
+ const D = G, H = D.choices[0];
3138
+ if (!H)
3033
3139
  throw new un({
3034
3140
  message: "No choice in response"
3035
3141
  });
3036
- const te = j.usage ? {
3037
- inputTokens: (t = j.usage.prompt_tokens) != null ? t : 0,
3038
- outputTokens: (n = j.usage.completion_tokens) != null ? n : 0,
3039
- totalTokens: ((r = j.usage.prompt_tokens) != null ? r : 0) + ((o = j.usage.completion_tokens) != null ? o : 0),
3040
- reasoningTokens: (l = (a = j.usage.completion_tokens_details) == null ? void 0 : a.reasoning_tokens) != null ? l : 0,
3041
- cachedInputTokens: (i = (c = j.usage.prompt_tokens_details) == null ? void 0 : c.cached_tokens) != null ? i : 0
3142
+ const ne = D.usage ? {
3143
+ inputTokens: (t = D.usage.prompt_tokens) != null ? t : 0,
3144
+ outputTokens: (n = D.usage.completion_tokens) != null ? n : 0,
3145
+ totalTokens: ((r = D.usage.prompt_tokens) != null ? r : 0) + ((o = D.usage.completion_tokens) != null ? o : 0),
3146
+ reasoningTokens: (i = (a = D.usage.completion_tokens_details) == null ? void 0 : a.reasoning_tokens) != null ? i : 0,
3147
+ cachedInputTokens: (l = (c = D.usage.prompt_tokens_details) == null ? void 0 : c.cached_tokens) != null ? l : 0
3042
3148
  } : {
3043
3149
  inputTokens: 0,
3044
3150
  outputTokens: 0,
3045
3151
  totalTokens: 0,
3046
3152
  reasoningTokens: 0,
3047
3153
  cachedInputTokens: 0
3048
- }, oe = (u = L.message.reasoning_details) != null ? u : [], ge = oe.length > 0 ? oe.map((R) => {
3049
- switch (R.type) {
3154
+ }, re = (u = H.message.reasoning_details) != null ? u : [], ve = re.length > 0 ? re.map((_) => {
3155
+ switch (_.type) {
3050
3156
  case "reasoning.text": {
3051
- if (R.text)
3157
+ if (_.text)
3052
3158
  return {
3053
3159
  type: "reasoning",
3054
- text: R.text,
3160
+ text: _.text,
3055
3161
  providerMetadata: {
3056
3162
  openrouter: {
3057
- reasoning_details: [R]
3163
+ reasoning_details: [_]
3058
3164
  }
3059
3165
  }
3060
3166
  };
3061
3167
  break;
3062
3168
  }
3063
3169
  case "reasoning.summary": {
3064
- if (R.summary)
3170
+ if (_.summary)
3065
3171
  return {
3066
3172
  type: "reasoning",
3067
- text: R.summary,
3173
+ text: _.summary,
3068
3174
  providerMetadata: {
3069
3175
  openrouter: {
3070
- reasoning_details: [R]
3176
+ reasoning_details: [_]
3071
3177
  }
3072
3178
  }
3073
3179
  };
3074
3180
  break;
3075
3181
  }
3076
3182
  case "reasoning.encrypted": {
3077
- if (R.data)
3183
+ if (_.data)
3078
3184
  return {
3079
3185
  type: "reasoning",
3080
3186
  text: "[REDACTED]",
3081
3187
  providerMetadata: {
3082
3188
  openrouter: {
3083
- reasoning_details: [R]
3189
+ reasoning_details: [_]
3084
3190
  }
3085
3191
  }
3086
3192
  };
@@ -3088,353 +3194,366 @@ var Bo = d({
3088
3194
  }
3089
3195
  }
3090
3196
  return null;
3091
- }).filter((R) => R !== null) : L.message.reasoning ? [
3197
+ }).filter((_) => _ !== null) : H.message.reasoning ? [
3092
3198
  {
3093
3199
  type: "reasoning",
3094
- text: L.message.reasoning
3200
+ text: H.message.reasoning
3095
3201
  }
3096
3202
  ] : [], Z = [];
3097
- if (Z.push(...ge), L.message.content && Z.push({
3203
+ if (Z.push(...ve), H.message.content && Z.push({
3098
3204
  type: "text",
3099
- text: L.message.content
3100
- }), L.message.tool_calls)
3101
- for (const R of L.message.tool_calls)
3205
+ text: H.message.content
3206
+ }), H.message.tool_calls)
3207
+ for (const _ of H.message.tool_calls)
3102
3208
  Z.push({
3103
3209
  type: "tool-call",
3104
- toolCallId: (h = R.id) != null ? h : F(),
3105
- toolName: R.function.name,
3106
- input: R.function.arguments,
3210
+ toolCallId: (h = _.id) != null ? h : W(),
3211
+ toolName: _.function.name,
3212
+ input: _.function.arguments,
3107
3213
  providerMetadata: {
3108
3214
  openrouter: {
3109
- reasoning_details: oe
3215
+ reasoning_details: re
3110
3216
  }
3111
3217
  }
3112
3218
  });
3113
- if (L.message.images)
3114
- for (const R of L.message.images)
3219
+ if (H.message.images)
3220
+ for (const _ of H.message.images)
3115
3221
  Z.push({
3116
3222
  type: "file",
3117
- mediaType: dt(R.image_url.url, "image/jpeg"),
3118
- data: Ve(R.image_url.url)
3223
+ mediaType: ht(_.image_url.url, "image/jpeg"),
3224
+ data: Je(_.image_url.url)
3119
3225
  });
3120
- if (L.message.annotations)
3121
- for (const R of L.message.annotations)
3122
- R.type === "url_citation" && Z.push({
3226
+ if (H.message.annotations)
3227
+ for (const _ of H.message.annotations)
3228
+ _.type === "url_citation" && Z.push({
3123
3229
  type: "source",
3124
3230
  sourceType: "url",
3125
- id: R.url_citation.url,
3126
- url: R.url_citation.url,
3127
- title: R.url_citation.title,
3231
+ id: _.url_citation.url,
3232
+ url: _.url_citation.url,
3233
+ title: _.url_citation.title,
3128
3234
  providerMetadata: {
3129
3235
  openrouter: {
3130
- content: R.url_citation.content || ""
3236
+ content: _.url_citation.content || ""
3131
3237
  }
3132
3238
  }
3133
3239
  });
3134
- const U = (f = L.message.annotations) == null ? void 0 : f.filter(
3135
- (R) => R.type === "file"
3136
- );
3240
+ const ae = (g = H.message.annotations) == null ? void 0 : g.filter(
3241
+ (_) => _.type === "file"
3242
+ ), U = H.message.tool_calls && H.message.tool_calls.length > 0, Q = re.some(
3243
+ (_) => _.type === "reasoning.encrypted" && _.data
3244
+ ), ie = U && Q && H.finish_reason === "stop" ? "tool-calls" : Oe(H.finish_reason);
3137
3245
  return {
3138
3246
  content: Z,
3139
- finishReason: xe(L.finish_reason),
3140
- usage: te,
3247
+ finishReason: ie,
3248
+ usage: ne,
3141
3249
  warnings: [],
3142
3250
  providerMetadata: {
3143
- openrouter: jo.parse({
3144
- provider: (m = j.provider) != null ? m : "",
3145
- reasoning_details: (_ = L.message.reasoning_details) != null ? _ : [],
3146
- annotations: U && U.length > 0 ? U : void 0,
3147
- usage: O(O(O({
3148
- promptTokens: (g = te.inputTokens) != null ? g : 0,
3149
- completionTokens: (p = te.outputTokens) != null ? p : 0,
3150
- totalTokens: (b = te.totalTokens) != null ? b : 0,
3151
- cost: (y = j.usage) == null ? void 0 : y.cost
3152
- }, ((w = (T = j.usage) == null ? void 0 : T.prompt_tokens_details) == null ? void 0 : w.cached_tokens) != null ? {
3251
+ openrouter: Jo.parse({
3252
+ provider: (f = D.provider) != null ? f : "",
3253
+ reasoning_details: (v = H.message.reasoning_details) != null ? v : [],
3254
+ annotations: ae && ae.length > 0 ? ae : void 0,
3255
+ usage: P(P(P({
3256
+ promptTokens: (m = ne.inputTokens) != null ? m : 0,
3257
+ completionTokens: (p = ne.outputTokens) != null ? p : 0,
3258
+ totalTokens: (w = ne.totalTokens) != null ? w : 0,
3259
+ cost: (b = D.usage) == null ? void 0 : b.cost
3260
+ }, ((T = (R = D.usage) == null ? void 0 : R.prompt_tokens_details) == null ? void 0 : T.cached_tokens) != null ? {
3153
3261
  promptTokensDetails: {
3154
- cachedTokens: j.usage.prompt_tokens_details.cached_tokens
3262
+ cachedTokens: D.usage.prompt_tokens_details.cached_tokens
3155
3263
  }
3156
- } : {}), ((x = (A = j.usage) == null ? void 0 : A.completion_tokens_details) == null ? void 0 : x.reasoning_tokens) != null ? {
3264
+ } : {}), ((M = (S = D.usage) == null ? void 0 : S.completion_tokens_details) == null ? void 0 : M.reasoning_tokens) != null ? {
3157
3265
  completionTokensDetails: {
3158
- reasoningTokens: j.usage.completion_tokens_details.reasoning_tokens
3266
+ reasoningTokens: D.usage.completion_tokens_details.reasoning_tokens
3159
3267
  }
3160
- } : {}), ((M = ($ = j.usage) == null ? void 0 : $.cost_details) == null ? void 0 : M.upstream_inference_cost) != null ? {
3268
+ } : {}), ((A = ($ = D.usage) == null ? void 0 : $.cost_details) == null ? void 0 : A.upstream_inference_cost) != null ? {
3161
3269
  costDetails: {
3162
- upstreamInferenceCost: j.usage.cost_details.upstream_inference_cost
3270
+ upstreamInferenceCost: D.usage.cost_details.upstream_inference_cost
3163
3271
  }
3164
3272
  } : {})
3165
3273
  })
3166
3274
  },
3167
- request: { body: z },
3275
+ request: { body: J },
3168
3276
  response: {
3169
- id: j.id,
3170
- modelId: j.model,
3171
- headers: re
3277
+ id: D.id,
3278
+ modelId: D.model,
3279
+ headers: se
3172
3280
  }
3173
3281
  };
3174
3282
  }
3175
3283
  async doStream(e) {
3176
3284
  var t;
3177
- const r = (e.providerOptions || {}).openrouter || {}, o = O(O({}, this.getArgs(e)), r), { value: a, responseHeaders: l } = await pe({
3285
+ const r = (e.providerOptions || {}).openrouter || {}, o = P(P({}, this.getArgs(e)), r), { value: a, responseHeaders: i } = await fe({
3178
3286
  url: this.config.url({
3179
3287
  path: "/chat/completions",
3180
3288
  modelId: this.modelId
3181
3289
  }),
3182
- headers: de(this.config.headers(), e.headers),
3183
- body: Ee(O({}, o), {
3290
+ headers: me(this.config.headers(), e.headers),
3291
+ body: xe(P({}, o), {
3184
3292
  stream: !0,
3185
3293
  // only include stream_options when in strict compatibility mode:
3186
- stream_options: this.config.compatibility === "strict" ? O({
3294
+ stream_options: this.config.compatibility === "strict" ? P({
3187
3295
  include_usage: !0
3188
3296
  }, (t = this.settings.usage) != null && t.include ? { include_usage: !0 } : {}) : void 0
3189
3297
  }),
3190
- failedResponseHandler: he,
3298
+ failedResponseHandler: ge,
3191
3299
  successfulResponseHandler: yn(
3192
- Wo
3300
+ es
3193
3301
  ),
3194
3302
  abortSignal: e.abortSignal,
3195
3303
  fetch: this.config.fetch
3196
3304
  }), c = [];
3197
- let i = "other";
3305
+ let l = "other";
3198
3306
  const u = {
3199
3307
  inputTokens: Number.NaN,
3200
3308
  outputTokens: Number.NaN,
3201
3309
  totalTokens: Number.NaN,
3202
3310
  reasoningTokens: Number.NaN,
3203
3311
  cachedInputTokens: Number.NaN
3204
- }, h = {}, f = [];
3205
- let m = !1, _ = !1, g, p, b, y;
3312
+ }, h = {}, g = [], f = [];
3313
+ let v = !1, m = !1, p, w, b, R;
3206
3314
  return {
3207
3315
  stream: a.pipeThrough(
3208
3316
  new TransformStream({
3209
- transform(T, w) {
3210
- var A, x, $, M, H, W, z, G, re, j, L, te, oe, ge, Z;
3317
+ transform(T, S) {
3318
+ var M, $, A, I, z, J, G, se, D, H, ne, re, ve, Z, ae;
3211
3319
  if (!T.success) {
3212
- i = "error", w.enqueue({ type: "error", error: T.error });
3320
+ l = "error", S.enqueue({ type: "error", error: T.error });
3213
3321
  return;
3214
3322
  }
3215
3323
  const U = T.value;
3216
3324
  if ("error" in U) {
3217
- i = "error", w.enqueue({ type: "error", error: U.error });
3325
+ l = "error", S.enqueue({ type: "error", error: U.error });
3218
3326
  return;
3219
3327
  }
3220
- if (U.provider && (y = U.provider), U.id && (b = U.id, w.enqueue({
3328
+ if (U.provider && (R = U.provider), U.id && (b = U.id, S.enqueue({
3221
3329
  type: "response-metadata",
3222
3330
  id: U.id
3223
- })), U.model && w.enqueue({
3331
+ })), U.model && S.enqueue({
3224
3332
  type: "response-metadata",
3225
3333
  modelId: U.model
3226
3334
  }), U.usage != null) {
3227
3335
  if (u.inputTokens = U.usage.prompt_tokens, u.outputTokens = U.usage.completion_tokens, u.totalTokens = U.usage.prompt_tokens + U.usage.completion_tokens, h.promptTokens = U.usage.prompt_tokens, U.usage.prompt_tokens_details) {
3228
- const I = (A = U.usage.prompt_tokens_details.cached_tokens) != null ? A : 0;
3229
- u.cachedInputTokens = I, h.promptTokensDetails = {
3230
- cachedTokens: I
3336
+ const C = (M = U.usage.prompt_tokens_details.cached_tokens) != null ? M : 0;
3337
+ u.cachedInputTokens = C, h.promptTokensDetails = {
3338
+ cachedTokens: C
3231
3339
  };
3232
3340
  }
3233
3341
  if (h.completionTokens = U.usage.completion_tokens, U.usage.completion_tokens_details) {
3234
- const I = (x = U.usage.completion_tokens_details.reasoning_tokens) != null ? x : 0;
3235
- u.reasoningTokens = I, h.completionTokensDetails = {
3236
- reasoningTokens: I
3342
+ const C = ($ = U.usage.completion_tokens_details.reasoning_tokens) != null ? $ : 0;
3343
+ u.reasoningTokens = C, h.completionTokensDetails = {
3344
+ reasoningTokens: C
3237
3345
  };
3238
3346
  }
3239
3347
  h.cost = U.usage.cost, h.totalTokens = U.usage.total_tokens;
3240
- const C = ($ = U.usage.cost_details) == null ? void 0 : $.upstream_inference_cost;
3241
- C != null && (h.costDetails = {
3242
- upstreamInferenceCost: C
3348
+ const _ = (A = U.usage.cost_details) == null ? void 0 : A.upstream_inference_cost;
3349
+ _ != null && (h.costDetails = {
3350
+ upstreamInferenceCost: _
3243
3351
  });
3244
3352
  }
3245
- const R = U.choices[0];
3246
- if (R?.finish_reason != null && (i = xe(R.finish_reason)), R?.delta == null)
3353
+ const Q = U.choices[0];
3354
+ if (Q?.finish_reason != null && (l = Oe(Q.finish_reason)), Q?.delta == null)
3247
3355
  return;
3248
- const V = R.delta, fe = (C, I) => {
3249
- _ || (p = b || F(), w.enqueue({
3250
- providerMetadata: I,
3356
+ const q = Q.delta, ie = (_, C) => {
3357
+ m || (w = b || W(), S.enqueue({
3358
+ providerMetadata: C,
3251
3359
  type: "reasoning-start",
3252
- id: p
3253
- }), _ = !0), w.enqueue({
3254
- providerMetadata: I,
3360
+ id: w
3361
+ }), m = !0), S.enqueue({
3362
+ providerMetadata: C,
3255
3363
  type: "reasoning-delta",
3256
- delta: C,
3257
- id: p || F()
3364
+ delta: _,
3365
+ id: w || W()
3258
3366
  });
3259
3367
  };
3260
- if (V.reasoning_details && V.reasoning_details.length > 0) {
3261
- for (const I of V.reasoning_details)
3262
- if (I.type === "reasoning.text") {
3263
- const N = f[f.length - 1];
3264
- N?.type === "reasoning.text" ? (N.text = (N.text || "") + (I.text || ""), N.signature = N.signature || I.signature, N.format = N.format || I.format) : f.push(O({}, I));
3368
+ if (q.reasoning_details && q.reasoning_details.length > 0) {
3369
+ for (const C of q.reasoning_details)
3370
+ if (C.type === "reasoning.text") {
3371
+ const N = g[g.length - 1];
3372
+ N?.type === "reasoning.text" ? (N.text = (N.text || "") + (C.text || ""), N.signature = N.signature || C.signature, N.format = N.format || C.format) : g.push(P({}, C));
3265
3373
  } else
3266
- f.push(I);
3267
- const C = {
3374
+ g.push(C);
3375
+ const _ = {
3268
3376
  openrouter: {
3269
- reasoning_details: V.reasoning_details
3377
+ reasoning_details: q.reasoning_details
3270
3378
  }
3271
3379
  };
3272
- for (const I of V.reasoning_details)
3273
- switch (I.type) {
3380
+ for (const C of q.reasoning_details)
3381
+ switch (C.type) {
3274
3382
  case "reasoning.text": {
3275
- I.text && fe(I.text, C);
3383
+ C.text && ie(C.text, _);
3276
3384
  break;
3277
3385
  }
3278
3386
  case "reasoning.encrypted": {
3279
- I.data && fe("[REDACTED]", C);
3387
+ C.data && ie("[REDACTED]", _);
3280
3388
  break;
3281
3389
  }
3282
3390
  case "reasoning.summary": {
3283
- I.summary && fe(I.summary, C);
3391
+ C.summary && ie(C.summary, _);
3284
3392
  break;
3285
3393
  }
3286
3394
  }
3287
- } else V.reasoning && fe(V.reasoning);
3288
- if (V.content && (_ && !m && (w.enqueue({
3395
+ } else q.reasoning && ie(q.reasoning);
3396
+ if (q.content && (m && !v && (S.enqueue({
3289
3397
  type: "reasoning-end",
3290
- id: p || F()
3291
- }), _ = !1), m || (g = b || F(), w.enqueue({
3398
+ id: w || W()
3399
+ }), m = !1), v || (p = b || W(), S.enqueue({
3292
3400
  type: "text-start",
3293
- id: g
3294
- }), m = !0), w.enqueue({
3401
+ id: p
3402
+ }), v = !0), S.enqueue({
3295
3403
  type: "text-delta",
3296
- delta: V.content,
3297
- id: g || F()
3298
- })), V.annotations)
3299
- for (const C of V.annotations)
3300
- C.type === "url_citation" && w.enqueue({
3301
- type: "source",
3302
- sourceType: "url",
3303
- id: C.url_citation.url,
3304
- url: C.url_citation.url,
3305
- title: C.url_citation.title,
3306
- providerMetadata: {
3307
- openrouter: {
3308
- content: C.url_citation.content || ""
3404
+ delta: q.content,
3405
+ id: p || W()
3406
+ })), q.annotations) {
3407
+ for (const _ of q.annotations)
3408
+ if (_.type === "url_citation")
3409
+ S.enqueue({
3410
+ type: "source",
3411
+ sourceType: "url",
3412
+ id: _.url_citation.url,
3413
+ url: _.url_citation.url,
3414
+ title: _.url_citation.title,
3415
+ providerMetadata: {
3416
+ openrouter: {
3417
+ content: _.url_citation.content || ""
3418
+ }
3309
3419
  }
3310
- }
3311
- });
3312
- if (V.tool_calls != null)
3313
- for (const C of V.tool_calls) {
3314
- const I = (M = C.index) != null ? M : c.length - 1;
3315
- if (c[I] == null) {
3316
- if (C.type !== "function")
3317
- throw new le({
3318
- data: C,
3420
+ });
3421
+ else if (_.type === "file") {
3422
+ const C = _.file;
3423
+ C && typeof C == "object" && "hash" in C && "name" in C && f.push(
3424
+ _
3425
+ );
3426
+ }
3427
+ }
3428
+ if (q.tool_calls != null)
3429
+ for (const _ of q.tool_calls) {
3430
+ const C = (I = _.index) != null ? I : c.length - 1;
3431
+ if (c[C] == null) {
3432
+ if (_.type !== "function")
3433
+ throw new de({
3434
+ data: _,
3319
3435
  message: "Expected 'function' type."
3320
3436
  });
3321
- if (C.id == null)
3322
- throw new le({
3323
- data: C,
3437
+ if (_.id == null)
3438
+ throw new de({
3439
+ data: _,
3324
3440
  message: "Expected 'id' to be a string."
3325
3441
  });
3326
- if (((H = C.function) == null ? void 0 : H.name) == null)
3327
- throw new le({
3328
- data: C,
3442
+ if (((z = _.function) == null ? void 0 : z.name) == null)
3443
+ throw new de({
3444
+ data: _,
3329
3445
  message: "Expected 'function.name' to be a string."
3330
3446
  });
3331
- c[I] = {
3332
- id: C.id,
3447
+ c[C] = {
3448
+ id: _.id,
3333
3449
  type: "function",
3334
3450
  function: {
3335
- name: C.function.name,
3336
- arguments: (W = C.function.arguments) != null ? W : ""
3451
+ name: _.function.name,
3452
+ arguments: (J = _.function.arguments) != null ? J : ""
3337
3453
  },
3338
3454
  inputStarted: !1,
3339
3455
  sent: !1
3340
3456
  };
3341
- const B = c[I];
3342
- if (B == null)
3343
- throw new le({
3344
- data: { index: I, toolCallsLength: c.length },
3345
- message: `Tool call at index ${I} is missing after creation.`
3457
+ const V = c[C];
3458
+ if (V == null)
3459
+ throw new de({
3460
+ data: { index: C, toolCallsLength: c.length },
3461
+ message: `Tool call at index ${C} is missing after creation.`
3346
3462
  });
3347
- ((z = B.function) == null ? void 0 : z.name) != null && ((G = B.function) == null ? void 0 : G.arguments) != null && Me(B.function.arguments) && (B.inputStarted = !0, w.enqueue({
3463
+ ((G = V.function) == null ? void 0 : G.name) != null && ((se = V.function) == null ? void 0 : se.arguments) != null && je(V.function.arguments) && (V.inputStarted = !0, S.enqueue({
3348
3464
  type: "tool-input-start",
3349
- id: B.id,
3350
- toolName: B.function.name
3351
- }), w.enqueue({
3465
+ id: V.id,
3466
+ toolName: V.function.name
3467
+ }), S.enqueue({
3352
3468
  type: "tool-input-delta",
3353
- id: B.id,
3354
- delta: B.function.arguments
3355
- }), w.enqueue({
3469
+ id: V.id,
3470
+ delta: V.function.arguments
3471
+ }), S.enqueue({
3356
3472
  type: "tool-input-end",
3357
- id: B.id
3358
- }), w.enqueue({
3473
+ id: V.id
3474
+ }), S.enqueue({
3359
3475
  type: "tool-call",
3360
- toolCallId: B.id,
3361
- toolName: B.function.name,
3362
- input: B.function.arguments,
3476
+ toolCallId: V.id,
3477
+ toolName: V.function.name,
3478
+ input: V.function.arguments,
3363
3479
  providerMetadata: {
3364
3480
  openrouter: {
3365
- reasoning_details: f
3481
+ reasoning_details: g
3366
3482
  }
3367
3483
  }
3368
- }), B.sent = !0);
3484
+ }), V.sent = !0);
3369
3485
  continue;
3370
3486
  }
3371
- const N = c[I];
3487
+ const N = c[C];
3372
3488
  if (N == null)
3373
- throw new le({
3489
+ throw new de({
3374
3490
  data: {
3375
- index: I,
3491
+ index: C,
3376
3492
  toolCallsLength: c.length,
3377
- toolCallDelta: C
3493
+ toolCallDelta: _
3378
3494
  },
3379
- message: `Tool call at index ${I} is missing during merge.`
3495
+ message: `Tool call at index ${C} is missing during merge.`
3380
3496
  });
3381
- N.inputStarted || (N.inputStarted = !0, w.enqueue({
3497
+ N.inputStarted || (N.inputStarted = !0, S.enqueue({
3382
3498
  type: "tool-input-start",
3383
3499
  id: N.id,
3384
3500
  toolName: N.function.name
3385
- })), ((re = C.function) == null ? void 0 : re.arguments) != null && (N.function.arguments += (L = (j = C.function) == null ? void 0 : j.arguments) != null ? L : ""), w.enqueue({
3501
+ })), ((D = _.function) == null ? void 0 : D.arguments) != null && (N.function.arguments += (ne = (H = _.function) == null ? void 0 : H.arguments) != null ? ne : ""), S.enqueue({
3386
3502
  type: "tool-input-delta",
3387
3503
  id: N.id,
3388
- delta: (te = C.function.arguments) != null ? te : ""
3389
- }), ((oe = N.function) == null ? void 0 : oe.name) != null && ((ge = N.function) == null ? void 0 : ge.arguments) != null && Me(N.function.arguments) && (w.enqueue({
3504
+ delta: (re = _.function.arguments) != null ? re : ""
3505
+ }), ((ve = N.function) == null ? void 0 : ve.name) != null && ((Z = N.function) == null ? void 0 : Z.arguments) != null && je(N.function.arguments) && (S.enqueue({
3390
3506
  type: "tool-call",
3391
- toolCallId: (Z = N.id) != null ? Z : F(),
3507
+ toolCallId: (ae = N.id) != null ? ae : W(),
3392
3508
  toolName: N.function.name,
3393
3509
  input: N.function.arguments,
3394
3510
  providerMetadata: {
3395
3511
  openrouter: {
3396
- reasoning_details: f
3512
+ reasoning_details: g
3397
3513
  }
3398
3514
  }
3399
3515
  }), N.sent = !0);
3400
3516
  }
3401
- if (V.images != null)
3402
- for (const C of V.images)
3403
- w.enqueue({
3517
+ if (q.images != null)
3518
+ for (const _ of q.images)
3519
+ S.enqueue({
3404
3520
  type: "file",
3405
- mediaType: dt(C.image_url.url, "image/jpeg"),
3406
- data: Ve(C.image_url.url)
3521
+ mediaType: ht(_.image_url.url, "image/jpeg"),
3522
+ data: Je(_.image_url.url)
3407
3523
  });
3408
3524
  },
3409
3525
  flush(T) {
3410
- var w;
3411
- if (i === "tool-calls")
3412
- for (const x of c)
3413
- x && !x.sent && (T.enqueue({
3526
+ var S;
3527
+ const M = c.length > 0, $ = g.some(
3528
+ (I) => I.type === "reasoning.encrypted" && I.data
3529
+ );
3530
+ if (M && $ && l === "stop" && (l = "tool-calls"), l === "tool-calls")
3531
+ for (const I of c)
3532
+ I && !I.sent && (T.enqueue({
3414
3533
  type: "tool-call",
3415
- toolCallId: (w = x.id) != null ? w : F(),
3416
- toolName: x.function.name,
3534
+ toolCallId: (S = I.id) != null ? S : W(),
3535
+ toolName: I.function.name,
3417
3536
  // Coerce invalid arguments to an empty JSON object
3418
- input: Me(x.function.arguments) ? x.function.arguments : "{}",
3537
+ input: je(I.function.arguments) ? I.function.arguments : "{}",
3419
3538
  providerMetadata: {
3420
3539
  openrouter: {
3421
- reasoning_details: f
3540
+ reasoning_details: g
3422
3541
  }
3423
3542
  }
3424
- }), x.sent = !0);
3425
- _ && T.enqueue({
3543
+ }), I.sent = !0);
3544
+ m && T.enqueue({
3426
3545
  type: "reasoning-end",
3427
- id: p || F()
3428
- }), m && T.enqueue({
3546
+ id: w || W()
3547
+ }), v && T.enqueue({
3429
3548
  type: "text-end",
3430
- id: g || F()
3549
+ id: p || W()
3431
3550
  });
3432
3551
  const A = {
3433
3552
  usage: h
3434
3553
  };
3435
- y !== void 0 && (A.provider = y), f.length > 0 && (A.reasoning_details = f), T.enqueue({
3554
+ R !== void 0 && (A.provider = R), g.length > 0 && (A.reasoning_details = g), f.length > 0 && (A.annotations = f), T.enqueue({
3436
3555
  type: "finish",
3437
- finishReason: i,
3556
+ finishReason: l,
3438
3557
  usage: u,
3439
3558
  providerMetadata: {
3440
3559
  openrouter: A
@@ -3445,11 +3564,11 @@ var Bo = d({
3445
3564
  ),
3446
3565
  warnings: [],
3447
3566
  request: { body: o },
3448
- response: { headers: l }
3567
+ response: { headers: i }
3449
3568
  };
3450
3569
  }
3451
3570
  };
3452
- function Fo({
3571
+ function ns({
3453
3572
  prompt: e,
3454
3573
  inputFormat: t,
3455
3574
  user: n = "user",
@@ -3461,20 +3580,20 @@ function Fo({
3461
3580
  e[0] && e[0].role === "system" && (o += `${e[0].content}
3462
3581
 
3463
3582
  `, e = e.slice(1));
3464
- for (const { role: a, content: l } of e)
3583
+ for (const { role: a, content: i } of e)
3465
3584
  switch (a) {
3466
3585
  case "system":
3467
- throw new to({
3468
- message: `Unexpected system message in prompt: ${l}`,
3586
+ throw new io({
3587
+ message: `Unexpected system message in prompt: ${i}`,
3469
3588
  prompt: e
3470
3589
  });
3471
3590
  case "user": {
3472
- const c = l.map((i) => {
3473
- switch (i.type) {
3591
+ const c = i.map((l) => {
3592
+ switch (l.type) {
3474
3593
  case "text":
3475
- return i.text;
3594
+ return l.text;
3476
3595
  case "file":
3477
- throw new ee({
3596
+ throw new te({
3478
3597
  functionality: "file attachments"
3479
3598
  });
3480
3599
  default:
@@ -3488,25 +3607,25 @@ ${c}
3488
3607
  break;
3489
3608
  }
3490
3609
  case "assistant": {
3491
- const c = l.map(
3492
- (i) => {
3493
- switch (i.type) {
3610
+ const c = i.map(
3611
+ (l) => {
3612
+ switch (l.type) {
3494
3613
  case "text":
3495
- return i.text;
3614
+ return l.text;
3496
3615
  case "tool-call":
3497
- throw new ee({
3616
+ throw new te({
3498
3617
  functionality: "tool-call messages"
3499
3618
  });
3500
3619
  case "tool-result":
3501
- throw new ee({
3620
+ throw new te({
3502
3621
  functionality: "tool-result messages"
3503
3622
  });
3504
3623
  case "reasoning":
3505
- throw new ee({
3624
+ throw new te({
3506
3625
  functionality: "reasoning messages"
3507
3626
  });
3508
3627
  case "file":
3509
- throw new ee({
3628
+ throw new te({
3510
3629
  functionality: "file attachments"
3511
3630
  });
3512
3631
  default:
@@ -3521,7 +3640,7 @@ ${c}
3521
3640
  break;
3522
3641
  }
3523
3642
  case "tool":
3524
- throw new ee({
3643
+ throw new te({
3525
3644
  functionality: "tool messages"
3526
3645
  });
3527
3646
  }
@@ -3530,21 +3649,21 @@ ${c}
3530
3649
  prompt: o
3531
3650
  };
3532
3651
  }
3533
- var pt = D([
3652
+ var mt = j([
3534
3653
  d({
3535
3654
  id: s().optional(),
3536
3655
  model: s().optional(),
3537
- choices: v(
3656
+ choices: y(
3538
3657
  d({
3539
3658
  text: s(),
3540
3659
  reasoning: s().nullish().optional(),
3541
- reasoning_details: Qe.nullish(),
3660
+ reasoning_details: tt.nullish(),
3542
3661
  finish_reason: s().nullish(),
3543
3662
  index: k().nullish(),
3544
3663
  logprobs: d({
3545
- tokens: v(s()),
3546
- token_logprobs: v(k()),
3547
- top_logprobs: v(Be(s(), k())).nullable()
3664
+ tokens: y(s()),
3665
+ token_logprobs: y(k()),
3666
+ top_logprobs: y(ze(s(), k())).nullable()
3548
3667
  }).passthrough().nullable().optional()
3549
3668
  }).passthrough()
3550
3669
  ),
@@ -3564,8 +3683,8 @@ var pt = D([
3564
3683
  }).passthrough().nullish()
3565
3684
  }).passthrough().nullish()
3566
3685
  }).passthrough(),
3567
- Ae
3568
- ]), Ko = class {
3686
+ Ue
3687
+ ]), rs = class {
3569
3688
  constructor(e, t, n) {
3570
3689
  this.specificationVersion = "v2", this.provider = "openrouter", this.supportsImageUrls = !0, this.supportedUrls = {
3571
3690
  "image/*": [
@@ -3583,26 +3702,26 @@ var pt = D([
3583
3702
  topP: r,
3584
3703
  frequencyPenalty: o,
3585
3704
  presencePenalty: a,
3586
- seed: l,
3705
+ seed: i,
3587
3706
  responseFormat: c,
3588
- topK: i,
3707
+ topK: l,
3589
3708
  stopSequences: u,
3590
3709
  tools: h,
3591
- toolChoice: f
3710
+ toolChoice: g
3592
3711
  }) {
3593
- const { prompt: m } = Fo({
3712
+ const { prompt: f } = ns({
3594
3713
  prompt: e,
3595
3714
  inputFormat: "prompt"
3596
3715
  });
3597
3716
  if (h?.length)
3598
- throw new ee({
3717
+ throw new te({
3599
3718
  functionality: "tools"
3600
3719
  });
3601
- if (f)
3602
- throw new ee({
3720
+ if (g)
3721
+ throw new te({
3603
3722
  functionality: "toolChoice"
3604
3723
  });
3605
- return O(O({
3724
+ return P(P({
3606
3725
  // model id:
3607
3726
  model: this.modelId,
3608
3727
  models: this.settings.models,
@@ -3617,49 +3736,49 @@ var pt = D([
3617
3736
  top_p: r,
3618
3737
  frequency_penalty: o,
3619
3738
  presence_penalty: a,
3620
- seed: l,
3739
+ seed: i,
3621
3740
  stop: u,
3622
3741
  response_format: c,
3623
- top_k: i,
3742
+ top_k: l,
3624
3743
  // prompt:
3625
- prompt: m,
3744
+ prompt: f,
3626
3745
  // OpenRouter specific settings:
3627
3746
  include_reasoning: this.settings.includeReasoning,
3628
3747
  reasoning: this.settings.reasoning
3629
3748
  }, this.config.extraBody), this.settings.extraBody);
3630
3749
  }
3631
3750
  async doGenerate(e) {
3632
- var t, n, r, o, a, l, c, i, u, h, f, m, _, g, p;
3633
- const y = (e.providerOptions || {}).openrouter || {}, T = O(O({}, this.getArgs(e)), y), { value: w, responseHeaders: A } = await pe({
3751
+ var t, n, r, o, a, i, c, l, u, h, g, f, v, m, p;
3752
+ const b = (e.providerOptions || {}).openrouter || {}, R = P(P({}, this.getArgs(e)), b), { value: T, responseHeaders: S } = await fe({
3634
3753
  url: this.config.url({
3635
3754
  path: "/completions",
3636
3755
  modelId: this.modelId
3637
3756
  }),
3638
- headers: de(this.config.headers(), e.headers),
3639
- body: T,
3640
- failedResponseHandler: he,
3641
- successfulResponseHandler: Ze(
3642
- pt
3757
+ headers: me(this.config.headers(), e.headers),
3758
+ body: R,
3759
+ failedResponseHandler: ge,
3760
+ successfulResponseHandler: Ye(
3761
+ mt
3643
3762
  ),
3644
3763
  abortSignal: e.abortSignal,
3645
3764
  fetch: this.config.fetch
3646
3765
  });
3647
- if ("error" in w) {
3648
- const $ = w.error;
3649
- throw new K({
3766
+ if ("error" in T) {
3767
+ const $ = T.error;
3768
+ throw new F({
3650
3769
  message: $.message,
3651
3770
  url: this.config.url({
3652
3771
  path: "/completions",
3653
3772
  modelId: this.modelId
3654
3773
  }),
3655
- requestBodyValues: T,
3774
+ requestBodyValues: R,
3656
3775
  statusCode: 200,
3657
- responseHeaders: A,
3776
+ responseHeaders: S,
3658
3777
  data: $
3659
3778
  });
3660
3779
  }
3661
- const x = w.choices[0];
3662
- if (!x)
3780
+ const M = T.choices[0];
3781
+ if (!M)
3663
3782
  throw new un({
3664
3783
  message: "No choice in OpenRouter completion response"
3665
3784
  });
@@ -3667,98 +3786,98 @@ var pt = D([
3667
3786
  content: [
3668
3787
  {
3669
3788
  type: "text",
3670
- text: (t = x.text) != null ? t : ""
3789
+ text: (t = M.text) != null ? t : ""
3671
3790
  }
3672
3791
  ],
3673
- finishReason: xe(x.finish_reason),
3792
+ finishReason: Oe(M.finish_reason),
3674
3793
  usage: {
3675
- inputTokens: (r = (n = w.usage) == null ? void 0 : n.prompt_tokens) != null ? r : 0,
3676
- outputTokens: (a = (o = w.usage) == null ? void 0 : o.completion_tokens) != null ? a : 0,
3677
- totalTokens: ((c = (l = w.usage) == null ? void 0 : l.prompt_tokens) != null ? c : 0) + ((u = (i = w.usage) == null ? void 0 : i.completion_tokens) != null ? u : 0),
3678
- reasoningTokens: (m = (f = (h = w.usage) == null ? void 0 : h.completion_tokens_details) == null ? void 0 : f.reasoning_tokens) != null ? m : 0,
3679
- cachedInputTokens: (p = (g = (_ = w.usage) == null ? void 0 : _.prompt_tokens_details) == null ? void 0 : g.cached_tokens) != null ? p : 0
3794
+ inputTokens: (r = (n = T.usage) == null ? void 0 : n.prompt_tokens) != null ? r : 0,
3795
+ outputTokens: (a = (o = T.usage) == null ? void 0 : o.completion_tokens) != null ? a : 0,
3796
+ totalTokens: ((c = (i = T.usage) == null ? void 0 : i.prompt_tokens) != null ? c : 0) + ((u = (l = T.usage) == null ? void 0 : l.completion_tokens) != null ? u : 0),
3797
+ reasoningTokens: (f = (g = (h = T.usage) == null ? void 0 : h.completion_tokens_details) == null ? void 0 : g.reasoning_tokens) != null ? f : 0,
3798
+ cachedInputTokens: (p = (m = (v = T.usage) == null ? void 0 : v.prompt_tokens_details) == null ? void 0 : m.cached_tokens) != null ? p : 0
3680
3799
  },
3681
3800
  warnings: [],
3682
3801
  response: {
3683
- headers: A
3802
+ headers: S
3684
3803
  }
3685
3804
  };
3686
3805
  }
3687
3806
  async doStream(e) {
3688
- const n = (e.providerOptions || {}).openrouter || {}, r = O(O({}, this.getArgs(e)), n), { value: o, responseHeaders: a } = await pe({
3807
+ const n = (e.providerOptions || {}).openrouter || {}, r = P(P({}, this.getArgs(e)), n), { value: o, responseHeaders: a } = await fe({
3689
3808
  url: this.config.url({
3690
3809
  path: "/completions",
3691
3810
  modelId: this.modelId
3692
3811
  }),
3693
- headers: de(this.config.headers(), e.headers),
3694
- body: Ee(O({}, r), {
3812
+ headers: me(this.config.headers(), e.headers),
3813
+ body: xe(P({}, r), {
3695
3814
  stream: !0,
3696
3815
  // only include stream_options when in strict compatibility mode:
3697
3816
  stream_options: this.config.compatibility === "strict" ? { include_usage: !0 } : void 0
3698
3817
  }),
3699
- failedResponseHandler: he,
3818
+ failedResponseHandler: ge,
3700
3819
  successfulResponseHandler: yn(
3701
- pt
3820
+ mt
3702
3821
  ),
3703
3822
  abortSignal: e.abortSignal,
3704
3823
  fetch: this.config.fetch
3705
3824
  });
3706
- let l = "other";
3825
+ let i = "other";
3707
3826
  const c = {
3708
3827
  inputTokens: Number.NaN,
3709
3828
  outputTokens: Number.NaN,
3710
3829
  totalTokens: Number.NaN,
3711
3830
  reasoningTokens: Number.NaN,
3712
3831
  cachedInputTokens: Number.NaN
3713
- }, i = {};
3832
+ }, l = {};
3714
3833
  return {
3715
3834
  stream: o.pipeThrough(
3716
3835
  new TransformStream({
3717
3836
  transform(u, h) {
3718
- var f, m, _;
3837
+ var g, f, v;
3719
3838
  if (!u.success) {
3720
- l = "error", h.enqueue({ type: "error", error: u.error });
3839
+ i = "error", h.enqueue({ type: "error", error: u.error });
3721
3840
  return;
3722
3841
  }
3723
- const g = u.value;
3724
- if ("error" in g) {
3725
- l = "error", h.enqueue({ type: "error", error: g.error });
3842
+ const m = u.value;
3843
+ if ("error" in m) {
3844
+ i = "error", h.enqueue({ type: "error", error: m.error });
3726
3845
  return;
3727
3846
  }
3728
- if (g.usage != null) {
3729
- if (c.inputTokens = g.usage.prompt_tokens, c.outputTokens = g.usage.completion_tokens, c.totalTokens = g.usage.prompt_tokens + g.usage.completion_tokens, i.promptTokens = g.usage.prompt_tokens, g.usage.prompt_tokens_details) {
3730
- const y = (f = g.usage.prompt_tokens_details.cached_tokens) != null ? f : 0;
3731
- c.cachedInputTokens = y, i.promptTokensDetails = {
3732
- cachedTokens: y
3847
+ if (m.usage != null) {
3848
+ if (c.inputTokens = m.usage.prompt_tokens, c.outputTokens = m.usage.completion_tokens, c.totalTokens = m.usage.prompt_tokens + m.usage.completion_tokens, l.promptTokens = m.usage.prompt_tokens, m.usage.prompt_tokens_details) {
3849
+ const b = (g = m.usage.prompt_tokens_details.cached_tokens) != null ? g : 0;
3850
+ c.cachedInputTokens = b, l.promptTokensDetails = {
3851
+ cachedTokens: b
3733
3852
  };
3734
3853
  }
3735
- if (i.completionTokens = g.usage.completion_tokens, g.usage.completion_tokens_details) {
3736
- const y = (m = g.usage.completion_tokens_details.reasoning_tokens) != null ? m : 0;
3737
- c.reasoningTokens = y, i.completionTokensDetails = {
3738
- reasoningTokens: y
3854
+ if (l.completionTokens = m.usage.completion_tokens, m.usage.completion_tokens_details) {
3855
+ const b = (f = m.usage.completion_tokens_details.reasoning_tokens) != null ? f : 0;
3856
+ c.reasoningTokens = b, l.completionTokensDetails = {
3857
+ reasoningTokens: b
3739
3858
  };
3740
3859
  }
3741
- i.cost = g.usage.cost, i.totalTokens = g.usage.total_tokens;
3742
- const b = (_ = g.usage.cost_details) == null ? void 0 : _.upstream_inference_cost;
3743
- b != null && (i.costDetails = {
3744
- upstreamInferenceCost: b
3860
+ l.cost = m.usage.cost, l.totalTokens = m.usage.total_tokens;
3861
+ const w = (v = m.usage.cost_details) == null ? void 0 : v.upstream_inference_cost;
3862
+ w != null && (l.costDetails = {
3863
+ upstreamInferenceCost: w
3745
3864
  });
3746
3865
  }
3747
- const p = g.choices[0];
3748
- p?.finish_reason != null && (l = xe(p.finish_reason)), p?.text != null && h.enqueue({
3866
+ const p = m.choices[0];
3867
+ p?.finish_reason != null && (i = Oe(p.finish_reason)), p?.text != null && h.enqueue({
3749
3868
  type: "text-delta",
3750
3869
  delta: p.text,
3751
- id: F()
3870
+ id: W()
3752
3871
  });
3753
3872
  },
3754
3873
  flush(u) {
3755
3874
  u.enqueue({
3756
3875
  type: "finish",
3757
- finishReason: l,
3876
+ finishReason: i,
3758
3877
  usage: c,
3759
3878
  providerMetadata: {
3760
3879
  openrouter: {
3761
- usage: i
3880
+ usage: l
3762
3881
  }
3763
3882
  }
3764
3883
  });
@@ -3770,81 +3889,81 @@ var pt = D([
3770
3889
  }
3771
3890
  };
3772
3891
  }
3773
- }, Zo = d({
3892
+ }, os = d({
3774
3893
  prompt_tokens: k(),
3775
3894
  total_tokens: k(),
3776
3895
  cost: k().optional()
3777
- }), Xo = d({
3778
- object: E("embedding"),
3779
- embedding: v(k()),
3896
+ }), ss = d({
3897
+ object: x("embedding"),
3898
+ embedding: y(k()),
3780
3899
  index: k().optional()
3781
- }), Yo = d({
3900
+ }), as = d({
3782
3901
  id: s().optional(),
3783
- object: E("list"),
3784
- data: v(Xo),
3902
+ object: x("list"),
3903
+ data: y(ss),
3785
3904
  model: s(),
3786
- usage: Zo.optional()
3787
- }), Qo = class {
3905
+ usage: os.optional()
3906
+ }), is = class {
3788
3907
  constructor(e, t, n) {
3789
3908
  this.specificationVersion = "v2", this.provider = "openrouter", this.maxEmbeddingsPerCall = void 0, this.supportsParallelCalls = !0, this.modelId = e, this.settings = t, this.config = n;
3790
3909
  }
3791
3910
  async doEmbed(e) {
3792
3911
  var t;
3793
- const { values: n, abortSignal: r, headers: o } = e, a = O(O({
3912
+ const { values: n, abortSignal: r, headers: o } = e, a = P(P({
3794
3913
  model: this.modelId,
3795
3914
  input: n,
3796
3915
  user: this.settings.user,
3797
3916
  provider: this.settings.provider
3798
- }, this.config.extraBody), this.settings.extraBody), { value: l, responseHeaders: c } = await pe({
3917
+ }, this.config.extraBody), this.settings.extraBody), { value: i, responseHeaders: c } = await fe({
3799
3918
  url: this.config.url({
3800
3919
  path: "/embeddings",
3801
3920
  modelId: this.modelId
3802
3921
  }),
3803
- headers: de(this.config.headers(), o),
3922
+ headers: me(this.config.headers(), o),
3804
3923
  body: a,
3805
- failedResponseHandler: he,
3806
- successfulResponseHandler: Ze(
3807
- Yo
3924
+ failedResponseHandler: ge,
3925
+ successfulResponseHandler: Ye(
3926
+ as
3808
3927
  ),
3809
3928
  abortSignal: r,
3810
3929
  fetch: this.config.fetch
3811
3930
  });
3812
3931
  return {
3813
- embeddings: l.data.map((i) => i.embedding),
3814
- usage: l.usage ? { tokens: l.usage.prompt_tokens } : void 0,
3815
- providerMetadata: (t = l.usage) != null && t.cost ? {
3932
+ embeddings: i.data.map((l) => l.embedding),
3933
+ usage: i.usage ? { tokens: i.usage.prompt_tokens } : void 0,
3934
+ providerMetadata: (t = i.usage) != null && t.cost ? {
3816
3935
  openrouter: {
3817
3936
  usage: {
3818
- cost: l.usage.cost
3937
+ cost: i.usage.cost
3819
3938
  }
3820
3939
  }
3821
3940
  } : void 0,
3822
3941
  response: {
3823
3942
  headers: c,
3824
- body: l
3943
+ body: i
3825
3944
  }
3826
3945
  };
3827
3946
  }
3828
3947
  };
3829
- function es(e) {
3948
+ function ls(e) {
3830
3949
  return Object.fromEntries(
3831
3950
  Object.entries(e).filter(([, t]) => t !== null)
3832
3951
  );
3833
3952
  }
3834
- function ts(e, ...t) {
3835
- const n = es(
3953
+ function cs(e, ...t) {
3954
+ const n = ls(
3836
3955
  e ?? {}
3837
3956
  ), o = [n["user-agent"] || "", ...t].filter(Boolean).join(" ");
3838
- return Ee(O({}, n), {
3957
+ return xe(P({}, n), {
3839
3958
  "user-agent": o
3840
3959
  });
3841
3960
  }
3842
- var ns = "1.4.1";
3961
+ var us = "1.5.4";
3843
3962
  function Sn(e = {}) {
3844
3963
  var t, n, r;
3845
- const o = (n = $o((t = e.baseURL) != null ? t : e.baseUrl)) != null ? n : "https://openrouter.ai/api/v1", a = (r = e.compatibility) != null ? r : "compatible", l = () => ts(
3846
- O(O({
3847
- Authorization: `Bearer ${_o({
3964
+ const o = (n = Lo((t = e.baseURL) != null ? t : e.baseUrl)) != null ? n : "https://openrouter.ai/api/v1", a = (r = e.compatibility) != null ? r : "compatible", i = () => cs(
3965
+ P(P({
3966
+ Authorization: `Bearer ${To({
3848
3967
  apiKey: e.apiKey,
3849
3968
  environmentVariableName: "OPENROUTER_API_KEY",
3850
3969
  description: "OpenRouter"
@@ -3852,87 +3971,87 @@ function Sn(e = {}) {
3852
3971
  }, e.headers), e.api_keys && Object.keys(e.api_keys).length > 0 && {
3853
3972
  "X-Provider-API-Keys": JSON.stringify(e.api_keys)
3854
3973
  }),
3855
- `ai-sdk/openrouter/${ns}`
3856
- ), c = (m, _ = {}) => new Go(m, _, {
3974
+ `ai-sdk/openrouter/${us}`
3975
+ ), c = (f, v = {}) => new ts(f, v, {
3857
3976
  provider: "openrouter.chat",
3858
- url: ({ path: g }) => `${o}${g}`,
3859
- headers: l,
3977
+ url: ({ path: m }) => `${o}${m}`,
3978
+ headers: i,
3860
3979
  compatibility: a,
3861
3980
  fetch: e.fetch,
3862
3981
  extraBody: e.extraBody
3863
- }), i = (m, _ = {}) => new Ko(m, _, {
3982
+ }), l = (f, v = {}) => new rs(f, v, {
3864
3983
  provider: "openrouter.completion",
3865
- url: ({ path: g }) => `${o}${g}`,
3866
- headers: l,
3984
+ url: ({ path: m }) => `${o}${m}`,
3985
+ headers: i,
3867
3986
  compatibility: a,
3868
3987
  fetch: e.fetch,
3869
3988
  extraBody: e.extraBody
3870
- }), u = (m, _ = {}) => new Qo(m, _, {
3989
+ }), u = (f, v = {}) => new is(f, v, {
3871
3990
  provider: "openrouter.embedding",
3872
- url: ({ path: g }) => `${o}${g}`,
3873
- headers: l,
3991
+ url: ({ path: m }) => `${o}${m}`,
3992
+ headers: i,
3874
3993
  fetch: e.fetch,
3875
3994
  extraBody: e.extraBody
3876
- }), h = (m, _) => {
3995
+ }), h = (f, v) => {
3877
3996
  if (new.target)
3878
3997
  throw new Error(
3879
3998
  "The OpenRouter model function cannot be called with the new keyword."
3880
3999
  );
3881
- return m === "openai/gpt-3.5-turbo-instruct" ? i(
3882
- m,
3883
- _
3884
- ) : c(m, _);
3885
- }, f = (m, _) => h(m, _);
3886
- return f.languageModel = h, f.chat = c, f.completion = i, f.textEmbeddingModel = u, f.embedding = u, f;
4000
+ return f === "openai/gpt-3.5-turbo-instruct" ? l(
4001
+ f,
4002
+ v
4003
+ ) : c(f, v);
4004
+ }, g = (f, v) => h(f, v);
4005
+ return g.languageModel = h, g.chat = c, g.completion = l, g.textEmbeddingModel = u, g.embedding = u, g;
3887
4006
  }
3888
4007
  Sn({
3889
4008
  compatibility: "strict"
3890
4009
  // strict for OpenRouter API
3891
4010
  });
3892
- const rs = "https://app.getgram.ai", ls = () => ({
3893
- chat: ss
3894
- }), os = d({
4011
+ const ds = "https://app.getgram.ai", gs = () => ({
4012
+ chat: hs
4013
+ }), ps = d({
3895
4014
  // currently only supports serverURL, however we will support other config shapes for this via a union type in the future
3896
- mcp: D([s()]),
3897
- environment: Be(s(), ne()).optional(),
4015
+ mcp: j([s()]),
4016
+ environment: ze(s(), oe()).optional(),
3898
4017
  projectSlug: s(),
3899
- model: Je(An)
3900
- }), ss = async (e, t) => {
4018
+ model: Ge(An)
4019
+ }), hs = async (e, t) => {
3901
4020
  if (e.method === "POST")
3902
4021
  try {
3903
4022
  const n = [];
3904
- for await (const _ of e)
3905
- n.push(_);
3906
- const r = Buffer.concat(n).toString(), { messages: o, config: a, system: l, tools: c } = JSON.parse(r), i = os.parse(a), h = await (await Lr({
4023
+ for await (const v of e)
4024
+ n.push(v);
4025
+ const r = Buffer.concat(n).toString(), { messages: o, config: a, system: i, tools: c } = JSON.parse(r), l = ps.parse(a), h = await (await Wr({
3907
4026
  transport: {
3908
4027
  type: "http",
3909
- url: i.mcp,
4028
+ url: l.mcp,
3910
4029
  headers: {
3911
- ...as(i.environment ?? {}),
4030
+ ...ms(l.environment ?? {}),
3912
4031
  // Always send the Gram-Key header last so that it isn't clobbered by the environment variables.
3913
4032
  Authorization: `Bearer ${process.env.GRAM_API_KEY ?? ""}`
3914
4033
  }
3915
4034
  }
3916
- })).tools(), f = Sn({
3917
- baseURL: rs,
4035
+ })).tools(), g = Sn({
4036
+ baseURL: ds,
3918
4037
  // We do not use the apiKey field as the requests are proxied through the Gram API.
3919
4038
  // Instead we use the Gram-Key header to authenticate the request.
3920
4039
  apiKey: "must be set",
3921
4040
  headers: {
3922
- "Gram-Project": i.projectSlug,
4041
+ "Gram-Project": l.projectSlug,
3923
4042
  "Gram-Key": process.env.GRAM_API_KEY ?? ""
3924
4043
  }
3925
- }), m = In({
3926
- system: l,
3927
- model: f.chat(i.model),
3928
- messages: On(o),
4044
+ }), f = In({
4045
+ system: i,
4046
+ model: g.chat(l.model),
4047
+ messages: Pn(o),
3929
4048
  tools: {
3930
4049
  ...h,
3931
- ...Un(c)
4050
+ ...$n(c)
3932
4051
  },
3933
- stopWhen: Pn(10)
4052
+ stopWhen: On(10)
3934
4053
  });
3935
- t.setHeader("Content-Type", "text/event-stream"), t.setHeader("Cache-Control", "no-cache"), t.setHeader("Connection", "keep-alive"), t.setHeader("Transfer-Encoding", "chunked"), t.statusCode = 200, m.pipeUIMessageStreamToResponse(t, {
4054
+ t.setHeader("Content-Type", "text/event-stream"), t.setHeader("Cache-Control", "no-cache"), t.setHeader("Connection", "keep-alive"), t.setHeader("Transfer-Encoding", "chunked"), t.statusCode = 200, f.pipeUIMessageStreamToResponse(t, {
3936
4055
  sendReasoning: !0,
3937
4056
  sendSources: !0
3938
4057
  });
@@ -3943,16 +4062,16 @@ const rs = "https://app.getgram.ai", ls = () => ({
3943
4062
  })
3944
4063
  );
3945
4064
  }
3946
- }, ht = "MCP-";
3947
- function as(e) {
4065
+ }, ft = "MCP-";
4066
+ function ms(e) {
3948
4067
  return typeof e != "object" || e === null ? {} : Object.entries(e).reduce(
3949
4068
  (t, [n, r]) => {
3950
- const o = n.replace(/_/g, "-"), a = o.startsWith(ht) ? o : `${ht}${o}`;
4069
+ const o = n.replace(/_/g, "-"), a = o.startsWith(ft) ? o : `${ft}${o}`;
3951
4070
  return t[a] = r, t;
3952
4071
  },
3953
4072
  {}
3954
4073
  );
3955
4074
  }
3956
4075
  export {
3957
- ls as createElementsServerHandlers
4076
+ gs as createElementsServerHandlers
3958
4077
  };