chainlesschain 0.66.0 → 0.132.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/bin/chainlesschain.js +0 -0
- package/package.json +1 -1
- package/src/commands/a2a.js +380 -0
- package/src/commands/agent-network.js +254 -1
- package/src/commands/audit.js +302 -0
- package/src/commands/automation.js +271 -1
- package/src/commands/bi.js +348 -0
- package/src/commands/codegen.js +224 -0
- package/src/commands/collab.js +341 -0
- package/src/commands/compliance.js +1035 -0
- package/src/commands/cowork.js +221 -0
- package/src/commands/crosschain.js +218 -0
- package/src/commands/dbevo.js +284 -0
- package/src/commands/dev.js +252 -0
- package/src/commands/did.js +358 -0
- package/src/commands/dlp.js +341 -0
- package/src/commands/encrypt.js +341 -0
- package/src/commands/evomap.js +394 -0
- package/src/commands/export.js +256 -1
- package/src/commands/federation.js +283 -0
- package/src/commands/fusion.js +258 -0
- package/src/commands/governance.js +325 -0
- package/src/commands/hardening.js +411 -0
- package/src/commands/hook.js +148 -0
- package/src/commands/import.js +252 -0
- package/src/commands/incentive.js +322 -0
- package/src/commands/inference.js +318 -0
- package/src/commands/infra.js +244 -0
- package/src/commands/instinct.js +260 -0
- package/src/commands/ipfs.js +318 -0
- package/src/commands/kg.js +387 -0
- package/src/commands/llm.js +263 -0
- package/src/commands/lowcode.js +356 -0
- package/src/commands/marketplace.js +256 -0
- package/src/commands/mcp.js +221 -0
- package/src/commands/memory.js +248 -0
- package/src/commands/multimodal.js +296 -0
- package/src/commands/nlprog.js +356 -0
- package/src/commands/note.js +244 -0
- package/src/commands/ops.js +354 -0
- package/src/commands/orchestrate.js +166 -0
- package/src/commands/org.js +277 -0
- package/src/commands/p2p.js +390 -0
- package/src/commands/perception.js +290 -0
- package/src/commands/permmem.js +251 -0
- package/src/commands/plugin-ecosystem.js +273 -0
- package/src/commands/pqc.js +393 -0
- package/src/commands/privacy.js +321 -0
- package/src/commands/quantization.js +351 -0
- package/src/commands/rcache.js +271 -0
- package/src/commands/recommend.js +340 -0
- package/src/commands/reputation.js +261 -0
- package/src/commands/runtime.js +307 -0
- package/src/commands/scim.js +262 -0
- package/src/commands/session.js +258 -0
- package/src/commands/siem.js +246 -0
- package/src/commands/skill.js +267 -1
- package/src/commands/sla.js +259 -0
- package/src/commands/social.js +256 -0
- package/src/commands/sso.js +186 -1
- package/src/commands/stress.js +230 -0
- package/src/commands/sync.js +256 -0
- package/src/commands/tech.js +338 -0
- package/src/commands/tenant.js +351 -0
- package/src/commands/terraform.js +245 -0
- package/src/commands/tokens.js +269 -0
- package/src/commands/trust.js +249 -0
- package/src/commands/wallet.js +277 -0
- package/src/commands/workflow.js +171 -0
- package/src/commands/zkp.js +335 -0
- package/src/index.js +4 -0
- package/src/lib/a2a-protocol.js +451 -0
- package/src/lib/agent-coordinator.js +325 -0
- package/src/lib/agent-network.js +387 -0
- package/src/lib/agent-router.js +395 -0
- package/src/lib/aiops.js +478 -0
- package/src/lib/app-builder.js +239 -0
- package/src/lib/audit-logger.js +379 -0
- package/src/lib/automation-engine.js +330 -0
- package/src/lib/autonomous-developer.js +350 -0
- package/src/lib/bi-engine.js +338 -0
- package/src/lib/code-agent.js +323 -0
- package/src/lib/collaboration-governance.js +364 -0
- package/src/lib/community-governance.js +436 -0
- package/src/lib/compliance-manager.js +434 -0
- package/src/lib/content-recommendation.js +469 -0
- package/src/lib/cross-chain.js +345 -0
- package/src/lib/crypto-manager.js +350 -0
- package/src/lib/dbevo.js +338 -0
- package/src/lib/decentral-infra.js +340 -0
- package/src/lib/did-manager.js +367 -0
- package/src/lib/dlp-engine.js +389 -0
- package/src/lib/evomap-federation.js +177 -0
- package/src/lib/evomap-governance.js +276 -0
- package/src/lib/federation-hardening.js +259 -0
- package/src/lib/hardening-manager.js +348 -0
- package/src/lib/hook-manager.js +380 -0
- package/src/lib/inference-network.js +330 -0
- package/src/lib/instinct-manager.js +332 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +381 -0
- package/src/lib/knowledge-graph.js +432 -0
- package/src/lib/knowledge-importer.js +379 -0
- package/src/lib/llm-providers.js +391 -0
- package/src/lib/mcp-registry.js +333 -0
- package/src/lib/memory-manager.js +330 -0
- package/src/lib/multimodal.js +346 -0
- package/src/lib/nl-programming.js +343 -0
- package/src/lib/note-versioning.js +327 -0
- package/src/lib/org-manager.js +323 -0
- package/src/lib/p2p-manager.js +387 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +4 -1
- package/src/lib/permanent-memory.js +320 -0
- package/src/lib/plugin-ecosystem.js +377 -0
- package/src/lib/pqc-manager.js +368 -0
- package/src/lib/privacy-computing.js +427 -0
- package/src/lib/protocol-fusion.js +417 -0
- package/src/lib/quantization.js +325 -0
- package/src/lib/reputation-optimizer.js +299 -0
- package/src/lib/response-cache.js +327 -0
- package/src/lib/scim-manager.js +329 -0
- package/src/lib/session-manager.js +329 -0
- package/src/lib/siem-exporter.js +333 -0
- package/src/lib/skill-loader.js +377 -0
- package/src/lib/skill-marketplace.js +325 -0
- package/src/lib/sla-manager.js +275 -0
- package/src/lib/social-manager.js +326 -0
- package/src/lib/sso-manager.js +332 -0
- package/src/lib/stress-tester.js +330 -0
- package/src/lib/sync-manager.js +326 -0
- package/src/lib/tech-learning-engine.js +369 -0
- package/src/lib/tenant-saas.js +460 -0
- package/src/lib/terraform-manager.js +363 -0
- package/src/lib/threat-intel.js +335 -0
- package/src/lib/token-incentive.js +293 -0
- package/src/lib/token-tracker.js +329 -0
- package/src/lib/trust-security.js +390 -0
- package/src/lib/ueba.js +389 -0
- package/src/lib/universal-runtime.js +325 -0
- package/src/lib/wallet-manager.js +326 -0
- package/src/lib/workflow-engine.js +322 -0
- package/src/lib/zkp-engine.js +274 -0
|
@@ -533,3 +533,420 @@ export function _resetState() {
|
|
|
533
533
|
_qualityScores.clear();
|
|
534
534
|
_translationCache.clear();
|
|
535
535
|
}
|
|
536
|
+
|
|
537
|
+
/* ── V2 Surface (Phase 72-73) ─────────────────────────────
|
|
538
|
+
* Strictly additive. Two parallel state machines:
|
|
539
|
+
* - Bridge maturity (5 states, retired terminal)
|
|
540
|
+
* - Translation run lifecycle (5 states, 3 terminals)
|
|
541
|
+
* Per-operator active-bridge cap + per-bridge running-translation cap.
|
|
542
|
+
* Auto-flip: idle-bridge → retired; stuck-running translation → failed.
|
|
543
|
+
*/
|
|
544
|
+
|
|
545
|
+
export const BRIDGE_MATURITY_V2 = Object.freeze({
|
|
546
|
+
PROVISIONAL: "provisional",
|
|
547
|
+
ACTIVE: "active",
|
|
548
|
+
DEGRADED: "degraded",
|
|
549
|
+
DEPRECATED: "deprecated",
|
|
550
|
+
RETIRED: "retired",
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
export const TRANSLATION_RUN_V2 = Object.freeze({
|
|
554
|
+
QUEUED: "queued",
|
|
555
|
+
RUNNING: "running",
|
|
556
|
+
SUCCEEDED: "succeeded",
|
|
557
|
+
FAILED: "failed",
|
|
558
|
+
CANCELED: "canceled",
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
const _BRIDGE_TRANSITIONS_V2 = new Map([
|
|
562
|
+
[
|
|
563
|
+
BRIDGE_MATURITY_V2.PROVISIONAL,
|
|
564
|
+
new Set([BRIDGE_MATURITY_V2.ACTIVE, BRIDGE_MATURITY_V2.RETIRED]),
|
|
565
|
+
],
|
|
566
|
+
[
|
|
567
|
+
BRIDGE_MATURITY_V2.ACTIVE,
|
|
568
|
+
new Set([
|
|
569
|
+
BRIDGE_MATURITY_V2.DEGRADED,
|
|
570
|
+
BRIDGE_MATURITY_V2.DEPRECATED,
|
|
571
|
+
BRIDGE_MATURITY_V2.RETIRED,
|
|
572
|
+
]),
|
|
573
|
+
],
|
|
574
|
+
[
|
|
575
|
+
BRIDGE_MATURITY_V2.DEGRADED,
|
|
576
|
+
new Set([
|
|
577
|
+
BRIDGE_MATURITY_V2.ACTIVE,
|
|
578
|
+
BRIDGE_MATURITY_V2.DEPRECATED,
|
|
579
|
+
BRIDGE_MATURITY_V2.RETIRED,
|
|
580
|
+
]),
|
|
581
|
+
],
|
|
582
|
+
[
|
|
583
|
+
BRIDGE_MATURITY_V2.DEPRECATED,
|
|
584
|
+
new Set([BRIDGE_MATURITY_V2.ACTIVE, BRIDGE_MATURITY_V2.RETIRED]),
|
|
585
|
+
],
|
|
586
|
+
]);
|
|
587
|
+
const _BRIDGE_TERMINAL_V2 = new Set([BRIDGE_MATURITY_V2.RETIRED]);
|
|
588
|
+
|
|
589
|
+
const _TRANSLATION_TRANSITIONS_V2 = new Map([
|
|
590
|
+
[
|
|
591
|
+
TRANSLATION_RUN_V2.QUEUED,
|
|
592
|
+
new Set([
|
|
593
|
+
TRANSLATION_RUN_V2.RUNNING,
|
|
594
|
+
TRANSLATION_RUN_V2.CANCELED,
|
|
595
|
+
TRANSLATION_RUN_V2.FAILED,
|
|
596
|
+
]),
|
|
597
|
+
],
|
|
598
|
+
[
|
|
599
|
+
TRANSLATION_RUN_V2.RUNNING,
|
|
600
|
+
new Set([
|
|
601
|
+
TRANSLATION_RUN_V2.SUCCEEDED,
|
|
602
|
+
TRANSLATION_RUN_V2.FAILED,
|
|
603
|
+
TRANSLATION_RUN_V2.CANCELED,
|
|
604
|
+
]),
|
|
605
|
+
],
|
|
606
|
+
]);
|
|
607
|
+
const _TRANSLATION_TERMINAL_V2 = new Set([
|
|
608
|
+
TRANSLATION_RUN_V2.SUCCEEDED,
|
|
609
|
+
TRANSLATION_RUN_V2.FAILED,
|
|
610
|
+
TRANSLATION_RUN_V2.CANCELED,
|
|
611
|
+
]);
|
|
612
|
+
|
|
613
|
+
export const PF_DEFAULT_MAX_ACTIVE_BRIDGES_PER_OPERATOR = 10;
|
|
614
|
+
export const PF_DEFAULT_MAX_RUNNING_TRANSLATIONS_PER_BRIDGE = 5;
|
|
615
|
+
export const PF_DEFAULT_BRIDGE_IDLE_MS = 14 * 86400000;
|
|
616
|
+
export const PF_DEFAULT_TRANSLATION_STUCK_MS = 10 * 60000;
|
|
617
|
+
|
|
618
|
+
let _pfMaxActiveBridgesPerOperator = PF_DEFAULT_MAX_ACTIVE_BRIDGES_PER_OPERATOR;
|
|
619
|
+
let _pfMaxRunningTranslationsPerBridge =
|
|
620
|
+
PF_DEFAULT_MAX_RUNNING_TRANSLATIONS_PER_BRIDGE;
|
|
621
|
+
let _pfBridgeIdleMs = PF_DEFAULT_BRIDGE_IDLE_MS;
|
|
622
|
+
let _pfTranslationStuckMs = PF_DEFAULT_TRANSLATION_STUCK_MS;
|
|
623
|
+
|
|
624
|
+
const _bridgesV2 = new Map();
|
|
625
|
+
const _translationsV2 = new Map();
|
|
626
|
+
|
|
627
|
+
function _positiveIntV2(n, label) {
|
|
628
|
+
const f = Math.floor(n);
|
|
629
|
+
if (!Number.isFinite(f) || f <= 0)
|
|
630
|
+
throw new Error(`${label} must be a positive integer`);
|
|
631
|
+
return f;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
export function getMaxActiveBridgesPerOperator() {
|
|
635
|
+
return _pfMaxActiveBridgesPerOperator;
|
|
636
|
+
}
|
|
637
|
+
export function setMaxActiveBridgesPerOperator(n) {
|
|
638
|
+
_pfMaxActiveBridgesPerOperator = _positiveIntV2(
|
|
639
|
+
n,
|
|
640
|
+
"maxActiveBridgesPerOperator",
|
|
641
|
+
);
|
|
642
|
+
return _pfMaxActiveBridgesPerOperator;
|
|
643
|
+
}
|
|
644
|
+
export function getMaxRunningTranslationsPerBridge() {
|
|
645
|
+
return _pfMaxRunningTranslationsPerBridge;
|
|
646
|
+
}
|
|
647
|
+
export function setMaxRunningTranslationsPerBridge(n) {
|
|
648
|
+
_pfMaxRunningTranslationsPerBridge = _positiveIntV2(
|
|
649
|
+
n,
|
|
650
|
+
"maxRunningTranslationsPerBridge",
|
|
651
|
+
);
|
|
652
|
+
return _pfMaxRunningTranslationsPerBridge;
|
|
653
|
+
}
|
|
654
|
+
export function getBridgeIdleMs() {
|
|
655
|
+
return _pfBridgeIdleMs;
|
|
656
|
+
}
|
|
657
|
+
export function setBridgeIdleMs(n) {
|
|
658
|
+
_pfBridgeIdleMs = _positiveIntV2(n, "bridgeIdleMs");
|
|
659
|
+
return _pfBridgeIdleMs;
|
|
660
|
+
}
|
|
661
|
+
export function getTranslationStuckMs() {
|
|
662
|
+
return _pfTranslationStuckMs;
|
|
663
|
+
}
|
|
664
|
+
export function setTranslationStuckMs(n) {
|
|
665
|
+
_pfTranslationStuckMs = _positiveIntV2(n, "translationStuckMs");
|
|
666
|
+
return _pfTranslationStuckMs;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
export function getActiveBridgeCount(operator) {
|
|
670
|
+
let c = 0;
|
|
671
|
+
for (const b of _bridgesV2.values()) {
|
|
672
|
+
if (b.status === BRIDGE_MATURITY_V2.RETIRED) continue;
|
|
673
|
+
if (b.status === BRIDGE_MATURITY_V2.PROVISIONAL) continue;
|
|
674
|
+
if (operator !== undefined && b.operator !== operator) continue;
|
|
675
|
+
c++;
|
|
676
|
+
}
|
|
677
|
+
return c;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export function getRunningTranslationCount(bridgeId) {
|
|
681
|
+
let c = 0;
|
|
682
|
+
for (const t of _translationsV2.values()) {
|
|
683
|
+
if (t.status !== TRANSLATION_RUN_V2.RUNNING) continue;
|
|
684
|
+
if (bridgeId !== undefined && t.bridgeId !== bridgeId) continue;
|
|
685
|
+
c++;
|
|
686
|
+
}
|
|
687
|
+
return c;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
export function registerBridgeV2({
|
|
691
|
+
id,
|
|
692
|
+
operator,
|
|
693
|
+
sourceProtocol,
|
|
694
|
+
targetProtocol,
|
|
695
|
+
initialStatus,
|
|
696
|
+
metadata,
|
|
697
|
+
} = {}) {
|
|
698
|
+
if (!id) throw new Error("id required");
|
|
699
|
+
if (!operator) throw new Error("operator required");
|
|
700
|
+
if (!sourceProtocol || !VALID_PROTOCOLS.has(sourceProtocol))
|
|
701
|
+
throw new Error("invalid sourceProtocol");
|
|
702
|
+
if (!targetProtocol || !VALID_PROTOCOLS.has(targetProtocol))
|
|
703
|
+
throw new Error("invalid targetProtocol");
|
|
704
|
+
if (_bridgesV2.has(id)) throw new Error(`bridge ${id} already exists`);
|
|
705
|
+
const status = initialStatus ?? BRIDGE_MATURITY_V2.PROVISIONAL;
|
|
706
|
+
if (!Object.values(BRIDGE_MATURITY_V2).includes(status))
|
|
707
|
+
throw new Error(`invalid initial status ${status}`);
|
|
708
|
+
const active =
|
|
709
|
+
status !== BRIDGE_MATURITY_V2.RETIRED &&
|
|
710
|
+
status !== BRIDGE_MATURITY_V2.PROVISIONAL;
|
|
711
|
+
if (
|
|
712
|
+
active &&
|
|
713
|
+
getActiveBridgeCount(operator) >= _pfMaxActiveBridgesPerOperator
|
|
714
|
+
)
|
|
715
|
+
throw new Error(`operator ${operator} active bridge cap reached`);
|
|
716
|
+
const now = _now();
|
|
717
|
+
const bridge = {
|
|
718
|
+
id,
|
|
719
|
+
operator,
|
|
720
|
+
sourceProtocol,
|
|
721
|
+
targetProtocol,
|
|
722
|
+
status,
|
|
723
|
+
metadata: metadata ? { ...metadata } : {},
|
|
724
|
+
createdAt: now,
|
|
725
|
+
updatedAt: now,
|
|
726
|
+
activatedAt: status === BRIDGE_MATURITY_V2.ACTIVE ? now : null,
|
|
727
|
+
lastUsedAt: now,
|
|
728
|
+
};
|
|
729
|
+
_bridgesV2.set(id, bridge);
|
|
730
|
+
return { ...bridge, metadata: { ...bridge.metadata } };
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
export function getBridgeV2(id) {
|
|
734
|
+
const b = _bridgesV2.get(id);
|
|
735
|
+
return b ? { ...b, metadata: { ...b.metadata } } : null;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
export function listBridgesV2({ operator, status } = {}) {
|
|
739
|
+
const out = [];
|
|
740
|
+
for (const b of _bridgesV2.values()) {
|
|
741
|
+
if (operator !== undefined && b.operator !== operator) continue;
|
|
742
|
+
if (status !== undefined && b.status !== status) continue;
|
|
743
|
+
out.push({ ...b, metadata: { ...b.metadata } });
|
|
744
|
+
}
|
|
745
|
+
return out;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
export function setBridgeMaturityV2(id, nextStatus, { reason, metadata } = {}) {
|
|
749
|
+
const b = _bridgesV2.get(id);
|
|
750
|
+
if (!b) throw new Error(`bridge ${id} not found`);
|
|
751
|
+
if (_BRIDGE_TERMINAL_V2.has(b.status))
|
|
752
|
+
throw new Error(`bridge ${id} is terminal (${b.status})`);
|
|
753
|
+
const allowed = _BRIDGE_TRANSITIONS_V2.get(b.status);
|
|
754
|
+
if (!allowed || !allowed.has(nextStatus))
|
|
755
|
+
throw new Error(`illegal transition ${b.status} → ${nextStatus}`);
|
|
756
|
+
const wasActive =
|
|
757
|
+
b.status !== BRIDGE_MATURITY_V2.RETIRED &&
|
|
758
|
+
b.status !== BRIDGE_MATURITY_V2.PROVISIONAL;
|
|
759
|
+
const willBeActive =
|
|
760
|
+
nextStatus !== BRIDGE_MATURITY_V2.RETIRED &&
|
|
761
|
+
nextStatus !== BRIDGE_MATURITY_V2.PROVISIONAL;
|
|
762
|
+
if (!wasActive && willBeActive) {
|
|
763
|
+
if (getActiveBridgeCount(b.operator) >= _pfMaxActiveBridgesPerOperator)
|
|
764
|
+
throw new Error(`operator ${b.operator} active bridge cap reached`);
|
|
765
|
+
}
|
|
766
|
+
b.status = nextStatus;
|
|
767
|
+
b.updatedAt = _now();
|
|
768
|
+
if (reason !== undefined) b.reason = reason;
|
|
769
|
+
if (metadata) b.metadata = { ...b.metadata, ...metadata };
|
|
770
|
+
if (nextStatus === BRIDGE_MATURITY_V2.ACTIVE && !b.activatedAt)
|
|
771
|
+
b.activatedAt = b.updatedAt;
|
|
772
|
+
return { ...b, metadata: { ...b.metadata } };
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
export function activateBridge(id, opts) {
|
|
776
|
+
return setBridgeMaturityV2(id, BRIDGE_MATURITY_V2.ACTIVE, opts);
|
|
777
|
+
}
|
|
778
|
+
export function degradeBridge(id, opts) {
|
|
779
|
+
return setBridgeMaturityV2(id, BRIDGE_MATURITY_V2.DEGRADED, opts);
|
|
780
|
+
}
|
|
781
|
+
export function deprecateBridge(id, opts) {
|
|
782
|
+
return setBridgeMaturityV2(id, BRIDGE_MATURITY_V2.DEPRECATED, opts);
|
|
783
|
+
}
|
|
784
|
+
export function retireBridge(id, opts) {
|
|
785
|
+
return setBridgeMaturityV2(id, BRIDGE_MATURITY_V2.RETIRED, opts);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
export function touchBridgeUsage(id) {
|
|
789
|
+
const b = _bridgesV2.get(id);
|
|
790
|
+
if (!b) throw new Error(`bridge ${id} not found`);
|
|
791
|
+
b.lastUsedAt = _now();
|
|
792
|
+
return { ...b, metadata: { ...b.metadata } };
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
export function enqueueTranslationV2({
|
|
796
|
+
id,
|
|
797
|
+
bridgeId,
|
|
798
|
+
sourceLang,
|
|
799
|
+
targetLang,
|
|
800
|
+
text,
|
|
801
|
+
metadata,
|
|
802
|
+
} = {}) {
|
|
803
|
+
if (!id) throw new Error("id required");
|
|
804
|
+
if (!bridgeId) throw new Error("bridgeId required");
|
|
805
|
+
if (!targetLang) throw new Error("targetLang required");
|
|
806
|
+
if (!text) throw new Error("text required");
|
|
807
|
+
const b = _bridgesV2.get(bridgeId);
|
|
808
|
+
if (!b) throw new Error(`bridge ${bridgeId} not found`);
|
|
809
|
+
if (_translationsV2.has(id))
|
|
810
|
+
throw new Error(`translation ${id} already exists`);
|
|
811
|
+
const now = _now();
|
|
812
|
+
const run = {
|
|
813
|
+
id,
|
|
814
|
+
bridgeId,
|
|
815
|
+
sourceLang: sourceLang || "auto",
|
|
816
|
+
targetLang,
|
|
817
|
+
text,
|
|
818
|
+
status: TRANSLATION_RUN_V2.QUEUED,
|
|
819
|
+
metadata: metadata ? { ...metadata } : {},
|
|
820
|
+
createdAt: now,
|
|
821
|
+
updatedAt: now,
|
|
822
|
+
startedAt: null,
|
|
823
|
+
result: null,
|
|
824
|
+
};
|
|
825
|
+
_translationsV2.set(id, run);
|
|
826
|
+
return { ...run, metadata: { ...run.metadata } };
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
export function getTranslationV2(id) {
|
|
830
|
+
const t = _translationsV2.get(id);
|
|
831
|
+
return t ? { ...t, metadata: { ...t.metadata } } : null;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
export function listTranslationsV2({ bridgeId, status } = {}) {
|
|
835
|
+
const out = [];
|
|
836
|
+
for (const t of _translationsV2.values()) {
|
|
837
|
+
if (bridgeId !== undefined && t.bridgeId !== bridgeId) continue;
|
|
838
|
+
if (status !== undefined && t.status !== status) continue;
|
|
839
|
+
out.push({ ...t, metadata: { ...t.metadata } });
|
|
840
|
+
}
|
|
841
|
+
return out;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
export function setTranslationStatusV2(
|
|
845
|
+
id,
|
|
846
|
+
nextStatus,
|
|
847
|
+
{ reason, metadata, result } = {},
|
|
848
|
+
) {
|
|
849
|
+
const t = _translationsV2.get(id);
|
|
850
|
+
if (!t) throw new Error(`translation ${id} not found`);
|
|
851
|
+
if (_TRANSLATION_TERMINAL_V2.has(t.status))
|
|
852
|
+
throw new Error(`translation ${id} is terminal (${t.status})`);
|
|
853
|
+
const allowed = _TRANSLATION_TRANSITIONS_V2.get(t.status);
|
|
854
|
+
if (!allowed || !allowed.has(nextStatus))
|
|
855
|
+
throw new Error(`illegal transition ${t.status} → ${nextStatus}`);
|
|
856
|
+
if (nextStatus === TRANSLATION_RUN_V2.RUNNING) {
|
|
857
|
+
if (
|
|
858
|
+
getRunningTranslationCount(t.bridgeId) >=
|
|
859
|
+
_pfMaxRunningTranslationsPerBridge
|
|
860
|
+
)
|
|
861
|
+
throw new Error(`bridge ${t.bridgeId} running translation cap reached`);
|
|
862
|
+
}
|
|
863
|
+
t.status = nextStatus;
|
|
864
|
+
t.updatedAt = _now();
|
|
865
|
+
if (reason !== undefined) t.reason = reason;
|
|
866
|
+
if (metadata) t.metadata = { ...t.metadata, ...metadata };
|
|
867
|
+
if (result !== undefined) t.result = result;
|
|
868
|
+
if (nextStatus === TRANSLATION_RUN_V2.RUNNING && !t.startedAt)
|
|
869
|
+
t.startedAt = t.updatedAt;
|
|
870
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
export function startTranslation(id, opts) {
|
|
874
|
+
return setTranslationStatusV2(id, TRANSLATION_RUN_V2.RUNNING, opts);
|
|
875
|
+
}
|
|
876
|
+
export function succeedTranslation(id, opts) {
|
|
877
|
+
return setTranslationStatusV2(id, TRANSLATION_RUN_V2.SUCCEEDED, opts);
|
|
878
|
+
}
|
|
879
|
+
export function failTranslation(id, opts) {
|
|
880
|
+
return setTranslationStatusV2(id, TRANSLATION_RUN_V2.FAILED, opts);
|
|
881
|
+
}
|
|
882
|
+
export function cancelTranslation(id, opts) {
|
|
883
|
+
return setTranslationStatusV2(id, TRANSLATION_RUN_V2.CANCELED, opts);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
export function autoRetireIdleBridges({ now } = {}) {
|
|
887
|
+
const cutoff = (now ?? _now()) - _pfBridgeIdleMs;
|
|
888
|
+
const flipped = [];
|
|
889
|
+
for (const b of _bridgesV2.values()) {
|
|
890
|
+
if (
|
|
891
|
+
b.status !== BRIDGE_MATURITY_V2.ACTIVE &&
|
|
892
|
+
b.status !== BRIDGE_MATURITY_V2.DEGRADED &&
|
|
893
|
+
b.status !== BRIDGE_MATURITY_V2.DEPRECATED
|
|
894
|
+
)
|
|
895
|
+
continue;
|
|
896
|
+
if ((b.lastUsedAt ?? b.createdAt) > cutoff) continue;
|
|
897
|
+
b.status = BRIDGE_MATURITY_V2.RETIRED;
|
|
898
|
+
b.updatedAt = now ?? _now();
|
|
899
|
+
b.reason = "auto_retire_idle";
|
|
900
|
+
flipped.push(b.id);
|
|
901
|
+
}
|
|
902
|
+
return flipped;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
export function autoFailStuckRunningTranslations({ now } = {}) {
|
|
906
|
+
const cutoff = (now ?? _now()) - _pfTranslationStuckMs;
|
|
907
|
+
const flipped = [];
|
|
908
|
+
for (const t of _translationsV2.values()) {
|
|
909
|
+
if (t.status !== TRANSLATION_RUN_V2.RUNNING) continue;
|
|
910
|
+
if (!t.startedAt || t.startedAt > cutoff) continue;
|
|
911
|
+
t.status = TRANSLATION_RUN_V2.FAILED;
|
|
912
|
+
t.updatedAt = now ?? _now();
|
|
913
|
+
t.reason = "auto_fail_stuck";
|
|
914
|
+
flipped.push(t.id);
|
|
915
|
+
}
|
|
916
|
+
return flipped;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function _zeroByEnum(enumObj) {
|
|
920
|
+
const out = {};
|
|
921
|
+
for (const v of Object.values(enumObj)) out[v] = 0;
|
|
922
|
+
return out;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
export function getProtocolFusionStatsV2() {
|
|
926
|
+
const bridges = [..._bridgesV2.values()];
|
|
927
|
+
const translations = [..._translationsV2.values()];
|
|
928
|
+
const bridgesByStatus = _zeroByEnum(BRIDGE_MATURITY_V2);
|
|
929
|
+
for (const b of bridges) bridgesByStatus[b.status]++;
|
|
930
|
+
const translationsByStatus = _zeroByEnum(TRANSLATION_RUN_V2);
|
|
931
|
+
for (const t of translations) translationsByStatus[t.status]++;
|
|
932
|
+
return {
|
|
933
|
+
totalBridgesV2: bridges.length,
|
|
934
|
+
totalTranslationsV2: translations.length,
|
|
935
|
+
maxActiveBridgesPerOperator: _pfMaxActiveBridgesPerOperator,
|
|
936
|
+
maxRunningTranslationsPerBridge: _pfMaxRunningTranslationsPerBridge,
|
|
937
|
+
bridgeIdleMs: _pfBridgeIdleMs,
|
|
938
|
+
translationStuckMs: _pfTranslationStuckMs,
|
|
939
|
+
bridgesByStatus,
|
|
940
|
+
translationsByStatus,
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
export function _resetStateV2() {
|
|
945
|
+
_bridgesV2.clear();
|
|
946
|
+
_translationsV2.clear();
|
|
947
|
+
_pfMaxActiveBridgesPerOperator = PF_DEFAULT_MAX_ACTIVE_BRIDGES_PER_OPERATOR;
|
|
948
|
+
_pfMaxRunningTranslationsPerBridge =
|
|
949
|
+
PF_DEFAULT_MAX_RUNNING_TRANSLATIONS_PER_BRIDGE;
|
|
950
|
+
_pfBridgeIdleMs = PF_DEFAULT_BRIDGE_IDLE_MS;
|
|
951
|
+
_pfTranslationStuckMs = PF_DEFAULT_TRANSLATION_STUCK_MS;
|
|
952
|
+
}
|