chainlesschain 0.145.0 → 0.156.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/README.md +52 -3
- package/package.json +1 -1
- package/src/commands/a2a.js +201 -0
- package/src/commands/activitypub.js +207 -0
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +1250 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +203 -0
- package/src/commands/browse.js +213 -0
- package/src/commands/chat.js +605 -0
- package/src/commands/cli-anything.js +426 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +822 -0
- package/src/commands/config.js +213 -0
- package/src/commands/cowork.js +1666 -0
- package/src/commands/crosschain.js +203 -0
- package/src/commands/dao.js +203 -0
- 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 +213 -0
- package/src/commands/economy.js +199 -0
- package/src/commands/encrypt.js +201 -0
- package/src/commands/evolution.js +199 -0
- package/src/commands/evomap.js +830 -0
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fusion.js +205 -0
- package/src/commands/governance.js +209 -0
- package/src/commands/hmemory.js +203 -0
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/inference.js +207 -0
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/kg.js +195 -0
- package/src/commands/llm.js +426 -0
- package/src/commands/matrix.js +207 -0
- package/src/commands/mcp.js +217 -0
- package/src/commands/memory.js +412 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +209 -0
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +406 -0
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/perception.js +209 -0
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +199 -0
- package/src/commands/planmode.js +426 -0
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/plugin.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +233 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/services.js +207 -0
- package/src/commands/session.js +209 -0
- package/src/commands/setup.js +205 -0
- package/src/commands/skill.js +414 -0
- package/src/commands/social.js +201 -0
- package/src/commands/sso.js +209 -0
- package/src/commands/start.js +209 -0
- package/src/commands/stream.js +213 -0
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/tokens.js +209 -0
- package/src/commands/trust.js +217 -0
- package/src/commands/ui.js +225 -0
- package/src/commands/wallet.js +209 -0
- package/src/commands/workflow.js +412 -0
- package/src/index.js +252 -0
- package/src/lib/a2a-protocol.js +332 -0
- package/src/lib/activitypub-bridge.js +334 -0
- package/src/lib/agent-coordinator.js +334 -0
- package/src/lib/agent-economy.js +334 -0
- package/src/lib/agent-network.js +341 -0
- package/src/lib/agent-router.js +333 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +332 -0
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +333 -0
- package/src/lib/browser-automation.js +334 -0
- package/src/lib/chat-core.js +335 -0
- package/src/lib/cli-anything-bridge.js +341 -0
- package/src/lib/cli-context-engineering.js +351 -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-manager.js +334 -0
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/cowork-adapter.js +336 -0
- package/src/lib/cowork-evomap-adapter.js +341 -0
- package/src/lib/cowork-mcp-tools.js +341 -0
- package/src/lib/cowork-observe-html.js +341 -0
- package/src/lib/cowork-observe.js +341 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-templates.js +342 -1
- package/src/lib/cowork-template-marketplace.js +340 -0
- package/src/lib/cross-chain.js +339 -0
- package/src/lib/crypto-manager.js +334 -0
- package/src/lib/dao-governance.js +339 -0
- 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 +339 -0
- package/src/lib/downloader.js +334 -0
- package/src/lib/evolution-system.js +334 -0
- package/src/lib/evomap-client.js +342 -0
- package/src/lib/evomap-federation.js +338 -0
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +330 -0
- package/src/lib/execution-backend.js +330 -0
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/hashline.js +338 -0
- package/src/lib/hierarchical-memory.js +334 -0
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +341 -0
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/interaction-adapter.js +330 -0
- package/src/lib/interactive-planner.js +354 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +331 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-registry.js +346 -0
- 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 +336 -0
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/pipeline-orchestrator.js +332 -0
- package/src/lib/plan-mode.js +336 -0
- package/src/lib/plugin-autodiscovery.js +334 -0
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/process-manager.js +336 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/provider-options.js +346 -0
- package/src/lib/provider-stream.js +348 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-manager.js +337 -0
- package/src/lib/session-core-singletons.js +341 -0
- package/src/lib/session-manager.js +334 -0
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-mcp.js +336 -0
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stix-parser.js +346 -0
- package/src/lib/sub-agent-context.js +343 -0
- package/src/lib/sub-agent-profiles.js +335 -0
- package/src/lib/sub-agent-registry.js +336 -0
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +336 -0
- package/src/lib/token-tracker.js +336 -0
- 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/wallet-manager.js +336 -0
- package/src/lib/web-ui-server.js +348 -0
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/workflow-expr.js +346 -0
- package/src/lib/ws-chat-handler.js +337 -0
|
@@ -672,3 +672,339 @@ export function _resetStateWalletManagerV2() {
|
|
|
672
672
|
_walletIdleMsV2 = WALLET_DEFAULT_WALLET_IDLE_MS;
|
|
673
673
|
_txStuckMsV2 = WALLET_DEFAULT_TX_STUCK_MS;
|
|
674
674
|
}
|
|
675
|
+
|
|
676
|
+
// =====================================================================
|
|
677
|
+
// wallet-manager V2 governance overlay (iter20)
|
|
678
|
+
// =====================================================================
|
|
679
|
+
export const WALGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
680
|
+
PENDING: "pending",
|
|
681
|
+
ACTIVE: "active",
|
|
682
|
+
FROZEN: "frozen",
|
|
683
|
+
ARCHIVED: "archived",
|
|
684
|
+
});
|
|
685
|
+
export const WALGOV_TRANSFER_LIFECYCLE_V2 = Object.freeze({
|
|
686
|
+
QUEUED: "queued",
|
|
687
|
+
SIGNING: "signing",
|
|
688
|
+
SIGNED: "signed",
|
|
689
|
+
FAILED: "failed",
|
|
690
|
+
CANCELLED: "cancelled",
|
|
691
|
+
});
|
|
692
|
+
const _walgovPTrans = new Map([
|
|
693
|
+
[
|
|
694
|
+
WALGOV_PROFILE_MATURITY_V2.PENDING,
|
|
695
|
+
new Set([
|
|
696
|
+
WALGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
697
|
+
WALGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
698
|
+
]),
|
|
699
|
+
],
|
|
700
|
+
[
|
|
701
|
+
WALGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
702
|
+
new Set([
|
|
703
|
+
WALGOV_PROFILE_MATURITY_V2.FROZEN,
|
|
704
|
+
WALGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
705
|
+
]),
|
|
706
|
+
],
|
|
707
|
+
[
|
|
708
|
+
WALGOV_PROFILE_MATURITY_V2.FROZEN,
|
|
709
|
+
new Set([
|
|
710
|
+
WALGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
711
|
+
WALGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
712
|
+
]),
|
|
713
|
+
],
|
|
714
|
+
[WALGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
715
|
+
]);
|
|
716
|
+
const _walgovPTerminal = new Set([WALGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
717
|
+
const _walgovJTrans = new Map([
|
|
718
|
+
[
|
|
719
|
+
WALGOV_TRANSFER_LIFECYCLE_V2.QUEUED,
|
|
720
|
+
new Set([
|
|
721
|
+
WALGOV_TRANSFER_LIFECYCLE_V2.SIGNING,
|
|
722
|
+
WALGOV_TRANSFER_LIFECYCLE_V2.CANCELLED,
|
|
723
|
+
]),
|
|
724
|
+
],
|
|
725
|
+
[
|
|
726
|
+
WALGOV_TRANSFER_LIFECYCLE_V2.SIGNING,
|
|
727
|
+
new Set([
|
|
728
|
+
WALGOV_TRANSFER_LIFECYCLE_V2.SIGNED,
|
|
729
|
+
WALGOV_TRANSFER_LIFECYCLE_V2.FAILED,
|
|
730
|
+
WALGOV_TRANSFER_LIFECYCLE_V2.CANCELLED,
|
|
731
|
+
]),
|
|
732
|
+
],
|
|
733
|
+
[WALGOV_TRANSFER_LIFECYCLE_V2.SIGNED, new Set()],
|
|
734
|
+
[WALGOV_TRANSFER_LIFECYCLE_V2.FAILED, new Set()],
|
|
735
|
+
[WALGOV_TRANSFER_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
736
|
+
]);
|
|
737
|
+
const _walgovPsV2 = new Map();
|
|
738
|
+
const _walgovJsV2 = new Map();
|
|
739
|
+
let _walgovMaxActive = 6,
|
|
740
|
+
_walgovMaxPending = 15,
|
|
741
|
+
_walgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
742
|
+
_walgovStuckMs = 60 * 1000;
|
|
743
|
+
function _walgovPos(n, label) {
|
|
744
|
+
const v = Math.floor(Number(n));
|
|
745
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
746
|
+
throw new Error(`${label} must be positive integer`);
|
|
747
|
+
return v;
|
|
748
|
+
}
|
|
749
|
+
function _walgovCheckP(from, to) {
|
|
750
|
+
const a = _walgovPTrans.get(from);
|
|
751
|
+
if (!a || !a.has(to))
|
|
752
|
+
throw new Error(`invalid walgov profile transition ${from} → ${to}`);
|
|
753
|
+
}
|
|
754
|
+
function _walgovCheckJ(from, to) {
|
|
755
|
+
const a = _walgovJTrans.get(from);
|
|
756
|
+
if (!a || !a.has(to))
|
|
757
|
+
throw new Error(`invalid walgov transfer transition ${from} → ${to}`);
|
|
758
|
+
}
|
|
759
|
+
function _walgovCountActive(owner) {
|
|
760
|
+
let c = 0;
|
|
761
|
+
for (const p of _walgovPsV2.values())
|
|
762
|
+
if (p.owner === owner && p.status === WALGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
763
|
+
c++;
|
|
764
|
+
return c;
|
|
765
|
+
}
|
|
766
|
+
function _walgovCountPending(profileId) {
|
|
767
|
+
let c = 0;
|
|
768
|
+
for (const j of _walgovJsV2.values())
|
|
769
|
+
if (
|
|
770
|
+
j.profileId === profileId &&
|
|
771
|
+
(j.status === WALGOV_TRANSFER_LIFECYCLE_V2.QUEUED ||
|
|
772
|
+
j.status === WALGOV_TRANSFER_LIFECYCLE_V2.SIGNING)
|
|
773
|
+
)
|
|
774
|
+
c++;
|
|
775
|
+
return c;
|
|
776
|
+
}
|
|
777
|
+
export function setMaxActiveWalgovProfilesPerOwnerV2(n) {
|
|
778
|
+
_walgovMaxActive = _walgovPos(n, "maxActiveWalgovProfilesPerOwner");
|
|
779
|
+
}
|
|
780
|
+
export function getMaxActiveWalgovProfilesPerOwnerV2() {
|
|
781
|
+
return _walgovMaxActive;
|
|
782
|
+
}
|
|
783
|
+
export function setMaxPendingWalgovTransfersPerProfileV2(n) {
|
|
784
|
+
_walgovMaxPending = _walgovPos(n, "maxPendingWalgovTransfersPerProfile");
|
|
785
|
+
}
|
|
786
|
+
export function getMaxPendingWalgovTransfersPerProfileV2() {
|
|
787
|
+
return _walgovMaxPending;
|
|
788
|
+
}
|
|
789
|
+
export function setWalgovProfileIdleMsV2(n) {
|
|
790
|
+
_walgovIdleMs = _walgovPos(n, "walgovProfileIdleMs");
|
|
791
|
+
}
|
|
792
|
+
export function getWalgovProfileIdleMsV2() {
|
|
793
|
+
return _walgovIdleMs;
|
|
794
|
+
}
|
|
795
|
+
export function setWalgovTransferStuckMsV2(n) {
|
|
796
|
+
_walgovStuckMs = _walgovPos(n, "walgovTransferStuckMs");
|
|
797
|
+
}
|
|
798
|
+
export function getWalgovTransferStuckMsV2() {
|
|
799
|
+
return _walgovStuckMs;
|
|
800
|
+
}
|
|
801
|
+
export function _resetStateWalletManagerGovV2() {
|
|
802
|
+
_walgovPsV2.clear();
|
|
803
|
+
_walgovJsV2.clear();
|
|
804
|
+
_walgovMaxActive = 6;
|
|
805
|
+
_walgovMaxPending = 15;
|
|
806
|
+
_walgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
807
|
+
_walgovStuckMs = 60 * 1000;
|
|
808
|
+
}
|
|
809
|
+
export function registerWalgovProfileV2({ id, owner, chain, metadata } = {}) {
|
|
810
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
811
|
+
if (_walgovPsV2.has(id))
|
|
812
|
+
throw new Error(`walgov profile ${id} already exists`);
|
|
813
|
+
const now = Date.now();
|
|
814
|
+
const p = {
|
|
815
|
+
id,
|
|
816
|
+
owner,
|
|
817
|
+
chain: chain || "mainnet",
|
|
818
|
+
status: WALGOV_PROFILE_MATURITY_V2.PENDING,
|
|
819
|
+
createdAt: now,
|
|
820
|
+
updatedAt: now,
|
|
821
|
+
lastTouchedAt: now,
|
|
822
|
+
activatedAt: null,
|
|
823
|
+
archivedAt: null,
|
|
824
|
+
metadata: { ...(metadata || {}) },
|
|
825
|
+
};
|
|
826
|
+
_walgovPsV2.set(id, p);
|
|
827
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
828
|
+
}
|
|
829
|
+
export function activateWalgovProfileV2(id) {
|
|
830
|
+
const p = _walgovPsV2.get(id);
|
|
831
|
+
if (!p) throw new Error(`walgov profile ${id} not found`);
|
|
832
|
+
const isInitial = p.status === WALGOV_PROFILE_MATURITY_V2.PENDING;
|
|
833
|
+
_walgovCheckP(p.status, WALGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
834
|
+
if (isInitial && _walgovCountActive(p.owner) >= _walgovMaxActive)
|
|
835
|
+
throw new Error(`max active walgov profiles for owner ${p.owner} reached`);
|
|
836
|
+
const now = Date.now();
|
|
837
|
+
p.status = WALGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
838
|
+
p.updatedAt = now;
|
|
839
|
+
p.lastTouchedAt = now;
|
|
840
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
841
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
842
|
+
}
|
|
843
|
+
export function freezeWalgovProfileV2(id) {
|
|
844
|
+
const p = _walgovPsV2.get(id);
|
|
845
|
+
if (!p) throw new Error(`walgov profile ${id} not found`);
|
|
846
|
+
_walgovCheckP(p.status, WALGOV_PROFILE_MATURITY_V2.FROZEN);
|
|
847
|
+
p.status = WALGOV_PROFILE_MATURITY_V2.FROZEN;
|
|
848
|
+
p.updatedAt = Date.now();
|
|
849
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
850
|
+
}
|
|
851
|
+
export function archiveWalgovProfileV2(id) {
|
|
852
|
+
const p = _walgovPsV2.get(id);
|
|
853
|
+
if (!p) throw new Error(`walgov profile ${id} not found`);
|
|
854
|
+
_walgovCheckP(p.status, WALGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
855
|
+
const now = Date.now();
|
|
856
|
+
p.status = WALGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
857
|
+
p.updatedAt = now;
|
|
858
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
859
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
860
|
+
}
|
|
861
|
+
export function touchWalgovProfileV2(id) {
|
|
862
|
+
const p = _walgovPsV2.get(id);
|
|
863
|
+
if (!p) throw new Error(`walgov profile ${id} not found`);
|
|
864
|
+
if (_walgovPTerminal.has(p.status))
|
|
865
|
+
throw new Error(`cannot touch terminal walgov profile ${id}`);
|
|
866
|
+
const now = Date.now();
|
|
867
|
+
p.lastTouchedAt = now;
|
|
868
|
+
p.updatedAt = now;
|
|
869
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
870
|
+
}
|
|
871
|
+
export function getWalgovProfileV2(id) {
|
|
872
|
+
const p = _walgovPsV2.get(id);
|
|
873
|
+
if (!p) return null;
|
|
874
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
875
|
+
}
|
|
876
|
+
export function listWalgovProfilesV2() {
|
|
877
|
+
return [..._walgovPsV2.values()].map((p) => ({
|
|
878
|
+
...p,
|
|
879
|
+
metadata: { ...p.metadata },
|
|
880
|
+
}));
|
|
881
|
+
}
|
|
882
|
+
export function createWalgovTransferV2({ id, profileId, to, metadata } = {}) {
|
|
883
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
884
|
+
if (_walgovJsV2.has(id))
|
|
885
|
+
throw new Error(`walgov transfer ${id} already exists`);
|
|
886
|
+
if (!_walgovPsV2.has(profileId))
|
|
887
|
+
throw new Error(`walgov profile ${profileId} not found`);
|
|
888
|
+
if (_walgovCountPending(profileId) >= _walgovMaxPending)
|
|
889
|
+
throw new Error(
|
|
890
|
+
`max pending walgov transfers for profile ${profileId} reached`,
|
|
891
|
+
);
|
|
892
|
+
const now = Date.now();
|
|
893
|
+
const j = {
|
|
894
|
+
id,
|
|
895
|
+
profileId,
|
|
896
|
+
to: to || "",
|
|
897
|
+
status: WALGOV_TRANSFER_LIFECYCLE_V2.QUEUED,
|
|
898
|
+
createdAt: now,
|
|
899
|
+
updatedAt: now,
|
|
900
|
+
startedAt: null,
|
|
901
|
+
settledAt: null,
|
|
902
|
+
metadata: { ...(metadata || {}) },
|
|
903
|
+
};
|
|
904
|
+
_walgovJsV2.set(id, j);
|
|
905
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
906
|
+
}
|
|
907
|
+
export function signingWalgovTransferV2(id) {
|
|
908
|
+
const j = _walgovJsV2.get(id);
|
|
909
|
+
if (!j) throw new Error(`walgov transfer ${id} not found`);
|
|
910
|
+
_walgovCheckJ(j.status, WALGOV_TRANSFER_LIFECYCLE_V2.SIGNING);
|
|
911
|
+
const now = Date.now();
|
|
912
|
+
j.status = WALGOV_TRANSFER_LIFECYCLE_V2.SIGNING;
|
|
913
|
+
j.updatedAt = now;
|
|
914
|
+
if (!j.startedAt) j.startedAt = now;
|
|
915
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
916
|
+
}
|
|
917
|
+
export function completeTransferWalgovV2(id) {
|
|
918
|
+
const j = _walgovJsV2.get(id);
|
|
919
|
+
if (!j) throw new Error(`walgov transfer ${id} not found`);
|
|
920
|
+
_walgovCheckJ(j.status, WALGOV_TRANSFER_LIFECYCLE_V2.SIGNED);
|
|
921
|
+
const now = Date.now();
|
|
922
|
+
j.status = WALGOV_TRANSFER_LIFECYCLE_V2.SIGNED;
|
|
923
|
+
j.updatedAt = now;
|
|
924
|
+
if (!j.settledAt) j.settledAt = now;
|
|
925
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
926
|
+
}
|
|
927
|
+
export function failWalgovTransferV2(id, reason) {
|
|
928
|
+
const j = _walgovJsV2.get(id);
|
|
929
|
+
if (!j) throw new Error(`walgov transfer ${id} not found`);
|
|
930
|
+
_walgovCheckJ(j.status, WALGOV_TRANSFER_LIFECYCLE_V2.FAILED);
|
|
931
|
+
const now = Date.now();
|
|
932
|
+
j.status = WALGOV_TRANSFER_LIFECYCLE_V2.FAILED;
|
|
933
|
+
j.updatedAt = now;
|
|
934
|
+
if (!j.settledAt) j.settledAt = now;
|
|
935
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
936
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
937
|
+
}
|
|
938
|
+
export function cancelWalgovTransferV2(id, reason) {
|
|
939
|
+
const j = _walgovJsV2.get(id);
|
|
940
|
+
if (!j) throw new Error(`walgov transfer ${id} not found`);
|
|
941
|
+
_walgovCheckJ(j.status, WALGOV_TRANSFER_LIFECYCLE_V2.CANCELLED);
|
|
942
|
+
const now = Date.now();
|
|
943
|
+
j.status = WALGOV_TRANSFER_LIFECYCLE_V2.CANCELLED;
|
|
944
|
+
j.updatedAt = now;
|
|
945
|
+
if (!j.settledAt) j.settledAt = now;
|
|
946
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
947
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
948
|
+
}
|
|
949
|
+
export function getWalgovTransferV2(id) {
|
|
950
|
+
const j = _walgovJsV2.get(id);
|
|
951
|
+
if (!j) return null;
|
|
952
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
953
|
+
}
|
|
954
|
+
export function listWalgovTransfersV2() {
|
|
955
|
+
return [..._walgovJsV2.values()].map((j) => ({
|
|
956
|
+
...j,
|
|
957
|
+
metadata: { ...j.metadata },
|
|
958
|
+
}));
|
|
959
|
+
}
|
|
960
|
+
export function autoFreezeIdleWalgovProfilesV2({ now } = {}) {
|
|
961
|
+
const t = now ?? Date.now();
|
|
962
|
+
const flipped = [];
|
|
963
|
+
for (const p of _walgovPsV2.values())
|
|
964
|
+
if (
|
|
965
|
+
p.status === WALGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
966
|
+
t - p.lastTouchedAt >= _walgovIdleMs
|
|
967
|
+
) {
|
|
968
|
+
p.status = WALGOV_PROFILE_MATURITY_V2.FROZEN;
|
|
969
|
+
p.updatedAt = t;
|
|
970
|
+
flipped.push(p.id);
|
|
971
|
+
}
|
|
972
|
+
return { flipped, count: flipped.length };
|
|
973
|
+
}
|
|
974
|
+
export function autoFailStuckWalgovTransfersV2({ now } = {}) {
|
|
975
|
+
const t = now ?? Date.now();
|
|
976
|
+
const flipped = [];
|
|
977
|
+
for (const j of _walgovJsV2.values())
|
|
978
|
+
if (
|
|
979
|
+
j.status === WALGOV_TRANSFER_LIFECYCLE_V2.SIGNING &&
|
|
980
|
+
j.startedAt != null &&
|
|
981
|
+
t - j.startedAt >= _walgovStuckMs
|
|
982
|
+
) {
|
|
983
|
+
j.status = WALGOV_TRANSFER_LIFECYCLE_V2.FAILED;
|
|
984
|
+
j.updatedAt = t;
|
|
985
|
+
if (!j.settledAt) j.settledAt = t;
|
|
986
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
987
|
+
flipped.push(j.id);
|
|
988
|
+
}
|
|
989
|
+
return { flipped, count: flipped.length };
|
|
990
|
+
}
|
|
991
|
+
export function getWalletManagerGovStatsV2() {
|
|
992
|
+
const profilesByStatus = {};
|
|
993
|
+
for (const v of Object.values(WALGOV_PROFILE_MATURITY_V2))
|
|
994
|
+
profilesByStatus[v] = 0;
|
|
995
|
+
for (const p of _walgovPsV2.values()) profilesByStatus[p.status]++;
|
|
996
|
+
const transfersByStatus = {};
|
|
997
|
+
for (const v of Object.values(WALGOV_TRANSFER_LIFECYCLE_V2))
|
|
998
|
+
transfersByStatus[v] = 0;
|
|
999
|
+
for (const j of _walgovJsV2.values()) transfersByStatus[j.status]++;
|
|
1000
|
+
return {
|
|
1001
|
+
totalWalgovProfilesV2: _walgovPsV2.size,
|
|
1002
|
+
totalWalgovTransfersV2: _walgovJsV2.size,
|
|
1003
|
+
maxActiveWalgovProfilesPerOwner: _walgovMaxActive,
|
|
1004
|
+
maxPendingWalgovTransfersPerProfile: _walgovMaxPending,
|
|
1005
|
+
walgovProfileIdleMs: _walgovIdleMs,
|
|
1006
|
+
walgovTransferStuckMs: _walgovStuckMs,
|
|
1007
|
+
profilesByStatus,
|
|
1008
|
+
transfersByStatus,
|
|
1009
|
+
};
|
|
1010
|
+
}
|
package/src/lib/web-ui-server.js
CHANGED
|
@@ -1296,3 +1296,351 @@ export function createWebUIServer(opts) {
|
|
|
1296
1296
|
res.end(html, "utf-8");
|
|
1297
1297
|
});
|
|
1298
1298
|
}
|
|
1299
|
+
|
|
1300
|
+
// =====================================================================
|
|
1301
|
+
// web-ui-server V2 governance overlay (iter26)
|
|
1302
|
+
// =====================================================================
|
|
1303
|
+
export const WEBUIGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
1304
|
+
PENDING: "pending",
|
|
1305
|
+
ACTIVE: "active",
|
|
1306
|
+
DEGRADED: "degraded",
|
|
1307
|
+
ARCHIVED: "archived",
|
|
1308
|
+
});
|
|
1309
|
+
export const WEBUIGOV_REQUEST_LIFECYCLE_V2 = Object.freeze({
|
|
1310
|
+
QUEUED: "queued",
|
|
1311
|
+
SERVING: "serving",
|
|
1312
|
+
SERVED: "served",
|
|
1313
|
+
FAILED: "failed",
|
|
1314
|
+
CANCELLED: "cancelled",
|
|
1315
|
+
});
|
|
1316
|
+
const _webuigovPTrans = new Map([
|
|
1317
|
+
[
|
|
1318
|
+
WEBUIGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1319
|
+
new Set([
|
|
1320
|
+
WEBUIGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1321
|
+
WEBUIGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1322
|
+
]),
|
|
1323
|
+
],
|
|
1324
|
+
[
|
|
1325
|
+
WEBUIGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1326
|
+
new Set([
|
|
1327
|
+
WEBUIGOV_PROFILE_MATURITY_V2.DEGRADED,
|
|
1328
|
+
WEBUIGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1329
|
+
]),
|
|
1330
|
+
],
|
|
1331
|
+
[
|
|
1332
|
+
WEBUIGOV_PROFILE_MATURITY_V2.DEGRADED,
|
|
1333
|
+
new Set([
|
|
1334
|
+
WEBUIGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1335
|
+
WEBUIGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1336
|
+
]),
|
|
1337
|
+
],
|
|
1338
|
+
[WEBUIGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1339
|
+
]);
|
|
1340
|
+
const _webuigovPTerminal = new Set([WEBUIGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1341
|
+
const _webuigovJTrans = new Map([
|
|
1342
|
+
[
|
|
1343
|
+
WEBUIGOV_REQUEST_LIFECYCLE_V2.QUEUED,
|
|
1344
|
+
new Set([
|
|
1345
|
+
WEBUIGOV_REQUEST_LIFECYCLE_V2.SERVING,
|
|
1346
|
+
WEBUIGOV_REQUEST_LIFECYCLE_V2.CANCELLED,
|
|
1347
|
+
]),
|
|
1348
|
+
],
|
|
1349
|
+
[
|
|
1350
|
+
WEBUIGOV_REQUEST_LIFECYCLE_V2.SERVING,
|
|
1351
|
+
new Set([
|
|
1352
|
+
WEBUIGOV_REQUEST_LIFECYCLE_V2.SERVED,
|
|
1353
|
+
WEBUIGOV_REQUEST_LIFECYCLE_V2.FAILED,
|
|
1354
|
+
WEBUIGOV_REQUEST_LIFECYCLE_V2.CANCELLED,
|
|
1355
|
+
]),
|
|
1356
|
+
],
|
|
1357
|
+
[WEBUIGOV_REQUEST_LIFECYCLE_V2.SERVED, new Set()],
|
|
1358
|
+
[WEBUIGOV_REQUEST_LIFECYCLE_V2.FAILED, new Set()],
|
|
1359
|
+
[WEBUIGOV_REQUEST_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1360
|
+
]);
|
|
1361
|
+
const _webuigovPsV2 = new Map();
|
|
1362
|
+
const _webuigovJsV2 = new Map();
|
|
1363
|
+
let _webuigovMaxActive = 10,
|
|
1364
|
+
_webuigovMaxPending = 25,
|
|
1365
|
+
_webuigovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1366
|
+
_webuigovStuckMs = 60 * 1000;
|
|
1367
|
+
function _webuigovPos(n, label) {
|
|
1368
|
+
const v = Math.floor(Number(n));
|
|
1369
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1370
|
+
throw new Error(`${label} must be positive integer`);
|
|
1371
|
+
return v;
|
|
1372
|
+
}
|
|
1373
|
+
function _webuigovCheckP(from, to) {
|
|
1374
|
+
const a = _webuigovPTrans.get(from);
|
|
1375
|
+
if (!a || !a.has(to))
|
|
1376
|
+
throw new Error(`invalid webuigov profile transition ${from} → ${to}`);
|
|
1377
|
+
}
|
|
1378
|
+
function _webuigovCheckJ(from, to) {
|
|
1379
|
+
const a = _webuigovJTrans.get(from);
|
|
1380
|
+
if (!a || !a.has(to))
|
|
1381
|
+
throw new Error(`invalid webuigov request transition ${from} → ${to}`);
|
|
1382
|
+
}
|
|
1383
|
+
function _webuigovCountActive(owner) {
|
|
1384
|
+
let c = 0;
|
|
1385
|
+
for (const p of _webuigovPsV2.values())
|
|
1386
|
+
if (p.owner === owner && p.status === WEBUIGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
1387
|
+
c++;
|
|
1388
|
+
return c;
|
|
1389
|
+
}
|
|
1390
|
+
function _webuigovCountPending(profileId) {
|
|
1391
|
+
let c = 0;
|
|
1392
|
+
for (const j of _webuigovJsV2.values())
|
|
1393
|
+
if (
|
|
1394
|
+
j.profileId === profileId &&
|
|
1395
|
+
(j.status === WEBUIGOV_REQUEST_LIFECYCLE_V2.QUEUED ||
|
|
1396
|
+
j.status === WEBUIGOV_REQUEST_LIFECYCLE_V2.SERVING)
|
|
1397
|
+
)
|
|
1398
|
+
c++;
|
|
1399
|
+
return c;
|
|
1400
|
+
}
|
|
1401
|
+
export function setMaxActiveWebuigovProfilesPerOwnerV2(n) {
|
|
1402
|
+
_webuigovMaxActive = _webuigovPos(n, "maxActiveWebuigovProfilesPerOwner");
|
|
1403
|
+
}
|
|
1404
|
+
export function getMaxActiveWebuigovProfilesPerOwnerV2() {
|
|
1405
|
+
return _webuigovMaxActive;
|
|
1406
|
+
}
|
|
1407
|
+
export function setMaxPendingWebuigovRequestsPerProfileV2(n) {
|
|
1408
|
+
_webuigovMaxPending = _webuigovPos(n, "maxPendingWebuigovRequestsPerProfile");
|
|
1409
|
+
}
|
|
1410
|
+
export function getMaxPendingWebuigovRequestsPerProfileV2() {
|
|
1411
|
+
return _webuigovMaxPending;
|
|
1412
|
+
}
|
|
1413
|
+
export function setWebuigovProfileIdleMsV2(n) {
|
|
1414
|
+
_webuigovIdleMs = _webuigovPos(n, "webuigovProfileIdleMs");
|
|
1415
|
+
}
|
|
1416
|
+
export function getWebuigovProfileIdleMsV2() {
|
|
1417
|
+
return _webuigovIdleMs;
|
|
1418
|
+
}
|
|
1419
|
+
export function setWebuigovRequestStuckMsV2(n) {
|
|
1420
|
+
_webuigovStuckMs = _webuigovPos(n, "webuigovRequestStuckMs");
|
|
1421
|
+
}
|
|
1422
|
+
export function getWebuigovRequestStuckMsV2() {
|
|
1423
|
+
return _webuigovStuckMs;
|
|
1424
|
+
}
|
|
1425
|
+
export function _resetStateWebUiServerGovV2() {
|
|
1426
|
+
_webuigovPsV2.clear();
|
|
1427
|
+
_webuigovJsV2.clear();
|
|
1428
|
+
_webuigovMaxActive = 10;
|
|
1429
|
+
_webuigovMaxPending = 25;
|
|
1430
|
+
_webuigovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1431
|
+
_webuigovStuckMs = 60 * 1000;
|
|
1432
|
+
}
|
|
1433
|
+
export function registerWebuigovProfileV2({
|
|
1434
|
+
id,
|
|
1435
|
+
owner,
|
|
1436
|
+
endpoint,
|
|
1437
|
+
metadata,
|
|
1438
|
+
} = {}) {
|
|
1439
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1440
|
+
if (_webuigovPsV2.has(id))
|
|
1441
|
+
throw new Error(`webuigov profile ${id} already exists`);
|
|
1442
|
+
const now = Date.now();
|
|
1443
|
+
const p = {
|
|
1444
|
+
id,
|
|
1445
|
+
owner,
|
|
1446
|
+
endpoint: endpoint || "/",
|
|
1447
|
+
status: WEBUIGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1448
|
+
createdAt: now,
|
|
1449
|
+
updatedAt: now,
|
|
1450
|
+
lastTouchedAt: now,
|
|
1451
|
+
activatedAt: null,
|
|
1452
|
+
archivedAt: null,
|
|
1453
|
+
metadata: { ...(metadata || {}) },
|
|
1454
|
+
};
|
|
1455
|
+
_webuigovPsV2.set(id, p);
|
|
1456
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1457
|
+
}
|
|
1458
|
+
export function activateWebuigovProfileV2(id) {
|
|
1459
|
+
const p = _webuigovPsV2.get(id);
|
|
1460
|
+
if (!p) throw new Error(`webuigov profile ${id} not found`);
|
|
1461
|
+
const isInitial = p.status === WEBUIGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1462
|
+
_webuigovCheckP(p.status, WEBUIGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1463
|
+
if (isInitial && _webuigovCountActive(p.owner) >= _webuigovMaxActive)
|
|
1464
|
+
throw new Error(
|
|
1465
|
+
`max active webuigov profiles for owner ${p.owner} reached`,
|
|
1466
|
+
);
|
|
1467
|
+
const now = Date.now();
|
|
1468
|
+
p.status = WEBUIGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1469
|
+
p.updatedAt = now;
|
|
1470
|
+
p.lastTouchedAt = now;
|
|
1471
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1472
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1473
|
+
}
|
|
1474
|
+
export function degradeWebuigovProfileV2(id) {
|
|
1475
|
+
const p = _webuigovPsV2.get(id);
|
|
1476
|
+
if (!p) throw new Error(`webuigov profile ${id} not found`);
|
|
1477
|
+
_webuigovCheckP(p.status, WEBUIGOV_PROFILE_MATURITY_V2.DEGRADED);
|
|
1478
|
+
p.status = WEBUIGOV_PROFILE_MATURITY_V2.DEGRADED;
|
|
1479
|
+
p.updatedAt = Date.now();
|
|
1480
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1481
|
+
}
|
|
1482
|
+
export function archiveWebuigovProfileV2(id) {
|
|
1483
|
+
const p = _webuigovPsV2.get(id);
|
|
1484
|
+
if (!p) throw new Error(`webuigov profile ${id} not found`);
|
|
1485
|
+
_webuigovCheckP(p.status, WEBUIGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1486
|
+
const now = Date.now();
|
|
1487
|
+
p.status = WEBUIGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1488
|
+
p.updatedAt = now;
|
|
1489
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1490
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1491
|
+
}
|
|
1492
|
+
export function touchWebuigovProfileV2(id) {
|
|
1493
|
+
const p = _webuigovPsV2.get(id);
|
|
1494
|
+
if (!p) throw new Error(`webuigov profile ${id} not found`);
|
|
1495
|
+
if (_webuigovPTerminal.has(p.status))
|
|
1496
|
+
throw new Error(`cannot touch terminal webuigov profile ${id}`);
|
|
1497
|
+
const now = Date.now();
|
|
1498
|
+
p.lastTouchedAt = now;
|
|
1499
|
+
p.updatedAt = now;
|
|
1500
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1501
|
+
}
|
|
1502
|
+
export function getWebuigovProfileV2(id) {
|
|
1503
|
+
const p = _webuigovPsV2.get(id);
|
|
1504
|
+
if (!p) return null;
|
|
1505
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1506
|
+
}
|
|
1507
|
+
export function listWebuigovProfilesV2() {
|
|
1508
|
+
return [..._webuigovPsV2.values()].map((p) => ({
|
|
1509
|
+
...p,
|
|
1510
|
+
metadata: { ...p.metadata },
|
|
1511
|
+
}));
|
|
1512
|
+
}
|
|
1513
|
+
export function createWebuigovRequestV2({
|
|
1514
|
+
id,
|
|
1515
|
+
profileId,
|
|
1516
|
+
method,
|
|
1517
|
+
metadata,
|
|
1518
|
+
} = {}) {
|
|
1519
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1520
|
+
if (_webuigovJsV2.has(id))
|
|
1521
|
+
throw new Error(`webuigov request ${id} already exists`);
|
|
1522
|
+
if (!_webuigovPsV2.has(profileId))
|
|
1523
|
+
throw new Error(`webuigov profile ${profileId} not found`);
|
|
1524
|
+
if (_webuigovCountPending(profileId) >= _webuigovMaxPending)
|
|
1525
|
+
throw new Error(
|
|
1526
|
+
`max pending webuigov requests for profile ${profileId} reached`,
|
|
1527
|
+
);
|
|
1528
|
+
const now = Date.now();
|
|
1529
|
+
const j = {
|
|
1530
|
+
id,
|
|
1531
|
+
profileId,
|
|
1532
|
+
method: method || "",
|
|
1533
|
+
status: WEBUIGOV_REQUEST_LIFECYCLE_V2.QUEUED,
|
|
1534
|
+
createdAt: now,
|
|
1535
|
+
updatedAt: now,
|
|
1536
|
+
startedAt: null,
|
|
1537
|
+
settledAt: null,
|
|
1538
|
+
metadata: { ...(metadata || {}) },
|
|
1539
|
+
};
|
|
1540
|
+
_webuigovJsV2.set(id, j);
|
|
1541
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1542
|
+
}
|
|
1543
|
+
export function servingWebuigovRequestV2(id) {
|
|
1544
|
+
const j = _webuigovJsV2.get(id);
|
|
1545
|
+
if (!j) throw new Error(`webuigov request ${id} not found`);
|
|
1546
|
+
_webuigovCheckJ(j.status, WEBUIGOV_REQUEST_LIFECYCLE_V2.SERVING);
|
|
1547
|
+
const now = Date.now();
|
|
1548
|
+
j.status = WEBUIGOV_REQUEST_LIFECYCLE_V2.SERVING;
|
|
1549
|
+
j.updatedAt = now;
|
|
1550
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1551
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1552
|
+
}
|
|
1553
|
+
export function completeRequestWebuigovV2(id) {
|
|
1554
|
+
const j = _webuigovJsV2.get(id);
|
|
1555
|
+
if (!j) throw new Error(`webuigov request ${id} not found`);
|
|
1556
|
+
_webuigovCheckJ(j.status, WEBUIGOV_REQUEST_LIFECYCLE_V2.SERVED);
|
|
1557
|
+
const now = Date.now();
|
|
1558
|
+
j.status = WEBUIGOV_REQUEST_LIFECYCLE_V2.SERVED;
|
|
1559
|
+
j.updatedAt = now;
|
|
1560
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1561
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1562
|
+
}
|
|
1563
|
+
export function failWebuigovRequestV2(id, reason) {
|
|
1564
|
+
const j = _webuigovJsV2.get(id);
|
|
1565
|
+
if (!j) throw new Error(`webuigov request ${id} not found`);
|
|
1566
|
+
_webuigovCheckJ(j.status, WEBUIGOV_REQUEST_LIFECYCLE_V2.FAILED);
|
|
1567
|
+
const now = Date.now();
|
|
1568
|
+
j.status = WEBUIGOV_REQUEST_LIFECYCLE_V2.FAILED;
|
|
1569
|
+
j.updatedAt = now;
|
|
1570
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1571
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1572
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1573
|
+
}
|
|
1574
|
+
export function cancelWebuigovRequestV2(id, reason) {
|
|
1575
|
+
const j = _webuigovJsV2.get(id);
|
|
1576
|
+
if (!j) throw new Error(`webuigov request ${id} not found`);
|
|
1577
|
+
_webuigovCheckJ(j.status, WEBUIGOV_REQUEST_LIFECYCLE_V2.CANCELLED);
|
|
1578
|
+
const now = Date.now();
|
|
1579
|
+
j.status = WEBUIGOV_REQUEST_LIFECYCLE_V2.CANCELLED;
|
|
1580
|
+
j.updatedAt = now;
|
|
1581
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1582
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1583
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1584
|
+
}
|
|
1585
|
+
export function getWebuigovRequestV2(id) {
|
|
1586
|
+
const j = _webuigovJsV2.get(id);
|
|
1587
|
+
if (!j) return null;
|
|
1588
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1589
|
+
}
|
|
1590
|
+
export function listWebuigovRequestsV2() {
|
|
1591
|
+
return [..._webuigovJsV2.values()].map((j) => ({
|
|
1592
|
+
...j,
|
|
1593
|
+
metadata: { ...j.metadata },
|
|
1594
|
+
}));
|
|
1595
|
+
}
|
|
1596
|
+
export function autoDegradeIdleWebuigovProfilesV2({ now } = {}) {
|
|
1597
|
+
const t = now ?? Date.now();
|
|
1598
|
+
const flipped = [];
|
|
1599
|
+
for (const p of _webuigovPsV2.values())
|
|
1600
|
+
if (
|
|
1601
|
+
p.status === WEBUIGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1602
|
+
t - p.lastTouchedAt >= _webuigovIdleMs
|
|
1603
|
+
) {
|
|
1604
|
+
p.status = WEBUIGOV_PROFILE_MATURITY_V2.DEGRADED;
|
|
1605
|
+
p.updatedAt = t;
|
|
1606
|
+
flipped.push(p.id);
|
|
1607
|
+
}
|
|
1608
|
+
return { flipped, count: flipped.length };
|
|
1609
|
+
}
|
|
1610
|
+
export function autoFailStuckWebuigovRequestsV2({ now } = {}) {
|
|
1611
|
+
const t = now ?? Date.now();
|
|
1612
|
+
const flipped = [];
|
|
1613
|
+
for (const j of _webuigovJsV2.values())
|
|
1614
|
+
if (
|
|
1615
|
+
j.status === WEBUIGOV_REQUEST_LIFECYCLE_V2.SERVING &&
|
|
1616
|
+
j.startedAt != null &&
|
|
1617
|
+
t - j.startedAt >= _webuigovStuckMs
|
|
1618
|
+
) {
|
|
1619
|
+
j.status = WEBUIGOV_REQUEST_LIFECYCLE_V2.FAILED;
|
|
1620
|
+
j.updatedAt = t;
|
|
1621
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1622
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1623
|
+
flipped.push(j.id);
|
|
1624
|
+
}
|
|
1625
|
+
return { flipped, count: flipped.length };
|
|
1626
|
+
}
|
|
1627
|
+
export function getWebUiServerGovStatsV2() {
|
|
1628
|
+
const profilesByStatus = {};
|
|
1629
|
+
for (const v of Object.values(WEBUIGOV_PROFILE_MATURITY_V2))
|
|
1630
|
+
profilesByStatus[v] = 0;
|
|
1631
|
+
for (const p of _webuigovPsV2.values()) profilesByStatus[p.status]++;
|
|
1632
|
+
const requestsByStatus = {};
|
|
1633
|
+
for (const v of Object.values(WEBUIGOV_REQUEST_LIFECYCLE_V2))
|
|
1634
|
+
requestsByStatus[v] = 0;
|
|
1635
|
+
for (const j of _webuigovJsV2.values()) requestsByStatus[j.status]++;
|
|
1636
|
+
return {
|
|
1637
|
+
totalWebuigovProfilesV2: _webuigovPsV2.size,
|
|
1638
|
+
totalWebuigovRequestsV2: _webuigovJsV2.size,
|
|
1639
|
+
maxActiveWebuigovProfilesPerOwner: _webuigovMaxActive,
|
|
1640
|
+
maxPendingWebuigovRequestsPerProfile: _webuigovMaxPending,
|
|
1641
|
+
webuigovProfileIdleMs: _webuigovIdleMs,
|
|
1642
|
+
webuigovRequestStuckMs: _webuigovStuckMs,
|
|
1643
|
+
profilesByStatus,
|
|
1644
|
+
requestsByStatus,
|
|
1645
|
+
};
|
|
1646
|
+
}
|