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
|
@@ -520,3 +520,349 @@ export function _resetStateInstinctManagerV2() {
|
|
|
520
520
|
_profileIdleMsV2 = INSTINCT_DEFAULT_PROFILE_IDLE_MS;
|
|
521
521
|
_obsStuckMsV2 = INSTINCT_DEFAULT_OBS_STUCK_MS;
|
|
522
522
|
}
|
|
523
|
+
|
|
524
|
+
// =====================================================================
|
|
525
|
+
// instinct-manager V2 governance overlay (iter18)
|
|
526
|
+
// =====================================================================
|
|
527
|
+
export const INSTGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
528
|
+
PENDING: "pending",
|
|
529
|
+
ACTIVE: "active",
|
|
530
|
+
DORMANT: "dormant",
|
|
531
|
+
ARCHIVED: "archived",
|
|
532
|
+
});
|
|
533
|
+
export const INSTGOV_TRIGGER_LIFECYCLE_V2 = Object.freeze({
|
|
534
|
+
QUEUED: "queued",
|
|
535
|
+
FIRING: "firing",
|
|
536
|
+
FIRED: "fired",
|
|
537
|
+
FAILED: "failed",
|
|
538
|
+
CANCELLED: "cancelled",
|
|
539
|
+
});
|
|
540
|
+
const _instgovPTrans = new Map([
|
|
541
|
+
[
|
|
542
|
+
INSTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
543
|
+
new Set([
|
|
544
|
+
INSTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
545
|
+
INSTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
546
|
+
]),
|
|
547
|
+
],
|
|
548
|
+
[
|
|
549
|
+
INSTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
550
|
+
new Set([
|
|
551
|
+
INSTGOV_PROFILE_MATURITY_V2.DORMANT,
|
|
552
|
+
INSTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
553
|
+
]),
|
|
554
|
+
],
|
|
555
|
+
[
|
|
556
|
+
INSTGOV_PROFILE_MATURITY_V2.DORMANT,
|
|
557
|
+
new Set([
|
|
558
|
+
INSTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
559
|
+
INSTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
560
|
+
]),
|
|
561
|
+
],
|
|
562
|
+
[INSTGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
563
|
+
]);
|
|
564
|
+
const _instgovPTerminal = new Set([INSTGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
565
|
+
const _instgovJTrans = new Map([
|
|
566
|
+
[
|
|
567
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.QUEUED,
|
|
568
|
+
new Set([
|
|
569
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING,
|
|
570
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.CANCELLED,
|
|
571
|
+
]),
|
|
572
|
+
],
|
|
573
|
+
[
|
|
574
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING,
|
|
575
|
+
new Set([
|
|
576
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.FIRED,
|
|
577
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.FAILED,
|
|
578
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.CANCELLED,
|
|
579
|
+
]),
|
|
580
|
+
],
|
|
581
|
+
[INSTGOV_TRIGGER_LIFECYCLE_V2.FIRED, new Set()],
|
|
582
|
+
[INSTGOV_TRIGGER_LIFECYCLE_V2.FAILED, new Set()],
|
|
583
|
+
[INSTGOV_TRIGGER_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
584
|
+
]);
|
|
585
|
+
const _instgovPsV2 = new Map();
|
|
586
|
+
const _instgovJsV2 = new Map();
|
|
587
|
+
let _instgovMaxActive = 8,
|
|
588
|
+
_instgovMaxPending = 20,
|
|
589
|
+
_instgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
590
|
+
_instgovStuckMs = 60 * 1000;
|
|
591
|
+
function _instgovPos(n, label) {
|
|
592
|
+
const v = Math.floor(Number(n));
|
|
593
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
594
|
+
throw new Error(`${label} must be positive integer`);
|
|
595
|
+
return v;
|
|
596
|
+
}
|
|
597
|
+
function _instgovCheckP(from, to) {
|
|
598
|
+
const a = _instgovPTrans.get(from);
|
|
599
|
+
if (!a || !a.has(to))
|
|
600
|
+
throw new Error(`invalid instgov profile transition ${from} → ${to}`);
|
|
601
|
+
}
|
|
602
|
+
function _instgovCheckJ(from, to) {
|
|
603
|
+
const a = _instgovJTrans.get(from);
|
|
604
|
+
if (!a || !a.has(to))
|
|
605
|
+
throw new Error(`invalid instgov trigger transition ${from} → ${to}`);
|
|
606
|
+
}
|
|
607
|
+
function _instgovCountActive(owner) {
|
|
608
|
+
let c = 0;
|
|
609
|
+
for (const p of _instgovPsV2.values())
|
|
610
|
+
if (p.owner === owner && p.status === INSTGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
611
|
+
c++;
|
|
612
|
+
return c;
|
|
613
|
+
}
|
|
614
|
+
function _instgovCountPending(profileId) {
|
|
615
|
+
let c = 0;
|
|
616
|
+
for (const j of _instgovJsV2.values())
|
|
617
|
+
if (
|
|
618
|
+
j.profileId === profileId &&
|
|
619
|
+
(j.status === INSTGOV_TRIGGER_LIFECYCLE_V2.QUEUED ||
|
|
620
|
+
j.status === INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING)
|
|
621
|
+
)
|
|
622
|
+
c++;
|
|
623
|
+
return c;
|
|
624
|
+
}
|
|
625
|
+
export function setMaxActiveInstgovProfilesPerOwnerV2(n) {
|
|
626
|
+
_instgovMaxActive = _instgovPos(n, "maxActiveInstgovProfilesPerOwner");
|
|
627
|
+
}
|
|
628
|
+
export function getMaxActiveInstgovProfilesPerOwnerV2() {
|
|
629
|
+
return _instgovMaxActive;
|
|
630
|
+
}
|
|
631
|
+
export function setMaxPendingInstgovTriggersPerProfileV2(n) {
|
|
632
|
+
_instgovMaxPending = _instgovPos(n, "maxPendingInstgovTriggersPerProfile");
|
|
633
|
+
}
|
|
634
|
+
export function getMaxPendingInstgovTriggersPerProfileV2() {
|
|
635
|
+
return _instgovMaxPending;
|
|
636
|
+
}
|
|
637
|
+
export function setInstgovProfileIdleMsV2(n) {
|
|
638
|
+
_instgovIdleMs = _instgovPos(n, "instgovProfileIdleMs");
|
|
639
|
+
}
|
|
640
|
+
export function getInstgovProfileIdleMsV2() {
|
|
641
|
+
return _instgovIdleMs;
|
|
642
|
+
}
|
|
643
|
+
export function setInstgovTriggerStuckMsV2(n) {
|
|
644
|
+
_instgovStuckMs = _instgovPos(n, "instgovTriggerStuckMs");
|
|
645
|
+
}
|
|
646
|
+
export function getInstgovTriggerStuckMsV2() {
|
|
647
|
+
return _instgovStuckMs;
|
|
648
|
+
}
|
|
649
|
+
export function _resetStateInstinctManagerGovV2() {
|
|
650
|
+
_instgovPsV2.clear();
|
|
651
|
+
_instgovJsV2.clear();
|
|
652
|
+
_instgovMaxActive = 8;
|
|
653
|
+
_instgovMaxPending = 20;
|
|
654
|
+
_instgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
655
|
+
_instgovStuckMs = 60 * 1000;
|
|
656
|
+
}
|
|
657
|
+
export function registerInstgovProfileV2({
|
|
658
|
+
id,
|
|
659
|
+
owner,
|
|
660
|
+
priority,
|
|
661
|
+
metadata,
|
|
662
|
+
} = {}) {
|
|
663
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
664
|
+
if (_instgovPsV2.has(id))
|
|
665
|
+
throw new Error(`instgov profile ${id} already exists`);
|
|
666
|
+
const now = Date.now();
|
|
667
|
+
const p = {
|
|
668
|
+
id,
|
|
669
|
+
owner,
|
|
670
|
+
priority: priority || "normal",
|
|
671
|
+
status: INSTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
672
|
+
createdAt: now,
|
|
673
|
+
updatedAt: now,
|
|
674
|
+
lastTouchedAt: now,
|
|
675
|
+
activatedAt: null,
|
|
676
|
+
archivedAt: null,
|
|
677
|
+
metadata: { ...(metadata || {}) },
|
|
678
|
+
};
|
|
679
|
+
_instgovPsV2.set(id, p);
|
|
680
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
681
|
+
}
|
|
682
|
+
export function activateInstgovProfileV2(id) {
|
|
683
|
+
const p = _instgovPsV2.get(id);
|
|
684
|
+
if (!p) throw new Error(`instgov profile ${id} not found`);
|
|
685
|
+
const isInitial = p.status === INSTGOV_PROFILE_MATURITY_V2.PENDING;
|
|
686
|
+
_instgovCheckP(p.status, INSTGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
687
|
+
if (isInitial && _instgovCountActive(p.owner) >= _instgovMaxActive)
|
|
688
|
+
throw new Error(`max active instgov profiles for owner ${p.owner} reached`);
|
|
689
|
+
const now = Date.now();
|
|
690
|
+
p.status = INSTGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
691
|
+
p.updatedAt = now;
|
|
692
|
+
p.lastTouchedAt = now;
|
|
693
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
694
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
695
|
+
}
|
|
696
|
+
export function dormantInstgovProfileV2(id) {
|
|
697
|
+
const p = _instgovPsV2.get(id);
|
|
698
|
+
if (!p) throw new Error(`instgov profile ${id} not found`);
|
|
699
|
+
_instgovCheckP(p.status, INSTGOV_PROFILE_MATURITY_V2.DORMANT);
|
|
700
|
+
p.status = INSTGOV_PROFILE_MATURITY_V2.DORMANT;
|
|
701
|
+
p.updatedAt = Date.now();
|
|
702
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
703
|
+
}
|
|
704
|
+
export function archiveInstgovProfileV2(id) {
|
|
705
|
+
const p = _instgovPsV2.get(id);
|
|
706
|
+
if (!p) throw new Error(`instgov profile ${id} not found`);
|
|
707
|
+
_instgovCheckP(p.status, INSTGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
708
|
+
const now = Date.now();
|
|
709
|
+
p.status = INSTGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
710
|
+
p.updatedAt = now;
|
|
711
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
712
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
713
|
+
}
|
|
714
|
+
export function touchInstgovProfileV2(id) {
|
|
715
|
+
const p = _instgovPsV2.get(id);
|
|
716
|
+
if (!p) throw new Error(`instgov profile ${id} not found`);
|
|
717
|
+
if (_instgovPTerminal.has(p.status))
|
|
718
|
+
throw new Error(`cannot touch terminal instgov profile ${id}`);
|
|
719
|
+
const now = Date.now();
|
|
720
|
+
p.lastTouchedAt = now;
|
|
721
|
+
p.updatedAt = now;
|
|
722
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
723
|
+
}
|
|
724
|
+
export function getInstgovProfileV2(id) {
|
|
725
|
+
const p = _instgovPsV2.get(id);
|
|
726
|
+
if (!p) return null;
|
|
727
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
728
|
+
}
|
|
729
|
+
export function listInstgovProfilesV2() {
|
|
730
|
+
return [..._instgovPsV2.values()].map((p) => ({
|
|
731
|
+
...p,
|
|
732
|
+
metadata: { ...p.metadata },
|
|
733
|
+
}));
|
|
734
|
+
}
|
|
735
|
+
export function createInstgovTriggerV2({
|
|
736
|
+
id,
|
|
737
|
+
profileId,
|
|
738
|
+
pattern,
|
|
739
|
+
metadata,
|
|
740
|
+
} = {}) {
|
|
741
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
742
|
+
if (_instgovJsV2.has(id))
|
|
743
|
+
throw new Error(`instgov trigger ${id} already exists`);
|
|
744
|
+
if (!_instgovPsV2.has(profileId))
|
|
745
|
+
throw new Error(`instgov profile ${profileId} not found`);
|
|
746
|
+
if (_instgovCountPending(profileId) >= _instgovMaxPending)
|
|
747
|
+
throw new Error(
|
|
748
|
+
`max pending instgov triggers for profile ${profileId} reached`,
|
|
749
|
+
);
|
|
750
|
+
const now = Date.now();
|
|
751
|
+
const j = {
|
|
752
|
+
id,
|
|
753
|
+
profileId,
|
|
754
|
+
pattern: pattern || "",
|
|
755
|
+
status: INSTGOV_TRIGGER_LIFECYCLE_V2.QUEUED,
|
|
756
|
+
createdAt: now,
|
|
757
|
+
updatedAt: now,
|
|
758
|
+
startedAt: null,
|
|
759
|
+
settledAt: null,
|
|
760
|
+
metadata: { ...(metadata || {}) },
|
|
761
|
+
};
|
|
762
|
+
_instgovJsV2.set(id, j);
|
|
763
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
764
|
+
}
|
|
765
|
+
export function firingInstgovTriggerV2(id) {
|
|
766
|
+
const j = _instgovJsV2.get(id);
|
|
767
|
+
if (!j) throw new Error(`instgov trigger ${id} not found`);
|
|
768
|
+
_instgovCheckJ(j.status, INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING);
|
|
769
|
+
const now = Date.now();
|
|
770
|
+
j.status = INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING;
|
|
771
|
+
j.updatedAt = now;
|
|
772
|
+
if (!j.startedAt) j.startedAt = now;
|
|
773
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
774
|
+
}
|
|
775
|
+
export function completeTriggerInstgovV2(id) {
|
|
776
|
+
const j = _instgovJsV2.get(id);
|
|
777
|
+
if (!j) throw new Error(`instgov trigger ${id} not found`);
|
|
778
|
+
_instgovCheckJ(j.status, INSTGOV_TRIGGER_LIFECYCLE_V2.FIRED);
|
|
779
|
+
const now = Date.now();
|
|
780
|
+
j.status = INSTGOV_TRIGGER_LIFECYCLE_V2.FIRED;
|
|
781
|
+
j.updatedAt = now;
|
|
782
|
+
if (!j.settledAt) j.settledAt = now;
|
|
783
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
784
|
+
}
|
|
785
|
+
export function failInstgovTriggerV2(id, reason) {
|
|
786
|
+
const j = _instgovJsV2.get(id);
|
|
787
|
+
if (!j) throw new Error(`instgov trigger ${id} not found`);
|
|
788
|
+
_instgovCheckJ(j.status, INSTGOV_TRIGGER_LIFECYCLE_V2.FAILED);
|
|
789
|
+
const now = Date.now();
|
|
790
|
+
j.status = INSTGOV_TRIGGER_LIFECYCLE_V2.FAILED;
|
|
791
|
+
j.updatedAt = now;
|
|
792
|
+
if (!j.settledAt) j.settledAt = now;
|
|
793
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
794
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
795
|
+
}
|
|
796
|
+
export function cancelInstgovTriggerV2(id, reason) {
|
|
797
|
+
const j = _instgovJsV2.get(id);
|
|
798
|
+
if (!j) throw new Error(`instgov trigger ${id} not found`);
|
|
799
|
+
_instgovCheckJ(j.status, INSTGOV_TRIGGER_LIFECYCLE_V2.CANCELLED);
|
|
800
|
+
const now = Date.now();
|
|
801
|
+
j.status = INSTGOV_TRIGGER_LIFECYCLE_V2.CANCELLED;
|
|
802
|
+
j.updatedAt = now;
|
|
803
|
+
if (!j.settledAt) j.settledAt = now;
|
|
804
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
805
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
806
|
+
}
|
|
807
|
+
export function getInstgovTriggerV2(id) {
|
|
808
|
+
const j = _instgovJsV2.get(id);
|
|
809
|
+
if (!j) return null;
|
|
810
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
811
|
+
}
|
|
812
|
+
export function listInstgovTriggersV2() {
|
|
813
|
+
return [..._instgovJsV2.values()].map((j) => ({
|
|
814
|
+
...j,
|
|
815
|
+
metadata: { ...j.metadata },
|
|
816
|
+
}));
|
|
817
|
+
}
|
|
818
|
+
export function autoDormantIdleInstgovProfilesV2({ now } = {}) {
|
|
819
|
+
const t = now ?? Date.now();
|
|
820
|
+
const flipped = [];
|
|
821
|
+
for (const p of _instgovPsV2.values())
|
|
822
|
+
if (
|
|
823
|
+
p.status === INSTGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
824
|
+
t - p.lastTouchedAt >= _instgovIdleMs
|
|
825
|
+
) {
|
|
826
|
+
p.status = INSTGOV_PROFILE_MATURITY_V2.DORMANT;
|
|
827
|
+
p.updatedAt = t;
|
|
828
|
+
flipped.push(p.id);
|
|
829
|
+
}
|
|
830
|
+
return { flipped, count: flipped.length };
|
|
831
|
+
}
|
|
832
|
+
export function autoFailStuckInstgovTriggersV2({ now } = {}) {
|
|
833
|
+
const t = now ?? Date.now();
|
|
834
|
+
const flipped = [];
|
|
835
|
+
for (const j of _instgovJsV2.values())
|
|
836
|
+
if (
|
|
837
|
+
j.status === INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING &&
|
|
838
|
+
j.startedAt != null &&
|
|
839
|
+
t - j.startedAt >= _instgovStuckMs
|
|
840
|
+
) {
|
|
841
|
+
j.status = INSTGOV_TRIGGER_LIFECYCLE_V2.FAILED;
|
|
842
|
+
j.updatedAt = t;
|
|
843
|
+
if (!j.settledAt) j.settledAt = t;
|
|
844
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
845
|
+
flipped.push(j.id);
|
|
846
|
+
}
|
|
847
|
+
return { flipped, count: flipped.length };
|
|
848
|
+
}
|
|
849
|
+
export function getInstinctManagerGovStatsV2() {
|
|
850
|
+
const profilesByStatus = {};
|
|
851
|
+
for (const v of Object.values(INSTGOV_PROFILE_MATURITY_V2))
|
|
852
|
+
profilesByStatus[v] = 0;
|
|
853
|
+
for (const p of _instgovPsV2.values()) profilesByStatus[p.status]++;
|
|
854
|
+
const triggersByStatus = {};
|
|
855
|
+
for (const v of Object.values(INSTGOV_TRIGGER_LIFECYCLE_V2))
|
|
856
|
+
triggersByStatus[v] = 0;
|
|
857
|
+
for (const j of _instgovJsV2.values()) triggersByStatus[j.status]++;
|
|
858
|
+
return {
|
|
859
|
+
totalInstgovProfilesV2: _instgovPsV2.size,
|
|
860
|
+
totalInstgovTriggersV2: _instgovJsV2.size,
|
|
861
|
+
maxActiveInstgovProfilesPerOwner: _instgovMaxActive,
|
|
862
|
+
maxPendingInstgovTriggersPerProfile: _instgovMaxPending,
|
|
863
|
+
instgovProfileIdleMs: _instgovIdleMs,
|
|
864
|
+
instgovTriggerStuckMs: _instgovStuckMs,
|
|
865
|
+
profilesByStatus,
|
|
866
|
+
triggersByStatus,
|
|
867
|
+
};
|
|
868
|
+
}
|
package/src/lib/ipfs-storage.js
CHANGED
|
@@ -907,3 +907,337 @@ export function _resetStateV2() {
|
|
|
907
907
|
_gatewaysV2.clear();
|
|
908
908
|
_pinsV2.clear();
|
|
909
909
|
}
|
|
910
|
+
|
|
911
|
+
// =====================================================================
|
|
912
|
+
// ipfs-storage V2 governance overlay (iter20)
|
|
913
|
+
// =====================================================================
|
|
914
|
+
export const IPFSGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
915
|
+
PENDING: "pending",
|
|
916
|
+
ACTIVE: "active",
|
|
917
|
+
STALE: "stale",
|
|
918
|
+
ARCHIVED: "archived",
|
|
919
|
+
});
|
|
920
|
+
export const IPFSGOV_PIN_LIFECYCLE_V2 = Object.freeze({
|
|
921
|
+
QUEUED: "queued",
|
|
922
|
+
PINNING: "pinning",
|
|
923
|
+
PINNED: "pinned",
|
|
924
|
+
FAILED: "failed",
|
|
925
|
+
CANCELLED: "cancelled",
|
|
926
|
+
});
|
|
927
|
+
const _ipfsgovPTrans = new Map([
|
|
928
|
+
[
|
|
929
|
+
IPFSGOV_PROFILE_MATURITY_V2.PENDING,
|
|
930
|
+
new Set([
|
|
931
|
+
IPFSGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
932
|
+
IPFSGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
933
|
+
]),
|
|
934
|
+
],
|
|
935
|
+
[
|
|
936
|
+
IPFSGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
937
|
+
new Set([
|
|
938
|
+
IPFSGOV_PROFILE_MATURITY_V2.STALE,
|
|
939
|
+
IPFSGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
940
|
+
]),
|
|
941
|
+
],
|
|
942
|
+
[
|
|
943
|
+
IPFSGOV_PROFILE_MATURITY_V2.STALE,
|
|
944
|
+
new Set([
|
|
945
|
+
IPFSGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
946
|
+
IPFSGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
947
|
+
]),
|
|
948
|
+
],
|
|
949
|
+
[IPFSGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
950
|
+
]);
|
|
951
|
+
const _ipfsgovPTerminal = new Set([IPFSGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
952
|
+
const _ipfsgovJTrans = new Map([
|
|
953
|
+
[
|
|
954
|
+
IPFSGOV_PIN_LIFECYCLE_V2.QUEUED,
|
|
955
|
+
new Set([
|
|
956
|
+
IPFSGOV_PIN_LIFECYCLE_V2.PINNING,
|
|
957
|
+
IPFSGOV_PIN_LIFECYCLE_V2.CANCELLED,
|
|
958
|
+
]),
|
|
959
|
+
],
|
|
960
|
+
[
|
|
961
|
+
IPFSGOV_PIN_LIFECYCLE_V2.PINNING,
|
|
962
|
+
new Set([
|
|
963
|
+
IPFSGOV_PIN_LIFECYCLE_V2.PINNED,
|
|
964
|
+
IPFSGOV_PIN_LIFECYCLE_V2.FAILED,
|
|
965
|
+
IPFSGOV_PIN_LIFECYCLE_V2.CANCELLED,
|
|
966
|
+
]),
|
|
967
|
+
],
|
|
968
|
+
[IPFSGOV_PIN_LIFECYCLE_V2.PINNED, new Set()],
|
|
969
|
+
[IPFSGOV_PIN_LIFECYCLE_V2.FAILED, new Set()],
|
|
970
|
+
[IPFSGOV_PIN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
971
|
+
]);
|
|
972
|
+
const _ipfsgovPsV2 = new Map();
|
|
973
|
+
const _ipfsgovJsV2 = new Map();
|
|
974
|
+
let _ipfsgovMaxActive = 8,
|
|
975
|
+
_ipfsgovMaxPending = 20,
|
|
976
|
+
_ipfsgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
977
|
+
_ipfsgovStuckMs = 60 * 1000;
|
|
978
|
+
function _ipfsgovPos(n, label) {
|
|
979
|
+
const v = Math.floor(Number(n));
|
|
980
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
981
|
+
throw new Error(`${label} must be positive integer`);
|
|
982
|
+
return v;
|
|
983
|
+
}
|
|
984
|
+
function _ipfsgovCheckP(from, to) {
|
|
985
|
+
const a = _ipfsgovPTrans.get(from);
|
|
986
|
+
if (!a || !a.has(to))
|
|
987
|
+
throw new Error(`invalid ipfsgov profile transition ${from} → ${to}`);
|
|
988
|
+
}
|
|
989
|
+
function _ipfsgovCheckJ(from, to) {
|
|
990
|
+
const a = _ipfsgovJTrans.get(from);
|
|
991
|
+
if (!a || !a.has(to))
|
|
992
|
+
throw new Error(`invalid ipfsgov pin transition ${from} → ${to}`);
|
|
993
|
+
}
|
|
994
|
+
function _ipfsgovCountActive(owner) {
|
|
995
|
+
let c = 0;
|
|
996
|
+
for (const p of _ipfsgovPsV2.values())
|
|
997
|
+
if (p.owner === owner && p.status === IPFSGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
998
|
+
c++;
|
|
999
|
+
return c;
|
|
1000
|
+
}
|
|
1001
|
+
function _ipfsgovCountPending(profileId) {
|
|
1002
|
+
let c = 0;
|
|
1003
|
+
for (const j of _ipfsgovJsV2.values())
|
|
1004
|
+
if (
|
|
1005
|
+
j.profileId === profileId &&
|
|
1006
|
+
(j.status === IPFSGOV_PIN_LIFECYCLE_V2.QUEUED ||
|
|
1007
|
+
j.status === IPFSGOV_PIN_LIFECYCLE_V2.PINNING)
|
|
1008
|
+
)
|
|
1009
|
+
c++;
|
|
1010
|
+
return c;
|
|
1011
|
+
}
|
|
1012
|
+
export function setMaxActiveIpfsgovProfilesPerOwnerV2(n) {
|
|
1013
|
+
_ipfsgovMaxActive = _ipfsgovPos(n, "maxActiveIpfsgovProfilesPerOwner");
|
|
1014
|
+
}
|
|
1015
|
+
export function getMaxActiveIpfsgovProfilesPerOwnerV2() {
|
|
1016
|
+
return _ipfsgovMaxActive;
|
|
1017
|
+
}
|
|
1018
|
+
export function setMaxPendingIpfsgovPinsPerProfileV2(n) {
|
|
1019
|
+
_ipfsgovMaxPending = _ipfsgovPos(n, "maxPendingIpfsgovPinsPerProfile");
|
|
1020
|
+
}
|
|
1021
|
+
export function getMaxPendingIpfsgovPinsPerProfileV2() {
|
|
1022
|
+
return _ipfsgovMaxPending;
|
|
1023
|
+
}
|
|
1024
|
+
export function setIpfsgovProfileIdleMsV2(n) {
|
|
1025
|
+
_ipfsgovIdleMs = _ipfsgovPos(n, "ipfsgovProfileIdleMs");
|
|
1026
|
+
}
|
|
1027
|
+
export function getIpfsgovProfileIdleMsV2() {
|
|
1028
|
+
return _ipfsgovIdleMs;
|
|
1029
|
+
}
|
|
1030
|
+
export function setIpfsgovPinStuckMsV2(n) {
|
|
1031
|
+
_ipfsgovStuckMs = _ipfsgovPos(n, "ipfsgovPinStuckMs");
|
|
1032
|
+
}
|
|
1033
|
+
export function getIpfsgovPinStuckMsV2() {
|
|
1034
|
+
return _ipfsgovStuckMs;
|
|
1035
|
+
}
|
|
1036
|
+
export function _resetStateIpfsStorageGovV2() {
|
|
1037
|
+
_ipfsgovPsV2.clear();
|
|
1038
|
+
_ipfsgovJsV2.clear();
|
|
1039
|
+
_ipfsgovMaxActive = 8;
|
|
1040
|
+
_ipfsgovMaxPending = 20;
|
|
1041
|
+
_ipfsgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1042
|
+
_ipfsgovStuckMs = 60 * 1000;
|
|
1043
|
+
}
|
|
1044
|
+
export function registerIpfsgovProfileV2({ id, owner, mode, metadata } = {}) {
|
|
1045
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1046
|
+
if (_ipfsgovPsV2.has(id))
|
|
1047
|
+
throw new Error(`ipfsgov profile ${id} already exists`);
|
|
1048
|
+
const now = Date.now();
|
|
1049
|
+
const p = {
|
|
1050
|
+
id,
|
|
1051
|
+
owner,
|
|
1052
|
+
mode: mode || "local",
|
|
1053
|
+
status: IPFSGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1054
|
+
createdAt: now,
|
|
1055
|
+
updatedAt: now,
|
|
1056
|
+
lastTouchedAt: now,
|
|
1057
|
+
activatedAt: null,
|
|
1058
|
+
archivedAt: null,
|
|
1059
|
+
metadata: { ...(metadata || {}) },
|
|
1060
|
+
};
|
|
1061
|
+
_ipfsgovPsV2.set(id, p);
|
|
1062
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1063
|
+
}
|
|
1064
|
+
export function activateIpfsgovProfileV2(id) {
|
|
1065
|
+
const p = _ipfsgovPsV2.get(id);
|
|
1066
|
+
if (!p) throw new Error(`ipfsgov profile ${id} not found`);
|
|
1067
|
+
const isInitial = p.status === IPFSGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1068
|
+
_ipfsgovCheckP(p.status, IPFSGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1069
|
+
if (isInitial && _ipfsgovCountActive(p.owner) >= _ipfsgovMaxActive)
|
|
1070
|
+
throw new Error(`max active ipfsgov profiles for owner ${p.owner} reached`);
|
|
1071
|
+
const now = Date.now();
|
|
1072
|
+
p.status = IPFSGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1073
|
+
p.updatedAt = now;
|
|
1074
|
+
p.lastTouchedAt = now;
|
|
1075
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1076
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1077
|
+
}
|
|
1078
|
+
export function staleIpfsgovProfileV2(id) {
|
|
1079
|
+
const p = _ipfsgovPsV2.get(id);
|
|
1080
|
+
if (!p) throw new Error(`ipfsgov profile ${id} not found`);
|
|
1081
|
+
_ipfsgovCheckP(p.status, IPFSGOV_PROFILE_MATURITY_V2.STALE);
|
|
1082
|
+
p.status = IPFSGOV_PROFILE_MATURITY_V2.STALE;
|
|
1083
|
+
p.updatedAt = Date.now();
|
|
1084
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1085
|
+
}
|
|
1086
|
+
export function archiveIpfsgovProfileV2(id) {
|
|
1087
|
+
const p = _ipfsgovPsV2.get(id);
|
|
1088
|
+
if (!p) throw new Error(`ipfsgov profile ${id} not found`);
|
|
1089
|
+
_ipfsgovCheckP(p.status, IPFSGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1090
|
+
const now = Date.now();
|
|
1091
|
+
p.status = IPFSGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1092
|
+
p.updatedAt = now;
|
|
1093
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1094
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1095
|
+
}
|
|
1096
|
+
export function touchIpfsgovProfileV2(id) {
|
|
1097
|
+
const p = _ipfsgovPsV2.get(id);
|
|
1098
|
+
if (!p) throw new Error(`ipfsgov profile ${id} not found`);
|
|
1099
|
+
if (_ipfsgovPTerminal.has(p.status))
|
|
1100
|
+
throw new Error(`cannot touch terminal ipfsgov profile ${id}`);
|
|
1101
|
+
const now = Date.now();
|
|
1102
|
+
p.lastTouchedAt = now;
|
|
1103
|
+
p.updatedAt = now;
|
|
1104
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1105
|
+
}
|
|
1106
|
+
export function getIpfsgovProfileV2(id) {
|
|
1107
|
+
const p = _ipfsgovPsV2.get(id);
|
|
1108
|
+
if (!p) return null;
|
|
1109
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1110
|
+
}
|
|
1111
|
+
export function listIpfsgovProfilesV2() {
|
|
1112
|
+
return [..._ipfsgovPsV2.values()].map((p) => ({
|
|
1113
|
+
...p,
|
|
1114
|
+
metadata: { ...p.metadata },
|
|
1115
|
+
}));
|
|
1116
|
+
}
|
|
1117
|
+
export function createIpfsgovPinV2({ id, profileId, cid, metadata } = {}) {
|
|
1118
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1119
|
+
if (_ipfsgovJsV2.has(id)) throw new Error(`ipfsgov pin ${id} already exists`);
|
|
1120
|
+
if (!_ipfsgovPsV2.has(profileId))
|
|
1121
|
+
throw new Error(`ipfsgov profile ${profileId} not found`);
|
|
1122
|
+
if (_ipfsgovCountPending(profileId) >= _ipfsgovMaxPending)
|
|
1123
|
+
throw new Error(
|
|
1124
|
+
`max pending ipfsgov pins for profile ${profileId} reached`,
|
|
1125
|
+
);
|
|
1126
|
+
const now = Date.now();
|
|
1127
|
+
const j = {
|
|
1128
|
+
id,
|
|
1129
|
+
profileId,
|
|
1130
|
+
cid: cid || "",
|
|
1131
|
+
status: IPFSGOV_PIN_LIFECYCLE_V2.QUEUED,
|
|
1132
|
+
createdAt: now,
|
|
1133
|
+
updatedAt: now,
|
|
1134
|
+
startedAt: null,
|
|
1135
|
+
settledAt: null,
|
|
1136
|
+
metadata: { ...(metadata || {}) },
|
|
1137
|
+
};
|
|
1138
|
+
_ipfsgovJsV2.set(id, j);
|
|
1139
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1140
|
+
}
|
|
1141
|
+
export function pinningIpfsgovPinV2(id) {
|
|
1142
|
+
const j = _ipfsgovJsV2.get(id);
|
|
1143
|
+
if (!j) throw new Error(`ipfsgov pin ${id} not found`);
|
|
1144
|
+
_ipfsgovCheckJ(j.status, IPFSGOV_PIN_LIFECYCLE_V2.PINNING);
|
|
1145
|
+
const now = Date.now();
|
|
1146
|
+
j.status = IPFSGOV_PIN_LIFECYCLE_V2.PINNING;
|
|
1147
|
+
j.updatedAt = now;
|
|
1148
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1149
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1150
|
+
}
|
|
1151
|
+
export function completePinIpfsgovV2(id) {
|
|
1152
|
+
const j = _ipfsgovJsV2.get(id);
|
|
1153
|
+
if (!j) throw new Error(`ipfsgov pin ${id} not found`);
|
|
1154
|
+
_ipfsgovCheckJ(j.status, IPFSGOV_PIN_LIFECYCLE_V2.PINNED);
|
|
1155
|
+
const now = Date.now();
|
|
1156
|
+
j.status = IPFSGOV_PIN_LIFECYCLE_V2.PINNED;
|
|
1157
|
+
j.updatedAt = now;
|
|
1158
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1159
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1160
|
+
}
|
|
1161
|
+
export function failIpfsgovPinV2(id, reason) {
|
|
1162
|
+
const j = _ipfsgovJsV2.get(id);
|
|
1163
|
+
if (!j) throw new Error(`ipfsgov pin ${id} not found`);
|
|
1164
|
+
_ipfsgovCheckJ(j.status, IPFSGOV_PIN_LIFECYCLE_V2.FAILED);
|
|
1165
|
+
const now = Date.now();
|
|
1166
|
+
j.status = IPFSGOV_PIN_LIFECYCLE_V2.FAILED;
|
|
1167
|
+
j.updatedAt = now;
|
|
1168
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1169
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1170
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1171
|
+
}
|
|
1172
|
+
export function cancelIpfsgovPinV2(id, reason) {
|
|
1173
|
+
const j = _ipfsgovJsV2.get(id);
|
|
1174
|
+
if (!j) throw new Error(`ipfsgov pin ${id} not found`);
|
|
1175
|
+
_ipfsgovCheckJ(j.status, IPFSGOV_PIN_LIFECYCLE_V2.CANCELLED);
|
|
1176
|
+
const now = Date.now();
|
|
1177
|
+
j.status = IPFSGOV_PIN_LIFECYCLE_V2.CANCELLED;
|
|
1178
|
+
j.updatedAt = now;
|
|
1179
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1180
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1181
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1182
|
+
}
|
|
1183
|
+
export function getIpfsgovPinV2(id) {
|
|
1184
|
+
const j = _ipfsgovJsV2.get(id);
|
|
1185
|
+
if (!j) return null;
|
|
1186
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1187
|
+
}
|
|
1188
|
+
export function listIpfsgovPinsV2() {
|
|
1189
|
+
return [..._ipfsgovJsV2.values()].map((j) => ({
|
|
1190
|
+
...j,
|
|
1191
|
+
metadata: { ...j.metadata },
|
|
1192
|
+
}));
|
|
1193
|
+
}
|
|
1194
|
+
export function autoStaleIdleIpfsgovProfilesV2({ now } = {}) {
|
|
1195
|
+
const t = now ?? Date.now();
|
|
1196
|
+
const flipped = [];
|
|
1197
|
+
for (const p of _ipfsgovPsV2.values())
|
|
1198
|
+
if (
|
|
1199
|
+
p.status === IPFSGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1200
|
+
t - p.lastTouchedAt >= _ipfsgovIdleMs
|
|
1201
|
+
) {
|
|
1202
|
+
p.status = IPFSGOV_PROFILE_MATURITY_V2.STALE;
|
|
1203
|
+
p.updatedAt = t;
|
|
1204
|
+
flipped.push(p.id);
|
|
1205
|
+
}
|
|
1206
|
+
return { flipped, count: flipped.length };
|
|
1207
|
+
}
|
|
1208
|
+
export function autoFailStuckIpfsgovPinsV2({ now } = {}) {
|
|
1209
|
+
const t = now ?? Date.now();
|
|
1210
|
+
const flipped = [];
|
|
1211
|
+
for (const j of _ipfsgovJsV2.values())
|
|
1212
|
+
if (
|
|
1213
|
+
j.status === IPFSGOV_PIN_LIFECYCLE_V2.PINNING &&
|
|
1214
|
+
j.startedAt != null &&
|
|
1215
|
+
t - j.startedAt >= _ipfsgovStuckMs
|
|
1216
|
+
) {
|
|
1217
|
+
j.status = IPFSGOV_PIN_LIFECYCLE_V2.FAILED;
|
|
1218
|
+
j.updatedAt = t;
|
|
1219
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1220
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1221
|
+
flipped.push(j.id);
|
|
1222
|
+
}
|
|
1223
|
+
return { flipped, count: flipped.length };
|
|
1224
|
+
}
|
|
1225
|
+
export function getIpfsStorageGovStatsV2() {
|
|
1226
|
+
const profilesByStatus = {};
|
|
1227
|
+
for (const v of Object.values(IPFSGOV_PROFILE_MATURITY_V2))
|
|
1228
|
+
profilesByStatus[v] = 0;
|
|
1229
|
+
for (const p of _ipfsgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1230
|
+
const pinsByStatus = {};
|
|
1231
|
+
for (const v of Object.values(IPFSGOV_PIN_LIFECYCLE_V2)) pinsByStatus[v] = 0;
|
|
1232
|
+
for (const j of _ipfsgovJsV2.values()) pinsByStatus[j.status]++;
|
|
1233
|
+
return {
|
|
1234
|
+
totalIpfsgovProfilesV2: _ipfsgovPsV2.size,
|
|
1235
|
+
totalIpfsgovPinsV2: _ipfsgovJsV2.size,
|
|
1236
|
+
maxActiveIpfsgovProfilesPerOwner: _ipfsgovMaxActive,
|
|
1237
|
+
maxPendingIpfsgovPinsPerProfile: _ipfsgovMaxPending,
|
|
1238
|
+
ipfsgovProfileIdleMs: _ipfsgovIdleMs,
|
|
1239
|
+
ipfsgovPinStuckMs: _ipfsgovStuckMs,
|
|
1240
|
+
profilesByStatus,
|
|
1241
|
+
pinsByStatus,
|
|
1242
|
+
};
|
|
1243
|
+
}
|