@ramarivera/coding-agent-langfuse 0.1.20 → 0.1.22
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.d.ts +5 -1
- package/dist/backfill.js +35 -6
- package/package.json +1 -1
package/dist/backfill.d.ts
CHANGED
|
@@ -62,7 +62,11 @@ declare function codexEvents(homeDir: string): BackfillEvent[];
|
|
|
62
62
|
declare function claudeEvents(homeDir: string): BackfillEvent[];
|
|
63
63
|
declare function piEvents(homeDir: string): BackfillEvent[];
|
|
64
64
|
declare function grokEvents(homeDir: string): BackfillEvent[];
|
|
65
|
-
declare function opencodeEvents(homeDir: string,
|
|
65
|
+
declare function opencodeEvents(homeDir: string, options?: {
|
|
66
|
+
rowLimit?: number;
|
|
67
|
+
sinceMs?: number;
|
|
68
|
+
untilMs?: number;
|
|
69
|
+
}): BackfillEvent[];
|
|
66
70
|
declare function fingerprint(event: BackfillEvent): string;
|
|
67
71
|
declare function toOtlp(events: BackfillEvent[]): Record<string, unknown>;
|
|
68
72
|
declare function discoverEvents(options: BackfillOptions): BackfillEvent[];
|
package/dist/backfill.js
CHANGED
|
@@ -659,15 +659,16 @@ function grokEvents(homeDir) {
|
|
|
659
659
|
const files = listFiles(join(homeDir, ".grok/sessions"), (path) => path.endsWith("chat_history.jsonl"));
|
|
660
660
|
return genericJsonlEvents("grok", files, "grok session");
|
|
661
661
|
}
|
|
662
|
-
function opencodeEvents(homeDir,
|
|
662
|
+
function opencodeEvents(homeDir, options = {}) {
|
|
663
663
|
const db = join(homeDir, ".local/share/opencode/opencode.db");
|
|
664
664
|
if (!existsSync(db))
|
|
665
665
|
return [];
|
|
666
|
+
const timeWhere = sqliteTimeWhere(options.sinceMs, options.untilMs);
|
|
666
667
|
let sessions = [];
|
|
667
668
|
let messages = [];
|
|
668
669
|
let parts = [];
|
|
669
670
|
try {
|
|
670
|
-
sessions = sqliteJsonByRowid(db, "session", "id, directory, time_created, time_updated, title, version, slug, project_id", undefined, rowLimit, 5_000);
|
|
671
|
+
sessions = sqliteJsonByRowid(db, "session", "id, directory, time_created, time_updated, title, version, slug, project_id", undefined, options.rowLimit, 5_000);
|
|
671
672
|
messages = sqliteJsonByRowid(db, "message", [
|
|
672
673
|
"id",
|
|
673
674
|
"session_id",
|
|
@@ -686,8 +687,11 @@ function opencodeEvents(homeDir, rowLimit) {
|
|
|
686
687
|
"json_extract(data, '$.agent') as agent",
|
|
687
688
|
"json_extract(data, '$.mode') as mode",
|
|
688
689
|
"json_extract(data, '$.error') as error",
|
|
689
|
-
].join(", "),
|
|
690
|
-
|
|
690
|
+
].join(", "), timeWhere, options.rowLimit, 5_000);
|
|
691
|
+
const messageIds = messages
|
|
692
|
+
.map((message) => asString(message.id))
|
|
693
|
+
.filter((id) => Boolean(id));
|
|
694
|
+
parts = sqliteJsonForIds(db, "part", "message_id", messageIds, [
|
|
691
695
|
"id",
|
|
692
696
|
"message_id",
|
|
693
697
|
"session_id",
|
|
@@ -695,7 +699,7 @@ function opencodeEvents(homeDir, rowLimit) {
|
|
|
695
699
|
"time_updated",
|
|
696
700
|
"json_extract(data, '$.type') as type",
|
|
697
701
|
"json_extract(data, '$') as data",
|
|
698
|
-
].join(", "),
|
|
702
|
+
].join(", "), 500);
|
|
699
703
|
}
|
|
700
704
|
catch (error) {
|
|
701
705
|
console.error(`Skipping OpenCode history from ${db}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -815,6 +819,27 @@ function opencodeEvents(homeDir, rowLimit) {
|
|
|
815
819
|
}
|
|
816
820
|
return events;
|
|
817
821
|
}
|
|
822
|
+
function sqliteTimeWhere(sinceMs, untilMs) {
|
|
823
|
+
const conditions = [
|
|
824
|
+
sinceMs === undefined ? undefined : `time_created >= ${Math.trunc(sinceMs)}`,
|
|
825
|
+
untilMs === undefined ? undefined : `time_created <= ${Math.trunc(untilMs)}`,
|
|
826
|
+
].filter((condition) => Boolean(condition));
|
|
827
|
+
return conditions.length > 0 ? conditions.join(" and ") : undefined;
|
|
828
|
+
}
|
|
829
|
+
function sqliteJsonForIds(db, table, idColumn, ids, columns, pageSize) {
|
|
830
|
+
const rows = [];
|
|
831
|
+
for (let index = 0; index < ids.length; index += pageSize) {
|
|
832
|
+
const pageIds = ids.slice(index, index + pageSize);
|
|
833
|
+
if (pageIds.length === 0)
|
|
834
|
+
continue;
|
|
835
|
+
const quotedIds = pageIds.map(sqliteQuote).join(", ");
|
|
836
|
+
rows.push(...sqliteJson(db, `select ${columns} from ${table} where ${idColumn} in (${quotedIds}) order by rowid;`));
|
|
837
|
+
}
|
|
838
|
+
return rows;
|
|
839
|
+
}
|
|
840
|
+
function sqliteQuote(value) {
|
|
841
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
842
|
+
}
|
|
818
843
|
function opencodeTextFromParts(parts) {
|
|
819
844
|
const text = parts
|
|
820
845
|
.map((part) => {
|
|
@@ -1247,7 +1272,11 @@ function discoverEvents(options) {
|
|
|
1247
1272
|
claude: (inner) => claudeEvents(inner.homeDir),
|
|
1248
1273
|
codex: (inner) => codexEvents(inner.homeDir),
|
|
1249
1274
|
grok: (inner) => grokEvents(inner.homeDir),
|
|
1250
|
-
opencode: (inner) => opencodeEvents(inner.homeDir,
|
|
1275
|
+
opencode: (inner) => opencodeEvents(inner.homeDir, {
|
|
1276
|
+
rowLimit: inner.limit,
|
|
1277
|
+
sinceMs: inner.sinceMs,
|
|
1278
|
+
untilMs: inner.untilMs,
|
|
1279
|
+
}),
|
|
1251
1280
|
pi: (inner) => piEvents(inner.homeDir),
|
|
1252
1281
|
};
|
|
1253
1282
|
return allAgents
|