@ramarivera/coding-agent-langfuse 0.1.6 → 0.1.8
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 -4
- package/package.json +1 -1
package/dist/backfill.js
CHANGED
|
@@ -522,8 +522,8 @@ function opencodeEvents(homeDir, rowLimit) {
|
|
|
522
522
|
let sessions = [];
|
|
523
523
|
let messages = [];
|
|
524
524
|
try {
|
|
525
|
-
sessions =
|
|
526
|
-
messages =
|
|
525
|
+
sessions = sqliteJsonByRowid(db, "session", "id, directory, time_created, time_updated, title, version, slug, project_id", undefined, rowLimit);
|
|
526
|
+
messages = sqliteJsonByRowid(db, "message", "id, session_id, time_created, time_updated, case when length(data) <= 1000000 then data else null end as data, length(data) <= 1000000 as __include", undefined, rowLimit);
|
|
527
527
|
}
|
|
528
528
|
catch (error) {
|
|
529
529
|
console.error(`Skipping OpenCode history from ${db}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -548,6 +548,8 @@ function opencodeEvents(homeDir, rowLimit) {
|
|
|
548
548
|
});
|
|
549
549
|
}
|
|
550
550
|
for (const message of messages) {
|
|
551
|
+
if (asNumber(message.__include) === 0)
|
|
552
|
+
continue;
|
|
551
553
|
const sessionId = asString(message.session_id);
|
|
552
554
|
const session = sessionsById.get(sessionId);
|
|
553
555
|
const data = parseMaybeJson(message.data);
|
|
@@ -586,17 +588,27 @@ function sqliteJson(db, sql) {
|
|
|
586
588
|
});
|
|
587
589
|
return JSON.parse(output || "[]");
|
|
588
590
|
}
|
|
589
|
-
function
|
|
591
|
+
function sqliteJsonByRowid(db, table, columns, whereClause, rowLimit) {
|
|
590
592
|
const pageSize = 5_000;
|
|
591
593
|
const rows = [];
|
|
594
|
+
let lastRowid = 0;
|
|
592
595
|
while (rowLimit === undefined || rows.length < rowLimit) {
|
|
593
596
|
const remaining = rowLimit === undefined
|
|
594
597
|
? pageSize
|
|
595
598
|
: Math.min(pageSize, Math.max(rowLimit - rows.length, 0));
|
|
596
599
|
if (remaining <= 0)
|
|
597
600
|
break;
|
|
598
|
-
const
|
|
601
|
+
const conditions = [`rowid > ${lastRowid}`];
|
|
602
|
+
if (whereClause)
|
|
603
|
+
conditions.push(`(${whereClause})`);
|
|
604
|
+
const page = sqliteJson(db, `select rowid as __rowid, ${columns} from ${table} where ${conditions.join(" and ")} order by rowid limit ${remaining};`);
|
|
599
605
|
rows.push(...page);
|
|
606
|
+
const nextRowid = page
|
|
607
|
+
.map((row) => asNumber(row.__rowid) ?? lastRowid)
|
|
608
|
+
.reduce((max, rowid) => Math.max(max, rowid), lastRowid);
|
|
609
|
+
if (nextRowid <= lastRowid)
|
|
610
|
+
break;
|
|
611
|
+
lastRowid = nextRowid;
|
|
600
612
|
if (page.length < remaining)
|
|
601
613
|
break;
|
|
602
614
|
}
|