@mastra/ai-sdk 1.4.1 → 1.4.2-alpha.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/CHANGELOG.md +34 -0
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +425 -1757
- package/dist/_types/@internal_ai-v6/dist/index.d.ts +311 -1772
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +895 -440
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +895 -440
- package/dist/index.js.map +1 -1
- package/dist/ui.cjs +1 -0
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.js +1 -0
- package/dist/ui.js.map +1 -1
- package/package.json +14 -14
- package/dist/chunk-3YJ25IUJ.js +0 -79
- package/dist/chunk-3YJ25IUJ.js.map +0 -1
- package/dist/chunk-DGUM43GV.js +0 -10
- package/dist/chunk-DGUM43GV.js.map +0 -1
- package/dist/chunk-HDI4ZP7N.js +0 -79
- package/dist/chunk-HDI4ZP7N.js.map +0 -1
- package/dist/chunk-HMOX24BQ.js +0 -439
- package/dist/chunk-HMOX24BQ.js.map +0 -1
- package/dist/chunk-IV3RKEE4.js +0 -439
- package/dist/chunk-IV3RKEE4.js.map +0 -1
- package/dist/chunk-JEQ2X3Z6.cjs +0 -12
- package/dist/chunk-JEQ2X3Z6.cjs.map +0 -1
- package/dist/chunk-PEZAMDZJ.cjs +0 -84
- package/dist/chunk-PEZAMDZJ.cjs.map +0 -1
- package/dist/chunk-VJW66KXQ.cjs +0 -441
- package/dist/chunk-VJW66KXQ.cjs.map +0 -1
- package/dist/chunk-WFARZCDO.cjs +0 -84
- package/dist/chunk-WFARZCDO.cjs.map +0 -1
- package/dist/chunk-X72VW7EY.cjs +0 -441
- package/dist/chunk-X72VW7EY.cjs.map +0 -1
- package/dist/token-APYSY3BW-CBIBV5F2.js +0 -61
- package/dist/token-APYSY3BW-CBIBV5F2.js.map +0 -1
- package/dist/token-APYSY3BW-INR55PKP.js +0 -61
- package/dist/token-APYSY3BW-INR55PKP.js.map +0 -1
- package/dist/token-APYSY3BW-M2K6HVOG.cjs +0 -63
- package/dist/token-APYSY3BW-M2K6HVOG.cjs.map +0 -1
- package/dist/token-APYSY3BW-Y5VD4L7Z.cjs +0 -63
- package/dist/token-APYSY3BW-Y5VD4L7Z.cjs.map +0 -1
- package/dist/token-util-RMHT2CPJ-3LCBPXJ6.cjs +0 -10
- package/dist/token-util-RMHT2CPJ-3LCBPXJ6.cjs.map +0 -1
- package/dist/token-util-RMHT2CPJ-4YTBAZ23.cjs +0 -10
- package/dist/token-util-RMHT2CPJ-4YTBAZ23.cjs.map +0 -1
- package/dist/token-util-RMHT2CPJ-HCMQIDTV.js +0 -8
- package/dist/token-util-RMHT2CPJ-HCMQIDTV.js.map +0 -1
- package/dist/token-util-RMHT2CPJ-IOKQM5O3.js +0 -8
- package/dist/token-util-RMHT2CPJ-IOKQM5O3.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { __commonJS, require_token_error, __toESM } from './chunk-3YJ25IUJ.js';
|
|
2
|
-
import { __commonJS as __commonJS$1, require_token_error as require_token_error$1, __toESM as __toESM$1 } from './chunk-HDI4ZP7N.js';
|
|
3
1
|
import * as z4 from 'zod/v4';
|
|
4
2
|
import { z } from 'zod/v4';
|
|
5
3
|
import { ZodFirstPartyTypeKind } from 'zod/v3';
|
|
@@ -11,6 +9,7 @@ import { TripWire, MessageList, aiV5ModelMessageToV2PromptMessage } from '@mastr
|
|
|
11
9
|
import { RequestContext } from '@mastra/core/di';
|
|
12
10
|
import { WorkingMemory, MessageHistory, SemanticRecall } from '@mastra/core/processors';
|
|
13
11
|
|
|
12
|
+
// ../../packages/_vendored/ai_v5/dist/chunk-UDIOFQR2.js
|
|
14
13
|
var marker = "vercel.ai.error";
|
|
15
14
|
var symbol = Symbol.for(marker);
|
|
16
15
|
var _a;
|
|
@@ -189,6 +188,9 @@ var ParseError = class extends Error {
|
|
|
189
188
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
190
189
|
}
|
|
191
190
|
};
|
|
191
|
+
var LF = 10;
|
|
192
|
+
var CR = 13;
|
|
193
|
+
var SPACE = 32;
|
|
192
194
|
function noop(_arg) {
|
|
193
195
|
}
|
|
194
196
|
function createParser(callbacks) {
|
|
@@ -196,39 +198,109 @@ function createParser(callbacks) {
|
|
|
196
198
|
throw new TypeError(
|
|
197
199
|
"`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
|
|
198
200
|
);
|
|
199
|
-
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
|
|
200
|
-
let
|
|
201
|
-
function feed(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
201
|
+
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks, pendingFragments = [];
|
|
202
|
+
let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
|
|
203
|
+
function feed(chunk) {
|
|
204
|
+
if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
|
|
205
|
+
const trailing2 = processLines(chunk);
|
|
206
|
+
trailing2 !== "" && pendingFragments.push(trailing2);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (chunk.indexOf(`
|
|
210
|
+
`) === -1 && chunk.indexOf("\r") === -1) {
|
|
211
|
+
pendingFragments.push(chunk);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
pendingFragments.push(chunk);
|
|
215
|
+
const input = pendingFragments.join("");
|
|
216
|
+
pendingFragments.length = 0;
|
|
217
|
+
const trailing = processLines(input);
|
|
218
|
+
trailing !== "" && pendingFragments.push(trailing);
|
|
219
|
+
}
|
|
220
|
+
function processLines(chunk) {
|
|
221
|
+
let searchIndex = 0;
|
|
222
|
+
if (chunk.indexOf("\r") === -1) {
|
|
223
|
+
let lfIndex = chunk.indexOf(`
|
|
224
|
+
`, searchIndex);
|
|
225
|
+
for (; lfIndex !== -1; ) {
|
|
226
|
+
if (searchIndex === lfIndex) {
|
|
227
|
+
dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
228
|
+
`, searchIndex);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
232
|
+
if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
|
|
233
|
+
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
234
|
+
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
|
|
235
|
+
onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
236
|
+
`, searchIndex);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
data = dataLines === 0 ? value : `${data}
|
|
240
|
+
${value}`, dataLines++;
|
|
241
|
+
} else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
|
|
242
|
+
chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
|
|
243
|
+
lfIndex
|
|
244
|
+
) || void 0 : parseLine(chunk, searchIndex, lfIndex);
|
|
245
|
+
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
246
|
+
`, searchIndex);
|
|
247
|
+
}
|
|
248
|
+
return chunk.slice(searchIndex);
|
|
249
|
+
}
|
|
250
|
+
for (; searchIndex < chunk.length; ) {
|
|
251
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
252
|
+
`, searchIndex);
|
|
253
|
+
let lineEnd = -1;
|
|
254
|
+
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
|
|
255
|
+
break;
|
|
256
|
+
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
|
|
257
|
+
}
|
|
258
|
+
return chunk.slice(searchIndex);
|
|
259
|
+
}
|
|
260
|
+
function parseLine(chunk, start, end) {
|
|
261
|
+
if (start === end) {
|
|
209
262
|
dispatchEvent();
|
|
210
263
|
return;
|
|
211
264
|
}
|
|
212
|
-
|
|
213
|
-
|
|
265
|
+
const firstCharCode = chunk.charCodeAt(start);
|
|
266
|
+
if (isDataPrefix(chunk, start, firstCharCode)) {
|
|
267
|
+
const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
268
|
+
data = dataLines === 0 ? value2 : `${data}
|
|
269
|
+
${value2}`, dataLines++;
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (isEventPrefix(chunk, start, firstCharCode)) {
|
|
273
|
+
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
277
|
+
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
|
|
278
|
+
id = value2.includes("\0") ? void 0 : value2;
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (firstCharCode === 58) {
|
|
282
|
+
if (onComment) {
|
|
283
|
+
const line2 = chunk.slice(start, end);
|
|
284
|
+
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
|
|
285
|
+
}
|
|
214
286
|
return;
|
|
215
287
|
}
|
|
216
|
-
const fieldSeparatorIndex = line.indexOf(":");
|
|
217
|
-
if (fieldSeparatorIndex
|
|
218
|
-
|
|
219
|
-
processField(field, value, line);
|
|
288
|
+
const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
|
|
289
|
+
if (fieldSeparatorIndex === -1) {
|
|
290
|
+
processField(line, "", line);
|
|
220
291
|
return;
|
|
221
292
|
}
|
|
222
|
-
|
|
293
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
294
|
+
processField(field, value, line);
|
|
223
295
|
}
|
|
224
296
|
function processField(field, value, line) {
|
|
225
297
|
switch (field) {
|
|
226
298
|
case "event":
|
|
227
|
-
eventType = value;
|
|
299
|
+
eventType = value || void 0;
|
|
228
300
|
break;
|
|
229
301
|
case "data":
|
|
230
|
-
data = `${data}
|
|
231
|
-
|
|
302
|
+
data = dataLines === 0 ? value : `${data}
|
|
303
|
+
${value}`, dataLines++;
|
|
232
304
|
break;
|
|
233
305
|
case "id":
|
|
234
306
|
id = value.includes("\0") ? void 0 : value;
|
|
@@ -253,37 +325,26 @@ function createParser(callbacks) {
|
|
|
253
325
|
}
|
|
254
326
|
}
|
|
255
327
|
function dispatchEvent() {
|
|
256
|
-
|
|
328
|
+
dataLines > 0 && onEvent({
|
|
257
329
|
id,
|
|
258
|
-
event: eventType
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
data: data.endsWith(`
|
|
262
|
-
`) ? data.slice(0, -1) : data
|
|
263
|
-
}), id = void 0, data = "", eventType = "";
|
|
330
|
+
event: eventType,
|
|
331
|
+
data
|
|
332
|
+
}), id = void 0, data = "", dataLines = 0, eventType = void 0;
|
|
264
333
|
}
|
|
265
334
|
function reset(options = {}) {
|
|
266
|
-
|
|
335
|
+
if (options.consume && pendingFragments.length > 0) {
|
|
336
|
+
const incompleteLine = pendingFragments.join("");
|
|
337
|
+
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
338
|
+
}
|
|
339
|
+
isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
|
|
267
340
|
}
|
|
268
341
|
return { feed, reset };
|
|
269
342
|
}
|
|
270
|
-
function
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
`, searchIndex);
|
|
276
|
-
let lineEnd = -1;
|
|
277
|
-
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
278
|
-
incompleteLine = chunk.slice(searchIndex);
|
|
279
|
-
break;
|
|
280
|
-
} else {
|
|
281
|
-
const line = chunk.slice(searchIndex, lineEnd);
|
|
282
|
-
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
283
|
-
` && searchIndex++;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return [lines, incompleteLine];
|
|
343
|
+
function isDataPrefix(chunk, i, firstCharCode) {
|
|
344
|
+
return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
|
|
345
|
+
}
|
|
346
|
+
function isEventPrefix(chunk, i, firstCharCode) {
|
|
347
|
+
return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
|
|
287
348
|
}
|
|
288
349
|
var EventSourceParserStream = class extends TransformStream {
|
|
289
350
|
constructor({ onError, onRetry, onComment } = {}) {
|
|
@@ -431,7 +492,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
431
492
|
);
|
|
432
493
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
433
494
|
}
|
|
434
|
-
var VERSION = "3.0.
|
|
495
|
+
var VERSION = "3.0.25";
|
|
435
496
|
var getOriginalFetch = () => globalThis.fetch;
|
|
436
497
|
var getFromApi = async ({
|
|
437
498
|
url,
|
|
@@ -900,6 +961,33 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
900
961
|
rawValue: parsedResult.rawValue
|
|
901
962
|
};
|
|
902
963
|
};
|
|
964
|
+
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
965
|
+
function lazySchema(createSchema) {
|
|
966
|
+
let schema;
|
|
967
|
+
return () => {
|
|
968
|
+
if (schema == null) {
|
|
969
|
+
schema = createSchema();
|
|
970
|
+
}
|
|
971
|
+
return schema;
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
function jsonSchema(jsonSchema22, {
|
|
975
|
+
validate
|
|
976
|
+
} = {}) {
|
|
977
|
+
return {
|
|
978
|
+
[schemaSymbol]: true,
|
|
979
|
+
_type: void 0,
|
|
980
|
+
// should never be used directly
|
|
981
|
+
[validatorSymbol]: true,
|
|
982
|
+
get jsonSchema() {
|
|
983
|
+
if (typeof jsonSchema22 === "function") {
|
|
984
|
+
jsonSchema22 = jsonSchema22();
|
|
985
|
+
}
|
|
986
|
+
return jsonSchema22;
|
|
987
|
+
},
|
|
988
|
+
validate
|
|
989
|
+
};
|
|
990
|
+
}
|
|
903
991
|
function addAdditionalPropertiesToJsonSchema(jsonSchema22) {
|
|
904
992
|
if (jsonSchema22.type === "object") {
|
|
905
993
|
jsonSchema22.additionalProperties = false;
|
|
@@ -925,13 +1013,6 @@ function addAdditionalPropertiesToJsonSchema(jsonSchema22) {
|
|
|
925
1013
|
}
|
|
926
1014
|
return jsonSchema22;
|
|
927
1015
|
}
|
|
928
|
-
var getRelativePath = (pathA, pathB) => {
|
|
929
|
-
let i = 0;
|
|
930
|
-
for (; i < pathA.length && i < pathB.length; i++) {
|
|
931
|
-
if (pathA[i] !== pathB[i]) break;
|
|
932
|
-
}
|
|
933
|
-
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
934
|
-
};
|
|
935
1016
|
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
936
1017
|
"Let zodToJsonSchema decide on which parser to use"
|
|
937
1018
|
);
|
|
@@ -1875,6 +1956,13 @@ var selectParser = (def, typeName, refs) => {
|
|
|
1875
1956
|
return /* @__PURE__ */ ((_) => void 0)();
|
|
1876
1957
|
}
|
|
1877
1958
|
};
|
|
1959
|
+
var getRelativePath = (pathA, pathB) => {
|
|
1960
|
+
let i = 0;
|
|
1961
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
1962
|
+
if (pathA[i] !== pathB[i]) break;
|
|
1963
|
+
}
|
|
1964
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
1965
|
+
};
|
|
1878
1966
|
function parseDef(def, refs, forceResolution = false) {
|
|
1879
1967
|
var _a224;
|
|
1880
1968
|
const seenItem = refs.seen.get(def);
|
|
@@ -2054,33 +2142,6 @@ function zodSchema(zodSchema22, options) {
|
|
|
2054
2142
|
return zod3Schema(zodSchema22);
|
|
2055
2143
|
}
|
|
2056
2144
|
}
|
|
2057
|
-
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
2058
|
-
function lazySchema(createSchema) {
|
|
2059
|
-
let schema;
|
|
2060
|
-
return () => {
|
|
2061
|
-
if (schema == null) {
|
|
2062
|
-
schema = createSchema();
|
|
2063
|
-
}
|
|
2064
|
-
return schema;
|
|
2065
|
-
};
|
|
2066
|
-
}
|
|
2067
|
-
function jsonSchema(jsonSchema22, {
|
|
2068
|
-
validate
|
|
2069
|
-
} = {}) {
|
|
2070
|
-
return {
|
|
2071
|
-
[schemaSymbol]: true,
|
|
2072
|
-
_type: void 0,
|
|
2073
|
-
// should never be used directly
|
|
2074
|
-
[validatorSymbol]: true,
|
|
2075
|
-
get jsonSchema() {
|
|
2076
|
-
if (typeof jsonSchema22 === "function") {
|
|
2077
|
-
jsonSchema22 = jsonSchema22();
|
|
2078
|
-
}
|
|
2079
|
-
return jsonSchema22;
|
|
2080
|
-
},
|
|
2081
|
-
validate
|
|
2082
|
-
};
|
|
2083
|
-
}
|
|
2084
2145
|
function isSchema(value) {
|
|
2085
2146
|
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
|
2086
2147
|
}
|
|
@@ -2093,138 +2154,17 @@ function asSchema(schema) {
|
|
|
2093
2154
|
function withoutTrailingSlash(url) {
|
|
2094
2155
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
2095
2156
|
}
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
__defProp22(target, name163, { get: all[name163], enumerable: true });
|
|
2105
|
-
};
|
|
2106
|
-
var __copyProps = (to, from, except, desc) => {
|
|
2107
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
2108
|
-
for (let key of __getOwnPropNames(from))
|
|
2109
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
2110
|
-
__defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
2111
|
-
}
|
|
2112
|
-
return to;
|
|
2113
|
-
};
|
|
2114
|
-
var __toCommonJS = (mod) => __copyProps(__defProp22({}, "__esModule", { value: true }), mod);
|
|
2115
|
-
var get_context_exports = {};
|
|
2116
|
-
__export22(get_context_exports, {
|
|
2117
|
-
SYMBOL_FOR_REQ_CONTEXT: () => SYMBOL_FOR_REQ_CONTEXT,
|
|
2118
|
-
getContext: () => getContext3
|
|
2119
|
-
});
|
|
2120
|
-
module.exports = __toCommonJS(get_context_exports);
|
|
2121
|
-
var SYMBOL_FOR_REQ_CONTEXT = /* @__PURE__ */ Symbol.for("@vercel/request-context");
|
|
2122
|
-
function getContext3() {
|
|
2123
|
-
const fromSymbol = globalThis;
|
|
2124
|
-
return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
});
|
|
2128
|
-
var require_get_vercel_oidc_token = __commonJS({
|
|
2129
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
|
|
2130
|
-
var __defProp22 = Object.defineProperty;
|
|
2131
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
2132
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2133
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2134
|
-
var __export22 = (target, all) => {
|
|
2135
|
-
for (var name163 in all)
|
|
2136
|
-
__defProp22(target, name163, { get: all[name163], enumerable: true });
|
|
2137
|
-
};
|
|
2138
|
-
var __copyProps = (to, from, except, desc) => {
|
|
2139
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
2140
|
-
for (let key of __getOwnPropNames(from))
|
|
2141
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
2142
|
-
__defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
2143
|
-
}
|
|
2144
|
-
return to;
|
|
2145
|
-
};
|
|
2146
|
-
var __toCommonJS = (mod) => __copyProps(__defProp22({}, "__esModule", { value: true }), mod);
|
|
2147
|
-
var get_vercel_oidc_token_exports = {};
|
|
2148
|
-
__export22(get_vercel_oidc_token_exports, {
|
|
2149
|
-
getVercelOidcToken: () => getVercelOidcToken3,
|
|
2150
|
-
getVercelOidcTokenSync: () => getVercelOidcTokenSync2
|
|
2151
|
-
});
|
|
2152
|
-
module.exports = __toCommonJS(get_vercel_oidc_token_exports);
|
|
2153
|
-
var import_get_context = require_get_context();
|
|
2154
|
-
var import_token_error = require_token_error();
|
|
2155
|
-
async function getVercelOidcToken3() {
|
|
2156
|
-
let token = "";
|
|
2157
|
-
let err;
|
|
2158
|
-
try {
|
|
2159
|
-
token = getVercelOidcTokenSync2();
|
|
2160
|
-
} catch (error) {
|
|
2161
|
-
err = error;
|
|
2162
|
-
}
|
|
2163
|
-
try {
|
|
2164
|
-
const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
|
|
2165
|
-
await import('./token-util-RMHT2CPJ-HCMQIDTV.js'),
|
|
2166
|
-
await import('./token-APYSY3BW-INR55PKP.js')
|
|
2167
|
-
]);
|
|
2168
|
-
if (!token || isExpired(getTokenPayload(token))) {
|
|
2169
|
-
await refreshToken();
|
|
2170
|
-
token = getVercelOidcTokenSync2();
|
|
2171
|
-
}
|
|
2172
|
-
} catch (error) {
|
|
2173
|
-
let message = err instanceof Error ? err.message : "";
|
|
2174
|
-
if (error instanceof Error) {
|
|
2175
|
-
message = `${message}
|
|
2176
|
-
${error.message}`;
|
|
2177
|
-
}
|
|
2178
|
-
if (message) {
|
|
2179
|
-
throw new import_token_error.VercelOidcTokenError(message);
|
|
2180
|
-
}
|
|
2181
|
-
throw error;
|
|
2182
|
-
}
|
|
2183
|
-
return token;
|
|
2184
|
-
}
|
|
2185
|
-
function getVercelOidcTokenSync2() {
|
|
2186
|
-
const token = (0, import_get_context.getContext)().headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
|
|
2187
|
-
if (!token) {
|
|
2188
|
-
throw new Error(
|
|
2189
|
-
`The 'x-vercel-oidc-token' header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings?`
|
|
2190
|
-
);
|
|
2191
|
-
}
|
|
2192
|
-
return token;
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
});
|
|
2196
|
-
var require_dist = __commonJS({
|
|
2197
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
|
|
2198
|
-
var __defProp22 = Object.defineProperty;
|
|
2199
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
2200
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2201
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2202
|
-
var __export22 = (target, all) => {
|
|
2203
|
-
for (var name163 in all)
|
|
2204
|
-
__defProp22(target, name163, { get: all[name163], enumerable: true });
|
|
2205
|
-
};
|
|
2206
|
-
var __copyProps = (to, from, except, desc) => {
|
|
2207
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
2208
|
-
for (let key of __getOwnPropNames(from))
|
|
2209
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
2210
|
-
__defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
2211
|
-
}
|
|
2212
|
-
return to;
|
|
2213
|
-
};
|
|
2214
|
-
var __toCommonJS = (mod) => __copyProps(__defProp22({}, "__esModule", { value: true }), mod);
|
|
2215
|
-
var src_exports = {};
|
|
2216
|
-
__export22(src_exports, {
|
|
2217
|
-
getContext: () => import_get_context.getContext,
|
|
2218
|
-
getVercelOidcToken: () => import_get_vercel_oidc_token.getVercelOidcToken,
|
|
2219
|
-
getVercelOidcTokenSync: () => import_get_vercel_oidc_token.getVercelOidcTokenSync
|
|
2220
|
-
});
|
|
2221
|
-
module.exports = __toCommonJS(src_exports);
|
|
2222
|
-
var import_get_vercel_oidc_token = require_get_vercel_oidc_token();
|
|
2223
|
-
var import_get_context = require_get_context();
|
|
2157
|
+
function getContext() {
|
|
2158
|
+
return {
|
|
2159
|
+
headers: {}
|
|
2160
|
+
};
|
|
2161
|
+
}
|
|
2162
|
+
async function getVercelOidcToken() {
|
|
2163
|
+
if (process.env.VERCEL_OIDC_TOKEN) {
|
|
2164
|
+
return process.env.VERCEL_OIDC_TOKEN ?? "";
|
|
2224
2165
|
}
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
var import_oidc2 = __toESM(require_dist(), 1);
|
|
2166
|
+
throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
|
|
2167
|
+
}
|
|
2228
2168
|
var marker16 = "vercel.ai.gateway.error";
|
|
2229
2169
|
var symbol16 = Symbol.for(marker16);
|
|
2230
2170
|
var _a16;
|
|
@@ -2489,6 +2429,19 @@ var gatewayErrorResponseSchema = lazyValidator(
|
|
|
2489
2429
|
})
|
|
2490
2430
|
)
|
|
2491
2431
|
);
|
|
2432
|
+
function extractApiCallResponse(error) {
|
|
2433
|
+
if (error.data !== void 0) {
|
|
2434
|
+
return error.data;
|
|
2435
|
+
}
|
|
2436
|
+
if (error.responseBody != null) {
|
|
2437
|
+
try {
|
|
2438
|
+
return JSON.parse(error.responseBody);
|
|
2439
|
+
} catch (e) {
|
|
2440
|
+
return error.responseBody;
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
return {};
|
|
2444
|
+
}
|
|
2492
2445
|
var name72 = "GatewayTimeoutError";
|
|
2493
2446
|
var marker82 = `vercel.ai.gateway.error.${name72}`;
|
|
2494
2447
|
var symbol82 = Symbol.for(marker82);
|
|
@@ -2575,19 +2528,6 @@ async function asGatewayError(error, authMethod) {
|
|
|
2575
2528
|
authMethod
|
|
2576
2529
|
});
|
|
2577
2530
|
}
|
|
2578
|
-
function extractApiCallResponse(error) {
|
|
2579
|
-
if (error.data !== void 0) {
|
|
2580
|
-
return error.data;
|
|
2581
|
-
}
|
|
2582
|
-
if (error.responseBody != null) {
|
|
2583
|
-
try {
|
|
2584
|
-
return JSON.parse(error.responseBody);
|
|
2585
|
-
} catch (e) {
|
|
2586
|
-
return error.responseBody;
|
|
2587
|
-
}
|
|
2588
|
-
}
|
|
2589
|
-
return {};
|
|
2590
|
-
}
|
|
2591
2531
|
var GATEWAY_AUTH_METHOD_HEADER = "ai-gateway-auth-method";
|
|
2592
2532
|
async function parseAuthMethod(headers) {
|
|
2593
2533
|
const result = await safeValidateTypes({
|
|
@@ -2599,6 +2539,7 @@ async function parseAuthMethod(headers) {
|
|
|
2599
2539
|
var gatewayAuthMethodSchema = lazyValidator(
|
|
2600
2540
|
() => zodSchema(z.union([z.literal("api-key"), z.literal("oidc")]))
|
|
2601
2541
|
);
|
|
2542
|
+
var KNOWN_MODEL_TYPES = ["embedding", "image", "language"];
|
|
2602
2543
|
var GatewayFetchMetadata = class {
|
|
2603
2544
|
constructor(config) {
|
|
2604
2545
|
this.config = config;
|
|
@@ -2669,8 +2610,12 @@ var gatewayAvailableModelsResponseSchema = lazyValidator(
|
|
|
2669
2610
|
provider: z.string(),
|
|
2670
2611
|
modelId: z.string()
|
|
2671
2612
|
}),
|
|
2672
|
-
modelType: z.
|
|
2613
|
+
modelType: z.string().nullish()
|
|
2673
2614
|
})
|
|
2615
|
+
).transform(
|
|
2616
|
+
(models) => models.filter(
|
|
2617
|
+
(m) => m.modelType == null || KNOWN_MODEL_TYPES.includes(m.modelType)
|
|
2618
|
+
)
|
|
2674
2619
|
)
|
|
2675
2620
|
})
|
|
2676
2621
|
)
|
|
@@ -2686,6 +2631,187 @@ var gatewayCreditsResponseSchema = lazyValidator(
|
|
|
2686
2631
|
}))
|
|
2687
2632
|
)
|
|
2688
2633
|
);
|
|
2634
|
+
var GatewaySpendReport = class {
|
|
2635
|
+
constructor(config) {
|
|
2636
|
+
this.config = config;
|
|
2637
|
+
}
|
|
2638
|
+
async getSpendReport(params) {
|
|
2639
|
+
try {
|
|
2640
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
2641
|
+
const searchParams = new URLSearchParams();
|
|
2642
|
+
searchParams.set("start_date", params.startDate);
|
|
2643
|
+
searchParams.set("end_date", params.endDate);
|
|
2644
|
+
if (params.groupBy) {
|
|
2645
|
+
searchParams.set("group_by", params.groupBy);
|
|
2646
|
+
}
|
|
2647
|
+
if (params.datePart) {
|
|
2648
|
+
searchParams.set("date_part", params.datePart);
|
|
2649
|
+
}
|
|
2650
|
+
if (params.userId) {
|
|
2651
|
+
searchParams.set("user_id", params.userId);
|
|
2652
|
+
}
|
|
2653
|
+
if (params.model) {
|
|
2654
|
+
searchParams.set("model", params.model);
|
|
2655
|
+
}
|
|
2656
|
+
if (params.provider) {
|
|
2657
|
+
searchParams.set("provider", params.provider);
|
|
2658
|
+
}
|
|
2659
|
+
if (params.credentialType) {
|
|
2660
|
+
searchParams.set("credential_type", params.credentialType);
|
|
2661
|
+
}
|
|
2662
|
+
if (params.tags && params.tags.length > 0) {
|
|
2663
|
+
searchParams.set("tags", params.tags.join(","));
|
|
2664
|
+
}
|
|
2665
|
+
const { value } = await getFromApi({
|
|
2666
|
+
url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
|
|
2667
|
+
headers: await resolve(this.config.headers()),
|
|
2668
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
2669
|
+
gatewaySpendReportResponseSchema
|
|
2670
|
+
),
|
|
2671
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
2672
|
+
errorSchema: z.any(),
|
|
2673
|
+
errorToMessage: (data) => data
|
|
2674
|
+
}),
|
|
2675
|
+
fetch: this.config.fetch
|
|
2676
|
+
});
|
|
2677
|
+
return value;
|
|
2678
|
+
} catch (error) {
|
|
2679
|
+
throw await asGatewayError(error);
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
};
|
|
2683
|
+
var gatewaySpendReportResponseSchema = lazySchema(
|
|
2684
|
+
() => zodSchema(
|
|
2685
|
+
z.object({
|
|
2686
|
+
results: z.array(
|
|
2687
|
+
z.object({
|
|
2688
|
+
day: z.string().optional(),
|
|
2689
|
+
hour: z.string().optional(),
|
|
2690
|
+
user: z.string().optional(),
|
|
2691
|
+
model: z.string().optional(),
|
|
2692
|
+
tag: z.string().optional(),
|
|
2693
|
+
provider: z.string().optional(),
|
|
2694
|
+
credential_type: z.enum(["byok", "system"]).optional(),
|
|
2695
|
+
total_cost: z.number(),
|
|
2696
|
+
market_cost: z.number().optional(),
|
|
2697
|
+
input_tokens: z.number().optional(),
|
|
2698
|
+
output_tokens: z.number().optional(),
|
|
2699
|
+
cached_input_tokens: z.number().optional(),
|
|
2700
|
+
cache_creation_input_tokens: z.number().optional(),
|
|
2701
|
+
reasoning_tokens: z.number().optional(),
|
|
2702
|
+
request_count: z.number().optional()
|
|
2703
|
+
}).transform(
|
|
2704
|
+
({
|
|
2705
|
+
credential_type,
|
|
2706
|
+
total_cost,
|
|
2707
|
+
market_cost,
|
|
2708
|
+
input_tokens,
|
|
2709
|
+
output_tokens,
|
|
2710
|
+
cached_input_tokens,
|
|
2711
|
+
cache_creation_input_tokens,
|
|
2712
|
+
reasoning_tokens,
|
|
2713
|
+
request_count,
|
|
2714
|
+
...rest
|
|
2715
|
+
}) => ({
|
|
2716
|
+
...rest,
|
|
2717
|
+
...credential_type !== void 0 ? { credentialType: credential_type } : {},
|
|
2718
|
+
totalCost: total_cost,
|
|
2719
|
+
...market_cost !== void 0 ? { marketCost: market_cost } : {},
|
|
2720
|
+
...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
|
|
2721
|
+
...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
|
|
2722
|
+
...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
|
|
2723
|
+
...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
|
|
2724
|
+
...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
|
|
2725
|
+
...request_count !== void 0 ? { requestCount: request_count } : {}
|
|
2726
|
+
})
|
|
2727
|
+
)
|
|
2728
|
+
)
|
|
2729
|
+
})
|
|
2730
|
+
)
|
|
2731
|
+
);
|
|
2732
|
+
var GatewayGenerationInfoFetcher = class {
|
|
2733
|
+
constructor(config) {
|
|
2734
|
+
this.config = config;
|
|
2735
|
+
}
|
|
2736
|
+
async getGenerationInfo(params) {
|
|
2737
|
+
try {
|
|
2738
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
2739
|
+
const { value } = await getFromApi({
|
|
2740
|
+
url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
|
|
2741
|
+
headers: await resolve(this.config.headers()),
|
|
2742
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
2743
|
+
gatewayGenerationInfoResponseSchema
|
|
2744
|
+
),
|
|
2745
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
2746
|
+
errorSchema: z.any(),
|
|
2747
|
+
errorToMessage: (data) => data
|
|
2748
|
+
}),
|
|
2749
|
+
fetch: this.config.fetch
|
|
2750
|
+
});
|
|
2751
|
+
return value;
|
|
2752
|
+
} catch (error) {
|
|
2753
|
+
throw await asGatewayError(error);
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
};
|
|
2757
|
+
var gatewayGenerationInfoResponseSchema = lazySchema(
|
|
2758
|
+
() => zodSchema(
|
|
2759
|
+
z.object({
|
|
2760
|
+
data: z.object({
|
|
2761
|
+
id: z.string(),
|
|
2762
|
+
total_cost: z.number(),
|
|
2763
|
+
upstream_inference_cost: z.number(),
|
|
2764
|
+
usage: z.number(),
|
|
2765
|
+
created_at: z.string(),
|
|
2766
|
+
model: z.string(),
|
|
2767
|
+
is_byok: z.boolean(),
|
|
2768
|
+
provider_name: z.string(),
|
|
2769
|
+
streamed: z.boolean(),
|
|
2770
|
+
finish_reason: z.string(),
|
|
2771
|
+
latency: z.number(),
|
|
2772
|
+
generation_time: z.number(),
|
|
2773
|
+
native_tokens_prompt: z.number(),
|
|
2774
|
+
native_tokens_completion: z.number(),
|
|
2775
|
+
native_tokens_reasoning: z.number(),
|
|
2776
|
+
native_tokens_cached: z.number(),
|
|
2777
|
+
native_tokens_cache_creation: z.number(),
|
|
2778
|
+
billable_web_search_calls: z.number()
|
|
2779
|
+
}).transform(
|
|
2780
|
+
({
|
|
2781
|
+
total_cost,
|
|
2782
|
+
upstream_inference_cost,
|
|
2783
|
+
created_at,
|
|
2784
|
+
is_byok,
|
|
2785
|
+
provider_name,
|
|
2786
|
+
finish_reason,
|
|
2787
|
+
generation_time,
|
|
2788
|
+
native_tokens_prompt,
|
|
2789
|
+
native_tokens_completion,
|
|
2790
|
+
native_tokens_reasoning,
|
|
2791
|
+
native_tokens_cached,
|
|
2792
|
+
native_tokens_cache_creation,
|
|
2793
|
+
billable_web_search_calls,
|
|
2794
|
+
...rest
|
|
2795
|
+
}) => ({
|
|
2796
|
+
...rest,
|
|
2797
|
+
totalCost: total_cost,
|
|
2798
|
+
upstreamInferenceCost: upstream_inference_cost,
|
|
2799
|
+
createdAt: created_at,
|
|
2800
|
+
isByok: is_byok,
|
|
2801
|
+
providerName: provider_name,
|
|
2802
|
+
finishReason: finish_reason,
|
|
2803
|
+
generationTime: generation_time,
|
|
2804
|
+
promptTokens: native_tokens_prompt,
|
|
2805
|
+
completionTokens: native_tokens_completion,
|
|
2806
|
+
reasoningTokens: native_tokens_reasoning,
|
|
2807
|
+
cachedTokens: native_tokens_cached,
|
|
2808
|
+
cacheCreationTokens: native_tokens_cache_creation,
|
|
2809
|
+
billableWebSearchCalls: billable_web_search_calls
|
|
2810
|
+
})
|
|
2811
|
+
)
|
|
2812
|
+
}).transform(({ data }) => data)
|
|
2813
|
+
)
|
|
2814
|
+
);
|
|
2689
2815
|
var GatewayLanguageModel = class {
|
|
2690
2816
|
constructor(modelId, config) {
|
|
2691
2817
|
this.modelId = modelId;
|
|
@@ -3186,9 +3312,9 @@ var gatewayTools = {
|
|
|
3186
3312
|
};
|
|
3187
3313
|
async function getVercelRequestId() {
|
|
3188
3314
|
var _a932;
|
|
3189
|
-
return (_a932 =
|
|
3315
|
+
return (_a932 = getContext().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
3190
3316
|
}
|
|
3191
|
-
var VERSION2 = "2.0.
|
|
3317
|
+
var VERSION2 = "2.0.86";
|
|
3192
3318
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
3193
3319
|
function createGatewayProvider(options = {}) {
|
|
3194
3320
|
var _a932, _b93;
|
|
@@ -3286,6 +3412,30 @@ function createGatewayProvider(options = {}) {
|
|
|
3286
3412
|
);
|
|
3287
3413
|
});
|
|
3288
3414
|
};
|
|
3415
|
+
const getSpendReport = async (params) => {
|
|
3416
|
+
return new GatewaySpendReport({
|
|
3417
|
+
baseURL,
|
|
3418
|
+
headers: getHeaders,
|
|
3419
|
+
fetch: options.fetch
|
|
3420
|
+
}).getSpendReport(params).catch(async (error) => {
|
|
3421
|
+
throw await asGatewayError(
|
|
3422
|
+
error,
|
|
3423
|
+
await parseAuthMethod(await getHeaders())
|
|
3424
|
+
);
|
|
3425
|
+
});
|
|
3426
|
+
};
|
|
3427
|
+
const getGenerationInfo = async (params) => {
|
|
3428
|
+
return new GatewayGenerationInfoFetcher({
|
|
3429
|
+
baseURL,
|
|
3430
|
+
headers: getHeaders,
|
|
3431
|
+
fetch: options.fetch
|
|
3432
|
+
}).getGenerationInfo(params).catch(async (error) => {
|
|
3433
|
+
throw await asGatewayError(
|
|
3434
|
+
error,
|
|
3435
|
+
await parseAuthMethod(await getHeaders())
|
|
3436
|
+
);
|
|
3437
|
+
});
|
|
3438
|
+
};
|
|
3289
3439
|
const provider = function(modelId) {
|
|
3290
3440
|
if (new.target) {
|
|
3291
3441
|
throw new Error(
|
|
@@ -3296,6 +3446,8 @@ function createGatewayProvider(options = {}) {
|
|
|
3296
3446
|
};
|
|
3297
3447
|
provider.getAvailableModels = getAvailableModels;
|
|
3298
3448
|
provider.getCredits = getCredits;
|
|
3449
|
+
provider.getSpendReport = getSpendReport;
|
|
3450
|
+
provider.getGenerationInfo = getGenerationInfo;
|
|
3299
3451
|
provider.imageModel = (modelId) => {
|
|
3300
3452
|
return new GatewayImageModel(modelId, {
|
|
3301
3453
|
provider: "gateway",
|
|
@@ -3331,7 +3483,7 @@ async function getGatewayAuthToken(options) {
|
|
|
3331
3483
|
};
|
|
3332
3484
|
}
|
|
3333
3485
|
try {
|
|
3334
|
-
const oidcToken = await
|
|
3486
|
+
const oidcToken = await getVercelOidcToken();
|
|
3335
3487
|
return {
|
|
3336
3488
|
token: oidcToken,
|
|
3337
3489
|
authMethod: "oidc"
|
|
@@ -4288,6 +4440,9 @@ function mergeObjects(base, overrides) {
|
|
|
4288
4440
|
}
|
|
4289
4441
|
const result = { ...base };
|
|
4290
4442
|
for (const key in overrides) {
|
|
4443
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
4444
|
+
continue;
|
|
4445
|
+
}
|
|
4291
4446
|
if (Object.prototype.hasOwnProperty.call(overrides, key)) {
|
|
4292
4447
|
const overridesValue = overrides[key];
|
|
4293
4448
|
if (overridesValue === void 0)
|
|
@@ -5599,6 +5754,9 @@ var ParseError2 = class extends Error {
|
|
|
5599
5754
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
5600
5755
|
}
|
|
5601
5756
|
};
|
|
5757
|
+
var LF2 = 10;
|
|
5758
|
+
var CR2 = 13;
|
|
5759
|
+
var SPACE2 = 32;
|
|
5602
5760
|
function noop2(_arg) {
|
|
5603
5761
|
}
|
|
5604
5762
|
function createParser2(callbacks) {
|
|
@@ -5606,39 +5764,109 @@ function createParser2(callbacks) {
|
|
|
5606
5764
|
throw new TypeError(
|
|
5607
5765
|
"`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
|
|
5608
5766
|
);
|
|
5609
|
-
const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks;
|
|
5610
|
-
let
|
|
5611
|
-
function feed(
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5767
|
+
const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks, pendingFragments = [];
|
|
5768
|
+
let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
|
|
5769
|
+
function feed(chunk) {
|
|
5770
|
+
if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
|
|
5771
|
+
const trailing2 = processLines(chunk);
|
|
5772
|
+
trailing2 !== "" && pendingFragments.push(trailing2);
|
|
5773
|
+
return;
|
|
5774
|
+
}
|
|
5775
|
+
if (chunk.indexOf(`
|
|
5776
|
+
`) === -1 && chunk.indexOf("\r") === -1) {
|
|
5777
|
+
pendingFragments.push(chunk);
|
|
5778
|
+
return;
|
|
5779
|
+
}
|
|
5780
|
+
pendingFragments.push(chunk);
|
|
5781
|
+
const input = pendingFragments.join("");
|
|
5782
|
+
pendingFragments.length = 0;
|
|
5783
|
+
const trailing = processLines(input);
|
|
5784
|
+
trailing !== "" && pendingFragments.push(trailing);
|
|
5785
|
+
}
|
|
5786
|
+
function processLines(chunk) {
|
|
5787
|
+
let searchIndex = 0;
|
|
5788
|
+
if (chunk.indexOf("\r") === -1) {
|
|
5789
|
+
let lfIndex = chunk.indexOf(`
|
|
5790
|
+
`, searchIndex);
|
|
5791
|
+
for (; lfIndex !== -1; ) {
|
|
5792
|
+
if (searchIndex === lfIndex) {
|
|
5793
|
+
dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
5794
|
+
`, searchIndex);
|
|
5795
|
+
continue;
|
|
5796
|
+
}
|
|
5797
|
+
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
5798
|
+
if (isDataPrefix2(chunk, searchIndex, firstCharCode)) {
|
|
5799
|
+
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE2 ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
5800
|
+
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF2) {
|
|
5801
|
+
onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
5802
|
+
`, searchIndex);
|
|
5803
|
+
continue;
|
|
5804
|
+
}
|
|
5805
|
+
data = dataLines === 0 ? value : `${data}
|
|
5806
|
+
${value}`, dataLines++;
|
|
5807
|
+
} else isEventPrefix2(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
|
|
5808
|
+
chunk.charCodeAt(searchIndex + 6) === SPACE2 ? searchIndex + 7 : searchIndex + 6,
|
|
5809
|
+
lfIndex
|
|
5810
|
+
) || void 0 : parseLine(chunk, searchIndex, lfIndex);
|
|
5811
|
+
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
5812
|
+
`, searchIndex);
|
|
5813
|
+
}
|
|
5814
|
+
return chunk.slice(searchIndex);
|
|
5815
|
+
}
|
|
5816
|
+
for (; searchIndex < chunk.length; ) {
|
|
5817
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
5818
|
+
`, searchIndex);
|
|
5819
|
+
let lineEnd = -1;
|
|
5820
|
+
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
|
|
5821
|
+
break;
|
|
5822
|
+
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR2 && chunk.charCodeAt(searchIndex) === LF2 && searchIndex++;
|
|
5823
|
+
}
|
|
5824
|
+
return chunk.slice(searchIndex);
|
|
5825
|
+
}
|
|
5826
|
+
function parseLine(chunk, start, end) {
|
|
5827
|
+
if (start === end) {
|
|
5619
5828
|
dispatchEvent();
|
|
5620
5829
|
return;
|
|
5621
5830
|
}
|
|
5622
|
-
|
|
5623
|
-
|
|
5831
|
+
const firstCharCode = chunk.charCodeAt(start);
|
|
5832
|
+
if (isDataPrefix2(chunk, start, firstCharCode)) {
|
|
5833
|
+
const valueStart = chunk.charCodeAt(start + 5) === SPACE2 ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
5834
|
+
data = dataLines === 0 ? value2 : `${data}
|
|
5835
|
+
${value2}`, dataLines++;
|
|
5836
|
+
return;
|
|
5837
|
+
}
|
|
5838
|
+
if (isEventPrefix2(chunk, start, firstCharCode)) {
|
|
5839
|
+
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE2 ? start + 7 : start + 6, end) || void 0;
|
|
5840
|
+
return;
|
|
5841
|
+
}
|
|
5842
|
+
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
5843
|
+
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE2 ? start + 4 : start + 3, end);
|
|
5844
|
+
id = value2.includes("\0") ? void 0 : value2;
|
|
5845
|
+
return;
|
|
5846
|
+
}
|
|
5847
|
+
if (firstCharCode === 58) {
|
|
5848
|
+
if (onComment) {
|
|
5849
|
+
const line2 = chunk.slice(start, end);
|
|
5850
|
+
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE2 ? 2 : 1));
|
|
5851
|
+
}
|
|
5624
5852
|
return;
|
|
5625
5853
|
}
|
|
5626
|
-
const fieldSeparatorIndex = line.indexOf(":");
|
|
5627
|
-
if (fieldSeparatorIndex
|
|
5628
|
-
|
|
5629
|
-
processField(field, value, line);
|
|
5854
|
+
const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
|
|
5855
|
+
if (fieldSeparatorIndex === -1) {
|
|
5856
|
+
processField(line, "", line);
|
|
5630
5857
|
return;
|
|
5631
5858
|
}
|
|
5632
|
-
|
|
5859
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE2 ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
5860
|
+
processField(field, value, line);
|
|
5633
5861
|
}
|
|
5634
5862
|
function processField(field, value, line) {
|
|
5635
5863
|
switch (field) {
|
|
5636
5864
|
case "event":
|
|
5637
|
-
eventType = value;
|
|
5865
|
+
eventType = value || void 0;
|
|
5638
5866
|
break;
|
|
5639
5867
|
case "data":
|
|
5640
|
-
data = `${data}
|
|
5641
|
-
|
|
5868
|
+
data = dataLines === 0 ? value : `${data}
|
|
5869
|
+
${value}`, dataLines++;
|
|
5642
5870
|
break;
|
|
5643
5871
|
case "id":
|
|
5644
5872
|
id = value.includes("\0") ? void 0 : value;
|
|
@@ -5663,37 +5891,26 @@ function createParser2(callbacks) {
|
|
|
5663
5891
|
}
|
|
5664
5892
|
}
|
|
5665
5893
|
function dispatchEvent() {
|
|
5666
|
-
|
|
5894
|
+
dataLines > 0 && onEvent({
|
|
5667
5895
|
id,
|
|
5668
|
-
event: eventType
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
data: data.endsWith(`
|
|
5672
|
-
`) ? data.slice(0, -1) : data
|
|
5673
|
-
}), id = void 0, data = "", eventType = "";
|
|
5896
|
+
event: eventType,
|
|
5897
|
+
data
|
|
5898
|
+
}), id = void 0, data = "", dataLines = 0, eventType = void 0;
|
|
5674
5899
|
}
|
|
5675
5900
|
function reset(options = {}) {
|
|
5676
|
-
|
|
5901
|
+
if (options.consume && pendingFragments.length > 0) {
|
|
5902
|
+
const incompleteLine = pendingFragments.join("");
|
|
5903
|
+
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
5904
|
+
}
|
|
5905
|
+
isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
|
|
5677
5906
|
}
|
|
5678
5907
|
return { feed, reset };
|
|
5679
5908
|
}
|
|
5680
|
-
function
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
`, searchIndex);
|
|
5686
|
-
let lineEnd = -1;
|
|
5687
|
-
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
5688
|
-
incompleteLine = chunk.slice(searchIndex);
|
|
5689
|
-
break;
|
|
5690
|
-
} else {
|
|
5691
|
-
const line = chunk.slice(searchIndex, lineEnd);
|
|
5692
|
-
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
5693
|
-
` && searchIndex++;
|
|
5694
|
-
}
|
|
5695
|
-
}
|
|
5696
|
-
return [lines, incompleteLine];
|
|
5909
|
+
function isDataPrefix2(chunk, i, firstCharCode) {
|
|
5910
|
+
return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
|
|
5911
|
+
}
|
|
5912
|
+
function isEventPrefix2(chunk, i, firstCharCode) {
|
|
5913
|
+
return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
|
|
5697
5914
|
}
|
|
5698
5915
|
var EventSourceParserStream2 = class extends TransformStream {
|
|
5699
5916
|
constructor({ onError, onRetry, onComment } = {}) {
|
|
@@ -5877,7 +6094,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
5877
6094
|
);
|
|
5878
6095
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
5879
6096
|
}
|
|
5880
|
-
var VERSION4 = "4.0.
|
|
6097
|
+
var VERSION4 = "4.0.26";
|
|
5881
6098
|
var getOriginalFetch3 = () => globalThis.fetch;
|
|
5882
6099
|
var getFromApi2 = async ({
|
|
5883
6100
|
url,
|
|
@@ -7537,138 +7754,17 @@ var createJsonResponseHandler2 = (responseSchema) => async ({ response, url, req
|
|
|
7537
7754
|
function withoutTrailingSlash2(url) {
|
|
7538
7755
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
7539
7756
|
}
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
__defProp22(target, name21, { get: all[name21], enumerable: true });
|
|
7549
|
-
};
|
|
7550
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7551
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7552
|
-
for (let key of __getOwnPropNames(from))
|
|
7553
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
7554
|
-
__defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
7555
|
-
}
|
|
7556
|
-
return to;
|
|
7557
|
-
};
|
|
7558
|
-
var __toCommonJS = (mod) => __copyProps(__defProp22({}, "__esModule", { value: true }), mod);
|
|
7559
|
-
var get_context_exports = {};
|
|
7560
|
-
__export22(get_context_exports, {
|
|
7561
|
-
SYMBOL_FOR_REQ_CONTEXT: () => SYMBOL_FOR_REQ_CONTEXT,
|
|
7562
|
-
getContext: () => getContext3
|
|
7563
|
-
});
|
|
7564
|
-
module.exports = __toCommonJS(get_context_exports);
|
|
7565
|
-
var SYMBOL_FOR_REQ_CONTEXT = /* @__PURE__ */ Symbol.for("@vercel/request-context");
|
|
7566
|
-
function getContext3() {
|
|
7567
|
-
const fromSymbol = globalThis;
|
|
7568
|
-
return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
|
|
7569
|
-
}
|
|
7570
|
-
}
|
|
7571
|
-
});
|
|
7572
|
-
var require_get_vercel_oidc_token2 = __commonJS$1({
|
|
7573
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
|
|
7574
|
-
var __defProp22 = Object.defineProperty;
|
|
7575
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7576
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7577
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7578
|
-
var __export22 = (target, all) => {
|
|
7579
|
-
for (var name21 in all)
|
|
7580
|
-
__defProp22(target, name21, { get: all[name21], enumerable: true });
|
|
7581
|
-
};
|
|
7582
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7583
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7584
|
-
for (let key of __getOwnPropNames(from))
|
|
7585
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
7586
|
-
__defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
7587
|
-
}
|
|
7588
|
-
return to;
|
|
7589
|
-
};
|
|
7590
|
-
var __toCommonJS = (mod) => __copyProps(__defProp22({}, "__esModule", { value: true }), mod);
|
|
7591
|
-
var get_vercel_oidc_token_exports = {};
|
|
7592
|
-
__export22(get_vercel_oidc_token_exports, {
|
|
7593
|
-
getVercelOidcToken: () => getVercelOidcToken3,
|
|
7594
|
-
getVercelOidcTokenSync: () => getVercelOidcTokenSync2
|
|
7595
|
-
});
|
|
7596
|
-
module.exports = __toCommonJS(get_vercel_oidc_token_exports);
|
|
7597
|
-
var import_get_context = require_get_context2();
|
|
7598
|
-
var import_token_error = require_token_error$1();
|
|
7599
|
-
async function getVercelOidcToken3() {
|
|
7600
|
-
let token = "";
|
|
7601
|
-
let err;
|
|
7602
|
-
try {
|
|
7603
|
-
token = getVercelOidcTokenSync2();
|
|
7604
|
-
} catch (error) {
|
|
7605
|
-
err = error;
|
|
7606
|
-
}
|
|
7607
|
-
try {
|
|
7608
|
-
const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
|
|
7609
|
-
await import('./token-util-RMHT2CPJ-IOKQM5O3.js'),
|
|
7610
|
-
await import('./token-APYSY3BW-CBIBV5F2.js')
|
|
7611
|
-
]);
|
|
7612
|
-
if (!token || isExpired(getTokenPayload(token))) {
|
|
7613
|
-
await refreshToken();
|
|
7614
|
-
token = getVercelOidcTokenSync2();
|
|
7615
|
-
}
|
|
7616
|
-
} catch (error) {
|
|
7617
|
-
let message = err instanceof Error ? err.message : "";
|
|
7618
|
-
if (error instanceof Error) {
|
|
7619
|
-
message = `${message}
|
|
7620
|
-
${error.message}`;
|
|
7621
|
-
}
|
|
7622
|
-
if (message) {
|
|
7623
|
-
throw new import_token_error.VercelOidcTokenError(message);
|
|
7624
|
-
}
|
|
7625
|
-
throw error;
|
|
7626
|
-
}
|
|
7627
|
-
return token;
|
|
7628
|
-
}
|
|
7629
|
-
function getVercelOidcTokenSync2() {
|
|
7630
|
-
const token = (0, import_get_context.getContext)().headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
|
|
7631
|
-
if (!token) {
|
|
7632
|
-
throw new Error(
|
|
7633
|
-
`The 'x-vercel-oidc-token' header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings?`
|
|
7634
|
-
);
|
|
7635
|
-
}
|
|
7636
|
-
return token;
|
|
7637
|
-
}
|
|
7638
|
-
}
|
|
7639
|
-
});
|
|
7640
|
-
var require_dist2 = __commonJS$1({
|
|
7641
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
|
|
7642
|
-
var __defProp22 = Object.defineProperty;
|
|
7643
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7644
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7645
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7646
|
-
var __export22 = (target, all) => {
|
|
7647
|
-
for (var name21 in all)
|
|
7648
|
-
__defProp22(target, name21, { get: all[name21], enumerable: true });
|
|
7649
|
-
};
|
|
7650
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7651
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7652
|
-
for (let key of __getOwnPropNames(from))
|
|
7653
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
7654
|
-
__defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
7655
|
-
}
|
|
7656
|
-
return to;
|
|
7657
|
-
};
|
|
7658
|
-
var __toCommonJS = (mod) => __copyProps(__defProp22({}, "__esModule", { value: true }), mod);
|
|
7659
|
-
var src_exports = {};
|
|
7660
|
-
__export22(src_exports, {
|
|
7661
|
-
getContext: () => import_get_context.getContext,
|
|
7662
|
-
getVercelOidcToken: () => import_get_vercel_oidc_token.getVercelOidcToken,
|
|
7663
|
-
getVercelOidcTokenSync: () => import_get_vercel_oidc_token.getVercelOidcTokenSync
|
|
7664
|
-
});
|
|
7665
|
-
module.exports = __toCommonJS(src_exports);
|
|
7666
|
-
var import_get_vercel_oidc_token = require_get_vercel_oidc_token2();
|
|
7667
|
-
var import_get_context = require_get_context2();
|
|
7757
|
+
function getContext2() {
|
|
7758
|
+
return {
|
|
7759
|
+
headers: {}
|
|
7760
|
+
};
|
|
7761
|
+
}
|
|
7762
|
+
async function getVercelOidcToken2() {
|
|
7763
|
+
if (process.env.VERCEL_OIDC_TOKEN) {
|
|
7764
|
+
return process.env.VERCEL_OIDC_TOKEN ?? "";
|
|
7668
7765
|
}
|
|
7669
|
-
|
|
7670
|
-
|
|
7671
|
-
var import_oidc22 = __toESM$1(require_dist2(), 1);
|
|
7766
|
+
throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
|
|
7767
|
+
}
|
|
7672
7768
|
var marker18 = "vercel.ai.gateway.error";
|
|
7673
7769
|
var symbol18 = Symbol.for(marker18);
|
|
7674
7770
|
var _a18;
|
|
@@ -7970,6 +8066,19 @@ var gatewayErrorResponseSchema2 = lazySchema2(
|
|
|
7970
8066
|
})
|
|
7971
8067
|
)
|
|
7972
8068
|
);
|
|
8069
|
+
function extractApiCallResponse2(error) {
|
|
8070
|
+
if (error.data !== void 0) {
|
|
8071
|
+
return error.data;
|
|
8072
|
+
}
|
|
8073
|
+
if (error.responseBody != null) {
|
|
8074
|
+
try {
|
|
8075
|
+
return JSON.parse(error.responseBody);
|
|
8076
|
+
} catch (e) {
|
|
8077
|
+
return error.responseBody;
|
|
8078
|
+
}
|
|
8079
|
+
}
|
|
8080
|
+
return {};
|
|
8081
|
+
}
|
|
7973
8082
|
var name74 = "GatewayTimeoutError";
|
|
7974
8083
|
var marker84 = `vercel.ai.gateway.error.${name74}`;
|
|
7975
8084
|
var symbol84 = Symbol.for(marker84);
|
|
@@ -8059,19 +8168,6 @@ async function asGatewayError2(error, authMethod) {
|
|
|
8059
8168
|
authMethod
|
|
8060
8169
|
});
|
|
8061
8170
|
}
|
|
8062
|
-
function extractApiCallResponse2(error) {
|
|
8063
|
-
if (error.data !== void 0) {
|
|
8064
|
-
return error.data;
|
|
8065
|
-
}
|
|
8066
|
-
if (error.responseBody != null) {
|
|
8067
|
-
try {
|
|
8068
|
-
return JSON.parse(error.responseBody);
|
|
8069
|
-
} catch (e) {
|
|
8070
|
-
return error.responseBody;
|
|
8071
|
-
}
|
|
8072
|
-
}
|
|
8073
|
-
return {};
|
|
8074
|
-
}
|
|
8075
8171
|
var GATEWAY_AUTH_METHOD_HEADER2 = "ai-gateway-auth-method";
|
|
8076
8172
|
async function parseAuthMethod2(headers) {
|
|
8077
8173
|
const result = await safeValidateTypes2({
|
|
@@ -8083,6 +8179,13 @@ async function parseAuthMethod2(headers) {
|
|
|
8083
8179
|
var gatewayAuthMethodSchema2 = lazySchema2(
|
|
8084
8180
|
() => zodSchema2(z.union([z.literal("api-key"), z.literal("oidc")]))
|
|
8085
8181
|
);
|
|
8182
|
+
var KNOWN_MODEL_TYPES2 = [
|
|
8183
|
+
"embedding",
|
|
8184
|
+
"image",
|
|
8185
|
+
"language",
|
|
8186
|
+
"reranking",
|
|
8187
|
+
"video"
|
|
8188
|
+
];
|
|
8086
8189
|
var GatewayFetchMetadata2 = class {
|
|
8087
8190
|
constructor(config) {
|
|
8088
8191
|
this.config = config;
|
|
@@ -8153,8 +8256,12 @@ var gatewayAvailableModelsResponseSchema2 = lazySchema2(
|
|
|
8153
8256
|
provider: z.string(),
|
|
8154
8257
|
modelId: z.string()
|
|
8155
8258
|
}),
|
|
8156
|
-
modelType: z.
|
|
8259
|
+
modelType: z.string().nullish()
|
|
8157
8260
|
})
|
|
8261
|
+
).transform(
|
|
8262
|
+
(models) => models.filter(
|
|
8263
|
+
(m) => m.modelType == null || KNOWN_MODEL_TYPES2.includes(m.modelType)
|
|
8264
|
+
)
|
|
8158
8265
|
)
|
|
8159
8266
|
})
|
|
8160
8267
|
)
|
|
@@ -8170,6 +8277,187 @@ var gatewayCreditsResponseSchema2 = lazySchema2(
|
|
|
8170
8277
|
}))
|
|
8171
8278
|
)
|
|
8172
8279
|
);
|
|
8280
|
+
var GatewaySpendReport2 = class {
|
|
8281
|
+
constructor(config) {
|
|
8282
|
+
this.config = config;
|
|
8283
|
+
}
|
|
8284
|
+
async getSpendReport(params) {
|
|
8285
|
+
try {
|
|
8286
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
8287
|
+
const searchParams = new URLSearchParams();
|
|
8288
|
+
searchParams.set("start_date", params.startDate);
|
|
8289
|
+
searchParams.set("end_date", params.endDate);
|
|
8290
|
+
if (params.groupBy) {
|
|
8291
|
+
searchParams.set("group_by", params.groupBy);
|
|
8292
|
+
}
|
|
8293
|
+
if (params.datePart) {
|
|
8294
|
+
searchParams.set("date_part", params.datePart);
|
|
8295
|
+
}
|
|
8296
|
+
if (params.userId) {
|
|
8297
|
+
searchParams.set("user_id", params.userId);
|
|
8298
|
+
}
|
|
8299
|
+
if (params.model) {
|
|
8300
|
+
searchParams.set("model", params.model);
|
|
8301
|
+
}
|
|
8302
|
+
if (params.provider) {
|
|
8303
|
+
searchParams.set("provider", params.provider);
|
|
8304
|
+
}
|
|
8305
|
+
if (params.credentialType) {
|
|
8306
|
+
searchParams.set("credential_type", params.credentialType);
|
|
8307
|
+
}
|
|
8308
|
+
if (params.tags && params.tags.length > 0) {
|
|
8309
|
+
searchParams.set("tags", params.tags.join(","));
|
|
8310
|
+
}
|
|
8311
|
+
const { value } = await getFromApi2({
|
|
8312
|
+
url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
|
|
8313
|
+
headers: await resolve2(this.config.headers()),
|
|
8314
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
8315
|
+
gatewaySpendReportResponseSchema2
|
|
8316
|
+
),
|
|
8317
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
8318
|
+
errorSchema: z.any(),
|
|
8319
|
+
errorToMessage: (data) => data
|
|
8320
|
+
}),
|
|
8321
|
+
fetch: this.config.fetch
|
|
8322
|
+
});
|
|
8323
|
+
return value;
|
|
8324
|
+
} catch (error) {
|
|
8325
|
+
throw await asGatewayError2(error);
|
|
8326
|
+
}
|
|
8327
|
+
}
|
|
8328
|
+
};
|
|
8329
|
+
var gatewaySpendReportResponseSchema2 = lazySchema2(
|
|
8330
|
+
() => zodSchema2(
|
|
8331
|
+
z.object({
|
|
8332
|
+
results: z.array(
|
|
8333
|
+
z.object({
|
|
8334
|
+
day: z.string().optional(),
|
|
8335
|
+
hour: z.string().optional(),
|
|
8336
|
+
user: z.string().optional(),
|
|
8337
|
+
model: z.string().optional(),
|
|
8338
|
+
tag: z.string().optional(),
|
|
8339
|
+
provider: z.string().optional(),
|
|
8340
|
+
credential_type: z.enum(["byok", "system"]).optional(),
|
|
8341
|
+
total_cost: z.number(),
|
|
8342
|
+
market_cost: z.number().optional(),
|
|
8343
|
+
input_tokens: z.number().optional(),
|
|
8344
|
+
output_tokens: z.number().optional(),
|
|
8345
|
+
cached_input_tokens: z.number().optional(),
|
|
8346
|
+
cache_creation_input_tokens: z.number().optional(),
|
|
8347
|
+
reasoning_tokens: z.number().optional(),
|
|
8348
|
+
request_count: z.number().optional()
|
|
8349
|
+
}).transform(
|
|
8350
|
+
({
|
|
8351
|
+
credential_type,
|
|
8352
|
+
total_cost,
|
|
8353
|
+
market_cost,
|
|
8354
|
+
input_tokens,
|
|
8355
|
+
output_tokens,
|
|
8356
|
+
cached_input_tokens,
|
|
8357
|
+
cache_creation_input_tokens,
|
|
8358
|
+
reasoning_tokens,
|
|
8359
|
+
request_count,
|
|
8360
|
+
...rest
|
|
8361
|
+
}) => ({
|
|
8362
|
+
...rest,
|
|
8363
|
+
...credential_type !== void 0 ? { credentialType: credential_type } : {},
|
|
8364
|
+
totalCost: total_cost,
|
|
8365
|
+
...market_cost !== void 0 ? { marketCost: market_cost } : {},
|
|
8366
|
+
...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
|
|
8367
|
+
...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
|
|
8368
|
+
...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
|
|
8369
|
+
...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
|
|
8370
|
+
...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
|
|
8371
|
+
...request_count !== void 0 ? { requestCount: request_count } : {}
|
|
8372
|
+
})
|
|
8373
|
+
)
|
|
8374
|
+
)
|
|
8375
|
+
})
|
|
8376
|
+
)
|
|
8377
|
+
);
|
|
8378
|
+
var GatewayGenerationInfoFetcher2 = class {
|
|
8379
|
+
constructor(config) {
|
|
8380
|
+
this.config = config;
|
|
8381
|
+
}
|
|
8382
|
+
async getGenerationInfo(params) {
|
|
8383
|
+
try {
|
|
8384
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
8385
|
+
const { value } = await getFromApi2({
|
|
8386
|
+
url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
|
|
8387
|
+
headers: await resolve2(this.config.headers()),
|
|
8388
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
8389
|
+
gatewayGenerationInfoResponseSchema2
|
|
8390
|
+
),
|
|
8391
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
8392
|
+
errorSchema: z.any(),
|
|
8393
|
+
errorToMessage: (data) => data
|
|
8394
|
+
}),
|
|
8395
|
+
fetch: this.config.fetch
|
|
8396
|
+
});
|
|
8397
|
+
return value;
|
|
8398
|
+
} catch (error) {
|
|
8399
|
+
throw await asGatewayError2(error);
|
|
8400
|
+
}
|
|
8401
|
+
}
|
|
8402
|
+
};
|
|
8403
|
+
var gatewayGenerationInfoResponseSchema2 = lazySchema2(
|
|
8404
|
+
() => zodSchema2(
|
|
8405
|
+
z.object({
|
|
8406
|
+
data: z.object({
|
|
8407
|
+
id: z.string(),
|
|
8408
|
+
total_cost: z.number(),
|
|
8409
|
+
upstream_inference_cost: z.number(),
|
|
8410
|
+
usage: z.number(),
|
|
8411
|
+
created_at: z.string(),
|
|
8412
|
+
model: z.string(),
|
|
8413
|
+
is_byok: z.boolean(),
|
|
8414
|
+
provider_name: z.string(),
|
|
8415
|
+
streamed: z.boolean(),
|
|
8416
|
+
finish_reason: z.string(),
|
|
8417
|
+
latency: z.number(),
|
|
8418
|
+
generation_time: z.number(),
|
|
8419
|
+
native_tokens_prompt: z.number(),
|
|
8420
|
+
native_tokens_completion: z.number(),
|
|
8421
|
+
native_tokens_reasoning: z.number(),
|
|
8422
|
+
native_tokens_cached: z.number(),
|
|
8423
|
+
native_tokens_cache_creation: z.number(),
|
|
8424
|
+
billable_web_search_calls: z.number()
|
|
8425
|
+
}).transform(
|
|
8426
|
+
({
|
|
8427
|
+
total_cost,
|
|
8428
|
+
upstream_inference_cost,
|
|
8429
|
+
created_at,
|
|
8430
|
+
is_byok,
|
|
8431
|
+
provider_name,
|
|
8432
|
+
finish_reason,
|
|
8433
|
+
generation_time,
|
|
8434
|
+
native_tokens_prompt,
|
|
8435
|
+
native_tokens_completion,
|
|
8436
|
+
native_tokens_reasoning,
|
|
8437
|
+
native_tokens_cached,
|
|
8438
|
+
native_tokens_cache_creation,
|
|
8439
|
+
billable_web_search_calls,
|
|
8440
|
+
...rest
|
|
8441
|
+
}) => ({
|
|
8442
|
+
...rest,
|
|
8443
|
+
totalCost: total_cost,
|
|
8444
|
+
upstreamInferenceCost: upstream_inference_cost,
|
|
8445
|
+
createdAt: created_at,
|
|
8446
|
+
isByok: is_byok,
|
|
8447
|
+
providerName: provider_name,
|
|
8448
|
+
finishReason: finish_reason,
|
|
8449
|
+
generationTime: generation_time,
|
|
8450
|
+
promptTokens: native_tokens_prompt,
|
|
8451
|
+
completionTokens: native_tokens_completion,
|
|
8452
|
+
reasoningTokens: native_tokens_reasoning,
|
|
8453
|
+
cachedTokens: native_tokens_cached,
|
|
8454
|
+
cacheCreationTokens: native_tokens_cache_creation,
|
|
8455
|
+
billableWebSearchCalls: billable_web_search_calls
|
|
8456
|
+
})
|
|
8457
|
+
)
|
|
8458
|
+
}).transform(({ data }) => data)
|
|
8459
|
+
)
|
|
8460
|
+
);
|
|
8173
8461
|
var GatewayLanguageModel2 = class {
|
|
8174
8462
|
constructor(modelId, config) {
|
|
8175
8463
|
this.modelId = modelId;
|
|
@@ -8717,6 +9005,86 @@ var gatewayVideoEventSchema = z.discriminatedUnion("type", [
|
|
|
8717
9005
|
param: z.unknown().nullable()
|
|
8718
9006
|
})
|
|
8719
9007
|
]);
|
|
9008
|
+
var GatewayRerankingModel = class {
|
|
9009
|
+
constructor(modelId, config) {
|
|
9010
|
+
this.modelId = modelId;
|
|
9011
|
+
this.config = config;
|
|
9012
|
+
this.specificationVersion = "v3";
|
|
9013
|
+
}
|
|
9014
|
+
get provider() {
|
|
9015
|
+
return this.config.provider;
|
|
9016
|
+
}
|
|
9017
|
+
async doRerank({
|
|
9018
|
+
documents,
|
|
9019
|
+
query,
|
|
9020
|
+
topN,
|
|
9021
|
+
headers,
|
|
9022
|
+
abortSignal,
|
|
9023
|
+
providerOptions
|
|
9024
|
+
}) {
|
|
9025
|
+
const resolvedHeaders = await resolve2(this.config.headers());
|
|
9026
|
+
try {
|
|
9027
|
+
const {
|
|
9028
|
+
responseHeaders,
|
|
9029
|
+
value: responseBody,
|
|
9030
|
+
rawValue
|
|
9031
|
+
} = await postJsonToApi2({
|
|
9032
|
+
url: this.getUrl(),
|
|
9033
|
+
headers: combineHeaders2(
|
|
9034
|
+
resolvedHeaders,
|
|
9035
|
+
headers != null ? headers : {},
|
|
9036
|
+
this.getModelConfigHeaders(),
|
|
9037
|
+
await resolve2(this.config.o11yHeaders)
|
|
9038
|
+
),
|
|
9039
|
+
body: {
|
|
9040
|
+
documents,
|
|
9041
|
+
query,
|
|
9042
|
+
...topN != null ? { topN } : {},
|
|
9043
|
+
...providerOptions ? { providerOptions } : {}
|
|
9044
|
+
},
|
|
9045
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
9046
|
+
gatewayRerankingResponseSchema
|
|
9047
|
+
),
|
|
9048
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
9049
|
+
errorSchema: z.any(),
|
|
9050
|
+
errorToMessage: (data) => data
|
|
9051
|
+
}),
|
|
9052
|
+
...abortSignal && { abortSignal },
|
|
9053
|
+
fetch: this.config.fetch
|
|
9054
|
+
});
|
|
9055
|
+
return {
|
|
9056
|
+
ranking: responseBody.ranking,
|
|
9057
|
+
providerMetadata: responseBody.providerMetadata,
|
|
9058
|
+
response: { headers: responseHeaders, body: rawValue },
|
|
9059
|
+
warnings: []
|
|
9060
|
+
};
|
|
9061
|
+
} catch (error) {
|
|
9062
|
+
throw await asGatewayError2(error, await parseAuthMethod2(resolvedHeaders));
|
|
9063
|
+
}
|
|
9064
|
+
}
|
|
9065
|
+
getUrl() {
|
|
9066
|
+
return `${this.config.baseURL}/reranking-model`;
|
|
9067
|
+
}
|
|
9068
|
+
getModelConfigHeaders() {
|
|
9069
|
+
return {
|
|
9070
|
+
"ai-reranking-model-specification-version": "3",
|
|
9071
|
+
"ai-model-id": this.modelId
|
|
9072
|
+
};
|
|
9073
|
+
}
|
|
9074
|
+
};
|
|
9075
|
+
var gatewayRerankingResponseSchema = lazySchema2(
|
|
9076
|
+
() => zodSchema2(
|
|
9077
|
+
z.object({
|
|
9078
|
+
ranking: z.array(
|
|
9079
|
+
z.object({
|
|
9080
|
+
index: z.number(),
|
|
9081
|
+
relevanceScore: z.number()
|
|
9082
|
+
})
|
|
9083
|
+
),
|
|
9084
|
+
providerMetadata: z.record(z.string(), z.record(z.string(), z.unknown())).optional()
|
|
9085
|
+
})
|
|
9086
|
+
)
|
|
9087
|
+
);
|
|
8720
9088
|
var parallelSearchInputSchema2 = lazySchema2(
|
|
8721
9089
|
() => zodSchema2(
|
|
8722
9090
|
z$1.object({
|
|
@@ -8891,9 +9259,9 @@ var gatewayTools2 = {
|
|
|
8891
9259
|
};
|
|
8892
9260
|
async function getVercelRequestId2() {
|
|
8893
9261
|
var _a932;
|
|
8894
|
-
return (_a932 = (
|
|
9262
|
+
return (_a932 = getContext2().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
8895
9263
|
}
|
|
8896
|
-
var VERSION5 = "3.0.
|
|
9264
|
+
var VERSION5 = "3.0.110";
|
|
8897
9265
|
var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
|
|
8898
9266
|
function createGatewayProvider2(options = {}) {
|
|
8899
9267
|
var _a932, _b93;
|
|
@@ -8993,6 +9361,30 @@ function createGatewayProvider2(options = {}) {
|
|
|
8993
9361
|
);
|
|
8994
9362
|
});
|
|
8995
9363
|
};
|
|
9364
|
+
const getSpendReport = async (params) => {
|
|
9365
|
+
return new GatewaySpendReport2({
|
|
9366
|
+
baseURL,
|
|
9367
|
+
headers: getHeaders,
|
|
9368
|
+
fetch: options.fetch
|
|
9369
|
+
}).getSpendReport(params).catch(async (error) => {
|
|
9370
|
+
throw await asGatewayError2(
|
|
9371
|
+
error,
|
|
9372
|
+
await parseAuthMethod2(await getHeaders())
|
|
9373
|
+
);
|
|
9374
|
+
});
|
|
9375
|
+
};
|
|
9376
|
+
const getGenerationInfo = async (params) => {
|
|
9377
|
+
return new GatewayGenerationInfoFetcher2({
|
|
9378
|
+
baseURL,
|
|
9379
|
+
headers: getHeaders,
|
|
9380
|
+
fetch: options.fetch
|
|
9381
|
+
}).getGenerationInfo(params).catch(async (error) => {
|
|
9382
|
+
throw await asGatewayError2(
|
|
9383
|
+
error,
|
|
9384
|
+
await parseAuthMethod2(await getHeaders())
|
|
9385
|
+
);
|
|
9386
|
+
});
|
|
9387
|
+
};
|
|
8996
9388
|
const provider = function(modelId) {
|
|
8997
9389
|
if (new.target) {
|
|
8998
9390
|
throw new Error(
|
|
@@ -9004,6 +9396,8 @@ function createGatewayProvider2(options = {}) {
|
|
|
9004
9396
|
provider.specificationVersion = "v3";
|
|
9005
9397
|
provider.getAvailableModels = getAvailableModels;
|
|
9006
9398
|
provider.getCredits = getCredits;
|
|
9399
|
+
provider.getSpendReport = getSpendReport;
|
|
9400
|
+
provider.getGenerationInfo = getGenerationInfo;
|
|
9007
9401
|
provider.imageModel = (modelId) => {
|
|
9008
9402
|
return new GatewayImageModel2(modelId, {
|
|
9009
9403
|
provider: "gateway",
|
|
@@ -9034,6 +9428,17 @@ function createGatewayProvider2(options = {}) {
|
|
|
9034
9428
|
o11yHeaders: createO11yHeaders()
|
|
9035
9429
|
});
|
|
9036
9430
|
};
|
|
9431
|
+
const createRerankingModel = (modelId) => {
|
|
9432
|
+
return new GatewayRerankingModel(modelId, {
|
|
9433
|
+
provider: "gateway",
|
|
9434
|
+
baseURL,
|
|
9435
|
+
headers: getHeaders,
|
|
9436
|
+
fetch: options.fetch,
|
|
9437
|
+
o11yHeaders: createO11yHeaders()
|
|
9438
|
+
});
|
|
9439
|
+
};
|
|
9440
|
+
provider.rerankingModel = createRerankingModel;
|
|
9441
|
+
provider.reranking = createRerankingModel;
|
|
9037
9442
|
provider.chat = provider.languageModel;
|
|
9038
9443
|
provider.embedding = provider.embeddingModel;
|
|
9039
9444
|
provider.image = provider.imageModel;
|
|
@@ -9053,7 +9458,7 @@ async function getGatewayAuthToken2(options) {
|
|
|
9053
9458
|
authMethod: "api-key"
|
|
9054
9459
|
};
|
|
9055
9460
|
}
|
|
9056
|
-
const oidcToken = await (
|
|
9461
|
+
const oidcToken = await getVercelOidcToken2();
|
|
9057
9462
|
return {
|
|
9058
9463
|
token: oidcToken,
|
|
9059
9464
|
authMethod: "oidc"
|
|
@@ -10033,6 +10438,9 @@ function mergeObjects2(base, overrides) {
|
|
|
10033
10438
|
}
|
|
10034
10439
|
const result = { ...base };
|
|
10035
10440
|
for (const key in overrides) {
|
|
10441
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
10442
|
+
continue;
|
|
10443
|
+
}
|
|
10036
10444
|
if (Object.prototype.hasOwnProperty.call(overrides, key)) {
|
|
10037
10445
|
const overridesValue = overrides[key];
|
|
10038
10446
|
if (overridesValue === void 0)
|
|
@@ -10831,8 +11239,14 @@ function processUIMessageStream2({
|
|
|
10831
11239
|
anyPart.title = options.title;
|
|
10832
11240
|
}
|
|
10833
11241
|
anyPart.providerExecuted = (_a2222 = anyOptions.providerExecuted) != null ? _a2222 : part.providerExecuted;
|
|
10834
|
-
|
|
10835
|
-
|
|
11242
|
+
const providerMetadata = anyOptions.providerMetadata;
|
|
11243
|
+
if (providerMetadata != null) {
|
|
11244
|
+
if (options.state === "output-available" || options.state === "output-error") {
|
|
11245
|
+
const resultPart = part;
|
|
11246
|
+
resultPart.resultProviderMetadata = providerMetadata;
|
|
11247
|
+
} else {
|
|
11248
|
+
part.callProviderMetadata = providerMetadata;
|
|
11249
|
+
}
|
|
10836
11250
|
}
|
|
10837
11251
|
} else {
|
|
10838
11252
|
state.message.parts.push({
|
|
@@ -10846,7 +11260,8 @@ function processUIMessageStream2({
|
|
|
10846
11260
|
errorText: anyOptions.errorText,
|
|
10847
11261
|
providerExecuted: anyOptions.providerExecuted,
|
|
10848
11262
|
preliminary: anyOptions.preliminary,
|
|
10849
|
-
...anyOptions.providerMetadata != null ? {
|
|
11263
|
+
...anyOptions.providerMetadata != null && (options.state === "output-available" || options.state === "output-error") ? { resultProviderMetadata: anyOptions.providerMetadata } : {},
|
|
11264
|
+
...anyOptions.providerMetadata != null && !(options.state === "output-available" || options.state === "output-error") ? { callProviderMetadata: anyOptions.providerMetadata } : {}
|
|
10850
11265
|
});
|
|
10851
11266
|
}
|
|
10852
11267
|
}
|
|
@@ -10869,8 +11284,14 @@ function processUIMessageStream2({
|
|
|
10869
11284
|
anyPart.title = options.title;
|
|
10870
11285
|
}
|
|
10871
11286
|
anyPart.providerExecuted = (_b222 = anyOptions.providerExecuted) != null ? _b222 : part.providerExecuted;
|
|
10872
|
-
|
|
10873
|
-
|
|
11287
|
+
const providerMetadata = anyOptions.providerMetadata;
|
|
11288
|
+
if (providerMetadata != null) {
|
|
11289
|
+
if (options.state === "output-available" || options.state === "output-error") {
|
|
11290
|
+
const resultPart = part;
|
|
11291
|
+
resultPart.resultProviderMetadata = providerMetadata;
|
|
11292
|
+
} else {
|
|
11293
|
+
part.callProviderMetadata = providerMetadata;
|
|
11294
|
+
}
|
|
10874
11295
|
}
|
|
10875
11296
|
} else {
|
|
10876
11297
|
state.message.parts.push({
|
|
@@ -10884,7 +11305,8 @@ function processUIMessageStream2({
|
|
|
10884
11305
|
preliminary: anyOptions.preliminary,
|
|
10885
11306
|
providerExecuted: anyOptions.providerExecuted,
|
|
10886
11307
|
title: options.title,
|
|
10887
|
-
...anyOptions.providerMetadata != null ? {
|
|
11308
|
+
...anyOptions.providerMetadata != null && (options.state === "output-available" || options.state === "output-error") ? { resultProviderMetadata: anyOptions.providerMetadata } : {},
|
|
11309
|
+
...anyOptions.providerMetadata != null && !(options.state === "output-available" || options.state === "output-error") ? { callProviderMetadata: anyOptions.providerMetadata } : {}
|
|
10888
11310
|
});
|
|
10889
11311
|
}
|
|
10890
11312
|
}
|
|
@@ -11168,6 +11590,7 @@ function processUIMessageStream2({
|
|
|
11168
11590
|
output: chunk.output,
|
|
11169
11591
|
preliminary: chunk.preliminary,
|
|
11170
11592
|
providerExecuted: chunk.providerExecuted,
|
|
11593
|
+
providerMetadata: chunk.providerMetadata,
|
|
11171
11594
|
title: toolInvocation.title
|
|
11172
11595
|
});
|
|
11173
11596
|
} else {
|
|
@@ -11179,6 +11602,7 @@ function processUIMessageStream2({
|
|
|
11179
11602
|
output: chunk.output,
|
|
11180
11603
|
providerExecuted: chunk.providerExecuted,
|
|
11181
11604
|
preliminary: chunk.preliminary,
|
|
11605
|
+
providerMetadata: chunk.providerMetadata,
|
|
11182
11606
|
title: toolInvocation.title
|
|
11183
11607
|
});
|
|
11184
11608
|
}
|
|
@@ -11195,6 +11619,7 @@ function processUIMessageStream2({
|
|
|
11195
11619
|
input: toolInvocation.input,
|
|
11196
11620
|
errorText: chunk.errorText,
|
|
11197
11621
|
providerExecuted: chunk.providerExecuted,
|
|
11622
|
+
providerMetadata: chunk.providerMetadata,
|
|
11198
11623
|
title: toolInvocation.title
|
|
11199
11624
|
});
|
|
11200
11625
|
} else {
|
|
@@ -11206,6 +11631,7 @@ function processUIMessageStream2({
|
|
|
11206
11631
|
rawInput: toolInvocation.rawInput,
|
|
11207
11632
|
errorText: chunk.errorText,
|
|
11208
11633
|
providerExecuted: chunk.providerExecuted,
|
|
11634
|
+
providerMetadata: chunk.providerMetadata,
|
|
11209
11635
|
title: toolInvocation.title
|
|
11210
11636
|
});
|
|
11211
11637
|
}
|
|
@@ -11602,6 +12028,25 @@ function toAISDKFinishReason(reason) {
|
|
|
11602
12028
|
}
|
|
11603
12029
|
return reason;
|
|
11604
12030
|
}
|
|
12031
|
+
function normalizeToolPayloadState(state) {
|
|
12032
|
+
if (!state || typeof state !== "object") {
|
|
12033
|
+
return void 0;
|
|
12034
|
+
}
|
|
12035
|
+
const payloadState = state;
|
|
12036
|
+
if (Object.prototype.hasOwnProperty.call(payloadState, "projected") && !Object.prototype.hasOwnProperty.call(payloadState, "transformed")) {
|
|
12037
|
+
const { projected, ...rest } = payloadState;
|
|
12038
|
+
return { ...rest, transformed: projected };
|
|
12039
|
+
}
|
|
12040
|
+
return payloadState;
|
|
12041
|
+
}
|
|
12042
|
+
function getTransformedToolPayload(metadata, target, phase) {
|
|
12043
|
+
const mastraMetadata = metadata?.mastra;
|
|
12044
|
+
const state = mastraMetadata?.toolPayloadTransform?.[target]?.[phase] ?? mastraMetadata?.toolPayloadProjection?.[target]?.[phase];
|
|
12045
|
+
return normalizeToolPayloadState(state);
|
|
12046
|
+
}
|
|
12047
|
+
function hasTransformedToolPayload(transform) {
|
|
12048
|
+
return Boolean(transform && Object.prototype.hasOwnProperty.call(transform, "transformed"));
|
|
12049
|
+
}
|
|
11605
12050
|
function convertMastraChunkToAISDKBase({
|
|
11606
12051
|
chunk,
|
|
11607
12052
|
mode = "stream",
|
|
@@ -11610,6 +12055,12 @@ function convertMastraChunkToAISDKBase({
|
|
|
11610
12055
|
normalizeFinishReason,
|
|
11611
12056
|
includeRawFinishReason = false
|
|
11612
12057
|
}) {
|
|
12058
|
+
const displayInputTransform = getTransformedToolPayload(chunk.metadata, "display", "input-available");
|
|
12059
|
+
const displayInputDeltaTransform = getTransformedToolPayload(chunk.metadata, "display", "input-delta");
|
|
12060
|
+
const displayOutputTransform = getTransformedToolPayload(chunk.metadata, "display", "output-available");
|
|
12061
|
+
const displayErrorTransform = getTransformedToolPayload(chunk.metadata, "display", "error");
|
|
12062
|
+
const displayApprovalTransform = getTransformedToolPayload(chunk.metadata, "display", "approval");
|
|
12063
|
+
const displaySuspendTransform = getTransformedToolPayload(chunk.metadata, "display", "suspend");
|
|
11613
12064
|
switch (chunk.type) {
|
|
11614
12065
|
case "start":
|
|
11615
12066
|
return {
|
|
@@ -11715,7 +12166,7 @@ function convertMastraChunkToAISDKBase({
|
|
|
11715
12166
|
providerMetadata: chunk.payload.providerMetadata,
|
|
11716
12167
|
providerExecuted: chunk.payload.providerExecuted,
|
|
11717
12168
|
toolName: chunk.payload.toolName,
|
|
11718
|
-
input: chunk.payload.args
|
|
12169
|
+
input: hasTransformedToolPayload(displayInputTransform) ? displayInputTransform.transformed : chunk.payload.args
|
|
11719
12170
|
};
|
|
11720
12171
|
case "tool-call-approval":
|
|
11721
12172
|
return {
|
|
@@ -11726,7 +12177,7 @@ function convertMastraChunkToAISDKBase({
|
|
|
11726
12177
|
runId: chunk.runId,
|
|
11727
12178
|
toolCallId: chunk.payload.toolCallId,
|
|
11728
12179
|
toolName: chunk.payload.toolName,
|
|
11729
|
-
args: chunk.payload.args,
|
|
12180
|
+
args: hasTransformedToolPayload(displayApprovalTransform) ? displayApprovalTransform.transformed : chunk.payload.args,
|
|
11730
12181
|
resumeSchema: chunk.payload.resumeSchema
|
|
11731
12182
|
}
|
|
11732
12183
|
};
|
|
@@ -11739,7 +12190,7 @@ function convertMastraChunkToAISDKBase({
|
|
|
11739
12190
|
runId: chunk.runId,
|
|
11740
12191
|
toolCallId: chunk.payload.toolCallId,
|
|
11741
12192
|
toolName: chunk.payload.toolName,
|
|
11742
|
-
suspendPayload: chunk.payload.suspendPayload,
|
|
12193
|
+
suspendPayload: hasTransformedToolPayload(displaySuspendTransform) ? displaySuspendTransform.transformed : chunk.payload.suspendPayload,
|
|
11743
12194
|
resumeSchema: chunk.payload.resumeSchema
|
|
11744
12195
|
}
|
|
11745
12196
|
};
|
|
@@ -11759,10 +12210,13 @@ function convertMastraChunkToAISDKBase({
|
|
|
11759
12210
|
providerMetadata: chunk.payload.providerMetadata
|
|
11760
12211
|
};
|
|
11761
12212
|
case "tool-call-delta":
|
|
12213
|
+
if (displayInputDeltaTransform?.suppress) {
|
|
12214
|
+
return;
|
|
12215
|
+
}
|
|
11762
12216
|
return {
|
|
11763
12217
|
type: "tool-input-delta",
|
|
11764
12218
|
id: chunk.payload.toolCallId,
|
|
11765
|
-
delta: chunk.payload.argsTextDelta,
|
|
12219
|
+
delta: displayInputDeltaTransform?.transformed ?? chunk.payload.argsTextDelta,
|
|
11766
12220
|
providerMetadata: chunk.payload.providerMetadata
|
|
11767
12221
|
};
|
|
11768
12222
|
case "step-finish": {
|
|
@@ -11803,18 +12257,18 @@ function convertMastraChunkToAISDKBase({
|
|
|
11803
12257
|
case "tool-result":
|
|
11804
12258
|
return {
|
|
11805
12259
|
type: "tool-result",
|
|
11806
|
-
input: chunk.payload.args,
|
|
12260
|
+
input: hasTransformedToolPayload(displayInputTransform) ? displayInputTransform.transformed : chunk.payload.args,
|
|
11807
12261
|
toolCallId: chunk.payload.toolCallId,
|
|
11808
12262
|
providerExecuted: chunk.payload.providerExecuted,
|
|
11809
12263
|
toolName: chunk.payload.toolName,
|
|
11810
|
-
output: chunk.payload.result
|
|
12264
|
+
output: hasTransformedToolPayload(displayOutputTransform) ? displayOutputTransform.transformed : chunk.payload.result
|
|
11811
12265
|
// providerMetadata: chunk.payload.providerMetadata, // AI v5 types don't show this?
|
|
11812
12266
|
};
|
|
11813
12267
|
case "tool-error":
|
|
11814
12268
|
return {
|
|
11815
12269
|
type: "tool-error",
|
|
11816
|
-
error: chunk.payload.error,
|
|
11817
|
-
input: chunk.payload.args,
|
|
12270
|
+
error: hasTransformedToolPayload(displayErrorTransform) ? displayErrorTransform.transformed : chunk.payload.error,
|
|
12271
|
+
input: hasTransformedToolPayload(displayInputTransform) ? displayInputTransform.transformed : chunk.payload.args,
|
|
11818
12272
|
toolCallId: chunk.payload.toolCallId,
|
|
11819
12273
|
providerExecuted: chunk.payload.providerExecuted,
|
|
11820
12274
|
toolName: chunk.payload.toolName
|
|
@@ -11916,7 +12370,7 @@ function normalizeV6Usage(usage) {
|
|
|
11916
12370
|
inputTokenDetails: {
|
|
11917
12371
|
noCacheTokens: usage?.inputTokens,
|
|
11918
12372
|
cacheReadTokens: usage?.cachedInputTokens,
|
|
11919
|
-
cacheWriteTokens:
|
|
12373
|
+
cacheWriteTokens: usage?.cacheCreationInputTokens
|
|
11920
12374
|
},
|
|
11921
12375
|
outputTokens: usage?.outputTokens,
|
|
11922
12376
|
outputTokenDetails: {
|
|
@@ -11933,6 +12387,7 @@ function convertMastraChunkToAISDKv6({
|
|
|
11933
12387
|
mode = "stream"
|
|
11934
12388
|
}) {
|
|
11935
12389
|
if (chunk.type === "tool-call-approval") {
|
|
12390
|
+
const displayTransform = getTransformedToolPayload(chunk.metadata, "display", "approval");
|
|
11936
12391
|
return [
|
|
11937
12392
|
{
|
|
11938
12393
|
type: "tool-approval-request",
|
|
@@ -11947,7 +12402,7 @@ function convertMastraChunkToAISDKv6({
|
|
|
11947
12402
|
runId: chunk.runId,
|
|
11948
12403
|
toolCallId: chunk.payload.toolCallId,
|
|
11949
12404
|
toolName: chunk.payload.toolName,
|
|
11950
|
-
args: chunk.payload.args,
|
|
12405
|
+
args: hasTransformedToolPayload(displayTransform) ? displayTransform.transformed : chunk.payload.args,
|
|
11951
12406
|
resumeSchema: chunk.payload.resumeSchema
|
|
11952
12407
|
}
|
|
11953
12408
|
}
|