190proof 1.0.97 → 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 +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +69 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -257,6 +257,14 @@ interface GenericPayload {
|
|
|
257
257
|
* adapters. Forwarded as the request body's `provider` field.
|
|
258
258
|
*/
|
|
259
259
|
provider?: OpenRouterProviderPreferences;
|
|
260
|
+
/**
|
|
261
|
+
* Per-request HTTP timeout in ms for the underlying provider call (applied
|
|
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.
|
|
266
|
+
*/
|
|
267
|
+
requestTimeoutMs?: number;
|
|
260
268
|
}
|
|
261
269
|
|
|
262
270
|
declare function parseModelString(model: string): {
|
package/dist/index.d.ts
CHANGED
|
@@ -257,6 +257,14 @@ interface GenericPayload {
|
|
|
257
257
|
* adapters. Forwarded as the request body's `provider` field.
|
|
258
258
|
*/
|
|
259
259
|
provider?: OpenRouterProviderPreferences;
|
|
260
|
+
/**
|
|
261
|
+
* Per-request HTTP timeout in ms for the underlying provider call (applied
|
|
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.
|
|
266
|
+
*/
|
|
267
|
+
requestTimeoutMs?: number;
|
|
260
268
|
}
|
|
261
269
|
|
|
262
270
|
declare function parseModelString(model: string): {
|
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
|
}
|
|
@@ -958,7 +975,7 @@ async function prepareGoogleAIPayload(_identifier, payload) {
|
|
|
958
975
|
}
|
|
959
976
|
return preparedPayload;
|
|
960
977
|
}
|
|
961
|
-
async function callGoogleAI(id, payload) {
|
|
978
|
+
async function callGoogleAI(id, payload, requestTimeoutMs = 12e4) {
|
|
962
979
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
963
980
|
const contents = jigGoogleMessages(payload.messages);
|
|
964
981
|
const requestBody = {
|
|
@@ -982,7 +999,7 @@ async function callGoogleAI(id, payload) {
|
|
|
982
999
|
"content-type": "application/json",
|
|
983
1000
|
"x-goog-api-key": process.env.GEMINI_API_KEY
|
|
984
1001
|
},
|
|
985
|
-
timeout:
|
|
1002
|
+
timeout: requestTimeoutMs
|
|
986
1003
|
}
|
|
987
1004
|
);
|
|
988
1005
|
response = httpResponse.data;
|
|
@@ -1081,9 +1098,9 @@ function removeImagesFromGooglePayload(payload) {
|
|
|
1081
1098
|
}
|
|
1082
1099
|
return removedImages;
|
|
1083
1100
|
}
|
|
1084
|
-
async function callGoogleAIWithRetries(id, payload, retries = 5) {
|
|
1101
|
+
async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutMs = 12e4) {
|
|
1085
1102
|
let hasTriedWithoutImages = false;
|
|
1086
|
-
return withRetries(id, "Google AI", () => callGoogleAI(id, payload), {
|
|
1103
|
+
return withRetries(id, "Google AI", () => callGoogleAI(id, payload, requestTimeoutMs), {
|
|
1087
1104
|
retries,
|
|
1088
1105
|
onError: (error2, attempt) => {
|
|
1089
1106
|
var _a, _b;
|
|
@@ -1210,7 +1227,7 @@ function prepareGroqPayload(payload) {
|
|
|
1210
1227
|
temperature: payload.temperature
|
|
1211
1228
|
};
|
|
1212
1229
|
}
|
|
1213
|
-
async function callGroq(id, payload) {
|
|
1230
|
+
async function callGroq(id, payload, requestTimeoutMs = 12e4) {
|
|
1214
1231
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1215
1232
|
const response = await import_axios.default.post(
|
|
1216
1233
|
"https://api.groq.com/openai/v1/chat/completions",
|
|
@@ -1219,7 +1236,8 @@ async function callGroq(id, payload) {
|
|
|
1219
1236
|
headers: {
|
|
1220
1237
|
"content-type": "application/json",
|
|
1221
1238
|
Authorization: `Bearer ${process.env.GROQ_API_KEY}`
|
|
1222
|
-
}
|
|
1239
|
+
},
|
|
1240
|
+
timeout: requestTimeoutMs
|
|
1223
1241
|
}
|
|
1224
1242
|
);
|
|
1225
1243
|
if (response.data.error) {
|
|
@@ -1267,8 +1285,10 @@ async function callGroq(id, payload) {
|
|
|
1267
1285
|
} : null
|
|
1268
1286
|
};
|
|
1269
1287
|
}
|
|
1270
|
-
async function callGroqWithRetries(id, payload, retries = 5) {
|
|
1271
|
-
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
|
+
});
|
|
1272
1292
|
}
|
|
1273
1293
|
function prepareOpenRouterPayload(payload) {
|
|
1274
1294
|
var _a;
|
|
@@ -1284,7 +1304,7 @@ function prepareOpenRouterPayload(payload) {
|
|
|
1284
1304
|
provider: payload.provider
|
|
1285
1305
|
};
|
|
1286
1306
|
}
|
|
1287
|
-
async function callOpenRouter(id, payload) {
|
|
1307
|
+
async function callOpenRouter(id, payload, requestTimeoutMs = 12e4) {
|
|
1288
1308
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1289
1309
|
const response = await import_axios.default.post(
|
|
1290
1310
|
"https://openrouter.ai/api/v1/chat/completions",
|
|
@@ -1293,7 +1313,8 @@ async function callOpenRouter(id, payload) {
|
|
|
1293
1313
|
headers: {
|
|
1294
1314
|
"content-type": "application/json",
|
|
1295
1315
|
Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`
|
|
1296
|
-
}
|
|
1316
|
+
},
|
|
1317
|
+
timeout: requestTimeoutMs
|
|
1297
1318
|
}
|
|
1298
1319
|
);
|
|
1299
1320
|
if (response.data.error) {
|
|
@@ -1342,8 +1363,13 @@ async function callOpenRouter(id, payload) {
|
|
|
1342
1363
|
} : null
|
|
1343
1364
|
};
|
|
1344
1365
|
}
|
|
1345
|
-
async function callOpenRouterWithRetries(id, payload, retries = 5) {
|
|
1346
|
-
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
|
+
);
|
|
1347
1373
|
}
|
|
1348
1374
|
var VALID_PROVIDERS = ["openai", "anthropic", "google", "groq", "openrouter"];
|
|
1349
1375
|
var ENUM_PROVIDER_MAP = [
|
|
@@ -1383,16 +1409,19 @@ function parseModelString(model) {
|
|
|
1383
1409
|
);
|
|
1384
1410
|
}
|
|
1385
1411
|
async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeoutMs = 15e3) {
|
|
1412
|
+
var _a;
|
|
1386
1413
|
try {
|
|
1387
1414
|
const { provider, modelId } = parseModelString(aiPayload.model);
|
|
1388
1415
|
const routingPayload = { ...aiPayload, model: modelId };
|
|
1416
|
+
const requestTimeoutMs = (_a = aiPayload.requestTimeoutMs) != null ? _a : 12e4;
|
|
1389
1417
|
switch (provider) {
|
|
1390
1418
|
case "anthropic":
|
|
1391
1419
|
return await callAnthropicWithRetries(
|
|
1392
1420
|
id,
|
|
1393
1421
|
await prepareAnthropicPayload(id, routingPayload),
|
|
1394
1422
|
aiConfig,
|
|
1395
|
-
retries
|
|
1423
|
+
retries,
|
|
1424
|
+
requestTimeoutMs
|
|
1396
1425
|
);
|
|
1397
1426
|
case "openai":
|
|
1398
1427
|
return await callOpenAiWithRetries(
|
|
@@ -1400,25 +1429,29 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1400
1429
|
await prepareOpenAIPayload(id, routingPayload),
|
|
1401
1430
|
aiConfig,
|
|
1402
1431
|
retries,
|
|
1403
|
-
chunkTimeoutMs
|
|
1432
|
+
chunkTimeoutMs,
|
|
1433
|
+
requestTimeoutMs
|
|
1404
1434
|
);
|
|
1405
1435
|
case "groq":
|
|
1406
1436
|
return await callGroqWithRetries(
|
|
1407
1437
|
id,
|
|
1408
1438
|
prepareGroqPayload(routingPayload),
|
|
1409
|
-
retries
|
|
1439
|
+
retries,
|
|
1440
|
+
requestTimeoutMs
|
|
1410
1441
|
);
|
|
1411
1442
|
case "google":
|
|
1412
1443
|
return await callGoogleAIWithRetries(
|
|
1413
1444
|
id,
|
|
1414
1445
|
await prepareGoogleAIPayload(id, routingPayload),
|
|
1415
|
-
retries
|
|
1446
|
+
retries,
|
|
1447
|
+
requestTimeoutMs
|
|
1416
1448
|
);
|
|
1417
1449
|
case "openrouter":
|
|
1418
1450
|
return await callOpenRouterWithRetries(
|
|
1419
1451
|
id,
|
|
1420
1452
|
prepareOpenRouterPayload(routingPayload),
|
|
1421
|
-
retries
|
|
1453
|
+
retries,
|
|
1454
|
+
requestTimeoutMs
|
|
1422
1455
|
);
|
|
1423
1456
|
}
|
|
1424
1457
|
} catch (error2) {
|