chainlesschain 0.143.0 → 0.145.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 +157 -27
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/bi.js +152 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +190 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/compliance.js +414 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +580 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dlp.js +172 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +182 -27
- package/src/commands/fflag.js +74 -22
- package/src/commands/git.js +177 -37
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +179 -27
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/nostr.js +178 -27
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/recommend.js +177 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/sandbox.js +206 -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/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +157 -32
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/topiccls.js +146 -33
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/webfetch.js +141 -32
- package/src/commands/zkp.js +184 -28
- package/src/index.js +40 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +288 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/bi-engine.js +283 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +296 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -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-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -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/dlp-engine.js +287 -49
- package/src/lib/evolution-system.js +278 -47
- 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/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/inference-network.js +308 -51
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/matrix-bridge.js +281 -47
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/nostr-bridge.js +286 -49
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perf-tuning.js +309 -50
- 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/privacy-computing.js +335 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/sandbox-v2.js +327 -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-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-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/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/zkp-engine.js +286 -49
|
@@ -706,83 +706,329 @@ export function analyticsStats(snapshot, opts = {}) {
|
|
|
706
706
|
};
|
|
707
707
|
}
|
|
708
708
|
|
|
709
|
-
|
|
710
709
|
// =====================================================================
|
|
711
710
|
// Social Graph Analytics V2 governance overlay
|
|
712
711
|
// =====================================================================
|
|
713
|
-
export const SGAN_PROFILE_MATURITY_V2 = Object.freeze({
|
|
714
|
-
|
|
712
|
+
export const SGAN_PROFILE_MATURITY_V2 = Object.freeze({
|
|
713
|
+
PENDING: "pending",
|
|
714
|
+
ACTIVE: "active",
|
|
715
|
+
STALE: "stale",
|
|
716
|
+
ARCHIVED: "archived",
|
|
717
|
+
});
|
|
718
|
+
export const SGAN_RUN_LIFECYCLE_V2 = Object.freeze({
|
|
719
|
+
QUEUED: "queued",
|
|
720
|
+
RUNNING: "running",
|
|
721
|
+
COMPLETED: "completed",
|
|
722
|
+
FAILED: "failed",
|
|
723
|
+
CANCELLED: "cancelled",
|
|
724
|
+
});
|
|
715
725
|
const _sganPTrans = new Map([
|
|
716
|
-
[
|
|
717
|
-
|
|
718
|
-
|
|
726
|
+
[
|
|
727
|
+
SGAN_PROFILE_MATURITY_V2.PENDING,
|
|
728
|
+
new Set([
|
|
729
|
+
SGAN_PROFILE_MATURITY_V2.ACTIVE,
|
|
730
|
+
SGAN_PROFILE_MATURITY_V2.ARCHIVED,
|
|
731
|
+
]),
|
|
732
|
+
],
|
|
733
|
+
[
|
|
734
|
+
SGAN_PROFILE_MATURITY_V2.ACTIVE,
|
|
735
|
+
new Set([
|
|
736
|
+
SGAN_PROFILE_MATURITY_V2.STALE,
|
|
737
|
+
SGAN_PROFILE_MATURITY_V2.ARCHIVED,
|
|
738
|
+
]),
|
|
739
|
+
],
|
|
740
|
+
[
|
|
741
|
+
SGAN_PROFILE_MATURITY_V2.STALE,
|
|
742
|
+
new Set([
|
|
743
|
+
SGAN_PROFILE_MATURITY_V2.ACTIVE,
|
|
744
|
+
SGAN_PROFILE_MATURITY_V2.ARCHIVED,
|
|
745
|
+
]),
|
|
746
|
+
],
|
|
719
747
|
[SGAN_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
720
748
|
]);
|
|
721
749
|
const _sganPTerminal = new Set([SGAN_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
722
750
|
const _sganJTrans = new Map([
|
|
723
|
-
[
|
|
724
|
-
|
|
751
|
+
[
|
|
752
|
+
SGAN_RUN_LIFECYCLE_V2.QUEUED,
|
|
753
|
+
new Set([SGAN_RUN_LIFECYCLE_V2.RUNNING, SGAN_RUN_LIFECYCLE_V2.CANCELLED]),
|
|
754
|
+
],
|
|
755
|
+
[
|
|
756
|
+
SGAN_RUN_LIFECYCLE_V2.RUNNING,
|
|
757
|
+
new Set([
|
|
758
|
+
SGAN_RUN_LIFECYCLE_V2.COMPLETED,
|
|
759
|
+
SGAN_RUN_LIFECYCLE_V2.FAILED,
|
|
760
|
+
SGAN_RUN_LIFECYCLE_V2.CANCELLED,
|
|
761
|
+
]),
|
|
762
|
+
],
|
|
725
763
|
[SGAN_RUN_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
726
764
|
[SGAN_RUN_LIFECYCLE_V2.FAILED, new Set()],
|
|
727
765
|
[SGAN_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
728
766
|
]);
|
|
729
767
|
const _sganPsV2 = new Map();
|
|
730
768
|
const _sganJsV2 = new Map();
|
|
731
|
-
let _sganMaxActive = 6,
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
function
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
769
|
+
let _sganMaxActive = 6,
|
|
770
|
+
_sganMaxPending = 12,
|
|
771
|
+
_sganIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
772
|
+
_sganStuckMs = 60 * 1000;
|
|
773
|
+
function _sganPos(n, label) {
|
|
774
|
+
const v = Math.floor(Number(n));
|
|
775
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
776
|
+
throw new Error(`${label} must be positive integer`);
|
|
777
|
+
return v;
|
|
778
|
+
}
|
|
779
|
+
function _sganCheckP(from, to) {
|
|
780
|
+
const a = _sganPTrans.get(from);
|
|
781
|
+
if (!a || !a.has(to))
|
|
782
|
+
throw new Error(`invalid sgan profile transition ${from} → ${to}`);
|
|
783
|
+
}
|
|
784
|
+
function _sganCheckJ(from, to) {
|
|
785
|
+
const a = _sganJTrans.get(from);
|
|
786
|
+
if (!a || !a.has(to))
|
|
787
|
+
throw new Error(`invalid sgan run transition ${from} → ${to}`);
|
|
788
|
+
}
|
|
789
|
+
function _sganCountActive(owner) {
|
|
790
|
+
let c = 0;
|
|
791
|
+
for (const p of _sganPsV2.values())
|
|
792
|
+
if (p.owner === owner && p.status === SGAN_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
793
|
+
return c;
|
|
794
|
+
}
|
|
795
|
+
function _sganCountPending(profileId) {
|
|
796
|
+
let c = 0;
|
|
797
|
+
for (const j of _sganJsV2.values())
|
|
798
|
+
if (
|
|
799
|
+
j.profileId === profileId &&
|
|
800
|
+
(j.status === SGAN_RUN_LIFECYCLE_V2.QUEUED ||
|
|
801
|
+
j.status === SGAN_RUN_LIFECYCLE_V2.RUNNING)
|
|
802
|
+
)
|
|
803
|
+
c++;
|
|
804
|
+
return c;
|
|
805
|
+
}
|
|
806
|
+
export function setMaxActiveSganProfilesPerOwnerV2(n) {
|
|
807
|
+
_sganMaxActive = _sganPos(n, "maxActiveSganProfilesPerOwner");
|
|
808
|
+
}
|
|
809
|
+
export function getMaxActiveSganProfilesPerOwnerV2() {
|
|
810
|
+
return _sganMaxActive;
|
|
811
|
+
}
|
|
812
|
+
export function setMaxPendingSganRunsPerProfileV2(n) {
|
|
813
|
+
_sganMaxPending = _sganPos(n, "maxPendingSganRunsPerProfile");
|
|
814
|
+
}
|
|
815
|
+
export function getMaxPendingSganRunsPerProfileV2() {
|
|
816
|
+
return _sganMaxPending;
|
|
817
|
+
}
|
|
818
|
+
export function setSganProfileIdleMsV2(n) {
|
|
819
|
+
_sganIdleMs = _sganPos(n, "sganProfileIdleMs");
|
|
820
|
+
}
|
|
821
|
+
export function getSganProfileIdleMsV2() {
|
|
822
|
+
return _sganIdleMs;
|
|
823
|
+
}
|
|
824
|
+
export function setSganRunStuckMsV2(n) {
|
|
825
|
+
_sganStuckMs = _sganPos(n, "sganRunStuckMs");
|
|
826
|
+
}
|
|
827
|
+
export function getSganRunStuckMsV2() {
|
|
828
|
+
return _sganStuckMs;
|
|
829
|
+
}
|
|
830
|
+
export function _resetStateSocialGraphAnalyticsV2() {
|
|
831
|
+
_sganPsV2.clear();
|
|
832
|
+
_sganJsV2.clear();
|
|
833
|
+
_sganMaxActive = 6;
|
|
834
|
+
_sganMaxPending = 12;
|
|
835
|
+
_sganIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
836
|
+
_sganStuckMs = 60 * 1000;
|
|
837
|
+
}
|
|
746
838
|
export function registerSganProfileV2({ id, owner, algorithm, metadata } = {}) {
|
|
747
839
|
if (!id || !owner) throw new Error("id and owner required");
|
|
748
840
|
if (_sganPsV2.has(id)) throw new Error(`sgan profile ${id} already exists`);
|
|
749
841
|
const now = Date.now();
|
|
750
|
-
const p = {
|
|
751
|
-
|
|
842
|
+
const p = {
|
|
843
|
+
id,
|
|
844
|
+
owner,
|
|
845
|
+
algorithm: algorithm || "centrality",
|
|
846
|
+
status: SGAN_PROFILE_MATURITY_V2.PENDING,
|
|
847
|
+
createdAt: now,
|
|
848
|
+
updatedAt: now,
|
|
849
|
+
lastTouchedAt: now,
|
|
850
|
+
activatedAt: null,
|
|
851
|
+
archivedAt: null,
|
|
852
|
+
metadata: { ...(metadata || {}) },
|
|
853
|
+
};
|
|
854
|
+
_sganPsV2.set(id, p);
|
|
855
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
752
856
|
}
|
|
753
857
|
export function activateSganProfileV2(id) {
|
|
754
|
-
const p = _sganPsV2.get(id);
|
|
858
|
+
const p = _sganPsV2.get(id);
|
|
859
|
+
if (!p) throw new Error(`sgan profile ${id} not found`);
|
|
755
860
|
const isInitial = p.status === SGAN_PROFILE_MATURITY_V2.PENDING;
|
|
756
861
|
_sganCheckP(p.status, SGAN_PROFILE_MATURITY_V2.ACTIVE);
|
|
757
|
-
if (isInitial && _sganCountActive(p.owner) >= _sganMaxActive)
|
|
758
|
-
|
|
862
|
+
if (isInitial && _sganCountActive(p.owner) >= _sganMaxActive)
|
|
863
|
+
throw new Error(`max active sgan profiles for owner ${p.owner} reached`);
|
|
864
|
+
const now = Date.now();
|
|
865
|
+
p.status = SGAN_PROFILE_MATURITY_V2.ACTIVE;
|
|
866
|
+
p.updatedAt = now;
|
|
867
|
+
p.lastTouchedAt = now;
|
|
759
868
|
if (!p.activatedAt) p.activatedAt = now;
|
|
760
869
|
return { ...p, metadata: { ...p.metadata } };
|
|
761
870
|
}
|
|
762
|
-
export function staleSganProfileV2(id) {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
871
|
+
export function staleSganProfileV2(id) {
|
|
872
|
+
const p = _sganPsV2.get(id);
|
|
873
|
+
if (!p) throw new Error(`sgan profile ${id} not found`);
|
|
874
|
+
_sganCheckP(p.status, SGAN_PROFILE_MATURITY_V2.STALE);
|
|
875
|
+
p.status = SGAN_PROFILE_MATURITY_V2.STALE;
|
|
876
|
+
p.updatedAt = Date.now();
|
|
877
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
878
|
+
}
|
|
879
|
+
export function archiveSganProfileV2(id) {
|
|
880
|
+
const p = _sganPsV2.get(id);
|
|
881
|
+
if (!p) throw new Error(`sgan profile ${id} not found`);
|
|
882
|
+
_sganCheckP(p.status, SGAN_PROFILE_MATURITY_V2.ARCHIVED);
|
|
883
|
+
const now = Date.now();
|
|
884
|
+
p.status = SGAN_PROFILE_MATURITY_V2.ARCHIVED;
|
|
885
|
+
p.updatedAt = now;
|
|
886
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
887
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
888
|
+
}
|
|
889
|
+
export function touchSganProfileV2(id) {
|
|
890
|
+
const p = _sganPsV2.get(id);
|
|
891
|
+
if (!p) throw new Error(`sgan profile ${id} not found`);
|
|
892
|
+
if (_sganPTerminal.has(p.status))
|
|
893
|
+
throw new Error(`cannot touch terminal sgan profile ${id}`);
|
|
894
|
+
const now = Date.now();
|
|
895
|
+
p.lastTouchedAt = now;
|
|
896
|
+
p.updatedAt = now;
|
|
897
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
898
|
+
}
|
|
899
|
+
export function getSganProfileV2(id) {
|
|
900
|
+
const p = _sganPsV2.get(id);
|
|
901
|
+
if (!p) return null;
|
|
902
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
903
|
+
}
|
|
904
|
+
export function listSganProfilesV2() {
|
|
905
|
+
return [..._sganPsV2.values()].map((p) => ({
|
|
906
|
+
...p,
|
|
907
|
+
metadata: { ...p.metadata },
|
|
908
|
+
}));
|
|
909
|
+
}
|
|
767
910
|
export function createSganRunV2({ id, profileId, snapshotId, metadata } = {}) {
|
|
768
911
|
if (!id || !profileId) throw new Error("id and profileId required");
|
|
769
912
|
if (_sganJsV2.has(id)) throw new Error(`sgan run ${id} already exists`);
|
|
770
|
-
if (!_sganPsV2.has(profileId))
|
|
771
|
-
|
|
913
|
+
if (!_sganPsV2.has(profileId))
|
|
914
|
+
throw new Error(`sgan profile ${profileId} not found`);
|
|
915
|
+
if (_sganCountPending(profileId) >= _sganMaxPending)
|
|
916
|
+
throw new Error(`max pending sgan runs for profile ${profileId} reached`);
|
|
917
|
+
const now = Date.now();
|
|
918
|
+
const j = {
|
|
919
|
+
id,
|
|
920
|
+
profileId,
|
|
921
|
+
snapshotId: snapshotId || "",
|
|
922
|
+
status: SGAN_RUN_LIFECYCLE_V2.QUEUED,
|
|
923
|
+
createdAt: now,
|
|
924
|
+
updatedAt: now,
|
|
925
|
+
startedAt: null,
|
|
926
|
+
settledAt: null,
|
|
927
|
+
metadata: { ...(metadata || {}) },
|
|
928
|
+
};
|
|
929
|
+
_sganJsV2.set(id, j);
|
|
930
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
931
|
+
}
|
|
932
|
+
export function runningSganRunV2(id) {
|
|
933
|
+
const j = _sganJsV2.get(id);
|
|
934
|
+
if (!j) throw new Error(`sgan run ${id} not found`);
|
|
935
|
+
_sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.RUNNING);
|
|
936
|
+
const now = Date.now();
|
|
937
|
+
j.status = SGAN_RUN_LIFECYCLE_V2.RUNNING;
|
|
938
|
+
j.updatedAt = now;
|
|
939
|
+
if (!j.startedAt) j.startedAt = now;
|
|
940
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
941
|
+
}
|
|
942
|
+
export function completeSganRunV2(id) {
|
|
943
|
+
const j = _sganJsV2.get(id);
|
|
944
|
+
if (!j) throw new Error(`sgan run ${id} not found`);
|
|
945
|
+
_sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.COMPLETED);
|
|
946
|
+
const now = Date.now();
|
|
947
|
+
j.status = SGAN_RUN_LIFECYCLE_V2.COMPLETED;
|
|
948
|
+
j.updatedAt = now;
|
|
949
|
+
if (!j.settledAt) j.settledAt = now;
|
|
950
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
951
|
+
}
|
|
952
|
+
export function failSganRunV2(id, reason) {
|
|
953
|
+
const j = _sganJsV2.get(id);
|
|
954
|
+
if (!j) throw new Error(`sgan run ${id} not found`);
|
|
955
|
+
_sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.FAILED);
|
|
772
956
|
const now = Date.now();
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
export function cancelSganRunV2(id, reason) {
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
957
|
+
j.status = SGAN_RUN_LIFECYCLE_V2.FAILED;
|
|
958
|
+
j.updatedAt = now;
|
|
959
|
+
if (!j.settledAt) j.settledAt = now;
|
|
960
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
961
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
962
|
+
}
|
|
963
|
+
export function cancelSganRunV2(id, reason) {
|
|
964
|
+
const j = _sganJsV2.get(id);
|
|
965
|
+
if (!j) throw new Error(`sgan run ${id} not found`);
|
|
966
|
+
_sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.CANCELLED);
|
|
967
|
+
const now = Date.now();
|
|
968
|
+
j.status = SGAN_RUN_LIFECYCLE_V2.CANCELLED;
|
|
969
|
+
j.updatedAt = now;
|
|
970
|
+
if (!j.settledAt) j.settledAt = now;
|
|
971
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
972
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
973
|
+
}
|
|
974
|
+
export function getSganRunV2(id) {
|
|
975
|
+
const j = _sganJsV2.get(id);
|
|
976
|
+
if (!j) return null;
|
|
977
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
978
|
+
}
|
|
979
|
+
export function listSganRunsV2() {
|
|
980
|
+
return [..._sganJsV2.values()].map((j) => ({
|
|
981
|
+
...j,
|
|
982
|
+
metadata: { ...j.metadata },
|
|
983
|
+
}));
|
|
984
|
+
}
|
|
985
|
+
export function autoStaleIdleSganProfilesV2({ now } = {}) {
|
|
986
|
+
const t = now ?? Date.now();
|
|
987
|
+
const flipped = [];
|
|
988
|
+
for (const p of _sganPsV2.values())
|
|
989
|
+
if (
|
|
990
|
+
p.status === SGAN_PROFILE_MATURITY_V2.ACTIVE &&
|
|
991
|
+
t - p.lastTouchedAt >= _sganIdleMs
|
|
992
|
+
) {
|
|
993
|
+
p.status = SGAN_PROFILE_MATURITY_V2.STALE;
|
|
994
|
+
p.updatedAt = t;
|
|
995
|
+
flipped.push(p.id);
|
|
996
|
+
}
|
|
997
|
+
return { flipped, count: flipped.length };
|
|
998
|
+
}
|
|
999
|
+
export function autoFailStuckSganRunsV2({ now } = {}) {
|
|
1000
|
+
const t = now ?? Date.now();
|
|
1001
|
+
const flipped = [];
|
|
1002
|
+
for (const j of _sganJsV2.values())
|
|
1003
|
+
if (
|
|
1004
|
+
j.status === SGAN_RUN_LIFECYCLE_V2.RUNNING &&
|
|
1005
|
+
j.startedAt != null &&
|
|
1006
|
+
t - j.startedAt >= _sganStuckMs
|
|
1007
|
+
) {
|
|
1008
|
+
j.status = SGAN_RUN_LIFECYCLE_V2.FAILED;
|
|
1009
|
+
j.updatedAt = t;
|
|
1010
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1011
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1012
|
+
flipped.push(j.id);
|
|
1013
|
+
}
|
|
1014
|
+
return { flipped, count: flipped.length };
|
|
1015
|
+
}
|
|
784
1016
|
export function getSocialGraphAnalyticsGovStatsV2() {
|
|
785
|
-
const profilesByStatus = {};
|
|
786
|
-
|
|
787
|
-
|
|
1017
|
+
const profilesByStatus = {};
|
|
1018
|
+
for (const v of Object.values(SGAN_PROFILE_MATURITY_V2))
|
|
1019
|
+
profilesByStatus[v] = 0;
|
|
1020
|
+
for (const p of _sganPsV2.values()) profilesByStatus[p.status]++;
|
|
1021
|
+
const runsByStatus = {};
|
|
1022
|
+
for (const v of Object.values(SGAN_RUN_LIFECYCLE_V2)) runsByStatus[v] = 0;
|
|
1023
|
+
for (const j of _sganJsV2.values()) runsByStatus[j.status]++;
|
|
1024
|
+
return {
|
|
1025
|
+
totalSganProfilesV2: _sganPsV2.size,
|
|
1026
|
+
totalSganRunsV2: _sganJsV2.size,
|
|
1027
|
+
maxActiveSganProfilesPerOwner: _sganMaxActive,
|
|
1028
|
+
maxPendingSganRunsPerProfile: _sganMaxPending,
|
|
1029
|
+
sganProfileIdleMs: _sganIdleMs,
|
|
1030
|
+
sganRunStuckMs: _sganStuckMs,
|
|
1031
|
+
profilesByStatus,
|
|
1032
|
+
runsByStatus,
|
|
1033
|
+
};
|
|
788
1034
|
}
|