190proof 1.0.106 → 1.0.107
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.js +88 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -146,6 +146,19 @@ function anySignal(signals) {
|
|
|
146
146
|
signals
|
|
147
147
|
);
|
|
148
148
|
}
|
|
149
|
+
async function withRequestDeadline(apiName, requestTimeoutMs, signal, fn) {
|
|
150
|
+
const deadline = AbortSignal.timeout(requestTimeoutMs);
|
|
151
|
+
try {
|
|
152
|
+
return await fn(signal ? anySignal([signal, deadline]) : deadline);
|
|
153
|
+
} catch (error2) {
|
|
154
|
+
if (deadline.aborted && !(signal == null ? void 0 : signal.aborted)) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
`${apiName} request exceeded hard deadline of ${requestTimeoutMs}ms`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
throw error2;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
149
162
|
async function withRetries(identifier, apiName, fn, options = {}) {
|
|
150
163
|
var _a, _b, _c, _d, _e;
|
|
151
164
|
const { retries = 5, baseDelayMs = 125, onError } = options;
|
|
@@ -786,28 +799,33 @@ async function callAnthropic(id, payload, config, requestTimeoutMs = 12e4, signa
|
|
|
786
799
|
...tools.slice(0, -1),
|
|
787
800
|
{ ...tools[tools.length - 1], cache_control: { type: "ephemeral" } }
|
|
788
801
|
] : tools;
|
|
789
|
-
const response = await
|
|
790
|
-
"
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
"x-api-key": process.env.ANTHROPIC_API_KEY,
|
|
805
|
-
"anthropic-version": "2023-06-01",
|
|
806
|
-
"anthropic-beta": "tools-2024-04-04"
|
|
802
|
+
const response = await withRequestDeadline(
|
|
803
|
+
"Anthropic",
|
|
804
|
+
requestTimeoutMs,
|
|
805
|
+
signal,
|
|
806
|
+
(mergedSignal) => import_axios.default.post(
|
|
807
|
+
"https://api.anthropic.com/v1/messages",
|
|
808
|
+
{
|
|
809
|
+
model: payload.model,
|
|
810
|
+
messages: anthropicMessages,
|
|
811
|
+
tools: cachedTools,
|
|
812
|
+
// tool_choice requires tools in the request; drop it otherwise.
|
|
813
|
+
tool_choice: (cachedTools == null ? void 0 : cachedTools.length) ? payload.tool_choice : void 0,
|
|
814
|
+
temperature: payload.temperature,
|
|
815
|
+
system: payload.system,
|
|
816
|
+
max_tokens: 4096
|
|
807
817
|
},
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
818
|
+
{
|
|
819
|
+
headers: {
|
|
820
|
+
"content-type": "application/json",
|
|
821
|
+
"x-api-key": process.env.ANTHROPIC_API_KEY,
|
|
822
|
+
"anthropic-version": "2023-06-01",
|
|
823
|
+
"anthropic-beta": "tools-2024-04-04"
|
|
824
|
+
},
|
|
825
|
+
timeout: requestTimeoutMs,
|
|
826
|
+
signal: mergedSignal
|
|
827
|
+
}
|
|
828
|
+
)
|
|
811
829
|
);
|
|
812
830
|
data = response.data;
|
|
813
831
|
}
|
|
@@ -1024,17 +1042,22 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
1024
1042
|
}
|
|
1025
1043
|
let response;
|
|
1026
1044
|
try {
|
|
1027
|
-
const httpResponse = await
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1045
|
+
const httpResponse = await withRequestDeadline(
|
|
1046
|
+
"Google AI",
|
|
1047
|
+
requestTimeoutMs,
|
|
1048
|
+
signal,
|
|
1049
|
+
(mergedSignal) => import_axios.default.post(
|
|
1050
|
+
`https://generativelanguage.googleapis.com/v1beta/models/${payload.model}:generateContent`,
|
|
1051
|
+
requestBody,
|
|
1052
|
+
{
|
|
1053
|
+
headers: {
|
|
1054
|
+
"content-type": "application/json",
|
|
1055
|
+
"x-goog-api-key": process.env.GEMINI_API_KEY
|
|
1056
|
+
},
|
|
1057
|
+
timeout: requestTimeoutMs,
|
|
1058
|
+
signal: mergedSignal
|
|
1059
|
+
}
|
|
1060
|
+
)
|
|
1038
1061
|
);
|
|
1039
1062
|
response = httpResponse.data;
|
|
1040
1063
|
} catch (err) {
|
|
@@ -1257,17 +1280,22 @@ function prepareGroqPayload(payload) {
|
|
|
1257
1280
|
}
|
|
1258
1281
|
async function callGroq(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
1259
1282
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1260
|
-
const response = await
|
|
1261
|
-
"
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1283
|
+
const response = await withRequestDeadline(
|
|
1284
|
+
"Groq",
|
|
1285
|
+
requestTimeoutMs,
|
|
1286
|
+
signal,
|
|
1287
|
+
(mergedSignal) => import_axios.default.post(
|
|
1288
|
+
"https://api.groq.com/openai/v1/chat/completions",
|
|
1289
|
+
payload,
|
|
1290
|
+
{
|
|
1291
|
+
headers: {
|
|
1292
|
+
"content-type": "application/json",
|
|
1293
|
+
Authorization: `Bearer ${process.env.GROQ_API_KEY}`
|
|
1294
|
+
},
|
|
1295
|
+
timeout: requestTimeoutMs,
|
|
1296
|
+
signal: mergedSignal
|
|
1297
|
+
}
|
|
1298
|
+
)
|
|
1271
1299
|
);
|
|
1272
1300
|
if (response.data.error) {
|
|
1273
1301
|
logger_default.error(id, "Groq error:", response.data.error);
|
|
@@ -1383,17 +1411,23 @@ function parseDsmlToolCalls(content) {
|
|
|
1383
1411
|
}
|
|
1384
1412
|
async function callOpenRouter(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
1385
1413
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1386
|
-
const response = await
|
|
1387
|
-
"
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1414
|
+
const response = await withRequestDeadline(
|
|
1415
|
+
"OpenRouter",
|
|
1416
|
+
requestTimeoutMs,
|
|
1417
|
+
signal,
|
|
1418
|
+
(mergedSignal) => import_axios.default.post(
|
|
1419
|
+
// Override point for tests (deadline behavior needs a local server).
|
|
1420
|
+
`${process.env.OPENROUTER_BASE_URL || "https://openrouter.ai"}/api/v1/chat/completions`,
|
|
1421
|
+
payload,
|
|
1422
|
+
{
|
|
1423
|
+
headers: {
|
|
1424
|
+
"content-type": "application/json",
|
|
1425
|
+
Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`
|
|
1426
|
+
},
|
|
1427
|
+
timeout: requestTimeoutMs,
|
|
1428
|
+
signal: mergedSignal
|
|
1429
|
+
}
|
|
1430
|
+
)
|
|
1397
1431
|
);
|
|
1398
1432
|
if (response.data.error) {
|
|
1399
1433
|
logger_default.error(id, "OpenRouter error:", response.data.error);
|