@ramarivera/coding-agent-langfuse 0.1.13 → 0.1.14
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 +12 -3
- 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 = "v7-host-independent-session-traces";
|
|
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");
|
|
@@ -345,6 +345,7 @@ function codexEvents(homeDir) {
|
|
|
345
345
|
asString(getPath(payload, ["model"]));
|
|
346
346
|
let currentModel = model;
|
|
347
347
|
let currentCwd = cwd;
|
|
348
|
+
const seenTokenCounts = new Set();
|
|
348
349
|
const events = [
|
|
349
350
|
{
|
|
350
351
|
agent: "codex",
|
|
@@ -420,6 +421,14 @@ function codexEvents(homeDir) {
|
|
|
420
421
|
const info = asRecord(rowPayload.info);
|
|
421
422
|
const usage = normalizeUsage(asRecord(info.last_token_usage)) ??
|
|
422
423
|
normalizeUsage(asRecord(info.total_token_usage));
|
|
424
|
+
const tokenKey = JSON.stringify({
|
|
425
|
+
timestamp,
|
|
426
|
+
model: asString(info.model) ?? currentModel,
|
|
427
|
+
usage,
|
|
428
|
+
});
|
|
429
|
+
if (seenTokenCounts.has(tokenKey))
|
|
430
|
+
continue;
|
|
431
|
+
seenTokenCounts.add(tokenKey);
|
|
423
432
|
events.push({
|
|
424
433
|
agent: "codex",
|
|
425
434
|
sourcePath: path,
|
|
@@ -740,10 +749,10 @@ function stableId(input) {
|
|
|
740
749
|
return createHash("sha256").update(input).digest("hex").slice(0, 32);
|
|
741
750
|
}
|
|
742
751
|
function fingerprint(event) {
|
|
743
|
-
return `${importIdentityVersion}:${event.agent}:${event.
|
|
752
|
+
return `${importIdentityVersion}:${event.agent}:${event.sessionId}:${event.recordId}`;
|
|
744
753
|
}
|
|
745
754
|
function traceFingerprint(event) {
|
|
746
|
-
return `${importIdentityVersion}:${event.agent}:${event.
|
|
755
|
+
return `${importIdentityVersion}:${event.agent}:${event.sessionId}`;
|
|
747
756
|
}
|
|
748
757
|
function traceId(event) {
|
|
749
758
|
return stableId(traceFingerprint(event));
|