sovr-mcp-proxy 7.0.0 → 7.2.0

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.
@@ -0,0 +1,208 @@
1
+ /**
2
+ * SOVR Audit Dashboard — Structured Audit Logs, Statistics, and Export
3
+ *
4
+ * P2-1: Provides the "Trust Vault" backend for audit evidence.
5
+ *
6
+ * Features:
7
+ * - Structured audit event storage (in-memory + file persistence)
8
+ * - Real-time statistics aggregation (call volume, success rate, latency)
9
+ * - Time-series trend analysis (hourly/daily/weekly)
10
+ * - CSV and JSON export for offline analysis
11
+ * - Risk distribution tracking
12
+ * - Top-N analysis (most blocked tools, most active policies)
13
+ * - Session-based grouping
14
+ * - Quota usage tracking with prediction
15
+ */
16
+ interface AuditEntry {
17
+ /** Unique entry ID */
18
+ id: string;
19
+ /** ISO timestamp */
20
+ timestamp: string;
21
+ /** Unix timestamp (ms) for sorting */
22
+ epochMs: number;
23
+ /** Event type */
24
+ type: AuditEventType;
25
+ /** Tool name */
26
+ toolName: string;
27
+ /** Sanitized arguments (secrets redacted) */
28
+ arguments: Record<string, unknown>;
29
+ /** Decision made */
30
+ decision: 'allow' | 'block' | 'transform' | 'require-approval' | 'rate-limited' | 'error';
31
+ /** Risk score (0-100) */
32
+ riskScore: number;
33
+ /** Risk level */
34
+ riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
35
+ /** Policy that triggered the decision */
36
+ policyId?: string;
37
+ /** Reason for decision */
38
+ reason: string;
39
+ /** Duration of processing (ms) */
40
+ durationMs: number;
41
+ /** Session ID (groups related calls) */
42
+ sessionId?: string;
43
+ /** User/agent identifier */
44
+ agentId?: string;
45
+ /** Error message if any */
46
+ error?: string;
47
+ /** Upstream result summary */
48
+ resultSummary?: string;
49
+ }
50
+ type AuditEventType = 'tool_call' | 'policy_match' | 'approval_request' | 'approval_granted' | 'approval_denied' | 'rate_limit' | 'error' | 'config_change' | 'session_start' | 'session_end';
51
+ interface DashboardStats {
52
+ /** Time range of data */
53
+ timeRange: {
54
+ from: string;
55
+ to: string;
56
+ };
57
+ /** Total events */
58
+ totalEvents: number;
59
+ /** Events by decision */
60
+ byDecision: Record<string, number>;
61
+ /** Events by risk level */
62
+ byRiskLevel: Record<string, number>;
63
+ /** Events by tool */
64
+ byTool: Record<string, number>;
65
+ /** Events by type */
66
+ byType: Record<string, number>;
67
+ /** Success rate (allowed / total) */
68
+ successRate: number;
69
+ /** Average latency (ms) */
70
+ avgLatencyMs: number;
71
+ /** P95 latency (ms) */
72
+ p95LatencyMs: number;
73
+ /** P99 latency (ms) */
74
+ p99LatencyMs: number;
75
+ /** Events per minute (current rate) */
76
+ eventsPerMinute: number;
77
+ /** Top blocked tools */
78
+ topBlocked: Array<{
79
+ tool: string;
80
+ count: number;
81
+ }>;
82
+ /** Top triggered policies */
83
+ topPolicies: Array<{
84
+ policyId: string;
85
+ count: number;
86
+ }>;
87
+ /** Risk score distribution (histogram) */
88
+ riskHistogram: Array<{
89
+ range: string;
90
+ count: number;
91
+ }>;
92
+ }
93
+ interface TrendPoint {
94
+ /** Time bucket label */
95
+ label: string;
96
+ /** Unix timestamp of bucket start */
97
+ epochMs: number;
98
+ /** Total events in bucket */
99
+ total: number;
100
+ /** Allowed events */
101
+ allowed: number;
102
+ /** Blocked events */
103
+ blocked: number;
104
+ /** Average risk score */
105
+ avgRisk: number;
106
+ /** Average latency */
107
+ avgLatency: number;
108
+ }
109
+ interface QuotaStatus {
110
+ /** Current period usage */
111
+ used: number;
112
+ /** Period limit */
113
+ limit: number;
114
+ /** Usage percentage */
115
+ percentage: number;
116
+ /** Predicted exhaustion date (ISO) */
117
+ predictedExhaustion?: string;
118
+ /** Daily average usage */
119
+ dailyAverage: number;
120
+ /** Days remaining at current rate */
121
+ daysRemaining?: number;
122
+ }
123
+ interface AuditDashboardConfig {
124
+ /** Maximum entries to keep in memory */
125
+ maxEntries: number;
126
+ /** File path for persistent storage (optional) */
127
+ persistPath?: string;
128
+ /** Auto-save interval (ms) */
129
+ autoSaveInterval: number;
130
+ /** Quota limit per period */
131
+ quotaLimit: number;
132
+ /** Quota period (ms) */
133
+ quotaPeriod: number;
134
+ /** Redact patterns for sensitive data */
135
+ redactPatterns: RegExp[];
136
+ }
137
+ declare class AuditDashboard {
138
+ private entries;
139
+ private config;
140
+ private saveTimer;
141
+ private quotaCounter;
142
+ private quotaPeriodStart;
143
+ constructor(config?: Partial<AuditDashboardConfig>);
144
+ /** Record a new audit entry */
145
+ record(entry: Omit<AuditEntry, 'id' | 'timestamp' | 'epochMs'>): AuditEntry;
146
+ /** Get entries with optional filters */
147
+ query(filters?: {
148
+ from?: number;
149
+ to?: number;
150
+ toolName?: string;
151
+ decision?: string;
152
+ riskLevel?: string;
153
+ sessionId?: string;
154
+ agentId?: string;
155
+ limit?: number;
156
+ offset?: number;
157
+ }): {
158
+ entries: AuditEntry[];
159
+ total: number;
160
+ };
161
+ /** Get a single entry by ID */
162
+ getById(id: string): AuditEntry | undefined;
163
+ /** Get dashboard statistics for a time range */
164
+ getStats(from?: number, to?: number): DashboardStats;
165
+ /** Get time-series trend data */
166
+ getTrends(granularity?: 'hourly' | 'daily' | 'weekly', from?: number, to?: number): TrendPoint[];
167
+ /** Get current quota status with prediction */
168
+ getQuotaStatus(): QuotaStatus;
169
+ /** Export audit log as CSV */
170
+ exportCSV(filters?: {
171
+ from?: number;
172
+ to?: number;
173
+ }): string;
174
+ /** Export audit log as JSON */
175
+ exportJSON(filters?: {
176
+ from?: number;
177
+ to?: number;
178
+ }): string;
179
+ /** Export Trust Bundle (evidence package) */
180
+ exportTrustBundle(sessionId?: string): {
181
+ bundleId: string;
182
+ exportedAt: string;
183
+ entries: AuditEntry[];
184
+ stats: DashboardStats;
185
+ integrity: string;
186
+ };
187
+ /** Start a new audit session */
188
+ startSession(agentId?: string): string;
189
+ /** End an audit session */
190
+ endSession(sessionId: string): void;
191
+ /** Get total entry count */
192
+ get size(): number;
193
+ /** Clear all entries */
194
+ clear(): void;
195
+ /** Destroy and cleanup */
196
+ destroy(): void;
197
+ private redactSensitive;
198
+ private formatBucketLabel;
199
+ private persist;
200
+ }
201
+ /** Create a dashboard with sensible defaults */
202
+ declare function createAuditDashboard(overrides?: Partial<AuditDashboardConfig>): AuditDashboard;
203
+ /** Create a dashboard for free tier (limited retention) */
204
+ declare function createFreeTierDashboard(): AuditDashboard;
205
+ /** Create a dashboard for pro tier */
206
+ declare function createProDashboard(): AuditDashboard;
207
+
208
+ export { AuditDashboard, type AuditDashboardConfig, type AuditEntry, type AuditEventType, type DashboardStats, type QuotaStatus, type TrendPoint, createAuditDashboard, createFreeTierDashboard, createProDashboard };
@@ -0,0 +1,208 @@
1
+ /**
2
+ * SOVR Audit Dashboard — Structured Audit Logs, Statistics, and Export
3
+ *
4
+ * P2-1: Provides the "Trust Vault" backend for audit evidence.
5
+ *
6
+ * Features:
7
+ * - Structured audit event storage (in-memory + file persistence)
8
+ * - Real-time statistics aggregation (call volume, success rate, latency)
9
+ * - Time-series trend analysis (hourly/daily/weekly)
10
+ * - CSV and JSON export for offline analysis
11
+ * - Risk distribution tracking
12
+ * - Top-N analysis (most blocked tools, most active policies)
13
+ * - Session-based grouping
14
+ * - Quota usage tracking with prediction
15
+ */
16
+ interface AuditEntry {
17
+ /** Unique entry ID */
18
+ id: string;
19
+ /** ISO timestamp */
20
+ timestamp: string;
21
+ /** Unix timestamp (ms) for sorting */
22
+ epochMs: number;
23
+ /** Event type */
24
+ type: AuditEventType;
25
+ /** Tool name */
26
+ toolName: string;
27
+ /** Sanitized arguments (secrets redacted) */
28
+ arguments: Record<string, unknown>;
29
+ /** Decision made */
30
+ decision: 'allow' | 'block' | 'transform' | 'require-approval' | 'rate-limited' | 'error';
31
+ /** Risk score (0-100) */
32
+ riskScore: number;
33
+ /** Risk level */
34
+ riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
35
+ /** Policy that triggered the decision */
36
+ policyId?: string;
37
+ /** Reason for decision */
38
+ reason: string;
39
+ /** Duration of processing (ms) */
40
+ durationMs: number;
41
+ /** Session ID (groups related calls) */
42
+ sessionId?: string;
43
+ /** User/agent identifier */
44
+ agentId?: string;
45
+ /** Error message if any */
46
+ error?: string;
47
+ /** Upstream result summary */
48
+ resultSummary?: string;
49
+ }
50
+ type AuditEventType = 'tool_call' | 'policy_match' | 'approval_request' | 'approval_granted' | 'approval_denied' | 'rate_limit' | 'error' | 'config_change' | 'session_start' | 'session_end';
51
+ interface DashboardStats {
52
+ /** Time range of data */
53
+ timeRange: {
54
+ from: string;
55
+ to: string;
56
+ };
57
+ /** Total events */
58
+ totalEvents: number;
59
+ /** Events by decision */
60
+ byDecision: Record<string, number>;
61
+ /** Events by risk level */
62
+ byRiskLevel: Record<string, number>;
63
+ /** Events by tool */
64
+ byTool: Record<string, number>;
65
+ /** Events by type */
66
+ byType: Record<string, number>;
67
+ /** Success rate (allowed / total) */
68
+ successRate: number;
69
+ /** Average latency (ms) */
70
+ avgLatencyMs: number;
71
+ /** P95 latency (ms) */
72
+ p95LatencyMs: number;
73
+ /** P99 latency (ms) */
74
+ p99LatencyMs: number;
75
+ /** Events per minute (current rate) */
76
+ eventsPerMinute: number;
77
+ /** Top blocked tools */
78
+ topBlocked: Array<{
79
+ tool: string;
80
+ count: number;
81
+ }>;
82
+ /** Top triggered policies */
83
+ topPolicies: Array<{
84
+ policyId: string;
85
+ count: number;
86
+ }>;
87
+ /** Risk score distribution (histogram) */
88
+ riskHistogram: Array<{
89
+ range: string;
90
+ count: number;
91
+ }>;
92
+ }
93
+ interface TrendPoint {
94
+ /** Time bucket label */
95
+ label: string;
96
+ /** Unix timestamp of bucket start */
97
+ epochMs: number;
98
+ /** Total events in bucket */
99
+ total: number;
100
+ /** Allowed events */
101
+ allowed: number;
102
+ /** Blocked events */
103
+ blocked: number;
104
+ /** Average risk score */
105
+ avgRisk: number;
106
+ /** Average latency */
107
+ avgLatency: number;
108
+ }
109
+ interface QuotaStatus {
110
+ /** Current period usage */
111
+ used: number;
112
+ /** Period limit */
113
+ limit: number;
114
+ /** Usage percentage */
115
+ percentage: number;
116
+ /** Predicted exhaustion date (ISO) */
117
+ predictedExhaustion?: string;
118
+ /** Daily average usage */
119
+ dailyAverage: number;
120
+ /** Days remaining at current rate */
121
+ daysRemaining?: number;
122
+ }
123
+ interface AuditDashboardConfig {
124
+ /** Maximum entries to keep in memory */
125
+ maxEntries: number;
126
+ /** File path for persistent storage (optional) */
127
+ persistPath?: string;
128
+ /** Auto-save interval (ms) */
129
+ autoSaveInterval: number;
130
+ /** Quota limit per period */
131
+ quotaLimit: number;
132
+ /** Quota period (ms) */
133
+ quotaPeriod: number;
134
+ /** Redact patterns for sensitive data */
135
+ redactPatterns: RegExp[];
136
+ }
137
+ declare class AuditDashboard {
138
+ private entries;
139
+ private config;
140
+ private saveTimer;
141
+ private quotaCounter;
142
+ private quotaPeriodStart;
143
+ constructor(config?: Partial<AuditDashboardConfig>);
144
+ /** Record a new audit entry */
145
+ record(entry: Omit<AuditEntry, 'id' | 'timestamp' | 'epochMs'>): AuditEntry;
146
+ /** Get entries with optional filters */
147
+ query(filters?: {
148
+ from?: number;
149
+ to?: number;
150
+ toolName?: string;
151
+ decision?: string;
152
+ riskLevel?: string;
153
+ sessionId?: string;
154
+ agentId?: string;
155
+ limit?: number;
156
+ offset?: number;
157
+ }): {
158
+ entries: AuditEntry[];
159
+ total: number;
160
+ };
161
+ /** Get a single entry by ID */
162
+ getById(id: string): AuditEntry | undefined;
163
+ /** Get dashboard statistics for a time range */
164
+ getStats(from?: number, to?: number): DashboardStats;
165
+ /** Get time-series trend data */
166
+ getTrends(granularity?: 'hourly' | 'daily' | 'weekly', from?: number, to?: number): TrendPoint[];
167
+ /** Get current quota status with prediction */
168
+ getQuotaStatus(): QuotaStatus;
169
+ /** Export audit log as CSV */
170
+ exportCSV(filters?: {
171
+ from?: number;
172
+ to?: number;
173
+ }): string;
174
+ /** Export audit log as JSON */
175
+ exportJSON(filters?: {
176
+ from?: number;
177
+ to?: number;
178
+ }): string;
179
+ /** Export Trust Bundle (evidence package) */
180
+ exportTrustBundle(sessionId?: string): {
181
+ bundleId: string;
182
+ exportedAt: string;
183
+ entries: AuditEntry[];
184
+ stats: DashboardStats;
185
+ integrity: string;
186
+ };
187
+ /** Start a new audit session */
188
+ startSession(agentId?: string): string;
189
+ /** End an audit session */
190
+ endSession(sessionId: string): void;
191
+ /** Get total entry count */
192
+ get size(): number;
193
+ /** Clear all entries */
194
+ clear(): void;
195
+ /** Destroy and cleanup */
196
+ destroy(): void;
197
+ private redactSensitive;
198
+ private formatBucketLabel;
199
+ private persist;
200
+ }
201
+ /** Create a dashboard with sensible defaults */
202
+ declare function createAuditDashboard(overrides?: Partial<AuditDashboardConfig>): AuditDashboard;
203
+ /** Create a dashboard for free tier (limited retention) */
204
+ declare function createFreeTierDashboard(): AuditDashboard;
205
+ /** Create a dashboard for pro tier */
206
+ declare function createProDashboard(): AuditDashboard;
207
+
208
+ export { AuditDashboard, type AuditDashboardConfig, type AuditEntry, type AuditEventType, type DashboardStats, type QuotaStatus, type TrendPoint, createAuditDashboard, createFreeTierDashboard, createProDashboard };