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
|
@@ -622,25 +622,53 @@ export function _resetState() {
|
|
|
622
622
|
|
|
623
623
|
export const _constants = { PUBLIC_AUDIENCE, CONTEXT, DEFAULT_ORIGIN };
|
|
624
624
|
|
|
625
|
-
|
|
626
625
|
// ===== V2 Surface: ActivityPub Bridge governance overlay (CLI v0.135.0) =====
|
|
627
626
|
export const AP_ACTOR_MATURITY_V2 = Object.freeze({
|
|
628
|
-
PENDING: "pending",
|
|
627
|
+
PENDING: "pending",
|
|
628
|
+
ACTIVE: "active",
|
|
629
|
+
SUSPENDED: "suspended",
|
|
630
|
+
DEACTIVATED: "deactivated",
|
|
629
631
|
});
|
|
630
632
|
export const AP_ACTIVITY_LIFECYCLE_V2 = Object.freeze({
|
|
631
|
-
QUEUED: "queued",
|
|
633
|
+
QUEUED: "queued",
|
|
634
|
+
DELIVERING: "delivering",
|
|
635
|
+
DELIVERED: "delivered",
|
|
636
|
+
FAILED: "failed",
|
|
637
|
+
CANCELLED: "cancelled",
|
|
632
638
|
});
|
|
633
639
|
|
|
634
640
|
const _apActorTrans = new Map([
|
|
635
|
-
[
|
|
636
|
-
|
|
637
|
-
|
|
641
|
+
[
|
|
642
|
+
AP_ACTOR_MATURITY_V2.PENDING,
|
|
643
|
+
new Set([AP_ACTOR_MATURITY_V2.ACTIVE, AP_ACTOR_MATURITY_V2.DEACTIVATED]),
|
|
644
|
+
],
|
|
645
|
+
[
|
|
646
|
+
AP_ACTOR_MATURITY_V2.ACTIVE,
|
|
647
|
+
new Set([AP_ACTOR_MATURITY_V2.SUSPENDED, AP_ACTOR_MATURITY_V2.DEACTIVATED]),
|
|
648
|
+
],
|
|
649
|
+
[
|
|
650
|
+
AP_ACTOR_MATURITY_V2.SUSPENDED,
|
|
651
|
+
new Set([AP_ACTOR_MATURITY_V2.ACTIVE, AP_ACTOR_MATURITY_V2.DEACTIVATED]),
|
|
652
|
+
],
|
|
638
653
|
[AP_ACTOR_MATURITY_V2.DEACTIVATED, new Set()],
|
|
639
654
|
]);
|
|
640
655
|
const _apActorTerminal = new Set([AP_ACTOR_MATURITY_V2.DEACTIVATED]);
|
|
641
656
|
const _apActTrans = new Map([
|
|
642
|
-
[
|
|
643
|
-
|
|
657
|
+
[
|
|
658
|
+
AP_ACTIVITY_LIFECYCLE_V2.QUEUED,
|
|
659
|
+
new Set([
|
|
660
|
+
AP_ACTIVITY_LIFECYCLE_V2.DELIVERING,
|
|
661
|
+
AP_ACTIVITY_LIFECYCLE_V2.CANCELLED,
|
|
662
|
+
]),
|
|
663
|
+
],
|
|
664
|
+
[
|
|
665
|
+
AP_ACTIVITY_LIFECYCLE_V2.DELIVERING,
|
|
666
|
+
new Set([
|
|
667
|
+
AP_ACTIVITY_LIFECYCLE_V2.DELIVERED,
|
|
668
|
+
AP_ACTIVITY_LIFECYCLE_V2.FAILED,
|
|
669
|
+
AP_ACTIVITY_LIFECYCLE_V2.CANCELLED,
|
|
670
|
+
]),
|
|
671
|
+
],
|
|
644
672
|
[AP_ACTIVITY_LIFECYCLE_V2.DELIVERED, new Set()],
|
|
645
673
|
[AP_ACTIVITY_LIFECYCLE_V2.FAILED, new Set()],
|
|
646
674
|
[AP_ACTIVITY_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -653,76 +681,620 @@ let _apMaxPendingPerActor = 25;
|
|
|
653
681
|
let _apActorIdleMs = 24 * 60 * 60 * 1000;
|
|
654
682
|
let _apActStuckMs = 3 * 60 * 1000;
|
|
655
683
|
|
|
656
|
-
function _apPos(n, lbl) {
|
|
684
|
+
function _apPos(n, lbl) {
|
|
685
|
+
const v = Math.floor(Number(n));
|
|
686
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
687
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
688
|
+
return v;
|
|
689
|
+
}
|
|
657
690
|
|
|
658
|
-
export function setMaxActiveApActorsPerOwnerV2(n) {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
export function
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
export function
|
|
665
|
-
|
|
691
|
+
export function setMaxActiveApActorsPerOwnerV2(n) {
|
|
692
|
+
_apMaxActivePerOwner = _apPos(n, "maxActiveApActorsPerOwner");
|
|
693
|
+
}
|
|
694
|
+
export function getMaxActiveApActorsPerOwnerV2() {
|
|
695
|
+
return _apMaxActivePerOwner;
|
|
696
|
+
}
|
|
697
|
+
export function setMaxPendingApActivitiesPerActorV2(n) {
|
|
698
|
+
_apMaxPendingPerActor = _apPos(n, "maxPendingApActivitiesPerActor");
|
|
699
|
+
}
|
|
700
|
+
export function getMaxPendingApActivitiesPerActorV2() {
|
|
701
|
+
return _apMaxPendingPerActor;
|
|
702
|
+
}
|
|
703
|
+
export function setApActorIdleMsV2(n) {
|
|
704
|
+
_apActorIdleMs = _apPos(n, "apActorIdleMs");
|
|
705
|
+
}
|
|
706
|
+
export function getApActorIdleMsV2() {
|
|
707
|
+
return _apActorIdleMs;
|
|
708
|
+
}
|
|
709
|
+
export function setApActivityStuckMsV2(n) {
|
|
710
|
+
_apActStuckMs = _apPos(n, "apActivityStuckMs");
|
|
711
|
+
}
|
|
712
|
+
export function getApActivityStuckMsV2() {
|
|
713
|
+
return _apActStuckMs;
|
|
714
|
+
}
|
|
666
715
|
|
|
667
716
|
export function _resetStateActivityPubBridgeV2() {
|
|
668
|
-
_apActors.clear();
|
|
669
|
-
|
|
670
|
-
|
|
717
|
+
_apActors.clear();
|
|
718
|
+
_apActs.clear();
|
|
719
|
+
_apMaxActivePerOwner = 15;
|
|
720
|
+
_apMaxPendingPerActor = 25;
|
|
721
|
+
_apActorIdleMs = 24 * 60 * 60 * 1000;
|
|
722
|
+
_apActStuckMs = 3 * 60 * 1000;
|
|
671
723
|
}
|
|
672
724
|
|
|
673
725
|
export function registerApActorV2({ id, owner, handle, metadata } = {}) {
|
|
674
726
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
675
727
|
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
676
|
-
if (_apActors.has(id))
|
|
728
|
+
if (_apActors.has(id))
|
|
729
|
+
throw new Error(`activitypub actor ${id} already registered`);
|
|
677
730
|
const now = Date.now();
|
|
678
|
-
const a = {
|
|
731
|
+
const a = {
|
|
732
|
+
id,
|
|
733
|
+
owner,
|
|
734
|
+
handle: handle || id,
|
|
735
|
+
status: AP_ACTOR_MATURITY_V2.PENDING,
|
|
736
|
+
createdAt: now,
|
|
737
|
+
updatedAt: now,
|
|
738
|
+
activatedAt: null,
|
|
739
|
+
deactivatedAt: null,
|
|
740
|
+
lastTouchedAt: now,
|
|
741
|
+
metadata: { ...(metadata || {}) },
|
|
742
|
+
};
|
|
679
743
|
_apActors.set(id, a);
|
|
680
744
|
return { ...a, metadata: { ...a.metadata } };
|
|
681
745
|
}
|
|
682
|
-
function _apCheckA(from, to) {
|
|
683
|
-
|
|
746
|
+
function _apCheckA(from, to) {
|
|
747
|
+
const al = _apActorTrans.get(from);
|
|
748
|
+
if (!al || !al.has(to))
|
|
749
|
+
throw new Error(`invalid activitypub actor transition ${from} → ${to}`);
|
|
750
|
+
}
|
|
751
|
+
function _apCountActive(owner) {
|
|
752
|
+
let n = 0;
|
|
753
|
+
for (const a of _apActors.values())
|
|
754
|
+
if (a.owner === owner && a.status === AP_ACTOR_MATURITY_V2.ACTIVE) n++;
|
|
755
|
+
return n;
|
|
756
|
+
}
|
|
684
757
|
|
|
685
758
|
export function activateApActorV2(id) {
|
|
686
|
-
const a = _apActors.get(id);
|
|
759
|
+
const a = _apActors.get(id);
|
|
760
|
+
if (!a) throw new Error(`activitypub actor ${id} not found`);
|
|
687
761
|
_apCheckA(a.status, AP_ACTOR_MATURITY_V2.ACTIVE);
|
|
688
762
|
const recovery = a.status === AP_ACTOR_MATURITY_V2.SUSPENDED;
|
|
689
|
-
if (!recovery) {
|
|
690
|
-
|
|
763
|
+
if (!recovery) {
|
|
764
|
+
const c = _apCountActive(a.owner);
|
|
765
|
+
if (c >= _apMaxActivePerOwner)
|
|
766
|
+
throw new Error(
|
|
767
|
+
`max active activitypub actors per owner (${_apMaxActivePerOwner}) reached for ${a.owner}`,
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
const now = Date.now();
|
|
771
|
+
a.status = AP_ACTOR_MATURITY_V2.ACTIVE;
|
|
772
|
+
a.updatedAt = now;
|
|
773
|
+
a.lastTouchedAt = now;
|
|
774
|
+
if (!a.activatedAt) a.activatedAt = now;
|
|
775
|
+
return { ...a, metadata: { ...a.metadata } };
|
|
776
|
+
}
|
|
777
|
+
export function suspendApActorV2(id) {
|
|
778
|
+
const a = _apActors.get(id);
|
|
779
|
+
if (!a) throw new Error(`activitypub actor ${id} not found`);
|
|
780
|
+
_apCheckA(a.status, AP_ACTOR_MATURITY_V2.SUSPENDED);
|
|
781
|
+
a.status = AP_ACTOR_MATURITY_V2.SUSPENDED;
|
|
782
|
+
a.updatedAt = Date.now();
|
|
783
|
+
return { ...a, metadata: { ...a.metadata } };
|
|
784
|
+
}
|
|
785
|
+
export function deactivateApActorV2(id) {
|
|
786
|
+
const a = _apActors.get(id);
|
|
787
|
+
if (!a) throw new Error(`activitypub actor ${id} not found`);
|
|
788
|
+
_apCheckA(a.status, AP_ACTOR_MATURITY_V2.DEACTIVATED);
|
|
789
|
+
const now = Date.now();
|
|
790
|
+
a.status = AP_ACTOR_MATURITY_V2.DEACTIVATED;
|
|
791
|
+
a.updatedAt = now;
|
|
792
|
+
if (!a.deactivatedAt) a.deactivatedAt = now;
|
|
793
|
+
return { ...a, metadata: { ...a.metadata } };
|
|
794
|
+
}
|
|
795
|
+
export function touchApActorV2(id) {
|
|
796
|
+
const a = _apActors.get(id);
|
|
797
|
+
if (!a) throw new Error(`activitypub actor ${id} not found`);
|
|
798
|
+
if (_apActorTerminal.has(a.status))
|
|
799
|
+
throw new Error(`cannot touch terminal activitypub actor ${id}`);
|
|
800
|
+
const now = Date.now();
|
|
801
|
+
a.lastTouchedAt = now;
|
|
802
|
+
a.updatedAt = now;
|
|
803
|
+
return { ...a, metadata: { ...a.metadata } };
|
|
804
|
+
}
|
|
805
|
+
export function getApActorV2(id) {
|
|
806
|
+
const a = _apActors.get(id);
|
|
807
|
+
if (!a) return null;
|
|
691
808
|
return { ...a, metadata: { ...a.metadata } };
|
|
692
809
|
}
|
|
693
|
-
export function
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
810
|
+
export function listApActorsV2() {
|
|
811
|
+
return [..._apActors.values()].map((a) => ({
|
|
812
|
+
...a,
|
|
813
|
+
metadata: { ...a.metadata },
|
|
814
|
+
}));
|
|
815
|
+
}
|
|
698
816
|
|
|
699
|
-
function _apCountPending(aid) {
|
|
817
|
+
function _apCountPending(aid) {
|
|
818
|
+
let n = 0;
|
|
819
|
+
for (const ac of _apActs.values())
|
|
820
|
+
if (
|
|
821
|
+
ac.actorId === aid &&
|
|
822
|
+
(ac.status === AP_ACTIVITY_LIFECYCLE_V2.QUEUED ||
|
|
823
|
+
ac.status === AP_ACTIVITY_LIFECYCLE_V2.DELIVERING)
|
|
824
|
+
)
|
|
825
|
+
n++;
|
|
826
|
+
return n;
|
|
827
|
+
}
|
|
700
828
|
|
|
701
829
|
export function createApActivityV2({ id, actorId, kind, metadata } = {}) {
|
|
702
830
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
703
|
-
if (!actorId || typeof actorId !== "string")
|
|
704
|
-
|
|
705
|
-
if (
|
|
831
|
+
if (!actorId || typeof actorId !== "string")
|
|
832
|
+
throw new Error("actorId is required");
|
|
833
|
+
if (_apActs.has(id))
|
|
834
|
+
throw new Error(`activitypub activity ${id} already exists`);
|
|
835
|
+
if (!_apActors.has(actorId))
|
|
836
|
+
throw new Error(`activitypub actor ${actorId} not found`);
|
|
706
837
|
const pending = _apCountPending(actorId);
|
|
707
|
-
if (pending >= _apMaxPendingPerActor)
|
|
838
|
+
if (pending >= _apMaxPendingPerActor)
|
|
839
|
+
throw new Error(
|
|
840
|
+
`max pending activitypub activities per actor (${_apMaxPendingPerActor}) reached for ${actorId}`,
|
|
841
|
+
);
|
|
708
842
|
const now = Date.now();
|
|
709
|
-
const ac = {
|
|
843
|
+
const ac = {
|
|
844
|
+
id,
|
|
845
|
+
actorId,
|
|
846
|
+
kind: kind || "Note",
|
|
847
|
+
status: AP_ACTIVITY_LIFECYCLE_V2.QUEUED,
|
|
848
|
+
createdAt: now,
|
|
849
|
+
updatedAt: now,
|
|
850
|
+
startedAt: null,
|
|
851
|
+
settledAt: null,
|
|
852
|
+
metadata: { ...(metadata || {}) },
|
|
853
|
+
};
|
|
710
854
|
_apActs.set(id, ac);
|
|
711
855
|
return { ...ac, metadata: { ...ac.metadata } };
|
|
712
856
|
}
|
|
713
|
-
function _apCheckAct(from, to) {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
export function
|
|
719
|
-
|
|
857
|
+
function _apCheckAct(from, to) {
|
|
858
|
+
const al = _apActTrans.get(from);
|
|
859
|
+
if (!al || !al.has(to))
|
|
860
|
+
throw new Error(`invalid activitypub activity transition ${from} → ${to}`);
|
|
861
|
+
}
|
|
862
|
+
export function startApActivityV2(id) {
|
|
863
|
+
const ac = _apActs.get(id);
|
|
864
|
+
if (!ac) throw new Error(`activitypub activity ${id} not found`);
|
|
865
|
+
_apCheckAct(ac.status, AP_ACTIVITY_LIFECYCLE_V2.DELIVERING);
|
|
866
|
+
const now = Date.now();
|
|
867
|
+
ac.status = AP_ACTIVITY_LIFECYCLE_V2.DELIVERING;
|
|
868
|
+
ac.updatedAt = now;
|
|
869
|
+
if (!ac.startedAt) ac.startedAt = now;
|
|
870
|
+
return { ...ac, metadata: { ...ac.metadata } };
|
|
871
|
+
}
|
|
872
|
+
export function deliverApActivityV2(id) {
|
|
873
|
+
const ac = _apActs.get(id);
|
|
874
|
+
if (!ac) throw new Error(`activitypub activity ${id} not found`);
|
|
875
|
+
_apCheckAct(ac.status, AP_ACTIVITY_LIFECYCLE_V2.DELIVERED);
|
|
876
|
+
const now = Date.now();
|
|
877
|
+
ac.status = AP_ACTIVITY_LIFECYCLE_V2.DELIVERED;
|
|
878
|
+
ac.updatedAt = now;
|
|
879
|
+
if (!ac.settledAt) ac.settledAt = now;
|
|
880
|
+
return { ...ac, metadata: { ...ac.metadata } };
|
|
881
|
+
}
|
|
882
|
+
export function failApActivityV2(id, reason) {
|
|
883
|
+
const ac = _apActs.get(id);
|
|
884
|
+
if (!ac) throw new Error(`activitypub activity ${id} not found`);
|
|
885
|
+
_apCheckAct(ac.status, AP_ACTIVITY_LIFECYCLE_V2.FAILED);
|
|
886
|
+
const now = Date.now();
|
|
887
|
+
ac.status = AP_ACTIVITY_LIFECYCLE_V2.FAILED;
|
|
888
|
+
ac.updatedAt = now;
|
|
889
|
+
if (!ac.settledAt) ac.settledAt = now;
|
|
890
|
+
if (reason) ac.metadata.failReason = String(reason);
|
|
891
|
+
return { ...ac, metadata: { ...ac.metadata } };
|
|
892
|
+
}
|
|
893
|
+
export function cancelApActivityV2(id, reason) {
|
|
894
|
+
const ac = _apActs.get(id);
|
|
895
|
+
if (!ac) throw new Error(`activitypub activity ${id} not found`);
|
|
896
|
+
_apCheckAct(ac.status, AP_ACTIVITY_LIFECYCLE_V2.CANCELLED);
|
|
897
|
+
const now = Date.now();
|
|
898
|
+
ac.status = AP_ACTIVITY_LIFECYCLE_V2.CANCELLED;
|
|
899
|
+
ac.updatedAt = now;
|
|
900
|
+
if (!ac.settledAt) ac.settledAt = now;
|
|
901
|
+
if (reason) ac.metadata.cancelReason = String(reason);
|
|
902
|
+
return { ...ac, metadata: { ...ac.metadata } };
|
|
903
|
+
}
|
|
904
|
+
export function getApActivityV2(id) {
|
|
905
|
+
const ac = _apActs.get(id);
|
|
906
|
+
if (!ac) return null;
|
|
907
|
+
return { ...ac, metadata: { ...ac.metadata } };
|
|
908
|
+
}
|
|
909
|
+
export function listApActivitiesV2() {
|
|
910
|
+
return [..._apActs.values()].map((ac) => ({
|
|
911
|
+
...ac,
|
|
912
|
+
metadata: { ...ac.metadata },
|
|
913
|
+
}));
|
|
914
|
+
}
|
|
720
915
|
|
|
721
|
-
export function autoSuspendIdleApActorsV2({ now } = {}) {
|
|
722
|
-
|
|
916
|
+
export function autoSuspendIdleApActorsV2({ now } = {}) {
|
|
917
|
+
const t = now ?? Date.now();
|
|
918
|
+
const flipped = [];
|
|
919
|
+
for (const a of _apActors.values())
|
|
920
|
+
if (
|
|
921
|
+
a.status === AP_ACTOR_MATURITY_V2.ACTIVE &&
|
|
922
|
+
t - a.lastTouchedAt >= _apActorIdleMs
|
|
923
|
+
) {
|
|
924
|
+
a.status = AP_ACTOR_MATURITY_V2.SUSPENDED;
|
|
925
|
+
a.updatedAt = t;
|
|
926
|
+
flipped.push(a.id);
|
|
927
|
+
}
|
|
928
|
+
return { flipped, count: flipped.length };
|
|
929
|
+
}
|
|
930
|
+
export function autoFailStuckApActivitiesV2({ now } = {}) {
|
|
931
|
+
const t = now ?? Date.now();
|
|
932
|
+
const flipped = [];
|
|
933
|
+
for (const ac of _apActs.values())
|
|
934
|
+
if (
|
|
935
|
+
ac.status === AP_ACTIVITY_LIFECYCLE_V2.DELIVERING &&
|
|
936
|
+
ac.startedAt != null &&
|
|
937
|
+
t - ac.startedAt >= _apActStuckMs
|
|
938
|
+
) {
|
|
939
|
+
ac.status = AP_ACTIVITY_LIFECYCLE_V2.FAILED;
|
|
940
|
+
ac.updatedAt = t;
|
|
941
|
+
if (!ac.settledAt) ac.settledAt = t;
|
|
942
|
+
ac.metadata.failReason = "auto-fail-stuck";
|
|
943
|
+
flipped.push(ac.id);
|
|
944
|
+
}
|
|
945
|
+
return { flipped, count: flipped.length };
|
|
946
|
+
}
|
|
723
947
|
|
|
724
948
|
export function getActivityPubBridgeStatsV2() {
|
|
725
|
-
const actorsByStatus = {};
|
|
726
|
-
|
|
727
|
-
|
|
949
|
+
const actorsByStatus = {};
|
|
950
|
+
for (const s of Object.values(AP_ACTOR_MATURITY_V2)) actorsByStatus[s] = 0;
|
|
951
|
+
for (const a of _apActors.values()) actorsByStatus[a.status]++;
|
|
952
|
+
const activitiesByStatus = {};
|
|
953
|
+
for (const s of Object.values(AP_ACTIVITY_LIFECYCLE_V2))
|
|
954
|
+
activitiesByStatus[s] = 0;
|
|
955
|
+
for (const ac of _apActs.values()) activitiesByStatus[ac.status]++;
|
|
956
|
+
return {
|
|
957
|
+
totalActorsV2: _apActors.size,
|
|
958
|
+
totalActivitiesV2: _apActs.size,
|
|
959
|
+
maxActiveApActorsPerOwner: _apMaxActivePerOwner,
|
|
960
|
+
maxPendingApActivitiesPerActor: _apMaxPendingPerActor,
|
|
961
|
+
apActorIdleMs: _apActorIdleMs,
|
|
962
|
+
apActivityStuckMs: _apActStuckMs,
|
|
963
|
+
actorsByStatus,
|
|
964
|
+
activitiesByStatus,
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// =====================================================================
|
|
969
|
+
// activitypub-bridge V2 governance overlay (iter21)
|
|
970
|
+
// =====================================================================
|
|
971
|
+
export const APGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
972
|
+
PENDING: "pending",
|
|
973
|
+
ACTIVE: "active",
|
|
974
|
+
SUSPENDED: "suspended",
|
|
975
|
+
ARCHIVED: "archived",
|
|
976
|
+
});
|
|
977
|
+
export const APGOV_DELIVERY_LIFECYCLE_V2 = Object.freeze({
|
|
978
|
+
QUEUED: "queued",
|
|
979
|
+
DELIVERING: "delivering",
|
|
980
|
+
DELIVERED: "delivered",
|
|
981
|
+
FAILED: "failed",
|
|
982
|
+
CANCELLED: "cancelled",
|
|
983
|
+
});
|
|
984
|
+
const _apgovPTrans = new Map([
|
|
985
|
+
[
|
|
986
|
+
APGOV_PROFILE_MATURITY_V2.PENDING,
|
|
987
|
+
new Set([
|
|
988
|
+
APGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
989
|
+
APGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
990
|
+
]),
|
|
991
|
+
],
|
|
992
|
+
[
|
|
993
|
+
APGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
994
|
+
new Set([
|
|
995
|
+
APGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
996
|
+
APGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
997
|
+
]),
|
|
998
|
+
],
|
|
999
|
+
[
|
|
1000
|
+
APGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1001
|
+
new Set([
|
|
1002
|
+
APGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1003
|
+
APGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1004
|
+
]),
|
|
1005
|
+
],
|
|
1006
|
+
[APGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1007
|
+
]);
|
|
1008
|
+
const _apgovPTerminal = new Set([APGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1009
|
+
const _apgovJTrans = new Map([
|
|
1010
|
+
[
|
|
1011
|
+
APGOV_DELIVERY_LIFECYCLE_V2.QUEUED,
|
|
1012
|
+
new Set([
|
|
1013
|
+
APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING,
|
|
1014
|
+
APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED,
|
|
1015
|
+
]),
|
|
1016
|
+
],
|
|
1017
|
+
[
|
|
1018
|
+
APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING,
|
|
1019
|
+
new Set([
|
|
1020
|
+
APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED,
|
|
1021
|
+
APGOV_DELIVERY_LIFECYCLE_V2.FAILED,
|
|
1022
|
+
APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED,
|
|
1023
|
+
]),
|
|
1024
|
+
],
|
|
1025
|
+
[APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED, new Set()],
|
|
1026
|
+
[APGOV_DELIVERY_LIFECYCLE_V2.FAILED, new Set()],
|
|
1027
|
+
[APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1028
|
+
]);
|
|
1029
|
+
const _apgovPsV2 = new Map();
|
|
1030
|
+
const _apgovJsV2 = new Map();
|
|
1031
|
+
let _apgovMaxActive = 8,
|
|
1032
|
+
_apgovMaxPending = 25,
|
|
1033
|
+
_apgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1034
|
+
_apgovStuckMs = 60 * 1000;
|
|
1035
|
+
function _apgovPos(n, label) {
|
|
1036
|
+
const v = Math.floor(Number(n));
|
|
1037
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1038
|
+
throw new Error(`${label} must be positive integer`);
|
|
1039
|
+
return v;
|
|
1040
|
+
}
|
|
1041
|
+
function _apgovCheckP(from, to) {
|
|
1042
|
+
const a = _apgovPTrans.get(from);
|
|
1043
|
+
if (!a || !a.has(to))
|
|
1044
|
+
throw new Error(`invalid apgov profile transition ${from} → ${to}`);
|
|
1045
|
+
}
|
|
1046
|
+
function _apgovCheckJ(from, to) {
|
|
1047
|
+
const a = _apgovJTrans.get(from);
|
|
1048
|
+
if (!a || !a.has(to))
|
|
1049
|
+
throw new Error(`invalid apgov delivery transition ${from} → ${to}`);
|
|
1050
|
+
}
|
|
1051
|
+
function _apgovCountActive(owner) {
|
|
1052
|
+
let c = 0;
|
|
1053
|
+
for (const p of _apgovPsV2.values())
|
|
1054
|
+
if (p.owner === owner && p.status === APGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
1055
|
+
return c;
|
|
1056
|
+
}
|
|
1057
|
+
function _apgovCountPending(profileId) {
|
|
1058
|
+
let c = 0;
|
|
1059
|
+
for (const j of _apgovJsV2.values())
|
|
1060
|
+
if (
|
|
1061
|
+
j.profileId === profileId &&
|
|
1062
|
+
(j.status === APGOV_DELIVERY_LIFECYCLE_V2.QUEUED ||
|
|
1063
|
+
j.status === APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING)
|
|
1064
|
+
)
|
|
1065
|
+
c++;
|
|
1066
|
+
return c;
|
|
1067
|
+
}
|
|
1068
|
+
export function setMaxActiveApgovProfilesPerOwnerV2(n) {
|
|
1069
|
+
_apgovMaxActive = _apgovPos(n, "maxActiveApgovProfilesPerOwner");
|
|
1070
|
+
}
|
|
1071
|
+
export function getMaxActiveApgovProfilesPerOwnerV2() {
|
|
1072
|
+
return _apgovMaxActive;
|
|
1073
|
+
}
|
|
1074
|
+
export function setMaxPendingApgovDeliverysPerProfileV2(n) {
|
|
1075
|
+
_apgovMaxPending = _apgovPos(n, "maxPendingApgovDeliverysPerProfile");
|
|
1076
|
+
}
|
|
1077
|
+
export function getMaxPendingApgovDeliverysPerProfileV2() {
|
|
1078
|
+
return _apgovMaxPending;
|
|
1079
|
+
}
|
|
1080
|
+
export function setApgovProfileIdleMsV2(n) {
|
|
1081
|
+
_apgovIdleMs = _apgovPos(n, "apgovProfileIdleMs");
|
|
1082
|
+
}
|
|
1083
|
+
export function getApgovProfileIdleMsV2() {
|
|
1084
|
+
return _apgovIdleMs;
|
|
1085
|
+
}
|
|
1086
|
+
export function setApgovDeliveryStuckMsV2(n) {
|
|
1087
|
+
_apgovStuckMs = _apgovPos(n, "apgovDeliveryStuckMs");
|
|
1088
|
+
}
|
|
1089
|
+
export function getApgovDeliveryStuckMsV2() {
|
|
1090
|
+
return _apgovStuckMs;
|
|
1091
|
+
}
|
|
1092
|
+
export function _resetStateActivityPubBridgeGovV2() {
|
|
1093
|
+
_apgovPsV2.clear();
|
|
1094
|
+
_apgovJsV2.clear();
|
|
1095
|
+
_apgovMaxActive = 8;
|
|
1096
|
+
_apgovMaxPending = 25;
|
|
1097
|
+
_apgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1098
|
+
_apgovStuckMs = 60 * 1000;
|
|
1099
|
+
}
|
|
1100
|
+
export function registerApgovProfileV2({ id, owner, actor, metadata } = {}) {
|
|
1101
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1102
|
+
if (_apgovPsV2.has(id)) throw new Error(`apgov profile ${id} already exists`);
|
|
1103
|
+
const now = Date.now();
|
|
1104
|
+
const p = {
|
|
1105
|
+
id,
|
|
1106
|
+
owner,
|
|
1107
|
+
actor: actor || "person",
|
|
1108
|
+
status: APGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1109
|
+
createdAt: now,
|
|
1110
|
+
updatedAt: now,
|
|
1111
|
+
lastTouchedAt: now,
|
|
1112
|
+
activatedAt: null,
|
|
1113
|
+
archivedAt: null,
|
|
1114
|
+
metadata: { ...(metadata || {}) },
|
|
1115
|
+
};
|
|
1116
|
+
_apgovPsV2.set(id, p);
|
|
1117
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1118
|
+
}
|
|
1119
|
+
export function activateApgovProfileV2(id) {
|
|
1120
|
+
const p = _apgovPsV2.get(id);
|
|
1121
|
+
if (!p) throw new Error(`apgov profile ${id} not found`);
|
|
1122
|
+
const isInitial = p.status === APGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1123
|
+
_apgovCheckP(p.status, APGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1124
|
+
if (isInitial && _apgovCountActive(p.owner) >= _apgovMaxActive)
|
|
1125
|
+
throw new Error(`max active apgov profiles for owner ${p.owner} reached`);
|
|
1126
|
+
const now = Date.now();
|
|
1127
|
+
p.status = APGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1128
|
+
p.updatedAt = now;
|
|
1129
|
+
p.lastTouchedAt = now;
|
|
1130
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1131
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1132
|
+
}
|
|
1133
|
+
export function suspendApgovProfileV2(id) {
|
|
1134
|
+
const p = _apgovPsV2.get(id);
|
|
1135
|
+
if (!p) throw new Error(`apgov profile ${id} not found`);
|
|
1136
|
+
_apgovCheckP(p.status, APGOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
1137
|
+
p.status = APGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1138
|
+
p.updatedAt = Date.now();
|
|
1139
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1140
|
+
}
|
|
1141
|
+
export function archiveApgovProfileV2(id) {
|
|
1142
|
+
const p = _apgovPsV2.get(id);
|
|
1143
|
+
if (!p) throw new Error(`apgov profile ${id} not found`);
|
|
1144
|
+
_apgovCheckP(p.status, APGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1145
|
+
const now = Date.now();
|
|
1146
|
+
p.status = APGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1147
|
+
p.updatedAt = now;
|
|
1148
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1149
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1150
|
+
}
|
|
1151
|
+
export function touchApgovProfileV2(id) {
|
|
1152
|
+
const p = _apgovPsV2.get(id);
|
|
1153
|
+
if (!p) throw new Error(`apgov profile ${id} not found`);
|
|
1154
|
+
if (_apgovPTerminal.has(p.status))
|
|
1155
|
+
throw new Error(`cannot touch terminal apgov profile ${id}`);
|
|
1156
|
+
const now = Date.now();
|
|
1157
|
+
p.lastTouchedAt = now;
|
|
1158
|
+
p.updatedAt = now;
|
|
1159
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1160
|
+
}
|
|
1161
|
+
export function getApgovProfileV2(id) {
|
|
1162
|
+
const p = _apgovPsV2.get(id);
|
|
1163
|
+
if (!p) return null;
|
|
1164
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1165
|
+
}
|
|
1166
|
+
export function listApgovProfilesV2() {
|
|
1167
|
+
return [..._apgovPsV2.values()].map((p) => ({
|
|
1168
|
+
...p,
|
|
1169
|
+
metadata: { ...p.metadata },
|
|
1170
|
+
}));
|
|
1171
|
+
}
|
|
1172
|
+
export function createApgovDeliveryV2({ id, profileId, inbox, metadata } = {}) {
|
|
1173
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1174
|
+
if (_apgovJsV2.has(id))
|
|
1175
|
+
throw new Error(`apgov delivery ${id} already exists`);
|
|
1176
|
+
if (!_apgovPsV2.has(profileId))
|
|
1177
|
+
throw new Error(`apgov profile ${profileId} not found`);
|
|
1178
|
+
if (_apgovCountPending(profileId) >= _apgovMaxPending)
|
|
1179
|
+
throw new Error(
|
|
1180
|
+
`max pending apgov deliverys for profile ${profileId} reached`,
|
|
1181
|
+
);
|
|
1182
|
+
const now = Date.now();
|
|
1183
|
+
const j = {
|
|
1184
|
+
id,
|
|
1185
|
+
profileId,
|
|
1186
|
+
inbox: inbox || "",
|
|
1187
|
+
status: APGOV_DELIVERY_LIFECYCLE_V2.QUEUED,
|
|
1188
|
+
createdAt: now,
|
|
1189
|
+
updatedAt: now,
|
|
1190
|
+
startedAt: null,
|
|
1191
|
+
settledAt: null,
|
|
1192
|
+
metadata: { ...(metadata || {}) },
|
|
1193
|
+
};
|
|
1194
|
+
_apgovJsV2.set(id, j);
|
|
1195
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1196
|
+
}
|
|
1197
|
+
export function deliveringApgovDeliveryV2(id) {
|
|
1198
|
+
const j = _apgovJsV2.get(id);
|
|
1199
|
+
if (!j) throw new Error(`apgov delivery ${id} not found`);
|
|
1200
|
+
_apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING);
|
|
1201
|
+
const now = Date.now();
|
|
1202
|
+
j.status = APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING;
|
|
1203
|
+
j.updatedAt = now;
|
|
1204
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1205
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1206
|
+
}
|
|
1207
|
+
export function completeDeliveryApgovV2(id) {
|
|
1208
|
+
const j = _apgovJsV2.get(id);
|
|
1209
|
+
if (!j) throw new Error(`apgov delivery ${id} not found`);
|
|
1210
|
+
_apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED);
|
|
1211
|
+
const now = Date.now();
|
|
1212
|
+
j.status = APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED;
|
|
1213
|
+
j.updatedAt = now;
|
|
1214
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1215
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1216
|
+
}
|
|
1217
|
+
export function failApgovDeliveryV2(id, reason) {
|
|
1218
|
+
const j = _apgovJsV2.get(id);
|
|
1219
|
+
if (!j) throw new Error(`apgov delivery ${id} not found`);
|
|
1220
|
+
_apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.FAILED);
|
|
1221
|
+
const now = Date.now();
|
|
1222
|
+
j.status = APGOV_DELIVERY_LIFECYCLE_V2.FAILED;
|
|
1223
|
+
j.updatedAt = now;
|
|
1224
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1225
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1226
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1227
|
+
}
|
|
1228
|
+
export function cancelApgovDeliveryV2(id, reason) {
|
|
1229
|
+
const j = _apgovJsV2.get(id);
|
|
1230
|
+
if (!j) throw new Error(`apgov delivery ${id} not found`);
|
|
1231
|
+
_apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED);
|
|
1232
|
+
const now = Date.now();
|
|
1233
|
+
j.status = APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED;
|
|
1234
|
+
j.updatedAt = now;
|
|
1235
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1236
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1237
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1238
|
+
}
|
|
1239
|
+
export function getApgovDeliveryV2(id) {
|
|
1240
|
+
const j = _apgovJsV2.get(id);
|
|
1241
|
+
if (!j) return null;
|
|
1242
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1243
|
+
}
|
|
1244
|
+
export function listApgovDeliverysV2() {
|
|
1245
|
+
return [..._apgovJsV2.values()].map((j) => ({
|
|
1246
|
+
...j,
|
|
1247
|
+
metadata: { ...j.metadata },
|
|
1248
|
+
}));
|
|
1249
|
+
}
|
|
1250
|
+
export function autoSuspendIdleApgovProfilesV2({ now } = {}) {
|
|
1251
|
+
const t = now ?? Date.now();
|
|
1252
|
+
const flipped = [];
|
|
1253
|
+
for (const p of _apgovPsV2.values())
|
|
1254
|
+
if (
|
|
1255
|
+
p.status === APGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1256
|
+
t - p.lastTouchedAt >= _apgovIdleMs
|
|
1257
|
+
) {
|
|
1258
|
+
p.status = APGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1259
|
+
p.updatedAt = t;
|
|
1260
|
+
flipped.push(p.id);
|
|
1261
|
+
}
|
|
1262
|
+
return { flipped, count: flipped.length };
|
|
1263
|
+
}
|
|
1264
|
+
export function autoFailStuckApgovDeliverysV2({ now } = {}) {
|
|
1265
|
+
const t = now ?? Date.now();
|
|
1266
|
+
const flipped = [];
|
|
1267
|
+
for (const j of _apgovJsV2.values())
|
|
1268
|
+
if (
|
|
1269
|
+
j.status === APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING &&
|
|
1270
|
+
j.startedAt != null &&
|
|
1271
|
+
t - j.startedAt >= _apgovStuckMs
|
|
1272
|
+
) {
|
|
1273
|
+
j.status = APGOV_DELIVERY_LIFECYCLE_V2.FAILED;
|
|
1274
|
+
j.updatedAt = t;
|
|
1275
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1276
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1277
|
+
flipped.push(j.id);
|
|
1278
|
+
}
|
|
1279
|
+
return { flipped, count: flipped.length };
|
|
1280
|
+
}
|
|
1281
|
+
export function getActivityPubBridgeGovStatsV2() {
|
|
1282
|
+
const profilesByStatus = {};
|
|
1283
|
+
for (const v of Object.values(APGOV_PROFILE_MATURITY_V2))
|
|
1284
|
+
profilesByStatus[v] = 0;
|
|
1285
|
+
for (const p of _apgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1286
|
+
const deliverysByStatus = {};
|
|
1287
|
+
for (const v of Object.values(APGOV_DELIVERY_LIFECYCLE_V2))
|
|
1288
|
+
deliverysByStatus[v] = 0;
|
|
1289
|
+
for (const j of _apgovJsV2.values()) deliverysByStatus[j.status]++;
|
|
1290
|
+
return {
|
|
1291
|
+
totalApgovProfilesV2: _apgovPsV2.size,
|
|
1292
|
+
totalApgovDeliverysV2: _apgovJsV2.size,
|
|
1293
|
+
maxActiveApgovProfilesPerOwner: _apgovMaxActive,
|
|
1294
|
+
maxPendingApgovDeliverysPerProfile: _apgovMaxPending,
|
|
1295
|
+
apgovProfileIdleMs: _apgovIdleMs,
|
|
1296
|
+
apgovDeliveryStuckMs: _apgovStuckMs,
|
|
1297
|
+
profilesByStatus,
|
|
1298
|
+
deliverysByStatus,
|
|
1299
|
+
};
|
|
728
1300
|
}
|