chainlesschain 0.143.0 → 0.152.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/a2a.js +196 -28
- package/src/commands/activitypub.js +364 -27
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +355 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +403 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +824 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +783 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dbevo.js +227 -0
- package/src/commands/dev.js +207 -0
- package/src/commands/did-v2.js +217 -0
- package/src/commands/did.js +221 -0
- package/src/commands/dlp.js +385 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +387 -27
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fflag.js +74 -22
- package/src/commands/fusion.js +205 -0
- package/src/commands/git.js +177 -37
- package/src/commands/governance.js +209 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/llm.js +217 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +386 -27
- package/src/commands/mcp.js +217 -0
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/memory.js +209 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +387 -27
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perception.js +209 -0
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +410 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/session.js +209 -0
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/skill.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +358 -32
- package/src/commands/sso.js +209 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/tokens.js +209 -0
- package/src/commands/topiccls.js +146 -33
- package/src/commands/trust.js +217 -0
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/wallet.js +209 -0
- package/src/commands/webfetch.js +141 -32
- package/src/commands/workflow.js +203 -0
- package/src/commands/zkp.js +184 -28
- package/src/index.js +180 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +622 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +616 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +630 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -0
- package/src/lib/compliance-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- package/src/lib/dbevo.js +351 -0
- package/src/lib/decentral-infra.js +330 -0
- package/src/lib/did-manager.js +341 -0
- package/src/lib/did-v2-manager.js +341 -0
- package/src/lib/dlp-engine.js +626 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +308 -51
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +620 -47
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/memory-manager.js +336 -0
- package/src/lib/multimodal.js +330 -0
- package/src/lib/nl-programming.js +341 -0
- package/src/lib/nostr-bridge.js +622 -49
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-manager.js +334 -0
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/trust-security.js +343 -0
- package/src/lib/ueba.js +340 -0
- package/src/lib/universal-runtime.js +330 -0
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/zkp-engine.js +286 -49
|
@@ -936,3 +936,344 @@ export function _resetStateV2() {
|
|
|
936
936
|
_specsV2.clear();
|
|
937
937
|
_turnsV2.clear();
|
|
938
938
|
}
|
|
939
|
+
|
|
940
|
+
// =====================================================================
|
|
941
|
+
// nl-programming V2 governance overlay (iter18)
|
|
942
|
+
// =====================================================================
|
|
943
|
+
export const NLPGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
944
|
+
PENDING: "pending",
|
|
945
|
+
ACTIVE: "active",
|
|
946
|
+
STALE: "stale",
|
|
947
|
+
ARCHIVED: "archived",
|
|
948
|
+
});
|
|
949
|
+
export const NLPGOV_TRANSLATION_LIFECYCLE_V2 = Object.freeze({
|
|
950
|
+
QUEUED: "queued",
|
|
951
|
+
TRANSLATING: "translating",
|
|
952
|
+
TRANSLATED: "translated",
|
|
953
|
+
FAILED: "failed",
|
|
954
|
+
CANCELLED: "cancelled",
|
|
955
|
+
});
|
|
956
|
+
const _nlpgovPTrans = new Map([
|
|
957
|
+
[
|
|
958
|
+
NLPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
959
|
+
new Set([
|
|
960
|
+
NLPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
961
|
+
NLPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
962
|
+
]),
|
|
963
|
+
],
|
|
964
|
+
[
|
|
965
|
+
NLPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
966
|
+
new Set([
|
|
967
|
+
NLPGOV_PROFILE_MATURITY_V2.STALE,
|
|
968
|
+
NLPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
969
|
+
]),
|
|
970
|
+
],
|
|
971
|
+
[
|
|
972
|
+
NLPGOV_PROFILE_MATURITY_V2.STALE,
|
|
973
|
+
new Set([
|
|
974
|
+
NLPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
975
|
+
NLPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
976
|
+
]),
|
|
977
|
+
],
|
|
978
|
+
[NLPGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
979
|
+
]);
|
|
980
|
+
const _nlpgovPTerminal = new Set([NLPGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
981
|
+
const _nlpgovJTrans = new Map([
|
|
982
|
+
[
|
|
983
|
+
NLPGOV_TRANSLATION_LIFECYCLE_V2.QUEUED,
|
|
984
|
+
new Set([
|
|
985
|
+
NLPGOV_TRANSLATION_LIFECYCLE_V2.TRANSLATING,
|
|
986
|
+
NLPGOV_TRANSLATION_LIFECYCLE_V2.CANCELLED,
|
|
987
|
+
]),
|
|
988
|
+
],
|
|
989
|
+
[
|
|
990
|
+
NLPGOV_TRANSLATION_LIFECYCLE_V2.TRANSLATING,
|
|
991
|
+
new Set([
|
|
992
|
+
NLPGOV_TRANSLATION_LIFECYCLE_V2.TRANSLATED,
|
|
993
|
+
NLPGOV_TRANSLATION_LIFECYCLE_V2.FAILED,
|
|
994
|
+
NLPGOV_TRANSLATION_LIFECYCLE_V2.CANCELLED,
|
|
995
|
+
]),
|
|
996
|
+
],
|
|
997
|
+
[NLPGOV_TRANSLATION_LIFECYCLE_V2.TRANSLATED, new Set()],
|
|
998
|
+
[NLPGOV_TRANSLATION_LIFECYCLE_V2.FAILED, new Set()],
|
|
999
|
+
[NLPGOV_TRANSLATION_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1000
|
+
]);
|
|
1001
|
+
const _nlpgovPsV2 = new Map();
|
|
1002
|
+
const _nlpgovJsV2 = new Map();
|
|
1003
|
+
let _nlpgovMaxActive = 8,
|
|
1004
|
+
_nlpgovMaxPending = 20,
|
|
1005
|
+
_nlpgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1006
|
+
_nlpgovStuckMs = 60 * 1000;
|
|
1007
|
+
function _nlpgovPos(n, label) {
|
|
1008
|
+
const v = Math.floor(Number(n));
|
|
1009
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1010
|
+
throw new Error(`${label} must be positive integer`);
|
|
1011
|
+
return v;
|
|
1012
|
+
}
|
|
1013
|
+
function _nlpgovCheckP(from, to) {
|
|
1014
|
+
const a = _nlpgovPTrans.get(from);
|
|
1015
|
+
if (!a || !a.has(to))
|
|
1016
|
+
throw new Error(`invalid nlpgov profile transition ${from} → ${to}`);
|
|
1017
|
+
}
|
|
1018
|
+
function _nlpgovCheckJ(from, to) {
|
|
1019
|
+
const a = _nlpgovJTrans.get(from);
|
|
1020
|
+
if (!a || !a.has(to))
|
|
1021
|
+
throw new Error(`invalid nlpgov translation transition ${from} → ${to}`);
|
|
1022
|
+
}
|
|
1023
|
+
function _nlpgovCountActive(owner) {
|
|
1024
|
+
let c = 0;
|
|
1025
|
+
for (const p of _nlpgovPsV2.values())
|
|
1026
|
+
if (p.owner === owner && p.status === NLPGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
1027
|
+
c++;
|
|
1028
|
+
return c;
|
|
1029
|
+
}
|
|
1030
|
+
function _nlpgovCountPending(profileId) {
|
|
1031
|
+
let c = 0;
|
|
1032
|
+
for (const j of _nlpgovJsV2.values())
|
|
1033
|
+
if (
|
|
1034
|
+
j.profileId === profileId &&
|
|
1035
|
+
(j.status === NLPGOV_TRANSLATION_LIFECYCLE_V2.QUEUED ||
|
|
1036
|
+
j.status === NLPGOV_TRANSLATION_LIFECYCLE_V2.TRANSLATING)
|
|
1037
|
+
)
|
|
1038
|
+
c++;
|
|
1039
|
+
return c;
|
|
1040
|
+
}
|
|
1041
|
+
export function setMaxActiveNlpgovProfilesPerOwnerV2(n) {
|
|
1042
|
+
_nlpgovMaxActive = _nlpgovPos(n, "maxActiveNlpgovProfilesPerOwner");
|
|
1043
|
+
}
|
|
1044
|
+
export function getMaxActiveNlpgovProfilesPerOwnerV2() {
|
|
1045
|
+
return _nlpgovMaxActive;
|
|
1046
|
+
}
|
|
1047
|
+
export function setMaxPendingNlpgovTranslationsPerProfileV2(n) {
|
|
1048
|
+
_nlpgovMaxPending = _nlpgovPos(n, "maxPendingNlpgovTranslationsPerProfile");
|
|
1049
|
+
}
|
|
1050
|
+
export function getMaxPendingNlpgovTranslationsPerProfileV2() {
|
|
1051
|
+
return _nlpgovMaxPending;
|
|
1052
|
+
}
|
|
1053
|
+
export function setNlpgovProfileIdleMsV2(n) {
|
|
1054
|
+
_nlpgovIdleMs = _nlpgovPos(n, "nlpgovProfileIdleMs");
|
|
1055
|
+
}
|
|
1056
|
+
export function getNlpgovProfileIdleMsV2() {
|
|
1057
|
+
return _nlpgovIdleMs;
|
|
1058
|
+
}
|
|
1059
|
+
export function setNlpgovTranslationStuckMsV2(n) {
|
|
1060
|
+
_nlpgovStuckMs = _nlpgovPos(n, "nlpgovTranslationStuckMs");
|
|
1061
|
+
}
|
|
1062
|
+
export function getNlpgovTranslationStuckMsV2() {
|
|
1063
|
+
return _nlpgovStuckMs;
|
|
1064
|
+
}
|
|
1065
|
+
export function _resetStateNlProgrammingGovV2() {
|
|
1066
|
+
_nlpgovPsV2.clear();
|
|
1067
|
+
_nlpgovJsV2.clear();
|
|
1068
|
+
_nlpgovMaxActive = 8;
|
|
1069
|
+
_nlpgovMaxPending = 20;
|
|
1070
|
+
_nlpgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1071
|
+
_nlpgovStuckMs = 60 * 1000;
|
|
1072
|
+
}
|
|
1073
|
+
export function registerNlpgovProfileV2({ id, owner, style, metadata } = {}) {
|
|
1074
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1075
|
+
if (_nlpgovPsV2.has(id))
|
|
1076
|
+
throw new Error(`nlpgov profile ${id} already exists`);
|
|
1077
|
+
const now = Date.now();
|
|
1078
|
+
const p = {
|
|
1079
|
+
id,
|
|
1080
|
+
owner,
|
|
1081
|
+
style: style || "natural",
|
|
1082
|
+
status: NLPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1083
|
+
createdAt: now,
|
|
1084
|
+
updatedAt: now,
|
|
1085
|
+
lastTouchedAt: now,
|
|
1086
|
+
activatedAt: null,
|
|
1087
|
+
archivedAt: null,
|
|
1088
|
+
metadata: { ...(metadata || {}) },
|
|
1089
|
+
};
|
|
1090
|
+
_nlpgovPsV2.set(id, p);
|
|
1091
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1092
|
+
}
|
|
1093
|
+
export function activateNlpgovProfileV2(id) {
|
|
1094
|
+
const p = _nlpgovPsV2.get(id);
|
|
1095
|
+
if (!p) throw new Error(`nlpgov profile ${id} not found`);
|
|
1096
|
+
const isInitial = p.status === NLPGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1097
|
+
_nlpgovCheckP(p.status, NLPGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1098
|
+
if (isInitial && _nlpgovCountActive(p.owner) >= _nlpgovMaxActive)
|
|
1099
|
+
throw new Error(`max active nlpgov profiles for owner ${p.owner} reached`);
|
|
1100
|
+
const now = Date.now();
|
|
1101
|
+
p.status = NLPGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1102
|
+
p.updatedAt = now;
|
|
1103
|
+
p.lastTouchedAt = now;
|
|
1104
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1105
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1106
|
+
}
|
|
1107
|
+
export function staleNlpgovProfileV2(id) {
|
|
1108
|
+
const p = _nlpgovPsV2.get(id);
|
|
1109
|
+
if (!p) throw new Error(`nlpgov profile ${id} not found`);
|
|
1110
|
+
_nlpgovCheckP(p.status, NLPGOV_PROFILE_MATURITY_V2.STALE);
|
|
1111
|
+
p.status = NLPGOV_PROFILE_MATURITY_V2.STALE;
|
|
1112
|
+
p.updatedAt = Date.now();
|
|
1113
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1114
|
+
}
|
|
1115
|
+
export function archiveNlpgovProfileV2(id) {
|
|
1116
|
+
const p = _nlpgovPsV2.get(id);
|
|
1117
|
+
if (!p) throw new Error(`nlpgov profile ${id} not found`);
|
|
1118
|
+
_nlpgovCheckP(p.status, NLPGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1119
|
+
const now = Date.now();
|
|
1120
|
+
p.status = NLPGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1121
|
+
p.updatedAt = now;
|
|
1122
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1123
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1124
|
+
}
|
|
1125
|
+
export function touchNlpgovProfileV2(id) {
|
|
1126
|
+
const p = _nlpgovPsV2.get(id);
|
|
1127
|
+
if (!p) throw new Error(`nlpgov profile ${id} not found`);
|
|
1128
|
+
if (_nlpgovPTerminal.has(p.status))
|
|
1129
|
+
throw new Error(`cannot touch terminal nlpgov profile ${id}`);
|
|
1130
|
+
const now = Date.now();
|
|
1131
|
+
p.lastTouchedAt = now;
|
|
1132
|
+
p.updatedAt = now;
|
|
1133
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1134
|
+
}
|
|
1135
|
+
export function getNlpgovProfileV2(id) {
|
|
1136
|
+
const p = _nlpgovPsV2.get(id);
|
|
1137
|
+
if (!p) return null;
|
|
1138
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1139
|
+
}
|
|
1140
|
+
export function listNlpgovProfilesV2() {
|
|
1141
|
+
return [..._nlpgovPsV2.values()].map((p) => ({
|
|
1142
|
+
...p,
|
|
1143
|
+
metadata: { ...p.metadata },
|
|
1144
|
+
}));
|
|
1145
|
+
}
|
|
1146
|
+
export function createNlpgovTranslationV2({
|
|
1147
|
+
id,
|
|
1148
|
+
profileId,
|
|
1149
|
+
intent,
|
|
1150
|
+
metadata,
|
|
1151
|
+
} = {}) {
|
|
1152
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1153
|
+
if (_nlpgovJsV2.has(id))
|
|
1154
|
+
throw new Error(`nlpgov translation ${id} already exists`);
|
|
1155
|
+
if (!_nlpgovPsV2.has(profileId))
|
|
1156
|
+
throw new Error(`nlpgov profile ${profileId} not found`);
|
|
1157
|
+
if (_nlpgovCountPending(profileId) >= _nlpgovMaxPending)
|
|
1158
|
+
throw new Error(
|
|
1159
|
+
`max pending nlpgov translations for profile ${profileId} reached`,
|
|
1160
|
+
);
|
|
1161
|
+
const now = Date.now();
|
|
1162
|
+
const j = {
|
|
1163
|
+
id,
|
|
1164
|
+
profileId,
|
|
1165
|
+
intent: intent || "",
|
|
1166
|
+
status: NLPGOV_TRANSLATION_LIFECYCLE_V2.QUEUED,
|
|
1167
|
+
createdAt: now,
|
|
1168
|
+
updatedAt: now,
|
|
1169
|
+
startedAt: null,
|
|
1170
|
+
settledAt: null,
|
|
1171
|
+
metadata: { ...(metadata || {}) },
|
|
1172
|
+
};
|
|
1173
|
+
_nlpgovJsV2.set(id, j);
|
|
1174
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1175
|
+
}
|
|
1176
|
+
export function translatingNlpgovTranslationV2(id) {
|
|
1177
|
+
const j = _nlpgovJsV2.get(id);
|
|
1178
|
+
if (!j) throw new Error(`nlpgov translation ${id} not found`);
|
|
1179
|
+
_nlpgovCheckJ(j.status, NLPGOV_TRANSLATION_LIFECYCLE_V2.TRANSLATING);
|
|
1180
|
+
const now = Date.now();
|
|
1181
|
+
j.status = NLPGOV_TRANSLATION_LIFECYCLE_V2.TRANSLATING;
|
|
1182
|
+
j.updatedAt = now;
|
|
1183
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1184
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1185
|
+
}
|
|
1186
|
+
export function completeTranslationNlpgovV2(id) {
|
|
1187
|
+
const j = _nlpgovJsV2.get(id);
|
|
1188
|
+
if (!j) throw new Error(`nlpgov translation ${id} not found`);
|
|
1189
|
+
_nlpgovCheckJ(j.status, NLPGOV_TRANSLATION_LIFECYCLE_V2.TRANSLATED);
|
|
1190
|
+
const now = Date.now();
|
|
1191
|
+
j.status = NLPGOV_TRANSLATION_LIFECYCLE_V2.TRANSLATED;
|
|
1192
|
+
j.updatedAt = now;
|
|
1193
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1194
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1195
|
+
}
|
|
1196
|
+
export function failNlpgovTranslationV2(id, reason) {
|
|
1197
|
+
const j = _nlpgovJsV2.get(id);
|
|
1198
|
+
if (!j) throw new Error(`nlpgov translation ${id} not found`);
|
|
1199
|
+
_nlpgovCheckJ(j.status, NLPGOV_TRANSLATION_LIFECYCLE_V2.FAILED);
|
|
1200
|
+
const now = Date.now();
|
|
1201
|
+
j.status = NLPGOV_TRANSLATION_LIFECYCLE_V2.FAILED;
|
|
1202
|
+
j.updatedAt = now;
|
|
1203
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1204
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1205
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1206
|
+
}
|
|
1207
|
+
export function cancelNlpgovTranslationV2(id, reason) {
|
|
1208
|
+
const j = _nlpgovJsV2.get(id);
|
|
1209
|
+
if (!j) throw new Error(`nlpgov translation ${id} not found`);
|
|
1210
|
+
_nlpgovCheckJ(j.status, NLPGOV_TRANSLATION_LIFECYCLE_V2.CANCELLED);
|
|
1211
|
+
const now = Date.now();
|
|
1212
|
+
j.status = NLPGOV_TRANSLATION_LIFECYCLE_V2.CANCELLED;
|
|
1213
|
+
j.updatedAt = now;
|
|
1214
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1215
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1216
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1217
|
+
}
|
|
1218
|
+
export function getNlpgovTranslationV2(id) {
|
|
1219
|
+
const j = _nlpgovJsV2.get(id);
|
|
1220
|
+
if (!j) return null;
|
|
1221
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1222
|
+
}
|
|
1223
|
+
export function listNlpgovTranslationsV2() {
|
|
1224
|
+
return [..._nlpgovJsV2.values()].map((j) => ({
|
|
1225
|
+
...j,
|
|
1226
|
+
metadata: { ...j.metadata },
|
|
1227
|
+
}));
|
|
1228
|
+
}
|
|
1229
|
+
export function autoStaleIdleNlpgovProfilesV2({ now } = {}) {
|
|
1230
|
+
const t = now ?? Date.now();
|
|
1231
|
+
const flipped = [];
|
|
1232
|
+
for (const p of _nlpgovPsV2.values())
|
|
1233
|
+
if (
|
|
1234
|
+
p.status === NLPGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1235
|
+
t - p.lastTouchedAt >= _nlpgovIdleMs
|
|
1236
|
+
) {
|
|
1237
|
+
p.status = NLPGOV_PROFILE_MATURITY_V2.STALE;
|
|
1238
|
+
p.updatedAt = t;
|
|
1239
|
+
flipped.push(p.id);
|
|
1240
|
+
}
|
|
1241
|
+
return { flipped, count: flipped.length };
|
|
1242
|
+
}
|
|
1243
|
+
export function autoFailStuckNlpgovTranslationsV2({ now } = {}) {
|
|
1244
|
+
const t = now ?? Date.now();
|
|
1245
|
+
const flipped = [];
|
|
1246
|
+
for (const j of _nlpgovJsV2.values())
|
|
1247
|
+
if (
|
|
1248
|
+
j.status === NLPGOV_TRANSLATION_LIFECYCLE_V2.TRANSLATING &&
|
|
1249
|
+
j.startedAt != null &&
|
|
1250
|
+
t - j.startedAt >= _nlpgovStuckMs
|
|
1251
|
+
) {
|
|
1252
|
+
j.status = NLPGOV_TRANSLATION_LIFECYCLE_V2.FAILED;
|
|
1253
|
+
j.updatedAt = t;
|
|
1254
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1255
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1256
|
+
flipped.push(j.id);
|
|
1257
|
+
}
|
|
1258
|
+
return { flipped, count: flipped.length };
|
|
1259
|
+
}
|
|
1260
|
+
export function getNlProgrammingGovStatsV2() {
|
|
1261
|
+
const profilesByStatus = {};
|
|
1262
|
+
for (const v of Object.values(NLPGOV_PROFILE_MATURITY_V2))
|
|
1263
|
+
profilesByStatus[v] = 0;
|
|
1264
|
+
for (const p of _nlpgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1265
|
+
const translationsByStatus = {};
|
|
1266
|
+
for (const v of Object.values(NLPGOV_TRANSLATION_LIFECYCLE_V2))
|
|
1267
|
+
translationsByStatus[v] = 0;
|
|
1268
|
+
for (const j of _nlpgovJsV2.values()) translationsByStatus[j.status]++;
|
|
1269
|
+
return {
|
|
1270
|
+
totalNlpgovProfilesV2: _nlpgovPsV2.size,
|
|
1271
|
+
totalNlpgovTranslationsV2: _nlpgovJsV2.size,
|
|
1272
|
+
maxActiveNlpgovProfilesPerOwner: _nlpgovMaxActive,
|
|
1273
|
+
maxPendingNlpgovTranslationsPerProfile: _nlpgovMaxPending,
|
|
1274
|
+
nlpgovProfileIdleMs: _nlpgovIdleMs,
|
|
1275
|
+
nlpgovTranslationStuckMs: _nlpgovStuckMs,
|
|
1276
|
+
profilesByStatus,
|
|
1277
|
+
translationsByStatus,
|
|
1278
|
+
};
|
|
1279
|
+
}
|