chainlesschain 0.143.0 → 0.145.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 +157 -27
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/bi.js +152 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +190 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/compliance.js +414 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +580 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dlp.js +172 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +182 -27
- package/src/commands/fflag.js +74 -22
- package/src/commands/git.js +177 -37
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +179 -27
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/nostr.js +178 -27
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/recommend.js +177 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/sandbox.js +206 -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/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +157 -32
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/topiccls.js +146 -33
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/webfetch.js +141 -32
- package/src/commands/zkp.js +184 -28
- package/src/index.js +40 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +288 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/bi-engine.js +283 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +296 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -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-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -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/dlp-engine.js +287 -49
- package/src/lib/evolution-system.js +278 -47
- 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/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/inference-network.js +308 -51
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/matrix-bridge.js +281 -47
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/nostr-bridge.js +286 -49
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perf-tuning.js +309 -50
- 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/privacy-computing.js +335 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/sandbox-v2.js +327 -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-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-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/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/zkp-engine.js +286 -49
package/src/lib/social-graph.js
CHANGED
|
@@ -409,81 +409,304 @@ export function _resetState() {
|
|
|
409
409
|
|
|
410
410
|
// ===== V2 Surface: Social Graph governance overlay (CLI v0.141.0) =====
|
|
411
411
|
export const SG_NODE_MATURITY_V2 = Object.freeze({
|
|
412
|
-
PENDING: "pending",
|
|
412
|
+
PENDING: "pending",
|
|
413
|
+
ACTIVE: "active",
|
|
414
|
+
INACTIVE: "inactive",
|
|
415
|
+
REMOVED: "removed",
|
|
413
416
|
});
|
|
414
417
|
export const SG_EDGE_LIFECYCLE_V2 = Object.freeze({
|
|
415
|
-
PROPOSED: "proposed",
|
|
418
|
+
PROPOSED: "proposed",
|
|
419
|
+
ESTABLISHED: "established",
|
|
420
|
+
SEVERED: "severed",
|
|
421
|
+
EXPIRED: "expired",
|
|
422
|
+
CANCELLED: "cancelled",
|
|
416
423
|
});
|
|
417
424
|
const _sgNTrans = new Map([
|
|
418
|
-
[
|
|
419
|
-
|
|
420
|
-
|
|
425
|
+
[
|
|
426
|
+
SG_NODE_MATURITY_V2.PENDING,
|
|
427
|
+
new Set([SG_NODE_MATURITY_V2.ACTIVE, SG_NODE_MATURITY_V2.REMOVED]),
|
|
428
|
+
],
|
|
429
|
+
[
|
|
430
|
+
SG_NODE_MATURITY_V2.ACTIVE,
|
|
431
|
+
new Set([SG_NODE_MATURITY_V2.INACTIVE, SG_NODE_MATURITY_V2.REMOVED]),
|
|
432
|
+
],
|
|
433
|
+
[
|
|
434
|
+
SG_NODE_MATURITY_V2.INACTIVE,
|
|
435
|
+
new Set([SG_NODE_MATURITY_V2.ACTIVE, SG_NODE_MATURITY_V2.REMOVED]),
|
|
436
|
+
],
|
|
421
437
|
[SG_NODE_MATURITY_V2.REMOVED, new Set()],
|
|
422
438
|
]);
|
|
423
439
|
const _sgNTerminal = new Set([SG_NODE_MATURITY_V2.REMOVED]);
|
|
424
440
|
const _sgETrans = new Map([
|
|
425
|
-
[
|
|
426
|
-
|
|
441
|
+
[
|
|
442
|
+
SG_EDGE_LIFECYCLE_V2.PROPOSED,
|
|
443
|
+
new Set([SG_EDGE_LIFECYCLE_V2.ESTABLISHED, SG_EDGE_LIFECYCLE_V2.CANCELLED]),
|
|
444
|
+
],
|
|
445
|
+
[
|
|
446
|
+
SG_EDGE_LIFECYCLE_V2.ESTABLISHED,
|
|
447
|
+
new Set([SG_EDGE_LIFECYCLE_V2.SEVERED, SG_EDGE_LIFECYCLE_V2.EXPIRED]),
|
|
448
|
+
],
|
|
427
449
|
[SG_EDGE_LIFECYCLE_V2.SEVERED, new Set()],
|
|
428
450
|
[SG_EDGE_LIFECYCLE_V2.EXPIRED, new Set()],
|
|
429
451
|
[SG_EDGE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
430
452
|
]);
|
|
431
453
|
const _sgNsV2 = new Map();
|
|
432
454
|
const _sgEsV2 = new Map();
|
|
433
|
-
let _sgMaxActivePerOwner = 50,
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
455
|
+
let _sgMaxActivePerOwner = 50,
|
|
456
|
+
_sgMaxPendingEdgesPerNode = 100,
|
|
457
|
+
_sgIdleMs = 60 * 24 * 60 * 60 * 1000,
|
|
458
|
+
_sgStuckMs = 14 * 24 * 60 * 60 * 1000;
|
|
459
|
+
function _sgPos(n, label) {
|
|
460
|
+
const v = Math.floor(Number(n));
|
|
461
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
462
|
+
throw new Error(`${label} must be positive integer`);
|
|
463
|
+
return v;
|
|
464
|
+
}
|
|
465
|
+
function _sgCheckN(from, to) {
|
|
466
|
+
const a = _sgNTrans.get(from);
|
|
467
|
+
if (!a || !a.has(to))
|
|
468
|
+
throw new Error(`invalid sg node transition ${from} → ${to}`);
|
|
469
|
+
}
|
|
470
|
+
function _sgCheckE(from, to) {
|
|
471
|
+
const a = _sgETrans.get(from);
|
|
472
|
+
if (!a || !a.has(to))
|
|
473
|
+
throw new Error(`invalid sg edge transition ${from} → ${to}`);
|
|
474
|
+
}
|
|
475
|
+
export function setMaxActiveSgNodesPerOwnerV2(n) {
|
|
476
|
+
_sgMaxActivePerOwner = _sgPos(n, "maxActiveSgNodesPerOwner");
|
|
477
|
+
}
|
|
478
|
+
export function getMaxActiveSgNodesPerOwnerV2() {
|
|
479
|
+
return _sgMaxActivePerOwner;
|
|
480
|
+
}
|
|
481
|
+
export function setMaxPendingSgEdgesPerNodeV2(n) {
|
|
482
|
+
_sgMaxPendingEdgesPerNode = _sgPos(n, "maxPendingSgEdgesPerNode");
|
|
483
|
+
}
|
|
484
|
+
export function getMaxPendingSgEdgesPerNodeV2() {
|
|
485
|
+
return _sgMaxPendingEdgesPerNode;
|
|
486
|
+
}
|
|
487
|
+
export function setSgNodeIdleMsV2(n) {
|
|
488
|
+
_sgIdleMs = _sgPos(n, "sgNodeIdleMs");
|
|
489
|
+
}
|
|
490
|
+
export function getSgNodeIdleMsV2() {
|
|
491
|
+
return _sgIdleMs;
|
|
492
|
+
}
|
|
493
|
+
export function setSgEdgeStuckMsV2(n) {
|
|
494
|
+
_sgStuckMs = _sgPos(n, "sgEdgeStuckMs");
|
|
495
|
+
}
|
|
496
|
+
export function getSgEdgeStuckMsV2() {
|
|
497
|
+
return _sgStuckMs;
|
|
498
|
+
}
|
|
499
|
+
export function _resetStateSocialGraphV2() {
|
|
500
|
+
_sgNsV2.clear();
|
|
501
|
+
_sgEsV2.clear();
|
|
502
|
+
_sgMaxActivePerOwner = 50;
|
|
503
|
+
_sgMaxPendingEdgesPerNode = 100;
|
|
504
|
+
_sgIdleMs = 60 * 24 * 60 * 60 * 1000;
|
|
505
|
+
_sgStuckMs = 14 * 24 * 60 * 60 * 1000;
|
|
506
|
+
}
|
|
446
507
|
export function registerSgNodeV2({ id, owner, handle, metadata } = {}) {
|
|
447
|
-
if (!id) throw new Error("sg node id required");
|
|
508
|
+
if (!id) throw new Error("sg node id required");
|
|
509
|
+
if (!owner) throw new Error("sg node owner required");
|
|
448
510
|
if (_sgNsV2.has(id)) throw new Error(`sg node ${id} already registered`);
|
|
449
511
|
const now = Date.now();
|
|
450
|
-
const n = {
|
|
451
|
-
|
|
512
|
+
const n = {
|
|
513
|
+
id,
|
|
514
|
+
owner,
|
|
515
|
+
handle: handle || id,
|
|
516
|
+
status: SG_NODE_MATURITY_V2.PENDING,
|
|
517
|
+
createdAt: now,
|
|
518
|
+
updatedAt: now,
|
|
519
|
+
activatedAt: null,
|
|
520
|
+
removedAt: null,
|
|
521
|
+
lastTouchedAt: now,
|
|
522
|
+
metadata: { ...(metadata || {}) },
|
|
523
|
+
};
|
|
524
|
+
_sgNsV2.set(id, n);
|
|
525
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
526
|
+
}
|
|
527
|
+
function _sgCountActive(owner) {
|
|
528
|
+
let n = 0;
|
|
529
|
+
for (const v of _sgNsV2.values())
|
|
530
|
+
if (v.owner === owner && v.status === SG_NODE_MATURITY_V2.ACTIVE) n++;
|
|
531
|
+
return n;
|
|
452
532
|
}
|
|
453
|
-
function _sgCountActive(owner) { let n = 0; for (const v of _sgNsV2.values()) if (v.owner === owner && v.status === SG_NODE_MATURITY_V2.ACTIVE) n++; return n; }
|
|
454
533
|
export function activateSgNodeV2(id) {
|
|
455
|
-
const n = _sgNsV2.get(id);
|
|
534
|
+
const n = _sgNsV2.get(id);
|
|
535
|
+
if (!n) throw new Error(`sg node ${id} not found`);
|
|
456
536
|
_sgCheckN(n.status, SG_NODE_MATURITY_V2.ACTIVE);
|
|
457
537
|
const recovery = n.status === SG_NODE_MATURITY_V2.INACTIVE;
|
|
458
|
-
if (!recovery && _sgCountActive(n.owner) >= _sgMaxActivePerOwner)
|
|
459
|
-
|
|
538
|
+
if (!recovery && _sgCountActive(n.owner) >= _sgMaxActivePerOwner)
|
|
539
|
+
throw new Error(`max active sg nodes for owner ${n.owner} reached`);
|
|
540
|
+
const now = Date.now();
|
|
541
|
+
n.status = SG_NODE_MATURITY_V2.ACTIVE;
|
|
542
|
+
n.updatedAt = now;
|
|
543
|
+
n.lastTouchedAt = now;
|
|
544
|
+
if (!n.activatedAt) n.activatedAt = now;
|
|
545
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
546
|
+
}
|
|
547
|
+
export function deactivateSgNodeV2(id) {
|
|
548
|
+
const n = _sgNsV2.get(id);
|
|
549
|
+
if (!n) throw new Error(`sg node ${id} not found`);
|
|
550
|
+
_sgCheckN(n.status, SG_NODE_MATURITY_V2.INACTIVE);
|
|
551
|
+
n.status = SG_NODE_MATURITY_V2.INACTIVE;
|
|
552
|
+
n.updatedAt = Date.now();
|
|
553
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
554
|
+
}
|
|
555
|
+
export function removeSgNodeV2(id) {
|
|
556
|
+
const n = _sgNsV2.get(id);
|
|
557
|
+
if (!n) throw new Error(`sg node ${id} not found`);
|
|
558
|
+
_sgCheckN(n.status, SG_NODE_MATURITY_V2.REMOVED);
|
|
559
|
+
const now = Date.now();
|
|
560
|
+
n.status = SG_NODE_MATURITY_V2.REMOVED;
|
|
561
|
+
n.updatedAt = now;
|
|
562
|
+
if (!n.removedAt) n.removedAt = now;
|
|
563
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
564
|
+
}
|
|
565
|
+
export function touchSgNodeV2(id) {
|
|
566
|
+
const n = _sgNsV2.get(id);
|
|
567
|
+
if (!n) throw new Error(`sg node ${id} not found`);
|
|
568
|
+
if (_sgNTerminal.has(n.status))
|
|
569
|
+
throw new Error(`cannot touch terminal sg node ${id}`);
|
|
570
|
+
const now = Date.now();
|
|
571
|
+
n.lastTouchedAt = now;
|
|
572
|
+
n.updatedAt = now;
|
|
573
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
574
|
+
}
|
|
575
|
+
export function getSgNodeV2(id) {
|
|
576
|
+
const n = _sgNsV2.get(id);
|
|
577
|
+
if (!n) return null;
|
|
460
578
|
return { ...n, metadata: { ...n.metadata } };
|
|
461
579
|
}
|
|
462
|
-
export function
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
580
|
+
export function listSgNodesV2() {
|
|
581
|
+
return [..._sgNsV2.values()].map((n) => ({
|
|
582
|
+
...n,
|
|
583
|
+
metadata: { ...n.metadata },
|
|
584
|
+
}));
|
|
585
|
+
}
|
|
586
|
+
function _sgCountPending(nodeId) {
|
|
587
|
+
let n = 0;
|
|
588
|
+
for (const e of _sgEsV2.values())
|
|
589
|
+
if (e.nodeId === nodeId && e.status === SG_EDGE_LIFECYCLE_V2.PROPOSED) n++;
|
|
590
|
+
return n;
|
|
591
|
+
}
|
|
468
592
|
export function createSgEdgeV2({ id, nodeId, targetId, metadata } = {}) {
|
|
469
|
-
if (!id) throw new Error("sg edge id required");
|
|
593
|
+
if (!id) throw new Error("sg edge id required");
|
|
594
|
+
if (!nodeId) throw new Error("sg edge nodeId required");
|
|
470
595
|
if (_sgEsV2.has(id)) throw new Error(`sg edge ${id} already exists`);
|
|
471
596
|
if (!_sgNsV2.has(nodeId)) throw new Error(`sg node ${nodeId} not found`);
|
|
472
|
-
if (_sgCountPending(nodeId) >= _sgMaxPendingEdgesPerNode)
|
|
597
|
+
if (_sgCountPending(nodeId) >= _sgMaxPendingEdgesPerNode)
|
|
598
|
+
throw new Error(`max pending sg edges for node ${nodeId} reached`);
|
|
599
|
+
const now = Date.now();
|
|
600
|
+
const e = {
|
|
601
|
+
id,
|
|
602
|
+
nodeId,
|
|
603
|
+
targetId: targetId || "",
|
|
604
|
+
status: SG_EDGE_LIFECYCLE_V2.PROPOSED,
|
|
605
|
+
createdAt: now,
|
|
606
|
+
updatedAt: now,
|
|
607
|
+
startedAt: now,
|
|
608
|
+
settledAt: null,
|
|
609
|
+
metadata: { ...(metadata || {}) },
|
|
610
|
+
};
|
|
611
|
+
_sgEsV2.set(id, e);
|
|
612
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
613
|
+
}
|
|
614
|
+
export function establishSgEdgeV2(id) {
|
|
615
|
+
const e = _sgEsV2.get(id);
|
|
616
|
+
if (!e) throw new Error(`sg edge ${id} not found`);
|
|
617
|
+
_sgCheckE(e.status, SG_EDGE_LIFECYCLE_V2.ESTABLISHED);
|
|
618
|
+
const now = Date.now();
|
|
619
|
+
e.status = SG_EDGE_LIFECYCLE_V2.ESTABLISHED;
|
|
620
|
+
e.updatedAt = now;
|
|
621
|
+
if (!e.settledAt) e.settledAt = now;
|
|
622
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
623
|
+
}
|
|
624
|
+
export function severSgEdgeV2(id, reason) {
|
|
625
|
+
const e = _sgEsV2.get(id);
|
|
626
|
+
if (!e) throw new Error(`sg edge ${id} not found`);
|
|
627
|
+
_sgCheckE(e.status, SG_EDGE_LIFECYCLE_V2.SEVERED);
|
|
628
|
+
const now = Date.now();
|
|
629
|
+
e.status = SG_EDGE_LIFECYCLE_V2.SEVERED;
|
|
630
|
+
e.updatedAt = now;
|
|
631
|
+
if (reason) e.metadata.severReason = String(reason);
|
|
632
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
633
|
+
}
|
|
634
|
+
export function expireSgEdgeV2(id) {
|
|
635
|
+
const e = _sgEsV2.get(id);
|
|
636
|
+
if (!e) throw new Error(`sg edge ${id} not found`);
|
|
637
|
+
_sgCheckE(e.status, SG_EDGE_LIFECYCLE_V2.EXPIRED);
|
|
638
|
+
const now = Date.now();
|
|
639
|
+
e.status = SG_EDGE_LIFECYCLE_V2.EXPIRED;
|
|
640
|
+
e.updatedAt = now;
|
|
641
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
642
|
+
}
|
|
643
|
+
export function cancelSgEdgeV2(id, reason) {
|
|
644
|
+
const e = _sgEsV2.get(id);
|
|
645
|
+
if (!e) throw new Error(`sg edge ${id} not found`);
|
|
646
|
+
_sgCheckE(e.status, SG_EDGE_LIFECYCLE_V2.CANCELLED);
|
|
473
647
|
const now = Date.now();
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
export function
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
648
|
+
e.status = SG_EDGE_LIFECYCLE_V2.CANCELLED;
|
|
649
|
+
e.updatedAt = now;
|
|
650
|
+
if (!e.settledAt) e.settledAt = now;
|
|
651
|
+
if (reason) e.metadata.cancelReason = String(reason);
|
|
652
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
653
|
+
}
|
|
654
|
+
export function getSgEdgeV2(id) {
|
|
655
|
+
const e = _sgEsV2.get(id);
|
|
656
|
+
if (!e) return null;
|
|
657
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
658
|
+
}
|
|
659
|
+
export function listSgEdgesV2() {
|
|
660
|
+
return [..._sgEsV2.values()].map((e) => ({
|
|
661
|
+
...e,
|
|
662
|
+
metadata: { ...e.metadata },
|
|
663
|
+
}));
|
|
664
|
+
}
|
|
665
|
+
export function autoDeactivateIdleSgNodesV2({ now } = {}) {
|
|
666
|
+
const t = now ?? Date.now();
|
|
667
|
+
const flipped = [];
|
|
668
|
+
for (const n of _sgNsV2.values())
|
|
669
|
+
if (
|
|
670
|
+
n.status === SG_NODE_MATURITY_V2.ACTIVE &&
|
|
671
|
+
t - n.lastTouchedAt >= _sgIdleMs
|
|
672
|
+
) {
|
|
673
|
+
n.status = SG_NODE_MATURITY_V2.INACTIVE;
|
|
674
|
+
n.updatedAt = t;
|
|
675
|
+
flipped.push(n.id);
|
|
676
|
+
}
|
|
677
|
+
return { flipped, count: flipped.length };
|
|
678
|
+
}
|
|
679
|
+
export function autoExpireStaleSgEdgesV2({ now } = {}) {
|
|
680
|
+
const t = now ?? Date.now();
|
|
681
|
+
const flipped = [];
|
|
682
|
+
for (const e of _sgEsV2.values())
|
|
683
|
+
if (
|
|
684
|
+
e.status === SG_EDGE_LIFECYCLE_V2.PROPOSED &&
|
|
685
|
+
t - e.startedAt >= _sgStuckMs
|
|
686
|
+
) {
|
|
687
|
+
e.status = SG_EDGE_LIFECYCLE_V2.CANCELLED;
|
|
688
|
+
e.updatedAt = t;
|
|
689
|
+
if (!e.settledAt) e.settledAt = t;
|
|
690
|
+
e.metadata.cancelReason = "auto-cancel-stale";
|
|
691
|
+
flipped.push(e.id);
|
|
692
|
+
}
|
|
693
|
+
return { flipped, count: flipped.length };
|
|
694
|
+
}
|
|
485
695
|
export function getSocialGraphGovStatsV2() {
|
|
486
|
-
const nodesByStatus = {};
|
|
487
|
-
|
|
488
|
-
|
|
696
|
+
const nodesByStatus = {};
|
|
697
|
+
for (const v of Object.values(SG_NODE_MATURITY_V2)) nodesByStatus[v] = 0;
|
|
698
|
+
for (const n of _sgNsV2.values()) nodesByStatus[n.status]++;
|
|
699
|
+
const edgesByStatus = {};
|
|
700
|
+
for (const v of Object.values(SG_EDGE_LIFECYCLE_V2)) edgesByStatus[v] = 0;
|
|
701
|
+
for (const e of _sgEsV2.values()) edgesByStatus[e.status]++;
|
|
702
|
+
return {
|
|
703
|
+
totalSgNodesV2: _sgNsV2.size,
|
|
704
|
+
totalSgEdgesV2: _sgEsV2.size,
|
|
705
|
+
maxActiveSgNodesPerOwner: _sgMaxActivePerOwner,
|
|
706
|
+
maxPendingSgEdgesPerNode: _sgMaxPendingEdgesPerNode,
|
|
707
|
+
sgNodeIdleMs: _sgIdleMs,
|
|
708
|
+
sgEdgeStuckMs: _sgStuckMs,
|
|
709
|
+
nodesByStatus,
|
|
710
|
+
edgesByStatus,
|
|
711
|
+
};
|
|
489
712
|
}
|