claude-memory-layer 1.0.34 → 1.0.36

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.
@@ -3573,6 +3573,16 @@ var SQLiteEventStore = class {
3573
3573
  getDatabase() {
3574
3574
  return this.db;
3575
3575
  }
3576
+ hasTableColumn(tableName, columnName) {
3577
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName))
3578
+ return false;
3579
+ try {
3580
+ const rows = sqliteAll(this.db, `PRAGMA table_info("${tableName}")`, []);
3581
+ return rows.some((row) => row.name === columnName);
3582
+ } catch {
3583
+ return false;
3584
+ }
3585
+ }
3576
3586
  async recordRetrievalTrace(input) {
3577
3587
  await this.initialize();
3578
3588
  const traceId = randomUUID5();
@@ -3638,17 +3648,18 @@ var SQLiteEventStore = class {
3638
3648
  async getRetrievalTraceStats() {
3639
3649
  await this.initialize();
3640
3650
  try {
3651
+ const rewrittenQueryRewriteKindSql = this.hasTableColumn("retrieval_traces", "query_rewrite_kind") ? REWRITTEN_QUERY_REWRITE_KIND_SQL : "0";
3641
3652
  const row = sqliteGet(
3642
3653
  this.db,
3643
3654
  `SELECT
3644
3655
  COUNT(*) as total_queries,
3645
3656
  AVG(candidate_count) as avg_candidate_count,
3646
3657
  AVG(selected_count) as avg_selected_count,
3647
- SUM(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} THEN 1 ELSE 0 END) as rewritten_queries,
3648
- SUM(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} AND selected_count > 0 THEN 1 ELSE 0 END) as rewritten_queries_with_selection,
3649
- SUM(CASE WHEN NOT (${REWRITTEN_QUERY_REWRITE_KIND_SQL}) AND selected_count > 0 THEN 1 ELSE 0 END) as raw_queries_with_selection,
3650
- AVG(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} THEN selected_count END) as avg_selected_count_for_rewritten_queries,
3651
- AVG(CASE WHEN NOT (${REWRITTEN_QUERY_REWRITE_KIND_SQL}) THEN selected_count END) as avg_selected_count_for_raw_queries,
3658
+ SUM(CASE WHEN ${rewrittenQueryRewriteKindSql} THEN 1 ELSE 0 END) as rewritten_queries,
3659
+ SUM(CASE WHEN ${rewrittenQueryRewriteKindSql} AND selected_count > 0 THEN 1 ELSE 0 END) as rewritten_queries_with_selection,
3660
+ SUM(CASE WHEN NOT (${rewrittenQueryRewriteKindSql}) AND selected_count > 0 THEN 1 ELSE 0 END) as raw_queries_with_selection,
3661
+ AVG(CASE WHEN ${rewrittenQueryRewriteKindSql} THEN selected_count END) as avg_selected_count_for_rewritten_queries,
3662
+ AVG(CASE WHEN NOT (${rewrittenQueryRewriteKindSql}) THEN selected_count END) as avg_selected_count_for_raw_queries,
3652
3663
  CASE
3653
3664
  WHEN SUM(candidate_count) > 0 THEN (SUM(selected_count) * 1.0 / SUM(candidate_count))
3654
3665
  ELSE 0