chainlesschain 0.145.0 → 0.156.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -3
- package/package.json +1 -1
- package/src/commands/a2a.js +201 -0
- package/src/commands/activitypub.js +207 -0
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +1250 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +203 -0
- package/src/commands/browse.js +213 -0
- package/src/commands/chat.js +605 -0
- package/src/commands/cli-anything.js +426 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +822 -0
- package/src/commands/config.js +213 -0
- package/src/commands/cowork.js +1666 -0
- package/src/commands/crosschain.js +203 -0
- package/src/commands/dao.js +203 -0
- package/src/commands/dbevo.js +227 -0
- package/src/commands/dev.js +207 -0
- package/src/commands/did-v2.js +217 -0
- package/src/commands/did.js +221 -0
- package/src/commands/dlp.js +213 -0
- package/src/commands/economy.js +199 -0
- package/src/commands/encrypt.js +201 -0
- package/src/commands/evolution.js +199 -0
- package/src/commands/evomap.js +830 -0
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fusion.js +205 -0
- package/src/commands/governance.js +209 -0
- package/src/commands/hmemory.js +203 -0
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/inference.js +207 -0
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/kg.js +195 -0
- package/src/commands/llm.js +426 -0
- package/src/commands/matrix.js +207 -0
- package/src/commands/mcp.js +217 -0
- package/src/commands/memory.js +412 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +209 -0
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +406 -0
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/perception.js +209 -0
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +199 -0
- package/src/commands/planmode.js +426 -0
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/plugin.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +233 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/services.js +207 -0
- package/src/commands/session.js +209 -0
- package/src/commands/setup.js +205 -0
- package/src/commands/skill.js +414 -0
- package/src/commands/social.js +201 -0
- package/src/commands/sso.js +209 -0
- package/src/commands/start.js +209 -0
- package/src/commands/stream.js +213 -0
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/tokens.js +209 -0
- package/src/commands/trust.js +217 -0
- package/src/commands/ui.js +225 -0
- package/src/commands/wallet.js +209 -0
- package/src/commands/workflow.js +412 -0
- package/src/index.js +252 -0
- package/src/lib/a2a-protocol.js +332 -0
- package/src/lib/activitypub-bridge.js +334 -0
- package/src/lib/agent-coordinator.js +334 -0
- package/src/lib/agent-economy.js +334 -0
- package/src/lib/agent-network.js +341 -0
- package/src/lib/agent-router.js +333 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +332 -0
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +333 -0
- package/src/lib/browser-automation.js +334 -0
- package/src/lib/chat-core.js +335 -0
- package/src/lib/cli-anything-bridge.js +341 -0
- package/src/lib/cli-context-engineering.js +351 -0
- package/src/lib/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -0
- package/src/lib/compliance-manager.js +334 -0
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/cowork-adapter.js +336 -0
- package/src/lib/cowork-evomap-adapter.js +341 -0
- package/src/lib/cowork-mcp-tools.js +341 -0
- package/src/lib/cowork-observe-html.js +341 -0
- package/src/lib/cowork-observe.js +341 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-templates.js +342 -1
- package/src/lib/cowork-template-marketplace.js +340 -0
- package/src/lib/cross-chain.js +339 -0
- package/src/lib/crypto-manager.js +334 -0
- package/src/lib/dao-governance.js +339 -0
- package/src/lib/dbevo.js +351 -0
- package/src/lib/decentral-infra.js +330 -0
- package/src/lib/did-manager.js +341 -0
- package/src/lib/did-v2-manager.js +341 -0
- package/src/lib/dlp-engine.js +339 -0
- package/src/lib/downloader.js +334 -0
- package/src/lib/evolution-system.js +334 -0
- package/src/lib/evomap-client.js +342 -0
- package/src/lib/evomap-federation.js +338 -0
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +330 -0
- package/src/lib/execution-backend.js +330 -0
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/hashline.js +338 -0
- package/src/lib/hierarchical-memory.js +334 -0
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +341 -0
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/interaction-adapter.js +330 -0
- package/src/lib/interactive-planner.js +354 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +331 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/memory-manager.js +336 -0
- package/src/lib/multimodal.js +330 -0
- package/src/lib/nl-programming.js +341 -0
- package/src/lib/nostr-bridge.js +336 -0
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/pipeline-orchestrator.js +332 -0
- package/src/lib/plan-mode.js +336 -0
- package/src/lib/plugin-autodiscovery.js +334 -0
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/process-manager.js +336 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/provider-options.js +346 -0
- package/src/lib/provider-stream.js +348 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-manager.js +337 -0
- package/src/lib/session-core-singletons.js +341 -0
- package/src/lib/session-manager.js +334 -0
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-mcp.js +336 -0
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stix-parser.js +346 -0
- package/src/lib/sub-agent-context.js +343 -0
- package/src/lib/sub-agent-profiles.js +335 -0
- package/src/lib/sub-agent-registry.js +336 -0
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +336 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/trust-security.js +343 -0
- package/src/lib/ueba.js +340 -0
- package/src/lib/universal-runtime.js +330 -0
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-ui-server.js +348 -0
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/workflow-expr.js +346 -0
- package/src/lib/ws-chat-handler.js +337 -0
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
|
+
}
|
|
@@ -681,3 +681,344 @@ export function _resetStateKnowledgeExporterV2() {
|
|
|
681
681
|
_stateV2.targetIdleMs = EXPORTER_DEFAULT_TARGET_IDLE_MS;
|
|
682
682
|
_stateV2.jobStuckMs = EXPORTER_DEFAULT_JOB_STUCK_MS;
|
|
683
683
|
}
|
|
684
|
+
|
|
685
|
+
// =====================================================================
|
|
686
|
+
// knowledge-exporter V2 governance overlay (iter22)
|
|
687
|
+
// =====================================================================
|
|
688
|
+
export const KEXPGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
689
|
+
PENDING: "pending",
|
|
690
|
+
ACTIVE: "active",
|
|
691
|
+
STALE: "stale",
|
|
692
|
+
ARCHIVED: "archived",
|
|
693
|
+
});
|
|
694
|
+
export const KEXPGOV_EXPORT_LIFECYCLE_V2 = Object.freeze({
|
|
695
|
+
QUEUED: "queued",
|
|
696
|
+
EXPORTING: "exporting",
|
|
697
|
+
EXPORTED: "exported",
|
|
698
|
+
FAILED: "failed",
|
|
699
|
+
CANCELLED: "cancelled",
|
|
700
|
+
});
|
|
701
|
+
const _kexpgovPTrans = new Map([
|
|
702
|
+
[
|
|
703
|
+
KEXPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
704
|
+
new Set([
|
|
705
|
+
KEXPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
706
|
+
KEXPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
707
|
+
]),
|
|
708
|
+
],
|
|
709
|
+
[
|
|
710
|
+
KEXPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
711
|
+
new Set([
|
|
712
|
+
KEXPGOV_PROFILE_MATURITY_V2.STALE,
|
|
713
|
+
KEXPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
714
|
+
]),
|
|
715
|
+
],
|
|
716
|
+
[
|
|
717
|
+
KEXPGOV_PROFILE_MATURITY_V2.STALE,
|
|
718
|
+
new Set([
|
|
719
|
+
KEXPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
720
|
+
KEXPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
721
|
+
]),
|
|
722
|
+
],
|
|
723
|
+
[KEXPGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
724
|
+
]);
|
|
725
|
+
const _kexpgovPTerminal = new Set([KEXPGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
726
|
+
const _kexpgovJTrans = new Map([
|
|
727
|
+
[
|
|
728
|
+
KEXPGOV_EXPORT_LIFECYCLE_V2.QUEUED,
|
|
729
|
+
new Set([
|
|
730
|
+
KEXPGOV_EXPORT_LIFECYCLE_V2.EXPORTING,
|
|
731
|
+
KEXPGOV_EXPORT_LIFECYCLE_V2.CANCELLED,
|
|
732
|
+
]),
|
|
733
|
+
],
|
|
734
|
+
[
|
|
735
|
+
KEXPGOV_EXPORT_LIFECYCLE_V2.EXPORTING,
|
|
736
|
+
new Set([
|
|
737
|
+
KEXPGOV_EXPORT_LIFECYCLE_V2.EXPORTED,
|
|
738
|
+
KEXPGOV_EXPORT_LIFECYCLE_V2.FAILED,
|
|
739
|
+
KEXPGOV_EXPORT_LIFECYCLE_V2.CANCELLED,
|
|
740
|
+
]),
|
|
741
|
+
],
|
|
742
|
+
[KEXPGOV_EXPORT_LIFECYCLE_V2.EXPORTED, new Set()],
|
|
743
|
+
[KEXPGOV_EXPORT_LIFECYCLE_V2.FAILED, new Set()],
|
|
744
|
+
[KEXPGOV_EXPORT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
745
|
+
]);
|
|
746
|
+
const _kexpgovPsV2 = new Map();
|
|
747
|
+
const _kexpgovJsV2 = new Map();
|
|
748
|
+
let _kexpgovMaxActive = 6,
|
|
749
|
+
_kexpgovMaxPending = 15,
|
|
750
|
+
_kexpgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
751
|
+
_kexpgovStuckMs = 60 * 1000;
|
|
752
|
+
function _kexpgovPos(n, label) {
|
|
753
|
+
const v = Math.floor(Number(n));
|
|
754
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
755
|
+
throw new Error(`${label} must be positive integer`);
|
|
756
|
+
return v;
|
|
757
|
+
}
|
|
758
|
+
function _kexpgovCheckP(from, to) {
|
|
759
|
+
const a = _kexpgovPTrans.get(from);
|
|
760
|
+
if (!a || !a.has(to))
|
|
761
|
+
throw new Error(`invalid kexpgov profile transition ${from} → ${to}`);
|
|
762
|
+
}
|
|
763
|
+
function _kexpgovCheckJ(from, to) {
|
|
764
|
+
const a = _kexpgovJTrans.get(from);
|
|
765
|
+
if (!a || !a.has(to))
|
|
766
|
+
throw new Error(`invalid kexpgov export transition ${from} → ${to}`);
|
|
767
|
+
}
|
|
768
|
+
function _kexpgovCountActive(owner) {
|
|
769
|
+
let c = 0;
|
|
770
|
+
for (const p of _kexpgovPsV2.values())
|
|
771
|
+
if (p.owner === owner && p.status === KEXPGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
772
|
+
c++;
|
|
773
|
+
return c;
|
|
774
|
+
}
|
|
775
|
+
function _kexpgovCountPending(profileId) {
|
|
776
|
+
let c = 0;
|
|
777
|
+
for (const j of _kexpgovJsV2.values())
|
|
778
|
+
if (
|
|
779
|
+
j.profileId === profileId &&
|
|
780
|
+
(j.status === KEXPGOV_EXPORT_LIFECYCLE_V2.QUEUED ||
|
|
781
|
+
j.status === KEXPGOV_EXPORT_LIFECYCLE_V2.EXPORTING)
|
|
782
|
+
)
|
|
783
|
+
c++;
|
|
784
|
+
return c;
|
|
785
|
+
}
|
|
786
|
+
export function setMaxActiveKexpgovProfilesPerOwnerV2(n) {
|
|
787
|
+
_kexpgovMaxActive = _kexpgovPos(n, "maxActiveKexpgovProfilesPerOwner");
|
|
788
|
+
}
|
|
789
|
+
export function getMaxActiveKexpgovProfilesPerOwnerV2() {
|
|
790
|
+
return _kexpgovMaxActive;
|
|
791
|
+
}
|
|
792
|
+
export function setMaxPendingKexpgovExportsPerProfileV2(n) {
|
|
793
|
+
_kexpgovMaxPending = _kexpgovPos(n, "maxPendingKexpgovExportsPerProfile");
|
|
794
|
+
}
|
|
795
|
+
export function getMaxPendingKexpgovExportsPerProfileV2() {
|
|
796
|
+
return _kexpgovMaxPending;
|
|
797
|
+
}
|
|
798
|
+
export function setKexpgovProfileIdleMsV2(n) {
|
|
799
|
+
_kexpgovIdleMs = _kexpgovPos(n, "kexpgovProfileIdleMs");
|
|
800
|
+
}
|
|
801
|
+
export function getKexpgovProfileIdleMsV2() {
|
|
802
|
+
return _kexpgovIdleMs;
|
|
803
|
+
}
|
|
804
|
+
export function setKexpgovExportStuckMsV2(n) {
|
|
805
|
+
_kexpgovStuckMs = _kexpgovPos(n, "kexpgovExportStuckMs");
|
|
806
|
+
}
|
|
807
|
+
export function getKexpgovExportStuckMsV2() {
|
|
808
|
+
return _kexpgovStuckMs;
|
|
809
|
+
}
|
|
810
|
+
export function _resetStateKnowledgeExporterGovV2() {
|
|
811
|
+
_kexpgovPsV2.clear();
|
|
812
|
+
_kexpgovJsV2.clear();
|
|
813
|
+
_kexpgovMaxActive = 6;
|
|
814
|
+
_kexpgovMaxPending = 15;
|
|
815
|
+
_kexpgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
816
|
+
_kexpgovStuckMs = 60 * 1000;
|
|
817
|
+
}
|
|
818
|
+
export function registerKexpgovProfileV2({ id, owner, format, metadata } = {}) {
|
|
819
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
820
|
+
if (_kexpgovPsV2.has(id))
|
|
821
|
+
throw new Error(`kexpgov profile ${id} already exists`);
|
|
822
|
+
const now = Date.now();
|
|
823
|
+
const p = {
|
|
824
|
+
id,
|
|
825
|
+
owner,
|
|
826
|
+
format: format || "json",
|
|
827
|
+
status: KEXPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
828
|
+
createdAt: now,
|
|
829
|
+
updatedAt: now,
|
|
830
|
+
lastTouchedAt: now,
|
|
831
|
+
activatedAt: null,
|
|
832
|
+
archivedAt: null,
|
|
833
|
+
metadata: { ...(metadata || {}) },
|
|
834
|
+
};
|
|
835
|
+
_kexpgovPsV2.set(id, p);
|
|
836
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
837
|
+
}
|
|
838
|
+
export function activateKexpgovProfileV2(id) {
|
|
839
|
+
const p = _kexpgovPsV2.get(id);
|
|
840
|
+
if (!p) throw new Error(`kexpgov profile ${id} not found`);
|
|
841
|
+
const isInitial = p.status === KEXPGOV_PROFILE_MATURITY_V2.PENDING;
|
|
842
|
+
_kexpgovCheckP(p.status, KEXPGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
843
|
+
if (isInitial && _kexpgovCountActive(p.owner) >= _kexpgovMaxActive)
|
|
844
|
+
throw new Error(`max active kexpgov profiles for owner ${p.owner} reached`);
|
|
845
|
+
const now = Date.now();
|
|
846
|
+
p.status = KEXPGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
847
|
+
p.updatedAt = now;
|
|
848
|
+
p.lastTouchedAt = now;
|
|
849
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
850
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
851
|
+
}
|
|
852
|
+
export function staleKexpgovProfileV2(id) {
|
|
853
|
+
const p = _kexpgovPsV2.get(id);
|
|
854
|
+
if (!p) throw new Error(`kexpgov profile ${id} not found`);
|
|
855
|
+
_kexpgovCheckP(p.status, KEXPGOV_PROFILE_MATURITY_V2.STALE);
|
|
856
|
+
p.status = KEXPGOV_PROFILE_MATURITY_V2.STALE;
|
|
857
|
+
p.updatedAt = Date.now();
|
|
858
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
859
|
+
}
|
|
860
|
+
export function archiveKexpgovProfileV2(id) {
|
|
861
|
+
const p = _kexpgovPsV2.get(id);
|
|
862
|
+
if (!p) throw new Error(`kexpgov profile ${id} not found`);
|
|
863
|
+
_kexpgovCheckP(p.status, KEXPGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
864
|
+
const now = Date.now();
|
|
865
|
+
p.status = KEXPGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
866
|
+
p.updatedAt = now;
|
|
867
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
868
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
869
|
+
}
|
|
870
|
+
export function touchKexpgovProfileV2(id) {
|
|
871
|
+
const p = _kexpgovPsV2.get(id);
|
|
872
|
+
if (!p) throw new Error(`kexpgov profile ${id} not found`);
|
|
873
|
+
if (_kexpgovPTerminal.has(p.status))
|
|
874
|
+
throw new Error(`cannot touch terminal kexpgov profile ${id}`);
|
|
875
|
+
const now = Date.now();
|
|
876
|
+
p.lastTouchedAt = now;
|
|
877
|
+
p.updatedAt = now;
|
|
878
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
879
|
+
}
|
|
880
|
+
export function getKexpgovProfileV2(id) {
|
|
881
|
+
const p = _kexpgovPsV2.get(id);
|
|
882
|
+
if (!p) return null;
|
|
883
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
884
|
+
}
|
|
885
|
+
export function listKexpgovProfilesV2() {
|
|
886
|
+
return [..._kexpgovPsV2.values()].map((p) => ({
|
|
887
|
+
...p,
|
|
888
|
+
metadata: { ...p.metadata },
|
|
889
|
+
}));
|
|
890
|
+
}
|
|
891
|
+
export function createKexpgovExportV2({
|
|
892
|
+
id,
|
|
893
|
+
profileId,
|
|
894
|
+
destination,
|
|
895
|
+
metadata,
|
|
896
|
+
} = {}) {
|
|
897
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
898
|
+
if (_kexpgovJsV2.has(id))
|
|
899
|
+
throw new Error(`kexpgov export ${id} already exists`);
|
|
900
|
+
if (!_kexpgovPsV2.has(profileId))
|
|
901
|
+
throw new Error(`kexpgov profile ${profileId} not found`);
|
|
902
|
+
if (_kexpgovCountPending(profileId) >= _kexpgovMaxPending)
|
|
903
|
+
throw new Error(
|
|
904
|
+
`max pending kexpgov exports for profile ${profileId} reached`,
|
|
905
|
+
);
|
|
906
|
+
const now = Date.now();
|
|
907
|
+
const j = {
|
|
908
|
+
id,
|
|
909
|
+
profileId,
|
|
910
|
+
destination: destination || "",
|
|
911
|
+
status: KEXPGOV_EXPORT_LIFECYCLE_V2.QUEUED,
|
|
912
|
+
createdAt: now,
|
|
913
|
+
updatedAt: now,
|
|
914
|
+
startedAt: null,
|
|
915
|
+
settledAt: null,
|
|
916
|
+
metadata: { ...(metadata || {}) },
|
|
917
|
+
};
|
|
918
|
+
_kexpgovJsV2.set(id, j);
|
|
919
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
920
|
+
}
|
|
921
|
+
export function exportingKexpgovExportV2(id) {
|
|
922
|
+
const j = _kexpgovJsV2.get(id);
|
|
923
|
+
if (!j) throw new Error(`kexpgov export ${id} not found`);
|
|
924
|
+
_kexpgovCheckJ(j.status, KEXPGOV_EXPORT_LIFECYCLE_V2.EXPORTING);
|
|
925
|
+
const now = Date.now();
|
|
926
|
+
j.status = KEXPGOV_EXPORT_LIFECYCLE_V2.EXPORTING;
|
|
927
|
+
j.updatedAt = now;
|
|
928
|
+
if (!j.startedAt) j.startedAt = now;
|
|
929
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
930
|
+
}
|
|
931
|
+
export function completeExportKexpgovV2(id) {
|
|
932
|
+
const j = _kexpgovJsV2.get(id);
|
|
933
|
+
if (!j) throw new Error(`kexpgov export ${id} not found`);
|
|
934
|
+
_kexpgovCheckJ(j.status, KEXPGOV_EXPORT_LIFECYCLE_V2.EXPORTED);
|
|
935
|
+
const now = Date.now();
|
|
936
|
+
j.status = KEXPGOV_EXPORT_LIFECYCLE_V2.EXPORTED;
|
|
937
|
+
j.updatedAt = now;
|
|
938
|
+
if (!j.settledAt) j.settledAt = now;
|
|
939
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
940
|
+
}
|
|
941
|
+
export function failKexpgovExportV2(id, reason) {
|
|
942
|
+
const j = _kexpgovJsV2.get(id);
|
|
943
|
+
if (!j) throw new Error(`kexpgov export ${id} not found`);
|
|
944
|
+
_kexpgovCheckJ(j.status, KEXPGOV_EXPORT_LIFECYCLE_V2.FAILED);
|
|
945
|
+
const now = Date.now();
|
|
946
|
+
j.status = KEXPGOV_EXPORT_LIFECYCLE_V2.FAILED;
|
|
947
|
+
j.updatedAt = now;
|
|
948
|
+
if (!j.settledAt) j.settledAt = now;
|
|
949
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
950
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
951
|
+
}
|
|
952
|
+
export function cancelKexpgovExportV2(id, reason) {
|
|
953
|
+
const j = _kexpgovJsV2.get(id);
|
|
954
|
+
if (!j) throw new Error(`kexpgov export ${id} not found`);
|
|
955
|
+
_kexpgovCheckJ(j.status, KEXPGOV_EXPORT_LIFECYCLE_V2.CANCELLED);
|
|
956
|
+
const now = Date.now();
|
|
957
|
+
j.status = KEXPGOV_EXPORT_LIFECYCLE_V2.CANCELLED;
|
|
958
|
+
j.updatedAt = now;
|
|
959
|
+
if (!j.settledAt) j.settledAt = now;
|
|
960
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
961
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
962
|
+
}
|
|
963
|
+
export function getKexpgovExportV2(id) {
|
|
964
|
+
const j = _kexpgovJsV2.get(id);
|
|
965
|
+
if (!j) return null;
|
|
966
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
967
|
+
}
|
|
968
|
+
export function listKexpgovExportsV2() {
|
|
969
|
+
return [..._kexpgovJsV2.values()].map((j) => ({
|
|
970
|
+
...j,
|
|
971
|
+
metadata: { ...j.metadata },
|
|
972
|
+
}));
|
|
973
|
+
}
|
|
974
|
+
export function autoStaleIdleKexpgovProfilesV2({ now } = {}) {
|
|
975
|
+
const t = now ?? Date.now();
|
|
976
|
+
const flipped = [];
|
|
977
|
+
for (const p of _kexpgovPsV2.values())
|
|
978
|
+
if (
|
|
979
|
+
p.status === KEXPGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
980
|
+
t - p.lastTouchedAt >= _kexpgovIdleMs
|
|
981
|
+
) {
|
|
982
|
+
p.status = KEXPGOV_PROFILE_MATURITY_V2.STALE;
|
|
983
|
+
p.updatedAt = t;
|
|
984
|
+
flipped.push(p.id);
|
|
985
|
+
}
|
|
986
|
+
return { flipped, count: flipped.length };
|
|
987
|
+
}
|
|
988
|
+
export function autoFailStuckKexpgovExportsV2({ now } = {}) {
|
|
989
|
+
const t = now ?? Date.now();
|
|
990
|
+
const flipped = [];
|
|
991
|
+
for (const j of _kexpgovJsV2.values())
|
|
992
|
+
if (
|
|
993
|
+
j.status === KEXPGOV_EXPORT_LIFECYCLE_V2.EXPORTING &&
|
|
994
|
+
j.startedAt != null &&
|
|
995
|
+
t - j.startedAt >= _kexpgovStuckMs
|
|
996
|
+
) {
|
|
997
|
+
j.status = KEXPGOV_EXPORT_LIFECYCLE_V2.FAILED;
|
|
998
|
+
j.updatedAt = t;
|
|
999
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1000
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1001
|
+
flipped.push(j.id);
|
|
1002
|
+
}
|
|
1003
|
+
return { flipped, count: flipped.length };
|
|
1004
|
+
}
|
|
1005
|
+
export function getKnowledgeExporterGovStatsV2() {
|
|
1006
|
+
const profilesByStatus = {};
|
|
1007
|
+
for (const v of Object.values(KEXPGOV_PROFILE_MATURITY_V2))
|
|
1008
|
+
profilesByStatus[v] = 0;
|
|
1009
|
+
for (const p of _kexpgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1010
|
+
const exportsByStatus = {};
|
|
1011
|
+
for (const v of Object.values(KEXPGOV_EXPORT_LIFECYCLE_V2))
|
|
1012
|
+
exportsByStatus[v] = 0;
|
|
1013
|
+
for (const j of _kexpgovJsV2.values()) exportsByStatus[j.status]++;
|
|
1014
|
+
return {
|
|
1015
|
+
totalKexpgovProfilesV2: _kexpgovPsV2.size,
|
|
1016
|
+
totalKexpgovExportsV2: _kexpgovJsV2.size,
|
|
1017
|
+
maxActiveKexpgovProfilesPerOwner: _kexpgovMaxActive,
|
|
1018
|
+
maxPendingKexpgovExportsPerProfile: _kexpgovMaxPending,
|
|
1019
|
+
kexpgovProfileIdleMs: _kexpgovIdleMs,
|
|
1020
|
+
kexpgovExportStuckMs: _kexpgovStuckMs,
|
|
1021
|
+
profilesByStatus,
|
|
1022
|
+
exportsByStatus,
|
|
1023
|
+
};
|
|
1024
|
+
}
|