@hongymagic/q 2026.402.0 → 2026.421.0-next.ad63dd0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/q.js +2732 -456
- package/package.json +15 -15
package/dist/q.js
CHANGED
|
@@ -1537,13 +1537,14 @@ var require_auth_config = __commonJS((exports, module) => {
|
|
|
1537
1537
|
}
|
|
1538
1538
|
fs.writeFileSync(authPath, JSON.stringify(config2, null, 2), { mode: 384 });
|
|
1539
1539
|
}
|
|
1540
|
-
function isValidAccessToken(authConfig) {
|
|
1540
|
+
function isValidAccessToken(authConfig, expirationBufferMs = 0) {
|
|
1541
1541
|
if (!authConfig.token)
|
|
1542
1542
|
return false;
|
|
1543
1543
|
if (typeof authConfig.expiresAt !== "number")
|
|
1544
1544
|
return true;
|
|
1545
1545
|
const nowInSeconds = Math.floor(Date.now() / 1000);
|
|
1546
|
-
|
|
1546
|
+
const bufferInSeconds = expirationBufferMs / 1000;
|
|
1547
|
+
return authConfig.expiresAt >= nowInSeconds + bufferInSeconds;
|
|
1547
1548
|
}
|
|
1548
1549
|
});
|
|
1549
1550
|
|
|
@@ -1633,6 +1634,47 @@ var require_oauth = __commonJS((exports, module) => {
|
|
|
1633
1634
|
}
|
|
1634
1635
|
});
|
|
1635
1636
|
|
|
1637
|
+
// node_modules/@vercel/oidc/dist/auth-errors.js
|
|
1638
|
+
var require_auth_errors = __commonJS((exports, module) => {
|
|
1639
|
+
var __defProp2 = Object.defineProperty;
|
|
1640
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
1641
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
1642
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
1643
|
+
var __export2 = (target, all) => {
|
|
1644
|
+
for (var name15 in all)
|
|
1645
|
+
__defProp2(target, name15, { get: all[name15], enumerable: true });
|
|
1646
|
+
};
|
|
1647
|
+
var __copyProps = (to, from, except, desc) => {
|
|
1648
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
1649
|
+
for (let key of __getOwnPropNames2(from))
|
|
1650
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
1651
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
1652
|
+
}
|
|
1653
|
+
return to;
|
|
1654
|
+
};
|
|
1655
|
+
var __toCommonJS = (mod) => __copyProps(__defProp2({}, "__esModule", { value: true }), mod);
|
|
1656
|
+
var auth_errors_exports = {};
|
|
1657
|
+
__export2(auth_errors_exports, {
|
|
1658
|
+
AccessTokenMissingError: () => AccessTokenMissingError2,
|
|
1659
|
+
RefreshAccessTokenFailedError: () => RefreshAccessTokenFailedError2
|
|
1660
|
+
});
|
|
1661
|
+
module.exports = __toCommonJS(auth_errors_exports);
|
|
1662
|
+
|
|
1663
|
+
class AccessTokenMissingError2 extends Error {
|
|
1664
|
+
constructor() {
|
|
1665
|
+
super("No authentication found. Please log in with the Vercel CLI (vercel login).");
|
|
1666
|
+
this.name = "AccessTokenMissingError";
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
class RefreshAccessTokenFailedError2 extends Error {
|
|
1671
|
+
constructor(cause) {
|
|
1672
|
+
super("Failed to refresh authentication token.", { cause });
|
|
1673
|
+
this.name = "RefreshAccessTokenFailedError";
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
});
|
|
1677
|
+
|
|
1636
1678
|
// node_modules/@vercel/oidc/dist/token-util.js
|
|
1637
1679
|
var require_token_util = __commonJS((exports, module) => {
|
|
1638
1680
|
var __create2 = Object.create;
|
|
@@ -1660,9 +1702,9 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
1660
1702
|
assertVercelOidcTokenResponse: () => assertVercelOidcTokenResponse,
|
|
1661
1703
|
findProjectInfo: () => findProjectInfo,
|
|
1662
1704
|
getTokenPayload: () => getTokenPayload,
|
|
1663
|
-
getVercelCliToken: () => getVercelCliToken,
|
|
1664
1705
|
getVercelDataDir: () => getVercelDataDir,
|
|
1665
1706
|
getVercelOidcToken: () => getVercelOidcToken2,
|
|
1707
|
+
getVercelToken: () => getVercelToken2,
|
|
1666
1708
|
isExpired: () => isExpired,
|
|
1667
1709
|
loadToken: () => loadToken,
|
|
1668
1710
|
saveToken: () => saveToken
|
|
@@ -1674,6 +1716,7 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
1674
1716
|
var import_token_io = require_token_io();
|
|
1675
1717
|
var import_auth_config = require_auth_config();
|
|
1676
1718
|
var import_oauth = require_oauth();
|
|
1719
|
+
var import_auth_errors = require_auth_errors();
|
|
1677
1720
|
function getVercelDataDir() {
|
|
1678
1721
|
const vercelFolder = "com.vercel.cli";
|
|
1679
1722
|
const dataDir = (0, import_token_io.getUserDataDir)();
|
|
@@ -1682,17 +1725,17 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
1682
1725
|
}
|
|
1683
1726
|
return path2.join(dataDir, vercelFolder);
|
|
1684
1727
|
}
|
|
1685
|
-
async function
|
|
1728
|
+
async function getVercelToken2(options) {
|
|
1686
1729
|
const authConfig = (0, import_auth_config.readAuthConfig)();
|
|
1687
|
-
if (!authConfig) {
|
|
1688
|
-
|
|
1730
|
+
if (!authConfig?.token) {
|
|
1731
|
+
throw new import_auth_errors.AccessTokenMissingError;
|
|
1689
1732
|
}
|
|
1690
|
-
if ((0, import_auth_config.isValidAccessToken)(authConfig)) {
|
|
1691
|
-
return authConfig.token
|
|
1733
|
+
if ((0, import_auth_config.isValidAccessToken)(authConfig, options?.expirationBufferMs)) {
|
|
1734
|
+
return authConfig.token;
|
|
1692
1735
|
}
|
|
1693
1736
|
if (!authConfig.refreshToken) {
|
|
1694
1737
|
(0, import_auth_config.writeAuthConfig)({});
|
|
1695
|
-
|
|
1738
|
+
throw new import_auth_errors.RefreshAccessTokenFailedError("No refresh token available");
|
|
1696
1739
|
}
|
|
1697
1740
|
try {
|
|
1698
1741
|
const tokenResponse = await (0, import_oauth.refreshTokenRequest)({
|
|
@@ -1701,7 +1744,7 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
1701
1744
|
const [tokensError, tokens] = await (0, import_oauth.processTokenResponse)(tokenResponse);
|
|
1702
1745
|
if (tokensError || !tokens) {
|
|
1703
1746
|
(0, import_auth_config.writeAuthConfig)({});
|
|
1704
|
-
|
|
1747
|
+
throw new import_auth_errors.RefreshAccessTokenFailedError(tokensError);
|
|
1705
1748
|
}
|
|
1706
1749
|
const updatedConfig = {
|
|
1707
1750
|
token: tokens.access_token,
|
|
@@ -1711,10 +1754,13 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
1711
1754
|
updatedConfig.refreshToken = tokens.refresh_token;
|
|
1712
1755
|
}
|
|
1713
1756
|
(0, import_auth_config.writeAuthConfig)(updatedConfig);
|
|
1714
|
-
return updatedConfig.token
|
|
1757
|
+
return updatedConfig.token;
|
|
1715
1758
|
} catch (error48) {
|
|
1716
1759
|
(0, import_auth_config.writeAuthConfig)({});
|
|
1717
|
-
|
|
1760
|
+
if (error48 instanceof import_auth_errors.AccessTokenMissingError || error48 instanceof import_auth_errors.RefreshAccessTokenFailedError) {
|
|
1761
|
+
throw error48;
|
|
1762
|
+
}
|
|
1763
|
+
throw new import_auth_errors.RefreshAccessTokenFailedError(error48);
|
|
1718
1764
|
}
|
|
1719
1765
|
}
|
|
1720
1766
|
async function getVercelOidcToken2(authToken, projectId, teamId) {
|
|
@@ -1789,8 +1835,8 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
1789
1835
|
const padded = base643.padEnd(base643.length + (4 - base643.length % 4) % 4, "=");
|
|
1790
1836
|
return JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
|
|
1791
1837
|
}
|
|
1792
|
-
function isExpired(token) {
|
|
1793
|
-
return token.exp * 1000 < Date.now();
|
|
1838
|
+
function isExpired(token, bufferMs = 0) {
|
|
1839
|
+
return token.exp * 1000 < Date.now() + bufferMs;
|
|
1794
1840
|
}
|
|
1795
1841
|
});
|
|
1796
1842
|
|
|
@@ -1820,17 +1866,26 @@ var require_token = __commonJS((exports, module) => {
|
|
|
1820
1866
|
module.exports = __toCommonJS(token_exports);
|
|
1821
1867
|
var import_token_error = require_token_error();
|
|
1822
1868
|
var import_token_util = require_token_util();
|
|
1823
|
-
async function refreshToken() {
|
|
1824
|
-
|
|
1869
|
+
async function refreshToken(options) {
|
|
1870
|
+
let projectId = options?.project;
|
|
1871
|
+
let teamId = options?.team;
|
|
1872
|
+
if (!projectId && !teamId) {
|
|
1873
|
+
const projectInfo = (0, import_token_util.findProjectInfo)();
|
|
1874
|
+
projectId = projectInfo.projectId;
|
|
1875
|
+
teamId = projectInfo.teamId;
|
|
1876
|
+
} else if (!projectId || !teamId) {
|
|
1877
|
+
const projectInfo = (0, import_token_util.findProjectInfo)();
|
|
1878
|
+
projectId = projectId ?? projectInfo.projectId;
|
|
1879
|
+
teamId = teamId ?? projectInfo.teamId;
|
|
1880
|
+
}
|
|
1881
|
+
if (!projectId) {
|
|
1882
|
+
throw new import_token_error.VercelOidcTokenError("Failed to refresh OIDC token: No project specified. Try re-linking your project with `vc link`");
|
|
1883
|
+
}
|
|
1825
1884
|
let maybeToken = (0, import_token_util.loadToken)(projectId);
|
|
1826
|
-
if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token))) {
|
|
1827
|
-
const authToken = await (0, import_token_util.
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
}
|
|
1831
|
-
if (!projectId) {
|
|
1832
|
-
throw new import_token_error.VercelOidcTokenError("Failed to refresh OIDC token: Try re-linking your project with `vc link`");
|
|
1833
|
-
}
|
|
1885
|
+
if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token), options?.expirationBufferMs)) {
|
|
1886
|
+
const authToken = await (0, import_token_util.getVercelToken)({
|
|
1887
|
+
expirationBufferMs: options?.expirationBufferMs
|
|
1888
|
+
});
|
|
1834
1889
|
maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);
|
|
1835
1890
|
if (!maybeToken) {
|
|
1836
1891
|
throw new import_token_error.VercelOidcTokenError("Failed to refresh OIDC token");
|
|
@@ -1869,7 +1924,7 @@ var require_get_vercel_oidc_token = __commonJS((exports, module) => {
|
|
|
1869
1924
|
module.exports = __toCommonJS(get_vercel_oidc_token_exports);
|
|
1870
1925
|
var import_get_context = require_get_context();
|
|
1871
1926
|
var import_token_error = require_token_error();
|
|
1872
|
-
async function getVercelOidcToken2() {
|
|
1927
|
+
async function getVercelOidcToken2(options) {
|
|
1873
1928
|
let token = "";
|
|
1874
1929
|
let err;
|
|
1875
1930
|
try {
|
|
@@ -1882,8 +1937,8 @@ var require_get_vercel_oidc_token = __commonJS((exports, module) => {
|
|
|
1882
1937
|
await Promise.resolve().then(() => __toESM(require_token_util())),
|
|
1883
1938
|
await Promise.resolve().then(() => __toESM(require_token()))
|
|
1884
1939
|
]);
|
|
1885
|
-
if (!token || isExpired(getTokenPayload(token))) {
|
|
1886
|
-
await refreshToken();
|
|
1940
|
+
if (!token || isExpired(getTokenPayload(token), options?.expirationBufferMs)) {
|
|
1941
|
+
await refreshToken(options);
|
|
1887
1942
|
token = getVercelOidcTokenSync2();
|
|
1888
1943
|
}
|
|
1889
1944
|
} catch (error48) {
|
|
@@ -1929,13 +1984,18 @@ var require_dist = __commonJS((exports, module) => {
|
|
|
1929
1984
|
var __toCommonJS = (mod) => __copyProps(__defProp2({}, "__esModule", { value: true }), mod);
|
|
1930
1985
|
var src_exports = {};
|
|
1931
1986
|
__export2(src_exports, {
|
|
1987
|
+
AccessTokenMissingError: () => import_auth_errors.AccessTokenMissingError,
|
|
1988
|
+
RefreshAccessTokenFailedError: () => import_auth_errors.RefreshAccessTokenFailedError,
|
|
1932
1989
|
getContext: () => import_get_context.getContext,
|
|
1933
1990
|
getVercelOidcToken: () => import_get_vercel_oidc_token.getVercelOidcToken,
|
|
1934
|
-
getVercelOidcTokenSync: () => import_get_vercel_oidc_token.getVercelOidcTokenSync
|
|
1991
|
+
getVercelOidcTokenSync: () => import_get_vercel_oidc_token.getVercelOidcTokenSync,
|
|
1992
|
+
getVercelToken: () => import_token_util.getVercelToken
|
|
1935
1993
|
});
|
|
1936
1994
|
module.exports = __toCommonJS(src_exports);
|
|
1937
1995
|
var import_get_vercel_oidc_token = require_get_vercel_oidc_token();
|
|
1938
1996
|
var import_get_context = require_get_context();
|
|
1997
|
+
var import_auth_errors = require_auth_errors();
|
|
1998
|
+
var import_token_util = require_token_util();
|
|
1939
1999
|
});
|
|
1940
2000
|
|
|
1941
2001
|
// node_modules/@opentelemetry/api/build/src/platform/node/globalThis.js
|
|
@@ -12055,7 +12115,7 @@ var init_main_sync = __esm(() => {
|
|
|
12055
12115
|
|
|
12056
12116
|
// node_modules/execa/lib/ipc/get-one.js
|
|
12057
12117
|
import { once as once5, on as on2 } from "node:events";
|
|
12058
|
-
var getOneMessage = ({ anyProcess, channel, isSubprocess, ipc }, { reference = true, filter:
|
|
12118
|
+
var getOneMessage = ({ anyProcess, channel, isSubprocess, ipc }, { reference = true, filter: filter3 } = {}) => {
|
|
12059
12119
|
validateIpcMethod({
|
|
12060
12120
|
methodName: "getOneMessage",
|
|
12061
12121
|
isSubprocess,
|
|
@@ -12066,16 +12126,16 @@ var getOneMessage = ({ anyProcess, channel, isSubprocess, ipc }, { reference = t
|
|
|
12066
12126
|
anyProcess,
|
|
12067
12127
|
channel,
|
|
12068
12128
|
isSubprocess,
|
|
12069
|
-
filter:
|
|
12129
|
+
filter: filter3,
|
|
12070
12130
|
reference
|
|
12071
12131
|
});
|
|
12072
|
-
}, getOneMessageAsync = async ({ anyProcess, channel, isSubprocess, filter:
|
|
12132
|
+
}, getOneMessageAsync = async ({ anyProcess, channel, isSubprocess, filter: filter3, reference }) => {
|
|
12073
12133
|
addReference(channel, reference);
|
|
12074
12134
|
const ipcEmitter = getIpcEmitter(anyProcess, channel, isSubprocess);
|
|
12075
12135
|
const controller = new AbortController;
|
|
12076
12136
|
try {
|
|
12077
12137
|
return await Promise.race([
|
|
12078
|
-
getMessage(ipcEmitter,
|
|
12138
|
+
getMessage(ipcEmitter, filter3, controller),
|
|
12079
12139
|
throwOnDisconnect2(ipcEmitter, isSubprocess, controller),
|
|
12080
12140
|
throwOnStrictError(ipcEmitter, isSubprocess, controller)
|
|
12081
12141
|
]);
|
|
@@ -12086,13 +12146,13 @@ var getOneMessage = ({ anyProcess, channel, isSubprocess, ipc }, { reference = t
|
|
|
12086
12146
|
controller.abort();
|
|
12087
12147
|
removeReference(channel, reference);
|
|
12088
12148
|
}
|
|
12089
|
-
}, getMessage = async (ipcEmitter,
|
|
12090
|
-
if (
|
|
12149
|
+
}, getMessage = async (ipcEmitter, filter3, { signal }) => {
|
|
12150
|
+
if (filter3 === undefined) {
|
|
12091
12151
|
const [message] = await once5(ipcEmitter, "message", { signal });
|
|
12092
12152
|
return message;
|
|
12093
12153
|
}
|
|
12094
12154
|
for await (const [message] of on2(ipcEmitter, "message", { signal })) {
|
|
12095
|
-
if (
|
|
12155
|
+
if (filter3(message)) {
|
|
12096
12156
|
return message;
|
|
12097
12157
|
}
|
|
12098
12158
|
}
|
|
@@ -12443,7 +12503,7 @@ var getHighWaterMark = (streams, objectMode) => {
|
|
|
12443
12503
|
if (signal.aborted || !streams.has(stream)) {
|
|
12444
12504
|
return;
|
|
12445
12505
|
}
|
|
12446
|
-
if (
|
|
12506
|
+
if (isAbortError3(error48)) {
|
|
12447
12507
|
aborted2.add(stream);
|
|
12448
12508
|
} else {
|
|
12449
12509
|
errorStream(passThroughStream, error48);
|
|
@@ -12462,12 +12522,12 @@ var getHighWaterMark = (streams, objectMode) => {
|
|
|
12462
12522
|
stream.end();
|
|
12463
12523
|
}
|
|
12464
12524
|
}, errorOrAbortStream = (stream, error48) => {
|
|
12465
|
-
if (
|
|
12525
|
+
if (isAbortError3(error48)) {
|
|
12466
12526
|
abortStream(stream);
|
|
12467
12527
|
} else {
|
|
12468
12528
|
errorStream(stream, error48);
|
|
12469
12529
|
}
|
|
12470
|
-
},
|
|
12530
|
+
}, isAbortError3 = (error48) => error48?.code === "ERR_STREAM_PREMATURE_CLOSE", abortStream = (stream) => {
|
|
12471
12531
|
if (stream.readable || stream.writable) {
|
|
12472
12532
|
stream.destroy();
|
|
12473
12533
|
}
|
|
@@ -14712,7 +14772,7 @@ import { parseArgs } from "node:util";
|
|
|
14712
14772
|
// package.json
|
|
14713
14773
|
var package_default = {
|
|
14714
14774
|
name: "@hongymagic/q",
|
|
14715
|
-
version: "2026.
|
|
14775
|
+
version: "2026.421.0-next.ad63dd0",
|
|
14716
14776
|
description: "Quick AI answers from the command line",
|
|
14717
14777
|
main: "dist/q.js",
|
|
14718
14778
|
type: "module",
|
|
@@ -14762,15 +14822,15 @@ var package_default = {
|
|
|
14762
14822
|
"release:dry": "bun run scripts/release.ts --dry-run"
|
|
14763
14823
|
},
|
|
14764
14824
|
dependencies: {
|
|
14765
|
-
"@ai-sdk/amazon-bedrock": "4.0.
|
|
14766
|
-
"@ai-sdk/anthropic": "3.0.
|
|
14767
|
-
"@ai-sdk/azure": "3.0.
|
|
14768
|
-
"@ai-sdk/google": "3.0.
|
|
14769
|
-
"@ai-sdk/groq": "3.0.
|
|
14770
|
-
"@ai-sdk/openai": "3.0.
|
|
14771
|
-
"@ai-sdk/openai-compatible": "2.0.
|
|
14825
|
+
"@ai-sdk/amazon-bedrock": "4.0.96",
|
|
14826
|
+
"@ai-sdk/anthropic": "3.0.71",
|
|
14827
|
+
"@ai-sdk/azure": "3.0.54",
|
|
14828
|
+
"@ai-sdk/google": "3.0.64",
|
|
14829
|
+
"@ai-sdk/groq": "3.0.35",
|
|
14830
|
+
"@ai-sdk/openai": "3.0.53",
|
|
14831
|
+
"@ai-sdk/openai-compatible": "2.0.41",
|
|
14772
14832
|
"@t3-oss/env-core": "0.13.11",
|
|
14773
|
-
ai: "6.0.
|
|
14833
|
+
ai: "6.0.168",
|
|
14774
14834
|
clipboardy: "5.3.1",
|
|
14775
14835
|
"env-paths": "4.0.0",
|
|
14776
14836
|
"ollama-ai-provider-v2": "3.5.0",
|
|
@@ -14778,12 +14838,12 @@ var package_default = {
|
|
|
14778
14838
|
zod: "4.3.6"
|
|
14779
14839
|
},
|
|
14780
14840
|
devDependencies: {
|
|
14781
|
-
"@biomejs/biome": "2.4.
|
|
14782
|
-
"@types/bun": "1.3.
|
|
14783
|
-
"@vitest/coverage-v8": "4.1.
|
|
14784
|
-
lefthook: "2.1.
|
|
14785
|
-
typescript: "6.0.
|
|
14786
|
-
vitest: "4.1.
|
|
14841
|
+
"@biomejs/biome": "2.4.12",
|
|
14842
|
+
"@types/bun": "1.3.12",
|
|
14843
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
14844
|
+
lefthook: "2.1.6",
|
|
14845
|
+
typescript: "6.0.3",
|
|
14846
|
+
vitest: "4.1.5"
|
|
14787
14847
|
}
|
|
14788
14848
|
};
|
|
14789
14849
|
|
|
@@ -34848,10 +34908,13 @@ function validateDownloadUrl(url2) {
|
|
|
34848
34908
|
message: `Invalid URL: ${url2}`
|
|
34849
34909
|
});
|
|
34850
34910
|
}
|
|
34911
|
+
if (parsed.protocol === "data:") {
|
|
34912
|
+
return;
|
|
34913
|
+
}
|
|
34851
34914
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
34852
34915
|
throw new DownloadError({
|
|
34853
34916
|
url: url2,
|
|
34854
|
-
message: `URL scheme must be http or
|
|
34917
|
+
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
34855
34918
|
});
|
|
34856
34919
|
}
|
|
34857
34920
|
const hostname3 = parsed.hostname;
|
|
@@ -35109,7 +35172,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
35109
35172
|
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
35110
35173
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
35111
35174
|
}
|
|
35112
|
-
var VERSION2 = "4.0.
|
|
35175
|
+
var VERSION2 = "4.0.23";
|
|
35113
35176
|
var getOriginalFetch = () => globalThis.fetch;
|
|
35114
35177
|
var getFromApi = async ({
|
|
35115
35178
|
url: url2,
|
|
@@ -35205,7 +35268,7 @@ function loadApiKey({
|
|
|
35205
35268
|
}
|
|
35206
35269
|
if (typeof process === "undefined") {
|
|
35207
35270
|
throw new LoadAPIKeyError({
|
|
35208
|
-
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables
|
|
35271
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables are not supported in this environment.`
|
|
35209
35272
|
});
|
|
35210
35273
|
}
|
|
35211
35274
|
apiKey = process.env[environmentVariableName];
|
|
@@ -35253,7 +35316,7 @@ function loadSetting({
|
|
|
35253
35316
|
}
|
|
35254
35317
|
if (typeof process === "undefined") {
|
|
35255
35318
|
throw new LoadSettingError({
|
|
35256
|
-
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables
|
|
35319
|
+
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables are not supported in this environment.`
|
|
35257
35320
|
});
|
|
35258
35321
|
}
|
|
35259
35322
|
settingValue = process.env[environmentVariableName];
|
|
@@ -36877,7 +36940,7 @@ async function* executeTool({
|
|
|
36877
36940
|
}
|
|
36878
36941
|
|
|
36879
36942
|
// node_modules/@ai-sdk/anthropic/dist/index.mjs
|
|
36880
|
-
var VERSION3 = "3.0.
|
|
36943
|
+
var VERSION3 = "3.0.71";
|
|
36881
36944
|
var anthropicErrorDataSchema = lazySchema(() => zodSchema(exports_external.object({
|
|
36882
36945
|
type: exports_external.literal("error"),
|
|
36883
36946
|
error: exports_external.object({
|
|
@@ -37566,7 +37629,8 @@ var anthropicLanguageModelOptions = exports_external.object({
|
|
|
37566
37629
|
structuredOutputMode: exports_external.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
37567
37630
|
thinking: exports_external.discriminatedUnion("type", [
|
|
37568
37631
|
exports_external.object({
|
|
37569
|
-
type: exports_external.literal("adaptive")
|
|
37632
|
+
type: exports_external.literal("adaptive"),
|
|
37633
|
+
display: exports_external.enum(["omitted", "summarized"]).optional()
|
|
37570
37634
|
}),
|
|
37571
37635
|
exports_external.object({
|
|
37572
37636
|
type: exports_external.literal("enabled"),
|
|
@@ -37603,8 +37667,14 @@ var anthropicLanguageModelOptions = exports_external.object({
|
|
|
37603
37667
|
})).optional()
|
|
37604
37668
|
}).optional(),
|
|
37605
37669
|
toolStreaming: exports_external.boolean().optional(),
|
|
37606
|
-
effort: exports_external.enum(["low", "medium", "high", "max"]).optional(),
|
|
37670
|
+
effort: exports_external.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
37671
|
+
taskBudget: exports_external.object({
|
|
37672
|
+
type: exports_external.literal("tokens"),
|
|
37673
|
+
total: exports_external.number().int().min(20000),
|
|
37674
|
+
remaining: exports_external.number().int().min(0).optional()
|
|
37675
|
+
}).optional(),
|
|
37607
37676
|
speed: exports_external.enum(["fast", "standard"]).optional(),
|
|
37677
|
+
inferenceGeo: exports_external.enum(["us", "global"]).optional(),
|
|
37608
37678
|
anthropicBeta: exports_external.array(exports_external.string()).optional(),
|
|
37609
37679
|
contextManagement: exports_external.object({
|
|
37610
37680
|
edits: exports_external.array(exports_external.discriminatedUnion("type", [
|
|
@@ -37863,9 +37933,10 @@ async function prepareTools({
|
|
|
37863
37933
|
disableParallelToolUse,
|
|
37864
37934
|
cacheControlValidator,
|
|
37865
37935
|
supportsStructuredOutput,
|
|
37866
|
-
supportsStrictTools
|
|
37936
|
+
supportsStrictTools,
|
|
37937
|
+
defaultEagerInputStreaming = false
|
|
37867
37938
|
}) {
|
|
37868
|
-
var _a16;
|
|
37939
|
+
var _a16, _b16;
|
|
37869
37940
|
tools = (tools == null ? undefined : tools.length) ? tools : undefined;
|
|
37870
37941
|
const toolWarnings = [];
|
|
37871
37942
|
const betas = /* @__PURE__ */ new Set;
|
|
@@ -37882,7 +37953,7 @@ async function prepareTools({
|
|
|
37882
37953
|
canCache: true
|
|
37883
37954
|
});
|
|
37884
37955
|
const anthropicOptions = (_a16 = tool2.providerOptions) == null ? undefined : _a16.anthropic;
|
|
37885
|
-
const eagerInputStreaming = anthropicOptions == null ? undefined : anthropicOptions.eagerInputStreaming;
|
|
37956
|
+
const eagerInputStreaming = (_b16 = anthropicOptions == null ? undefined : anthropicOptions.eagerInputStreaming) != null ? _b16 : defaultEagerInputStreaming;
|
|
37886
37957
|
const deferLoading = anthropicOptions == null ? undefined : anthropicOptions.deferLoading;
|
|
37887
37958
|
const allowedCallers = anthropicOptions == null ? undefined : anthropicOptions.allowedCallers;
|
|
37888
37959
|
if (!supportsStrictTools && tool2.strict != null) {
|
|
@@ -39344,7 +39415,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
39344
39415
|
providerOptions,
|
|
39345
39416
|
stream
|
|
39346
39417
|
}) {
|
|
39347
|
-
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i;
|
|
39418
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
39348
39419
|
const warnings = [];
|
|
39349
39420
|
if (frequencyPenalty != null) {
|
|
39350
39421
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -39395,8 +39466,36 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
39395
39466
|
const {
|
|
39396
39467
|
maxOutputTokens: maxOutputTokensForModel,
|
|
39397
39468
|
supportsStructuredOutput: modelSupportsStructuredOutput,
|
|
39469
|
+
rejectsSamplingParameters,
|
|
39398
39470
|
isKnownModel
|
|
39399
39471
|
} = getModelCapabilities(this.modelId);
|
|
39472
|
+
if (rejectsSamplingParameters) {
|
|
39473
|
+
if (temperature != null) {
|
|
39474
|
+
warnings.push({
|
|
39475
|
+
type: "unsupported",
|
|
39476
|
+
feature: "temperature",
|
|
39477
|
+
details: `temperature is not supported by ${this.modelId} and will be ignored`
|
|
39478
|
+
});
|
|
39479
|
+
temperature = undefined;
|
|
39480
|
+
}
|
|
39481
|
+
if (topK != null) {
|
|
39482
|
+
warnings.push({
|
|
39483
|
+
type: "unsupported",
|
|
39484
|
+
feature: "topK",
|
|
39485
|
+
details: `topK is not supported by ${this.modelId} and will be ignored`
|
|
39486
|
+
});
|
|
39487
|
+
topK = undefined;
|
|
39488
|
+
}
|
|
39489
|
+
if (topP != null) {
|
|
39490
|
+
warnings.push({
|
|
39491
|
+
type: "unsupported",
|
|
39492
|
+
feature: "topP",
|
|
39493
|
+
details: `topP is not supported by ${this.modelId} and will be ignored`
|
|
39494
|
+
});
|
|
39495
|
+
topP = undefined;
|
|
39496
|
+
}
|
|
39497
|
+
}
|
|
39498
|
+
const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
|
|
39400
39499
|
const supportsStructuredOutput = ((_a16 = this.config.supportsNativeStructuredOutput) != null ? _a16 : true) && modelSupportsStructuredOutput;
|
|
39401
39500
|
const supportsStrictTools = ((_b16 = this.config.supportsStrictTools) != null ? _b16 : true) && modelSupportsStructuredOutput;
|
|
39402
39501
|
const structureOutputMode = (_c = anthropicOptions == null ? undefined : anthropicOptions.structuredOutputMode) != null ? _c : "auto";
|
|
@@ -39442,6 +39541,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
39442
39541
|
const thinkingType = (_e = anthropicOptions == null ? undefined : anthropicOptions.thinking) == null ? undefined : _e.type;
|
|
39443
39542
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
39444
39543
|
let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? undefined : anthropicOptions.thinking) == null ? undefined : _f.budgetTokens : undefined;
|
|
39544
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? undefined : anthropicOptions.thinking) == null ? undefined : _g.display : undefined;
|
|
39445
39545
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
39446
39546
|
const baseArgs = {
|
|
39447
39547
|
model: this.modelId,
|
|
@@ -39453,14 +39553,24 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
39453
39553
|
...isThinking && {
|
|
39454
39554
|
thinking: {
|
|
39455
39555
|
type: thinkingType,
|
|
39456
|
-
...thinkingBudget != null && { budget_tokens: thinkingBudget }
|
|
39556
|
+
...thinkingBudget != null && { budget_tokens: thinkingBudget },
|
|
39557
|
+
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
39457
39558
|
}
|
|
39458
39559
|
},
|
|
39459
|
-
...((anthropicOptions == null ? undefined : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? undefined : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
39560
|
+
...((anthropicOptions == null ? undefined : anthropicOptions.effort) || (anthropicOptions == null ? undefined : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? undefined : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
39460
39561
|
output_config: {
|
|
39461
39562
|
...(anthropicOptions == null ? undefined : anthropicOptions.effort) && {
|
|
39462
39563
|
effort: anthropicOptions.effort
|
|
39463
39564
|
},
|
|
39565
|
+
...(anthropicOptions == null ? undefined : anthropicOptions.taskBudget) && {
|
|
39566
|
+
task_budget: {
|
|
39567
|
+
type: anthropicOptions.taskBudget.type,
|
|
39568
|
+
total: anthropicOptions.taskBudget.total,
|
|
39569
|
+
...anthropicOptions.taskBudget.remaining != null && {
|
|
39570
|
+
remaining: anthropicOptions.taskBudget.remaining
|
|
39571
|
+
}
|
|
39572
|
+
}
|
|
39573
|
+
},
|
|
39464
39574
|
...useStructuredOutput && (responseFormat == null ? undefined : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
39465
39575
|
format: {
|
|
39466
39576
|
type: "json_schema",
|
|
@@ -39472,10 +39582,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
39472
39582
|
...(anthropicOptions == null ? undefined : anthropicOptions.speed) && {
|
|
39473
39583
|
speed: anthropicOptions.speed
|
|
39474
39584
|
},
|
|
39585
|
+
...(anthropicOptions == null ? undefined : anthropicOptions.inferenceGeo) && {
|
|
39586
|
+
inference_geo: anthropicOptions.inferenceGeo
|
|
39587
|
+
},
|
|
39475
39588
|
...(anthropicOptions == null ? undefined : anthropicOptions.cacheControl) && {
|
|
39476
39589
|
cache_control: anthropicOptions.cacheControl
|
|
39477
39590
|
},
|
|
39478
|
-
...((
|
|
39591
|
+
...((_h = anthropicOptions == null ? undefined : anthropicOptions.metadata) == null ? undefined : _h.userId) != null && {
|
|
39479
39592
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
39480
39593
|
},
|
|
39481
39594
|
...(anthropicOptions == null ? undefined : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && {
|
|
@@ -39592,7 +39705,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
39592
39705
|
}
|
|
39593
39706
|
baseArgs.max_tokens = maxTokens + (thinkingBudget != null ? thinkingBudget : 0);
|
|
39594
39707
|
} else {
|
|
39595
|
-
if (topP != null && temperature != null) {
|
|
39708
|
+
if (isAnthropicModel && topP != null && temperature != null) {
|
|
39596
39709
|
warnings.push({
|
|
39597
39710
|
type: "unsupported",
|
|
39598
39711
|
feature: "topP",
|
|
@@ -39634,12 +39747,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
39634
39747
|
if (anthropicOptions == null ? undefined : anthropicOptions.effort) {
|
|
39635
39748
|
betas.add("effort-2025-11-24");
|
|
39636
39749
|
}
|
|
39750
|
+
if (anthropicOptions == null ? undefined : anthropicOptions.taskBudget) {
|
|
39751
|
+
betas.add("task-budgets-2026-03-13");
|
|
39752
|
+
}
|
|
39637
39753
|
if ((anthropicOptions == null ? undefined : anthropicOptions.speed) === "fast") {
|
|
39638
39754
|
betas.add("fast-mode-2026-02-01");
|
|
39639
39755
|
}
|
|
39640
|
-
|
|
39641
|
-
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
39642
|
-
}
|
|
39756
|
+
const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? undefined : anthropicOptions.toolStreaming) != null ? _i : true);
|
|
39643
39757
|
const {
|
|
39644
39758
|
tools: anthropicTools2,
|
|
39645
39759
|
toolChoice: anthropicToolChoice,
|
|
@@ -39651,14 +39765,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
39651
39765
|
disableParallelToolUse: true,
|
|
39652
39766
|
cacheControlValidator,
|
|
39653
39767
|
supportsStructuredOutput: false,
|
|
39654
|
-
supportsStrictTools
|
|
39768
|
+
supportsStrictTools,
|
|
39769
|
+
defaultEagerInputStreaming
|
|
39655
39770
|
} : {
|
|
39656
39771
|
tools: tools != null ? tools : [],
|
|
39657
39772
|
toolChoice,
|
|
39658
39773
|
disableParallelToolUse: anthropicOptions == null ? undefined : anthropicOptions.disableParallelToolUse,
|
|
39659
39774
|
cacheControlValidator,
|
|
39660
39775
|
supportsStructuredOutput,
|
|
39661
|
-
supportsStrictTools
|
|
39776
|
+
supportsStrictTools,
|
|
39777
|
+
defaultEagerInputStreaming
|
|
39662
39778
|
});
|
|
39663
39779
|
const cacheWarnings = cacheControlValidator.getWarnings();
|
|
39664
39780
|
return {
|
|
@@ -39673,7 +39789,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
39673
39789
|
...betas,
|
|
39674
39790
|
...toolsBetas,
|
|
39675
39791
|
...userSuppliedBetas,
|
|
39676
|
-
...(
|
|
39792
|
+
...(_j = anthropicOptions == null ? undefined : anthropicOptions.anthropicBeta) != null ? _j : []
|
|
39677
39793
|
]),
|
|
39678
39794
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
39679
39795
|
toolNameMapping,
|
|
@@ -40877,46 +40993,60 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
40877
40993
|
}
|
|
40878
40994
|
};
|
|
40879
40995
|
function getModelCapabilities(modelId) {
|
|
40880
|
-
if (modelId.includes("claude-
|
|
40996
|
+
if (modelId.includes("claude-opus-4-7")) {
|
|
40881
40997
|
return {
|
|
40882
40998
|
maxOutputTokens: 128000,
|
|
40883
40999
|
supportsStructuredOutput: true,
|
|
41000
|
+
rejectsSamplingParameters: true,
|
|
41001
|
+
isKnownModel: true
|
|
41002
|
+
};
|
|
41003
|
+
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
41004
|
+
return {
|
|
41005
|
+
maxOutputTokens: 128000,
|
|
41006
|
+
supportsStructuredOutput: true,
|
|
41007
|
+
rejectsSamplingParameters: false,
|
|
40884
41008
|
isKnownModel: true
|
|
40885
41009
|
};
|
|
40886
41010
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
40887
41011
|
return {
|
|
40888
41012
|
maxOutputTokens: 64000,
|
|
40889
41013
|
supportsStructuredOutput: true,
|
|
41014
|
+
rejectsSamplingParameters: false,
|
|
40890
41015
|
isKnownModel: true
|
|
40891
41016
|
};
|
|
40892
41017
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
40893
41018
|
return {
|
|
40894
41019
|
maxOutputTokens: 32000,
|
|
40895
41020
|
supportsStructuredOutput: true,
|
|
41021
|
+
rejectsSamplingParameters: false,
|
|
40896
41022
|
isKnownModel: true
|
|
40897
41023
|
};
|
|
40898
41024
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
40899
41025
|
return {
|
|
40900
41026
|
maxOutputTokens: 64000,
|
|
40901
41027
|
supportsStructuredOutput: false,
|
|
41028
|
+
rejectsSamplingParameters: false,
|
|
40902
41029
|
isKnownModel: true
|
|
40903
41030
|
};
|
|
40904
41031
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
40905
41032
|
return {
|
|
40906
41033
|
maxOutputTokens: 32000,
|
|
40907
41034
|
supportsStructuredOutput: false,
|
|
41035
|
+
rejectsSamplingParameters: false,
|
|
40908
41036
|
isKnownModel: true
|
|
40909
41037
|
};
|
|
40910
41038
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
40911
41039
|
return {
|
|
40912
41040
|
maxOutputTokens: 4096,
|
|
40913
41041
|
supportsStructuredOutput: false,
|
|
41042
|
+
rejectsSamplingParameters: false,
|
|
40914
41043
|
isKnownModel: true
|
|
40915
41044
|
};
|
|
40916
41045
|
} else {
|
|
40917
41046
|
return {
|
|
40918
41047
|
maxOutputTokens: 4096,
|
|
40919
41048
|
supportsStructuredOutput: false,
|
|
41049
|
+
rejectsSamplingParameters: false,
|
|
40920
41050
|
isKnownModel: false
|
|
40921
41051
|
};
|
|
40922
41052
|
}
|
|
@@ -41311,6 +41441,9 @@ function convertOpenAIChatUsage(usage) {
|
|
|
41311
41441
|
raw: usage
|
|
41312
41442
|
};
|
|
41313
41443
|
}
|
|
41444
|
+
function serializeToolCallArguments(input) {
|
|
41445
|
+
return JSON.stringify(input === undefined ? {} : input);
|
|
41446
|
+
}
|
|
41314
41447
|
function convertToOpenAIChatMessages({
|
|
41315
41448
|
prompt,
|
|
41316
41449
|
systemMessageMode = "system"
|
|
@@ -41438,7 +41571,7 @@ function convertToOpenAIChatMessages({
|
|
|
41438
41571
|
type: "function",
|
|
41439
41572
|
function: {
|
|
41440
41573
|
name: part.toolName,
|
|
41441
|
-
arguments:
|
|
41574
|
+
arguments: serializeToolCallArguments(part.input)
|
|
41442
41575
|
}
|
|
41443
41576
|
});
|
|
41444
41577
|
break;
|
|
@@ -43307,6 +43440,9 @@ var toolSearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
|
43307
43440
|
inputSchema: toolSearchInputSchema,
|
|
43308
43441
|
outputSchema: toolSearchOutputSchema
|
|
43309
43442
|
});
|
|
43443
|
+
function serializeToolCallArguments2(input) {
|
|
43444
|
+
return JSON.stringify(input === undefined ? {} : input);
|
|
43445
|
+
}
|
|
43310
43446
|
function isFileId(data, prefixes) {
|
|
43311
43447
|
if (!prefixes)
|
|
43312
43448
|
return false;
|
|
@@ -43527,7 +43663,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
43527
43663
|
type: "function_call",
|
|
43528
43664
|
call_id: part.toolCallId,
|
|
43529
43665
|
name: resolvedToolName,
|
|
43530
|
-
arguments:
|
|
43666
|
+
arguments: serializeToolCallArguments2(part.input),
|
|
43531
43667
|
id
|
|
43532
43668
|
});
|
|
43533
43669
|
break;
|
|
@@ -46929,7 +47065,7 @@ var azureOpenaiTools = {
|
|
|
46929
47065
|
imageGeneration,
|
|
46930
47066
|
webSearchPreview
|
|
46931
47067
|
};
|
|
46932
|
-
var VERSION4 = "3.0.
|
|
47068
|
+
var VERSION4 = "3.0.54";
|
|
46933
47069
|
function createAzure(options = {}) {
|
|
46934
47070
|
var _a16;
|
|
46935
47071
|
const getHeaders = () => {
|
|
@@ -47729,7 +47865,8 @@ var anthropicLanguageModelOptions2 = exports_external.object({
|
|
|
47729
47865
|
structuredOutputMode: exports_external.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
47730
47866
|
thinking: exports_external.discriminatedUnion("type", [
|
|
47731
47867
|
exports_external.object({
|
|
47732
|
-
type: exports_external.literal("adaptive")
|
|
47868
|
+
type: exports_external.literal("adaptive"),
|
|
47869
|
+
display: exports_external.enum(["omitted", "summarized"]).optional()
|
|
47733
47870
|
}),
|
|
47734
47871
|
exports_external.object({
|
|
47735
47872
|
type: exports_external.literal("enabled"),
|
|
@@ -47766,8 +47903,14 @@ var anthropicLanguageModelOptions2 = exports_external.object({
|
|
|
47766
47903
|
})).optional()
|
|
47767
47904
|
}).optional(),
|
|
47768
47905
|
toolStreaming: exports_external.boolean().optional(),
|
|
47769
|
-
effort: exports_external.enum(["low", "medium", "high", "max"]).optional(),
|
|
47906
|
+
effort: exports_external.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
47907
|
+
taskBudget: exports_external.object({
|
|
47908
|
+
type: exports_external.literal("tokens"),
|
|
47909
|
+
total: exports_external.number().int().min(20000),
|
|
47910
|
+
remaining: exports_external.number().int().min(0).optional()
|
|
47911
|
+
}).optional(),
|
|
47770
47912
|
speed: exports_external.enum(["fast", "standard"]).optional(),
|
|
47913
|
+
inferenceGeo: exports_external.enum(["us", "global"]).optional(),
|
|
47771
47914
|
anthropicBeta: exports_external.array(exports_external.string()).optional(),
|
|
47772
47915
|
contextManagement: exports_external.object({
|
|
47773
47916
|
edits: exports_external.array(exports_external.discriminatedUnion("type", [
|
|
@@ -48026,9 +48169,10 @@ async function prepareTools2({
|
|
|
48026
48169
|
disableParallelToolUse,
|
|
48027
48170
|
cacheControlValidator,
|
|
48028
48171
|
supportsStructuredOutput,
|
|
48029
|
-
supportsStrictTools
|
|
48172
|
+
supportsStrictTools,
|
|
48173
|
+
defaultEagerInputStreaming = false
|
|
48030
48174
|
}) {
|
|
48031
|
-
var _a16;
|
|
48175
|
+
var _a16, _b16;
|
|
48032
48176
|
tools = (tools == null ? undefined : tools.length) ? tools : undefined;
|
|
48033
48177
|
const toolWarnings = [];
|
|
48034
48178
|
const betas = /* @__PURE__ */ new Set;
|
|
@@ -48045,7 +48189,7 @@ async function prepareTools2({
|
|
|
48045
48189
|
canCache: true
|
|
48046
48190
|
});
|
|
48047
48191
|
const anthropicOptions = (_a16 = tool2.providerOptions) == null ? undefined : _a16.anthropic;
|
|
48048
|
-
const eagerInputStreaming = anthropicOptions == null ? undefined : anthropicOptions.eagerInputStreaming;
|
|
48192
|
+
const eagerInputStreaming = (_b16 = anthropicOptions == null ? undefined : anthropicOptions.eagerInputStreaming) != null ? _b16 : defaultEagerInputStreaming;
|
|
48049
48193
|
const deferLoading = anthropicOptions == null ? undefined : anthropicOptions.deferLoading;
|
|
48050
48194
|
const allowedCallers = anthropicOptions == null ? undefined : anthropicOptions.allowedCallers;
|
|
48051
48195
|
if (!supportsStrictTools && tool2.strict != null) {
|
|
@@ -49411,9 +49555,11 @@ var amazonBedrockLanguageModelOptions = exports_external.object({
|
|
|
49411
49555
|
exports_external.literal("adaptive")
|
|
49412
49556
|
]).optional(),
|
|
49413
49557
|
budgetTokens: exports_external.number().optional(),
|
|
49414
|
-
maxReasoningEffort: exports_external.enum(["low", "medium", "high", "max"]).optional()
|
|
49558
|
+
maxReasoningEffort: exports_external.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
49559
|
+
display: exports_external.enum(["omitted", "summarized"]).optional()
|
|
49415
49560
|
}).optional(),
|
|
49416
|
-
anthropicBeta: exports_external.array(exports_external.string()).optional()
|
|
49561
|
+
anthropicBeta: exports_external.array(exports_external.string()).optional(),
|
|
49562
|
+
serviceTier: exports_external.enum(["reserved", "priority", "default", "flex"]).optional()
|
|
49417
49563
|
});
|
|
49418
49564
|
var BedrockErrorSchema = exports_external.object({
|
|
49419
49565
|
message: exports_external.string(),
|
|
@@ -49838,12 +49984,13 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
49838
49984
|
const message = block.messages[j];
|
|
49839
49985
|
const isLastMessage = j === block.messages.length - 1;
|
|
49840
49986
|
const { content } = message;
|
|
49987
|
+
const hasReasoningBlocks = content.some((part) => part.type === "reasoning");
|
|
49841
49988
|
for (let k = 0;k < content.length; k++) {
|
|
49842
49989
|
const part = content[k];
|
|
49843
49990
|
const isLastContentPart = k === content.length - 1;
|
|
49844
49991
|
switch (part.type) {
|
|
49845
49992
|
case "text": {
|
|
49846
|
-
if (!part.text.trim()) {
|
|
49993
|
+
if (!part.text.trim() && !hasReasoningBlocks) {
|
|
49847
49994
|
break;
|
|
49848
49995
|
}
|
|
49849
49996
|
bedrockContent.push({
|
|
@@ -50027,7 +50174,7 @@ var BedrockChatLanguageModel = class {
|
|
|
50027
50174
|
toolChoice,
|
|
50028
50175
|
providerOptions
|
|
50029
50176
|
}) {
|
|
50030
|
-
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
50177
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
50031
50178
|
const bedrockOptions = (_a16 = await parseProviderOptions({
|
|
50032
50179
|
provider: "bedrock",
|
|
50033
50180
|
providerOptions,
|
|
@@ -50105,6 +50252,7 @@ var BedrockChatLanguageModel = class {
|
|
|
50105
50252
|
}
|
|
50106
50253
|
const thinkingType = (_e = bedrockOptions.reasoningConfig) == null ? undefined : _e.type;
|
|
50107
50254
|
const thinkingBudget = thinkingType === "enabled" ? (_f = bedrockOptions.reasoningConfig) == null ? undefined : _f.budgetTokens : undefined;
|
|
50255
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_g = bedrockOptions.reasoningConfig) == null ? undefined : _g.display : undefined;
|
|
50108
50256
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
|
|
50109
50257
|
const inferenceConfig = {
|
|
50110
50258
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -50131,12 +50279,13 @@ var BedrockChatLanguageModel = class {
|
|
|
50131
50279
|
bedrockOptions.additionalModelRequestFields = {
|
|
50132
50280
|
...bedrockOptions.additionalModelRequestFields,
|
|
50133
50281
|
thinking: {
|
|
50134
|
-
type: "adaptive"
|
|
50282
|
+
type: "adaptive",
|
|
50283
|
+
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
50135
50284
|
}
|
|
50136
50285
|
};
|
|
50137
50286
|
}
|
|
50138
50287
|
} else if (!isAnthropicModel) {
|
|
50139
|
-
if (((
|
|
50288
|
+
if (((_h = bedrockOptions.reasoningConfig) == null ? undefined : _h.budgetTokens) != null) {
|
|
50140
50289
|
warnings.push({
|
|
50141
50290
|
type: "unsupported",
|
|
50142
50291
|
feature: "budgetTokens",
|
|
@@ -50151,14 +50300,14 @@ var BedrockChatLanguageModel = class {
|
|
|
50151
50300
|
});
|
|
50152
50301
|
}
|
|
50153
50302
|
}
|
|
50154
|
-
const maxReasoningEffort = (
|
|
50303
|
+
const maxReasoningEffort = (_i = bedrockOptions.reasoningConfig) == null ? undefined : _i.maxReasoningEffort;
|
|
50155
50304
|
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
50156
50305
|
if (maxReasoningEffort != null) {
|
|
50157
50306
|
if (isAnthropicModel) {
|
|
50158
50307
|
bedrockOptions.additionalModelRequestFields = {
|
|
50159
50308
|
...bedrockOptions.additionalModelRequestFields,
|
|
50160
50309
|
output_config: {
|
|
50161
|
-
...(
|
|
50310
|
+
...(_j = bedrockOptions.additionalModelRequestFields) == null ? undefined : _j.output_config,
|
|
50162
50311
|
effort: maxReasoningEffort
|
|
50163
50312
|
}
|
|
50164
50313
|
};
|
|
@@ -50182,7 +50331,7 @@ var BedrockChatLanguageModel = class {
|
|
|
50182
50331
|
bedrockOptions.additionalModelRequestFields = {
|
|
50183
50332
|
...bedrockOptions.additionalModelRequestFields,
|
|
50184
50333
|
output_config: {
|
|
50185
|
-
...(
|
|
50334
|
+
...(_k = bedrockOptions.additionalModelRequestFields) == null ? undefined : _k.output_config,
|
|
50186
50335
|
format: {
|
|
50187
50336
|
type: "json_schema",
|
|
50188
50337
|
schema: responseFormat.schema
|
|
@@ -50214,7 +50363,7 @@ var BedrockChatLanguageModel = class {
|
|
|
50214
50363
|
details: "topK is not supported when thinking is enabled"
|
|
50215
50364
|
});
|
|
50216
50365
|
}
|
|
50217
|
-
const hasAnyTools = ((
|
|
50366
|
+
const hasAnyTools = ((_m = (_l = toolConfig.tools) == null ? undefined : _l.length) != null ? _m : 0) > 0 || additionalTools;
|
|
50218
50367
|
let filteredPrompt = prompt;
|
|
50219
50368
|
if (!hasAnyTools) {
|
|
50220
50369
|
const hasToolContent = prompt.some((message) => ("content" in message) && Array.isArray(message.content) && message.content.some((part) => part.type === "tool-call" || part.type === "tool-result"));
|
|
@@ -50235,6 +50384,7 @@ var BedrockChatLanguageModel = class {
|
|
|
50235
50384
|
const {
|
|
50236
50385
|
reasoningConfig: _,
|
|
50237
50386
|
additionalModelRequestFields: __,
|
|
50387
|
+
serviceTier: ___,
|
|
50238
50388
|
...filteredBedrockOptions
|
|
50239
50389
|
} = (providerOptions == null ? undefined : providerOptions.bedrock) || {};
|
|
50240
50390
|
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : undefined;
|
|
@@ -50249,6 +50399,11 @@ var BedrockChatLanguageModel = class {
|
|
|
50249
50399
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
50250
50400
|
inferenceConfig
|
|
50251
50401
|
},
|
|
50402
|
+
...bedrockOptions.serviceTier != null && {
|
|
50403
|
+
serviceTier: {
|
|
50404
|
+
type: bedrockOptions.serviceTier
|
|
50405
|
+
}
|
|
50406
|
+
},
|
|
50252
50407
|
...filteredBedrockOptions,
|
|
50253
50408
|
...toolConfig.tools !== undefined && toolConfig.tools.length > 0 ? { toolConfig } : {}
|
|
50254
50409
|
},
|
|
@@ -50288,7 +50443,7 @@ var BedrockChatLanguageModel = class {
|
|
|
50288
50443
|
const content = [];
|
|
50289
50444
|
let isJsonResponseFromTool = false;
|
|
50290
50445
|
for (const part of response.output.message.content) {
|
|
50291
|
-
if (part.text) {
|
|
50446
|
+
if (part.text != null) {
|
|
50292
50447
|
content.push({ type: "text", text: part.text });
|
|
50293
50448
|
}
|
|
50294
50449
|
if (part.reasoningContent) {
|
|
@@ -50575,6 +50730,13 @@ var BedrockChatLanguageModel = class {
|
|
|
50575
50730
|
delta: reasoningContent.text
|
|
50576
50731
|
});
|
|
50577
50732
|
} else if ("signature" in reasoningContent && reasoningContent.signature) {
|
|
50733
|
+
if (contentBlocks[blockIndex] == null) {
|
|
50734
|
+
contentBlocks[blockIndex] = { type: "reasoning" };
|
|
50735
|
+
controller.enqueue({
|
|
50736
|
+
type: "reasoning-start",
|
|
50737
|
+
id: String(blockIndex)
|
|
50738
|
+
});
|
|
50739
|
+
}
|
|
50578
50740
|
controller.enqueue({
|
|
50579
50741
|
type: "reasoning-delta",
|
|
50580
50742
|
id: String(blockIndex),
|
|
@@ -50586,6 +50748,13 @@ var BedrockChatLanguageModel = class {
|
|
|
50586
50748
|
}
|
|
50587
50749
|
});
|
|
50588
50750
|
} else if ("data" in reasoningContent && reasoningContent.data) {
|
|
50751
|
+
if (contentBlocks[blockIndex] == null) {
|
|
50752
|
+
contentBlocks[blockIndex] = { type: "reasoning" };
|
|
50753
|
+
controller.enqueue({
|
|
50754
|
+
type: "reasoning-start",
|
|
50755
|
+
id: String(blockIndex)
|
|
50756
|
+
});
|
|
50757
|
+
}
|
|
50589
50758
|
controller.enqueue({
|
|
50590
50759
|
type: "reasoning-delta",
|
|
50591
50760
|
id: String(blockIndex),
|
|
@@ -51098,7 +51267,7 @@ var bedrockImageResponseSchema = exports_external.object({
|
|
|
51098
51267
|
details: exports_external.record(exports_external.string(), exports_external.unknown()).optional(),
|
|
51099
51268
|
preview: exports_external.unknown().optional()
|
|
51100
51269
|
});
|
|
51101
|
-
var VERSION5 = "4.0.
|
|
51270
|
+
var VERSION5 = "4.0.96";
|
|
51102
51271
|
function createSigV4FetchFunction(getCredentials, fetch2 = globalThis.fetch) {
|
|
51103
51272
|
return async (input, init) => {
|
|
51104
51273
|
var _a16, _b16;
|
|
@@ -51394,7 +51563,7 @@ function createBedrockProvider(config2, providerName) {
|
|
|
51394
51563
|
}
|
|
51395
51564
|
|
|
51396
51565
|
// node_modules/@ai-sdk/google/dist/index.mjs
|
|
51397
|
-
var VERSION6 = "3.0.
|
|
51566
|
+
var VERSION6 = "3.0.64";
|
|
51398
51567
|
var googleErrorDataSchema = lazySchema(() => zodSchema(exports_external.object({
|
|
51399
51568
|
error: exports_external.object({
|
|
51400
51569
|
code: exports_external.number().nullable(),
|
|
@@ -51773,7 +51942,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
|
51773
51942
|
}
|
|
51774
51943
|
}
|
|
51775
51944
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
51776
|
-
var _a16, _b16, _c, _d;
|
|
51945
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h;
|
|
51777
51946
|
const systemInstructionParts = [];
|
|
51778
51947
|
const contents = [];
|
|
51779
51948
|
let systemMessagesAllowed = true;
|
|
@@ -51858,6 +52027,18 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
51858
52027
|
};
|
|
51859
52028
|
}
|
|
51860
52029
|
case "tool-call": {
|
|
52030
|
+
const serverToolCallId = (providerOpts == null ? undefined : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : undefined;
|
|
52031
|
+
const serverToolType = (providerOpts == null ? undefined : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : undefined;
|
|
52032
|
+
if (serverToolCallId && serverToolType) {
|
|
52033
|
+
return {
|
|
52034
|
+
toolCall: {
|
|
52035
|
+
toolType: serverToolType,
|
|
52036
|
+
args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
|
|
52037
|
+
id: serverToolCallId
|
|
52038
|
+
},
|
|
52039
|
+
thoughtSignature
|
|
52040
|
+
};
|
|
52041
|
+
}
|
|
51861
52042
|
return {
|
|
51862
52043
|
functionCall: {
|
|
51863
52044
|
name: part.toolName,
|
|
@@ -51866,6 +52047,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
51866
52047
|
thoughtSignature
|
|
51867
52048
|
};
|
|
51868
52049
|
}
|
|
52050
|
+
case "tool-result": {
|
|
52051
|
+
const serverToolCallId = (providerOpts == null ? undefined : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : undefined;
|
|
52052
|
+
const serverToolType = (providerOpts == null ? undefined : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : undefined;
|
|
52053
|
+
if (serverToolCallId && serverToolType) {
|
|
52054
|
+
return {
|
|
52055
|
+
toolResponse: {
|
|
52056
|
+
toolType: serverToolType,
|
|
52057
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
52058
|
+
id: serverToolCallId
|
|
52059
|
+
},
|
|
52060
|
+
thoughtSignature
|
|
52061
|
+
};
|
|
52062
|
+
}
|
|
52063
|
+
return;
|
|
52064
|
+
}
|
|
51869
52065
|
}
|
|
51870
52066
|
}).filter((part) => part !== undefined)
|
|
51871
52067
|
});
|
|
@@ -51878,6 +52074,26 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
51878
52074
|
if (part.type === "tool-approval-response") {
|
|
51879
52075
|
continue;
|
|
51880
52076
|
}
|
|
52077
|
+
const partProviderOpts = (_g = (_d = part.providerOptions) == null ? undefined : _d[providerOptionsName]) != null ? _g : providerOptionsName !== "google" ? (_e = part.providerOptions) == null ? undefined : _e.google : (_f = part.providerOptions) == null ? undefined : _f.vertex;
|
|
52078
|
+
const serverToolCallId = (partProviderOpts == null ? undefined : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : undefined;
|
|
52079
|
+
const serverToolType = (partProviderOpts == null ? undefined : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : undefined;
|
|
52080
|
+
if (serverToolCallId && serverToolType) {
|
|
52081
|
+
const serverThoughtSignature = (partProviderOpts == null ? undefined : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : undefined;
|
|
52082
|
+
if (contents.length > 0) {
|
|
52083
|
+
const lastContent = contents[contents.length - 1];
|
|
52084
|
+
if (lastContent.role === "model") {
|
|
52085
|
+
lastContent.parts.push({
|
|
52086
|
+
toolResponse: {
|
|
52087
|
+
toolType: serverToolType,
|
|
52088
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
52089
|
+
id: serverToolCallId
|
|
52090
|
+
},
|
|
52091
|
+
thoughtSignature: serverThoughtSignature
|
|
52092
|
+
});
|
|
52093
|
+
continue;
|
|
52094
|
+
}
|
|
52095
|
+
}
|
|
52096
|
+
}
|
|
51881
52097
|
const output = part.output;
|
|
51882
52098
|
if (output.type === "content") {
|
|
51883
52099
|
if (supportsFunctionResponseParts) {
|
|
@@ -51891,7 +52107,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
51891
52107
|
name: part.toolName,
|
|
51892
52108
|
response: {
|
|
51893
52109
|
name: part.toolName,
|
|
51894
|
-
content: output.type === "execution-denied" ? (
|
|
52110
|
+
content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
|
|
51895
52111
|
}
|
|
51896
52112
|
}
|
|
51897
52113
|
});
|
|
@@ -51989,18 +52205,20 @@ var googleLanguageModelOptions = lazySchema(() => zodSchema(exports_external.obj
|
|
|
51989
52205
|
longitude: exports_external.number()
|
|
51990
52206
|
}).optional()
|
|
51991
52207
|
}).optional(),
|
|
51992
|
-
|
|
51993
|
-
|
|
51994
|
-
"SERVICE_TIER_FLEX",
|
|
51995
|
-
"SERVICE_TIER_PRIORITY"
|
|
51996
|
-
]).optional()
|
|
52208
|
+
streamFunctionCallArguments: exports_external.boolean().optional(),
|
|
52209
|
+
serviceTier: exports_external.enum(["standard", "flex", "priority"]).optional()
|
|
51997
52210
|
})));
|
|
52211
|
+
var VertexServiceTierMap = {
|
|
52212
|
+
standard: "SERVICE_TIER_STANDARD",
|
|
52213
|
+
flex: "SERVICE_TIER_FLEX",
|
|
52214
|
+
priority: "SERVICE_TIER_PRIORITY"
|
|
52215
|
+
};
|
|
51998
52216
|
function prepareTools4({
|
|
51999
52217
|
tools,
|
|
52000
52218
|
toolChoice,
|
|
52001
52219
|
modelId
|
|
52002
52220
|
}) {
|
|
52003
|
-
var _a16;
|
|
52221
|
+
var _a16, _b16;
|
|
52004
52222
|
tools = (tools == null ? undefined : tools.length) ? tools : undefined;
|
|
52005
52223
|
const toolWarnings = [];
|
|
52006
52224
|
const isLatest = [
|
|
@@ -52009,13 +52227,14 @@ function prepareTools4({
|
|
|
52009
52227
|
"gemini-pro-latest"
|
|
52010
52228
|
].some((id) => id === modelId);
|
|
52011
52229
|
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
52230
|
+
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
52012
52231
|
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
52013
52232
|
if (tools == null) {
|
|
52014
52233
|
return { tools: undefined, toolConfig: undefined, toolWarnings };
|
|
52015
52234
|
}
|
|
52016
52235
|
const hasFunctionTools = tools.some((tool2) => tool2.type === "function");
|
|
52017
52236
|
const hasProviderTools = tools.some((tool2) => tool2.type === "provider");
|
|
52018
|
-
if (hasFunctionTools && hasProviderTools) {
|
|
52237
|
+
if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
|
|
52019
52238
|
toolWarnings.push({
|
|
52020
52239
|
type: "unsupported",
|
|
52021
52240
|
feature: `combination of function and provider-defined tools`
|
|
@@ -52066,7 +52285,7 @@ function prepareTools4({
|
|
|
52066
52285
|
toolWarnings.push({
|
|
52067
52286
|
type: "unsupported",
|
|
52068
52287
|
feature: `provider-defined tool ${tool2.id}`,
|
|
52069
|
-
details: "The code execution
|
|
52288
|
+
details: "The code execution tool is not supported with other Gemini models than Gemini 2."
|
|
52070
52289
|
});
|
|
52071
52290
|
}
|
|
52072
52291
|
break;
|
|
@@ -52120,6 +52339,45 @@ function prepareTools4({
|
|
|
52120
52339
|
break;
|
|
52121
52340
|
}
|
|
52122
52341
|
});
|
|
52342
|
+
if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
|
|
52343
|
+
const functionDeclarations2 = [];
|
|
52344
|
+
for (const tool2 of tools) {
|
|
52345
|
+
if (tool2.type === "function") {
|
|
52346
|
+
functionDeclarations2.push({
|
|
52347
|
+
name: tool2.name,
|
|
52348
|
+
description: (_a16 = tool2.description) != null ? _a16 : "",
|
|
52349
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool2.inputSchema)
|
|
52350
|
+
});
|
|
52351
|
+
}
|
|
52352
|
+
}
|
|
52353
|
+
const combinedToolConfig = {
|
|
52354
|
+
functionCallingConfig: { mode: "VALIDATED" },
|
|
52355
|
+
includeServerSideToolInvocations: true
|
|
52356
|
+
};
|
|
52357
|
+
if (toolChoice != null) {
|
|
52358
|
+
switch (toolChoice.type) {
|
|
52359
|
+
case "auto":
|
|
52360
|
+
break;
|
|
52361
|
+
case "none":
|
|
52362
|
+
combinedToolConfig.functionCallingConfig = { mode: "NONE" };
|
|
52363
|
+
break;
|
|
52364
|
+
case "required":
|
|
52365
|
+
combinedToolConfig.functionCallingConfig = { mode: "ANY" };
|
|
52366
|
+
break;
|
|
52367
|
+
case "tool":
|
|
52368
|
+
combinedToolConfig.functionCallingConfig = {
|
|
52369
|
+
mode: "ANY",
|
|
52370
|
+
allowedFunctionNames: [toolChoice.toolName]
|
|
52371
|
+
};
|
|
52372
|
+
break;
|
|
52373
|
+
}
|
|
52374
|
+
}
|
|
52375
|
+
return {
|
|
52376
|
+
tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
|
|
52377
|
+
toolConfig: combinedToolConfig,
|
|
52378
|
+
toolWarnings
|
|
52379
|
+
};
|
|
52380
|
+
}
|
|
52123
52381
|
return {
|
|
52124
52382
|
tools: googleTools2.length > 0 ? googleTools2 : undefined,
|
|
52125
52383
|
toolConfig: undefined,
|
|
@@ -52133,7 +52391,7 @@ function prepareTools4({
|
|
|
52133
52391
|
case "function":
|
|
52134
52392
|
functionDeclarations.push({
|
|
52135
52393
|
name: tool2.name,
|
|
52136
|
-
description: (
|
|
52394
|
+
description: (_b16 = tool2.description) != null ? _b16 : "",
|
|
52137
52395
|
parameters: convertJSONSchemaToOpenAPISchema(tool2.inputSchema)
|
|
52138
52396
|
});
|
|
52139
52397
|
if (tool2.strict === true) {
|
|
@@ -52202,6 +52460,172 @@ function prepareTools4({
|
|
|
52202
52460
|
}
|
|
52203
52461
|
}
|
|
52204
52462
|
}
|
|
52463
|
+
var GoogleJSONAccumulator = class {
|
|
52464
|
+
constructor() {
|
|
52465
|
+
this.accumulatedArgs = {};
|
|
52466
|
+
this.jsonText = "";
|
|
52467
|
+
this.pathStack = [];
|
|
52468
|
+
this.stringOpen = false;
|
|
52469
|
+
}
|
|
52470
|
+
processPartialArgs(partialArgs) {
|
|
52471
|
+
let delta = "";
|
|
52472
|
+
for (const arg of partialArgs) {
|
|
52473
|
+
const rawPath = arg.jsonPath.replace(/^\$\./, "");
|
|
52474
|
+
if (!rawPath)
|
|
52475
|
+
continue;
|
|
52476
|
+
const segments = parsePath(rawPath);
|
|
52477
|
+
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
52478
|
+
const isStringContinuation = arg.stringValue != null && existingValue !== undefined;
|
|
52479
|
+
if (isStringContinuation) {
|
|
52480
|
+
const escaped = JSON.stringify(arg.stringValue).slice(1, -1);
|
|
52481
|
+
setNestedValue(this.accumulatedArgs, segments, existingValue + arg.stringValue);
|
|
52482
|
+
delta += escaped;
|
|
52483
|
+
continue;
|
|
52484
|
+
}
|
|
52485
|
+
const resolved = resolvePartialArgValue(arg);
|
|
52486
|
+
if (resolved == null)
|
|
52487
|
+
continue;
|
|
52488
|
+
setNestedValue(this.accumulatedArgs, segments, resolved.value);
|
|
52489
|
+
delta += this.emitNavigationTo(segments, arg, resolved.json);
|
|
52490
|
+
}
|
|
52491
|
+
this.jsonText += delta;
|
|
52492
|
+
return {
|
|
52493
|
+
currentJSON: this.accumulatedArgs,
|
|
52494
|
+
textDelta: delta
|
|
52495
|
+
};
|
|
52496
|
+
}
|
|
52497
|
+
finalize() {
|
|
52498
|
+
const finalArgs = JSON.stringify(this.accumulatedArgs);
|
|
52499
|
+
const closingDelta = finalArgs.slice(this.jsonText.length);
|
|
52500
|
+
return { finalJSON: finalArgs, closingDelta };
|
|
52501
|
+
}
|
|
52502
|
+
ensureRoot() {
|
|
52503
|
+
if (this.pathStack.length === 0) {
|
|
52504
|
+
this.pathStack.push({ segment: "", isArray: false, childCount: 0 });
|
|
52505
|
+
return "{";
|
|
52506
|
+
}
|
|
52507
|
+
return "";
|
|
52508
|
+
}
|
|
52509
|
+
emitNavigationTo(targetSegments, arg, valueJson) {
|
|
52510
|
+
let fragment = "";
|
|
52511
|
+
if (this.stringOpen) {
|
|
52512
|
+
fragment += '"';
|
|
52513
|
+
this.stringOpen = false;
|
|
52514
|
+
}
|
|
52515
|
+
fragment += this.ensureRoot();
|
|
52516
|
+
const targetContainerSegments = targetSegments.slice(0, -1);
|
|
52517
|
+
const leafSegment = targetSegments[targetSegments.length - 1];
|
|
52518
|
+
const commonDepth = this.findCommonStackDepth(targetContainerSegments);
|
|
52519
|
+
fragment += this.closeDownTo(commonDepth);
|
|
52520
|
+
fragment += this.openDownTo(targetContainerSegments, leafSegment);
|
|
52521
|
+
fragment += this.emitLeaf(leafSegment, arg, valueJson);
|
|
52522
|
+
return fragment;
|
|
52523
|
+
}
|
|
52524
|
+
findCommonStackDepth(targetContainer) {
|
|
52525
|
+
const maxDepth = Math.min(this.pathStack.length - 1, targetContainer.length);
|
|
52526
|
+
let common = 0;
|
|
52527
|
+
for (let i = 0;i < maxDepth; i++) {
|
|
52528
|
+
if (this.pathStack[i + 1].segment === targetContainer[i]) {
|
|
52529
|
+
common++;
|
|
52530
|
+
} else {
|
|
52531
|
+
break;
|
|
52532
|
+
}
|
|
52533
|
+
}
|
|
52534
|
+
return common + 1;
|
|
52535
|
+
}
|
|
52536
|
+
closeDownTo(targetDepth) {
|
|
52537
|
+
let fragment = "";
|
|
52538
|
+
while (this.pathStack.length > targetDepth) {
|
|
52539
|
+
const entry = this.pathStack.pop();
|
|
52540
|
+
fragment += entry.isArray ? "]" : "}";
|
|
52541
|
+
}
|
|
52542
|
+
return fragment;
|
|
52543
|
+
}
|
|
52544
|
+
openDownTo(targetContainer, leafSegment) {
|
|
52545
|
+
let fragment = "";
|
|
52546
|
+
const startIdx = this.pathStack.length - 1;
|
|
52547
|
+
for (let i = startIdx;i < targetContainer.length; i++) {
|
|
52548
|
+
const seg = targetContainer[i];
|
|
52549
|
+
const parentEntry = this.pathStack[this.pathStack.length - 1];
|
|
52550
|
+
if (parentEntry.childCount > 0) {
|
|
52551
|
+
fragment += ",";
|
|
52552
|
+
}
|
|
52553
|
+
parentEntry.childCount++;
|
|
52554
|
+
if (typeof seg === "string") {
|
|
52555
|
+
fragment += `${JSON.stringify(seg)}:`;
|
|
52556
|
+
}
|
|
52557
|
+
const childSeg = i + 1 < targetContainer.length ? targetContainer[i + 1] : leafSegment;
|
|
52558
|
+
const isArray = typeof childSeg === "number";
|
|
52559
|
+
fragment += isArray ? "[" : "{";
|
|
52560
|
+
this.pathStack.push({ segment: seg, isArray, childCount: 0 });
|
|
52561
|
+
}
|
|
52562
|
+
return fragment;
|
|
52563
|
+
}
|
|
52564
|
+
emitLeaf(leafSegment, arg, valueJson) {
|
|
52565
|
+
let fragment = "";
|
|
52566
|
+
const container = this.pathStack[this.pathStack.length - 1];
|
|
52567
|
+
if (container.childCount > 0) {
|
|
52568
|
+
fragment += ",";
|
|
52569
|
+
}
|
|
52570
|
+
container.childCount++;
|
|
52571
|
+
if (typeof leafSegment === "string") {
|
|
52572
|
+
fragment += `${JSON.stringify(leafSegment)}:`;
|
|
52573
|
+
}
|
|
52574
|
+
if (arg.stringValue != null && arg.willContinue) {
|
|
52575
|
+
fragment += valueJson.slice(0, -1);
|
|
52576
|
+
this.stringOpen = true;
|
|
52577
|
+
} else {
|
|
52578
|
+
fragment += valueJson;
|
|
52579
|
+
}
|
|
52580
|
+
return fragment;
|
|
52581
|
+
}
|
|
52582
|
+
};
|
|
52583
|
+
function parsePath(rawPath) {
|
|
52584
|
+
const segments = [];
|
|
52585
|
+
for (const part of rawPath.split(".")) {
|
|
52586
|
+
const bracketIdx = part.indexOf("[");
|
|
52587
|
+
if (bracketIdx === -1) {
|
|
52588
|
+
segments.push(part);
|
|
52589
|
+
} else {
|
|
52590
|
+
if (bracketIdx > 0)
|
|
52591
|
+
segments.push(part.slice(0, bracketIdx));
|
|
52592
|
+
for (const m of part.matchAll(/\[(\d+)\]/g)) {
|
|
52593
|
+
segments.push(parseInt(m[1], 10));
|
|
52594
|
+
}
|
|
52595
|
+
}
|
|
52596
|
+
}
|
|
52597
|
+
return segments;
|
|
52598
|
+
}
|
|
52599
|
+
function getNestedValue(obj, segments) {
|
|
52600
|
+
let current = obj;
|
|
52601
|
+
for (const seg of segments) {
|
|
52602
|
+
if (current == null || typeof current !== "object")
|
|
52603
|
+
return;
|
|
52604
|
+
current = current[seg];
|
|
52605
|
+
}
|
|
52606
|
+
return current;
|
|
52607
|
+
}
|
|
52608
|
+
function setNestedValue(obj, segments, value) {
|
|
52609
|
+
let current = obj;
|
|
52610
|
+
for (let i = 0;i < segments.length - 1; i++) {
|
|
52611
|
+
const seg = segments[i];
|
|
52612
|
+
const nextSeg = segments[i + 1];
|
|
52613
|
+
if (current[seg] == null) {
|
|
52614
|
+
current[seg] = typeof nextSeg === "number" ? [] : {};
|
|
52615
|
+
}
|
|
52616
|
+
current = current[seg];
|
|
52617
|
+
}
|
|
52618
|
+
current[segments[segments.length - 1]] = value;
|
|
52619
|
+
}
|
|
52620
|
+
function resolvePartialArgValue(arg) {
|
|
52621
|
+
var _a16, _b16;
|
|
52622
|
+
const value = (_b16 = (_a16 = arg.stringValue) != null ? _a16 : arg.numberValue) != null ? _b16 : arg.boolValue;
|
|
52623
|
+
if (value != null)
|
|
52624
|
+
return { value, json: JSON.stringify(value) };
|
|
52625
|
+
if ("nullValue" in arg)
|
|
52626
|
+
return { value: null, json: "null" };
|
|
52627
|
+
return;
|
|
52628
|
+
}
|
|
52205
52629
|
function mapGoogleGenerativeAIFinishReason({
|
|
52206
52630
|
finishReason,
|
|
52207
52631
|
hasToolCalls
|
|
@@ -52255,8 +52679,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52255
52679
|
tools,
|
|
52256
52680
|
toolChoice,
|
|
52257
52681
|
providerOptions
|
|
52258
|
-
}) {
|
|
52259
|
-
var _a16;
|
|
52682
|
+
}, { isStreaming = false } = {}) {
|
|
52683
|
+
var _a16, _b16;
|
|
52260
52684
|
const warnings = [];
|
|
52261
52685
|
const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
|
|
52262
52686
|
let googleOptions = await parseProviderOptions({
|
|
@@ -52271,12 +52695,23 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52271
52695
|
schema: googleLanguageModelOptions
|
|
52272
52696
|
});
|
|
52273
52697
|
}
|
|
52274
|
-
|
|
52698
|
+
const isVertexProvider = this.config.provider.startsWith("google.vertex.");
|
|
52699
|
+
if ((tools == null ? undefined : tools.some((tool2) => tool2.type === "provider" && tool2.id === "google.vertex_rag_store")) && !isVertexProvider) {
|
|
52275
52700
|
warnings.push({
|
|
52276
52701
|
type: "other",
|
|
52277
52702
|
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}).`
|
|
52278
52703
|
});
|
|
52279
52704
|
}
|
|
52705
|
+
if ((googleOptions == null ? undefined : googleOptions.streamFunctionCallArguments) && !isVertexProvider) {
|
|
52706
|
+
warnings.push({
|
|
52707
|
+
type: "other",
|
|
52708
|
+
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`
|
|
52709
|
+
});
|
|
52710
|
+
}
|
|
52711
|
+
let sanitizedServiceTier = googleOptions == null ? undefined : googleOptions.serviceTier;
|
|
52712
|
+
if ((googleOptions == null ? undefined : googleOptions.serviceTier) && isVertexProvider) {
|
|
52713
|
+
sanitizedServiceTier = VertexServiceTierMap[googleOptions.serviceTier];
|
|
52714
|
+
}
|
|
52280
52715
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
52281
52716
|
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
52282
52717
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(prompt, {
|
|
@@ -52293,6 +52728,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52293
52728
|
toolChoice,
|
|
52294
52729
|
modelId: this.modelId
|
|
52295
52730
|
});
|
|
52731
|
+
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a16 = googleOptions == null ? undefined : googleOptions.streamFunctionCallArguments) != null ? _a16 : false : undefined;
|
|
52732
|
+
const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? undefined : googleOptions.retrievalConfig) ? {
|
|
52733
|
+
...googleToolConfig,
|
|
52734
|
+
...streamFunctionCallArguments && {
|
|
52735
|
+
functionCallingConfig: {
|
|
52736
|
+
...googleToolConfig == null ? undefined : googleToolConfig.functionCallingConfig,
|
|
52737
|
+
streamFunctionCallArguments: true
|
|
52738
|
+
}
|
|
52739
|
+
},
|
|
52740
|
+
...(googleOptions == null ? undefined : googleOptions.retrievalConfig) && {
|
|
52741
|
+
retrievalConfig: googleOptions.retrievalConfig
|
|
52742
|
+
}
|
|
52743
|
+
} : undefined;
|
|
52296
52744
|
return {
|
|
52297
52745
|
args: {
|
|
52298
52746
|
generationConfig: {
|
|
@@ -52305,7 +52753,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52305
52753
|
stopSequences,
|
|
52306
52754
|
seed,
|
|
52307
52755
|
responseMimeType: (responseFormat == null ? undefined : responseFormat.type) === "json" ? "application/json" : undefined,
|
|
52308
|
-
responseSchema: (responseFormat == null ? undefined : responseFormat.type) === "json" && responseFormat.schema != null && ((
|
|
52756
|
+
responseSchema: (responseFormat == null ? undefined : responseFormat.type) === "json" && responseFormat.schema != null && ((_b16 = googleOptions == null ? undefined : googleOptions.structuredOutputs) != null ? _b16 : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : undefined,
|
|
52309
52757
|
...(googleOptions == null ? undefined : googleOptions.audioTimestamp) && {
|
|
52310
52758
|
audioTimestamp: googleOptions.audioTimestamp
|
|
52311
52759
|
},
|
|
@@ -52322,20 +52770,17 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52322
52770
|
systemInstruction: isGemmaModel ? undefined : systemInstruction,
|
|
52323
52771
|
safetySettings: googleOptions == null ? undefined : googleOptions.safetySettings,
|
|
52324
52772
|
tools: googleTools2,
|
|
52325
|
-
toolConfig
|
|
52326
|
-
...googleToolConfig,
|
|
52327
|
-
retrievalConfig: googleOptions.retrievalConfig
|
|
52328
|
-
} : googleToolConfig,
|
|
52773
|
+
toolConfig,
|
|
52329
52774
|
cachedContent: googleOptions == null ? undefined : googleOptions.cachedContent,
|
|
52330
52775
|
labels: googleOptions == null ? undefined : googleOptions.labels,
|
|
52331
|
-
serviceTier:
|
|
52776
|
+
serviceTier: sanitizedServiceTier
|
|
52332
52777
|
},
|
|
52333
52778
|
warnings: [...warnings, ...toolWarnings],
|
|
52334
52779
|
providerOptionsName
|
|
52335
52780
|
};
|
|
52336
52781
|
}
|
|
52337
52782
|
async doGenerate(options) {
|
|
52338
|
-
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
52783
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
52339
52784
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
52340
52785
|
const mergedHeaders = combineHeaders(await resolve(this.config.headers), options.headers);
|
|
52341
52786
|
const {
|
|
@@ -52356,6 +52801,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52356
52801
|
const parts = (_b16 = (_a16 = candidate.content) == null ? undefined : _a16.parts) != null ? _b16 : [];
|
|
52357
52802
|
const usageMetadata = response.usageMetadata;
|
|
52358
52803
|
let lastCodeExecutionToolCallId;
|
|
52804
|
+
let lastServerToolCallId;
|
|
52359
52805
|
for (const part of parts) {
|
|
52360
52806
|
if ("executableCode" in part && ((_c = part.executableCode) == null ? undefined : _c.code)) {
|
|
52361
52807
|
const toolCallId = this.config.generateId();
|
|
@@ -52396,7 +52842,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52396
52842
|
providerMetadata: thoughtSignatureMetadata
|
|
52397
52843
|
});
|
|
52398
52844
|
}
|
|
52399
|
-
} else if ("functionCall" in part) {
|
|
52845
|
+
} else if ("functionCall" in part && part.functionCall.name != null && part.functionCall.args != null) {
|
|
52400
52846
|
content.push({
|
|
52401
52847
|
type: "tool-call",
|
|
52402
52848
|
toolCallId: this.config.generateId(),
|
|
@@ -52422,12 +52868,56 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52422
52868
|
}
|
|
52423
52869
|
} : undefined
|
|
52424
52870
|
});
|
|
52871
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
52872
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
|
|
52873
|
+
lastServerToolCallId = toolCallId;
|
|
52874
|
+
content.push({
|
|
52875
|
+
type: "tool-call",
|
|
52876
|
+
toolCallId,
|
|
52877
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
52878
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
52879
|
+
providerExecuted: true,
|
|
52880
|
+
dynamic: true,
|
|
52881
|
+
providerMetadata: part.thoughtSignature ? {
|
|
52882
|
+
[providerOptionsName]: {
|
|
52883
|
+
thoughtSignature: part.thoughtSignature,
|
|
52884
|
+
serverToolCallId: toolCallId,
|
|
52885
|
+
serverToolType: part.toolCall.toolType
|
|
52886
|
+
}
|
|
52887
|
+
} : {
|
|
52888
|
+
[providerOptionsName]: {
|
|
52889
|
+
serverToolCallId: toolCallId,
|
|
52890
|
+
serverToolType: part.toolCall.toolType
|
|
52891
|
+
}
|
|
52892
|
+
}
|
|
52893
|
+
});
|
|
52894
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
52895
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
|
|
52896
|
+
content.push({
|
|
52897
|
+
type: "tool-result",
|
|
52898
|
+
toolCallId: responseToolCallId,
|
|
52899
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
52900
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
52901
|
+
providerMetadata: part.thoughtSignature ? {
|
|
52902
|
+
[providerOptionsName]: {
|
|
52903
|
+
thoughtSignature: part.thoughtSignature,
|
|
52904
|
+
serverToolCallId: responseToolCallId,
|
|
52905
|
+
serverToolType: part.toolResponse.toolType
|
|
52906
|
+
}
|
|
52907
|
+
} : {
|
|
52908
|
+
[providerOptionsName]: {
|
|
52909
|
+
serverToolCallId: responseToolCallId,
|
|
52910
|
+
serverToolType: part.toolResponse.toolType
|
|
52911
|
+
}
|
|
52912
|
+
}
|
|
52913
|
+
});
|
|
52914
|
+
lastServerToolCallId = undefined;
|
|
52425
52915
|
}
|
|
52426
52916
|
}
|
|
52427
|
-
const sources = (
|
|
52917
|
+
const sources = (_i = extractSources({
|
|
52428
52918
|
groundingMetadata: candidate.groundingMetadata,
|
|
52429
52919
|
generateId: this.config.generateId
|
|
52430
|
-
})) != null ?
|
|
52920
|
+
})) != null ? _i : [];
|
|
52431
52921
|
for (const source of sources) {
|
|
52432
52922
|
content.push(source);
|
|
52433
52923
|
}
|
|
@@ -52438,19 +52928,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52438
52928
|
finishReason: candidate.finishReason,
|
|
52439
52929
|
hasToolCalls: content.some((part) => part.type === "tool-call" && !part.providerExecuted)
|
|
52440
52930
|
}),
|
|
52441
|
-
raw: (
|
|
52931
|
+
raw: (_j = candidate.finishReason) != null ? _j : undefined
|
|
52442
52932
|
},
|
|
52443
52933
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
52444
52934
|
warnings,
|
|
52445
52935
|
providerMetadata: {
|
|
52446
52936
|
[providerOptionsName]: {
|
|
52447
|
-
promptFeedback: (
|
|
52448
|
-
groundingMetadata: (
|
|
52449
|
-
urlContextMetadata: (
|
|
52450
|
-
safetyRatings: (
|
|
52937
|
+
promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
|
|
52938
|
+
groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
|
|
52939
|
+
urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
|
|
52940
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
52451
52941
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
52452
|
-
finishMessage: (
|
|
52453
|
-
serviceTier: (
|
|
52942
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
52943
|
+
serviceTier: (_p = response.serviceTier) != null ? _p : null
|
|
52454
52944
|
}
|
|
52455
52945
|
},
|
|
52456
52946
|
request: { body: args },
|
|
@@ -52461,7 +52951,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52461
52951
|
};
|
|
52462
52952
|
}
|
|
52463
52953
|
async doStream(options) {
|
|
52464
|
-
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
52954
|
+
const { args, warnings, providerOptionsName } = await this.getArgs(options, { isStreaming: true });
|
|
52465
52955
|
const headers = combineHeaders(await resolve(this.config.headers), options.headers);
|
|
52466
52956
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
52467
52957
|
url: `${this.config.baseURL}/${getModelPath(this.modelId)}:streamGenerateContent?alt=sse`,
|
|
@@ -52488,13 +52978,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52488
52978
|
let blockCounter = 0;
|
|
52489
52979
|
const emittedSourceUrls = /* @__PURE__ */ new Set;
|
|
52490
52980
|
let lastCodeExecutionToolCallId;
|
|
52981
|
+
let lastServerToolCallId;
|
|
52982
|
+
const activeStreamingToolCalls = [];
|
|
52491
52983
|
return {
|
|
52492
52984
|
stream: response.pipeThrough(new TransformStream({
|
|
52493
52985
|
start(controller) {
|
|
52494
52986
|
controller.enqueue({ type: "stream-start", warnings });
|
|
52495
52987
|
},
|
|
52496
52988
|
transform(chunk, controller) {
|
|
52497
|
-
var _a16, _b16, _c, _d, _e, _f, _g;
|
|
52989
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
52498
52990
|
if (options.includeRawChunks) {
|
|
52499
52991
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
52500
52992
|
}
|
|
@@ -52649,38 +53141,145 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52649
53141
|
data: part.inlineData.data,
|
|
52650
53142
|
providerMetadata: fileMeta
|
|
52651
53143
|
});
|
|
53144
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
53145
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId3();
|
|
53146
|
+
lastServerToolCallId = toolCallId;
|
|
53147
|
+
const serverMeta = {
|
|
53148
|
+
[providerOptionsName]: {
|
|
53149
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
53150
|
+
serverToolCallId: toolCallId,
|
|
53151
|
+
serverToolType: part.toolCall.toolType
|
|
53152
|
+
}
|
|
53153
|
+
};
|
|
53154
|
+
controller.enqueue({
|
|
53155
|
+
type: "tool-call",
|
|
53156
|
+
toolCallId,
|
|
53157
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
53158
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
53159
|
+
providerExecuted: true,
|
|
53160
|
+
dynamic: true,
|
|
53161
|
+
providerMetadata: serverMeta
|
|
53162
|
+
});
|
|
53163
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
53164
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId3();
|
|
53165
|
+
const serverMeta = {
|
|
53166
|
+
[providerOptionsName]: {
|
|
53167
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
53168
|
+
serverToolCallId: responseToolCallId,
|
|
53169
|
+
serverToolType: part.toolResponse.toolType
|
|
53170
|
+
}
|
|
53171
|
+
};
|
|
53172
|
+
controller.enqueue({
|
|
53173
|
+
type: "tool-result",
|
|
53174
|
+
toolCallId: responseToolCallId,
|
|
53175
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
53176
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
53177
|
+
providerMetadata: serverMeta
|
|
53178
|
+
});
|
|
53179
|
+
lastServerToolCallId = undefined;
|
|
52652
53180
|
}
|
|
52653
53181
|
}
|
|
52654
|
-
const
|
|
52655
|
-
|
|
52656
|
-
|
|
52657
|
-
|
|
52658
|
-
|
|
52659
|
-
|
|
52660
|
-
|
|
53182
|
+
for (const part of parts) {
|
|
53183
|
+
if (!("functionCall" in part))
|
|
53184
|
+
continue;
|
|
53185
|
+
const providerMeta = part.thoughtSignature ? {
|
|
53186
|
+
[providerOptionsName]: {
|
|
53187
|
+
thoughtSignature: part.thoughtSignature
|
|
53188
|
+
}
|
|
53189
|
+
} : undefined;
|
|
53190
|
+
const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
|
|
53191
|
+
const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
|
|
53192
|
+
const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
|
|
53193
|
+
if (isStreamingChunk) {
|
|
53194
|
+
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
53195
|
+
const toolCallId = generateId3();
|
|
53196
|
+
const accumulator = new GoogleJSONAccumulator;
|
|
53197
|
+
activeStreamingToolCalls.push({
|
|
53198
|
+
toolCallId,
|
|
53199
|
+
toolName: part.functionCall.name,
|
|
53200
|
+
accumulator,
|
|
53201
|
+
providerMetadata: providerMeta
|
|
53202
|
+
});
|
|
53203
|
+
controller.enqueue({
|
|
53204
|
+
type: "tool-input-start",
|
|
53205
|
+
id: toolCallId,
|
|
53206
|
+
toolName: part.functionCall.name,
|
|
53207
|
+
providerMetadata: providerMeta
|
|
53208
|
+
});
|
|
53209
|
+
if (part.functionCall.partialArgs != null) {
|
|
53210
|
+
const { textDelta } = accumulator.processPartialArgs(part.functionCall.partialArgs);
|
|
53211
|
+
if (textDelta.length > 0) {
|
|
53212
|
+
controller.enqueue({
|
|
53213
|
+
type: "tool-input-delta",
|
|
53214
|
+
id: toolCallId,
|
|
53215
|
+
delta: textDelta,
|
|
53216
|
+
providerMetadata: providerMeta
|
|
53217
|
+
});
|
|
53218
|
+
}
|
|
53219
|
+
}
|
|
53220
|
+
} else if (part.functionCall.partialArgs != null && activeStreamingToolCalls.length > 0) {
|
|
53221
|
+
const active = activeStreamingToolCalls[activeStreamingToolCalls.length - 1];
|
|
53222
|
+
const { textDelta } = active.accumulator.processPartialArgs(part.functionCall.partialArgs);
|
|
53223
|
+
if (textDelta.length > 0) {
|
|
53224
|
+
controller.enqueue({
|
|
53225
|
+
type: "tool-input-delta",
|
|
53226
|
+
id: active.toolCallId,
|
|
53227
|
+
delta: textDelta,
|
|
53228
|
+
providerMetadata: providerMeta
|
|
53229
|
+
});
|
|
53230
|
+
}
|
|
53231
|
+
}
|
|
53232
|
+
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
53233
|
+
const active = activeStreamingToolCalls.pop();
|
|
53234
|
+
const { finalJSON, closingDelta } = active.accumulator.finalize();
|
|
53235
|
+
if (closingDelta.length > 0) {
|
|
53236
|
+
controller.enqueue({
|
|
53237
|
+
type: "tool-input-delta",
|
|
53238
|
+
id: active.toolCallId,
|
|
53239
|
+
delta: closingDelta,
|
|
53240
|
+
providerMetadata: active.providerMetadata
|
|
53241
|
+
});
|
|
53242
|
+
}
|
|
53243
|
+
controller.enqueue({
|
|
53244
|
+
type: "tool-input-end",
|
|
53245
|
+
id: active.toolCallId,
|
|
53246
|
+
providerMetadata: active.providerMetadata
|
|
53247
|
+
});
|
|
53248
|
+
controller.enqueue({
|
|
53249
|
+
type: "tool-call",
|
|
53250
|
+
toolCallId: active.toolCallId,
|
|
53251
|
+
toolName: active.toolName,
|
|
53252
|
+
input: finalJSON,
|
|
53253
|
+
providerMetadata: active.providerMetadata
|
|
53254
|
+
});
|
|
53255
|
+
hasToolCalls = true;
|
|
53256
|
+
} else if (isCompleteCall) {
|
|
53257
|
+
const toolCallId = generateId3();
|
|
53258
|
+
const toolName = part.functionCall.name;
|
|
53259
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_i = part.functionCall.args) != null ? _i : {});
|
|
52661
53260
|
controller.enqueue({
|
|
52662
53261
|
type: "tool-input-start",
|
|
52663
|
-
id:
|
|
52664
|
-
toolName
|
|
52665
|
-
providerMetadata:
|
|
53262
|
+
id: toolCallId,
|
|
53263
|
+
toolName,
|
|
53264
|
+
providerMetadata: providerMeta
|
|
52666
53265
|
});
|
|
52667
53266
|
controller.enqueue({
|
|
52668
53267
|
type: "tool-input-delta",
|
|
52669
|
-
id:
|
|
52670
|
-
delta:
|
|
52671
|
-
providerMetadata:
|
|
53268
|
+
id: toolCallId,
|
|
53269
|
+
delta: args2,
|
|
53270
|
+
providerMetadata: providerMeta
|
|
52672
53271
|
});
|
|
52673
53272
|
controller.enqueue({
|
|
52674
53273
|
type: "tool-input-end",
|
|
52675
|
-
id:
|
|
52676
|
-
providerMetadata:
|
|
53274
|
+
id: toolCallId,
|
|
53275
|
+
providerMetadata: providerMeta
|
|
52677
53276
|
});
|
|
52678
53277
|
controller.enqueue({
|
|
52679
53278
|
type: "tool-call",
|
|
52680
|
-
toolCallId
|
|
52681
|
-
toolName
|
|
52682
|
-
input:
|
|
52683
|
-
providerMetadata:
|
|
53279
|
+
toolCallId,
|
|
53280
|
+
toolName,
|
|
53281
|
+
input: args2,
|
|
53282
|
+
providerMetadata: providerMeta
|
|
52684
53283
|
});
|
|
52685
53284
|
hasToolCalls = true;
|
|
52686
53285
|
}
|
|
@@ -52696,12 +53295,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52696
53295
|
};
|
|
52697
53296
|
providerMetadata = {
|
|
52698
53297
|
[providerOptionsName]: {
|
|
52699
|
-
promptFeedback: (
|
|
53298
|
+
promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
|
|
52700
53299
|
groundingMetadata: lastGroundingMetadata,
|
|
52701
53300
|
urlContextMetadata: lastUrlContextMetadata,
|
|
52702
|
-
safetyRatings: (
|
|
53301
|
+
safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
|
|
52703
53302
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
52704
|
-
finishMessage: (
|
|
53303
|
+
finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
|
|
52705
53304
|
serviceTier
|
|
52706
53305
|
}
|
|
52707
53306
|
};
|
|
@@ -52733,24 +53332,6 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
52733
53332
|
};
|
|
52734
53333
|
}
|
|
52735
53334
|
};
|
|
52736
|
-
function getToolCallsFromParts({
|
|
52737
|
-
parts,
|
|
52738
|
-
generateId: generateId3,
|
|
52739
|
-
providerOptionsName
|
|
52740
|
-
}) {
|
|
52741
|
-
const functionCallParts = parts == null ? undefined : parts.filter((part) => ("functionCall" in part));
|
|
52742
|
-
return functionCallParts == null || functionCallParts.length === 0 ? undefined : functionCallParts.map((part) => ({
|
|
52743
|
-
type: "tool-call",
|
|
52744
|
-
toolCallId: generateId3(),
|
|
52745
|
-
toolName: part.functionCall.name,
|
|
52746
|
-
args: JSON.stringify(part.functionCall.args),
|
|
52747
|
-
providerMetadata: part.thoughtSignature ? {
|
|
52748
|
-
[providerOptionsName]: {
|
|
52749
|
-
thoughtSignature: part.thoughtSignature
|
|
52750
|
-
}
|
|
52751
|
-
} : undefined
|
|
52752
|
-
}));
|
|
52753
|
-
}
|
|
52754
53335
|
function extractSources({
|
|
52755
53336
|
groundingMetadata,
|
|
52756
53337
|
generateId: generateId3
|
|
@@ -52888,12 +53469,22 @@ var getGroundingMetadataSchema = () => exports_external.object({
|
|
|
52888
53469
|
exports_external.object({})
|
|
52889
53470
|
]).nullish()
|
|
52890
53471
|
});
|
|
53472
|
+
var partialArgSchema = exports_external.object({
|
|
53473
|
+
jsonPath: exports_external.string(),
|
|
53474
|
+
stringValue: exports_external.string().nullish(),
|
|
53475
|
+
numberValue: exports_external.number().nullish(),
|
|
53476
|
+
boolValue: exports_external.boolean().nullish(),
|
|
53477
|
+
nullValue: exports_external.unknown().nullish(),
|
|
53478
|
+
willContinue: exports_external.boolean().nullish()
|
|
53479
|
+
});
|
|
52891
53480
|
var getContentSchema = () => exports_external.object({
|
|
52892
53481
|
parts: exports_external.array(exports_external.union([
|
|
52893
53482
|
exports_external.object({
|
|
52894
53483
|
functionCall: exports_external.object({
|
|
52895
|
-
name: exports_external.string(),
|
|
52896
|
-
args: exports_external.unknown()
|
|
53484
|
+
name: exports_external.string().nullish(),
|
|
53485
|
+
args: exports_external.unknown().nullish(),
|
|
53486
|
+
partialArgs: exports_external.array(partialArgSchema).nullish(),
|
|
53487
|
+
willContinue: exports_external.boolean().nullish()
|
|
52897
53488
|
}),
|
|
52898
53489
|
thoughtSignature: exports_external.string().nullish()
|
|
52899
53490
|
}),
|
|
@@ -52905,6 +53496,22 @@ var getContentSchema = () => exports_external.object({
|
|
|
52905
53496
|
thought: exports_external.boolean().nullish(),
|
|
52906
53497
|
thoughtSignature: exports_external.string().nullish()
|
|
52907
53498
|
}),
|
|
53499
|
+
exports_external.object({
|
|
53500
|
+
toolCall: exports_external.object({
|
|
53501
|
+
toolType: exports_external.string(),
|
|
53502
|
+
args: exports_external.unknown().nullish(),
|
|
53503
|
+
id: exports_external.string()
|
|
53504
|
+
}),
|
|
53505
|
+
thoughtSignature: exports_external.string().nullish()
|
|
53506
|
+
}),
|
|
53507
|
+
exports_external.object({
|
|
53508
|
+
toolResponse: exports_external.object({
|
|
53509
|
+
toolType: exports_external.string(),
|
|
53510
|
+
response: exports_external.unknown().nullish(),
|
|
53511
|
+
id: exports_external.string()
|
|
53512
|
+
}),
|
|
53513
|
+
thoughtSignature: exports_external.string().nullish()
|
|
53514
|
+
}),
|
|
52908
53515
|
exports_external.object({
|
|
52909
53516
|
executableCode: exports_external.object({
|
|
52910
53517
|
language: exports_external.string(),
|
|
@@ -52928,13 +53535,19 @@ var getSafetyRatingSchema = () => exports_external.object({
|
|
|
52928
53535
|
severityScore: exports_external.number().nullish(),
|
|
52929
53536
|
blocked: exports_external.boolean().nullish()
|
|
52930
53537
|
});
|
|
53538
|
+
var tokenDetailsSchema = exports_external.array(exports_external.object({
|
|
53539
|
+
modality: exports_external.string(),
|
|
53540
|
+
tokenCount: exports_external.number()
|
|
53541
|
+
})).nullish();
|
|
52931
53542
|
var usageSchema = exports_external.object({
|
|
52932
53543
|
cachedContentTokenCount: exports_external.number().nullish(),
|
|
52933
53544
|
thoughtsTokenCount: exports_external.number().nullish(),
|
|
52934
53545
|
promptTokenCount: exports_external.number().nullish(),
|
|
52935
53546
|
candidatesTokenCount: exports_external.number().nullish(),
|
|
52936
53547
|
totalTokenCount: exports_external.number().nullish(),
|
|
52937
|
-
trafficType: exports_external.string().nullish()
|
|
53548
|
+
trafficType: exports_external.string().nullish(),
|
|
53549
|
+
promptTokensDetails: tokenDetailsSchema,
|
|
53550
|
+
candidatesTokensDetails: tokenDetailsSchema
|
|
52938
53551
|
});
|
|
52939
53552
|
var getUrlContextMetadataSchema = () => exports_external.object({
|
|
52940
53553
|
urlMetadata: exports_external.array(exports_external.object({
|
|
@@ -53733,7 +54346,7 @@ var groqLanguageModelOptions = exports_external.object({
|
|
|
53733
54346
|
user: exports_external.string().optional(),
|
|
53734
54347
|
structuredOutputs: exports_external.boolean().optional(),
|
|
53735
54348
|
strictJsonSchema: exports_external.boolean().optional(),
|
|
53736
|
-
serviceTier: exports_external.enum(["on_demand", "flex", "auto"]).optional()
|
|
54349
|
+
serviceTier: exports_external.enum(["on_demand", "performance", "flex", "auto"]).optional()
|
|
53737
54350
|
});
|
|
53738
54351
|
var groqErrorDataSchema = exports_external.object({
|
|
53739
54352
|
error: exports_external.object({
|
|
@@ -54293,178 +54906,1750 @@ var GroqTranscriptionModel = class {
|
|
|
54293
54906
|
this.config = config2;
|
|
54294
54907
|
this.specificationVersion = "v3";
|
|
54295
54908
|
}
|
|
54296
|
-
get provider() {
|
|
54297
|
-
return this.config.provider;
|
|
54909
|
+
get provider() {
|
|
54910
|
+
return this.config.provider;
|
|
54911
|
+
}
|
|
54912
|
+
async getArgs({
|
|
54913
|
+
audio,
|
|
54914
|
+
mediaType,
|
|
54915
|
+
providerOptions
|
|
54916
|
+
}) {
|
|
54917
|
+
var _a16, _b16, _c, _d, _e;
|
|
54918
|
+
const warnings = [];
|
|
54919
|
+
const groqOptions = await parseProviderOptions({
|
|
54920
|
+
provider: "groq",
|
|
54921
|
+
providerOptions,
|
|
54922
|
+
schema: groqTranscriptionModelOptions
|
|
54923
|
+
});
|
|
54924
|
+
const formData = new FormData;
|
|
54925
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
54926
|
+
formData.append("model", this.modelId);
|
|
54927
|
+
const fileExtension = mediaTypeToExtension(mediaType);
|
|
54928
|
+
formData.append("file", new File([blob], "audio", { type: mediaType }), `audio.${fileExtension}`);
|
|
54929
|
+
if (groqOptions) {
|
|
54930
|
+
const transcriptionModelOptions = {
|
|
54931
|
+
language: (_a16 = groqOptions.language) != null ? _a16 : undefined,
|
|
54932
|
+
prompt: (_b16 = groqOptions.prompt) != null ? _b16 : undefined,
|
|
54933
|
+
response_format: (_c = groqOptions.responseFormat) != null ? _c : undefined,
|
|
54934
|
+
temperature: (_d = groqOptions.temperature) != null ? _d : undefined,
|
|
54935
|
+
timestamp_granularities: (_e = groqOptions.timestampGranularities) != null ? _e : undefined
|
|
54936
|
+
};
|
|
54937
|
+
for (const key in transcriptionModelOptions) {
|
|
54938
|
+
const value = transcriptionModelOptions[key];
|
|
54939
|
+
if (value !== undefined) {
|
|
54940
|
+
if (Array.isArray(value)) {
|
|
54941
|
+
for (const item of value) {
|
|
54942
|
+
formData.append(`${key}[]`, String(item));
|
|
54943
|
+
}
|
|
54944
|
+
} else {
|
|
54945
|
+
formData.append(key, String(value));
|
|
54946
|
+
}
|
|
54947
|
+
}
|
|
54948
|
+
}
|
|
54949
|
+
}
|
|
54950
|
+
return {
|
|
54951
|
+
formData,
|
|
54952
|
+
warnings
|
|
54953
|
+
};
|
|
54954
|
+
}
|
|
54955
|
+
async doGenerate(options) {
|
|
54956
|
+
var _a16, _b16, _c, _d, _e, _f, _g;
|
|
54957
|
+
const currentDate = (_c = (_b16 = (_a16 = this.config._internal) == null ? undefined : _a16.currentDate) == null ? undefined : _b16.call(_a16)) != null ? _c : /* @__PURE__ */ new Date;
|
|
54958
|
+
const { formData, warnings } = await this.getArgs(options);
|
|
54959
|
+
const {
|
|
54960
|
+
value: response,
|
|
54961
|
+
responseHeaders,
|
|
54962
|
+
rawValue: rawResponse
|
|
54963
|
+
} = await postFormDataToApi({
|
|
54964
|
+
url: this.config.url({
|
|
54965
|
+
path: "/audio/transcriptions",
|
|
54966
|
+
modelId: this.modelId
|
|
54967
|
+
}),
|
|
54968
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
54969
|
+
formData,
|
|
54970
|
+
failedResponseHandler: groqFailedResponseHandler,
|
|
54971
|
+
successfulResponseHandler: createJsonResponseHandler(groqTranscriptionResponseSchema),
|
|
54972
|
+
abortSignal: options.abortSignal,
|
|
54973
|
+
fetch: this.config.fetch
|
|
54974
|
+
});
|
|
54975
|
+
return {
|
|
54976
|
+
text: response.text,
|
|
54977
|
+
segments: (_e = (_d = response.segments) == null ? undefined : _d.map((segment) => ({
|
|
54978
|
+
text: segment.text,
|
|
54979
|
+
startSecond: segment.start,
|
|
54980
|
+
endSecond: segment.end
|
|
54981
|
+
}))) != null ? _e : [],
|
|
54982
|
+
language: (_f = response.language) != null ? _f : undefined,
|
|
54983
|
+
durationInSeconds: (_g = response.duration) != null ? _g : undefined,
|
|
54984
|
+
warnings,
|
|
54985
|
+
response: {
|
|
54986
|
+
timestamp: currentDate,
|
|
54987
|
+
modelId: this.modelId,
|
|
54988
|
+
headers: responseHeaders,
|
|
54989
|
+
body: rawResponse
|
|
54990
|
+
}
|
|
54991
|
+
};
|
|
54992
|
+
}
|
|
54993
|
+
};
|
|
54994
|
+
var groqTranscriptionResponseSchema = exports_external.object({
|
|
54995
|
+
text: exports_external.string(),
|
|
54996
|
+
x_groq: exports_external.object({
|
|
54997
|
+
id: exports_external.string()
|
|
54998
|
+
}),
|
|
54999
|
+
task: exports_external.string().nullish(),
|
|
55000
|
+
language: exports_external.string().nullish(),
|
|
55001
|
+
duration: exports_external.number().nullish(),
|
|
55002
|
+
segments: exports_external.array(exports_external.object({
|
|
55003
|
+
id: exports_external.number(),
|
|
55004
|
+
seek: exports_external.number(),
|
|
55005
|
+
start: exports_external.number(),
|
|
55006
|
+
end: exports_external.number(),
|
|
55007
|
+
text: exports_external.string(),
|
|
55008
|
+
tokens: exports_external.array(exports_external.number()),
|
|
55009
|
+
temperature: exports_external.number(),
|
|
55010
|
+
avg_logprob: exports_external.number(),
|
|
55011
|
+
compression_ratio: exports_external.number(),
|
|
55012
|
+
no_speech_prob: exports_external.number()
|
|
55013
|
+
})).nullish()
|
|
55014
|
+
});
|
|
55015
|
+
var browserSearch = createProviderToolFactory({
|
|
55016
|
+
id: "groq.browser_search",
|
|
55017
|
+
inputSchema: exports_external.object({})
|
|
55018
|
+
});
|
|
55019
|
+
var groqTools = {
|
|
55020
|
+
browserSearch
|
|
55021
|
+
};
|
|
55022
|
+
var VERSION7 = "3.0.35";
|
|
55023
|
+
function createGroq(options = {}) {
|
|
55024
|
+
var _a16;
|
|
55025
|
+
const baseURL = (_a16 = withoutTrailingSlash(options.baseURL)) != null ? _a16 : "https://api.groq.com/openai/v1";
|
|
55026
|
+
const getHeaders = () => withUserAgentSuffix({
|
|
55027
|
+
Authorization: `Bearer ${loadApiKey({
|
|
55028
|
+
apiKey: options.apiKey,
|
|
55029
|
+
environmentVariableName: "GROQ_API_KEY",
|
|
55030
|
+
description: "Groq"
|
|
55031
|
+
})}`,
|
|
55032
|
+
...options.headers
|
|
55033
|
+
}, `ai-sdk/groq/${VERSION7}`);
|
|
55034
|
+
const createChatModel = (modelId) => new GroqChatLanguageModel(modelId, {
|
|
55035
|
+
provider: "groq.chat",
|
|
55036
|
+
url: ({ path: path2 }) => `${baseURL}${path2}`,
|
|
55037
|
+
headers: getHeaders,
|
|
55038
|
+
fetch: options.fetch
|
|
55039
|
+
});
|
|
55040
|
+
const createLanguageModel = (modelId) => {
|
|
55041
|
+
if (new.target) {
|
|
55042
|
+
throw new Error("The Groq model function cannot be called with the new keyword.");
|
|
55043
|
+
}
|
|
55044
|
+
return createChatModel(modelId);
|
|
55045
|
+
};
|
|
55046
|
+
const createTranscriptionModel = (modelId) => {
|
|
55047
|
+
return new GroqTranscriptionModel(modelId, {
|
|
55048
|
+
provider: "groq.transcription",
|
|
55049
|
+
url: ({ path: path2 }) => `${baseURL}${path2}`,
|
|
55050
|
+
headers: getHeaders,
|
|
55051
|
+
fetch: options.fetch
|
|
55052
|
+
});
|
|
55053
|
+
};
|
|
55054
|
+
const provider = function(modelId) {
|
|
55055
|
+
return createLanguageModel(modelId);
|
|
55056
|
+
};
|
|
55057
|
+
provider.specificationVersion = "v3";
|
|
55058
|
+
provider.languageModel = createLanguageModel;
|
|
55059
|
+
provider.chat = createChatModel;
|
|
55060
|
+
provider.embeddingModel = (modelId) => {
|
|
55061
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
55062
|
+
};
|
|
55063
|
+
provider.textEmbeddingModel = provider.embeddingModel;
|
|
55064
|
+
provider.imageModel = (modelId) => {
|
|
55065
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
55066
|
+
};
|
|
55067
|
+
provider.transcription = createTranscriptionModel;
|
|
55068
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
55069
|
+
provider.tools = groqTools;
|
|
55070
|
+
return provider;
|
|
55071
|
+
}
|
|
55072
|
+
var groq = createGroq();
|
|
55073
|
+
|
|
55074
|
+
// src/providers/groq.ts
|
|
55075
|
+
function createGroqProvider(config2, providerName) {
|
|
55076
|
+
return createGroq({
|
|
55077
|
+
apiKey: resolveApiKey(config2.api_key_env, providerName),
|
|
55078
|
+
baseURL: config2.base_url,
|
|
55079
|
+
headers: config2.headers
|
|
55080
|
+
});
|
|
55081
|
+
}
|
|
55082
|
+
|
|
55083
|
+
// node_modules/ollama-ai-provider-v2/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
55084
|
+
function combineHeaders2(...headers) {
|
|
55085
|
+
return headers.reduce((combinedHeaders, currentHeaders) => ({
|
|
55086
|
+
...combinedHeaders,
|
|
55087
|
+
...currentHeaders != null ? currentHeaders : {}
|
|
55088
|
+
}), {});
|
|
55089
|
+
}
|
|
55090
|
+
function extractResponseHeaders2(response) {
|
|
55091
|
+
return Object.fromEntries([...response.headers]);
|
|
55092
|
+
}
|
|
55093
|
+
var name16 = "AI_DownloadError";
|
|
55094
|
+
var marker17 = `vercel.ai.error.${name16}`;
|
|
55095
|
+
var symbol17 = Symbol.for(marker17);
|
|
55096
|
+
var _a17;
|
|
55097
|
+
var _b17;
|
|
55098
|
+
var DownloadError2 = class extends (_b17 = AISDKError, _a17 = symbol17, _b17) {
|
|
55099
|
+
constructor({
|
|
55100
|
+
url: url2,
|
|
55101
|
+
statusCode,
|
|
55102
|
+
statusText,
|
|
55103
|
+
cause,
|
|
55104
|
+
message = cause == null ? `Failed to download ${url2}: ${statusCode} ${statusText}` : `Failed to download ${url2}: ${cause}`
|
|
55105
|
+
}) {
|
|
55106
|
+
super({ name: name16, message, cause });
|
|
55107
|
+
this[_a17] = true;
|
|
55108
|
+
this.url = url2;
|
|
55109
|
+
this.statusCode = statusCode;
|
|
55110
|
+
this.statusText = statusText;
|
|
55111
|
+
}
|
|
55112
|
+
static isInstance(error48) {
|
|
55113
|
+
return AISDKError.hasMarker(error48, marker17);
|
|
55114
|
+
}
|
|
55115
|
+
};
|
|
55116
|
+
var DEFAULT_MAX_DOWNLOAD_SIZE2 = 2 * 1024 * 1024 * 1024;
|
|
55117
|
+
var createIdGenerator2 = ({
|
|
55118
|
+
prefix,
|
|
55119
|
+
size = 16,
|
|
55120
|
+
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
55121
|
+
separator = "-"
|
|
55122
|
+
} = {}) => {
|
|
55123
|
+
const generator = () => {
|
|
55124
|
+
const alphabetLength = alphabet.length;
|
|
55125
|
+
const chars = new Array(size);
|
|
55126
|
+
for (let i = 0;i < size; i++) {
|
|
55127
|
+
chars[i] = alphabet[Math.random() * alphabetLength | 0];
|
|
55128
|
+
}
|
|
55129
|
+
return chars.join("");
|
|
55130
|
+
};
|
|
55131
|
+
if (prefix == null) {
|
|
55132
|
+
return generator;
|
|
55133
|
+
}
|
|
55134
|
+
if (alphabet.includes(separator)) {
|
|
55135
|
+
throw new InvalidArgumentError({
|
|
55136
|
+
argument: "separator",
|
|
55137
|
+
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
55138
|
+
});
|
|
55139
|
+
}
|
|
55140
|
+
return () => `${prefix}${separator}${generator()}`;
|
|
55141
|
+
};
|
|
55142
|
+
var generateId2 = createIdGenerator2();
|
|
55143
|
+
function isAbortError2(error48) {
|
|
55144
|
+
return (error48 instanceof Error || error48 instanceof DOMException) && (error48.name === "AbortError" || error48.name === "ResponseAborted" || error48.name === "TimeoutError");
|
|
55145
|
+
}
|
|
55146
|
+
var FETCH_FAILED_ERROR_MESSAGES2 = ["fetch failed", "failed to fetch"];
|
|
55147
|
+
var BUN_ERROR_CODES2 = [
|
|
55148
|
+
"ConnectionRefused",
|
|
55149
|
+
"ConnectionClosed",
|
|
55150
|
+
"FailedToOpenSocket",
|
|
55151
|
+
"ECONNRESET",
|
|
55152
|
+
"ECONNREFUSED",
|
|
55153
|
+
"ETIMEDOUT",
|
|
55154
|
+
"EPIPE"
|
|
55155
|
+
];
|
|
55156
|
+
function isBunNetworkError2(error48) {
|
|
55157
|
+
if (!(error48 instanceof Error)) {
|
|
55158
|
+
return false;
|
|
55159
|
+
}
|
|
55160
|
+
const code = error48.code;
|
|
55161
|
+
if (typeof code === "string" && BUN_ERROR_CODES2.includes(code)) {
|
|
55162
|
+
return true;
|
|
55163
|
+
}
|
|
55164
|
+
return false;
|
|
55165
|
+
}
|
|
55166
|
+
function handleFetchError2({
|
|
55167
|
+
error: error48,
|
|
55168
|
+
url: url2,
|
|
55169
|
+
requestBodyValues
|
|
55170
|
+
}) {
|
|
55171
|
+
if (isAbortError2(error48)) {
|
|
55172
|
+
return error48;
|
|
55173
|
+
}
|
|
55174
|
+
if (error48 instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES2.includes(error48.message.toLowerCase())) {
|
|
55175
|
+
const cause = error48.cause;
|
|
55176
|
+
if (cause != null) {
|
|
55177
|
+
return new APICallError({
|
|
55178
|
+
message: `Cannot connect to API: ${cause.message}`,
|
|
55179
|
+
cause,
|
|
55180
|
+
url: url2,
|
|
55181
|
+
requestBodyValues,
|
|
55182
|
+
isRetryable: true
|
|
55183
|
+
});
|
|
55184
|
+
}
|
|
55185
|
+
}
|
|
55186
|
+
if (isBunNetworkError2(error48)) {
|
|
55187
|
+
return new APICallError({
|
|
55188
|
+
message: `Cannot connect to API: ${error48.message}`,
|
|
55189
|
+
cause: error48,
|
|
55190
|
+
url: url2,
|
|
55191
|
+
requestBodyValues,
|
|
55192
|
+
isRetryable: true
|
|
55193
|
+
});
|
|
55194
|
+
}
|
|
55195
|
+
return error48;
|
|
55196
|
+
}
|
|
55197
|
+
function getRuntimeEnvironmentUserAgent2(globalThisAny = globalThis) {
|
|
55198
|
+
var _a23, _b22, _c;
|
|
55199
|
+
if (globalThisAny.window) {
|
|
55200
|
+
return `runtime/browser`;
|
|
55201
|
+
}
|
|
55202
|
+
if ((_a23 = globalThisAny.navigator) == null ? undefined : _a23.userAgent) {
|
|
55203
|
+
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
55204
|
+
}
|
|
55205
|
+
if ((_c = (_b22 = globalThisAny.process) == null ? undefined : _b22.versions) == null ? undefined : _c.node) {
|
|
55206
|
+
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
55207
|
+
}
|
|
55208
|
+
if (globalThisAny.EdgeRuntime) {
|
|
55209
|
+
return `runtime/vercel-edge`;
|
|
55210
|
+
}
|
|
55211
|
+
return "runtime/unknown";
|
|
55212
|
+
}
|
|
55213
|
+
function normalizeHeaders2(headers) {
|
|
55214
|
+
if (headers == null) {
|
|
55215
|
+
return {};
|
|
55216
|
+
}
|
|
55217
|
+
const normalized = {};
|
|
55218
|
+
if (headers instanceof Headers) {
|
|
55219
|
+
headers.forEach((value, key) => {
|
|
55220
|
+
normalized[key.toLowerCase()] = value;
|
|
55221
|
+
});
|
|
55222
|
+
} else {
|
|
55223
|
+
if (!Array.isArray(headers)) {
|
|
55224
|
+
headers = Object.entries(headers);
|
|
55225
|
+
}
|
|
55226
|
+
for (const [key, value] of headers) {
|
|
55227
|
+
if (value != null) {
|
|
55228
|
+
normalized[key.toLowerCase()] = value;
|
|
55229
|
+
}
|
|
55230
|
+
}
|
|
55231
|
+
}
|
|
55232
|
+
return normalized;
|
|
55233
|
+
}
|
|
55234
|
+
function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
55235
|
+
const normalizedHeaders = new Headers(normalizeHeaders2(headers));
|
|
55236
|
+
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
55237
|
+
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
55238
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
55239
|
+
}
|
|
55240
|
+
var VERSION8 = "4.0.21";
|
|
55241
|
+
var suspectProtoRx2 = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
55242
|
+
var suspectConstructorRx2 = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
55243
|
+
function _parse3(text) {
|
|
55244
|
+
const obj = JSON.parse(text);
|
|
55245
|
+
if (obj === null || typeof obj !== "object") {
|
|
55246
|
+
return obj;
|
|
55247
|
+
}
|
|
55248
|
+
if (suspectProtoRx2.test(text) === false && suspectConstructorRx2.test(text) === false) {
|
|
55249
|
+
return obj;
|
|
55250
|
+
}
|
|
55251
|
+
return filter2(obj);
|
|
55252
|
+
}
|
|
55253
|
+
function filter2(obj) {
|
|
55254
|
+
let next = [obj];
|
|
55255
|
+
while (next.length) {
|
|
55256
|
+
const nodes = next;
|
|
55257
|
+
next = [];
|
|
55258
|
+
for (const node of nodes) {
|
|
55259
|
+
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
55260
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
55261
|
+
}
|
|
55262
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
55263
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
55264
|
+
}
|
|
55265
|
+
for (const key in node) {
|
|
55266
|
+
const value = node[key];
|
|
55267
|
+
if (value && typeof value === "object") {
|
|
55268
|
+
next.push(value);
|
|
55269
|
+
}
|
|
55270
|
+
}
|
|
55271
|
+
}
|
|
55272
|
+
}
|
|
55273
|
+
return obj;
|
|
55274
|
+
}
|
|
55275
|
+
function secureJsonParse2(text) {
|
|
55276
|
+
const { stackTraceLimit } = Error;
|
|
55277
|
+
try {
|
|
55278
|
+
Error.stackTraceLimit = 0;
|
|
55279
|
+
} catch (e) {
|
|
55280
|
+
return _parse3(text);
|
|
55281
|
+
}
|
|
55282
|
+
try {
|
|
55283
|
+
return _parse3(text);
|
|
55284
|
+
} finally {
|
|
55285
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
55286
|
+
}
|
|
55287
|
+
}
|
|
55288
|
+
function addAdditionalPropertiesToJsonSchema2(jsonSchema2) {
|
|
55289
|
+
if (jsonSchema2.type === "object" || Array.isArray(jsonSchema2.type) && jsonSchema2.type.includes("object")) {
|
|
55290
|
+
jsonSchema2.additionalProperties = false;
|
|
55291
|
+
const { properties } = jsonSchema2;
|
|
55292
|
+
if (properties != null) {
|
|
55293
|
+
for (const key of Object.keys(properties)) {
|
|
55294
|
+
properties[key] = visit2(properties[key]);
|
|
55295
|
+
}
|
|
55296
|
+
}
|
|
55297
|
+
}
|
|
55298
|
+
if (jsonSchema2.items != null) {
|
|
55299
|
+
jsonSchema2.items = Array.isArray(jsonSchema2.items) ? jsonSchema2.items.map(visit2) : visit2(jsonSchema2.items);
|
|
55300
|
+
}
|
|
55301
|
+
if (jsonSchema2.anyOf != null) {
|
|
55302
|
+
jsonSchema2.anyOf = jsonSchema2.anyOf.map(visit2);
|
|
55303
|
+
}
|
|
55304
|
+
if (jsonSchema2.allOf != null) {
|
|
55305
|
+
jsonSchema2.allOf = jsonSchema2.allOf.map(visit2);
|
|
55306
|
+
}
|
|
55307
|
+
if (jsonSchema2.oneOf != null) {
|
|
55308
|
+
jsonSchema2.oneOf = jsonSchema2.oneOf.map(visit2);
|
|
55309
|
+
}
|
|
55310
|
+
const { definitions } = jsonSchema2;
|
|
55311
|
+
if (definitions != null) {
|
|
55312
|
+
for (const key of Object.keys(definitions)) {
|
|
55313
|
+
definitions[key] = visit2(definitions[key]);
|
|
55314
|
+
}
|
|
55315
|
+
}
|
|
55316
|
+
return jsonSchema2;
|
|
55317
|
+
}
|
|
55318
|
+
function visit2(def) {
|
|
55319
|
+
if (typeof def === "boolean")
|
|
55320
|
+
return def;
|
|
55321
|
+
return addAdditionalPropertiesToJsonSchema2(def);
|
|
55322
|
+
}
|
|
55323
|
+
var ignoreOverride2 = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
55324
|
+
var defaultOptions2 = {
|
|
55325
|
+
name: undefined,
|
|
55326
|
+
$refStrategy: "root",
|
|
55327
|
+
basePath: ["#"],
|
|
55328
|
+
effectStrategy: "input",
|
|
55329
|
+
pipeStrategy: "all",
|
|
55330
|
+
dateStrategy: "format:date-time",
|
|
55331
|
+
mapStrategy: "entries",
|
|
55332
|
+
removeAdditionalStrategy: "passthrough",
|
|
55333
|
+
allowedAdditionalProperties: true,
|
|
55334
|
+
rejectedAdditionalProperties: false,
|
|
55335
|
+
definitionPath: "definitions",
|
|
55336
|
+
strictUnions: false,
|
|
55337
|
+
definitions: {},
|
|
55338
|
+
errorMessages: false,
|
|
55339
|
+
patternStrategy: "escape",
|
|
55340
|
+
applyRegexFlags: false,
|
|
55341
|
+
emailStrategy: "format:email",
|
|
55342
|
+
base64Strategy: "contentEncoding:base64",
|
|
55343
|
+
nameStrategy: "ref"
|
|
55344
|
+
};
|
|
55345
|
+
var getDefaultOptions2 = (options) => typeof options === "string" ? {
|
|
55346
|
+
...defaultOptions2,
|
|
55347
|
+
name: options
|
|
55348
|
+
} : {
|
|
55349
|
+
...defaultOptions2,
|
|
55350
|
+
...options
|
|
55351
|
+
};
|
|
55352
|
+
function parseAnyDef2() {
|
|
55353
|
+
return {};
|
|
55354
|
+
}
|
|
55355
|
+
function parseArrayDef2(def, refs) {
|
|
55356
|
+
var _a23, _b22, _c;
|
|
55357
|
+
const res = {
|
|
55358
|
+
type: "array"
|
|
55359
|
+
};
|
|
55360
|
+
if (((_a23 = def.type) == null ? undefined : _a23._def) && ((_c = (_b22 = def.type) == null ? undefined : _b22._def) == null ? undefined : _c.typeName) !== ZodFirstPartyTypeKind2.ZodAny) {
|
|
55361
|
+
res.items = parseDef2(def.type._def, {
|
|
55362
|
+
...refs,
|
|
55363
|
+
currentPath: [...refs.currentPath, "items"]
|
|
55364
|
+
});
|
|
55365
|
+
}
|
|
55366
|
+
if (def.minLength) {
|
|
55367
|
+
res.minItems = def.minLength.value;
|
|
55368
|
+
}
|
|
55369
|
+
if (def.maxLength) {
|
|
55370
|
+
res.maxItems = def.maxLength.value;
|
|
55371
|
+
}
|
|
55372
|
+
if (def.exactLength) {
|
|
55373
|
+
res.minItems = def.exactLength.value;
|
|
55374
|
+
res.maxItems = def.exactLength.value;
|
|
55375
|
+
}
|
|
55376
|
+
return res;
|
|
55377
|
+
}
|
|
55378
|
+
function parseBigintDef2(def) {
|
|
55379
|
+
const res = {
|
|
55380
|
+
type: "integer",
|
|
55381
|
+
format: "int64"
|
|
55382
|
+
};
|
|
55383
|
+
if (!def.checks)
|
|
55384
|
+
return res;
|
|
55385
|
+
for (const check2 of def.checks) {
|
|
55386
|
+
switch (check2.kind) {
|
|
55387
|
+
case "min":
|
|
55388
|
+
if (check2.inclusive) {
|
|
55389
|
+
res.minimum = check2.value;
|
|
55390
|
+
} else {
|
|
55391
|
+
res.exclusiveMinimum = check2.value;
|
|
55392
|
+
}
|
|
55393
|
+
break;
|
|
55394
|
+
case "max":
|
|
55395
|
+
if (check2.inclusive) {
|
|
55396
|
+
res.maximum = check2.value;
|
|
55397
|
+
} else {
|
|
55398
|
+
res.exclusiveMaximum = check2.value;
|
|
55399
|
+
}
|
|
55400
|
+
break;
|
|
55401
|
+
case "multipleOf":
|
|
55402
|
+
res.multipleOf = check2.value;
|
|
55403
|
+
break;
|
|
55404
|
+
}
|
|
55405
|
+
}
|
|
55406
|
+
return res;
|
|
55407
|
+
}
|
|
55408
|
+
function parseBooleanDef2() {
|
|
55409
|
+
return { type: "boolean" };
|
|
55410
|
+
}
|
|
55411
|
+
function parseBrandedDef2(_def, refs) {
|
|
55412
|
+
return parseDef2(_def.type._def, refs);
|
|
55413
|
+
}
|
|
55414
|
+
var parseCatchDef2 = (def, refs) => {
|
|
55415
|
+
return parseDef2(def.innerType._def, refs);
|
|
55416
|
+
};
|
|
55417
|
+
function parseDateDef2(def, refs, overrideDateStrategy) {
|
|
55418
|
+
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
55419
|
+
if (Array.isArray(strategy)) {
|
|
55420
|
+
return {
|
|
55421
|
+
anyOf: strategy.map((item, i) => parseDateDef2(def, refs, item))
|
|
55422
|
+
};
|
|
55423
|
+
}
|
|
55424
|
+
switch (strategy) {
|
|
55425
|
+
case "string":
|
|
55426
|
+
case "format:date-time":
|
|
55427
|
+
return {
|
|
55428
|
+
type: "string",
|
|
55429
|
+
format: "date-time"
|
|
55430
|
+
};
|
|
55431
|
+
case "format:date":
|
|
55432
|
+
return {
|
|
55433
|
+
type: "string",
|
|
55434
|
+
format: "date"
|
|
55435
|
+
};
|
|
55436
|
+
case "integer":
|
|
55437
|
+
return integerDateParser2(def);
|
|
55438
|
+
}
|
|
55439
|
+
}
|
|
55440
|
+
var integerDateParser2 = (def) => {
|
|
55441
|
+
const res = {
|
|
55442
|
+
type: "integer",
|
|
55443
|
+
format: "unix-time"
|
|
55444
|
+
};
|
|
55445
|
+
for (const check2 of def.checks) {
|
|
55446
|
+
switch (check2.kind) {
|
|
55447
|
+
case "min":
|
|
55448
|
+
res.minimum = check2.value;
|
|
55449
|
+
break;
|
|
55450
|
+
case "max":
|
|
55451
|
+
res.maximum = check2.value;
|
|
55452
|
+
break;
|
|
55453
|
+
}
|
|
55454
|
+
}
|
|
55455
|
+
return res;
|
|
55456
|
+
};
|
|
55457
|
+
function parseDefaultDef2(_def, refs) {
|
|
55458
|
+
return {
|
|
55459
|
+
...parseDef2(_def.innerType._def, refs),
|
|
55460
|
+
default: _def.defaultValue()
|
|
55461
|
+
};
|
|
55462
|
+
}
|
|
55463
|
+
function parseEffectsDef2(_def, refs) {
|
|
55464
|
+
return refs.effectStrategy === "input" ? parseDef2(_def.schema._def, refs) : parseAnyDef2();
|
|
55465
|
+
}
|
|
55466
|
+
function parseEnumDef2(def) {
|
|
55467
|
+
return {
|
|
55468
|
+
type: "string",
|
|
55469
|
+
enum: Array.from(def.values)
|
|
55470
|
+
};
|
|
55471
|
+
}
|
|
55472
|
+
var isJsonSchema7AllOfType2 = (type) => {
|
|
55473
|
+
if ("type" in type && type.type === "string")
|
|
55474
|
+
return false;
|
|
55475
|
+
return "allOf" in type;
|
|
55476
|
+
};
|
|
55477
|
+
function parseIntersectionDef2(def, refs) {
|
|
55478
|
+
const allOf = [
|
|
55479
|
+
parseDef2(def.left._def, {
|
|
55480
|
+
...refs,
|
|
55481
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
55482
|
+
}),
|
|
55483
|
+
parseDef2(def.right._def, {
|
|
55484
|
+
...refs,
|
|
55485
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
55486
|
+
})
|
|
55487
|
+
].filter((x) => !!x);
|
|
55488
|
+
const mergedAllOf = [];
|
|
55489
|
+
allOf.forEach((schema) => {
|
|
55490
|
+
if (isJsonSchema7AllOfType2(schema)) {
|
|
55491
|
+
mergedAllOf.push(...schema.allOf);
|
|
55492
|
+
} else {
|
|
55493
|
+
let nestedSchema = schema;
|
|
55494
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
55495
|
+
const { additionalProperties, ...rest } = schema;
|
|
55496
|
+
nestedSchema = rest;
|
|
55497
|
+
}
|
|
55498
|
+
mergedAllOf.push(nestedSchema);
|
|
55499
|
+
}
|
|
55500
|
+
});
|
|
55501
|
+
return mergedAllOf.length ? { allOf: mergedAllOf } : undefined;
|
|
55502
|
+
}
|
|
55503
|
+
function parseLiteralDef2(def) {
|
|
55504
|
+
const parsedType2 = typeof def.value;
|
|
55505
|
+
if (parsedType2 !== "bigint" && parsedType2 !== "number" && parsedType2 !== "boolean" && parsedType2 !== "string") {
|
|
55506
|
+
return {
|
|
55507
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
55508
|
+
};
|
|
55509
|
+
}
|
|
55510
|
+
return {
|
|
55511
|
+
type: parsedType2 === "bigint" ? "integer" : parsedType2,
|
|
55512
|
+
const: def.value
|
|
55513
|
+
};
|
|
55514
|
+
}
|
|
55515
|
+
var emojiRegex3 = undefined;
|
|
55516
|
+
var zodPatterns2 = {
|
|
55517
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
55518
|
+
cuid2: /^[0-9a-z]+$/,
|
|
55519
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
55520
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
55521
|
+
emoji: () => {
|
|
55522
|
+
if (emojiRegex3 === undefined) {
|
|
55523
|
+
emojiRegex3 = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
55524
|
+
}
|
|
55525
|
+
return emojiRegex3;
|
|
55526
|
+
},
|
|
55527
|
+
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
55528
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
55529
|
+
ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
|
|
55530
|
+
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
55531
|
+
ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
55532
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
55533
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
55534
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
55535
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
55536
|
+
};
|
|
55537
|
+
function parseStringDef2(def, refs) {
|
|
55538
|
+
const res = {
|
|
55539
|
+
type: "string"
|
|
55540
|
+
};
|
|
55541
|
+
if (def.checks) {
|
|
55542
|
+
for (const check2 of def.checks) {
|
|
55543
|
+
switch (check2.kind) {
|
|
55544
|
+
case "min":
|
|
55545
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check2.value) : check2.value;
|
|
55546
|
+
break;
|
|
55547
|
+
case "max":
|
|
55548
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check2.value) : check2.value;
|
|
55549
|
+
break;
|
|
55550
|
+
case "email":
|
|
55551
|
+
switch (refs.emailStrategy) {
|
|
55552
|
+
case "format:email":
|
|
55553
|
+
addFormat2(res, "email", check2.message, refs);
|
|
55554
|
+
break;
|
|
55555
|
+
case "format:idn-email":
|
|
55556
|
+
addFormat2(res, "idn-email", check2.message, refs);
|
|
55557
|
+
break;
|
|
55558
|
+
case "pattern:zod":
|
|
55559
|
+
addPattern2(res, zodPatterns2.email, check2.message, refs);
|
|
55560
|
+
break;
|
|
55561
|
+
}
|
|
55562
|
+
break;
|
|
55563
|
+
case "url":
|
|
55564
|
+
addFormat2(res, "uri", check2.message, refs);
|
|
55565
|
+
break;
|
|
55566
|
+
case "uuid":
|
|
55567
|
+
addFormat2(res, "uuid", check2.message, refs);
|
|
55568
|
+
break;
|
|
55569
|
+
case "regex":
|
|
55570
|
+
addPattern2(res, check2.regex, check2.message, refs);
|
|
55571
|
+
break;
|
|
55572
|
+
case "cuid":
|
|
55573
|
+
addPattern2(res, zodPatterns2.cuid, check2.message, refs);
|
|
55574
|
+
break;
|
|
55575
|
+
case "cuid2":
|
|
55576
|
+
addPattern2(res, zodPatterns2.cuid2, check2.message, refs);
|
|
55577
|
+
break;
|
|
55578
|
+
case "startsWith":
|
|
55579
|
+
addPattern2(res, RegExp(`^${escapeLiteralCheckValue2(check2.value, refs)}`), check2.message, refs);
|
|
55580
|
+
break;
|
|
55581
|
+
case "endsWith":
|
|
55582
|
+
addPattern2(res, RegExp(`${escapeLiteralCheckValue2(check2.value, refs)}$`), check2.message, refs);
|
|
55583
|
+
break;
|
|
55584
|
+
case "datetime":
|
|
55585
|
+
addFormat2(res, "date-time", check2.message, refs);
|
|
55586
|
+
break;
|
|
55587
|
+
case "date":
|
|
55588
|
+
addFormat2(res, "date", check2.message, refs);
|
|
55589
|
+
break;
|
|
55590
|
+
case "time":
|
|
55591
|
+
addFormat2(res, "time", check2.message, refs);
|
|
55592
|
+
break;
|
|
55593
|
+
case "duration":
|
|
55594
|
+
addFormat2(res, "duration", check2.message, refs);
|
|
55595
|
+
break;
|
|
55596
|
+
case "length":
|
|
55597
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check2.value) : check2.value;
|
|
55598
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check2.value) : check2.value;
|
|
55599
|
+
break;
|
|
55600
|
+
case "includes": {
|
|
55601
|
+
addPattern2(res, RegExp(escapeLiteralCheckValue2(check2.value, refs)), check2.message, refs);
|
|
55602
|
+
break;
|
|
55603
|
+
}
|
|
55604
|
+
case "ip": {
|
|
55605
|
+
if (check2.version !== "v6") {
|
|
55606
|
+
addFormat2(res, "ipv4", check2.message, refs);
|
|
55607
|
+
}
|
|
55608
|
+
if (check2.version !== "v4") {
|
|
55609
|
+
addFormat2(res, "ipv6", check2.message, refs);
|
|
55610
|
+
}
|
|
55611
|
+
break;
|
|
55612
|
+
}
|
|
55613
|
+
case "base64url":
|
|
55614
|
+
addPattern2(res, zodPatterns2.base64url, check2.message, refs);
|
|
55615
|
+
break;
|
|
55616
|
+
case "jwt":
|
|
55617
|
+
addPattern2(res, zodPatterns2.jwt, check2.message, refs);
|
|
55618
|
+
break;
|
|
55619
|
+
case "cidr": {
|
|
55620
|
+
if (check2.version !== "v6") {
|
|
55621
|
+
addPattern2(res, zodPatterns2.ipv4Cidr, check2.message, refs);
|
|
55622
|
+
}
|
|
55623
|
+
if (check2.version !== "v4") {
|
|
55624
|
+
addPattern2(res, zodPatterns2.ipv6Cidr, check2.message, refs);
|
|
55625
|
+
}
|
|
55626
|
+
break;
|
|
55627
|
+
}
|
|
55628
|
+
case "emoji":
|
|
55629
|
+
addPattern2(res, zodPatterns2.emoji(), check2.message, refs);
|
|
55630
|
+
break;
|
|
55631
|
+
case "ulid": {
|
|
55632
|
+
addPattern2(res, zodPatterns2.ulid, check2.message, refs);
|
|
55633
|
+
break;
|
|
55634
|
+
}
|
|
55635
|
+
case "base64": {
|
|
55636
|
+
switch (refs.base64Strategy) {
|
|
55637
|
+
case "format:binary": {
|
|
55638
|
+
addFormat2(res, "binary", check2.message, refs);
|
|
55639
|
+
break;
|
|
55640
|
+
}
|
|
55641
|
+
case "contentEncoding:base64": {
|
|
55642
|
+
res.contentEncoding = "base64";
|
|
55643
|
+
break;
|
|
55644
|
+
}
|
|
55645
|
+
case "pattern:zod": {
|
|
55646
|
+
addPattern2(res, zodPatterns2.base64, check2.message, refs);
|
|
55647
|
+
break;
|
|
55648
|
+
}
|
|
55649
|
+
}
|
|
55650
|
+
break;
|
|
55651
|
+
}
|
|
55652
|
+
case "nanoid": {
|
|
55653
|
+
addPattern2(res, zodPatterns2.nanoid, check2.message, refs);
|
|
55654
|
+
}
|
|
55655
|
+
case "toLowerCase":
|
|
55656
|
+
case "toUpperCase":
|
|
55657
|
+
case "trim":
|
|
55658
|
+
break;
|
|
55659
|
+
default:
|
|
55660
|
+
}
|
|
55661
|
+
}
|
|
55662
|
+
}
|
|
55663
|
+
return res;
|
|
55664
|
+
}
|
|
55665
|
+
function escapeLiteralCheckValue2(literal2, refs) {
|
|
55666
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric2(literal2) : literal2;
|
|
55667
|
+
}
|
|
55668
|
+
var ALPHA_NUMERIC2 = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
55669
|
+
function escapeNonAlphaNumeric2(source) {
|
|
55670
|
+
let result = "";
|
|
55671
|
+
for (let i = 0;i < source.length; i++) {
|
|
55672
|
+
if (!ALPHA_NUMERIC2.has(source[i])) {
|
|
55673
|
+
result += "\\";
|
|
55674
|
+
}
|
|
55675
|
+
result += source[i];
|
|
55676
|
+
}
|
|
55677
|
+
return result;
|
|
55678
|
+
}
|
|
55679
|
+
function addFormat2(schema, value, message, refs) {
|
|
55680
|
+
var _a23;
|
|
55681
|
+
if (schema.format || ((_a23 = schema.anyOf) == null ? undefined : _a23.some((x) => x.format))) {
|
|
55682
|
+
if (!schema.anyOf) {
|
|
55683
|
+
schema.anyOf = [];
|
|
55684
|
+
}
|
|
55685
|
+
if (schema.format) {
|
|
55686
|
+
schema.anyOf.push({
|
|
55687
|
+
format: schema.format
|
|
55688
|
+
});
|
|
55689
|
+
delete schema.format;
|
|
55690
|
+
}
|
|
55691
|
+
schema.anyOf.push({
|
|
55692
|
+
format: value,
|
|
55693
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
55694
|
+
});
|
|
55695
|
+
} else {
|
|
55696
|
+
schema.format = value;
|
|
55697
|
+
}
|
|
55698
|
+
}
|
|
55699
|
+
function addPattern2(schema, regex, message, refs) {
|
|
55700
|
+
var _a23;
|
|
55701
|
+
if (schema.pattern || ((_a23 = schema.allOf) == null ? undefined : _a23.some((x) => x.pattern))) {
|
|
55702
|
+
if (!schema.allOf) {
|
|
55703
|
+
schema.allOf = [];
|
|
55704
|
+
}
|
|
55705
|
+
if (schema.pattern) {
|
|
55706
|
+
schema.allOf.push({
|
|
55707
|
+
pattern: schema.pattern
|
|
55708
|
+
});
|
|
55709
|
+
delete schema.pattern;
|
|
55710
|
+
}
|
|
55711
|
+
schema.allOf.push({
|
|
55712
|
+
pattern: stringifyRegExpWithFlags2(regex, refs),
|
|
55713
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
55714
|
+
});
|
|
55715
|
+
} else {
|
|
55716
|
+
schema.pattern = stringifyRegExpWithFlags2(regex, refs);
|
|
55717
|
+
}
|
|
55718
|
+
}
|
|
55719
|
+
function stringifyRegExpWithFlags2(regex, refs) {
|
|
55720
|
+
var _a23;
|
|
55721
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
55722
|
+
return regex.source;
|
|
55723
|
+
}
|
|
55724
|
+
const flags = {
|
|
55725
|
+
i: regex.flags.includes("i"),
|
|
55726
|
+
m: regex.flags.includes("m"),
|
|
55727
|
+
s: regex.flags.includes("s")
|
|
55728
|
+
};
|
|
55729
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
55730
|
+
let pattern = "";
|
|
55731
|
+
let isEscaped = false;
|
|
55732
|
+
let inCharGroup = false;
|
|
55733
|
+
let inCharRange = false;
|
|
55734
|
+
for (let i = 0;i < source.length; i++) {
|
|
55735
|
+
if (isEscaped) {
|
|
55736
|
+
pattern += source[i];
|
|
55737
|
+
isEscaped = false;
|
|
55738
|
+
continue;
|
|
55739
|
+
}
|
|
55740
|
+
if (flags.i) {
|
|
55741
|
+
if (inCharGroup) {
|
|
55742
|
+
if (source[i].match(/[a-z]/)) {
|
|
55743
|
+
if (inCharRange) {
|
|
55744
|
+
pattern += source[i];
|
|
55745
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
55746
|
+
inCharRange = false;
|
|
55747
|
+
} else if (source[i + 1] === "-" && ((_a23 = source[i + 2]) == null ? undefined : _a23.match(/[a-z]/))) {
|
|
55748
|
+
pattern += source[i];
|
|
55749
|
+
inCharRange = true;
|
|
55750
|
+
} else {
|
|
55751
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
55752
|
+
}
|
|
55753
|
+
continue;
|
|
55754
|
+
}
|
|
55755
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
55756
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
55757
|
+
continue;
|
|
55758
|
+
}
|
|
55759
|
+
}
|
|
55760
|
+
if (flags.m) {
|
|
55761
|
+
if (source[i] === "^") {
|
|
55762
|
+
pattern += `(^|(?<=[\r
|
|
55763
|
+
]))`;
|
|
55764
|
+
continue;
|
|
55765
|
+
} else if (source[i] === "$") {
|
|
55766
|
+
pattern += `($|(?=[\r
|
|
55767
|
+
]))`;
|
|
55768
|
+
continue;
|
|
55769
|
+
}
|
|
55770
|
+
}
|
|
55771
|
+
if (flags.s && source[i] === ".") {
|
|
55772
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
55773
|
+
` : `[${source[i]}\r
|
|
55774
|
+
]`;
|
|
55775
|
+
continue;
|
|
55776
|
+
}
|
|
55777
|
+
pattern += source[i];
|
|
55778
|
+
if (source[i] === "\\") {
|
|
55779
|
+
isEscaped = true;
|
|
55780
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
55781
|
+
inCharGroup = false;
|
|
55782
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
55783
|
+
inCharGroup = true;
|
|
55784
|
+
}
|
|
55785
|
+
}
|
|
55786
|
+
try {
|
|
55787
|
+
new RegExp(pattern);
|
|
55788
|
+
} catch (e) {
|
|
55789
|
+
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
55790
|
+
return regex.source;
|
|
55791
|
+
}
|
|
55792
|
+
return pattern;
|
|
55793
|
+
}
|
|
55794
|
+
function parseRecordDef2(def, refs) {
|
|
55795
|
+
var _a23, _b22, _c, _d, _e, _f;
|
|
55796
|
+
const schema = {
|
|
55797
|
+
type: "object",
|
|
55798
|
+
additionalProperties: (_a23 = parseDef2(def.valueType._def, {
|
|
55799
|
+
...refs,
|
|
55800
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
55801
|
+
})) != null ? _a23 : refs.allowedAdditionalProperties
|
|
55802
|
+
};
|
|
55803
|
+
if (((_b22 = def.keyType) == null ? undefined : _b22._def.typeName) === ZodFirstPartyTypeKind2.ZodString && ((_c = def.keyType._def.checks) == null ? undefined : _c.length)) {
|
|
55804
|
+
const { type, ...keyType } = parseStringDef2(def.keyType._def, refs);
|
|
55805
|
+
return {
|
|
55806
|
+
...schema,
|
|
55807
|
+
propertyNames: keyType
|
|
55808
|
+
};
|
|
55809
|
+
} else if (((_d = def.keyType) == null ? undefined : _d._def.typeName) === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
55810
|
+
return {
|
|
55811
|
+
...schema,
|
|
55812
|
+
propertyNames: {
|
|
55813
|
+
enum: def.keyType._def.values
|
|
55814
|
+
}
|
|
55815
|
+
};
|
|
55816
|
+
} else if (((_e = def.keyType) == null ? undefined : _e._def.typeName) === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && ((_f = def.keyType._def.type._def.checks) == null ? undefined : _f.length)) {
|
|
55817
|
+
const { type, ...keyType } = parseBrandedDef2(def.keyType._def, refs);
|
|
55818
|
+
return {
|
|
55819
|
+
...schema,
|
|
55820
|
+
propertyNames: keyType
|
|
55821
|
+
};
|
|
55822
|
+
}
|
|
55823
|
+
return schema;
|
|
55824
|
+
}
|
|
55825
|
+
function parseMapDef2(def, refs) {
|
|
55826
|
+
if (refs.mapStrategy === "record") {
|
|
55827
|
+
return parseRecordDef2(def, refs);
|
|
55828
|
+
}
|
|
55829
|
+
const keys = parseDef2(def.keyType._def, {
|
|
55830
|
+
...refs,
|
|
55831
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
55832
|
+
}) || parseAnyDef2();
|
|
55833
|
+
const values = parseDef2(def.valueType._def, {
|
|
55834
|
+
...refs,
|
|
55835
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
55836
|
+
}) || parseAnyDef2();
|
|
55837
|
+
return {
|
|
55838
|
+
type: "array",
|
|
55839
|
+
maxItems: 125,
|
|
55840
|
+
items: {
|
|
55841
|
+
type: "array",
|
|
55842
|
+
items: [keys, values],
|
|
55843
|
+
minItems: 2,
|
|
55844
|
+
maxItems: 2
|
|
55845
|
+
}
|
|
55846
|
+
};
|
|
55847
|
+
}
|
|
55848
|
+
function parseNativeEnumDef2(def) {
|
|
55849
|
+
const object2 = def.values;
|
|
55850
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
55851
|
+
return typeof object2[object2[key]] !== "number";
|
|
55852
|
+
});
|
|
55853
|
+
const actualValues = actualKeys.map((key) => object2[key]);
|
|
55854
|
+
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
55855
|
+
return {
|
|
55856
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
55857
|
+
enum: actualValues
|
|
55858
|
+
};
|
|
55859
|
+
}
|
|
55860
|
+
function parseNeverDef2() {
|
|
55861
|
+
return { not: parseAnyDef2() };
|
|
55862
|
+
}
|
|
55863
|
+
function parseNullDef2() {
|
|
55864
|
+
return {
|
|
55865
|
+
type: "null"
|
|
55866
|
+
};
|
|
55867
|
+
}
|
|
55868
|
+
var primitiveMappings2 = {
|
|
55869
|
+
ZodString: "string",
|
|
55870
|
+
ZodNumber: "number",
|
|
55871
|
+
ZodBigInt: "integer",
|
|
55872
|
+
ZodBoolean: "boolean",
|
|
55873
|
+
ZodNull: "null"
|
|
55874
|
+
};
|
|
55875
|
+
function parseUnionDef2(def, refs) {
|
|
55876
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
55877
|
+
if (options.every((x) => (x._def.typeName in primitiveMappings2) && (!x._def.checks || !x._def.checks.length))) {
|
|
55878
|
+
const types = options.reduce((types2, x) => {
|
|
55879
|
+
const type = primitiveMappings2[x._def.typeName];
|
|
55880
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
55881
|
+
}, []);
|
|
55882
|
+
return {
|
|
55883
|
+
type: types.length > 1 ? types : types[0]
|
|
55884
|
+
};
|
|
55885
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
55886
|
+
const types = options.reduce((acc, x) => {
|
|
55887
|
+
const type = typeof x._def.value;
|
|
55888
|
+
switch (type) {
|
|
55889
|
+
case "string":
|
|
55890
|
+
case "number":
|
|
55891
|
+
case "boolean":
|
|
55892
|
+
return [...acc, type];
|
|
55893
|
+
case "bigint":
|
|
55894
|
+
return [...acc, "integer"];
|
|
55895
|
+
case "object":
|
|
55896
|
+
if (x._def.value === null)
|
|
55897
|
+
return [...acc, "null"];
|
|
55898
|
+
case "symbol":
|
|
55899
|
+
case "undefined":
|
|
55900
|
+
case "function":
|
|
55901
|
+
default:
|
|
55902
|
+
return acc;
|
|
55903
|
+
}
|
|
55904
|
+
}, []);
|
|
55905
|
+
if (types.length === options.length) {
|
|
55906
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
55907
|
+
return {
|
|
55908
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
55909
|
+
enum: options.reduce((acc, x) => {
|
|
55910
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
55911
|
+
}, [])
|
|
55912
|
+
};
|
|
55913
|
+
}
|
|
55914
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
55915
|
+
return {
|
|
55916
|
+
type: "string",
|
|
55917
|
+
enum: options.reduce((acc, x) => [
|
|
55918
|
+
...acc,
|
|
55919
|
+
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
55920
|
+
], [])
|
|
55921
|
+
};
|
|
55922
|
+
}
|
|
55923
|
+
return asAnyOf2(def, refs);
|
|
55924
|
+
}
|
|
55925
|
+
var asAnyOf2 = (def, refs) => {
|
|
55926
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef2(x._def, {
|
|
55927
|
+
...refs,
|
|
55928
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
55929
|
+
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
55930
|
+
return anyOf.length ? { anyOf } : undefined;
|
|
55931
|
+
};
|
|
55932
|
+
function parseNullableDef2(def, refs) {
|
|
55933
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
55934
|
+
return {
|
|
55935
|
+
type: [
|
|
55936
|
+
primitiveMappings2[def.innerType._def.typeName],
|
|
55937
|
+
"null"
|
|
55938
|
+
]
|
|
55939
|
+
};
|
|
55940
|
+
}
|
|
55941
|
+
const base = parseDef2(def.innerType._def, {
|
|
55942
|
+
...refs,
|
|
55943
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
55944
|
+
});
|
|
55945
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
55946
|
+
}
|
|
55947
|
+
function parseNumberDef2(def) {
|
|
55948
|
+
const res = {
|
|
55949
|
+
type: "number"
|
|
55950
|
+
};
|
|
55951
|
+
if (!def.checks)
|
|
55952
|
+
return res;
|
|
55953
|
+
for (const check2 of def.checks) {
|
|
55954
|
+
switch (check2.kind) {
|
|
55955
|
+
case "int":
|
|
55956
|
+
res.type = "integer";
|
|
55957
|
+
break;
|
|
55958
|
+
case "min":
|
|
55959
|
+
if (check2.inclusive) {
|
|
55960
|
+
res.minimum = check2.value;
|
|
55961
|
+
} else {
|
|
55962
|
+
res.exclusiveMinimum = check2.value;
|
|
55963
|
+
}
|
|
55964
|
+
break;
|
|
55965
|
+
case "max":
|
|
55966
|
+
if (check2.inclusive) {
|
|
55967
|
+
res.maximum = check2.value;
|
|
55968
|
+
} else {
|
|
55969
|
+
res.exclusiveMaximum = check2.value;
|
|
55970
|
+
}
|
|
55971
|
+
break;
|
|
55972
|
+
case "multipleOf":
|
|
55973
|
+
res.multipleOf = check2.value;
|
|
55974
|
+
break;
|
|
55975
|
+
}
|
|
55976
|
+
}
|
|
55977
|
+
return res;
|
|
55978
|
+
}
|
|
55979
|
+
function parseObjectDef2(def, refs) {
|
|
55980
|
+
const result = {
|
|
55981
|
+
type: "object",
|
|
55982
|
+
properties: {}
|
|
55983
|
+
};
|
|
55984
|
+
const required2 = [];
|
|
55985
|
+
const shape = def.shape();
|
|
55986
|
+
for (const propName in shape) {
|
|
55987
|
+
let propDef = shape[propName];
|
|
55988
|
+
if (propDef === undefined || propDef._def === undefined) {
|
|
55989
|
+
continue;
|
|
55990
|
+
}
|
|
55991
|
+
const propOptional = safeIsOptional2(propDef);
|
|
55992
|
+
const parsedDef = parseDef2(propDef._def, {
|
|
55993
|
+
...refs,
|
|
55994
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
55995
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
55996
|
+
});
|
|
55997
|
+
if (parsedDef === undefined) {
|
|
55998
|
+
continue;
|
|
55999
|
+
}
|
|
56000
|
+
result.properties[propName] = parsedDef;
|
|
56001
|
+
if (!propOptional) {
|
|
56002
|
+
required2.push(propName);
|
|
56003
|
+
}
|
|
56004
|
+
}
|
|
56005
|
+
if (required2.length) {
|
|
56006
|
+
result.required = required2;
|
|
56007
|
+
}
|
|
56008
|
+
const additionalProperties = decideAdditionalProperties2(def, refs);
|
|
56009
|
+
if (additionalProperties !== undefined) {
|
|
56010
|
+
result.additionalProperties = additionalProperties;
|
|
56011
|
+
}
|
|
56012
|
+
return result;
|
|
56013
|
+
}
|
|
56014
|
+
function decideAdditionalProperties2(def, refs) {
|
|
56015
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
56016
|
+
return parseDef2(def.catchall._def, {
|
|
56017
|
+
...refs,
|
|
56018
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
56019
|
+
});
|
|
56020
|
+
}
|
|
56021
|
+
switch (def.unknownKeys) {
|
|
56022
|
+
case "passthrough":
|
|
56023
|
+
return refs.allowedAdditionalProperties;
|
|
56024
|
+
case "strict":
|
|
56025
|
+
return refs.rejectedAdditionalProperties;
|
|
56026
|
+
case "strip":
|
|
56027
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
56028
|
+
}
|
|
56029
|
+
}
|
|
56030
|
+
function safeIsOptional2(schema) {
|
|
56031
|
+
try {
|
|
56032
|
+
return schema.isOptional();
|
|
56033
|
+
} catch (e) {
|
|
56034
|
+
return true;
|
|
56035
|
+
}
|
|
56036
|
+
}
|
|
56037
|
+
var parseOptionalDef2 = (def, refs) => {
|
|
56038
|
+
var _a23;
|
|
56039
|
+
if (refs.currentPath.toString() === ((_a23 = refs.propertyPath) == null ? undefined : _a23.toString())) {
|
|
56040
|
+
return parseDef2(def.innerType._def, refs);
|
|
56041
|
+
}
|
|
56042
|
+
const innerSchema = parseDef2(def.innerType._def, {
|
|
56043
|
+
...refs,
|
|
56044
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
56045
|
+
});
|
|
56046
|
+
return innerSchema ? { anyOf: [{ not: parseAnyDef2() }, innerSchema] } : parseAnyDef2();
|
|
56047
|
+
};
|
|
56048
|
+
var parsePipelineDef2 = (def, refs) => {
|
|
56049
|
+
if (refs.pipeStrategy === "input") {
|
|
56050
|
+
return parseDef2(def.in._def, refs);
|
|
56051
|
+
} else if (refs.pipeStrategy === "output") {
|
|
56052
|
+
return parseDef2(def.out._def, refs);
|
|
56053
|
+
}
|
|
56054
|
+
const a = parseDef2(def.in._def, {
|
|
56055
|
+
...refs,
|
|
56056
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
56057
|
+
});
|
|
56058
|
+
const b = parseDef2(def.out._def, {
|
|
56059
|
+
...refs,
|
|
56060
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
56061
|
+
});
|
|
56062
|
+
return {
|
|
56063
|
+
allOf: [a, b].filter((x) => x !== undefined)
|
|
56064
|
+
};
|
|
56065
|
+
};
|
|
56066
|
+
function parsePromiseDef2(def, refs) {
|
|
56067
|
+
return parseDef2(def.type._def, refs);
|
|
56068
|
+
}
|
|
56069
|
+
function parseSetDef2(def, refs) {
|
|
56070
|
+
const items = parseDef2(def.valueType._def, {
|
|
56071
|
+
...refs,
|
|
56072
|
+
currentPath: [...refs.currentPath, "items"]
|
|
56073
|
+
});
|
|
56074
|
+
const schema = {
|
|
56075
|
+
type: "array",
|
|
56076
|
+
uniqueItems: true,
|
|
56077
|
+
items
|
|
56078
|
+
};
|
|
56079
|
+
if (def.minSize) {
|
|
56080
|
+
schema.minItems = def.minSize.value;
|
|
56081
|
+
}
|
|
56082
|
+
if (def.maxSize) {
|
|
56083
|
+
schema.maxItems = def.maxSize.value;
|
|
56084
|
+
}
|
|
56085
|
+
return schema;
|
|
56086
|
+
}
|
|
56087
|
+
function parseTupleDef2(def, refs) {
|
|
56088
|
+
if (def.rest) {
|
|
56089
|
+
return {
|
|
56090
|
+
type: "array",
|
|
56091
|
+
minItems: def.items.length,
|
|
56092
|
+
items: def.items.map((x, i) => parseDef2(x._def, {
|
|
56093
|
+
...refs,
|
|
56094
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
56095
|
+
})).reduce((acc, x) => x === undefined ? acc : [...acc, x], []),
|
|
56096
|
+
additionalItems: parseDef2(def.rest._def, {
|
|
56097
|
+
...refs,
|
|
56098
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
56099
|
+
})
|
|
56100
|
+
};
|
|
56101
|
+
} else {
|
|
56102
|
+
return {
|
|
56103
|
+
type: "array",
|
|
56104
|
+
minItems: def.items.length,
|
|
56105
|
+
maxItems: def.items.length,
|
|
56106
|
+
items: def.items.map((x, i) => parseDef2(x._def, {
|
|
56107
|
+
...refs,
|
|
56108
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
56109
|
+
})).reduce((acc, x) => x === undefined ? acc : [...acc, x], [])
|
|
56110
|
+
};
|
|
56111
|
+
}
|
|
56112
|
+
}
|
|
56113
|
+
function parseUndefinedDef2() {
|
|
56114
|
+
return {
|
|
56115
|
+
not: parseAnyDef2()
|
|
56116
|
+
};
|
|
56117
|
+
}
|
|
56118
|
+
function parseUnknownDef2() {
|
|
56119
|
+
return parseAnyDef2();
|
|
56120
|
+
}
|
|
56121
|
+
var parseReadonlyDef2 = (def, refs) => {
|
|
56122
|
+
return parseDef2(def.innerType._def, refs);
|
|
56123
|
+
};
|
|
56124
|
+
var selectParser2 = (def, typeName, refs) => {
|
|
56125
|
+
switch (typeName) {
|
|
56126
|
+
case ZodFirstPartyTypeKind2.ZodString:
|
|
56127
|
+
return parseStringDef2(def, refs);
|
|
56128
|
+
case ZodFirstPartyTypeKind2.ZodNumber:
|
|
56129
|
+
return parseNumberDef2(def);
|
|
56130
|
+
case ZodFirstPartyTypeKind2.ZodObject:
|
|
56131
|
+
return parseObjectDef2(def, refs);
|
|
56132
|
+
case ZodFirstPartyTypeKind2.ZodBigInt:
|
|
56133
|
+
return parseBigintDef2(def);
|
|
56134
|
+
case ZodFirstPartyTypeKind2.ZodBoolean:
|
|
56135
|
+
return parseBooleanDef2();
|
|
56136
|
+
case ZodFirstPartyTypeKind2.ZodDate:
|
|
56137
|
+
return parseDateDef2(def, refs);
|
|
56138
|
+
case ZodFirstPartyTypeKind2.ZodUndefined:
|
|
56139
|
+
return parseUndefinedDef2();
|
|
56140
|
+
case ZodFirstPartyTypeKind2.ZodNull:
|
|
56141
|
+
return parseNullDef2();
|
|
56142
|
+
case ZodFirstPartyTypeKind2.ZodArray:
|
|
56143
|
+
return parseArrayDef2(def, refs);
|
|
56144
|
+
case ZodFirstPartyTypeKind2.ZodUnion:
|
|
56145
|
+
case ZodFirstPartyTypeKind2.ZodDiscriminatedUnion:
|
|
56146
|
+
return parseUnionDef2(def, refs);
|
|
56147
|
+
case ZodFirstPartyTypeKind2.ZodIntersection:
|
|
56148
|
+
return parseIntersectionDef2(def, refs);
|
|
56149
|
+
case ZodFirstPartyTypeKind2.ZodTuple:
|
|
56150
|
+
return parseTupleDef2(def, refs);
|
|
56151
|
+
case ZodFirstPartyTypeKind2.ZodRecord:
|
|
56152
|
+
return parseRecordDef2(def, refs);
|
|
56153
|
+
case ZodFirstPartyTypeKind2.ZodLiteral:
|
|
56154
|
+
return parseLiteralDef2(def);
|
|
56155
|
+
case ZodFirstPartyTypeKind2.ZodEnum:
|
|
56156
|
+
return parseEnumDef2(def);
|
|
56157
|
+
case ZodFirstPartyTypeKind2.ZodNativeEnum:
|
|
56158
|
+
return parseNativeEnumDef2(def);
|
|
56159
|
+
case ZodFirstPartyTypeKind2.ZodNullable:
|
|
56160
|
+
return parseNullableDef2(def, refs);
|
|
56161
|
+
case ZodFirstPartyTypeKind2.ZodOptional:
|
|
56162
|
+
return parseOptionalDef2(def, refs);
|
|
56163
|
+
case ZodFirstPartyTypeKind2.ZodMap:
|
|
56164
|
+
return parseMapDef2(def, refs);
|
|
56165
|
+
case ZodFirstPartyTypeKind2.ZodSet:
|
|
56166
|
+
return parseSetDef2(def, refs);
|
|
56167
|
+
case ZodFirstPartyTypeKind2.ZodLazy:
|
|
56168
|
+
return () => def.getter()._def;
|
|
56169
|
+
case ZodFirstPartyTypeKind2.ZodPromise:
|
|
56170
|
+
return parsePromiseDef2(def, refs);
|
|
56171
|
+
case ZodFirstPartyTypeKind2.ZodNaN:
|
|
56172
|
+
case ZodFirstPartyTypeKind2.ZodNever:
|
|
56173
|
+
return parseNeverDef2();
|
|
56174
|
+
case ZodFirstPartyTypeKind2.ZodEffects:
|
|
56175
|
+
return parseEffectsDef2(def, refs);
|
|
56176
|
+
case ZodFirstPartyTypeKind2.ZodAny:
|
|
56177
|
+
return parseAnyDef2();
|
|
56178
|
+
case ZodFirstPartyTypeKind2.ZodUnknown:
|
|
56179
|
+
return parseUnknownDef2();
|
|
56180
|
+
case ZodFirstPartyTypeKind2.ZodDefault:
|
|
56181
|
+
return parseDefaultDef2(def, refs);
|
|
56182
|
+
case ZodFirstPartyTypeKind2.ZodBranded:
|
|
56183
|
+
return parseBrandedDef2(def, refs);
|
|
56184
|
+
case ZodFirstPartyTypeKind2.ZodReadonly:
|
|
56185
|
+
return parseReadonlyDef2(def, refs);
|
|
56186
|
+
case ZodFirstPartyTypeKind2.ZodCatch:
|
|
56187
|
+
return parseCatchDef2(def, refs);
|
|
56188
|
+
case ZodFirstPartyTypeKind2.ZodPipeline:
|
|
56189
|
+
return parsePipelineDef2(def, refs);
|
|
56190
|
+
case ZodFirstPartyTypeKind2.ZodFunction:
|
|
56191
|
+
case ZodFirstPartyTypeKind2.ZodVoid:
|
|
56192
|
+
case ZodFirstPartyTypeKind2.ZodSymbol:
|
|
56193
|
+
return;
|
|
56194
|
+
default:
|
|
56195
|
+
return /* @__PURE__ */ ((_) => {
|
|
56196
|
+
return;
|
|
56197
|
+
})(typeName);
|
|
56198
|
+
}
|
|
56199
|
+
};
|
|
56200
|
+
var getRelativePath2 = (pathA, pathB) => {
|
|
56201
|
+
let i = 0;
|
|
56202
|
+
for (;i < pathA.length && i < pathB.length; i++) {
|
|
56203
|
+
if (pathA[i] !== pathB[i])
|
|
56204
|
+
break;
|
|
56205
|
+
}
|
|
56206
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
56207
|
+
};
|
|
56208
|
+
function parseDef2(def, refs, forceResolution = false) {
|
|
56209
|
+
var _a23;
|
|
56210
|
+
const seenItem = refs.seen.get(def);
|
|
56211
|
+
if (refs.override) {
|
|
56212
|
+
const overrideResult = (_a23 = refs.override) == null ? undefined : _a23.call(refs, def, refs, seenItem, forceResolution);
|
|
56213
|
+
if (overrideResult !== ignoreOverride2) {
|
|
56214
|
+
return overrideResult;
|
|
56215
|
+
}
|
|
56216
|
+
}
|
|
56217
|
+
if (seenItem && !forceResolution) {
|
|
56218
|
+
const seenSchema = get$ref2(seenItem, refs);
|
|
56219
|
+
if (seenSchema !== undefined) {
|
|
56220
|
+
return seenSchema;
|
|
56221
|
+
}
|
|
56222
|
+
}
|
|
56223
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: undefined };
|
|
56224
|
+
refs.seen.set(def, newItem);
|
|
56225
|
+
const jsonSchemaOrGetter = selectParser2(def, def.typeName, refs);
|
|
56226
|
+
const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef2(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
56227
|
+
if (jsonSchema2) {
|
|
56228
|
+
addMeta2(def, refs, jsonSchema2);
|
|
56229
|
+
}
|
|
56230
|
+
if (refs.postProcess) {
|
|
56231
|
+
const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
|
|
56232
|
+
newItem.jsonSchema = jsonSchema2;
|
|
56233
|
+
return postProcessResult;
|
|
56234
|
+
}
|
|
56235
|
+
newItem.jsonSchema = jsonSchema2;
|
|
56236
|
+
return jsonSchema2;
|
|
56237
|
+
}
|
|
56238
|
+
var get$ref2 = (item, refs) => {
|
|
56239
|
+
switch (refs.$refStrategy) {
|
|
56240
|
+
case "root":
|
|
56241
|
+
return { $ref: item.path.join("/") };
|
|
56242
|
+
case "relative":
|
|
56243
|
+
return { $ref: getRelativePath2(refs.currentPath, item.path) };
|
|
56244
|
+
case "none":
|
|
56245
|
+
case "seen": {
|
|
56246
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
56247
|
+
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
56248
|
+
return parseAnyDef2();
|
|
56249
|
+
}
|
|
56250
|
+
return refs.$refStrategy === "seen" ? parseAnyDef2() : undefined;
|
|
56251
|
+
}
|
|
56252
|
+
}
|
|
56253
|
+
};
|
|
56254
|
+
var addMeta2 = (def, refs, jsonSchema2) => {
|
|
56255
|
+
if (def.description) {
|
|
56256
|
+
jsonSchema2.description = def.description;
|
|
56257
|
+
}
|
|
56258
|
+
return jsonSchema2;
|
|
56259
|
+
};
|
|
56260
|
+
var getRefs2 = (options) => {
|
|
56261
|
+
const _options = getDefaultOptions2(options);
|
|
56262
|
+
const currentPath = _options.name !== undefined ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
56263
|
+
return {
|
|
56264
|
+
..._options,
|
|
56265
|
+
currentPath,
|
|
56266
|
+
propertyPath: undefined,
|
|
56267
|
+
seen: new Map(Object.entries(_options.definitions).map(([name22, def]) => [
|
|
56268
|
+
def._def,
|
|
56269
|
+
{
|
|
56270
|
+
def: def._def,
|
|
56271
|
+
path: [..._options.basePath, _options.definitionPath, name22],
|
|
56272
|
+
jsonSchema: undefined
|
|
56273
|
+
}
|
|
56274
|
+
]))
|
|
56275
|
+
};
|
|
56276
|
+
};
|
|
56277
|
+
var zod3ToJsonSchema2 = (schema, options) => {
|
|
56278
|
+
var _a23;
|
|
56279
|
+
const refs = getRefs2(options);
|
|
56280
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name32, schema2]) => {
|
|
56281
|
+
var _a32;
|
|
56282
|
+
return {
|
|
56283
|
+
...acc,
|
|
56284
|
+
[name32]: (_a32 = parseDef2(schema2._def, {
|
|
56285
|
+
...refs,
|
|
56286
|
+
currentPath: [...refs.basePath, refs.definitionPath, name32]
|
|
56287
|
+
}, true)) != null ? _a32 : parseAnyDef2()
|
|
56288
|
+
};
|
|
56289
|
+
}, {}) : undefined;
|
|
56290
|
+
const name22 = typeof options === "string" ? options : (options == null ? undefined : options.nameStrategy) === "title" ? undefined : options == null ? undefined : options.name;
|
|
56291
|
+
const main = (_a23 = parseDef2(schema._def, name22 === undefined ? refs : {
|
|
56292
|
+
...refs,
|
|
56293
|
+
currentPath: [...refs.basePath, refs.definitionPath, name22]
|
|
56294
|
+
}, false)) != null ? _a23 : parseAnyDef2();
|
|
56295
|
+
const title = typeof options === "object" && options.name !== undefined && options.nameStrategy === "title" ? options.name : undefined;
|
|
56296
|
+
if (title !== undefined) {
|
|
56297
|
+
main.title = title;
|
|
56298
|
+
}
|
|
56299
|
+
const combined = name22 === undefined ? definitions ? {
|
|
56300
|
+
...main,
|
|
56301
|
+
[refs.definitionPath]: definitions
|
|
56302
|
+
} : main : {
|
|
56303
|
+
$ref: [
|
|
56304
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
56305
|
+
refs.definitionPath,
|
|
56306
|
+
name22
|
|
56307
|
+
].join("/"),
|
|
56308
|
+
[refs.definitionPath]: {
|
|
56309
|
+
...definitions,
|
|
56310
|
+
[name22]: main
|
|
56311
|
+
}
|
|
56312
|
+
};
|
|
56313
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
56314
|
+
return combined;
|
|
56315
|
+
};
|
|
56316
|
+
var schemaSymbol2 = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
56317
|
+
function jsonSchema2(jsonSchema22, {
|
|
56318
|
+
validate
|
|
56319
|
+
} = {}) {
|
|
56320
|
+
return {
|
|
56321
|
+
[schemaSymbol2]: true,
|
|
56322
|
+
_type: undefined,
|
|
56323
|
+
get jsonSchema() {
|
|
56324
|
+
if (typeof jsonSchema22 === "function") {
|
|
56325
|
+
jsonSchema22 = jsonSchema22();
|
|
56326
|
+
}
|
|
56327
|
+
return jsonSchema22;
|
|
56328
|
+
},
|
|
56329
|
+
validate
|
|
56330
|
+
};
|
|
56331
|
+
}
|
|
56332
|
+
function isSchema2(value) {
|
|
56333
|
+
return typeof value === "object" && value !== null && schemaSymbol2 in value && value[schemaSymbol2] === true && "jsonSchema" in value && "validate" in value;
|
|
56334
|
+
}
|
|
56335
|
+
function asSchema2(schema) {
|
|
56336
|
+
return schema == null ? jsonSchema2({ properties: {}, additionalProperties: false }) : isSchema2(schema) ? schema : ("~standard" in schema) ? schema["~standard"].vendor === "zod" ? zodSchema2(schema) : standardSchema2(schema) : schema();
|
|
56337
|
+
}
|
|
56338
|
+
function standardSchema2(standardSchema22) {
|
|
56339
|
+
return jsonSchema2(() => addAdditionalPropertiesToJsonSchema2(standardSchema22["~standard"].jsonSchema.input({
|
|
56340
|
+
target: "draft-07"
|
|
56341
|
+
})), {
|
|
56342
|
+
validate: async (value) => {
|
|
56343
|
+
const result = await standardSchema22["~standard"].validate(value);
|
|
56344
|
+
return "value" in result ? { success: true, value: result.value } : {
|
|
56345
|
+
success: false,
|
|
56346
|
+
error: new TypeValidationError({
|
|
56347
|
+
value,
|
|
56348
|
+
cause: result.issues
|
|
56349
|
+
})
|
|
56350
|
+
};
|
|
56351
|
+
}
|
|
56352
|
+
});
|
|
56353
|
+
}
|
|
56354
|
+
function zod3Schema2(zodSchema2, options) {
|
|
56355
|
+
var _a23;
|
|
56356
|
+
const useReferences = (_a23 = options == null ? undefined : options.useReferences) != null ? _a23 : false;
|
|
56357
|
+
return jsonSchema2(() => zod3ToJsonSchema2(zodSchema2, {
|
|
56358
|
+
$refStrategy: useReferences ? "root" : "none"
|
|
56359
|
+
}), {
|
|
56360
|
+
validate: async (value) => {
|
|
56361
|
+
const result = await zodSchema2.safeParseAsync(value);
|
|
56362
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
56363
|
+
}
|
|
56364
|
+
});
|
|
56365
|
+
}
|
|
56366
|
+
function zod4Schema2(zodSchema2, options) {
|
|
56367
|
+
var _a23;
|
|
56368
|
+
const useReferences = (_a23 = options == null ? undefined : options.useReferences) != null ? _a23 : false;
|
|
56369
|
+
return jsonSchema2(() => addAdditionalPropertiesToJsonSchema2(toJSONSchema(zodSchema2, {
|
|
56370
|
+
target: "draft-7",
|
|
56371
|
+
io: "input",
|
|
56372
|
+
reused: useReferences ? "ref" : "inline"
|
|
56373
|
+
})), {
|
|
56374
|
+
validate: async (value) => {
|
|
56375
|
+
const result = await safeParseAsync2(zodSchema2, value);
|
|
56376
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
56377
|
+
}
|
|
56378
|
+
});
|
|
56379
|
+
}
|
|
56380
|
+
function isZod4Schema2(zodSchema2) {
|
|
56381
|
+
return "_zod" in zodSchema2;
|
|
56382
|
+
}
|
|
56383
|
+
function zodSchema2(zodSchema22, options) {
|
|
56384
|
+
if (isZod4Schema2(zodSchema22)) {
|
|
56385
|
+
return zod4Schema2(zodSchema22, options);
|
|
56386
|
+
} else {
|
|
56387
|
+
return zod3Schema2(zodSchema22, options);
|
|
56388
|
+
}
|
|
56389
|
+
}
|
|
56390
|
+
async function validateTypes2({
|
|
56391
|
+
value,
|
|
56392
|
+
schema,
|
|
56393
|
+
context
|
|
56394
|
+
}) {
|
|
56395
|
+
const result = await safeValidateTypes2({ value, schema, context });
|
|
56396
|
+
if (!result.success) {
|
|
56397
|
+
throw TypeValidationError.wrap({ value, cause: result.error, context });
|
|
56398
|
+
}
|
|
56399
|
+
return result.value;
|
|
56400
|
+
}
|
|
56401
|
+
async function safeValidateTypes2({
|
|
56402
|
+
value,
|
|
56403
|
+
schema,
|
|
56404
|
+
context
|
|
56405
|
+
}) {
|
|
56406
|
+
const actualSchema = asSchema2(schema);
|
|
56407
|
+
try {
|
|
56408
|
+
if (actualSchema.validate == null) {
|
|
56409
|
+
return { success: true, value, rawValue: value };
|
|
56410
|
+
}
|
|
56411
|
+
const result = await actualSchema.validate(value);
|
|
56412
|
+
if (result.success) {
|
|
56413
|
+
return { success: true, value: result.value, rawValue: value };
|
|
56414
|
+
}
|
|
56415
|
+
return {
|
|
56416
|
+
success: false,
|
|
56417
|
+
error: TypeValidationError.wrap({ value, cause: result.error, context }),
|
|
56418
|
+
rawValue: value
|
|
56419
|
+
};
|
|
56420
|
+
} catch (error48) {
|
|
56421
|
+
return {
|
|
56422
|
+
success: false,
|
|
56423
|
+
error: TypeValidationError.wrap({ value, cause: error48, context }),
|
|
56424
|
+
rawValue: value
|
|
56425
|
+
};
|
|
56426
|
+
}
|
|
56427
|
+
}
|
|
56428
|
+
async function parseJSON2({
|
|
56429
|
+
text,
|
|
56430
|
+
schema
|
|
56431
|
+
}) {
|
|
56432
|
+
try {
|
|
56433
|
+
const value = secureJsonParse2(text);
|
|
56434
|
+
if (schema == null) {
|
|
56435
|
+
return value;
|
|
56436
|
+
}
|
|
56437
|
+
return validateTypes2({ value, schema });
|
|
56438
|
+
} catch (error48) {
|
|
56439
|
+
if (JSONParseError.isInstance(error48) || TypeValidationError.isInstance(error48)) {
|
|
56440
|
+
throw error48;
|
|
56441
|
+
}
|
|
56442
|
+
throw new JSONParseError({ text, cause: error48 });
|
|
54298
56443
|
}
|
|
54299
|
-
|
|
54300
|
-
|
|
54301
|
-
|
|
54302
|
-
|
|
54303
|
-
|
|
54304
|
-
|
|
54305
|
-
const
|
|
54306
|
-
|
|
54307
|
-
|
|
54308
|
-
|
|
54309
|
-
|
|
56444
|
+
}
|
|
56445
|
+
async function safeParseJSON2({
|
|
56446
|
+
text,
|
|
56447
|
+
schema
|
|
56448
|
+
}) {
|
|
56449
|
+
try {
|
|
56450
|
+
const value = secureJsonParse2(text);
|
|
56451
|
+
if (schema == null) {
|
|
56452
|
+
return { success: true, value, rawValue: value };
|
|
56453
|
+
}
|
|
56454
|
+
return await safeValidateTypes2({ value, schema });
|
|
56455
|
+
} catch (error48) {
|
|
56456
|
+
return {
|
|
56457
|
+
success: false,
|
|
56458
|
+
error: JSONParseError.isInstance(error48) ? error48 : new JSONParseError({ text, cause: error48 }),
|
|
56459
|
+
rawValue: undefined
|
|
56460
|
+
};
|
|
56461
|
+
}
|
|
56462
|
+
}
|
|
56463
|
+
async function parseProviderOptions2({
|
|
56464
|
+
provider,
|
|
56465
|
+
providerOptions,
|
|
56466
|
+
schema
|
|
56467
|
+
}) {
|
|
56468
|
+
if ((providerOptions == null ? undefined : providerOptions[provider]) == null) {
|
|
56469
|
+
return;
|
|
56470
|
+
}
|
|
56471
|
+
const parsedProviderOptions = await safeValidateTypes2({
|
|
56472
|
+
value: providerOptions[provider],
|
|
56473
|
+
schema
|
|
56474
|
+
});
|
|
56475
|
+
if (!parsedProviderOptions.success) {
|
|
56476
|
+
throw new InvalidArgumentError({
|
|
56477
|
+
argument: "providerOptions",
|
|
56478
|
+
message: `invalid ${provider} provider options`,
|
|
56479
|
+
cause: parsedProviderOptions.error
|
|
54310
56480
|
});
|
|
54311
|
-
|
|
54312
|
-
|
|
54313
|
-
|
|
54314
|
-
|
|
54315
|
-
|
|
54316
|
-
|
|
54317
|
-
|
|
54318
|
-
|
|
54319
|
-
|
|
54320
|
-
|
|
54321
|
-
|
|
54322
|
-
|
|
54323
|
-
|
|
54324
|
-
|
|
54325
|
-
|
|
54326
|
-
|
|
54327
|
-
|
|
54328
|
-
|
|
54329
|
-
|
|
54330
|
-
|
|
54331
|
-
|
|
54332
|
-
|
|
54333
|
-
|
|
56481
|
+
}
|
|
56482
|
+
return parsedProviderOptions.value;
|
|
56483
|
+
}
|
|
56484
|
+
var getOriginalFetch22 = () => globalThis.fetch;
|
|
56485
|
+
var postJsonToApi2 = async ({
|
|
56486
|
+
url: url2,
|
|
56487
|
+
headers,
|
|
56488
|
+
body,
|
|
56489
|
+
failedResponseHandler,
|
|
56490
|
+
successfulResponseHandler,
|
|
56491
|
+
abortSignal,
|
|
56492
|
+
fetch: fetch2
|
|
56493
|
+
}) => postToApi2({
|
|
56494
|
+
url: url2,
|
|
56495
|
+
headers: {
|
|
56496
|
+
"Content-Type": "application/json",
|
|
56497
|
+
...headers
|
|
56498
|
+
},
|
|
56499
|
+
body: {
|
|
56500
|
+
content: JSON.stringify(body),
|
|
56501
|
+
values: body
|
|
56502
|
+
},
|
|
56503
|
+
failedResponseHandler,
|
|
56504
|
+
successfulResponseHandler,
|
|
56505
|
+
abortSignal,
|
|
56506
|
+
fetch: fetch2
|
|
56507
|
+
});
|
|
56508
|
+
var postToApi2 = async ({
|
|
56509
|
+
url: url2,
|
|
56510
|
+
headers = {},
|
|
56511
|
+
body,
|
|
56512
|
+
successfulResponseHandler,
|
|
56513
|
+
failedResponseHandler,
|
|
56514
|
+
abortSignal,
|
|
56515
|
+
fetch: fetch2 = getOriginalFetch22()
|
|
56516
|
+
}) => {
|
|
56517
|
+
try {
|
|
56518
|
+
const response = await fetch2(url2, {
|
|
56519
|
+
method: "POST",
|
|
56520
|
+
headers: withUserAgentSuffix2(headers, `ai-sdk/provider-utils/${VERSION8}`, getRuntimeEnvironmentUserAgent2()),
|
|
56521
|
+
body: body.content,
|
|
56522
|
+
signal: abortSignal
|
|
56523
|
+
});
|
|
56524
|
+
const responseHeaders = extractResponseHeaders2(response);
|
|
56525
|
+
if (!response.ok) {
|
|
56526
|
+
let errorInformation;
|
|
56527
|
+
try {
|
|
56528
|
+
errorInformation = await failedResponseHandler({
|
|
56529
|
+
response,
|
|
56530
|
+
url: url2,
|
|
56531
|
+
requestBodyValues: body.values
|
|
56532
|
+
});
|
|
56533
|
+
} catch (error48) {
|
|
56534
|
+
if (isAbortError2(error48) || APICallError.isInstance(error48)) {
|
|
56535
|
+
throw error48;
|
|
56536
|
+
}
|
|
56537
|
+
throw new APICallError({
|
|
56538
|
+
message: "Failed to process error response",
|
|
56539
|
+
cause: error48,
|
|
56540
|
+
statusCode: response.status,
|
|
56541
|
+
url: url2,
|
|
56542
|
+
responseHeaders,
|
|
56543
|
+
requestBodyValues: body.values
|
|
56544
|
+
});
|
|
56545
|
+
}
|
|
56546
|
+
throw errorInformation.value;
|
|
56547
|
+
}
|
|
56548
|
+
try {
|
|
56549
|
+
return await successfulResponseHandler({
|
|
56550
|
+
response,
|
|
56551
|
+
url: url2,
|
|
56552
|
+
requestBodyValues: body.values
|
|
56553
|
+
});
|
|
56554
|
+
} catch (error48) {
|
|
56555
|
+
if (error48 instanceof Error) {
|
|
56556
|
+
if (isAbortError2(error48) || APICallError.isInstance(error48)) {
|
|
56557
|
+
throw error48;
|
|
54334
56558
|
}
|
|
54335
56559
|
}
|
|
56560
|
+
throw new APICallError({
|
|
56561
|
+
message: "Failed to process successful response",
|
|
56562
|
+
cause: error48,
|
|
56563
|
+
statusCode: response.status,
|
|
56564
|
+
url: url2,
|
|
56565
|
+
responseHeaders,
|
|
56566
|
+
requestBodyValues: body.values
|
|
56567
|
+
});
|
|
54336
56568
|
}
|
|
56569
|
+
} catch (error48) {
|
|
56570
|
+
throw handleFetchError2({ error: error48, url: url2, requestBodyValues: body.values });
|
|
56571
|
+
}
|
|
56572
|
+
};
|
|
56573
|
+
var createJsonErrorResponseHandler2 = ({
|
|
56574
|
+
errorSchema,
|
|
56575
|
+
errorToMessage,
|
|
56576
|
+
isRetryable
|
|
56577
|
+
}) => async ({ response, url: url2, requestBodyValues }) => {
|
|
56578
|
+
const responseBody = await response.text();
|
|
56579
|
+
const responseHeaders = extractResponseHeaders2(response);
|
|
56580
|
+
if (responseBody.trim() === "") {
|
|
54337
56581
|
return {
|
|
54338
|
-
|
|
54339
|
-
|
|
56582
|
+
responseHeaders,
|
|
56583
|
+
value: new APICallError({
|
|
56584
|
+
message: response.statusText,
|
|
56585
|
+
url: url2,
|
|
56586
|
+
requestBodyValues,
|
|
56587
|
+
statusCode: response.status,
|
|
56588
|
+
responseHeaders,
|
|
56589
|
+
responseBody,
|
|
56590
|
+
isRetryable: isRetryable == null ? undefined : isRetryable(response)
|
|
56591
|
+
})
|
|
54340
56592
|
};
|
|
54341
56593
|
}
|
|
54342
|
-
|
|
54343
|
-
|
|
54344
|
-
|
|
54345
|
-
|
|
54346
|
-
const {
|
|
54347
|
-
value: response,
|
|
54348
|
-
responseHeaders,
|
|
54349
|
-
rawValue: rawResponse
|
|
54350
|
-
} = await postFormDataToApi({
|
|
54351
|
-
url: this.config.url({
|
|
54352
|
-
path: "/audio/transcriptions",
|
|
54353
|
-
modelId: this.modelId
|
|
54354
|
-
}),
|
|
54355
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
54356
|
-
formData,
|
|
54357
|
-
failedResponseHandler: groqFailedResponseHandler,
|
|
54358
|
-
successfulResponseHandler: createJsonResponseHandler(groqTranscriptionResponseSchema),
|
|
54359
|
-
abortSignal: options.abortSignal,
|
|
54360
|
-
fetch: this.config.fetch
|
|
56594
|
+
try {
|
|
56595
|
+
const parsedError = await parseJSON2({
|
|
56596
|
+
text: responseBody,
|
|
56597
|
+
schema: errorSchema
|
|
54361
56598
|
});
|
|
54362
56599
|
return {
|
|
54363
|
-
|
|
54364
|
-
|
|
54365
|
-
|
|
54366
|
-
|
|
54367
|
-
|
|
54368
|
-
|
|
54369
|
-
|
|
54370
|
-
|
|
54371
|
-
|
|
54372
|
-
|
|
54373
|
-
|
|
54374
|
-
|
|
54375
|
-
|
|
54376
|
-
|
|
54377
|
-
|
|
56600
|
+
responseHeaders,
|
|
56601
|
+
value: new APICallError({
|
|
56602
|
+
message: errorToMessage(parsedError),
|
|
56603
|
+
url: url2,
|
|
56604
|
+
requestBodyValues,
|
|
56605
|
+
statusCode: response.status,
|
|
56606
|
+
responseHeaders,
|
|
56607
|
+
responseBody,
|
|
56608
|
+
data: parsedError,
|
|
56609
|
+
isRetryable: isRetryable == null ? undefined : isRetryable(response, parsedError)
|
|
56610
|
+
})
|
|
56611
|
+
};
|
|
56612
|
+
} catch (parseError) {
|
|
56613
|
+
return {
|
|
56614
|
+
responseHeaders,
|
|
56615
|
+
value: new APICallError({
|
|
56616
|
+
message: response.statusText,
|
|
56617
|
+
url: url2,
|
|
56618
|
+
requestBodyValues,
|
|
56619
|
+
statusCode: response.status,
|
|
56620
|
+
responseHeaders,
|
|
56621
|
+
responseBody,
|
|
56622
|
+
isRetryable: isRetryable == null ? undefined : isRetryable(response)
|
|
56623
|
+
})
|
|
54378
56624
|
};
|
|
54379
56625
|
}
|
|
54380
56626
|
};
|
|
54381
|
-
var
|
|
54382
|
-
|
|
54383
|
-
|
|
54384
|
-
|
|
54385
|
-
|
|
54386
|
-
task: exports_external.string().nullish(),
|
|
54387
|
-
language: exports_external.string().nullish(),
|
|
54388
|
-
duration: exports_external.number().nullish(),
|
|
54389
|
-
segments: exports_external.array(exports_external.object({
|
|
54390
|
-
id: exports_external.number(),
|
|
54391
|
-
seek: exports_external.number(),
|
|
54392
|
-
start: exports_external.number(),
|
|
54393
|
-
end: exports_external.number(),
|
|
54394
|
-
text: exports_external.string(),
|
|
54395
|
-
tokens: exports_external.array(exports_external.number()),
|
|
54396
|
-
temperature: exports_external.number(),
|
|
54397
|
-
avg_logprob: exports_external.number(),
|
|
54398
|
-
compression_ratio: exports_external.number(),
|
|
54399
|
-
no_speech_prob: exports_external.number()
|
|
54400
|
-
})).nullish()
|
|
54401
|
-
});
|
|
54402
|
-
var browserSearch = createProviderToolFactory({
|
|
54403
|
-
id: "groq.browser_search",
|
|
54404
|
-
inputSchema: exports_external.object({})
|
|
54405
|
-
});
|
|
54406
|
-
var groqTools = {
|
|
54407
|
-
browserSearch
|
|
54408
|
-
};
|
|
54409
|
-
var VERSION7 = "3.0.31";
|
|
54410
|
-
function createGroq(options = {}) {
|
|
54411
|
-
var _a16;
|
|
54412
|
-
const baseURL = (_a16 = withoutTrailingSlash(options.baseURL)) != null ? _a16 : "https://api.groq.com/openai/v1";
|
|
54413
|
-
const getHeaders = () => withUserAgentSuffix({
|
|
54414
|
-
Authorization: `Bearer ${loadApiKey({
|
|
54415
|
-
apiKey: options.apiKey,
|
|
54416
|
-
environmentVariableName: "GROQ_API_KEY",
|
|
54417
|
-
description: "Groq"
|
|
54418
|
-
})}`,
|
|
54419
|
-
...options.headers
|
|
54420
|
-
}, `ai-sdk/groq/${VERSION7}`);
|
|
54421
|
-
const createChatModel = (modelId) => new GroqChatLanguageModel(modelId, {
|
|
54422
|
-
provider: "groq.chat",
|
|
54423
|
-
url: ({ path: path2 }) => `${baseURL}${path2}`,
|
|
54424
|
-
headers: getHeaders,
|
|
54425
|
-
fetch: options.fetch
|
|
56627
|
+
var createJsonResponseHandler2 = (responseSchema2) => async ({ response, url: url2, requestBodyValues }) => {
|
|
56628
|
+
const responseBody = await response.text();
|
|
56629
|
+
const parsedResult = await safeParseJSON2({
|
|
56630
|
+
text: responseBody,
|
|
56631
|
+
schema: responseSchema2
|
|
54426
56632
|
});
|
|
54427
|
-
const
|
|
54428
|
-
|
|
54429
|
-
|
|
54430
|
-
|
|
54431
|
-
|
|
54432
|
-
|
|
54433
|
-
|
|
54434
|
-
|
|
54435
|
-
|
|
54436
|
-
|
|
54437
|
-
headers: getHeaders,
|
|
54438
|
-
fetch: options.fetch
|
|
56633
|
+
const responseHeaders = extractResponseHeaders2(response);
|
|
56634
|
+
if (!parsedResult.success) {
|
|
56635
|
+
throw new APICallError({
|
|
56636
|
+
message: "Invalid JSON response",
|
|
56637
|
+
cause: parsedResult.error,
|
|
56638
|
+
statusCode: response.status,
|
|
56639
|
+
responseHeaders,
|
|
56640
|
+
responseBody,
|
|
56641
|
+
url: url2,
|
|
56642
|
+
requestBodyValues
|
|
54439
56643
|
});
|
|
56644
|
+
}
|
|
56645
|
+
return {
|
|
56646
|
+
responseHeaders,
|
|
56647
|
+
value: parsedResult.value,
|
|
56648
|
+
rawValue: parsedResult.rawValue
|
|
54440
56649
|
};
|
|
54441
|
-
|
|
54442
|
-
|
|
54443
|
-
|
|
54444
|
-
provider.specificationVersion = "v3";
|
|
54445
|
-
provider.languageModel = createLanguageModel;
|
|
54446
|
-
provider.chat = createChatModel;
|
|
54447
|
-
provider.embeddingModel = (modelId) => {
|
|
54448
|
-
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
54449
|
-
};
|
|
54450
|
-
provider.textEmbeddingModel = provider.embeddingModel;
|
|
54451
|
-
provider.imageModel = (modelId) => {
|
|
54452
|
-
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
54453
|
-
};
|
|
54454
|
-
provider.transcription = createTranscriptionModel;
|
|
54455
|
-
provider.transcriptionModel = createTranscriptionModel;
|
|
54456
|
-
provider.tools = groqTools;
|
|
54457
|
-
return provider;
|
|
54458
|
-
}
|
|
54459
|
-
var groq = createGroq();
|
|
54460
|
-
|
|
54461
|
-
// src/providers/groq.ts
|
|
54462
|
-
function createGroqProvider(config2, providerName) {
|
|
54463
|
-
return createGroq({
|
|
54464
|
-
apiKey: resolveApiKey(config2.api_key_env, providerName),
|
|
54465
|
-
baseURL: config2.base_url,
|
|
54466
|
-
headers: config2.headers
|
|
54467
|
-
});
|
|
56650
|
+
};
|
|
56651
|
+
function withoutTrailingSlash2(url2) {
|
|
56652
|
+
return url2 == null ? undefined : url2.replace(/\/$/, "");
|
|
54468
56653
|
}
|
|
54469
56654
|
|
|
54470
56655
|
// node_modules/ollama-ai-provider-v2/dist/index.mjs
|
|
@@ -54582,7 +56767,7 @@ function getResponseMetadata5({
|
|
|
54582
56767
|
}
|
|
54583
56768
|
function createNdjsonStreamResponseHandler(schema) {
|
|
54584
56769
|
return async ({ response }) => {
|
|
54585
|
-
const responseHeaders =
|
|
56770
|
+
const responseHeaders = extractResponseHeaders2(response);
|
|
54586
56771
|
if (response.body == null) {
|
|
54587
56772
|
throw new Error("Response body is null");
|
|
54588
56773
|
}
|
|
@@ -54640,7 +56825,7 @@ var ollamaErrorDataSchema = exports_external.object({
|
|
|
54640
56825
|
code: exports_external.union([exports_external.string(), exports_external.number()]).nullish()
|
|
54641
56826
|
})
|
|
54642
56827
|
});
|
|
54643
|
-
var ollamaFailedResponseHandler =
|
|
56828
|
+
var ollamaFailedResponseHandler = createJsonErrorResponseHandler2({
|
|
54644
56829
|
errorSchema: ollamaErrorDataSchema,
|
|
54645
56830
|
errorToMessage: (data) => data.error.message
|
|
54646
56831
|
});
|
|
@@ -54722,15 +56907,15 @@ var OllamaCompletionLanguageModel = class {
|
|
|
54722
56907
|
responseHeaders,
|
|
54723
56908
|
value: response,
|
|
54724
56909
|
rawValue: rawResponse
|
|
54725
|
-
} = await
|
|
56910
|
+
} = await postJsonToApi2({
|
|
54726
56911
|
url: this.config.url({
|
|
54727
56912
|
path: "/generate",
|
|
54728
56913
|
modelId: this.modelId
|
|
54729
56914
|
}),
|
|
54730
|
-
headers:
|
|
56915
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
54731
56916
|
body: { ...body, stream: false },
|
|
54732
56917
|
failedResponseHandler: ollamaFailedResponseHandler,
|
|
54733
|
-
successfulResponseHandler:
|
|
56918
|
+
successfulResponseHandler: createJsonResponseHandler2(baseOllamaResponseSchema),
|
|
54734
56919
|
abortSignal: options.abortSignal,
|
|
54735
56920
|
fetch: this.config.fetch
|
|
54736
56921
|
});
|
|
@@ -54772,12 +56957,12 @@ var OllamaCompletionLanguageModel = class {
|
|
|
54772
56957
|
...args,
|
|
54773
56958
|
stream: true
|
|
54774
56959
|
};
|
|
54775
|
-
const { responseHeaders, value: response } = await
|
|
56960
|
+
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
54776
56961
|
url: this.config.url({
|
|
54777
56962
|
path: "/generate",
|
|
54778
56963
|
modelId: this.modelId
|
|
54779
56964
|
}),
|
|
54780
|
-
headers:
|
|
56965
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
54781
56966
|
body,
|
|
54782
56967
|
failedResponseHandler: ollamaFailedResponseHandler,
|
|
54783
56968
|
successfulResponseHandler: createNdjsonStreamResponseHandler(baseOllamaResponseSchema),
|
|
@@ -54801,7 +56986,7 @@ var OllamaCompletionLanguageModel = class {
|
|
|
54801
56986
|
};
|
|
54802
56987
|
let isFirstChunk = true;
|
|
54803
56988
|
let textStarted = false;
|
|
54804
|
-
const textId =
|
|
56989
|
+
const textId = generateId2();
|
|
54805
56990
|
return {
|
|
54806
56991
|
stream: response.pipeThrough(new TransformStream({
|
|
54807
56992
|
transform(chunk, controller) {
|
|
@@ -54915,7 +57100,7 @@ var OllamaEmbeddingModel = class {
|
|
|
54915
57100
|
values
|
|
54916
57101
|
});
|
|
54917
57102
|
}
|
|
54918
|
-
const ollamaOptions = await
|
|
57103
|
+
const ollamaOptions = await parseProviderOptions2({
|
|
54919
57104
|
provider: "ollama",
|
|
54920
57105
|
providerOptions,
|
|
54921
57106
|
schema: ollamaEmbeddingProviderOptions
|
|
@@ -54937,15 +57122,15 @@ var OllamaEmbeddingModel = class {
|
|
|
54937
57122
|
responseHeaders,
|
|
54938
57123
|
value: response,
|
|
54939
57124
|
rawValue
|
|
54940
|
-
} = await
|
|
57125
|
+
} = await postJsonToApi2({
|
|
54941
57126
|
url: this.config.url({
|
|
54942
57127
|
path: "/embed",
|
|
54943
57128
|
modelId: this.modelId
|
|
54944
57129
|
}),
|
|
54945
|
-
headers:
|
|
57130
|
+
headers: combineHeaders2(this.config.headers(), headers),
|
|
54946
57131
|
body: { ...body },
|
|
54947
57132
|
failedResponseHandler: ollamaFailedResponseHandler,
|
|
54948
|
-
successfulResponseHandler:
|
|
57133
|
+
successfulResponseHandler: createJsonResponseHandler2(ollamaTextEmbeddingResponseSchema),
|
|
54949
57134
|
abortSignal,
|
|
54950
57135
|
fetch: this.config.fetch
|
|
54951
57136
|
});
|
|
@@ -55027,7 +57212,7 @@ var OllamaResponseProcessor = class {
|
|
|
55027
57212
|
for (const toolCall of (_a16 = response.message.tool_calls) != null ? _a16 : []) {
|
|
55028
57213
|
content.push({
|
|
55029
57214
|
type: "tool-call",
|
|
55030
|
-
toolCallId: (_e = toolCall.id) != null ? _e : (_d = (_c = (_b16 = this.config).generateId) == null ? undefined : _c.call(_b16)) != null ? _d :
|
|
57215
|
+
toolCallId: (_e = toolCall.id) != null ? _e : (_d = (_c = (_b16 = this.config).generateId) == null ? undefined : _c.call(_b16)) != null ? _d : generateId2(),
|
|
55031
57216
|
toolName: toolCall.function.name,
|
|
55032
57217
|
input: JSON.stringify(toolCall.function.arguments)
|
|
55033
57218
|
});
|
|
@@ -55476,7 +57661,7 @@ var OllamaRequestBuilder = class {
|
|
|
55476
57661
|
return warnings;
|
|
55477
57662
|
}
|
|
55478
57663
|
async parseProviderOptions(providerOptions) {
|
|
55479
|
-
const result = await
|
|
57664
|
+
const result = await parseProviderOptions2({
|
|
55480
57665
|
provider: "ollama",
|
|
55481
57666
|
providerOptions,
|
|
55482
57667
|
schema: ollamaProviderOptions
|
|
@@ -55552,8 +57737,8 @@ var OllamaStreamProcessor = class {
|
|
|
55552
57737
|
hasReasoningStarted: false,
|
|
55553
57738
|
textEnded: false,
|
|
55554
57739
|
reasoningEnded: false,
|
|
55555
|
-
textId:
|
|
55556
|
-
reasoningId:
|
|
57740
|
+
textId: generateId2(),
|
|
57741
|
+
reasoningId: generateId2()
|
|
55557
57742
|
};
|
|
55558
57743
|
}
|
|
55559
57744
|
processChunk(chunk, controller, options) {
|
|
@@ -55664,7 +57849,7 @@ var OllamaStreamProcessor = class {
|
|
|
55664
57849
|
}
|
|
55665
57850
|
emitToolCall(toolCall, controller) {
|
|
55666
57851
|
var _a16, _b16, _c, _d;
|
|
55667
|
-
const id = (_d = toolCall.id) != null ? _d : (_c = (_b16 = (_a16 = this.config).generateId) == null ? undefined : _b16.call(_a16)) != null ? _c :
|
|
57852
|
+
const id = (_d = toolCall.id) != null ? _d : (_c = (_b16 = (_a16 = this.config).generateId) == null ? undefined : _b16.call(_a16)) != null ? _c : generateId2();
|
|
55668
57853
|
controller.enqueue({
|
|
55669
57854
|
type: "tool-input-start",
|
|
55670
57855
|
id,
|
|
@@ -55729,15 +57914,15 @@ var OllamaResponsesLanguageModel = class {
|
|
|
55729
57914
|
responseHeaders,
|
|
55730
57915
|
value: response,
|
|
55731
57916
|
rawValue: rawResponse
|
|
55732
|
-
} = await
|
|
57917
|
+
} = await postJsonToApi2({
|
|
55733
57918
|
url: this.config.url({
|
|
55734
57919
|
path: "/chat",
|
|
55735
57920
|
modelId: this.modelId
|
|
55736
57921
|
}),
|
|
55737
|
-
headers:
|
|
57922
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
55738
57923
|
body: { ...body, stream: false },
|
|
55739
57924
|
failedResponseHandler: ollamaFailedResponseHandler,
|
|
55740
|
-
successfulResponseHandler:
|
|
57925
|
+
successfulResponseHandler: createJsonResponseHandler2(baseOllamaResponseSchema2),
|
|
55741
57926
|
abortSignal: options.abortSignal,
|
|
55742
57927
|
fetch: this.config.fetch
|
|
55743
57928
|
});
|
|
@@ -55756,12 +57941,12 @@ var OllamaResponsesLanguageModel = class {
|
|
|
55756
57941
|
}
|
|
55757
57942
|
async doStream(options) {
|
|
55758
57943
|
const { args: body, warnings } = await this.prepareRequest(options);
|
|
55759
|
-
const { responseHeaders, value: response } = await
|
|
57944
|
+
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
55760
57945
|
url: this.config.url({
|
|
55761
57946
|
path: "/chat",
|
|
55762
57947
|
modelId: this.modelId
|
|
55763
57948
|
}),
|
|
55764
|
-
headers:
|
|
57949
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
55765
57950
|
body: { ...body, stream: true },
|
|
55766
57951
|
failedResponseHandler: ollamaFailedResponseHandler,
|
|
55767
57952
|
successfulResponseHandler: createNdjsonStreamResponseHandler(baseOllamaResponseSchema2),
|
|
@@ -55785,7 +57970,7 @@ var OllamaResponsesLanguageModel = class {
|
|
|
55785
57970
|
};
|
|
55786
57971
|
function createOllama(options = {}) {
|
|
55787
57972
|
var _a16, _b16;
|
|
55788
|
-
const baseURL = (_a16 =
|
|
57973
|
+
const baseURL = (_a16 = withoutTrailingSlash2(options.baseURL)) != null ? _a16 : "http://127.0.0.1:11434/api";
|
|
55789
57974
|
const providerName = (_b16 = options.name) != null ? _b16 : "ollama";
|
|
55790
57975
|
const getHeaders = () => ({
|
|
55791
57976
|
"Ollama-Organization": options.organization,
|
|
@@ -55918,6 +58103,9 @@ function convertOpenAIChatUsage2(usage) {
|
|
|
55918
58103
|
raw: usage
|
|
55919
58104
|
};
|
|
55920
58105
|
}
|
|
58106
|
+
function serializeToolCallArguments3(input) {
|
|
58107
|
+
return JSON.stringify(input === undefined ? {} : input);
|
|
58108
|
+
}
|
|
55921
58109
|
function convertToOpenAIChatMessages2({
|
|
55922
58110
|
prompt,
|
|
55923
58111
|
systemMessageMode = "system"
|
|
@@ -56045,7 +58233,7 @@ function convertToOpenAIChatMessages2({
|
|
|
56045
58233
|
type: "function",
|
|
56046
58234
|
function: {
|
|
56047
58235
|
name: part.toolName,
|
|
56048
|
-
arguments:
|
|
58236
|
+
arguments: serializeToolCallArguments3(part.input)
|
|
56049
58237
|
}
|
|
56050
58238
|
});
|
|
56051
58239
|
break;
|
|
@@ -57863,6 +60051,9 @@ function convertOpenAIResponsesUsage2(usage) {
|
|
|
57863
60051
|
raw: usage
|
|
57864
60052
|
};
|
|
57865
60053
|
}
|
|
60054
|
+
function serializeToolCallArguments22(input) {
|
|
60055
|
+
return JSON.stringify(input === undefined ? {} : input);
|
|
60056
|
+
}
|
|
57866
60057
|
function isFileId2(data, prefixes) {
|
|
57867
60058
|
if (!prefixes)
|
|
57868
60059
|
return false;
|
|
@@ -58083,7 +60274,7 @@ async function convertToOpenAIResponsesInput2({
|
|
|
58083
60274
|
type: "function_call",
|
|
58084
60275
|
call_id: part.toolCallId,
|
|
58085
60276
|
name: resolvedToolName,
|
|
58086
|
-
arguments:
|
|
60277
|
+
arguments: serializeToolCallArguments22(part.input),
|
|
58087
60278
|
id
|
|
58088
60279
|
});
|
|
58089
60280
|
break;
|
|
@@ -59484,8 +61675,8 @@ async function prepareResponsesTools3({
|
|
|
59484
61675
|
value: tool2.args,
|
|
59485
61676
|
schema: mcpArgsSchema2
|
|
59486
61677
|
});
|
|
59487
|
-
const mapApprovalFilter = (
|
|
59488
|
-
tool_names:
|
|
61678
|
+
const mapApprovalFilter = (filter3) => ({
|
|
61679
|
+
tool_names: filter3.toolNames
|
|
59489
61680
|
});
|
|
59490
61681
|
const requireApproval = args.requireApproval;
|
|
59491
61682
|
const requireApprovalParam = requireApproval == null ? undefined : typeof requireApproval === "string" ? requireApproval : requireApproval.never != null ? { never: mapApprovalFilter(requireApproval.never) } : undefined;
|
|
@@ -61546,7 +63737,7 @@ var OpenAITranscriptionModel2 = class {
|
|
|
61546
63737
|
};
|
|
61547
63738
|
}
|
|
61548
63739
|
};
|
|
61549
|
-
var
|
|
63740
|
+
var VERSION9 = "3.0.53";
|
|
61550
63741
|
function createOpenAI(options = {}) {
|
|
61551
63742
|
var _a16, _b16;
|
|
61552
63743
|
const baseURL = (_a16 = withoutTrailingSlash(loadOptionalSetting({
|
|
@@ -61563,7 +63754,7 @@ function createOpenAI(options = {}) {
|
|
|
61563
63754
|
"OpenAI-Organization": options.organization,
|
|
61564
63755
|
"OpenAI-Project": options.project,
|
|
61565
63756
|
...options.headers
|
|
61566
|
-
}, `ai-sdk/openai/${
|
|
63757
|
+
}, `ai-sdk/openai/${VERSION9}`);
|
|
61567
63758
|
const createChatModel = (modelId) => new OpenAIChatLanguageModel2(modelId, {
|
|
61568
63759
|
provider: `${providerName}.chat`,
|
|
61569
63760
|
url: ({ path: path2 }) => `${baseURL}${path2}`,
|
|
@@ -61648,6 +63839,16 @@ function createOpenAIProvider(config2, providerName) {
|
|
|
61648
63839
|
}
|
|
61649
63840
|
|
|
61650
63841
|
// node_modules/@ai-sdk/openai-compatible/dist/index.mjs
|
|
63842
|
+
function toCamelCase(str) {
|
|
63843
|
+
return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
|
|
63844
|
+
}
|
|
63845
|
+
function resolveProviderOptionsKey(rawName, providerOptions) {
|
|
63846
|
+
const camelName = toCamelCase(rawName);
|
|
63847
|
+
if (camelName !== rawName && (providerOptions == null ? undefined : providerOptions[camelName]) != null) {
|
|
63848
|
+
return camelName;
|
|
63849
|
+
}
|
|
63850
|
+
return rawName;
|
|
63851
|
+
}
|
|
61651
63852
|
var openaiCompatibleErrorDataSchema = exports_external.object({
|
|
61652
63853
|
error: exports_external.object({
|
|
61653
63854
|
message: exports_external.string(),
|
|
@@ -62037,8 +64238,12 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
62037
64238
|
provider: this.providerOptionsName,
|
|
62038
64239
|
providerOptions,
|
|
62039
64240
|
schema: openaiCompatibleLanguageModelChatOptions
|
|
62040
|
-
})) != null ? _b16 : {}
|
|
62041
|
-
|
|
64241
|
+
})) != null ? _b16 : {}, (_c = await parseProviderOptions({
|
|
64242
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
64243
|
+
providerOptions,
|
|
64244
|
+
schema: openaiCompatibleLanguageModelChatOptions
|
|
64245
|
+
})) != null ? _c : {});
|
|
64246
|
+
const strictJsonSchema = (_d = compatibleOptions == null ? undefined : compatibleOptions.strictJsonSchema) != null ? _d : true;
|
|
62042
64247
|
if (topK != null) {
|
|
62043
64248
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
62044
64249
|
}
|
|
@@ -62057,7 +64262,9 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
62057
64262
|
tools,
|
|
62058
64263
|
toolChoice
|
|
62059
64264
|
});
|
|
64265
|
+
const metadataKey = resolveProviderOptionsKey(this.providerOptionsName, providerOptions);
|
|
62060
64266
|
return {
|
|
64267
|
+
metadataKey,
|
|
62061
64268
|
args: {
|
|
62062
64269
|
model: this.modelId,
|
|
62063
64270
|
user: compatibleOptions.user,
|
|
@@ -62071,13 +64278,16 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
62071
64278
|
json_schema: {
|
|
62072
64279
|
schema: responseFormat.schema,
|
|
62073
64280
|
strict: strictJsonSchema,
|
|
62074
|
-
name: (
|
|
64281
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
62075
64282
|
description: responseFormat.description
|
|
62076
64283
|
}
|
|
62077
64284
|
} : { type: "json_object" } : undefined,
|
|
62078
64285
|
stop: stopSequences,
|
|
62079
64286
|
seed,
|
|
62080
|
-
...Object.fromEntries(Object.entries(
|
|
64287
|
+
...Object.fromEntries(Object.entries({
|
|
64288
|
+
...providerOptions == null ? undefined : providerOptions[this.providerOptionsName],
|
|
64289
|
+
...providerOptions == null ? undefined : providerOptions[toCamelCase(this.providerOptionsName)]
|
|
64290
|
+
}).filter(([key]) => !Object.keys(openaiCompatibleLanguageModelChatOptions.shape).includes(key))),
|
|
62081
64291
|
reasoning_effort: compatibleOptions.reasoningEffort,
|
|
62082
64292
|
verbosity: compatibleOptions.textVerbosity,
|
|
62083
64293
|
messages: convertToOpenAICompatibleChatMessages(prompt),
|
|
@@ -62089,7 +64299,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
62089
64299
|
}
|
|
62090
64300
|
async doGenerate(options) {
|
|
62091
64301
|
var _a16, _b16, _c, _d, _e, _f, _g, _h;
|
|
62092
|
-
const { args, warnings } = await this.getArgs({ ...options });
|
|
64302
|
+
const { args, warnings, metadataKey } = await this.getArgs({ ...options });
|
|
62093
64303
|
const transformedBody = this.transformRequestBody(args);
|
|
62094
64304
|
const body = JSON.stringify(transformedBody);
|
|
62095
64305
|
const {
|
|
@@ -62131,24 +64341,24 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
62131
64341
|
input: toolCall.function.arguments,
|
|
62132
64342
|
...thoughtSignature ? {
|
|
62133
64343
|
providerMetadata: {
|
|
62134
|
-
[
|
|
64344
|
+
[metadataKey]: { thoughtSignature }
|
|
62135
64345
|
}
|
|
62136
64346
|
} : {}
|
|
62137
64347
|
});
|
|
62138
64348
|
}
|
|
62139
64349
|
}
|
|
62140
64350
|
const providerMetadata = {
|
|
62141
|
-
[
|
|
64351
|
+
[metadataKey]: {},
|
|
62142
64352
|
...await ((_f = (_e = this.config.metadataExtractor) == null ? undefined : _e.extractMetadata) == null ? undefined : _f.call(_e, {
|
|
62143
64353
|
parsedBody: rawResponse
|
|
62144
64354
|
}))
|
|
62145
64355
|
};
|
|
62146
64356
|
const completionTokenDetails = (_g = responseBody.usage) == null ? undefined : _g.completion_tokens_details;
|
|
62147
64357
|
if ((completionTokenDetails == null ? undefined : completionTokenDetails.accepted_prediction_tokens) != null) {
|
|
62148
|
-
providerMetadata[
|
|
64358
|
+
providerMetadata[metadataKey].acceptedPredictionTokens = completionTokenDetails == null ? undefined : completionTokenDetails.accepted_prediction_tokens;
|
|
62149
64359
|
}
|
|
62150
64360
|
if ((completionTokenDetails == null ? undefined : completionTokenDetails.rejected_prediction_tokens) != null) {
|
|
62151
|
-
providerMetadata[
|
|
64361
|
+
providerMetadata[metadataKey].rejectedPredictionTokens = completionTokenDetails == null ? undefined : completionTokenDetails.rejected_prediction_tokens;
|
|
62152
64362
|
}
|
|
62153
64363
|
return {
|
|
62154
64364
|
content,
|
|
@@ -62169,7 +64379,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
62169
64379
|
}
|
|
62170
64380
|
async doStream(options) {
|
|
62171
64381
|
var _a16;
|
|
62172
|
-
const { args, warnings } = await this.getArgs({ ...options });
|
|
64382
|
+
const { args, warnings, metadataKey } = await this.getArgs({ ...options });
|
|
62173
64383
|
const body = this.transformRequestBody({
|
|
62174
64384
|
...args,
|
|
62175
64385
|
stream: true,
|
|
@@ -62195,7 +64405,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
62195
64405
|
};
|
|
62196
64406
|
let usage = undefined;
|
|
62197
64407
|
let isFirstChunk = true;
|
|
62198
|
-
const providerOptionsName =
|
|
64408
|
+
const providerOptionsName = metadataKey;
|
|
62199
64409
|
let isActiveReasoning = false;
|
|
62200
64410
|
let isActiveText = false;
|
|
62201
64411
|
return {
|
|
@@ -62675,13 +64885,17 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
62675
64885
|
tools,
|
|
62676
64886
|
toolChoice
|
|
62677
64887
|
}) {
|
|
62678
|
-
var _a16;
|
|
64888
|
+
var _a16, _b16;
|
|
62679
64889
|
const warnings = [];
|
|
62680
|
-
const completionOptions = (_a16 = await parseProviderOptions({
|
|
64890
|
+
const completionOptions = Object.assign((_a16 = await parseProviderOptions({
|
|
62681
64891
|
provider: this.providerOptionsName,
|
|
62682
64892
|
providerOptions,
|
|
62683
64893
|
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
62684
|
-
})) != null ? _a16 : {}
|
|
64894
|
+
})) != null ? _a16 : {}, (_b16 = await parseProviderOptions({
|
|
64895
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
64896
|
+
providerOptions,
|
|
64897
|
+
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
64898
|
+
})) != null ? _b16 : {});
|
|
62685
64899
|
if (topK != null) {
|
|
62686
64900
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
62687
64901
|
}
|
|
@@ -62714,6 +64928,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
62714
64928
|
presence_penalty: presencePenalty,
|
|
62715
64929
|
seed,
|
|
62716
64930
|
...providerOptions == null ? undefined : providerOptions[this.providerOptionsName],
|
|
64931
|
+
...providerOptions == null ? undefined : providerOptions[toCamelCase(this.providerOptionsName)],
|
|
62717
64932
|
prompt: completionPrompt,
|
|
62718
64933
|
stop: stop.length > 0 ? stop : undefined
|
|
62719
64934
|
},
|
|
@@ -63091,10 +65306,7 @@ async function fileToBlob3(file2) {
|
|
|
63091
65306
|
const data = file2.data instanceof Uint8Array ? file2.data : convertBase64ToUint8Array(file2.data);
|
|
63092
65307
|
return new Blob([data], { type: file2.mediaType });
|
|
63093
65308
|
}
|
|
63094
|
-
|
|
63095
|
-
return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
|
|
63096
|
-
}
|
|
63097
|
-
var VERSION9 = "2.0.37";
|
|
65309
|
+
var VERSION10 = "2.0.41";
|
|
63098
65310
|
function createOpenAICompatible(options) {
|
|
63099
65311
|
const baseURL = withoutTrailingSlash(options.baseURL);
|
|
63100
65312
|
const providerName = options.name;
|
|
@@ -63102,7 +65314,7 @@ function createOpenAICompatible(options) {
|
|
|
63102
65314
|
...options.apiKey && { Authorization: `Bearer ${options.apiKey}` },
|
|
63103
65315
|
...options.headers
|
|
63104
65316
|
};
|
|
63105
|
-
const getHeaders = () => withUserAgentSuffix(headers, `ai-sdk/openai-compatible/${
|
|
65317
|
+
const getHeaders = () => withUserAgentSuffix(headers, `ai-sdk/openai-compatible/${VERSION10}`);
|
|
63106
65318
|
const getCommonModelConfig = (modelType) => ({
|
|
63107
65319
|
provider: `${providerName}.${modelType}`,
|
|
63108
65320
|
url: ({ path: path2 }) => {
|
|
@@ -63330,11 +65542,11 @@ function listProviders(config2) {
|
|
|
63330
65542
|
// node_modules/@ai-sdk/gateway/dist/index.mjs
|
|
63331
65543
|
var import_oidc = __toESM(require_dist(), 1);
|
|
63332
65544
|
var import_oidc2 = __toESM(require_dist(), 1);
|
|
63333
|
-
var
|
|
63334
|
-
var
|
|
63335
|
-
var
|
|
63336
|
-
var
|
|
63337
|
-
var GatewayError = class _GatewayError extends (
|
|
65545
|
+
var marker18 = "vercel.ai.gateway.error";
|
|
65546
|
+
var symbol18 = Symbol.for(marker18);
|
|
65547
|
+
var _a18;
|
|
65548
|
+
var _b18;
|
|
65549
|
+
var GatewayError = class _GatewayError extends (_b18 = Error, _a18 = symbol18, _b18) {
|
|
63338
65550
|
constructor({
|
|
63339
65551
|
message,
|
|
63340
65552
|
statusCode = 500,
|
|
@@ -63342,7 +65554,7 @@ var GatewayError = class _GatewayError extends (_b17 = Error, _a17 = symbol17, _
|
|
|
63342
65554
|
generationId
|
|
63343
65555
|
}) {
|
|
63344
65556
|
super(generationId ? `${message} [${generationId}]` : message);
|
|
63345
|
-
this[
|
|
65557
|
+
this[_a18] = true;
|
|
63346
65558
|
this.statusCode = statusCode;
|
|
63347
65559
|
this.cause = cause;
|
|
63348
65560
|
this.generationId = generationId;
|
|
@@ -63351,11 +65563,11 @@ var GatewayError = class _GatewayError extends (_b17 = Error, _a17 = symbol17, _
|
|
|
63351
65563
|
return _GatewayError.hasMarker(error48);
|
|
63352
65564
|
}
|
|
63353
65565
|
static hasMarker(error48) {
|
|
63354
|
-
return typeof error48 === "object" && error48 !== null &&
|
|
65566
|
+
return typeof error48 === "object" && error48 !== null && symbol18 in error48 && error48[symbol18] === true;
|
|
63355
65567
|
}
|
|
63356
65568
|
};
|
|
63357
|
-
var
|
|
63358
|
-
var marker22 = `vercel.ai.gateway.error.${
|
|
65569
|
+
var name17 = "GatewayAuthenticationError";
|
|
65570
|
+
var marker22 = `vercel.ai.gateway.error.${name17}`;
|
|
63359
65571
|
var symbol23 = Symbol.for(marker22);
|
|
63360
65572
|
var _a23;
|
|
63361
65573
|
var _b22;
|
|
@@ -63368,7 +65580,7 @@ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b22
|
|
|
63368
65580
|
} = {}) {
|
|
63369
65581
|
super({ message, statusCode, cause, generationId });
|
|
63370
65582
|
this[_a23] = true;
|
|
63371
|
-
this.name =
|
|
65583
|
+
this.name = name17;
|
|
63372
65584
|
this.type = "authentication_error";
|
|
63373
65585
|
}
|
|
63374
65586
|
static isInstance(error48) {
|
|
@@ -63723,6 +65935,13 @@ async function parseAuthMethod(headers) {
|
|
|
63723
65935
|
return result.success ? result.value : undefined;
|
|
63724
65936
|
}
|
|
63725
65937
|
var gatewayAuthMethodSchema = lazySchema(() => zodSchema(exports_external.union([exports_external.literal("api-key"), exports_external.literal("oidc")])));
|
|
65938
|
+
var KNOWN_MODEL_TYPES = [
|
|
65939
|
+
"embedding",
|
|
65940
|
+
"image",
|
|
65941
|
+
"language",
|
|
65942
|
+
"reranking",
|
|
65943
|
+
"video"
|
|
65944
|
+
];
|
|
63726
65945
|
var GatewayFetchMetadata = class {
|
|
63727
65946
|
constructor(config2) {
|
|
63728
65947
|
this.config = config2;
|
|
@@ -63784,8 +66003,8 @@ var gatewayAvailableModelsResponseSchema = lazySchema(() => zodSchema(exports_ex
|
|
|
63784
66003
|
provider: exports_external.string(),
|
|
63785
66004
|
modelId: exports_external.string()
|
|
63786
66005
|
}),
|
|
63787
|
-
modelType: exports_external.
|
|
63788
|
-
}))
|
|
66006
|
+
modelType: exports_external.string().nullish()
|
|
66007
|
+
})).transform((models) => models.filter((m) => m.modelType == null || KNOWN_MODEL_TYPES.includes(m.modelType)))
|
|
63789
66008
|
})));
|
|
63790
66009
|
var gatewayCreditsResponseSchema = lazySchema(() => zodSchema(exports_external.object({
|
|
63791
66010
|
balance: exports_external.string(),
|
|
@@ -64457,6 +66676,73 @@ var gatewayVideoEventSchema = exports_external.discriminatedUnion("type", [
|
|
|
64457
66676
|
param: exports_external.unknown().nullable()
|
|
64458
66677
|
})
|
|
64459
66678
|
]);
|
|
66679
|
+
var GatewayRerankingModel = class {
|
|
66680
|
+
constructor(modelId, config2) {
|
|
66681
|
+
this.modelId = modelId;
|
|
66682
|
+
this.config = config2;
|
|
66683
|
+
this.specificationVersion = "v3";
|
|
66684
|
+
}
|
|
66685
|
+
get provider() {
|
|
66686
|
+
return this.config.provider;
|
|
66687
|
+
}
|
|
66688
|
+
async doRerank({
|
|
66689
|
+
documents,
|
|
66690
|
+
query,
|
|
66691
|
+
topN,
|
|
66692
|
+
headers,
|
|
66693
|
+
abortSignal,
|
|
66694
|
+
providerOptions
|
|
66695
|
+
}) {
|
|
66696
|
+
const resolvedHeaders = await resolve(this.config.headers());
|
|
66697
|
+
try {
|
|
66698
|
+
const {
|
|
66699
|
+
responseHeaders,
|
|
66700
|
+
value: responseBody,
|
|
66701
|
+
rawValue
|
|
66702
|
+
} = await postJsonToApi({
|
|
66703
|
+
url: this.getUrl(),
|
|
66704
|
+
headers: combineHeaders(resolvedHeaders, headers != null ? headers : {}, this.getModelConfigHeaders(), await resolve(this.config.o11yHeaders)),
|
|
66705
|
+
body: {
|
|
66706
|
+
documents,
|
|
66707
|
+
query,
|
|
66708
|
+
...topN != null ? { topN } : {},
|
|
66709
|
+
...providerOptions ? { providerOptions } : {}
|
|
66710
|
+
},
|
|
66711
|
+
successfulResponseHandler: createJsonResponseHandler(gatewayRerankingResponseSchema),
|
|
66712
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
66713
|
+
errorSchema: exports_external.any(),
|
|
66714
|
+
errorToMessage: (data) => data
|
|
66715
|
+
}),
|
|
66716
|
+
...abortSignal && { abortSignal },
|
|
66717
|
+
fetch: this.config.fetch
|
|
66718
|
+
});
|
|
66719
|
+
return {
|
|
66720
|
+
ranking: responseBody.ranking,
|
|
66721
|
+
providerMetadata: responseBody.providerMetadata,
|
|
66722
|
+
response: { headers: responseHeaders, body: rawValue },
|
|
66723
|
+
warnings: []
|
|
66724
|
+
};
|
|
66725
|
+
} catch (error48) {
|
|
66726
|
+
throw await asGatewayError(error48, await parseAuthMethod(resolvedHeaders));
|
|
66727
|
+
}
|
|
66728
|
+
}
|
|
66729
|
+
getUrl() {
|
|
66730
|
+
return `${this.config.baseURL}/reranking-model`;
|
|
66731
|
+
}
|
|
66732
|
+
getModelConfigHeaders() {
|
|
66733
|
+
return {
|
|
66734
|
+
"ai-reranking-model-specification-version": "3",
|
|
66735
|
+
"ai-model-id": this.modelId
|
|
66736
|
+
};
|
|
66737
|
+
}
|
|
66738
|
+
};
|
|
66739
|
+
var gatewayRerankingResponseSchema = lazySchema(() => zodSchema(exports_external.object({
|
|
66740
|
+
ranking: exports_external.array(exports_external.object({
|
|
66741
|
+
index: exports_external.number(),
|
|
66742
|
+
relevanceScore: exports_external.number()
|
|
66743
|
+
})),
|
|
66744
|
+
providerMetadata: exports_external.record(exports_external.string(), exports_external.record(exports_external.string(), exports_external.unknown())).optional()
|
|
66745
|
+
})));
|
|
64460
66746
|
var parallelSearchInputSchema = lazySchema(() => zodSchema(exports_external.object({
|
|
64461
66747
|
objective: exports_external.string().describe("Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."),
|
|
64462
66748
|
search_queries: exports_external.array(exports_external.string()).optional().describe("Optional search queries to supplement the objective. Maximum 200 characters per query."),
|
|
@@ -64556,7 +66842,7 @@ async function getVercelRequestId() {
|
|
|
64556
66842
|
var _a92;
|
|
64557
66843
|
return (_a92 = import_oidc.getContext().headers) == null ? undefined : _a92["x-vercel-id"];
|
|
64558
66844
|
}
|
|
64559
|
-
var
|
|
66845
|
+
var VERSION11 = "3.0.104";
|
|
64560
66846
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
64561
66847
|
function createGatewayProvider(options = {}) {
|
|
64562
66848
|
var _a92, _b92;
|
|
@@ -64573,7 +66859,7 @@ function createGatewayProvider(options = {}) {
|
|
|
64573
66859
|
"ai-gateway-protocol-version": AI_GATEWAY_PROTOCOL_VERSION,
|
|
64574
66860
|
[GATEWAY_AUTH_METHOD_HEADER]: auth.authMethod,
|
|
64575
66861
|
...options.headers
|
|
64576
|
-
}, `ai-sdk/gateway/${
|
|
66862
|
+
}, `ai-sdk/gateway/${VERSION11}`);
|
|
64577
66863
|
} catch (error48) {
|
|
64578
66864
|
throw GatewayAuthenticationError.createContextualError({
|
|
64579
66865
|
apiKeyProvided: false,
|
|
@@ -64706,6 +66992,17 @@ function createGatewayProvider(options = {}) {
|
|
|
64706
66992
|
o11yHeaders: createO11yHeaders()
|
|
64707
66993
|
});
|
|
64708
66994
|
};
|
|
66995
|
+
const createRerankingModel = (modelId) => {
|
|
66996
|
+
return new GatewayRerankingModel(modelId, {
|
|
66997
|
+
provider: "gateway",
|
|
66998
|
+
baseURL,
|
|
66999
|
+
headers: getHeaders,
|
|
67000
|
+
fetch: options.fetch,
|
|
67001
|
+
o11yHeaders: createO11yHeaders()
|
|
67002
|
+
});
|
|
67003
|
+
};
|
|
67004
|
+
provider.rerankingModel = createRerankingModel;
|
|
67005
|
+
provider.reranking = createRerankingModel;
|
|
64709
67006
|
provider.chat = provider.languageModel;
|
|
64710
67007
|
provider.embedding = provider.embeddingModel;
|
|
64711
67008
|
provider.image = provider.imageModel;
|
|
@@ -64740,10 +67037,10 @@ var __export2 = (target, all) => {
|
|
|
64740
67037
|
for (var name21 in all)
|
|
64741
67038
|
__defProp2(target, name21, { get: all[name21], enumerable: true });
|
|
64742
67039
|
};
|
|
64743
|
-
var
|
|
64744
|
-
var
|
|
64745
|
-
var
|
|
64746
|
-
var
|
|
67040
|
+
var name18 = "AI_InvalidArgumentError";
|
|
67041
|
+
var marker19 = `vercel.ai.error.${name18}`;
|
|
67042
|
+
var symbol19 = Symbol.for(marker19);
|
|
67043
|
+
var _a19;
|
|
64747
67044
|
var InvalidArgumentError2 = class extends AISDKError {
|
|
64748
67045
|
constructor({
|
|
64749
67046
|
parameter,
|
|
@@ -64751,18 +67048,18 @@ var InvalidArgumentError2 = class extends AISDKError {
|
|
|
64751
67048
|
message
|
|
64752
67049
|
}) {
|
|
64753
67050
|
super({
|
|
64754
|
-
name:
|
|
67051
|
+
name: name18,
|
|
64755
67052
|
message: `Invalid argument for parameter ${parameter}: ${message}`
|
|
64756
67053
|
});
|
|
64757
|
-
this[
|
|
67054
|
+
this[_a19] = true;
|
|
64758
67055
|
this.parameter = parameter;
|
|
64759
67056
|
this.value = value;
|
|
64760
67057
|
}
|
|
64761
67058
|
static isInstance(error48) {
|
|
64762
|
-
return AISDKError.hasMarker(error48,
|
|
67059
|
+
return AISDKError.hasMarker(error48, marker19);
|
|
64763
67060
|
}
|
|
64764
67061
|
};
|
|
64765
|
-
|
|
67062
|
+
_a19 = symbol19;
|
|
64766
67063
|
var name23 = "AI_InvalidStreamPartError";
|
|
64767
67064
|
var marker23 = `vercel.ai.error.${name23}`;
|
|
64768
67065
|
var symbol24 = Symbol.for(marker23);
|
|
@@ -65002,15 +67299,15 @@ var InvalidMessageRoleError = class extends AISDKError {
|
|
|
65002
67299
|
}
|
|
65003
67300
|
};
|
|
65004
67301
|
_a172 = symbol172;
|
|
65005
|
-
var
|
|
65006
|
-
var marker182 = `vercel.ai.error.${
|
|
67302
|
+
var name182 = "AI_MessageConversionError";
|
|
67303
|
+
var marker182 = `vercel.ai.error.${name182}`;
|
|
65007
67304
|
var symbol182 = Symbol.for(marker182);
|
|
65008
67305
|
var _a182;
|
|
65009
67306
|
_a182 = symbol182;
|
|
65010
67307
|
var name19 = "AI_RetryError";
|
|
65011
|
-
var
|
|
65012
|
-
var
|
|
65013
|
-
var
|
|
67308
|
+
var marker192 = `vercel.ai.error.${name19}`;
|
|
67309
|
+
var symbol192 = Symbol.for(marker192);
|
|
67310
|
+
var _a192;
|
|
65014
67311
|
var RetryError = class extends AISDKError {
|
|
65015
67312
|
constructor({
|
|
65016
67313
|
message,
|
|
@@ -65018,16 +67315,16 @@ var RetryError = class extends AISDKError {
|
|
|
65018
67315
|
errors: errors3
|
|
65019
67316
|
}) {
|
|
65020
67317
|
super({ name: name19, message });
|
|
65021
|
-
this[
|
|
67318
|
+
this[_a192] = true;
|
|
65022
67319
|
this.reason = reason;
|
|
65023
67320
|
this.errors = errors3;
|
|
65024
67321
|
this.lastError = errors3[errors3.length - 1];
|
|
65025
67322
|
}
|
|
65026
67323
|
static isInstance(error48) {
|
|
65027
|
-
return AISDKError.hasMarker(error48,
|
|
67324
|
+
return AISDKError.hasMarker(error48, marker192);
|
|
65028
67325
|
}
|
|
65029
67326
|
};
|
|
65030
|
-
|
|
67327
|
+
_a192 = symbol192;
|
|
65031
67328
|
function asArray(value) {
|
|
65032
67329
|
return value === undefined ? [] : Array.isArray(value) ? value : [value];
|
|
65033
67330
|
}
|
|
@@ -65324,7 +67621,7 @@ function detectMediaType({
|
|
|
65324
67621
|
}
|
|
65325
67622
|
return;
|
|
65326
67623
|
}
|
|
65327
|
-
var
|
|
67624
|
+
var VERSION12 = "6.0.168";
|
|
65328
67625
|
var download = async ({
|
|
65329
67626
|
url: url2,
|
|
65330
67627
|
maxBytes,
|
|
@@ -65335,7 +67632,7 @@ var download = async ({
|
|
|
65335
67632
|
validateDownloadUrl(urlText);
|
|
65336
67633
|
try {
|
|
65337
67634
|
const response = await fetch(urlText, {
|
|
65338
|
-
headers: withUserAgentSuffix({}, `ai-sdk/${
|
|
67635
|
+
headers: withUserAgentSuffix({}, `ai-sdk/${VERSION12}`, getRuntimeEnvironmentUserAgent()),
|
|
65339
67636
|
signal: abortSignal
|
|
65340
67637
|
});
|
|
65341
67638
|
if (response.redirected) {
|
|
@@ -67189,9 +69486,9 @@ var object2 = ({
|
|
|
67189
69486
|
const schema = asSchema(inputSchema);
|
|
67190
69487
|
return {
|
|
67191
69488
|
name: "object",
|
|
67192
|
-
responseFormat: resolve(schema.jsonSchema).then((
|
|
69489
|
+
responseFormat: resolve(schema.jsonSchema).then((jsonSchema22) => ({
|
|
67193
69490
|
type: "json",
|
|
67194
|
-
schema:
|
|
69491
|
+
schema: jsonSchema22,
|
|
67195
69492
|
...name21 != null && { name: name21 },
|
|
67196
69493
|
...description != null && { description }
|
|
67197
69494
|
})),
|
|
@@ -67251,8 +69548,8 @@ var array2 = ({
|
|
|
67251
69548
|
const elementSchema = asSchema(inputElementSchema);
|
|
67252
69549
|
return {
|
|
67253
69550
|
name: "array",
|
|
67254
|
-
responseFormat: resolve(elementSchema.jsonSchema).then((
|
|
67255
|
-
const { $schema, ...itemSchema } =
|
|
69551
|
+
responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema22) => {
|
|
69552
|
+
const { $schema, ...itemSchema } = jsonSchema22;
|
|
67256
69553
|
return {
|
|
67257
69554
|
type: "json",
|
|
67258
69555
|
schema: {
|
|
@@ -67714,7 +70011,7 @@ async function toResponseMessages({
|
|
|
67714
70011
|
type: "tool-call",
|
|
67715
70012
|
toolCallId: part.toolCallId,
|
|
67716
70013
|
toolName: part.toolName,
|
|
67717
|
-
input: part.input,
|
|
70014
|
+
input: part.invalid && typeof part.input !== "object" ? {} : part.input,
|
|
67718
70015
|
providerExecuted: part.providerExecuted,
|
|
67719
70016
|
providerOptions: part.providerMetadata
|
|
67720
70017
|
});
|
|
@@ -68918,7 +71215,7 @@ function runToolsTransformation({
|
|
|
68918
71215
|
abortSignal,
|
|
68919
71216
|
repairToolCall,
|
|
68920
71217
|
experimental_context,
|
|
68921
|
-
generateId:
|
|
71218
|
+
generateId: generateId22,
|
|
68922
71219
|
stepNumber,
|
|
68923
71220
|
model,
|
|
68924
71221
|
onToolCallStart,
|
|
@@ -69048,14 +71345,14 @@ function runToolsTransformation({
|
|
|
69048
71345
|
})) {
|
|
69049
71346
|
toolResultsStreamController.enqueue({
|
|
69050
71347
|
type: "tool-approval-request",
|
|
69051
|
-
approvalId:
|
|
71348
|
+
approvalId: generateId22(),
|
|
69052
71349
|
toolCall
|
|
69053
71350
|
});
|
|
69054
71351
|
break;
|
|
69055
71352
|
}
|
|
69056
71353
|
toolInputs.set(toolCall.toolCallId, toolCall.input);
|
|
69057
71354
|
if (tool2.execute != null && toolCall.providerExecuted !== true) {
|
|
69058
|
-
const toolExecutionId =
|
|
71355
|
+
const toolExecutionId = generateId22();
|
|
69059
71356
|
outstandingToolResults.add(toolExecutionId);
|
|
69060
71357
|
executeToolCall({
|
|
69061
71358
|
toolCall,
|
|
@@ -69188,7 +71485,7 @@ function streamText({
|
|
|
69188
71485
|
experimental_onToolCallFinish: onToolCallFinish,
|
|
69189
71486
|
experimental_context,
|
|
69190
71487
|
experimental_include: include,
|
|
69191
|
-
_internal: { now: now2 = now, generateId:
|
|
71488
|
+
_internal: { now: now2 = now, generateId: generateId22 = originalGenerateId2 } = {},
|
|
69192
71489
|
...settings
|
|
69193
71490
|
}) {
|
|
69194
71491
|
const totalTimeoutMs = getTotalTimeoutMs(timeout);
|
|
@@ -69233,7 +71530,7 @@ function streamText({
|
|
|
69233
71530
|
onToolCallStart,
|
|
69234
71531
|
onToolCallFinish,
|
|
69235
71532
|
now: now2,
|
|
69236
|
-
generateId:
|
|
71533
|
+
generateId: generateId22,
|
|
69237
71534
|
experimental_context,
|
|
69238
71535
|
download: download2,
|
|
69239
71536
|
include
|
|
@@ -69244,7 +71541,7 @@ function createOutputTransformStream(output) {
|
|
|
69244
71541
|
let text2 = "";
|
|
69245
71542
|
let textChunk = "";
|
|
69246
71543
|
let textProviderMetadata = undefined;
|
|
69247
|
-
let
|
|
71544
|
+
let lastPublishedValue = "";
|
|
69248
71545
|
function publishTextChunk({
|
|
69249
71546
|
controller,
|
|
69250
71547
|
partialOutput = undefined
|
|
@@ -69292,10 +71589,10 @@ function createOutputTransformStream(output) {
|
|
|
69292
71589
|
textProviderMetadata = (_a21 = chunk.providerMetadata) != null ? _a21 : textProviderMetadata;
|
|
69293
71590
|
const result = await output.parsePartialOutput({ text: text2 });
|
|
69294
71591
|
if (result !== undefined) {
|
|
69295
|
-
const
|
|
69296
|
-
if (
|
|
71592
|
+
const currentValue = typeof result.partial === "string" ? result.partial : JSON.stringify(result.partial);
|
|
71593
|
+
if (currentValue !== lastPublishedValue) {
|
|
69297
71594
|
publishTextChunk({ controller, partialOutput: result.partial });
|
|
69298
|
-
|
|
71595
|
+
lastPublishedValue = currentValue;
|
|
69299
71596
|
}
|
|
69300
71597
|
}
|
|
69301
71598
|
}
|
|
@@ -69327,7 +71624,7 @@ var DefaultStreamTextResult = class {
|
|
|
69327
71624
|
prepareStep,
|
|
69328
71625
|
includeRawChunks,
|
|
69329
71626
|
now: now2,
|
|
69330
|
-
generateId:
|
|
71627
|
+
generateId: generateId22,
|
|
69331
71628
|
timeout,
|
|
69332
71629
|
stopWhen,
|
|
69333
71630
|
originalAbortSignal,
|
|
@@ -69736,10 +72033,6 @@ var DefaultStreamTextResult = class {
|
|
|
69736
72033
|
const initialResponseMessages = [];
|
|
69737
72034
|
const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
|
|
69738
72035
|
if (deniedToolApprovals.length > 0 || approvedToolApprovals.length > 0) {
|
|
69739
|
-
const providerExecutedToolApprovals = [
|
|
69740
|
-
...approvedToolApprovals,
|
|
69741
|
-
...deniedToolApprovals
|
|
69742
|
-
].filter((toolApproval) => toolApproval.toolCall.providerExecuted);
|
|
69743
72036
|
const localApprovedToolApprovals = approvedToolApprovals.filter((toolApproval) => !toolApproval.toolCall.providerExecuted);
|
|
69744
72037
|
const localDeniedToolApprovals = deniedToolApprovals.filter((toolApproval) => !toolApproval.toolCall.providerExecuted);
|
|
69745
72038
|
const deniedProviderExecutedToolApprovals = deniedToolApprovals.filter((toolApproval) => toolApproval.toolCall.providerExecuted);
|
|
@@ -69790,18 +72083,6 @@ var DefaultStreamTextResult = class {
|
|
|
69790
72083
|
toolOutputs.push(result);
|
|
69791
72084
|
}
|
|
69792
72085
|
}));
|
|
69793
|
-
if (providerExecutedToolApprovals.length > 0) {
|
|
69794
|
-
initialResponseMessages.push({
|
|
69795
|
-
role: "tool",
|
|
69796
|
-
content: providerExecutedToolApprovals.map((toolApproval) => ({
|
|
69797
|
-
type: "tool-approval-response",
|
|
69798
|
-
approvalId: toolApproval.approvalResponse.approvalId,
|
|
69799
|
-
approved: toolApproval.approvalResponse.approved,
|
|
69800
|
-
reason: toolApproval.approvalResponse.reason,
|
|
69801
|
-
providerExecuted: true
|
|
69802
|
-
}))
|
|
69803
|
-
});
|
|
69804
|
-
}
|
|
69805
72086
|
if (toolOutputs.length > 0 || localDeniedToolApprovals.length > 0) {
|
|
69806
72087
|
const localToolContent = [];
|
|
69807
72088
|
for (const output2 of toolOutputs) {
|
|
@@ -69989,7 +72270,7 @@ var DefaultStreamTextResult = class {
|
|
|
69989
72270
|
repairToolCall,
|
|
69990
72271
|
abortSignal,
|
|
69991
72272
|
experimental_context,
|
|
69992
|
-
generateId:
|
|
72273
|
+
generateId: generateId22,
|
|
69993
72274
|
stepNumber: recordedSteps.length,
|
|
69994
72275
|
model: stepModelInfo,
|
|
69995
72276
|
onToolCallStart: [
|
|
@@ -70012,7 +72293,7 @@ var DefaultStreamTextResult = class {
|
|
|
70012
72293
|
let stepProviderMetadata;
|
|
70013
72294
|
let stepFirstChunk = true;
|
|
70014
72295
|
let stepResponse = {
|
|
70015
|
-
id:
|
|
72296
|
+
id: generateId22(),
|
|
70016
72297
|
timestamp: /* @__PURE__ */ new Date,
|
|
70017
72298
|
modelId: modelInfo.modelId
|
|
70018
72299
|
};
|
|
@@ -70502,12 +72783,15 @@ var DefaultStreamTextResult = class {
|
|
|
70502
72783
|
});
|
|
70503
72784
|
break;
|
|
70504
72785
|
}
|
|
70505
|
-
case "reasoning-start":
|
|
70506
|
-
|
|
70507
|
-
|
|
70508
|
-
|
|
70509
|
-
|
|
70510
|
-
|
|
72786
|
+
case "reasoning-start":
|
|
72787
|
+
case "reasoning-end": {
|
|
72788
|
+
if (sendReasoning) {
|
|
72789
|
+
controller.enqueue({
|
|
72790
|
+
type: partType,
|
|
72791
|
+
id: part.id,
|
|
72792
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
72793
|
+
});
|
|
72794
|
+
}
|
|
70511
72795
|
break;
|
|
70512
72796
|
}
|
|
70513
72797
|
case "reasoning-delta": {
|
|
@@ -70521,14 +72805,6 @@ var DefaultStreamTextResult = class {
|
|
|
70521
72805
|
}
|
|
70522
72806
|
break;
|
|
70523
72807
|
}
|
|
70524
|
-
case "reasoning-end": {
|
|
70525
|
-
controller.enqueue({
|
|
70526
|
-
type: "reasoning-end",
|
|
70527
|
-
id: part.id,
|
|
70528
|
-
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
70529
|
-
});
|
|
70530
|
-
break;
|
|
70531
|
-
}
|
|
70532
72808
|
case "file": {
|
|
70533
72809
|
controller.enqueue({
|
|
70534
72810
|
type: "file",
|