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
|
@@ -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
|
+
}
|
|
@@ -960,3 +960,336 @@ export function _resetStateV2() {
|
|
|
960
960
|
_entityStaleMsV2 = KG_DEFAULT_ENTITY_STALE_MS;
|
|
961
961
|
_relationStaleMsV2 = KG_DEFAULT_RELATION_STALE_MS;
|
|
962
962
|
}
|
|
963
|
+
|
|
964
|
+
// =====================================================================
|
|
965
|
+
// knowledge-graph V2 governance overlay (iter16)
|
|
966
|
+
// =====================================================================
|
|
967
|
+
export const KGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
968
|
+
PENDING: "pending",
|
|
969
|
+
ACTIVE: "active",
|
|
970
|
+
STALE: "stale",
|
|
971
|
+
ARCHIVED: "archived",
|
|
972
|
+
});
|
|
973
|
+
export const KGOV_IMPORT_LIFECYCLE_V2 = Object.freeze({
|
|
974
|
+
QUEUED: "queued",
|
|
975
|
+
IMPORTING: "importing",
|
|
976
|
+
IMPORTED: "imported",
|
|
977
|
+
FAILED: "failed",
|
|
978
|
+
CANCELLED: "cancelled",
|
|
979
|
+
});
|
|
980
|
+
const _kgovPTrans = new Map([
|
|
981
|
+
[
|
|
982
|
+
KGOV_PROFILE_MATURITY_V2.PENDING,
|
|
983
|
+
new Set([
|
|
984
|
+
KGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
985
|
+
KGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
986
|
+
]),
|
|
987
|
+
],
|
|
988
|
+
[
|
|
989
|
+
KGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
990
|
+
new Set([
|
|
991
|
+
KGOV_PROFILE_MATURITY_V2.STALE,
|
|
992
|
+
KGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
993
|
+
]),
|
|
994
|
+
],
|
|
995
|
+
[
|
|
996
|
+
KGOV_PROFILE_MATURITY_V2.STALE,
|
|
997
|
+
new Set([
|
|
998
|
+
KGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
999
|
+
KGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1000
|
+
]),
|
|
1001
|
+
],
|
|
1002
|
+
[KGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1003
|
+
]);
|
|
1004
|
+
const _kgovPTerminal = new Set([KGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1005
|
+
const _kgovJTrans = new Map([
|
|
1006
|
+
[
|
|
1007
|
+
KGOV_IMPORT_LIFECYCLE_V2.QUEUED,
|
|
1008
|
+
new Set([
|
|
1009
|
+
KGOV_IMPORT_LIFECYCLE_V2.IMPORTING,
|
|
1010
|
+
KGOV_IMPORT_LIFECYCLE_V2.CANCELLED,
|
|
1011
|
+
]),
|
|
1012
|
+
],
|
|
1013
|
+
[
|
|
1014
|
+
KGOV_IMPORT_LIFECYCLE_V2.IMPORTING,
|
|
1015
|
+
new Set([
|
|
1016
|
+
KGOV_IMPORT_LIFECYCLE_V2.IMPORTED,
|
|
1017
|
+
KGOV_IMPORT_LIFECYCLE_V2.FAILED,
|
|
1018
|
+
KGOV_IMPORT_LIFECYCLE_V2.CANCELLED,
|
|
1019
|
+
]),
|
|
1020
|
+
],
|
|
1021
|
+
[KGOV_IMPORT_LIFECYCLE_V2.IMPORTED, new Set()],
|
|
1022
|
+
[KGOV_IMPORT_LIFECYCLE_V2.FAILED, new Set()],
|
|
1023
|
+
[KGOV_IMPORT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1024
|
+
]);
|
|
1025
|
+
const _kgovPsV2 = new Map();
|
|
1026
|
+
const _kgovJsV2 = new Map();
|
|
1027
|
+
let _kgovMaxActive = 6,
|
|
1028
|
+
_kgovMaxPending = 20,
|
|
1029
|
+
_kgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1030
|
+
_kgovStuckMs = 60 * 1000;
|
|
1031
|
+
function _kgovPos(n, label) {
|
|
1032
|
+
const v = Math.floor(Number(n));
|
|
1033
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1034
|
+
throw new Error(`${label} must be positive integer`);
|
|
1035
|
+
return v;
|
|
1036
|
+
}
|
|
1037
|
+
function _kgovCheckP(from, to) {
|
|
1038
|
+
const a = _kgovPTrans.get(from);
|
|
1039
|
+
if (!a || !a.has(to))
|
|
1040
|
+
throw new Error(`invalid kgov profile transition ${from} → ${to}`);
|
|
1041
|
+
}
|
|
1042
|
+
function _kgovCheckJ(from, to) {
|
|
1043
|
+
const a = _kgovJTrans.get(from);
|
|
1044
|
+
if (!a || !a.has(to))
|
|
1045
|
+
throw new Error(`invalid kgov import transition ${from} → ${to}`);
|
|
1046
|
+
}
|
|
1047
|
+
function _kgovCountActive(owner) {
|
|
1048
|
+
let c = 0;
|
|
1049
|
+
for (const p of _kgovPsV2.values())
|
|
1050
|
+
if (p.owner === owner && p.status === KGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
1051
|
+
return c;
|
|
1052
|
+
}
|
|
1053
|
+
function _kgovCountPending(profileId) {
|
|
1054
|
+
let c = 0;
|
|
1055
|
+
for (const j of _kgovJsV2.values())
|
|
1056
|
+
if (
|
|
1057
|
+
j.profileId === profileId &&
|
|
1058
|
+
(j.status === KGOV_IMPORT_LIFECYCLE_V2.QUEUED ||
|
|
1059
|
+
j.status === KGOV_IMPORT_LIFECYCLE_V2.IMPORTING)
|
|
1060
|
+
)
|
|
1061
|
+
c++;
|
|
1062
|
+
return c;
|
|
1063
|
+
}
|
|
1064
|
+
export function setMaxActiveKgovProfilesPerOwnerV2(n) {
|
|
1065
|
+
_kgovMaxActive = _kgovPos(n, "maxActiveKgovProfilesPerOwner");
|
|
1066
|
+
}
|
|
1067
|
+
export function getMaxActiveKgovProfilesPerOwnerV2() {
|
|
1068
|
+
return _kgovMaxActive;
|
|
1069
|
+
}
|
|
1070
|
+
export function setMaxPendingKgovImportsPerProfileV2(n) {
|
|
1071
|
+
_kgovMaxPending = _kgovPos(n, "maxPendingKgovImportsPerProfile");
|
|
1072
|
+
}
|
|
1073
|
+
export function getMaxPendingKgovImportsPerProfileV2() {
|
|
1074
|
+
return _kgovMaxPending;
|
|
1075
|
+
}
|
|
1076
|
+
export function setKgovProfileIdleMsV2(n) {
|
|
1077
|
+
_kgovIdleMs = _kgovPos(n, "kgovProfileIdleMs");
|
|
1078
|
+
}
|
|
1079
|
+
export function getKgovProfileIdleMsV2() {
|
|
1080
|
+
return _kgovIdleMs;
|
|
1081
|
+
}
|
|
1082
|
+
export function setKgovImportStuckMsV2(n) {
|
|
1083
|
+
_kgovStuckMs = _kgovPos(n, "kgovImportStuckMs");
|
|
1084
|
+
}
|
|
1085
|
+
export function getKgovImportStuckMsV2() {
|
|
1086
|
+
return _kgovStuckMs;
|
|
1087
|
+
}
|
|
1088
|
+
export function _resetStateKnowledgeGraphV2() {
|
|
1089
|
+
_kgovPsV2.clear();
|
|
1090
|
+
_kgovJsV2.clear();
|
|
1091
|
+
_kgovMaxActive = 6;
|
|
1092
|
+
_kgovMaxPending = 20;
|
|
1093
|
+
_kgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1094
|
+
_kgovStuckMs = 60 * 1000;
|
|
1095
|
+
}
|
|
1096
|
+
export function registerKgovProfileV2({ id, owner, namespace, metadata } = {}) {
|
|
1097
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1098
|
+
if (_kgovPsV2.has(id)) throw new Error(`kgov profile ${id} already exists`);
|
|
1099
|
+
const now = Date.now();
|
|
1100
|
+
const p = {
|
|
1101
|
+
id,
|
|
1102
|
+
owner,
|
|
1103
|
+
namespace: namespace || "default",
|
|
1104
|
+
status: KGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1105
|
+
createdAt: now,
|
|
1106
|
+
updatedAt: now,
|
|
1107
|
+
lastTouchedAt: now,
|
|
1108
|
+
activatedAt: null,
|
|
1109
|
+
archivedAt: null,
|
|
1110
|
+
metadata: { ...(metadata || {}) },
|
|
1111
|
+
};
|
|
1112
|
+
_kgovPsV2.set(id, p);
|
|
1113
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1114
|
+
}
|
|
1115
|
+
export function activateKgovProfileV2(id) {
|
|
1116
|
+
const p = _kgovPsV2.get(id);
|
|
1117
|
+
if (!p) throw new Error(`kgov profile ${id} not found`);
|
|
1118
|
+
const isInitial = p.status === KGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1119
|
+
_kgovCheckP(p.status, KGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1120
|
+
if (isInitial && _kgovCountActive(p.owner) >= _kgovMaxActive)
|
|
1121
|
+
throw new Error(`max active kgov profiles for owner ${p.owner} reached`);
|
|
1122
|
+
const now = Date.now();
|
|
1123
|
+
p.status = KGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1124
|
+
p.updatedAt = now;
|
|
1125
|
+
p.lastTouchedAt = now;
|
|
1126
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1127
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1128
|
+
}
|
|
1129
|
+
export function staleKgovProfileV2(id) {
|
|
1130
|
+
const p = _kgovPsV2.get(id);
|
|
1131
|
+
if (!p) throw new Error(`kgov profile ${id} not found`);
|
|
1132
|
+
_kgovCheckP(p.status, KGOV_PROFILE_MATURITY_V2.STALE);
|
|
1133
|
+
p.status = KGOV_PROFILE_MATURITY_V2.STALE;
|
|
1134
|
+
p.updatedAt = Date.now();
|
|
1135
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1136
|
+
}
|
|
1137
|
+
export function archiveKgovProfileV2(id) {
|
|
1138
|
+
const p = _kgovPsV2.get(id);
|
|
1139
|
+
if (!p) throw new Error(`kgov profile ${id} not found`);
|
|
1140
|
+
_kgovCheckP(p.status, KGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1141
|
+
const now = Date.now();
|
|
1142
|
+
p.status = KGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1143
|
+
p.updatedAt = now;
|
|
1144
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1145
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1146
|
+
}
|
|
1147
|
+
export function touchKgovProfileV2(id) {
|
|
1148
|
+
const p = _kgovPsV2.get(id);
|
|
1149
|
+
if (!p) throw new Error(`kgov profile ${id} not found`);
|
|
1150
|
+
if (_kgovPTerminal.has(p.status))
|
|
1151
|
+
throw new Error(`cannot touch terminal kgov profile ${id}`);
|
|
1152
|
+
const now = Date.now();
|
|
1153
|
+
p.lastTouchedAt = now;
|
|
1154
|
+
p.updatedAt = now;
|
|
1155
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1156
|
+
}
|
|
1157
|
+
export function getKgovProfileV2(id) {
|
|
1158
|
+
const p = _kgovPsV2.get(id);
|
|
1159
|
+
if (!p) return null;
|
|
1160
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1161
|
+
}
|
|
1162
|
+
export function listKgovProfilesV2() {
|
|
1163
|
+
return [..._kgovPsV2.values()].map((p) => ({
|
|
1164
|
+
...p,
|
|
1165
|
+
metadata: { ...p.metadata },
|
|
1166
|
+
}));
|
|
1167
|
+
}
|
|
1168
|
+
export function createKgovImportV2({ id, profileId, source, metadata } = {}) {
|
|
1169
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1170
|
+
if (_kgovJsV2.has(id)) throw new Error(`kgov import ${id} already exists`);
|
|
1171
|
+
if (!_kgovPsV2.has(profileId))
|
|
1172
|
+
throw new Error(`kgov profile ${profileId} not found`);
|
|
1173
|
+
if (_kgovCountPending(profileId) >= _kgovMaxPending)
|
|
1174
|
+
throw new Error(
|
|
1175
|
+
`max pending kgov imports for profile ${profileId} reached`,
|
|
1176
|
+
);
|
|
1177
|
+
const now = Date.now();
|
|
1178
|
+
const j = {
|
|
1179
|
+
id,
|
|
1180
|
+
profileId,
|
|
1181
|
+
source: source || "",
|
|
1182
|
+
status: KGOV_IMPORT_LIFECYCLE_V2.QUEUED,
|
|
1183
|
+
createdAt: now,
|
|
1184
|
+
updatedAt: now,
|
|
1185
|
+
startedAt: null,
|
|
1186
|
+
settledAt: null,
|
|
1187
|
+
metadata: { ...(metadata || {}) },
|
|
1188
|
+
};
|
|
1189
|
+
_kgovJsV2.set(id, j);
|
|
1190
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1191
|
+
}
|
|
1192
|
+
export function importingKgovImportV2(id) {
|
|
1193
|
+
const j = _kgovJsV2.get(id);
|
|
1194
|
+
if (!j) throw new Error(`kgov import ${id} not found`);
|
|
1195
|
+
_kgovCheckJ(j.status, KGOV_IMPORT_LIFECYCLE_V2.IMPORTING);
|
|
1196
|
+
const now = Date.now();
|
|
1197
|
+
j.status = KGOV_IMPORT_LIFECYCLE_V2.IMPORTING;
|
|
1198
|
+
j.updatedAt = now;
|
|
1199
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1200
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1201
|
+
}
|
|
1202
|
+
export function completeImportKgovV2(id) {
|
|
1203
|
+
const j = _kgovJsV2.get(id);
|
|
1204
|
+
if (!j) throw new Error(`kgov import ${id} not found`);
|
|
1205
|
+
_kgovCheckJ(j.status, KGOV_IMPORT_LIFECYCLE_V2.IMPORTED);
|
|
1206
|
+
const now = Date.now();
|
|
1207
|
+
j.status = KGOV_IMPORT_LIFECYCLE_V2.IMPORTED;
|
|
1208
|
+
j.updatedAt = now;
|
|
1209
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1210
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1211
|
+
}
|
|
1212
|
+
export function failKgovImportV2(id, reason) {
|
|
1213
|
+
const j = _kgovJsV2.get(id);
|
|
1214
|
+
if (!j) throw new Error(`kgov import ${id} not found`);
|
|
1215
|
+
_kgovCheckJ(j.status, KGOV_IMPORT_LIFECYCLE_V2.FAILED);
|
|
1216
|
+
const now = Date.now();
|
|
1217
|
+
j.status = KGOV_IMPORT_LIFECYCLE_V2.FAILED;
|
|
1218
|
+
j.updatedAt = now;
|
|
1219
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1220
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1221
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1222
|
+
}
|
|
1223
|
+
export function cancelKgovImportV2(id, reason) {
|
|
1224
|
+
const j = _kgovJsV2.get(id);
|
|
1225
|
+
if (!j) throw new Error(`kgov import ${id} not found`);
|
|
1226
|
+
_kgovCheckJ(j.status, KGOV_IMPORT_LIFECYCLE_V2.CANCELLED);
|
|
1227
|
+
const now = Date.now();
|
|
1228
|
+
j.status = KGOV_IMPORT_LIFECYCLE_V2.CANCELLED;
|
|
1229
|
+
j.updatedAt = now;
|
|
1230
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1231
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1232
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1233
|
+
}
|
|
1234
|
+
export function getKgovImportV2(id) {
|
|
1235
|
+
const j = _kgovJsV2.get(id);
|
|
1236
|
+
if (!j) return null;
|
|
1237
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1238
|
+
}
|
|
1239
|
+
export function listKgovImportsV2() {
|
|
1240
|
+
return [..._kgovJsV2.values()].map((j) => ({
|
|
1241
|
+
...j,
|
|
1242
|
+
metadata: { ...j.metadata },
|
|
1243
|
+
}));
|
|
1244
|
+
}
|
|
1245
|
+
export function autoStaleIdleKgovProfilesV2({ now } = {}) {
|
|
1246
|
+
const t = now ?? Date.now();
|
|
1247
|
+
const flipped = [];
|
|
1248
|
+
for (const p of _kgovPsV2.values())
|
|
1249
|
+
if (
|
|
1250
|
+
p.status === KGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1251
|
+
t - p.lastTouchedAt >= _kgovIdleMs
|
|
1252
|
+
) {
|
|
1253
|
+
p.status = KGOV_PROFILE_MATURITY_V2.STALE;
|
|
1254
|
+
p.updatedAt = t;
|
|
1255
|
+
flipped.push(p.id);
|
|
1256
|
+
}
|
|
1257
|
+
return { flipped, count: flipped.length };
|
|
1258
|
+
}
|
|
1259
|
+
export function autoFailStuckKgovImportsV2({ now } = {}) {
|
|
1260
|
+
const t = now ?? Date.now();
|
|
1261
|
+
const flipped = [];
|
|
1262
|
+
for (const j of _kgovJsV2.values())
|
|
1263
|
+
if (
|
|
1264
|
+
j.status === KGOV_IMPORT_LIFECYCLE_V2.IMPORTING &&
|
|
1265
|
+
j.startedAt != null &&
|
|
1266
|
+
t - j.startedAt >= _kgovStuckMs
|
|
1267
|
+
) {
|
|
1268
|
+
j.status = KGOV_IMPORT_LIFECYCLE_V2.FAILED;
|
|
1269
|
+
j.updatedAt = t;
|
|
1270
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1271
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1272
|
+
flipped.push(j.id);
|
|
1273
|
+
}
|
|
1274
|
+
return { flipped, count: flipped.length };
|
|
1275
|
+
}
|
|
1276
|
+
export function getKnowledgeGraphGovStatsV2() {
|
|
1277
|
+
const profilesByStatus = {};
|
|
1278
|
+
for (const v of Object.values(KGOV_PROFILE_MATURITY_V2))
|
|
1279
|
+
profilesByStatus[v] = 0;
|
|
1280
|
+
for (const p of _kgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1281
|
+
const importsByStatus = {};
|
|
1282
|
+
for (const v of Object.values(KGOV_IMPORT_LIFECYCLE_V2))
|
|
1283
|
+
importsByStatus[v] = 0;
|
|
1284
|
+
for (const j of _kgovJsV2.values()) importsByStatus[j.status]++;
|
|
1285
|
+
return {
|
|
1286
|
+
totalKgovProfilesV2: _kgovPsV2.size,
|
|
1287
|
+
totalKgovImportsV2: _kgovJsV2.size,
|
|
1288
|
+
maxActiveKgovProfilesPerOwner: _kgovMaxActive,
|
|
1289
|
+
maxPendingKgovImportsPerProfile: _kgovMaxPending,
|
|
1290
|
+
kgovProfileIdleMs: _kgovIdleMs,
|
|
1291
|
+
kgovImportStuckMs: _kgovStuckMs,
|
|
1292
|
+
profilesByStatus,
|
|
1293
|
+
importsByStatus,
|
|
1294
|
+
};
|
|
1295
|
+
}
|