@ramarivera/coding-agent-langfuse 0.1.10 → 0.1.11

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 +30 -17
  2. package/package.json +1 -1
package/dist/backfill.js CHANGED
@@ -523,7 +523,25 @@ function opencodeEvents(homeDir, rowLimit) {
523
523
  let messages = [];
524
524
  try {
525
525
  sessions = sqliteJsonByRowid(db, "session", "id, directory, time_created, time_updated, title, version, slug, project_id", undefined, rowLimit, 5_000);
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, 500);
526
+ messages = sqliteJsonByRowid(db, "message", [
527
+ "id",
528
+ "session_id",
529
+ "time_created",
530
+ "time_updated",
531
+ "json_extract(data, '$.role') as role",
532
+ "json_extract(data, '$.modelID') as model_id",
533
+ "json_extract(data, '$.providerID') as provider_id",
534
+ "json_extract(data, '$.model.modelID') as nested_model_id",
535
+ "json_extract(data, '$.model.providerID') as nested_provider_id",
536
+ "json_extract(data, '$.tokens') as tokens",
537
+ "json_extract(data, '$.usage') as usage",
538
+ "json_extract(data, '$.cost') as cost",
539
+ "json_extract(data, '$.parentID') as parent_id",
540
+ "json_extract(data, '$.path.cwd') as cwd",
541
+ "json_extract(data, '$.agent') as agent",
542
+ "json_extract(data, '$.mode') as mode",
543
+ "json_extract(data, '$.error') as error",
544
+ ].join(", "), undefined, rowLimit, 5_000);
527
545
  }
528
546
  catch (error) {
529
547
  console.error(`Skipping OpenCode history from ${db}: ${error instanceof Error ? error.message : String(error)}`);
@@ -548,34 +566,29 @@ function opencodeEvents(homeDir, rowLimit) {
548
566
  });
549
567
  }
550
568
  for (const message of messages) {
551
- if (asNumber(message.__include) === 0)
552
- continue;
553
569
  const sessionId = asString(message.session_id);
554
570
  const session = sessionsById.get(sessionId);
555
- const data = parseMaybeJson(message.data);
556
- const dataRecord = asRecord(data);
557
- const tokens = normalizeUsage(dataRecord.tokens);
571
+ const tokens = normalizeUsage(parseMaybeJson(message.tokens));
558
572
  const usage = tokens
559
- ? { ...tokens, cost: asNumber(dataRecord.cost) ?? tokens.cost }
560
- : normalizeUsage(dataRecord.usage);
573
+ ? { ...tokens, cost: asNumber(message.cost) ?? tokens.cost }
574
+ : normalizeUsage(parseMaybeJson(message.usage));
561
575
  events.push({
562
576
  agent: "opencode",
563
577
  sourcePath: db,
564
578
  sessionId: sessionId ?? stableId(db),
565
579
  recordId: asString(message.id) ?? stableId(JSON.stringify(message)),
566
- name: `opencode ${asString(dataRecord.role) ?? "message"}`,
567
- role: asString(dataRecord.role),
568
- model: asString(dataRecord.modelID) ??
569
- asString(getPath(dataRecord, ["model", "modelID"])),
570
- provider: asString(dataRecord.providerID) ??
571
- asString(getPath(dataRecord, ["model", "providerID"])),
572
- cwd: asString(getPath(dataRecord, ["path", "cwd"])) ??
580
+ name: `opencode ${asString(message.role) ?? "message"}`,
581
+ role: asString(message.role),
582
+ model: asString(message.model_id) ?? asString(message.nested_model_id),
583
+ provider: asString(message.provider_id) ??
584
+ asString(message.nested_provider_id),
585
+ cwd: asString(message.cwd) ??
573
586
  asString(asRecord(session).directory),
574
587
  startMs: getTimestampMs(message.time_created),
575
588
  endMs: getTimestampMs(message.time_updated),
576
- parentRecordId: asString(dataRecord.parentID) ?? "session",
589
+ parentRecordId: asString(message.parent_id) ?? "session",
577
590
  usage,
578
- metadata: pick(dataRecord, ["agent", "mode", "error"]),
591
+ metadata: pick(message, ["agent", "mode", "error"]),
579
592
  });
580
593
  }
581
594
  return events;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramarivera/coding-agent-langfuse",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Universal coding-agent Langfuse backfiller and live OTLP helpers",
5
5
  "type": "module",
6
6
  "license": "MIT",