190proof 1.0.119 → 1.0.122
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 +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +40 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -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,
|
|
@@ -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");
|
|
@@ -870,7 +890,8 @@ ${text}` : text;
|
|
|
870
890
|
prompt_tokens: promptTokens,
|
|
871
891
|
completion_tokens: data.usage.output_tokens,
|
|
872
892
|
total_tokens: promptTokens + data.usage.output_tokens,
|
|
873
|
-
cached_tokens: cacheRead
|
|
893
|
+
cached_tokens: cacheRead,
|
|
894
|
+
cache_write_tokens: cacheWrite
|
|
874
895
|
};
|
|
875
896
|
}
|
|
876
897
|
return {
|
|
@@ -1182,7 +1203,7 @@ async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutM
|
|
|
1182
1203
|
const fetchError = new Error(
|
|
1183
1204
|
"Google AI could not fetch the provided image URL(s)."
|
|
1184
1205
|
);
|
|
1185
|
-
fetchError.cause = error2;
|
|
1206
|
+
fetchError.cause = redactError(error2);
|
|
1186
1207
|
fetchError.googleFetchFailure = true;
|
|
1187
1208
|
throw fetchError;
|
|
1188
1209
|
}
|
|
@@ -1480,7 +1501,8 @@ function finalizeOpenRouterMessage(id, raw) {
|
|
|
1480
1501
|
prompt_tokens: raw.usage.prompt_tokens,
|
|
1481
1502
|
completion_tokens: raw.usage.completion_tokens,
|
|
1482
1503
|
total_tokens: raw.usage.total_tokens,
|
|
1483
|
-
cached_tokens: (_e = (_d = raw.usage.prompt_tokens_details) == null ? void 0 : _d.cached_tokens) != null ? _e : 0
|
|
1504
|
+
cached_tokens: (_e = (_d = raw.usage.prompt_tokens_details) == null ? void 0 : _d.cached_tokens) != null ? _e : 0,
|
|
1505
|
+
cost: typeof raw.usage.cost === "number" ? raw.usage.cost : void 0
|
|
1484
1506
|
} : null
|
|
1485
1507
|
};
|
|
1486
1508
|
}
|
|
@@ -1760,7 +1782,7 @@ async function callOpenRouterNonStreaming(id, payload, requestTimeoutMs = OPENRO
|
|
|
1760
1782
|
"OpenRouter",
|
|
1761
1783
|
requestTimeoutMs,
|
|
1762
1784
|
signal,
|
|
1763
|
-
(mergedSignal) => axios.post(openRouterEndpoint(), payload, {
|
|
1785
|
+
(mergedSignal) => axios.post(openRouterEndpoint(), { ...payload, usage: { include: true } }, {
|
|
1764
1786
|
headers: {
|
|
1765
1787
|
"content-type": "application/json",
|
|
1766
1788
|
Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`
|
|
@@ -1965,7 +1987,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1965
1987
|
(_e = result.provider) != null ? _e : result.provider = provider;
|
|
1966
1988
|
return result;
|
|
1967
1989
|
} catch (error2) {
|
|
1968
|
-
if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted) throw error2;
|
|
1990
|
+
if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted) throw redactError(error2);
|
|
1969
1991
|
if (aiPayload.fallbackModel) {
|
|
1970
1992
|
logger_default.error(
|
|
1971
1993
|
id,
|
|
@@ -1987,7 +2009,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1987
2009
|
chunkTimeoutMs
|
|
1988
2010
|
);
|
|
1989
2011
|
}
|
|
1990
|
-
throw error2;
|
|
2012
|
+
throw redactError(error2);
|
|
1991
2013
|
}
|
|
1992
2014
|
}
|
|
1993
2015
|
export {
|
|
@@ -2001,6 +2023,8 @@ export {
|
|
|
2001
2023
|
OpenRouterModel,
|
|
2002
2024
|
callWithRetries,
|
|
2003
2025
|
openRouterImageRejectedModels,
|
|
2004
|
-
parseModelString
|
|
2026
|
+
parseModelString,
|
|
2027
|
+
redactError,
|
|
2028
|
+
setLogger
|
|
2005
2029
|
};
|
|
2006
2030
|
//# sourceMappingURL=index.mjs.map
|