billion-context 0.1.111-pr.777.621 → 0.1.111-pr.783.626
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/dist/index.js +14 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -54644,7 +54644,7 @@ function usageTotals(protocol, usage) {
|
|
|
54644
54644
|
}
|
|
54645
54645
|
if (protocol === "openai") {
|
|
54646
54646
|
const prompt = num4(usage["prompt_tokens"]);
|
|
54647
|
-
const cached = num4(usage["prompt_tokens_details"]?.["cached_tokens"]);
|
|
54647
|
+
const cached = num4(usage["prompt_tokens_details"]?.["cached_tokens"]) ?? num4(usage["prompt_cache_hit_tokens"]);
|
|
54648
54648
|
return {
|
|
54649
54649
|
total: prompt !== void 0 ? promptInputTotal("openai", prompt, cached) : void 0,
|
|
54650
54650
|
cached
|
|
@@ -55873,6 +55873,12 @@ function stripFinishReasonChunk(buf) {
|
|
|
55873
55873
|
return buf;
|
|
55874
55874
|
}
|
|
55875
55875
|
}
|
|
55876
|
+
function openaiCachedTokens(u2) {
|
|
55877
|
+
const pd = u2.prompt_tokens_details;
|
|
55878
|
+
if (typeof pd?.cached_tokens === "number") return pd.cached_tokens;
|
|
55879
|
+
if (typeof u2.prompt_cache_hit_tokens === "number") return u2.prompt_cache_hit_tokens;
|
|
55880
|
+
return void 0;
|
|
55881
|
+
}
|
|
55876
55882
|
function createOpenaiAdapter(requestBody, clientSystem, absorbName) {
|
|
55877
55883
|
const model = requestBody.model ?? "unknown";
|
|
55878
55884
|
let responseId = `chatcmpl-proxy-${Date.now()}`;
|
|
@@ -56062,12 +56068,11 @@ function createOpenaiAdapter(requestBody, clientSystem, absorbName) {
|
|
|
56062
56068
|
if (!choice) {
|
|
56063
56069
|
if (parsed.usage) {
|
|
56064
56070
|
const u2 = parsed.usage;
|
|
56065
|
-
const pd = u2.prompt_tokens_details;
|
|
56066
56071
|
yield {
|
|
56067
56072
|
kind: "usage",
|
|
56068
56073
|
inputTokens: typeof u2.prompt_tokens === "number" ? u2.prompt_tokens : void 0,
|
|
56069
56074
|
outputTokens: typeof u2.completion_tokens === "number" ? u2.completion_tokens : void 0,
|
|
56070
|
-
cachedTokens:
|
|
56075
|
+
cachedTokens: openaiCachedTokens(u2)
|
|
56071
56076
|
};
|
|
56072
56077
|
if (sawRealToolCall) {
|
|
56073
56078
|
yield { kind: "meta", chunk: rawBuf };
|
|
@@ -56082,12 +56087,11 @@ function createOpenaiAdapter(requestBody, clientSystem, absorbName) {
|
|
|
56082
56087
|
const hadToolCalls = [...pending.values()].some((tc) => tc.name.length > 0 || tc.id.length > 0);
|
|
56083
56088
|
yield* settleToolCalls();
|
|
56084
56089
|
const u2 = parsed.usage;
|
|
56085
|
-
const pd = u2?.prompt_tokens_details;
|
|
56086
56090
|
yield {
|
|
56087
56091
|
kind: "usage",
|
|
56088
56092
|
inputTokens: typeof u2?.prompt_tokens === "number" ? u2.prompt_tokens : void 0,
|
|
56089
56093
|
outputTokens: typeof u2?.completion_tokens === "number" ? u2.completion_tokens : void 0,
|
|
56090
|
-
cachedTokens:
|
|
56094
|
+
cachedTokens: u2 ? openaiCachedTokens(u2) : void 0
|
|
56091
56095
|
};
|
|
56092
56096
|
if (sawRealToolCall) {
|
|
56093
56097
|
const chunk = rawBuf;
|
|
@@ -58551,7 +58555,9 @@ function usageFromSseEvent(obj) {
|
|
|
58551
58555
|
return {
|
|
58552
58556
|
inputTokens: num3(usage["prompt_tokens"]),
|
|
58553
58557
|
outputTokens: num3(usage["completion_tokens"]),
|
|
58554
|
-
|
|
58558
|
+
// DeepSeek-style upstreams report KV-cache hits as top-level
|
|
58559
|
+
// prompt_cache_hit_tokens instead of the standard details field (#779).
|
|
58560
|
+
cachedTokens: num3(usage["prompt_tokens_details"]?.["cached_tokens"]) ?? num3(usage["prompt_cache_hit_tokens"])
|
|
58555
58561
|
};
|
|
58556
58562
|
}
|
|
58557
58563
|
return void 0;
|
|
@@ -59060,7 +59066,8 @@ async function pipePluginJson(stream2, res, session, protocol) {
|
|
|
59060
59066
|
applyUsageSample(session, {
|
|
59061
59067
|
inputTokens: input,
|
|
59062
59068
|
outputTokens: num3(usage["completion_tokens"]) ?? num3(usage["output_tokens"]),
|
|
59063
|
-
cachedTokens: num3(usage["prompt_tokens_details"]?.["cached_tokens"]) ?? num3(usage["input_tokens_details"]?.["cached_tokens"]) ?? num3(usage["cache_read_input_tokens"])
|
|
59069
|
+
cachedTokens: num3(usage["prompt_tokens_details"]?.["cached_tokens"]) ?? num3(usage["input_tokens_details"]?.["cached_tokens"]) ?? num3(usage["cache_read_input_tokens"]) ?? // #779: DeepSeek-style top-level field (openai wire)
|
|
59070
|
+
num3(usage["prompt_cache_hit_tokens"])
|
|
59064
59071
|
}, protocol);
|
|
59065
59072
|
markDirty(session);
|
|
59066
59073
|
}
|