@austinthesing/magic-shell 0.2.17 → 0.2.18
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/README.md +4 -1
- package/dist/cli.js +11305 -8174
- package/dist/index.js +1027 -240
- package/dist/tui.js +11305 -8174
- package/package.json +11 -10
package/dist/index.js
CHANGED
|
@@ -6,25 +6,43 @@ var __getProtoOf = Object.getPrototypeOf;
|
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
7
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
function __accessProp(key) {
|
|
10
|
+
return this[key];
|
|
11
|
+
}
|
|
12
|
+
var __toESMCache_node;
|
|
13
|
+
var __toESMCache_esm;
|
|
9
14
|
var __toESM = (mod, isNodeMode, target) => {
|
|
15
|
+
var canCache = mod != null && typeof mod === "object";
|
|
16
|
+
if (canCache) {
|
|
17
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
18
|
+
var cached = cache.get(mod);
|
|
19
|
+
if (cached)
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
10
22
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
11
23
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
12
24
|
for (let key of __getOwnPropNames(mod))
|
|
13
25
|
if (!__hasOwnProp.call(to, key))
|
|
14
26
|
__defProp(to, key, {
|
|
15
|
-
get: (
|
|
27
|
+
get: __accessProp.bind(mod, key),
|
|
16
28
|
enumerable: true
|
|
17
29
|
});
|
|
30
|
+
if (canCache)
|
|
31
|
+
cache.set(mod, to);
|
|
18
32
|
return to;
|
|
19
33
|
};
|
|
20
34
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
35
|
+
var __returnValue = (v) => v;
|
|
36
|
+
function __exportSetter(name, newValue) {
|
|
37
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
38
|
+
}
|
|
21
39
|
var __export = (target, all) => {
|
|
22
40
|
for (var name in all)
|
|
23
41
|
__defProp(target, name, {
|
|
24
42
|
get: all[name],
|
|
25
43
|
enumerable: true,
|
|
26
44
|
configurable: true,
|
|
27
|
-
set: (
|
|
45
|
+
set: __exportSetter.bind(all, name)
|
|
28
46
|
});
|
|
29
47
|
};
|
|
30
48
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
@@ -230,13 +248,14 @@ var require_auth_config = __commonJS((exports, module) => {
|
|
|
230
248
|
}
|
|
231
249
|
fs.writeFileSync(authPath, JSON.stringify(config2, null, 2), { mode: 384 });
|
|
232
250
|
}
|
|
233
|
-
function isValidAccessToken(authConfig) {
|
|
251
|
+
function isValidAccessToken(authConfig, expirationBufferMs = 0) {
|
|
234
252
|
if (!authConfig.token)
|
|
235
253
|
return false;
|
|
236
254
|
if (typeof authConfig.expiresAt !== "number")
|
|
237
255
|
return true;
|
|
238
256
|
const nowInSeconds = Math.floor(Date.now() / 1000);
|
|
239
|
-
|
|
257
|
+
const bufferInSeconds = expirationBufferMs / 1000;
|
|
258
|
+
return authConfig.expiresAt >= nowInSeconds + bufferInSeconds;
|
|
240
259
|
}
|
|
241
260
|
});
|
|
242
261
|
|
|
@@ -326,6 +345,47 @@ var require_oauth = __commonJS((exports, module) => {
|
|
|
326
345
|
}
|
|
327
346
|
});
|
|
328
347
|
|
|
348
|
+
// node_modules/@vercel/oidc/dist/auth-errors.js
|
|
349
|
+
var require_auth_errors = __commonJS((exports, module) => {
|
|
350
|
+
var __defProp2 = Object.defineProperty;
|
|
351
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
352
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
353
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
354
|
+
var __export2 = (target, all) => {
|
|
355
|
+
for (var name15 in all)
|
|
356
|
+
__defProp2(target, name15, { get: all[name15], enumerable: true });
|
|
357
|
+
};
|
|
358
|
+
var __copyProps = (to, from, except, desc) => {
|
|
359
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
360
|
+
for (let key of __getOwnPropNames2(from))
|
|
361
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
362
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
363
|
+
}
|
|
364
|
+
return to;
|
|
365
|
+
};
|
|
366
|
+
var __toCommonJS = (mod) => __copyProps(__defProp2({}, "__esModule", { value: true }), mod);
|
|
367
|
+
var auth_errors_exports = {};
|
|
368
|
+
__export2(auth_errors_exports, {
|
|
369
|
+
AccessTokenMissingError: () => AccessTokenMissingError2,
|
|
370
|
+
RefreshAccessTokenFailedError: () => RefreshAccessTokenFailedError2
|
|
371
|
+
});
|
|
372
|
+
module.exports = __toCommonJS(auth_errors_exports);
|
|
373
|
+
|
|
374
|
+
class AccessTokenMissingError2 extends Error {
|
|
375
|
+
constructor() {
|
|
376
|
+
super("No authentication found. Please log in with the Vercel CLI (vercel login).");
|
|
377
|
+
this.name = "AccessTokenMissingError";
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
class RefreshAccessTokenFailedError2 extends Error {
|
|
382
|
+
constructor(cause) {
|
|
383
|
+
super("Failed to refresh authentication token.", { cause });
|
|
384
|
+
this.name = "RefreshAccessTokenFailedError";
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
|
|
329
389
|
// node_modules/@vercel/oidc/dist/token-util.js
|
|
330
390
|
var require_token_util = __commonJS((exports, module) => {
|
|
331
391
|
var __create2 = Object.create;
|
|
@@ -353,9 +413,9 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
353
413
|
assertVercelOidcTokenResponse: () => assertVercelOidcTokenResponse,
|
|
354
414
|
findProjectInfo: () => findProjectInfo,
|
|
355
415
|
getTokenPayload: () => getTokenPayload,
|
|
356
|
-
getVercelCliToken: () => getVercelCliToken,
|
|
357
416
|
getVercelDataDir: () => getVercelDataDir,
|
|
358
417
|
getVercelOidcToken: () => getVercelOidcToken2,
|
|
418
|
+
getVercelToken: () => getVercelToken2,
|
|
359
419
|
isExpired: () => isExpired,
|
|
360
420
|
loadToken: () => loadToken,
|
|
361
421
|
saveToken: () => saveToken
|
|
@@ -367,6 +427,7 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
367
427
|
var import_token_io = require_token_io();
|
|
368
428
|
var import_auth_config = require_auth_config();
|
|
369
429
|
var import_oauth = require_oauth();
|
|
430
|
+
var import_auth_errors = require_auth_errors();
|
|
370
431
|
function getVercelDataDir() {
|
|
371
432
|
const vercelFolder = "com.vercel.cli";
|
|
372
433
|
const dataDir = (0, import_token_io.getUserDataDir)();
|
|
@@ -375,17 +436,17 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
375
436
|
}
|
|
376
437
|
return path.join(dataDir, vercelFolder);
|
|
377
438
|
}
|
|
378
|
-
async function
|
|
439
|
+
async function getVercelToken2(options) {
|
|
379
440
|
const authConfig = (0, import_auth_config.readAuthConfig)();
|
|
380
|
-
if (!authConfig) {
|
|
381
|
-
|
|
441
|
+
if (!authConfig?.token) {
|
|
442
|
+
throw new import_auth_errors.AccessTokenMissingError;
|
|
382
443
|
}
|
|
383
|
-
if ((0, import_auth_config.isValidAccessToken)(authConfig)) {
|
|
384
|
-
return authConfig.token
|
|
444
|
+
if ((0, import_auth_config.isValidAccessToken)(authConfig, options?.expirationBufferMs)) {
|
|
445
|
+
return authConfig.token;
|
|
385
446
|
}
|
|
386
447
|
if (!authConfig.refreshToken) {
|
|
387
448
|
(0, import_auth_config.writeAuthConfig)({});
|
|
388
|
-
|
|
449
|
+
throw new import_auth_errors.RefreshAccessTokenFailedError("No refresh token available");
|
|
389
450
|
}
|
|
390
451
|
try {
|
|
391
452
|
const tokenResponse = await (0, import_oauth.refreshTokenRequest)({
|
|
@@ -394,7 +455,7 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
394
455
|
const [tokensError, tokens] = await (0, import_oauth.processTokenResponse)(tokenResponse);
|
|
395
456
|
if (tokensError || !tokens) {
|
|
396
457
|
(0, import_auth_config.writeAuthConfig)({});
|
|
397
|
-
|
|
458
|
+
throw new import_auth_errors.RefreshAccessTokenFailedError(tokensError);
|
|
398
459
|
}
|
|
399
460
|
const updatedConfig = {
|
|
400
461
|
token: tokens.access_token,
|
|
@@ -404,10 +465,13 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
404
465
|
updatedConfig.refreshToken = tokens.refresh_token;
|
|
405
466
|
}
|
|
406
467
|
(0, import_auth_config.writeAuthConfig)(updatedConfig);
|
|
407
|
-
return updatedConfig.token
|
|
468
|
+
return updatedConfig.token;
|
|
408
469
|
} catch (error40) {
|
|
409
470
|
(0, import_auth_config.writeAuthConfig)({});
|
|
410
|
-
|
|
471
|
+
if (error40 instanceof import_auth_errors.AccessTokenMissingError || error40 instanceof import_auth_errors.RefreshAccessTokenFailedError) {
|
|
472
|
+
throw error40;
|
|
473
|
+
}
|
|
474
|
+
throw new import_auth_errors.RefreshAccessTokenFailedError(error40);
|
|
411
475
|
}
|
|
412
476
|
}
|
|
413
477
|
async function getVercelOidcToken2(authToken, projectId, teamId) {
|
|
@@ -482,8 +546,8 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
482
546
|
const padded = base643.padEnd(base643.length + (4 - base643.length % 4) % 4, "=");
|
|
483
547
|
return JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
|
|
484
548
|
}
|
|
485
|
-
function isExpired(token) {
|
|
486
|
-
return token.exp * 1000 < Date.now();
|
|
549
|
+
function isExpired(token, bufferMs = 0) {
|
|
550
|
+
return token.exp * 1000 < Date.now() + bufferMs;
|
|
487
551
|
}
|
|
488
552
|
});
|
|
489
553
|
|
|
@@ -513,17 +577,26 @@ var require_token = __commonJS((exports, module) => {
|
|
|
513
577
|
module.exports = __toCommonJS(token_exports);
|
|
514
578
|
var import_token_error = require_token_error();
|
|
515
579
|
var import_token_util = require_token_util();
|
|
516
|
-
async function refreshToken() {
|
|
517
|
-
|
|
580
|
+
async function refreshToken(options) {
|
|
581
|
+
let projectId = options?.project;
|
|
582
|
+
let teamId = options?.team;
|
|
583
|
+
if (!projectId && !teamId) {
|
|
584
|
+
const projectInfo = (0, import_token_util.findProjectInfo)();
|
|
585
|
+
projectId = projectInfo.projectId;
|
|
586
|
+
teamId = projectInfo.teamId;
|
|
587
|
+
} else if (!projectId || !teamId) {
|
|
588
|
+
const projectInfo = (0, import_token_util.findProjectInfo)();
|
|
589
|
+
projectId = projectId ?? projectInfo.projectId;
|
|
590
|
+
teamId = teamId ?? projectInfo.teamId;
|
|
591
|
+
}
|
|
592
|
+
if (!projectId) {
|
|
593
|
+
throw new import_token_error.VercelOidcTokenError("Failed to refresh OIDC token: No project specified. Try re-linking your project with `vc link`");
|
|
594
|
+
}
|
|
518
595
|
let maybeToken = (0, import_token_util.loadToken)(projectId);
|
|
519
|
-
if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token))) {
|
|
520
|
-
const authToken = await (0, import_token_util.
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
}
|
|
524
|
-
if (!projectId) {
|
|
525
|
-
throw new import_token_error.VercelOidcTokenError("Failed to refresh OIDC token: Try re-linking your project with `vc link`");
|
|
526
|
-
}
|
|
596
|
+
if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token), options?.expirationBufferMs)) {
|
|
597
|
+
const authToken = await (0, import_token_util.getVercelToken)({
|
|
598
|
+
expirationBufferMs: options?.expirationBufferMs
|
|
599
|
+
});
|
|
527
600
|
maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);
|
|
528
601
|
if (!maybeToken) {
|
|
529
602
|
throw new import_token_error.VercelOidcTokenError("Failed to refresh OIDC token");
|
|
@@ -562,7 +635,7 @@ var require_get_vercel_oidc_token = __commonJS((exports, module) => {
|
|
|
562
635
|
module.exports = __toCommonJS(get_vercel_oidc_token_exports);
|
|
563
636
|
var import_get_context = require_get_context();
|
|
564
637
|
var import_token_error = require_token_error();
|
|
565
|
-
async function getVercelOidcToken2() {
|
|
638
|
+
async function getVercelOidcToken2(options) {
|
|
566
639
|
let token = "";
|
|
567
640
|
let err;
|
|
568
641
|
try {
|
|
@@ -575,8 +648,8 @@ var require_get_vercel_oidc_token = __commonJS((exports, module) => {
|
|
|
575
648
|
await Promise.resolve().then(() => __toESM(require_token_util())),
|
|
576
649
|
await Promise.resolve().then(() => __toESM(require_token()))
|
|
577
650
|
]);
|
|
578
|
-
if (!token || isExpired(getTokenPayload(token))) {
|
|
579
|
-
await refreshToken();
|
|
651
|
+
if (!token || isExpired(getTokenPayload(token), options?.expirationBufferMs)) {
|
|
652
|
+
await refreshToken(options);
|
|
580
653
|
token = getVercelOidcTokenSync2();
|
|
581
654
|
}
|
|
582
655
|
} catch (error40) {
|
|
@@ -622,13 +695,18 @@ var require_dist = __commonJS((exports, module) => {
|
|
|
622
695
|
var __toCommonJS = (mod) => __copyProps(__defProp2({}, "__esModule", { value: true }), mod);
|
|
623
696
|
var src_exports = {};
|
|
624
697
|
__export2(src_exports, {
|
|
698
|
+
AccessTokenMissingError: () => import_auth_errors.AccessTokenMissingError,
|
|
699
|
+
RefreshAccessTokenFailedError: () => import_auth_errors.RefreshAccessTokenFailedError,
|
|
625
700
|
getContext: () => import_get_context.getContext,
|
|
626
701
|
getVercelOidcToken: () => import_get_vercel_oidc_token.getVercelOidcToken,
|
|
627
|
-
getVercelOidcTokenSync: () => import_get_vercel_oidc_token.getVercelOidcTokenSync
|
|
702
|
+
getVercelOidcTokenSync: () => import_get_vercel_oidc_token.getVercelOidcTokenSync,
|
|
703
|
+
getVercelToken: () => import_token_util.getVercelToken
|
|
628
704
|
});
|
|
629
705
|
module.exports = __toCommonJS(src_exports);
|
|
630
706
|
var import_get_vercel_oidc_token = require_get_vercel_oidc_token();
|
|
631
707
|
var import_get_context = require_get_context();
|
|
708
|
+
var import_auth_errors = require_auth_errors();
|
|
709
|
+
var import_token_util = require_token_util();
|
|
632
710
|
});
|
|
633
711
|
|
|
634
712
|
// node_modules/@opentelemetry/api/build/src/platform/node/globalThis.js
|
|
@@ -18382,43 +18460,114 @@ class ParseError extends Error {
|
|
|
18382
18460
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
18383
18461
|
}
|
|
18384
18462
|
}
|
|
18463
|
+
var LF = 10;
|
|
18464
|
+
var CR = 13;
|
|
18465
|
+
var SPACE = 32;
|
|
18385
18466
|
function noop(_arg) {}
|
|
18386
18467
|
function createParser(callbacks) {
|
|
18387
18468
|
if (typeof callbacks == "function")
|
|
18388
18469
|
throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");
|
|
18389
|
-
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
|
|
18390
|
-
let
|
|
18391
|
-
function feed(
|
|
18392
|
-
|
|
18393
|
-
|
|
18394
|
-
|
|
18395
|
-
|
|
18396
|
-
|
|
18397
|
-
|
|
18398
|
-
|
|
18470
|
+
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks, pendingFragments = [];
|
|
18471
|
+
let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
|
|
18472
|
+
function feed(chunk) {
|
|
18473
|
+
if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
|
|
18474
|
+
const trailing2 = processLines(chunk);
|
|
18475
|
+
trailing2 !== "" && pendingFragments.push(trailing2);
|
|
18476
|
+
return;
|
|
18477
|
+
}
|
|
18478
|
+
if (chunk.indexOf(`
|
|
18479
|
+
`) === -1 && chunk.indexOf("\r") === -1) {
|
|
18480
|
+
pendingFragments.push(chunk);
|
|
18481
|
+
return;
|
|
18482
|
+
}
|
|
18483
|
+
pendingFragments.push(chunk);
|
|
18484
|
+
const input = pendingFragments.join("");
|
|
18485
|
+
pendingFragments.length = 0;
|
|
18486
|
+
const trailing = processLines(input);
|
|
18487
|
+
trailing !== "" && pendingFragments.push(trailing);
|
|
18488
|
+
}
|
|
18489
|
+
function processLines(chunk) {
|
|
18490
|
+
let searchIndex = 0;
|
|
18491
|
+
if (chunk.indexOf("\r") === -1) {
|
|
18492
|
+
let lfIndex = chunk.indexOf(`
|
|
18493
|
+
`, searchIndex);
|
|
18494
|
+
for (;lfIndex !== -1; ) {
|
|
18495
|
+
if (searchIndex === lfIndex) {
|
|
18496
|
+
dataLines > 0 && onEvent({ id, event: eventType, data }), id = undefined, data = "", dataLines = 0, eventType = undefined, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
18497
|
+
`, searchIndex);
|
|
18498
|
+
continue;
|
|
18499
|
+
}
|
|
18500
|
+
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
18501
|
+
if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
|
|
18502
|
+
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
18503
|
+
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
|
|
18504
|
+
onEvent({ id, event: eventType, data: value }), id = undefined, data = "", eventType = undefined, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
18505
|
+
`, searchIndex);
|
|
18506
|
+
continue;
|
|
18507
|
+
}
|
|
18508
|
+
data = dataLines === 0 ? value : `${data}
|
|
18509
|
+
${value}`, dataLines++;
|
|
18510
|
+
} else
|
|
18511
|
+
isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6, lfIndex) || undefined : parseLine(chunk, searchIndex, lfIndex);
|
|
18512
|
+
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
18513
|
+
`, searchIndex);
|
|
18514
|
+
}
|
|
18515
|
+
return chunk.slice(searchIndex);
|
|
18516
|
+
}
|
|
18517
|
+
for (;searchIndex < chunk.length; ) {
|
|
18518
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
18519
|
+
`, searchIndex);
|
|
18520
|
+
let lineEnd = -1;
|
|
18521
|
+
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)
|
|
18522
|
+
break;
|
|
18523
|
+
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
|
|
18524
|
+
}
|
|
18525
|
+
return chunk.slice(searchIndex);
|
|
18526
|
+
}
|
|
18527
|
+
function parseLine(chunk, start, end) {
|
|
18528
|
+
if (start === end) {
|
|
18399
18529
|
dispatchEvent();
|
|
18400
18530
|
return;
|
|
18401
18531
|
}
|
|
18402
|
-
|
|
18403
|
-
|
|
18532
|
+
const firstCharCode = chunk.charCodeAt(start);
|
|
18533
|
+
if (isDataPrefix(chunk, start, firstCharCode)) {
|
|
18534
|
+
const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
18535
|
+
data = dataLines === 0 ? value2 : `${data}
|
|
18536
|
+
${value2}`, dataLines++;
|
|
18537
|
+
return;
|
|
18538
|
+
}
|
|
18539
|
+
if (isEventPrefix(chunk, start, firstCharCode)) {
|
|
18540
|
+
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || undefined;
|
|
18541
|
+
return;
|
|
18542
|
+
}
|
|
18543
|
+
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
18544
|
+
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
|
|
18545
|
+
id = value2.includes("\x00") ? undefined : value2;
|
|
18546
|
+
return;
|
|
18547
|
+
}
|
|
18548
|
+
if (firstCharCode === 58) {
|
|
18549
|
+
if (onComment) {
|
|
18550
|
+
const line2 = chunk.slice(start, end);
|
|
18551
|
+
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
|
|
18552
|
+
}
|
|
18404
18553
|
return;
|
|
18405
18554
|
}
|
|
18406
|
-
const fieldSeparatorIndex = line.indexOf(":");
|
|
18407
|
-
if (fieldSeparatorIndex
|
|
18408
|
-
|
|
18409
|
-
processField(field, value, line);
|
|
18555
|
+
const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
|
|
18556
|
+
if (fieldSeparatorIndex === -1) {
|
|
18557
|
+
processField(line, "", line);
|
|
18410
18558
|
return;
|
|
18411
18559
|
}
|
|
18412
|
-
|
|
18560
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
18561
|
+
processField(field, value, line);
|
|
18413
18562
|
}
|
|
18414
18563
|
function processField(field, value, line) {
|
|
18415
18564
|
switch (field) {
|
|
18416
18565
|
case "event":
|
|
18417
|
-
eventType = value;
|
|
18566
|
+
eventType = value || undefined;
|
|
18418
18567
|
break;
|
|
18419
18568
|
case "data":
|
|
18420
|
-
data = `${data}
|
|
18421
|
-
|
|
18569
|
+
data = dataLines === 0 ? value : `${data}
|
|
18570
|
+
${value}`, dataLines++;
|
|
18422
18571
|
break;
|
|
18423
18572
|
case "id":
|
|
18424
18573
|
id = value.includes("\x00") ? undefined : value;
|
|
@@ -18436,35 +18585,26 @@ function createParser(callbacks) {
|
|
|
18436
18585
|
}
|
|
18437
18586
|
}
|
|
18438
18587
|
function dispatchEvent() {
|
|
18439
|
-
|
|
18588
|
+
dataLines > 0 && onEvent({
|
|
18440
18589
|
id,
|
|
18441
|
-
event: eventType
|
|
18442
|
-
data
|
|
18443
|
-
|
|
18444
|
-
}), id = undefined, data = "", eventType = "";
|
|
18590
|
+
event: eventType,
|
|
18591
|
+
data
|
|
18592
|
+
}), id = undefined, data = "", dataLines = 0, eventType = undefined;
|
|
18445
18593
|
}
|
|
18446
18594
|
function reset(options = {}) {
|
|
18447
|
-
|
|
18595
|
+
if (options.consume && pendingFragments.length > 0) {
|
|
18596
|
+
const incompleteLine = pendingFragments.join("");
|
|
18597
|
+
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
18598
|
+
}
|
|
18599
|
+
isFirstChunk = true, id = undefined, data = "", dataLines = 0, eventType = undefined, pendingFragments.length = 0;
|
|
18448
18600
|
}
|
|
18449
18601
|
return { feed, reset };
|
|
18450
18602
|
}
|
|
18451
|
-
function
|
|
18452
|
-
|
|
18453
|
-
|
|
18454
|
-
|
|
18455
|
-
|
|
18456
|
-
`, searchIndex);
|
|
18457
|
-
let lineEnd = -1;
|
|
18458
|
-
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) {
|
|
18459
|
-
incompleteLine = chunk.slice(searchIndex);
|
|
18460
|
-
break;
|
|
18461
|
-
} else {
|
|
18462
|
-
const line = chunk.slice(searchIndex, lineEnd);
|
|
18463
|
-
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
18464
|
-
` && searchIndex++;
|
|
18465
|
-
}
|
|
18466
|
-
}
|
|
18467
|
-
return [lines, incompleteLine];
|
|
18603
|
+
function isDataPrefix(chunk, i, firstCharCode) {
|
|
18604
|
+
return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
|
|
18605
|
+
}
|
|
18606
|
+
function isEventPrefix(chunk, i, firstCharCode) {
|
|
18607
|
+
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;
|
|
18468
18608
|
}
|
|
18469
18609
|
|
|
18470
18610
|
// node_modules/eventsource-parser/dist/stream.js
|
|
@@ -18946,7 +19086,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
18946
19086
|
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
18947
19087
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
18948
19088
|
}
|
|
18949
|
-
var VERSION = "4.0.
|
|
19089
|
+
var VERSION = "4.0.26";
|
|
18950
19090
|
var getOriginalFetch = () => globalThis.fetch;
|
|
18951
19091
|
var getFromApi = async ({
|
|
18952
19092
|
url: url2,
|
|
@@ -19042,7 +19182,7 @@ function loadApiKey({
|
|
|
19042
19182
|
}
|
|
19043
19183
|
if (typeof process === "undefined") {
|
|
19044
19184
|
throw new LoadAPIKeyError({
|
|
19045
|
-
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables
|
|
19185
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables are not supported in this environment.`
|
|
19046
19186
|
});
|
|
19047
19187
|
}
|
|
19048
19188
|
apiKey = process.env[environmentVariableName];
|
|
@@ -20678,7 +20818,7 @@ async function* executeTool({
|
|
|
20678
20818
|
}
|
|
20679
20819
|
|
|
20680
20820
|
// node_modules/@ai-sdk/anthropic/dist/index.mjs
|
|
20681
|
-
var VERSION2 = "3.0.
|
|
20821
|
+
var VERSION2 = "3.0.74";
|
|
20682
20822
|
var anthropicErrorDataSchema = lazySchema(() => zodSchema(exports_external.object({
|
|
20683
20823
|
type: exports_external.literal("error"),
|
|
20684
20824
|
error: exports_external.object({
|
|
@@ -21367,7 +21507,8 @@ var anthropicLanguageModelOptions = exports_external.object({
|
|
|
21367
21507
|
structuredOutputMode: exports_external.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
21368
21508
|
thinking: exports_external.discriminatedUnion("type", [
|
|
21369
21509
|
exports_external.object({
|
|
21370
|
-
type: exports_external.literal("adaptive")
|
|
21510
|
+
type: exports_external.literal("adaptive"),
|
|
21511
|
+
display: exports_external.enum(["omitted", "summarized"]).optional()
|
|
21371
21512
|
}),
|
|
21372
21513
|
exports_external.object({
|
|
21373
21514
|
type: exports_external.literal("enabled"),
|
|
@@ -21404,8 +21545,14 @@ var anthropicLanguageModelOptions = exports_external.object({
|
|
|
21404
21545
|
})).optional()
|
|
21405
21546
|
}).optional(),
|
|
21406
21547
|
toolStreaming: exports_external.boolean().optional(),
|
|
21407
|
-
effort: exports_external.enum(["low", "medium", "high", "max"]).optional(),
|
|
21548
|
+
effort: exports_external.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
21549
|
+
taskBudget: exports_external.object({
|
|
21550
|
+
type: exports_external.literal("tokens"),
|
|
21551
|
+
total: exports_external.number().int().min(20000),
|
|
21552
|
+
remaining: exports_external.number().int().min(0).optional()
|
|
21553
|
+
}).optional(),
|
|
21408
21554
|
speed: exports_external.enum(["fast", "standard"]).optional(),
|
|
21555
|
+
inferenceGeo: exports_external.enum(["us", "global"]).optional(),
|
|
21409
21556
|
anthropicBeta: exports_external.array(exports_external.string()).optional(),
|
|
21410
21557
|
contextManagement: exports_external.object({
|
|
21411
21558
|
edits: exports_external.array(exports_external.discriminatedUnion("type", [
|
|
@@ -21664,9 +21811,10 @@ async function prepareTools({
|
|
|
21664
21811
|
disableParallelToolUse,
|
|
21665
21812
|
cacheControlValidator,
|
|
21666
21813
|
supportsStructuredOutput,
|
|
21667
|
-
supportsStrictTools
|
|
21814
|
+
supportsStrictTools,
|
|
21815
|
+
defaultEagerInputStreaming = false
|
|
21668
21816
|
}) {
|
|
21669
|
-
var _a16;
|
|
21817
|
+
var _a16, _b16;
|
|
21670
21818
|
tools = (tools == null ? undefined : tools.length) ? tools : undefined;
|
|
21671
21819
|
const toolWarnings = [];
|
|
21672
21820
|
const betas = /* @__PURE__ */ new Set;
|
|
@@ -21683,7 +21831,7 @@ async function prepareTools({
|
|
|
21683
21831
|
canCache: true
|
|
21684
21832
|
});
|
|
21685
21833
|
const anthropicOptions = (_a16 = tool2.providerOptions) == null ? undefined : _a16.anthropic;
|
|
21686
|
-
const eagerInputStreaming = anthropicOptions == null ? undefined : anthropicOptions.eagerInputStreaming;
|
|
21834
|
+
const eagerInputStreaming = (_b16 = anthropicOptions == null ? undefined : anthropicOptions.eagerInputStreaming) != null ? _b16 : defaultEagerInputStreaming;
|
|
21687
21835
|
const deferLoading = anthropicOptions == null ? undefined : anthropicOptions.deferLoading;
|
|
21688
21836
|
const allowedCallers = anthropicOptions == null ? undefined : anthropicOptions.allowedCallers;
|
|
21689
21837
|
if (!supportsStrictTools && tool2.strict != null) {
|
|
@@ -23061,6 +23209,144 @@ function mapAnthropicStopReason({
|
|
|
23061
23209
|
return "other";
|
|
23062
23210
|
}
|
|
23063
23211
|
}
|
|
23212
|
+
var SUPPORTED_STRING_FORMATS = /* @__PURE__ */ new Set([
|
|
23213
|
+
"date-time",
|
|
23214
|
+
"time",
|
|
23215
|
+
"date",
|
|
23216
|
+
"duration",
|
|
23217
|
+
"email",
|
|
23218
|
+
"hostname",
|
|
23219
|
+
"uri",
|
|
23220
|
+
"ipv4",
|
|
23221
|
+
"ipv6",
|
|
23222
|
+
"uuid"
|
|
23223
|
+
]);
|
|
23224
|
+
var DESCRIPTION_CONSTRAINT_KEYS = [
|
|
23225
|
+
"minimum",
|
|
23226
|
+
"maximum",
|
|
23227
|
+
"exclusiveMinimum",
|
|
23228
|
+
"exclusiveMaximum",
|
|
23229
|
+
"multipleOf",
|
|
23230
|
+
"minLength",
|
|
23231
|
+
"maxLength",
|
|
23232
|
+
"pattern",
|
|
23233
|
+
"minItems",
|
|
23234
|
+
"maxItems",
|
|
23235
|
+
"uniqueItems",
|
|
23236
|
+
"minProperties",
|
|
23237
|
+
"maxProperties",
|
|
23238
|
+
"not"
|
|
23239
|
+
];
|
|
23240
|
+
function sanitizeJsonSchema(schema) {
|
|
23241
|
+
return sanitizeSchema(schema);
|
|
23242
|
+
}
|
|
23243
|
+
function sanitizeDefinition(definition) {
|
|
23244
|
+
if (typeof definition === "boolean" || !isPlainObject2(definition)) {
|
|
23245
|
+
return definition;
|
|
23246
|
+
}
|
|
23247
|
+
return sanitizeSchema(definition);
|
|
23248
|
+
}
|
|
23249
|
+
function sanitizeSchema(schema) {
|
|
23250
|
+
const result = {};
|
|
23251
|
+
const schemaWithDefs = schema;
|
|
23252
|
+
if (schema.$ref != null) {
|
|
23253
|
+
return { $ref: schema.$ref };
|
|
23254
|
+
}
|
|
23255
|
+
if (schema.$schema != null) {
|
|
23256
|
+
result.$schema = schema.$schema;
|
|
23257
|
+
}
|
|
23258
|
+
if (schema.$id != null) {
|
|
23259
|
+
result.$id = schema.$id;
|
|
23260
|
+
}
|
|
23261
|
+
if (schema.title != null) {
|
|
23262
|
+
result.title = schema.title;
|
|
23263
|
+
}
|
|
23264
|
+
if (schema.description != null) {
|
|
23265
|
+
result.description = schema.description;
|
|
23266
|
+
}
|
|
23267
|
+
if (schema.default !== undefined) {
|
|
23268
|
+
result.default = schema.default;
|
|
23269
|
+
}
|
|
23270
|
+
if (schema.const !== undefined) {
|
|
23271
|
+
result.const = schema.const;
|
|
23272
|
+
}
|
|
23273
|
+
if (schema.enum != null) {
|
|
23274
|
+
result.enum = schema.enum;
|
|
23275
|
+
}
|
|
23276
|
+
if (schema.type != null) {
|
|
23277
|
+
result.type = schema.type;
|
|
23278
|
+
}
|
|
23279
|
+
if (schema.anyOf != null) {
|
|
23280
|
+
result.anyOf = schema.anyOf.map(sanitizeDefinition);
|
|
23281
|
+
} else if (schema.oneOf != null) {
|
|
23282
|
+
result.anyOf = schema.oneOf.map(sanitizeDefinition);
|
|
23283
|
+
}
|
|
23284
|
+
if (schema.allOf != null) {
|
|
23285
|
+
result.allOf = schema.allOf.map(sanitizeDefinition);
|
|
23286
|
+
}
|
|
23287
|
+
if (schema.definitions != null) {
|
|
23288
|
+
result.definitions = Object.fromEntries(Object.entries(schema.definitions).map(([name15, definition]) => [
|
|
23289
|
+
name15,
|
|
23290
|
+
sanitizeDefinition(definition)
|
|
23291
|
+
]));
|
|
23292
|
+
}
|
|
23293
|
+
if (schemaWithDefs.$defs != null) {
|
|
23294
|
+
const resultWithDefs = result;
|
|
23295
|
+
resultWithDefs.$defs = Object.fromEntries(Object.entries(schemaWithDefs.$defs).map(([name15, definition]) => [
|
|
23296
|
+
name15,
|
|
23297
|
+
sanitizeDefinition(definition)
|
|
23298
|
+
]));
|
|
23299
|
+
}
|
|
23300
|
+
if (schema.type === "object" || schema.properties != null) {
|
|
23301
|
+
if (schema.properties != null) {
|
|
23302
|
+
result.properties = Object.fromEntries(Object.entries(schema.properties).map(([name15, definition]) => [
|
|
23303
|
+
name15,
|
|
23304
|
+
sanitizeDefinition(definition)
|
|
23305
|
+
]));
|
|
23306
|
+
}
|
|
23307
|
+
result.additionalProperties = false;
|
|
23308
|
+
if (schema.required != null) {
|
|
23309
|
+
result.required = schema.required;
|
|
23310
|
+
}
|
|
23311
|
+
}
|
|
23312
|
+
if (schema.items != null) {
|
|
23313
|
+
result.items = Array.isArray(schema.items) ? schema.items.map(sanitizeDefinition) : sanitizeDefinition(schema.items);
|
|
23314
|
+
}
|
|
23315
|
+
if (typeof schema.format === "string" && SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
23316
|
+
result.format = schema.format;
|
|
23317
|
+
}
|
|
23318
|
+
const constraintDescription = getConstraintDescription(schema);
|
|
23319
|
+
if (constraintDescription != null) {
|
|
23320
|
+
result.description = result.description == null ? constraintDescription : `${result.description}
|
|
23321
|
+
${constraintDescription}`;
|
|
23322
|
+
}
|
|
23323
|
+
return result;
|
|
23324
|
+
}
|
|
23325
|
+
function getConstraintDescription(schema) {
|
|
23326
|
+
const descriptions = DESCRIPTION_CONSTRAINT_KEYS.flatMap((key) => {
|
|
23327
|
+
const value = schema[key];
|
|
23328
|
+
if (value == null || value === false) {
|
|
23329
|
+
return [];
|
|
23330
|
+
}
|
|
23331
|
+
return `${formatConstraintName(key)}: ${formatConstraintValue(value)}`;
|
|
23332
|
+
});
|
|
23333
|
+
if (typeof schema.format === "string" && !SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
23334
|
+
descriptions.push(`format: ${schema.format}`);
|
|
23335
|
+
}
|
|
23336
|
+
return descriptions.length === 0 ? undefined : `${descriptions.join("; ")}.`;
|
|
23337
|
+
}
|
|
23338
|
+
function formatConstraintName(key) {
|
|
23339
|
+
return key.replace(/[A-Z]/g, (match) => ` ${match.toLowerCase()}`);
|
|
23340
|
+
}
|
|
23341
|
+
function formatConstraintValue(value) {
|
|
23342
|
+
if (typeof value === "string") {
|
|
23343
|
+
return value;
|
|
23344
|
+
}
|
|
23345
|
+
return JSON.stringify(value);
|
|
23346
|
+
}
|
|
23347
|
+
function isPlainObject2(value) {
|
|
23348
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23349
|
+
}
|
|
23064
23350
|
function createCitationSource(citation, citationDocuments, generateId3) {
|
|
23065
23351
|
var _a16;
|
|
23066
23352
|
if (citation.type === "web_search_result_location") {
|
|
@@ -23145,7 +23431,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
23145
23431
|
providerOptions,
|
|
23146
23432
|
stream
|
|
23147
23433
|
}) {
|
|
23148
|
-
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i;
|
|
23434
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
23149
23435
|
const warnings = [];
|
|
23150
23436
|
if (frequencyPenalty != null) {
|
|
23151
23437
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -23196,8 +23482,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
23196
23482
|
const {
|
|
23197
23483
|
maxOutputTokens: maxOutputTokensForModel,
|
|
23198
23484
|
supportsStructuredOutput: modelSupportsStructuredOutput,
|
|
23485
|
+
rejectsSamplingParameters,
|
|
23199
23486
|
isKnownModel
|
|
23200
23487
|
} = getModelCapabilities(this.modelId);
|
|
23488
|
+
if (rejectsSamplingParameters) {
|
|
23489
|
+
if (temperature != null) {
|
|
23490
|
+
warnings.push({
|
|
23491
|
+
type: "unsupported",
|
|
23492
|
+
feature: "temperature",
|
|
23493
|
+
details: `temperature is not supported by ${this.modelId} and will be ignored`
|
|
23494
|
+
});
|
|
23495
|
+
temperature = undefined;
|
|
23496
|
+
}
|
|
23497
|
+
if (topK != null) {
|
|
23498
|
+
warnings.push({
|
|
23499
|
+
type: "unsupported",
|
|
23500
|
+
feature: "topK",
|
|
23501
|
+
details: `topK is not supported by ${this.modelId} and will be ignored`
|
|
23502
|
+
});
|
|
23503
|
+
topK = undefined;
|
|
23504
|
+
}
|
|
23505
|
+
if (topP != null) {
|
|
23506
|
+
warnings.push({
|
|
23507
|
+
type: "unsupported",
|
|
23508
|
+
feature: "topP",
|
|
23509
|
+
details: `topP is not supported by ${this.modelId} and will be ignored`
|
|
23510
|
+
});
|
|
23511
|
+
topP = undefined;
|
|
23512
|
+
}
|
|
23513
|
+
}
|
|
23201
23514
|
const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
|
|
23202
23515
|
const supportsStructuredOutput = ((_a16 = this.config.supportsNativeStructuredOutput) != null ? _a16 : true) && modelSupportsStructuredOutput;
|
|
23203
23516
|
const supportsStrictTools = ((_b16 = this.config.supportsStrictTools) != null ? _b16 : true) && modelSupportsStructuredOutput;
|
|
@@ -23244,6 +23557,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
23244
23557
|
const thinkingType = (_e = anthropicOptions == null ? undefined : anthropicOptions.thinking) == null ? undefined : _e.type;
|
|
23245
23558
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
23246
23559
|
let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? undefined : anthropicOptions.thinking) == null ? undefined : _f.budgetTokens : undefined;
|
|
23560
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? undefined : anthropicOptions.thinking) == null ? undefined : _g.display : undefined;
|
|
23247
23561
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
23248
23562
|
const baseArgs = {
|
|
23249
23563
|
model: this.modelId,
|
|
@@ -23255,18 +23569,28 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
23255
23569
|
...isThinking && {
|
|
23256
23570
|
thinking: {
|
|
23257
23571
|
type: thinkingType,
|
|
23258
|
-
...thinkingBudget != null && { budget_tokens: thinkingBudget }
|
|
23572
|
+
...thinkingBudget != null && { budget_tokens: thinkingBudget },
|
|
23573
|
+
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
23259
23574
|
}
|
|
23260
23575
|
},
|
|
23261
|
-
...((anthropicOptions == null ? undefined : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? undefined : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
23576
|
+
...((anthropicOptions == null ? undefined : anthropicOptions.effort) || (anthropicOptions == null ? undefined : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? undefined : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
23262
23577
|
output_config: {
|
|
23263
23578
|
...(anthropicOptions == null ? undefined : anthropicOptions.effort) && {
|
|
23264
23579
|
effort: anthropicOptions.effort
|
|
23265
23580
|
},
|
|
23581
|
+
...(anthropicOptions == null ? undefined : anthropicOptions.taskBudget) && {
|
|
23582
|
+
task_budget: {
|
|
23583
|
+
type: anthropicOptions.taskBudget.type,
|
|
23584
|
+
total: anthropicOptions.taskBudget.total,
|
|
23585
|
+
...anthropicOptions.taskBudget.remaining != null && {
|
|
23586
|
+
remaining: anthropicOptions.taskBudget.remaining
|
|
23587
|
+
}
|
|
23588
|
+
}
|
|
23589
|
+
},
|
|
23266
23590
|
...useStructuredOutput && (responseFormat == null ? undefined : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
23267
23591
|
format: {
|
|
23268
23592
|
type: "json_schema",
|
|
23269
|
-
schema: responseFormat.schema
|
|
23593
|
+
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
23270
23594
|
}
|
|
23271
23595
|
}
|
|
23272
23596
|
}
|
|
@@ -23274,10 +23598,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
23274
23598
|
...(anthropicOptions == null ? undefined : anthropicOptions.speed) && {
|
|
23275
23599
|
speed: anthropicOptions.speed
|
|
23276
23600
|
},
|
|
23601
|
+
...(anthropicOptions == null ? undefined : anthropicOptions.inferenceGeo) && {
|
|
23602
|
+
inference_geo: anthropicOptions.inferenceGeo
|
|
23603
|
+
},
|
|
23277
23604
|
...(anthropicOptions == null ? undefined : anthropicOptions.cacheControl) && {
|
|
23278
23605
|
cache_control: anthropicOptions.cacheControl
|
|
23279
23606
|
},
|
|
23280
|
-
...((
|
|
23607
|
+
...((_h = anthropicOptions == null ? undefined : anthropicOptions.metadata) == null ? undefined : _h.userId) != null && {
|
|
23281
23608
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
23282
23609
|
},
|
|
23283
23610
|
...(anthropicOptions == null ? undefined : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && {
|
|
@@ -23436,12 +23763,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
23436
23763
|
if (anthropicOptions == null ? undefined : anthropicOptions.effort) {
|
|
23437
23764
|
betas.add("effort-2025-11-24");
|
|
23438
23765
|
}
|
|
23766
|
+
if (anthropicOptions == null ? undefined : anthropicOptions.taskBudget) {
|
|
23767
|
+
betas.add("task-budgets-2026-03-13");
|
|
23768
|
+
}
|
|
23439
23769
|
if ((anthropicOptions == null ? undefined : anthropicOptions.speed) === "fast") {
|
|
23440
23770
|
betas.add("fast-mode-2026-02-01");
|
|
23441
23771
|
}
|
|
23442
|
-
|
|
23443
|
-
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
23444
|
-
}
|
|
23772
|
+
const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? undefined : anthropicOptions.toolStreaming) != null ? _i : true);
|
|
23445
23773
|
const {
|
|
23446
23774
|
tools: anthropicTools2,
|
|
23447
23775
|
toolChoice: anthropicToolChoice,
|
|
@@ -23453,14 +23781,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
23453
23781
|
disableParallelToolUse: true,
|
|
23454
23782
|
cacheControlValidator,
|
|
23455
23783
|
supportsStructuredOutput: false,
|
|
23456
|
-
supportsStrictTools
|
|
23784
|
+
supportsStrictTools,
|
|
23785
|
+
defaultEagerInputStreaming
|
|
23457
23786
|
} : {
|
|
23458
23787
|
tools: tools != null ? tools : [],
|
|
23459
23788
|
toolChoice,
|
|
23460
23789
|
disableParallelToolUse: anthropicOptions == null ? undefined : anthropicOptions.disableParallelToolUse,
|
|
23461
23790
|
cacheControlValidator,
|
|
23462
23791
|
supportsStructuredOutput,
|
|
23463
|
-
supportsStrictTools
|
|
23792
|
+
supportsStrictTools,
|
|
23793
|
+
defaultEagerInputStreaming
|
|
23464
23794
|
});
|
|
23465
23795
|
const cacheWarnings = cacheControlValidator.getWarnings();
|
|
23466
23796
|
return {
|
|
@@ -23475,7 +23805,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
23475
23805
|
...betas,
|
|
23476
23806
|
...toolsBetas,
|
|
23477
23807
|
...userSuppliedBetas,
|
|
23478
|
-
...(
|
|
23808
|
+
...(_j = anthropicOptions == null ? undefined : anthropicOptions.anthropicBeta) != null ? _j : []
|
|
23479
23809
|
]),
|
|
23480
23810
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
23481
23811
|
toolNameMapping,
|
|
@@ -24679,46 +25009,60 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
24679
25009
|
}
|
|
24680
25010
|
};
|
|
24681
25011
|
function getModelCapabilities(modelId) {
|
|
24682
|
-
if (modelId.includes("claude-
|
|
25012
|
+
if (modelId.includes("claude-opus-4-7")) {
|
|
25013
|
+
return {
|
|
25014
|
+
maxOutputTokens: 128000,
|
|
25015
|
+
supportsStructuredOutput: true,
|
|
25016
|
+
rejectsSamplingParameters: true,
|
|
25017
|
+
isKnownModel: true
|
|
25018
|
+
};
|
|
25019
|
+
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
24683
25020
|
return {
|
|
24684
25021
|
maxOutputTokens: 128000,
|
|
24685
25022
|
supportsStructuredOutput: true,
|
|
25023
|
+
rejectsSamplingParameters: false,
|
|
24686
25024
|
isKnownModel: true
|
|
24687
25025
|
};
|
|
24688
25026
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
24689
25027
|
return {
|
|
24690
25028
|
maxOutputTokens: 64000,
|
|
24691
25029
|
supportsStructuredOutput: true,
|
|
25030
|
+
rejectsSamplingParameters: false,
|
|
24692
25031
|
isKnownModel: true
|
|
24693
25032
|
};
|
|
24694
25033
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
24695
25034
|
return {
|
|
24696
25035
|
maxOutputTokens: 32000,
|
|
24697
25036
|
supportsStructuredOutput: true,
|
|
25037
|
+
rejectsSamplingParameters: false,
|
|
24698
25038
|
isKnownModel: true
|
|
24699
25039
|
};
|
|
24700
25040
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
24701
25041
|
return {
|
|
24702
25042
|
maxOutputTokens: 64000,
|
|
24703
25043
|
supportsStructuredOutput: false,
|
|
25044
|
+
rejectsSamplingParameters: false,
|
|
24704
25045
|
isKnownModel: true
|
|
24705
25046
|
};
|
|
24706
25047
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
24707
25048
|
return {
|
|
24708
25049
|
maxOutputTokens: 32000,
|
|
24709
25050
|
supportsStructuredOutput: false,
|
|
25051
|
+
rejectsSamplingParameters: false,
|
|
24710
25052
|
isKnownModel: true
|
|
24711
25053
|
};
|
|
24712
25054
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
24713
25055
|
return {
|
|
24714
25056
|
maxOutputTokens: 4096,
|
|
24715
25057
|
supportsStructuredOutput: false,
|
|
25058
|
+
rejectsSamplingParameters: false,
|
|
24716
25059
|
isKnownModel: true
|
|
24717
25060
|
};
|
|
24718
25061
|
} else {
|
|
24719
25062
|
return {
|
|
24720
25063
|
maxOutputTokens: 4096,
|
|
24721
25064
|
supportsStructuredOutput: false,
|
|
25065
|
+
rejectsSamplingParameters: false,
|
|
24722
25066
|
isKnownModel: false
|
|
24723
25067
|
};
|
|
24724
25068
|
}
|
|
@@ -25050,7 +25394,7 @@ function createAnthropic(options = {}) {
|
|
|
25050
25394
|
var anthropic = createAnthropic();
|
|
25051
25395
|
|
|
25052
25396
|
// node_modules/@ai-sdk/google/dist/index.mjs
|
|
25053
|
-
var VERSION3 = "3.0.
|
|
25397
|
+
var VERSION3 = "3.0.67";
|
|
25054
25398
|
var googleErrorDataSchema = lazySchema(() => zodSchema(exports_external.object({
|
|
25055
25399
|
error: exports_external.object({
|
|
25056
25400
|
code: exports_external.number().nullable(),
|
|
@@ -25692,8 +26036,14 @@ var googleLanguageModelOptions = lazySchema(() => zodSchema(exports_external.obj
|
|
|
25692
26036
|
longitude: exports_external.number()
|
|
25693
26037
|
}).optional()
|
|
25694
26038
|
}).optional(),
|
|
26039
|
+
streamFunctionCallArguments: exports_external.boolean().optional(),
|
|
25695
26040
|
serviceTier: exports_external.enum(["standard", "flex", "priority"]).optional()
|
|
25696
26041
|
})));
|
|
26042
|
+
var VertexServiceTierMap = {
|
|
26043
|
+
standard: "SERVICE_TIER_STANDARD",
|
|
26044
|
+
flex: "SERVICE_TIER_FLEX",
|
|
26045
|
+
priority: "SERVICE_TIER_PRIORITY"
|
|
26046
|
+
};
|
|
25697
26047
|
function prepareTools2({
|
|
25698
26048
|
tools,
|
|
25699
26049
|
toolChoice,
|
|
@@ -25766,7 +26116,7 @@ function prepareTools2({
|
|
|
25766
26116
|
toolWarnings.push({
|
|
25767
26117
|
type: "unsupported",
|
|
25768
26118
|
feature: `provider-defined tool ${tool2.id}`,
|
|
25769
|
-
details: "The code execution
|
|
26119
|
+
details: "The code execution tool is not supported with other Gemini models than Gemini 2."
|
|
25770
26120
|
});
|
|
25771
26121
|
}
|
|
25772
26122
|
break;
|
|
@@ -25941,6 +26291,172 @@ function prepareTools2({
|
|
|
25941
26291
|
}
|
|
25942
26292
|
}
|
|
25943
26293
|
}
|
|
26294
|
+
var GoogleJSONAccumulator = class {
|
|
26295
|
+
constructor() {
|
|
26296
|
+
this.accumulatedArgs = {};
|
|
26297
|
+
this.jsonText = "";
|
|
26298
|
+
this.pathStack = [];
|
|
26299
|
+
this.stringOpen = false;
|
|
26300
|
+
}
|
|
26301
|
+
processPartialArgs(partialArgs) {
|
|
26302
|
+
let delta = "";
|
|
26303
|
+
for (const arg of partialArgs) {
|
|
26304
|
+
const rawPath = arg.jsonPath.replace(/^\$\./, "");
|
|
26305
|
+
if (!rawPath)
|
|
26306
|
+
continue;
|
|
26307
|
+
const segments = parsePath(rawPath);
|
|
26308
|
+
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
26309
|
+
const isStringContinuation = arg.stringValue != null && existingValue !== undefined;
|
|
26310
|
+
if (isStringContinuation) {
|
|
26311
|
+
const escaped = JSON.stringify(arg.stringValue).slice(1, -1);
|
|
26312
|
+
setNestedValue(this.accumulatedArgs, segments, existingValue + arg.stringValue);
|
|
26313
|
+
delta += escaped;
|
|
26314
|
+
continue;
|
|
26315
|
+
}
|
|
26316
|
+
const resolved = resolvePartialArgValue(arg);
|
|
26317
|
+
if (resolved == null)
|
|
26318
|
+
continue;
|
|
26319
|
+
setNestedValue(this.accumulatedArgs, segments, resolved.value);
|
|
26320
|
+
delta += this.emitNavigationTo(segments, arg, resolved.json);
|
|
26321
|
+
}
|
|
26322
|
+
this.jsonText += delta;
|
|
26323
|
+
return {
|
|
26324
|
+
currentJSON: this.accumulatedArgs,
|
|
26325
|
+
textDelta: delta
|
|
26326
|
+
};
|
|
26327
|
+
}
|
|
26328
|
+
finalize() {
|
|
26329
|
+
const finalArgs = JSON.stringify(this.accumulatedArgs);
|
|
26330
|
+
const closingDelta = finalArgs.slice(this.jsonText.length);
|
|
26331
|
+
return { finalJSON: finalArgs, closingDelta };
|
|
26332
|
+
}
|
|
26333
|
+
ensureRoot() {
|
|
26334
|
+
if (this.pathStack.length === 0) {
|
|
26335
|
+
this.pathStack.push({ segment: "", isArray: false, childCount: 0 });
|
|
26336
|
+
return "{";
|
|
26337
|
+
}
|
|
26338
|
+
return "";
|
|
26339
|
+
}
|
|
26340
|
+
emitNavigationTo(targetSegments, arg, valueJson) {
|
|
26341
|
+
let fragment = "";
|
|
26342
|
+
if (this.stringOpen) {
|
|
26343
|
+
fragment += '"';
|
|
26344
|
+
this.stringOpen = false;
|
|
26345
|
+
}
|
|
26346
|
+
fragment += this.ensureRoot();
|
|
26347
|
+
const targetContainerSegments = targetSegments.slice(0, -1);
|
|
26348
|
+
const leafSegment = targetSegments[targetSegments.length - 1];
|
|
26349
|
+
const commonDepth = this.findCommonStackDepth(targetContainerSegments);
|
|
26350
|
+
fragment += this.closeDownTo(commonDepth);
|
|
26351
|
+
fragment += this.openDownTo(targetContainerSegments, leafSegment);
|
|
26352
|
+
fragment += this.emitLeaf(leafSegment, arg, valueJson);
|
|
26353
|
+
return fragment;
|
|
26354
|
+
}
|
|
26355
|
+
findCommonStackDepth(targetContainer) {
|
|
26356
|
+
const maxDepth = Math.min(this.pathStack.length - 1, targetContainer.length);
|
|
26357
|
+
let common = 0;
|
|
26358
|
+
for (let i = 0;i < maxDepth; i++) {
|
|
26359
|
+
if (this.pathStack[i + 1].segment === targetContainer[i]) {
|
|
26360
|
+
common++;
|
|
26361
|
+
} else {
|
|
26362
|
+
break;
|
|
26363
|
+
}
|
|
26364
|
+
}
|
|
26365
|
+
return common + 1;
|
|
26366
|
+
}
|
|
26367
|
+
closeDownTo(targetDepth) {
|
|
26368
|
+
let fragment = "";
|
|
26369
|
+
while (this.pathStack.length > targetDepth) {
|
|
26370
|
+
const entry = this.pathStack.pop();
|
|
26371
|
+
fragment += entry.isArray ? "]" : "}";
|
|
26372
|
+
}
|
|
26373
|
+
return fragment;
|
|
26374
|
+
}
|
|
26375
|
+
openDownTo(targetContainer, leafSegment) {
|
|
26376
|
+
let fragment = "";
|
|
26377
|
+
const startIdx = this.pathStack.length - 1;
|
|
26378
|
+
for (let i = startIdx;i < targetContainer.length; i++) {
|
|
26379
|
+
const seg = targetContainer[i];
|
|
26380
|
+
const parentEntry = this.pathStack[this.pathStack.length - 1];
|
|
26381
|
+
if (parentEntry.childCount > 0) {
|
|
26382
|
+
fragment += ",";
|
|
26383
|
+
}
|
|
26384
|
+
parentEntry.childCount++;
|
|
26385
|
+
if (typeof seg === "string") {
|
|
26386
|
+
fragment += `${JSON.stringify(seg)}:`;
|
|
26387
|
+
}
|
|
26388
|
+
const childSeg = i + 1 < targetContainer.length ? targetContainer[i + 1] : leafSegment;
|
|
26389
|
+
const isArray = typeof childSeg === "number";
|
|
26390
|
+
fragment += isArray ? "[" : "{";
|
|
26391
|
+
this.pathStack.push({ segment: seg, isArray, childCount: 0 });
|
|
26392
|
+
}
|
|
26393
|
+
return fragment;
|
|
26394
|
+
}
|
|
26395
|
+
emitLeaf(leafSegment, arg, valueJson) {
|
|
26396
|
+
let fragment = "";
|
|
26397
|
+
const container = this.pathStack[this.pathStack.length - 1];
|
|
26398
|
+
if (container.childCount > 0) {
|
|
26399
|
+
fragment += ",";
|
|
26400
|
+
}
|
|
26401
|
+
container.childCount++;
|
|
26402
|
+
if (typeof leafSegment === "string") {
|
|
26403
|
+
fragment += `${JSON.stringify(leafSegment)}:`;
|
|
26404
|
+
}
|
|
26405
|
+
if (arg.stringValue != null && arg.willContinue) {
|
|
26406
|
+
fragment += valueJson.slice(0, -1);
|
|
26407
|
+
this.stringOpen = true;
|
|
26408
|
+
} else {
|
|
26409
|
+
fragment += valueJson;
|
|
26410
|
+
}
|
|
26411
|
+
return fragment;
|
|
26412
|
+
}
|
|
26413
|
+
};
|
|
26414
|
+
function parsePath(rawPath) {
|
|
26415
|
+
const segments = [];
|
|
26416
|
+
for (const part of rawPath.split(".")) {
|
|
26417
|
+
const bracketIdx = part.indexOf("[");
|
|
26418
|
+
if (bracketIdx === -1) {
|
|
26419
|
+
segments.push(part);
|
|
26420
|
+
} else {
|
|
26421
|
+
if (bracketIdx > 0)
|
|
26422
|
+
segments.push(part.slice(0, bracketIdx));
|
|
26423
|
+
for (const m of part.matchAll(/\[(\d+)\]/g)) {
|
|
26424
|
+
segments.push(parseInt(m[1], 10));
|
|
26425
|
+
}
|
|
26426
|
+
}
|
|
26427
|
+
}
|
|
26428
|
+
return segments;
|
|
26429
|
+
}
|
|
26430
|
+
function getNestedValue(obj, segments) {
|
|
26431
|
+
let current = obj;
|
|
26432
|
+
for (const seg of segments) {
|
|
26433
|
+
if (current == null || typeof current !== "object")
|
|
26434
|
+
return;
|
|
26435
|
+
current = current[seg];
|
|
26436
|
+
}
|
|
26437
|
+
return current;
|
|
26438
|
+
}
|
|
26439
|
+
function setNestedValue(obj, segments, value) {
|
|
26440
|
+
let current = obj;
|
|
26441
|
+
for (let i = 0;i < segments.length - 1; i++) {
|
|
26442
|
+
const seg = segments[i];
|
|
26443
|
+
const nextSeg = segments[i + 1];
|
|
26444
|
+
if (current[seg] == null) {
|
|
26445
|
+
current[seg] = typeof nextSeg === "number" ? [] : {};
|
|
26446
|
+
}
|
|
26447
|
+
current = current[seg];
|
|
26448
|
+
}
|
|
26449
|
+
current[segments[segments.length - 1]] = value;
|
|
26450
|
+
}
|
|
26451
|
+
function resolvePartialArgValue(arg) {
|
|
26452
|
+
var _a16, _b16;
|
|
26453
|
+
const value = (_b16 = (_a16 = arg.stringValue) != null ? _a16 : arg.numberValue) != null ? _b16 : arg.boolValue;
|
|
26454
|
+
if (value != null)
|
|
26455
|
+
return { value, json: JSON.stringify(value) };
|
|
26456
|
+
if ("nullValue" in arg)
|
|
26457
|
+
return { value: null, json: "null" };
|
|
26458
|
+
return;
|
|
26459
|
+
}
|
|
25944
26460
|
function mapGoogleGenerativeAIFinishReason({
|
|
25945
26461
|
finishReason,
|
|
25946
26462
|
hasToolCalls
|
|
@@ -25994,8 +26510,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
25994
26510
|
tools,
|
|
25995
26511
|
toolChoice,
|
|
25996
26512
|
providerOptions
|
|
25997
|
-
}) {
|
|
25998
|
-
var _a16;
|
|
26513
|
+
}, { isStreaming = false } = {}) {
|
|
26514
|
+
var _a16, _b16;
|
|
25999
26515
|
const warnings = [];
|
|
26000
26516
|
const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
|
|
26001
26517
|
let googleOptions = await parseProviderOptions({
|
|
@@ -26010,12 +26526,23 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
26010
26526
|
schema: googleLanguageModelOptions
|
|
26011
26527
|
});
|
|
26012
26528
|
}
|
|
26013
|
-
|
|
26529
|
+
const isVertexProvider = this.config.provider.startsWith("google.vertex.");
|
|
26530
|
+
if ((tools == null ? undefined : tools.some((tool2) => tool2.type === "provider" && tool2.id === "google.vertex_rag_store")) && !isVertexProvider) {
|
|
26014
26531
|
warnings.push({
|
|
26015
26532
|
type: "other",
|
|
26016
26533
|
message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
|
|
26017
26534
|
});
|
|
26018
26535
|
}
|
|
26536
|
+
if ((googleOptions == null ? undefined : googleOptions.streamFunctionCallArguments) && !isVertexProvider) {
|
|
26537
|
+
warnings.push({
|
|
26538
|
+
type: "other",
|
|
26539
|
+
message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${this.config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
|
|
26540
|
+
});
|
|
26541
|
+
}
|
|
26542
|
+
let sanitizedServiceTier = googleOptions == null ? undefined : googleOptions.serviceTier;
|
|
26543
|
+
if ((googleOptions == null ? undefined : googleOptions.serviceTier) && isVertexProvider) {
|
|
26544
|
+
sanitizedServiceTier = VertexServiceTierMap[googleOptions.serviceTier];
|
|
26545
|
+
}
|
|
26019
26546
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
26020
26547
|
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
26021
26548
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(prompt, {
|
|
@@ -26032,6 +26559,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
26032
26559
|
toolChoice,
|
|
26033
26560
|
modelId: this.modelId
|
|
26034
26561
|
});
|
|
26562
|
+
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a16 = googleOptions == null ? undefined : googleOptions.streamFunctionCallArguments) != null ? _a16 : false : undefined;
|
|
26563
|
+
const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? undefined : googleOptions.retrievalConfig) ? {
|
|
26564
|
+
...googleToolConfig,
|
|
26565
|
+
...streamFunctionCallArguments && {
|
|
26566
|
+
functionCallingConfig: {
|
|
26567
|
+
...googleToolConfig == null ? undefined : googleToolConfig.functionCallingConfig,
|
|
26568
|
+
streamFunctionCallArguments: true
|
|
26569
|
+
}
|
|
26570
|
+
},
|
|
26571
|
+
...(googleOptions == null ? undefined : googleOptions.retrievalConfig) && {
|
|
26572
|
+
retrievalConfig: googleOptions.retrievalConfig
|
|
26573
|
+
}
|
|
26574
|
+
} : undefined;
|
|
26035
26575
|
return {
|
|
26036
26576
|
args: {
|
|
26037
26577
|
generationConfig: {
|
|
@@ -26044,7 +26584,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
26044
26584
|
stopSequences,
|
|
26045
26585
|
seed,
|
|
26046
26586
|
responseMimeType: (responseFormat == null ? undefined : responseFormat.type) === "json" ? "application/json" : undefined,
|
|
26047
|
-
responseSchema: (responseFormat == null ? undefined : responseFormat.type) === "json" && responseFormat.schema != null && ((
|
|
26587
|
+
responseSchema: (responseFormat == null ? undefined : responseFormat.type) === "json" && responseFormat.schema != null && ((_b16 = googleOptions == null ? undefined : googleOptions.structuredOutputs) != null ? _b16 : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : undefined,
|
|
26048
26588
|
...(googleOptions == null ? undefined : googleOptions.audioTimestamp) && {
|
|
26049
26589
|
audioTimestamp: googleOptions.audioTimestamp
|
|
26050
26590
|
},
|
|
@@ -26061,13 +26601,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
26061
26601
|
systemInstruction: isGemmaModel ? undefined : systemInstruction,
|
|
26062
26602
|
safetySettings: googleOptions == null ? undefined : googleOptions.safetySettings,
|
|
26063
26603
|
tools: googleTools2,
|
|
26064
|
-
toolConfig
|
|
26065
|
-
...googleToolConfig,
|
|
26066
|
-
retrievalConfig: googleOptions.retrievalConfig
|
|
26067
|
-
} : googleToolConfig,
|
|
26604
|
+
toolConfig,
|
|
26068
26605
|
cachedContent: googleOptions == null ? undefined : googleOptions.cachedContent,
|
|
26069
26606
|
labels: googleOptions == null ? undefined : googleOptions.labels,
|
|
26070
|
-
serviceTier:
|
|
26607
|
+
serviceTier: sanitizedServiceTier
|
|
26071
26608
|
},
|
|
26072
26609
|
warnings: [...warnings, ...toolWarnings],
|
|
26073
26610
|
providerOptionsName
|
|
@@ -26136,7 +26673,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
26136
26673
|
providerMetadata: thoughtSignatureMetadata
|
|
26137
26674
|
});
|
|
26138
26675
|
}
|
|
26139
|
-
} else if ("functionCall" in part) {
|
|
26676
|
+
} else if ("functionCall" in part && part.functionCall.name != null && part.functionCall.args != null) {
|
|
26140
26677
|
content.push({
|
|
26141
26678
|
type: "tool-call",
|
|
26142
26679
|
toolCallId: this.config.generateId(),
|
|
@@ -26245,7 +26782,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
26245
26782
|
};
|
|
26246
26783
|
}
|
|
26247
26784
|
async doStream(options) {
|
|
26248
|
-
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
26785
|
+
const { args, warnings, providerOptionsName } = await this.getArgs(options, { isStreaming: true });
|
|
26249
26786
|
const headers = combineHeaders(await resolve(this.config.headers), options.headers);
|
|
26250
26787
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
26251
26788
|
url: `${this.config.baseURL}/${getModelPath(this.modelId)}:streamGenerateContent?alt=sse`,
|
|
@@ -26273,13 +26810,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
26273
26810
|
const emittedSourceUrls = /* @__PURE__ */ new Set;
|
|
26274
26811
|
let lastCodeExecutionToolCallId;
|
|
26275
26812
|
let lastServerToolCallId;
|
|
26813
|
+
const activeStreamingToolCalls = [];
|
|
26276
26814
|
return {
|
|
26277
26815
|
stream: response.pipeThrough(new TransformStream({
|
|
26278
26816
|
start(controller) {
|
|
26279
26817
|
controller.enqueue({ type: "stream-start", warnings });
|
|
26280
26818
|
},
|
|
26281
26819
|
transform(chunk, controller) {
|
|
26282
|
-
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
26820
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
26283
26821
|
if (options.includeRawChunks) {
|
|
26284
26822
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
26285
26823
|
}
|
|
@@ -26472,36 +27010,107 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
26472
27010
|
lastServerToolCallId = undefined;
|
|
26473
27011
|
}
|
|
26474
27012
|
}
|
|
26475
|
-
const
|
|
26476
|
-
|
|
26477
|
-
|
|
26478
|
-
|
|
26479
|
-
|
|
26480
|
-
|
|
26481
|
-
|
|
27013
|
+
for (const part of parts) {
|
|
27014
|
+
if (!("functionCall" in part))
|
|
27015
|
+
continue;
|
|
27016
|
+
const providerMeta = part.thoughtSignature ? {
|
|
27017
|
+
[providerOptionsName]: {
|
|
27018
|
+
thoughtSignature: part.thoughtSignature
|
|
27019
|
+
}
|
|
27020
|
+
} : undefined;
|
|
27021
|
+
const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
|
|
27022
|
+
const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
|
|
27023
|
+
const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
|
|
27024
|
+
if (isStreamingChunk) {
|
|
27025
|
+
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
27026
|
+
const toolCallId = generateId3();
|
|
27027
|
+
const accumulator = new GoogleJSONAccumulator;
|
|
27028
|
+
activeStreamingToolCalls.push({
|
|
27029
|
+
toolCallId,
|
|
27030
|
+
toolName: part.functionCall.name,
|
|
27031
|
+
accumulator,
|
|
27032
|
+
providerMetadata: providerMeta
|
|
27033
|
+
});
|
|
27034
|
+
controller.enqueue({
|
|
27035
|
+
type: "tool-input-start",
|
|
27036
|
+
id: toolCallId,
|
|
27037
|
+
toolName: part.functionCall.name,
|
|
27038
|
+
providerMetadata: providerMeta
|
|
27039
|
+
});
|
|
27040
|
+
if (part.functionCall.partialArgs != null) {
|
|
27041
|
+
const { textDelta } = accumulator.processPartialArgs(part.functionCall.partialArgs);
|
|
27042
|
+
if (textDelta.length > 0) {
|
|
27043
|
+
controller.enqueue({
|
|
27044
|
+
type: "tool-input-delta",
|
|
27045
|
+
id: toolCallId,
|
|
27046
|
+
delta: textDelta,
|
|
27047
|
+
providerMetadata: providerMeta
|
|
27048
|
+
});
|
|
27049
|
+
}
|
|
27050
|
+
}
|
|
27051
|
+
} else if (part.functionCall.partialArgs != null && activeStreamingToolCalls.length > 0) {
|
|
27052
|
+
const active = activeStreamingToolCalls[activeStreamingToolCalls.length - 1];
|
|
27053
|
+
const { textDelta } = active.accumulator.processPartialArgs(part.functionCall.partialArgs);
|
|
27054
|
+
if (textDelta.length > 0) {
|
|
27055
|
+
controller.enqueue({
|
|
27056
|
+
type: "tool-input-delta",
|
|
27057
|
+
id: active.toolCallId,
|
|
27058
|
+
delta: textDelta,
|
|
27059
|
+
providerMetadata: providerMeta
|
|
27060
|
+
});
|
|
27061
|
+
}
|
|
27062
|
+
}
|
|
27063
|
+
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
27064
|
+
const active = activeStreamingToolCalls.pop();
|
|
27065
|
+
const { finalJSON, closingDelta } = active.accumulator.finalize();
|
|
27066
|
+
if (closingDelta.length > 0) {
|
|
27067
|
+
controller.enqueue({
|
|
27068
|
+
type: "tool-input-delta",
|
|
27069
|
+
id: active.toolCallId,
|
|
27070
|
+
delta: closingDelta,
|
|
27071
|
+
providerMetadata: active.providerMetadata
|
|
27072
|
+
});
|
|
27073
|
+
}
|
|
27074
|
+
controller.enqueue({
|
|
27075
|
+
type: "tool-input-end",
|
|
27076
|
+
id: active.toolCallId,
|
|
27077
|
+
providerMetadata: active.providerMetadata
|
|
27078
|
+
});
|
|
27079
|
+
controller.enqueue({
|
|
27080
|
+
type: "tool-call",
|
|
27081
|
+
toolCallId: active.toolCallId,
|
|
27082
|
+
toolName: active.toolName,
|
|
27083
|
+
input: finalJSON,
|
|
27084
|
+
providerMetadata: active.providerMetadata
|
|
27085
|
+
});
|
|
27086
|
+
hasToolCalls = true;
|
|
27087
|
+
} else if (isCompleteCall) {
|
|
27088
|
+
const toolCallId = generateId3();
|
|
27089
|
+
const toolName = part.functionCall.name;
|
|
27090
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_i = part.functionCall.args) != null ? _i : {});
|
|
26482
27091
|
controller.enqueue({
|
|
26483
27092
|
type: "tool-input-start",
|
|
26484
|
-
id:
|
|
26485
|
-
toolName
|
|
26486
|
-
providerMetadata:
|
|
27093
|
+
id: toolCallId,
|
|
27094
|
+
toolName,
|
|
27095
|
+
providerMetadata: providerMeta
|
|
26487
27096
|
});
|
|
26488
27097
|
controller.enqueue({
|
|
26489
27098
|
type: "tool-input-delta",
|
|
26490
|
-
id:
|
|
26491
|
-
delta:
|
|
26492
|
-
providerMetadata:
|
|
27099
|
+
id: toolCallId,
|
|
27100
|
+
delta: args2,
|
|
27101
|
+
providerMetadata: providerMeta
|
|
26493
27102
|
});
|
|
26494
27103
|
controller.enqueue({
|
|
26495
27104
|
type: "tool-input-end",
|
|
26496
|
-
id:
|
|
26497
|
-
providerMetadata:
|
|
27105
|
+
id: toolCallId,
|
|
27106
|
+
providerMetadata: providerMeta
|
|
26498
27107
|
});
|
|
26499
27108
|
controller.enqueue({
|
|
26500
27109
|
type: "tool-call",
|
|
26501
|
-
toolCallId
|
|
26502
|
-
toolName
|
|
26503
|
-
input:
|
|
26504
|
-
providerMetadata:
|
|
27110
|
+
toolCallId,
|
|
27111
|
+
toolName,
|
|
27112
|
+
input: args2,
|
|
27113
|
+
providerMetadata: providerMeta
|
|
26505
27114
|
});
|
|
26506
27115
|
hasToolCalls = true;
|
|
26507
27116
|
}
|
|
@@ -26517,12 +27126,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
26517
27126
|
};
|
|
26518
27127
|
providerMetadata = {
|
|
26519
27128
|
[providerOptionsName]: {
|
|
26520
|
-
promptFeedback: (
|
|
27129
|
+
promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
|
|
26521
27130
|
groundingMetadata: lastGroundingMetadata,
|
|
26522
27131
|
urlContextMetadata: lastUrlContextMetadata,
|
|
26523
|
-
safetyRatings: (
|
|
27132
|
+
safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
|
|
26524
27133
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
26525
|
-
finishMessage: (
|
|
27134
|
+
finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
|
|
26526
27135
|
serviceTier
|
|
26527
27136
|
}
|
|
26528
27137
|
};
|
|
@@ -26554,24 +27163,6 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
26554
27163
|
};
|
|
26555
27164
|
}
|
|
26556
27165
|
};
|
|
26557
|
-
function getToolCallsFromParts({
|
|
26558
|
-
parts,
|
|
26559
|
-
generateId: generateId3,
|
|
26560
|
-
providerOptionsName
|
|
26561
|
-
}) {
|
|
26562
|
-
const functionCallParts = parts == null ? undefined : parts.filter((part) => ("functionCall" in part));
|
|
26563
|
-
return functionCallParts == null || functionCallParts.length === 0 ? undefined : functionCallParts.map((part) => ({
|
|
26564
|
-
type: "tool-call",
|
|
26565
|
-
toolCallId: generateId3(),
|
|
26566
|
-
toolName: part.functionCall.name,
|
|
26567
|
-
args: JSON.stringify(part.functionCall.args),
|
|
26568
|
-
providerMetadata: part.thoughtSignature ? {
|
|
26569
|
-
[providerOptionsName]: {
|
|
26570
|
-
thoughtSignature: part.thoughtSignature
|
|
26571
|
-
}
|
|
26572
|
-
} : undefined
|
|
26573
|
-
}));
|
|
26574
|
-
}
|
|
26575
27166
|
function extractSources({
|
|
26576
27167
|
groundingMetadata,
|
|
26577
27168
|
generateId: generateId3
|
|
@@ -26709,12 +27300,22 @@ var getGroundingMetadataSchema = () => exports_external.object({
|
|
|
26709
27300
|
exports_external.object({})
|
|
26710
27301
|
]).nullish()
|
|
26711
27302
|
});
|
|
27303
|
+
var partialArgSchema = exports_external.object({
|
|
27304
|
+
jsonPath: exports_external.string(),
|
|
27305
|
+
stringValue: exports_external.string().nullish(),
|
|
27306
|
+
numberValue: exports_external.number().nullish(),
|
|
27307
|
+
boolValue: exports_external.boolean().nullish(),
|
|
27308
|
+
nullValue: exports_external.unknown().nullish(),
|
|
27309
|
+
willContinue: exports_external.boolean().nullish()
|
|
27310
|
+
});
|
|
26712
27311
|
var getContentSchema = () => exports_external.object({
|
|
26713
27312
|
parts: exports_external.array(exports_external.union([
|
|
26714
27313
|
exports_external.object({
|
|
26715
27314
|
functionCall: exports_external.object({
|
|
26716
|
-
name: exports_external.string(),
|
|
26717
|
-
args: exports_external.unknown()
|
|
27315
|
+
name: exports_external.string().nullish(),
|
|
27316
|
+
args: exports_external.unknown().nullish(),
|
|
27317
|
+
partialArgs: exports_external.array(partialArgSchema).nullish(),
|
|
27318
|
+
willContinue: exports_external.boolean().nullish()
|
|
26718
27319
|
}),
|
|
26719
27320
|
thoughtSignature: exports_external.string().nullish()
|
|
26720
27321
|
}),
|
|
@@ -26765,13 +27366,19 @@ var getSafetyRatingSchema = () => exports_external.object({
|
|
|
26765
27366
|
severityScore: exports_external.number().nullish(),
|
|
26766
27367
|
blocked: exports_external.boolean().nullish()
|
|
26767
27368
|
});
|
|
27369
|
+
var tokenDetailsSchema = exports_external.array(exports_external.object({
|
|
27370
|
+
modality: exports_external.string(),
|
|
27371
|
+
tokenCount: exports_external.number()
|
|
27372
|
+
})).nullish();
|
|
26768
27373
|
var usageSchema = exports_external.object({
|
|
26769
27374
|
cachedContentTokenCount: exports_external.number().nullish(),
|
|
26770
27375
|
thoughtsTokenCount: exports_external.number().nullish(),
|
|
26771
27376
|
promptTokenCount: exports_external.number().nullish(),
|
|
26772
27377
|
candidatesTokenCount: exports_external.number().nullish(),
|
|
26773
27378
|
totalTokenCount: exports_external.number().nullish(),
|
|
26774
|
-
trafficType: exports_external.string().nullish()
|
|
27379
|
+
trafficType: exports_external.string().nullish(),
|
|
27380
|
+
promptTokensDetails: tokenDetailsSchema,
|
|
27381
|
+
candidatesTokensDetails: tokenDetailsSchema
|
|
26775
27382
|
});
|
|
26776
27383
|
var getUrlContextMetadataSchema = () => exports_external.object({
|
|
26777
27384
|
urlMetadata: exports_external.array(exports_external.object({
|
|
@@ -27457,6 +28064,9 @@ function convertOpenAIChatUsage(usage) {
|
|
|
27457
28064
|
raw: usage
|
|
27458
28065
|
};
|
|
27459
28066
|
}
|
|
28067
|
+
function serializeToolCallArguments(input) {
|
|
28068
|
+
return JSON.stringify(input === undefined ? {} : input);
|
|
28069
|
+
}
|
|
27460
28070
|
function convertToOpenAIChatMessages({
|
|
27461
28071
|
prompt,
|
|
27462
28072
|
systemMessageMode = "system"
|
|
@@ -27584,7 +28194,7 @@ function convertToOpenAIChatMessages({
|
|
|
27584
28194
|
type: "function",
|
|
27585
28195
|
function: {
|
|
27586
28196
|
name: part.toolName,
|
|
27587
|
-
arguments:
|
|
28197
|
+
arguments: serializeToolCallArguments(part.input)
|
|
27588
28198
|
}
|
|
27589
28199
|
});
|
|
27590
28200
|
break;
|
|
@@ -27593,7 +28203,7 @@ function convertToOpenAIChatMessages({
|
|
|
27593
28203
|
}
|
|
27594
28204
|
messages.push({
|
|
27595
28205
|
role: "assistant",
|
|
27596
|
-
content: text,
|
|
28206
|
+
content: text || null,
|
|
27597
28207
|
tool_calls: toolCalls.length > 0 ? toolCalls : undefined
|
|
27598
28208
|
});
|
|
27599
28209
|
break;
|
|
@@ -28808,17 +29418,34 @@ var modelMaxImagesPerCall = {
|
|
|
28808
29418
|
"gpt-image-1": 10,
|
|
28809
29419
|
"gpt-image-1-mini": 10,
|
|
28810
29420
|
"gpt-image-1.5": 10,
|
|
29421
|
+
"gpt-image-2": 10,
|
|
28811
29422
|
"chatgpt-image-latest": 10
|
|
28812
29423
|
};
|
|
28813
29424
|
var defaultResponseFormatPrefixes = [
|
|
28814
29425
|
"chatgpt-image-",
|
|
28815
29426
|
"gpt-image-1-mini",
|
|
28816
29427
|
"gpt-image-1.5",
|
|
28817
|
-
"gpt-image-1"
|
|
29428
|
+
"gpt-image-1",
|
|
29429
|
+
"gpt-image-2"
|
|
28818
29430
|
];
|
|
28819
29431
|
function hasDefaultResponseFormat(modelId) {
|
|
28820
29432
|
return defaultResponseFormatPrefixes.some((prefix) => modelId.startsWith(prefix));
|
|
28821
29433
|
}
|
|
29434
|
+
var baseImageModelOptionsObject = exports_external.object({
|
|
29435
|
+
quality: exports_external.enum(["standard", "hd", "low", "medium", "high", "auto"]).optional(),
|
|
29436
|
+
background: exports_external.enum(["transparent", "opaque", "auto"]).optional(),
|
|
29437
|
+
outputFormat: exports_external.enum(["png", "jpeg", "webp"]).optional(),
|
|
29438
|
+
outputCompression: exports_external.number().int().min(0).max(100).optional(),
|
|
29439
|
+
user: exports_external.string().optional()
|
|
29440
|
+
});
|
|
29441
|
+
var openaiImageModelOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject));
|
|
29442
|
+
var openaiImageModelGenerationOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject.extend({
|
|
29443
|
+
style: exports_external.enum(["vivid", "natural"]).optional(),
|
|
29444
|
+
moderation: exports_external.enum(["auto", "low"]).optional()
|
|
29445
|
+
})));
|
|
29446
|
+
var openaiImageModelEditOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject.extend({
|
|
29447
|
+
inputFidelity: exports_external.enum(["high", "low"]).optional()
|
|
29448
|
+
})));
|
|
28822
29449
|
var OpenAIImageModel = class {
|
|
28823
29450
|
constructor(modelId, config2) {
|
|
28824
29451
|
this.modelId = modelId;
|
|
@@ -28858,6 +29485,11 @@ var OpenAIImageModel = class {
|
|
|
28858
29485
|
}
|
|
28859
29486
|
const currentDate = (_c = (_b16 = (_a16 = this.config._internal) == null ? undefined : _a16.currentDate) == null ? undefined : _b16.call(_a16)) != null ? _c : /* @__PURE__ */ new Date;
|
|
28860
29487
|
if (files != null) {
|
|
29488
|
+
const openaiOptions2 = (_d = await parseProviderOptions({
|
|
29489
|
+
provider: "openai",
|
|
29490
|
+
providerOptions,
|
|
29491
|
+
schema: openaiImageModelEditOptions
|
|
29492
|
+
})) != null ? _d : {};
|
|
28861
29493
|
const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi({
|
|
28862
29494
|
url: this.config.url({
|
|
28863
29495
|
path: "/images/edits",
|
|
@@ -28877,7 +29509,12 @@ var OpenAIImageModel = class {
|
|
|
28877
29509
|
mask: mask != null ? await fileToBlob(mask) : undefined,
|
|
28878
29510
|
n,
|
|
28879
29511
|
size,
|
|
28880
|
-
|
|
29512
|
+
quality: openaiOptions2.quality,
|
|
29513
|
+
background: openaiOptions2.background,
|
|
29514
|
+
output_format: openaiOptions2.outputFormat,
|
|
29515
|
+
output_compression: openaiOptions2.outputCompression,
|
|
29516
|
+
input_fidelity: openaiOptions2.inputFidelity,
|
|
29517
|
+
user: openaiOptions2.user
|
|
28881
29518
|
}),
|
|
28882
29519
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
28883
29520
|
successfulResponseHandler: createJsonResponseHandler(openaiImageResponseSchema),
|
|
@@ -28915,6 +29552,11 @@ var OpenAIImageModel = class {
|
|
|
28915
29552
|
}
|
|
28916
29553
|
};
|
|
28917
29554
|
}
|
|
29555
|
+
const openaiOptions = (_h = await parseProviderOptions({
|
|
29556
|
+
provider: "openai",
|
|
29557
|
+
providerOptions,
|
|
29558
|
+
schema: openaiImageModelGenerationOptions
|
|
29559
|
+
})) != null ? _h : {};
|
|
28918
29560
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
28919
29561
|
url: this.config.url({
|
|
28920
29562
|
path: "/images/generations",
|
|
@@ -28926,7 +29568,13 @@ var OpenAIImageModel = class {
|
|
|
28926
29568
|
prompt,
|
|
28927
29569
|
n,
|
|
28928
29570
|
size,
|
|
28929
|
-
|
|
29571
|
+
quality: openaiOptions.quality,
|
|
29572
|
+
style: openaiOptions.style,
|
|
29573
|
+
background: openaiOptions.background,
|
|
29574
|
+
moderation: openaiOptions.moderation,
|
|
29575
|
+
output_format: openaiOptions.outputFormat,
|
|
29576
|
+
output_compression: openaiOptions.outputCompression,
|
|
29577
|
+
user: openaiOptions.user,
|
|
28930
29578
|
...!hasDefaultResponseFormat(this.modelId) ? { response_format: "b64_json" } : {}
|
|
28931
29579
|
},
|
|
28932
29580
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
@@ -29402,6 +30050,9 @@ function convertOpenAIResponsesUsage(usage) {
|
|
|
29402
30050
|
raw: usage
|
|
29403
30051
|
};
|
|
29404
30052
|
}
|
|
30053
|
+
function serializeToolCallArguments2(input) {
|
|
30054
|
+
return JSON.stringify(input === undefined ? {} : input);
|
|
30055
|
+
}
|
|
29405
30056
|
function isFileId(data, prefixes) {
|
|
29406
30057
|
if (!prefixes)
|
|
29407
30058
|
return false;
|
|
@@ -29622,7 +30273,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
29622
30273
|
type: "function_call",
|
|
29623
30274
|
call_id: part.toolCallId,
|
|
29624
30275
|
name: resolvedToolName,
|
|
29625
|
-
arguments:
|
|
30276
|
+
arguments: serializeToolCallArguments2(part.input),
|
|
29626
30277
|
id
|
|
29627
30278
|
});
|
|
29628
30279
|
break;
|
|
@@ -30090,7 +30741,8 @@ var openaiResponsesChunkSchema = lazySchema(() => zodSchema(exports_external.uni
|
|
|
30090
30741
|
id: exports_external.string(),
|
|
30091
30742
|
call_id: exports_external.string(),
|
|
30092
30743
|
name: exports_external.string(),
|
|
30093
|
-
arguments: exports_external.string()
|
|
30744
|
+
arguments: exports_external.string(),
|
|
30745
|
+
namespace: exports_external.string().nullish()
|
|
30094
30746
|
}),
|
|
30095
30747
|
exports_external.object({
|
|
30096
30748
|
type: exports_external.literal("web_search_call"),
|
|
@@ -30228,7 +30880,8 @@ var openaiResponsesChunkSchema = lazySchema(() => zodSchema(exports_external.uni
|
|
|
30228
30880
|
call_id: exports_external.string(),
|
|
30229
30881
|
name: exports_external.string(),
|
|
30230
30882
|
arguments: exports_external.string(),
|
|
30231
|
-
status: exports_external.literal("completed")
|
|
30883
|
+
status: exports_external.literal("completed"),
|
|
30884
|
+
namespace: exports_external.string().nullish()
|
|
30232
30885
|
}),
|
|
30233
30886
|
exports_external.object({
|
|
30234
30887
|
type: exports_external.literal("custom_tool_call"),
|
|
@@ -30652,7 +31305,8 @@ var openaiResponsesResponseSchema = lazySchema(() => zodSchema(exports_external.
|
|
|
30652
31305
|
call_id: exports_external.string(),
|
|
30653
31306
|
name: exports_external.string(),
|
|
30654
31307
|
arguments: exports_external.string(),
|
|
30655
|
-
id: exports_external.string()
|
|
31308
|
+
id: exports_external.string(),
|
|
31309
|
+
namespace: exports_external.string().nullish()
|
|
30656
31310
|
}),
|
|
30657
31311
|
exports_external.object({
|
|
30658
31312
|
type: exports_external.literal("custom_tool_call"),
|
|
@@ -31682,7 +32336,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
31682
32336
|
input: part.arguments,
|
|
31683
32337
|
providerMetadata: {
|
|
31684
32338
|
[providerOptionsName]: {
|
|
31685
|
-
itemId: part.id
|
|
32339
|
+
itemId: part.id,
|
|
32340
|
+
...part.namespace != null && { namespace: part.namespace }
|
|
31686
32341
|
}
|
|
31687
32342
|
}
|
|
31688
32343
|
});
|
|
@@ -32146,7 +32801,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
32146
32801
|
hasFunctionCall = true;
|
|
32147
32802
|
controller.enqueue({
|
|
32148
32803
|
type: "tool-input-end",
|
|
32149
|
-
id: value.item.call_id
|
|
32804
|
+
id: value.item.call_id,
|
|
32805
|
+
...value.item.namespace != null && {
|
|
32806
|
+
providerMetadata: {
|
|
32807
|
+
[providerOptionsName]: {
|
|
32808
|
+
namespace: value.item.namespace
|
|
32809
|
+
}
|
|
32810
|
+
}
|
|
32811
|
+
}
|
|
32150
32812
|
});
|
|
32151
32813
|
controller.enqueue({
|
|
32152
32814
|
type: "tool-call",
|
|
@@ -32155,7 +32817,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
32155
32817
|
input: value.item.arguments,
|
|
32156
32818
|
providerMetadata: {
|
|
32157
32819
|
[providerOptionsName]: {
|
|
32158
|
-
itemId: value.item.id
|
|
32820
|
+
itemId: value.item.id,
|
|
32821
|
+
...value.item.namespace != null && {
|
|
32822
|
+
namespace: value.item.namespace
|
|
32823
|
+
}
|
|
32159
32824
|
}
|
|
32160
32825
|
}
|
|
32161
32826
|
});
|
|
@@ -33085,7 +33750,7 @@ var OpenAITranscriptionModel = class {
|
|
|
33085
33750
|
};
|
|
33086
33751
|
}
|
|
33087
33752
|
};
|
|
33088
|
-
var VERSION4 = "3.0.
|
|
33753
|
+
var VERSION4 = "3.0.58";
|
|
33089
33754
|
function createOpenAI(options = {}) {
|
|
33090
33755
|
var _a16, _b16;
|
|
33091
33756
|
const baseURL = (_a16 = withoutTrailingSlash(loadOptionalSetting({
|
|
@@ -33178,6 +33843,16 @@ function createOpenAI(options = {}) {
|
|
|
33178
33843
|
var openai = createOpenAI();
|
|
33179
33844
|
|
|
33180
33845
|
// node_modules/@ai-sdk/openai-compatible/dist/index.mjs
|
|
33846
|
+
function toCamelCase(str) {
|
|
33847
|
+
return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
|
|
33848
|
+
}
|
|
33849
|
+
function resolveProviderOptionsKey(rawName, providerOptions) {
|
|
33850
|
+
const camelName = toCamelCase(rawName);
|
|
33851
|
+
if (camelName !== rawName && (providerOptions == null ? undefined : providerOptions[camelName]) != null) {
|
|
33852
|
+
return camelName;
|
|
33853
|
+
}
|
|
33854
|
+
return rawName;
|
|
33855
|
+
}
|
|
33181
33856
|
var openaiCompatibleErrorDataSchema = exports_external.object({
|
|
33182
33857
|
error: exports_external.object({
|
|
33183
33858
|
message: exports_external.string(),
|
|
@@ -33374,7 +34049,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
33374
34049
|
}
|
|
33375
34050
|
messages.push({
|
|
33376
34051
|
role: "assistant",
|
|
33377
|
-
content: text,
|
|
34052
|
+
content: text || null,
|
|
33378
34053
|
...reasoning.length > 0 ? { reasoning_content: reasoning } : {},
|
|
33379
34054
|
tool_calls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
33380
34055
|
...metadata
|
|
@@ -33531,6 +34206,10 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
33531
34206
|
var _a16, _b16, _c;
|
|
33532
34207
|
return (_c = (_b16 = (_a16 = this.config).transformRequestBody) == null ? undefined : _b16.call(_a16, args)) != null ? _c : args;
|
|
33533
34208
|
}
|
|
34209
|
+
convertUsage(usage) {
|
|
34210
|
+
var _a16, _b16, _c;
|
|
34211
|
+
return (_c = (_b16 = (_a16 = this.config).convertUsage) == null ? undefined : _b16.call(_a16, usage)) != null ? _c : convertOpenAICompatibleChatUsage(usage);
|
|
34212
|
+
}
|
|
33534
34213
|
async getArgs({
|
|
33535
34214
|
prompt,
|
|
33536
34215
|
maxOutputTokens,
|
|
@@ -33567,8 +34246,12 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
33567
34246
|
provider: this.providerOptionsName,
|
|
33568
34247
|
providerOptions,
|
|
33569
34248
|
schema: openaiCompatibleLanguageModelChatOptions
|
|
33570
|
-
})) != null ? _b16 : {}
|
|
33571
|
-
|
|
34249
|
+
})) != null ? _b16 : {}, (_c = await parseProviderOptions({
|
|
34250
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
34251
|
+
providerOptions,
|
|
34252
|
+
schema: openaiCompatibleLanguageModelChatOptions
|
|
34253
|
+
})) != null ? _c : {});
|
|
34254
|
+
const strictJsonSchema = (_d = compatibleOptions == null ? undefined : compatibleOptions.strictJsonSchema) != null ? _d : true;
|
|
33572
34255
|
if (topK != null) {
|
|
33573
34256
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
33574
34257
|
}
|
|
@@ -33587,7 +34270,9 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
33587
34270
|
tools,
|
|
33588
34271
|
toolChoice
|
|
33589
34272
|
});
|
|
34273
|
+
const metadataKey = resolveProviderOptionsKey(this.providerOptionsName, providerOptions);
|
|
33590
34274
|
return {
|
|
34275
|
+
metadataKey,
|
|
33591
34276
|
args: {
|
|
33592
34277
|
model: this.modelId,
|
|
33593
34278
|
user: compatibleOptions.user,
|
|
@@ -33601,13 +34286,16 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
33601
34286
|
json_schema: {
|
|
33602
34287
|
schema: responseFormat.schema,
|
|
33603
34288
|
strict: strictJsonSchema,
|
|
33604
|
-
name: (
|
|
34289
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
33605
34290
|
description: responseFormat.description
|
|
33606
34291
|
}
|
|
33607
34292
|
} : { type: "json_object" } : undefined,
|
|
33608
34293
|
stop: stopSequences,
|
|
33609
34294
|
seed,
|
|
33610
|
-
...Object.fromEntries(Object.entries(
|
|
34295
|
+
...Object.fromEntries(Object.entries({
|
|
34296
|
+
...providerOptions == null ? undefined : providerOptions[this.providerOptionsName],
|
|
34297
|
+
...providerOptions == null ? undefined : providerOptions[toCamelCase(this.providerOptionsName)]
|
|
34298
|
+
}).filter(([key]) => !Object.keys(openaiCompatibleLanguageModelChatOptions.shape).includes(key))),
|
|
33611
34299
|
reasoning_effort: compatibleOptions.reasoningEffort,
|
|
33612
34300
|
verbosity: compatibleOptions.textVerbosity,
|
|
33613
34301
|
messages: convertToOpenAICompatibleChatMessages(prompt),
|
|
@@ -33619,7 +34307,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
33619
34307
|
}
|
|
33620
34308
|
async doGenerate(options) {
|
|
33621
34309
|
var _a16, _b16, _c, _d, _e, _f, _g, _h;
|
|
33622
|
-
const { args, warnings } = await this.getArgs({ ...options });
|
|
34310
|
+
const { args, warnings, metadataKey } = await this.getArgs({ ...options });
|
|
33623
34311
|
const transformedBody = this.transformRequestBody(args);
|
|
33624
34312
|
const body = JSON.stringify(transformedBody);
|
|
33625
34313
|
const {
|
|
@@ -33661,24 +34349,24 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
33661
34349
|
input: toolCall.function.arguments,
|
|
33662
34350
|
...thoughtSignature ? {
|
|
33663
34351
|
providerMetadata: {
|
|
33664
|
-
[
|
|
34352
|
+
[metadataKey]: { thoughtSignature }
|
|
33665
34353
|
}
|
|
33666
34354
|
} : {}
|
|
33667
34355
|
});
|
|
33668
34356
|
}
|
|
33669
34357
|
}
|
|
33670
34358
|
const providerMetadata = {
|
|
33671
|
-
[
|
|
34359
|
+
[metadataKey]: {},
|
|
33672
34360
|
...await ((_f = (_e = this.config.metadataExtractor) == null ? undefined : _e.extractMetadata) == null ? undefined : _f.call(_e, {
|
|
33673
34361
|
parsedBody: rawResponse
|
|
33674
34362
|
}))
|
|
33675
34363
|
};
|
|
33676
34364
|
const completionTokenDetails = (_g = responseBody.usage) == null ? undefined : _g.completion_tokens_details;
|
|
33677
34365
|
if ((completionTokenDetails == null ? undefined : completionTokenDetails.accepted_prediction_tokens) != null) {
|
|
33678
|
-
providerMetadata[
|
|
34366
|
+
providerMetadata[metadataKey].acceptedPredictionTokens = completionTokenDetails == null ? undefined : completionTokenDetails.accepted_prediction_tokens;
|
|
33679
34367
|
}
|
|
33680
34368
|
if ((completionTokenDetails == null ? undefined : completionTokenDetails.rejected_prediction_tokens) != null) {
|
|
33681
|
-
providerMetadata[
|
|
34369
|
+
providerMetadata[metadataKey].rejectedPredictionTokens = completionTokenDetails == null ? undefined : completionTokenDetails.rejected_prediction_tokens;
|
|
33682
34370
|
}
|
|
33683
34371
|
return {
|
|
33684
34372
|
content,
|
|
@@ -33686,7 +34374,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
33686
34374
|
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
33687
34375
|
raw: (_h = choice.finish_reason) != null ? _h : undefined
|
|
33688
34376
|
},
|
|
33689
|
-
usage:
|
|
34377
|
+
usage: this.convertUsage(responseBody.usage),
|
|
33690
34378
|
providerMetadata,
|
|
33691
34379
|
request: { body },
|
|
33692
34380
|
response: {
|
|
@@ -33699,7 +34387,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
33699
34387
|
}
|
|
33700
34388
|
async doStream(options) {
|
|
33701
34389
|
var _a16;
|
|
33702
|
-
const { args, warnings } = await this.getArgs({ ...options });
|
|
34390
|
+
const { args, warnings, metadataKey } = await this.getArgs({ ...options });
|
|
33703
34391
|
const body = this.transformRequestBody({
|
|
33704
34392
|
...args,
|
|
33705
34393
|
stream: true,
|
|
@@ -33725,9 +34413,10 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
33725
34413
|
};
|
|
33726
34414
|
let usage = undefined;
|
|
33727
34415
|
let isFirstChunk = true;
|
|
33728
|
-
const providerOptionsName =
|
|
34416
|
+
const providerOptionsName = metadataKey;
|
|
33729
34417
|
let isActiveReasoning = false;
|
|
33730
34418
|
let isActiveText = false;
|
|
34419
|
+
const convertUsage = (usage2) => this.convertUsage(usage2);
|
|
33731
34420
|
return {
|
|
33732
34421
|
stream: response.pipeThrough(new TransformStream({
|
|
33733
34422
|
start(controller) {
|
|
@@ -33952,7 +34641,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
33952
34641
|
controller.enqueue({
|
|
33953
34642
|
type: "finish",
|
|
33954
34643
|
finishReason,
|
|
33955
|
-
usage:
|
|
34644
|
+
usage: convertUsage(usage),
|
|
33956
34645
|
providerMetadata
|
|
33957
34646
|
});
|
|
33958
34647
|
}
|
|
@@ -34205,13 +34894,17 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
34205
34894
|
tools,
|
|
34206
34895
|
toolChoice
|
|
34207
34896
|
}) {
|
|
34208
|
-
var _a16;
|
|
34897
|
+
var _a16, _b16;
|
|
34209
34898
|
const warnings = [];
|
|
34210
|
-
const completionOptions = (_a16 = await parseProviderOptions({
|
|
34899
|
+
const completionOptions = Object.assign((_a16 = await parseProviderOptions({
|
|
34211
34900
|
provider: this.providerOptionsName,
|
|
34212
34901
|
providerOptions,
|
|
34213
34902
|
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
34214
|
-
})) != null ? _a16 : {}
|
|
34903
|
+
})) != null ? _a16 : {}, (_b16 = await parseProviderOptions({
|
|
34904
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
34905
|
+
providerOptions,
|
|
34906
|
+
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
34907
|
+
})) != null ? _b16 : {});
|
|
34215
34908
|
if (topK != null) {
|
|
34216
34909
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
34217
34910
|
}
|
|
@@ -34244,6 +34937,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
34244
34937
|
presence_penalty: presencePenalty,
|
|
34245
34938
|
seed,
|
|
34246
34939
|
...providerOptions == null ? undefined : providerOptions[this.providerOptionsName],
|
|
34940
|
+
...providerOptions == null ? undefined : providerOptions[toCamelCase(this.providerOptionsName)],
|
|
34247
34941
|
prompt: completionPrompt,
|
|
34248
34942
|
stop: stop.length > 0 ? stop : undefined
|
|
34249
34943
|
},
|
|
@@ -34621,10 +35315,7 @@ async function fileToBlob2(file2) {
|
|
|
34621
35315
|
const data = file2.data instanceof Uint8Array ? file2.data : convertBase64ToUint8Array(file2.data);
|
|
34622
35316
|
return new Blob([data], { type: file2.mediaType });
|
|
34623
35317
|
}
|
|
34624
|
-
|
|
34625
|
-
return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
|
|
34626
|
-
}
|
|
34627
|
-
var VERSION5 = "2.0.38";
|
|
35318
|
+
var VERSION5 = "2.0.45";
|
|
34628
35319
|
function createOpenAICompatible(options) {
|
|
34629
35320
|
const baseURL = withoutTrailingSlash(options.baseURL);
|
|
34630
35321
|
const providerName = options.name;
|
|
@@ -34650,8 +35341,10 @@ function createOpenAICompatible(options) {
|
|
|
34650
35341
|
...getCommonModelConfig("chat"),
|
|
34651
35342
|
includeUsage: options.includeUsage,
|
|
34652
35343
|
supportsStructuredOutputs: options.supportsStructuredOutputs,
|
|
35344
|
+
supportedUrls: options.supportedUrls,
|
|
34653
35345
|
transformRequestBody: options.transformRequestBody,
|
|
34654
|
-
metadataExtractor: options.metadataExtractor
|
|
35346
|
+
metadataExtractor: options.metadataExtractor,
|
|
35347
|
+
convertUsage: options.convertUsage
|
|
34655
35348
|
});
|
|
34656
35349
|
const createCompletionModel = (modelId) => new OpenAICompatibleCompletionLanguageModel(modelId, {
|
|
34657
35350
|
...getCommonModelConfig("completion"),
|
|
@@ -34959,6 +35652,19 @@ var gatewayErrorResponseSchema = lazySchema(() => zodSchema(exports_external.obj
|
|
|
34959
35652
|
}),
|
|
34960
35653
|
generationId: exports_external.string().nullish()
|
|
34961
35654
|
})));
|
|
35655
|
+
function extractApiCallResponse(error40) {
|
|
35656
|
+
if (error40.data !== undefined) {
|
|
35657
|
+
return error40.data;
|
|
35658
|
+
}
|
|
35659
|
+
if (error40.responseBody != null) {
|
|
35660
|
+
try {
|
|
35661
|
+
return JSON.parse(error40.responseBody);
|
|
35662
|
+
} catch (e) {
|
|
35663
|
+
return error40.responseBody;
|
|
35664
|
+
}
|
|
35665
|
+
}
|
|
35666
|
+
return {};
|
|
35667
|
+
}
|
|
34962
35668
|
var name72 = "GatewayTimeoutError";
|
|
34963
35669
|
var marker82 = `vercel.ai.gateway.error.${name72}`;
|
|
34964
35670
|
var symbol82 = Symbol.for(marker82);
|
|
@@ -35045,19 +35751,6 @@ async function asGatewayError(error40, authMethod) {
|
|
|
35045
35751
|
authMethod
|
|
35046
35752
|
});
|
|
35047
35753
|
}
|
|
35048
|
-
function extractApiCallResponse(error40) {
|
|
35049
|
-
if (error40.data !== undefined) {
|
|
35050
|
-
return error40.data;
|
|
35051
|
-
}
|
|
35052
|
-
if (error40.responseBody != null) {
|
|
35053
|
-
try {
|
|
35054
|
-
return JSON.parse(error40.responseBody);
|
|
35055
|
-
} catch (e) {
|
|
35056
|
-
return error40.responseBody;
|
|
35057
|
-
}
|
|
35058
|
-
}
|
|
35059
|
-
return {};
|
|
35060
|
-
}
|
|
35061
35754
|
var GATEWAY_AUTH_METHOD_HEADER = "ai-gateway-auth-method";
|
|
35062
35755
|
async function parseAuthMethod(headers) {
|
|
35063
35756
|
const result = await safeValidateTypes({
|
|
@@ -35067,6 +35760,13 @@ async function parseAuthMethod(headers) {
|
|
|
35067
35760
|
return result.success ? result.value : undefined;
|
|
35068
35761
|
}
|
|
35069
35762
|
var gatewayAuthMethodSchema = lazySchema(() => zodSchema(exports_external.union([exports_external.literal("api-key"), exports_external.literal("oidc")])));
|
|
35763
|
+
var KNOWN_MODEL_TYPES = [
|
|
35764
|
+
"embedding",
|
|
35765
|
+
"image",
|
|
35766
|
+
"language",
|
|
35767
|
+
"reranking",
|
|
35768
|
+
"video"
|
|
35769
|
+
];
|
|
35070
35770
|
var GatewayFetchMetadata = class {
|
|
35071
35771
|
constructor(config2) {
|
|
35072
35772
|
this.config = config2;
|
|
@@ -35128,8 +35828,8 @@ var gatewayAvailableModelsResponseSchema = lazySchema(() => zodSchema(exports_ex
|
|
|
35128
35828
|
provider: exports_external.string(),
|
|
35129
35829
|
modelId: exports_external.string()
|
|
35130
35830
|
}),
|
|
35131
|
-
modelType: exports_external.
|
|
35132
|
-
}))
|
|
35831
|
+
modelType: exports_external.string().nullish()
|
|
35832
|
+
})).transform((models) => models.filter((m) => m.modelType == null || KNOWN_MODEL_TYPES.includes(m.modelType)))
|
|
35133
35833
|
})));
|
|
35134
35834
|
var gatewayCreditsResponseSchema = lazySchema(() => zodSchema(exports_external.object({
|
|
35135
35835
|
balance: exports_external.string(),
|
|
@@ -35801,6 +36501,73 @@ var gatewayVideoEventSchema = exports_external.discriminatedUnion("type", [
|
|
|
35801
36501
|
param: exports_external.unknown().nullable()
|
|
35802
36502
|
})
|
|
35803
36503
|
]);
|
|
36504
|
+
var GatewayRerankingModel = class {
|
|
36505
|
+
constructor(modelId, config2) {
|
|
36506
|
+
this.modelId = modelId;
|
|
36507
|
+
this.config = config2;
|
|
36508
|
+
this.specificationVersion = "v3";
|
|
36509
|
+
}
|
|
36510
|
+
get provider() {
|
|
36511
|
+
return this.config.provider;
|
|
36512
|
+
}
|
|
36513
|
+
async doRerank({
|
|
36514
|
+
documents,
|
|
36515
|
+
query,
|
|
36516
|
+
topN,
|
|
36517
|
+
headers,
|
|
36518
|
+
abortSignal,
|
|
36519
|
+
providerOptions
|
|
36520
|
+
}) {
|
|
36521
|
+
const resolvedHeaders = await resolve(this.config.headers());
|
|
36522
|
+
try {
|
|
36523
|
+
const {
|
|
36524
|
+
responseHeaders,
|
|
36525
|
+
value: responseBody,
|
|
36526
|
+
rawValue
|
|
36527
|
+
} = await postJsonToApi({
|
|
36528
|
+
url: this.getUrl(),
|
|
36529
|
+
headers: combineHeaders(resolvedHeaders, headers != null ? headers : {}, this.getModelConfigHeaders(), await resolve(this.config.o11yHeaders)),
|
|
36530
|
+
body: {
|
|
36531
|
+
documents,
|
|
36532
|
+
query,
|
|
36533
|
+
...topN != null ? { topN } : {},
|
|
36534
|
+
...providerOptions ? { providerOptions } : {}
|
|
36535
|
+
},
|
|
36536
|
+
successfulResponseHandler: createJsonResponseHandler(gatewayRerankingResponseSchema),
|
|
36537
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
36538
|
+
errorSchema: exports_external.any(),
|
|
36539
|
+
errorToMessage: (data) => data
|
|
36540
|
+
}),
|
|
36541
|
+
...abortSignal && { abortSignal },
|
|
36542
|
+
fetch: this.config.fetch
|
|
36543
|
+
});
|
|
36544
|
+
return {
|
|
36545
|
+
ranking: responseBody.ranking,
|
|
36546
|
+
providerMetadata: responseBody.providerMetadata,
|
|
36547
|
+
response: { headers: responseHeaders, body: rawValue },
|
|
36548
|
+
warnings: []
|
|
36549
|
+
};
|
|
36550
|
+
} catch (error40) {
|
|
36551
|
+
throw await asGatewayError(error40, await parseAuthMethod(resolvedHeaders));
|
|
36552
|
+
}
|
|
36553
|
+
}
|
|
36554
|
+
getUrl() {
|
|
36555
|
+
return `${this.config.baseURL}/reranking-model`;
|
|
36556
|
+
}
|
|
36557
|
+
getModelConfigHeaders() {
|
|
36558
|
+
return {
|
|
36559
|
+
"ai-reranking-model-specification-version": "3",
|
|
36560
|
+
"ai-model-id": this.modelId
|
|
36561
|
+
};
|
|
36562
|
+
}
|
|
36563
|
+
};
|
|
36564
|
+
var gatewayRerankingResponseSchema = lazySchema(() => zodSchema(exports_external.object({
|
|
36565
|
+
ranking: exports_external.array(exports_external.object({
|
|
36566
|
+
index: exports_external.number(),
|
|
36567
|
+
relevanceScore: exports_external.number()
|
|
36568
|
+
})),
|
|
36569
|
+
providerMetadata: exports_external.record(exports_external.string(), exports_external.record(exports_external.string(), exports_external.unknown())).optional()
|
|
36570
|
+
})));
|
|
35804
36571
|
var parallelSearchInputSchema = lazySchema(() => zodSchema(exports_external2.object({
|
|
35805
36572
|
objective: exports_external2.string().describe("Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."),
|
|
35806
36573
|
search_queries: exports_external2.array(exports_external2.string()).optional().describe("Optional search queries to supplement the objective. Maximum 200 characters per query."),
|
|
@@ -35900,7 +36667,7 @@ async function getVercelRequestId() {
|
|
|
35900
36667
|
var _a92;
|
|
35901
36668
|
return (_a92 = import_oidc.getContext().headers) == null ? undefined : _a92["x-vercel-id"];
|
|
35902
36669
|
}
|
|
35903
|
-
var VERSION6 = "3.0.
|
|
36670
|
+
var VERSION6 = "3.0.109";
|
|
35904
36671
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
35905
36672
|
function createGatewayProvider(options = {}) {
|
|
35906
36673
|
var _a92, _b92;
|
|
@@ -36050,6 +36817,17 @@ function createGatewayProvider(options = {}) {
|
|
|
36050
36817
|
o11yHeaders: createO11yHeaders()
|
|
36051
36818
|
});
|
|
36052
36819
|
};
|
|
36820
|
+
const createRerankingModel = (modelId) => {
|
|
36821
|
+
return new GatewayRerankingModel(modelId, {
|
|
36822
|
+
provider: "gateway",
|
|
36823
|
+
baseURL,
|
|
36824
|
+
headers: getHeaders,
|
|
36825
|
+
fetch: options.fetch,
|
|
36826
|
+
o11yHeaders: createO11yHeaders()
|
|
36827
|
+
});
|
|
36828
|
+
};
|
|
36829
|
+
provider.rerankingModel = createRerankingModel;
|
|
36830
|
+
provider.reranking = createRerankingModel;
|
|
36053
36831
|
provider.chat = provider.languageModel;
|
|
36054
36832
|
provider.embedding = provider.embeddingModel;
|
|
36055
36833
|
provider.image = provider.imageModel;
|
|
@@ -36647,7 +37425,7 @@ function detectMediaType({
|
|
|
36647
37425
|
}
|
|
36648
37426
|
return;
|
|
36649
37427
|
}
|
|
36650
|
-
var VERSION7 = "6.0.
|
|
37428
|
+
var VERSION7 = "6.0.174";
|
|
36651
37429
|
var download = async ({
|
|
36652
37430
|
url: url2,
|
|
36653
37431
|
maxBytes,
|
|
@@ -37401,33 +38179,35 @@ var modelMessageSchema = exports_external.union([
|
|
|
37401
38179
|
assistantModelMessageSchema,
|
|
37402
38180
|
toolModelMessageSchema
|
|
37403
38181
|
]);
|
|
37404
|
-
async function standardizePrompt(
|
|
37405
|
-
|
|
38182
|
+
async function standardizePrompt({
|
|
38183
|
+
allowSystemInMessages,
|
|
38184
|
+
system,
|
|
38185
|
+
prompt,
|
|
38186
|
+
messages
|
|
38187
|
+
}) {
|
|
38188
|
+
if (prompt == null && messages == null) {
|
|
37406
38189
|
throw new InvalidPromptError({
|
|
37407
38190
|
prompt,
|
|
37408
38191
|
message: "prompt or messages must be defined"
|
|
37409
38192
|
});
|
|
37410
38193
|
}
|
|
37411
|
-
if (prompt
|
|
38194
|
+
if (prompt != null && messages != null) {
|
|
37412
38195
|
throw new InvalidPromptError({
|
|
37413
38196
|
prompt,
|
|
37414
38197
|
message: "prompt and messages cannot be defined at the same time"
|
|
37415
38198
|
});
|
|
37416
38199
|
}
|
|
37417
|
-
if (
|
|
38200
|
+
if (typeof system !== "string" && !asArray(system).every((message) => message.role === "system")) {
|
|
37418
38201
|
throw new InvalidPromptError({
|
|
37419
38202
|
prompt,
|
|
37420
38203
|
message: "system must be a string, SystemModelMessage, or array of SystemModelMessage"
|
|
37421
38204
|
});
|
|
37422
38205
|
}
|
|
37423
|
-
|
|
37424
|
-
|
|
37425
|
-
|
|
37426
|
-
|
|
37427
|
-
|
|
37428
|
-
} else if (prompt.messages != null) {
|
|
37429
|
-
messages = prompt.messages;
|
|
37430
|
-
} else {
|
|
38206
|
+
if (prompt != null && typeof prompt === "string") {
|
|
38207
|
+
messages = [{ role: "user", content: prompt }];
|
|
38208
|
+
} else if (prompt != null && Array.isArray(prompt)) {
|
|
38209
|
+
messages = prompt;
|
|
38210
|
+
} else if (messages == null) {
|
|
37431
38211
|
throw new InvalidPromptError({
|
|
37432
38212
|
prompt,
|
|
37433
38213
|
message: "prompt or messages must be defined"
|
|
@@ -37439,6 +38219,17 @@ async function standardizePrompt(prompt) {
|
|
|
37439
38219
|
message: "messages must not be empty"
|
|
37440
38220
|
});
|
|
37441
38221
|
}
|
|
38222
|
+
if (messages.some((message) => message.role === "system")) {
|
|
38223
|
+
if (allowSystemInMessages === false) {
|
|
38224
|
+
throw new InvalidPromptError({
|
|
38225
|
+
prompt,
|
|
38226
|
+
message: "System messages are not allowed in the prompt or messages fields. Use the system option instead."
|
|
38227
|
+
});
|
|
38228
|
+
}
|
|
38229
|
+
if (allowSystemInMessages === undefined) {
|
|
38230
|
+
console.warn("AI SDK Warning: System messages in the prompt or messages fields can be a security risk because they may enable prompt injection attacks. Use the system option instead when possible. Set allowSystemInMessages to true to suppress this warning, or false to throw an error.");
|
|
38231
|
+
}
|
|
38232
|
+
}
|
|
37442
38233
|
const validationResult = await safeValidateTypes({
|
|
37443
38234
|
value: messages,
|
|
37444
38235
|
schema: exports_external.array(modelMessageSchema)
|
|
@@ -37450,10 +38241,7 @@ async function standardizePrompt(prompt) {
|
|
|
37450
38241
|
cause: validationResult.error
|
|
37451
38242
|
});
|
|
37452
38243
|
}
|
|
37453
|
-
return {
|
|
37454
|
-
messages,
|
|
37455
|
-
system: prompt.system
|
|
37456
|
-
};
|
|
38244
|
+
return { messages, system };
|
|
37457
38245
|
}
|
|
37458
38246
|
function wrapGatewayError(error40) {
|
|
37459
38247
|
if (!GatewayAuthenticationError.isInstance(error40))
|
|
@@ -37755,6 +38543,9 @@ function mergeObjects(base, overrides) {
|
|
|
37755
38543
|
}
|
|
37756
38544
|
const result = { ...base };
|
|
37757
38545
|
for (const key in overrides) {
|
|
38546
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
38547
|
+
continue;
|
|
38548
|
+
}
|
|
37758
38549
|
if (Object.prototype.hasOwnProperty.call(overrides, key)) {
|
|
37759
38550
|
const overridesValue = overrides[key];
|
|
37760
38551
|
if (overridesValue === undefined)
|
|
@@ -38785,6 +39576,15 @@ var json2 = ({
|
|
|
38785
39576
|
}
|
|
38786
39577
|
};
|
|
38787
39578
|
};
|
|
39579
|
+
function mergeToolProviderMetadata(toolMetadata, callMetadata) {
|
|
39580
|
+
if (toolMetadata == null) {
|
|
39581
|
+
return callMetadata;
|
|
39582
|
+
}
|
|
39583
|
+
if (callMetadata == null) {
|
|
39584
|
+
return toolMetadata;
|
|
39585
|
+
}
|
|
39586
|
+
return { ...toolMetadata, ...callMetadata };
|
|
39587
|
+
}
|
|
38788
39588
|
async function parseToolCall({
|
|
38789
39589
|
toolCall,
|
|
38790
39590
|
tools,
|
|
@@ -38792,7 +39592,7 @@ async function parseToolCall({
|
|
|
38792
39592
|
system,
|
|
38793
39593
|
messages
|
|
38794
39594
|
}) {
|
|
38795
|
-
var _a21;
|
|
39595
|
+
var _a21, _b16;
|
|
38796
39596
|
try {
|
|
38797
39597
|
if (tools == null) {
|
|
38798
39598
|
if (toolCall.providerExecuted && toolCall.dynamic) {
|
|
@@ -38843,7 +39643,7 @@ async function parseToolCall({
|
|
|
38843
39643
|
error: error40,
|
|
38844
39644
|
title: (_a21 = tools == null ? undefined : tools[toolCall.toolName]) == null ? undefined : _a21.title,
|
|
38845
39645
|
providerExecuted: toolCall.providerExecuted,
|
|
38846
|
-
providerMetadata: toolCall.providerMetadata
|
|
39646
|
+
providerMetadata: mergeToolProviderMetadata((_b16 = tools == null ? undefined : tools[toolCall.toolName]) == null ? undefined : _b16.providerMetadata, toolCall.providerMetadata)
|
|
38847
39647
|
};
|
|
38848
39648
|
}
|
|
38849
39649
|
}
|
|
@@ -38890,13 +39690,14 @@ async function doParseToolCall({
|
|
|
38890
39690
|
cause: parseResult.error
|
|
38891
39691
|
});
|
|
38892
39692
|
}
|
|
39693
|
+
const mergedProviderMetadata = mergeToolProviderMetadata(tool2.providerMetadata, toolCall.providerMetadata);
|
|
38893
39694
|
return tool2.type === "dynamic" ? {
|
|
38894
39695
|
type: "tool-call",
|
|
38895
39696
|
toolCallId: toolCall.toolCallId,
|
|
38896
39697
|
toolName: toolCall.toolName,
|
|
38897
39698
|
input: parseResult.value,
|
|
38898
39699
|
providerExecuted: toolCall.providerExecuted,
|
|
38899
|
-
providerMetadata:
|
|
39700
|
+
providerMetadata: mergedProviderMetadata,
|
|
38900
39701
|
dynamic: true,
|
|
38901
39702
|
title: tool2.title
|
|
38902
39703
|
} : {
|
|
@@ -38905,7 +39706,7 @@ async function doParseToolCall({
|
|
|
38905
39706
|
toolName,
|
|
38906
39707
|
input: parseResult.value,
|
|
38907
39708
|
providerExecuted: toolCall.providerExecuted,
|
|
38908
|
-
providerMetadata:
|
|
39709
|
+
providerMetadata: mergedProviderMetadata,
|
|
38909
39710
|
title: tool2.title
|
|
38910
39711
|
};
|
|
38911
39712
|
}
|
|
@@ -39026,7 +39827,7 @@ async function toResponseMessages({
|
|
|
39026
39827
|
type: "tool-call",
|
|
39027
39828
|
toolCallId: part.toolCallId,
|
|
39028
39829
|
toolName: part.toolName,
|
|
39029
|
-
input: part.input,
|
|
39830
|
+
input: part.invalid && typeof part.input !== "object" ? {} : part.input,
|
|
39030
39831
|
providerExecuted: part.providerExecuted,
|
|
39031
39832
|
providerOptions: part.providerMetadata
|
|
39032
39833
|
});
|
|
@@ -39139,6 +39940,7 @@ async function generateText({
|
|
|
39139
39940
|
system,
|
|
39140
39941
|
prompt,
|
|
39141
39942
|
messages,
|
|
39943
|
+
allowSystemInMessages,
|
|
39142
39944
|
maxRetries: maxRetriesArg,
|
|
39143
39945
|
abortSignal,
|
|
39144
39946
|
timeout,
|
|
@@ -39188,7 +39990,8 @@ async function generateText({
|
|
|
39188
39990
|
const initialPrompt = await standardizePrompt({
|
|
39189
39991
|
system,
|
|
39190
39992
|
prompt,
|
|
39191
|
-
messages
|
|
39993
|
+
messages,
|
|
39994
|
+
allowSystemInMessages
|
|
39192
39995
|
});
|
|
39193
39996
|
const globalTelemetry = createGlobalTelemetry(telemetry == null ? undefined : telemetry.integrations);
|
|
39194
39997
|
await notify({
|
|
@@ -39310,22 +40113,6 @@ async function generateText({
|
|
|
39310
40113
|
content: toolContent
|
|
39311
40114
|
});
|
|
39312
40115
|
}
|
|
39313
|
-
const providerExecutedToolApprovals = [
|
|
39314
|
-
...approvedToolApprovals,
|
|
39315
|
-
...deniedToolApprovals
|
|
39316
|
-
].filter((toolApproval) => toolApproval.toolCall.providerExecuted);
|
|
39317
|
-
if (providerExecutedToolApprovals.length > 0) {
|
|
39318
|
-
responseMessages.push({
|
|
39319
|
-
role: "tool",
|
|
39320
|
-
content: providerExecutedToolApprovals.map((toolApproval) => ({
|
|
39321
|
-
type: "tool-approval-response",
|
|
39322
|
-
approvalId: toolApproval.approvalResponse.approvalId,
|
|
39323
|
-
approved: toolApproval.approvalResponse.approved,
|
|
39324
|
-
reason: toolApproval.approvalResponse.reason,
|
|
39325
|
-
providerExecuted: true
|
|
39326
|
-
}))
|
|
39327
|
-
});
|
|
39328
|
-
}
|
|
39329
40116
|
const callSettings2 = prepareCallSettings(settings);
|
|
39330
40117
|
let currentModelResponse;
|
|
39331
40118
|
let clientToolCalls = [];
|