@ramarivera/coding-agent-langfuse 0.1.21 → 0.1.23

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 +54 -6
  2. package/package.json +1 -1
package/dist/backfill.js CHANGED
@@ -688,15 +688,28 @@ function opencodeEvents(homeDir, options = {}) {
688
688
  "json_extract(data, '$.mode') as mode",
689
689
  "json_extract(data, '$.error') as error",
690
690
  ].join(", "), timeWhere, options.rowLimit, 5_000);
691
- parts = sqliteJsonByRowid(db, "part", [
691
+ const messageIds = messages
692
+ .map((message) => asString(message.id))
693
+ .filter((id) => Boolean(id));
694
+ parts = sqliteJsonForIds(db, "part", "message_id", messageIds, [
692
695
  "id",
693
696
  "message_id",
694
697
  "session_id",
695
698
  "time_created",
696
699
  "time_updated",
697
700
  "json_extract(data, '$.type') as type",
698
- "json_extract(data, '$') as data",
699
- ].join(", "), timeWhere, options.rowLimit, 5_000);
701
+ "substr(json_extract(data, '$.text'), 1, 8000) as text",
702
+ "json_extract(data, '$.tool') as tool",
703
+ "json_extract(data, '$.callID') as call_id_upper",
704
+ "json_extract(data, '$.call_id') as call_id",
705
+ "substr(json_extract(data, '$.state.input'), 1, 8000) as state_input",
706
+ "substr(json_extract(data, '$.state.output'), 1, 8000) as state_output",
707
+ "json_extract(data, '$.state.status') as state_status",
708
+ "json_extract(data, '$.state.title') as state_title",
709
+ "json_type(data, '$.metadata.openai.reasoningEncryptedContent') is not null as has_encrypted_content",
710
+ "json_extract(data, '$.filename') as filename",
711
+ "json_extract(data, '$.url') as url",
712
+ ].join(", "), 500);
700
713
  }
701
714
  catch (error) {
702
715
  console.error(`Skipping OpenCode history from ${db}: ${error instanceof Error ? error.message : String(error)}`);
@@ -762,7 +775,7 @@ function opencodeEvents(homeDir, options = {}) {
762
775
  metadata: pick(message, ["agent", "mode", "error"]),
763
776
  });
764
777
  for (const part of messageParts) {
765
- const data = asRecord(parseMaybeJson(part.data));
778
+ const data = opencodePartData(part);
766
779
  const type = asString(part.type) ?? asString(data.type);
767
780
  const partId = asString(part.id) ?? stableId(JSON.stringify(part));
768
781
  const partStartMs = getTimestampMs(part.time_created, getTimestampMs(message.time_created));
@@ -783,7 +796,7 @@ function opencodeEvents(homeDir, options = {}) {
783
796
  parentRecordId: messageId,
784
797
  output: extractText(data.text),
785
798
  metadata: {
786
- has_encrypted_content: getPath(data, ["metadata", "openai", "reasoningEncryptedContent"]) !== undefined,
799
+ has_encrypted_content: Boolean(data.has_encrypted_content),
787
800
  },
788
801
  });
789
802
  }
@@ -823,10 +836,24 @@ function sqliteTimeWhere(sinceMs, untilMs) {
823
836
  ].filter((condition) => Boolean(condition));
824
837
  return conditions.length > 0 ? conditions.join(" and ") : undefined;
825
838
  }
839
+ function sqliteJsonForIds(db, table, idColumn, ids, columns, pageSize) {
840
+ const rows = [];
841
+ for (let index = 0; index < ids.length; index += pageSize) {
842
+ const pageIds = ids.slice(index, index + pageSize);
843
+ if (pageIds.length === 0)
844
+ continue;
845
+ const quotedIds = pageIds.map(sqliteQuote).join(", ");
846
+ rows.push(...sqliteJson(db, `select ${columns} from ${table} where ${idColumn} in (${quotedIds}) order by rowid;`));
847
+ }
848
+ return rows;
849
+ }
850
+ function sqliteQuote(value) {
851
+ return `'${value.replaceAll("'", "''")}'`;
852
+ }
826
853
  function opencodeTextFromParts(parts) {
827
854
  const text = parts
828
855
  .map((part) => {
829
- const data = asRecord(parseMaybeJson(part.data));
856
+ const data = opencodePartData(part);
830
857
  const type = asString(part.type) ?? asString(data.type);
831
858
  if (type === "text")
832
859
  return extractText(data.text, 8000);
@@ -843,6 +870,27 @@ function opencodeTextFromParts(parts) {
843
870
  .join("\n");
844
871
  return text ? text.slice(0, 8000) : undefined;
845
872
  }
873
+ function opencodePartData(part) {
874
+ const data = asRecord(parseMaybeJson(part.data));
875
+ if (Object.keys(data).length > 0)
876
+ return data;
877
+ return {
878
+ type: part.type,
879
+ text: part.text,
880
+ tool: part.tool,
881
+ callID: part.call_id_upper,
882
+ call_id: part.call_id,
883
+ state: {
884
+ input: parseMaybeJson(part.state_input),
885
+ output: parseMaybeJson(part.state_output),
886
+ status: part.state_status,
887
+ title: part.state_title,
888
+ },
889
+ has_encrypted_content: Boolean(part.has_encrypted_content),
890
+ filename: part.filename,
891
+ url: part.url,
892
+ };
893
+ }
846
894
  function sqliteJson(db, sql) {
847
895
  const output = execFileSync("sqlite3", ["-readonly", "-json", db, sql], {
848
896
  encoding: "utf8",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramarivera/coding-agent-langfuse",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "Universal coding-agent Langfuse backfiller and live OTLP helpers",
5
5
  "type": "module",
6
6
  "license": "MIT",