@ramarivera/coding-agent-langfuse 0.1.15 → 0.1.16
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/backfill.js +16 -8
- package/package.json +1 -1
package/dist/backfill.js
CHANGED
|
@@ -5,7 +5,7 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSy
|
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
7
|
const allAgents = ["claude", "codex", "grok", "opencode", "pi"];
|
|
8
|
-
const importIdentityVersion = "
|
|
8
|
+
const importIdentityVersion = "v8-cached-input-token-split";
|
|
9
9
|
const defaultEndpoint = "https://langfuse.ai.roxasroot.net/otel/v1/traces";
|
|
10
10
|
const deadRemoteEndpoint = "http://langfuse.ai.roxasroot.net:14318/v1/traces";
|
|
11
11
|
const defaultStatePath = join(homedir(), ".local/state/coding-agent-langfuse/backfill-v6.json");
|
|
@@ -227,9 +227,11 @@ function normalizeUsage(value) {
|
|
|
227
227
|
asNumber(record.completion_tokens),
|
|
228
228
|
reasoning: asNumber(record.reasoning) ??
|
|
229
229
|
asNumber(record.reasoning_tokens) ??
|
|
230
|
+
asNumber(record.reasoning_output_tokens) ??
|
|
230
231
|
asNumber(outputDetails.reasoning_tokens),
|
|
231
232
|
cacheRead: asNumber(record.cacheRead) ??
|
|
232
233
|
asNumber(record.cache_read_input_tokens) ??
|
|
234
|
+
asNumber(record.cached_input_tokens) ??
|
|
233
235
|
asNumber(record.cached_tokens) ??
|
|
234
236
|
asNumber(inputDetails.cached_tokens) ??
|
|
235
237
|
asNumber(cache.read),
|
|
@@ -248,7 +250,6 @@ function normalizeUsage(value) {
|
|
|
248
250
|
const total = (usage.input ?? 0) +
|
|
249
251
|
(usage.output ?? 0) +
|
|
250
252
|
(usage.reasoning ?? 0) +
|
|
251
|
-
(usage.cacheRead ?? 0) +
|
|
252
253
|
(usage.cacheWrite ?? 0);
|
|
253
254
|
if (total > 0)
|
|
254
255
|
usage.total = total;
|
|
@@ -270,8 +271,13 @@ function usageDetails(usage) {
|
|
|
270
271
|
if (!usage)
|
|
271
272
|
return undefined;
|
|
272
273
|
const details = {};
|
|
273
|
-
|
|
274
|
-
|
|
274
|
+
const cachedInput = usage.cacheRead ?? 0;
|
|
275
|
+
const cacheWrite = usage.cacheWrite ?? 0;
|
|
276
|
+
const regularInput = usage.input === undefined
|
|
277
|
+
? undefined
|
|
278
|
+
: Math.max(usage.input - cachedInput - cacheWrite, 0);
|
|
279
|
+
if (regularInput !== undefined)
|
|
280
|
+
details.input = regularInput;
|
|
275
281
|
if (usage.output !== undefined)
|
|
276
282
|
details.output = usage.output;
|
|
277
283
|
if (usage.reasoning !== undefined)
|
|
@@ -313,12 +319,14 @@ function costDetails(usage, model) {
|
|
|
313
319
|
return undefined;
|
|
314
320
|
const rates = pricingForModel(model);
|
|
315
321
|
if (rates) {
|
|
316
|
-
const
|
|
322
|
+
const cachedInput = usage.cacheRead ?? 0;
|
|
323
|
+
const cacheWriteTokens = usage.cacheWrite ?? 0;
|
|
324
|
+
const regularInput = Math.max((usage.input ?? 0) - cachedInput - cacheWriteTokens, 0);
|
|
325
|
+
const input = (regularInput * rates.input) / 1_000_000;
|
|
317
326
|
const output = (((usage.output ?? 0) + (usage.reasoning ?? 0)) * rates.output) /
|
|
318
327
|
1_000_000;
|
|
319
|
-
const cache_read = (
|
|
320
|
-
const cache_write = (
|
|
321
|
-
1_000_000;
|
|
328
|
+
const cache_read = (cachedInput * rates.cacheRead) / 1_000_000;
|
|
329
|
+
const cache_write = (cacheWriteTokens * rates.cacheWrite) / 1_000_000;
|
|
322
330
|
const total = input + output + cache_read + cache_write;
|
|
323
331
|
if (total > 0) {
|
|
324
332
|
return { input, output, cache_read, cache_write, total, source: "estimated" };
|