190proof 1.0.118 → 1.0.120
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 +13 -0
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +67 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
5
5
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
// interfaces.ts
|
|
8
|
+
// src/interfaces.ts
|
|
9
9
|
var ClaudeModel = /* @__PURE__ */ ((ClaudeModel2) => {
|
|
10
10
|
ClaudeModel2["HAIKU_3"] = "claude-3-haiku-20240307";
|
|
11
11
|
ClaudeModel2["SONNET_3"] = "claude-3-sonnet-20240229";
|
|
@@ -64,7 +64,7 @@ var GeminiModel = /* @__PURE__ */ ((GeminiModel2) => {
|
|
|
64
64
|
return GeminiModel2;
|
|
65
65
|
})(GeminiModel || {});
|
|
66
66
|
|
|
67
|
-
// logger.ts
|
|
67
|
+
// src/logger.ts
|
|
68
68
|
function formatIdentifier(identifier) {
|
|
69
69
|
if (Array.isArray(identifier)) {
|
|
70
70
|
return identifier.map((id) => `[${id}]`).join(" ");
|
|
@@ -74,14 +74,34 @@ function formatIdentifier(identifier) {
|
|
|
74
74
|
function formatMessage(level, identifier, message) {
|
|
75
75
|
return `[${level}] ${formatIdentifier(identifier)} ${message}`;
|
|
76
76
|
}
|
|
77
|
+
var sink = console;
|
|
78
|
+
function setLogger(next) {
|
|
79
|
+
sink = next;
|
|
80
|
+
}
|
|
77
81
|
function log(identifier, message, ...args) {
|
|
78
|
-
|
|
82
|
+
sink == null ? void 0 : sink.log(formatMessage("LOG", identifier, message), ...args);
|
|
79
83
|
}
|
|
80
84
|
function warn(identifier, message, ...args) {
|
|
81
|
-
|
|
85
|
+
sink == null ? void 0 : sink.warn(formatMessage("WARN", identifier, message), ...args);
|
|
82
86
|
}
|
|
83
87
|
function error(identifier, message, ...args) {
|
|
84
|
-
|
|
88
|
+
sink == null ? void 0 : sink.error(formatMessage("ERROR", identifier, message), ...args);
|
|
89
|
+
}
|
|
90
|
+
function redactError(err) {
|
|
91
|
+
const e = err;
|
|
92
|
+
if (!e || typeof e !== "object" || !(e.config || e.request || e.isAxiosError)) {
|
|
93
|
+
return err;
|
|
94
|
+
}
|
|
95
|
+
const clean = new Error(e.message);
|
|
96
|
+
clean.name = e.name;
|
|
97
|
+
if (e.code !== void 0) clean.code = e.code;
|
|
98
|
+
if (e.status !== void 0) clean.status = e.status;
|
|
99
|
+
if (e.response) {
|
|
100
|
+
clean.response = { status: e.response.status, statusText: e.response.statusText, data: e.response.data };
|
|
101
|
+
}
|
|
102
|
+
if (e.data !== void 0) clean.data = e.data;
|
|
103
|
+
if (e.cause) clean.cause = redactError(e.cause);
|
|
104
|
+
return clean;
|
|
85
105
|
}
|
|
86
106
|
var logger_default = {
|
|
87
107
|
log,
|
|
@@ -89,14 +109,14 @@ var logger_default = {
|
|
|
89
109
|
error
|
|
90
110
|
};
|
|
91
111
|
|
|
92
|
-
// index.ts
|
|
112
|
+
// src/index.ts
|
|
93
113
|
import {
|
|
94
114
|
BedrockRuntimeClient,
|
|
95
115
|
InvokeModelCommand
|
|
96
116
|
} from "@aws-sdk/client-bedrock-runtime";
|
|
97
117
|
import axios from "axios";
|
|
98
118
|
|
|
99
|
-
// utils.ts
|
|
119
|
+
// src/utils.ts
|
|
100
120
|
function timeout(ms) {
|
|
101
121
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
102
122
|
}
|
|
@@ -106,7 +126,7 @@ function isHeicImage(name, mime) {
|
|
|
106
126
|
return ["heic", "heif", "heics"].includes(extension) || !!(mime && ["image/heic", "image/heif", "image/heic-sequence"].includes(mime));
|
|
107
127
|
}
|
|
108
128
|
|
|
109
|
-
// index.ts
|
|
129
|
+
// src/index.ts
|
|
110
130
|
var sharp = __require("sharp");
|
|
111
131
|
var decode = __require("heic-decode");
|
|
112
132
|
function anySignal(signals) {
|
|
@@ -144,7 +164,7 @@ async function withRetries(identifier, apiName, fn, options = {}) {
|
|
|
144
164
|
logger_default.error(
|
|
145
165
|
identifier,
|
|
146
166
|
`Retry #${attempt} error: ${error3.message}`,
|
|
147
|
-
((_b = error3.response) == null ? void 0 : _b.data) || error3
|
|
167
|
+
((_b = error3.response) == null ? void 0 : _b.data) || redactError(error3)
|
|
148
168
|
);
|
|
149
169
|
}
|
|
150
170
|
await timeout(baseDelayMs * attempt);
|
|
@@ -154,7 +174,7 @@ async function withRetries(identifier, apiName, fn, options = {}) {
|
|
|
154
174
|
const error2 = new Error(
|
|
155
175
|
`Failed to call ${apiName} API after ${retries} attempts: ${detail}`
|
|
156
176
|
);
|
|
157
|
-
error2.cause = lastError;
|
|
177
|
+
error2.cause = redactError(lastError);
|
|
158
178
|
throw error2;
|
|
159
179
|
}
|
|
160
180
|
function parseStreamedResponse(identifier, paragraph, toolCallAccumulators, allowedFunctionNames, reasoning) {
|
|
@@ -624,7 +644,7 @@ async function callOpenAiWithRetries(id, openAiPayload, openAiConfig, retries =
|
|
|
624
644
|
logger_default.error(
|
|
625
645
|
id,
|
|
626
646
|
`Retry #${attempt} error: ${error2.message}`,
|
|
627
|
-
((_a = error2.response) == null ? void 0 : _a.data) || error2.data || error2
|
|
647
|
+
((_a = error2.response) == null ? void 0 : _a.data) || error2.data || redactError(error2)
|
|
628
648
|
);
|
|
629
649
|
if (((_b = error2.data) == null ? void 0 : _b.code) === "content_policy_violation") {
|
|
630
650
|
logger_default.log(id, "Removing images due to content policy violation");
|
|
@@ -1182,7 +1202,7 @@ async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutM
|
|
|
1182
1202
|
const fetchError = new Error(
|
|
1183
1203
|
"Google AI could not fetch the provided image URL(s)."
|
|
1184
1204
|
);
|
|
1185
|
-
fetchError.cause = error2;
|
|
1205
|
+
fetchError.cause = redactError(error2);
|
|
1186
1206
|
fetchError.googleFetchFailure = true;
|
|
1187
1207
|
throw fetchError;
|
|
1188
1208
|
}
|
|
@@ -1529,6 +1549,14 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
|
|
|
1529
1549
|
let finishReason = null;
|
|
1530
1550
|
let sawDone = false;
|
|
1531
1551
|
let dataChunks = 0;
|
|
1552
|
+
const RAW_HEAD_MAX = 3e3;
|
|
1553
|
+
const RAW_TAIL_MAX = 1500;
|
|
1554
|
+
let rawHead = "";
|
|
1555
|
+
let rawTail = "";
|
|
1556
|
+
let generationId;
|
|
1557
|
+
const unreadKeys = /* @__PURE__ */ new Set();
|
|
1558
|
+
const KNOWN_DELTA_KEYS = /* @__PURE__ */ new Set(["role", "content", "reasoning", "reasoning_details", "tool_calls"]);
|
|
1559
|
+
const KNOWN_CHOICE_KEYS = /* @__PURE__ */ new Set(["index", "delta", "finish_reason", "native_finish_reason", "logprobs"]);
|
|
1532
1560
|
try {
|
|
1533
1561
|
armStallTimer();
|
|
1534
1562
|
const response = await fetch(openRouterEndpoint(), {
|
|
@@ -1580,6 +1608,11 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
|
|
|
1580
1608
|
sawDone = true;
|
|
1581
1609
|
break outer;
|
|
1582
1610
|
}
|
|
1611
|
+
if (rawHead.length < RAW_HEAD_MAX) {
|
|
1612
|
+
rawHead += dataStr.slice(0, RAW_HEAD_MAX - rawHead.length) + "\n";
|
|
1613
|
+
} else {
|
|
1614
|
+
rawTail = (rawTail + dataStr + "\n").slice(-RAW_TAIL_MAX);
|
|
1615
|
+
}
|
|
1583
1616
|
let json;
|
|
1584
1617
|
try {
|
|
1585
1618
|
json = JSON.parse(dataStr);
|
|
@@ -1601,6 +1634,7 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
|
|
|
1601
1634
|
throw error2;
|
|
1602
1635
|
}
|
|
1603
1636
|
if (json.provider) provider = json.provider;
|
|
1637
|
+
if (json.id && !generationId) generationId = json.id;
|
|
1604
1638
|
let useful = false;
|
|
1605
1639
|
if (json.usage) {
|
|
1606
1640
|
usage = json.usage;
|
|
@@ -1609,6 +1643,12 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
|
|
|
1609
1643
|
const choice = (_c = json.choices) == null ? void 0 : _c[0];
|
|
1610
1644
|
if (choice) {
|
|
1611
1645
|
const delta = (_d = choice.delta) != null ? _d : {};
|
|
1646
|
+
for (const k of Object.keys(choice)) {
|
|
1647
|
+
if (!KNOWN_CHOICE_KEYS.has(k) && choice[k] != null) unreadKeys.add(`choice.${k}`);
|
|
1648
|
+
}
|
|
1649
|
+
for (const k of Object.keys(delta)) {
|
|
1650
|
+
if (!KNOWN_DELTA_KEYS.has(k) && delta[k] != null && delta[k] !== "") unreadKeys.add(`delta.${k}`);
|
|
1651
|
+
}
|
|
1612
1652
|
if (delta.content) {
|
|
1613
1653
|
paragraph += delta.content;
|
|
1614
1654
|
useful = true;
|
|
@@ -1665,7 +1705,12 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
|
|
|
1665
1705
|
usage,
|
|
1666
1706
|
paragraph: paragraph.slice(0, 500),
|
|
1667
1707
|
reasoningChars: reasoning.length,
|
|
1668
|
-
toolCalls
|
|
1708
|
+
toolCalls,
|
|
1709
|
+
generationId,
|
|
1710
|
+
dataChunks,
|
|
1711
|
+
unreadKeys: [...unreadKeys],
|
|
1712
|
+
rawHead,
|
|
1713
|
+
rawTail: rawTail || void 0
|
|
1669
1714
|
})
|
|
1670
1715
|
});
|
|
1671
1716
|
} catch (error2) {
|
|
@@ -1940,7 +1985,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1940
1985
|
(_e = result.provider) != null ? _e : result.provider = provider;
|
|
1941
1986
|
return result;
|
|
1942
1987
|
} catch (error2) {
|
|
1943
|
-
if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted) throw error2;
|
|
1988
|
+
if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted) throw redactError(error2);
|
|
1944
1989
|
if (aiPayload.fallbackModel) {
|
|
1945
1990
|
logger_default.error(
|
|
1946
1991
|
id,
|
|
@@ -1962,7 +2007,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1962
2007
|
chunkTimeoutMs
|
|
1963
2008
|
);
|
|
1964
2009
|
}
|
|
1965
|
-
throw error2;
|
|
2010
|
+
throw redactError(error2);
|
|
1966
2011
|
}
|
|
1967
2012
|
}
|
|
1968
2013
|
export {
|
|
@@ -1976,6 +2021,8 @@ export {
|
|
|
1976
2021
|
OpenRouterModel,
|
|
1977
2022
|
callWithRetries,
|
|
1978
2023
|
openRouterImageRejectedModels,
|
|
1979
|
-
parseModelString
|
|
2024
|
+
parseModelString,
|
|
2025
|
+
redactError,
|
|
2026
|
+
setLogger
|
|
1980
2027
|
};
|
|
1981
2028
|
//# sourceMappingURL=index.mjs.map
|