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/org-manager.js
CHANGED
|
@@ -745,3 +745,339 @@ export function _resetStateOrgManagerV2() {
|
|
|
745
745
|
_orgIdleMsV2 = ORG_DEFAULT_ORG_IDLE_MS;
|
|
746
746
|
_inviteStaleMsV2 = ORG_DEFAULT_INVITE_STALE_MS;
|
|
747
747
|
}
|
|
748
|
+
|
|
749
|
+
// =====================================================================
|
|
750
|
+
// org-manager V2 governance overlay (iter19)
|
|
751
|
+
// =====================================================================
|
|
752
|
+
export const ORGGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
753
|
+
PENDING: "pending",
|
|
754
|
+
ACTIVE: "active",
|
|
755
|
+
PAUSED: "paused",
|
|
756
|
+
ARCHIVED: "archived",
|
|
757
|
+
});
|
|
758
|
+
export const ORGGOV_INVITE_LIFECYCLE_V2 = Object.freeze({
|
|
759
|
+
QUEUED: "queued",
|
|
760
|
+
INVITING: "inviting",
|
|
761
|
+
INVITED: "invited",
|
|
762
|
+
FAILED: "failed",
|
|
763
|
+
CANCELLED: "cancelled",
|
|
764
|
+
});
|
|
765
|
+
const _orggovPTrans = new Map([
|
|
766
|
+
[
|
|
767
|
+
ORGGOV_PROFILE_MATURITY_V2.PENDING,
|
|
768
|
+
new Set([
|
|
769
|
+
ORGGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
770
|
+
ORGGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
771
|
+
]),
|
|
772
|
+
],
|
|
773
|
+
[
|
|
774
|
+
ORGGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
775
|
+
new Set([
|
|
776
|
+
ORGGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
777
|
+
ORGGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
778
|
+
]),
|
|
779
|
+
],
|
|
780
|
+
[
|
|
781
|
+
ORGGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
782
|
+
new Set([
|
|
783
|
+
ORGGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
784
|
+
ORGGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
785
|
+
]),
|
|
786
|
+
],
|
|
787
|
+
[ORGGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
788
|
+
]);
|
|
789
|
+
const _orggovPTerminal = new Set([ORGGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
790
|
+
const _orggovJTrans = new Map([
|
|
791
|
+
[
|
|
792
|
+
ORGGOV_INVITE_LIFECYCLE_V2.QUEUED,
|
|
793
|
+
new Set([
|
|
794
|
+
ORGGOV_INVITE_LIFECYCLE_V2.INVITING,
|
|
795
|
+
ORGGOV_INVITE_LIFECYCLE_V2.CANCELLED,
|
|
796
|
+
]),
|
|
797
|
+
],
|
|
798
|
+
[
|
|
799
|
+
ORGGOV_INVITE_LIFECYCLE_V2.INVITING,
|
|
800
|
+
new Set([
|
|
801
|
+
ORGGOV_INVITE_LIFECYCLE_V2.INVITED,
|
|
802
|
+
ORGGOV_INVITE_LIFECYCLE_V2.FAILED,
|
|
803
|
+
ORGGOV_INVITE_LIFECYCLE_V2.CANCELLED,
|
|
804
|
+
]),
|
|
805
|
+
],
|
|
806
|
+
[ORGGOV_INVITE_LIFECYCLE_V2.INVITED, new Set()],
|
|
807
|
+
[ORGGOV_INVITE_LIFECYCLE_V2.FAILED, new Set()],
|
|
808
|
+
[ORGGOV_INVITE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
809
|
+
]);
|
|
810
|
+
const _orggovPsV2 = new Map();
|
|
811
|
+
const _orggovJsV2 = new Map();
|
|
812
|
+
let _orggovMaxActive = 6,
|
|
813
|
+
_orggovMaxPending = 30,
|
|
814
|
+
_orggovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
815
|
+
_orggovStuckMs = 60 * 1000;
|
|
816
|
+
function _orggovPos(n, label) {
|
|
817
|
+
const v = Math.floor(Number(n));
|
|
818
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
819
|
+
throw new Error(`${label} must be positive integer`);
|
|
820
|
+
return v;
|
|
821
|
+
}
|
|
822
|
+
function _orggovCheckP(from, to) {
|
|
823
|
+
const a = _orggovPTrans.get(from);
|
|
824
|
+
if (!a || !a.has(to))
|
|
825
|
+
throw new Error(`invalid orggov profile transition ${from} → ${to}`);
|
|
826
|
+
}
|
|
827
|
+
function _orggovCheckJ(from, to) {
|
|
828
|
+
const a = _orggovJTrans.get(from);
|
|
829
|
+
if (!a || !a.has(to))
|
|
830
|
+
throw new Error(`invalid orggov invite transition ${from} → ${to}`);
|
|
831
|
+
}
|
|
832
|
+
function _orggovCountActive(owner) {
|
|
833
|
+
let c = 0;
|
|
834
|
+
for (const p of _orggovPsV2.values())
|
|
835
|
+
if (p.owner === owner && p.status === ORGGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
836
|
+
c++;
|
|
837
|
+
return c;
|
|
838
|
+
}
|
|
839
|
+
function _orggovCountPending(profileId) {
|
|
840
|
+
let c = 0;
|
|
841
|
+
for (const j of _orggovJsV2.values())
|
|
842
|
+
if (
|
|
843
|
+
j.profileId === profileId &&
|
|
844
|
+
(j.status === ORGGOV_INVITE_LIFECYCLE_V2.QUEUED ||
|
|
845
|
+
j.status === ORGGOV_INVITE_LIFECYCLE_V2.INVITING)
|
|
846
|
+
)
|
|
847
|
+
c++;
|
|
848
|
+
return c;
|
|
849
|
+
}
|
|
850
|
+
export function setMaxActiveOrggovProfilesPerOwnerV2(n) {
|
|
851
|
+
_orggovMaxActive = _orggovPos(n, "maxActiveOrggovProfilesPerOwner");
|
|
852
|
+
}
|
|
853
|
+
export function getMaxActiveOrggovProfilesPerOwnerV2() {
|
|
854
|
+
return _orggovMaxActive;
|
|
855
|
+
}
|
|
856
|
+
export function setMaxPendingOrggovInvitesPerProfileV2(n) {
|
|
857
|
+
_orggovMaxPending = _orggovPos(n, "maxPendingOrggovInvitesPerProfile");
|
|
858
|
+
}
|
|
859
|
+
export function getMaxPendingOrggovInvitesPerProfileV2() {
|
|
860
|
+
return _orggovMaxPending;
|
|
861
|
+
}
|
|
862
|
+
export function setOrggovProfileIdleMsV2(n) {
|
|
863
|
+
_orggovIdleMs = _orggovPos(n, "orggovProfileIdleMs");
|
|
864
|
+
}
|
|
865
|
+
export function getOrggovProfileIdleMsV2() {
|
|
866
|
+
return _orggovIdleMs;
|
|
867
|
+
}
|
|
868
|
+
export function setOrggovInviteStuckMsV2(n) {
|
|
869
|
+
_orggovStuckMs = _orggovPos(n, "orggovInviteStuckMs");
|
|
870
|
+
}
|
|
871
|
+
export function getOrggovInviteStuckMsV2() {
|
|
872
|
+
return _orggovStuckMs;
|
|
873
|
+
}
|
|
874
|
+
export function _resetStateOrgManagerGovV2() {
|
|
875
|
+
_orggovPsV2.clear();
|
|
876
|
+
_orggovJsV2.clear();
|
|
877
|
+
_orggovMaxActive = 6;
|
|
878
|
+
_orggovMaxPending = 30;
|
|
879
|
+
_orggovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
880
|
+
_orggovStuckMs = 60 * 1000;
|
|
881
|
+
}
|
|
882
|
+
export function registerOrggovProfileV2({ id, owner, tier, metadata } = {}) {
|
|
883
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
884
|
+
if (_orggovPsV2.has(id))
|
|
885
|
+
throw new Error(`orggov profile ${id} already exists`);
|
|
886
|
+
const now = Date.now();
|
|
887
|
+
const p = {
|
|
888
|
+
id,
|
|
889
|
+
owner,
|
|
890
|
+
tier: tier || "standard",
|
|
891
|
+
status: ORGGOV_PROFILE_MATURITY_V2.PENDING,
|
|
892
|
+
createdAt: now,
|
|
893
|
+
updatedAt: now,
|
|
894
|
+
lastTouchedAt: now,
|
|
895
|
+
activatedAt: null,
|
|
896
|
+
archivedAt: null,
|
|
897
|
+
metadata: { ...(metadata || {}) },
|
|
898
|
+
};
|
|
899
|
+
_orggovPsV2.set(id, p);
|
|
900
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
901
|
+
}
|
|
902
|
+
export function activateOrggovProfileV2(id) {
|
|
903
|
+
const p = _orggovPsV2.get(id);
|
|
904
|
+
if (!p) throw new Error(`orggov profile ${id} not found`);
|
|
905
|
+
const isInitial = p.status === ORGGOV_PROFILE_MATURITY_V2.PENDING;
|
|
906
|
+
_orggovCheckP(p.status, ORGGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
907
|
+
if (isInitial && _orggovCountActive(p.owner) >= _orggovMaxActive)
|
|
908
|
+
throw new Error(`max active orggov profiles for owner ${p.owner} reached`);
|
|
909
|
+
const now = Date.now();
|
|
910
|
+
p.status = ORGGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
911
|
+
p.updatedAt = now;
|
|
912
|
+
p.lastTouchedAt = now;
|
|
913
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
914
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
915
|
+
}
|
|
916
|
+
export function pauseOrggovProfileV2(id) {
|
|
917
|
+
const p = _orggovPsV2.get(id);
|
|
918
|
+
if (!p) throw new Error(`orggov profile ${id} not found`);
|
|
919
|
+
_orggovCheckP(p.status, ORGGOV_PROFILE_MATURITY_V2.PAUSED);
|
|
920
|
+
p.status = ORGGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
921
|
+
p.updatedAt = Date.now();
|
|
922
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
923
|
+
}
|
|
924
|
+
export function archiveOrggovProfileV2(id) {
|
|
925
|
+
const p = _orggovPsV2.get(id);
|
|
926
|
+
if (!p) throw new Error(`orggov profile ${id} not found`);
|
|
927
|
+
_orggovCheckP(p.status, ORGGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
928
|
+
const now = Date.now();
|
|
929
|
+
p.status = ORGGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
930
|
+
p.updatedAt = now;
|
|
931
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
932
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
933
|
+
}
|
|
934
|
+
export function touchOrggovProfileV2(id) {
|
|
935
|
+
const p = _orggovPsV2.get(id);
|
|
936
|
+
if (!p) throw new Error(`orggov profile ${id} not found`);
|
|
937
|
+
if (_orggovPTerminal.has(p.status))
|
|
938
|
+
throw new Error(`cannot touch terminal orggov profile ${id}`);
|
|
939
|
+
const now = Date.now();
|
|
940
|
+
p.lastTouchedAt = now;
|
|
941
|
+
p.updatedAt = now;
|
|
942
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
943
|
+
}
|
|
944
|
+
export function getOrggovProfileV2(id) {
|
|
945
|
+
const p = _orggovPsV2.get(id);
|
|
946
|
+
if (!p) return null;
|
|
947
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
948
|
+
}
|
|
949
|
+
export function listOrggovProfilesV2() {
|
|
950
|
+
return [..._orggovPsV2.values()].map((p) => ({
|
|
951
|
+
...p,
|
|
952
|
+
metadata: { ...p.metadata },
|
|
953
|
+
}));
|
|
954
|
+
}
|
|
955
|
+
export function createOrggovInviteV2({ id, profileId, email, metadata } = {}) {
|
|
956
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
957
|
+
if (_orggovJsV2.has(id))
|
|
958
|
+
throw new Error(`orggov invite ${id} already exists`);
|
|
959
|
+
if (!_orggovPsV2.has(profileId))
|
|
960
|
+
throw new Error(`orggov profile ${profileId} not found`);
|
|
961
|
+
if (_orggovCountPending(profileId) >= _orggovMaxPending)
|
|
962
|
+
throw new Error(
|
|
963
|
+
`max pending orggov invites for profile ${profileId} reached`,
|
|
964
|
+
);
|
|
965
|
+
const now = Date.now();
|
|
966
|
+
const j = {
|
|
967
|
+
id,
|
|
968
|
+
profileId,
|
|
969
|
+
email: email || "",
|
|
970
|
+
status: ORGGOV_INVITE_LIFECYCLE_V2.QUEUED,
|
|
971
|
+
createdAt: now,
|
|
972
|
+
updatedAt: now,
|
|
973
|
+
startedAt: null,
|
|
974
|
+
settledAt: null,
|
|
975
|
+
metadata: { ...(metadata || {}) },
|
|
976
|
+
};
|
|
977
|
+
_orggovJsV2.set(id, j);
|
|
978
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
979
|
+
}
|
|
980
|
+
export function invitingOrggovInviteV2(id) {
|
|
981
|
+
const j = _orggovJsV2.get(id);
|
|
982
|
+
if (!j) throw new Error(`orggov invite ${id} not found`);
|
|
983
|
+
_orggovCheckJ(j.status, ORGGOV_INVITE_LIFECYCLE_V2.INVITING);
|
|
984
|
+
const now = Date.now();
|
|
985
|
+
j.status = ORGGOV_INVITE_LIFECYCLE_V2.INVITING;
|
|
986
|
+
j.updatedAt = now;
|
|
987
|
+
if (!j.startedAt) j.startedAt = now;
|
|
988
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
989
|
+
}
|
|
990
|
+
export function completeInviteOrggovV2(id) {
|
|
991
|
+
const j = _orggovJsV2.get(id);
|
|
992
|
+
if (!j) throw new Error(`orggov invite ${id} not found`);
|
|
993
|
+
_orggovCheckJ(j.status, ORGGOV_INVITE_LIFECYCLE_V2.INVITED);
|
|
994
|
+
const now = Date.now();
|
|
995
|
+
j.status = ORGGOV_INVITE_LIFECYCLE_V2.INVITED;
|
|
996
|
+
j.updatedAt = now;
|
|
997
|
+
if (!j.settledAt) j.settledAt = now;
|
|
998
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
999
|
+
}
|
|
1000
|
+
export function failOrggovInviteV2(id, reason) {
|
|
1001
|
+
const j = _orggovJsV2.get(id);
|
|
1002
|
+
if (!j) throw new Error(`orggov invite ${id} not found`);
|
|
1003
|
+
_orggovCheckJ(j.status, ORGGOV_INVITE_LIFECYCLE_V2.FAILED);
|
|
1004
|
+
const now = Date.now();
|
|
1005
|
+
j.status = ORGGOV_INVITE_LIFECYCLE_V2.FAILED;
|
|
1006
|
+
j.updatedAt = now;
|
|
1007
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1008
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1009
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1010
|
+
}
|
|
1011
|
+
export function cancelOrggovInviteV2(id, reason) {
|
|
1012
|
+
const j = _orggovJsV2.get(id);
|
|
1013
|
+
if (!j) throw new Error(`orggov invite ${id} not found`);
|
|
1014
|
+
_orggovCheckJ(j.status, ORGGOV_INVITE_LIFECYCLE_V2.CANCELLED);
|
|
1015
|
+
const now = Date.now();
|
|
1016
|
+
j.status = ORGGOV_INVITE_LIFECYCLE_V2.CANCELLED;
|
|
1017
|
+
j.updatedAt = now;
|
|
1018
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1019
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1020
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1021
|
+
}
|
|
1022
|
+
export function getOrggovInviteV2(id) {
|
|
1023
|
+
const j = _orggovJsV2.get(id);
|
|
1024
|
+
if (!j) return null;
|
|
1025
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1026
|
+
}
|
|
1027
|
+
export function listOrggovInvitesV2() {
|
|
1028
|
+
return [..._orggovJsV2.values()].map((j) => ({
|
|
1029
|
+
...j,
|
|
1030
|
+
metadata: { ...j.metadata },
|
|
1031
|
+
}));
|
|
1032
|
+
}
|
|
1033
|
+
export function autoPauseIdleOrggovProfilesV2({ now } = {}) {
|
|
1034
|
+
const t = now ?? Date.now();
|
|
1035
|
+
const flipped = [];
|
|
1036
|
+
for (const p of _orggovPsV2.values())
|
|
1037
|
+
if (
|
|
1038
|
+
p.status === ORGGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1039
|
+
t - p.lastTouchedAt >= _orggovIdleMs
|
|
1040
|
+
) {
|
|
1041
|
+
p.status = ORGGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
1042
|
+
p.updatedAt = t;
|
|
1043
|
+
flipped.push(p.id);
|
|
1044
|
+
}
|
|
1045
|
+
return { flipped, count: flipped.length };
|
|
1046
|
+
}
|
|
1047
|
+
export function autoFailStuckOrggovInvitesV2({ now } = {}) {
|
|
1048
|
+
const t = now ?? Date.now();
|
|
1049
|
+
const flipped = [];
|
|
1050
|
+
for (const j of _orggovJsV2.values())
|
|
1051
|
+
if (
|
|
1052
|
+
j.status === ORGGOV_INVITE_LIFECYCLE_V2.INVITING &&
|
|
1053
|
+
j.startedAt != null &&
|
|
1054
|
+
t - j.startedAt >= _orggovStuckMs
|
|
1055
|
+
) {
|
|
1056
|
+
j.status = ORGGOV_INVITE_LIFECYCLE_V2.FAILED;
|
|
1057
|
+
j.updatedAt = t;
|
|
1058
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1059
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1060
|
+
flipped.push(j.id);
|
|
1061
|
+
}
|
|
1062
|
+
return { flipped, count: flipped.length };
|
|
1063
|
+
}
|
|
1064
|
+
export function getOrgManagerGovStatsV2() {
|
|
1065
|
+
const profilesByStatus = {};
|
|
1066
|
+
for (const v of Object.values(ORGGOV_PROFILE_MATURITY_V2))
|
|
1067
|
+
profilesByStatus[v] = 0;
|
|
1068
|
+
for (const p of _orggovPsV2.values()) profilesByStatus[p.status]++;
|
|
1069
|
+
const invitesByStatus = {};
|
|
1070
|
+
for (const v of Object.values(ORGGOV_INVITE_LIFECYCLE_V2))
|
|
1071
|
+
invitesByStatus[v] = 0;
|
|
1072
|
+
for (const j of _orggovJsV2.values()) invitesByStatus[j.status]++;
|
|
1073
|
+
return {
|
|
1074
|
+
totalOrggovProfilesV2: _orggovPsV2.size,
|
|
1075
|
+
totalOrggovInvitesV2: _orggovJsV2.size,
|
|
1076
|
+
maxActiveOrggovProfilesPerOwner: _orggovMaxActive,
|
|
1077
|
+
maxPendingOrggovInvitesPerProfile: _orggovMaxPending,
|
|
1078
|
+
orggovProfileIdleMs: _orggovIdleMs,
|
|
1079
|
+
orggovInviteStuckMs: _orggovStuckMs,
|
|
1080
|
+
profilesByStatus,
|
|
1081
|
+
invitesByStatus,
|
|
1082
|
+
};
|
|
1083
|
+
}
|
package/src/lib/p2p-manager.js
CHANGED
|
@@ -702,3 +702,344 @@ export function _resetStateP2pManagerV2() {
|
|
|
702
702
|
_stateP2pV2.peerIdleMs = PEER_DEFAULT_PEER_IDLE_MS;
|
|
703
703
|
_stateP2pV2.messageStuckMs = PEER_DEFAULT_MESSAGE_STUCK_MS;
|
|
704
704
|
}
|
|
705
|
+
|
|
706
|
+
// =====================================================================
|
|
707
|
+
// p2p-manager V2 governance overlay (iter20)
|
|
708
|
+
// =====================================================================
|
|
709
|
+
export const P2PGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
710
|
+
PENDING: "pending",
|
|
711
|
+
ACTIVE: "active",
|
|
712
|
+
SUSPENDED: "suspended",
|
|
713
|
+
ARCHIVED: "archived",
|
|
714
|
+
});
|
|
715
|
+
export const P2PGOV_GOSSIP_LIFECYCLE_V2 = Object.freeze({
|
|
716
|
+
QUEUED: "queued",
|
|
717
|
+
BROADCASTING: "broadcasting",
|
|
718
|
+
BROADCAST: "broadcast",
|
|
719
|
+
FAILED: "failed",
|
|
720
|
+
CANCELLED: "cancelled",
|
|
721
|
+
});
|
|
722
|
+
const _p2pgovPTrans = new Map([
|
|
723
|
+
[
|
|
724
|
+
P2PGOV_PROFILE_MATURITY_V2.PENDING,
|
|
725
|
+
new Set([
|
|
726
|
+
P2PGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
727
|
+
P2PGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
728
|
+
]),
|
|
729
|
+
],
|
|
730
|
+
[
|
|
731
|
+
P2PGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
732
|
+
new Set([
|
|
733
|
+
P2PGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
734
|
+
P2PGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
735
|
+
]),
|
|
736
|
+
],
|
|
737
|
+
[
|
|
738
|
+
P2PGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
739
|
+
new Set([
|
|
740
|
+
P2PGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
741
|
+
P2PGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
742
|
+
]),
|
|
743
|
+
],
|
|
744
|
+
[P2PGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
745
|
+
]);
|
|
746
|
+
const _p2pgovPTerminal = new Set([P2PGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
747
|
+
const _p2pgovJTrans = new Map([
|
|
748
|
+
[
|
|
749
|
+
P2PGOV_GOSSIP_LIFECYCLE_V2.QUEUED,
|
|
750
|
+
new Set([
|
|
751
|
+
P2PGOV_GOSSIP_LIFECYCLE_V2.BROADCASTING,
|
|
752
|
+
P2PGOV_GOSSIP_LIFECYCLE_V2.CANCELLED,
|
|
753
|
+
]),
|
|
754
|
+
],
|
|
755
|
+
[
|
|
756
|
+
P2PGOV_GOSSIP_LIFECYCLE_V2.BROADCASTING,
|
|
757
|
+
new Set([
|
|
758
|
+
P2PGOV_GOSSIP_LIFECYCLE_V2.BROADCAST,
|
|
759
|
+
P2PGOV_GOSSIP_LIFECYCLE_V2.FAILED,
|
|
760
|
+
P2PGOV_GOSSIP_LIFECYCLE_V2.CANCELLED,
|
|
761
|
+
]),
|
|
762
|
+
],
|
|
763
|
+
[P2PGOV_GOSSIP_LIFECYCLE_V2.BROADCAST, new Set()],
|
|
764
|
+
[P2PGOV_GOSSIP_LIFECYCLE_V2.FAILED, new Set()],
|
|
765
|
+
[P2PGOV_GOSSIP_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
766
|
+
]);
|
|
767
|
+
const _p2pgovPsV2 = new Map();
|
|
768
|
+
const _p2pgovJsV2 = new Map();
|
|
769
|
+
let _p2pgovMaxActive = 12,
|
|
770
|
+
_p2pgovMaxPending = 30,
|
|
771
|
+
_p2pgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
772
|
+
_p2pgovStuckMs = 60 * 1000;
|
|
773
|
+
function _p2pgovPos(n, label) {
|
|
774
|
+
const v = Math.floor(Number(n));
|
|
775
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
776
|
+
throw new Error(`${label} must be positive integer`);
|
|
777
|
+
return v;
|
|
778
|
+
}
|
|
779
|
+
function _p2pgovCheckP(from, to) {
|
|
780
|
+
const a = _p2pgovPTrans.get(from);
|
|
781
|
+
if (!a || !a.has(to))
|
|
782
|
+
throw new Error(`invalid p2pgov profile transition ${from} → ${to}`);
|
|
783
|
+
}
|
|
784
|
+
function _p2pgovCheckJ(from, to) {
|
|
785
|
+
const a = _p2pgovJTrans.get(from);
|
|
786
|
+
if (!a || !a.has(to))
|
|
787
|
+
throw new Error(`invalid p2pgov gossip transition ${from} → ${to}`);
|
|
788
|
+
}
|
|
789
|
+
function _p2pgovCountActive(owner) {
|
|
790
|
+
let c = 0;
|
|
791
|
+
for (const p of _p2pgovPsV2.values())
|
|
792
|
+
if (p.owner === owner && p.status === P2PGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
793
|
+
c++;
|
|
794
|
+
return c;
|
|
795
|
+
}
|
|
796
|
+
function _p2pgovCountPending(profileId) {
|
|
797
|
+
let c = 0;
|
|
798
|
+
for (const j of _p2pgovJsV2.values())
|
|
799
|
+
if (
|
|
800
|
+
j.profileId === profileId &&
|
|
801
|
+
(j.status === P2PGOV_GOSSIP_LIFECYCLE_V2.QUEUED ||
|
|
802
|
+
j.status === P2PGOV_GOSSIP_LIFECYCLE_V2.BROADCASTING)
|
|
803
|
+
)
|
|
804
|
+
c++;
|
|
805
|
+
return c;
|
|
806
|
+
}
|
|
807
|
+
export function setMaxActiveP2pgovProfilesPerOwnerV2(n) {
|
|
808
|
+
_p2pgovMaxActive = _p2pgovPos(n, "maxActiveP2pgovProfilesPerOwner");
|
|
809
|
+
}
|
|
810
|
+
export function getMaxActiveP2pgovProfilesPerOwnerV2() {
|
|
811
|
+
return _p2pgovMaxActive;
|
|
812
|
+
}
|
|
813
|
+
export function setMaxPendingP2pgovGossipsPerProfileV2(n) {
|
|
814
|
+
_p2pgovMaxPending = _p2pgovPos(n, "maxPendingP2pgovGossipsPerProfile");
|
|
815
|
+
}
|
|
816
|
+
export function getMaxPendingP2pgovGossipsPerProfileV2() {
|
|
817
|
+
return _p2pgovMaxPending;
|
|
818
|
+
}
|
|
819
|
+
export function setP2pgovProfileIdleMsV2(n) {
|
|
820
|
+
_p2pgovIdleMs = _p2pgovPos(n, "p2pgovProfileIdleMs");
|
|
821
|
+
}
|
|
822
|
+
export function getP2pgovProfileIdleMsV2() {
|
|
823
|
+
return _p2pgovIdleMs;
|
|
824
|
+
}
|
|
825
|
+
export function setP2pgovGossipStuckMsV2(n) {
|
|
826
|
+
_p2pgovStuckMs = _p2pgovPos(n, "p2pgovGossipStuckMs");
|
|
827
|
+
}
|
|
828
|
+
export function getP2pgovGossipStuckMsV2() {
|
|
829
|
+
return _p2pgovStuckMs;
|
|
830
|
+
}
|
|
831
|
+
export function _resetStateP2pManagerGovV2() {
|
|
832
|
+
_p2pgovPsV2.clear();
|
|
833
|
+
_p2pgovJsV2.clear();
|
|
834
|
+
_p2pgovMaxActive = 12;
|
|
835
|
+
_p2pgovMaxPending = 30;
|
|
836
|
+
_p2pgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
837
|
+
_p2pgovStuckMs = 60 * 1000;
|
|
838
|
+
}
|
|
839
|
+
export function registerP2pgovProfileV2({
|
|
840
|
+
id,
|
|
841
|
+
owner,
|
|
842
|
+
transport,
|
|
843
|
+
metadata,
|
|
844
|
+
} = {}) {
|
|
845
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
846
|
+
if (_p2pgovPsV2.has(id))
|
|
847
|
+
throw new Error(`p2pgov profile ${id} already exists`);
|
|
848
|
+
const now = Date.now();
|
|
849
|
+
const p = {
|
|
850
|
+
id,
|
|
851
|
+
owner,
|
|
852
|
+
transport: transport || "tcp",
|
|
853
|
+
status: P2PGOV_PROFILE_MATURITY_V2.PENDING,
|
|
854
|
+
createdAt: now,
|
|
855
|
+
updatedAt: now,
|
|
856
|
+
lastTouchedAt: now,
|
|
857
|
+
activatedAt: null,
|
|
858
|
+
archivedAt: null,
|
|
859
|
+
metadata: { ...(metadata || {}) },
|
|
860
|
+
};
|
|
861
|
+
_p2pgovPsV2.set(id, p);
|
|
862
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
863
|
+
}
|
|
864
|
+
export function activateP2pgovProfileV2(id) {
|
|
865
|
+
const p = _p2pgovPsV2.get(id);
|
|
866
|
+
if (!p) throw new Error(`p2pgov profile ${id} not found`);
|
|
867
|
+
const isInitial = p.status === P2PGOV_PROFILE_MATURITY_V2.PENDING;
|
|
868
|
+
_p2pgovCheckP(p.status, P2PGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
869
|
+
if (isInitial && _p2pgovCountActive(p.owner) >= _p2pgovMaxActive)
|
|
870
|
+
throw new Error(`max active p2pgov profiles for owner ${p.owner} reached`);
|
|
871
|
+
const now = Date.now();
|
|
872
|
+
p.status = P2PGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
873
|
+
p.updatedAt = now;
|
|
874
|
+
p.lastTouchedAt = now;
|
|
875
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
876
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
877
|
+
}
|
|
878
|
+
export function suspendP2pgovProfileV2(id) {
|
|
879
|
+
const p = _p2pgovPsV2.get(id);
|
|
880
|
+
if (!p) throw new Error(`p2pgov profile ${id} not found`);
|
|
881
|
+
_p2pgovCheckP(p.status, P2PGOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
882
|
+
p.status = P2PGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
883
|
+
p.updatedAt = Date.now();
|
|
884
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
885
|
+
}
|
|
886
|
+
export function archiveP2pgovProfileV2(id) {
|
|
887
|
+
const p = _p2pgovPsV2.get(id);
|
|
888
|
+
if (!p) throw new Error(`p2pgov profile ${id} not found`);
|
|
889
|
+
_p2pgovCheckP(p.status, P2PGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
890
|
+
const now = Date.now();
|
|
891
|
+
p.status = P2PGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
892
|
+
p.updatedAt = now;
|
|
893
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
894
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
895
|
+
}
|
|
896
|
+
export function touchP2pgovProfileV2(id) {
|
|
897
|
+
const p = _p2pgovPsV2.get(id);
|
|
898
|
+
if (!p) throw new Error(`p2pgov profile ${id} not found`);
|
|
899
|
+
if (_p2pgovPTerminal.has(p.status))
|
|
900
|
+
throw new Error(`cannot touch terminal p2pgov profile ${id}`);
|
|
901
|
+
const now = Date.now();
|
|
902
|
+
p.lastTouchedAt = now;
|
|
903
|
+
p.updatedAt = now;
|
|
904
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
905
|
+
}
|
|
906
|
+
export function getP2pgovProfileV2(id) {
|
|
907
|
+
const p = _p2pgovPsV2.get(id);
|
|
908
|
+
if (!p) return null;
|
|
909
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
910
|
+
}
|
|
911
|
+
export function listP2pgovProfilesV2() {
|
|
912
|
+
return [..._p2pgovPsV2.values()].map((p) => ({
|
|
913
|
+
...p,
|
|
914
|
+
metadata: { ...p.metadata },
|
|
915
|
+
}));
|
|
916
|
+
}
|
|
917
|
+
export function createP2pgovGossipV2({ id, profileId, topic, metadata } = {}) {
|
|
918
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
919
|
+
if (_p2pgovJsV2.has(id))
|
|
920
|
+
throw new Error(`p2pgov gossip ${id} already exists`);
|
|
921
|
+
if (!_p2pgovPsV2.has(profileId))
|
|
922
|
+
throw new Error(`p2pgov profile ${profileId} not found`);
|
|
923
|
+
if (_p2pgovCountPending(profileId) >= _p2pgovMaxPending)
|
|
924
|
+
throw new Error(
|
|
925
|
+
`max pending p2pgov gossips for profile ${profileId} reached`,
|
|
926
|
+
);
|
|
927
|
+
const now = Date.now();
|
|
928
|
+
const j = {
|
|
929
|
+
id,
|
|
930
|
+
profileId,
|
|
931
|
+
topic: topic || "",
|
|
932
|
+
status: P2PGOV_GOSSIP_LIFECYCLE_V2.QUEUED,
|
|
933
|
+
createdAt: now,
|
|
934
|
+
updatedAt: now,
|
|
935
|
+
startedAt: null,
|
|
936
|
+
settledAt: null,
|
|
937
|
+
metadata: { ...(metadata || {}) },
|
|
938
|
+
};
|
|
939
|
+
_p2pgovJsV2.set(id, j);
|
|
940
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
941
|
+
}
|
|
942
|
+
export function broadcastingP2pgovGossipV2(id) {
|
|
943
|
+
const j = _p2pgovJsV2.get(id);
|
|
944
|
+
if (!j) throw new Error(`p2pgov gossip ${id} not found`);
|
|
945
|
+
_p2pgovCheckJ(j.status, P2PGOV_GOSSIP_LIFECYCLE_V2.BROADCASTING);
|
|
946
|
+
const now = Date.now();
|
|
947
|
+
j.status = P2PGOV_GOSSIP_LIFECYCLE_V2.BROADCASTING;
|
|
948
|
+
j.updatedAt = now;
|
|
949
|
+
if (!j.startedAt) j.startedAt = now;
|
|
950
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
951
|
+
}
|
|
952
|
+
export function completeGossipP2pgovV2(id) {
|
|
953
|
+
const j = _p2pgovJsV2.get(id);
|
|
954
|
+
if (!j) throw new Error(`p2pgov gossip ${id} not found`);
|
|
955
|
+
_p2pgovCheckJ(j.status, P2PGOV_GOSSIP_LIFECYCLE_V2.BROADCAST);
|
|
956
|
+
const now = Date.now();
|
|
957
|
+
j.status = P2PGOV_GOSSIP_LIFECYCLE_V2.BROADCAST;
|
|
958
|
+
j.updatedAt = now;
|
|
959
|
+
if (!j.settledAt) j.settledAt = now;
|
|
960
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
961
|
+
}
|
|
962
|
+
export function failP2pgovGossipV2(id, reason) {
|
|
963
|
+
const j = _p2pgovJsV2.get(id);
|
|
964
|
+
if (!j) throw new Error(`p2pgov gossip ${id} not found`);
|
|
965
|
+
_p2pgovCheckJ(j.status, P2PGOV_GOSSIP_LIFECYCLE_V2.FAILED);
|
|
966
|
+
const now = Date.now();
|
|
967
|
+
j.status = P2PGOV_GOSSIP_LIFECYCLE_V2.FAILED;
|
|
968
|
+
j.updatedAt = now;
|
|
969
|
+
if (!j.settledAt) j.settledAt = now;
|
|
970
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
971
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
972
|
+
}
|
|
973
|
+
export function cancelP2pgovGossipV2(id, reason) {
|
|
974
|
+
const j = _p2pgovJsV2.get(id);
|
|
975
|
+
if (!j) throw new Error(`p2pgov gossip ${id} not found`);
|
|
976
|
+
_p2pgovCheckJ(j.status, P2PGOV_GOSSIP_LIFECYCLE_V2.CANCELLED);
|
|
977
|
+
const now = Date.now();
|
|
978
|
+
j.status = P2PGOV_GOSSIP_LIFECYCLE_V2.CANCELLED;
|
|
979
|
+
j.updatedAt = now;
|
|
980
|
+
if (!j.settledAt) j.settledAt = now;
|
|
981
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
982
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
983
|
+
}
|
|
984
|
+
export function getP2pgovGossipV2(id) {
|
|
985
|
+
const j = _p2pgovJsV2.get(id);
|
|
986
|
+
if (!j) return null;
|
|
987
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
988
|
+
}
|
|
989
|
+
export function listP2pgovGossipsV2() {
|
|
990
|
+
return [..._p2pgovJsV2.values()].map((j) => ({
|
|
991
|
+
...j,
|
|
992
|
+
metadata: { ...j.metadata },
|
|
993
|
+
}));
|
|
994
|
+
}
|
|
995
|
+
export function autoSuspendIdleP2pgovProfilesV2({ now } = {}) {
|
|
996
|
+
const t = now ?? Date.now();
|
|
997
|
+
const flipped = [];
|
|
998
|
+
for (const p of _p2pgovPsV2.values())
|
|
999
|
+
if (
|
|
1000
|
+
p.status === P2PGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1001
|
+
t - p.lastTouchedAt >= _p2pgovIdleMs
|
|
1002
|
+
) {
|
|
1003
|
+
p.status = P2PGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1004
|
+
p.updatedAt = t;
|
|
1005
|
+
flipped.push(p.id);
|
|
1006
|
+
}
|
|
1007
|
+
return { flipped, count: flipped.length };
|
|
1008
|
+
}
|
|
1009
|
+
export function autoFailStuckP2pgovGossipsV2({ now } = {}) {
|
|
1010
|
+
const t = now ?? Date.now();
|
|
1011
|
+
const flipped = [];
|
|
1012
|
+
for (const j of _p2pgovJsV2.values())
|
|
1013
|
+
if (
|
|
1014
|
+
j.status === P2PGOV_GOSSIP_LIFECYCLE_V2.BROADCASTING &&
|
|
1015
|
+
j.startedAt != null &&
|
|
1016
|
+
t - j.startedAt >= _p2pgovStuckMs
|
|
1017
|
+
) {
|
|
1018
|
+
j.status = P2PGOV_GOSSIP_LIFECYCLE_V2.FAILED;
|
|
1019
|
+
j.updatedAt = t;
|
|
1020
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1021
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1022
|
+
flipped.push(j.id);
|
|
1023
|
+
}
|
|
1024
|
+
return { flipped, count: flipped.length };
|
|
1025
|
+
}
|
|
1026
|
+
export function getP2pManagerGovStatsV2() {
|
|
1027
|
+
const profilesByStatus = {};
|
|
1028
|
+
for (const v of Object.values(P2PGOV_PROFILE_MATURITY_V2))
|
|
1029
|
+
profilesByStatus[v] = 0;
|
|
1030
|
+
for (const p of _p2pgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1031
|
+
const gossipsByStatus = {};
|
|
1032
|
+
for (const v of Object.values(P2PGOV_GOSSIP_LIFECYCLE_V2))
|
|
1033
|
+
gossipsByStatus[v] = 0;
|
|
1034
|
+
for (const j of _p2pgovJsV2.values()) gossipsByStatus[j.status]++;
|
|
1035
|
+
return {
|
|
1036
|
+
totalP2pgovProfilesV2: _p2pgovPsV2.size,
|
|
1037
|
+
totalP2pgovGossipsV2: _p2pgovJsV2.size,
|
|
1038
|
+
maxActiveP2pgovProfilesPerOwner: _p2pgovMaxActive,
|
|
1039
|
+
maxPendingP2pgovGossipsPerProfile: _p2pgovMaxPending,
|
|
1040
|
+
p2pgovProfileIdleMs: _p2pgovIdleMs,
|
|
1041
|
+
p2pgovGossipStuckMs: _p2pgovStuckMs,
|
|
1042
|
+
profilesByStatus,
|
|
1043
|
+
gossipsByStatus,
|
|
1044
|
+
};
|
|
1045
|
+
}
|