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
|
@@ -736,25 +736,62 @@ export function getInferenceStatsV2() {
|
|
|
736
736
|
};
|
|
737
737
|
}
|
|
738
738
|
|
|
739
|
-
|
|
740
739
|
// ===== V2 Surface: Inference Network governance overlay (CLI v0.139.0) =====
|
|
741
740
|
export const INFERENCE_NODE_MATURITY_V2 = Object.freeze({
|
|
742
|
-
PENDING: "pending",
|
|
741
|
+
PENDING: "pending",
|
|
742
|
+
ACTIVE: "active",
|
|
743
|
+
DEGRADED: "degraded",
|
|
744
|
+
DECOMMISSIONED: "decommissioned",
|
|
743
745
|
});
|
|
744
746
|
export const INFERENCE_JOB_LIFECYCLE_V2 = Object.freeze({
|
|
745
|
-
QUEUED: "queued",
|
|
747
|
+
QUEUED: "queued",
|
|
748
|
+
RUNNING: "running",
|
|
749
|
+
COMPLETED: "completed",
|
|
750
|
+
FAILED: "failed",
|
|
751
|
+
CANCELLED: "cancelled",
|
|
746
752
|
});
|
|
747
753
|
|
|
748
754
|
const _inTrans = new Map([
|
|
749
|
-
[
|
|
750
|
-
|
|
751
|
-
|
|
755
|
+
[
|
|
756
|
+
INFERENCE_NODE_MATURITY_V2.PENDING,
|
|
757
|
+
new Set([
|
|
758
|
+
INFERENCE_NODE_MATURITY_V2.ACTIVE,
|
|
759
|
+
INFERENCE_NODE_MATURITY_V2.DECOMMISSIONED,
|
|
760
|
+
]),
|
|
761
|
+
],
|
|
762
|
+
[
|
|
763
|
+
INFERENCE_NODE_MATURITY_V2.ACTIVE,
|
|
764
|
+
new Set([
|
|
765
|
+
INFERENCE_NODE_MATURITY_V2.DEGRADED,
|
|
766
|
+
INFERENCE_NODE_MATURITY_V2.DECOMMISSIONED,
|
|
767
|
+
]),
|
|
768
|
+
],
|
|
769
|
+
[
|
|
770
|
+
INFERENCE_NODE_MATURITY_V2.DEGRADED,
|
|
771
|
+
new Set([
|
|
772
|
+
INFERENCE_NODE_MATURITY_V2.ACTIVE,
|
|
773
|
+
INFERENCE_NODE_MATURITY_V2.DECOMMISSIONED,
|
|
774
|
+
]),
|
|
775
|
+
],
|
|
752
776
|
[INFERENCE_NODE_MATURITY_V2.DECOMMISSIONED, new Set()],
|
|
753
777
|
]);
|
|
754
778
|
const _inTerminal = new Set([INFERENCE_NODE_MATURITY_V2.DECOMMISSIONED]);
|
|
755
779
|
const _ijTrans = new Map([
|
|
756
|
-
[
|
|
757
|
-
|
|
780
|
+
[
|
|
781
|
+
INFERENCE_JOB_LIFECYCLE_V2.QUEUED,
|
|
782
|
+
new Set([
|
|
783
|
+
INFERENCE_JOB_LIFECYCLE_V2.RUNNING,
|
|
784
|
+
INFERENCE_JOB_LIFECYCLE_V2.CANCELLED,
|
|
785
|
+
]),
|
|
786
|
+
],
|
|
787
|
+
[
|
|
788
|
+
INFERENCE_JOB_LIFECYCLE_V2.RUNNING,
|
|
789
|
+
new Set([
|
|
790
|
+
INFERENCE_JOB_LIFECYCLE_V2.COMPLETED,
|
|
791
|
+
INFERENCE_JOB_LIFECYCLE_V2.FAILED,
|
|
792
|
+
INFERENCE_JOB_LIFECYCLE_V2.CANCELLED,
|
|
793
|
+
]),
|
|
794
|
+
],
|
|
758
795
|
[INFERENCE_JOB_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
759
796
|
[INFERENCE_JOB_LIFECYCLE_V2.FAILED, new Set()],
|
|
760
797
|
[INFERENCE_JOB_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -767,76 +804,296 @@ let _inMaxPendingJobsPerNode = 25;
|
|
|
767
804
|
let _inIdleMs = 24 * 60 * 60 * 1000;
|
|
768
805
|
let _ijStuckMs = 10 * 60 * 1000;
|
|
769
806
|
|
|
770
|
-
function _inPos(n, lbl) {
|
|
807
|
+
function _inPos(n, lbl) {
|
|
808
|
+
const v = Math.floor(Number(n));
|
|
809
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
810
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
811
|
+
return v;
|
|
812
|
+
}
|
|
771
813
|
|
|
772
|
-
export function setMaxActiveInferenceNodesPerOperatorV2(n) {
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
export function
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
export function
|
|
779
|
-
|
|
814
|
+
export function setMaxActiveInferenceNodesPerOperatorV2(n) {
|
|
815
|
+
_inMaxActivePerOperator = _inPos(n, "maxActiveInferenceNodesPerOperator");
|
|
816
|
+
}
|
|
817
|
+
export function getMaxActiveInferenceNodesPerOperatorV2() {
|
|
818
|
+
return _inMaxActivePerOperator;
|
|
819
|
+
}
|
|
820
|
+
export function setMaxPendingInferenceJobsPerNodeV2(n) {
|
|
821
|
+
_inMaxPendingJobsPerNode = _inPos(n, "maxPendingInferenceJobsPerNode");
|
|
822
|
+
}
|
|
823
|
+
export function getMaxPendingInferenceJobsPerNodeV2() {
|
|
824
|
+
return _inMaxPendingJobsPerNode;
|
|
825
|
+
}
|
|
826
|
+
export function setInferenceNodeIdleMsV2(n) {
|
|
827
|
+
_inIdleMs = _inPos(n, "inferenceNodeIdleMs");
|
|
828
|
+
}
|
|
829
|
+
export function getInferenceNodeIdleMsV2() {
|
|
830
|
+
return _inIdleMs;
|
|
831
|
+
}
|
|
832
|
+
export function setInferenceJobStuckMsV2(n) {
|
|
833
|
+
_ijStuckMs = _inPos(n, "inferenceJobStuckMs");
|
|
834
|
+
}
|
|
835
|
+
export function getInferenceJobStuckMsV2() {
|
|
836
|
+
return _ijStuckMs;
|
|
837
|
+
}
|
|
780
838
|
|
|
781
839
|
export function _resetStateInferenceNetworkV2() {
|
|
782
|
-
_innV2.clear();
|
|
783
|
-
|
|
784
|
-
|
|
840
|
+
_innV2.clear();
|
|
841
|
+
_ijsV2.clear();
|
|
842
|
+
_inMaxActivePerOperator = 12;
|
|
843
|
+
_inMaxPendingJobsPerNode = 25;
|
|
844
|
+
_inIdleMs = 24 * 60 * 60 * 1000;
|
|
845
|
+
_ijStuckMs = 10 * 60 * 1000;
|
|
785
846
|
}
|
|
786
847
|
|
|
787
|
-
export function registerInferenceNodeV2({
|
|
848
|
+
export function registerInferenceNodeV2({
|
|
849
|
+
id,
|
|
850
|
+
operator,
|
|
851
|
+
model,
|
|
852
|
+
metadata,
|
|
853
|
+
} = {}) {
|
|
788
854
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
789
|
-
if (!operator || typeof operator !== "string")
|
|
790
|
-
|
|
855
|
+
if (!operator || typeof operator !== "string")
|
|
856
|
+
throw new Error("operator is required");
|
|
857
|
+
if (_innV2.has(id))
|
|
858
|
+
throw new Error(`inference node ${id} already registered`);
|
|
791
859
|
const now = Date.now();
|
|
792
|
-
const n = {
|
|
860
|
+
const n = {
|
|
861
|
+
id,
|
|
862
|
+
operator,
|
|
863
|
+
model: model || "default",
|
|
864
|
+
status: INFERENCE_NODE_MATURITY_V2.PENDING,
|
|
865
|
+
createdAt: now,
|
|
866
|
+
updatedAt: now,
|
|
867
|
+
activatedAt: null,
|
|
868
|
+
decommissionedAt: null,
|
|
869
|
+
lastTouchedAt: now,
|
|
870
|
+
metadata: { ...(metadata || {}) },
|
|
871
|
+
};
|
|
793
872
|
_innV2.set(id, n);
|
|
794
873
|
return { ...n, metadata: { ...n.metadata } };
|
|
795
874
|
}
|
|
796
|
-
function _inCheckN(from, to) {
|
|
797
|
-
|
|
875
|
+
function _inCheckN(from, to) {
|
|
876
|
+
const a = _inTrans.get(from);
|
|
877
|
+
if (!a || !a.has(to))
|
|
878
|
+
throw new Error(`invalid inference node transition ${from} → ${to}`);
|
|
879
|
+
}
|
|
880
|
+
function _inCountActive(operator) {
|
|
881
|
+
let n = 0;
|
|
882
|
+
for (const x of _innV2.values())
|
|
883
|
+
if (
|
|
884
|
+
x.operator === operator &&
|
|
885
|
+
x.status === INFERENCE_NODE_MATURITY_V2.ACTIVE
|
|
886
|
+
)
|
|
887
|
+
n++;
|
|
888
|
+
return n;
|
|
889
|
+
}
|
|
798
890
|
|
|
799
891
|
export function activateInferenceNodeV2(id) {
|
|
800
|
-
const n = _innV2.get(id);
|
|
892
|
+
const n = _innV2.get(id);
|
|
893
|
+
if (!n) throw new Error(`inference node ${id} not found`);
|
|
801
894
|
_inCheckN(n.status, INFERENCE_NODE_MATURITY_V2.ACTIVE);
|
|
802
895
|
const recovery = n.status === INFERENCE_NODE_MATURITY_V2.DEGRADED;
|
|
803
|
-
if (!recovery) {
|
|
804
|
-
|
|
896
|
+
if (!recovery) {
|
|
897
|
+
const c = _inCountActive(n.operator);
|
|
898
|
+
if (c >= _inMaxActivePerOperator)
|
|
899
|
+
throw new Error(
|
|
900
|
+
`max active inference nodes per operator (${_inMaxActivePerOperator}) reached for ${n.operator}`,
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
const now = Date.now();
|
|
904
|
+
n.status = INFERENCE_NODE_MATURITY_V2.ACTIVE;
|
|
905
|
+
n.updatedAt = now;
|
|
906
|
+
n.lastTouchedAt = now;
|
|
907
|
+
if (!n.activatedAt) n.activatedAt = now;
|
|
805
908
|
return { ...n, metadata: { ...n.metadata } };
|
|
806
909
|
}
|
|
807
|
-
export function degradeInferenceNodeV2(id) {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
910
|
+
export function degradeInferenceNodeV2(id) {
|
|
911
|
+
const n = _innV2.get(id);
|
|
912
|
+
if (!n) throw new Error(`inference node ${id} not found`);
|
|
913
|
+
_inCheckN(n.status, INFERENCE_NODE_MATURITY_V2.DEGRADED);
|
|
914
|
+
n.status = INFERENCE_NODE_MATURITY_V2.DEGRADED;
|
|
915
|
+
n.updatedAt = Date.now();
|
|
916
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
917
|
+
}
|
|
918
|
+
export function decommissionInferenceNodeV2(id) {
|
|
919
|
+
const n = _innV2.get(id);
|
|
920
|
+
if (!n) throw new Error(`inference node ${id} not found`);
|
|
921
|
+
_inCheckN(n.status, INFERENCE_NODE_MATURITY_V2.DECOMMISSIONED);
|
|
922
|
+
const now = Date.now();
|
|
923
|
+
n.status = INFERENCE_NODE_MATURITY_V2.DECOMMISSIONED;
|
|
924
|
+
n.updatedAt = now;
|
|
925
|
+
if (!n.decommissionedAt) n.decommissionedAt = now;
|
|
926
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
927
|
+
}
|
|
928
|
+
export function touchInferenceNodeV2(id) {
|
|
929
|
+
const n = _innV2.get(id);
|
|
930
|
+
if (!n) throw new Error(`inference node ${id} not found`);
|
|
931
|
+
if (_inTerminal.has(n.status))
|
|
932
|
+
throw new Error(`cannot touch terminal inference node ${id}`);
|
|
933
|
+
const now = Date.now();
|
|
934
|
+
n.lastTouchedAt = now;
|
|
935
|
+
n.updatedAt = now;
|
|
936
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
937
|
+
}
|
|
938
|
+
export function getInferenceNodeV2(id) {
|
|
939
|
+
const n = _innV2.get(id);
|
|
940
|
+
if (!n) return null;
|
|
941
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
942
|
+
}
|
|
943
|
+
export function listInferenceNodesV2() {
|
|
944
|
+
return [..._innV2.values()].map((n) => ({
|
|
945
|
+
...n,
|
|
946
|
+
metadata: { ...n.metadata },
|
|
947
|
+
}));
|
|
948
|
+
}
|
|
812
949
|
|
|
813
|
-
function _ijCountPending(nodeId) {
|
|
950
|
+
function _ijCountPending(nodeId) {
|
|
951
|
+
let n = 0;
|
|
952
|
+
for (const j of _ijsV2.values())
|
|
953
|
+
if (
|
|
954
|
+
j.nodeId === nodeId &&
|
|
955
|
+
(j.status === INFERENCE_JOB_LIFECYCLE_V2.QUEUED ||
|
|
956
|
+
j.status === INFERENCE_JOB_LIFECYCLE_V2.RUNNING)
|
|
957
|
+
)
|
|
958
|
+
n++;
|
|
959
|
+
return n;
|
|
960
|
+
}
|
|
814
961
|
|
|
815
962
|
export function createInferenceJobV2({ id, nodeId, prompt, metadata } = {}) {
|
|
816
963
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
817
|
-
if (!nodeId || typeof nodeId !== "string")
|
|
964
|
+
if (!nodeId || typeof nodeId !== "string")
|
|
965
|
+
throw new Error("nodeId is required");
|
|
818
966
|
if (_ijsV2.has(id)) throw new Error(`inference job ${id} already exists`);
|
|
819
|
-
if (!_innV2.has(nodeId))
|
|
967
|
+
if (!_innV2.has(nodeId))
|
|
968
|
+
throw new Error(`inference node ${nodeId} not found`);
|
|
820
969
|
const pending = _ijCountPending(nodeId);
|
|
821
|
-
if (pending >= _inMaxPendingJobsPerNode)
|
|
970
|
+
if (pending >= _inMaxPendingJobsPerNode)
|
|
971
|
+
throw new Error(
|
|
972
|
+
`max pending inference jobs per node (${_inMaxPendingJobsPerNode}) reached for ${nodeId}`,
|
|
973
|
+
);
|
|
822
974
|
const now = Date.now();
|
|
823
|
-
const j = {
|
|
975
|
+
const j = {
|
|
976
|
+
id,
|
|
977
|
+
nodeId,
|
|
978
|
+
prompt: prompt || "",
|
|
979
|
+
status: INFERENCE_JOB_LIFECYCLE_V2.QUEUED,
|
|
980
|
+
createdAt: now,
|
|
981
|
+
updatedAt: now,
|
|
982
|
+
startedAt: null,
|
|
983
|
+
settledAt: null,
|
|
984
|
+
metadata: { ...(metadata || {}) },
|
|
985
|
+
};
|
|
824
986
|
_ijsV2.set(id, j);
|
|
825
987
|
return { ...j, metadata: { ...j.metadata } };
|
|
826
988
|
}
|
|
827
|
-
function _ijCheckJ(from, to) {
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
export function
|
|
833
|
-
|
|
989
|
+
function _ijCheckJ(from, to) {
|
|
990
|
+
const a = _ijTrans.get(from);
|
|
991
|
+
if (!a || !a.has(to))
|
|
992
|
+
throw new Error(`invalid inference job transition ${from} → ${to}`);
|
|
993
|
+
}
|
|
994
|
+
export function startInferenceJobV2(id) {
|
|
995
|
+
const j = _ijsV2.get(id);
|
|
996
|
+
if (!j) throw new Error(`inference job ${id} not found`);
|
|
997
|
+
_ijCheckJ(j.status, INFERENCE_JOB_LIFECYCLE_V2.RUNNING);
|
|
998
|
+
const now = Date.now();
|
|
999
|
+
j.status = INFERENCE_JOB_LIFECYCLE_V2.RUNNING;
|
|
1000
|
+
j.updatedAt = now;
|
|
1001
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1002
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1003
|
+
}
|
|
1004
|
+
export function completeInferenceJobV2(id) {
|
|
1005
|
+
const j = _ijsV2.get(id);
|
|
1006
|
+
if (!j) throw new Error(`inference job ${id} not found`);
|
|
1007
|
+
_ijCheckJ(j.status, INFERENCE_JOB_LIFECYCLE_V2.COMPLETED);
|
|
1008
|
+
const now = Date.now();
|
|
1009
|
+
j.status = INFERENCE_JOB_LIFECYCLE_V2.COMPLETED;
|
|
1010
|
+
j.updatedAt = now;
|
|
1011
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1012
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1013
|
+
}
|
|
1014
|
+
export function failInferenceJobV2(id, reason) {
|
|
1015
|
+
const j = _ijsV2.get(id);
|
|
1016
|
+
if (!j) throw new Error(`inference job ${id} not found`);
|
|
1017
|
+
_ijCheckJ(j.status, INFERENCE_JOB_LIFECYCLE_V2.FAILED);
|
|
1018
|
+
const now = Date.now();
|
|
1019
|
+
j.status = INFERENCE_JOB_LIFECYCLE_V2.FAILED;
|
|
1020
|
+
j.updatedAt = now;
|
|
1021
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1022
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1023
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1024
|
+
}
|
|
1025
|
+
export function cancelInferenceJobV2(id, reason) {
|
|
1026
|
+
const j = _ijsV2.get(id);
|
|
1027
|
+
if (!j) throw new Error(`inference job ${id} not found`);
|
|
1028
|
+
_ijCheckJ(j.status, INFERENCE_JOB_LIFECYCLE_V2.CANCELLED);
|
|
1029
|
+
const now = Date.now();
|
|
1030
|
+
j.status = INFERENCE_JOB_LIFECYCLE_V2.CANCELLED;
|
|
1031
|
+
j.updatedAt = now;
|
|
1032
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1033
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1034
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1035
|
+
}
|
|
1036
|
+
export function getInferenceJobV2(id) {
|
|
1037
|
+
const j = _ijsV2.get(id);
|
|
1038
|
+
if (!j) return null;
|
|
1039
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1040
|
+
}
|
|
1041
|
+
export function listInferenceJobsV2() {
|
|
1042
|
+
return [..._ijsV2.values()].map((j) => ({
|
|
1043
|
+
...j,
|
|
1044
|
+
metadata: { ...j.metadata },
|
|
1045
|
+
}));
|
|
1046
|
+
}
|
|
834
1047
|
|
|
835
|
-
export function autoDegradeIdleInferenceNodesV2({ now } = {}) {
|
|
836
|
-
|
|
1048
|
+
export function autoDegradeIdleInferenceNodesV2({ now } = {}) {
|
|
1049
|
+
const t = now ?? Date.now();
|
|
1050
|
+
const flipped = [];
|
|
1051
|
+
for (const n of _innV2.values())
|
|
1052
|
+
if (
|
|
1053
|
+
n.status === INFERENCE_NODE_MATURITY_V2.ACTIVE &&
|
|
1054
|
+
t - n.lastTouchedAt >= _inIdleMs
|
|
1055
|
+
) {
|
|
1056
|
+
n.status = INFERENCE_NODE_MATURITY_V2.DEGRADED;
|
|
1057
|
+
n.updatedAt = t;
|
|
1058
|
+
flipped.push(n.id);
|
|
1059
|
+
}
|
|
1060
|
+
return { flipped, count: flipped.length };
|
|
1061
|
+
}
|
|
1062
|
+
export function autoFailStuckInferenceJobsV2({ now } = {}) {
|
|
1063
|
+
const t = now ?? Date.now();
|
|
1064
|
+
const flipped = [];
|
|
1065
|
+
for (const j of _ijsV2.values())
|
|
1066
|
+
if (
|
|
1067
|
+
j.status === INFERENCE_JOB_LIFECYCLE_V2.RUNNING &&
|
|
1068
|
+
j.startedAt != null &&
|
|
1069
|
+
t - j.startedAt >= _ijStuckMs
|
|
1070
|
+
) {
|
|
1071
|
+
j.status = INFERENCE_JOB_LIFECYCLE_V2.FAILED;
|
|
1072
|
+
j.updatedAt = t;
|
|
1073
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1074
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1075
|
+
flipped.push(j.id);
|
|
1076
|
+
}
|
|
1077
|
+
return { flipped, count: flipped.length };
|
|
1078
|
+
}
|
|
837
1079
|
|
|
838
1080
|
export function getInferenceNetworkGovStatsV2() {
|
|
839
|
-
const nodesByStatus = {};
|
|
840
|
-
|
|
841
|
-
|
|
1081
|
+
const nodesByStatus = {};
|
|
1082
|
+
for (const s of Object.values(INFERENCE_NODE_MATURITY_V2))
|
|
1083
|
+
nodesByStatus[s] = 0;
|
|
1084
|
+
for (const n of _innV2.values()) nodesByStatus[n.status]++;
|
|
1085
|
+
const jobsByStatus = {};
|
|
1086
|
+
for (const s of Object.values(INFERENCE_JOB_LIFECYCLE_V2))
|
|
1087
|
+
jobsByStatus[s] = 0;
|
|
1088
|
+
for (const j of _ijsV2.values()) jobsByStatus[j.status]++;
|
|
1089
|
+
return {
|
|
1090
|
+
totalInferenceNodesV2: _innV2.size,
|
|
1091
|
+
totalInferenceJobsV2: _ijsV2.size,
|
|
1092
|
+
maxActiveInferenceNodesPerOperator: _inMaxActivePerOperator,
|
|
1093
|
+
maxPendingInferenceJobsPerNode: _inMaxPendingJobsPerNode,
|
|
1094
|
+
inferenceNodeIdleMs: _inIdleMs,
|
|
1095
|
+
inferenceJobStuckMs: _ijStuckMs,
|
|
1096
|
+
nodesByStatus,
|
|
1097
|
+
jobsByStatus,
|
|
1098
|
+
};
|
|
842
1099
|
}
|