@sovr/engine 3.5.0 → 3.7.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.
package/dist/index.d.ts CHANGED
@@ -845,14 +845,14 @@ interface CostRecord {
845
845
  tokenCount?: number;
846
846
  modelName?: string;
847
847
  timestamp: number;
848
- category: CostCategory;
848
+ category: CostCategory$1;
849
849
  metadata?: Record<string, unknown>;
850
850
  }
851
- type CostCategory = 'llm_inference' | 'tool_call' | 'human_review' | 'storage' | 'network' | 'compute' | 'other';
851
+ type CostCategory$1 = 'llm_inference' | 'tool_call' | 'human_review' | 'storage' | 'network' | 'compute' | 'other';
852
852
  interface CostSummary {
853
853
  period: '1h' | '24h' | '7d' | '30d';
854
854
  totalCostUsd: number;
855
- byCategory: Record<CostCategory, number>;
855
+ byCategory: Record<CostCategory$1, number>;
856
856
  byAgent: Record<string, number>;
857
857
  byTool: Record<string, number>;
858
858
  recordCount: number;
@@ -864,7 +864,7 @@ interface CostSummary {
864
864
  interface DailyCostStats {
865
865
  date: string;
866
866
  totalCostUsd: number;
867
- byCategory: Record<CostCategory, number>;
867
+ byCategory: Record<CostCategory$1, number>;
868
868
  actionCount: number;
869
869
  uniqueAgents: number;
870
870
  budgetUtilization: number;
@@ -1870,6 +1870,751 @@ declare class ContextAccelerator {
1870
1870
  private evictLRU;
1871
1871
  }
1872
1872
 
1873
+ /**
1874
+ * trendAlertEngine.ts — 趋势触发告警与 Kill-Switch 对接引擎
1875
+ *
1876
+ * 覆盖 PDF5: 人工智能痛点执行方案(1) — 趋势触发告警与 Kill-Switch 对接
1877
+ *
1878
+ * 核心能力:
1879
+ * - Block Rate 突增检测: 拦截率相对基线大幅上升
1880
+ * - Override Rate 突增检测: 人工强制通过率飙升
1881
+ * - 未知原因码检测: 出现未定义的 reason_code
1882
+ * - 人工审批队列积压检测: 审核队列任务大量堆积
1883
+ * - 自动降级 (Degrade): 进入降级模式
1884
+ * - 自动提高门槛: 提升安全阈值
1885
+ * - 触发 Kill-Switch: 全局紧急停止
1886
+ * - 告警事件持久化: 写入 sovr_system_events
1887
+ * - DegradeEvaluator Cron: 定时评估趋势
1888
+ */
1889
+ type AlertSeverity$1 = 'INFO' | 'WARN' | 'CRITICAL' | 'EMERGENCY';
1890
+ type AlertType = 'BLOCK_RATE_SURGE' | 'OVERRIDE_RATE_SURGE' | 'UNKNOWN_REASON_CODE' | 'APPROVAL_QUEUE_BACKLOG' | 'CONFIDENCE_DROP' | 'LATENCY_SPIKE' | 'ERROR_RATE_SURGE';
1891
+ type ProtectiveAction = 'DEGRADE' | 'TIGHTEN_THRESHOLD' | 'KILL_SWITCH' | 'NOTIFY_ONLY' | 'FORCE_HUMAN_GATE';
1892
+ interface AlertThreshold {
1893
+ alert_type: AlertType;
1894
+ metric_name: string;
1895
+ baseline_window_hours: number;
1896
+ surge_multiplier: number;
1897
+ absolute_threshold: number;
1898
+ severity: AlertSeverity$1;
1899
+ protective_actions: ProtectiveAction[];
1900
+ cooldown_seconds: number;
1901
+ enabled: boolean;
1902
+ }
1903
+ interface TrendMetric {
1904
+ metric_name: string;
1905
+ current_value: number;
1906
+ baseline_value: number;
1907
+ window_start: number;
1908
+ window_end: number;
1909
+ sample_count: number;
1910
+ }
1911
+ interface AlertEvent {
1912
+ alert_id: string;
1913
+ alert_type: AlertType;
1914
+ severity: AlertSeverity$1;
1915
+ metric_name: string;
1916
+ current_value: number;
1917
+ baseline_value: number;
1918
+ threshold_value: number;
1919
+ surge_ratio: number;
1920
+ protective_actions_taken: ProtectiveAction[];
1921
+ message: string;
1922
+ tenant_id: string;
1923
+ created_at: number;
1924
+ acknowledged: boolean;
1925
+ acknowledged_by: string | null;
1926
+ acknowledged_at: number | null;
1927
+ }
1928
+ interface KillSwitchState {
1929
+ enabled: boolean;
1930
+ reason: string | null;
1931
+ enabled_at: number | null;
1932
+ enabled_by: string;
1933
+ auto_triggered: boolean;
1934
+ }
1935
+ interface DegradeState {
1936
+ active: boolean;
1937
+ level: 'LIGHT' | 'MODERATE' | 'SEVERE';
1938
+ reason: string;
1939
+ activated_at: number | null;
1940
+ auto_recover_at: number | null;
1941
+ }
1942
+ interface SystemState {
1943
+ kill_switch: KillSwitchState;
1944
+ degrade: DegradeState;
1945
+ tightened_threshold_multiplier: number;
1946
+ force_human_gate: boolean;
1947
+ }
1948
+ declare class TrendAlertEngine {
1949
+ private thresholds;
1950
+ private alertHistory;
1951
+ private lastAlertTime;
1952
+ private systemState;
1953
+ private metricsBuffer;
1954
+ constructor(customThresholds?: AlertThreshold[]);
1955
+ evaluate(metrics: TrendMetric[], tenantId?: string): AlertEvent[];
1956
+ cronEvaluate(getMetrics: () => TrendMetric[], tenantId?: string): {
1957
+ alerts: AlertEvent[];
1958
+ state: SystemState;
1959
+ };
1960
+ private executeProtectiveAction;
1961
+ private activateDegrade;
1962
+ private tightenThreshold;
1963
+ private activateKillSwitch;
1964
+ private checkThreshold;
1965
+ private checkAutoRecover;
1966
+ acknowledgeAlert(alertId: string, acknowledgedBy: string): boolean;
1967
+ disableKillSwitch(reason: string, actor: string): boolean;
1968
+ resetDegrade(): void;
1969
+ getSystemState(): SystemState;
1970
+ getAlertHistory(limit?: number): AlertEvent[];
1971
+ getActiveAlerts(): AlertEvent[];
1972
+ getMetricsBuffer(): TrendMetric[];
1973
+ private formatAlertMessage;
1974
+ }
1975
+
1976
+ /**
1977
+ * selfConstraintEngine.ts — 自我约束机制引擎
1978
+ *
1979
+ * 覆盖 PDF10: 人工智能痛点自我约束机制实施计划
1980
+ *
1981
+ * 核心能力:
1982
+ * - 风险密度监测: 持续跟踪风险密度指标
1983
+ * - 规则冲突率监测: 检测规则之间的冲突
1984
+ * - 决策置信度监测: 跟踪决策置信度下降趋势
1985
+ * - Auto Tightening Thresholds: 自动收紧阈值
1986
+ * - Capability Downgrade Flags: 功能降级标志
1987
+ * - Forced Human Gate: 强制人工门禁
1988
+ * - tightening_thresholds 配置: 可配置化阈值策略
1989
+ * - capability_flags 配置: 功能开关控制
1990
+ *
1991
+ * 三种退让模式:
1992
+ * 1. 降低能力 — 自动缩小可执行操作范围
1993
+ * 2. 降低速度 — 延后决策等待更多证据
1994
+ * 3. 降低权限 — 交由人工介入
1995
+ */
1996
+ type ConstraintMode = 'CAPABILITY_DOWN' | 'SPEED_DOWN' | 'PERMISSION_DOWN';
1997
+ type ConstraintLevel = 'NORMAL' | 'CAUTIOUS' | 'RESTRICTED' | 'LOCKDOWN';
1998
+ interface TighteningThresholds {
1999
+ risk_density: number;
2000
+ conflict_rate: number;
2001
+ confidence_drop: number;
2002
+ error_rate: number;
2003
+ latency_p99_ms: number;
2004
+ consecutive_failures: number;
2005
+ }
2006
+ interface CapabilityFlags {
2007
+ enable_advanced_features: boolean;
2008
+ enable_auto_approve: boolean;
2009
+ enable_batch_operations: boolean;
2010
+ enable_external_api_calls: boolean;
2011
+ enable_write_operations: boolean;
2012
+ require_human_gate: boolean;
2013
+ require_dual_review: boolean;
2014
+ max_concurrent_decisions: number;
2015
+ decision_delay_ms: number;
2016
+ }
2017
+ interface ConstraintConfig {
2018
+ thresholds: TighteningThresholds;
2019
+ flags: CapabilityFlags;
2020
+ auto_recover_after_minutes: number;
2021
+ evaluation_interval_seconds: number;
2022
+ }
2023
+ interface MonitoringMetrics {
2024
+ risk_density: number;
2025
+ conflict_rate: number;
2026
+ avg_confidence: number;
2027
+ prev_avg_confidence: number;
2028
+ error_rate: number;
2029
+ latency_p99_ms: number;
2030
+ consecutive_failures: number;
2031
+ pending_approval_count: number;
2032
+ system_pressure: number;
2033
+ }
2034
+ interface ConstraintDecision {
2035
+ decision_id: string;
2036
+ timestamp: number;
2037
+ level: ConstraintLevel;
2038
+ modes_activated: ConstraintMode[];
2039
+ triggers: ConstraintTrigger[];
2040
+ flags_applied: Partial<CapabilityFlags>;
2041
+ reason_code: string;
2042
+ auto_recover_at: number | null;
2043
+ }
2044
+ interface ConstraintTrigger {
2045
+ metric_name: string;
2046
+ current_value: number;
2047
+ threshold_value: number;
2048
+ exceeded: boolean;
2049
+ }
2050
+ interface ConstraintState {
2051
+ current_level: ConstraintLevel;
2052
+ active_modes: ConstraintMode[];
2053
+ flags: CapabilityFlags;
2054
+ activated_at: number | null;
2055
+ auto_recover_at: number | null;
2056
+ last_evaluation_at: number;
2057
+ evaluation_count: number;
2058
+ constraint_history: ConstraintDecision[];
2059
+ }
2060
+ declare class SelfConstraintEngine {
2061
+ private config;
2062
+ private state;
2063
+ constructor(config?: Partial<ConstraintConfig>);
2064
+ evaluate(metrics: MonitoringMetrics): ConstraintDecision;
2065
+ private calculateLevel;
2066
+ private applyConstraint;
2067
+ checkAutoRecover(): boolean;
2068
+ reset(): void;
2069
+ forceLevel(level: ConstraintLevel): void;
2070
+ preDecisionCheck(action: string, resource: string): {
2071
+ allowed: boolean;
2072
+ delay_ms: number;
2073
+ requires_human: boolean;
2074
+ requires_dual_review: boolean;
2075
+ reason: string;
2076
+ };
2077
+ getState(): ConstraintState;
2078
+ getCurrentLevel(): ConstraintLevel;
2079
+ getFlags(): CapabilityFlags;
2080
+ isConstrained(): boolean;
2081
+ private isWriteAction;
2082
+ private isExternalAction;
2083
+ private isBatchAction;
2084
+ }
2085
+
2086
+ /**
2087
+ * contributionSettlement.ts — 贡献结算引擎
2088
+ *
2089
+ * 覆盖 PDF3: 人工智能痛点上下文总结(3) — 激励对齐方案
2090
+ *
2091
+ * 核心能力:
2092
+ * - 四维贡献打分: Risk / Cost / Human / Stability
2093
+ * - 归因引擎: 对 rule/model/tool/agent/human/system 各参与者计分
2094
+ * - 窗口聚合: 按时间窗口聚合贡献事件为分数
2095
+ * - 反作弊机制: 硬性门槛 + 惩罚机制 + 审计抽查
2096
+ * - 评分公式: Score_total = w_R*Score_risk + w_C*Score_cost + w_H*Score_human + w_S*Score_stability - Penalties
2097
+ * - 与控制面联动: 贡献分数→权限/资源分配
2098
+ */
2099
+ type ContributionDimension = 'RISK' | 'COST' | 'HUMAN' | 'STABILITY';
2100
+ type EntityType = 'rule' | 'model' | 'tool' | 'agent' | 'human' | 'system';
2101
+ interface ContributionEvent {
2102
+ event_id: string;
2103
+ trace_id: string;
2104
+ decision_id: string;
2105
+ tenant_id: string;
2106
+ entity_type: EntityType;
2107
+ entity_id: string;
2108
+ dimension: ContributionDimension;
2109
+ delta_value: number;
2110
+ delta_confidence: number;
2111
+ baseline_ref: string;
2112
+ evidence_bundle_hash: string;
2113
+ created_at: number;
2114
+ }
2115
+ interface ContributionScore {
2116
+ score_id: string;
2117
+ window_start: number;
2118
+ window_end: number;
2119
+ tenant_id: string;
2120
+ entity_type: EntityType;
2121
+ entity_id: string;
2122
+ score_risk: number;
2123
+ score_cost: number;
2124
+ score_human: number;
2125
+ score_stability: number;
2126
+ score_total: number;
2127
+ penalty_total: number;
2128
+ confidence: number;
2129
+ score_config_version: string;
2130
+ created_at: number;
2131
+ }
2132
+ interface ScoreConfigVersion {
2133
+ version: string;
2134
+ weight_risk: number;
2135
+ weight_cost: number;
2136
+ weight_human: number;
2137
+ weight_stability: number;
2138
+ weight_penalty: number;
2139
+ caps: {
2140
+ max_single_event: number;
2141
+ max_risk_positive_when_risk_up: boolean;
2142
+ };
2143
+ guardrails: string[];
2144
+ approved_by: string;
2145
+ approved_at: number;
2146
+ }
2147
+ interface AttributionRule {
2148
+ condition: string;
2149
+ target_entity_type: EntityType;
2150
+ target_entity_field: string;
2151
+ weight: number;
2152
+ }
2153
+ interface PenaltyCheck {
2154
+ name: string;
2155
+ detect: (events: ContributionEvent[], context: SettlementContext) => number;
2156
+ }
2157
+ interface SettlementContext {
2158
+ tenant_id: string;
2159
+ window_start: number;
2160
+ window_end: number;
2161
+ override_count_delta: number;
2162
+ replay_fail_delta: number;
2163
+ risk_regression: boolean;
2164
+ evidence_downgrade: boolean;
2165
+ }
2166
+ declare class ContributionSettlementEngine {
2167
+ private config;
2168
+ private attributionRules;
2169
+ private penaltyChecks;
2170
+ private eventStore;
2171
+ private scoreStore;
2172
+ constructor(config?: Partial<ScoreConfigVersion>, customRules?: AttributionRule[], customPenalties?: PenaltyCheck[]);
2173
+ recordEvent(event: ContributionEvent): ContributionEvent;
2174
+ attribute(traceId: string, condition: string, entityType: EntityType, entityId: string): ContributionEvent | null;
2175
+ settle(context: SettlementContext): ContributionScore[];
2176
+ getResourceAllocation(entityType: EntityType, entityId: string): {
2177
+ token_budget_multiplier: number;
2178
+ concurrency_quota_multiplier: number;
2179
+ auto_approve_eligible: boolean;
2180
+ requires_dual_review: boolean;
2181
+ };
2182
+ auditSample(entityType: EntityType, entityId: string, sampleSize?: number): ContributionEvent[];
2183
+ private inferDimension;
2184
+ getConfig(): ScoreConfigVersion;
2185
+ getEventCount(): number;
2186
+ getScoreCount(): number;
2187
+ }
2188
+
2189
+ /**
2190
+ * overrideDriftAnalyzer.ts — Override 漂移分析器
2191
+ *
2192
+ * 覆盖 PDF1/2: 对抗防护闭环 — Override Drift 检测
2193
+ *
2194
+ * 核心能力:
2195
+ * - 周期统计: 按时间窗口统计 override 频率/分布
2196
+ * - drift_index 计算: 量化 override 偏离基线的程度
2197
+ * - 告警生成: 当 drift_index 超过阈值时触发告警
2198
+ * - 模式识别: 识别 override 的时间/用户/规则模式
2199
+ * - 与 trendAlertEngine / selfConstraintEngine 联动
2200
+ */
2201
+ interface OverrideEvent {
2202
+ event_id: string;
2203
+ decision_id: string;
2204
+ trace_id: string;
2205
+ tenant_id: string;
2206
+ actor_id: string;
2207
+ actor_type: 'human' | 'agent' | 'system';
2208
+ rule_id: string;
2209
+ original_outcome: 'BLOCK' | 'WARN';
2210
+ override_outcome: 'ALLOW';
2211
+ override_reason: string;
2212
+ risk_level: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
2213
+ created_at: number;
2214
+ }
2215
+ interface DriftWindow {
2216
+ window_start: number;
2217
+ window_end: number;
2218
+ total_decisions: number;
2219
+ total_overrides: number;
2220
+ override_rate: number;
2221
+ by_actor: Map<string, number>;
2222
+ by_rule: Map<string, number>;
2223
+ by_risk_level: Record<string, number>;
2224
+ by_hour: number[];
2225
+ }
2226
+ interface DriftIndex {
2227
+ value: number;
2228
+ rate_drift: number;
2229
+ concentration_drift: number;
2230
+ risk_drift: number;
2231
+ temporal_drift: number;
2232
+ trend: 'STABLE' | 'RISING' | 'FALLING' | 'VOLATILE';
2233
+ }
2234
+ interface DriftAlert {
2235
+ alert_id: string;
2236
+ drift_index: DriftIndex;
2237
+ severity: 'INFO' | 'WARN' | 'CRITICAL';
2238
+ message: string;
2239
+ patterns_detected: DriftPattern[];
2240
+ recommendations: string[];
2241
+ created_at: number;
2242
+ }
2243
+ interface DriftPattern {
2244
+ pattern_type: 'ACTOR_CONCENTRATION' | 'RULE_BYPASS' | 'TIME_ANOMALY' | 'RISK_ESCALATION' | 'RATE_SPIKE';
2245
+ description: string;
2246
+ evidence: Record<string, unknown>;
2247
+ confidence: number;
2248
+ }
2249
+ interface DriftAnalyzerConfig {
2250
+ baseline_window_hours: number;
2251
+ analysis_window_hours: number;
2252
+ rate_drift_threshold: number;
2253
+ concentration_threshold: number;
2254
+ risk_drift_threshold: number;
2255
+ temporal_drift_threshold: number;
2256
+ composite_alert_threshold: number;
2257
+ min_sample_size: number;
2258
+ }
2259
+ declare class OverrideDriftAnalyzer {
2260
+ private config;
2261
+ private events;
2262
+ private baselineWindow;
2263
+ private alerts;
2264
+ constructor(config?: Partial<DriftAnalyzerConfig>);
2265
+ recordOverride(event: OverrideEvent): void;
2266
+ computeWindow(start: number, end: number, totalDecisions?: number): DriftWindow;
2267
+ updateBaseline(totalDecisions?: number): DriftWindow;
2268
+ calculateDriftIndex(currentWindow?: DriftWindow, totalDecisions?: number): DriftIndex;
2269
+ analyze(totalDecisions?: number): DriftAlert | null;
2270
+ private detectPatterns;
2271
+ private generateRecommendations;
2272
+ private calculateConcentration;
2273
+ private calculateTemporalDrift;
2274
+ private determineTrend;
2275
+ getAlerts(limit?: number): DriftAlert[];
2276
+ getEventCount(): number;
2277
+ getLatestDriftIndex(totalDecisions?: number): DriftIndex;
2278
+ getStats(): {
2279
+ total_events: number;
2280
+ total_alerts: number;
2281
+ baseline_override_rate: number;
2282
+ current_override_rate: number;
2283
+ };
2284
+ }
2285
+
2286
+ /**
2287
+ * cockpitDataService.ts — SOVR Cockpit 控制面板数据服务层
2288
+ *
2289
+ * 来源文档: SOVR系统Cockpit趋势面板执行方案.pdf 等 85 份文档
2290
+ * 优先级: P0
2291
+ *
2292
+ * 职责:
2293
+ * 1. 聚合多维度运行指标 (gate/audit/trust/budget)
2294
+ * 2. 提供 Cockpit 面板所需的实时数据 API
2295
+ * 3. 趋势计算 + 健康评分 + 异常标记
2296
+ * 4. 支持时间窗口查询 (1h/6h/24h/7d/30d)
2297
+ */
2298
+ interface CockpitTimeWindow {
2299
+ label: string;
2300
+ seconds: number;
2301
+ }
2302
+ declare const TIME_WINDOWS: Record<string, CockpitTimeWindow>;
2303
+ interface MetricPoint {
2304
+ timestamp: number;
2305
+ value: number;
2306
+ label?: string;
2307
+ }
2308
+ interface CockpitMetric {
2309
+ id: string;
2310
+ name: string;
2311
+ category: 'gate' | 'audit' | 'trust' | 'budget' | 'performance' | 'security';
2312
+ current: number;
2313
+ previous: number;
2314
+ trend: 'up' | 'down' | 'stable';
2315
+ changePercent: number;
2316
+ unit: string;
2317
+ isAnomaly: boolean;
2318
+ history: MetricPoint[];
2319
+ }
2320
+ interface HealthScore {
2321
+ overall: number;
2322
+ gate: number;
2323
+ audit: number;
2324
+ trust: number;
2325
+ budget: number;
2326
+ security: number;
2327
+ lastUpdated: number;
2328
+ }
2329
+
2330
+ /**
2331
+ * timeConsistencyService.ts — SOVR 时间一致性服务
2332
+ *
2333
+ * 来源文档: 时间一致性实施方案.pdf 等 62 份文档
2334
+ * 优先级: P0
2335
+ *
2336
+ * 职责:
2337
+ * 1. 统一时间戳格式 (UTC Unix ms)
2338
+ * 2. 时钟偏移检测 + 校正
2339
+ * 3. 事件排序一致性保证
2340
+ * 4. 跨服务时间同步验证
2341
+ */
2342
+ interface TimestampRecord {
2343
+ utcMs: number;
2344
+ iso8601: string;
2345
+ source: string;
2346
+ clockDriftMs: number;
2347
+ isReliable: boolean;
2348
+ }
2349
+ interface ClockDriftReport {
2350
+ sourceA: string;
2351
+ sourceB: string;
2352
+ driftMs: number;
2353
+ measuredAt: number;
2354
+ withinTolerance: boolean;
2355
+ }
2356
+ interface EventOrderValidation {
2357
+ events: Array<{
2358
+ id: string;
2359
+ timestamp: number;
2360
+ }>;
2361
+ isMonotonic: boolean;
2362
+ violations: Array<{
2363
+ before: string;
2364
+ after: string;
2365
+ gapMs: number;
2366
+ }>;
2367
+ }
2368
+ interface TimeConsistencyConfig {
2369
+ maxClockDriftMs: number;
2370
+ ntpCheckIntervalMs: number;
2371
+ enableDriftCorrection: boolean;
2372
+ referenceSource: string;
2373
+ }
2374
+
2375
+ /**
2376
+ * failureAbsorber.ts — SOVR 失败吸收机制
2377
+ *
2378
+ * 来源文档: 失败吸收机制执行计划.pdf + 失败资本化自动回灌方案.pdf (20 份文档)
2379
+ * 优先级: P0
2380
+ *
2381
+ * 职责:
2382
+ * 1. 失败分类 (transient/permanent/degraded)
2383
+ * 2. 失败资本化 — 将失败转化为知识资产
2384
+ * 3. 自动回灌 — 失败经验注入策略引擎
2385
+ * 4. 失败预算 — 控制可接受失败率
2386
+ */
2387
+ type FailureCategory = 'transient' | 'permanent' | 'degraded' | 'unknown';
2388
+ type FailureSeverity = 'low' | 'medium' | 'high' | 'critical';
2389
+ interface FailureRecord {
2390
+ id: string;
2391
+ timestamp: number;
2392
+ category: FailureCategory;
2393
+ severity: FailureSeverity;
2394
+ source: string;
2395
+ action: string;
2396
+ error: string;
2397
+ context: Record<string, unknown>;
2398
+ retryCount: number;
2399
+ maxRetries: number;
2400
+ resolved: boolean;
2401
+ capitalizedAs?: string;
2402
+ injectedToPolicy: boolean;
2403
+ }
2404
+ interface FailureBudget {
2405
+ windowMs: number;
2406
+ maxFailures: number;
2407
+ currentFailures: number;
2408
+ exhausted: boolean;
2409
+ resetAt: number;
2410
+ }
2411
+ interface CapitalizationResult {
2412
+ failureId: string;
2413
+ knowledgeType: 'pattern' | 'rule' | 'threshold' | 'blocklist';
2414
+ description: string;
2415
+ injectedAt: number;
2416
+ policyRef?: string;
2417
+ }
2418
+
2419
+ /**
2420
+ * realityAnchor.ts — SOVR 现实约束锚定系统
2421
+ *
2422
+ * 来源文档: 现实约束锚定系统执行计划.pdf (19 份文档)
2423
+ * 优先级: P0
2424
+ *
2425
+ * 职责:
2426
+ * 1. 物理世界约束注入 (时间/预算/法规/物理限制)
2427
+ * 2. AI 输出的现实可行性验证
2428
+ * 3. 约束冲突检测 + 解决建议
2429
+ * 4. 约束松弛度评估
2430
+ */
2431
+ type ConstraintType = 'temporal' | 'financial' | 'legal' | 'physical' | 'capacity' | 'dependency';
2432
+ type ConstraintStatus = 'active' | 'violated' | 'relaxed' | 'expired';
2433
+ interface RealityConstraint {
2434
+ id: string;
2435
+ type: ConstraintType;
2436
+ name: string;
2437
+ description: string;
2438
+ condition: string;
2439
+ threshold: number | string;
2440
+ currentValue?: number | string;
2441
+ status: ConstraintStatus;
2442
+ severity: 'hard' | 'soft';
2443
+ createdAt: number;
2444
+ expiresAt?: number;
2445
+ metadata: Record<string, unknown>;
2446
+ }
2447
+ interface FeasibilityCheck {
2448
+ actionId: string;
2449
+ action: string;
2450
+ constraints: ConstraintCheckResult[];
2451
+ overallFeasible: boolean;
2452
+ feasibilityScore: number;
2453
+ suggestions: string[];
2454
+ }
2455
+ interface ConstraintCheckResult {
2456
+ constraintId: string;
2457
+ constraintName: string;
2458
+ type: ConstraintType;
2459
+ passed: boolean;
2460
+ reason: string;
2461
+ relaxable: boolean;
2462
+ relaxationCost?: string;
2463
+ }
2464
+
2465
+ /**
2466
+ * topNRanker.ts — SOVR Top-N 排名引擎
2467
+ *
2468
+ * 来源文档: 人工智能痛点Top-N实现方案.pdf (14 份文档)
2469
+ * 优先级: P0
2470
+ *
2471
+ * 职责:
2472
+ * 1. 多维度评分排名 (风险/频率/影响/成本)
2473
+ * 2. 动态 Top-N 列表维护
2474
+ * 3. 排名变化追踪 + 趋势告警
2475
+ * 4. 可配置权重 + 自定义评分函数
2476
+ */
2477
+ interface RankableItem {
2478
+ id: string;
2479
+ name: string;
2480
+ category: string;
2481
+ dimensions: Record<string, number>;
2482
+ metadata?: Record<string, unknown>;
2483
+ }
2484
+ interface RankResult {
2485
+ rank: number;
2486
+ item: RankableItem;
2487
+ compositeScore: number;
2488
+ dimensionScores: Record<string, number>;
2489
+ previousRank?: number;
2490
+ rankChange: number;
2491
+ }
2492
+ interface RankingConfig {
2493
+ n: number;
2494
+ weights: Record<string, number>;
2495
+ sortOrder: 'desc' | 'asc';
2496
+ minScoreThreshold: number;
2497
+ trackHistory: boolean;
2498
+ }
2499
+ interface RankingSnapshot {
2500
+ timestamp: number;
2501
+ configHash: string;
2502
+ rankings: RankResult[];
2503
+ totalItems: number;
2504
+ }
2505
+
2506
+ /**
2507
+ * finOpsRiskEngine.ts — SOVR FinOps 风险引擎
2508
+ *
2509
+ * 来源文档: FinOps风险执行方案.pdf (3 份文档)
2510
+ * 优先级: P1
2511
+ *
2512
+ * 职责:
2513
+ * 1. AI 运营成本追踪 (LLM tokens, API 调用, 存储)
2514
+ * 2. 预算阈值告警
2515
+ * 3. 成本异常检测
2516
+ * 4. 成本优化建议
2517
+ * 5. FinOps 报告生成
2518
+ */
2519
+ type CostCategory = 'llm_tokens' | 'api_calls' | 'storage' | 'compute' | 'bandwidth' | 'third_party' | 'other';
2520
+ type AlertSeverity = 'info' | 'warning' | 'critical';
2521
+ interface CostEntry {
2522
+ id: string;
2523
+ category: CostCategory;
2524
+ service: string;
2525
+ amount: number;
2526
+ quantity: number;
2527
+ unitPrice: number;
2528
+ timestamp: number;
2529
+ metadata: Record<string, unknown>;
2530
+ }
2531
+ interface BudgetConfig {
2532
+ category: CostCategory;
2533
+ dailyLimit: number;
2534
+ monthlyLimit: number;
2535
+ alertThresholds: number[];
2536
+ }
2537
+ interface CostAlert {
2538
+ id: string;
2539
+ category: CostCategory;
2540
+ severity: AlertSeverity;
2541
+ message: string;
2542
+ currentSpend: number;
2543
+ budgetLimit: number;
2544
+ percentage: number;
2545
+ timestamp: number;
2546
+ }
2547
+
2548
+ /**
2549
+ * apiCacheOptimizer.ts — SOVR API 缓存优化策略引擎
2550
+ *
2551
+ * 来源文档: SOVRAPI缓存优化策略.pdf (2 份文档)
2552
+ * 优先级: P1
2553
+ *
2554
+ * 职责:
2555
+ * 1. 多层缓存管理 (L1 内存 / L2 Redis / L3 CDN)
2556
+ * 2. 缓存策略自动选择 (TTL / LRU / LFU / Write-Through)
2557
+ * 3. 缓存命中率监控与优化
2558
+ * 4. 缓存预热与失效管理
2559
+ * 5. 热点检测与自动扩容
2560
+ */
2561
+ type CacheLayer = 'L1_memory' | 'L2_redis' | 'L3_cdn';
2562
+ type CacheStrategy = 'ttl' | 'lru' | 'lfu' | 'write_through' | 'write_behind' | 'read_through';
2563
+ type EvictionPolicy = 'lru' | 'lfu' | 'fifo' | 'random' | 'ttl';
2564
+ interface CacheConfig {
2565
+ layer: CacheLayer;
2566
+ maxSize: number;
2567
+ maxMemoryMB: number;
2568
+ defaultTTLMs: number;
2569
+ evictionPolicy: EvictionPolicy;
2570
+ warmupEnabled: boolean;
2571
+ compressionEnabled: boolean;
2572
+ }
2573
+
2574
+ /**
2575
+ * releaseManager.ts — SOVR 冻结发布管理器
2576
+ *
2577
+ * 来源文档: 主权AIv1.2冻结发布方案.pdf + SOVRv2.0最终阶段计划.pdf + SOVRv2.0Gamma自动化执行计划.pdf (4 份文档)
2578
+ * 优先级: P1
2579
+ *
2580
+ * 职责:
2581
+ * 1. 版本冻结管理 (Code Freeze / Feature Freeze)
2582
+ * 2. 发布 Checklist 自动化
2583
+ * 3. 回归测试协调
2584
+ * 4. 发布门禁 (Release Gate)
2585
+ * 5. 灰度发布与回滚管理
2586
+ */
2587
+ type FreezeType = 'feature_freeze' | 'code_freeze' | 'full_freeze';
2588
+ type ReleasePhase = 'planning' | 'development' | 'feature_frozen' | 'code_frozen' | 'testing' | 'staging' | 'canary' | 'rolling' | 'released' | 'rolled_back';
2589
+ type ChecklistItemStatus = 'pending' | 'in_progress' | 'passed' | 'failed' | 'skipped' | 'blocked';
2590
+ interface ReleaseVersion {
2591
+ id: string;
2592
+ version: string;
2593
+ codename: string;
2594
+ phase: ReleasePhase;
2595
+ freezeType?: FreezeType;
2596
+ frozenAt?: number;
2597
+ plannedDate: number;
2598
+ actualDate?: number;
2599
+ owner: string;
2600
+ changelog: string[];
2601
+ blockers: string[];
2602
+ rollbackPlan: string;
2603
+ metadata: Record<string, unknown>;
2604
+ }
2605
+ interface ChecklistItem {
2606
+ id: string;
2607
+ releaseId: string;
2608
+ category: 'build' | 'test' | 'security' | 'performance' | 'docs' | 'infra' | 'approval';
2609
+ name: string;
2610
+ description: string;
2611
+ status: ChecklistItemStatus;
2612
+ assignee: string;
2613
+ completedAt?: number;
2614
+ evidence?: string;
2615
+ required: boolean;
2616
+ }
2617
+
1873
2618
  /**
1874
2619
  * @sovr/engine — Unified Policy Engine
1875
2620
  *
@@ -2086,4 +2831,4 @@ declare class PolicyEngine {
2086
2831
  }): void;
2087
2832
  }
2088
2833
 
2089
- export { type ABTestConfig, AdaptiveThresholdManager, type AdaptiveThresholdOptions, type AdjustmentResult, type AggregateSnapshot, type AggregationResult, type AggregationType, type AggregationWindow, type AssembledContext, type AuditEvent, AutoHardenEngine, type BudgetAlert, type BudgetLevel, type BudgetNode, type CacheEntry, type Channel, type CircuitBreakerState, type CircuitState, type ComparableInput, type ComparableResult, type ComparisonNode, type CompiledExpression, type ConsistencyMismatch, type ConsistencyResult, ContextAccelerator, type ContextAcceleratorConfig, type ContextFragment, type ContextPriority, type CostAuditEvent, type CostCategory, type CostEstimate, type CostEstimateRequest, type CostGateEnhancedConfig, CostGateEnhancedEngine, type CostRecord, type CostReport, type CostSummary, type DCFInput, type DCFResult, DEFAULT_CA_CONFIG, DEFAULT_GE_CONFIG, DEFAULT_HARD_RULES, DEFAULT_RULES, DEFAULT_SCORING_WEIGHTS, DEFAULT_TSA_CONFIG, type DataPoint, type DecisionFeedback, type DegradationLevel, type DriftConfig, type DriftResult, type EligibilityResult, type EngineConfig, type EngineTier, type EngineTierLimits, type EstimateAccuracy, type EvalContext, type EvalRequest, type EvalResult, EvolutionChannelEngine, type EvolutionConfig, type EvolutionEvent, type ExecContext, type ExprTreePolicyRule, type ExpressionNode, type FeatureSwitchDef, type FeatureSwitchState, FeatureSwitchesManager, type FeatureSwitchesOptions, type FunctionNode, type PolicyVersion as GovPolicyVersion, type GovernanceDecision, GovernanceEnhancer, type GovernanceEnhancerConfig, type GovernanceRule, type HardRule, type HardenConfig, type HardenEvent, type HardenLevel, type HardenMeasure, type HardenMeasureType, type HardenState, type HttpContext, type LiteralNode, type LogicalNode, type MarketSize, type McpContext, type ModelCandidate, type ModelPricing, type ModelTier, type MultiLevelBudgetConfig, MultiLevelBudgetEngine, type NetworkEffectInput, type NetworkEffectResult, type NotNode, PolicyEngine, type PolicyRule, type PolicySnapshot, type PolicyVersion$1 as PolicyVersion, type PrefetchRule, type PricingEvalRequest, type PricingEvalResult, type PricingRule, PricingRulesEngine, type ReasonCode, type RecalcEngineConfig, type RecalcGranularity, type RecalcHandler, type RecalcTask, type RecalcTaskStatus, type RecalcTriggerType, RecalculationEngine, type RiskLevel, type RoutingDecision, type RoutingRequest, type RuleCondition, type RuleEvalResult, SOVR_FEATURE_SWITCHES, type ScoringResult, type ScoringWeights, SemanticDriftDetectorEngine, type SemanticFingerprint, type SensitivityResult, type SqlContext, type ThresholdConfig, TimeSeriesAggregator, type TimeSeriesAggregatorConfig, type ToolPricing, TwoPhaseRouter, type TwoPhaseRouterConfig, type UnitEconomics, ValuationModel, type ValuationModelConfig, type VariableNode, type Verdict, type WindowType, compileFromJSON, compileRuleSet, createAutoHardenEngine, createCostGateEnhanced, createEvolutionChannel, createMultiLevelBudget, createRecalculationEngine, createSemanticDriftDetector, PolicyEngine as default, estimateCost, evaluateRules, getAccuracyStats, getModelPricingTable, getToolPricingTable, recordActualCost, registerFunction, updateModelPricing, updateToolPricing };
2834
+ export { type ABTestConfig, AdaptiveThresholdManager, type AdaptiveThresholdOptions, type AdjustmentResult, type AggregateSnapshot, type AggregationResult, type AggregationType, type AggregationWindow, type AlertEvent, type AlertSeverity$1 as AlertSeverity, type AlertThreshold, type AlertType, type AssembledContext, type AttributionRule, type AuditEvent, AutoHardenEngine, type BudgetAlert, type BudgetConfig, type BudgetLevel, type BudgetNode, type CacheConfig, type CacheEntry, type CacheLayer, type CacheStrategy, type CapabilityFlags, type CapitalizationResult, type Channel, type ChecklistItem, type ChecklistItemStatus, type CircuitBreakerState, type CircuitState, type ClockDriftReport, type CockpitMetric, type CockpitTimeWindow, type ComparableInput, type ComparableResult, type ComparisonNode, type CompiledExpression, type ConsistencyMismatch, type ConsistencyResult, type ConstraintCheckResult, type ConstraintConfig, type ConstraintDecision, type ConstraintLevel, type ConstraintMode, type ConstraintState, type ConstraintTrigger, ContextAccelerator, type ContextAcceleratorConfig, type ContextFragment, type ContextPriority, type ContributionDimension, type ContributionEvent, type ContributionScore, ContributionSettlementEngine, type CostAlert, type CostAuditEvent, type CostCategory$1 as CostCategory, type CostEntry, type CostEstimate, type CostEstimateRequest, type CostGateEnhancedConfig, CostGateEnhancedEngine, type CostRecord, type CostReport, type CostSummary, type DCFInput, type DCFResult, DEFAULT_CA_CONFIG, DEFAULT_GE_CONFIG, DEFAULT_HARD_RULES, DEFAULT_RULES, DEFAULT_SCORING_WEIGHTS, DEFAULT_TSA_CONFIG, type DataPoint, type DecisionFeedback, type DegradationLevel, type DegradeState, type DriftAlert, type DriftAnalyzerConfig, type DriftConfig, type DriftIndex, type DriftPattern, type DriftResult, type DriftWindow, type EligibilityResult, type EngineConfig, type EngineTier, type EngineTierLimits, type EntityType, type EstimateAccuracy, type EvalContext, type EvalRequest, type EvalResult, type EventOrderValidation, type EvictionPolicy, EvolutionChannelEngine, type EvolutionConfig, type EvolutionEvent, type ExecContext, type ExprTreePolicyRule, type ExpressionNode, type FailureBudget, type FailureCategory, type FailureRecord, type FailureSeverity, type FeasibilityCheck, type FeatureSwitchDef, type FeatureSwitchState, FeatureSwitchesManager, type FeatureSwitchesOptions, type CostCategory as FinOpsCostCategory, type FreezeType, type FunctionNode, type PolicyVersion as GovPolicyVersion, type GovernanceDecision, GovernanceEnhancer, type GovernanceEnhancerConfig, type GovernanceRule, type HardRule, type HardenConfig, type HardenEvent, type HardenLevel, type HardenMeasure, type HardenMeasureType, type HardenState, type HealthScore, type HttpContext, type KillSwitchState, type LiteralNode, type LogicalNode, type MarketSize, type McpContext, type MetricPoint, type ModelCandidate, type ModelPricing, type ModelTier, type MonitoringMetrics, type MultiLevelBudgetConfig, MultiLevelBudgetEngine, type NetworkEffectInput, type NetworkEffectResult, type NotNode, OverrideDriftAnalyzer, type OverrideEvent, type PenaltyCheck, PolicyEngine, type PolicyRule, type PolicySnapshot, type PolicyVersion$1 as PolicyVersion, type PrefetchRule, type PricingEvalRequest, type PricingEvalResult, type PricingRule, PricingRulesEngine, type ProtectiveAction, type RankResult, type RankableItem, type RankingConfig, type RankingSnapshot, type RealityConstraint, type ReasonCode, type RecalcEngineConfig, type RecalcGranularity, type RecalcHandler, type RecalcTask, type RecalcTaskStatus, type RecalcTriggerType, RecalculationEngine, type ReleasePhase, type ReleaseVersion, type RiskLevel, type RoutingDecision, type RoutingRequest, type RuleCondition, type RuleEvalResult, SOVR_FEATURE_SWITCHES, type ScoreConfigVersion, type ScoringResult, type ScoringWeights, SelfConstraintEngine, SemanticDriftDetectorEngine, type SemanticFingerprint, type SensitivityResult, type SettlementContext, type SqlContext, type SystemState, TIME_WINDOWS, type ThresholdConfig, type TighteningThresholds, type TimeConsistencyConfig, TimeSeriesAggregator, type TimeSeriesAggregatorConfig, type TimestampRecord, type ToolPricing, TrendAlertEngine, type TrendMetric, TwoPhaseRouter, type TwoPhaseRouterConfig, type UnitEconomics, ValuationModel, type ValuationModelConfig, type VariableNode, type Verdict, type WindowType, compileFromJSON, compileRuleSet, createAutoHardenEngine, createCostGateEnhanced, createEvolutionChannel, createMultiLevelBudget, createRecalculationEngine, createSemanticDriftDetector, PolicyEngine as default, estimateCost, evaluateRules, getAccuracyStats, getModelPricingTable, getToolPricingTable, recordActualCost, registerFunction, updateModelPricing, updateToolPricing };