chainlesschain 0.143.0 → 0.152.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/package.json +1 -1
- package/src/commands/a2a.js +196 -28
- package/src/commands/activitypub.js +364 -27
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +355 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +403 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +824 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +783 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dbevo.js +227 -0
- package/src/commands/dev.js +207 -0
- package/src/commands/did-v2.js +217 -0
- package/src/commands/did.js +221 -0
- package/src/commands/dlp.js +385 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +387 -27
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fflag.js +74 -22
- package/src/commands/fusion.js +205 -0
- package/src/commands/git.js +177 -37
- package/src/commands/governance.js +209 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/llm.js +217 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +386 -27
- package/src/commands/mcp.js +217 -0
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/memory.js +209 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +387 -27
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perception.js +209 -0
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +410 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/session.js +209 -0
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/skill.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +358 -32
- package/src/commands/sso.js +209 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/tokens.js +209 -0
- package/src/commands/topiccls.js +146 -33
- package/src/commands/trust.js +217 -0
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/wallet.js +209 -0
- package/src/commands/webfetch.js +141 -32
- package/src/commands/workflow.js +203 -0
- package/src/commands/zkp.js +184 -28
- package/src/index.js +180 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +622 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +616 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +630 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -0
- package/src/lib/compliance-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- package/src/lib/dbevo.js +351 -0
- package/src/lib/decentral-infra.js +330 -0
- package/src/lib/did-manager.js +341 -0
- package/src/lib/did-v2-manager.js +341 -0
- package/src/lib/dlp-engine.js +626 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +308 -51
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +620 -47
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/memory-manager.js +336 -0
- package/src/lib/multimodal.js +330 -0
- package/src/lib/nl-programming.js +341 -0
- package/src/lib/nostr-bridge.js +622 -49
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-manager.js +334 -0
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/trust-security.js +343 -0
- package/src/lib/ueba.js +340 -0
- package/src/lib/universal-runtime.js +330 -0
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/zkp-engine.js +286 -49
package/src/lib/agent-network.js
CHANGED
|
@@ -1506,3 +1506,344 @@ export function _resetStateAgentNetworkV2() {
|
|
|
1506
1506
|
_stateAnetV2.agentIdleMs = AGENT_DEFAULT_AGENT_IDLE_MS;
|
|
1507
1507
|
_stateAnetV2.taskStuckMs = AGENT_DEFAULT_TASK_STUCK_MS;
|
|
1508
1508
|
}
|
|
1509
|
+
|
|
1510
|
+
// =====================================================================
|
|
1511
|
+
// agent-network V2 governance overlay (iter20)
|
|
1512
|
+
// =====================================================================
|
|
1513
|
+
export const ANETGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
1514
|
+
PENDING: "pending",
|
|
1515
|
+
ACTIVE: "active",
|
|
1516
|
+
SUSPENDED: "suspended",
|
|
1517
|
+
ARCHIVED: "archived",
|
|
1518
|
+
});
|
|
1519
|
+
export const ANETGOV_DISPATCH_LIFECYCLE_V2 = Object.freeze({
|
|
1520
|
+
QUEUED: "queued",
|
|
1521
|
+
DISPATCHING: "dispatching",
|
|
1522
|
+
DISPATCHED: "dispatched",
|
|
1523
|
+
FAILED: "failed",
|
|
1524
|
+
CANCELLED: "cancelled",
|
|
1525
|
+
});
|
|
1526
|
+
const _anetgovPTrans = new Map([
|
|
1527
|
+
[
|
|
1528
|
+
ANETGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1529
|
+
new Set([
|
|
1530
|
+
ANETGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1531
|
+
ANETGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1532
|
+
]),
|
|
1533
|
+
],
|
|
1534
|
+
[
|
|
1535
|
+
ANETGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1536
|
+
new Set([
|
|
1537
|
+
ANETGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1538
|
+
ANETGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1539
|
+
]),
|
|
1540
|
+
],
|
|
1541
|
+
[
|
|
1542
|
+
ANETGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1543
|
+
new Set([
|
|
1544
|
+
ANETGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1545
|
+
ANETGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1546
|
+
]),
|
|
1547
|
+
],
|
|
1548
|
+
[ANETGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1549
|
+
]);
|
|
1550
|
+
const _anetgovPTerminal = new Set([ANETGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1551
|
+
const _anetgovJTrans = new Map([
|
|
1552
|
+
[
|
|
1553
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.QUEUED,
|
|
1554
|
+
new Set([
|
|
1555
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING,
|
|
1556
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.CANCELLED,
|
|
1557
|
+
]),
|
|
1558
|
+
],
|
|
1559
|
+
[
|
|
1560
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING,
|
|
1561
|
+
new Set([
|
|
1562
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHED,
|
|
1563
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.FAILED,
|
|
1564
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.CANCELLED,
|
|
1565
|
+
]),
|
|
1566
|
+
],
|
|
1567
|
+
[ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHED, new Set()],
|
|
1568
|
+
[ANETGOV_DISPATCH_LIFECYCLE_V2.FAILED, new Set()],
|
|
1569
|
+
[ANETGOV_DISPATCH_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1570
|
+
]);
|
|
1571
|
+
const _anetgovPsV2 = new Map();
|
|
1572
|
+
const _anetgovJsV2 = new Map();
|
|
1573
|
+
let _anetgovMaxActive = 10,
|
|
1574
|
+
_anetgovMaxPending = 25,
|
|
1575
|
+
_anetgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1576
|
+
_anetgovStuckMs = 60 * 1000;
|
|
1577
|
+
function _anetgovPos(n, label) {
|
|
1578
|
+
const v = Math.floor(Number(n));
|
|
1579
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1580
|
+
throw new Error(`${label} must be positive integer`);
|
|
1581
|
+
return v;
|
|
1582
|
+
}
|
|
1583
|
+
function _anetgovCheckP(from, to) {
|
|
1584
|
+
const a = _anetgovPTrans.get(from);
|
|
1585
|
+
if (!a || !a.has(to))
|
|
1586
|
+
throw new Error(`invalid anetgov profile transition ${from} → ${to}`);
|
|
1587
|
+
}
|
|
1588
|
+
function _anetgovCheckJ(from, to) {
|
|
1589
|
+
const a = _anetgovJTrans.get(from);
|
|
1590
|
+
if (!a || !a.has(to))
|
|
1591
|
+
throw new Error(`invalid anetgov dispatch transition ${from} → ${to}`);
|
|
1592
|
+
}
|
|
1593
|
+
function _anetgovCountActive(owner) {
|
|
1594
|
+
let c = 0;
|
|
1595
|
+
for (const p of _anetgovPsV2.values())
|
|
1596
|
+
if (p.owner === owner && p.status === ANETGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
1597
|
+
c++;
|
|
1598
|
+
return c;
|
|
1599
|
+
}
|
|
1600
|
+
function _anetgovCountPending(profileId) {
|
|
1601
|
+
let c = 0;
|
|
1602
|
+
for (const j of _anetgovJsV2.values())
|
|
1603
|
+
if (
|
|
1604
|
+
j.profileId === profileId &&
|
|
1605
|
+
(j.status === ANETGOV_DISPATCH_LIFECYCLE_V2.QUEUED ||
|
|
1606
|
+
j.status === ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING)
|
|
1607
|
+
)
|
|
1608
|
+
c++;
|
|
1609
|
+
return c;
|
|
1610
|
+
}
|
|
1611
|
+
export function setMaxActiveAnetgovProfilesPerOwnerV2(n) {
|
|
1612
|
+
_anetgovMaxActive = _anetgovPos(n, "maxActiveAnetgovProfilesPerOwner");
|
|
1613
|
+
}
|
|
1614
|
+
export function getMaxActiveAnetgovProfilesPerOwnerV2() {
|
|
1615
|
+
return _anetgovMaxActive;
|
|
1616
|
+
}
|
|
1617
|
+
export function setMaxPendingAnetgovDispatchsPerProfileV2(n) {
|
|
1618
|
+
_anetgovMaxPending = _anetgovPos(n, "maxPendingAnetgovDispatchsPerProfile");
|
|
1619
|
+
}
|
|
1620
|
+
export function getMaxPendingAnetgovDispatchsPerProfileV2() {
|
|
1621
|
+
return _anetgovMaxPending;
|
|
1622
|
+
}
|
|
1623
|
+
export function setAnetgovProfileIdleMsV2(n) {
|
|
1624
|
+
_anetgovIdleMs = _anetgovPos(n, "anetgovProfileIdleMs");
|
|
1625
|
+
}
|
|
1626
|
+
export function getAnetgovProfileIdleMsV2() {
|
|
1627
|
+
return _anetgovIdleMs;
|
|
1628
|
+
}
|
|
1629
|
+
export function setAnetgovDispatchStuckMsV2(n) {
|
|
1630
|
+
_anetgovStuckMs = _anetgovPos(n, "anetgovDispatchStuckMs");
|
|
1631
|
+
}
|
|
1632
|
+
export function getAnetgovDispatchStuckMsV2() {
|
|
1633
|
+
return _anetgovStuckMs;
|
|
1634
|
+
}
|
|
1635
|
+
export function _resetStateAgentNetworkGovV2() {
|
|
1636
|
+
_anetgovPsV2.clear();
|
|
1637
|
+
_anetgovJsV2.clear();
|
|
1638
|
+
_anetgovMaxActive = 10;
|
|
1639
|
+
_anetgovMaxPending = 25;
|
|
1640
|
+
_anetgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1641
|
+
_anetgovStuckMs = 60 * 1000;
|
|
1642
|
+
}
|
|
1643
|
+
export function registerAnetgovProfileV2({ id, owner, role, metadata } = {}) {
|
|
1644
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1645
|
+
if (_anetgovPsV2.has(id))
|
|
1646
|
+
throw new Error(`anetgov profile ${id} already exists`);
|
|
1647
|
+
const now = Date.now();
|
|
1648
|
+
const p = {
|
|
1649
|
+
id,
|
|
1650
|
+
owner,
|
|
1651
|
+
role: role || "worker",
|
|
1652
|
+
status: ANETGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1653
|
+
createdAt: now,
|
|
1654
|
+
updatedAt: now,
|
|
1655
|
+
lastTouchedAt: now,
|
|
1656
|
+
activatedAt: null,
|
|
1657
|
+
archivedAt: null,
|
|
1658
|
+
metadata: { ...(metadata || {}) },
|
|
1659
|
+
};
|
|
1660
|
+
_anetgovPsV2.set(id, p);
|
|
1661
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1662
|
+
}
|
|
1663
|
+
export function activateAnetgovProfileV2(id) {
|
|
1664
|
+
const p = _anetgovPsV2.get(id);
|
|
1665
|
+
if (!p) throw new Error(`anetgov profile ${id} not found`);
|
|
1666
|
+
const isInitial = p.status === ANETGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1667
|
+
_anetgovCheckP(p.status, ANETGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1668
|
+
if (isInitial && _anetgovCountActive(p.owner) >= _anetgovMaxActive)
|
|
1669
|
+
throw new Error(`max active anetgov profiles for owner ${p.owner} reached`);
|
|
1670
|
+
const now = Date.now();
|
|
1671
|
+
p.status = ANETGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1672
|
+
p.updatedAt = now;
|
|
1673
|
+
p.lastTouchedAt = now;
|
|
1674
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1675
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1676
|
+
}
|
|
1677
|
+
export function suspendAnetgovProfileV2(id) {
|
|
1678
|
+
const p = _anetgovPsV2.get(id);
|
|
1679
|
+
if (!p) throw new Error(`anetgov profile ${id} not found`);
|
|
1680
|
+
_anetgovCheckP(p.status, ANETGOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
1681
|
+
p.status = ANETGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1682
|
+
p.updatedAt = Date.now();
|
|
1683
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1684
|
+
}
|
|
1685
|
+
export function archiveAnetgovProfileV2(id) {
|
|
1686
|
+
const p = _anetgovPsV2.get(id);
|
|
1687
|
+
if (!p) throw new Error(`anetgov profile ${id} not found`);
|
|
1688
|
+
_anetgovCheckP(p.status, ANETGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1689
|
+
const now = Date.now();
|
|
1690
|
+
p.status = ANETGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1691
|
+
p.updatedAt = now;
|
|
1692
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1693
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1694
|
+
}
|
|
1695
|
+
export function touchAnetgovProfileV2(id) {
|
|
1696
|
+
const p = _anetgovPsV2.get(id);
|
|
1697
|
+
if (!p) throw new Error(`anetgov profile ${id} not found`);
|
|
1698
|
+
if (_anetgovPTerminal.has(p.status))
|
|
1699
|
+
throw new Error(`cannot touch terminal anetgov profile ${id}`);
|
|
1700
|
+
const now = Date.now();
|
|
1701
|
+
p.lastTouchedAt = now;
|
|
1702
|
+
p.updatedAt = now;
|
|
1703
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1704
|
+
}
|
|
1705
|
+
export function getAnetgovProfileV2(id) {
|
|
1706
|
+
const p = _anetgovPsV2.get(id);
|
|
1707
|
+
if (!p) return null;
|
|
1708
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1709
|
+
}
|
|
1710
|
+
export function listAnetgovProfilesV2() {
|
|
1711
|
+
return [..._anetgovPsV2.values()].map((p) => ({
|
|
1712
|
+
...p,
|
|
1713
|
+
metadata: { ...p.metadata },
|
|
1714
|
+
}));
|
|
1715
|
+
}
|
|
1716
|
+
export function createAnetgovDispatchV2({
|
|
1717
|
+
id,
|
|
1718
|
+
profileId,
|
|
1719
|
+
target,
|
|
1720
|
+
metadata,
|
|
1721
|
+
} = {}) {
|
|
1722
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1723
|
+
if (_anetgovJsV2.has(id))
|
|
1724
|
+
throw new Error(`anetgov dispatch ${id} already exists`);
|
|
1725
|
+
if (!_anetgovPsV2.has(profileId))
|
|
1726
|
+
throw new Error(`anetgov profile ${profileId} not found`);
|
|
1727
|
+
if (_anetgovCountPending(profileId) >= _anetgovMaxPending)
|
|
1728
|
+
throw new Error(
|
|
1729
|
+
`max pending anetgov dispatchs for profile ${profileId} reached`,
|
|
1730
|
+
);
|
|
1731
|
+
const now = Date.now();
|
|
1732
|
+
const j = {
|
|
1733
|
+
id,
|
|
1734
|
+
profileId,
|
|
1735
|
+
target: target || "",
|
|
1736
|
+
status: ANETGOV_DISPATCH_LIFECYCLE_V2.QUEUED,
|
|
1737
|
+
createdAt: now,
|
|
1738
|
+
updatedAt: now,
|
|
1739
|
+
startedAt: null,
|
|
1740
|
+
settledAt: null,
|
|
1741
|
+
metadata: { ...(metadata || {}) },
|
|
1742
|
+
};
|
|
1743
|
+
_anetgovJsV2.set(id, j);
|
|
1744
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1745
|
+
}
|
|
1746
|
+
export function dispatchingAnetgovDispatchV2(id) {
|
|
1747
|
+
const j = _anetgovJsV2.get(id);
|
|
1748
|
+
if (!j) throw new Error(`anetgov dispatch ${id} not found`);
|
|
1749
|
+
_anetgovCheckJ(j.status, ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING);
|
|
1750
|
+
const now = Date.now();
|
|
1751
|
+
j.status = ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING;
|
|
1752
|
+
j.updatedAt = now;
|
|
1753
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1754
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1755
|
+
}
|
|
1756
|
+
export function completeDispatchAnetgovV2(id) {
|
|
1757
|
+
const j = _anetgovJsV2.get(id);
|
|
1758
|
+
if (!j) throw new Error(`anetgov dispatch ${id} not found`);
|
|
1759
|
+
_anetgovCheckJ(j.status, ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHED);
|
|
1760
|
+
const now = Date.now();
|
|
1761
|
+
j.status = ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHED;
|
|
1762
|
+
j.updatedAt = now;
|
|
1763
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1764
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1765
|
+
}
|
|
1766
|
+
export function failAnetgovDispatchV2(id, reason) {
|
|
1767
|
+
const j = _anetgovJsV2.get(id);
|
|
1768
|
+
if (!j) throw new Error(`anetgov dispatch ${id} not found`);
|
|
1769
|
+
_anetgovCheckJ(j.status, ANETGOV_DISPATCH_LIFECYCLE_V2.FAILED);
|
|
1770
|
+
const now = Date.now();
|
|
1771
|
+
j.status = ANETGOV_DISPATCH_LIFECYCLE_V2.FAILED;
|
|
1772
|
+
j.updatedAt = now;
|
|
1773
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1774
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1775
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1776
|
+
}
|
|
1777
|
+
export function cancelAnetgovDispatchV2(id, reason) {
|
|
1778
|
+
const j = _anetgovJsV2.get(id);
|
|
1779
|
+
if (!j) throw new Error(`anetgov dispatch ${id} not found`);
|
|
1780
|
+
_anetgovCheckJ(j.status, ANETGOV_DISPATCH_LIFECYCLE_V2.CANCELLED);
|
|
1781
|
+
const now = Date.now();
|
|
1782
|
+
j.status = ANETGOV_DISPATCH_LIFECYCLE_V2.CANCELLED;
|
|
1783
|
+
j.updatedAt = now;
|
|
1784
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1785
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1786
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1787
|
+
}
|
|
1788
|
+
export function getAnetgovDispatchV2(id) {
|
|
1789
|
+
const j = _anetgovJsV2.get(id);
|
|
1790
|
+
if (!j) return null;
|
|
1791
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1792
|
+
}
|
|
1793
|
+
export function listAnetgovDispatchsV2() {
|
|
1794
|
+
return [..._anetgovJsV2.values()].map((j) => ({
|
|
1795
|
+
...j,
|
|
1796
|
+
metadata: { ...j.metadata },
|
|
1797
|
+
}));
|
|
1798
|
+
}
|
|
1799
|
+
export function autoSuspendIdleAnetgovProfilesV2({ now } = {}) {
|
|
1800
|
+
const t = now ?? Date.now();
|
|
1801
|
+
const flipped = [];
|
|
1802
|
+
for (const p of _anetgovPsV2.values())
|
|
1803
|
+
if (
|
|
1804
|
+
p.status === ANETGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1805
|
+
t - p.lastTouchedAt >= _anetgovIdleMs
|
|
1806
|
+
) {
|
|
1807
|
+
p.status = ANETGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1808
|
+
p.updatedAt = t;
|
|
1809
|
+
flipped.push(p.id);
|
|
1810
|
+
}
|
|
1811
|
+
return { flipped, count: flipped.length };
|
|
1812
|
+
}
|
|
1813
|
+
export function autoFailStuckAnetgovDispatchsV2({ now } = {}) {
|
|
1814
|
+
const t = now ?? Date.now();
|
|
1815
|
+
const flipped = [];
|
|
1816
|
+
for (const j of _anetgovJsV2.values())
|
|
1817
|
+
if (
|
|
1818
|
+
j.status === ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING &&
|
|
1819
|
+
j.startedAt != null &&
|
|
1820
|
+
t - j.startedAt >= _anetgovStuckMs
|
|
1821
|
+
) {
|
|
1822
|
+
j.status = ANETGOV_DISPATCH_LIFECYCLE_V2.FAILED;
|
|
1823
|
+
j.updatedAt = t;
|
|
1824
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1825
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1826
|
+
flipped.push(j.id);
|
|
1827
|
+
}
|
|
1828
|
+
return { flipped, count: flipped.length };
|
|
1829
|
+
}
|
|
1830
|
+
export function getAgentNetworkGovStatsV2() {
|
|
1831
|
+
const profilesByStatus = {};
|
|
1832
|
+
for (const v of Object.values(ANETGOV_PROFILE_MATURITY_V2))
|
|
1833
|
+
profilesByStatus[v] = 0;
|
|
1834
|
+
for (const p of _anetgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1835
|
+
const dispatchsByStatus = {};
|
|
1836
|
+
for (const v of Object.values(ANETGOV_DISPATCH_LIFECYCLE_V2))
|
|
1837
|
+
dispatchsByStatus[v] = 0;
|
|
1838
|
+
for (const j of _anetgovJsV2.values()) dispatchsByStatus[j.status]++;
|
|
1839
|
+
return {
|
|
1840
|
+
totalAnetgovProfilesV2: _anetgovPsV2.size,
|
|
1841
|
+
totalAnetgovDispatchsV2: _anetgovJsV2.size,
|
|
1842
|
+
maxActiveAnetgovProfilesPerOwner: _anetgovMaxActive,
|
|
1843
|
+
maxPendingAnetgovDispatchsPerProfile: _anetgovMaxPending,
|
|
1844
|
+
anetgovProfileIdleMs: _anetgovIdleMs,
|
|
1845
|
+
anetgovDispatchStuckMs: _anetgovStuckMs,
|
|
1846
|
+
profilesByStatus,
|
|
1847
|
+
dispatchsByStatus,
|
|
1848
|
+
};
|
|
1849
|
+
}
|
package/src/lib/aiops.js
CHANGED
|
@@ -999,3 +999,349 @@ export function _resetStateV2() {
|
|
|
999
999
|
_playbookStaleMsV2 = AIOPS_DEFAULT_PLAYBOOK_STALE_MS;
|
|
1000
1000
|
_remediationTimeoutMsV2 = AIOPS_DEFAULT_REMEDIATION_TIMEOUT_MS;
|
|
1001
1001
|
}
|
|
1002
|
+
|
|
1003
|
+
// =====================================================================
|
|
1004
|
+
// aiops V2 governance overlay (iter18)
|
|
1005
|
+
// =====================================================================
|
|
1006
|
+
export const AIOPSGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
1007
|
+
PENDING: "pending",
|
|
1008
|
+
ACTIVE: "active",
|
|
1009
|
+
STALE: "stale",
|
|
1010
|
+
ARCHIVED: "archived",
|
|
1011
|
+
});
|
|
1012
|
+
export const AIOPSGOV_INCIDENT_LIFECYCLE_V2 = Object.freeze({
|
|
1013
|
+
QUEUED: "queued",
|
|
1014
|
+
TRIAGING: "triaging",
|
|
1015
|
+
TRIAGED: "triaged",
|
|
1016
|
+
FAILED: "failed",
|
|
1017
|
+
CANCELLED: "cancelled",
|
|
1018
|
+
});
|
|
1019
|
+
const _aiopsgovPTrans = new Map([
|
|
1020
|
+
[
|
|
1021
|
+
AIOPSGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1022
|
+
new Set([
|
|
1023
|
+
AIOPSGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1024
|
+
AIOPSGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1025
|
+
]),
|
|
1026
|
+
],
|
|
1027
|
+
[
|
|
1028
|
+
AIOPSGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1029
|
+
new Set([
|
|
1030
|
+
AIOPSGOV_PROFILE_MATURITY_V2.STALE,
|
|
1031
|
+
AIOPSGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1032
|
+
]),
|
|
1033
|
+
],
|
|
1034
|
+
[
|
|
1035
|
+
AIOPSGOV_PROFILE_MATURITY_V2.STALE,
|
|
1036
|
+
new Set([
|
|
1037
|
+
AIOPSGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1038
|
+
AIOPSGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1039
|
+
]),
|
|
1040
|
+
],
|
|
1041
|
+
[AIOPSGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1042
|
+
]);
|
|
1043
|
+
const _aiopsgovPTerminal = new Set([AIOPSGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1044
|
+
const _aiopsgovJTrans = new Map([
|
|
1045
|
+
[
|
|
1046
|
+
AIOPSGOV_INCIDENT_LIFECYCLE_V2.QUEUED,
|
|
1047
|
+
new Set([
|
|
1048
|
+
AIOPSGOV_INCIDENT_LIFECYCLE_V2.TRIAGING,
|
|
1049
|
+
AIOPSGOV_INCIDENT_LIFECYCLE_V2.CANCELLED,
|
|
1050
|
+
]),
|
|
1051
|
+
],
|
|
1052
|
+
[
|
|
1053
|
+
AIOPSGOV_INCIDENT_LIFECYCLE_V2.TRIAGING,
|
|
1054
|
+
new Set([
|
|
1055
|
+
AIOPSGOV_INCIDENT_LIFECYCLE_V2.TRIAGED,
|
|
1056
|
+
AIOPSGOV_INCIDENT_LIFECYCLE_V2.FAILED,
|
|
1057
|
+
AIOPSGOV_INCIDENT_LIFECYCLE_V2.CANCELLED,
|
|
1058
|
+
]),
|
|
1059
|
+
],
|
|
1060
|
+
[AIOPSGOV_INCIDENT_LIFECYCLE_V2.TRIAGED, new Set()],
|
|
1061
|
+
[AIOPSGOV_INCIDENT_LIFECYCLE_V2.FAILED, new Set()],
|
|
1062
|
+
[AIOPSGOV_INCIDENT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1063
|
+
]);
|
|
1064
|
+
const _aiopsgovPsV2 = new Map();
|
|
1065
|
+
const _aiopsgovJsV2 = new Map();
|
|
1066
|
+
let _aiopsgovMaxActive = 6,
|
|
1067
|
+
_aiopsgovMaxPending = 15,
|
|
1068
|
+
_aiopsgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1069
|
+
_aiopsgovStuckMs = 60 * 1000;
|
|
1070
|
+
function _aiopsgovPos(n, label) {
|
|
1071
|
+
const v = Math.floor(Number(n));
|
|
1072
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1073
|
+
throw new Error(`${label} must be positive integer`);
|
|
1074
|
+
return v;
|
|
1075
|
+
}
|
|
1076
|
+
function _aiopsgovCheckP(from, to) {
|
|
1077
|
+
const a = _aiopsgovPTrans.get(from);
|
|
1078
|
+
if (!a || !a.has(to))
|
|
1079
|
+
throw new Error(`invalid aiopsgov profile transition ${from} → ${to}`);
|
|
1080
|
+
}
|
|
1081
|
+
function _aiopsgovCheckJ(from, to) {
|
|
1082
|
+
const a = _aiopsgovJTrans.get(from);
|
|
1083
|
+
if (!a || !a.has(to))
|
|
1084
|
+
throw new Error(`invalid aiopsgov incident transition ${from} → ${to}`);
|
|
1085
|
+
}
|
|
1086
|
+
function _aiopsgovCountActive(owner) {
|
|
1087
|
+
let c = 0;
|
|
1088
|
+
for (const p of _aiopsgovPsV2.values())
|
|
1089
|
+
if (p.owner === owner && p.status === AIOPSGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
1090
|
+
c++;
|
|
1091
|
+
return c;
|
|
1092
|
+
}
|
|
1093
|
+
function _aiopsgovCountPending(profileId) {
|
|
1094
|
+
let c = 0;
|
|
1095
|
+
for (const j of _aiopsgovJsV2.values())
|
|
1096
|
+
if (
|
|
1097
|
+
j.profileId === profileId &&
|
|
1098
|
+
(j.status === AIOPSGOV_INCIDENT_LIFECYCLE_V2.QUEUED ||
|
|
1099
|
+
j.status === AIOPSGOV_INCIDENT_LIFECYCLE_V2.TRIAGING)
|
|
1100
|
+
)
|
|
1101
|
+
c++;
|
|
1102
|
+
return c;
|
|
1103
|
+
}
|
|
1104
|
+
export function setMaxActiveAiopsgovProfilesPerOwnerV2(n) {
|
|
1105
|
+
_aiopsgovMaxActive = _aiopsgovPos(n, "maxActiveAiopsgovProfilesPerOwner");
|
|
1106
|
+
}
|
|
1107
|
+
export function getMaxActiveAiopsgovProfilesPerOwnerV2() {
|
|
1108
|
+
return _aiopsgovMaxActive;
|
|
1109
|
+
}
|
|
1110
|
+
export function setMaxPendingAiopsgovIncidentsPerProfileV2(n) {
|
|
1111
|
+
_aiopsgovMaxPending = _aiopsgovPos(
|
|
1112
|
+
n,
|
|
1113
|
+
"maxPendingAiopsgovIncidentsPerProfile",
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
export function getMaxPendingAiopsgovIncidentsPerProfileV2() {
|
|
1117
|
+
return _aiopsgovMaxPending;
|
|
1118
|
+
}
|
|
1119
|
+
export function setAiopsgovProfileIdleMsV2(n) {
|
|
1120
|
+
_aiopsgovIdleMs = _aiopsgovPos(n, "aiopsgovProfileIdleMs");
|
|
1121
|
+
}
|
|
1122
|
+
export function getAiopsgovProfileIdleMsV2() {
|
|
1123
|
+
return _aiopsgovIdleMs;
|
|
1124
|
+
}
|
|
1125
|
+
export function setAiopsgovIncidentStuckMsV2(n) {
|
|
1126
|
+
_aiopsgovStuckMs = _aiopsgovPos(n, "aiopsgovIncidentStuckMs");
|
|
1127
|
+
}
|
|
1128
|
+
export function getAiopsgovIncidentStuckMsV2() {
|
|
1129
|
+
return _aiopsgovStuckMs;
|
|
1130
|
+
}
|
|
1131
|
+
export function _resetStateAiopsGovV2() {
|
|
1132
|
+
_aiopsgovPsV2.clear();
|
|
1133
|
+
_aiopsgovJsV2.clear();
|
|
1134
|
+
_aiopsgovMaxActive = 6;
|
|
1135
|
+
_aiopsgovMaxPending = 15;
|
|
1136
|
+
_aiopsgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1137
|
+
_aiopsgovStuckMs = 60 * 1000;
|
|
1138
|
+
}
|
|
1139
|
+
export function registerAiopsgovProfileV2({ id, owner, mode, metadata } = {}) {
|
|
1140
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1141
|
+
if (_aiopsgovPsV2.has(id))
|
|
1142
|
+
throw new Error(`aiopsgov profile ${id} already exists`);
|
|
1143
|
+
const now = Date.now();
|
|
1144
|
+
const p = {
|
|
1145
|
+
id,
|
|
1146
|
+
owner,
|
|
1147
|
+
mode: mode || "monitor",
|
|
1148
|
+
status: AIOPSGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1149
|
+
createdAt: now,
|
|
1150
|
+
updatedAt: now,
|
|
1151
|
+
lastTouchedAt: now,
|
|
1152
|
+
activatedAt: null,
|
|
1153
|
+
archivedAt: null,
|
|
1154
|
+
metadata: { ...(metadata || {}) },
|
|
1155
|
+
};
|
|
1156
|
+
_aiopsgovPsV2.set(id, p);
|
|
1157
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1158
|
+
}
|
|
1159
|
+
export function activateAiopsgovProfileV2(id) {
|
|
1160
|
+
const p = _aiopsgovPsV2.get(id);
|
|
1161
|
+
if (!p) throw new Error(`aiopsgov profile ${id} not found`);
|
|
1162
|
+
const isInitial = p.status === AIOPSGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1163
|
+
_aiopsgovCheckP(p.status, AIOPSGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1164
|
+
if (isInitial && _aiopsgovCountActive(p.owner) >= _aiopsgovMaxActive)
|
|
1165
|
+
throw new Error(
|
|
1166
|
+
`max active aiopsgov profiles for owner ${p.owner} reached`,
|
|
1167
|
+
);
|
|
1168
|
+
const now = Date.now();
|
|
1169
|
+
p.status = AIOPSGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1170
|
+
p.updatedAt = now;
|
|
1171
|
+
p.lastTouchedAt = now;
|
|
1172
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1173
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1174
|
+
}
|
|
1175
|
+
export function staleAiopsgovProfileV2(id) {
|
|
1176
|
+
const p = _aiopsgovPsV2.get(id);
|
|
1177
|
+
if (!p) throw new Error(`aiopsgov profile ${id} not found`);
|
|
1178
|
+
_aiopsgovCheckP(p.status, AIOPSGOV_PROFILE_MATURITY_V2.STALE);
|
|
1179
|
+
p.status = AIOPSGOV_PROFILE_MATURITY_V2.STALE;
|
|
1180
|
+
p.updatedAt = Date.now();
|
|
1181
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1182
|
+
}
|
|
1183
|
+
export function archiveAiopsgovProfileV2(id) {
|
|
1184
|
+
const p = _aiopsgovPsV2.get(id);
|
|
1185
|
+
if (!p) throw new Error(`aiopsgov profile ${id} not found`);
|
|
1186
|
+
_aiopsgovCheckP(p.status, AIOPSGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1187
|
+
const now = Date.now();
|
|
1188
|
+
p.status = AIOPSGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1189
|
+
p.updatedAt = now;
|
|
1190
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1191
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1192
|
+
}
|
|
1193
|
+
export function touchAiopsgovProfileV2(id) {
|
|
1194
|
+
const p = _aiopsgovPsV2.get(id);
|
|
1195
|
+
if (!p) throw new Error(`aiopsgov profile ${id} not found`);
|
|
1196
|
+
if (_aiopsgovPTerminal.has(p.status))
|
|
1197
|
+
throw new Error(`cannot touch terminal aiopsgov profile ${id}`);
|
|
1198
|
+
const now = Date.now();
|
|
1199
|
+
p.lastTouchedAt = now;
|
|
1200
|
+
p.updatedAt = now;
|
|
1201
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1202
|
+
}
|
|
1203
|
+
export function getAiopsgovProfileV2(id) {
|
|
1204
|
+
const p = _aiopsgovPsV2.get(id);
|
|
1205
|
+
if (!p) return null;
|
|
1206
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1207
|
+
}
|
|
1208
|
+
export function listAiopsgovProfilesV2() {
|
|
1209
|
+
return [..._aiopsgovPsV2.values()].map((p) => ({
|
|
1210
|
+
...p,
|
|
1211
|
+
metadata: { ...p.metadata },
|
|
1212
|
+
}));
|
|
1213
|
+
}
|
|
1214
|
+
export function createAiopsgovIncidentV2({
|
|
1215
|
+
id,
|
|
1216
|
+
profileId,
|
|
1217
|
+
summary,
|
|
1218
|
+
metadata,
|
|
1219
|
+
} = {}) {
|
|
1220
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1221
|
+
if (_aiopsgovJsV2.has(id))
|
|
1222
|
+
throw new Error(`aiopsgov incident ${id} already exists`);
|
|
1223
|
+
if (!_aiopsgovPsV2.has(profileId))
|
|
1224
|
+
throw new Error(`aiopsgov profile ${profileId} not found`);
|
|
1225
|
+
if (_aiopsgovCountPending(profileId) >= _aiopsgovMaxPending)
|
|
1226
|
+
throw new Error(
|
|
1227
|
+
`max pending aiopsgov incidents for profile ${profileId} reached`,
|
|
1228
|
+
);
|
|
1229
|
+
const now = Date.now();
|
|
1230
|
+
const j = {
|
|
1231
|
+
id,
|
|
1232
|
+
profileId,
|
|
1233
|
+
summary: summary || "",
|
|
1234
|
+
status: AIOPSGOV_INCIDENT_LIFECYCLE_V2.QUEUED,
|
|
1235
|
+
createdAt: now,
|
|
1236
|
+
updatedAt: now,
|
|
1237
|
+
startedAt: null,
|
|
1238
|
+
settledAt: null,
|
|
1239
|
+
metadata: { ...(metadata || {}) },
|
|
1240
|
+
};
|
|
1241
|
+
_aiopsgovJsV2.set(id, j);
|
|
1242
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1243
|
+
}
|
|
1244
|
+
export function triagingAiopsgovIncidentV2(id) {
|
|
1245
|
+
const j = _aiopsgovJsV2.get(id);
|
|
1246
|
+
if (!j) throw new Error(`aiopsgov incident ${id} not found`);
|
|
1247
|
+
_aiopsgovCheckJ(j.status, AIOPSGOV_INCIDENT_LIFECYCLE_V2.TRIAGING);
|
|
1248
|
+
const now = Date.now();
|
|
1249
|
+
j.status = AIOPSGOV_INCIDENT_LIFECYCLE_V2.TRIAGING;
|
|
1250
|
+
j.updatedAt = now;
|
|
1251
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1252
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1253
|
+
}
|
|
1254
|
+
export function completeIncidentAiopsgovV2(id) {
|
|
1255
|
+
const j = _aiopsgovJsV2.get(id);
|
|
1256
|
+
if (!j) throw new Error(`aiopsgov incident ${id} not found`);
|
|
1257
|
+
_aiopsgovCheckJ(j.status, AIOPSGOV_INCIDENT_LIFECYCLE_V2.TRIAGED);
|
|
1258
|
+
const now = Date.now();
|
|
1259
|
+
j.status = AIOPSGOV_INCIDENT_LIFECYCLE_V2.TRIAGED;
|
|
1260
|
+
j.updatedAt = now;
|
|
1261
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1262
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1263
|
+
}
|
|
1264
|
+
export function failAiopsgovIncidentV2(id, reason) {
|
|
1265
|
+
const j = _aiopsgovJsV2.get(id);
|
|
1266
|
+
if (!j) throw new Error(`aiopsgov incident ${id} not found`);
|
|
1267
|
+
_aiopsgovCheckJ(j.status, AIOPSGOV_INCIDENT_LIFECYCLE_V2.FAILED);
|
|
1268
|
+
const now = Date.now();
|
|
1269
|
+
j.status = AIOPSGOV_INCIDENT_LIFECYCLE_V2.FAILED;
|
|
1270
|
+
j.updatedAt = now;
|
|
1271
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1272
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1273
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1274
|
+
}
|
|
1275
|
+
export function cancelAiopsgovIncidentV2(id, reason) {
|
|
1276
|
+
const j = _aiopsgovJsV2.get(id);
|
|
1277
|
+
if (!j) throw new Error(`aiopsgov incident ${id} not found`);
|
|
1278
|
+
_aiopsgovCheckJ(j.status, AIOPSGOV_INCIDENT_LIFECYCLE_V2.CANCELLED);
|
|
1279
|
+
const now = Date.now();
|
|
1280
|
+
j.status = AIOPSGOV_INCIDENT_LIFECYCLE_V2.CANCELLED;
|
|
1281
|
+
j.updatedAt = now;
|
|
1282
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1283
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1284
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1285
|
+
}
|
|
1286
|
+
export function getAiopsgovIncidentV2(id) {
|
|
1287
|
+
const j = _aiopsgovJsV2.get(id);
|
|
1288
|
+
if (!j) return null;
|
|
1289
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1290
|
+
}
|
|
1291
|
+
export function listAiopsgovIncidentsV2() {
|
|
1292
|
+
return [..._aiopsgovJsV2.values()].map((j) => ({
|
|
1293
|
+
...j,
|
|
1294
|
+
metadata: { ...j.metadata },
|
|
1295
|
+
}));
|
|
1296
|
+
}
|
|
1297
|
+
export function autoStaleIdleAiopsgovProfilesV2({ now } = {}) {
|
|
1298
|
+
const t = now ?? Date.now();
|
|
1299
|
+
const flipped = [];
|
|
1300
|
+
for (const p of _aiopsgovPsV2.values())
|
|
1301
|
+
if (
|
|
1302
|
+
p.status === AIOPSGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1303
|
+
t - p.lastTouchedAt >= _aiopsgovIdleMs
|
|
1304
|
+
) {
|
|
1305
|
+
p.status = AIOPSGOV_PROFILE_MATURITY_V2.STALE;
|
|
1306
|
+
p.updatedAt = t;
|
|
1307
|
+
flipped.push(p.id);
|
|
1308
|
+
}
|
|
1309
|
+
return { flipped, count: flipped.length };
|
|
1310
|
+
}
|
|
1311
|
+
export function autoFailStuckAiopsgovIncidentsV2({ now } = {}) {
|
|
1312
|
+
const t = now ?? Date.now();
|
|
1313
|
+
const flipped = [];
|
|
1314
|
+
for (const j of _aiopsgovJsV2.values())
|
|
1315
|
+
if (
|
|
1316
|
+
j.status === AIOPSGOV_INCIDENT_LIFECYCLE_V2.TRIAGING &&
|
|
1317
|
+
j.startedAt != null &&
|
|
1318
|
+
t - j.startedAt >= _aiopsgovStuckMs
|
|
1319
|
+
) {
|
|
1320
|
+
j.status = AIOPSGOV_INCIDENT_LIFECYCLE_V2.FAILED;
|
|
1321
|
+
j.updatedAt = t;
|
|
1322
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1323
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1324
|
+
flipped.push(j.id);
|
|
1325
|
+
}
|
|
1326
|
+
return { flipped, count: flipped.length };
|
|
1327
|
+
}
|
|
1328
|
+
export function getAiopsGovStatsV2() {
|
|
1329
|
+
const profilesByStatus = {};
|
|
1330
|
+
for (const v of Object.values(AIOPSGOV_PROFILE_MATURITY_V2))
|
|
1331
|
+
profilesByStatus[v] = 0;
|
|
1332
|
+
for (const p of _aiopsgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1333
|
+
const incidentsByStatus = {};
|
|
1334
|
+
for (const v of Object.values(AIOPSGOV_INCIDENT_LIFECYCLE_V2))
|
|
1335
|
+
incidentsByStatus[v] = 0;
|
|
1336
|
+
for (const j of _aiopsgovJsV2.values()) incidentsByStatus[j.status]++;
|
|
1337
|
+
return {
|
|
1338
|
+
totalAiopsgovProfilesV2: _aiopsgovPsV2.size,
|
|
1339
|
+
totalAiopsgovIncidentsV2: _aiopsgovJsV2.size,
|
|
1340
|
+
maxActiveAiopsgovProfilesPerOwner: _aiopsgovMaxActive,
|
|
1341
|
+
maxPendingAiopsgovIncidentsPerProfile: _aiopsgovMaxPending,
|
|
1342
|
+
aiopsgovProfileIdleMs: _aiopsgovIdleMs,
|
|
1343
|
+
aiopsgovIncidentStuckMs: _aiopsgovStuckMs,
|
|
1344
|
+
profilesByStatus,
|
|
1345
|
+
incidentsByStatus,
|
|
1346
|
+
};
|
|
1347
|
+
}
|