@sovr/engine 3.4.0 → 3.6.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.mts +1091 -7
- package/dist/index.d.ts +1091 -7
- package/dist/index.js +2286 -0
- package/dist/index.mjs +2272 -0
- package/package.json +1 -1
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,1100 @@ 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
|
+
|
|
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 = '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;
|
|
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;
|
|
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
|
+
|
|
1202
2286
|
/**
|
|
1203
2287
|
* @sovr/engine — Unified Policy Engine
|
|
1204
2288
|
*
|
|
@@ -1415,4 +2499,4 @@ declare class PolicyEngine {
|
|
|
1415
2499
|
}): void;
|
|
1416
2500
|
}
|
|
1417
2501
|
|
|
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 };
|
|
2502
|
+
export { type ABTestConfig, AdaptiveThresholdManager, type AdaptiveThresholdOptions, type AdjustmentResult, type AggregateSnapshot, type AggregationResult, type AggregationType, type AggregationWindow, type AlertEvent, type AlertSeverity, type AlertThreshold, type AlertType, type AssembledContext, type AttributionRule, type AuditEvent, AutoHardenEngine, type BudgetAlert, type BudgetLevel, type BudgetNode, type CacheEntry, type CapabilityFlags, type Channel, type CircuitBreakerState, type CircuitState, type ComparableInput, type ComparableResult, type ComparisonNode, type CompiledExpression, type ConsistencyMismatch, type ConsistencyResult, 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 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 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, 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 KillSwitchState, type LiteralNode, type LogicalNode, type MarketSize, type McpContext, 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 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 ScoreConfigVersion, type ScoringResult, type ScoringWeights, SelfConstraintEngine, SemanticDriftDetectorEngine, type SemanticFingerprint, type SensitivityResult, type SettlementContext, type SqlContext, type SystemState, type ThresholdConfig, type TighteningThresholds, TimeSeriesAggregator, type TimeSeriesAggregatorConfig, 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 };
|