@merit-systems/echo-react-sdk 1.0.38-test.2eb0e31e.0 → 1.0.38
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/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1746 -308
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1256,7 +1256,7 @@ function prettifyError(error2) {
|
|
|
1256
1256
|
}
|
|
1257
1257
|
return lines.join("\n");
|
|
1258
1258
|
}
|
|
1259
|
-
const _parse$
|
|
1259
|
+
const _parse$3 = (_Err) => (schema, value, _ctx, _params) => {
|
|
1260
1260
|
const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
|
|
1261
1261
|
const result = schema._zod.run({ value, issues: [] }, ctx);
|
|
1262
1262
|
if (result instanceof Promise) {
|
|
@@ -1269,7 +1269,7 @@ const _parse$2 = (_Err) => (schema, value, _ctx, _params) => {
|
|
|
1269
1269
|
}
|
|
1270
1270
|
return result.value;
|
|
1271
1271
|
};
|
|
1272
|
-
const parse$1 = /* @__PURE__ */ _parse$
|
|
1272
|
+
const parse$1 = /* @__PURE__ */ _parse$3($ZodRealError);
|
|
1273
1273
|
const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
1274
1274
|
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
1275
1275
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
@@ -1308,11 +1308,11 @@ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
|
1308
1308
|
const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
|
|
1309
1309
|
const _encode = (_Err) => (schema, value, _ctx) => {
|
|
1310
1310
|
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
1311
|
-
return _parse$
|
|
1311
|
+
return _parse$3(_Err)(schema, value, ctx);
|
|
1312
1312
|
};
|
|
1313
1313
|
const encode$1 = /* @__PURE__ */ _encode($ZodRealError);
|
|
1314
1314
|
const _decode = (_Err) => (schema, value, _ctx) => {
|
|
1315
|
-
return _parse$
|
|
1315
|
+
return _parse$3(_Err)(schema, value, _ctx);
|
|
1316
1316
|
};
|
|
1317
1317
|
const decode$1 = /* @__PURE__ */ _decode($ZodRealError);
|
|
1318
1318
|
const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
@@ -11299,7 +11299,7 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
11299
11299
|
_number,
|
|
11300
11300
|
_optional,
|
|
11301
11301
|
_overwrite,
|
|
11302
|
-
_parse: _parse$
|
|
11302
|
+
_parse: _parse$3,
|
|
11303
11303
|
_parseAsync,
|
|
11304
11304
|
_pipe,
|
|
11305
11305
|
_positive,
|
|
@@ -11452,7 +11452,7 @@ const ZodError = $constructor("ZodError", initializer);
|
|
|
11452
11452
|
const ZodRealError = $constructor("ZodError", initializer, {
|
|
11453
11453
|
Parent: Error
|
|
11454
11454
|
});
|
|
11455
|
-
const parse = /* @__PURE__ */ _parse$
|
|
11455
|
+
const parse = /* @__PURE__ */ _parse$3(ZodRealError);
|
|
11456
11456
|
const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
11457
11457
|
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
11458
11458
|
const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
@@ -12711,7 +12711,7 @@ const z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
12711
12711
|
void: _void,
|
|
12712
12712
|
xid
|
|
12713
12713
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
12714
|
-
function combineHeaders$
|
|
12714
|
+
function combineHeaders$2(...headers) {
|
|
12715
12715
|
return headers.reduce(
|
|
12716
12716
|
(combinedHeaders, currentHeaders) => ({
|
|
12717
12717
|
...combinedHeaders,
|
|
@@ -12720,7 +12720,7 @@ function combineHeaders$1(...headers) {
|
|
|
12720
12720
|
{}
|
|
12721
12721
|
);
|
|
12722
12722
|
}
|
|
12723
|
-
function extractResponseHeaders$
|
|
12723
|
+
function extractResponseHeaders$2(response) {
|
|
12724
12724
|
return Object.fromEntries([...response.headers]);
|
|
12725
12725
|
}
|
|
12726
12726
|
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
@@ -12739,13 +12739,13 @@ function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
|
12739
12739
|
}
|
|
12740
12740
|
return "runtime/unknown";
|
|
12741
12741
|
}
|
|
12742
|
-
function removeUndefinedEntries$
|
|
12742
|
+
function removeUndefinedEntries$2(record2) {
|
|
12743
12743
|
return Object.fromEntries(
|
|
12744
12744
|
Object.entries(record2).filter(([_key, value]) => value != null)
|
|
12745
12745
|
);
|
|
12746
12746
|
}
|
|
12747
12747
|
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
12748
|
-
const cleanedHeaders = removeUndefinedEntries$
|
|
12748
|
+
const cleanedHeaders = removeUndefinedEntries$2(
|
|
12749
12749
|
headers != null ? headers : {}
|
|
12750
12750
|
);
|
|
12751
12751
|
const normalizedHeaders = new Headers(cleanedHeaders);
|
|
@@ -12756,7 +12756,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
12756
12756
|
);
|
|
12757
12757
|
return Object.fromEntries(normalizedHeaders);
|
|
12758
12758
|
}
|
|
12759
|
-
var createIdGenerator$
|
|
12759
|
+
var createIdGenerator$2 = ({
|
|
12760
12760
|
prefix,
|
|
12761
12761
|
size = 16,
|
|
12762
12762
|
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
@@ -12781,21 +12781,21 @@ var createIdGenerator$1 = ({
|
|
|
12781
12781
|
}
|
|
12782
12782
|
return () => `${prefix}${separator}${generator()}`;
|
|
12783
12783
|
};
|
|
12784
|
-
var generateId$
|
|
12785
|
-
function isAbortError$
|
|
12784
|
+
var generateId$2 = createIdGenerator$2();
|
|
12785
|
+
function isAbortError$2(error2) {
|
|
12786
12786
|
return (error2 instanceof Error || error2 instanceof DOMException) && (error2.name === "AbortError" || error2.name === "ResponseAborted" || // Next.js
|
|
12787
12787
|
error2.name === "TimeoutError");
|
|
12788
12788
|
}
|
|
12789
|
-
var FETCH_FAILED_ERROR_MESSAGES$
|
|
12790
|
-
function handleFetchError$
|
|
12789
|
+
var FETCH_FAILED_ERROR_MESSAGES$2 = ["fetch failed", "failed to fetch"];
|
|
12790
|
+
function handleFetchError$2({
|
|
12791
12791
|
error: error2,
|
|
12792
12792
|
url: url2,
|
|
12793
12793
|
requestBodyValues
|
|
12794
12794
|
}) {
|
|
12795
|
-
if (isAbortError$
|
|
12795
|
+
if (isAbortError$2(error2)) {
|
|
12796
12796
|
return error2;
|
|
12797
12797
|
}
|
|
12798
|
-
if (error2 instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES$
|
|
12798
|
+
if (error2 instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES$2.includes(error2.message.toLowerCase())) {
|
|
12799
12799
|
const cause = error2.cause;
|
|
12800
12800
|
if (cause != null) {
|
|
12801
12801
|
return new APICallError$1({
|
|
@@ -12811,7 +12811,7 @@ function handleFetchError$1({
|
|
|
12811
12811
|
return error2;
|
|
12812
12812
|
}
|
|
12813
12813
|
var VERSION = "3.0.9";
|
|
12814
|
-
function loadApiKey$
|
|
12814
|
+
function loadApiKey$2({
|
|
12815
12815
|
apiKey,
|
|
12816
12816
|
environmentVariableName,
|
|
12817
12817
|
apiKeyParameterName = "apiKey",
|
|
@@ -12843,7 +12843,7 @@ function loadApiKey$1({
|
|
|
12843
12843
|
}
|
|
12844
12844
|
return apiKey;
|
|
12845
12845
|
}
|
|
12846
|
-
function mediaTypeToExtension(mediaType) {
|
|
12846
|
+
function mediaTypeToExtension$1(mediaType) {
|
|
12847
12847
|
var _a10;
|
|
12848
12848
|
const [_type, subtype = ""] = mediaType.toLowerCase().split("/");
|
|
12849
12849
|
return (_a10 = {
|
|
@@ -12854,19 +12854,19 @@ function mediaTypeToExtension(mediaType) {
|
|
|
12854
12854
|
"x-m4a": "m4a"
|
|
12855
12855
|
}[subtype]) != null ? _a10 : subtype;
|
|
12856
12856
|
}
|
|
12857
|
-
var suspectProtoRx$
|
|
12858
|
-
var suspectConstructorRx$
|
|
12859
|
-
function _parse$
|
|
12857
|
+
var suspectProtoRx$2 = /"__proto__"\s*:/;
|
|
12858
|
+
var suspectConstructorRx$2 = /"constructor"\s*:/;
|
|
12859
|
+
function _parse$2(text2) {
|
|
12860
12860
|
const obj = JSON.parse(text2);
|
|
12861
12861
|
if (obj === null || typeof obj !== "object") {
|
|
12862
12862
|
return obj;
|
|
12863
12863
|
}
|
|
12864
|
-
if (suspectProtoRx$
|
|
12864
|
+
if (suspectProtoRx$2.test(text2) === false && suspectConstructorRx$2.test(text2) === false) {
|
|
12865
12865
|
return obj;
|
|
12866
12866
|
}
|
|
12867
|
-
return filter$
|
|
12867
|
+
return filter$2(obj);
|
|
12868
12868
|
}
|
|
12869
|
-
function filter$
|
|
12869
|
+
function filter$2(obj) {
|
|
12870
12870
|
let next = [obj];
|
|
12871
12871
|
while (next.length) {
|
|
12872
12872
|
const nodes = next;
|
|
@@ -12888,27 +12888,27 @@ function filter$1(obj) {
|
|
|
12888
12888
|
}
|
|
12889
12889
|
return obj;
|
|
12890
12890
|
}
|
|
12891
|
-
function secureJsonParse$
|
|
12891
|
+
function secureJsonParse$2(text2) {
|
|
12892
12892
|
const { stackTraceLimit } = Error;
|
|
12893
12893
|
Error.stackTraceLimit = 0;
|
|
12894
12894
|
try {
|
|
12895
|
-
return _parse$
|
|
12895
|
+
return _parse$2(text2);
|
|
12896
12896
|
} finally {
|
|
12897
12897
|
Error.stackTraceLimit = stackTraceLimit;
|
|
12898
12898
|
}
|
|
12899
12899
|
}
|
|
12900
|
-
var validatorSymbol$
|
|
12901
|
-
function validator$
|
|
12902
|
-
return { [validatorSymbol$
|
|
12900
|
+
var validatorSymbol$2 = Symbol.for("vercel.ai.validator");
|
|
12901
|
+
function validator$2(validate) {
|
|
12902
|
+
return { [validatorSymbol$2]: true, validate };
|
|
12903
12903
|
}
|
|
12904
|
-
function isValidator$
|
|
12905
|
-
return typeof value === "object" && value !== null && validatorSymbol$
|
|
12904
|
+
function isValidator$2(value) {
|
|
12905
|
+
return typeof value === "object" && value !== null && validatorSymbol$2 in value && value[validatorSymbol$2] === true && "validate" in value;
|
|
12906
12906
|
}
|
|
12907
|
-
function asValidator$
|
|
12908
|
-
return isValidator$
|
|
12907
|
+
function asValidator$2(value) {
|
|
12908
|
+
return isValidator$2(value) ? value : standardSchemaValidator$2(value);
|
|
12909
12909
|
}
|
|
12910
|
-
function standardSchemaValidator$
|
|
12911
|
-
return validator$
|
|
12910
|
+
function standardSchemaValidator$2(standardSchema) {
|
|
12911
|
+
return validator$2(async (value) => {
|
|
12912
12912
|
const result = await standardSchema["~standard"].validate(value);
|
|
12913
12913
|
return result.issues == null ? { success: true, value: result.value } : {
|
|
12914
12914
|
success: false,
|
|
@@ -12919,21 +12919,21 @@ function standardSchemaValidator$1(standardSchema) {
|
|
|
12919
12919
|
};
|
|
12920
12920
|
});
|
|
12921
12921
|
}
|
|
12922
|
-
async function validateTypes$
|
|
12922
|
+
async function validateTypes$2({
|
|
12923
12923
|
value,
|
|
12924
12924
|
schema
|
|
12925
12925
|
}) {
|
|
12926
|
-
const result = await safeValidateTypes$
|
|
12926
|
+
const result = await safeValidateTypes$2({ value, schema });
|
|
12927
12927
|
if (!result.success) {
|
|
12928
12928
|
throw TypeValidationError$1.wrap({ value, cause: result.error });
|
|
12929
12929
|
}
|
|
12930
12930
|
return result.value;
|
|
12931
12931
|
}
|
|
12932
|
-
async function safeValidateTypes$
|
|
12932
|
+
async function safeValidateTypes$2({
|
|
12933
12933
|
value,
|
|
12934
12934
|
schema
|
|
12935
12935
|
}) {
|
|
12936
|
-
const validator2 = asValidator$
|
|
12936
|
+
const validator2 = asValidator$2(schema);
|
|
12937
12937
|
try {
|
|
12938
12938
|
if (validator2.validate == null) {
|
|
12939
12939
|
return { success: true, value, rawValue: value };
|
|
@@ -12955,16 +12955,16 @@ async function safeValidateTypes$1({
|
|
|
12955
12955
|
};
|
|
12956
12956
|
}
|
|
12957
12957
|
}
|
|
12958
|
-
async function parseJSON$
|
|
12958
|
+
async function parseJSON$2({
|
|
12959
12959
|
text: text2,
|
|
12960
12960
|
schema
|
|
12961
12961
|
}) {
|
|
12962
12962
|
try {
|
|
12963
|
-
const value = secureJsonParse$
|
|
12963
|
+
const value = secureJsonParse$2(text2);
|
|
12964
12964
|
if (schema == null) {
|
|
12965
12965
|
return value;
|
|
12966
12966
|
}
|
|
12967
|
-
return validateTypes$
|
|
12967
|
+
return validateTypes$2({ value, schema });
|
|
12968
12968
|
} catch (error2) {
|
|
12969
12969
|
if (JSONParseError$1.isInstance(error2) || TypeValidationError$1.isInstance(error2)) {
|
|
12970
12970
|
throw error2;
|
|
@@ -12972,16 +12972,16 @@ async function parseJSON$1({
|
|
|
12972
12972
|
throw new JSONParseError$1({ text: text2, cause: error2 });
|
|
12973
12973
|
}
|
|
12974
12974
|
}
|
|
12975
|
-
async function safeParseJSON$
|
|
12975
|
+
async function safeParseJSON$2({
|
|
12976
12976
|
text: text2,
|
|
12977
12977
|
schema
|
|
12978
12978
|
}) {
|
|
12979
12979
|
try {
|
|
12980
|
-
const value = secureJsonParse$
|
|
12980
|
+
const value = secureJsonParse$2(text2);
|
|
12981
12981
|
if (schema == null) {
|
|
12982
12982
|
return { success: true, value, rawValue: value };
|
|
12983
12983
|
}
|
|
12984
|
-
return await safeValidateTypes$
|
|
12984
|
+
return await safeValidateTypes$2({ value, schema });
|
|
12985
12985
|
} catch (error2) {
|
|
12986
12986
|
return {
|
|
12987
12987
|
success: false,
|
|
@@ -12990,15 +12990,15 @@ async function safeParseJSON$1({
|
|
|
12990
12990
|
};
|
|
12991
12991
|
}
|
|
12992
12992
|
}
|
|
12993
|
-
function isParsableJson$
|
|
12993
|
+
function isParsableJson$2(input) {
|
|
12994
12994
|
try {
|
|
12995
|
-
secureJsonParse$
|
|
12995
|
+
secureJsonParse$2(input);
|
|
12996
12996
|
return true;
|
|
12997
12997
|
} catch (e) {
|
|
12998
12998
|
return false;
|
|
12999
12999
|
}
|
|
13000
13000
|
}
|
|
13001
|
-
function parseJsonEventStream$
|
|
13001
|
+
function parseJsonEventStream$2({
|
|
13002
13002
|
stream,
|
|
13003
13003
|
schema
|
|
13004
13004
|
}) {
|
|
@@ -13008,12 +13008,12 @@ function parseJsonEventStream$1({
|
|
|
13008
13008
|
if (data === "[DONE]") {
|
|
13009
13009
|
return;
|
|
13010
13010
|
}
|
|
13011
|
-
controller.enqueue(await safeParseJSON$
|
|
13011
|
+
controller.enqueue(await safeParseJSON$2({ text: data, schema }));
|
|
13012
13012
|
}
|
|
13013
13013
|
})
|
|
13014
13014
|
);
|
|
13015
13015
|
}
|
|
13016
|
-
async function parseProviderOptions({
|
|
13016
|
+
async function parseProviderOptions$1({
|
|
13017
13017
|
provider,
|
|
13018
13018
|
providerOptions,
|
|
13019
13019
|
schema
|
|
@@ -13021,7 +13021,7 @@ async function parseProviderOptions({
|
|
|
13021
13021
|
if ((providerOptions == null ? void 0 : providerOptions[provider]) == null) {
|
|
13022
13022
|
return void 0;
|
|
13023
13023
|
}
|
|
13024
|
-
const parsedProviderOptions = await safeValidateTypes$
|
|
13024
|
+
const parsedProviderOptions = await safeValidateTypes$2({
|
|
13025
13025
|
value: providerOptions[provider],
|
|
13026
13026
|
schema
|
|
13027
13027
|
});
|
|
@@ -13034,8 +13034,8 @@ async function parseProviderOptions({
|
|
|
13034
13034
|
}
|
|
13035
13035
|
return parsedProviderOptions.value;
|
|
13036
13036
|
}
|
|
13037
|
-
var getOriginalFetch2$
|
|
13038
|
-
var postJsonToApi$
|
|
13037
|
+
var getOriginalFetch2$2 = () => globalThis.fetch;
|
|
13038
|
+
var postJsonToApi$2 = async ({
|
|
13039
13039
|
url: url2,
|
|
13040
13040
|
headers,
|
|
13041
13041
|
body,
|
|
@@ -13043,7 +13043,7 @@ var postJsonToApi$1 = async ({
|
|
|
13043
13043
|
successfulResponseHandler,
|
|
13044
13044
|
abortSignal,
|
|
13045
13045
|
fetch: fetch2
|
|
13046
|
-
}) => postToApi$
|
|
13046
|
+
}) => postToApi$2({
|
|
13047
13047
|
url: url2,
|
|
13048
13048
|
headers: {
|
|
13049
13049
|
"Content-Type": "application/json",
|
|
@@ -13058,7 +13058,7 @@ var postJsonToApi$1 = async ({
|
|
|
13058
13058
|
abortSignal,
|
|
13059
13059
|
fetch: fetch2
|
|
13060
13060
|
});
|
|
13061
|
-
var postFormDataToApi = async ({
|
|
13061
|
+
var postFormDataToApi$1 = async ({
|
|
13062
13062
|
url: url2,
|
|
13063
13063
|
headers,
|
|
13064
13064
|
formData,
|
|
@@ -13066,7 +13066,7 @@ var postFormDataToApi = async ({
|
|
|
13066
13066
|
successfulResponseHandler,
|
|
13067
13067
|
abortSignal,
|
|
13068
13068
|
fetch: fetch2
|
|
13069
|
-
}) => postToApi$
|
|
13069
|
+
}) => postToApi$2({
|
|
13070
13070
|
url: url2,
|
|
13071
13071
|
headers,
|
|
13072
13072
|
body: {
|
|
@@ -13078,14 +13078,14 @@ var postFormDataToApi = async ({
|
|
|
13078
13078
|
abortSignal,
|
|
13079
13079
|
fetch: fetch2
|
|
13080
13080
|
});
|
|
13081
|
-
var postToApi$
|
|
13081
|
+
var postToApi$2 = async ({
|
|
13082
13082
|
url: url2,
|
|
13083
13083
|
headers = {},
|
|
13084
13084
|
body,
|
|
13085
13085
|
successfulResponseHandler,
|
|
13086
13086
|
failedResponseHandler,
|
|
13087
13087
|
abortSignal,
|
|
13088
|
-
fetch: fetch2 = getOriginalFetch2$
|
|
13088
|
+
fetch: fetch2 = getOriginalFetch2$2()
|
|
13089
13089
|
}) => {
|
|
13090
13090
|
try {
|
|
13091
13091
|
const response = await fetch2(url2, {
|
|
@@ -13098,7 +13098,7 @@ var postToApi$1 = async ({
|
|
|
13098
13098
|
body: body.content,
|
|
13099
13099
|
signal: abortSignal
|
|
13100
13100
|
});
|
|
13101
|
-
const responseHeaders = extractResponseHeaders$
|
|
13101
|
+
const responseHeaders = extractResponseHeaders$2(response);
|
|
13102
13102
|
if (!response.ok) {
|
|
13103
13103
|
let errorInformation;
|
|
13104
13104
|
try {
|
|
@@ -13108,7 +13108,7 @@ var postToApi$1 = async ({
|
|
|
13108
13108
|
requestBodyValues: body.values
|
|
13109
13109
|
});
|
|
13110
13110
|
} catch (error2) {
|
|
13111
|
-
if (isAbortError$
|
|
13111
|
+
if (isAbortError$2(error2) || APICallError$1.isInstance(error2)) {
|
|
13112
13112
|
throw error2;
|
|
13113
13113
|
}
|
|
13114
13114
|
throw new APICallError$1({
|
|
@@ -13130,7 +13130,7 @@ var postToApi$1 = async ({
|
|
|
13130
13130
|
});
|
|
13131
13131
|
} catch (error2) {
|
|
13132
13132
|
if (error2 instanceof Error) {
|
|
13133
|
-
if (isAbortError$
|
|
13133
|
+
if (isAbortError$2(error2) || APICallError$1.isInstance(error2)) {
|
|
13134
13134
|
throw error2;
|
|
13135
13135
|
}
|
|
13136
13136
|
}
|
|
@@ -13144,13 +13144,13 @@ var postToApi$1 = async ({
|
|
|
13144
13144
|
});
|
|
13145
13145
|
}
|
|
13146
13146
|
} catch (error2) {
|
|
13147
|
-
throw handleFetchError$
|
|
13147
|
+
throw handleFetchError$2({ error: error2, url: url2, requestBodyValues: body.values });
|
|
13148
13148
|
}
|
|
13149
13149
|
};
|
|
13150
|
-
function tool(tool2) {
|
|
13150
|
+
function tool$1(tool2) {
|
|
13151
13151
|
return tool2;
|
|
13152
13152
|
}
|
|
13153
|
-
function createProviderDefinedToolFactory({
|
|
13153
|
+
function createProviderDefinedToolFactory$1({
|
|
13154
13154
|
id: id2,
|
|
13155
13155
|
name: name8,
|
|
13156
13156
|
inputSchema
|
|
@@ -13163,7 +13163,7 @@ function createProviderDefinedToolFactory({
|
|
|
13163
13163
|
onInputDelta,
|
|
13164
13164
|
onInputAvailable,
|
|
13165
13165
|
...args
|
|
13166
|
-
}) => tool({
|
|
13166
|
+
}) => tool$1({
|
|
13167
13167
|
type: "provider-defined",
|
|
13168
13168
|
id: id2,
|
|
13169
13169
|
name: name8,
|
|
@@ -13190,7 +13190,7 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
13190
13190
|
onInputDelta,
|
|
13191
13191
|
onInputAvailable,
|
|
13192
13192
|
...args
|
|
13193
|
-
}) => tool({
|
|
13193
|
+
}) => tool$1({
|
|
13194
13194
|
type: "provider-defined",
|
|
13195
13195
|
id: id2,
|
|
13196
13196
|
name: name8,
|
|
@@ -13210,13 +13210,13 @@ async function resolve(value) {
|
|
|
13210
13210
|
}
|
|
13211
13211
|
return Promise.resolve(value);
|
|
13212
13212
|
}
|
|
13213
|
-
var createJsonErrorResponseHandler$
|
|
13213
|
+
var createJsonErrorResponseHandler$2 = ({
|
|
13214
13214
|
errorSchema,
|
|
13215
13215
|
errorToMessage,
|
|
13216
13216
|
isRetryable
|
|
13217
13217
|
}) => async ({ response, url: url2, requestBodyValues }) => {
|
|
13218
13218
|
const responseBody = await response.text();
|
|
13219
|
-
const responseHeaders = extractResponseHeaders$
|
|
13219
|
+
const responseHeaders = extractResponseHeaders$2(response);
|
|
13220
13220
|
if (responseBody.trim() === "") {
|
|
13221
13221
|
return {
|
|
13222
13222
|
responseHeaders,
|
|
@@ -13232,7 +13232,7 @@ var createJsonErrorResponseHandler$1 = ({
|
|
|
13232
13232
|
};
|
|
13233
13233
|
}
|
|
13234
13234
|
try {
|
|
13235
|
-
const parsedError = await parseJSON$
|
|
13235
|
+
const parsedError = await parseJSON$2({
|
|
13236
13236
|
text: responseBody,
|
|
13237
13237
|
schema: errorSchema
|
|
13238
13238
|
});
|
|
@@ -13264,26 +13264,26 @@ var createJsonErrorResponseHandler$1 = ({
|
|
|
13264
13264
|
};
|
|
13265
13265
|
}
|
|
13266
13266
|
};
|
|
13267
|
-
var createEventSourceResponseHandler$
|
|
13268
|
-
const responseHeaders = extractResponseHeaders$
|
|
13267
|
+
var createEventSourceResponseHandler$2 = (chunkSchema2) => async ({ response }) => {
|
|
13268
|
+
const responseHeaders = extractResponseHeaders$2(response);
|
|
13269
13269
|
if (response.body == null) {
|
|
13270
13270
|
throw new EmptyResponseBodyError$1({});
|
|
13271
13271
|
}
|
|
13272
13272
|
return {
|
|
13273
13273
|
responseHeaders,
|
|
13274
|
-
value: parseJsonEventStream$
|
|
13274
|
+
value: parseJsonEventStream$2({
|
|
13275
13275
|
stream: response.body,
|
|
13276
13276
|
schema: chunkSchema2
|
|
13277
13277
|
})
|
|
13278
13278
|
};
|
|
13279
13279
|
};
|
|
13280
|
-
var createJsonResponseHandler$
|
|
13280
|
+
var createJsonResponseHandler$2 = (responseSchema2) => async ({ response, url: url2, requestBodyValues }) => {
|
|
13281
13281
|
const responseBody = await response.text();
|
|
13282
|
-
const parsedResult = await safeParseJSON$
|
|
13282
|
+
const parsedResult = await safeParseJSON$2({
|
|
13283
13283
|
text: responseBody,
|
|
13284
13284
|
schema: responseSchema2
|
|
13285
13285
|
});
|
|
13286
|
-
const responseHeaders = extractResponseHeaders$
|
|
13286
|
+
const responseHeaders = extractResponseHeaders$2(response);
|
|
13287
13287
|
if (!parsedResult.success) {
|
|
13288
13288
|
throw new APICallError$1({
|
|
13289
13289
|
message: "Invalid JSON response",
|
|
@@ -13302,7 +13302,7 @@ var createJsonResponseHandler$1 = (responseSchema2) => async ({ response, url: u
|
|
|
13302
13302
|
};
|
|
13303
13303
|
};
|
|
13304
13304
|
var createBinaryResponseHandler = () => async ({ response, url: url2, requestBodyValues }) => {
|
|
13305
|
-
const responseHeaders = extractResponseHeaders$
|
|
13305
|
+
const responseHeaders = extractResponseHeaders$2(response);
|
|
13306
13306
|
if (!response.body) {
|
|
13307
13307
|
throw new APICallError$1({
|
|
13308
13308
|
message: "Response body is empty",
|
|
@@ -13334,23 +13334,23 @@ var createBinaryResponseHandler = () => async ({ response, url: url2, requestBod
|
|
|
13334
13334
|
new Set(
|
|
13335
13335
|
"ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
|
|
13336
13336
|
);
|
|
13337
|
-
var { btoa: btoa$
|
|
13338
|
-
function convertBase64ToUint8Array(base64String) {
|
|
13337
|
+
var { btoa: btoa$3, atob: atob$2 } = globalThis;
|
|
13338
|
+
function convertBase64ToUint8Array$1(base64String) {
|
|
13339
13339
|
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
13340
|
-
const latin1string = atob$
|
|
13340
|
+
const latin1string = atob$2(base64Url);
|
|
13341
13341
|
return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
|
|
13342
13342
|
}
|
|
13343
|
-
function convertUint8ArrayToBase64$
|
|
13343
|
+
function convertUint8ArrayToBase64$2(array2) {
|
|
13344
13344
|
let latin1string = "";
|
|
13345
13345
|
for (let i = 0; i < array2.length; i++) {
|
|
13346
13346
|
latin1string += String.fromCodePoint(array2[i]);
|
|
13347
13347
|
}
|
|
13348
|
-
return btoa$
|
|
13348
|
+
return btoa$3(latin1string);
|
|
13349
13349
|
}
|
|
13350
|
-
function convertToBase64(value) {
|
|
13351
|
-
return value instanceof Uint8Array ? convertUint8ArrayToBase64$
|
|
13350
|
+
function convertToBase64$1(value) {
|
|
13351
|
+
return value instanceof Uint8Array ? convertUint8ArrayToBase64$2(value) : value;
|
|
13352
13352
|
}
|
|
13353
|
-
function withoutTrailingSlash$
|
|
13353
|
+
function withoutTrailingSlash$2(url2) {
|
|
13354
13354
|
return url2 == null ? void 0 : url2.replace(/\/$/, "");
|
|
13355
13355
|
}
|
|
13356
13356
|
var anthropicErrorDataSchema = object({
|
|
@@ -13360,7 +13360,7 @@ var anthropicErrorDataSchema = object({
|
|
|
13360
13360
|
message: string$1()
|
|
13361
13361
|
})
|
|
13362
13362
|
});
|
|
13363
|
-
var anthropicFailedResponseHandler = createJsonErrorResponseHandler$
|
|
13363
|
+
var anthropicFailedResponseHandler = createJsonErrorResponseHandler$2({
|
|
13364
13364
|
errorSchema: anthropicErrorDataSchema,
|
|
13365
13365
|
errorToMessage: (data) => data.error.message
|
|
13366
13366
|
});
|
|
@@ -13460,7 +13460,7 @@ var webSearch_20250305 = (args = {}) => {
|
|
|
13460
13460
|
function isWebSearchTool(tool2) {
|
|
13461
13461
|
return typeof tool2 === "object" && tool2 !== null && "type" in tool2 && tool2.type === "web_search_20250305";
|
|
13462
13462
|
}
|
|
13463
|
-
function prepareTools$
|
|
13463
|
+
function prepareTools$2({
|
|
13464
13464
|
tools,
|
|
13465
13465
|
toolChoice,
|
|
13466
13466
|
disableParallelToolUse
|
|
@@ -13670,7 +13670,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
13670
13670
|
const messages = [];
|
|
13671
13671
|
async function shouldEnableCitations(providerMetadata) {
|
|
13672
13672
|
var _a22, _b2;
|
|
13673
|
-
const anthropicOptions = await parseProviderOptions({
|
|
13673
|
+
const anthropicOptions = await parseProviderOptions$1({
|
|
13674
13674
|
provider: "anthropic",
|
|
13675
13675
|
providerOptions: providerMetadata,
|
|
13676
13676
|
schema: anthropicFilePartProviderOptions
|
|
@@ -13678,7 +13678,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
13678
13678
|
return (_b2 = (_a22 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a22.enabled) != null ? _b2 : false;
|
|
13679
13679
|
}
|
|
13680
13680
|
async function getDocumentMetadata(providerMetadata) {
|
|
13681
|
-
const anthropicOptions = await parseProviderOptions({
|
|
13681
|
+
const anthropicOptions = await parseProviderOptions$1({
|
|
13682
13682
|
provider: "anthropic",
|
|
13683
13683
|
providerOptions: providerMetadata,
|
|
13684
13684
|
schema: anthropicFilePartProviderOptions
|
|
@@ -13735,7 +13735,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
13735
13735
|
} : {
|
|
13736
13736
|
type: "base64",
|
|
13737
13737
|
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
13738
|
-
data: convertToBase64(part.data)
|
|
13738
|
+
data: convertToBase64$1(part.data)
|
|
13739
13739
|
},
|
|
13740
13740
|
cache_control: cacheControl
|
|
13741
13741
|
});
|
|
@@ -13755,7 +13755,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
13755
13755
|
} : {
|
|
13756
13756
|
type: "base64",
|
|
13757
13757
|
media_type: "application/pdf",
|
|
13758
|
-
data: convertToBase64(part.data)
|
|
13758
|
+
data: convertToBase64$1(part.data)
|
|
13759
13759
|
},
|
|
13760
13760
|
title: (_b = metadata.title) != null ? _b : part.filename,
|
|
13761
13761
|
...metadata.context && { context: metadata.context },
|
|
@@ -13890,7 +13890,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
13890
13890
|
}
|
|
13891
13891
|
case "reasoning": {
|
|
13892
13892
|
if (sendReasoning) {
|
|
13893
|
-
const reasoningMetadata = await parseProviderOptions({
|
|
13893
|
+
const reasoningMetadata = await parseProviderOptions$1({
|
|
13894
13894
|
provider: "anthropic",
|
|
13895
13895
|
providerOptions: part.providerOptions,
|
|
13896
13896
|
schema: anthropicReasoningMetadataSchema
|
|
@@ -14183,7 +14183,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
14183
14183
|
var _a10;
|
|
14184
14184
|
this.modelId = modelId;
|
|
14185
14185
|
this.config = config2;
|
|
14186
|
-
this.generateId = (_a10 = config2.generateId) != null ? _a10 : generateId$
|
|
14186
|
+
this.generateId = (_a10 = config2.generateId) != null ? _a10 : generateId$2;
|
|
14187
14187
|
}
|
|
14188
14188
|
supportsUrl(url2) {
|
|
14189
14189
|
return url2.protocol === "https:";
|
|
@@ -14252,7 +14252,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
14252
14252
|
description: "Respond with a JSON object.",
|
|
14253
14253
|
inputSchema: responseFormat.schema
|
|
14254
14254
|
} : void 0;
|
|
14255
|
-
const anthropicOptions = await parseProviderOptions({
|
|
14255
|
+
const anthropicOptions = await parseProviderOptions$1({
|
|
14256
14256
|
provider: "anthropic",
|
|
14257
14257
|
providerOptions,
|
|
14258
14258
|
schema: anthropicProviderOptions
|
|
@@ -14318,7 +14318,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
14318
14318
|
toolChoice: anthropicToolChoice,
|
|
14319
14319
|
toolWarnings,
|
|
14320
14320
|
betas: toolsBetas
|
|
14321
|
-
} = prepareTools$
|
|
14321
|
+
} = prepareTools$2(
|
|
14322
14322
|
jsonResponseTool != null ? {
|
|
14323
14323
|
tools: [jsonResponseTool],
|
|
14324
14324
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name },
|
|
@@ -14344,7 +14344,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
14344
14344
|
betas,
|
|
14345
14345
|
headers
|
|
14346
14346
|
}) {
|
|
14347
|
-
return combineHeaders$
|
|
14347
|
+
return combineHeaders$2(
|
|
14348
14348
|
await resolve(this.config.headers),
|
|
14349
14349
|
betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
|
|
14350
14350
|
headers
|
|
@@ -14389,12 +14389,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
14389
14389
|
responseHeaders,
|
|
14390
14390
|
value: response,
|
|
14391
14391
|
rawValue: rawResponse
|
|
14392
|
-
} = await postJsonToApi$
|
|
14392
|
+
} = await postJsonToApi$2({
|
|
14393
14393
|
url: this.buildRequestUrl(false),
|
|
14394
14394
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
14395
14395
|
body: this.transformRequestBody(args),
|
|
14396
14396
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
14397
|
-
successfulResponseHandler: createJsonResponseHandler$
|
|
14397
|
+
successfulResponseHandler: createJsonResponseHandler$2(
|
|
14398
14398
|
anthropicMessagesResponseSchema
|
|
14399
14399
|
),
|
|
14400
14400
|
abortSignal: options.abortSignal,
|
|
@@ -14580,12 +14580,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
14580
14580
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
14581
14581
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
14582
14582
|
const body = { ...args, stream: true };
|
|
14583
|
-
const { responseHeaders, value: response } = await postJsonToApi$
|
|
14583
|
+
const { responseHeaders, value: response } = await postJsonToApi$2({
|
|
14584
14584
|
url: this.buildRequestUrl(true),
|
|
14585
14585
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
14586
14586
|
body: this.transformRequestBody(body),
|
|
14587
14587
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
14588
|
-
successfulResponseHandler: createEventSourceResponseHandler$
|
|
14588
|
+
successfulResponseHandler: createEventSourceResponseHandler$2(
|
|
14589
14589
|
anthropicMessagesChunkSchema
|
|
14590
14590
|
),
|
|
14591
14591
|
abortSignal: options.abortSignal,
|
|
@@ -15146,7 +15146,7 @@ var anthropicReasoningMetadataSchema = object({
|
|
|
15146
15146
|
signature: string$1().optional(),
|
|
15147
15147
|
redactedData: string$1().optional()
|
|
15148
15148
|
});
|
|
15149
|
-
var bash_20241022 = createProviderDefinedToolFactory({
|
|
15149
|
+
var bash_20241022 = createProviderDefinedToolFactory$1({
|
|
15150
15150
|
id: "anthropic.bash_20241022",
|
|
15151
15151
|
name: "bash",
|
|
15152
15152
|
inputSchema: z.object({
|
|
@@ -15154,7 +15154,7 @@ var bash_20241022 = createProviderDefinedToolFactory({
|
|
|
15154
15154
|
restart: z.boolean().optional()
|
|
15155
15155
|
})
|
|
15156
15156
|
});
|
|
15157
|
-
var bash_20250124 = createProviderDefinedToolFactory({
|
|
15157
|
+
var bash_20250124 = createProviderDefinedToolFactory$1({
|
|
15158
15158
|
id: "anthropic.bash_20250124",
|
|
15159
15159
|
name: "bash",
|
|
15160
15160
|
inputSchema: z.object({
|
|
@@ -15162,7 +15162,7 @@ var bash_20250124 = createProviderDefinedToolFactory({
|
|
|
15162
15162
|
restart: z.boolean().optional()
|
|
15163
15163
|
})
|
|
15164
15164
|
});
|
|
15165
|
-
var computer_20241022 = createProviderDefinedToolFactory({
|
|
15165
|
+
var computer_20241022 = createProviderDefinedToolFactory$1({
|
|
15166
15166
|
id: "anthropic.computer_20241022",
|
|
15167
15167
|
name: "computer",
|
|
15168
15168
|
inputSchema: object({
|
|
@@ -15182,7 +15182,7 @@ var computer_20241022 = createProviderDefinedToolFactory({
|
|
|
15182
15182
|
text: string$1().optional()
|
|
15183
15183
|
})
|
|
15184
15184
|
});
|
|
15185
|
-
var computer_20250124 = createProviderDefinedToolFactory({
|
|
15185
|
+
var computer_20250124 = createProviderDefinedToolFactory$1({
|
|
15186
15186
|
id: "anthropic.computer_20250124",
|
|
15187
15187
|
name: "computer",
|
|
15188
15188
|
inputSchema: object({
|
|
@@ -15212,7 +15212,7 @@ var computer_20250124 = createProviderDefinedToolFactory({
|
|
|
15212
15212
|
text: string$1().optional()
|
|
15213
15213
|
})
|
|
15214
15214
|
});
|
|
15215
|
-
var textEditor_20241022 = createProviderDefinedToolFactory({
|
|
15215
|
+
var textEditor_20241022 = createProviderDefinedToolFactory$1({
|
|
15216
15216
|
id: "anthropic.text_editor_20241022",
|
|
15217
15217
|
name: "str_replace_editor",
|
|
15218
15218
|
inputSchema: object({
|
|
@@ -15225,7 +15225,7 @@ var textEditor_20241022 = createProviderDefinedToolFactory({
|
|
|
15225
15225
|
view_range: array(number$1().int()).optional()
|
|
15226
15226
|
})
|
|
15227
15227
|
});
|
|
15228
|
-
var textEditor_20250124 = createProviderDefinedToolFactory({
|
|
15228
|
+
var textEditor_20250124 = createProviderDefinedToolFactory$1({
|
|
15229
15229
|
id: "anthropic.text_editor_20250124",
|
|
15230
15230
|
name: "str_replace_editor",
|
|
15231
15231
|
inputSchema: object({
|
|
@@ -15238,7 +15238,7 @@ var textEditor_20250124 = createProviderDefinedToolFactory({
|
|
|
15238
15238
|
view_range: array(number$1().int()).optional()
|
|
15239
15239
|
})
|
|
15240
15240
|
});
|
|
15241
|
-
var textEditor_20250429 = createProviderDefinedToolFactory({
|
|
15241
|
+
var textEditor_20250429 = createProviderDefinedToolFactory$1({
|
|
15242
15242
|
id: "anthropic.text_editor_20250429",
|
|
15243
15243
|
name: "str_replace_based_edit_tool",
|
|
15244
15244
|
inputSchema: object({
|
|
@@ -15347,10 +15347,10 @@ var anthropicTools = {
|
|
|
15347
15347
|
};
|
|
15348
15348
|
function createAnthropic(options = {}) {
|
|
15349
15349
|
var _a10;
|
|
15350
|
-
const baseURL = (_a10 = withoutTrailingSlash$
|
|
15350
|
+
const baseURL = (_a10 = withoutTrailingSlash$2(options.baseURL)) != null ? _a10 : "https://api.anthropic.com/v1";
|
|
15351
15351
|
const getHeaders = () => ({
|
|
15352
15352
|
"anthropic-version": "2023-06-01",
|
|
15353
|
-
"x-api-key": loadApiKey$
|
|
15353
|
+
"x-api-key": loadApiKey$2({
|
|
15354
15354
|
apiKey: options.apiKey,
|
|
15355
15355
|
environmentVariableName: "ANTHROPIC_API_KEY",
|
|
15356
15356
|
description: "Anthropic"
|
|
@@ -15364,7 +15364,7 @@ function createAnthropic(options = {}) {
|
|
|
15364
15364
|
baseURL,
|
|
15365
15365
|
headers: getHeaders,
|
|
15366
15366
|
fetch: options.fetch,
|
|
15367
|
-
generateId: (_a22 = options.generateId) != null ? _a22 : generateId$
|
|
15367
|
+
generateId: (_a22 = options.generateId) != null ? _a22 : generateId$2,
|
|
15368
15368
|
supportedUrls: () => ({
|
|
15369
15369
|
"image/*": [/^https?:\/\/.*$/]
|
|
15370
15370
|
})
|
|
@@ -15398,7 +15398,7 @@ var googleErrorDataSchema = object({
|
|
|
15398
15398
|
status: string$1()
|
|
15399
15399
|
})
|
|
15400
15400
|
});
|
|
15401
|
-
var googleFailedResponseHandler = createJsonErrorResponseHandler$
|
|
15401
|
+
var googleFailedResponseHandler = createJsonErrorResponseHandler$2({
|
|
15402
15402
|
errorSchema: googleErrorDataSchema,
|
|
15403
15403
|
errorToMessage: (data) => data.error.message
|
|
15404
15404
|
});
|
|
@@ -15448,7 +15448,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
15448
15448
|
abortSignal,
|
|
15449
15449
|
providerOptions
|
|
15450
15450
|
}) {
|
|
15451
|
-
const googleOptions = await parseProviderOptions({
|
|
15451
|
+
const googleOptions = await parseProviderOptions$1({
|
|
15452
15452
|
provider: "google",
|
|
15453
15453
|
providerOptions,
|
|
15454
15454
|
schema: googleGenerativeAIEmbeddingProviderOptions
|
|
@@ -15461,7 +15461,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
15461
15461
|
values
|
|
15462
15462
|
});
|
|
15463
15463
|
}
|
|
15464
|
-
const mergedHeaders = combineHeaders$
|
|
15464
|
+
const mergedHeaders = combineHeaders$2(
|
|
15465
15465
|
await resolve(this.config.headers),
|
|
15466
15466
|
headers
|
|
15467
15467
|
);
|
|
@@ -15470,7 +15470,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
15470
15470
|
responseHeaders: responseHeaders2,
|
|
15471
15471
|
value: response2,
|
|
15472
15472
|
rawValue: rawValue2
|
|
15473
|
-
} = await postJsonToApi$
|
|
15473
|
+
} = await postJsonToApi$2({
|
|
15474
15474
|
url: `${this.config.baseURL}/models/${this.modelId}:embedContent`,
|
|
15475
15475
|
headers: mergedHeaders,
|
|
15476
15476
|
body: {
|
|
@@ -15482,7 +15482,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
15482
15482
|
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
|
15483
15483
|
},
|
|
15484
15484
|
failedResponseHandler: googleFailedResponseHandler,
|
|
15485
|
-
successfulResponseHandler: createJsonResponseHandler$
|
|
15485
|
+
successfulResponseHandler: createJsonResponseHandler$2(
|
|
15486
15486
|
googleGenerativeAISingleEmbeddingResponseSchema
|
|
15487
15487
|
),
|
|
15488
15488
|
abortSignal,
|
|
@@ -15498,7 +15498,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
15498
15498
|
responseHeaders,
|
|
15499
15499
|
value: response,
|
|
15500
15500
|
rawValue
|
|
15501
|
-
} = await postJsonToApi$
|
|
15501
|
+
} = await postJsonToApi$2({
|
|
15502
15502
|
url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
|
|
15503
15503
|
headers: mergedHeaders,
|
|
15504
15504
|
body: {
|
|
@@ -15510,7 +15510,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
15510
15510
|
}))
|
|
15511
15511
|
},
|
|
15512
15512
|
failedResponseHandler: googleFailedResponseHandler,
|
|
15513
|
-
successfulResponseHandler: createJsonResponseHandler$
|
|
15513
|
+
successfulResponseHandler: createJsonResponseHandler$2(
|
|
15514
15514
|
googleGenerativeAITextEmbeddingResponseSchema
|
|
15515
15515
|
),
|
|
15516
15516
|
abortSignal,
|
|
@@ -15661,7 +15661,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
15661
15661
|
} : {
|
|
15662
15662
|
inlineData: {
|
|
15663
15663
|
mimeType: mediaType,
|
|
15664
|
-
data: convertToBase64(part.data)
|
|
15664
|
+
data: convertToBase64$1(part.data)
|
|
15665
15665
|
}
|
|
15666
15666
|
}
|
|
15667
15667
|
);
|
|
@@ -15706,7 +15706,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
15706
15706
|
return {
|
|
15707
15707
|
inlineData: {
|
|
15708
15708
|
mimeType: part.mediaType,
|
|
15709
|
-
data: convertToBase64(part.data)
|
|
15709
|
+
data: convertToBase64$1(part.data)
|
|
15710
15710
|
}
|
|
15711
15711
|
};
|
|
15712
15712
|
}
|
|
@@ -15858,7 +15858,7 @@ var googleGenerativeAIProviderOptions = object({
|
|
|
15858
15858
|
*/
|
|
15859
15859
|
labels: record(string$1(), string$1()).optional()
|
|
15860
15860
|
});
|
|
15861
|
-
function prepareTools({
|
|
15861
|
+
function prepareTools$1({
|
|
15862
15862
|
tools,
|
|
15863
15863
|
toolChoice,
|
|
15864
15864
|
modelId
|
|
@@ -16052,7 +16052,7 @@ var groundingMetadataSchema = object({
|
|
|
16052
16052
|
object({})
|
|
16053
16053
|
]).nullish()
|
|
16054
16054
|
});
|
|
16055
|
-
var googleSearch = createProviderDefinedToolFactory({
|
|
16055
|
+
var googleSearch = createProviderDefinedToolFactory$1({
|
|
16056
16056
|
id: "google.google_search",
|
|
16057
16057
|
name: "google_search",
|
|
16058
16058
|
inputSchema: object({
|
|
@@ -16067,7 +16067,7 @@ var urlMetadataSchema = object({
|
|
|
16067
16067
|
var urlContextMetadataSchema = object({
|
|
16068
16068
|
urlMetadata: array(urlMetadataSchema)
|
|
16069
16069
|
});
|
|
16070
|
-
var urlContext = createProviderDefinedToolFactory({
|
|
16070
|
+
var urlContext = createProviderDefinedToolFactory$1({
|
|
16071
16071
|
id: "google.url_context",
|
|
16072
16072
|
name: "url_context",
|
|
16073
16073
|
inputSchema: object({})
|
|
@@ -16078,7 +16078,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
16078
16078
|
var _a10;
|
|
16079
16079
|
this.modelId = modelId;
|
|
16080
16080
|
this.config = config2;
|
|
16081
|
-
this.generateId = (_a10 = config2.generateId) != null ? _a10 : generateId$
|
|
16081
|
+
this.generateId = (_a10 = config2.generateId) != null ? _a10 : generateId$2;
|
|
16082
16082
|
}
|
|
16083
16083
|
get provider() {
|
|
16084
16084
|
return this.config.provider;
|
|
@@ -16104,7 +16104,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
16104
16104
|
}) {
|
|
16105
16105
|
var _a10, _b;
|
|
16106
16106
|
const warnings = [];
|
|
16107
|
-
const googleOptions = await parseProviderOptions({
|
|
16107
|
+
const googleOptions = await parseProviderOptions$1({
|
|
16108
16108
|
provider: "google",
|
|
16109
16109
|
providerOptions,
|
|
16110
16110
|
schema: googleGenerativeAIProviderOptions
|
|
@@ -16124,7 +16124,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
16124
16124
|
tools: googleTools2,
|
|
16125
16125
|
toolConfig: googleToolConfig,
|
|
16126
16126
|
toolWarnings
|
|
16127
|
-
} = prepareTools({
|
|
16127
|
+
} = prepareTools$1({
|
|
16128
16128
|
tools,
|
|
16129
16129
|
toolChoice,
|
|
16130
16130
|
modelId: this.modelId
|
|
@@ -16169,7 +16169,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
16169
16169
|
var _a10, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
16170
16170
|
const { args, warnings } = await this.getArgs(options);
|
|
16171
16171
|
const body = JSON.stringify(args);
|
|
16172
|
-
const mergedHeaders = combineHeaders$
|
|
16172
|
+
const mergedHeaders = combineHeaders$2(
|
|
16173
16173
|
await resolve(this.config.headers),
|
|
16174
16174
|
options.headers
|
|
16175
16175
|
);
|
|
@@ -16177,14 +16177,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
16177
16177
|
responseHeaders,
|
|
16178
16178
|
value: response,
|
|
16179
16179
|
rawValue: rawResponse
|
|
16180
|
-
} = await postJsonToApi$
|
|
16180
|
+
} = await postJsonToApi$2({
|
|
16181
16181
|
url: `${this.config.baseURL}/${getModelPath(
|
|
16182
16182
|
this.modelId
|
|
16183
16183
|
)}:generateContent`,
|
|
16184
16184
|
headers: mergedHeaders,
|
|
16185
16185
|
body: args,
|
|
16186
16186
|
failedResponseHandler: googleFailedResponseHandler,
|
|
16187
|
-
successfulResponseHandler: createJsonResponseHandler$
|
|
16187
|
+
successfulResponseHandler: createJsonResponseHandler$2(responseSchema),
|
|
16188
16188
|
abortSignal: options.abortSignal,
|
|
16189
16189
|
fetch: this.config.fetch
|
|
16190
16190
|
});
|
|
@@ -16279,18 +16279,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
16279
16279
|
async doStream(options) {
|
|
16280
16280
|
const { args, warnings } = await this.getArgs(options);
|
|
16281
16281
|
const body = JSON.stringify(args);
|
|
16282
|
-
const headers = combineHeaders$
|
|
16282
|
+
const headers = combineHeaders$2(
|
|
16283
16283
|
await resolve(this.config.headers),
|
|
16284
16284
|
options.headers
|
|
16285
16285
|
);
|
|
16286
|
-
const { responseHeaders, value: response } = await postJsonToApi$
|
|
16286
|
+
const { responseHeaders, value: response } = await postJsonToApi$2({
|
|
16287
16287
|
url: `${this.config.baseURL}/${getModelPath(
|
|
16288
16288
|
this.modelId
|
|
16289
16289
|
)}:streamGenerateContent?alt=sse`,
|
|
16290
16290
|
headers,
|
|
16291
16291
|
body: args,
|
|
16292
16292
|
failedResponseHandler: googleFailedResponseHandler,
|
|
16293
|
-
successfulResponseHandler: createEventSourceResponseHandler$
|
|
16293
|
+
successfulResponseHandler: createEventSourceResponseHandler$2(chunkSchema),
|
|
16294
16294
|
abortSignal: options.abortSignal,
|
|
16295
16295
|
fetch: this.config.fetch
|
|
16296
16296
|
});
|
|
@@ -16682,155 +16682,1556 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
16682
16682
|
get provider() {
|
|
16683
16683
|
return this.config.provider;
|
|
16684
16684
|
}
|
|
16685
|
-
async doGenerate(options) {
|
|
16686
|
-
var _a10, _b, _c;
|
|
16687
|
-
const {
|
|
16688
|
-
prompt,
|
|
16689
|
-
n = 1,
|
|
16690
|
-
size = "1024x1024",
|
|
16691
|
-
aspectRatio = "1:1",
|
|
16692
|
-
seed,
|
|
16693
|
-
providerOptions,
|
|
16694
|
-
headers,
|
|
16695
|
-
abortSignal
|
|
16696
|
-
} = options;
|
|
16685
|
+
async doGenerate(options) {
|
|
16686
|
+
var _a10, _b, _c;
|
|
16687
|
+
const {
|
|
16688
|
+
prompt,
|
|
16689
|
+
n = 1,
|
|
16690
|
+
size = "1024x1024",
|
|
16691
|
+
aspectRatio = "1:1",
|
|
16692
|
+
seed,
|
|
16693
|
+
providerOptions,
|
|
16694
|
+
headers,
|
|
16695
|
+
abortSignal
|
|
16696
|
+
} = options;
|
|
16697
|
+
const warnings = [];
|
|
16698
|
+
if (size != null) {
|
|
16699
|
+
warnings.push({
|
|
16700
|
+
type: "unsupported-setting",
|
|
16701
|
+
setting: "size",
|
|
16702
|
+
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
16703
|
+
});
|
|
16704
|
+
}
|
|
16705
|
+
if (seed != null) {
|
|
16706
|
+
warnings.push({
|
|
16707
|
+
type: "unsupported-setting",
|
|
16708
|
+
setting: "seed",
|
|
16709
|
+
details: "This model does not support the `seed` option through this provider."
|
|
16710
|
+
});
|
|
16711
|
+
}
|
|
16712
|
+
const googleOptions = await parseProviderOptions$1({
|
|
16713
|
+
provider: "google",
|
|
16714
|
+
providerOptions,
|
|
16715
|
+
schema: googleImageProviderOptionsSchema
|
|
16716
|
+
});
|
|
16717
|
+
const currentDate = (_c = (_b = (_a10 = this.config._internal) == null ? void 0 : _a10.currentDate) == null ? void 0 : _b.call(_a10)) != null ? _c : /* @__PURE__ */ new Date();
|
|
16718
|
+
const parameters = {
|
|
16719
|
+
sampleCount: n
|
|
16720
|
+
};
|
|
16721
|
+
if (aspectRatio != null) {
|
|
16722
|
+
parameters.aspectRatio = aspectRatio;
|
|
16723
|
+
}
|
|
16724
|
+
if (googleOptions) {
|
|
16725
|
+
Object.assign(parameters, googleOptions);
|
|
16726
|
+
}
|
|
16727
|
+
const body = {
|
|
16728
|
+
instances: [{ prompt }],
|
|
16729
|
+
parameters
|
|
16730
|
+
};
|
|
16731
|
+
const { responseHeaders, value: response } = await postJsonToApi$2({
|
|
16732
|
+
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
16733
|
+
headers: combineHeaders$2(await resolve(this.config.headers), headers),
|
|
16734
|
+
body,
|
|
16735
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
16736
|
+
successfulResponseHandler: createJsonResponseHandler$2(
|
|
16737
|
+
googleImageResponseSchema
|
|
16738
|
+
),
|
|
16739
|
+
abortSignal,
|
|
16740
|
+
fetch: this.config.fetch
|
|
16741
|
+
});
|
|
16742
|
+
return {
|
|
16743
|
+
images: response.predictions.map(
|
|
16744
|
+
(p) => p.bytesBase64Encoded
|
|
16745
|
+
),
|
|
16746
|
+
warnings: warnings != null ? warnings : [],
|
|
16747
|
+
providerMetadata: {
|
|
16748
|
+
google: {
|
|
16749
|
+
images: response.predictions.map((prediction) => ({
|
|
16750
|
+
// Add any prediction-specific metadata here
|
|
16751
|
+
}))
|
|
16752
|
+
}
|
|
16753
|
+
},
|
|
16754
|
+
response: {
|
|
16755
|
+
timestamp: currentDate,
|
|
16756
|
+
modelId: this.modelId,
|
|
16757
|
+
headers: responseHeaders
|
|
16758
|
+
}
|
|
16759
|
+
};
|
|
16760
|
+
}
|
|
16761
|
+
};
|
|
16762
|
+
var googleImageResponseSchema = object({
|
|
16763
|
+
predictions: array(object({ bytesBase64Encoded: string$1() })).default([])
|
|
16764
|
+
});
|
|
16765
|
+
var googleImageProviderOptionsSchema = object({
|
|
16766
|
+
personGeneration: _enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
16767
|
+
aspectRatio: _enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
|
|
16768
|
+
});
|
|
16769
|
+
function createGoogleGenerativeAI(options = {}) {
|
|
16770
|
+
var _a10;
|
|
16771
|
+
const baseURL = (_a10 = withoutTrailingSlash$2(options.baseURL)) != null ? _a10 : "https://generativelanguage.googleapis.com/v1beta";
|
|
16772
|
+
const getHeaders = () => ({
|
|
16773
|
+
"x-goog-api-key": loadApiKey$2({
|
|
16774
|
+
apiKey: options.apiKey,
|
|
16775
|
+
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
16776
|
+
description: "Google Generative AI"
|
|
16777
|
+
}),
|
|
16778
|
+
...options.headers
|
|
16779
|
+
});
|
|
16780
|
+
const createChatModel = (modelId) => {
|
|
16781
|
+
var _a22;
|
|
16782
|
+
return new GoogleGenerativeAILanguageModel(modelId, {
|
|
16783
|
+
provider: "google.generative-ai",
|
|
16784
|
+
baseURL,
|
|
16785
|
+
headers: getHeaders,
|
|
16786
|
+
generateId: (_a22 = options.generateId) != null ? _a22 : generateId$2,
|
|
16787
|
+
supportedUrls: () => ({
|
|
16788
|
+
"*": [
|
|
16789
|
+
// Google Generative Language "files" endpoint
|
|
16790
|
+
// e.g. https://generativelanguage.googleapis.com/v1beta/files/...
|
|
16791
|
+
new RegExp(`^${baseURL}/files/.*$`),
|
|
16792
|
+
// YouTube URLs (public or unlisted videos)
|
|
16793
|
+
new RegExp(
|
|
16794
|
+
`^https://(?:www\\.)?youtube\\.com/watch\\?v=[\\w-]+(?:&[\\w=&.-]*)?$`
|
|
16795
|
+
),
|
|
16796
|
+
new RegExp(`^https://youtu\\.be/[\\w-]+(?:\\?[\\w=&.-]*)?$`)
|
|
16797
|
+
]
|
|
16798
|
+
}),
|
|
16799
|
+
fetch: options.fetch
|
|
16800
|
+
});
|
|
16801
|
+
};
|
|
16802
|
+
const createEmbeddingModel = (modelId) => new GoogleGenerativeAIEmbeddingModel(modelId, {
|
|
16803
|
+
provider: "google.generative-ai",
|
|
16804
|
+
baseURL,
|
|
16805
|
+
headers: getHeaders,
|
|
16806
|
+
fetch: options.fetch
|
|
16807
|
+
});
|
|
16808
|
+
const createImageModel = (modelId, settings = {}) => new GoogleGenerativeAIImageModel(modelId, settings, {
|
|
16809
|
+
provider: "google.generative-ai",
|
|
16810
|
+
baseURL,
|
|
16811
|
+
headers: getHeaders,
|
|
16812
|
+
fetch: options.fetch
|
|
16813
|
+
});
|
|
16814
|
+
const provider = function(modelId) {
|
|
16815
|
+
if (new.target) {
|
|
16816
|
+
throw new Error(
|
|
16817
|
+
"The Google Generative AI model function cannot be called with the new keyword."
|
|
16818
|
+
);
|
|
16819
|
+
}
|
|
16820
|
+
return createChatModel(modelId);
|
|
16821
|
+
};
|
|
16822
|
+
provider.languageModel = createChatModel;
|
|
16823
|
+
provider.chat = createChatModel;
|
|
16824
|
+
provider.generativeAI = createChatModel;
|
|
16825
|
+
provider.embedding = createEmbeddingModel;
|
|
16826
|
+
provider.textEmbedding = createEmbeddingModel;
|
|
16827
|
+
provider.textEmbeddingModel = createEmbeddingModel;
|
|
16828
|
+
provider.image = createImageModel;
|
|
16829
|
+
provider.imageModel = createImageModel;
|
|
16830
|
+
provider.tools = googleTools;
|
|
16831
|
+
return provider;
|
|
16832
|
+
}
|
|
16833
|
+
createGoogleGenerativeAI();
|
|
16834
|
+
function combineHeaders$1(...headers) {
|
|
16835
|
+
return headers.reduce(
|
|
16836
|
+
(combinedHeaders, currentHeaders) => ({
|
|
16837
|
+
...combinedHeaders,
|
|
16838
|
+
...currentHeaders != null ? currentHeaders : {}
|
|
16839
|
+
}),
|
|
16840
|
+
{}
|
|
16841
|
+
);
|
|
16842
|
+
}
|
|
16843
|
+
function extractResponseHeaders$1(response) {
|
|
16844
|
+
return Object.fromEntries([...response.headers]);
|
|
16845
|
+
}
|
|
16846
|
+
var createIdGenerator$1 = ({
|
|
16847
|
+
prefix,
|
|
16848
|
+
size = 16,
|
|
16849
|
+
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
16850
|
+
separator = "-"
|
|
16851
|
+
} = {}) => {
|
|
16852
|
+
const generator = () => {
|
|
16853
|
+
const alphabetLength = alphabet.length;
|
|
16854
|
+
const chars = new Array(size);
|
|
16855
|
+
for (let i = 0; i < size; i++) {
|
|
16856
|
+
chars[i] = alphabet[Math.random() * alphabetLength | 0];
|
|
16857
|
+
}
|
|
16858
|
+
return chars.join("");
|
|
16859
|
+
};
|
|
16860
|
+
if (prefix == null) {
|
|
16861
|
+
return generator;
|
|
16862
|
+
}
|
|
16863
|
+
if (alphabet.includes(separator)) {
|
|
16864
|
+
throw new InvalidArgumentError$1({
|
|
16865
|
+
argument: "separator",
|
|
16866
|
+
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
16867
|
+
});
|
|
16868
|
+
}
|
|
16869
|
+
return () => `${prefix}${separator}${generator()}`;
|
|
16870
|
+
};
|
|
16871
|
+
var generateId$1 = createIdGenerator$1();
|
|
16872
|
+
function isAbortError$1(error2) {
|
|
16873
|
+
return (error2 instanceof Error || error2 instanceof DOMException) && (error2.name === "AbortError" || error2.name === "ResponseAborted" || // Next.js
|
|
16874
|
+
error2.name === "TimeoutError");
|
|
16875
|
+
}
|
|
16876
|
+
var FETCH_FAILED_ERROR_MESSAGES$1 = ["fetch failed", "failed to fetch"];
|
|
16877
|
+
function handleFetchError$1({
|
|
16878
|
+
error: error2,
|
|
16879
|
+
url: url2,
|
|
16880
|
+
requestBodyValues
|
|
16881
|
+
}) {
|
|
16882
|
+
if (isAbortError$1(error2)) {
|
|
16883
|
+
return error2;
|
|
16884
|
+
}
|
|
16885
|
+
if (error2 instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES$1.includes(error2.message.toLowerCase())) {
|
|
16886
|
+
const cause = error2.cause;
|
|
16887
|
+
if (cause != null) {
|
|
16888
|
+
return new APICallError$1({
|
|
16889
|
+
message: `Cannot connect to API: ${cause.message}`,
|
|
16890
|
+
cause,
|
|
16891
|
+
url: url2,
|
|
16892
|
+
requestBodyValues,
|
|
16893
|
+
isRetryable: true
|
|
16894
|
+
// retry when network error
|
|
16895
|
+
});
|
|
16896
|
+
}
|
|
16897
|
+
}
|
|
16898
|
+
return error2;
|
|
16899
|
+
}
|
|
16900
|
+
function removeUndefinedEntries$1(record2) {
|
|
16901
|
+
return Object.fromEntries(
|
|
16902
|
+
Object.entries(record2).filter(([_key, value]) => value != null)
|
|
16903
|
+
);
|
|
16904
|
+
}
|
|
16905
|
+
function loadApiKey$1({
|
|
16906
|
+
apiKey,
|
|
16907
|
+
environmentVariableName,
|
|
16908
|
+
apiKeyParameterName = "apiKey",
|
|
16909
|
+
description
|
|
16910
|
+
}) {
|
|
16911
|
+
if (typeof apiKey === "string") {
|
|
16912
|
+
return apiKey;
|
|
16913
|
+
}
|
|
16914
|
+
if (apiKey != null) {
|
|
16915
|
+
throw new LoadAPIKeyError$1({
|
|
16916
|
+
message: `${description} API key must be a string.`
|
|
16917
|
+
});
|
|
16918
|
+
}
|
|
16919
|
+
if (typeof process === "undefined") {
|
|
16920
|
+
throw new LoadAPIKeyError$1({
|
|
16921
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
16922
|
+
});
|
|
16923
|
+
}
|
|
16924
|
+
apiKey = process.env[environmentVariableName];
|
|
16925
|
+
if (apiKey == null) {
|
|
16926
|
+
throw new LoadAPIKeyError$1({
|
|
16927
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
16928
|
+
});
|
|
16929
|
+
}
|
|
16930
|
+
if (typeof apiKey !== "string") {
|
|
16931
|
+
throw new LoadAPIKeyError$1({
|
|
16932
|
+
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
16933
|
+
});
|
|
16934
|
+
}
|
|
16935
|
+
return apiKey;
|
|
16936
|
+
}
|
|
16937
|
+
function mediaTypeToExtension(mediaType) {
|
|
16938
|
+
var _a10;
|
|
16939
|
+
const [_type, subtype = ""] = mediaType.toLowerCase().split("/");
|
|
16940
|
+
return (_a10 = {
|
|
16941
|
+
mpeg: "mp3",
|
|
16942
|
+
"x-wav": "wav",
|
|
16943
|
+
opus: "ogg",
|
|
16944
|
+
mp4: "m4a",
|
|
16945
|
+
"x-m4a": "m4a"
|
|
16946
|
+
}[subtype]) != null ? _a10 : subtype;
|
|
16947
|
+
}
|
|
16948
|
+
var suspectProtoRx$1 = /"__proto__"\s*:/;
|
|
16949
|
+
var suspectConstructorRx$1 = /"constructor"\s*:/;
|
|
16950
|
+
function _parse$1(text2) {
|
|
16951
|
+
const obj = JSON.parse(text2);
|
|
16952
|
+
if (obj === null || typeof obj !== "object") {
|
|
16953
|
+
return obj;
|
|
16954
|
+
}
|
|
16955
|
+
if (suspectProtoRx$1.test(text2) === false && suspectConstructorRx$1.test(text2) === false) {
|
|
16956
|
+
return obj;
|
|
16957
|
+
}
|
|
16958
|
+
return filter$1(obj);
|
|
16959
|
+
}
|
|
16960
|
+
function filter$1(obj) {
|
|
16961
|
+
let next = [obj];
|
|
16962
|
+
while (next.length) {
|
|
16963
|
+
const nodes = next;
|
|
16964
|
+
next = [];
|
|
16965
|
+
for (const node of nodes) {
|
|
16966
|
+
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
16967
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
16968
|
+
}
|
|
16969
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
16970
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
16971
|
+
}
|
|
16972
|
+
for (const key in node) {
|
|
16973
|
+
const value = node[key];
|
|
16974
|
+
if (value && typeof value === "object") {
|
|
16975
|
+
next.push(value);
|
|
16976
|
+
}
|
|
16977
|
+
}
|
|
16978
|
+
}
|
|
16979
|
+
}
|
|
16980
|
+
return obj;
|
|
16981
|
+
}
|
|
16982
|
+
function secureJsonParse$1(text2) {
|
|
16983
|
+
const { stackTraceLimit } = Error;
|
|
16984
|
+
Error.stackTraceLimit = 0;
|
|
16985
|
+
try {
|
|
16986
|
+
return _parse$1(text2);
|
|
16987
|
+
} finally {
|
|
16988
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
16989
|
+
}
|
|
16990
|
+
}
|
|
16991
|
+
var validatorSymbol$1 = Symbol.for("vercel.ai.validator");
|
|
16992
|
+
function validator$1(validate) {
|
|
16993
|
+
return { [validatorSymbol$1]: true, validate };
|
|
16994
|
+
}
|
|
16995
|
+
function isValidator$1(value) {
|
|
16996
|
+
return typeof value === "object" && value !== null && validatorSymbol$1 in value && value[validatorSymbol$1] === true && "validate" in value;
|
|
16997
|
+
}
|
|
16998
|
+
function asValidator$1(value) {
|
|
16999
|
+
return isValidator$1(value) ? value : standardSchemaValidator$1(value);
|
|
17000
|
+
}
|
|
17001
|
+
function standardSchemaValidator$1(standardSchema) {
|
|
17002
|
+
return validator$1(async (value) => {
|
|
17003
|
+
const result = await standardSchema["~standard"].validate(value);
|
|
17004
|
+
return result.issues == null ? { success: true, value: result.value } : {
|
|
17005
|
+
success: false,
|
|
17006
|
+
error: new TypeValidationError$1({
|
|
17007
|
+
value,
|
|
17008
|
+
cause: result.issues
|
|
17009
|
+
})
|
|
17010
|
+
};
|
|
17011
|
+
});
|
|
17012
|
+
}
|
|
17013
|
+
async function validateTypes$1({
|
|
17014
|
+
value,
|
|
17015
|
+
schema
|
|
17016
|
+
}) {
|
|
17017
|
+
const result = await safeValidateTypes$1({ value, schema });
|
|
17018
|
+
if (!result.success) {
|
|
17019
|
+
throw TypeValidationError$1.wrap({ value, cause: result.error });
|
|
17020
|
+
}
|
|
17021
|
+
return result.value;
|
|
17022
|
+
}
|
|
17023
|
+
async function safeValidateTypes$1({
|
|
17024
|
+
value,
|
|
17025
|
+
schema
|
|
17026
|
+
}) {
|
|
17027
|
+
const validator2 = asValidator$1(schema);
|
|
17028
|
+
try {
|
|
17029
|
+
if (validator2.validate == null) {
|
|
17030
|
+
return { success: true, value, rawValue: value };
|
|
17031
|
+
}
|
|
17032
|
+
const result = await validator2.validate(value);
|
|
17033
|
+
if (result.success) {
|
|
17034
|
+
return { success: true, value: result.value, rawValue: value };
|
|
17035
|
+
}
|
|
17036
|
+
return {
|
|
17037
|
+
success: false,
|
|
17038
|
+
error: TypeValidationError$1.wrap({ value, cause: result.error }),
|
|
17039
|
+
rawValue: value
|
|
17040
|
+
};
|
|
17041
|
+
} catch (error2) {
|
|
17042
|
+
return {
|
|
17043
|
+
success: false,
|
|
17044
|
+
error: TypeValidationError$1.wrap({ value, cause: error2 }),
|
|
17045
|
+
rawValue: value
|
|
17046
|
+
};
|
|
17047
|
+
}
|
|
17048
|
+
}
|
|
17049
|
+
async function parseJSON$1({
|
|
17050
|
+
text: text2,
|
|
17051
|
+
schema
|
|
17052
|
+
}) {
|
|
17053
|
+
try {
|
|
17054
|
+
const value = secureJsonParse$1(text2);
|
|
17055
|
+
if (schema == null) {
|
|
17056
|
+
return value;
|
|
17057
|
+
}
|
|
17058
|
+
return validateTypes$1({ value, schema });
|
|
17059
|
+
} catch (error2) {
|
|
17060
|
+
if (JSONParseError$1.isInstance(error2) || TypeValidationError$1.isInstance(error2)) {
|
|
17061
|
+
throw error2;
|
|
17062
|
+
}
|
|
17063
|
+
throw new JSONParseError$1({ text: text2, cause: error2 });
|
|
17064
|
+
}
|
|
17065
|
+
}
|
|
17066
|
+
async function safeParseJSON$1({
|
|
17067
|
+
text: text2,
|
|
17068
|
+
schema
|
|
17069
|
+
}) {
|
|
17070
|
+
try {
|
|
17071
|
+
const value = secureJsonParse$1(text2);
|
|
17072
|
+
if (schema == null) {
|
|
17073
|
+
return { success: true, value, rawValue: value };
|
|
17074
|
+
}
|
|
17075
|
+
return await safeValidateTypes$1({ value, schema });
|
|
17076
|
+
} catch (error2) {
|
|
17077
|
+
return {
|
|
17078
|
+
success: false,
|
|
17079
|
+
error: JSONParseError$1.isInstance(error2) ? error2 : new JSONParseError$1({ text: text2, cause: error2 }),
|
|
17080
|
+
rawValue: void 0
|
|
17081
|
+
};
|
|
17082
|
+
}
|
|
17083
|
+
}
|
|
17084
|
+
function isParsableJson$1(input) {
|
|
17085
|
+
try {
|
|
17086
|
+
secureJsonParse$1(input);
|
|
17087
|
+
return true;
|
|
17088
|
+
} catch (e) {
|
|
17089
|
+
return false;
|
|
17090
|
+
}
|
|
17091
|
+
}
|
|
17092
|
+
function parseJsonEventStream$1({
|
|
17093
|
+
stream,
|
|
17094
|
+
schema
|
|
17095
|
+
}) {
|
|
17096
|
+
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream$1()).pipeThrough(
|
|
17097
|
+
new TransformStream({
|
|
17098
|
+
async transform({ data }, controller) {
|
|
17099
|
+
if (data === "[DONE]") {
|
|
17100
|
+
return;
|
|
17101
|
+
}
|
|
17102
|
+
controller.enqueue(await safeParseJSON$1({ text: data, schema }));
|
|
17103
|
+
}
|
|
17104
|
+
})
|
|
17105
|
+
);
|
|
17106
|
+
}
|
|
17107
|
+
async function parseProviderOptions({
|
|
17108
|
+
provider,
|
|
17109
|
+
providerOptions,
|
|
17110
|
+
schema
|
|
17111
|
+
}) {
|
|
17112
|
+
if ((providerOptions == null ? void 0 : providerOptions[provider]) == null) {
|
|
17113
|
+
return void 0;
|
|
17114
|
+
}
|
|
17115
|
+
const parsedProviderOptions = await safeValidateTypes$1({
|
|
17116
|
+
value: providerOptions[provider],
|
|
17117
|
+
schema
|
|
17118
|
+
});
|
|
17119
|
+
if (!parsedProviderOptions.success) {
|
|
17120
|
+
throw new InvalidArgumentError$1({
|
|
17121
|
+
argument: "providerOptions",
|
|
17122
|
+
message: `invalid ${provider} provider options`,
|
|
17123
|
+
cause: parsedProviderOptions.error
|
|
17124
|
+
});
|
|
17125
|
+
}
|
|
17126
|
+
return parsedProviderOptions.value;
|
|
17127
|
+
}
|
|
17128
|
+
var getOriginalFetch2$1 = () => globalThis.fetch;
|
|
17129
|
+
var postJsonToApi$1 = async ({
|
|
17130
|
+
url: url2,
|
|
17131
|
+
headers,
|
|
17132
|
+
body,
|
|
17133
|
+
failedResponseHandler,
|
|
17134
|
+
successfulResponseHandler,
|
|
17135
|
+
abortSignal,
|
|
17136
|
+
fetch: fetch2
|
|
17137
|
+
}) => postToApi$1({
|
|
17138
|
+
url: url2,
|
|
17139
|
+
headers: {
|
|
17140
|
+
"Content-Type": "application/json",
|
|
17141
|
+
...headers
|
|
17142
|
+
},
|
|
17143
|
+
body: {
|
|
17144
|
+
content: JSON.stringify(body),
|
|
17145
|
+
values: body
|
|
17146
|
+
},
|
|
17147
|
+
failedResponseHandler,
|
|
17148
|
+
successfulResponseHandler,
|
|
17149
|
+
abortSignal,
|
|
17150
|
+
fetch: fetch2
|
|
17151
|
+
});
|
|
17152
|
+
var postFormDataToApi = async ({
|
|
17153
|
+
url: url2,
|
|
17154
|
+
headers,
|
|
17155
|
+
formData,
|
|
17156
|
+
failedResponseHandler,
|
|
17157
|
+
successfulResponseHandler,
|
|
17158
|
+
abortSignal,
|
|
17159
|
+
fetch: fetch2
|
|
17160
|
+
}) => postToApi$1({
|
|
17161
|
+
url: url2,
|
|
17162
|
+
headers,
|
|
17163
|
+
body: {
|
|
17164
|
+
content: formData,
|
|
17165
|
+
values: Object.fromEntries(formData.entries())
|
|
17166
|
+
},
|
|
17167
|
+
failedResponseHandler,
|
|
17168
|
+
successfulResponseHandler,
|
|
17169
|
+
abortSignal,
|
|
17170
|
+
fetch: fetch2
|
|
17171
|
+
});
|
|
17172
|
+
var postToApi$1 = async ({
|
|
17173
|
+
url: url2,
|
|
17174
|
+
headers = {},
|
|
17175
|
+
body,
|
|
17176
|
+
successfulResponseHandler,
|
|
17177
|
+
failedResponseHandler,
|
|
17178
|
+
abortSignal,
|
|
17179
|
+
fetch: fetch2 = getOriginalFetch2$1()
|
|
17180
|
+
}) => {
|
|
17181
|
+
try {
|
|
17182
|
+
const response = await fetch2(url2, {
|
|
17183
|
+
method: "POST",
|
|
17184
|
+
headers: removeUndefinedEntries$1(headers),
|
|
17185
|
+
body: body.content,
|
|
17186
|
+
signal: abortSignal
|
|
17187
|
+
});
|
|
17188
|
+
const responseHeaders = extractResponseHeaders$1(response);
|
|
17189
|
+
if (!response.ok) {
|
|
17190
|
+
let errorInformation;
|
|
17191
|
+
try {
|
|
17192
|
+
errorInformation = await failedResponseHandler({
|
|
17193
|
+
response,
|
|
17194
|
+
url: url2,
|
|
17195
|
+
requestBodyValues: body.values
|
|
17196
|
+
});
|
|
17197
|
+
} catch (error2) {
|
|
17198
|
+
if (isAbortError$1(error2) || APICallError$1.isInstance(error2)) {
|
|
17199
|
+
throw error2;
|
|
17200
|
+
}
|
|
17201
|
+
throw new APICallError$1({
|
|
17202
|
+
message: "Failed to process error response",
|
|
17203
|
+
cause: error2,
|
|
17204
|
+
statusCode: response.status,
|
|
17205
|
+
url: url2,
|
|
17206
|
+
responseHeaders,
|
|
17207
|
+
requestBodyValues: body.values
|
|
17208
|
+
});
|
|
17209
|
+
}
|
|
17210
|
+
throw errorInformation.value;
|
|
17211
|
+
}
|
|
17212
|
+
try {
|
|
17213
|
+
return await successfulResponseHandler({
|
|
17214
|
+
response,
|
|
17215
|
+
url: url2,
|
|
17216
|
+
requestBodyValues: body.values
|
|
17217
|
+
});
|
|
17218
|
+
} catch (error2) {
|
|
17219
|
+
if (error2 instanceof Error) {
|
|
17220
|
+
if (isAbortError$1(error2) || APICallError$1.isInstance(error2)) {
|
|
17221
|
+
throw error2;
|
|
17222
|
+
}
|
|
17223
|
+
}
|
|
17224
|
+
throw new APICallError$1({
|
|
17225
|
+
message: "Failed to process successful response",
|
|
17226
|
+
cause: error2,
|
|
17227
|
+
statusCode: response.status,
|
|
17228
|
+
url: url2,
|
|
17229
|
+
responseHeaders,
|
|
17230
|
+
requestBodyValues: body.values
|
|
17231
|
+
});
|
|
17232
|
+
}
|
|
17233
|
+
} catch (error2) {
|
|
17234
|
+
throw handleFetchError$1({ error: error2, url: url2, requestBodyValues: body.values });
|
|
17235
|
+
}
|
|
17236
|
+
};
|
|
17237
|
+
function tool(tool2) {
|
|
17238
|
+
return tool2;
|
|
17239
|
+
}
|
|
17240
|
+
function createProviderDefinedToolFactory({
|
|
17241
|
+
id: id2,
|
|
17242
|
+
name: name8,
|
|
17243
|
+
inputSchema
|
|
17244
|
+
}) {
|
|
17245
|
+
return ({
|
|
17246
|
+
execute,
|
|
17247
|
+
outputSchema,
|
|
17248
|
+
toModelOutput,
|
|
17249
|
+
onInputStart,
|
|
17250
|
+
onInputDelta,
|
|
17251
|
+
onInputAvailable,
|
|
17252
|
+
...args
|
|
17253
|
+
}) => tool({
|
|
17254
|
+
type: "provider-defined",
|
|
17255
|
+
id: id2,
|
|
17256
|
+
name: name8,
|
|
17257
|
+
args,
|
|
17258
|
+
inputSchema,
|
|
17259
|
+
outputSchema,
|
|
17260
|
+
execute,
|
|
17261
|
+
toModelOutput,
|
|
17262
|
+
onInputStart,
|
|
17263
|
+
onInputDelta,
|
|
17264
|
+
onInputAvailable
|
|
17265
|
+
});
|
|
17266
|
+
}
|
|
17267
|
+
var createJsonErrorResponseHandler$1 = ({
|
|
17268
|
+
errorSchema,
|
|
17269
|
+
errorToMessage,
|
|
17270
|
+
isRetryable
|
|
17271
|
+
}) => async ({ response, url: url2, requestBodyValues }) => {
|
|
17272
|
+
const responseBody = await response.text();
|
|
17273
|
+
const responseHeaders = extractResponseHeaders$1(response);
|
|
17274
|
+
if (responseBody.trim() === "") {
|
|
17275
|
+
return {
|
|
17276
|
+
responseHeaders,
|
|
17277
|
+
value: new APICallError$1({
|
|
17278
|
+
message: response.statusText,
|
|
17279
|
+
url: url2,
|
|
17280
|
+
requestBodyValues,
|
|
17281
|
+
statusCode: response.status,
|
|
17282
|
+
responseHeaders,
|
|
17283
|
+
responseBody,
|
|
17284
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
17285
|
+
})
|
|
17286
|
+
};
|
|
17287
|
+
}
|
|
17288
|
+
try {
|
|
17289
|
+
const parsedError = await parseJSON$1({
|
|
17290
|
+
text: responseBody,
|
|
17291
|
+
schema: errorSchema
|
|
17292
|
+
});
|
|
17293
|
+
return {
|
|
17294
|
+
responseHeaders,
|
|
17295
|
+
value: new APICallError$1({
|
|
17296
|
+
message: errorToMessage(parsedError),
|
|
17297
|
+
url: url2,
|
|
17298
|
+
requestBodyValues,
|
|
17299
|
+
statusCode: response.status,
|
|
17300
|
+
responseHeaders,
|
|
17301
|
+
responseBody,
|
|
17302
|
+
data: parsedError,
|
|
17303
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
|
17304
|
+
})
|
|
17305
|
+
};
|
|
17306
|
+
} catch (parseError) {
|
|
17307
|
+
return {
|
|
17308
|
+
responseHeaders,
|
|
17309
|
+
value: new APICallError$1({
|
|
17310
|
+
message: response.statusText,
|
|
17311
|
+
url: url2,
|
|
17312
|
+
requestBodyValues,
|
|
17313
|
+
statusCode: response.status,
|
|
17314
|
+
responseHeaders,
|
|
17315
|
+
responseBody,
|
|
17316
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
17317
|
+
})
|
|
17318
|
+
};
|
|
17319
|
+
}
|
|
17320
|
+
};
|
|
17321
|
+
var createEventSourceResponseHandler$1 = (chunkSchema2) => async ({ response }) => {
|
|
17322
|
+
const responseHeaders = extractResponseHeaders$1(response);
|
|
17323
|
+
if (response.body == null) {
|
|
17324
|
+
throw new EmptyResponseBodyError$1({});
|
|
17325
|
+
}
|
|
17326
|
+
return {
|
|
17327
|
+
responseHeaders,
|
|
17328
|
+
value: parseJsonEventStream$1({
|
|
17329
|
+
stream: response.body,
|
|
17330
|
+
schema: chunkSchema2
|
|
17331
|
+
})
|
|
17332
|
+
};
|
|
17333
|
+
};
|
|
17334
|
+
var createJsonResponseHandler$1 = (responseSchema2) => async ({ response, url: url2, requestBodyValues }) => {
|
|
17335
|
+
const responseBody = await response.text();
|
|
17336
|
+
const parsedResult = await safeParseJSON$1({
|
|
17337
|
+
text: responseBody,
|
|
17338
|
+
schema: responseSchema2
|
|
17339
|
+
});
|
|
17340
|
+
const responseHeaders = extractResponseHeaders$1(response);
|
|
17341
|
+
if (!parsedResult.success) {
|
|
17342
|
+
throw new APICallError$1({
|
|
17343
|
+
message: "Invalid JSON response",
|
|
17344
|
+
cause: parsedResult.error,
|
|
17345
|
+
statusCode: response.status,
|
|
17346
|
+
responseHeaders,
|
|
17347
|
+
responseBody,
|
|
17348
|
+
url: url2,
|
|
17349
|
+
requestBodyValues
|
|
17350
|
+
});
|
|
17351
|
+
}
|
|
17352
|
+
return {
|
|
17353
|
+
responseHeaders,
|
|
17354
|
+
value: parsedResult.value,
|
|
17355
|
+
rawValue: parsedResult.rawValue
|
|
17356
|
+
};
|
|
17357
|
+
};
|
|
17358
|
+
new Set(
|
|
17359
|
+
"ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
|
|
17360
|
+
);
|
|
17361
|
+
var { btoa: btoa$2, atob: atob$1 } = globalThis;
|
|
17362
|
+
function convertBase64ToUint8Array(base64String) {
|
|
17363
|
+
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
17364
|
+
const latin1string = atob$1(base64Url);
|
|
17365
|
+
return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
|
|
17366
|
+
}
|
|
17367
|
+
function convertUint8ArrayToBase64$1(array2) {
|
|
17368
|
+
let latin1string = "";
|
|
17369
|
+
for (let i = 0; i < array2.length; i++) {
|
|
17370
|
+
latin1string += String.fromCodePoint(array2[i]);
|
|
17371
|
+
}
|
|
17372
|
+
return btoa$2(latin1string);
|
|
17373
|
+
}
|
|
17374
|
+
function convertToBase64(value) {
|
|
17375
|
+
return value instanceof Uint8Array ? convertUint8ArrayToBase64$1(value) : value;
|
|
17376
|
+
}
|
|
17377
|
+
function withoutTrailingSlash$1(url2) {
|
|
17378
|
+
return url2 == null ? void 0 : url2.replace(/\/$/, "");
|
|
17379
|
+
}
|
|
17380
|
+
function convertToGroqChatMessages(prompt) {
|
|
17381
|
+
const messages = [];
|
|
17382
|
+
for (const { role, content } of prompt) {
|
|
17383
|
+
switch (role) {
|
|
17384
|
+
case "system": {
|
|
17385
|
+
messages.push({ role: "system", content });
|
|
17386
|
+
break;
|
|
17387
|
+
}
|
|
17388
|
+
case "user": {
|
|
17389
|
+
if (content.length === 1 && content[0].type === "text") {
|
|
17390
|
+
messages.push({ role: "user", content: content[0].text });
|
|
17391
|
+
break;
|
|
17392
|
+
}
|
|
17393
|
+
messages.push({
|
|
17394
|
+
role: "user",
|
|
17395
|
+
content: content.map((part) => {
|
|
17396
|
+
switch (part.type) {
|
|
17397
|
+
case "text": {
|
|
17398
|
+
return { type: "text", text: part.text };
|
|
17399
|
+
}
|
|
17400
|
+
case "file": {
|
|
17401
|
+
if (!part.mediaType.startsWith("image/")) {
|
|
17402
|
+
throw new UnsupportedFunctionalityError$1({
|
|
17403
|
+
functionality: "Non-image file content parts"
|
|
17404
|
+
});
|
|
17405
|
+
}
|
|
17406
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
17407
|
+
return {
|
|
17408
|
+
type: "image_url",
|
|
17409
|
+
image_url: {
|
|
17410
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
17411
|
+
}
|
|
17412
|
+
};
|
|
17413
|
+
}
|
|
17414
|
+
}
|
|
17415
|
+
})
|
|
17416
|
+
});
|
|
17417
|
+
break;
|
|
17418
|
+
}
|
|
17419
|
+
case "assistant": {
|
|
17420
|
+
let text2 = "";
|
|
17421
|
+
let reasoning = "";
|
|
17422
|
+
const toolCalls = [];
|
|
17423
|
+
for (const part of content) {
|
|
17424
|
+
switch (part.type) {
|
|
17425
|
+
// groq supports reasoning for tool-calls in multi-turn conversations
|
|
17426
|
+
// https://github.com/vercel/ai/issues/7860
|
|
17427
|
+
case "reasoning": {
|
|
17428
|
+
reasoning += part.text;
|
|
17429
|
+
break;
|
|
17430
|
+
}
|
|
17431
|
+
case "text": {
|
|
17432
|
+
text2 += part.text;
|
|
17433
|
+
break;
|
|
17434
|
+
}
|
|
17435
|
+
case "tool-call": {
|
|
17436
|
+
toolCalls.push({
|
|
17437
|
+
id: part.toolCallId,
|
|
17438
|
+
type: "function",
|
|
17439
|
+
function: {
|
|
17440
|
+
name: part.toolName,
|
|
17441
|
+
arguments: JSON.stringify(part.input)
|
|
17442
|
+
}
|
|
17443
|
+
});
|
|
17444
|
+
break;
|
|
17445
|
+
}
|
|
17446
|
+
}
|
|
17447
|
+
}
|
|
17448
|
+
messages.push({
|
|
17449
|
+
role: "assistant",
|
|
17450
|
+
content: text2,
|
|
17451
|
+
...reasoning.length > 0 ? { reasoning } : null,
|
|
17452
|
+
...toolCalls.length > 0 ? { tool_calls: toolCalls } : null
|
|
17453
|
+
});
|
|
17454
|
+
break;
|
|
17455
|
+
}
|
|
17456
|
+
case "tool": {
|
|
17457
|
+
for (const toolResponse of content) {
|
|
17458
|
+
const output = toolResponse.output;
|
|
17459
|
+
let contentValue;
|
|
17460
|
+
switch (output.type) {
|
|
17461
|
+
case "text":
|
|
17462
|
+
case "error-text":
|
|
17463
|
+
contentValue = output.value;
|
|
17464
|
+
break;
|
|
17465
|
+
case "content":
|
|
17466
|
+
case "json":
|
|
17467
|
+
case "error-json":
|
|
17468
|
+
contentValue = JSON.stringify(output.value);
|
|
17469
|
+
break;
|
|
17470
|
+
}
|
|
17471
|
+
messages.push({
|
|
17472
|
+
role: "tool",
|
|
17473
|
+
tool_call_id: toolResponse.toolCallId,
|
|
17474
|
+
content: contentValue
|
|
17475
|
+
});
|
|
17476
|
+
}
|
|
17477
|
+
break;
|
|
17478
|
+
}
|
|
17479
|
+
default: {
|
|
17480
|
+
const _exhaustiveCheck = role;
|
|
17481
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
17482
|
+
}
|
|
17483
|
+
}
|
|
17484
|
+
}
|
|
17485
|
+
return messages;
|
|
17486
|
+
}
|
|
17487
|
+
function getResponseMetadata$1({
|
|
17488
|
+
id: id2,
|
|
17489
|
+
model,
|
|
17490
|
+
created
|
|
17491
|
+
}) {
|
|
17492
|
+
return {
|
|
17493
|
+
id: id2 != null ? id2 : void 0,
|
|
17494
|
+
modelId: model != null ? model : void 0,
|
|
17495
|
+
timestamp: created != null ? new Date(created * 1e3) : void 0
|
|
17496
|
+
};
|
|
17497
|
+
}
|
|
17498
|
+
var groqProviderOptions = object({
|
|
17499
|
+
reasoningFormat: _enum(["parsed", "raw", "hidden"]).optional(),
|
|
17500
|
+
reasoningEffort: string$1().optional(),
|
|
17501
|
+
/**
|
|
17502
|
+
* Whether to enable parallel function calling during tool use. Default to true.
|
|
17503
|
+
*/
|
|
17504
|
+
parallelToolCalls: boolean$1().optional(),
|
|
17505
|
+
/**
|
|
17506
|
+
* A unique identifier representing your end-user, which can help OpenAI to
|
|
17507
|
+
* monitor and detect abuse. Learn more.
|
|
17508
|
+
*/
|
|
17509
|
+
user: string$1().optional(),
|
|
17510
|
+
/**
|
|
17511
|
+
* Whether to use structured outputs.
|
|
17512
|
+
*
|
|
17513
|
+
* @default true
|
|
17514
|
+
*/
|
|
17515
|
+
structuredOutputs: boolean$1().optional(),
|
|
17516
|
+
/**
|
|
17517
|
+
* Service tier for the request.
|
|
17518
|
+
* - 'on_demand': Default tier with consistent performance and fairness
|
|
17519
|
+
* - 'flex': Higher throughput tier optimized for workloads that can handle occasional request failures
|
|
17520
|
+
* - 'auto': Uses on_demand rate limits, then falls back to flex tier if exceeded
|
|
17521
|
+
*
|
|
17522
|
+
* @default 'on_demand'
|
|
17523
|
+
*/
|
|
17524
|
+
serviceTier: _enum(["on_demand", "flex", "auto"]).optional()
|
|
17525
|
+
});
|
|
17526
|
+
var groqErrorDataSchema = object({
|
|
17527
|
+
error: object({
|
|
17528
|
+
message: string$1(),
|
|
17529
|
+
type: string$1()
|
|
17530
|
+
})
|
|
17531
|
+
});
|
|
17532
|
+
var groqFailedResponseHandler = createJsonErrorResponseHandler$1({
|
|
17533
|
+
errorSchema: groqErrorDataSchema,
|
|
17534
|
+
errorToMessage: (data) => data.error.message
|
|
17535
|
+
});
|
|
17536
|
+
var BROWSER_SEARCH_SUPPORTED_MODELS = [
|
|
17537
|
+
"openai/gpt-oss-20b",
|
|
17538
|
+
"openai/gpt-oss-120b"
|
|
17539
|
+
];
|
|
17540
|
+
function isBrowserSearchSupportedModel(modelId) {
|
|
17541
|
+
return BROWSER_SEARCH_SUPPORTED_MODELS.includes(modelId);
|
|
17542
|
+
}
|
|
17543
|
+
function getSupportedModelsString() {
|
|
17544
|
+
return BROWSER_SEARCH_SUPPORTED_MODELS.join(", ");
|
|
17545
|
+
}
|
|
17546
|
+
function prepareTools({
|
|
17547
|
+
tools,
|
|
17548
|
+
toolChoice,
|
|
17549
|
+
modelId
|
|
17550
|
+
}) {
|
|
17551
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
17552
|
+
const toolWarnings = [];
|
|
17553
|
+
if (tools == null) {
|
|
17554
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
17555
|
+
}
|
|
17556
|
+
const groqTools2 = [];
|
|
17557
|
+
for (const tool2 of tools) {
|
|
17558
|
+
if (tool2.type === "provider-defined") {
|
|
17559
|
+
if (tool2.id === "groq.browser_search") {
|
|
17560
|
+
if (!isBrowserSearchSupportedModel(modelId)) {
|
|
17561
|
+
toolWarnings.push({
|
|
17562
|
+
type: "unsupported-tool",
|
|
17563
|
+
tool: tool2,
|
|
17564
|
+
details: `Browser search is only supported on the following models: ${getSupportedModelsString()}. Current model: ${modelId}`
|
|
17565
|
+
});
|
|
17566
|
+
} else {
|
|
17567
|
+
groqTools2.push({
|
|
17568
|
+
type: "browser_search"
|
|
17569
|
+
});
|
|
17570
|
+
}
|
|
17571
|
+
} else {
|
|
17572
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool2 });
|
|
17573
|
+
}
|
|
17574
|
+
} else {
|
|
17575
|
+
groqTools2.push({
|
|
17576
|
+
type: "function",
|
|
17577
|
+
function: {
|
|
17578
|
+
name: tool2.name,
|
|
17579
|
+
description: tool2.description,
|
|
17580
|
+
parameters: tool2.inputSchema
|
|
17581
|
+
}
|
|
17582
|
+
});
|
|
17583
|
+
}
|
|
17584
|
+
}
|
|
17585
|
+
if (toolChoice == null) {
|
|
17586
|
+
return { tools: groqTools2, toolChoice: void 0, toolWarnings };
|
|
17587
|
+
}
|
|
17588
|
+
const type = toolChoice.type;
|
|
17589
|
+
switch (type) {
|
|
17590
|
+
case "auto":
|
|
17591
|
+
case "none":
|
|
17592
|
+
case "required":
|
|
17593
|
+
return { tools: groqTools2, toolChoice: type, toolWarnings };
|
|
17594
|
+
case "tool":
|
|
17595
|
+
return {
|
|
17596
|
+
tools: groqTools2,
|
|
17597
|
+
toolChoice: {
|
|
17598
|
+
type: "function",
|
|
17599
|
+
function: {
|
|
17600
|
+
name: toolChoice.toolName
|
|
17601
|
+
}
|
|
17602
|
+
},
|
|
17603
|
+
toolWarnings
|
|
17604
|
+
};
|
|
17605
|
+
default: {
|
|
17606
|
+
const _exhaustiveCheck = type;
|
|
17607
|
+
throw new UnsupportedFunctionalityError$1({
|
|
17608
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
17609
|
+
});
|
|
17610
|
+
}
|
|
17611
|
+
}
|
|
17612
|
+
}
|
|
17613
|
+
function mapGroqFinishReason(finishReason) {
|
|
17614
|
+
switch (finishReason) {
|
|
17615
|
+
case "stop":
|
|
17616
|
+
return "stop";
|
|
17617
|
+
case "length":
|
|
17618
|
+
return "length";
|
|
17619
|
+
case "content_filter":
|
|
17620
|
+
return "content-filter";
|
|
17621
|
+
case "function_call":
|
|
17622
|
+
case "tool_calls":
|
|
17623
|
+
return "tool-calls";
|
|
17624
|
+
default:
|
|
17625
|
+
return "unknown";
|
|
17626
|
+
}
|
|
17627
|
+
}
|
|
17628
|
+
var GroqChatLanguageModel = class {
|
|
17629
|
+
constructor(modelId, config2) {
|
|
17630
|
+
this.specificationVersion = "v2";
|
|
17631
|
+
this.supportedUrls = {
|
|
17632
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
17633
|
+
};
|
|
17634
|
+
this.modelId = modelId;
|
|
17635
|
+
this.config = config2;
|
|
17636
|
+
}
|
|
17637
|
+
get provider() {
|
|
17638
|
+
return this.config.provider;
|
|
17639
|
+
}
|
|
17640
|
+
async getArgs({
|
|
17641
|
+
prompt,
|
|
17642
|
+
maxOutputTokens,
|
|
17643
|
+
temperature,
|
|
17644
|
+
topP,
|
|
17645
|
+
topK,
|
|
17646
|
+
frequencyPenalty,
|
|
17647
|
+
presencePenalty,
|
|
17648
|
+
stopSequences,
|
|
17649
|
+
responseFormat,
|
|
17650
|
+
seed,
|
|
17651
|
+
stream,
|
|
17652
|
+
tools,
|
|
17653
|
+
toolChoice,
|
|
17654
|
+
providerOptions
|
|
17655
|
+
}) {
|
|
17656
|
+
var _a10, _b;
|
|
17657
|
+
const warnings = [];
|
|
17658
|
+
const groqOptions = await parseProviderOptions({
|
|
17659
|
+
provider: "groq",
|
|
17660
|
+
providerOptions,
|
|
17661
|
+
schema: groqProviderOptions
|
|
17662
|
+
});
|
|
17663
|
+
const structuredOutputs = (_a10 = groqOptions == null ? void 0 : groqOptions.structuredOutputs) != null ? _a10 : true;
|
|
17664
|
+
if (topK != null) {
|
|
17665
|
+
warnings.push({
|
|
17666
|
+
type: "unsupported-setting",
|
|
17667
|
+
setting: "topK"
|
|
17668
|
+
});
|
|
17669
|
+
}
|
|
17670
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !structuredOutputs) {
|
|
17671
|
+
warnings.push({
|
|
17672
|
+
type: "unsupported-setting",
|
|
17673
|
+
setting: "responseFormat",
|
|
17674
|
+
details: "JSON response format schema is only supported with structuredOutputs"
|
|
17675
|
+
});
|
|
17676
|
+
}
|
|
17677
|
+
const {
|
|
17678
|
+
tools: groqTools2,
|
|
17679
|
+
toolChoice: groqToolChoice,
|
|
17680
|
+
toolWarnings
|
|
17681
|
+
} = prepareTools({ tools, toolChoice, modelId: this.modelId });
|
|
17682
|
+
return {
|
|
17683
|
+
args: {
|
|
17684
|
+
// model id:
|
|
17685
|
+
model: this.modelId,
|
|
17686
|
+
// model specific settings:
|
|
17687
|
+
user: groqOptions == null ? void 0 : groqOptions.user,
|
|
17688
|
+
parallel_tool_calls: groqOptions == null ? void 0 : groqOptions.parallelToolCalls,
|
|
17689
|
+
// standardized settings:
|
|
17690
|
+
max_tokens: maxOutputTokens,
|
|
17691
|
+
temperature,
|
|
17692
|
+
top_p: topP,
|
|
17693
|
+
frequency_penalty: frequencyPenalty,
|
|
17694
|
+
presence_penalty: presencePenalty,
|
|
17695
|
+
stop: stopSequences,
|
|
17696
|
+
seed,
|
|
17697
|
+
// response format:
|
|
17698
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && responseFormat.schema != null ? {
|
|
17699
|
+
type: "json_schema",
|
|
17700
|
+
json_schema: {
|
|
17701
|
+
schema: responseFormat.schema,
|
|
17702
|
+
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
17703
|
+
description: responseFormat.description
|
|
17704
|
+
}
|
|
17705
|
+
} : { type: "json_object" } : void 0,
|
|
17706
|
+
// provider options:
|
|
17707
|
+
reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
|
|
17708
|
+
reasoning_effort: groqOptions == null ? void 0 : groqOptions.reasoningEffort,
|
|
17709
|
+
service_tier: groqOptions == null ? void 0 : groqOptions.serviceTier,
|
|
17710
|
+
// messages:
|
|
17711
|
+
messages: convertToGroqChatMessages(prompt),
|
|
17712
|
+
// tools:
|
|
17713
|
+
tools: groqTools2,
|
|
17714
|
+
tool_choice: groqToolChoice
|
|
17715
|
+
},
|
|
17716
|
+
warnings: [...warnings, ...toolWarnings]
|
|
17717
|
+
};
|
|
17718
|
+
}
|
|
17719
|
+
async doGenerate(options) {
|
|
17720
|
+
var _a10, _b, _c, _d, _e, _f, _g;
|
|
17721
|
+
const { args, warnings } = await this.getArgs({
|
|
17722
|
+
...options,
|
|
17723
|
+
stream: false
|
|
17724
|
+
});
|
|
17725
|
+
const body = JSON.stringify(args);
|
|
17726
|
+
const {
|
|
17727
|
+
responseHeaders,
|
|
17728
|
+
value: response,
|
|
17729
|
+
rawValue: rawResponse
|
|
17730
|
+
} = await postJsonToApi$1({
|
|
17731
|
+
url: this.config.url({
|
|
17732
|
+
path: "/chat/completions",
|
|
17733
|
+
modelId: this.modelId
|
|
17734
|
+
}),
|
|
17735
|
+
headers: combineHeaders$1(this.config.headers(), options.headers),
|
|
17736
|
+
body: args,
|
|
17737
|
+
failedResponseHandler: groqFailedResponseHandler,
|
|
17738
|
+
successfulResponseHandler: createJsonResponseHandler$1(
|
|
17739
|
+
groqChatResponseSchema
|
|
17740
|
+
),
|
|
17741
|
+
abortSignal: options.abortSignal,
|
|
17742
|
+
fetch: this.config.fetch
|
|
17743
|
+
});
|
|
17744
|
+
const choice = response.choices[0];
|
|
17745
|
+
const content = [];
|
|
17746
|
+
const text2 = choice.message.content;
|
|
17747
|
+
if (text2 != null && text2.length > 0) {
|
|
17748
|
+
content.push({ type: "text", text: text2 });
|
|
17749
|
+
}
|
|
17750
|
+
const reasoning = choice.message.reasoning;
|
|
17751
|
+
if (reasoning != null && reasoning.length > 0) {
|
|
17752
|
+
content.push({
|
|
17753
|
+
type: "reasoning",
|
|
17754
|
+
text: reasoning
|
|
17755
|
+
});
|
|
17756
|
+
}
|
|
17757
|
+
if (choice.message.tool_calls != null) {
|
|
17758
|
+
for (const toolCall of choice.message.tool_calls) {
|
|
17759
|
+
content.push({
|
|
17760
|
+
type: "tool-call",
|
|
17761
|
+
toolCallId: (_a10 = toolCall.id) != null ? _a10 : generateId$1(),
|
|
17762
|
+
toolName: toolCall.function.name,
|
|
17763
|
+
input: toolCall.function.arguments
|
|
17764
|
+
});
|
|
17765
|
+
}
|
|
17766
|
+
}
|
|
17767
|
+
return {
|
|
17768
|
+
content,
|
|
17769
|
+
finishReason: mapGroqFinishReason(choice.finish_reason),
|
|
17770
|
+
usage: {
|
|
17771
|
+
inputTokens: (_c = (_b = response.usage) == null ? void 0 : _b.prompt_tokens) != null ? _c : void 0,
|
|
17772
|
+
outputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : void 0,
|
|
17773
|
+
totalTokens: (_g = (_f = response.usage) == null ? void 0 : _f.total_tokens) != null ? _g : void 0
|
|
17774
|
+
},
|
|
17775
|
+
response: {
|
|
17776
|
+
...getResponseMetadata$1(response),
|
|
17777
|
+
headers: responseHeaders,
|
|
17778
|
+
body: rawResponse
|
|
17779
|
+
},
|
|
17780
|
+
warnings,
|
|
17781
|
+
request: { body }
|
|
17782
|
+
};
|
|
17783
|
+
}
|
|
17784
|
+
async doStream(options) {
|
|
17785
|
+
const { args, warnings } = await this.getArgs({ ...options, stream: true });
|
|
17786
|
+
const body = JSON.stringify({ ...args, stream: true });
|
|
17787
|
+
const { responseHeaders, value: response } = await postJsonToApi$1({
|
|
17788
|
+
url: this.config.url({
|
|
17789
|
+
path: "/chat/completions",
|
|
17790
|
+
modelId: this.modelId
|
|
17791
|
+
}),
|
|
17792
|
+
headers: combineHeaders$1(this.config.headers(), options.headers),
|
|
17793
|
+
body: {
|
|
17794
|
+
...args,
|
|
17795
|
+
stream: true
|
|
17796
|
+
},
|
|
17797
|
+
failedResponseHandler: groqFailedResponseHandler,
|
|
17798
|
+
successfulResponseHandler: createEventSourceResponseHandler$1(groqChatChunkSchema),
|
|
17799
|
+
abortSignal: options.abortSignal,
|
|
17800
|
+
fetch: this.config.fetch
|
|
17801
|
+
});
|
|
17802
|
+
const toolCalls = [];
|
|
17803
|
+
let finishReason = "unknown";
|
|
17804
|
+
const usage = {
|
|
17805
|
+
inputTokens: void 0,
|
|
17806
|
+
outputTokens: void 0,
|
|
17807
|
+
totalTokens: void 0
|
|
17808
|
+
};
|
|
17809
|
+
let isFirstChunk = true;
|
|
17810
|
+
let isActiveText = false;
|
|
17811
|
+
let isActiveReasoning = false;
|
|
17812
|
+
return {
|
|
17813
|
+
stream: response.pipeThrough(
|
|
17814
|
+
new TransformStream({
|
|
17815
|
+
start(controller) {
|
|
17816
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
17817
|
+
},
|
|
17818
|
+
transform(chunk, controller) {
|
|
17819
|
+
var _a10, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
17820
|
+
if (options.includeRawChunks) {
|
|
17821
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
17822
|
+
}
|
|
17823
|
+
if (!chunk.success) {
|
|
17824
|
+
finishReason = "error";
|
|
17825
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
17826
|
+
return;
|
|
17827
|
+
}
|
|
17828
|
+
const value = chunk.value;
|
|
17829
|
+
if ("error" in value) {
|
|
17830
|
+
finishReason = "error";
|
|
17831
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
17832
|
+
return;
|
|
17833
|
+
}
|
|
17834
|
+
if (isFirstChunk) {
|
|
17835
|
+
isFirstChunk = false;
|
|
17836
|
+
controller.enqueue({
|
|
17837
|
+
type: "response-metadata",
|
|
17838
|
+
...getResponseMetadata$1(value)
|
|
17839
|
+
});
|
|
17840
|
+
}
|
|
17841
|
+
if (((_a10 = value.x_groq) == null ? void 0 : _a10.usage) != null) {
|
|
17842
|
+
usage.inputTokens = (_b = value.x_groq.usage.prompt_tokens) != null ? _b : void 0;
|
|
17843
|
+
usage.outputTokens = (_c = value.x_groq.usage.completion_tokens) != null ? _c : void 0;
|
|
17844
|
+
usage.totalTokens = (_d = value.x_groq.usage.total_tokens) != null ? _d : void 0;
|
|
17845
|
+
}
|
|
17846
|
+
const choice = value.choices[0];
|
|
17847
|
+
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
17848
|
+
finishReason = mapGroqFinishReason(choice.finish_reason);
|
|
17849
|
+
}
|
|
17850
|
+
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
17851
|
+
return;
|
|
17852
|
+
}
|
|
17853
|
+
const delta = choice.delta;
|
|
17854
|
+
if (delta.reasoning != null && delta.reasoning.length > 0) {
|
|
17855
|
+
if (!isActiveReasoning) {
|
|
17856
|
+
controller.enqueue({
|
|
17857
|
+
type: "reasoning-start",
|
|
17858
|
+
id: "reasoning-0"
|
|
17859
|
+
});
|
|
17860
|
+
isActiveReasoning = true;
|
|
17861
|
+
}
|
|
17862
|
+
controller.enqueue({
|
|
17863
|
+
type: "reasoning-delta",
|
|
17864
|
+
id: "reasoning-0",
|
|
17865
|
+
delta: delta.reasoning
|
|
17866
|
+
});
|
|
17867
|
+
}
|
|
17868
|
+
if (delta.content != null && delta.content.length > 0) {
|
|
17869
|
+
if (!isActiveText) {
|
|
17870
|
+
controller.enqueue({ type: "text-start", id: "txt-0" });
|
|
17871
|
+
isActiveText = true;
|
|
17872
|
+
}
|
|
17873
|
+
controller.enqueue({
|
|
17874
|
+
type: "text-delta",
|
|
17875
|
+
id: "txt-0",
|
|
17876
|
+
delta: delta.content
|
|
17877
|
+
});
|
|
17878
|
+
}
|
|
17879
|
+
if (delta.tool_calls != null) {
|
|
17880
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
17881
|
+
const index2 = toolCallDelta.index;
|
|
17882
|
+
if (toolCalls[index2] == null) {
|
|
17883
|
+
if (toolCallDelta.type !== "function") {
|
|
17884
|
+
throw new InvalidResponseDataError$1({
|
|
17885
|
+
data: toolCallDelta,
|
|
17886
|
+
message: `Expected 'function' type.`
|
|
17887
|
+
});
|
|
17888
|
+
}
|
|
17889
|
+
if (toolCallDelta.id == null) {
|
|
17890
|
+
throw new InvalidResponseDataError$1({
|
|
17891
|
+
data: toolCallDelta,
|
|
17892
|
+
message: `Expected 'id' to be a string.`
|
|
17893
|
+
});
|
|
17894
|
+
}
|
|
17895
|
+
if (((_e = toolCallDelta.function) == null ? void 0 : _e.name) == null) {
|
|
17896
|
+
throw new InvalidResponseDataError$1({
|
|
17897
|
+
data: toolCallDelta,
|
|
17898
|
+
message: `Expected 'function.name' to be a string.`
|
|
17899
|
+
});
|
|
17900
|
+
}
|
|
17901
|
+
controller.enqueue({
|
|
17902
|
+
type: "tool-input-start",
|
|
17903
|
+
id: toolCallDelta.id,
|
|
17904
|
+
toolName: toolCallDelta.function.name
|
|
17905
|
+
});
|
|
17906
|
+
toolCalls[index2] = {
|
|
17907
|
+
id: toolCallDelta.id,
|
|
17908
|
+
type: "function",
|
|
17909
|
+
function: {
|
|
17910
|
+
name: toolCallDelta.function.name,
|
|
17911
|
+
arguments: (_f = toolCallDelta.function.arguments) != null ? _f : ""
|
|
17912
|
+
},
|
|
17913
|
+
hasFinished: false
|
|
17914
|
+
};
|
|
17915
|
+
const toolCall2 = toolCalls[index2];
|
|
17916
|
+
if (((_g = toolCall2.function) == null ? void 0 : _g.name) != null && ((_h = toolCall2.function) == null ? void 0 : _h.arguments) != null) {
|
|
17917
|
+
if (toolCall2.function.arguments.length > 0) {
|
|
17918
|
+
controller.enqueue({
|
|
17919
|
+
type: "tool-input-delta",
|
|
17920
|
+
id: toolCall2.id,
|
|
17921
|
+
delta: toolCall2.function.arguments
|
|
17922
|
+
});
|
|
17923
|
+
}
|
|
17924
|
+
if (isParsableJson$1(toolCall2.function.arguments)) {
|
|
17925
|
+
controller.enqueue({
|
|
17926
|
+
type: "tool-input-end",
|
|
17927
|
+
id: toolCall2.id
|
|
17928
|
+
});
|
|
17929
|
+
controller.enqueue({
|
|
17930
|
+
type: "tool-call",
|
|
17931
|
+
toolCallId: (_i = toolCall2.id) != null ? _i : generateId$1(),
|
|
17932
|
+
toolName: toolCall2.function.name,
|
|
17933
|
+
input: toolCall2.function.arguments
|
|
17934
|
+
});
|
|
17935
|
+
toolCall2.hasFinished = true;
|
|
17936
|
+
}
|
|
17937
|
+
}
|
|
17938
|
+
continue;
|
|
17939
|
+
}
|
|
17940
|
+
const toolCall = toolCalls[index2];
|
|
17941
|
+
if (toolCall.hasFinished) {
|
|
17942
|
+
continue;
|
|
17943
|
+
}
|
|
17944
|
+
if (((_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null) {
|
|
17945
|
+
toolCall.function.arguments += (_l = (_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null ? _l : "";
|
|
17946
|
+
}
|
|
17947
|
+
controller.enqueue({
|
|
17948
|
+
type: "tool-input-delta",
|
|
17949
|
+
id: toolCall.id,
|
|
17950
|
+
delta: (_m = toolCallDelta.function.arguments) != null ? _m : ""
|
|
17951
|
+
});
|
|
17952
|
+
if (((_n = toolCall.function) == null ? void 0 : _n.name) != null && ((_o = toolCall.function) == null ? void 0 : _o.arguments) != null && isParsableJson$1(toolCall.function.arguments)) {
|
|
17953
|
+
controller.enqueue({
|
|
17954
|
+
type: "tool-input-end",
|
|
17955
|
+
id: toolCall.id
|
|
17956
|
+
});
|
|
17957
|
+
controller.enqueue({
|
|
17958
|
+
type: "tool-call",
|
|
17959
|
+
toolCallId: (_p = toolCall.id) != null ? _p : generateId$1(),
|
|
17960
|
+
toolName: toolCall.function.name,
|
|
17961
|
+
input: toolCall.function.arguments
|
|
17962
|
+
});
|
|
17963
|
+
toolCall.hasFinished = true;
|
|
17964
|
+
}
|
|
17965
|
+
}
|
|
17966
|
+
}
|
|
17967
|
+
},
|
|
17968
|
+
flush(controller) {
|
|
17969
|
+
if (isActiveReasoning) {
|
|
17970
|
+
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
|
17971
|
+
}
|
|
17972
|
+
if (isActiveText) {
|
|
17973
|
+
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
17974
|
+
}
|
|
17975
|
+
controller.enqueue({
|
|
17976
|
+
type: "finish",
|
|
17977
|
+
finishReason,
|
|
17978
|
+
usage,
|
|
17979
|
+
...{}
|
|
17980
|
+
});
|
|
17981
|
+
}
|
|
17982
|
+
})
|
|
17983
|
+
),
|
|
17984
|
+
request: { body },
|
|
17985
|
+
response: { headers: responseHeaders }
|
|
17986
|
+
};
|
|
17987
|
+
}
|
|
17988
|
+
};
|
|
17989
|
+
var groqChatResponseSchema = object({
|
|
17990
|
+
id: string$1().nullish(),
|
|
17991
|
+
created: number$1().nullish(),
|
|
17992
|
+
model: string$1().nullish(),
|
|
17993
|
+
choices: array(
|
|
17994
|
+
object({
|
|
17995
|
+
message: object({
|
|
17996
|
+
content: string$1().nullish(),
|
|
17997
|
+
reasoning: string$1().nullish(),
|
|
17998
|
+
tool_calls: array(
|
|
17999
|
+
object({
|
|
18000
|
+
id: string$1().nullish(),
|
|
18001
|
+
type: literal("function"),
|
|
18002
|
+
function: object({
|
|
18003
|
+
name: string$1(),
|
|
18004
|
+
arguments: string$1()
|
|
18005
|
+
})
|
|
18006
|
+
})
|
|
18007
|
+
).nullish()
|
|
18008
|
+
}),
|
|
18009
|
+
index: number$1(),
|
|
18010
|
+
finish_reason: string$1().nullish()
|
|
18011
|
+
})
|
|
18012
|
+
),
|
|
18013
|
+
usage: object({
|
|
18014
|
+
prompt_tokens: number$1().nullish(),
|
|
18015
|
+
completion_tokens: number$1().nullish(),
|
|
18016
|
+
total_tokens: number$1().nullish()
|
|
18017
|
+
}).nullish()
|
|
18018
|
+
});
|
|
18019
|
+
var groqChatChunkSchema = union([
|
|
18020
|
+
object({
|
|
18021
|
+
id: string$1().nullish(),
|
|
18022
|
+
created: number$1().nullish(),
|
|
18023
|
+
model: string$1().nullish(),
|
|
18024
|
+
choices: array(
|
|
18025
|
+
object({
|
|
18026
|
+
delta: object({
|
|
18027
|
+
content: string$1().nullish(),
|
|
18028
|
+
reasoning: string$1().nullish(),
|
|
18029
|
+
tool_calls: array(
|
|
18030
|
+
object({
|
|
18031
|
+
index: number$1(),
|
|
18032
|
+
id: string$1().nullish(),
|
|
18033
|
+
type: literal("function").optional(),
|
|
18034
|
+
function: object({
|
|
18035
|
+
name: string$1().nullish(),
|
|
18036
|
+
arguments: string$1().nullish()
|
|
18037
|
+
})
|
|
18038
|
+
})
|
|
18039
|
+
).nullish()
|
|
18040
|
+
}).nullish(),
|
|
18041
|
+
finish_reason: string$1().nullable().optional(),
|
|
18042
|
+
index: number$1()
|
|
18043
|
+
})
|
|
18044
|
+
),
|
|
18045
|
+
x_groq: object({
|
|
18046
|
+
usage: object({
|
|
18047
|
+
prompt_tokens: number$1().nullish(),
|
|
18048
|
+
completion_tokens: number$1().nullish(),
|
|
18049
|
+
total_tokens: number$1().nullish()
|
|
18050
|
+
}).nullish()
|
|
18051
|
+
}).nullish()
|
|
18052
|
+
}),
|
|
18053
|
+
groqErrorDataSchema
|
|
18054
|
+
]);
|
|
18055
|
+
var groqProviderOptionsSchema = object({
|
|
18056
|
+
language: string$1().nullish(),
|
|
18057
|
+
prompt: string$1().nullish(),
|
|
18058
|
+
responseFormat: string$1().nullish(),
|
|
18059
|
+
temperature: number$1().min(0).max(1).nullish(),
|
|
18060
|
+
timestampGranularities: array(string$1()).nullish()
|
|
18061
|
+
});
|
|
18062
|
+
var GroqTranscriptionModel = class {
|
|
18063
|
+
constructor(modelId, config2) {
|
|
18064
|
+
this.modelId = modelId;
|
|
18065
|
+
this.config = config2;
|
|
18066
|
+
this.specificationVersion = "v2";
|
|
18067
|
+
}
|
|
18068
|
+
get provider() {
|
|
18069
|
+
return this.config.provider;
|
|
18070
|
+
}
|
|
18071
|
+
async getArgs({
|
|
18072
|
+
audio,
|
|
18073
|
+
mediaType,
|
|
18074
|
+
providerOptions
|
|
18075
|
+
}) {
|
|
18076
|
+
var _a10, _b, _c, _d, _e;
|
|
16697
18077
|
const warnings = [];
|
|
16698
|
-
|
|
16699
|
-
|
|
16700
|
-
type: "unsupported-setting",
|
|
16701
|
-
setting: "size",
|
|
16702
|
-
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
16703
|
-
});
|
|
16704
|
-
}
|
|
16705
|
-
if (seed != null) {
|
|
16706
|
-
warnings.push({
|
|
16707
|
-
type: "unsupported-setting",
|
|
16708
|
-
setting: "seed",
|
|
16709
|
-
details: "This model does not support the `seed` option through this provider."
|
|
16710
|
-
});
|
|
16711
|
-
}
|
|
16712
|
-
const googleOptions = await parseProviderOptions({
|
|
16713
|
-
provider: "google",
|
|
18078
|
+
const groqOptions = await parseProviderOptions({
|
|
18079
|
+
provider: "groq",
|
|
16714
18080
|
providerOptions,
|
|
16715
|
-
schema:
|
|
18081
|
+
schema: groqProviderOptionsSchema
|
|
16716
18082
|
});
|
|
16717
|
-
const
|
|
16718
|
-
const
|
|
16719
|
-
|
|
16720
|
-
|
|
16721
|
-
|
|
16722
|
-
|
|
16723
|
-
|
|
16724
|
-
|
|
16725
|
-
|
|
18083
|
+
const formData = new FormData();
|
|
18084
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
18085
|
+
formData.append("model", this.modelId);
|
|
18086
|
+
const fileExtension = mediaTypeToExtension(mediaType);
|
|
18087
|
+
formData.append(
|
|
18088
|
+
"file",
|
|
18089
|
+
new File([blob], "audio", { type: mediaType }),
|
|
18090
|
+
`audio.${fileExtension}`
|
|
18091
|
+
);
|
|
18092
|
+
if (groqOptions) {
|
|
18093
|
+
const transcriptionModelOptions = {
|
|
18094
|
+
language: (_a10 = groqOptions.language) != null ? _a10 : void 0,
|
|
18095
|
+
prompt: (_b = groqOptions.prompt) != null ? _b : void 0,
|
|
18096
|
+
response_format: (_c = groqOptions.responseFormat) != null ? _c : void 0,
|
|
18097
|
+
temperature: (_d = groqOptions.temperature) != null ? _d : void 0,
|
|
18098
|
+
timestamp_granularities: (_e = groqOptions.timestampGranularities) != null ? _e : void 0
|
|
18099
|
+
};
|
|
18100
|
+
for (const key in transcriptionModelOptions) {
|
|
18101
|
+
const value = transcriptionModelOptions[key];
|
|
18102
|
+
if (value !== void 0) {
|
|
18103
|
+
formData.append(key, String(value));
|
|
18104
|
+
}
|
|
18105
|
+
}
|
|
16726
18106
|
}
|
|
16727
|
-
|
|
16728
|
-
|
|
16729
|
-
|
|
18107
|
+
return {
|
|
18108
|
+
formData,
|
|
18109
|
+
warnings
|
|
16730
18110
|
};
|
|
16731
|
-
|
|
16732
|
-
|
|
16733
|
-
|
|
16734
|
-
|
|
16735
|
-
|
|
18111
|
+
}
|
|
18112
|
+
async doGenerate(options) {
|
|
18113
|
+
var _a10, _b, _c, _d, _e, _f, _g;
|
|
18114
|
+
const currentDate = (_c = (_b = (_a10 = this.config._internal) == null ? void 0 : _a10.currentDate) == null ? void 0 : _b.call(_a10)) != null ? _c : /* @__PURE__ */ new Date();
|
|
18115
|
+
const { formData, warnings } = await this.getArgs(options);
|
|
18116
|
+
const {
|
|
18117
|
+
value: response,
|
|
18118
|
+
responseHeaders,
|
|
18119
|
+
rawValue: rawResponse
|
|
18120
|
+
} = await postFormDataToApi({
|
|
18121
|
+
url: this.config.url({
|
|
18122
|
+
path: "/audio/transcriptions",
|
|
18123
|
+
modelId: this.modelId
|
|
18124
|
+
}),
|
|
18125
|
+
headers: combineHeaders$1(this.config.headers(), options.headers),
|
|
18126
|
+
formData,
|
|
18127
|
+
failedResponseHandler: groqFailedResponseHandler,
|
|
16736
18128
|
successfulResponseHandler: createJsonResponseHandler$1(
|
|
16737
|
-
|
|
18129
|
+
groqTranscriptionResponseSchema
|
|
16738
18130
|
),
|
|
16739
|
-
abortSignal,
|
|
18131
|
+
abortSignal: options.abortSignal,
|
|
16740
18132
|
fetch: this.config.fetch
|
|
16741
18133
|
});
|
|
16742
18134
|
return {
|
|
16743
|
-
|
|
16744
|
-
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
|
|
16748
|
-
|
|
16749
|
-
|
|
16750
|
-
|
|
16751
|
-
|
|
16752
|
-
}
|
|
16753
|
-
},
|
|
18135
|
+
text: response.text,
|
|
18136
|
+
segments: (_e = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
|
|
18137
|
+
text: segment.text,
|
|
18138
|
+
startSecond: segment.start,
|
|
18139
|
+
endSecond: segment.end
|
|
18140
|
+
}))) != null ? _e : [],
|
|
18141
|
+
language: (_f = response.language) != null ? _f : void 0,
|
|
18142
|
+
durationInSeconds: (_g = response.duration) != null ? _g : void 0,
|
|
18143
|
+
warnings,
|
|
16754
18144
|
response: {
|
|
16755
18145
|
timestamp: currentDate,
|
|
16756
18146
|
modelId: this.modelId,
|
|
16757
|
-
headers: responseHeaders
|
|
18147
|
+
headers: responseHeaders,
|
|
18148
|
+
body: rawResponse
|
|
16758
18149
|
}
|
|
16759
18150
|
};
|
|
16760
18151
|
}
|
|
16761
18152
|
};
|
|
16762
|
-
var
|
|
16763
|
-
|
|
18153
|
+
var groqTranscriptionResponseSchema = object({
|
|
18154
|
+
text: string$1(),
|
|
18155
|
+
x_groq: object({
|
|
18156
|
+
id: string$1()
|
|
18157
|
+
}),
|
|
18158
|
+
// additional properties are returned when `response_format: 'verbose_json'` is
|
|
18159
|
+
task: string$1().nullish(),
|
|
18160
|
+
language: string$1().nullish(),
|
|
18161
|
+
duration: number$1().nullish(),
|
|
18162
|
+
segments: array(
|
|
18163
|
+
object({
|
|
18164
|
+
id: number$1(),
|
|
18165
|
+
seek: number$1(),
|
|
18166
|
+
start: number$1(),
|
|
18167
|
+
end: number$1(),
|
|
18168
|
+
text: string$1(),
|
|
18169
|
+
tokens: array(number$1()),
|
|
18170
|
+
temperature: number$1(),
|
|
18171
|
+
avg_logprob: number$1(),
|
|
18172
|
+
compression_ratio: number$1(),
|
|
18173
|
+
no_speech_prob: number$1()
|
|
18174
|
+
})
|
|
18175
|
+
).nullish()
|
|
16764
18176
|
});
|
|
16765
|
-
var
|
|
16766
|
-
|
|
16767
|
-
|
|
18177
|
+
var browserSearch = createProviderDefinedToolFactory({
|
|
18178
|
+
id: "groq.browser_search",
|
|
18179
|
+
name: "browser_search",
|
|
18180
|
+
inputSchema: object({})
|
|
16768
18181
|
});
|
|
16769
|
-
|
|
18182
|
+
var groqTools = {
|
|
18183
|
+
browserSearch
|
|
18184
|
+
};
|
|
18185
|
+
function createGroq(options = {}) {
|
|
16770
18186
|
var _a10;
|
|
16771
|
-
const baseURL = (_a10 = withoutTrailingSlash$1(options.baseURL)) != null ? _a10 : "https://
|
|
18187
|
+
const baseURL = (_a10 = withoutTrailingSlash$1(options.baseURL)) != null ? _a10 : "https://api.groq.com/openai/v1";
|
|
16772
18188
|
const getHeaders = () => ({
|
|
16773
|
-
|
|
18189
|
+
Authorization: `Bearer ${loadApiKey$1({
|
|
16774
18190
|
apiKey: options.apiKey,
|
|
16775
|
-
environmentVariableName: "
|
|
16776
|
-
description: "
|
|
16777
|
-
})
|
|
18191
|
+
environmentVariableName: "GROQ_API_KEY",
|
|
18192
|
+
description: "Groq"
|
|
18193
|
+
})}`,
|
|
16778
18194
|
...options.headers
|
|
16779
18195
|
});
|
|
16780
|
-
const createChatModel = (modelId) => {
|
|
16781
|
-
|
|
16782
|
-
|
|
16783
|
-
provider: "google.generative-ai",
|
|
16784
|
-
baseURL,
|
|
16785
|
-
headers: getHeaders,
|
|
16786
|
-
generateId: (_a22 = options.generateId) != null ? _a22 : generateId$1,
|
|
16787
|
-
supportedUrls: () => ({
|
|
16788
|
-
"*": [
|
|
16789
|
-
// Google Generative Language "files" endpoint
|
|
16790
|
-
// e.g. https://generativelanguage.googleapis.com/v1beta/files/...
|
|
16791
|
-
new RegExp(`^${baseURL}/files/.*$`),
|
|
16792
|
-
// YouTube URLs (public or unlisted videos)
|
|
16793
|
-
new RegExp(
|
|
16794
|
-
`^https://(?:www\\.)?youtube\\.com/watch\\?v=[\\w-]+(?:&[\\w=&.-]*)?$`
|
|
16795
|
-
),
|
|
16796
|
-
new RegExp(`^https://youtu\\.be/[\\w-]+(?:\\?[\\w=&.-]*)?$`)
|
|
16797
|
-
]
|
|
16798
|
-
}),
|
|
16799
|
-
fetch: options.fetch
|
|
16800
|
-
});
|
|
16801
|
-
};
|
|
16802
|
-
const createEmbeddingModel = (modelId) => new GoogleGenerativeAIEmbeddingModel(modelId, {
|
|
16803
|
-
provider: "google.generative-ai",
|
|
16804
|
-
baseURL,
|
|
16805
|
-
headers: getHeaders,
|
|
16806
|
-
fetch: options.fetch
|
|
16807
|
-
});
|
|
16808
|
-
const createImageModel = (modelId, settings = {}) => new GoogleGenerativeAIImageModel(modelId, settings, {
|
|
16809
|
-
provider: "google.generative-ai",
|
|
16810
|
-
baseURL,
|
|
18196
|
+
const createChatModel = (modelId) => new GroqChatLanguageModel(modelId, {
|
|
18197
|
+
provider: "groq.chat",
|
|
18198
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
16811
18199
|
headers: getHeaders,
|
|
16812
18200
|
fetch: options.fetch
|
|
16813
18201
|
});
|
|
16814
|
-
const
|
|
18202
|
+
const createLanguageModel = (modelId) => {
|
|
16815
18203
|
if (new.target) {
|
|
16816
18204
|
throw new Error(
|
|
16817
|
-
"The
|
|
18205
|
+
"The Groq model function cannot be called with the new keyword."
|
|
16818
18206
|
);
|
|
16819
18207
|
}
|
|
16820
18208
|
return createChatModel(modelId);
|
|
16821
18209
|
};
|
|
16822
|
-
|
|
18210
|
+
const createTranscriptionModel = (modelId) => {
|
|
18211
|
+
return new GroqTranscriptionModel(modelId, {
|
|
18212
|
+
provider: "groq.transcription",
|
|
18213
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
18214
|
+
headers: getHeaders,
|
|
18215
|
+
fetch: options.fetch
|
|
18216
|
+
});
|
|
18217
|
+
};
|
|
18218
|
+
const provider = function(modelId) {
|
|
18219
|
+
return createLanguageModel(modelId);
|
|
18220
|
+
};
|
|
18221
|
+
provider.languageModel = createLanguageModel;
|
|
16823
18222
|
provider.chat = createChatModel;
|
|
16824
|
-
provider.
|
|
16825
|
-
|
|
16826
|
-
|
|
16827
|
-
provider.
|
|
16828
|
-
|
|
16829
|
-
|
|
16830
|
-
provider.
|
|
18223
|
+
provider.textEmbeddingModel = (modelId) => {
|
|
18224
|
+
throw new NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
18225
|
+
};
|
|
18226
|
+
provider.imageModel = (modelId) => {
|
|
18227
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
18228
|
+
};
|
|
18229
|
+
provider.transcription = createTranscriptionModel;
|
|
18230
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
18231
|
+
provider.tools = groqTools;
|
|
16831
18232
|
return provider;
|
|
16832
18233
|
}
|
|
16833
|
-
|
|
18234
|
+
createGroq();
|
|
16834
18235
|
var openaiErrorDataSchema = object({
|
|
16835
18236
|
error: object({
|
|
16836
18237
|
message: string$1(),
|
|
@@ -16842,7 +18243,7 @@ var openaiErrorDataSchema = object({
|
|
|
16842
18243
|
code: union([string$1(), number$1()]).nullish()
|
|
16843
18244
|
})
|
|
16844
18245
|
});
|
|
16845
|
-
var openaiFailedResponseHandler = createJsonErrorResponseHandler$
|
|
18246
|
+
var openaiFailedResponseHandler = createJsonErrorResponseHandler$2({
|
|
16846
18247
|
errorSchema: openaiErrorDataSchema,
|
|
16847
18248
|
errorToMessage: (data) => data.error.message
|
|
16848
18249
|
});
|
|
@@ -16899,7 +18300,7 @@ function convertToOpenAIChatMessages({
|
|
|
16899
18300
|
return {
|
|
16900
18301
|
type: "image_url",
|
|
16901
18302
|
image_url: {
|
|
16902
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
|
|
18303
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64$1(part.data)}`,
|
|
16903
18304
|
// OpenAI specific extension: image detail
|
|
16904
18305
|
detail: (_b = (_a10 = part.providerOptions) == null ? void 0 : _a10.openai) == null ? void 0 : _b.imageDetail
|
|
16905
18306
|
}
|
|
@@ -16915,7 +18316,7 @@ function convertToOpenAIChatMessages({
|
|
|
16915
18316
|
return {
|
|
16916
18317
|
type: "input_audio",
|
|
16917
18318
|
input_audio: {
|
|
16918
|
-
data: convertToBase64(part.data),
|
|
18319
|
+
data: convertToBase64$1(part.data),
|
|
16919
18320
|
format: "wav"
|
|
16920
18321
|
}
|
|
16921
18322
|
};
|
|
@@ -16925,7 +18326,7 @@ function convertToOpenAIChatMessages({
|
|
|
16925
18326
|
return {
|
|
16926
18327
|
type: "input_audio",
|
|
16927
18328
|
input_audio: {
|
|
16928
|
-
data: convertToBase64(part.data),
|
|
18329
|
+
data: convertToBase64$1(part.data),
|
|
16929
18330
|
format: "mp3"
|
|
16930
18331
|
}
|
|
16931
18332
|
};
|
|
@@ -16946,7 +18347,7 @@ function convertToOpenAIChatMessages({
|
|
|
16946
18347
|
type: "file",
|
|
16947
18348
|
file: typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
|
|
16948
18349
|
filename: (_c = part.filename) != null ? _c : `part-${index2}.pdf`,
|
|
16949
|
-
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
|
|
18350
|
+
file_data: `data:application/pdf;base64,${convertToBase64$1(part.data)}`
|
|
16950
18351
|
}
|
|
16951
18352
|
};
|
|
16952
18353
|
} else {
|
|
@@ -17220,7 +18621,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
17220
18621
|
}) {
|
|
17221
18622
|
var _a10, _b, _c, _d;
|
|
17222
18623
|
const warnings = [];
|
|
17223
|
-
const openaiOptions = (_a10 = await parseProviderOptions({
|
|
18624
|
+
const openaiOptions = (_a10 = await parseProviderOptions$1({
|
|
17224
18625
|
provider: "openai",
|
|
17225
18626
|
providerOptions,
|
|
17226
18627
|
schema: openaiProviderOptions
|
|
@@ -17399,15 +18800,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
17399
18800
|
responseHeaders,
|
|
17400
18801
|
value: response,
|
|
17401
18802
|
rawValue: rawResponse
|
|
17402
|
-
} = await postJsonToApi$
|
|
18803
|
+
} = await postJsonToApi$2({
|
|
17403
18804
|
url: this.config.url({
|
|
17404
18805
|
path: "/chat/completions",
|
|
17405
18806
|
modelId: this.modelId
|
|
17406
18807
|
}),
|
|
17407
|
-
headers: combineHeaders$
|
|
18808
|
+
headers: combineHeaders$2(this.config.headers(), options.headers),
|
|
17408
18809
|
body,
|
|
17409
18810
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
17410
|
-
successfulResponseHandler: createJsonResponseHandler$
|
|
18811
|
+
successfulResponseHandler: createJsonResponseHandler$2(
|
|
17411
18812
|
openaiChatResponseSchema
|
|
17412
18813
|
),
|
|
17413
18814
|
abortSignal: options.abortSignal,
|
|
@@ -17422,7 +18823,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
17422
18823
|
for (const toolCall of (_a10 = choice.message.tool_calls) != null ? _a10 : []) {
|
|
17423
18824
|
content.push({
|
|
17424
18825
|
type: "tool-call",
|
|
17425
|
-
toolCallId: (_b = toolCall.id) != null ? _b : generateId$
|
|
18826
|
+
toolCallId: (_b = toolCall.id) != null ? _b : generateId$2(),
|
|
17426
18827
|
toolName: toolCall.function.name,
|
|
17427
18828
|
input: toolCall.function.arguments
|
|
17428
18829
|
});
|
|
@@ -17431,7 +18832,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
17431
18832
|
content.push({
|
|
17432
18833
|
type: "source",
|
|
17433
18834
|
sourceType: "url",
|
|
17434
|
-
id: generateId$
|
|
18835
|
+
id: generateId$2(),
|
|
17435
18836
|
url: annotation.url,
|
|
17436
18837
|
title: annotation.title
|
|
17437
18838
|
});
|
|
@@ -17477,15 +18878,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
17477
18878
|
include_usage: true
|
|
17478
18879
|
}
|
|
17479
18880
|
};
|
|
17480
|
-
const { responseHeaders, value: response } = await postJsonToApi$
|
|
18881
|
+
const { responseHeaders, value: response } = await postJsonToApi$2({
|
|
17481
18882
|
url: this.config.url({
|
|
17482
18883
|
path: "/chat/completions",
|
|
17483
18884
|
modelId: this.modelId
|
|
17484
18885
|
}),
|
|
17485
|
-
headers: combineHeaders$
|
|
18886
|
+
headers: combineHeaders$2(this.config.headers(), options.headers),
|
|
17486
18887
|
body,
|
|
17487
18888
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
17488
|
-
successfulResponseHandler: createEventSourceResponseHandler$
|
|
18889
|
+
successfulResponseHandler: createEventSourceResponseHandler$2(
|
|
17489
18890
|
openaiChatChunkSchema
|
|
17490
18891
|
),
|
|
17491
18892
|
abortSignal: options.abortSignal,
|
|
@@ -17610,14 +19011,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
17610
19011
|
delta: toolCall2.function.arguments
|
|
17611
19012
|
});
|
|
17612
19013
|
}
|
|
17613
|
-
if (isParsableJson$
|
|
19014
|
+
if (isParsableJson$2(toolCall2.function.arguments)) {
|
|
17614
19015
|
controller.enqueue({
|
|
17615
19016
|
type: "tool-input-end",
|
|
17616
19017
|
id: toolCall2.id
|
|
17617
19018
|
});
|
|
17618
19019
|
controller.enqueue({
|
|
17619
19020
|
type: "tool-call",
|
|
17620
|
-
toolCallId: (_q = toolCall2.id) != null ? _q : generateId$
|
|
19021
|
+
toolCallId: (_q = toolCall2.id) != null ? _q : generateId$2(),
|
|
17621
19022
|
toolName: toolCall2.function.name,
|
|
17622
19023
|
input: toolCall2.function.arguments
|
|
17623
19024
|
});
|
|
@@ -17638,14 +19039,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
17638
19039
|
id: toolCall.id,
|
|
17639
19040
|
delta: (_u = toolCallDelta.function.arguments) != null ? _u : ""
|
|
17640
19041
|
});
|
|
17641
|
-
if (((_v = toolCall.function) == null ? void 0 : _v.name) != null && ((_w = toolCall.function) == null ? void 0 : _w.arguments) != null && isParsableJson$
|
|
19042
|
+
if (((_v = toolCall.function) == null ? void 0 : _v.name) != null && ((_w = toolCall.function) == null ? void 0 : _w.arguments) != null && isParsableJson$2(toolCall.function.arguments)) {
|
|
17642
19043
|
controller.enqueue({
|
|
17643
19044
|
type: "tool-input-end",
|
|
17644
19045
|
id: toolCall.id
|
|
17645
19046
|
});
|
|
17646
19047
|
controller.enqueue({
|
|
17647
19048
|
type: "tool-call",
|
|
17648
|
-
toolCallId: (_x = toolCall.id) != null ? _x : generateId$
|
|
19049
|
+
toolCallId: (_x = toolCall.id) != null ? _x : generateId$2(),
|
|
17649
19050
|
toolName: toolCall.function.name,
|
|
17650
19051
|
input: toolCall.function.arguments
|
|
17651
19052
|
});
|
|
@@ -17658,7 +19059,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
17658
19059
|
controller.enqueue({
|
|
17659
19060
|
type: "source",
|
|
17660
19061
|
sourceType: "url",
|
|
17661
|
-
id: generateId$
|
|
19062
|
+
id: generateId$2(),
|
|
17662
19063
|
url: annotation.url,
|
|
17663
19064
|
title: annotation.title
|
|
17664
19065
|
});
|
|
@@ -18016,12 +19417,12 @@ var OpenAICompletionLanguageModel = class {
|
|
|
18016
19417
|
}) {
|
|
18017
19418
|
const warnings = [];
|
|
18018
19419
|
const openaiOptions = {
|
|
18019
|
-
...await parseProviderOptions({
|
|
19420
|
+
...await parseProviderOptions$1({
|
|
18020
19421
|
provider: "openai",
|
|
18021
19422
|
providerOptions,
|
|
18022
19423
|
schema: openaiCompletionProviderOptions
|
|
18023
19424
|
}),
|
|
18024
|
-
...await parseProviderOptions({
|
|
19425
|
+
...await parseProviderOptions$1({
|
|
18025
19426
|
provider: this.providerOptionsName,
|
|
18026
19427
|
providerOptions,
|
|
18027
19428
|
schema: openaiCompletionProviderOptions
|
|
@@ -18077,15 +19478,15 @@ var OpenAICompletionLanguageModel = class {
|
|
|
18077
19478
|
responseHeaders,
|
|
18078
19479
|
value: response,
|
|
18079
19480
|
rawValue: rawResponse
|
|
18080
|
-
} = await postJsonToApi$
|
|
19481
|
+
} = await postJsonToApi$2({
|
|
18081
19482
|
url: this.config.url({
|
|
18082
19483
|
path: "/completions",
|
|
18083
19484
|
modelId: this.modelId
|
|
18084
19485
|
}),
|
|
18085
|
-
headers: combineHeaders$
|
|
19486
|
+
headers: combineHeaders$2(this.config.headers(), options.headers),
|
|
18086
19487
|
body: args,
|
|
18087
19488
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
18088
|
-
successfulResponseHandler: createJsonResponseHandler$
|
|
19489
|
+
successfulResponseHandler: createJsonResponseHandler$2(
|
|
18089
19490
|
openaiCompletionResponseSchema
|
|
18090
19491
|
),
|
|
18091
19492
|
abortSignal: options.abortSignal,
|
|
@@ -18123,15 +19524,15 @@ var OpenAICompletionLanguageModel = class {
|
|
|
18123
19524
|
include_usage: true
|
|
18124
19525
|
}
|
|
18125
19526
|
};
|
|
18126
|
-
const { responseHeaders, value: response } = await postJsonToApi$
|
|
19527
|
+
const { responseHeaders, value: response } = await postJsonToApi$2({
|
|
18127
19528
|
url: this.config.url({
|
|
18128
19529
|
path: "/completions",
|
|
18129
19530
|
modelId: this.modelId
|
|
18130
19531
|
}),
|
|
18131
|
-
headers: combineHeaders$
|
|
19532
|
+
headers: combineHeaders$2(this.config.headers(), options.headers),
|
|
18132
19533
|
body,
|
|
18133
19534
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
18134
|
-
successfulResponseHandler: createEventSourceResponseHandler$
|
|
19535
|
+
successfulResponseHandler: createEventSourceResponseHandler$2(
|
|
18135
19536
|
openaiCompletionChunkSchema
|
|
18136
19537
|
),
|
|
18137
19538
|
abortSignal: options.abortSignal,
|
|
@@ -18293,7 +19694,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
18293
19694
|
values
|
|
18294
19695
|
});
|
|
18295
19696
|
}
|
|
18296
|
-
const openaiOptions = (_a10 = await parseProviderOptions({
|
|
19697
|
+
const openaiOptions = (_a10 = await parseProviderOptions$1({
|
|
18297
19698
|
provider: "openai",
|
|
18298
19699
|
providerOptions,
|
|
18299
19700
|
schema: openaiEmbeddingProviderOptions
|
|
@@ -18302,12 +19703,12 @@ var OpenAIEmbeddingModel = class {
|
|
|
18302
19703
|
responseHeaders,
|
|
18303
19704
|
value: response,
|
|
18304
19705
|
rawValue
|
|
18305
|
-
} = await postJsonToApi$
|
|
19706
|
+
} = await postJsonToApi$2({
|
|
18306
19707
|
url: this.config.url({
|
|
18307
19708
|
path: "/embeddings",
|
|
18308
19709
|
modelId: this.modelId
|
|
18309
19710
|
}),
|
|
18310
|
-
headers: combineHeaders$
|
|
19711
|
+
headers: combineHeaders$2(this.config.headers(), headers),
|
|
18311
19712
|
body: {
|
|
18312
19713
|
model: this.modelId,
|
|
18313
19714
|
input: values,
|
|
@@ -18316,7 +19717,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
18316
19717
|
user: openaiOptions.user
|
|
18317
19718
|
},
|
|
18318
19719
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
18319
|
-
successfulResponseHandler: createJsonResponseHandler$
|
|
19720
|
+
successfulResponseHandler: createJsonResponseHandler$2(
|
|
18320
19721
|
openaiTextEmbeddingResponseSchema
|
|
18321
19722
|
),
|
|
18322
19723
|
abortSignal,
|
|
@@ -18375,12 +19776,12 @@ var OpenAIImageModel = class {
|
|
|
18375
19776
|
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
18376
19777
|
}
|
|
18377
19778
|
const currentDate = (_c = (_b = (_a10 = this.config._internal) == null ? void 0 : _a10.currentDate) == null ? void 0 : _b.call(_a10)) != null ? _c : /* @__PURE__ */ new Date();
|
|
18378
|
-
const { value: response, responseHeaders } = await postJsonToApi$
|
|
19779
|
+
const { value: response, responseHeaders } = await postJsonToApi$2({
|
|
18379
19780
|
url: this.config.url({
|
|
18380
19781
|
path: "/images/generations",
|
|
18381
19782
|
modelId: this.modelId
|
|
18382
19783
|
}),
|
|
18383
|
-
headers: combineHeaders$
|
|
19784
|
+
headers: combineHeaders$2(this.config.headers(), headers),
|
|
18384
19785
|
body: {
|
|
18385
19786
|
model: this.modelId,
|
|
18386
19787
|
prompt,
|
|
@@ -18390,7 +19791,7 @@ var OpenAIImageModel = class {
|
|
|
18390
19791
|
...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
|
|
18391
19792
|
},
|
|
18392
19793
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
18393
|
-
successfulResponseHandler: createJsonResponseHandler$
|
|
19794
|
+
successfulResponseHandler: createJsonResponseHandler$2(
|
|
18394
19795
|
openaiImageResponseSchema
|
|
18395
19796
|
),
|
|
18396
19797
|
abortSignal,
|
|
@@ -18527,7 +19928,7 @@ var webSearchArgsSchema = object({
|
|
|
18527
19928
|
timezone: string$1().optional()
|
|
18528
19929
|
}).optional()
|
|
18529
19930
|
});
|
|
18530
|
-
var webSearchToolFactory = createProviderDefinedToolFactory({
|
|
19931
|
+
var webSearchToolFactory = createProviderDefinedToolFactory$1({
|
|
18531
19932
|
id: "openai.web_search",
|
|
18532
19933
|
name: "web_search",
|
|
18533
19934
|
inputSchema: object({
|
|
@@ -18585,7 +19986,7 @@ var webSearchPreviewArgsSchema = object({
|
|
|
18585
19986
|
timezone: string$1().optional()
|
|
18586
19987
|
}).optional()
|
|
18587
19988
|
});
|
|
18588
|
-
var webSearchPreview = createProviderDefinedToolFactory({
|
|
19989
|
+
var webSearchPreview = createProviderDefinedToolFactory$1({
|
|
18589
19990
|
id: "openai.web_search_preview",
|
|
18590
19991
|
name: "web_search_preview",
|
|
18591
19992
|
inputSchema: object({
|
|
@@ -18724,7 +20125,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
18724
20125
|
return {
|
|
18725
20126
|
type: "input_image",
|
|
18726
20127
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
18727
|
-
image_url: `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
20128
|
+
image_url: `data:${mediaType};base64,${convertToBase64$1(part.data)}`
|
|
18728
20129
|
},
|
|
18729
20130
|
detail: (_b2 = (_a22 = part.providerOptions) == null ? void 0 : _a22.openai) == null ? void 0 : _b2.imageDetail
|
|
18730
20131
|
};
|
|
@@ -18739,7 +20140,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
18739
20140
|
type: "input_file",
|
|
18740
20141
|
...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
18741
20142
|
filename: (_c2 = part.filename) != null ? _c2 : `part-${index2}.pdf`,
|
|
18742
|
-
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
|
|
20143
|
+
file_data: `data:application/pdf;base64,${convertToBase64$1(part.data)}`
|
|
18743
20144
|
}
|
|
18744
20145
|
};
|
|
18745
20146
|
} else {
|
|
@@ -18792,7 +20193,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
18792
20193
|
break;
|
|
18793
20194
|
}
|
|
18794
20195
|
case "reasoning": {
|
|
18795
|
-
const providerOptions = await parseProviderOptions({
|
|
20196
|
+
const providerOptions = await parseProviderOptions$1({
|
|
18796
20197
|
provider: "openai",
|
|
18797
20198
|
providerOptions: part.providerOptions,
|
|
18798
20199
|
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
@@ -19114,7 +20515,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
19114
20515
|
if (stopSequences != null) {
|
|
19115
20516
|
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
19116
20517
|
}
|
|
19117
|
-
const openaiOptions = await parseProviderOptions({
|
|
20518
|
+
const openaiOptions = await parseProviderOptions$1({
|
|
19118
20519
|
provider: "openai",
|
|
19119
20520
|
providerOptions,
|
|
19120
20521
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -19282,12 +20683,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
19282
20683
|
responseHeaders,
|
|
19283
20684
|
value: response,
|
|
19284
20685
|
rawValue: rawResponse
|
|
19285
|
-
} = await postJsonToApi$
|
|
20686
|
+
} = await postJsonToApi$2({
|
|
19286
20687
|
url: url2,
|
|
19287
|
-
headers: combineHeaders$
|
|
20688
|
+
headers: combineHeaders$2(this.config.headers(), options.headers),
|
|
19288
20689
|
body,
|
|
19289
20690
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
19290
|
-
successfulResponseHandler: createJsonResponseHandler$
|
|
20691
|
+
successfulResponseHandler: createJsonResponseHandler$2(
|
|
19291
20692
|
object({
|
|
19292
20693
|
id: string$1(),
|
|
19293
20694
|
created_at: number$1(),
|
|
@@ -19442,7 +20843,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
19442
20843
|
content.push({
|
|
19443
20844
|
type: "source",
|
|
19444
20845
|
sourceType: "url",
|
|
19445
|
-
id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : generateId$
|
|
20846
|
+
id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : generateId$2(),
|
|
19446
20847
|
url: annotation.url,
|
|
19447
20848
|
title: annotation.title
|
|
19448
20849
|
});
|
|
@@ -19450,7 +20851,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
19450
20851
|
content.push({
|
|
19451
20852
|
type: "source",
|
|
19452
20853
|
sourceType: "document",
|
|
19453
|
-
id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId$
|
|
20854
|
+
id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId$2(),
|
|
19454
20855
|
mediaType: "text/plain",
|
|
19455
20856
|
title: (_k = (_j = annotation.quote) != null ? _j : annotation.filename) != null ? _k : "Document",
|
|
19456
20857
|
filename: (_l = annotation.filename) != null ? _l : annotation.file_id
|
|
@@ -19602,18 +21003,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
19602
21003
|
warnings,
|
|
19603
21004
|
webSearchToolName
|
|
19604
21005
|
} = await this.getArgs(options);
|
|
19605
|
-
const { responseHeaders, value: response } = await postJsonToApi$
|
|
21006
|
+
const { responseHeaders, value: response } = await postJsonToApi$2({
|
|
19606
21007
|
url: this.config.url({
|
|
19607
21008
|
path: "/responses",
|
|
19608
21009
|
modelId: this.modelId
|
|
19609
21010
|
}),
|
|
19610
|
-
headers: combineHeaders$
|
|
21011
|
+
headers: combineHeaders$2(this.config.headers(), options.headers),
|
|
19611
21012
|
body: {
|
|
19612
21013
|
...body,
|
|
19613
21014
|
stream: true
|
|
19614
21015
|
},
|
|
19615
21016
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
19616
|
-
successfulResponseHandler: createEventSourceResponseHandler$
|
|
21017
|
+
successfulResponseHandler: createEventSourceResponseHandler$2(
|
|
19617
21018
|
openaiResponsesChunkSchema
|
|
19618
21019
|
),
|
|
19619
21020
|
abortSignal: options.abortSignal,
|
|
@@ -19924,7 +21325,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
19924
21325
|
controller.enqueue({
|
|
19925
21326
|
type: "source",
|
|
19926
21327
|
sourceType: "url",
|
|
19927
|
-
id: (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId$
|
|
21328
|
+
id: (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId$2(),
|
|
19928
21329
|
url: value.annotation.url,
|
|
19929
21330
|
title: value.annotation.title
|
|
19930
21331
|
});
|
|
@@ -19932,7 +21333,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
19932
21333
|
controller.enqueue({
|
|
19933
21334
|
type: "source",
|
|
19934
21335
|
sourceType: "document",
|
|
19935
|
-
id: (_t = (_s = (_r = self.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId$
|
|
21336
|
+
id: (_t = (_s = (_r = self.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId$2(),
|
|
19936
21337
|
mediaType: "text/plain",
|
|
19937
21338
|
title: (_v = (_u = value.annotation.quote) != null ? _u : value.annotation.filename) != null ? _v : "Document",
|
|
19938
21339
|
filename: (_w = value.annotation.filename) != null ? _w : value.annotation.file_id
|
|
@@ -20264,7 +21665,7 @@ var OpenAISpeechModel = class {
|
|
|
20264
21665
|
providerOptions
|
|
20265
21666
|
}) {
|
|
20266
21667
|
const warnings = [];
|
|
20267
|
-
const openAIOptions = await parseProviderOptions({
|
|
21668
|
+
const openAIOptions = await parseProviderOptions$1({
|
|
20268
21669
|
provider: "openai",
|
|
20269
21670
|
providerOptions,
|
|
20270
21671
|
schema: OpenAIProviderOptionsSchema
|
|
@@ -20317,12 +21718,12 @@ var OpenAISpeechModel = class {
|
|
|
20317
21718
|
value: audio,
|
|
20318
21719
|
responseHeaders,
|
|
20319
21720
|
rawValue: rawResponse
|
|
20320
|
-
} = await postJsonToApi$
|
|
21721
|
+
} = await postJsonToApi$2({
|
|
20321
21722
|
url: this.config.url({
|
|
20322
21723
|
path: "/audio/speech",
|
|
20323
21724
|
modelId: this.modelId
|
|
20324
21725
|
}),
|
|
20325
|
-
headers: combineHeaders$
|
|
21726
|
+
headers: combineHeaders$2(this.config.headers(), options.headers),
|
|
20326
21727
|
body: requestBody,
|
|
20327
21728
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
20328
21729
|
successfulResponseHandler: createBinaryResponseHandler(),
|
|
@@ -20442,15 +21843,15 @@ var OpenAITranscriptionModel = class {
|
|
|
20442
21843
|
providerOptions
|
|
20443
21844
|
}) {
|
|
20444
21845
|
const warnings = [];
|
|
20445
|
-
const openAIOptions = await parseProviderOptions({
|
|
21846
|
+
const openAIOptions = await parseProviderOptions$1({
|
|
20446
21847
|
provider: "openai",
|
|
20447
21848
|
providerOptions,
|
|
20448
21849
|
schema: openAITranscriptionProviderOptions
|
|
20449
21850
|
});
|
|
20450
21851
|
const formData = new FormData();
|
|
20451
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
21852
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array$1(audio)]);
|
|
20452
21853
|
formData.append("model", this.modelId);
|
|
20453
|
-
const fileExtension = mediaTypeToExtension(mediaType);
|
|
21854
|
+
const fileExtension = mediaTypeToExtension$1(mediaType);
|
|
20454
21855
|
formData.append(
|
|
20455
21856
|
"file",
|
|
20456
21857
|
new File([blob], "audio", { type: mediaType }),
|
|
@@ -20495,15 +21896,15 @@ var OpenAITranscriptionModel = class {
|
|
|
20495
21896
|
value: response,
|
|
20496
21897
|
responseHeaders,
|
|
20497
21898
|
rawValue: rawResponse
|
|
20498
|
-
} = await postFormDataToApi({
|
|
21899
|
+
} = await postFormDataToApi$1({
|
|
20499
21900
|
url: this.config.url({
|
|
20500
21901
|
path: "/audio/transcriptions",
|
|
20501
21902
|
modelId: this.modelId
|
|
20502
21903
|
}),
|
|
20503
|
-
headers: combineHeaders$
|
|
21904
|
+
headers: combineHeaders$2(this.config.headers(), options.headers),
|
|
20504
21905
|
formData,
|
|
20505
21906
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
20506
|
-
successfulResponseHandler: createJsonResponseHandler$
|
|
21907
|
+
successfulResponseHandler: createJsonResponseHandler$2(
|
|
20507
21908
|
openaiTranscriptionResponseSchema
|
|
20508
21909
|
),
|
|
20509
21910
|
abortSignal: options.abortSignal,
|
|
@@ -20561,10 +21962,10 @@ var openaiTranscriptionResponseSchema = object({
|
|
|
20561
21962
|
});
|
|
20562
21963
|
function createOpenAI(options = {}) {
|
|
20563
21964
|
var _a10, _b;
|
|
20564
|
-
const baseURL = (_a10 = withoutTrailingSlash$
|
|
21965
|
+
const baseURL = (_a10 = withoutTrailingSlash$2(options.baseURL)) != null ? _a10 : "https://api.openai.com/v1";
|
|
20565
21966
|
const providerName = (_b = options.name) != null ? _b : "openai";
|
|
20566
21967
|
const getHeaders = () => ({
|
|
20567
|
-
Authorization: `Bearer ${loadApiKey$
|
|
21968
|
+
Authorization: `Bearer ${loadApiKey$2({
|
|
20568
21969
|
apiKey: options.apiKey,
|
|
20569
21970
|
environmentVariableName: "OPENAI_API_KEY",
|
|
20570
21971
|
description: "OpenAI"
|
|
@@ -23990,6 +25391,18 @@ var OpenRouterModels = [
|
|
|
23990
25391
|
output_cost_per_token: 59e-8,
|
|
23991
25392
|
provider: "OpenRouter"
|
|
23992
25393
|
},
|
|
25394
|
+
{
|
|
25395
|
+
model_id: "deepcogito/cogito-v2-preview-llama-405b",
|
|
25396
|
+
input_cost_per_token: 35e-7,
|
|
25397
|
+
output_cost_per_token: 35e-7,
|
|
25398
|
+
provider: "OpenRouter"
|
|
25399
|
+
},
|
|
25400
|
+
{
|
|
25401
|
+
model_id: "deepcogito/cogito-v2-preview-llama-70b",
|
|
25402
|
+
input_cost_per_token: 88e-8,
|
|
25403
|
+
output_cost_per_token: 88e-8,
|
|
25404
|
+
provider: "OpenRouter"
|
|
25405
|
+
},
|
|
23993
25406
|
{
|
|
23994
25407
|
model_id: "deepseek/deepseek-chat",
|
|
23995
25408
|
input_cost_per_token: 3e-7,
|
|
@@ -24182,6 +25595,18 @@ var OpenRouterModels = [
|
|
|
24182
25595
|
output_cost_per_token: 1e-6,
|
|
24183
25596
|
provider: "OpenRouter"
|
|
24184
25597
|
},
|
|
25598
|
+
{
|
|
25599
|
+
model_id: "inclusionai/ling-1t",
|
|
25600
|
+
input_cost_per_token: 4e-7,
|
|
25601
|
+
output_cost_per_token: 2e-6,
|
|
25602
|
+
provider: "OpenRouter"
|
|
25603
|
+
},
|
|
25604
|
+
{
|
|
25605
|
+
model_id: "inclusionai/ring-1t",
|
|
25606
|
+
input_cost_per_token: 57e-8,
|
|
25607
|
+
output_cost_per_token: 228e-8,
|
|
25608
|
+
provider: "OpenRouter"
|
|
25609
|
+
},
|
|
24185
25610
|
{
|
|
24186
25611
|
model_id: "inflection/inflection-3-pi",
|
|
24187
25612
|
input_cost_per_token: 25e-7,
|
|
@@ -25120,8 +26545,8 @@ var OpenRouterModels = [
|
|
|
25120
26545
|
},
|
|
25121
26546
|
{
|
|
25122
26547
|
model_id: "qwen/qwen3-vl-235b-a22b-thinking",
|
|
25123
|
-
input_cost_per_token:
|
|
25124
|
-
output_cost_per_token:
|
|
26548
|
+
input_cost_per_token: 3e-7,
|
|
26549
|
+
output_cost_per_token: 12e-7,
|
|
25125
26550
|
provider: "OpenRouter"
|
|
25126
26551
|
},
|
|
25127
26552
|
{
|
|
@@ -25520,6 +26945,18 @@ function createEchoGoogle({ appId, baseRouterUrl = ROUTER_BASE_URL }, getTokenFn
|
|
|
25520
26945
|
)
|
|
25521
26946
|
});
|
|
25522
26947
|
}
|
|
26948
|
+
function createEchoGroq({ appId, baseRouterUrl = ROUTER_BASE_URL }, getTokenFn, onInsufficientFunds) {
|
|
26949
|
+
validateAppId(appId, "createEchoGroq");
|
|
26950
|
+
return createGroq({
|
|
26951
|
+
baseURL: baseRouterUrl,
|
|
26952
|
+
apiKey: "placeholder_replaced_by_echoFetch",
|
|
26953
|
+
fetch: echoFetch(
|
|
26954
|
+
fetch,
|
|
26955
|
+
async () => await getTokenFn(appId),
|
|
26956
|
+
onInsufficientFunds
|
|
26957
|
+
)
|
|
26958
|
+
});
|
|
26959
|
+
}
|
|
25523
26960
|
function createEchoOpenAI({ appId, baseRouterUrl = ROUTER_BASE_URL }, getTokenFn, onInsufficientFunds) {
|
|
25524
26961
|
validateAppId(appId, "createEchoOpenAI");
|
|
25525
26962
|
return createOpenAI({
|
|
@@ -28562,7 +29999,8 @@ const useEchoModelProviders = () => {
|
|
|
28562
29999
|
baseConfig,
|
|
28563
30000
|
getToken,
|
|
28564
30001
|
onInsufficientFunds
|
|
28565
|
-
)
|
|
30002
|
+
),
|
|
30003
|
+
groq: createEchoGroq(baseConfig, getToken, onInsufficientFunds)
|
|
28566
30004
|
};
|
|
28567
30005
|
}, [getToken, config2.appId, config2.baseRouterUrl, setIsInsufficientFunds]);
|
|
28568
30006
|
};
|