File size: 3,217 Bytes
6111b2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**

 * Database performance optimization settings stored in SQLite key-value pairs.

 * User-configurable aggregation, retention, and optimization settings.

 */

export interface DatabaseSettings {
  /** 1. Location (read-only display) */
  location: {
    databasePath: string;
    dataDir: string;
    walSizeBytes: number;
    schemaVersion: number;
  };

  /** 2. Logs (what gets captured) */
  logs: {
    detailedLogsEnabled: boolean;
    callLogPipelineEnabled: boolean;
    maxDetailSizeKb: number;
    ringBufferSize: number;
  };

  /** 3. Backup (backup/restore/import/export) */
  backup: {
    autoBackupEnabled: boolean;
    autoBackupFrequency: "never" | "daily" | "weekly" | "monthly";
    keepLastNBackups: number;
  };

  /** 4. Cache (moved from CacheSettingsTab) */
  cache: {
    semanticCacheEnabled: boolean;
    semanticCacheMaxSize: number;
    semanticCacheTTL: number;
    promptCacheEnabled: boolean;
    promptCacheStrategy: "auto" | "system-only" | "manual";
    alwaysPreserveClientCache: "auto" | "always" | "never";
  };

  /** 5. Retention (per-table cleanup policies) */
  retention: {
    quotaSnapshots: number;
    compressionAnalytics: number;
    mcpAudit: number;
    a2aEvents: number;
    callLogs: number;
    usageHistory: number;
    memoryEntries: number;
    autoCleanupEnabled: boolean;
  };

  /** 6. Compression (aggregation) */
  aggregation: {
    enabled: boolean;
    rawDataRetentionDays: number;
    granularity: "hourly" | "daily" | "weekly";
  };

  /** 7. Optimization (auto_vacuum, VACUUM, page/cache) */
  optimization: {
    autoVacuumMode: "NONE" | "FULL" | "INCREMENTAL";
    scheduledVacuum: "never" | "daily" | "weekly" | "monthly";
    vacuumHour: number;
    pageSize: number;
    cacheSize: number;
    optimizeOnStartup: boolean;
  };

  /** Read-only stats */
  stats: {
    databaseSizeBytes: number;
    pageCount: number;
    freelistCount: number;
    lastVacuumAt: string | null;
    lastOptimizationAt: string | null;
    integrityCheck: "ok" | "error" | null;
  };
}

/** Default database settings */
export const DEFAULT_DATABASE_SETTINGS: Omit<DatabaseSettings, "location" | "stats"> = {
  logs: {
    detailedLogsEnabled: false,
    callLogPipelineEnabled: false,
    maxDetailSizeKb: 10,
    ringBufferSize: 500,
  },
  backup: {
    autoBackupEnabled: false,
    autoBackupFrequency: "never",
    keepLastNBackups: 5,
  },
  cache: {
    semanticCacheEnabled: true,
    semanticCacheMaxSize: 100,
    semanticCacheTTL: 1800000,
    promptCacheEnabled: true,
    promptCacheStrategy: "auto",
    alwaysPreserveClientCache: "auto",
  },
  retention: {
    quotaSnapshots: 7,
    compressionAnalytics: 30,
    mcpAudit: 30,
    a2aEvents: 30,
    callLogs: 30,
    usageHistory: 30,
    memoryEntries: 30,
    autoCleanupEnabled: true,
  },
  aggregation: {
    enabled: true,
    rawDataRetentionDays: 30,
    granularity: "daily",
  },
  optimization: {
    autoVacuumMode: "FULL",
    scheduledVacuum: "weekly",
    vacuumHour: 2,
    pageSize: 4096,
    cacheSize: -2000,
    optimizeOnStartup: true,
  },
};