190proof 1.0.105 → 1.0.106
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/README.md +1 -1
- package/dist/index.js +28 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -52
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -4
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
2
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
3
|
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
5
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
6
|
});
|
|
8
7
|
|
|
@@ -125,8 +124,7 @@ async function withRetries(identifier, apiName, fn, options = {}) {
|
|
|
125
124
|
return await fn();
|
|
126
125
|
} catch (error3) {
|
|
127
126
|
lastError = error3;
|
|
128
|
-
if ((_a = options.signal) == null ? void 0 : _a.aborted)
|
|
129
|
-
throw error3;
|
|
127
|
+
if ((_a = options.signal) == null ? void 0 : _a.aborted) throw error3;
|
|
130
128
|
if (onError) {
|
|
131
129
|
onError(error3, attempt);
|
|
132
130
|
} else {
|
|
@@ -150,8 +148,7 @@ function parseStreamedResponse(identifier, paragraph, toolCallAccumulators, allo
|
|
|
150
148
|
const functionCalls = [];
|
|
151
149
|
for (let i = 0; i < toolCallAccumulators.length; i++) {
|
|
152
150
|
const acc = toolCallAccumulators[i];
|
|
153
|
-
if (!acc.name || !acc.arguments)
|
|
154
|
-
continue;
|
|
151
|
+
if (!acc.name || !acc.arguments) continue;
|
|
155
152
|
if (allowedFunctionNames && !allowedFunctionNames.has(acc.name)) {
|
|
156
153
|
throw new Error(
|
|
157
154
|
`Stream error: received function call with unknown name: ${acc.name}`
|
|
@@ -290,8 +287,7 @@ function buildOpenAIRequestConfig(identifier, model, config) {
|
|
|
290
287
|
};
|
|
291
288
|
}
|
|
292
289
|
function filterOpenAICompatReasoningDetails(details) {
|
|
293
|
-
if (!Array.isArray(details))
|
|
294
|
-
return details || void 0;
|
|
290
|
+
if (!Array.isArray(details)) return details || void 0;
|
|
295
291
|
const blocks = details.filter(
|
|
296
292
|
(block) => typeof (block == null ? void 0 : block.type) === "string" && block.type.startsWith("reasoning.")
|
|
297
293
|
);
|
|
@@ -362,13 +358,11 @@ async function prepareOpenAIPayload(identifier, payload) {
|
|
|
362
358
|
};
|
|
363
359
|
});
|
|
364
360
|
}
|
|
365
|
-
if (message.reasoning)
|
|
366
|
-
outMessage.reasoning = message.reasoning;
|
|
361
|
+
if (message.reasoning) outMessage.reasoning = message.reasoning;
|
|
367
362
|
const reasoningDetails = filterOpenAICompatReasoningDetails(
|
|
368
363
|
message.reasoningDetails
|
|
369
364
|
);
|
|
370
|
-
if (reasoningDetails)
|
|
371
|
-
outMessage.reasoning_details = reasoningDetails;
|
|
365
|
+
if (reasoningDetails) outMessage.reasoning_details = reasoningDetails;
|
|
372
366
|
preparedPayload.messages.push(outMessage);
|
|
373
367
|
}
|
|
374
368
|
return preparedPayload;
|
|
@@ -430,8 +424,7 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
430
424
|
}
|
|
431
425
|
const jsonStrings = chunk.split(/^data: /gm);
|
|
432
426
|
for (const jsonString of jsonStrings) {
|
|
433
|
-
if (!jsonString)
|
|
434
|
-
continue;
|
|
427
|
+
if (!jsonString) continue;
|
|
435
428
|
if (jsonString.includes("[DONE]")) {
|
|
436
429
|
clearTimeout(overallTimeout);
|
|
437
430
|
return parseStreamedResponse(
|
|
@@ -469,8 +462,7 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
469
462
|
while (toolCallAccumulators.length <= idx) {
|
|
470
463
|
toolCallAccumulators.push({ name: "", arguments: "" });
|
|
471
464
|
}
|
|
472
|
-
if (toolCall.id)
|
|
473
|
-
toolCallAccumulators[idx].id = toolCall.id;
|
|
465
|
+
if (toolCall.id) toolCallAccumulators[idx].id = toolCall.id;
|
|
474
466
|
if ((_e = toolCall.function) == null ? void 0 : _e.name)
|
|
475
467
|
toolCallAccumulators[idx].name += toolCall.function.name;
|
|
476
468
|
if ((_f = toolCall.function) == null ? void 0 : _f.arguments)
|
|
@@ -478,11 +470,9 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
478
470
|
}
|
|
479
471
|
}
|
|
480
472
|
const text = (_h = (_g = json.choices[0]) == null ? void 0 : _g.delta) == null ? void 0 : _h.content;
|
|
481
|
-
if (text)
|
|
482
|
-
paragraph += text;
|
|
473
|
+
if (text) paragraph += text;
|
|
483
474
|
const reasoningDelta = (_j = (_i = json.choices[0]) == null ? void 0 : _i.delta) == null ? void 0 : _j.reasoning;
|
|
484
|
-
if (reasoningDelta)
|
|
485
|
-
reasoning += reasoningDelta;
|
|
475
|
+
if (reasoningDelta) reasoning += reasoningDelta;
|
|
486
476
|
}
|
|
487
477
|
}
|
|
488
478
|
}
|
|
@@ -627,8 +617,7 @@ function jigAnthropicMessages(messages) {
|
|
|
627
617
|
];
|
|
628
618
|
}
|
|
629
619
|
jiggedMessages = jiggedMessages.reduce((acc, message) => {
|
|
630
|
-
if (acc.length === 0)
|
|
631
|
-
return [message];
|
|
620
|
+
if (acc.length === 0) return [message];
|
|
632
621
|
const lastMessage = acc[acc.length - 1];
|
|
633
622
|
if (lastMessage.role === message.role) {
|
|
634
623
|
const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [{ type: "text", text: lastMessage.content }];
|
|
@@ -877,8 +866,7 @@ function jigGoogleMessages(messages) {
|
|
|
877
866
|
];
|
|
878
867
|
}
|
|
879
868
|
jiggedMessages = jiggedMessages.reduce((acc, message) => {
|
|
880
|
-
if (acc.length === 0)
|
|
881
|
-
return [message];
|
|
869
|
+
if (acc.length === 0) return [message];
|
|
882
870
|
const lastMessage = acc[acc.length - 1];
|
|
883
871
|
if (lastMessage.role === message.role) {
|
|
884
872
|
lastMessage.parts = [...lastMessage.parts, ...message.parts];
|
|
@@ -916,8 +904,7 @@ async function prepareGoogleAIPayload(_identifier, payload) {
|
|
|
916
904
|
const toolNameById = /* @__PURE__ */ new Map();
|
|
917
905
|
for (const m of payload.messages) {
|
|
918
906
|
for (const fc of m.functionCalls || []) {
|
|
919
|
-
if (fc.id)
|
|
920
|
-
toolNameById.set(fc.id, fc.name);
|
|
907
|
+
if (fc.id) toolNameById.set(fc.id, fc.name);
|
|
921
908
|
}
|
|
922
909
|
}
|
|
923
910
|
for (const message of payload.messages) {
|
|
@@ -994,8 +981,7 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
994
981
|
contents,
|
|
995
982
|
generationConfig: { responseModalities: ["TEXT"] }
|
|
996
983
|
};
|
|
997
|
-
if (payload.tools)
|
|
998
|
-
requestBody.tools = [payload.tools];
|
|
984
|
+
if (payload.tools) requestBody.tools = [payload.tools];
|
|
999
985
|
if (payload.tools && payload.toolConfig) {
|
|
1000
986
|
requestBody.toolConfig = payload.toolConfig;
|
|
1001
987
|
}
|
|
@@ -1048,8 +1034,7 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
1048
1034
|
});
|
|
1049
1035
|
continue;
|
|
1050
1036
|
}
|
|
1051
|
-
if (part.text)
|
|
1052
|
-
text += part.text;
|
|
1037
|
+
if (part.text) text += part.text;
|
|
1053
1038
|
if ((_m = part.inlineData) == null ? void 0 : _m.data) {
|
|
1054
1039
|
files.push({ mimeType: "image/png", data: part.inlineData.data });
|
|
1055
1040
|
}
|
|
@@ -1126,21 +1111,15 @@ async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutM
|
|
|
1126
1111
|
finishReason: error2.finishReason,
|
|
1127
1112
|
modelVersion: error2.modelVersion
|
|
1128
1113
|
};
|
|
1129
|
-
if (error2.safetyRatings)
|
|
1130
|
-
|
|
1131
|
-
if (error2.usageMetadata)
|
|
1132
|
-
errorDetails.usageMetadata = error2.usageMetadata;
|
|
1114
|
+
if (error2.safetyRatings) errorDetails.safetyRatings = error2.safetyRatings;
|
|
1115
|
+
if (error2.usageMetadata) errorDetails.usageMetadata = error2.usageMetadata;
|
|
1133
1116
|
if (error2.promptFeedback)
|
|
1134
1117
|
errorDetails.promptFeedback = error2.promptFeedback;
|
|
1135
|
-
if (error2.status)
|
|
1136
|
-
|
|
1137
|
-
if (error2.
|
|
1138
|
-
errorDetails.errorCode = error2.code;
|
|
1139
|
-
if (error2.details)
|
|
1140
|
-
errorDetails.errorDetails = error2.details;
|
|
1118
|
+
if (error2.status) errorDetails.httpStatus = error2.status;
|
|
1119
|
+
if (error2.code) errorDetails.errorCode = error2.code;
|
|
1120
|
+
if (error2.details) errorDetails.errorDetails = error2.details;
|
|
1141
1121
|
const fileUris = payload.messages.flatMap((m) => m.parts).filter((p) => "fileData" in p).map((p) => p.fileData.fileUri);
|
|
1142
|
-
if (fileUris.length)
|
|
1143
|
-
errorDetails.fileUris = fileUris;
|
|
1122
|
+
if (fileUris.length) errorDetails.fileUris = fileUris;
|
|
1144
1123
|
logger_default.error(
|
|
1145
1124
|
id,
|
|
1146
1125
|
`Retry #${attempt} error: ${error2.message}`,
|
|
@@ -1220,16 +1199,13 @@ function prepareOpenAICompatMessages(messages) {
|
|
|
1220
1199
|
}
|
|
1221
1200
|
};
|
|
1222
1201
|
});
|
|
1223
|
-
if (!message.content)
|
|
1224
|
-
outMessage.content = null;
|
|
1202
|
+
if (!message.content) outMessage.content = null;
|
|
1225
1203
|
}
|
|
1226
|
-
if (message.reasoning)
|
|
1227
|
-
outMessage.reasoning = message.reasoning;
|
|
1204
|
+
if (message.reasoning) outMessage.reasoning = message.reasoning;
|
|
1228
1205
|
const reasoningDetails = filterOpenAICompatReasoningDetails(
|
|
1229
1206
|
message.reasoningDetails
|
|
1230
1207
|
);
|
|
1231
|
-
if (reasoningDetails)
|
|
1232
|
-
outMessage.reasoning_details = reasoningDetails;
|
|
1208
|
+
if (reasoningDetails) outMessage.reasoning_details = reasoningDetails;
|
|
1233
1209
|
out.push(outMessage);
|
|
1234
1210
|
}
|
|
1235
1211
|
return out;
|
|
@@ -1367,8 +1343,7 @@ function parseDsmlToolCalls(content) {
|
|
|
1367
1343
|
let last = -1;
|
|
1368
1344
|
let tag;
|
|
1369
1345
|
while ((tag = DSML_ANY_TAG_RE.exec(content)) !== null) {
|
|
1370
|
-
if (first === -1)
|
|
1371
|
-
first = tag.index;
|
|
1346
|
+
if (first === -1) first = tag.index;
|
|
1372
1347
|
last = tag.index + tag[0].length;
|
|
1373
1348
|
}
|
|
1374
1349
|
const remaining = first === -1 ? content : (content.slice(0, first) + content.slice(last)).trim();
|
|
@@ -1552,8 +1527,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1552
1527
|
(_b = result.provider) != null ? _b : result.provider = provider;
|
|
1553
1528
|
return result;
|
|
1554
1529
|
} catch (error2) {
|
|
1555
|
-
if ((_c = aiPayload.signal) == null ? void 0 : _c.aborted)
|
|
1556
|
-
throw error2;
|
|
1530
|
+
if ((_c = aiPayload.signal) == null ? void 0 : _c.aborted) throw error2;
|
|
1557
1531
|
if (aiPayload.fallbackModel) {
|
|
1558
1532
|
logger_default.error(
|
|
1559
1533
|
id,
|