@ramarivera/coding-agent-langfuse 0.1.6 → 0.1.7
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 +14 -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, data", "length(data) <= 1000000", rowLimit);
|
|
527
527
|
}
|
|
528
528
|
catch (error) {
|
|
529
529
|
console.error(`Skipping OpenCode history from ${db}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -586,17 +586,27 @@ function sqliteJson(db, sql) {
|
|
|
586
586
|
});
|
|
587
587
|
return JSON.parse(output || "[]");
|
|
588
588
|
}
|
|
589
|
-
function
|
|
589
|
+
function sqliteJsonByRowid(db, table, columns, whereClause, rowLimit) {
|
|
590
590
|
const pageSize = 5_000;
|
|
591
591
|
const rows = [];
|
|
592
|
+
let lastRowid = 0;
|
|
592
593
|
while (rowLimit === undefined || rows.length < rowLimit) {
|
|
593
594
|
const remaining = rowLimit === undefined
|
|
594
595
|
? pageSize
|
|
595
596
|
: Math.min(pageSize, Math.max(rowLimit - rows.length, 0));
|
|
596
597
|
if (remaining <= 0)
|
|
597
598
|
break;
|
|
598
|
-
const
|
|
599
|
+
const conditions = [`rowid > ${lastRowid}`];
|
|
600
|
+
if (whereClause)
|
|
601
|
+
conditions.push(`(${whereClause})`);
|
|
602
|
+
const page = sqliteJson(db, `select rowid as __rowid, ${columns} from ${table} where ${conditions.join(" and ")} order by rowid limit ${remaining};`);
|
|
599
603
|
rows.push(...page);
|
|
604
|
+
const nextRowid = page
|
|
605
|
+
.map((row) => asNumber(row.__rowid) ?? lastRowid)
|
|
606
|
+
.reduce((max, rowid) => Math.max(max, rowid), lastRowid);
|
|
607
|
+
if (nextRowid <= lastRowid)
|
|
608
|
+
break;
|
|
609
|
+
lastRowid = nextRowid;
|
|
600
610
|
if (page.length < remaining)
|
|
601
611
|
break;
|
|
602
612
|
}
|