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/README.md
CHANGED
|
@@ -323,6 +323,19 @@ interface ParsedResponseMessage {
|
|
|
323
323
|
}
|
|
324
324
|
```
|
|
325
325
|
|
|
326
|
+
### `setLogger(sink | null)`
|
|
327
|
+
|
|
328
|
+
190proof logs each call and retry to the console. Route those lines to your own logger, or pass `null` to silence them (useful when 190proof is a dependency of a library):
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
import { setLogger } from "190proof";
|
|
332
|
+
|
|
333
|
+
setLogger(null); // silent
|
|
334
|
+
setLogger({ log: myLog.info, warn: myLog.warn, error: myLog.error });
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Errors thrown by `callWithRetries` never carry the HTTP request (and so never the API key); provider status and response body stay on `error.response`.
|
|
338
|
+
|
|
326
339
|
### `parseModelString(model)`
|
|
327
340
|
|
|
328
341
|
Parses a model string into its provider and model ID components.
|
package/dist/index.d.mts
CHANGED
|
@@ -206,6 +206,17 @@ interface ParsedResponseMessage {
|
|
|
206
206
|
* when the provider reports none.
|
|
207
207
|
*/
|
|
208
208
|
thoughts_tokens?: number;
|
|
209
|
+
/**
|
|
210
|
+
* Prompt tokens written to the provider's cache (subset of prompt_tokens).
|
|
211
|
+
* Billed above the plain input rate on Anthropic (1.25x 5m, 2x 1h).
|
|
212
|
+
* Currently populated from Anthropic's `cache_creation_input_tokens`.
|
|
213
|
+
*/
|
|
214
|
+
cache_write_tokens?: number;
|
|
215
|
+
/**
|
|
216
|
+
* USD actually billed for this call, as reported by the provider.
|
|
217
|
+
* Currently populated from OpenRouter's `usage.cost`; undefined elsewhere.
|
|
218
|
+
*/
|
|
219
|
+
cost?: number;
|
|
209
220
|
} | null;
|
|
210
221
|
}
|
|
211
222
|
interface FunctionCall {
|
|
@@ -359,6 +370,26 @@ interface GenericPayload {
|
|
|
359
370
|
signal?: AbortSignal;
|
|
360
371
|
}
|
|
361
372
|
|
|
373
|
+
/** Where 190proof's own log lines go. Defaults to the console. */
|
|
374
|
+
interface LogSink {
|
|
375
|
+
log(message: string, ...args: any[]): void;
|
|
376
|
+
warn(message: string, ...args: any[]): void;
|
|
377
|
+
error(message: string, ...args: any[]): void;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Route 190proof's logging to your own logger, or pass null to silence it
|
|
381
|
+
* (useful when embedding the SDK in a library).
|
|
382
|
+
*/
|
|
383
|
+
declare function setLogger(next: LogSink | null): void;
|
|
384
|
+
/**
|
|
385
|
+
* HTTP client errors (axios) carry the full request config, API-key headers
|
|
386
|
+
* included; logging or rethrowing one as a `cause` leaks the key into every
|
|
387
|
+
* log that prints it. Rebuild a plain Error with only what callers use:
|
|
388
|
+
* message, name, code, and the response status + body. Non-HTTP errors pass
|
|
389
|
+
* through untouched.
|
|
390
|
+
*/
|
|
391
|
+
declare function redactError<T>(err: T): T | Error;
|
|
392
|
+
|
|
362
393
|
/**
|
|
363
394
|
* In-process memory of OpenRouter models that rejected image input (the
|
|
364
395
|
* routing-layer 404 "No endpoints found that support image input"). Payloads
|
|
@@ -382,4 +413,4 @@ declare function parseModelString(model: string): {
|
|
|
382
413
|
};
|
|
383
414
|
declare function callWithRetries(id: string | string[], aiPayload: GenericPayload, aiConfig?: OpenAIConfig | AnthropicAIConfig, retries?: number, chunkTimeoutMs?: number): Promise<ParsedResponseMessage>;
|
|
384
415
|
|
|
385
|
-
export { type AnyModel, ClaudeModel, type FunctionCall, type FunctionDefinition, GPTModel, GeminiModel, type GenericMessage, type GenericPayload, GroqModel, MIN_STREAM_ATTEMPT_MS, OPENROUTER_NONSTREAM_TIMEOUT_MS, OPENROUTER_STREAM_TIMEOUT_MS, type OpenAIConfig, OpenRouterModel, type OpenRouterProviderPreferences, type ParsedResponseMessage, type Provider, type ToolResult, callWithRetries, openRouterImageRejectedModels, parseModelString };
|
|
416
|
+
export { type AnyModel, ClaudeModel, type FunctionCall, type FunctionDefinition, GPTModel, GeminiModel, type GenericMessage, type GenericPayload, GroqModel, type LogSink, MIN_STREAM_ATTEMPT_MS, OPENROUTER_NONSTREAM_TIMEOUT_MS, OPENROUTER_STREAM_TIMEOUT_MS, type OpenAIConfig, OpenRouterModel, type OpenRouterProviderPreferences, type ParsedResponseMessage, type Provider, type ToolResult, callWithRetries, openRouterImageRejectedModels, parseModelString, redactError, setLogger };
|
package/dist/index.d.ts
CHANGED
|
@@ -206,6 +206,17 @@ interface ParsedResponseMessage {
|
|
|
206
206
|
* when the provider reports none.
|
|
207
207
|
*/
|
|
208
208
|
thoughts_tokens?: number;
|
|
209
|
+
/**
|
|
210
|
+
* Prompt tokens written to the provider's cache (subset of prompt_tokens).
|
|
211
|
+
* Billed above the plain input rate on Anthropic (1.25x 5m, 2x 1h).
|
|
212
|
+
* Currently populated from Anthropic's `cache_creation_input_tokens`.
|
|
213
|
+
*/
|
|
214
|
+
cache_write_tokens?: number;
|
|
215
|
+
/**
|
|
216
|
+
* USD actually billed for this call, as reported by the provider.
|
|
217
|
+
* Currently populated from OpenRouter's `usage.cost`; undefined elsewhere.
|
|
218
|
+
*/
|
|
219
|
+
cost?: number;
|
|
209
220
|
} | null;
|
|
210
221
|
}
|
|
211
222
|
interface FunctionCall {
|
|
@@ -359,6 +370,26 @@ interface GenericPayload {
|
|
|
359
370
|
signal?: AbortSignal;
|
|
360
371
|
}
|
|
361
372
|
|
|
373
|
+
/** Where 190proof's own log lines go. Defaults to the console. */
|
|
374
|
+
interface LogSink {
|
|
375
|
+
log(message: string, ...args: any[]): void;
|
|
376
|
+
warn(message: string, ...args: any[]): void;
|
|
377
|
+
error(message: string, ...args: any[]): void;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Route 190proof's logging to your own logger, or pass null to silence it
|
|
381
|
+
* (useful when embedding the SDK in a library).
|
|
382
|
+
*/
|
|
383
|
+
declare function setLogger(next: LogSink | null): void;
|
|
384
|
+
/**
|
|
385
|
+
* HTTP client errors (axios) carry the full request config, API-key headers
|
|
386
|
+
* included; logging or rethrowing one as a `cause` leaks the key into every
|
|
387
|
+
* log that prints it. Rebuild a plain Error with only what callers use:
|
|
388
|
+
* message, name, code, and the response status + body. Non-HTTP errors pass
|
|
389
|
+
* through untouched.
|
|
390
|
+
*/
|
|
391
|
+
declare function redactError<T>(err: T): T | Error;
|
|
392
|
+
|
|
362
393
|
/**
|
|
363
394
|
* In-process memory of OpenRouter models that rejected image input (the
|
|
364
395
|
* routing-layer 404 "No endpoints found that support image input"). Payloads
|
|
@@ -382,4 +413,4 @@ declare function parseModelString(model: string): {
|
|
|
382
413
|
};
|
|
383
414
|
declare function callWithRetries(id: string | string[], aiPayload: GenericPayload, aiConfig?: OpenAIConfig | AnthropicAIConfig, retries?: number, chunkTimeoutMs?: number): Promise<ParsedResponseMessage>;
|
|
384
415
|
|
|
385
|
-
export { type AnyModel, ClaudeModel, type FunctionCall, type FunctionDefinition, GPTModel, GeminiModel, type GenericMessage, type GenericPayload, GroqModel, MIN_STREAM_ATTEMPT_MS, OPENROUTER_NONSTREAM_TIMEOUT_MS, OPENROUTER_STREAM_TIMEOUT_MS, type OpenAIConfig, OpenRouterModel, type OpenRouterProviderPreferences, type ParsedResponseMessage, type Provider, type ToolResult, callWithRetries, openRouterImageRejectedModels, parseModelString };
|
|
416
|
+
export { type AnyModel, ClaudeModel, type FunctionCall, type FunctionDefinition, GPTModel, GeminiModel, type GenericMessage, type GenericPayload, GroqModel, type LogSink, MIN_STREAM_ATTEMPT_MS, OPENROUTER_NONSTREAM_TIMEOUT_MS, OPENROUTER_STREAM_TIMEOUT_MS, type OpenAIConfig, OpenRouterModel, type OpenRouterProviderPreferences, type ParsedResponseMessage, type Provider, type ToolResult, callWithRetries, openRouterImageRejectedModels, parseModelString, redactError, setLogger };
|
package/dist/index.js
CHANGED
|
@@ -40,7 +40,9 @@ __export(index_exports, {
|
|
|
40
40
|
OpenRouterModel: () => OpenRouterModel,
|
|
41
41
|
callWithRetries: () => callWithRetries,
|
|
42
42
|
openRouterImageRejectedModels: () => openRouterImageRejectedModels,
|
|
43
|
-
parseModelString: () => parseModelString
|
|
43
|
+
parseModelString: () => parseModelString,
|
|
44
|
+
redactError: () => redactError,
|
|
45
|
+
setLogger: () => setLogger
|
|
44
46
|
});
|
|
45
47
|
module.exports = __toCommonJS(index_exports);
|
|
46
48
|
|
|
@@ -113,14 +115,34 @@ function formatIdentifier(identifier) {
|
|
|
113
115
|
function formatMessage(level, identifier, message) {
|
|
114
116
|
return `[${level}] ${formatIdentifier(identifier)} ${message}`;
|
|
115
117
|
}
|
|
118
|
+
var sink = console;
|
|
119
|
+
function setLogger(next) {
|
|
120
|
+
sink = next;
|
|
121
|
+
}
|
|
116
122
|
function log(identifier, message, ...args) {
|
|
117
|
-
|
|
123
|
+
sink == null ? void 0 : sink.log(formatMessage("LOG", identifier, message), ...args);
|
|
118
124
|
}
|
|
119
125
|
function warn(identifier, message, ...args) {
|
|
120
|
-
|
|
126
|
+
sink == null ? void 0 : sink.warn(formatMessage("WARN", identifier, message), ...args);
|
|
121
127
|
}
|
|
122
128
|
function error(identifier, message, ...args) {
|
|
123
|
-
|
|
129
|
+
sink == null ? void 0 : sink.error(formatMessage("ERROR", identifier, message), ...args);
|
|
130
|
+
}
|
|
131
|
+
function redactError(err) {
|
|
132
|
+
const e = err;
|
|
133
|
+
if (!e || typeof e !== "object" || !(e.config || e.request || e.isAxiosError)) {
|
|
134
|
+
return err;
|
|
135
|
+
}
|
|
136
|
+
const clean = new Error(e.message);
|
|
137
|
+
clean.name = e.name;
|
|
138
|
+
if (e.code !== void 0) clean.code = e.code;
|
|
139
|
+
if (e.status !== void 0) clean.status = e.status;
|
|
140
|
+
if (e.response) {
|
|
141
|
+
clean.response = { status: e.response.status, statusText: e.response.statusText, data: e.response.data };
|
|
142
|
+
}
|
|
143
|
+
if (e.data !== void 0) clean.data = e.data;
|
|
144
|
+
if (e.cause) clean.cause = redactError(e.cause);
|
|
145
|
+
return clean;
|
|
124
146
|
}
|
|
125
147
|
var logger_default = {
|
|
126
148
|
log,
|
|
@@ -180,7 +202,7 @@ async function withRetries(identifier, apiName, fn, options = {}) {
|
|
|
180
202
|
logger_default.error(
|
|
181
203
|
identifier,
|
|
182
204
|
`Retry #${attempt} error: ${error3.message}`,
|
|
183
|
-
((_b = error3.response) == null ? void 0 : _b.data) || error3
|
|
205
|
+
((_b = error3.response) == null ? void 0 : _b.data) || redactError(error3)
|
|
184
206
|
);
|
|
185
207
|
}
|
|
186
208
|
await timeout(baseDelayMs * attempt);
|
|
@@ -190,7 +212,7 @@ async function withRetries(identifier, apiName, fn, options = {}) {
|
|
|
190
212
|
const error2 = new Error(
|
|
191
213
|
`Failed to call ${apiName} API after ${retries} attempts: ${detail}`
|
|
192
214
|
);
|
|
193
|
-
error2.cause = lastError;
|
|
215
|
+
error2.cause = redactError(lastError);
|
|
194
216
|
throw error2;
|
|
195
217
|
}
|
|
196
218
|
function parseStreamedResponse(identifier, paragraph, toolCallAccumulators, allowedFunctionNames, reasoning) {
|
|
@@ -660,7 +682,7 @@ async function callOpenAiWithRetries(id, openAiPayload, openAiConfig, retries =
|
|
|
660
682
|
logger_default.error(
|
|
661
683
|
id,
|
|
662
684
|
`Retry #${attempt} error: ${error2.message}`,
|
|
663
|
-
((_a = error2.response) == null ? void 0 : _a.data) || error2.data || error2
|
|
685
|
+
((_a = error2.response) == null ? void 0 : _a.data) || error2.data || redactError(error2)
|
|
664
686
|
);
|
|
665
687
|
if (((_b = error2.data) == null ? void 0 : _b.code) === "content_policy_violation") {
|
|
666
688
|
logger_default.log(id, "Removing images due to content policy violation");
|
|
@@ -906,7 +928,8 @@ ${text}` : text;
|
|
|
906
928
|
prompt_tokens: promptTokens,
|
|
907
929
|
completion_tokens: data.usage.output_tokens,
|
|
908
930
|
total_tokens: promptTokens + data.usage.output_tokens,
|
|
909
|
-
cached_tokens: cacheRead
|
|
931
|
+
cached_tokens: cacheRead,
|
|
932
|
+
cache_write_tokens: cacheWrite
|
|
910
933
|
};
|
|
911
934
|
}
|
|
912
935
|
return {
|
|
@@ -1218,7 +1241,7 @@ async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutM
|
|
|
1218
1241
|
const fetchError = new Error(
|
|
1219
1242
|
"Google AI could not fetch the provided image URL(s)."
|
|
1220
1243
|
);
|
|
1221
|
-
fetchError.cause = error2;
|
|
1244
|
+
fetchError.cause = redactError(error2);
|
|
1222
1245
|
fetchError.googleFetchFailure = true;
|
|
1223
1246
|
throw fetchError;
|
|
1224
1247
|
}
|
|
@@ -1516,7 +1539,8 @@ function finalizeOpenRouterMessage(id, raw) {
|
|
|
1516
1539
|
prompt_tokens: raw.usage.prompt_tokens,
|
|
1517
1540
|
completion_tokens: raw.usage.completion_tokens,
|
|
1518
1541
|
total_tokens: raw.usage.total_tokens,
|
|
1519
|
-
cached_tokens: (_e = (_d = raw.usage.prompt_tokens_details) == null ? void 0 : _d.cached_tokens) != null ? _e : 0
|
|
1542
|
+
cached_tokens: (_e = (_d = raw.usage.prompt_tokens_details) == null ? void 0 : _d.cached_tokens) != null ? _e : 0,
|
|
1543
|
+
cost: typeof raw.usage.cost === "number" ? raw.usage.cost : void 0
|
|
1520
1544
|
} : null
|
|
1521
1545
|
};
|
|
1522
1546
|
}
|
|
@@ -1796,7 +1820,7 @@ async function callOpenRouterNonStreaming(id, payload, requestTimeoutMs = OPENRO
|
|
|
1796
1820
|
"OpenRouter",
|
|
1797
1821
|
requestTimeoutMs,
|
|
1798
1822
|
signal,
|
|
1799
|
-
(mergedSignal) => import_axios.default.post(openRouterEndpoint(), payload, {
|
|
1823
|
+
(mergedSignal) => import_axios.default.post(openRouterEndpoint(), { ...payload, usage: { include: true } }, {
|
|
1800
1824
|
headers: {
|
|
1801
1825
|
"content-type": "application/json",
|
|
1802
1826
|
Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`
|
|
@@ -2001,7 +2025,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
2001
2025
|
(_e = result.provider) != null ? _e : result.provider = provider;
|
|
2002
2026
|
return result;
|
|
2003
2027
|
} catch (error2) {
|
|
2004
|
-
if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted) throw error2;
|
|
2028
|
+
if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted) throw redactError(error2);
|
|
2005
2029
|
if (aiPayload.fallbackModel) {
|
|
2006
2030
|
logger_default.error(
|
|
2007
2031
|
id,
|
|
@@ -2023,7 +2047,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
2023
2047
|
chunkTimeoutMs
|
|
2024
2048
|
);
|
|
2025
2049
|
}
|
|
2026
|
-
throw error2;
|
|
2050
|
+
throw redactError(error2);
|
|
2027
2051
|
}
|
|
2028
2052
|
}
|
|
2029
2053
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -2038,6 +2062,8 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
2038
2062
|
OpenRouterModel,
|
|
2039
2063
|
callWithRetries,
|
|
2040
2064
|
openRouterImageRejectedModels,
|
|
2041
|
-
parseModelString
|
|
2065
|
+
parseModelString,
|
|
2066
|
+
redactError,
|
|
2067
|
+
setLogger
|
|
2042
2068
|
});
|
|
2043
2069
|
//# sourceMappingURL=index.js.map
|