@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/LICENSE +661 -0
- package/dist/elements.cjs +20 -20
- package/dist/elements.css +1 -1
- package/dist/elements.js +3163 -2946
- package/dist/index-BqoFmyxX.cjs +60 -0
- package/dist/{index-cubKOZsm.js → index-CVZt-xeH.js} +5760 -5494
- package/dist/server.cjs +14 -16
- package/dist/server.js +1375 -1256
- package/package.json +13 -16
- package/dist/components/assistant-ui/d3-renderer.d.ts +0 -5
- package/dist/index-Bq3DSKiX.cjs +0 -60
package/dist/server.js
CHANGED
|
@@ -1,45 +1,113 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
{
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
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
|
|
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
|
|
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[
|
|
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
|
|
121
|
+
return be.hasMarker(e, yt);
|
|
54
122
|
}
|
|
55
|
-
},
|
|
56
|
-
|
|
123
|
+
}, ue = "2025-06-18", Wn = [
|
|
124
|
+
ue,
|
|
57
125
|
"2025-03-26",
|
|
58
126
|
"2024-11-05"
|
|
59
|
-
],
|
|
127
|
+
], Fn = le({
|
|
60
128
|
name: s(),
|
|
61
129
|
version: s()
|
|
62
|
-
}),
|
|
63
|
-
_meta:
|
|
64
|
-
}), Y =
|
|
130
|
+
}), Pe = le({
|
|
131
|
+
_meta: E(d({}).loose())
|
|
132
|
+
}), Y = Pe, wt = d({
|
|
65
133
|
method: s(),
|
|
66
|
-
params:
|
|
134
|
+
params: E(Pe)
|
|
67
135
|
}), bt = d({
|
|
68
|
-
applyDefaults:
|
|
69
|
-
}).loose(),
|
|
70
|
-
experimental:
|
|
71
|
-
logging:
|
|
72
|
-
prompts:
|
|
73
|
-
|
|
74
|
-
listChanged:
|
|
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:
|
|
78
|
-
|
|
79
|
-
subscribe:
|
|
80
|
-
listChanged:
|
|
145
|
+
resources: E(
|
|
146
|
+
le({
|
|
147
|
+
subscribe: E(X()),
|
|
148
|
+
listChanged: E(X())
|
|
81
149
|
})
|
|
82
150
|
),
|
|
83
|
-
tools:
|
|
84
|
-
|
|
85
|
-
listChanged:
|
|
151
|
+
tools: E(
|
|
152
|
+
le({
|
|
153
|
+
listChanged: E(X())
|
|
86
154
|
})
|
|
87
155
|
),
|
|
88
|
-
elicitation:
|
|
156
|
+
elicitation: E(bt)
|
|
89
157
|
});
|
|
90
158
|
d({
|
|
91
|
-
elicitation:
|
|
159
|
+
elicitation: E(bt)
|
|
92
160
|
}).loose();
|
|
93
|
-
var
|
|
161
|
+
var Zn = Y.extend({
|
|
94
162
|
protocolVersion: s(),
|
|
95
|
-
capabilities:
|
|
96
|
-
serverInfo:
|
|
97
|
-
instructions:
|
|
98
|
-
}),
|
|
99
|
-
nextCursor:
|
|
100
|
-
}),
|
|
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:
|
|
170
|
+
description: E(s()),
|
|
103
171
|
inputSchema: d({
|
|
104
|
-
type:
|
|
105
|
-
properties:
|
|
172
|
+
type: x("object"),
|
|
173
|
+
properties: E(d({}).loose())
|
|
106
174
|
}).loose()
|
|
107
|
-
}).loose(),
|
|
108
|
-
tools:
|
|
175
|
+
}).loose(), Yn = Fe.extend({
|
|
176
|
+
tools: y(Xn)
|
|
109
177
|
}), kt = d({
|
|
110
|
-
type:
|
|
178
|
+
type: x("text"),
|
|
111
179
|
text: s()
|
|
112
180
|
}).loose(), Tt = d({
|
|
113
|
-
type:
|
|
114
|
-
data:
|
|
181
|
+
type: x("image"),
|
|
182
|
+
data: gt(),
|
|
115
183
|
mimeType: s()
|
|
116
|
-
}).loose(),
|
|
184
|
+
}).loose(), Qn = d({
|
|
117
185
|
uri: s(),
|
|
118
186
|
name: s(),
|
|
119
|
-
title:
|
|
120
|
-
description:
|
|
121
|
-
mimeType:
|
|
122
|
-
size:
|
|
123
|
-
}).loose(),
|
|
124
|
-
resources:
|
|
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:
|
|
201
|
+
name: E(s()),
|
|
134
202
|
/**
|
|
135
203
|
* Optional human readable title.
|
|
136
204
|
*/
|
|
137
|
-
title:
|
|
205
|
+
title: E(s()),
|
|
138
206
|
/**
|
|
139
207
|
* The MIME type of this resource, if known.
|
|
140
208
|
*/
|
|
141
|
-
mimeType:
|
|
209
|
+
mimeType: E(s())
|
|
142
210
|
}).loose(), Rt = St.extend({
|
|
143
211
|
text: s()
|
|
144
212
|
}), Et = St.extend({
|
|
145
|
-
blob:
|
|
213
|
+
blob: gt()
|
|
146
214
|
}), Ct = d({
|
|
147
|
-
type:
|
|
148
|
-
resource:
|
|
149
|
-
}).loose(),
|
|
150
|
-
content:
|
|
151
|
-
|
|
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:
|
|
224
|
+
toolResult: oe()
|
|
157
225
|
})
|
|
158
|
-
),
|
|
226
|
+
), nr = d({
|
|
159
227
|
uriTemplate: s(),
|
|
160
228
|
name: s(),
|
|
161
|
-
title:
|
|
162
|
-
description:
|
|
163
|
-
mimeType:
|
|
164
|
-
}).loose(),
|
|
165
|
-
resourceTemplates:
|
|
166
|
-
}),
|
|
167
|
-
contents:
|
|
168
|
-
|
|
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
|
-
}),
|
|
238
|
+
}), sr = d({
|
|
171
239
|
name: s(),
|
|
172
|
-
description:
|
|
173
|
-
required:
|
|
174
|
-
}).loose(),
|
|
240
|
+
description: E(s()),
|
|
241
|
+
required: E(X())
|
|
242
|
+
}).loose(), ar = d({
|
|
175
243
|
name: s(),
|
|
176
|
-
title:
|
|
177
|
-
description:
|
|
178
|
-
arguments:
|
|
179
|
-
}).loose(),
|
|
180
|
-
prompts:
|
|
181
|
-
}),
|
|
182
|
-
role:
|
|
183
|
-
content:
|
|
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(),
|
|
189
|
-
description:
|
|
190
|
-
messages:
|
|
191
|
-
}),
|
|
256
|
+
}).loose(), cr = Y.extend({
|
|
257
|
+
description: E(s()),
|
|
258
|
+
messages: y(lr)
|
|
259
|
+
}), ur = Pe.extend({
|
|
192
260
|
message: s(),
|
|
193
|
-
requestedSchema:
|
|
194
|
-
}),
|
|
195
|
-
method:
|
|
196
|
-
params:
|
|
197
|
-
}),
|
|
198
|
-
action:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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:
|
|
204
|
-
}),
|
|
205
|
-
jsonrpc:
|
|
206
|
-
id:
|
|
207
|
-
}).merge(wt).strict(),
|
|
208
|
-
jsonrpc:
|
|
209
|
-
id:
|
|
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(),
|
|
212
|
-
jsonrpc:
|
|
213
|
-
id:
|
|
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:
|
|
285
|
+
data: E(oe())
|
|
218
286
|
})
|
|
219
|
-
}).strict(),
|
|
220
|
-
jsonrpc:
|
|
287
|
+
}).strict(), fr = d({
|
|
288
|
+
jsonrpc: x(Ae)
|
|
221
289
|
}).merge(
|
|
222
290
|
d({
|
|
223
291
|
method: s(),
|
|
224
|
-
params:
|
|
292
|
+
params: E(Pe)
|
|
225
293
|
})
|
|
226
|
-
).strict(),
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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(),
|
|
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
|
-
),
|
|
320
|
+
), gr = d({
|
|
253
321
|
resource: s().url(),
|
|
254
|
-
authorization_servers:
|
|
322
|
+
authorization_servers: y(B).optional(),
|
|
255
323
|
jwks_uri: s().url().optional(),
|
|
256
|
-
scopes_supported:
|
|
257
|
-
bearer_methods_supported:
|
|
258
|
-
resource_signing_alg_values_supported:
|
|
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:
|
|
265
|
-
dpop_signing_alg_values_supported:
|
|
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(),
|
|
335
|
+
}).passthrough(), Ot = d({
|
|
268
336
|
issuer: s(),
|
|
269
|
-
authorization_endpoint:
|
|
270
|
-
token_endpoint:
|
|
271
|
-
registration_endpoint:
|
|
272
|
-
scopes_supported:
|
|
273
|
-
response_types_supported:
|
|
274
|
-
grant_types_supported:
|
|
275
|
-
code_challenge_methods_supported:
|
|
276
|
-
token_endpoint_auth_methods_supported:
|
|
277
|
-
token_endpoint_auth_signing_alg_values_supported:
|
|
278
|
-
}).passthrough(),
|
|
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:
|
|
281
|
-
token_endpoint:
|
|
282
|
-
userinfo_endpoint:
|
|
283
|
-
jwks_uri:
|
|
284
|
-
registration_endpoint:
|
|
285
|
-
scopes_supported:
|
|
286
|
-
response_types_supported:
|
|
287
|
-
grant_types_supported:
|
|
288
|
-
subject_types_supported:
|
|
289
|
-
id_token_signing_alg_values_supported:
|
|
290
|
-
claims_supported:
|
|
291
|
-
token_endpoint_auth_methods_supported:
|
|
292
|
-
}).passthrough(),
|
|
293
|
-
|
|
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
|
-
),
|
|
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(),
|
|
302
|
-
redirect_uris:
|
|
369
|
+
}).strip(), wr = d({
|
|
370
|
+
redirect_uris: y(B),
|
|
303
371
|
token_endpoint_auth_method: s().optional(),
|
|
304
|
-
grant_types:
|
|
305
|
-
response_types:
|
|
372
|
+
grant_types: y(s()).optional(),
|
|
373
|
+
response_types: y(s()).optional(),
|
|
306
374
|
client_name: s().optional(),
|
|
307
|
-
client_uri:
|
|
308
|
-
logo_uri:
|
|
375
|
+
client_uri: B.optional(),
|
|
376
|
+
logo_uri: B.optional(),
|
|
309
377
|
scope: s().optional(),
|
|
310
|
-
contacts:
|
|
311
|
-
tos_uri:
|
|
378
|
+
contacts: y(s()).optional(),
|
|
379
|
+
tos_uri: B.optional(),
|
|
312
380
|
policy_uri: s().optional(),
|
|
313
|
-
jwks_uri:
|
|
314
|
-
jwks:
|
|
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(),
|
|
386
|
+
}).strip(), br = d({
|
|
319
387
|
error: s(),
|
|
320
388
|
error_description: s().optional(),
|
|
321
389
|
error_uri: s().optional()
|
|
322
|
-
}),
|
|
323
|
-
|
|
324
|
-
),
|
|
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[
|
|
398
|
+
super({ name: e, message: t, cause: n }), this[at] = !0;
|
|
331
399
|
}
|
|
332
400
|
static isInstance(e) {
|
|
333
|
-
return
|
|
401
|
+
return be.hasMarker(e, Pt);
|
|
334
402
|
}
|
|
335
|
-
},
|
|
403
|
+
}, ce = class extends _e {
|
|
336
404
|
};
|
|
337
|
-
|
|
338
|
-
var
|
|
405
|
+
ce.errorCode = "server_error";
|
|
406
|
+
var ke = class extends _e {
|
|
339
407
|
};
|
|
340
|
-
|
|
341
|
-
var
|
|
408
|
+
ke.errorCode = "invalid_client";
|
|
409
|
+
var Te = class extends _e {
|
|
342
410
|
};
|
|
343
|
-
|
|
344
|
-
var
|
|
411
|
+
Te.errorCode = "invalid_grant";
|
|
412
|
+
var Se = class extends _e {
|
|
345
413
|
};
|
|
346
|
-
|
|
347
|
-
var
|
|
348
|
-
[
|
|
349
|
-
[
|
|
350
|
-
[
|
|
351
|
-
[
|
|
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
|
|
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
|
|
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
|
|
435
|
+
var Re = class extends Error {
|
|
368
436
|
constructor(e = "Unauthorized") {
|
|
369
437
|
super(e), this.name = "UnauthorizedError";
|
|
370
438
|
}
|
|
371
439
|
};
|
|
372
|
-
function
|
|
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="([^"]*)"/,
|
|
381
|
-
if (
|
|
448
|
+
const a = /resource_metadata="([^"]*)"/, i = n.match(a);
|
|
449
|
+
if (i)
|
|
382
450
|
try {
|
|
383
|
-
return new URL(
|
|
451
|
+
return new URL(i[1]);
|
|
384
452
|
} catch {
|
|
385
453
|
return;
|
|
386
454
|
}
|
|
387
455
|
}
|
|
388
|
-
function
|
|
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
|
|
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 ?
|
|
464
|
+
return t ? Ke(e, void 0, n) : void 0;
|
|
397
465
|
throw r;
|
|
398
466
|
}
|
|
399
467
|
}
|
|
400
|
-
async function
|
|
401
|
-
return await
|
|
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
|
|
473
|
+
function Ir(e, t) {
|
|
406
474
|
return !e || e.status >= 400 && e.status < 500 && t !== "/";
|
|
407
475
|
}
|
|
408
|
-
async function
|
|
476
|
+
async function Or(e, t, n, r) {
|
|
409
477
|
var o, a;
|
|
410
|
-
const
|
|
411
|
-
let
|
|
478
|
+
const i = new URL(e), c = (o = r?.protocolVersion) != null ? o : ue;
|
|
479
|
+
let l;
|
|
412
480
|
if (r?.metadataUrl)
|
|
413
|
-
|
|
481
|
+
l = new URL(r.metadataUrl);
|
|
414
482
|
else {
|
|
415
|
-
const h =
|
|
416
|
-
|
|
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
|
|
419
|
-
if (!r?.metadataUrl &&
|
|
420
|
-
const h = new URL(`/.well-known/${t}`,
|
|
421
|
-
u = await
|
|
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
|
|
426
|
-
const r = await
|
|
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
|
|
511
|
+
return gr.parse(await r.json());
|
|
444
512
|
}
|
|
445
|
-
function
|
|
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
|
|
541
|
+
async function $r(e, {
|
|
474
542
|
fetchFn: t = fetch,
|
|
475
|
-
protocolVersion: n =
|
|
543
|
+
protocolVersion: n = ue
|
|
476
544
|
} = {}) {
|
|
477
545
|
var r;
|
|
478
|
-
const o = { "MCP-Protocol-Version": n }, a =
|
|
479
|
-
for (const { url:
|
|
480
|
-
const
|
|
481
|
-
if (
|
|
482
|
-
if (!
|
|
483
|
-
if (
|
|
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 ${
|
|
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
|
|
558
|
+
return Ot.parse(await l.json());
|
|
491
559
|
{
|
|
492
|
-
const u =
|
|
493
|
-
await
|
|
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 ${
|
|
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
|
|
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:
|
|
578
|
+
resource: i
|
|
511
579
|
}) {
|
|
512
|
-
const c = "code",
|
|
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(
|
|
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 ${
|
|
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
|
|
526
|
-
return u.searchParams.set("response_type", c), u.searchParams.set("client_id", n.client_id), u.searchParams.set("code_challenge",
|
|
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
|
-
|
|
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"),
|
|
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
|
|
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
|
-
|
|
607
|
+
Mr(o, a, n);
|
|
540
608
|
return;
|
|
541
609
|
case "client_secret_post":
|
|
542
|
-
|
|
610
|
+
Nr(o, a, r);
|
|
543
611
|
return;
|
|
544
612
|
case "none":
|
|
545
|
-
|
|
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
|
|
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
|
|
627
|
+
function Nr(e, t, n) {
|
|
560
628
|
n.set("client_id", e), t && n.set("client_secret", t);
|
|
561
629
|
}
|
|
562
|
-
function
|
|
630
|
+
function jr(e, t) {
|
|
563
631
|
t.set("client_id", e);
|
|
564
632
|
}
|
|
565
|
-
async function
|
|
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 =
|
|
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:
|
|
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
|
|
643
|
+
return new ce({ message: o });
|
|
576
644
|
}
|
|
577
645
|
}
|
|
578
|
-
async function
|
|
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:
|
|
652
|
+
resource: i,
|
|
585
653
|
addClientAuthentication: c,
|
|
586
|
-
fetchFn:
|
|
654
|
+
fetchFn: l
|
|
587
655
|
}) {
|
|
588
656
|
var u;
|
|
589
|
-
const h = "authorization_code",
|
|
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
|
|
662
|
+
const f = new Headers({
|
|
595
663
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
596
664
|
Accept: "application/json"
|
|
597
|
-
}),
|
|
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(
|
|
672
|
+
c(f, v, e, t);
|
|
605
673
|
else {
|
|
606
|
-
const p = (u = t?.token_endpoint_auth_methods_supported) != null ? u : [],
|
|
674
|
+
const p = (u = t?.token_endpoint_auth_methods_supported) != null ? u : [], w = At(
|
|
607
675
|
n,
|
|
608
676
|
p
|
|
609
677
|
);
|
|
610
|
-
|
|
678
|
+
$t(w, n, f, v);
|
|
611
679
|
}
|
|
612
|
-
|
|
613
|
-
const
|
|
680
|
+
i && v.set("resource", i.href);
|
|
681
|
+
const m = await (l ?? fetch)(g, {
|
|
614
682
|
method: "POST",
|
|
615
|
-
headers:
|
|
616
|
-
body:
|
|
683
|
+
headers: f,
|
|
684
|
+
body: v
|
|
617
685
|
});
|
|
618
|
-
if (!
|
|
619
|
-
throw await
|
|
620
|
-
return It.parse(await
|
|
686
|
+
if (!m.ok)
|
|
687
|
+
throw await Ze(m);
|
|
688
|
+
return It.parse(await m.json());
|
|
621
689
|
}
|
|
622
|
-
async function
|
|
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:
|
|
696
|
+
fetchFn: i
|
|
629
697
|
}) {
|
|
630
698
|
var c;
|
|
631
|
-
const
|
|
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(
|
|
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 ${
|
|
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
|
-
}),
|
|
643
|
-
grant_type:
|
|
710
|
+
}), g = new URLSearchParams({
|
|
711
|
+
grant_type: l,
|
|
644
712
|
refresh_token: r
|
|
645
713
|
});
|
|
646
714
|
if (a)
|
|
647
|
-
a(h,
|
|
715
|
+
a(h, g, e, t);
|
|
648
716
|
else {
|
|
649
|
-
const
|
|
717
|
+
const v = (c = t?.token_endpoint_auth_methods_supported) != null ? c : [], m = At(
|
|
650
718
|
n,
|
|
651
|
-
|
|
719
|
+
v
|
|
652
720
|
);
|
|
653
|
-
|
|
721
|
+
$t(m, n, h, g);
|
|
654
722
|
}
|
|
655
|
-
o &&
|
|
656
|
-
const
|
|
723
|
+
o && g.set("resource", o.href);
|
|
724
|
+
const f = await (i ?? fetch)(u, {
|
|
657
725
|
method: "POST",
|
|
658
726
|
headers: h,
|
|
659
|
-
body:
|
|
727
|
+
body: g
|
|
660
728
|
});
|
|
661
|
-
if (!
|
|
662
|
-
throw await
|
|
729
|
+
if (!f.ok)
|
|
730
|
+
throw await Ze(f);
|
|
663
731
|
return It.parse({
|
|
664
732
|
refresh_token: r,
|
|
665
|
-
...await
|
|
733
|
+
...await f.json()
|
|
666
734
|
});
|
|
667
735
|
}
|
|
668
|
-
async function
|
|
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
|
|
691
|
-
return
|
|
758
|
+
throw await Ze(a);
|
|
759
|
+
return kr.parse(await a.json());
|
|
692
760
|
}
|
|
693
|
-
async function
|
|
761
|
+
async function Ce(e, t) {
|
|
694
762
|
var n, r;
|
|
695
763
|
try {
|
|
696
|
-
return await
|
|
764
|
+
return await Me(e, t);
|
|
697
765
|
} catch (o) {
|
|
698
|
-
if (o instanceof
|
|
699
|
-
return await ((n = e.invalidateCredentials) == null ? void 0 : n.call(e, "all")), await
|
|
700
|
-
if (o instanceof
|
|
701
|
-
return await ((r = e.invalidateCredentials) == null ? void 0 : r.call(e, "tokens")), await
|
|
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
|
|
706
|
-
const r =
|
|
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 (!
|
|
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
|
|
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
|
|
798
|
+
let i, c;
|
|
731
799
|
try {
|
|
732
|
-
|
|
800
|
+
i = await Pr(
|
|
733
801
|
t,
|
|
734
802
|
{ resourceMetadataUrl: o },
|
|
735
803
|
a
|
|
736
|
-
),
|
|
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
|
|
808
|
+
const l = await qr(
|
|
741
809
|
t,
|
|
742
810
|
e,
|
|
743
|
-
|
|
744
|
-
), u = await
|
|
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
|
|
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(),
|
|
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:
|
|
842
|
+
resource: l,
|
|
775
843
|
addClientAuthentication: e.addClientAuthentication,
|
|
776
844
|
fetchFn: a
|
|
777
845
|
});
|
|
778
|
-
return await e.saveTokens(
|
|
846
|
+
return await e.saveTokens(w), "AUTHORIZED";
|
|
779
847
|
}
|
|
780
|
-
const
|
|
781
|
-
if (
|
|
848
|
+
const g = await e.tokens();
|
|
849
|
+
if (g?.refresh_token)
|
|
782
850
|
try {
|
|
783
|
-
const p = await
|
|
851
|
+
const p = await Hr(c, {
|
|
784
852
|
metadata: u,
|
|
785
853
|
clientInformation: h,
|
|
786
|
-
refreshToken:
|
|
787
|
-
resource:
|
|
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
|
|
863
|
+
!(!(p instanceof _e) || p instanceof ce)
|
|
796
864
|
) throw p;
|
|
797
865
|
}
|
|
798
|
-
const
|
|
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:
|
|
871
|
+
state: f,
|
|
804
872
|
redirectUrl: e.redirectUrl,
|
|
805
873
|
scope: r || e.clientMetadata.scope,
|
|
806
|
-
resource:
|
|
874
|
+
resource: l
|
|
807
875
|
}
|
|
808
876
|
);
|
|
809
|
-
return await e.saveCodeVerifier(
|
|
877
|
+
return await e.saveCodeVerifier(m), await e.redirectToAuthorization(v), "REDIRECT";
|
|
810
878
|
}
|
|
811
|
-
var
|
|
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":
|
|
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
|
|
897
|
+
return vt(
|
|
830
898
|
t,
|
|
831
899
|
`ai-sdk/${xt}`,
|
|
832
|
-
|
|
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,
|
|
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 =
|
|
918
|
+
this.resourceMetadataUrl = Ee(h);
|
|
851
919
|
try {
|
|
852
|
-
if (await
|
|
920
|
+
if (await Ce(this.authProvider, {
|
|
853
921
|
serverUrl: this.url,
|
|
854
922
|
resourceMetadataUrl: this.resourceMetadataUrl
|
|
855
923
|
}) !== "AUTHORIZED") {
|
|
856
|
-
const p = new
|
|
924
|
+
const p = new Re();
|
|
857
925
|
return (a = this.onerror) == null || a.call(this, p), t(p);
|
|
858
926
|
}
|
|
859
|
-
} catch (
|
|
860
|
-
return (
|
|
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
|
|
866
|
-
h.status === 405 && (
|
|
867
|
-
const p = new
|
|
868
|
-
message:
|
|
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
|
|
873
|
-
var
|
|
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:
|
|
877
|
-
if (
|
|
944
|
+
const { done: b, value: R } = await f.read();
|
|
945
|
+
if (b) {
|
|
878
946
|
if (this.connected)
|
|
879
|
-
throw this.connected = !1, new
|
|
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:
|
|
885
|
-
if (
|
|
886
|
-
if (this.endpoint = new URL(
|
|
887
|
-
throw new
|
|
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 (
|
|
959
|
+
} else if (T === "message")
|
|
892
960
|
try {
|
|
893
|
-
const
|
|
894
|
-
JSON.parse(
|
|
961
|
+
const M = pe.parse(
|
|
962
|
+
JSON.parse(S)
|
|
895
963
|
);
|
|
896
|
-
(
|
|
897
|
-
} catch (
|
|
898
|
-
const $ = new
|
|
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:
|
|
968
|
+
cause: M
|
|
901
969
|
});
|
|
902
970
|
(p = this.onerror) == null || p.call(this, $);
|
|
903
971
|
}
|
|
904
972
|
}
|
|
905
|
-
} catch (
|
|
906
|
-
if (
|
|
973
|
+
} catch (b) {
|
|
974
|
+
if (b instanceof Error && b.name === "AbortError")
|
|
907
975
|
return;
|
|
908
|
-
(
|
|
976
|
+
(w = this.onerror) == null || w.call(this, b), t(b);
|
|
909
977
|
}
|
|
910
978
|
};
|
|
911
979
|
this.sseConnection = {
|
|
912
|
-
close: () =>
|
|
913
|
-
},
|
|
980
|
+
close: () => f.cancel()
|
|
981
|
+
}, v();
|
|
914
982
|
} catch (u) {
|
|
915
983
|
if (u instanceof Error && u.name === "AbortError")
|
|
916
984
|
return;
|
|
917
|
-
(
|
|
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
|
|
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,
|
|
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
|
-
},
|
|
943
|
-
if (
|
|
944
|
-
this.resourceMetadataUrl =
|
|
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
|
|
1014
|
+
if (await Ce(this.authProvider, {
|
|
947
1015
|
serverUrl: this.url,
|
|
948
1016
|
resourceMetadataUrl: this.resourceMetadataUrl
|
|
949
1017
|
}) !== "AUTHORIZED") {
|
|
950
|
-
const
|
|
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 (
|
|
955
|
-
(
|
|
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 (!
|
|
961
|
-
const
|
|
962
|
-
message: `MCP SSE Transport Error: POSTing to endpoint (HTTP ${
|
|
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
|
-
(
|
|
1036
|
+
(l = this.onerror) == null || l.call(this, u);
|
|
969
1037
|
return;
|
|
970
1038
|
}
|
|
971
1039
|
};
|
|
972
1040
|
await n();
|
|
973
1041
|
}
|
|
974
|
-
},
|
|
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":
|
|
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
|
|
1065
|
+
return vt(
|
|
998
1066
|
t,
|
|
999
1067
|
`ai-sdk/${xt}`,
|
|
1000
|
-
|
|
1068
|
+
_t()
|
|
1001
1069
|
);
|
|
1002
1070
|
}
|
|
1003
1071
|
async start() {
|
|
1004
1072
|
if (this.abortController)
|
|
1005
|
-
throw new
|
|
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,
|
|
1097
|
+
var r, o, a, i, c, l, u;
|
|
1030
1098
|
try {
|
|
1031
|
-
const
|
|
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
|
-
},
|
|
1040
|
-
if (
|
|
1041
|
-
this.resourceMetadataUrl =
|
|
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
|
|
1111
|
+
if (await Ce(this.authProvider, {
|
|
1044
1112
|
serverUrl: this.url,
|
|
1045
1113
|
resourceMetadataUrl: this.resourceMetadataUrl
|
|
1046
1114
|
}) !== "AUTHORIZED")
|
|
1047
|
-
throw new
|
|
1048
|
-
} catch (
|
|
1049
|
-
throw (o = this.onerror) == null || o.call(this,
|
|
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 (
|
|
1121
|
+
if (f.status === 202) {
|
|
1054
1122
|
this.inboundSseConnection || this.openInboundSse();
|
|
1055
1123
|
return;
|
|
1056
1124
|
}
|
|
1057
|
-
if (!
|
|
1058
|
-
const
|
|
1059
|
-
let
|
|
1060
|
-
|
|
1061
|
-
const
|
|
1062
|
-
message:
|
|
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,
|
|
1132
|
+
throw (a = this.onerror) == null || a.call(this, R), R;
|
|
1065
1133
|
}
|
|
1066
|
-
const
|
|
1067
|
-
if (
|
|
1068
|
-
const
|
|
1069
|
-
for (const
|
|
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 (
|
|
1073
|
-
if (!
|
|
1074
|
-
const
|
|
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,
|
|
1145
|
+
throw (c = this.onerror) == null || c.call(this, T), T;
|
|
1078
1146
|
}
|
|
1079
|
-
const
|
|
1147
|
+
const b = f.body.pipeThrough(new TextDecoderStream()).pipeThrough(new He()).getReader();
|
|
1080
1148
|
(async () => {
|
|
1081
|
-
var
|
|
1149
|
+
var T, S, M;
|
|
1082
1150
|
try {
|
|
1083
1151
|
for (; ; ) {
|
|
1084
|
-
const { done: $, value:
|
|
1152
|
+
const { done: $, value: A } = await b.read();
|
|
1085
1153
|
if ($) return;
|
|
1086
|
-
const { event:
|
|
1087
|
-
if (
|
|
1154
|
+
const { event: I, data: z } = A;
|
|
1155
|
+
if (I === "message")
|
|
1088
1156
|
try {
|
|
1089
|
-
const
|
|
1090
|
-
(
|
|
1091
|
-
} catch (
|
|
1092
|
-
const G = new
|
|
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:
|
|
1162
|
+
cause: J
|
|
1095
1163
|
});
|
|
1096
|
-
(
|
|
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
|
-
(
|
|
1170
|
+
(M = this.onerror) == null || M.call(this, $);
|
|
1103
1171
|
}
|
|
1104
1172
|
})();
|
|
1105
1173
|
return;
|
|
1106
1174
|
}
|
|
1107
|
-
const p = new
|
|
1108
|
-
message: `MCP HTTP Transport Error: Unexpected content type: ${
|
|
1175
|
+
const p = new O({
|
|
1176
|
+
message: `MCP HTTP Transport Error: Unexpected content type: ${m}`
|
|
1109
1177
|
});
|
|
1110
|
-
throw (
|
|
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
|
|
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,
|
|
1216
|
+
var n, r, o, a, i, c;
|
|
1149
1217
|
try {
|
|
1150
|
-
const
|
|
1218
|
+
const l = await this.commonHeaders({
|
|
1151
1219
|
Accept: "text/event-stream"
|
|
1152
1220
|
});
|
|
1153
|
-
t && (
|
|
1221
|
+
t && (l["last-event-id"] = t);
|
|
1154
1222
|
const u = await fetch(this.url.href, {
|
|
1155
1223
|
method: "GET",
|
|
1156
|
-
headers:
|
|
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 =
|
|
1228
|
+
this.resourceMetadataUrl = Ee(u);
|
|
1161
1229
|
try {
|
|
1162
|
-
if (await
|
|
1230
|
+
if (await Ce(this.authProvider, {
|
|
1163
1231
|
serverUrl: this.url,
|
|
1164
1232
|
resourceMetadataUrl: this.resourceMetadataUrl
|
|
1165
1233
|
}) !== "AUTHORIZED") {
|
|
1166
|
-
const p = new
|
|
1234
|
+
const p = new Re();
|
|
1167
1235
|
(r = this.onerror) == null || r.call(this, p);
|
|
1168
1236
|
return;
|
|
1169
1237
|
}
|
|
1170
|
-
} catch (
|
|
1171
|
-
(o = this.onerror) == null || o.call(this,
|
|
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
|
|
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,
|
|
1250
|
+
(a = this.onerror) == null || a.call(this, m);
|
|
1183
1251
|
return;
|
|
1184
1252
|
}
|
|
1185
|
-
const
|
|
1186
|
-
var
|
|
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:
|
|
1190
|
-
if (
|
|
1191
|
-
const { event:
|
|
1192
|
-
if ($ && (this.lastInboundEventId = $),
|
|
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
|
|
1195
|
-
(
|
|
1196
|
-
} catch (
|
|
1197
|
-
const
|
|
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:
|
|
1267
|
+
cause: A
|
|
1200
1268
|
});
|
|
1201
|
-
(p = this.onerror) == null || p.call(this,
|
|
1269
|
+
(p = this.onerror) == null || p.call(this, I);
|
|
1202
1270
|
}
|
|
1203
1271
|
}
|
|
1204
|
-
} catch (
|
|
1205
|
-
if (
|
|
1272
|
+
} catch (R) {
|
|
1273
|
+
if (R instanceof Error && R.name === "AbortError")
|
|
1206
1274
|
return;
|
|
1207
|
-
(
|
|
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: () =>
|
|
1212
|
-
}, this.inboundReconnectAttempts = 0,
|
|
1213
|
-
} catch (
|
|
1214
|
-
if (
|
|
1279
|
+
close: () => f.cancel()
|
|
1280
|
+
}, this.inboundReconnectAttempts = 0, v();
|
|
1281
|
+
} catch (l) {
|
|
1282
|
+
if (l instanceof Error && l.name === "AbortError")
|
|
1215
1283
|
return;
|
|
1216
|
-
(
|
|
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
|
|
1288
|
+
function Jr(e) {
|
|
1221
1289
|
switch (e.type) {
|
|
1222
1290
|
case "sse":
|
|
1223
|
-
return new
|
|
1291
|
+
return new Vr(e);
|
|
1224
1292
|
case "http":
|
|
1225
|
-
return new
|
|
1293
|
+
return new Br(e);
|
|
1226
1294
|
default:
|
|
1227
|
-
throw new
|
|
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
|
|
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
|
|
1236
|
-
async function
|
|
1237
|
-
const t = new
|
|
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
|
|
1308
|
+
var Fr = class {
|
|
1241
1309
|
constructor({
|
|
1242
1310
|
transport: e,
|
|
1243
1311
|
name: t = "ai-sdk-mcp-client",
|
|
1244
|
-
version: n =
|
|
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 ?? {},
|
|
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
|
|
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:
|
|
1338
|
+
protocolVersion: ue,
|
|
1271
1339
|
capabilities: this.clientCapabilities,
|
|
1272
1340
|
clientInfo: this.clientInfo
|
|
1273
1341
|
}
|
|
1274
1342
|
},
|
|
1275
|
-
resultSchema:
|
|
1343
|
+
resultSchema: Zn
|
|
1276
1344
|
});
|
|
1277
1345
|
if (e === void 0)
|
|
1278
|
-
throw new
|
|
1346
|
+
throw new O({
|
|
1279
1347
|
message: "Server sent invalid initialize result"
|
|
1280
1348
|
});
|
|
1281
|
-
if (!
|
|
1282
|
-
throw new
|
|
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
|
|
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
|
|
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
|
|
1386
|
+
throw new O({
|
|
1319
1387
|
message: "Server does not support prompts"
|
|
1320
1388
|
});
|
|
1321
1389
|
break;
|
|
1322
1390
|
default:
|
|
1323
|
-
throw new
|
|
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
|
|
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
|
|
1411
|
+
const i = this.requestMessageId++, c = {
|
|
1344
1412
|
...e,
|
|
1345
1413
|
jsonrpc: "2.0",
|
|
1346
|
-
id:
|
|
1347
|
-
},
|
|
1348
|
-
this.responseHandlers.delete(
|
|
1414
|
+
id: i
|
|
1415
|
+
}, l = () => {
|
|
1416
|
+
this.responseHandlers.delete(i);
|
|
1349
1417
|
};
|
|
1350
|
-
this.responseHandlers.set(
|
|
1418
|
+
this.responseHandlers.set(i, (u) => {
|
|
1351
1419
|
if (a?.aborted)
|
|
1352
1420
|
return o(
|
|
1353
|
-
new
|
|
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
|
|
1432
|
+
const g = new O({
|
|
1365
1433
|
message: "Failed to parse server response",
|
|
1366
1434
|
cause: h
|
|
1367
1435
|
});
|
|
1368
|
-
o(
|
|
1436
|
+
o(g);
|
|
1369
1437
|
}
|
|
1370
1438
|
}), this.transport.send(c).catch((u) => {
|
|
1371
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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,
|
|
1498
|
-
var
|
|
1499
|
-
return (
|
|
1500
|
-
}, u = e === "automatic" ?
|
|
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:
|
|
1503
|
-
...
|
|
1504
|
-
properties: (t =
|
|
1570
|
+
inputSchema: Hn({
|
|
1571
|
+
...i,
|
|
1572
|
+
properties: (t = i.properties) != null ? t : {},
|
|
1505
1573
|
additionalProperties: !1
|
|
1506
1574
|
}),
|
|
1507
|
-
execute:
|
|
1508
|
-
}) :
|
|
1575
|
+
execute: l
|
|
1576
|
+
}) : {
|
|
1509
1577
|
description: a,
|
|
1510
1578
|
inputSchema: e[o].inputSchema,
|
|
1511
|
-
execute:
|
|
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 !==
|
|
1552
|
-
throw new
|
|
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 =
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
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
|
-
},
|
|
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
|
-
|
|
1651
|
-
if (
|
|
1652
|
-
for (var n of
|
|
1653
|
-
|
|
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
|
-
},
|
|
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,
|
|
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 =
|
|
1685
|
-
var
|
|
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:
|
|
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:
|
|
1767
|
+
data: l
|
|
1700
1768
|
}) {
|
|
1701
|
-
super({ name:
|
|
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
|
|
1772
|
+
return L.hasMarker(e, Dt);
|
|
1705
1773
|
}
|
|
1706
1774
|
};
|
|
1707
|
-
|
|
1708
|
-
var
|
|
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:
|
|
1779
|
+
super({ name: Lt, message: e }), this[Vt] = !0;
|
|
1712
1780
|
}
|
|
1713
1781
|
static isInstance(e) {
|
|
1714
|
-
return
|
|
1782
|
+
return L.hasMarker(e, qt);
|
|
1715
1783
|
}
|
|
1716
1784
|
};
|
|
1717
|
-
Vt =
|
|
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}`,
|
|
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[
|
|
1795
|
+
super({ name: Jt, message: e, cause: t }), this[Gt] = !0, this.argument = n;
|
|
1728
1796
|
}
|
|
1729
1797
|
static isInstance(e) {
|
|
1730
|
-
return
|
|
1798
|
+
return L.hasMarker(e, zt);
|
|
1731
1799
|
}
|
|
1732
1800
|
};
|
|
1733
|
-
|
|
1734
|
-
var Ft = "AI_InvalidPromptError", Kt = `vercel.ai.error.${Ft}`,
|
|
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
|
|
1811
|
+
return L.hasMarker(e, Kt);
|
|
1744
1812
|
}
|
|
1745
1813
|
};
|
|
1746
|
-
Zt =
|
|
1747
|
-
var Xt = "AI_InvalidResponseDataError", Yt = `vercel.ai.error.${Xt}`,
|
|
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
|
|
1823
|
+
return L.hasMarker(e, Yt);
|
|
1756
1824
|
}
|
|
1757
1825
|
};
|
|
1758
|
-
Qt =
|
|
1759
|
-
var en = "AI_JSONParseError", tn = `vercel.ai.error.${en}`,
|
|
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
|
|
1837
|
+
return L.hasMarker(e, tn);
|
|
1770
1838
|
}
|
|
1771
1839
|
};
|
|
1772
|
-
nn =
|
|
1773
|
-
var rn = "AI_LoadAPIKeyError", on = `vercel.ai.error.${rn}`,
|
|
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
|
|
1847
|
+
return L.hasMarker(e, on);
|
|
1780
1848
|
}
|
|
1781
1849
|
};
|
|
1782
|
-
sn =
|
|
1783
|
-
var an = "AI_NoContentGeneratedError", ln = `vercel.ai.error.${an}`,
|
|
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
|
|
1859
|
+
return L.hasMarker(e, ln);
|
|
1792
1860
|
}
|
|
1793
1861
|
};
|
|
1794
|
-
cn =
|
|
1795
|
-
var dn = "AI_TypeValidationError", pn = `vercel.ai.error.${dn}`,
|
|
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
|
|
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
|
|
1889
|
+
return Le.isInstance(n) && n.value === t ? n : new Le({ value: t, cause: n });
|
|
1822
1890
|
}
|
|
1823
1891
|
};
|
|
1824
|
-
hn =
|
|
1825
|
-
var
|
|
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[
|
|
1898
|
+
super({ name: mn, message: t }), this[gn] = !0, this.functionality = e;
|
|
1831
1899
|
}
|
|
1832
1900
|
static isInstance(e) {
|
|
1833
|
-
return
|
|
1901
|
+
return L.hasMarker(e, fn);
|
|
1834
1902
|
}
|
|
1835
1903
|
};
|
|
1836
|
-
|
|
1837
|
-
var
|
|
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
|
|
1910
|
+
function Ne(e) {
|
|
1843
1911
|
}
|
|
1844
|
-
function
|
|
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 =
|
|
1850
|
-
let a = "",
|
|
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
|
|
1853
|
-
for (const
|
|
1854
|
-
|
|
1855
|
-
a =
|
|
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
|
|
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
|
|
1867
|
-
if (
|
|
1868
|
-
const
|
|
1869
|
-
|
|
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
|
-
|
|
1940
|
+
f(p, "", p);
|
|
1873
1941
|
}
|
|
1874
|
-
function
|
|
1942
|
+
function f(p, w, b) {
|
|
1875
1943
|
switch (p) {
|
|
1876
1944
|
case "event":
|
|
1877
|
-
u =
|
|
1945
|
+
u = w;
|
|
1878
1946
|
break;
|
|
1879
1947
|
case "data":
|
|
1880
|
-
|
|
1948
|
+
l = `${l}${w}
|
|
1881
1949
|
`;
|
|
1882
1950
|
break;
|
|
1883
1951
|
case "id":
|
|
1884
|
-
c =
|
|
1952
|
+
c = w.includes("\0") ? void 0 : w;
|
|
1885
1953
|
break;
|
|
1886
1954
|
case "retry":
|
|
1887
|
-
/^\d+$/.test(
|
|
1888
|
-
new
|
|
1955
|
+
/^\d+$/.test(w) ? r(parseInt(w, 10)) : n(
|
|
1956
|
+
new dt(`Invalid \`retry\` value: "${w}"`, {
|
|
1889
1957
|
type: "invalid-retry",
|
|
1890
|
-
value:
|
|
1891
|
-
line:
|
|
1958
|
+
value: w,
|
|
1959
|
+
line: b
|
|
1892
1960
|
})
|
|
1893
1961
|
);
|
|
1894
1962
|
break;
|
|
1895
1963
|
default:
|
|
1896
1964
|
n(
|
|
1897
|
-
new
|
|
1965
|
+
new dt(
|
|
1898
1966
|
`Unknown field "${p.length > 20 ? `${p.slice(0, 20)}…` : p}"`,
|
|
1899
|
-
{ type: "unknown-field", field: p, value:
|
|
1967
|
+
{ type: "unknown-field", field: p, value: w, line: b }
|
|
1900
1968
|
)
|
|
1901
1969
|
);
|
|
1902
1970
|
break;
|
|
1903
1971
|
}
|
|
1904
1972
|
}
|
|
1905
|
-
function
|
|
1906
|
-
|
|
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:
|
|
1912
|
-
`) ?
|
|
1913
|
-
}), c = void 0,
|
|
1979
|
+
data: l.endsWith(`
|
|
1980
|
+
`) ? l.slice(0, -1) : l
|
|
1981
|
+
}), c = void 0, l = "", u = "";
|
|
1914
1982
|
}
|
|
1915
|
-
function
|
|
1916
|
-
a && p.consume &&
|
|
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:
|
|
1986
|
+
return { feed: h, reset: m };
|
|
1919
1987
|
}
|
|
1920
|
-
function
|
|
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
|
|
1927
|
-
if (o !== -1 && a !== -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,
|
|
1932
|
-
t.push(c), 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
|
|
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 =
|
|
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
|
|
2029
|
+
function me(...e) {
|
|
1962
2030
|
return e.reduce(
|
|
1963
|
-
(t, n) =>
|
|
2031
|
+
(t, n) => P(P({}, t), n ?? {}),
|
|
1964
2032
|
{}
|
|
1965
2033
|
);
|
|
1966
2034
|
}
|
|
1967
|
-
function
|
|
2035
|
+
function $e(e) {
|
|
1968
2036
|
return Object.fromEntries([...e.headers]);
|
|
1969
2037
|
}
|
|
1970
|
-
var
|
|
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,
|
|
2045
|
+
const a = n.length, i = new Array(t);
|
|
1978
2046
|
for (let c = 0; c < t; c++)
|
|
1979
|
-
|
|
1980
|
-
return
|
|
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
|
|
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
|
-
},
|
|
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
|
|
1996
|
-
function
|
|
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 &&
|
|
2071
|
+
if (e instanceof TypeError && wo.includes(e.message.toLowerCase())) {
|
|
2004
2072
|
const r = e.cause;
|
|
2005
2073
|
if (r != null)
|
|
2006
|
-
return new
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
2049
|
-
function
|
|
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" ||
|
|
2119
|
+
return t === null || typeof t != "object" || So.test(e) === !1 && Ro.test(e) === !1 ? t : Co(t);
|
|
2052
2120
|
}
|
|
2053
|
-
function
|
|
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
|
|
2139
|
+
function Xe(e) {
|
|
2072
2140
|
const { stackTraceLimit: t } = Error;
|
|
2073
2141
|
Error.stackTraceLimit = 0;
|
|
2074
2142
|
try {
|
|
2075
|
-
return
|
|
2143
|
+
return Eo(e);
|
|
2076
2144
|
} finally {
|
|
2077
2145
|
Error.stackTraceLimit = t;
|
|
2078
2146
|
}
|
|
2079
2147
|
}
|
|
2080
|
-
var
|
|
2081
|
-
function
|
|
2082
|
-
return { [
|
|
2148
|
+
var Ve = Symbol.for("vercel.ai.validator");
|
|
2149
|
+
function xo(e) {
|
|
2150
|
+
return { [Ve]: !0, validate: e };
|
|
2083
2151
|
}
|
|
2084
|
-
function
|
|
2085
|
-
return typeof e == "object" && e !== null &&
|
|
2152
|
+
function Io(e) {
|
|
2153
|
+
return typeof e == "object" && e !== null && Ve in e && e[Ve] === !0 && "validate" in e;
|
|
2086
2154
|
}
|
|
2087
|
-
function
|
|
2088
|
-
return
|
|
2155
|
+
function Oo(e) {
|
|
2156
|
+
return Io(e) ? e : Po(e);
|
|
2089
2157
|
}
|
|
2090
|
-
function
|
|
2091
|
-
return
|
|
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
|
|
2163
|
+
error: new he({
|
|
2096
2164
|
value: t,
|
|
2097
2165
|
cause: n.issues
|
|
2098
2166
|
})
|
|
2099
2167
|
};
|
|
2100
2168
|
});
|
|
2101
2169
|
}
|
|
2102
|
-
async function
|
|
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
|
|
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 =
|
|
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:
|
|
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:
|
|
2196
|
+
error: he.wrap({ value: e, cause: r }),
|
|
2129
2197
|
rawValue: e
|
|
2130
2198
|
};
|
|
2131
2199
|
}
|
|
2132
2200
|
}
|
|
2133
|
-
async function
|
|
2201
|
+
async function $o({
|
|
2134
2202
|
text: e,
|
|
2135
2203
|
schema: t
|
|
2136
2204
|
}) {
|
|
2137
2205
|
try {
|
|
2138
|
-
const n =
|
|
2139
|
-
return t == null ? n :
|
|
2206
|
+
const n = Xe(e);
|
|
2207
|
+
return t == null ? n : Ao({ value: n, schema: t });
|
|
2140
2208
|
} catch (n) {
|
|
2141
|
-
throw
|
|
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 =
|
|
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:
|
|
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
|
|
2227
|
+
function je(e) {
|
|
2160
2228
|
try {
|
|
2161
|
-
return
|
|
2229
|
+
return Xe(e), !0;
|
|
2162
2230
|
} catch {
|
|
2163
2231
|
return !1;
|
|
2164
2232
|
}
|
|
2165
2233
|
}
|
|
2166
|
-
function
|
|
2234
|
+
function Uo({
|
|
2167
2235
|
stream: e,
|
|
2168
2236
|
schema: t
|
|
2169
2237
|
}) {
|
|
2170
|
-
return e.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
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
|
|
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:
|
|
2186
|
-
}) =>
|
|
2253
|
+
fetch: i
|
|
2254
|
+
}) => No({
|
|
2187
2255
|
url: e,
|
|
2188
|
-
headers:
|
|
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:
|
|
2199
|
-
}),
|
|
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:
|
|
2274
|
+
fetch: i = Mo()
|
|
2207
2275
|
}) => {
|
|
2208
2276
|
try {
|
|
2209
|
-
const c = await
|
|
2277
|
+
const c = await i(e, {
|
|
2210
2278
|
method: "POST",
|
|
2211
|
-
headers:
|
|
2279
|
+
headers: ko(t),
|
|
2212
2280
|
body: n.content,
|
|
2213
2281
|
signal: a
|
|
2214
|
-
}),
|
|
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) ||
|
|
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:
|
|
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) ||
|
|
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:
|
|
2315
|
+
responseHeaders: l,
|
|
2248
2316
|
requestBodyValues: n.values
|
|
2249
2317
|
});
|
|
2250
2318
|
}
|
|
2251
2319
|
} catch (c) {
|
|
2252
|
-
throw
|
|
2320
|
+
throw bo({ error: c, url: e, requestBodyValues: n.values });
|
|
2253
2321
|
}
|
|
2254
|
-
},
|
|
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
|
|
2260
|
-
if (
|
|
2327
|
+
const i = await r.text(), c = $e(r);
|
|
2328
|
+
if (i.trim() === "")
|
|
2261
2329
|
return {
|
|
2262
2330
|
responseHeaders: c,
|
|
2263
|
-
value: new
|
|
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:
|
|
2337
|
+
responseBody: i,
|
|
2270
2338
|
isRetryable: n?.(r)
|
|
2271
2339
|
})
|
|
2272
2340
|
};
|
|
2273
2341
|
try {
|
|
2274
|
-
const
|
|
2275
|
-
text:
|
|
2342
|
+
const l = await $o({
|
|
2343
|
+
text: i,
|
|
2276
2344
|
schema: e
|
|
2277
2345
|
});
|
|
2278
2346
|
return {
|
|
2279
2347
|
responseHeaders: c,
|
|
2280
|
-
value: new
|
|
2281
|
-
message: t(
|
|
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:
|
|
2287
|
-
data:
|
|
2288
|
-
isRetryable: n?.(r,
|
|
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
|
|
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:
|
|
2368
|
+
responseBody: i,
|
|
2301
2369
|
isRetryable: n?.(r)
|
|
2302
2370
|
})
|
|
2303
2371
|
};
|
|
2304
2372
|
}
|
|
2305
2373
|
}, yn = (e) => async ({ response: t }) => {
|
|
2306
|
-
const n =
|
|
2374
|
+
const n = $e(t);
|
|
2307
2375
|
if (t.body == null)
|
|
2308
|
-
throw new
|
|
2376
|
+
throw new oo({});
|
|
2309
2377
|
return {
|
|
2310
2378
|
responseHeaders: n,
|
|
2311
|
-
value:
|
|
2379
|
+
value: Uo({
|
|
2312
2380
|
stream: t.body,
|
|
2313
2381
|
schema: e
|
|
2314
2382
|
})
|
|
2315
2383
|
};
|
|
2316
|
-
},
|
|
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
|
-
}),
|
|
2388
|
+
}), i = $e(t);
|
|
2321
2389
|
if (!a.success)
|
|
2322
|
-
throw new
|
|
2390
|
+
throw new F({
|
|
2323
2391
|
message: "Invalid JSON response",
|
|
2324
2392
|
cause: a.error,
|
|
2325
2393
|
statusCode: t.status,
|
|
2326
|
-
responseHeaders:
|
|
2394
|
+
responseHeaders: i,
|
|
2327
2395
|
responseBody: o,
|
|
2328
2396
|
url: n,
|
|
2329
2397
|
requestBodyValues: r
|
|
2330
2398
|
});
|
|
2331
2399
|
return {
|
|
2332
|
-
responseHeaders:
|
|
2400
|
+
responseHeaders: i,
|
|
2333
2401
|
value: a.value,
|
|
2334
2402
|
rawValue: a.rawValue
|
|
2335
2403
|
};
|
|
2336
|
-
}, { btoa:
|
|
2337
|
-
function
|
|
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
|
|
2409
|
+
return Do(t);
|
|
2342
2410
|
}
|
|
2343
|
-
function
|
|
2411
|
+
function Lo(e) {
|
|
2344
2412
|
return e?.replace(/\/$/, "");
|
|
2345
2413
|
}
|
|
2346
|
-
function
|
|
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 || {}),
|
|
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:
|
|
2419
|
+
format: Ge(wn).nullish(),
|
|
2352
2420
|
index: k().optional()
|
|
2353
|
-
}).loose(),
|
|
2354
|
-
type:
|
|
2421
|
+
}).loose(), qo = d({
|
|
2422
|
+
type: x(
|
|
2355
2423
|
"reasoning.summary"
|
|
2356
2424
|
/* Summary */
|
|
2357
2425
|
),
|
|
2358
2426
|
summary: s()
|
|
2359
|
-
}).extend(
|
|
2360
|
-
type:
|
|
2427
|
+
}).extend(Qe.shape), Vo = d({
|
|
2428
|
+
type: x(
|
|
2361
2429
|
"reasoning.encrypted"
|
|
2362
2430
|
/* Encrypted */
|
|
2363
2431
|
),
|
|
2364
2432
|
data: s()
|
|
2365
|
-
}).extend(
|
|
2366
|
-
type:
|
|
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(
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
]),
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
]),
|
|
2380
|
-
|
|
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:
|
|
2451
|
+
reasoning_details: y(we)
|
|
2384
2452
|
})
|
|
2385
2453
|
}).transform(
|
|
2386
|
-
(e) => e.delta.reasoning_details.filter(
|
|
2454
|
+
(e) => e.delta.reasoning_details.filter(De)
|
|
2387
2455
|
),
|
|
2388
2456
|
d({
|
|
2389
2457
|
message: d({
|
|
2390
|
-
reasoning_details:
|
|
2458
|
+
reasoning_details: y(we)
|
|
2391
2459
|
})
|
|
2392
2460
|
}).transform(
|
|
2393
|
-
(e) => e.message.reasoning_details.filter(
|
|
2461
|
+
(e) => e.message.reasoning_details.filter(De)
|
|
2394
2462
|
),
|
|
2395
2463
|
d({
|
|
2396
2464
|
text: s(),
|
|
2397
|
-
reasoning_details:
|
|
2398
|
-
}).transform((e) => e.reasoning_details.filter(
|
|
2465
|
+
reasoning_details: y(we)
|
|
2466
|
+
}).transform((e) => e.reasoning_details.filter(De))
|
|
2399
2467
|
]);
|
|
2400
|
-
var
|
|
2468
|
+
var Ue = d({
|
|
2401
2469
|
error: d({
|
|
2402
|
-
code:
|
|
2470
|
+
code: j([s(), k()]).nullable().optional().default(null),
|
|
2403
2471
|
message: s(),
|
|
2404
2472
|
type: s().nullable().optional().default(null),
|
|
2405
|
-
param:
|
|
2473
|
+
param: K().nullable().optional().default(null)
|
|
2406
2474
|
}).passthrough()
|
|
2407
|
-
}).passthrough(),
|
|
2408
|
-
errorSchema:
|
|
2475
|
+
}).passthrough(), ge = jo({
|
|
2476
|
+
errorSchema: Ue,
|
|
2409
2477
|
errorToMessage: (e) => e.error.message
|
|
2410
2478
|
}), bn = d({
|
|
2411
|
-
type:
|
|
2479
|
+
type: x("file"),
|
|
2412
2480
|
file: d({
|
|
2413
2481
|
hash: s(),
|
|
2414
2482
|
name: s(),
|
|
2415
|
-
content:
|
|
2483
|
+
content: y(
|
|
2416
2484
|
d({
|
|
2417
2485
|
type: s(),
|
|
2418
2486
|
text: s().optional()
|
|
2419
|
-
}).
|
|
2487
|
+
}).catchall(K())
|
|
2420
2488
|
).optional()
|
|
2421
|
-
}).
|
|
2422
|
-
}),
|
|
2489
|
+
}).catchall(K())
|
|
2490
|
+
}).catchall(K()), Jo = d({
|
|
2423
2491
|
provider: s(),
|
|
2424
|
-
reasoning_details:
|
|
2425
|
-
annotations:
|
|
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
|
-
}).
|
|
2498
|
+
}).catchall(K()).optional(),
|
|
2431
2499
|
completionTokens: k(),
|
|
2432
2500
|
completionTokensDetails: d({
|
|
2433
2501
|
reasoningTokens: k()
|
|
2434
|
-
}).
|
|
2502
|
+
}).catchall(K()).optional(),
|
|
2435
2503
|
totalTokens: k(),
|
|
2436
2504
|
cost: k().optional(),
|
|
2437
2505
|
costDetails: d({
|
|
2438
2506
|
upstreamInferenceCost: k()
|
|
2439
|
-
}).
|
|
2440
|
-
}).
|
|
2441
|
-
}).
|
|
2507
|
+
}).catchall(K()).optional()
|
|
2508
|
+
}).catchall(K())
|
|
2509
|
+
}).catchall(K()), pt = d({
|
|
2442
2510
|
openrouter: d({
|
|
2443
|
-
reasoning_details:
|
|
2444
|
-
annotations:
|
|
2511
|
+
reasoning_details: y(et).optional(),
|
|
2512
|
+
annotations: y(bn).optional()
|
|
2445
2513
|
}).optional()
|
|
2446
2514
|
}).optional();
|
|
2447
|
-
function
|
|
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
|
-
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
2572
|
+
function Je(e) {
|
|
2494
2573
|
const t = e.match(/^data:[^;]*;base64,(.+)$/);
|
|
2495
2574
|
return t ? t[1] : e;
|
|
2496
2575
|
}
|
|
2497
|
-
|
|
2498
|
-
|
|
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 (
|
|
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 =
|
|
2519
|
-
|
|
2520
|
-
|
|
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
|
|
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
|
-
|
|
2635
|
+
}
|
|
2636
|
+
return { data: n, format: a };
|
|
2531
2637
|
}
|
|
2532
|
-
function
|
|
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
|
|
2538
|
-
var t, n, r, o, a,
|
|
2539
|
-
const
|
|
2540
|
-
for (const { role:
|
|
2541
|
-
switch (
|
|
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
|
-
|
|
2649
|
+
g.push({
|
|
2544
2650
|
role: "system",
|
|
2545
|
-
content:
|
|
2546
|
-
cache_control:
|
|
2651
|
+
content: v,
|
|
2652
|
+
cache_control: ee(m)
|
|
2547
2653
|
});
|
|
2548
2654
|
break;
|
|
2549
2655
|
}
|
|
2550
2656
|
case "user": {
|
|
2551
|
-
if (
|
|
2552
|
-
const
|
|
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:
|
|
2556
|
-
cache_control:
|
|
2661
|
+
text: v[0].text,
|
|
2662
|
+
cache_control: b
|
|
2557
2663
|
}
|
|
2558
|
-
] :
|
|
2559
|
-
|
|
2664
|
+
] : v[0].text;
|
|
2665
|
+
g.push({
|
|
2560
2666
|
role: "user",
|
|
2561
|
-
content:
|
|
2667
|
+
content: R
|
|
2562
2668
|
});
|
|
2563
2669
|
break;
|
|
2564
2670
|
}
|
|
2565
|
-
const p =
|
|
2566
|
-
(
|
|
2567
|
-
var
|
|
2568
|
-
const
|
|
2569
|
-
switch (
|
|
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:
|
|
2679
|
+
text: b.text,
|
|
2574
2680
|
// For text parts, only use part-specific cache control
|
|
2575
|
-
cache_control:
|
|
2681
|
+
cache_control: z
|
|
2576
2682
|
};
|
|
2577
2683
|
case "file": {
|
|
2578
|
-
if ((
|
|
2684
|
+
if ((T = b.mediaType) != null && T.startsWith("image/"))
|
|
2579
2685
|
return {
|
|
2580
2686
|
type: "image_url",
|
|
2581
2687
|
image_url: {
|
|
2582
|
-
url:
|
|
2583
|
-
part:
|
|
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:
|
|
2694
|
+
cache_control: z
|
|
2589
2695
|
};
|
|
2590
|
-
if ((
|
|
2696
|
+
if ((S = b.mediaType) != null && S.startsWith("audio/"))
|
|
2591
2697
|
return {
|
|
2592
2698
|
type: "input_audio",
|
|
2593
|
-
input_audio:
|
|
2594
|
-
cache_control:
|
|
2699
|
+
input_audio: Wo(b),
|
|
2700
|
+
cache_control: z
|
|
2595
2701
|
};
|
|
2596
|
-
const
|
|
2597
|
-
(
|
|
2598
|
-
), G =
|
|
2599
|
-
part:
|
|
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
|
|
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:
|
|
2714
|
+
filename: J,
|
|
2609
2715
|
file_data: G
|
|
2610
2716
|
}
|
|
2611
2717
|
} : {
|
|
2612
2718
|
type: "file",
|
|
2613
2719
|
file: {
|
|
2614
|
-
filename:
|
|
2720
|
+
filename: J,
|
|
2615
2721
|
file_data: G
|
|
2616
2722
|
},
|
|
2617
|
-
cache_control:
|
|
2723
|
+
cache_control: z
|
|
2618
2724
|
};
|
|
2619
2725
|
}
|
|
2620
2726
|
default:
|
|
2621
2727
|
return {
|
|
2622
2728
|
type: "text",
|
|
2623
2729
|
text: "",
|
|
2624
|
-
cache_control:
|
|
2730
|
+
cache_control: z
|
|
2625
2731
|
};
|
|
2626
2732
|
}
|
|
2627
2733
|
}
|
|
2628
2734
|
);
|
|
2629
|
-
|
|
2735
|
+
g.push({
|
|
2630
2736
|
role: "user",
|
|
2631
|
-
content:
|
|
2737
|
+
content: w
|
|
2632
2738
|
});
|
|
2633
2739
|
break;
|
|
2634
2740
|
}
|
|
2635
2741
|
case "assistant": {
|
|
2636
|
-
let p = "",
|
|
2637
|
-
const
|
|
2638
|
-
for (const
|
|
2639
|
-
switch (
|
|
2742
|
+
let p = "", w = "";
|
|
2743
|
+
const b = [], R = [];
|
|
2744
|
+
for (const A of v)
|
|
2745
|
+
switch (A.type) {
|
|
2640
2746
|
case "text": {
|
|
2641
|
-
p +=
|
|
2747
|
+
p += A.text;
|
|
2642
2748
|
break;
|
|
2643
2749
|
}
|
|
2644
2750
|
case "tool-call": {
|
|
2645
|
-
const
|
|
2646
|
-
|
|
2647
|
-
...
|
|
2648
|
-
),
|
|
2649
|
-
id:
|
|
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:
|
|
2653
|
-
arguments: JSON.stringify(
|
|
2758
|
+
name: A.toolName,
|
|
2759
|
+
arguments: JSON.stringify(A.input)
|
|
2654
2760
|
}
|
|
2655
2761
|
});
|
|
2656
2762
|
break;
|
|
2657
2763
|
}
|
|
2658
2764
|
case "reasoning": {
|
|
2659
|
-
|
|
2660
|
-
const
|
|
2661
|
-
|
|
2662
|
-
...
|
|
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
|
|
2668
|
-
|
|
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:
|
|
2672
|
-
reasoning:
|
|
2777
|
+
tool_calls: b.length > 0 ? b : void 0,
|
|
2778
|
+
reasoning: w || void 0,
|
|
2673
2779
|
reasoning_details: $,
|
|
2674
|
-
annotations:
|
|
2675
|
-
cache_control:
|
|
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
|
|
2682
|
-
|
|
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:
|
|
2686
|
-
cache_control: (h =
|
|
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
|
|
2798
|
+
return g;
|
|
2693
2799
|
}
|
|
2694
|
-
function
|
|
2800
|
+
function Ko(e) {
|
|
2695
2801
|
return e.output.type === "text" ? e.output.value : JSON.stringify(e.output.value);
|
|
2696
2802
|
}
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2803
|
+
j([
|
|
2804
|
+
x("auto"),
|
|
2805
|
+
x("none"),
|
|
2806
|
+
x("required"),
|
|
2701
2807
|
d({
|
|
2702
|
-
type:
|
|
2808
|
+
type: x("function"),
|
|
2703
2809
|
function: d({
|
|
2704
2810
|
name: s()
|
|
2705
2811
|
})
|
|
2706
2812
|
})
|
|
2707
2813
|
]);
|
|
2708
|
-
function
|
|
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
|
|
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
|
|
2727
|
-
type:
|
|
2832
|
+
var Xo = d({
|
|
2833
|
+
type: x("image_url"),
|
|
2728
2834
|
image_url: d({
|
|
2729
2835
|
url: s()
|
|
2730
2836
|
}).passthrough()
|
|
2731
|
-
}).passthrough(),
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
]), kn =
|
|
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(),
|
|
2859
|
+
}).passthrough(), Qo = j([
|
|
2754
2860
|
// Success response with choices
|
|
2755
2861
|
Tn.extend({
|
|
2756
|
-
choices:
|
|
2862
|
+
choices: y(
|
|
2757
2863
|
d({
|
|
2758
2864
|
message: d({
|
|
2759
|
-
role:
|
|
2865
|
+
role: x("assistant"),
|
|
2760
2866
|
content: s().nullable().optional(),
|
|
2761
2867
|
reasoning: s().nullable().optional(),
|
|
2762
|
-
reasoning_details:
|
|
2868
|
+
reasoning_details: tt.nullish(),
|
|
2763
2869
|
images: kn.nullish(),
|
|
2764
|
-
tool_calls:
|
|
2870
|
+
tool_calls: y(
|
|
2765
2871
|
d({
|
|
2766
2872
|
id: s().optional().nullable(),
|
|
2767
|
-
type:
|
|
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:
|
|
2775
|
-
|
|
2880
|
+
annotations: y(
|
|
2881
|
+
j([
|
|
2776
2882
|
// URL citation from web search
|
|
2777
2883
|
d({
|
|
2778
|
-
type:
|
|
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:
|
|
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:
|
|
2903
|
+
type: x("file"),
|
|
2798
2904
|
file: d({
|
|
2799
2905
|
hash: s(),
|
|
2800
2906
|
name: s(),
|
|
2801
|
-
content:
|
|
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:
|
|
2920
|
+
content: y(
|
|
2815
2921
|
d({
|
|
2816
2922
|
token: s(),
|
|
2817
2923
|
logprob: k(),
|
|
2818
|
-
top_logprobs:
|
|
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
|
-
|
|
2938
|
+
Ue.extend({
|
|
2833
2939
|
user_id: s().optional()
|
|
2834
2940
|
})
|
|
2835
|
-
]),
|
|
2941
|
+
]), es = j([
|
|
2836
2942
|
Tn.extend({
|
|
2837
|
-
choices:
|
|
2943
|
+
choices: y(
|
|
2838
2944
|
d({
|
|
2839
2945
|
delta: d({
|
|
2840
|
-
role:
|
|
2946
|
+
role: Ge(["assistant"]).optional(),
|
|
2841
2947
|
content: s().nullish(),
|
|
2842
2948
|
reasoning: s().nullish().optional(),
|
|
2843
|
-
reasoning_details:
|
|
2949
|
+
reasoning_details: tt.nullish(),
|
|
2844
2950
|
images: kn.nullish(),
|
|
2845
|
-
tool_calls:
|
|
2951
|
+
tool_calls: y(
|
|
2846
2952
|
d({
|
|
2847
2953
|
index: k().nullish(),
|
|
2848
2954
|
id: s().nullish(),
|
|
2849
|
-
type:
|
|
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:
|
|
2857
|
-
|
|
2962
|
+
annotations: y(
|
|
2963
|
+
j([
|
|
2858
2964
|
// URL citation from web search
|
|
2859
2965
|
d({
|
|
2860
|
-
type:
|
|
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:
|
|
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:
|
|
2985
|
+
type: x("file"),
|
|
2880
2986
|
file: d({
|
|
2881
2987
|
hash: s(),
|
|
2882
2988
|
name: s(),
|
|
2883
|
-
content:
|
|
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:
|
|
3001
|
+
content: y(
|
|
2896
3002
|
d({
|
|
2897
3003
|
token: s(),
|
|
2898
3004
|
logprob: k(),
|
|
2899
|
-
top_logprobs:
|
|
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
|
-
|
|
2914
|
-
]),
|
|
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:
|
|
3038
|
+
seed: i,
|
|
2933
3039
|
stopSequences: c,
|
|
2934
|
-
responseFormat:
|
|
3040
|
+
responseFormat: l,
|
|
2935
3041
|
topK: u,
|
|
2936
3042
|
tools: h,
|
|
2937
|
-
toolChoice:
|
|
3043
|
+
toolChoice: g
|
|
2938
3044
|
}) {
|
|
2939
|
-
var
|
|
2940
|
-
const
|
|
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:
|
|
3062
|
+
seed: i,
|
|
2957
3063
|
stop: c,
|
|
2958
|
-
response_format:
|
|
3064
|
+
response_format: l?.type === "json" ? l.schema != null ? {
|
|
2959
3065
|
type: "json_schema",
|
|
2960
|
-
json_schema:
|
|
2961
|
-
schema:
|
|
3066
|
+
json_schema: P({
|
|
3067
|
+
schema: l.schema,
|
|
2962
3068
|
strict: !0,
|
|
2963
|
-
name: (
|
|
2964
|
-
},
|
|
2965
|
-
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:
|
|
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
|
|
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
|
|
2995
|
-
tools:
|
|
2996
|
-
tool_choice:
|
|
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,
|
|
3003
|
-
const
|
|
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:
|
|
3009
|
-
body:
|
|
3010
|
-
failedResponseHandler:
|
|
3011
|
-
successfulResponseHandler:
|
|
3012
|
-
|
|
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
|
|
3019
|
-
throw new
|
|
3020
|
-
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:
|
|
3131
|
+
requestBodyValues: J,
|
|
3026
3132
|
statusCode: 200,
|
|
3027
|
-
responseHeaders:
|
|
3028
|
-
data:
|
|
3133
|
+
responseHeaders: se,
|
|
3134
|
+
data: _
|
|
3029
3135
|
});
|
|
3030
3136
|
}
|
|
3031
|
-
const
|
|
3032
|
-
if (!
|
|
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
|
|
3037
|
-
inputTokens: (t =
|
|
3038
|
-
outputTokens: (n =
|
|
3039
|
-
totalTokens: ((r =
|
|
3040
|
-
reasoningTokens: (
|
|
3041
|
-
cachedInputTokens: (
|
|
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
|
-
},
|
|
3049
|
-
switch (
|
|
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 (
|
|
3157
|
+
if (_.text)
|
|
3052
3158
|
return {
|
|
3053
3159
|
type: "reasoning",
|
|
3054
|
-
text:
|
|
3160
|
+
text: _.text,
|
|
3055
3161
|
providerMetadata: {
|
|
3056
3162
|
openrouter: {
|
|
3057
|
-
reasoning_details: [
|
|
3163
|
+
reasoning_details: [_]
|
|
3058
3164
|
}
|
|
3059
3165
|
}
|
|
3060
3166
|
};
|
|
3061
3167
|
break;
|
|
3062
3168
|
}
|
|
3063
3169
|
case "reasoning.summary": {
|
|
3064
|
-
if (
|
|
3170
|
+
if (_.summary)
|
|
3065
3171
|
return {
|
|
3066
3172
|
type: "reasoning",
|
|
3067
|
-
text:
|
|
3173
|
+
text: _.summary,
|
|
3068
3174
|
providerMetadata: {
|
|
3069
3175
|
openrouter: {
|
|
3070
|
-
reasoning_details: [
|
|
3176
|
+
reasoning_details: [_]
|
|
3071
3177
|
}
|
|
3072
3178
|
}
|
|
3073
3179
|
};
|
|
3074
3180
|
break;
|
|
3075
3181
|
}
|
|
3076
3182
|
case "reasoning.encrypted": {
|
|
3077
|
-
if (
|
|
3183
|
+
if (_.data)
|
|
3078
3184
|
return {
|
|
3079
3185
|
type: "reasoning",
|
|
3080
3186
|
text: "[REDACTED]",
|
|
3081
3187
|
providerMetadata: {
|
|
3082
3188
|
openrouter: {
|
|
3083
|
-
reasoning_details: [
|
|
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((
|
|
3197
|
+
}).filter((_) => _ !== null) : H.message.reasoning ? [
|
|
3092
3198
|
{
|
|
3093
3199
|
type: "reasoning",
|
|
3094
|
-
text:
|
|
3200
|
+
text: H.message.reasoning
|
|
3095
3201
|
}
|
|
3096
3202
|
] : [], Z = [];
|
|
3097
|
-
if (Z.push(...
|
|
3203
|
+
if (Z.push(...ve), H.message.content && Z.push({
|
|
3098
3204
|
type: "text",
|
|
3099
|
-
text:
|
|
3100
|
-
}),
|
|
3101
|
-
for (const
|
|
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 =
|
|
3105
|
-
toolName:
|
|
3106
|
-
input:
|
|
3210
|
+
toolCallId: (h = _.id) != null ? h : W(),
|
|
3211
|
+
toolName: _.function.name,
|
|
3212
|
+
input: _.function.arguments,
|
|
3107
3213
|
providerMetadata: {
|
|
3108
3214
|
openrouter: {
|
|
3109
|
-
reasoning_details:
|
|
3215
|
+
reasoning_details: re
|
|
3110
3216
|
}
|
|
3111
3217
|
}
|
|
3112
3218
|
});
|
|
3113
|
-
if (
|
|
3114
|
-
for (const
|
|
3219
|
+
if (H.message.images)
|
|
3220
|
+
for (const _ of H.message.images)
|
|
3115
3221
|
Z.push({
|
|
3116
3222
|
type: "file",
|
|
3117
|
-
mediaType:
|
|
3118
|
-
data:
|
|
3223
|
+
mediaType: ht(_.image_url.url, "image/jpeg"),
|
|
3224
|
+
data: Je(_.image_url.url)
|
|
3119
3225
|
});
|
|
3120
|
-
if (
|
|
3121
|
-
for (const
|
|
3122
|
-
|
|
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:
|
|
3126
|
-
url:
|
|
3127
|
-
title:
|
|
3231
|
+
id: _.url_citation.url,
|
|
3232
|
+
url: _.url_citation.url,
|
|
3233
|
+
title: _.url_citation.title,
|
|
3128
3234
|
providerMetadata: {
|
|
3129
3235
|
openrouter: {
|
|
3130
|
-
content:
|
|
3236
|
+
content: _.url_citation.content || ""
|
|
3131
3237
|
}
|
|
3132
3238
|
}
|
|
3133
3239
|
});
|
|
3134
|
-
const
|
|
3135
|
-
(
|
|
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:
|
|
3140
|
-
usage:
|
|
3247
|
+
finishReason: ie,
|
|
3248
|
+
usage: ne,
|
|
3141
3249
|
warnings: [],
|
|
3142
3250
|
providerMetadata: {
|
|
3143
|
-
openrouter:
|
|
3144
|
-
provider: (
|
|
3145
|
-
reasoning_details: (
|
|
3146
|
-
annotations:
|
|
3147
|
-
usage:
|
|
3148
|
-
promptTokens: (
|
|
3149
|
-
completionTokens: (p =
|
|
3150
|
-
totalTokens: (
|
|
3151
|
-
cost: (
|
|
3152
|
-
}, ((
|
|
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:
|
|
3262
|
+
cachedTokens: D.usage.prompt_tokens_details.cached_tokens
|
|
3155
3263
|
}
|
|
3156
|
-
} : {}), ((
|
|
3264
|
+
} : {}), ((M = (S = D.usage) == null ? void 0 : S.completion_tokens_details) == null ? void 0 : M.reasoning_tokens) != null ? {
|
|
3157
3265
|
completionTokensDetails: {
|
|
3158
|
-
reasoningTokens:
|
|
3266
|
+
reasoningTokens: D.usage.completion_tokens_details.reasoning_tokens
|
|
3159
3267
|
}
|
|
3160
|
-
} : {}), ((
|
|
3268
|
+
} : {}), ((A = ($ = D.usage) == null ? void 0 : $.cost_details) == null ? void 0 : A.upstream_inference_cost) != null ? {
|
|
3161
3269
|
costDetails: {
|
|
3162
|
-
upstreamInferenceCost:
|
|
3270
|
+
upstreamInferenceCost: D.usage.cost_details.upstream_inference_cost
|
|
3163
3271
|
}
|
|
3164
3272
|
} : {})
|
|
3165
3273
|
})
|
|
3166
3274
|
},
|
|
3167
|
-
request: { body:
|
|
3275
|
+
request: { body: J },
|
|
3168
3276
|
response: {
|
|
3169
|
-
id:
|
|
3170
|
-
modelId:
|
|
3171
|
-
headers:
|
|
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 =
|
|
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:
|
|
3183
|
-
body:
|
|
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" ?
|
|
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:
|
|
3298
|
+
failedResponseHandler: ge,
|
|
3191
3299
|
successfulResponseHandler: yn(
|
|
3192
|
-
|
|
3300
|
+
es
|
|
3193
3301
|
),
|
|
3194
3302
|
abortSignal: e.abortSignal,
|
|
3195
3303
|
fetch: this.config.fetch
|
|
3196
3304
|
}), c = [];
|
|
3197
|
-
let
|
|
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
|
|
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,
|
|
3210
|
-
var
|
|
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
|
-
|
|
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
|
-
|
|
3325
|
+
l = "error", S.enqueue({ type: "error", error: U.error });
|
|
3218
3326
|
return;
|
|
3219
3327
|
}
|
|
3220
|
-
if (U.provider && (
|
|
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 &&
|
|
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
|
|
3229
|
-
u.cachedInputTokens =
|
|
3230
|
-
cachedTokens:
|
|
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
|
|
3235
|
-
u.reasoningTokens =
|
|
3236
|
-
reasoningTokens:
|
|
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
|
|
3241
|
-
|
|
3242
|
-
upstreamInferenceCost:
|
|
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
|
|
3246
|
-
if (
|
|
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
|
|
3249
|
-
|
|
3250
|
-
providerMetadata:
|
|
3356
|
+
const q = Q.delta, ie = (_, C) => {
|
|
3357
|
+
m || (w = b || W(), S.enqueue({
|
|
3358
|
+
providerMetadata: C,
|
|
3251
3359
|
type: "reasoning-start",
|
|
3252
|
-
id:
|
|
3253
|
-
}),
|
|
3254
|
-
providerMetadata:
|
|
3360
|
+
id: w
|
|
3361
|
+
}), m = !0), S.enqueue({
|
|
3362
|
+
providerMetadata: C,
|
|
3255
3363
|
type: "reasoning-delta",
|
|
3256
|
-
delta:
|
|
3257
|
-
id:
|
|
3364
|
+
delta: _,
|
|
3365
|
+
id: w || W()
|
|
3258
3366
|
});
|
|
3259
3367
|
};
|
|
3260
|
-
if (
|
|
3261
|
-
for (const
|
|
3262
|
-
if (
|
|
3263
|
-
const N =
|
|
3264
|
-
N?.type === "reasoning.text" ? (N.text = (N.text || "") + (
|
|
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
|
-
|
|
3267
|
-
const
|
|
3374
|
+
g.push(C);
|
|
3375
|
+
const _ = {
|
|
3268
3376
|
openrouter: {
|
|
3269
|
-
reasoning_details:
|
|
3377
|
+
reasoning_details: q.reasoning_details
|
|
3270
3378
|
}
|
|
3271
3379
|
};
|
|
3272
|
-
for (const
|
|
3273
|
-
switch (
|
|
3380
|
+
for (const C of q.reasoning_details)
|
|
3381
|
+
switch (C.type) {
|
|
3274
3382
|
case "reasoning.text": {
|
|
3275
|
-
|
|
3383
|
+
C.text && ie(C.text, _);
|
|
3276
3384
|
break;
|
|
3277
3385
|
}
|
|
3278
3386
|
case "reasoning.encrypted": {
|
|
3279
|
-
|
|
3387
|
+
C.data && ie("[REDACTED]", _);
|
|
3280
3388
|
break;
|
|
3281
3389
|
}
|
|
3282
3390
|
case "reasoning.summary": {
|
|
3283
|
-
|
|
3391
|
+
C.summary && ie(C.summary, _);
|
|
3284
3392
|
break;
|
|
3285
3393
|
}
|
|
3286
3394
|
}
|
|
3287
|
-
} else
|
|
3288
|
-
if (
|
|
3395
|
+
} else q.reasoning && ie(q.reasoning);
|
|
3396
|
+
if (q.content && (m && !v && (S.enqueue({
|
|
3289
3397
|
type: "reasoning-end",
|
|
3290
|
-
id:
|
|
3291
|
-
}),
|
|
3398
|
+
id: w || W()
|
|
3399
|
+
}), m = !1), v || (p = b || W(), S.enqueue({
|
|
3292
3400
|
type: "text-start",
|
|
3293
|
-
id:
|
|
3294
|
-
}),
|
|
3401
|
+
id: p
|
|
3402
|
+
}), v = !0), S.enqueue({
|
|
3295
3403
|
type: "text-delta",
|
|
3296
|
-
delta:
|
|
3297
|
-
id:
|
|
3298
|
-
})),
|
|
3299
|
-
for (const
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
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
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
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 (
|
|
3322
|
-
throw new
|
|
3323
|
-
data:
|
|
3437
|
+
if (_.id == null)
|
|
3438
|
+
throw new de({
|
|
3439
|
+
data: _,
|
|
3324
3440
|
message: "Expected 'id' to be a string."
|
|
3325
3441
|
});
|
|
3326
|
-
if (((
|
|
3327
|
-
throw new
|
|
3328
|
-
data:
|
|
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[
|
|
3332
|
-
id:
|
|
3447
|
+
c[C] = {
|
|
3448
|
+
id: _.id,
|
|
3333
3449
|
type: "function",
|
|
3334
3450
|
function: {
|
|
3335
|
-
name:
|
|
3336
|
-
arguments: (
|
|
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
|
|
3342
|
-
if (
|
|
3343
|
-
throw new
|
|
3344
|
-
data: { index:
|
|
3345
|
-
message: `Tool call at index ${
|
|
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
|
-
((
|
|
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:
|
|
3350
|
-
toolName:
|
|
3351
|
-
}),
|
|
3465
|
+
id: V.id,
|
|
3466
|
+
toolName: V.function.name
|
|
3467
|
+
}), S.enqueue({
|
|
3352
3468
|
type: "tool-input-delta",
|
|
3353
|
-
id:
|
|
3354
|
-
delta:
|
|
3355
|
-
}),
|
|
3469
|
+
id: V.id,
|
|
3470
|
+
delta: V.function.arguments
|
|
3471
|
+
}), S.enqueue({
|
|
3356
3472
|
type: "tool-input-end",
|
|
3357
|
-
id:
|
|
3358
|
-
}),
|
|
3473
|
+
id: V.id
|
|
3474
|
+
}), S.enqueue({
|
|
3359
3475
|
type: "tool-call",
|
|
3360
|
-
toolCallId:
|
|
3361
|
-
toolName:
|
|
3362
|
-
input:
|
|
3476
|
+
toolCallId: V.id,
|
|
3477
|
+
toolName: V.function.name,
|
|
3478
|
+
input: V.function.arguments,
|
|
3363
3479
|
providerMetadata: {
|
|
3364
3480
|
openrouter: {
|
|
3365
|
-
reasoning_details:
|
|
3481
|
+
reasoning_details: g
|
|
3366
3482
|
}
|
|
3367
3483
|
}
|
|
3368
|
-
}),
|
|
3484
|
+
}), V.sent = !0);
|
|
3369
3485
|
continue;
|
|
3370
3486
|
}
|
|
3371
|
-
const N = c[
|
|
3487
|
+
const N = c[C];
|
|
3372
3488
|
if (N == null)
|
|
3373
|
-
throw new
|
|
3489
|
+
throw new de({
|
|
3374
3490
|
data: {
|
|
3375
|
-
index:
|
|
3491
|
+
index: C,
|
|
3376
3492
|
toolCallsLength: c.length,
|
|
3377
|
-
toolCallDelta:
|
|
3493
|
+
toolCallDelta: _
|
|
3378
3494
|
},
|
|
3379
|
-
message: `Tool call at index ${
|
|
3495
|
+
message: `Tool call at index ${C} is missing during merge.`
|
|
3380
3496
|
});
|
|
3381
|
-
N.inputStarted || (N.inputStarted = !0,
|
|
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
|
-
})), ((
|
|
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: (
|
|
3389
|
-
}), ((
|
|
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: (
|
|
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:
|
|
3512
|
+
reasoning_details: g
|
|
3397
3513
|
}
|
|
3398
3514
|
}
|
|
3399
3515
|
}), N.sent = !0);
|
|
3400
3516
|
}
|
|
3401
|
-
if (
|
|
3402
|
-
for (const
|
|
3403
|
-
|
|
3517
|
+
if (q.images != null)
|
|
3518
|
+
for (const _ of q.images)
|
|
3519
|
+
S.enqueue({
|
|
3404
3520
|
type: "file",
|
|
3405
|
-
mediaType:
|
|
3406
|
-
data:
|
|
3521
|
+
mediaType: ht(_.image_url.url, "image/jpeg"),
|
|
3522
|
+
data: Je(_.image_url.url)
|
|
3407
3523
|
});
|
|
3408
3524
|
},
|
|
3409
3525
|
flush(T) {
|
|
3410
|
-
var
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
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: (
|
|
3416
|
-
toolName:
|
|
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:
|
|
3537
|
+
input: je(I.function.arguments) ? I.function.arguments : "{}",
|
|
3419
3538
|
providerMetadata: {
|
|
3420
3539
|
openrouter: {
|
|
3421
|
-
reasoning_details:
|
|
3540
|
+
reasoning_details: g
|
|
3422
3541
|
}
|
|
3423
3542
|
}
|
|
3424
|
-
}),
|
|
3425
|
-
|
|
3543
|
+
}), I.sent = !0);
|
|
3544
|
+
m && T.enqueue({
|
|
3426
3545
|
type: "reasoning-end",
|
|
3427
|
-
id:
|
|
3428
|
-
}),
|
|
3546
|
+
id: w || W()
|
|
3547
|
+
}), v && T.enqueue({
|
|
3429
3548
|
type: "text-end",
|
|
3430
|
-
id:
|
|
3549
|
+
id: p || W()
|
|
3431
3550
|
});
|
|
3432
3551
|
const A = {
|
|
3433
3552
|
usage: h
|
|
3434
3553
|
};
|
|
3435
|
-
|
|
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:
|
|
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:
|
|
3567
|
+
response: { headers: i }
|
|
3449
3568
|
};
|
|
3450
3569
|
}
|
|
3451
3570
|
};
|
|
3452
|
-
function
|
|
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:
|
|
3583
|
+
for (const { role: a, content: i } of e)
|
|
3465
3584
|
switch (a) {
|
|
3466
3585
|
case "system":
|
|
3467
|
-
throw new
|
|
3468
|
-
message: `Unexpected system message in prompt: ${
|
|
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 =
|
|
3473
|
-
switch (
|
|
3591
|
+
const c = i.map((l) => {
|
|
3592
|
+
switch (l.type) {
|
|
3474
3593
|
case "text":
|
|
3475
|
-
return
|
|
3594
|
+
return l.text;
|
|
3476
3595
|
case "file":
|
|
3477
|
-
throw new
|
|
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 =
|
|
3492
|
-
(
|
|
3493
|
-
switch (
|
|
3610
|
+
const c = i.map(
|
|
3611
|
+
(l) => {
|
|
3612
|
+
switch (l.type) {
|
|
3494
3613
|
case "text":
|
|
3495
|
-
return
|
|
3614
|
+
return l.text;
|
|
3496
3615
|
case "tool-call":
|
|
3497
|
-
throw new
|
|
3616
|
+
throw new te({
|
|
3498
3617
|
functionality: "tool-call messages"
|
|
3499
3618
|
});
|
|
3500
3619
|
case "tool-result":
|
|
3501
|
-
throw new
|
|
3620
|
+
throw new te({
|
|
3502
3621
|
functionality: "tool-result messages"
|
|
3503
3622
|
});
|
|
3504
3623
|
case "reasoning":
|
|
3505
|
-
throw new
|
|
3624
|
+
throw new te({
|
|
3506
3625
|
functionality: "reasoning messages"
|
|
3507
3626
|
});
|
|
3508
3627
|
case "file":
|
|
3509
|
-
throw new
|
|
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
|
|
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
|
|
3652
|
+
var mt = j([
|
|
3534
3653
|
d({
|
|
3535
3654
|
id: s().optional(),
|
|
3536
3655
|
model: s().optional(),
|
|
3537
|
-
choices:
|
|
3656
|
+
choices: y(
|
|
3538
3657
|
d({
|
|
3539
3658
|
text: s(),
|
|
3540
3659
|
reasoning: s().nullish().optional(),
|
|
3541
|
-
reasoning_details:
|
|
3660
|
+
reasoning_details: tt.nullish(),
|
|
3542
3661
|
finish_reason: s().nullish(),
|
|
3543
3662
|
index: k().nullish(),
|
|
3544
3663
|
logprobs: d({
|
|
3545
|
-
tokens:
|
|
3546
|
-
token_logprobs:
|
|
3547
|
-
top_logprobs:
|
|
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
|
-
|
|
3568
|
-
]),
|
|
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:
|
|
3705
|
+
seed: i,
|
|
3587
3706
|
responseFormat: c,
|
|
3588
|
-
topK:
|
|
3707
|
+
topK: l,
|
|
3589
3708
|
stopSequences: u,
|
|
3590
3709
|
tools: h,
|
|
3591
|
-
toolChoice:
|
|
3710
|
+
toolChoice: g
|
|
3592
3711
|
}) {
|
|
3593
|
-
const { prompt:
|
|
3712
|
+
const { prompt: f } = ns({
|
|
3594
3713
|
prompt: e,
|
|
3595
3714
|
inputFormat: "prompt"
|
|
3596
3715
|
});
|
|
3597
3716
|
if (h?.length)
|
|
3598
|
-
throw new
|
|
3717
|
+
throw new te({
|
|
3599
3718
|
functionality: "tools"
|
|
3600
3719
|
});
|
|
3601
|
-
if (
|
|
3602
|
-
throw new
|
|
3720
|
+
if (g)
|
|
3721
|
+
throw new te({
|
|
3603
3722
|
functionality: "toolChoice"
|
|
3604
3723
|
});
|
|
3605
|
-
return
|
|
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:
|
|
3739
|
+
seed: i,
|
|
3621
3740
|
stop: u,
|
|
3622
3741
|
response_format: c,
|
|
3623
|
-
top_k:
|
|
3742
|
+
top_k: l,
|
|
3624
3743
|
// prompt:
|
|
3625
|
-
prompt:
|
|
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,
|
|
3633
|
-
const
|
|
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:
|
|
3639
|
-
body:
|
|
3640
|
-
failedResponseHandler:
|
|
3641
|
-
successfulResponseHandler:
|
|
3642
|
-
|
|
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
|
|
3648
|
-
const $ =
|
|
3649
|
-
throw new
|
|
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:
|
|
3774
|
+
requestBodyValues: R,
|
|
3656
3775
|
statusCode: 200,
|
|
3657
|
-
responseHeaders:
|
|
3776
|
+
responseHeaders: S,
|
|
3658
3777
|
data: $
|
|
3659
3778
|
});
|
|
3660
3779
|
}
|
|
3661
|
-
const
|
|
3662
|
-
if (!
|
|
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 =
|
|
3789
|
+
text: (t = M.text) != null ? t : ""
|
|
3671
3790
|
}
|
|
3672
3791
|
],
|
|
3673
|
-
finishReason:
|
|
3792
|
+
finishReason: Oe(M.finish_reason),
|
|
3674
3793
|
usage: {
|
|
3675
|
-
inputTokens: (r = (n =
|
|
3676
|
-
outputTokens: (a = (o =
|
|
3677
|
-
totalTokens: ((c = (
|
|
3678
|
-
reasoningTokens: (
|
|
3679
|
-
cachedInputTokens: (p = (
|
|
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:
|
|
3802
|
+
headers: S
|
|
3684
3803
|
}
|
|
3685
3804
|
};
|
|
3686
3805
|
}
|
|
3687
3806
|
async doStream(e) {
|
|
3688
|
-
const n = (e.providerOptions || {}).openrouter || {}, r =
|
|
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:
|
|
3694
|
-
body:
|
|
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:
|
|
3818
|
+
failedResponseHandler: ge,
|
|
3700
3819
|
successfulResponseHandler: yn(
|
|
3701
|
-
|
|
3820
|
+
mt
|
|
3702
3821
|
),
|
|
3703
3822
|
abortSignal: e.abortSignal,
|
|
3704
3823
|
fetch: this.config.fetch
|
|
3705
3824
|
});
|
|
3706
|
-
let
|
|
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
|
-
},
|
|
3832
|
+
}, l = {};
|
|
3714
3833
|
return {
|
|
3715
3834
|
stream: o.pipeThrough(
|
|
3716
3835
|
new TransformStream({
|
|
3717
3836
|
transform(u, h) {
|
|
3718
|
-
var
|
|
3837
|
+
var g, f, v;
|
|
3719
3838
|
if (!u.success) {
|
|
3720
|
-
|
|
3839
|
+
i = "error", h.enqueue({ type: "error", error: u.error });
|
|
3721
3840
|
return;
|
|
3722
3841
|
}
|
|
3723
|
-
const
|
|
3724
|
-
if ("error" in
|
|
3725
|
-
|
|
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 (
|
|
3729
|
-
if (c.inputTokens =
|
|
3730
|
-
const
|
|
3731
|
-
c.cachedInputTokens =
|
|
3732
|
-
cachedTokens:
|
|
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 (
|
|
3736
|
-
const
|
|
3737
|
-
c.reasoningTokens =
|
|
3738
|
-
reasoningTokens:
|
|
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
|
-
|
|
3742
|
-
const
|
|
3743
|
-
|
|
3744
|
-
upstreamInferenceCost:
|
|
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 =
|
|
3748
|
-
p?.finish_reason != null && (
|
|
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:
|
|
3870
|
+
id: W()
|
|
3752
3871
|
});
|
|
3753
3872
|
},
|
|
3754
3873
|
flush(u) {
|
|
3755
3874
|
u.enqueue({
|
|
3756
3875
|
type: "finish",
|
|
3757
|
-
finishReason:
|
|
3876
|
+
finishReason: i,
|
|
3758
3877
|
usage: c,
|
|
3759
3878
|
providerMetadata: {
|
|
3760
3879
|
openrouter: {
|
|
3761
|
-
usage:
|
|
3880
|
+
usage: l
|
|
3762
3881
|
}
|
|
3763
3882
|
}
|
|
3764
3883
|
});
|
|
@@ -3770,81 +3889,81 @@ var pt = D([
|
|
|
3770
3889
|
}
|
|
3771
3890
|
};
|
|
3772
3891
|
}
|
|
3773
|
-
},
|
|
3892
|
+
}, os = d({
|
|
3774
3893
|
prompt_tokens: k(),
|
|
3775
3894
|
total_tokens: k(),
|
|
3776
3895
|
cost: k().optional()
|
|
3777
|
-
}),
|
|
3778
|
-
object:
|
|
3779
|
-
embedding:
|
|
3896
|
+
}), ss = d({
|
|
3897
|
+
object: x("embedding"),
|
|
3898
|
+
embedding: y(k()),
|
|
3780
3899
|
index: k().optional()
|
|
3781
|
-
}),
|
|
3900
|
+
}), as = d({
|
|
3782
3901
|
id: s().optional(),
|
|
3783
|
-
object:
|
|
3784
|
-
data:
|
|
3902
|
+
object: x("list"),
|
|
3903
|
+
data: y(ss),
|
|
3785
3904
|
model: s(),
|
|
3786
|
-
usage:
|
|
3787
|
-
}),
|
|
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 =
|
|
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:
|
|
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:
|
|
3922
|
+
headers: me(this.config.headers(), o),
|
|
3804
3923
|
body: a,
|
|
3805
|
-
failedResponseHandler:
|
|
3806
|
-
successfulResponseHandler:
|
|
3807
|
-
|
|
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:
|
|
3814
|
-
usage:
|
|
3815
|
-
providerMetadata: (t =
|
|
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:
|
|
3937
|
+
cost: i.usage.cost
|
|
3819
3938
|
}
|
|
3820
3939
|
}
|
|
3821
3940
|
} : void 0,
|
|
3822
3941
|
response: {
|
|
3823
3942
|
headers: c,
|
|
3824
|
-
body:
|
|
3943
|
+
body: i
|
|
3825
3944
|
}
|
|
3826
3945
|
};
|
|
3827
3946
|
}
|
|
3828
3947
|
};
|
|
3829
|
-
function
|
|
3948
|
+
function ls(e) {
|
|
3830
3949
|
return Object.fromEntries(
|
|
3831
3950
|
Object.entries(e).filter(([, t]) => t !== null)
|
|
3832
3951
|
);
|
|
3833
3952
|
}
|
|
3834
|
-
function
|
|
3835
|
-
const n =
|
|
3953
|
+
function cs(e, ...t) {
|
|
3954
|
+
const n = ls(
|
|
3836
3955
|
e ?? {}
|
|
3837
3956
|
), o = [n["user-agent"] || "", ...t].filter(Boolean).join(" ");
|
|
3838
|
-
return
|
|
3957
|
+
return xe(P({}, n), {
|
|
3839
3958
|
"user-agent": o
|
|
3840
3959
|
});
|
|
3841
3960
|
}
|
|
3842
|
-
var
|
|
3961
|
+
var us = "1.5.4";
|
|
3843
3962
|
function Sn(e = {}) {
|
|
3844
3963
|
var t, n, r;
|
|
3845
|
-
const o = (n =
|
|
3846
|
-
|
|
3847
|
-
Authorization: `Bearer ${
|
|
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/${
|
|
3856
|
-
), c = (
|
|
3974
|
+
`ai-sdk/openrouter/${us}`
|
|
3975
|
+
), c = (f, v = {}) => new ts(f, v, {
|
|
3857
3976
|
provider: "openrouter.chat",
|
|
3858
|
-
url: ({ path:
|
|
3859
|
-
headers:
|
|
3977
|
+
url: ({ path: m }) => `${o}${m}`,
|
|
3978
|
+
headers: i,
|
|
3860
3979
|
compatibility: a,
|
|
3861
3980
|
fetch: e.fetch,
|
|
3862
3981
|
extraBody: e.extraBody
|
|
3863
|
-
}),
|
|
3982
|
+
}), l = (f, v = {}) => new rs(f, v, {
|
|
3864
3983
|
provider: "openrouter.completion",
|
|
3865
|
-
url: ({ path:
|
|
3866
|
-
headers:
|
|
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 = (
|
|
3989
|
+
}), u = (f, v = {}) => new is(f, v, {
|
|
3871
3990
|
provider: "openrouter.embedding",
|
|
3872
|
-
url: ({ path:
|
|
3873
|
-
headers:
|
|
3991
|
+
url: ({ path: m }) => `${o}${m}`,
|
|
3992
|
+
headers: i,
|
|
3874
3993
|
fetch: e.fetch,
|
|
3875
3994
|
extraBody: e.extraBody
|
|
3876
|
-
}), h = (
|
|
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
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
) : c(
|
|
3885
|
-
},
|
|
3886
|
-
return
|
|
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
|
|
3893
|
-
chat:
|
|
3894
|
-
}),
|
|
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:
|
|
3897
|
-
environment:
|
|
4015
|
+
mcp: j([s()]),
|
|
4016
|
+
environment: ze(s(), oe()).optional(),
|
|
3898
4017
|
projectSlug: s(),
|
|
3899
|
-
model:
|
|
3900
|
-
}),
|
|
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
|
|
3905
|
-
n.push(
|
|
3906
|
-
const r = Buffer.concat(n).toString(), { messages: o, config: a, system:
|
|
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:
|
|
4028
|
+
url: l.mcp,
|
|
3910
4029
|
headers: {
|
|
3911
|
-
...
|
|
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(),
|
|
3917
|
-
baseURL:
|
|
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":
|
|
4041
|
+
"Gram-Project": l.projectSlug,
|
|
3923
4042
|
"Gram-Key": process.env.GRAM_API_KEY ?? ""
|
|
3924
4043
|
}
|
|
3925
|
-
}),
|
|
3926
|
-
system:
|
|
3927
|
-
model:
|
|
3928
|
-
messages:
|
|
4044
|
+
}), f = In({
|
|
4045
|
+
system: i,
|
|
4046
|
+
model: g.chat(l.model),
|
|
4047
|
+
messages: Pn(o),
|
|
3929
4048
|
tools: {
|
|
3930
4049
|
...h,
|
|
3931
|
-
|
|
4050
|
+
...$n(c)
|
|
3932
4051
|
},
|
|
3933
|
-
stopWhen:
|
|
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,
|
|
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
|
-
},
|
|
3947
|
-
function
|
|
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(
|
|
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
|
-
|
|
4076
|
+
gs as createElementsServerHandlers
|
|
3958
4077
|
};
|