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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 190proof
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An opinionated unified interface for interacting with multiple AI providers including **OpenAI**, **Anthropic**, **Google**, **Groq**, **OpenRouter**, and **AWS Bedrock**. This package provides a consistent API for making requests to different LLM providers while handling retries, streaming, and multimodal inputs.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
package/dist/index.js
CHANGED
|
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
33
|
ClaudeModel: () => ClaudeModel,
|
|
34
34
|
GPTModel: () => GPTModel,
|
|
35
35
|
GeminiModel: () => GeminiModel,
|
|
@@ -38,7 +38,7 @@ __export(proof_exports, {
|
|
|
38
38
|
callWithRetries: () => callWithRetries,
|
|
39
39
|
parseModelString: () => parseModelString
|
|
40
40
|
});
|
|
41
|
-
module.exports = __toCommonJS(
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
42
|
|
|
43
43
|
// interfaces.ts
|
|
44
44
|
var ClaudeModel = /* @__PURE__ */ ((ClaudeModel2) => {
|
|
@@ -156,8 +156,7 @@ async function withRetries(identifier, apiName, fn, options = {}) {
|
|
|
156
156
|
return await fn();
|
|
157
157
|
} catch (error3) {
|
|
158
158
|
lastError = error3;
|
|
159
|
-
if ((_a = options.signal) == null ? void 0 : _a.aborted)
|
|
160
|
-
throw error3;
|
|
159
|
+
if ((_a = options.signal) == null ? void 0 : _a.aborted) throw error3;
|
|
161
160
|
if (onError) {
|
|
162
161
|
onError(error3, attempt);
|
|
163
162
|
} else {
|
|
@@ -181,8 +180,7 @@ function parseStreamedResponse(identifier, paragraph, toolCallAccumulators, allo
|
|
|
181
180
|
const functionCalls = [];
|
|
182
181
|
for (let i = 0; i < toolCallAccumulators.length; i++) {
|
|
183
182
|
const acc = toolCallAccumulators[i];
|
|
184
|
-
if (!acc.name || !acc.arguments)
|
|
185
|
-
continue;
|
|
183
|
+
if (!acc.name || !acc.arguments) continue;
|
|
186
184
|
if (allowedFunctionNames && !allowedFunctionNames.has(acc.name)) {
|
|
187
185
|
throw new Error(
|
|
188
186
|
`Stream error: received function call with unknown name: ${acc.name}`
|
|
@@ -321,8 +319,7 @@ function buildOpenAIRequestConfig(identifier, model, config) {
|
|
|
321
319
|
};
|
|
322
320
|
}
|
|
323
321
|
function filterOpenAICompatReasoningDetails(details) {
|
|
324
|
-
if (!Array.isArray(details))
|
|
325
|
-
return details || void 0;
|
|
322
|
+
if (!Array.isArray(details)) return details || void 0;
|
|
326
323
|
const blocks = details.filter(
|
|
327
324
|
(block) => typeof (block == null ? void 0 : block.type) === "string" && block.type.startsWith("reasoning.")
|
|
328
325
|
);
|
|
@@ -393,13 +390,11 @@ async function prepareOpenAIPayload(identifier, payload) {
|
|
|
393
390
|
};
|
|
394
391
|
});
|
|
395
392
|
}
|
|
396
|
-
if (message.reasoning)
|
|
397
|
-
outMessage.reasoning = message.reasoning;
|
|
393
|
+
if (message.reasoning) outMessage.reasoning = message.reasoning;
|
|
398
394
|
const reasoningDetails = filterOpenAICompatReasoningDetails(
|
|
399
395
|
message.reasoningDetails
|
|
400
396
|
);
|
|
401
|
-
if (reasoningDetails)
|
|
402
|
-
outMessage.reasoning_details = reasoningDetails;
|
|
397
|
+
if (reasoningDetails) outMessage.reasoning_details = reasoningDetails;
|
|
403
398
|
preparedPayload.messages.push(outMessage);
|
|
404
399
|
}
|
|
405
400
|
return preparedPayload;
|
|
@@ -461,8 +456,7 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
461
456
|
}
|
|
462
457
|
const jsonStrings = chunk.split(/^data: /gm);
|
|
463
458
|
for (const jsonString of jsonStrings) {
|
|
464
|
-
if (!jsonString)
|
|
465
|
-
continue;
|
|
459
|
+
if (!jsonString) continue;
|
|
466
460
|
if (jsonString.includes("[DONE]")) {
|
|
467
461
|
clearTimeout(overallTimeout);
|
|
468
462
|
return parseStreamedResponse(
|
|
@@ -500,8 +494,7 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
500
494
|
while (toolCallAccumulators.length <= idx) {
|
|
501
495
|
toolCallAccumulators.push({ name: "", arguments: "" });
|
|
502
496
|
}
|
|
503
|
-
if (toolCall.id)
|
|
504
|
-
toolCallAccumulators[idx].id = toolCall.id;
|
|
497
|
+
if (toolCall.id) toolCallAccumulators[idx].id = toolCall.id;
|
|
505
498
|
if ((_e = toolCall.function) == null ? void 0 : _e.name)
|
|
506
499
|
toolCallAccumulators[idx].name += toolCall.function.name;
|
|
507
500
|
if ((_f = toolCall.function) == null ? void 0 : _f.arguments)
|
|
@@ -509,11 +502,9 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
509
502
|
}
|
|
510
503
|
}
|
|
511
504
|
const text = (_h = (_g = json.choices[0]) == null ? void 0 : _g.delta) == null ? void 0 : _h.content;
|
|
512
|
-
if (text)
|
|
513
|
-
paragraph += text;
|
|
505
|
+
if (text) paragraph += text;
|
|
514
506
|
const reasoningDelta = (_j = (_i = json.choices[0]) == null ? void 0 : _i.delta) == null ? void 0 : _j.reasoning;
|
|
515
|
-
if (reasoningDelta)
|
|
516
|
-
reasoning += reasoningDelta;
|
|
507
|
+
if (reasoningDelta) reasoning += reasoningDelta;
|
|
517
508
|
}
|
|
518
509
|
}
|
|
519
510
|
}
|
|
@@ -658,8 +649,7 @@ function jigAnthropicMessages(messages) {
|
|
|
658
649
|
];
|
|
659
650
|
}
|
|
660
651
|
jiggedMessages = jiggedMessages.reduce((acc, message) => {
|
|
661
|
-
if (acc.length === 0)
|
|
662
|
-
return [message];
|
|
652
|
+
if (acc.length === 0) return [message];
|
|
663
653
|
const lastMessage = acc[acc.length - 1];
|
|
664
654
|
if (lastMessage.role === message.role) {
|
|
665
655
|
const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [{ type: "text", text: lastMessage.content }];
|
|
@@ -908,8 +898,7 @@ function jigGoogleMessages(messages) {
|
|
|
908
898
|
];
|
|
909
899
|
}
|
|
910
900
|
jiggedMessages = jiggedMessages.reduce((acc, message) => {
|
|
911
|
-
if (acc.length === 0)
|
|
912
|
-
return [message];
|
|
901
|
+
if (acc.length === 0) return [message];
|
|
913
902
|
const lastMessage = acc[acc.length - 1];
|
|
914
903
|
if (lastMessage.role === message.role) {
|
|
915
904
|
lastMessage.parts = [...lastMessage.parts, ...message.parts];
|
|
@@ -947,8 +936,7 @@ async function prepareGoogleAIPayload(_identifier, payload) {
|
|
|
947
936
|
const toolNameById = /* @__PURE__ */ new Map();
|
|
948
937
|
for (const m of payload.messages) {
|
|
949
938
|
for (const fc of m.functionCalls || []) {
|
|
950
|
-
if (fc.id)
|
|
951
|
-
toolNameById.set(fc.id, fc.name);
|
|
939
|
+
if (fc.id) toolNameById.set(fc.id, fc.name);
|
|
952
940
|
}
|
|
953
941
|
}
|
|
954
942
|
for (const message of payload.messages) {
|
|
@@ -1025,8 +1013,7 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
1025
1013
|
contents,
|
|
1026
1014
|
generationConfig: { responseModalities: ["TEXT"] }
|
|
1027
1015
|
};
|
|
1028
|
-
if (payload.tools)
|
|
1029
|
-
requestBody.tools = [payload.tools];
|
|
1016
|
+
if (payload.tools) requestBody.tools = [payload.tools];
|
|
1030
1017
|
if (payload.tools && payload.toolConfig) {
|
|
1031
1018
|
requestBody.toolConfig = payload.toolConfig;
|
|
1032
1019
|
}
|
|
@@ -1079,8 +1066,7 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
1079
1066
|
});
|
|
1080
1067
|
continue;
|
|
1081
1068
|
}
|
|
1082
|
-
if (part.text)
|
|
1083
|
-
text += part.text;
|
|
1069
|
+
if (part.text) text += part.text;
|
|
1084
1070
|
if ((_m = part.inlineData) == null ? void 0 : _m.data) {
|
|
1085
1071
|
files.push({ mimeType: "image/png", data: part.inlineData.data });
|
|
1086
1072
|
}
|
|
@@ -1157,21 +1143,15 @@ async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutM
|
|
|
1157
1143
|
finishReason: error2.finishReason,
|
|
1158
1144
|
modelVersion: error2.modelVersion
|
|
1159
1145
|
};
|
|
1160
|
-
if (error2.safetyRatings)
|
|
1161
|
-
|
|
1162
|
-
if (error2.usageMetadata)
|
|
1163
|
-
errorDetails.usageMetadata = error2.usageMetadata;
|
|
1146
|
+
if (error2.safetyRatings) errorDetails.safetyRatings = error2.safetyRatings;
|
|
1147
|
+
if (error2.usageMetadata) errorDetails.usageMetadata = error2.usageMetadata;
|
|
1164
1148
|
if (error2.promptFeedback)
|
|
1165
1149
|
errorDetails.promptFeedback = error2.promptFeedback;
|
|
1166
|
-
if (error2.status)
|
|
1167
|
-
|
|
1168
|
-
if (error2.
|
|
1169
|
-
errorDetails.errorCode = error2.code;
|
|
1170
|
-
if (error2.details)
|
|
1171
|
-
errorDetails.errorDetails = error2.details;
|
|
1150
|
+
if (error2.status) errorDetails.httpStatus = error2.status;
|
|
1151
|
+
if (error2.code) errorDetails.errorCode = error2.code;
|
|
1152
|
+
if (error2.details) errorDetails.errorDetails = error2.details;
|
|
1172
1153
|
const fileUris = payload.messages.flatMap((m) => m.parts).filter((p) => "fileData" in p).map((p) => p.fileData.fileUri);
|
|
1173
|
-
if (fileUris.length)
|
|
1174
|
-
errorDetails.fileUris = fileUris;
|
|
1154
|
+
if (fileUris.length) errorDetails.fileUris = fileUris;
|
|
1175
1155
|
logger_default.error(
|
|
1176
1156
|
id,
|
|
1177
1157
|
`Retry #${attempt} error: ${error2.message}`,
|
|
@@ -1251,16 +1231,13 @@ function prepareOpenAICompatMessages(messages) {
|
|
|
1251
1231
|
}
|
|
1252
1232
|
};
|
|
1253
1233
|
});
|
|
1254
|
-
if (!message.content)
|
|
1255
|
-
outMessage.content = null;
|
|
1234
|
+
if (!message.content) outMessage.content = null;
|
|
1256
1235
|
}
|
|
1257
|
-
if (message.reasoning)
|
|
1258
|
-
outMessage.reasoning = message.reasoning;
|
|
1236
|
+
if (message.reasoning) outMessage.reasoning = message.reasoning;
|
|
1259
1237
|
const reasoningDetails = filterOpenAICompatReasoningDetails(
|
|
1260
1238
|
message.reasoningDetails
|
|
1261
1239
|
);
|
|
1262
|
-
if (reasoningDetails)
|
|
1263
|
-
outMessage.reasoning_details = reasoningDetails;
|
|
1240
|
+
if (reasoningDetails) outMessage.reasoning_details = reasoningDetails;
|
|
1264
1241
|
out.push(outMessage);
|
|
1265
1242
|
}
|
|
1266
1243
|
return out;
|
|
@@ -1398,8 +1375,7 @@ function parseDsmlToolCalls(content) {
|
|
|
1398
1375
|
let last = -1;
|
|
1399
1376
|
let tag;
|
|
1400
1377
|
while ((tag = DSML_ANY_TAG_RE.exec(content)) !== null) {
|
|
1401
|
-
if (first === -1)
|
|
1402
|
-
first = tag.index;
|
|
1378
|
+
if (first === -1) first = tag.index;
|
|
1403
1379
|
last = tag.index + tag[0].length;
|
|
1404
1380
|
}
|
|
1405
1381
|
const remaining = first === -1 ? content : (content.slice(0, first) + content.slice(last)).trim();
|
|
@@ -1583,8 +1559,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1583
1559
|
(_b = result.provider) != null ? _b : result.provider = provider;
|
|
1584
1560
|
return result;
|
|
1585
1561
|
} catch (error2) {
|
|
1586
|
-
if ((_c = aiPayload.signal) == null ? void 0 : _c.aborted)
|
|
1587
|
-
throw error2;
|
|
1562
|
+
if ((_c = aiPayload.signal) == null ? void 0 : _c.aborted) throw error2;
|
|
1588
1563
|
if (aiPayload.fallbackModel) {
|
|
1589
1564
|
logger_default.error(
|
|
1590
1565
|
id,
|