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
package/src/lib/bi-engine.js
CHANGED
|
@@ -636,25 +636,50 @@ export function _resetV2State() {
|
|
|
636
636
|
_statusHistoryV2.clear();
|
|
637
637
|
}
|
|
638
638
|
|
|
639
|
-
|
|
640
639
|
// ===== V2 Surface: BI Engine governance overlay (CLI v0.135.0) =====
|
|
641
640
|
export const BI_DATASET_MATURITY_V2 = Object.freeze({
|
|
642
|
-
PENDING: "pending",
|
|
641
|
+
PENDING: "pending",
|
|
642
|
+
ACTIVE: "active",
|
|
643
|
+
STALE: "stale",
|
|
644
|
+
ARCHIVED: "archived",
|
|
643
645
|
});
|
|
644
646
|
export const BI_QUERY_LIFECYCLE_V2 = Object.freeze({
|
|
645
|
-
QUEUED: "queued",
|
|
647
|
+
QUEUED: "queued",
|
|
648
|
+
RUNNING: "running",
|
|
649
|
+
COMPLETED: "completed",
|
|
650
|
+
FAILED: "failed",
|
|
651
|
+
CANCELLED: "cancelled",
|
|
646
652
|
});
|
|
647
653
|
|
|
648
654
|
const _biDsTrans = new Map([
|
|
649
|
-
[
|
|
650
|
-
|
|
651
|
-
|
|
655
|
+
[
|
|
656
|
+
BI_DATASET_MATURITY_V2.PENDING,
|
|
657
|
+
new Set([BI_DATASET_MATURITY_V2.ACTIVE, BI_DATASET_MATURITY_V2.ARCHIVED]),
|
|
658
|
+
],
|
|
659
|
+
[
|
|
660
|
+
BI_DATASET_MATURITY_V2.ACTIVE,
|
|
661
|
+
new Set([BI_DATASET_MATURITY_V2.STALE, BI_DATASET_MATURITY_V2.ARCHIVED]),
|
|
662
|
+
],
|
|
663
|
+
[
|
|
664
|
+
BI_DATASET_MATURITY_V2.STALE,
|
|
665
|
+
new Set([BI_DATASET_MATURITY_V2.ACTIVE, BI_DATASET_MATURITY_V2.ARCHIVED]),
|
|
666
|
+
],
|
|
652
667
|
[BI_DATASET_MATURITY_V2.ARCHIVED, new Set()],
|
|
653
668
|
]);
|
|
654
669
|
const _biDsTerminal = new Set([BI_DATASET_MATURITY_V2.ARCHIVED]);
|
|
655
670
|
const _biQTrans = new Map([
|
|
656
|
-
[
|
|
657
|
-
|
|
671
|
+
[
|
|
672
|
+
BI_QUERY_LIFECYCLE_V2.QUEUED,
|
|
673
|
+
new Set([BI_QUERY_LIFECYCLE_V2.RUNNING, BI_QUERY_LIFECYCLE_V2.CANCELLED]),
|
|
674
|
+
],
|
|
675
|
+
[
|
|
676
|
+
BI_QUERY_LIFECYCLE_V2.RUNNING,
|
|
677
|
+
new Set([
|
|
678
|
+
BI_QUERY_LIFECYCLE_V2.COMPLETED,
|
|
679
|
+
BI_QUERY_LIFECYCLE_V2.FAILED,
|
|
680
|
+
BI_QUERY_LIFECYCLE_V2.CANCELLED,
|
|
681
|
+
]),
|
|
682
|
+
],
|
|
658
683
|
[BI_QUERY_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
659
684
|
[BI_QUERY_LIFECYCLE_V2.FAILED, new Set()],
|
|
660
685
|
[BI_QUERY_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -667,76 +692,285 @@ let _biMaxPendingPerDs = 10;
|
|
|
667
692
|
let _biDsIdleMs = 7 * 24 * 60 * 60 * 1000;
|
|
668
693
|
let _biQStuckMs = 5 * 60 * 1000;
|
|
669
694
|
|
|
670
|
-
function _biPos(n, lbl) {
|
|
695
|
+
function _biPos(n, lbl) {
|
|
696
|
+
const v = Math.floor(Number(n));
|
|
697
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
698
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
699
|
+
return v;
|
|
700
|
+
}
|
|
671
701
|
|
|
672
|
-
export function setMaxActiveBiDatasetsPerOwnerV2(n) {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
export function
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
export function
|
|
679
|
-
|
|
702
|
+
export function setMaxActiveBiDatasetsPerOwnerV2(n) {
|
|
703
|
+
_biMaxActivePerOwner = _biPos(n, "maxActiveBiDatasetsPerOwner");
|
|
704
|
+
}
|
|
705
|
+
export function getMaxActiveBiDatasetsPerOwnerV2() {
|
|
706
|
+
return _biMaxActivePerOwner;
|
|
707
|
+
}
|
|
708
|
+
export function setMaxPendingBiQueriesPerDatasetV2(n) {
|
|
709
|
+
_biMaxPendingPerDs = _biPos(n, "maxPendingBiQueriesPerDataset");
|
|
710
|
+
}
|
|
711
|
+
export function getMaxPendingBiQueriesPerDatasetV2() {
|
|
712
|
+
return _biMaxPendingPerDs;
|
|
713
|
+
}
|
|
714
|
+
export function setBiDatasetIdleMsV2(n) {
|
|
715
|
+
_biDsIdleMs = _biPos(n, "biDatasetIdleMs");
|
|
716
|
+
}
|
|
717
|
+
export function getBiDatasetIdleMsV2() {
|
|
718
|
+
return _biDsIdleMs;
|
|
719
|
+
}
|
|
720
|
+
export function setBiQueryStuckMsV2(n) {
|
|
721
|
+
_biQStuckMs = _biPos(n, "biQueryStuckMs");
|
|
722
|
+
}
|
|
723
|
+
export function getBiQueryStuckMsV2() {
|
|
724
|
+
return _biQStuckMs;
|
|
725
|
+
}
|
|
680
726
|
|
|
681
727
|
export function _resetStateBiEngineV2() {
|
|
682
|
-
_biDatasets.clear();
|
|
683
|
-
|
|
684
|
-
|
|
728
|
+
_biDatasets.clear();
|
|
729
|
+
_biQueries.clear();
|
|
730
|
+
_biMaxActivePerOwner = 8;
|
|
731
|
+
_biMaxPendingPerDs = 10;
|
|
732
|
+
_biDsIdleMs = 7 * 24 * 60 * 60 * 1000;
|
|
733
|
+
_biQStuckMs = 5 * 60 * 1000;
|
|
685
734
|
}
|
|
686
735
|
|
|
687
736
|
export function registerBiDatasetV2({ id, owner, source, metadata } = {}) {
|
|
688
737
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
689
738
|
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
690
|
-
if (_biDatasets.has(id))
|
|
739
|
+
if (_biDatasets.has(id))
|
|
740
|
+
throw new Error(`bi dataset ${id} already registered`);
|
|
691
741
|
const now = Date.now();
|
|
692
|
-
const d = {
|
|
742
|
+
const d = {
|
|
743
|
+
id,
|
|
744
|
+
owner,
|
|
745
|
+
source: source || "",
|
|
746
|
+
status: BI_DATASET_MATURITY_V2.PENDING,
|
|
747
|
+
createdAt: now,
|
|
748
|
+
updatedAt: now,
|
|
749
|
+
activatedAt: null,
|
|
750
|
+
archivedAt: null,
|
|
751
|
+
lastTouchedAt: now,
|
|
752
|
+
metadata: { ...(metadata || {}) },
|
|
753
|
+
};
|
|
693
754
|
_biDatasets.set(id, d);
|
|
694
755
|
return { ...d, metadata: { ...d.metadata } };
|
|
695
756
|
}
|
|
696
|
-
function _biCheckD(from, to) {
|
|
697
|
-
|
|
757
|
+
function _biCheckD(from, to) {
|
|
758
|
+
const a = _biDsTrans.get(from);
|
|
759
|
+
if (!a || !a.has(to))
|
|
760
|
+
throw new Error(`invalid bi dataset transition ${from} → ${to}`);
|
|
761
|
+
}
|
|
762
|
+
function _biCountActive(owner) {
|
|
763
|
+
let n = 0;
|
|
764
|
+
for (const d of _biDatasets.values())
|
|
765
|
+
if (d.owner === owner && d.status === BI_DATASET_MATURITY_V2.ACTIVE) n++;
|
|
766
|
+
return n;
|
|
767
|
+
}
|
|
698
768
|
|
|
699
769
|
export function activateBiDatasetV2(id) {
|
|
700
|
-
const d = _biDatasets.get(id);
|
|
770
|
+
const d = _biDatasets.get(id);
|
|
771
|
+
if (!d) throw new Error(`bi dataset ${id} not found`);
|
|
701
772
|
_biCheckD(d.status, BI_DATASET_MATURITY_V2.ACTIVE);
|
|
702
773
|
const recovery = d.status === BI_DATASET_MATURITY_V2.STALE;
|
|
703
|
-
if (!recovery) {
|
|
704
|
-
|
|
774
|
+
if (!recovery) {
|
|
775
|
+
const a = _biCountActive(d.owner);
|
|
776
|
+
if (a >= _biMaxActivePerOwner)
|
|
777
|
+
throw new Error(
|
|
778
|
+
`max active bi datasets per owner (${_biMaxActivePerOwner}) reached for ${d.owner}`,
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
const now = Date.now();
|
|
782
|
+
d.status = BI_DATASET_MATURITY_V2.ACTIVE;
|
|
783
|
+
d.updatedAt = now;
|
|
784
|
+
d.lastTouchedAt = now;
|
|
785
|
+
if (!d.activatedAt) d.activatedAt = now;
|
|
705
786
|
return { ...d, metadata: { ...d.metadata } };
|
|
706
787
|
}
|
|
707
|
-
export function staleBiDatasetV2(id) {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
788
|
+
export function staleBiDatasetV2(id) {
|
|
789
|
+
const d = _biDatasets.get(id);
|
|
790
|
+
if (!d) throw new Error(`bi dataset ${id} not found`);
|
|
791
|
+
_biCheckD(d.status, BI_DATASET_MATURITY_V2.STALE);
|
|
792
|
+
d.status = BI_DATASET_MATURITY_V2.STALE;
|
|
793
|
+
d.updatedAt = Date.now();
|
|
794
|
+
return { ...d, metadata: { ...d.metadata } };
|
|
795
|
+
}
|
|
796
|
+
export function archiveBiDatasetV2(id) {
|
|
797
|
+
const d = _biDatasets.get(id);
|
|
798
|
+
if (!d) throw new Error(`bi dataset ${id} not found`);
|
|
799
|
+
_biCheckD(d.status, BI_DATASET_MATURITY_V2.ARCHIVED);
|
|
800
|
+
const now = Date.now();
|
|
801
|
+
d.status = BI_DATASET_MATURITY_V2.ARCHIVED;
|
|
802
|
+
d.updatedAt = now;
|
|
803
|
+
if (!d.archivedAt) d.archivedAt = now;
|
|
804
|
+
return { ...d, metadata: { ...d.metadata } };
|
|
805
|
+
}
|
|
806
|
+
export function touchBiDatasetV2(id) {
|
|
807
|
+
const d = _biDatasets.get(id);
|
|
808
|
+
if (!d) throw new Error(`bi dataset ${id} not found`);
|
|
809
|
+
if (_biDsTerminal.has(d.status))
|
|
810
|
+
throw new Error(`cannot touch terminal bi dataset ${id}`);
|
|
811
|
+
const now = Date.now();
|
|
812
|
+
d.lastTouchedAt = now;
|
|
813
|
+
d.updatedAt = now;
|
|
814
|
+
return { ...d, metadata: { ...d.metadata } };
|
|
815
|
+
}
|
|
816
|
+
export function getBiDatasetV2(id) {
|
|
817
|
+
const d = _biDatasets.get(id);
|
|
818
|
+
if (!d) return null;
|
|
819
|
+
return { ...d, metadata: { ...d.metadata } };
|
|
820
|
+
}
|
|
821
|
+
export function listBiDatasetsV2() {
|
|
822
|
+
return [..._biDatasets.values()].map((d) => ({
|
|
823
|
+
...d,
|
|
824
|
+
metadata: { ...d.metadata },
|
|
825
|
+
}));
|
|
826
|
+
}
|
|
712
827
|
|
|
713
|
-
function _biCountPending(did) {
|
|
828
|
+
function _biCountPending(did) {
|
|
829
|
+
let n = 0;
|
|
830
|
+
for (const q of _biQueries.values())
|
|
831
|
+
if (
|
|
832
|
+
q.datasetId === did &&
|
|
833
|
+
(q.status === BI_QUERY_LIFECYCLE_V2.QUEUED ||
|
|
834
|
+
q.status === BI_QUERY_LIFECYCLE_V2.RUNNING)
|
|
835
|
+
)
|
|
836
|
+
n++;
|
|
837
|
+
return n;
|
|
838
|
+
}
|
|
714
839
|
|
|
715
840
|
export function createBiQueryV2({ id, datasetId, sql, metadata } = {}) {
|
|
716
841
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
717
|
-
if (!datasetId || typeof datasetId !== "string")
|
|
842
|
+
if (!datasetId || typeof datasetId !== "string")
|
|
843
|
+
throw new Error("datasetId is required");
|
|
718
844
|
if (_biQueries.has(id)) throw new Error(`bi query ${id} already exists`);
|
|
719
|
-
if (!_biDatasets.has(datasetId))
|
|
845
|
+
if (!_biDatasets.has(datasetId))
|
|
846
|
+
throw new Error(`bi dataset ${datasetId} not found`);
|
|
720
847
|
const pending = _biCountPending(datasetId);
|
|
721
|
-
if (pending >= _biMaxPendingPerDs)
|
|
848
|
+
if (pending >= _biMaxPendingPerDs)
|
|
849
|
+
throw new Error(
|
|
850
|
+
`max pending bi queries per dataset (${_biMaxPendingPerDs}) reached for ${datasetId}`,
|
|
851
|
+
);
|
|
722
852
|
const now = Date.now();
|
|
723
|
-
const q = {
|
|
853
|
+
const q = {
|
|
854
|
+
id,
|
|
855
|
+
datasetId,
|
|
856
|
+
sql: sql || "",
|
|
857
|
+
status: BI_QUERY_LIFECYCLE_V2.QUEUED,
|
|
858
|
+
createdAt: now,
|
|
859
|
+
updatedAt: now,
|
|
860
|
+
startedAt: null,
|
|
861
|
+
settledAt: null,
|
|
862
|
+
metadata: { ...(metadata || {}) },
|
|
863
|
+
};
|
|
724
864
|
_biQueries.set(id, q);
|
|
725
865
|
return { ...q, metadata: { ...q.metadata } };
|
|
726
866
|
}
|
|
727
|
-
function _biCheckQ(from, to) {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
export function
|
|
733
|
-
|
|
867
|
+
function _biCheckQ(from, to) {
|
|
868
|
+
const a = _biQTrans.get(from);
|
|
869
|
+
if (!a || !a.has(to))
|
|
870
|
+
throw new Error(`invalid bi query transition ${from} → ${to}`);
|
|
871
|
+
}
|
|
872
|
+
export function startBiQueryV2(id) {
|
|
873
|
+
const q = _biQueries.get(id);
|
|
874
|
+
if (!q) throw new Error(`bi query ${id} not found`);
|
|
875
|
+
_biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.RUNNING);
|
|
876
|
+
const now = Date.now();
|
|
877
|
+
q.status = BI_QUERY_LIFECYCLE_V2.RUNNING;
|
|
878
|
+
q.updatedAt = now;
|
|
879
|
+
if (!q.startedAt) q.startedAt = now;
|
|
880
|
+
return { ...q, metadata: { ...q.metadata } };
|
|
881
|
+
}
|
|
882
|
+
export function completeBiQueryV2(id) {
|
|
883
|
+
const q = _biQueries.get(id);
|
|
884
|
+
if (!q) throw new Error(`bi query ${id} not found`);
|
|
885
|
+
_biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.COMPLETED);
|
|
886
|
+
const now = Date.now();
|
|
887
|
+
q.status = BI_QUERY_LIFECYCLE_V2.COMPLETED;
|
|
888
|
+
q.updatedAt = now;
|
|
889
|
+
if (!q.settledAt) q.settledAt = now;
|
|
890
|
+
return { ...q, metadata: { ...q.metadata } };
|
|
891
|
+
}
|
|
892
|
+
export function failBiQueryV2(id, reason) {
|
|
893
|
+
const q = _biQueries.get(id);
|
|
894
|
+
if (!q) throw new Error(`bi query ${id} not found`);
|
|
895
|
+
_biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.FAILED);
|
|
896
|
+
const now = Date.now();
|
|
897
|
+
q.status = BI_QUERY_LIFECYCLE_V2.FAILED;
|
|
898
|
+
q.updatedAt = now;
|
|
899
|
+
if (!q.settledAt) q.settledAt = now;
|
|
900
|
+
if (reason) q.metadata.failReason = String(reason);
|
|
901
|
+
return { ...q, metadata: { ...q.metadata } };
|
|
902
|
+
}
|
|
903
|
+
export function cancelBiQueryV2(id, reason) {
|
|
904
|
+
const q = _biQueries.get(id);
|
|
905
|
+
if (!q) throw new Error(`bi query ${id} not found`);
|
|
906
|
+
_biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.CANCELLED);
|
|
907
|
+
const now = Date.now();
|
|
908
|
+
q.status = BI_QUERY_LIFECYCLE_V2.CANCELLED;
|
|
909
|
+
q.updatedAt = now;
|
|
910
|
+
if (!q.settledAt) q.settledAt = now;
|
|
911
|
+
if (reason) q.metadata.cancelReason = String(reason);
|
|
912
|
+
return { ...q, metadata: { ...q.metadata } };
|
|
913
|
+
}
|
|
914
|
+
export function getBiQueryV2(id) {
|
|
915
|
+
const q = _biQueries.get(id);
|
|
916
|
+
if (!q) return null;
|
|
917
|
+
return { ...q, metadata: { ...q.metadata } };
|
|
918
|
+
}
|
|
919
|
+
export function listBiQueriesV2() {
|
|
920
|
+
return [..._biQueries.values()].map((q) => ({
|
|
921
|
+
...q,
|
|
922
|
+
metadata: { ...q.metadata },
|
|
923
|
+
}));
|
|
924
|
+
}
|
|
734
925
|
|
|
735
|
-
export function autoStaleIdleBiDatasetsV2({ now } = {}) {
|
|
736
|
-
|
|
926
|
+
export function autoStaleIdleBiDatasetsV2({ now } = {}) {
|
|
927
|
+
const t = now ?? Date.now();
|
|
928
|
+
const flipped = [];
|
|
929
|
+
for (const d of _biDatasets.values())
|
|
930
|
+
if (
|
|
931
|
+
d.status === BI_DATASET_MATURITY_V2.ACTIVE &&
|
|
932
|
+
t - d.lastTouchedAt >= _biDsIdleMs
|
|
933
|
+
) {
|
|
934
|
+
d.status = BI_DATASET_MATURITY_V2.STALE;
|
|
935
|
+
d.updatedAt = t;
|
|
936
|
+
flipped.push(d.id);
|
|
937
|
+
}
|
|
938
|
+
return { flipped, count: flipped.length };
|
|
939
|
+
}
|
|
940
|
+
export function autoFailStuckBiQueriesV2({ now } = {}) {
|
|
941
|
+
const t = now ?? Date.now();
|
|
942
|
+
const flipped = [];
|
|
943
|
+
for (const q of _biQueries.values())
|
|
944
|
+
if (
|
|
945
|
+
q.status === BI_QUERY_LIFECYCLE_V2.RUNNING &&
|
|
946
|
+
q.startedAt != null &&
|
|
947
|
+
t - q.startedAt >= _biQStuckMs
|
|
948
|
+
) {
|
|
949
|
+
q.status = BI_QUERY_LIFECYCLE_V2.FAILED;
|
|
950
|
+
q.updatedAt = t;
|
|
951
|
+
if (!q.settledAt) q.settledAt = t;
|
|
952
|
+
q.metadata.failReason = "auto-fail-stuck";
|
|
953
|
+
flipped.push(q.id);
|
|
954
|
+
}
|
|
955
|
+
return { flipped, count: flipped.length };
|
|
956
|
+
}
|
|
737
957
|
|
|
738
958
|
export function getBiEngineStatsV2() {
|
|
739
|
-
const datasetsByStatus = {};
|
|
740
|
-
|
|
741
|
-
|
|
959
|
+
const datasetsByStatus = {};
|
|
960
|
+
for (const s of Object.values(BI_DATASET_MATURITY_V2))
|
|
961
|
+
datasetsByStatus[s] = 0;
|
|
962
|
+
for (const d of _biDatasets.values()) datasetsByStatus[d.status]++;
|
|
963
|
+
const queriesByStatus = {};
|
|
964
|
+
for (const s of Object.values(BI_QUERY_LIFECYCLE_V2)) queriesByStatus[s] = 0;
|
|
965
|
+
for (const q of _biQueries.values()) queriesByStatus[q.status]++;
|
|
966
|
+
return {
|
|
967
|
+
totalDatasetsV2: _biDatasets.size,
|
|
968
|
+
totalQueriesV2: _biQueries.size,
|
|
969
|
+
maxActiveBiDatasetsPerOwner: _biMaxActivePerOwner,
|
|
970
|
+
maxPendingBiQueriesPerDataset: _biMaxPendingPerDs,
|
|
971
|
+
biDatasetIdleMs: _biDsIdleMs,
|
|
972
|
+
biQueryStuckMs: _biQStuckMs,
|
|
973
|
+
datasetsByStatus,
|
|
974
|
+
queriesByStatus,
|
|
975
|
+
};
|
|
742
976
|
}
|