@ramarivera/coding-agent-langfuse 0.1.10 → 0.1.12
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 +29 -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,27 @@ 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
|
|
557
|
-
const tokens = normalizeUsage(dataRecord.tokens);
|
|
558
|
-
const usage = tokens
|
|
559
|
-
? { ...tokens, cost: asNumber(dataRecord.cost) ?? tokens.cost }
|
|
560
|
-
: normalizeUsage(dataRecord.usage);
|
|
571
|
+
const tokens = normalizeUsage(parseMaybeJson(message.tokens));
|
|
572
|
+
const usage = tokens ?? normalizeUsage(parseMaybeJson(message.usage));
|
|
561
573
|
events.push({
|
|
562
574
|
agent: "opencode",
|
|
563
575
|
sourcePath: db,
|
|
564
576
|
sessionId: sessionId ?? stableId(db),
|
|
565
577
|
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"])) ??
|
|
578
|
+
name: `opencode ${asString(message.role) ?? "message"}`,
|
|
579
|
+
role: asString(message.role),
|
|
580
|
+
model: asString(message.model_id) ?? asString(message.nested_model_id),
|
|
581
|
+
provider: asString(message.provider_id) ??
|
|
582
|
+
asString(message.nested_provider_id),
|
|
583
|
+
cwd: asString(message.cwd) ??
|
|
573
584
|
asString(asRecord(session).directory),
|
|
574
585
|
startMs: getTimestampMs(message.time_created),
|
|
575
586
|
endMs: getTimestampMs(message.time_updated),
|
|
576
|
-
parentRecordId: asString(
|
|
587
|
+
parentRecordId: asString(message.parent_id) ?? "session",
|
|
577
588
|
usage,
|
|
578
|
-
metadata: pick(
|
|
589
|
+
metadata: pick(message, ["agent", "mode", "error"]),
|
|
579
590
|
});
|
|
580
591
|
}
|
|
581
592
|
return events;
|