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