chainlesschain 0.132.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 +230 -0
- package/src/commands/activitypub.js +191 -0
- package/src/commands/agent.js +601 -0
- package/src/commands/audit.js +206 -0
- package/src/commands/bi.js +186 -0
- package/src/commands/bm25.js +162 -0
- package/src/commands/browse.js +225 -0
- package/src/commands/ccron.js +178 -0
- package/src/commands/chat.js +207 -0
- package/src/commands/compliance.js +420 -0
- package/src/commands/compt.js +176 -0
- package/src/commands/consol.js +237 -0
- package/src/commands/cowork.js +588 -0
- package/src/commands/crosschain.js +216 -0
- package/src/commands/dao.js +216 -0
- package/src/commands/dlp.js +206 -0
- package/src/commands/economy.js +211 -0
- package/src/commands/evolution.js +209 -0
- package/src/commands/evomap.js +216 -0
- package/src/commands/fflag.js +230 -0
- package/src/commands/git.js +185 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +210 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +178 -0
- package/src/commands/itbudget.js +161 -0
- package/src/commands/kg.js +206 -0
- package/src/commands/lowcode.js +201 -0
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +214 -0
- package/src/commands/mcpscaf.js +153 -0
- package/src/commands/meminj.js +153 -0
- package/src/commands/nostr.js +213 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +156 -0
- package/src/commands/pdfp.js +160 -0
- package/src/commands/perf.js +176 -0
- package/src/commands/perm.js +156 -0
- package/src/commands/pipeline.js +211 -0
- package/src/commands/planmode.js +154 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +166 -0
- package/src/commands/recommend.js +185 -0
- package/src/commands/reputation.js +208 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/seshhook.js +153 -0
- package/src/commands/seshsearch.js +149 -0
- package/src/commands/seshtail.js +152 -0
- package/src/commands/seshu.js +160 -0
- package/src/commands/sganal.js +172 -0
- package/src/commands/siem.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +154 -0
- package/src/commands/social.js +159 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +157 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +183 -0
- package/src/commands/topiccls.js +158 -0
- package/src/commands/uprof.js +154 -0
- package/src/commands/vcheck.js +172 -0
- package/src/commands/webfetch.js +150 -0
- package/src/commands/zkp.js +218 -0
- package/src/harness/prompt-compressor.js +331 -0
- package/src/index.js +101 -1
- package/src/lib/a2a-protocol.js +373 -0
- package/src/lib/activitypub-bridge.js +343 -0
- package/src/lib/agent-economy.js +358 -0
- package/src/lib/app-builder.js +338 -0
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/autonomous-agent.js +341 -0
- package/src/lib/bi-engine.js +339 -0
- package/src/lib/bm25-search.js +333 -0
- package/src/lib/browser-automation.js +352 -0
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/compliance-framework-reporter.js +359 -0
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +333 -0
- package/src/lib/content-recommender.js +370 -0
- package/src/lib/cowork-cron.js +330 -0
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-task-runner.js +362 -0
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +365 -0
- package/src/lib/dao-governance.js +339 -0
- package/src/lib/dlp-engine.js +343 -0
- package/src/lib/evolution-system.js +336 -0
- package/src/lib/evomap-manager.js +339 -0
- package/src/lib/execution-backend.js +351 -0
- package/src/lib/feature-flags.js +330 -0
- package/src/lib/git-integration.js +343 -0
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +341 -0
- package/src/lib/inference-network.js +362 -0
- package/src/lib/iteration-budget.js +357 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-scaffold.js +345 -0
- package/src/lib/memory-injection.js +320 -0
- package/src/lib/nostr-bridge.js +342 -0
- package/src/lib/orchestrator.js +350 -0
- package/src/lib/pdf-parser.js +330 -0
- package/src/lib/perf-tuning.js +364 -0
- package/src/lib/permission-engine.js +319 -0
- package/src/lib/pipeline-orchestrator.js +345 -0
- package/src/lib/plan-mode.js +328 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/prompt-compressor.js +1 -10
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/service-container.js +342 -0
- package/src/lib/session-consolidator.js +352 -0
- package/src/lib/session-hooks.js +340 -0
- package/src/lib/session-search.js +334 -0
- package/src/lib/session-tail.js +320 -0
- package/src/lib/session-usage.js +329 -0
- package/src/lib/siem-exporter.js +352 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +333 -0
- package/src/lib/social-graph-analytics.js +327 -0
- package/src/lib/social-graph.js +304 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +359 -0
- package/src/lib/task-model-selector.js +333 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/todo-manager.js +339 -0
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/topic-classifier.js +353 -0
- package/src/lib/user-profile.js +325 -0
- package/src/lib/version-checker.js +335 -0
- package/src/lib/web-fetch.js +322 -0
- package/src/lib/zkp-engine.js +342 -0
|
@@ -804,3 +804,344 @@ export function _resetStateV2() {
|
|
|
804
804
|
_claimExpiryMs = TOKEN_DEFAULT_CLAIM_EXPIRY_MS;
|
|
805
805
|
_maxClaimAmount = TOKEN_DEFAULT_MAX_CLAIM_AMOUNT;
|
|
806
806
|
}
|
|
807
|
+
|
|
808
|
+
// =====================================================================
|
|
809
|
+
// token-incentive V2 governance overlay (iter17)
|
|
810
|
+
// =====================================================================
|
|
811
|
+
export const INCGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
812
|
+
PENDING: "pending",
|
|
813
|
+
ACTIVE: "active",
|
|
814
|
+
PAUSED: "paused",
|
|
815
|
+
ARCHIVED: "archived",
|
|
816
|
+
});
|
|
817
|
+
export const INCGOV_PAYOUT_LIFECYCLE_V2 = Object.freeze({
|
|
818
|
+
QUEUED: "queued",
|
|
819
|
+
PROCESSING: "processing",
|
|
820
|
+
PAID: "paid",
|
|
821
|
+
FAILED: "failed",
|
|
822
|
+
CANCELLED: "cancelled",
|
|
823
|
+
});
|
|
824
|
+
const _incgovPTrans = new Map([
|
|
825
|
+
[
|
|
826
|
+
INCGOV_PROFILE_MATURITY_V2.PENDING,
|
|
827
|
+
new Set([
|
|
828
|
+
INCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
829
|
+
INCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
830
|
+
]),
|
|
831
|
+
],
|
|
832
|
+
[
|
|
833
|
+
INCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
834
|
+
new Set([
|
|
835
|
+
INCGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
836
|
+
INCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
837
|
+
]),
|
|
838
|
+
],
|
|
839
|
+
[
|
|
840
|
+
INCGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
841
|
+
new Set([
|
|
842
|
+
INCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
843
|
+
INCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
844
|
+
]),
|
|
845
|
+
],
|
|
846
|
+
[INCGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
847
|
+
]);
|
|
848
|
+
const _incgovPTerminal = new Set([INCGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
849
|
+
const _incgovJTrans = new Map([
|
|
850
|
+
[
|
|
851
|
+
INCGOV_PAYOUT_LIFECYCLE_V2.QUEUED,
|
|
852
|
+
new Set([
|
|
853
|
+
INCGOV_PAYOUT_LIFECYCLE_V2.PROCESSING,
|
|
854
|
+
INCGOV_PAYOUT_LIFECYCLE_V2.CANCELLED,
|
|
855
|
+
]),
|
|
856
|
+
],
|
|
857
|
+
[
|
|
858
|
+
INCGOV_PAYOUT_LIFECYCLE_V2.PROCESSING,
|
|
859
|
+
new Set([
|
|
860
|
+
INCGOV_PAYOUT_LIFECYCLE_V2.PAID,
|
|
861
|
+
INCGOV_PAYOUT_LIFECYCLE_V2.FAILED,
|
|
862
|
+
INCGOV_PAYOUT_LIFECYCLE_V2.CANCELLED,
|
|
863
|
+
]),
|
|
864
|
+
],
|
|
865
|
+
[INCGOV_PAYOUT_LIFECYCLE_V2.PAID, new Set()],
|
|
866
|
+
[INCGOV_PAYOUT_LIFECYCLE_V2.FAILED, new Set()],
|
|
867
|
+
[INCGOV_PAYOUT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
868
|
+
]);
|
|
869
|
+
const _incgovPsV2 = new Map();
|
|
870
|
+
const _incgovJsV2 = new Map();
|
|
871
|
+
let _incgovMaxActive = 10,
|
|
872
|
+
_incgovMaxPending = 30,
|
|
873
|
+
_incgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
874
|
+
_incgovStuckMs = 60 * 1000;
|
|
875
|
+
function _incgovPos(n, label) {
|
|
876
|
+
const v = Math.floor(Number(n));
|
|
877
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
878
|
+
throw new Error(`${label} must be positive integer`);
|
|
879
|
+
return v;
|
|
880
|
+
}
|
|
881
|
+
function _incgovCheckP(from, to) {
|
|
882
|
+
const a = _incgovPTrans.get(from);
|
|
883
|
+
if (!a || !a.has(to))
|
|
884
|
+
throw new Error(`invalid incgov profile transition ${from} → ${to}`);
|
|
885
|
+
}
|
|
886
|
+
function _incgovCheckJ(from, to) {
|
|
887
|
+
const a = _incgovJTrans.get(from);
|
|
888
|
+
if (!a || !a.has(to))
|
|
889
|
+
throw new Error(`invalid incgov payout transition ${from} → ${to}`);
|
|
890
|
+
}
|
|
891
|
+
function _incgovCountActive(owner) {
|
|
892
|
+
let c = 0;
|
|
893
|
+
for (const p of _incgovPsV2.values())
|
|
894
|
+
if (p.owner === owner && p.status === INCGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
895
|
+
c++;
|
|
896
|
+
return c;
|
|
897
|
+
}
|
|
898
|
+
function _incgovCountPending(profileId) {
|
|
899
|
+
let c = 0;
|
|
900
|
+
for (const j of _incgovJsV2.values())
|
|
901
|
+
if (
|
|
902
|
+
j.profileId === profileId &&
|
|
903
|
+
(j.status === INCGOV_PAYOUT_LIFECYCLE_V2.QUEUED ||
|
|
904
|
+
j.status === INCGOV_PAYOUT_LIFECYCLE_V2.PROCESSING)
|
|
905
|
+
)
|
|
906
|
+
c++;
|
|
907
|
+
return c;
|
|
908
|
+
}
|
|
909
|
+
export function setMaxActiveIncgovProfilesPerOwnerV2(n) {
|
|
910
|
+
_incgovMaxActive = _incgovPos(n, "maxActiveIncgovProfilesPerOwner");
|
|
911
|
+
}
|
|
912
|
+
export function getMaxActiveIncgovProfilesPerOwnerV2() {
|
|
913
|
+
return _incgovMaxActive;
|
|
914
|
+
}
|
|
915
|
+
export function setMaxPendingIncgovPayoutsPerProfileV2(n) {
|
|
916
|
+
_incgovMaxPending = _incgovPos(n, "maxPendingIncgovPayoutsPerProfile");
|
|
917
|
+
}
|
|
918
|
+
export function getMaxPendingIncgovPayoutsPerProfileV2() {
|
|
919
|
+
return _incgovMaxPending;
|
|
920
|
+
}
|
|
921
|
+
export function setIncgovProfileIdleMsV2(n) {
|
|
922
|
+
_incgovIdleMs = _incgovPos(n, "incgovProfileIdleMs");
|
|
923
|
+
}
|
|
924
|
+
export function getIncgovProfileIdleMsV2() {
|
|
925
|
+
return _incgovIdleMs;
|
|
926
|
+
}
|
|
927
|
+
export function setIncgovPayoutStuckMsV2(n) {
|
|
928
|
+
_incgovStuckMs = _incgovPos(n, "incgovPayoutStuckMs");
|
|
929
|
+
}
|
|
930
|
+
export function getIncgovPayoutStuckMsV2() {
|
|
931
|
+
return _incgovStuckMs;
|
|
932
|
+
}
|
|
933
|
+
export function _resetStateTokenIncentiveV2() {
|
|
934
|
+
_incgovPsV2.clear();
|
|
935
|
+
_incgovJsV2.clear();
|
|
936
|
+
_incgovMaxActive = 10;
|
|
937
|
+
_incgovMaxPending = 30;
|
|
938
|
+
_incgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
939
|
+
_incgovStuckMs = 60 * 1000;
|
|
940
|
+
}
|
|
941
|
+
export function registerIncgovProfileV2({ id, owner, token, metadata } = {}) {
|
|
942
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
943
|
+
if (_incgovPsV2.has(id))
|
|
944
|
+
throw new Error(`incgov profile ${id} already exists`);
|
|
945
|
+
const now = Date.now();
|
|
946
|
+
const p = {
|
|
947
|
+
id,
|
|
948
|
+
owner,
|
|
949
|
+
token: token || "CLC",
|
|
950
|
+
status: INCGOV_PROFILE_MATURITY_V2.PENDING,
|
|
951
|
+
createdAt: now,
|
|
952
|
+
updatedAt: now,
|
|
953
|
+
lastTouchedAt: now,
|
|
954
|
+
activatedAt: null,
|
|
955
|
+
archivedAt: null,
|
|
956
|
+
metadata: { ...(metadata || {}) },
|
|
957
|
+
};
|
|
958
|
+
_incgovPsV2.set(id, p);
|
|
959
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
960
|
+
}
|
|
961
|
+
export function activateIncgovProfileV2(id) {
|
|
962
|
+
const p = _incgovPsV2.get(id);
|
|
963
|
+
if (!p) throw new Error(`incgov profile ${id} not found`);
|
|
964
|
+
const isInitial = p.status === INCGOV_PROFILE_MATURITY_V2.PENDING;
|
|
965
|
+
_incgovCheckP(p.status, INCGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
966
|
+
if (isInitial && _incgovCountActive(p.owner) >= _incgovMaxActive)
|
|
967
|
+
throw new Error(`max active incgov profiles for owner ${p.owner} reached`);
|
|
968
|
+
const now = Date.now();
|
|
969
|
+
p.status = INCGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
970
|
+
p.updatedAt = now;
|
|
971
|
+
p.lastTouchedAt = now;
|
|
972
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
973
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
974
|
+
}
|
|
975
|
+
export function pauseIncgovProfileV2(id) {
|
|
976
|
+
const p = _incgovPsV2.get(id);
|
|
977
|
+
if (!p) throw new Error(`incgov profile ${id} not found`);
|
|
978
|
+
_incgovCheckP(p.status, INCGOV_PROFILE_MATURITY_V2.PAUSED);
|
|
979
|
+
p.status = INCGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
980
|
+
p.updatedAt = Date.now();
|
|
981
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
982
|
+
}
|
|
983
|
+
export function archiveIncgovProfileV2(id) {
|
|
984
|
+
const p = _incgovPsV2.get(id);
|
|
985
|
+
if (!p) throw new Error(`incgov profile ${id} not found`);
|
|
986
|
+
_incgovCheckP(p.status, INCGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
987
|
+
const now = Date.now();
|
|
988
|
+
p.status = INCGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
989
|
+
p.updatedAt = now;
|
|
990
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
991
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
992
|
+
}
|
|
993
|
+
export function touchIncgovProfileV2(id) {
|
|
994
|
+
const p = _incgovPsV2.get(id);
|
|
995
|
+
if (!p) throw new Error(`incgov profile ${id} not found`);
|
|
996
|
+
if (_incgovPTerminal.has(p.status))
|
|
997
|
+
throw new Error(`cannot touch terminal incgov profile ${id}`);
|
|
998
|
+
const now = Date.now();
|
|
999
|
+
p.lastTouchedAt = now;
|
|
1000
|
+
p.updatedAt = now;
|
|
1001
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1002
|
+
}
|
|
1003
|
+
export function getIncgovProfileV2(id) {
|
|
1004
|
+
const p = _incgovPsV2.get(id);
|
|
1005
|
+
if (!p) return null;
|
|
1006
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1007
|
+
}
|
|
1008
|
+
export function listIncgovProfilesV2() {
|
|
1009
|
+
return [..._incgovPsV2.values()].map((p) => ({
|
|
1010
|
+
...p,
|
|
1011
|
+
metadata: { ...p.metadata },
|
|
1012
|
+
}));
|
|
1013
|
+
}
|
|
1014
|
+
export function createIncgovPayoutV2({
|
|
1015
|
+
id,
|
|
1016
|
+
profileId,
|
|
1017
|
+
recipient,
|
|
1018
|
+
metadata,
|
|
1019
|
+
} = {}) {
|
|
1020
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1021
|
+
if (_incgovJsV2.has(id))
|
|
1022
|
+
throw new Error(`incgov payout ${id} already exists`);
|
|
1023
|
+
if (!_incgovPsV2.has(profileId))
|
|
1024
|
+
throw new Error(`incgov profile ${profileId} not found`);
|
|
1025
|
+
if (_incgovCountPending(profileId) >= _incgovMaxPending)
|
|
1026
|
+
throw new Error(
|
|
1027
|
+
`max pending incgov payouts for profile ${profileId} reached`,
|
|
1028
|
+
);
|
|
1029
|
+
const now = Date.now();
|
|
1030
|
+
const j = {
|
|
1031
|
+
id,
|
|
1032
|
+
profileId,
|
|
1033
|
+
recipient: recipient || "",
|
|
1034
|
+
status: INCGOV_PAYOUT_LIFECYCLE_V2.QUEUED,
|
|
1035
|
+
createdAt: now,
|
|
1036
|
+
updatedAt: now,
|
|
1037
|
+
startedAt: null,
|
|
1038
|
+
settledAt: null,
|
|
1039
|
+
metadata: { ...(metadata || {}) },
|
|
1040
|
+
};
|
|
1041
|
+
_incgovJsV2.set(id, j);
|
|
1042
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1043
|
+
}
|
|
1044
|
+
export function processingIncgovPayoutV2(id) {
|
|
1045
|
+
const j = _incgovJsV2.get(id);
|
|
1046
|
+
if (!j) throw new Error(`incgov payout ${id} not found`);
|
|
1047
|
+
_incgovCheckJ(j.status, INCGOV_PAYOUT_LIFECYCLE_V2.PROCESSING);
|
|
1048
|
+
const now = Date.now();
|
|
1049
|
+
j.status = INCGOV_PAYOUT_LIFECYCLE_V2.PROCESSING;
|
|
1050
|
+
j.updatedAt = now;
|
|
1051
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1052
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1053
|
+
}
|
|
1054
|
+
export function completePayoutIncgovV2(id) {
|
|
1055
|
+
const j = _incgovJsV2.get(id);
|
|
1056
|
+
if (!j) throw new Error(`incgov payout ${id} not found`);
|
|
1057
|
+
_incgovCheckJ(j.status, INCGOV_PAYOUT_LIFECYCLE_V2.PAID);
|
|
1058
|
+
const now = Date.now();
|
|
1059
|
+
j.status = INCGOV_PAYOUT_LIFECYCLE_V2.PAID;
|
|
1060
|
+
j.updatedAt = now;
|
|
1061
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1062
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1063
|
+
}
|
|
1064
|
+
export function failIncgovPayoutV2(id, reason) {
|
|
1065
|
+
const j = _incgovJsV2.get(id);
|
|
1066
|
+
if (!j) throw new Error(`incgov payout ${id} not found`);
|
|
1067
|
+
_incgovCheckJ(j.status, INCGOV_PAYOUT_LIFECYCLE_V2.FAILED);
|
|
1068
|
+
const now = Date.now();
|
|
1069
|
+
j.status = INCGOV_PAYOUT_LIFECYCLE_V2.FAILED;
|
|
1070
|
+
j.updatedAt = now;
|
|
1071
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1072
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1073
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1074
|
+
}
|
|
1075
|
+
export function cancelIncgovPayoutV2(id, reason) {
|
|
1076
|
+
const j = _incgovJsV2.get(id);
|
|
1077
|
+
if (!j) throw new Error(`incgov payout ${id} not found`);
|
|
1078
|
+
_incgovCheckJ(j.status, INCGOV_PAYOUT_LIFECYCLE_V2.CANCELLED);
|
|
1079
|
+
const now = Date.now();
|
|
1080
|
+
j.status = INCGOV_PAYOUT_LIFECYCLE_V2.CANCELLED;
|
|
1081
|
+
j.updatedAt = now;
|
|
1082
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1083
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1084
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1085
|
+
}
|
|
1086
|
+
export function getIncgovPayoutV2(id) {
|
|
1087
|
+
const j = _incgovJsV2.get(id);
|
|
1088
|
+
if (!j) return null;
|
|
1089
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1090
|
+
}
|
|
1091
|
+
export function listIncgovPayoutsV2() {
|
|
1092
|
+
return [..._incgovJsV2.values()].map((j) => ({
|
|
1093
|
+
...j,
|
|
1094
|
+
metadata: { ...j.metadata },
|
|
1095
|
+
}));
|
|
1096
|
+
}
|
|
1097
|
+
export function autoPauseIdleIncgovProfilesV2({ now } = {}) {
|
|
1098
|
+
const t = now ?? Date.now();
|
|
1099
|
+
const flipped = [];
|
|
1100
|
+
for (const p of _incgovPsV2.values())
|
|
1101
|
+
if (
|
|
1102
|
+
p.status === INCGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1103
|
+
t - p.lastTouchedAt >= _incgovIdleMs
|
|
1104
|
+
) {
|
|
1105
|
+
p.status = INCGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
1106
|
+
p.updatedAt = t;
|
|
1107
|
+
flipped.push(p.id);
|
|
1108
|
+
}
|
|
1109
|
+
return { flipped, count: flipped.length };
|
|
1110
|
+
}
|
|
1111
|
+
export function autoFailStuckIncgovPayoutsV2({ now } = {}) {
|
|
1112
|
+
const t = now ?? Date.now();
|
|
1113
|
+
const flipped = [];
|
|
1114
|
+
for (const j of _incgovJsV2.values())
|
|
1115
|
+
if (
|
|
1116
|
+
j.status === INCGOV_PAYOUT_LIFECYCLE_V2.PROCESSING &&
|
|
1117
|
+
j.startedAt != null &&
|
|
1118
|
+
t - j.startedAt >= _incgovStuckMs
|
|
1119
|
+
) {
|
|
1120
|
+
j.status = INCGOV_PAYOUT_LIFECYCLE_V2.FAILED;
|
|
1121
|
+
j.updatedAt = t;
|
|
1122
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1123
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1124
|
+
flipped.push(j.id);
|
|
1125
|
+
}
|
|
1126
|
+
return { flipped, count: flipped.length };
|
|
1127
|
+
}
|
|
1128
|
+
export function getTokenIncentiveGovStatsV2() {
|
|
1129
|
+
const profilesByStatus = {};
|
|
1130
|
+
for (const v of Object.values(INCGOV_PROFILE_MATURITY_V2))
|
|
1131
|
+
profilesByStatus[v] = 0;
|
|
1132
|
+
for (const p of _incgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1133
|
+
const payoutsByStatus = {};
|
|
1134
|
+
for (const v of Object.values(INCGOV_PAYOUT_LIFECYCLE_V2))
|
|
1135
|
+
payoutsByStatus[v] = 0;
|
|
1136
|
+
for (const j of _incgovJsV2.values()) payoutsByStatus[j.status]++;
|
|
1137
|
+
return {
|
|
1138
|
+
totalIncgovProfilesV2: _incgovPsV2.size,
|
|
1139
|
+
totalIncgovPayoutsV2: _incgovJsV2.size,
|
|
1140
|
+
maxActiveIncgovProfilesPerOwner: _incgovMaxActive,
|
|
1141
|
+
maxPendingIncgovPayoutsPerProfile: _incgovMaxPending,
|
|
1142
|
+
incgovProfileIdleMs: _incgovIdleMs,
|
|
1143
|
+
incgovPayoutStuckMs: _incgovStuckMs,
|
|
1144
|
+
profilesByStatus,
|
|
1145
|
+
payoutsByStatus,
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
@@ -398,3 +398,356 @@ export function classifyTopic(text, opts = {}) {
|
|
|
398
398
|
export function _resetState() {
|
|
399
399
|
_customLexicons.clear();
|
|
400
400
|
}
|
|
401
|
+
|
|
402
|
+
// ===== V2 Surface: Topic Classifier governance overlay (CLI v0.140.0) =====
|
|
403
|
+
export const TOPIC_CLS_PROFILE_MATURITY_V2 = Object.freeze({
|
|
404
|
+
PENDING: "pending",
|
|
405
|
+
ACTIVE: "active",
|
|
406
|
+
STALE: "stale",
|
|
407
|
+
ARCHIVED: "archived",
|
|
408
|
+
});
|
|
409
|
+
export const TOPIC_CLS_JOB_LIFECYCLE_V2 = Object.freeze({
|
|
410
|
+
QUEUED: "queued",
|
|
411
|
+
RUNNING: "running",
|
|
412
|
+
COMPLETED: "completed",
|
|
413
|
+
FAILED: "failed",
|
|
414
|
+
CANCELLED: "cancelled",
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
const _tcpTrans = new Map([
|
|
418
|
+
[
|
|
419
|
+
TOPIC_CLS_PROFILE_MATURITY_V2.PENDING,
|
|
420
|
+
new Set([
|
|
421
|
+
TOPIC_CLS_PROFILE_MATURITY_V2.ACTIVE,
|
|
422
|
+
TOPIC_CLS_PROFILE_MATURITY_V2.ARCHIVED,
|
|
423
|
+
]),
|
|
424
|
+
],
|
|
425
|
+
[
|
|
426
|
+
TOPIC_CLS_PROFILE_MATURITY_V2.ACTIVE,
|
|
427
|
+
new Set([
|
|
428
|
+
TOPIC_CLS_PROFILE_MATURITY_V2.STALE,
|
|
429
|
+
TOPIC_CLS_PROFILE_MATURITY_V2.ARCHIVED,
|
|
430
|
+
]),
|
|
431
|
+
],
|
|
432
|
+
[
|
|
433
|
+
TOPIC_CLS_PROFILE_MATURITY_V2.STALE,
|
|
434
|
+
new Set([
|
|
435
|
+
TOPIC_CLS_PROFILE_MATURITY_V2.ACTIVE,
|
|
436
|
+
TOPIC_CLS_PROFILE_MATURITY_V2.ARCHIVED,
|
|
437
|
+
]),
|
|
438
|
+
],
|
|
439
|
+
[TOPIC_CLS_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
440
|
+
]);
|
|
441
|
+
const _tcpTerminal = new Set([TOPIC_CLS_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
442
|
+
const _tcjTrans = new Map([
|
|
443
|
+
[
|
|
444
|
+
TOPIC_CLS_JOB_LIFECYCLE_V2.QUEUED,
|
|
445
|
+
new Set([
|
|
446
|
+
TOPIC_CLS_JOB_LIFECYCLE_V2.RUNNING,
|
|
447
|
+
TOPIC_CLS_JOB_LIFECYCLE_V2.CANCELLED,
|
|
448
|
+
]),
|
|
449
|
+
],
|
|
450
|
+
[
|
|
451
|
+
TOPIC_CLS_JOB_LIFECYCLE_V2.RUNNING,
|
|
452
|
+
new Set([
|
|
453
|
+
TOPIC_CLS_JOB_LIFECYCLE_V2.COMPLETED,
|
|
454
|
+
TOPIC_CLS_JOB_LIFECYCLE_V2.FAILED,
|
|
455
|
+
TOPIC_CLS_JOB_LIFECYCLE_V2.CANCELLED,
|
|
456
|
+
]),
|
|
457
|
+
],
|
|
458
|
+
[TOPIC_CLS_JOB_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
459
|
+
[TOPIC_CLS_JOB_LIFECYCLE_V2.FAILED, new Set()],
|
|
460
|
+
[TOPIC_CLS_JOB_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
461
|
+
]);
|
|
462
|
+
|
|
463
|
+
const _tcpsV2 = new Map();
|
|
464
|
+
const _tcjsV2 = new Map();
|
|
465
|
+
let _tcpMaxActivePerOwner = 8;
|
|
466
|
+
let _tcpMaxPendingJobsPerProfile = 20;
|
|
467
|
+
let _tcpIdleMs = 14 * 24 * 60 * 60 * 1000;
|
|
468
|
+
let _tcjStuckMs = 5 * 60 * 1000;
|
|
469
|
+
|
|
470
|
+
function _tcpPos(n, lbl) {
|
|
471
|
+
const v = Math.floor(Number(n));
|
|
472
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
473
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
474
|
+
return v;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export function setMaxActiveTopicClsProfilesPerOwnerV2(n) {
|
|
478
|
+
_tcpMaxActivePerOwner = _tcpPos(n, "maxActiveTopicClsProfilesPerOwner");
|
|
479
|
+
}
|
|
480
|
+
export function getMaxActiveTopicClsProfilesPerOwnerV2() {
|
|
481
|
+
return _tcpMaxActivePerOwner;
|
|
482
|
+
}
|
|
483
|
+
export function setMaxPendingTopicClsJobsPerProfileV2(n) {
|
|
484
|
+
_tcpMaxPendingJobsPerProfile = _tcpPos(n, "maxPendingTopicClsJobsPerProfile");
|
|
485
|
+
}
|
|
486
|
+
export function getMaxPendingTopicClsJobsPerProfileV2() {
|
|
487
|
+
return _tcpMaxPendingJobsPerProfile;
|
|
488
|
+
}
|
|
489
|
+
export function setTopicClsProfileIdleMsV2(n) {
|
|
490
|
+
_tcpIdleMs = _tcpPos(n, "topicClsProfileIdleMs");
|
|
491
|
+
}
|
|
492
|
+
export function getTopicClsProfileIdleMsV2() {
|
|
493
|
+
return _tcpIdleMs;
|
|
494
|
+
}
|
|
495
|
+
export function setTopicClsJobStuckMsV2(n) {
|
|
496
|
+
_tcjStuckMs = _tcpPos(n, "topicClsJobStuckMs");
|
|
497
|
+
}
|
|
498
|
+
export function getTopicClsJobStuckMsV2() {
|
|
499
|
+
return _tcjStuckMs;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export function _resetStateTopicClsV2() {
|
|
503
|
+
_tcpsV2.clear();
|
|
504
|
+
_tcjsV2.clear();
|
|
505
|
+
_tcpMaxActivePerOwner = 8;
|
|
506
|
+
_tcpMaxPendingJobsPerProfile = 20;
|
|
507
|
+
_tcpIdleMs = 14 * 24 * 60 * 60 * 1000;
|
|
508
|
+
_tcjStuckMs = 5 * 60 * 1000;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export function registerTopicClsProfileV2({ id, owner, model, metadata } = {}) {
|
|
512
|
+
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
513
|
+
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
514
|
+
if (_tcpsV2.has(id))
|
|
515
|
+
throw new Error(`topic cls profile ${id} already registered`);
|
|
516
|
+
const now = Date.now();
|
|
517
|
+
const p = {
|
|
518
|
+
id,
|
|
519
|
+
owner,
|
|
520
|
+
model: model || "default",
|
|
521
|
+
status: TOPIC_CLS_PROFILE_MATURITY_V2.PENDING,
|
|
522
|
+
createdAt: now,
|
|
523
|
+
updatedAt: now,
|
|
524
|
+
activatedAt: null,
|
|
525
|
+
archivedAt: null,
|
|
526
|
+
lastTouchedAt: now,
|
|
527
|
+
metadata: { ...(metadata || {}) },
|
|
528
|
+
};
|
|
529
|
+
_tcpsV2.set(id, p);
|
|
530
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
531
|
+
}
|
|
532
|
+
function _tcpCheckP(from, to) {
|
|
533
|
+
const a = _tcpTrans.get(from);
|
|
534
|
+
if (!a || !a.has(to))
|
|
535
|
+
throw new Error(`invalid topic cls profile transition ${from} → ${to}`);
|
|
536
|
+
}
|
|
537
|
+
function _tcpCountActive(owner) {
|
|
538
|
+
let n = 0;
|
|
539
|
+
for (const p of _tcpsV2.values())
|
|
540
|
+
if (p.owner === owner && p.status === TOPIC_CLS_PROFILE_MATURITY_V2.ACTIVE)
|
|
541
|
+
n++;
|
|
542
|
+
return n;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export function activateTopicClsProfileV2(id) {
|
|
546
|
+
const p = _tcpsV2.get(id);
|
|
547
|
+
if (!p) throw new Error(`topic cls profile ${id} not found`);
|
|
548
|
+
_tcpCheckP(p.status, TOPIC_CLS_PROFILE_MATURITY_V2.ACTIVE);
|
|
549
|
+
const recovery = p.status === TOPIC_CLS_PROFILE_MATURITY_V2.STALE;
|
|
550
|
+
if (!recovery) {
|
|
551
|
+
const c = _tcpCountActive(p.owner);
|
|
552
|
+
if (c >= _tcpMaxActivePerOwner)
|
|
553
|
+
throw new Error(
|
|
554
|
+
`max active topic cls profiles per owner (${_tcpMaxActivePerOwner}) reached for ${p.owner}`,
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
const now = Date.now();
|
|
558
|
+
p.status = TOPIC_CLS_PROFILE_MATURITY_V2.ACTIVE;
|
|
559
|
+
p.updatedAt = now;
|
|
560
|
+
p.lastTouchedAt = now;
|
|
561
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
562
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
563
|
+
}
|
|
564
|
+
export function staleTopicClsProfileV2(id) {
|
|
565
|
+
const p = _tcpsV2.get(id);
|
|
566
|
+
if (!p) throw new Error(`topic cls profile ${id} not found`);
|
|
567
|
+
_tcpCheckP(p.status, TOPIC_CLS_PROFILE_MATURITY_V2.STALE);
|
|
568
|
+
p.status = TOPIC_CLS_PROFILE_MATURITY_V2.STALE;
|
|
569
|
+
p.updatedAt = Date.now();
|
|
570
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
571
|
+
}
|
|
572
|
+
export function archiveTopicClsProfileV2(id) {
|
|
573
|
+
const p = _tcpsV2.get(id);
|
|
574
|
+
if (!p) throw new Error(`topic cls profile ${id} not found`);
|
|
575
|
+
_tcpCheckP(p.status, TOPIC_CLS_PROFILE_MATURITY_V2.ARCHIVED);
|
|
576
|
+
const now = Date.now();
|
|
577
|
+
p.status = TOPIC_CLS_PROFILE_MATURITY_V2.ARCHIVED;
|
|
578
|
+
p.updatedAt = now;
|
|
579
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
580
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
581
|
+
}
|
|
582
|
+
export function touchTopicClsProfileV2(id) {
|
|
583
|
+
const p = _tcpsV2.get(id);
|
|
584
|
+
if (!p) throw new Error(`topic cls profile ${id} not found`);
|
|
585
|
+
if (_tcpTerminal.has(p.status))
|
|
586
|
+
throw new Error(`cannot touch terminal topic cls profile ${id}`);
|
|
587
|
+
const now = Date.now();
|
|
588
|
+
p.lastTouchedAt = now;
|
|
589
|
+
p.updatedAt = now;
|
|
590
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
591
|
+
}
|
|
592
|
+
export function getTopicClsProfileV2(id) {
|
|
593
|
+
const p = _tcpsV2.get(id);
|
|
594
|
+
if (!p) return null;
|
|
595
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
596
|
+
}
|
|
597
|
+
export function listTopicClsProfilesV2() {
|
|
598
|
+
return [..._tcpsV2.values()].map((p) => ({
|
|
599
|
+
...p,
|
|
600
|
+
metadata: { ...p.metadata },
|
|
601
|
+
}));
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function _tcjCountPending(profileId) {
|
|
605
|
+
let n = 0;
|
|
606
|
+
for (const j of _tcjsV2.values())
|
|
607
|
+
if (
|
|
608
|
+
j.profileId === profileId &&
|
|
609
|
+
(j.status === TOPIC_CLS_JOB_LIFECYCLE_V2.QUEUED ||
|
|
610
|
+
j.status === TOPIC_CLS_JOB_LIFECYCLE_V2.RUNNING)
|
|
611
|
+
)
|
|
612
|
+
n++;
|
|
613
|
+
return n;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
export function createTopicClsJobV2({ id, profileId, text, metadata } = {}) {
|
|
617
|
+
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
618
|
+
if (!profileId || typeof profileId !== "string")
|
|
619
|
+
throw new Error("profileId is required");
|
|
620
|
+
if (_tcjsV2.has(id)) throw new Error(`topic cls job ${id} already exists`);
|
|
621
|
+
if (!_tcpsV2.has(profileId))
|
|
622
|
+
throw new Error(`topic cls profile ${profileId} not found`);
|
|
623
|
+
const pending = _tcjCountPending(profileId);
|
|
624
|
+
if (pending >= _tcpMaxPendingJobsPerProfile)
|
|
625
|
+
throw new Error(
|
|
626
|
+
`max pending topic cls jobs per profile (${_tcpMaxPendingJobsPerProfile}) reached for ${profileId}`,
|
|
627
|
+
);
|
|
628
|
+
const now = Date.now();
|
|
629
|
+
const j = {
|
|
630
|
+
id,
|
|
631
|
+
profileId,
|
|
632
|
+
text: text || "",
|
|
633
|
+
status: TOPIC_CLS_JOB_LIFECYCLE_V2.QUEUED,
|
|
634
|
+
createdAt: now,
|
|
635
|
+
updatedAt: now,
|
|
636
|
+
startedAt: null,
|
|
637
|
+
settledAt: null,
|
|
638
|
+
metadata: { ...(metadata || {}) },
|
|
639
|
+
};
|
|
640
|
+
_tcjsV2.set(id, j);
|
|
641
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
642
|
+
}
|
|
643
|
+
function _tcjCheckJ(from, to) {
|
|
644
|
+
const a = _tcjTrans.get(from);
|
|
645
|
+
if (!a || !a.has(to))
|
|
646
|
+
throw new Error(`invalid topic cls job transition ${from} → ${to}`);
|
|
647
|
+
}
|
|
648
|
+
export function startTopicClsJobV2(id) {
|
|
649
|
+
const j = _tcjsV2.get(id);
|
|
650
|
+
if (!j) throw new Error(`topic cls job ${id} not found`);
|
|
651
|
+
_tcjCheckJ(j.status, TOPIC_CLS_JOB_LIFECYCLE_V2.RUNNING);
|
|
652
|
+
const now = Date.now();
|
|
653
|
+
j.status = TOPIC_CLS_JOB_LIFECYCLE_V2.RUNNING;
|
|
654
|
+
j.updatedAt = now;
|
|
655
|
+
if (!j.startedAt) j.startedAt = now;
|
|
656
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
657
|
+
}
|
|
658
|
+
export function completeTopicClsJobV2(id) {
|
|
659
|
+
const j = _tcjsV2.get(id);
|
|
660
|
+
if (!j) throw new Error(`topic cls job ${id} not found`);
|
|
661
|
+
_tcjCheckJ(j.status, TOPIC_CLS_JOB_LIFECYCLE_V2.COMPLETED);
|
|
662
|
+
const now = Date.now();
|
|
663
|
+
j.status = TOPIC_CLS_JOB_LIFECYCLE_V2.COMPLETED;
|
|
664
|
+
j.updatedAt = now;
|
|
665
|
+
if (!j.settledAt) j.settledAt = now;
|
|
666
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
667
|
+
}
|
|
668
|
+
export function failTopicClsJobV2(id, reason) {
|
|
669
|
+
const j = _tcjsV2.get(id);
|
|
670
|
+
if (!j) throw new Error(`topic cls job ${id} not found`);
|
|
671
|
+
_tcjCheckJ(j.status, TOPIC_CLS_JOB_LIFECYCLE_V2.FAILED);
|
|
672
|
+
const now = Date.now();
|
|
673
|
+
j.status = TOPIC_CLS_JOB_LIFECYCLE_V2.FAILED;
|
|
674
|
+
j.updatedAt = now;
|
|
675
|
+
if (!j.settledAt) j.settledAt = now;
|
|
676
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
677
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
678
|
+
}
|
|
679
|
+
export function cancelTopicClsJobV2(id, reason) {
|
|
680
|
+
const j = _tcjsV2.get(id);
|
|
681
|
+
if (!j) throw new Error(`topic cls job ${id} not found`);
|
|
682
|
+
_tcjCheckJ(j.status, TOPIC_CLS_JOB_LIFECYCLE_V2.CANCELLED);
|
|
683
|
+
const now = Date.now();
|
|
684
|
+
j.status = TOPIC_CLS_JOB_LIFECYCLE_V2.CANCELLED;
|
|
685
|
+
j.updatedAt = now;
|
|
686
|
+
if (!j.settledAt) j.settledAt = now;
|
|
687
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
688
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
689
|
+
}
|
|
690
|
+
export function getTopicClsJobV2(id) {
|
|
691
|
+
const j = _tcjsV2.get(id);
|
|
692
|
+
if (!j) return null;
|
|
693
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
694
|
+
}
|
|
695
|
+
export function listTopicClsJobsV2() {
|
|
696
|
+
return [..._tcjsV2.values()].map((j) => ({
|
|
697
|
+
...j,
|
|
698
|
+
metadata: { ...j.metadata },
|
|
699
|
+
}));
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
export function autoStaleIdleTopicClsProfilesV2({ now } = {}) {
|
|
703
|
+
const t = now ?? Date.now();
|
|
704
|
+
const flipped = [];
|
|
705
|
+
for (const p of _tcpsV2.values())
|
|
706
|
+
if (
|
|
707
|
+
p.status === TOPIC_CLS_PROFILE_MATURITY_V2.ACTIVE &&
|
|
708
|
+
t - p.lastTouchedAt >= _tcpIdleMs
|
|
709
|
+
) {
|
|
710
|
+
p.status = TOPIC_CLS_PROFILE_MATURITY_V2.STALE;
|
|
711
|
+
p.updatedAt = t;
|
|
712
|
+
flipped.push(p.id);
|
|
713
|
+
}
|
|
714
|
+
return { flipped, count: flipped.length };
|
|
715
|
+
}
|
|
716
|
+
export function autoFailStuckTopicClsJobsV2({ now } = {}) {
|
|
717
|
+
const t = now ?? Date.now();
|
|
718
|
+
const flipped = [];
|
|
719
|
+
for (const j of _tcjsV2.values())
|
|
720
|
+
if (
|
|
721
|
+
j.status === TOPIC_CLS_JOB_LIFECYCLE_V2.RUNNING &&
|
|
722
|
+
j.startedAt != null &&
|
|
723
|
+
t - j.startedAt >= _tcjStuckMs
|
|
724
|
+
) {
|
|
725
|
+
j.status = TOPIC_CLS_JOB_LIFECYCLE_V2.FAILED;
|
|
726
|
+
j.updatedAt = t;
|
|
727
|
+
if (!j.settledAt) j.settledAt = t;
|
|
728
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
729
|
+
flipped.push(j.id);
|
|
730
|
+
}
|
|
731
|
+
return { flipped, count: flipped.length };
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
export function getTopicClassifierGovStatsV2() {
|
|
735
|
+
const profilesByStatus = {};
|
|
736
|
+
for (const s of Object.values(TOPIC_CLS_PROFILE_MATURITY_V2))
|
|
737
|
+
profilesByStatus[s] = 0;
|
|
738
|
+
for (const p of _tcpsV2.values()) profilesByStatus[p.status]++;
|
|
739
|
+
const jobsByStatus = {};
|
|
740
|
+
for (const s of Object.values(TOPIC_CLS_JOB_LIFECYCLE_V2))
|
|
741
|
+
jobsByStatus[s] = 0;
|
|
742
|
+
for (const j of _tcjsV2.values()) jobsByStatus[j.status]++;
|
|
743
|
+
return {
|
|
744
|
+
totalTopicClsProfilesV2: _tcpsV2.size,
|
|
745
|
+
totalTopicClsJobsV2: _tcjsV2.size,
|
|
746
|
+
maxActiveTopicClsProfilesPerOwner: _tcpMaxActivePerOwner,
|
|
747
|
+
maxPendingTopicClsJobsPerProfile: _tcpMaxPendingJobsPerProfile,
|
|
748
|
+
topicClsProfileIdleMs: _tcpIdleMs,
|
|
749
|
+
topicClsJobStuckMs: _tcjStuckMs,
|
|
750
|
+
profilesByStatus,
|
|
751
|
+
jobsByStatus,
|
|
752
|
+
};
|
|
753
|
+
}
|