@ramarivera/coding-agent-langfuse 0.1.9 → 0.1.11
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 +31 -18
- package/package.json +1 -1
package/dist/backfill.js
CHANGED
|
@@ -523,7 +523,25 @@ function opencodeEvents(homeDir, rowLimit) {
|
|
|
523
523
|
let messages = [];
|
|
524
524
|
try {
|
|
525
525
|
sessions = sqliteJsonByRowid(db, "session", "id, directory, time_created, time_updated, title, version, slug, project_id", undefined, rowLimit, 5_000);
|
|
526
|
-
messages = sqliteJsonByRowid(db, "message",
|
|
526
|
+
messages = sqliteJsonByRowid(db, "message", [
|
|
527
|
+
"id",
|
|
528
|
+
"session_id",
|
|
529
|
+
"time_created",
|
|
530
|
+
"time_updated",
|
|
531
|
+
"json_extract(data, '$.role') as role",
|
|
532
|
+
"json_extract(data, '$.modelID') as model_id",
|
|
533
|
+
"json_extract(data, '$.providerID') as provider_id",
|
|
534
|
+
"json_extract(data, '$.model.modelID') as nested_model_id",
|
|
535
|
+
"json_extract(data, '$.model.providerID') as nested_provider_id",
|
|
536
|
+
"json_extract(data, '$.tokens') as tokens",
|
|
537
|
+
"json_extract(data, '$.usage') as usage",
|
|
538
|
+
"json_extract(data, '$.cost') as cost",
|
|
539
|
+
"json_extract(data, '$.parentID') as parent_id",
|
|
540
|
+
"json_extract(data, '$.path.cwd') as cwd",
|
|
541
|
+
"json_extract(data, '$.agent') as agent",
|
|
542
|
+
"json_extract(data, '$.mode') as mode",
|
|
543
|
+
"json_extract(data, '$.error') as error",
|
|
544
|
+
].join(", "), undefined, rowLimit, 5_000);
|
|
527
545
|
}
|
|
528
546
|
catch (error) {
|
|
529
547
|
console.error(`Skipping OpenCode history from ${db}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -548,34 +566,29 @@ function opencodeEvents(homeDir, rowLimit) {
|
|
|
548
566
|
});
|
|
549
567
|
}
|
|
550
568
|
for (const message of messages) {
|
|
551
|
-
if (asNumber(message.__include) === 0)
|
|
552
|
-
continue;
|
|
553
569
|
const sessionId = asString(message.session_id);
|
|
554
570
|
const session = sessionsById.get(sessionId);
|
|
555
|
-
const
|
|
556
|
-
const dataRecord = asRecord(data);
|
|
557
|
-
const tokens = normalizeUsage(dataRecord.tokens);
|
|
571
|
+
const tokens = normalizeUsage(parseMaybeJson(message.tokens));
|
|
558
572
|
const usage = tokens
|
|
559
|
-
? { ...tokens, cost: asNumber(
|
|
560
|
-
: normalizeUsage(
|
|
573
|
+
? { ...tokens, cost: asNumber(message.cost) ?? tokens.cost }
|
|
574
|
+
: normalizeUsage(parseMaybeJson(message.usage));
|
|
561
575
|
events.push({
|
|
562
576
|
agent: "opencode",
|
|
563
577
|
sourcePath: db,
|
|
564
578
|
sessionId: sessionId ?? stableId(db),
|
|
565
579
|
recordId: asString(message.id) ?? stableId(JSON.stringify(message)),
|
|
566
|
-
name: `opencode ${asString(
|
|
567
|
-
role: asString(
|
|
568
|
-
model: asString(
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
cwd: asString(getPath(dataRecord, ["path", "cwd"])) ??
|
|
580
|
+
name: `opencode ${asString(message.role) ?? "message"}`,
|
|
581
|
+
role: asString(message.role),
|
|
582
|
+
model: asString(message.model_id) ?? asString(message.nested_model_id),
|
|
583
|
+
provider: asString(message.provider_id) ??
|
|
584
|
+
asString(message.nested_provider_id),
|
|
585
|
+
cwd: asString(message.cwd) ??
|
|
573
586
|
asString(asRecord(session).directory),
|
|
574
587
|
startMs: getTimestampMs(message.time_created),
|
|
575
588
|
endMs: getTimestampMs(message.time_updated),
|
|
576
|
-
parentRecordId: asString(
|
|
589
|
+
parentRecordId: asString(message.parent_id) ?? "session",
|
|
577
590
|
usage,
|
|
578
|
-
metadata: pick(
|
|
591
|
+
metadata: pick(message, ["agent", "mode", "error"]),
|
|
579
592
|
});
|
|
580
593
|
}
|
|
581
594
|
return events;
|
|
@@ -583,7 +596,7 @@ function opencodeEvents(homeDir, rowLimit) {
|
|
|
583
596
|
function sqliteJson(db, sql) {
|
|
584
597
|
const output = execFileSync("sqlite3", ["-readonly", "-json", db, sql], {
|
|
585
598
|
encoding: "utf8",
|
|
586
|
-
maxBuffer:
|
|
599
|
+
maxBuffer: 1024 * 1024 * 1024,
|
|
587
600
|
stdio: ["ignore", "pipe", "ignore"],
|
|
588
601
|
});
|
|
589
602
|
return JSON.parse(output || "[]");
|