@ramarivera/coding-agent-langfuse 0.1.5 → 0.1.6
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 +18 -5
- package/package.json +1 -1
package/dist/backfill.js
CHANGED
|
@@ -522,11 +522,8 @@ function opencodeEvents(homeDir, rowLimit) {
|
|
|
522
522
|
let sessions = [];
|
|
523
523
|
let messages = [];
|
|
524
524
|
try {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
: ` limit ${Math.max(rowLimit, 1)}`;
|
|
528
|
-
sessions = sqliteJson(db, `select * from session order by time_created${limitClause};`);
|
|
529
|
-
messages = sqliteJson(db, `select * from message where length(data) <= 1000000 order by time_created${limitClause};`);
|
|
525
|
+
sessions = sqliteJsonPaged(db, "select id, directory, time_created, time_updated, title, version, slug, project_id from session order by time_created", rowLimit);
|
|
526
|
+
messages = sqliteJsonPaged(db, "select id, session_id, time_created, time_updated, data from message where length(data) <= 1000000 order by time_created", rowLimit);
|
|
530
527
|
}
|
|
531
528
|
catch (error) {
|
|
532
529
|
console.error(`Skipping OpenCode history from ${db}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -589,6 +586,22 @@ function sqliteJson(db, sql) {
|
|
|
589
586
|
});
|
|
590
587
|
return JSON.parse(output || "[]");
|
|
591
588
|
}
|
|
589
|
+
function sqliteJsonPaged(db, baseSql, rowLimit) {
|
|
590
|
+
const pageSize = 5_000;
|
|
591
|
+
const rows = [];
|
|
592
|
+
while (rowLimit === undefined || rows.length < rowLimit) {
|
|
593
|
+
const remaining = rowLimit === undefined
|
|
594
|
+
? pageSize
|
|
595
|
+
: Math.min(pageSize, Math.max(rowLimit - rows.length, 0));
|
|
596
|
+
if (remaining <= 0)
|
|
597
|
+
break;
|
|
598
|
+
const page = sqliteJson(db, `${baseSql} limit ${remaining} offset ${rows.length};`);
|
|
599
|
+
rows.push(...page);
|
|
600
|
+
if (page.length < remaining)
|
|
601
|
+
break;
|
|
602
|
+
}
|
|
603
|
+
return rows;
|
|
604
|
+
}
|
|
592
605
|
function genericJsonlEvents(agent, files, sessionName) {
|
|
593
606
|
return files.flatMap((path) => {
|
|
594
607
|
const rows = parseJsonl(path).map(asRecord);
|