190proof 1.0.98 → 1.0.99
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.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +83 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -259,9 +259,10 @@ interface GenericPayload {
|
|
|
259
259
|
provider?: OpenRouterProviderPreferences;
|
|
260
260
|
/**
|
|
261
261
|
* Per-request HTTP timeout in ms for the underlying provider call (applied
|
|
262
|
-
* per attempt, not across retries).
|
|
263
|
-
* defaults to
|
|
264
|
-
* single-file app codegen) so a long-but-
|
|
262
|
+
* per attempt, not across retries). Honored by all adapters (Anthropic,
|
|
263
|
+
* Google, OpenAI, OpenRouter, Groq); defaults to 120s when omitted. Raise it
|
|
264
|
+
* for slow, large generations (e.g. single-file app codegen) so a long-but-
|
|
265
|
+
* valid response isn't cut short.
|
|
265
266
|
*/
|
|
266
267
|
requestTimeoutMs?: number;
|
|
267
268
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -259,9 +259,10 @@ interface GenericPayload {
|
|
|
259
259
|
provider?: OpenRouterProviderPreferences;
|
|
260
260
|
/**
|
|
261
261
|
* Per-request HTTP timeout in ms for the underlying provider call (applied
|
|
262
|
-
* per attempt, not across retries).
|
|
263
|
-
* defaults to
|
|
264
|
-
* single-file app codegen) so a long-but-
|
|
262
|
+
* per attempt, not across retries). Honored by all adapters (Anthropic,
|
|
263
|
+
* Google, OpenAI, OpenRouter, Groq); defaults to 120s when omitted. Raise it
|
|
264
|
+
* for slow, large generations (e.g. single-file app codegen) so a long-but-
|
|
265
|
+
* valid response isn't cut short.
|
|
265
266
|
*/
|
|
266
267
|
requestTimeoutMs?: number;
|
|
267
268
|
}
|
package/dist/index.js
CHANGED
|
@@ -385,7 +385,7 @@ async function prepareOpenAIPayload(identifier, payload) {
|
|
|
385
385
|
}
|
|
386
386
|
return preparedPayload;
|
|
387
387
|
}
|
|
388
|
-
async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs) {
|
|
388
|
+
async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs, requestTimeoutMs = 12e4) {
|
|
389
389
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
390
390
|
const functionNames = openAiPayload.tools ? new Set(openAiPayload.tools.map((fn) => fn.function.name)) : null;
|
|
391
391
|
const { endpoint, headers } = buildOpenAIRequestConfig(
|
|
@@ -394,6 +394,13 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs)
|
|
|
394
394
|
openAiConfig
|
|
395
395
|
);
|
|
396
396
|
const controller = new AbortController();
|
|
397
|
+
const overallTimeout = setTimeout(() => {
|
|
398
|
+
logger_default.error(id, `Request timeout after ${requestTimeoutMs}ms`);
|
|
399
|
+
controller.abort();
|
|
400
|
+
}, requestTimeoutMs);
|
|
401
|
+
if (typeof overallTimeout === "object" && "unref" in overallTimeout) {
|
|
402
|
+
overallTimeout.unref();
|
|
403
|
+
}
|
|
397
404
|
const response = await fetch(endpoint, {
|
|
398
405
|
method: "POST",
|
|
399
406
|
headers,
|
|
@@ -435,6 +442,7 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs)
|
|
|
435
442
|
if (!jsonString)
|
|
436
443
|
continue;
|
|
437
444
|
if (jsonString.includes("[DONE]")) {
|
|
445
|
+
clearTimeout(overallTimeout);
|
|
438
446
|
return parseStreamedResponse(
|
|
439
447
|
id,
|
|
440
448
|
paragraph,
|
|
@@ -487,24 +495,32 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs)
|
|
|
487
495
|
}
|
|
488
496
|
}
|
|
489
497
|
}
|
|
490
|
-
async function callOpenAI(id, openAiPayload, openAiConfig) {
|
|
498
|
+
async function callOpenAI(id, openAiPayload, openAiConfig, requestTimeoutMs = 12e4) {
|
|
491
499
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
492
500
|
const { endpoint, headers } = buildOpenAIRequestConfig(
|
|
493
501
|
id,
|
|
494
502
|
openAiPayload.model,
|
|
495
503
|
openAiConfig
|
|
496
504
|
);
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
505
|
+
const controller = new AbortController();
|
|
506
|
+
const timer = setTimeout(() => controller.abort(), requestTimeoutMs);
|
|
507
|
+
let data;
|
|
508
|
+
try {
|
|
509
|
+
const response = await fetch(endpoint, {
|
|
510
|
+
method: "POST",
|
|
511
|
+
headers,
|
|
512
|
+
body: JSON.stringify({ ...openAiPayload, stream: false }),
|
|
513
|
+
signal: controller.signal
|
|
514
|
+
});
|
|
515
|
+
if (!response.ok) {
|
|
516
|
+
const errorData = await response.json();
|
|
517
|
+
logger_default.error(id, "OpenAI API error:", errorData);
|
|
518
|
+
throw new Error(`OpenAI API Error: ${errorData.error.message}`);
|
|
519
|
+
}
|
|
520
|
+
data = await response.json();
|
|
521
|
+
} finally {
|
|
522
|
+
clearTimeout(timer);
|
|
506
523
|
}
|
|
507
|
-
const data = await response.json();
|
|
508
524
|
if (!((_a = data.choices) == null ? void 0 : _a.length)) {
|
|
509
525
|
if (data.error) {
|
|
510
526
|
logger_default.error(id, "OpenAI error:", data.error);
|
|
@@ -557,7 +573,7 @@ async function callOpenAI(id, openAiPayload, openAiConfig) {
|
|
|
557
573
|
} : null
|
|
558
574
|
};
|
|
559
575
|
}
|
|
560
|
-
async function callOpenAiWithRetries(id, openAiPayload, openAiConfig, retries = 5, chunkTimeoutMs = 15e3) {
|
|
576
|
+
async function callOpenAiWithRetries(id, openAiPayload, openAiConfig, retries = 5, chunkTimeoutMs = 15e3, requestTimeoutMs = 12e4) {
|
|
561
577
|
logger_default.log(
|
|
562
578
|
id,
|
|
563
579
|
"Calling OpenAI API with retries:",
|
|
@@ -575,10 +591,11 @@ async function callOpenAiWithRetries(id, openAiPayload, openAiConfig, retries =
|
|
|
575
591
|
id,
|
|
576
592
|
openAiPayload,
|
|
577
593
|
openAiConfig,
|
|
578
|
-
chunkTimeoutMs
|
|
594
|
+
chunkTimeoutMs,
|
|
595
|
+
requestTimeoutMs
|
|
579
596
|
);
|
|
580
597
|
} else {
|
|
581
|
-
return callOpenAI(id, openAiPayload, openAiConfig);
|
|
598
|
+
return callOpenAI(id, openAiPayload, openAiConfig, requestTimeoutMs);
|
|
582
599
|
}
|
|
583
600
|
},
|
|
584
601
|
{
|
|
@@ -714,7 +731,7 @@ async function prepareAnthropicPayload(_identifier, payload) {
|
|
|
714
731
|
}
|
|
715
732
|
return preparedPayload;
|
|
716
733
|
}
|
|
717
|
-
async function callAnthropic(id, payload, config) {
|
|
734
|
+
async function callAnthropic(id, payload, config, requestTimeoutMs = 12e4) {
|
|
718
735
|
var _a, _b, _c;
|
|
719
736
|
const anthropicMessages = jigAnthropicMessages(payload.messages);
|
|
720
737
|
const tools = (_a = payload.functions) == null ? void 0 : _a.map((f) => ({
|
|
@@ -764,7 +781,7 @@ async function callAnthropic(id, payload, config) {
|
|
|
764
781
|
"anthropic-version": "2023-06-01",
|
|
765
782
|
"anthropic-beta": "tools-2024-04-04"
|
|
766
783
|
},
|
|
767
|
-
timeout:
|
|
784
|
+
timeout: requestTimeoutMs
|
|
768
785
|
}
|
|
769
786
|
);
|
|
770
787
|
data = response.data;
|
|
@@ -834,11 +851,11 @@ ${text}` : text;
|
|
|
834
851
|
usage
|
|
835
852
|
};
|
|
836
853
|
}
|
|
837
|
-
async function callAnthropicWithRetries(id, payload, config, retries = 5) {
|
|
854
|
+
async function callAnthropicWithRetries(id, payload, config, retries = 5, requestTimeoutMs = 12e4) {
|
|
838
855
|
return withRetries(
|
|
839
856
|
id,
|
|
840
857
|
"Anthropic",
|
|
841
|
-
() => callAnthropic(id, payload, config),
|
|
858
|
+
() => callAnthropic(id, payload, config, requestTimeoutMs),
|
|
842
859
|
{
|
|
843
860
|
retries
|
|
844
861
|
}
|
|
@@ -874,7 +891,6 @@ async function prepareGoogleAIPayload(_identifier, payload) {
|
|
|
874
891
|
const preparedPayload = {
|
|
875
892
|
model: payload.model,
|
|
876
893
|
messages: [],
|
|
877
|
-
requestTimeoutMs: payload.requestTimeoutMs,
|
|
878
894
|
tools: payload.functions ? {
|
|
879
895
|
functionDeclarations: payload.functions.map((fn) => ({
|
|
880
896
|
name: fn.name,
|
|
@@ -959,8 +975,8 @@ async function prepareGoogleAIPayload(_identifier, payload) {
|
|
|
959
975
|
}
|
|
960
976
|
return preparedPayload;
|
|
961
977
|
}
|
|
962
|
-
async function callGoogleAI(id, payload) {
|
|
963
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r
|
|
978
|
+
async function callGoogleAI(id, payload, requestTimeoutMs = 12e4) {
|
|
979
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
964
980
|
const contents = jigGoogleMessages(payload.messages);
|
|
965
981
|
const requestBody = {
|
|
966
982
|
contents,
|
|
@@ -983,50 +999,47 @@ async function callGoogleAI(id, payload) {
|
|
|
983
999
|
"content-type": "application/json",
|
|
984
1000
|
"x-goog-api-key": process.env.GEMINI_API_KEY
|
|
985
1001
|
},
|
|
986
|
-
|
|
987
|
-
// payload.requestTimeoutMs for slow, large generations (e.g. single-file
|
|
988
|
-
// app codegen) so a long-but-valid response isn't cut short.
|
|
989
|
-
timeout: (_a = payload.requestTimeoutMs) != null ? _a : 6e4
|
|
1002
|
+
timeout: requestTimeoutMs
|
|
990
1003
|
}
|
|
991
1004
|
);
|
|
992
1005
|
response = httpResponse.data;
|
|
993
1006
|
} catch (err) {
|
|
994
|
-
const apiError = (
|
|
1007
|
+
const apiError = (_b = (_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) == null ? void 0 : _b.error;
|
|
995
1008
|
const wrapped = new Error(
|
|
996
1009
|
(apiError == null ? void 0 : apiError.message) || (err == null ? void 0 : err.message) || "Google AI API request failed"
|
|
997
1010
|
);
|
|
998
|
-
wrapped.status = (
|
|
1011
|
+
wrapped.status = (_d = apiError == null ? void 0 : apiError.status) != null ? _d : (_c = err == null ? void 0 : err.response) == null ? void 0 : _c.status;
|
|
999
1012
|
wrapped.code = apiError == null ? void 0 : apiError.code;
|
|
1000
1013
|
wrapped.details = apiError == null ? void 0 : apiError.details;
|
|
1001
|
-
wrapped.promptFeedback = (
|
|
1014
|
+
wrapped.promptFeedback = (_f = (_e = err == null ? void 0 : err.response) == null ? void 0 : _e.data) == null ? void 0 : _f.promptFeedback;
|
|
1002
1015
|
throw wrapped;
|
|
1003
1016
|
}
|
|
1004
1017
|
let text = "";
|
|
1005
1018
|
const files = [];
|
|
1006
1019
|
const reasoningParts = [];
|
|
1007
1020
|
const functionCalls = [];
|
|
1008
|
-
for (const part of ((
|
|
1021
|
+
for (const part of ((_i = (_h = (_g = response.candidates) == null ? void 0 : _g[0]) == null ? void 0 : _h.content) == null ? void 0 : _i.parts) || []) {
|
|
1009
1022
|
if (part.thought) {
|
|
1010
1023
|
reasoningParts.push(part);
|
|
1011
1024
|
continue;
|
|
1012
1025
|
}
|
|
1013
1026
|
if (part.functionCall) {
|
|
1014
1027
|
functionCalls.push({
|
|
1015
|
-
id: (
|
|
1016
|
-
name: (
|
|
1017
|
-
arguments: (
|
|
1028
|
+
id: (_j = part.functionCall.id) != null ? _j : `call_${functionCalls.length}`,
|
|
1029
|
+
name: (_k = part.functionCall.name) != null ? _k : "",
|
|
1030
|
+
arguments: (_l = part.functionCall.args) != null ? _l : {},
|
|
1018
1031
|
thoughtSignature: part.thoughtSignature
|
|
1019
1032
|
});
|
|
1020
1033
|
continue;
|
|
1021
1034
|
}
|
|
1022
1035
|
if (part.text)
|
|
1023
1036
|
text += part.text;
|
|
1024
|
-
if ((
|
|
1037
|
+
if ((_m = part.inlineData) == null ? void 0 : _m.data) {
|
|
1025
1038
|
files.push({ mimeType: "image/png", data: part.inlineData.data });
|
|
1026
1039
|
}
|
|
1027
1040
|
}
|
|
1028
1041
|
if (!text && !functionCalls.length && !files.length) {
|
|
1029
|
-
const candidate = (
|
|
1042
|
+
const candidate = (_n = response.candidates) == null ? void 0 : _n[0];
|
|
1030
1043
|
const finishReason = candidate == null ? void 0 : candidate.finishReason;
|
|
1031
1044
|
logger_default.error(id, "Missing text & functions in Google AI API response:", {
|
|
1032
1045
|
finishReason,
|
|
@@ -1061,10 +1074,10 @@ async function callGoogleAI(id, payload) {
|
|
|
1061
1074
|
function_calls: functionCalls,
|
|
1062
1075
|
reasoningDetails: reasoningParts.length ? reasoningParts : void 0,
|
|
1063
1076
|
usage: response.usageMetadata ? {
|
|
1064
|
-
prompt_tokens: (
|
|
1065
|
-
completion_tokens: (
|
|
1066
|
-
total_tokens: (
|
|
1067
|
-
cached_tokens: (
|
|
1077
|
+
prompt_tokens: (_o = response.usageMetadata.promptTokenCount) != null ? _o : 0,
|
|
1078
|
+
completion_tokens: (_p = response.usageMetadata.candidatesTokenCount) != null ? _p : 0,
|
|
1079
|
+
total_tokens: (_q = response.usageMetadata.totalTokenCount) != null ? _q : 0,
|
|
1080
|
+
cached_tokens: (_r = response.usageMetadata.cachedContentTokenCount) != null ? _r : 0
|
|
1068
1081
|
} : null
|
|
1069
1082
|
};
|
|
1070
1083
|
}
|
|
@@ -1085,9 +1098,9 @@ function removeImagesFromGooglePayload(payload) {
|
|
|
1085
1098
|
}
|
|
1086
1099
|
return removedImages;
|
|
1087
1100
|
}
|
|
1088
|
-
async function callGoogleAIWithRetries(id, payload, retries = 5) {
|
|
1101
|
+
async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutMs = 12e4) {
|
|
1089
1102
|
let hasTriedWithoutImages = false;
|
|
1090
|
-
return withRetries(id, "Google AI", () => callGoogleAI(id, payload), {
|
|
1103
|
+
return withRetries(id, "Google AI", () => callGoogleAI(id, payload, requestTimeoutMs), {
|
|
1091
1104
|
retries,
|
|
1092
1105
|
onError: (error2, attempt) => {
|
|
1093
1106
|
var _a, _b;
|
|
@@ -1214,7 +1227,7 @@ function prepareGroqPayload(payload) {
|
|
|
1214
1227
|
temperature: payload.temperature
|
|
1215
1228
|
};
|
|
1216
1229
|
}
|
|
1217
|
-
async function callGroq(id, payload) {
|
|
1230
|
+
async function callGroq(id, payload, requestTimeoutMs = 12e4) {
|
|
1218
1231
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1219
1232
|
const response = await import_axios.default.post(
|
|
1220
1233
|
"https://api.groq.com/openai/v1/chat/completions",
|
|
@@ -1223,7 +1236,8 @@ async function callGroq(id, payload) {
|
|
|
1223
1236
|
headers: {
|
|
1224
1237
|
"content-type": "application/json",
|
|
1225
1238
|
Authorization: `Bearer ${process.env.GROQ_API_KEY}`
|
|
1226
|
-
}
|
|
1239
|
+
},
|
|
1240
|
+
timeout: requestTimeoutMs
|
|
1227
1241
|
}
|
|
1228
1242
|
);
|
|
1229
1243
|
if (response.data.error) {
|
|
@@ -1271,8 +1285,10 @@ async function callGroq(id, payload) {
|
|
|
1271
1285
|
} : null
|
|
1272
1286
|
};
|
|
1273
1287
|
}
|
|
1274
|
-
async function callGroqWithRetries(id, payload, retries = 5) {
|
|
1275
|
-
return withRetries(id, "Groq", () => callGroq(id, payload), {
|
|
1288
|
+
async function callGroqWithRetries(id, payload, retries = 5, requestTimeoutMs = 12e4) {
|
|
1289
|
+
return withRetries(id, "Groq", () => callGroq(id, payload, requestTimeoutMs), {
|
|
1290
|
+
retries
|
|
1291
|
+
});
|
|
1276
1292
|
}
|
|
1277
1293
|
function prepareOpenRouterPayload(payload) {
|
|
1278
1294
|
var _a;
|
|
@@ -1288,7 +1304,7 @@ function prepareOpenRouterPayload(payload) {
|
|
|
1288
1304
|
provider: payload.provider
|
|
1289
1305
|
};
|
|
1290
1306
|
}
|
|
1291
|
-
async function callOpenRouter(id, payload) {
|
|
1307
|
+
async function callOpenRouter(id, payload, requestTimeoutMs = 12e4) {
|
|
1292
1308
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1293
1309
|
const response = await import_axios.default.post(
|
|
1294
1310
|
"https://openrouter.ai/api/v1/chat/completions",
|
|
@@ -1297,7 +1313,8 @@ async function callOpenRouter(id, payload) {
|
|
|
1297
1313
|
headers: {
|
|
1298
1314
|
"content-type": "application/json",
|
|
1299
1315
|
Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`
|
|
1300
|
-
}
|
|
1316
|
+
},
|
|
1317
|
+
timeout: requestTimeoutMs
|
|
1301
1318
|
}
|
|
1302
1319
|
);
|
|
1303
1320
|
if (response.data.error) {
|
|
@@ -1346,8 +1363,13 @@ async function callOpenRouter(id, payload) {
|
|
|
1346
1363
|
} : null
|
|
1347
1364
|
};
|
|
1348
1365
|
}
|
|
1349
|
-
async function callOpenRouterWithRetries(id, payload, retries = 5) {
|
|
1350
|
-
return withRetries(
|
|
1366
|
+
async function callOpenRouterWithRetries(id, payload, retries = 5, requestTimeoutMs = 12e4) {
|
|
1367
|
+
return withRetries(
|
|
1368
|
+
id,
|
|
1369
|
+
"OpenRouter",
|
|
1370
|
+
() => callOpenRouter(id, payload, requestTimeoutMs),
|
|
1371
|
+
{ retries }
|
|
1372
|
+
);
|
|
1351
1373
|
}
|
|
1352
1374
|
var VALID_PROVIDERS = ["openai", "anthropic", "google", "groq", "openrouter"];
|
|
1353
1375
|
var ENUM_PROVIDER_MAP = [
|
|
@@ -1387,16 +1409,19 @@ function parseModelString(model) {
|
|
|
1387
1409
|
);
|
|
1388
1410
|
}
|
|
1389
1411
|
async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeoutMs = 15e3) {
|
|
1412
|
+
var _a;
|
|
1390
1413
|
try {
|
|
1391
1414
|
const { provider, modelId } = parseModelString(aiPayload.model);
|
|
1392
1415
|
const routingPayload = { ...aiPayload, model: modelId };
|
|
1416
|
+
const requestTimeoutMs = (_a = aiPayload.requestTimeoutMs) != null ? _a : 12e4;
|
|
1393
1417
|
switch (provider) {
|
|
1394
1418
|
case "anthropic":
|
|
1395
1419
|
return await callAnthropicWithRetries(
|
|
1396
1420
|
id,
|
|
1397
1421
|
await prepareAnthropicPayload(id, routingPayload),
|
|
1398
1422
|
aiConfig,
|
|
1399
|
-
retries
|
|
1423
|
+
retries,
|
|
1424
|
+
requestTimeoutMs
|
|
1400
1425
|
);
|
|
1401
1426
|
case "openai":
|
|
1402
1427
|
return await callOpenAiWithRetries(
|
|
@@ -1404,25 +1429,29 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1404
1429
|
await prepareOpenAIPayload(id, routingPayload),
|
|
1405
1430
|
aiConfig,
|
|
1406
1431
|
retries,
|
|
1407
|
-
chunkTimeoutMs
|
|
1432
|
+
chunkTimeoutMs,
|
|
1433
|
+
requestTimeoutMs
|
|
1408
1434
|
);
|
|
1409
1435
|
case "groq":
|
|
1410
1436
|
return await callGroqWithRetries(
|
|
1411
1437
|
id,
|
|
1412
1438
|
prepareGroqPayload(routingPayload),
|
|
1413
|
-
retries
|
|
1439
|
+
retries,
|
|
1440
|
+
requestTimeoutMs
|
|
1414
1441
|
);
|
|
1415
1442
|
case "google":
|
|
1416
1443
|
return await callGoogleAIWithRetries(
|
|
1417
1444
|
id,
|
|
1418
1445
|
await prepareGoogleAIPayload(id, routingPayload),
|
|
1419
|
-
retries
|
|
1446
|
+
retries,
|
|
1447
|
+
requestTimeoutMs
|
|
1420
1448
|
);
|
|
1421
1449
|
case "openrouter":
|
|
1422
1450
|
return await callOpenRouterWithRetries(
|
|
1423
1451
|
id,
|
|
1424
1452
|
prepareOpenRouterPayload(routingPayload),
|
|
1425
|
-
retries
|
|
1453
|
+
retries,
|
|
1454
|
+
requestTimeoutMs
|
|
1426
1455
|
);
|
|
1427
1456
|
}
|
|
1428
1457
|
} catch (error2) {
|