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