@ramarivera/coding-agent-langfuse 0.1.5 → 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.
Files changed (2) hide show
  1. package/dist/backfill.js +28 -5
  2. 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
- const limitClause = rowLimit === undefined
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 = 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);
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,32 @@ function sqliteJson(db, sql) {
589
586
  });
590
587
  return JSON.parse(output || "[]");
591
588
  }
589
+ function sqliteJsonByRowid(db, table, columns, whereClause, rowLimit) {
590
+ const pageSize = 5_000;
591
+ const rows = [];
592
+ let lastRowid = 0;
593
+ while (rowLimit === undefined || rows.length < rowLimit) {
594
+ const remaining = rowLimit === undefined
595
+ ? pageSize
596
+ : Math.min(pageSize, Math.max(rowLimit - rows.length, 0));
597
+ if (remaining <= 0)
598
+ break;
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};`);
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;
610
+ if (page.length < remaining)
611
+ break;
612
+ }
613
+ return rows;
614
+ }
592
615
  function genericJsonlEvents(agent, files, sessionName) {
593
616
  return files.flatMap((path) => {
594
617
  const rows = parseJsonl(path).map(asRecord);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramarivera/coding-agent-langfuse",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Universal coding-agent Langfuse backfiller and live OTLP helpers",
5
5
  "type": "module",
6
6
  "license": "MIT",