@sovr/engine 3.4.0 → 3.5.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
@@ -1094,7 +1094,7 @@ declare function createMultiLevelBudget(config?: Partial<MultiLevelBudgetConfig>
1094
1094
  *
1095
1095
  * 设计原则:纯逻辑模块,无数据库依赖
1096
1096
  */
1097
- interface PolicyVersion {
1097
+ interface PolicyVersion$1 {
1098
1098
  id: string;
1099
1099
  version: string;
1100
1100
  name: string;
@@ -1154,7 +1154,7 @@ declare class EvolutionChannelEngine {
1154
1154
  /**
1155
1155
  * 发布新策略版本
1156
1156
  */
1157
- publish(version: PolicyVersion): PolicyVersion;
1157
+ publish(version: PolicyVersion$1): PolicyVersion$1;
1158
1158
  /**
1159
1159
  * 启动灰度发布
1160
1160
  */
@@ -1170,7 +1170,7 @@ declare class EvolutionChannelEngine {
1170
1170
  /**
1171
1171
  * 路由决策:根据灰度百分比选择策略版本
1172
1172
  */
1173
- resolveVersion(requestHash?: number): PolicyVersion | null;
1173
+ resolveVersion(requestHash?: number): PolicyVersion$1 | null;
1174
1174
  /**
1175
1175
  * 启动 A/B 测试
1176
1176
  */
@@ -1179,7 +1179,7 @@ declare class EvolutionChannelEngine {
1179
1179
  * A/B 测试路由
1180
1180
  */
1181
1181
  resolveABTest(testId: string, requestHash?: number): {
1182
- version: PolicyVersion;
1182
+ version: PolicyVersion$1;
1183
1183
  group: 'control' | 'treatment';
1184
1184
  } | null;
1185
1185
  /**
@@ -1189,16 +1189,687 @@ declare class EvolutionChannelEngine {
1189
1189
  /**
1190
1190
  * 获取所有版本
1191
1191
  */
1192
- listVersions(): PolicyVersion[];
1192
+ listVersions(): PolicyVersion$1[];
1193
1193
  /**
1194
1194
  * 获取当前 active 版本
1195
1195
  */
1196
- getActiveVersion(): PolicyVersion | null;
1196
+ getActiveVersion(): PolicyVersion$1 | null;
1197
1197
  private cleanupOldVersions;
1198
1198
  private audit;
1199
1199
  }
1200
1200
  declare function createEvolutionChannel(config?: Partial<EvolutionConfig>): EvolutionChannelEngine;
1201
1201
 
1202
+ /**
1203
+ * SOVR Two-Phase Router Engine
1204
+ * 补齐 N4 两阶段路由 + N5 可解释路由(原因代码) + N6 MVP分层路由(3层)
1205
+ *
1206
+ * 纯内存引擎,无外部依赖
1207
+ *
1208
+ * 架构:
1209
+ * Phase 1: Eligibility (资格筛选) — 硬性规则过滤
1210
+ * Phase 2: Scoring (评分排序) — 软性指标加权
1211
+ *
1212
+ * MVP 3层分层:
1213
+ * - cheap: 低成本模型 (GPT-3.5, Claude Haiku)
1214
+ * - balanced: 平衡模型 (GPT-4o-mini, Claude Sonnet)
1215
+ * - powerful: 高能力模型 (GPT-4o, Claude Opus, o1)
1216
+ */
1217
+ type ModelTier = 'cheap' | 'balanced' | 'powerful';
1218
+ interface ModelCandidate {
1219
+ id: string;
1220
+ name: string;
1221
+ provider: string;
1222
+ tier: ModelTier;
1223
+ costPer1kTokens: number;
1224
+ maxContextTokens: number;
1225
+ avgLatencyMs: number;
1226
+ capabilities: string[];
1227
+ enabled: boolean;
1228
+ weight: number;
1229
+ metadata?: Record<string, unknown>;
1230
+ }
1231
+ interface RoutingRequest {
1232
+ taskType: string;
1233
+ requiredCapabilities: string[];
1234
+ estimatedTokens: number;
1235
+ maxCostUsd?: number;
1236
+ maxLatencyMs?: number;
1237
+ preferredTier?: ModelTier;
1238
+ riskLevel: 'low' | 'medium' | 'high' | 'critical';
1239
+ userId?: string;
1240
+ metadata?: Record<string, unknown>;
1241
+ }
1242
+ type ReasonCode = 'ELIGIBLE' | 'DISABLED' | 'CAPABILITY_MISSING' | 'CONTEXT_TOO_LARGE' | 'COST_EXCEEDS_BUDGET' | 'LATENCY_EXCEEDS_LIMIT' | 'RISK_TIER_MISMATCH' | 'HARD_RULE_BLOCKED';
1243
+ interface EligibilityResult {
1244
+ candidateId: string;
1245
+ eligible: boolean;
1246
+ reasonCode: ReasonCode;
1247
+ reasonDetail: string;
1248
+ }
1249
+ interface ScoringResult {
1250
+ candidateId: string;
1251
+ score: number;
1252
+ breakdown: {
1253
+ costScore: number;
1254
+ latencyScore: number;
1255
+ capabilityScore: number;
1256
+ weightScore: number;
1257
+ tierMatchScore: number;
1258
+ };
1259
+ }
1260
+ interface RoutingDecision {
1261
+ selectedModelId: string;
1262
+ selectedModelName: string;
1263
+ tier: ModelTier;
1264
+ phase1Results: EligibilityResult[];
1265
+ phase2Results: ScoringResult[];
1266
+ reasonChain: string[];
1267
+ totalCandidates: number;
1268
+ eligibleCandidates: number;
1269
+ decisionTimeMs: number;
1270
+ fallbackUsed: boolean;
1271
+ metadata?: Record<string, unknown>;
1272
+ }
1273
+ interface HardRule {
1274
+ id: string;
1275
+ name: string;
1276
+ condition: (request: RoutingRequest, candidate: ModelCandidate) => boolean;
1277
+ reasonCode: ReasonCode;
1278
+ reasonTemplate: string;
1279
+ enabled: boolean;
1280
+ }
1281
+ interface ScoringWeights {
1282
+ cost: number;
1283
+ latency: number;
1284
+ capability: number;
1285
+ weight: number;
1286
+ tierMatch: number;
1287
+ }
1288
+ interface TwoPhaseRouterConfig {
1289
+ models: ModelCandidate[];
1290
+ hardRules: HardRule[];
1291
+ scoringWeights: ScoringWeights;
1292
+ defaultTier: ModelTier;
1293
+ fallbackModelId?: string;
1294
+ onDecision?: (decision: RoutingDecision) => void | Promise<void>;
1295
+ onAudit?: (event: {
1296
+ type: string;
1297
+ data: Record<string, unknown>;
1298
+ }) => void | Promise<void>;
1299
+ }
1300
+ declare const DEFAULT_HARD_RULES: HardRule[];
1301
+ declare const DEFAULT_SCORING_WEIGHTS: ScoringWeights;
1302
+ declare class TwoPhaseRouter {
1303
+ private config;
1304
+ constructor(config: TwoPhaseRouterConfig);
1305
+ /**
1306
+ * Phase 1: Eligibility — 硬性规则过滤
1307
+ */
1308
+ private evaluateEligibility;
1309
+ /**
1310
+ * Phase 2: Scoring — 软性指标加权评分
1311
+ */
1312
+ private evaluateScoring;
1313
+ /**
1314
+ * Main routing decision
1315
+ */
1316
+ route(request: RoutingRequest): Promise<RoutingDecision>;
1317
+ /**
1318
+ * Get models by tier
1319
+ */
1320
+ getModelsByTier(tier: ModelTier): ModelCandidate[];
1321
+ /**
1322
+ * Update model status
1323
+ */
1324
+ updateModel(modelId: string, updates: Partial<ModelCandidate>): boolean;
1325
+ /**
1326
+ * Add a new hard rule
1327
+ */
1328
+ addHardRule(rule: HardRule): void;
1329
+ /**
1330
+ * Get routing explanation for a specific request (dry run)
1331
+ */
1332
+ explain(request: RoutingRequest): Promise<{
1333
+ decision: RoutingDecision;
1334
+ explanation: string;
1335
+ }>;
1336
+ }
1337
+
1338
+ /**
1339
+ * SOVR Time Series Aggregator
1340
+ * 补齐 PDF3 时间序列聚合方案中的:
1341
+ * - 幂等聚合 (idempotent aggregation with dedup)
1342
+ * - P95 延迟计算
1343
+ * - 时间窗口聚合 (tumbling + sliding)
1344
+ * - 增量聚合 (不需要全量重算)
1345
+ *
1346
+ * 纯内存引擎,无外部依赖
1347
+ */
1348
+ type WindowType = 'tumbling' | 'sliding';
1349
+ type AggregationType = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'p50' | 'p95' | 'p99' | 'rate';
1350
+ interface DataPoint {
1351
+ id: string;
1352
+ timestamp: number;
1353
+ value: number;
1354
+ labels?: Record<string, string>;
1355
+ }
1356
+ interface AggregationWindow {
1357
+ windowId: string;
1358
+ windowType: WindowType;
1359
+ startMs: number;
1360
+ endMs: number;
1361
+ count: number;
1362
+ sum: number;
1363
+ min: number;
1364
+ max: number;
1365
+ values: number[];
1366
+ seenIds: Set<string>;
1367
+ }
1368
+ interface AggregationResult {
1369
+ windowId: string;
1370
+ windowType: WindowType;
1371
+ startMs: number;
1372
+ endMs: number;
1373
+ metrics: {
1374
+ count: number;
1375
+ sum: number;
1376
+ avg: number;
1377
+ min: number;
1378
+ max: number;
1379
+ p50: number;
1380
+ p95: number;
1381
+ p99: number;
1382
+ rate: number;
1383
+ };
1384
+ dedupCount: number;
1385
+ }
1386
+ interface TimeSeriesAggregatorConfig {
1387
+ /** Window size in ms */
1388
+ windowSizeMs: number;
1389
+ /** Window type */
1390
+ windowType: WindowType;
1391
+ /** Slide interval for sliding windows (ms), ignored for tumbling */
1392
+ slideIntervalMs?: number;
1393
+ /** Max windows to keep in memory */
1394
+ maxWindows: number;
1395
+ /** Max values per window (for percentile calc memory) */
1396
+ maxValuesPerWindow: number;
1397
+ /** Audit callback */
1398
+ onAudit?: (event: {
1399
+ type: string;
1400
+ data: Record<string, unknown>;
1401
+ }) => void | Promise<void>;
1402
+ /** Window closed callback */
1403
+ onWindowClosed?: (result: AggregationResult) => void | Promise<void>;
1404
+ }
1405
+ declare const DEFAULT_TSA_CONFIG: TimeSeriesAggregatorConfig;
1406
+ declare class TimeSeriesAggregator {
1407
+ private windows;
1408
+ private closedResults;
1409
+ private config;
1410
+ private totalDedups;
1411
+ constructor(config?: Partial<TimeSeriesAggregatorConfig>);
1412
+ /**
1413
+ * Ingest a data point (idempotent — duplicates are rejected)
1414
+ */
1415
+ ingest(point: DataPoint): Promise<{
1416
+ accepted: boolean;
1417
+ windowId: string;
1418
+ duplicate: boolean;
1419
+ }>;
1420
+ /**
1421
+ * Ingest multiple points (batch)
1422
+ */
1423
+ ingestBatch(points: DataPoint[]): Promise<{
1424
+ accepted: number;
1425
+ duplicates: number;
1426
+ errors: number;
1427
+ }>;
1428
+ /**
1429
+ * Get aggregation result for a specific window
1430
+ */
1431
+ getWindowResult(windowId: string): AggregationResult | null;
1432
+ /**
1433
+ * Get current (latest) window result
1434
+ */
1435
+ getCurrentResult(): AggregationResult | null;
1436
+ /**
1437
+ * Get results for a time range
1438
+ */
1439
+ getResultsInRange(startMs: number, endMs: number): AggregationResult[];
1440
+ /**
1441
+ * Close current window and emit result
1442
+ */
1443
+ closeWindow(windowId: string): Promise<AggregationResult | null>;
1444
+ /**
1445
+ * Get overall stats
1446
+ */
1447
+ getStats(): {
1448
+ activeWindows: number;
1449
+ closedWindows: number;
1450
+ totalDedups: number;
1451
+ totalDataPoints: number;
1452
+ };
1453
+ /**
1454
+ * Reset all windows
1455
+ */
1456
+ reset(): void;
1457
+ private getWindowId;
1458
+ private createWindow;
1459
+ private computeResult;
1460
+ private evictOldWindows;
1461
+ }
1462
+
1463
+ /**
1464
+ * SOVR Valuation Model Engine
1465
+ * 补齐 PDF1 千亿美金估值研究:
1466
+ * - TAM/SAM/SOM 市场规模计算
1467
+ * - 多维度估值模型 (DCF, Comparable, Network Effect)
1468
+ * - 增长预测与敏感性分析
1469
+ * - 单位经济学 (Unit Economics)
1470
+ *
1471
+ * 纯内存引擎,无外部依赖
1472
+ */
1473
+ interface MarketSize {
1474
+ tam: number;
1475
+ sam: number;
1476
+ som: number;
1477
+ year: number;
1478
+ growthRate: number;
1479
+ assumptions: string[];
1480
+ }
1481
+ interface UnitEconomics {
1482
+ arpu: number;
1483
+ cac: number;
1484
+ ltv: number;
1485
+ ltvCacRatio: number;
1486
+ paybackMonths: number;
1487
+ grossMargin: number;
1488
+ churnRate: number;
1489
+ expansionRate: number;
1490
+ }
1491
+ interface DCFInput {
1492
+ projectedRevenues: number[];
1493
+ growthRates: number[];
1494
+ discountRate: number;
1495
+ terminalGrowthRate: number;
1496
+ operatingMargin: number;
1497
+ taxRate: number;
1498
+ capexRatio: number;
1499
+ }
1500
+ interface DCFResult {
1501
+ presentValue: number;
1502
+ terminalValue: number;
1503
+ enterpriseValue: number;
1504
+ freeCashFlows: number[];
1505
+ discountedCashFlows: number[];
1506
+ impliedMultiple: number;
1507
+ }
1508
+ interface ComparableInput {
1509
+ revenue: number;
1510
+ ebitda: number;
1511
+ users: number;
1512
+ growthRate: number;
1513
+ comparables: Array<{
1514
+ name: string;
1515
+ evRevenue: number;
1516
+ evEbitda: number;
1517
+ evUser: number;
1518
+ growthRate: number;
1519
+ }>;
1520
+ }
1521
+ interface ComparableResult {
1522
+ revenueMultipleValuation: number;
1523
+ ebitdaMultipleValuation: number;
1524
+ perUserValuation: number;
1525
+ averageValuation: number;
1526
+ medianMultiple: number;
1527
+ growthAdjustedValuation: number;
1528
+ }
1529
+ interface NetworkEffectInput {
1530
+ currentUsers: number;
1531
+ projectedUsers: number[];
1532
+ valuePerConnection: number;
1533
+ networkDensity: number;
1534
+ metcalfeExponent: number;
1535
+ }
1536
+ interface NetworkEffectResult {
1537
+ currentNetworkValue: number;
1538
+ projectedValues: number[];
1539
+ metcalfeValue: number;
1540
+ adjustedValue: number;
1541
+ }
1542
+ interface SensitivityResult {
1543
+ baseCase: number;
1544
+ scenarios: Array<{
1545
+ name: string;
1546
+ value: number;
1547
+ delta: number;
1548
+ variables: Record<string, number>;
1549
+ }>;
1550
+ tornado: Array<{
1551
+ variable: string;
1552
+ lowValue: number;
1553
+ highValue: number;
1554
+ range: number;
1555
+ }>;
1556
+ }
1557
+ interface ValuationModelConfig {
1558
+ onAudit?: (event: {
1559
+ type: string;
1560
+ data: Record<string, unknown>;
1561
+ }) => void | Promise<void>;
1562
+ }
1563
+ declare class ValuationModel {
1564
+ private config;
1565
+ constructor(config?: ValuationModelConfig);
1566
+ /**
1567
+ * Calculate TAM/SAM/SOM
1568
+ */
1569
+ calculateMarketSize(input: {
1570
+ totalMarketUsd: number;
1571
+ serviceablePercent: number;
1572
+ obtainablePercent: number;
1573
+ growthRate: number;
1574
+ year: number;
1575
+ assumptions: string[];
1576
+ }): MarketSize;
1577
+ /**
1578
+ * Calculate Unit Economics
1579
+ */
1580
+ calculateUnitEconomics(input: {
1581
+ arpu: number;
1582
+ cac: number;
1583
+ grossMargin: number;
1584
+ churnRate: number;
1585
+ expansionRate: number;
1586
+ }): UnitEconomics;
1587
+ /**
1588
+ * DCF Valuation
1589
+ */
1590
+ calculateDCF(input: DCFInput): DCFResult;
1591
+ /**
1592
+ * Comparable Company Valuation
1593
+ */
1594
+ calculateComparable(input: ComparableInput): ComparableResult;
1595
+ /**
1596
+ * Network Effect Valuation (Metcalfe's Law)
1597
+ */
1598
+ calculateNetworkEffect(input: NetworkEffectInput): NetworkEffectResult;
1599
+ /**
1600
+ * Sensitivity Analysis
1601
+ */
1602
+ runSensitivity(baseInput: DCFInput, variables: Array<{
1603
+ name: string;
1604
+ low: number;
1605
+ high: number;
1606
+ field: keyof DCFInput;
1607
+ }>): SensitivityResult;
1608
+ private median;
1609
+ }
1610
+
1611
+ /**
1612
+ * SOVR Governance Enhancer
1613
+ * 补齐 PDF6/7 路由治理增强计划:
1614
+ * - 策略热更新 (hot-reload policies without restart)
1615
+ * - 降级链 (cascading degradation with fallback chain)
1616
+ * - 熔断器 (circuit breaker with half-open state)
1617
+ * - 治理规则版本管理
1618
+ *
1619
+ * 纯内存引擎,无外部依赖
1620
+ */
1621
+ type CircuitState = 'CLOSED' | 'OPEN' | 'HALF_OPEN';
1622
+ interface PolicyVersion {
1623
+ version: string;
1624
+ rules: GovernanceRule[];
1625
+ activatedAt: number;
1626
+ hash: string;
1627
+ metadata?: Record<string, unknown>;
1628
+ }
1629
+ interface GovernanceRule {
1630
+ id: string;
1631
+ name: string;
1632
+ condition: string;
1633
+ action: 'allow' | 'deny' | 'degrade' | 'escalate';
1634
+ priority: number;
1635
+ enabled: boolean;
1636
+ degradeTo?: string;
1637
+ metadata?: Record<string, unknown>;
1638
+ }
1639
+ interface DegradationLevel {
1640
+ id: string;
1641
+ name: string;
1642
+ order: number;
1643
+ capabilities: string[];
1644
+ restrictions: string[];
1645
+ }
1646
+ interface CircuitBreakerState {
1647
+ name: string;
1648
+ state: CircuitState;
1649
+ failureCount: number;
1650
+ successCount: number;
1651
+ lastFailureAt: number;
1652
+ lastSuccessAt: number;
1653
+ openedAt: number;
1654
+ halfOpenAttempts: number;
1655
+ }
1656
+ interface GovernanceDecision {
1657
+ allowed: boolean;
1658
+ action: string;
1659
+ ruleId?: string;
1660
+ ruleName?: string;
1661
+ degradationLevel?: string;
1662
+ circuitState?: CircuitState;
1663
+ reason: string;
1664
+ policyVersion: string;
1665
+ }
1666
+ interface GovernanceEnhancerConfig {
1667
+ /** Circuit breaker: failures before opening */
1668
+ circuitBreakerThreshold: number;
1669
+ /** Circuit breaker: time in OPEN before trying HALF_OPEN (ms) */
1670
+ circuitBreakerTimeoutMs: number;
1671
+ /** Circuit breaker: successes in HALF_OPEN before closing */
1672
+ halfOpenSuccessThreshold: number;
1673
+ /** Degradation chain (ordered from full to minimal) */
1674
+ degradationChain: DegradationLevel[];
1675
+ /** Max policy versions to keep */
1676
+ maxPolicyVersions: number;
1677
+ /** Audit callback */
1678
+ onAudit?: (event: {
1679
+ type: string;
1680
+ data: Record<string, unknown>;
1681
+ }) => void | Promise<void>;
1682
+ /** Policy change callback */
1683
+ onPolicyChange?: (oldVersion: string, newVersion: string) => void | Promise<void>;
1684
+ }
1685
+ declare const DEFAULT_GE_CONFIG: GovernanceEnhancerConfig;
1686
+ declare class GovernanceEnhancer {
1687
+ private currentPolicy;
1688
+ private policyHistory;
1689
+ private circuitBreakers;
1690
+ private currentDegradationLevel;
1691
+ private config;
1692
+ constructor(config?: Partial<GovernanceEnhancerConfig>);
1693
+ /**
1694
+ * Load a new policy version (hot-reload)
1695
+ */
1696
+ loadPolicy(version: string, rules: GovernanceRule[]): Promise<{
1697
+ success: boolean;
1698
+ previousVersion?: string;
1699
+ newVersion: string;
1700
+ }>;
1701
+ /**
1702
+ * Rollback to a previous policy version
1703
+ */
1704
+ rollbackPolicy(version: string): Promise<boolean>;
1705
+ /**
1706
+ * Evaluate a governance decision
1707
+ */
1708
+ evaluate(context: {
1709
+ action: string;
1710
+ resource: string;
1711
+ agentId: string;
1712
+ metadata?: Record<string, unknown>;
1713
+ }): Promise<GovernanceDecision>;
1714
+ /**
1715
+ * Record a success for circuit breaker
1716
+ */
1717
+ recordSuccess(resource: string): void;
1718
+ /**
1719
+ * Record a failure for circuit breaker
1720
+ */
1721
+ recordFailure(resource: string): void;
1722
+ /**
1723
+ * Get circuit breaker state for a resource
1724
+ */
1725
+ getCircuitBreakerState(resource: string): CircuitState;
1726
+ /**
1727
+ * Get current degradation level
1728
+ */
1729
+ getCurrentDegradationLevel(): DegradationLevel | undefined;
1730
+ /**
1731
+ * Degrade to next level
1732
+ */
1733
+ degradeOneLevel(): DegradationLevel | null;
1734
+ /**
1735
+ * Restore to full capability
1736
+ */
1737
+ restoreFullCapability(): void;
1738
+ /**
1739
+ * Check if a capability is available at current degradation level
1740
+ */
1741
+ isCapabilityAvailable(capability: string): boolean;
1742
+ /**
1743
+ * Get full governance status
1744
+ */
1745
+ getStatus(): {
1746
+ policyVersion: string | null;
1747
+ ruleCount: number;
1748
+ degradationLevel: string;
1749
+ circuitBreakers: CircuitBreakerState[];
1750
+ policyHistoryCount: number;
1751
+ };
1752
+ private evaluateCondition;
1753
+ private getOrCreateCircuitBreaker;
1754
+ }
1755
+
1756
+ /**
1757
+ * SOVR Context Accelerator
1758
+ * 补齐 PDF8 上下文加速器设计任务:
1759
+ * - 上下文缓存 (LRU with TTL)
1760
+ * - 上下文预热 (prefetch pipeline)
1761
+ * - 上下文压缩 (token budget optimization)
1762
+ * - 上下文优先级排序
1763
+ *
1764
+ * 纯内存引擎,无外部依赖
1765
+ */
1766
+ type ContextPriority = 'critical' | 'high' | 'medium' | 'low';
1767
+ interface ContextFragment {
1768
+ id: string;
1769
+ content: string;
1770
+ tokenCount: number;
1771
+ priority: ContextPriority;
1772
+ source: string;
1773
+ timestamp: number;
1774
+ ttlMs: number;
1775
+ compressed: boolean;
1776
+ metadata?: Record<string, unknown>;
1777
+ }
1778
+ interface CacheEntry {
1779
+ fragment: ContextFragment;
1780
+ accessCount: number;
1781
+ lastAccessedAt: number;
1782
+ createdAt: number;
1783
+ expiresAt: number;
1784
+ }
1785
+ interface AssembledContext {
1786
+ fragments: ContextFragment[];
1787
+ totalTokens: number;
1788
+ budgetUsed: number;
1789
+ droppedCount: number;
1790
+ compressedCount: number;
1791
+ cacheHits: number;
1792
+ cacheMisses: number;
1793
+ assemblyTimeMs: number;
1794
+ }
1795
+ interface PrefetchRule {
1796
+ id: string;
1797
+ trigger: string;
1798
+ fragmentIds: string[];
1799
+ enabled: boolean;
1800
+ }
1801
+ interface ContextAcceleratorConfig {
1802
+ /** Max cache entries */
1803
+ maxCacheEntries: number;
1804
+ /** Default TTL for cache entries (ms) */
1805
+ defaultTtlMs: number;
1806
+ /** Token budget for assembled context */
1807
+ tokenBudget: number;
1808
+ /** Compression ratio target (0-1) */
1809
+ compressionTarget: number;
1810
+ /** Priority weights for sorting */
1811
+ priorityWeights: Record<ContextPriority, number>;
1812
+ /** Audit callback */
1813
+ onAudit?: (event: {
1814
+ type: string;
1815
+ data: Record<string, unknown>;
1816
+ }) => void | Promise<void>;
1817
+ /** Custom compressor function */
1818
+ compressor?: (content: string, targetTokens: number) => string;
1819
+ }
1820
+ declare const DEFAULT_CA_CONFIG: ContextAcceleratorConfig;
1821
+ declare class ContextAccelerator {
1822
+ private cache;
1823
+ private prefetchRules;
1824
+ private config;
1825
+ private stats;
1826
+ constructor(config?: Partial<ContextAcceleratorConfig>);
1827
+ /**
1828
+ * Put a fragment into cache
1829
+ */
1830
+ put(fragment: ContextFragment): void;
1831
+ /**
1832
+ * Get a fragment from cache
1833
+ */
1834
+ get(id: string): ContextFragment | null;
1835
+ /**
1836
+ * Assemble context from fragments within token budget
1837
+ */
1838
+ assemble(fragmentIds: string[], additionalFragments?: ContextFragment[], budgetOverride?: number): Promise<AssembledContext>;
1839
+ /**
1840
+ * Register a prefetch rule
1841
+ */
1842
+ addPrefetchRule(rule: PrefetchRule): void;
1843
+ /**
1844
+ * Execute prefetch based on task type
1845
+ */
1846
+ prefetch(taskType: string, fragmentLoader: (ids: string[]) => Promise<ContextFragment[]>): Promise<number>;
1847
+ /**
1848
+ * Invalidate cache entries
1849
+ */
1850
+ invalidate(ids: string[]): number;
1851
+ /**
1852
+ * Get cache stats
1853
+ */
1854
+ getStats(): {
1855
+ cacheSize: number;
1856
+ maxSize: number;
1857
+ hitRate: number;
1858
+ totalHits: number;
1859
+ totalMisses: number;
1860
+ totalEvictions: number;
1861
+ totalCompressions: number;
1862
+ totalAssemblies: number;
1863
+ prefetchRuleCount: number;
1864
+ };
1865
+ /**
1866
+ * Clear all cache
1867
+ */
1868
+ clear(): void;
1869
+ private evictExpired;
1870
+ private evictLRU;
1871
+ }
1872
+
1202
1873
  /**
1203
1874
  * @sovr/engine — Unified Policy Engine
1204
1875
  *
@@ -1415,4 +2086,4 @@ declare class PolicyEngine {
1415
2086
  }): void;
1416
2087
  }
1417
2088
 
1418
- export { type ABTestConfig, AdaptiveThresholdManager, type AdaptiveThresholdOptions, type AdjustmentResult, type AggregateSnapshot, type AuditEvent, AutoHardenEngine, type BudgetAlert, type BudgetLevel, type BudgetNode, type Channel, type ComparisonNode, type CompiledExpression, type ConsistencyMismatch, type ConsistencyResult, type CostAuditEvent, type CostCategory, type CostEstimate, type CostEstimateRequest, type CostGateEnhancedConfig, CostGateEnhancedEngine, type CostRecord, type CostReport, type CostSummary, DEFAULT_RULES, type DecisionFeedback, type DriftConfig, type DriftResult, 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 HardenConfig, type HardenEvent, type HardenLevel, type HardenMeasure, type HardenMeasureType, type HardenState, type HttpContext, type LiteralNode, type LogicalNode, type McpContext, type ModelPricing, type MultiLevelBudgetConfig, MultiLevelBudgetEngine, type NotNode, PolicyEngine, type PolicyRule, type PolicySnapshot, type PolicyVersion, type PricingEvalRequest, type PricingEvalResult, type PricingRule, PricingRulesEngine, type RecalcEngineConfig, type RecalcGranularity, type RecalcHandler, type RecalcTask, type RecalcTaskStatus, type RecalcTriggerType, RecalculationEngine, type RiskLevel, type RuleCondition, type RuleEvalResult, SOVR_FEATURE_SWITCHES, SemanticDriftDetectorEngine, type SemanticFingerprint, type SqlContext, type ThresholdConfig, type ToolPricing, type VariableNode, type Verdict, compileFromJSON, compileRuleSet, createAutoHardenEngine, createCostGateEnhanced, createEvolutionChannel, createMultiLevelBudget, createRecalculationEngine, createSemanticDriftDetector, PolicyEngine as default, estimateCost, evaluateRules, getAccuracyStats, getModelPricingTable, getToolPricingTable, recordActualCost, registerFunction, updateModelPricing, updateToolPricing };
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 };