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
package/src/lib/audit-logger.js
CHANGED
|
@@ -741,3 +741,324 @@ export function _resetStateV2() {
|
|
|
741
741
|
_archiveRetentionMs = AUDIT_DEFAULT_ARCHIVE_RETENTION_MS;
|
|
742
742
|
_purgeRetentionMs = AUDIT_DEFAULT_PURGE_RETENTION_MS;
|
|
743
743
|
}
|
|
744
|
+
|
|
745
|
+
// =====================================================================
|
|
746
|
+
// audit-logger V2 governance overlay (iter16)
|
|
747
|
+
// =====================================================================
|
|
748
|
+
export const AUD_PROFILE_MATURITY_V2 = Object.freeze({
|
|
749
|
+
PENDING: "pending",
|
|
750
|
+
ACTIVE: "active",
|
|
751
|
+
SUSPENDED: "suspended",
|
|
752
|
+
ARCHIVED: "archived",
|
|
753
|
+
});
|
|
754
|
+
export const AUD_WRITE_LIFECYCLE_V2 = Object.freeze({
|
|
755
|
+
QUEUED: "queued",
|
|
756
|
+
WRITING: "writing",
|
|
757
|
+
WRITTEN: "written",
|
|
758
|
+
FAILED: "failed",
|
|
759
|
+
CANCELLED: "cancelled",
|
|
760
|
+
});
|
|
761
|
+
const _audPTrans = new Map([
|
|
762
|
+
[
|
|
763
|
+
AUD_PROFILE_MATURITY_V2.PENDING,
|
|
764
|
+
new Set([AUD_PROFILE_MATURITY_V2.ACTIVE, AUD_PROFILE_MATURITY_V2.ARCHIVED]),
|
|
765
|
+
],
|
|
766
|
+
[
|
|
767
|
+
AUD_PROFILE_MATURITY_V2.ACTIVE,
|
|
768
|
+
new Set([
|
|
769
|
+
AUD_PROFILE_MATURITY_V2.SUSPENDED,
|
|
770
|
+
AUD_PROFILE_MATURITY_V2.ARCHIVED,
|
|
771
|
+
]),
|
|
772
|
+
],
|
|
773
|
+
[
|
|
774
|
+
AUD_PROFILE_MATURITY_V2.SUSPENDED,
|
|
775
|
+
new Set([AUD_PROFILE_MATURITY_V2.ACTIVE, AUD_PROFILE_MATURITY_V2.ARCHIVED]),
|
|
776
|
+
],
|
|
777
|
+
[AUD_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
778
|
+
]);
|
|
779
|
+
const _audPTerminal = new Set([AUD_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
780
|
+
const _audJTrans = new Map([
|
|
781
|
+
[
|
|
782
|
+
AUD_WRITE_LIFECYCLE_V2.QUEUED,
|
|
783
|
+
new Set([AUD_WRITE_LIFECYCLE_V2.WRITING, AUD_WRITE_LIFECYCLE_V2.CANCELLED]),
|
|
784
|
+
],
|
|
785
|
+
[
|
|
786
|
+
AUD_WRITE_LIFECYCLE_V2.WRITING,
|
|
787
|
+
new Set([
|
|
788
|
+
AUD_WRITE_LIFECYCLE_V2.WRITTEN,
|
|
789
|
+
AUD_WRITE_LIFECYCLE_V2.FAILED,
|
|
790
|
+
AUD_WRITE_LIFECYCLE_V2.CANCELLED,
|
|
791
|
+
]),
|
|
792
|
+
],
|
|
793
|
+
[AUD_WRITE_LIFECYCLE_V2.WRITTEN, new Set()],
|
|
794
|
+
[AUD_WRITE_LIFECYCLE_V2.FAILED, new Set()],
|
|
795
|
+
[AUD_WRITE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
796
|
+
]);
|
|
797
|
+
const _audPsV2 = new Map();
|
|
798
|
+
const _audJsV2 = new Map();
|
|
799
|
+
let _audMaxActive = 8,
|
|
800
|
+
_audMaxPending = 30,
|
|
801
|
+
_audIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
802
|
+
_audStuckMs = 60 * 1000;
|
|
803
|
+
function _audPos(n, label) {
|
|
804
|
+
const v = Math.floor(Number(n));
|
|
805
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
806
|
+
throw new Error(`${label} must be positive integer`);
|
|
807
|
+
return v;
|
|
808
|
+
}
|
|
809
|
+
function _audCheckP(from, to) {
|
|
810
|
+
const a = _audPTrans.get(from);
|
|
811
|
+
if (!a || !a.has(to))
|
|
812
|
+
throw new Error(`invalid aud profile transition ${from} → ${to}`);
|
|
813
|
+
}
|
|
814
|
+
function _audCheckJ(from, to) {
|
|
815
|
+
const a = _audJTrans.get(from);
|
|
816
|
+
if (!a || !a.has(to))
|
|
817
|
+
throw new Error(`invalid aud write transition ${from} → ${to}`);
|
|
818
|
+
}
|
|
819
|
+
function _audCountActive(owner) {
|
|
820
|
+
let c = 0;
|
|
821
|
+
for (const p of _audPsV2.values())
|
|
822
|
+
if (p.owner === owner && p.status === AUD_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
823
|
+
return c;
|
|
824
|
+
}
|
|
825
|
+
function _audCountPending(profileId) {
|
|
826
|
+
let c = 0;
|
|
827
|
+
for (const j of _audJsV2.values())
|
|
828
|
+
if (
|
|
829
|
+
j.profileId === profileId &&
|
|
830
|
+
(j.status === AUD_WRITE_LIFECYCLE_V2.QUEUED ||
|
|
831
|
+
j.status === AUD_WRITE_LIFECYCLE_V2.WRITING)
|
|
832
|
+
)
|
|
833
|
+
c++;
|
|
834
|
+
return c;
|
|
835
|
+
}
|
|
836
|
+
export function setMaxActiveAudProfilesPerOwnerV2(n) {
|
|
837
|
+
_audMaxActive = _audPos(n, "maxActiveAudProfilesPerOwner");
|
|
838
|
+
}
|
|
839
|
+
export function getMaxActiveAudProfilesPerOwnerV2() {
|
|
840
|
+
return _audMaxActive;
|
|
841
|
+
}
|
|
842
|
+
export function setMaxPendingAudWritesPerProfileV2(n) {
|
|
843
|
+
_audMaxPending = _audPos(n, "maxPendingAudWritesPerProfile");
|
|
844
|
+
}
|
|
845
|
+
export function getMaxPendingAudWritesPerProfileV2() {
|
|
846
|
+
return _audMaxPending;
|
|
847
|
+
}
|
|
848
|
+
export function setAudProfileIdleMsV2(n) {
|
|
849
|
+
_audIdleMs = _audPos(n, "audProfileIdleMs");
|
|
850
|
+
}
|
|
851
|
+
export function getAudProfileIdleMsV2() {
|
|
852
|
+
return _audIdleMs;
|
|
853
|
+
}
|
|
854
|
+
export function setAudWriteStuckMsV2(n) {
|
|
855
|
+
_audStuckMs = _audPos(n, "audWriteStuckMs");
|
|
856
|
+
}
|
|
857
|
+
export function getAudWriteStuckMsV2() {
|
|
858
|
+
return _audStuckMs;
|
|
859
|
+
}
|
|
860
|
+
export function _resetStateAuditLoggerV2() {
|
|
861
|
+
_audPsV2.clear();
|
|
862
|
+
_audJsV2.clear();
|
|
863
|
+
_audMaxActive = 8;
|
|
864
|
+
_audMaxPending = 30;
|
|
865
|
+
_audIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
866
|
+
_audStuckMs = 60 * 1000;
|
|
867
|
+
}
|
|
868
|
+
export function registerAudProfileV2({ id, owner, level, metadata } = {}) {
|
|
869
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
870
|
+
if (_audPsV2.has(id)) throw new Error(`aud profile ${id} already exists`);
|
|
871
|
+
const now = Date.now();
|
|
872
|
+
const p = {
|
|
873
|
+
id,
|
|
874
|
+
owner,
|
|
875
|
+
level: level || "info",
|
|
876
|
+
status: AUD_PROFILE_MATURITY_V2.PENDING,
|
|
877
|
+
createdAt: now,
|
|
878
|
+
updatedAt: now,
|
|
879
|
+
lastTouchedAt: now,
|
|
880
|
+
activatedAt: null,
|
|
881
|
+
archivedAt: null,
|
|
882
|
+
metadata: { ...(metadata || {}) },
|
|
883
|
+
};
|
|
884
|
+
_audPsV2.set(id, p);
|
|
885
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
886
|
+
}
|
|
887
|
+
export function activateAudProfileV2(id) {
|
|
888
|
+
const p = _audPsV2.get(id);
|
|
889
|
+
if (!p) throw new Error(`aud profile ${id} not found`);
|
|
890
|
+
const isInitial = p.status === AUD_PROFILE_MATURITY_V2.PENDING;
|
|
891
|
+
_audCheckP(p.status, AUD_PROFILE_MATURITY_V2.ACTIVE);
|
|
892
|
+
if (isInitial && _audCountActive(p.owner) >= _audMaxActive)
|
|
893
|
+
throw new Error(`max active aud profiles for owner ${p.owner} reached`);
|
|
894
|
+
const now = Date.now();
|
|
895
|
+
p.status = AUD_PROFILE_MATURITY_V2.ACTIVE;
|
|
896
|
+
p.updatedAt = now;
|
|
897
|
+
p.lastTouchedAt = now;
|
|
898
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
899
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
900
|
+
}
|
|
901
|
+
export function suspendAudProfileV2(id) {
|
|
902
|
+
const p = _audPsV2.get(id);
|
|
903
|
+
if (!p) throw new Error(`aud profile ${id} not found`);
|
|
904
|
+
_audCheckP(p.status, AUD_PROFILE_MATURITY_V2.SUSPENDED);
|
|
905
|
+
p.status = AUD_PROFILE_MATURITY_V2.SUSPENDED;
|
|
906
|
+
p.updatedAt = Date.now();
|
|
907
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
908
|
+
}
|
|
909
|
+
export function archiveAudProfileV2(id) {
|
|
910
|
+
const p = _audPsV2.get(id);
|
|
911
|
+
if (!p) throw new Error(`aud profile ${id} not found`);
|
|
912
|
+
_audCheckP(p.status, AUD_PROFILE_MATURITY_V2.ARCHIVED);
|
|
913
|
+
const now = Date.now();
|
|
914
|
+
p.status = AUD_PROFILE_MATURITY_V2.ARCHIVED;
|
|
915
|
+
p.updatedAt = now;
|
|
916
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
917
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
918
|
+
}
|
|
919
|
+
export function touchAudProfileV2(id) {
|
|
920
|
+
const p = _audPsV2.get(id);
|
|
921
|
+
if (!p) throw new Error(`aud profile ${id} not found`);
|
|
922
|
+
if (_audPTerminal.has(p.status))
|
|
923
|
+
throw new Error(`cannot touch terminal aud profile ${id}`);
|
|
924
|
+
const now = Date.now();
|
|
925
|
+
p.lastTouchedAt = now;
|
|
926
|
+
p.updatedAt = now;
|
|
927
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
928
|
+
}
|
|
929
|
+
export function getAudProfileV2(id) {
|
|
930
|
+
const p = _audPsV2.get(id);
|
|
931
|
+
if (!p) return null;
|
|
932
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
933
|
+
}
|
|
934
|
+
export function listAudProfilesV2() {
|
|
935
|
+
return [..._audPsV2.values()].map((p) => ({
|
|
936
|
+
...p,
|
|
937
|
+
metadata: { ...p.metadata },
|
|
938
|
+
}));
|
|
939
|
+
}
|
|
940
|
+
export function createAudWriteV2({ id, profileId, key, metadata } = {}) {
|
|
941
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
942
|
+
if (_audJsV2.has(id)) throw new Error(`aud write ${id} already exists`);
|
|
943
|
+
if (!_audPsV2.has(profileId))
|
|
944
|
+
throw new Error(`aud profile ${profileId} not found`);
|
|
945
|
+
if (_audCountPending(profileId) >= _audMaxPending)
|
|
946
|
+
throw new Error(`max pending aud writes for profile ${profileId} reached`);
|
|
947
|
+
const now = Date.now();
|
|
948
|
+
const j = {
|
|
949
|
+
id,
|
|
950
|
+
profileId,
|
|
951
|
+
key: key || "",
|
|
952
|
+
status: AUD_WRITE_LIFECYCLE_V2.QUEUED,
|
|
953
|
+
createdAt: now,
|
|
954
|
+
updatedAt: now,
|
|
955
|
+
startedAt: null,
|
|
956
|
+
settledAt: null,
|
|
957
|
+
metadata: { ...(metadata || {}) },
|
|
958
|
+
};
|
|
959
|
+
_audJsV2.set(id, j);
|
|
960
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
961
|
+
}
|
|
962
|
+
export function writingAudWriteV2(id) {
|
|
963
|
+
const j = _audJsV2.get(id);
|
|
964
|
+
if (!j) throw new Error(`aud write ${id} not found`);
|
|
965
|
+
_audCheckJ(j.status, AUD_WRITE_LIFECYCLE_V2.WRITING);
|
|
966
|
+
const now = Date.now();
|
|
967
|
+
j.status = AUD_WRITE_LIFECYCLE_V2.WRITING;
|
|
968
|
+
j.updatedAt = now;
|
|
969
|
+
if (!j.startedAt) j.startedAt = now;
|
|
970
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
971
|
+
}
|
|
972
|
+
export function writeOkAudV2(id) {
|
|
973
|
+
const j = _audJsV2.get(id);
|
|
974
|
+
if (!j) throw new Error(`aud write ${id} not found`);
|
|
975
|
+
_audCheckJ(j.status, AUD_WRITE_LIFECYCLE_V2.WRITTEN);
|
|
976
|
+
const now = Date.now();
|
|
977
|
+
j.status = AUD_WRITE_LIFECYCLE_V2.WRITTEN;
|
|
978
|
+
j.updatedAt = now;
|
|
979
|
+
if (!j.settledAt) j.settledAt = now;
|
|
980
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
981
|
+
}
|
|
982
|
+
export function failAudWriteV2(id, reason) {
|
|
983
|
+
const j = _audJsV2.get(id);
|
|
984
|
+
if (!j) throw new Error(`aud write ${id} not found`);
|
|
985
|
+
_audCheckJ(j.status, AUD_WRITE_LIFECYCLE_V2.FAILED);
|
|
986
|
+
const now = Date.now();
|
|
987
|
+
j.status = AUD_WRITE_LIFECYCLE_V2.FAILED;
|
|
988
|
+
j.updatedAt = now;
|
|
989
|
+
if (!j.settledAt) j.settledAt = now;
|
|
990
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
991
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
992
|
+
}
|
|
993
|
+
export function cancelAudWriteV2(id, reason) {
|
|
994
|
+
const j = _audJsV2.get(id);
|
|
995
|
+
if (!j) throw new Error(`aud write ${id} not found`);
|
|
996
|
+
_audCheckJ(j.status, AUD_WRITE_LIFECYCLE_V2.CANCELLED);
|
|
997
|
+
const now = Date.now();
|
|
998
|
+
j.status = AUD_WRITE_LIFECYCLE_V2.CANCELLED;
|
|
999
|
+
j.updatedAt = now;
|
|
1000
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1001
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1002
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1003
|
+
}
|
|
1004
|
+
export function getAudWriteV2(id) {
|
|
1005
|
+
const j = _audJsV2.get(id);
|
|
1006
|
+
if (!j) return null;
|
|
1007
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1008
|
+
}
|
|
1009
|
+
export function listAudWritesV2() {
|
|
1010
|
+
return [..._audJsV2.values()].map((j) => ({
|
|
1011
|
+
...j,
|
|
1012
|
+
metadata: { ...j.metadata },
|
|
1013
|
+
}));
|
|
1014
|
+
}
|
|
1015
|
+
export function autoSuspendIdleAudProfilesV2({ now } = {}) {
|
|
1016
|
+
const t = now ?? Date.now();
|
|
1017
|
+
const flipped = [];
|
|
1018
|
+
for (const p of _audPsV2.values())
|
|
1019
|
+
if (
|
|
1020
|
+
p.status === AUD_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1021
|
+
t - p.lastTouchedAt >= _audIdleMs
|
|
1022
|
+
) {
|
|
1023
|
+
p.status = AUD_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1024
|
+
p.updatedAt = t;
|
|
1025
|
+
flipped.push(p.id);
|
|
1026
|
+
}
|
|
1027
|
+
return { flipped, count: flipped.length };
|
|
1028
|
+
}
|
|
1029
|
+
export function autoFailStuckAudWritesV2({ now } = {}) {
|
|
1030
|
+
const t = now ?? Date.now();
|
|
1031
|
+
const flipped = [];
|
|
1032
|
+
for (const j of _audJsV2.values())
|
|
1033
|
+
if (
|
|
1034
|
+
j.status === AUD_WRITE_LIFECYCLE_V2.WRITING &&
|
|
1035
|
+
j.startedAt != null &&
|
|
1036
|
+
t - j.startedAt >= _audStuckMs
|
|
1037
|
+
) {
|
|
1038
|
+
j.status = AUD_WRITE_LIFECYCLE_V2.FAILED;
|
|
1039
|
+
j.updatedAt = t;
|
|
1040
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1041
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1042
|
+
flipped.push(j.id);
|
|
1043
|
+
}
|
|
1044
|
+
return { flipped, count: flipped.length };
|
|
1045
|
+
}
|
|
1046
|
+
export function getAuditLoggerGovStatsV2() {
|
|
1047
|
+
const profilesByStatus = {};
|
|
1048
|
+
for (const v of Object.values(AUD_PROFILE_MATURITY_V2))
|
|
1049
|
+
profilesByStatus[v] = 0;
|
|
1050
|
+
for (const p of _audPsV2.values()) profilesByStatus[p.status]++;
|
|
1051
|
+
const writesByStatus = {};
|
|
1052
|
+
for (const v of Object.values(AUD_WRITE_LIFECYCLE_V2)) writesByStatus[v] = 0;
|
|
1053
|
+
for (const j of _audJsV2.values()) writesByStatus[j.status]++;
|
|
1054
|
+
return {
|
|
1055
|
+
totalAudProfilesV2: _audPsV2.size,
|
|
1056
|
+
totalAudWritesV2: _audJsV2.size,
|
|
1057
|
+
maxActiveAudProfilesPerOwner: _audMaxActive,
|
|
1058
|
+
maxPendingAudWritesPerProfile: _audMaxPending,
|
|
1059
|
+
audProfileIdleMs: _audIdleMs,
|
|
1060
|
+
audWriteStuckMs: _audStuckMs,
|
|
1061
|
+
profilesByStatus,
|
|
1062
|
+
writesByStatus,
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
@@ -1276,3 +1276,338 @@ export function _resetStateAutomationEngineV2() {
|
|
|
1276
1276
|
_automationIdleMsV2 = AUTOMATION_DEFAULT_AUTOMATION_IDLE_MS;
|
|
1277
1277
|
_executionStuckMsV2 = AUTOMATION_DEFAULT_EXECUTION_STUCK_MS;
|
|
1278
1278
|
}
|
|
1279
|
+
|
|
1280
|
+
// =====================================================================
|
|
1281
|
+
// automation-engine V2 governance overlay (iter22)
|
|
1282
|
+
// =====================================================================
|
|
1283
|
+
export const AUGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
1284
|
+
PENDING: "pending",
|
|
1285
|
+
ACTIVE: "active",
|
|
1286
|
+
PAUSED: "paused",
|
|
1287
|
+
ARCHIVED: "archived",
|
|
1288
|
+
});
|
|
1289
|
+
export const AUGOV_FLOW_LIFECYCLE_V2 = Object.freeze({
|
|
1290
|
+
QUEUED: "queued",
|
|
1291
|
+
RUNNING: "running",
|
|
1292
|
+
COMPLETED: "completed",
|
|
1293
|
+
FAILED: "failed",
|
|
1294
|
+
CANCELLED: "cancelled",
|
|
1295
|
+
});
|
|
1296
|
+
const _augovPTrans = new Map([
|
|
1297
|
+
[
|
|
1298
|
+
AUGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1299
|
+
new Set([
|
|
1300
|
+
AUGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1301
|
+
AUGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1302
|
+
]),
|
|
1303
|
+
],
|
|
1304
|
+
[
|
|
1305
|
+
AUGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1306
|
+
new Set([
|
|
1307
|
+
AUGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
1308
|
+
AUGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1309
|
+
]),
|
|
1310
|
+
],
|
|
1311
|
+
[
|
|
1312
|
+
AUGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
1313
|
+
new Set([
|
|
1314
|
+
AUGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1315
|
+
AUGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1316
|
+
]),
|
|
1317
|
+
],
|
|
1318
|
+
[AUGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1319
|
+
]);
|
|
1320
|
+
const _augovPTerminal = new Set([AUGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1321
|
+
const _augovJTrans = new Map([
|
|
1322
|
+
[
|
|
1323
|
+
AUGOV_FLOW_LIFECYCLE_V2.QUEUED,
|
|
1324
|
+
new Set([
|
|
1325
|
+
AUGOV_FLOW_LIFECYCLE_V2.RUNNING,
|
|
1326
|
+
AUGOV_FLOW_LIFECYCLE_V2.CANCELLED,
|
|
1327
|
+
]),
|
|
1328
|
+
],
|
|
1329
|
+
[
|
|
1330
|
+
AUGOV_FLOW_LIFECYCLE_V2.RUNNING,
|
|
1331
|
+
new Set([
|
|
1332
|
+
AUGOV_FLOW_LIFECYCLE_V2.COMPLETED,
|
|
1333
|
+
AUGOV_FLOW_LIFECYCLE_V2.FAILED,
|
|
1334
|
+
AUGOV_FLOW_LIFECYCLE_V2.CANCELLED,
|
|
1335
|
+
]),
|
|
1336
|
+
],
|
|
1337
|
+
[AUGOV_FLOW_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
1338
|
+
[AUGOV_FLOW_LIFECYCLE_V2.FAILED, new Set()],
|
|
1339
|
+
[AUGOV_FLOW_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1340
|
+
]);
|
|
1341
|
+
const _augovPsV2 = new Map();
|
|
1342
|
+
const _augovJsV2 = new Map();
|
|
1343
|
+
let _augovMaxActive = 10,
|
|
1344
|
+
_augovMaxPending = 25,
|
|
1345
|
+
_augovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1346
|
+
_augovStuckMs = 60 * 1000;
|
|
1347
|
+
function _augovPos(n, label) {
|
|
1348
|
+
const v = Math.floor(Number(n));
|
|
1349
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1350
|
+
throw new Error(`${label} must be positive integer`);
|
|
1351
|
+
return v;
|
|
1352
|
+
}
|
|
1353
|
+
function _augovCheckP(from, to) {
|
|
1354
|
+
const a = _augovPTrans.get(from);
|
|
1355
|
+
if (!a || !a.has(to))
|
|
1356
|
+
throw new Error(`invalid augov profile transition ${from} → ${to}`);
|
|
1357
|
+
}
|
|
1358
|
+
function _augovCheckJ(from, to) {
|
|
1359
|
+
const a = _augovJTrans.get(from);
|
|
1360
|
+
if (!a || !a.has(to))
|
|
1361
|
+
throw new Error(`invalid augov flow transition ${from} → ${to}`);
|
|
1362
|
+
}
|
|
1363
|
+
function _augovCountActive(owner) {
|
|
1364
|
+
let c = 0;
|
|
1365
|
+
for (const p of _augovPsV2.values())
|
|
1366
|
+
if (p.owner === owner && p.status === AUGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
1367
|
+
return c;
|
|
1368
|
+
}
|
|
1369
|
+
function _augovCountPending(profileId) {
|
|
1370
|
+
let c = 0;
|
|
1371
|
+
for (const j of _augovJsV2.values())
|
|
1372
|
+
if (
|
|
1373
|
+
j.profileId === profileId &&
|
|
1374
|
+
(j.status === AUGOV_FLOW_LIFECYCLE_V2.QUEUED ||
|
|
1375
|
+
j.status === AUGOV_FLOW_LIFECYCLE_V2.RUNNING)
|
|
1376
|
+
)
|
|
1377
|
+
c++;
|
|
1378
|
+
return c;
|
|
1379
|
+
}
|
|
1380
|
+
export function setMaxActiveAugovProfilesPerOwnerV2(n) {
|
|
1381
|
+
_augovMaxActive = _augovPos(n, "maxActiveAugovProfilesPerOwner");
|
|
1382
|
+
}
|
|
1383
|
+
export function getMaxActiveAugovProfilesPerOwnerV2() {
|
|
1384
|
+
return _augovMaxActive;
|
|
1385
|
+
}
|
|
1386
|
+
export function setMaxPendingAugovFlowsPerProfileV2(n) {
|
|
1387
|
+
_augovMaxPending = _augovPos(n, "maxPendingAugovFlowsPerProfile");
|
|
1388
|
+
}
|
|
1389
|
+
export function getMaxPendingAugovFlowsPerProfileV2() {
|
|
1390
|
+
return _augovMaxPending;
|
|
1391
|
+
}
|
|
1392
|
+
export function setAugovProfileIdleMsV2(n) {
|
|
1393
|
+
_augovIdleMs = _augovPos(n, "augovProfileIdleMs");
|
|
1394
|
+
}
|
|
1395
|
+
export function getAugovProfileIdleMsV2() {
|
|
1396
|
+
return _augovIdleMs;
|
|
1397
|
+
}
|
|
1398
|
+
export function setAugovFlowStuckMsV2(n) {
|
|
1399
|
+
_augovStuckMs = _augovPos(n, "augovFlowStuckMs");
|
|
1400
|
+
}
|
|
1401
|
+
export function getAugovFlowStuckMsV2() {
|
|
1402
|
+
return _augovStuckMs;
|
|
1403
|
+
}
|
|
1404
|
+
export function _resetStateAutomationEngineGovV2() {
|
|
1405
|
+
_augovPsV2.clear();
|
|
1406
|
+
_augovJsV2.clear();
|
|
1407
|
+
_augovMaxActive = 10;
|
|
1408
|
+
_augovMaxPending = 25;
|
|
1409
|
+
_augovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1410
|
+
_augovStuckMs = 60 * 1000;
|
|
1411
|
+
}
|
|
1412
|
+
export function registerAugovProfileV2({
|
|
1413
|
+
id,
|
|
1414
|
+
owner,
|
|
1415
|
+
connector,
|
|
1416
|
+
metadata,
|
|
1417
|
+
} = {}) {
|
|
1418
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1419
|
+
if (_augovPsV2.has(id)) throw new Error(`augov profile ${id} already exists`);
|
|
1420
|
+
const now = Date.now();
|
|
1421
|
+
const p = {
|
|
1422
|
+
id,
|
|
1423
|
+
owner,
|
|
1424
|
+
connector: connector || "webhook",
|
|
1425
|
+
status: AUGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1426
|
+
createdAt: now,
|
|
1427
|
+
updatedAt: now,
|
|
1428
|
+
lastTouchedAt: now,
|
|
1429
|
+
activatedAt: null,
|
|
1430
|
+
archivedAt: null,
|
|
1431
|
+
metadata: { ...(metadata || {}) },
|
|
1432
|
+
};
|
|
1433
|
+
_augovPsV2.set(id, p);
|
|
1434
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1435
|
+
}
|
|
1436
|
+
export function activateAugovProfileV2(id) {
|
|
1437
|
+
const p = _augovPsV2.get(id);
|
|
1438
|
+
if (!p) throw new Error(`augov profile ${id} not found`);
|
|
1439
|
+
const isInitial = p.status === AUGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1440
|
+
_augovCheckP(p.status, AUGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1441
|
+
if (isInitial && _augovCountActive(p.owner) >= _augovMaxActive)
|
|
1442
|
+
throw new Error(`max active augov profiles for owner ${p.owner} reached`);
|
|
1443
|
+
const now = Date.now();
|
|
1444
|
+
p.status = AUGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1445
|
+
p.updatedAt = now;
|
|
1446
|
+
p.lastTouchedAt = now;
|
|
1447
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1448
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1449
|
+
}
|
|
1450
|
+
export function pauseAugovProfileV2(id) {
|
|
1451
|
+
const p = _augovPsV2.get(id);
|
|
1452
|
+
if (!p) throw new Error(`augov profile ${id} not found`);
|
|
1453
|
+
_augovCheckP(p.status, AUGOV_PROFILE_MATURITY_V2.PAUSED);
|
|
1454
|
+
p.status = AUGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
1455
|
+
p.updatedAt = Date.now();
|
|
1456
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1457
|
+
}
|
|
1458
|
+
export function archiveAugovProfileV2(id) {
|
|
1459
|
+
const p = _augovPsV2.get(id);
|
|
1460
|
+
if (!p) throw new Error(`augov profile ${id} not found`);
|
|
1461
|
+
_augovCheckP(p.status, AUGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1462
|
+
const now = Date.now();
|
|
1463
|
+
p.status = AUGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1464
|
+
p.updatedAt = now;
|
|
1465
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1466
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1467
|
+
}
|
|
1468
|
+
export function touchAugovProfileV2(id) {
|
|
1469
|
+
const p = _augovPsV2.get(id);
|
|
1470
|
+
if (!p) throw new Error(`augov profile ${id} not found`);
|
|
1471
|
+
if (_augovPTerminal.has(p.status))
|
|
1472
|
+
throw new Error(`cannot touch terminal augov profile ${id}`);
|
|
1473
|
+
const now = Date.now();
|
|
1474
|
+
p.lastTouchedAt = now;
|
|
1475
|
+
p.updatedAt = now;
|
|
1476
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1477
|
+
}
|
|
1478
|
+
export function getAugovProfileV2(id) {
|
|
1479
|
+
const p = _augovPsV2.get(id);
|
|
1480
|
+
if (!p) return null;
|
|
1481
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1482
|
+
}
|
|
1483
|
+
export function listAugovProfilesV2() {
|
|
1484
|
+
return [..._augovPsV2.values()].map((p) => ({
|
|
1485
|
+
...p,
|
|
1486
|
+
metadata: { ...p.metadata },
|
|
1487
|
+
}));
|
|
1488
|
+
}
|
|
1489
|
+
export function createAugovFlowV2({ id, profileId, trigger, metadata } = {}) {
|
|
1490
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1491
|
+
if (_augovJsV2.has(id)) throw new Error(`augov flow ${id} already exists`);
|
|
1492
|
+
if (!_augovPsV2.has(profileId))
|
|
1493
|
+
throw new Error(`augov profile ${profileId} not found`);
|
|
1494
|
+
if (_augovCountPending(profileId) >= _augovMaxPending)
|
|
1495
|
+
throw new Error(`max pending augov flows for profile ${profileId} reached`);
|
|
1496
|
+
const now = Date.now();
|
|
1497
|
+
const j = {
|
|
1498
|
+
id,
|
|
1499
|
+
profileId,
|
|
1500
|
+
trigger: trigger || "",
|
|
1501
|
+
status: AUGOV_FLOW_LIFECYCLE_V2.QUEUED,
|
|
1502
|
+
createdAt: now,
|
|
1503
|
+
updatedAt: now,
|
|
1504
|
+
startedAt: null,
|
|
1505
|
+
settledAt: null,
|
|
1506
|
+
metadata: { ...(metadata || {}) },
|
|
1507
|
+
};
|
|
1508
|
+
_augovJsV2.set(id, j);
|
|
1509
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1510
|
+
}
|
|
1511
|
+
export function runningAugovFlowV2(id) {
|
|
1512
|
+
const j = _augovJsV2.get(id);
|
|
1513
|
+
if (!j) throw new Error(`augov flow ${id} not found`);
|
|
1514
|
+
_augovCheckJ(j.status, AUGOV_FLOW_LIFECYCLE_V2.RUNNING);
|
|
1515
|
+
const now = Date.now();
|
|
1516
|
+
j.status = AUGOV_FLOW_LIFECYCLE_V2.RUNNING;
|
|
1517
|
+
j.updatedAt = now;
|
|
1518
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1519
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1520
|
+
}
|
|
1521
|
+
export function completeFlowAugovV2(id) {
|
|
1522
|
+
const j = _augovJsV2.get(id);
|
|
1523
|
+
if (!j) throw new Error(`augov flow ${id} not found`);
|
|
1524
|
+
_augovCheckJ(j.status, AUGOV_FLOW_LIFECYCLE_V2.COMPLETED);
|
|
1525
|
+
const now = Date.now();
|
|
1526
|
+
j.status = AUGOV_FLOW_LIFECYCLE_V2.COMPLETED;
|
|
1527
|
+
j.updatedAt = now;
|
|
1528
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1529
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1530
|
+
}
|
|
1531
|
+
export function failAugovFlowV2(id, reason) {
|
|
1532
|
+
const j = _augovJsV2.get(id);
|
|
1533
|
+
if (!j) throw new Error(`augov flow ${id} not found`);
|
|
1534
|
+
_augovCheckJ(j.status, AUGOV_FLOW_LIFECYCLE_V2.FAILED);
|
|
1535
|
+
const now = Date.now();
|
|
1536
|
+
j.status = AUGOV_FLOW_LIFECYCLE_V2.FAILED;
|
|
1537
|
+
j.updatedAt = now;
|
|
1538
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1539
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1540
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1541
|
+
}
|
|
1542
|
+
export function cancelAugovFlowV2(id, reason) {
|
|
1543
|
+
const j = _augovJsV2.get(id);
|
|
1544
|
+
if (!j) throw new Error(`augov flow ${id} not found`);
|
|
1545
|
+
_augovCheckJ(j.status, AUGOV_FLOW_LIFECYCLE_V2.CANCELLED);
|
|
1546
|
+
const now = Date.now();
|
|
1547
|
+
j.status = AUGOV_FLOW_LIFECYCLE_V2.CANCELLED;
|
|
1548
|
+
j.updatedAt = now;
|
|
1549
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1550
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1551
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1552
|
+
}
|
|
1553
|
+
export function getAugovFlowV2(id) {
|
|
1554
|
+
const j = _augovJsV2.get(id);
|
|
1555
|
+
if (!j) return null;
|
|
1556
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1557
|
+
}
|
|
1558
|
+
export function listAugovFlowsV2() {
|
|
1559
|
+
return [..._augovJsV2.values()].map((j) => ({
|
|
1560
|
+
...j,
|
|
1561
|
+
metadata: { ...j.metadata },
|
|
1562
|
+
}));
|
|
1563
|
+
}
|
|
1564
|
+
export function autoPauseIdleAugovProfilesV2({ now } = {}) {
|
|
1565
|
+
const t = now ?? Date.now();
|
|
1566
|
+
const flipped = [];
|
|
1567
|
+
for (const p of _augovPsV2.values())
|
|
1568
|
+
if (
|
|
1569
|
+
p.status === AUGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1570
|
+
t - p.lastTouchedAt >= _augovIdleMs
|
|
1571
|
+
) {
|
|
1572
|
+
p.status = AUGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
1573
|
+
p.updatedAt = t;
|
|
1574
|
+
flipped.push(p.id);
|
|
1575
|
+
}
|
|
1576
|
+
return { flipped, count: flipped.length };
|
|
1577
|
+
}
|
|
1578
|
+
export function autoFailStuckAugovFlowsV2({ now } = {}) {
|
|
1579
|
+
const t = now ?? Date.now();
|
|
1580
|
+
const flipped = [];
|
|
1581
|
+
for (const j of _augovJsV2.values())
|
|
1582
|
+
if (
|
|
1583
|
+
j.status === AUGOV_FLOW_LIFECYCLE_V2.RUNNING &&
|
|
1584
|
+
j.startedAt != null &&
|
|
1585
|
+
t - j.startedAt >= _augovStuckMs
|
|
1586
|
+
) {
|
|
1587
|
+
j.status = AUGOV_FLOW_LIFECYCLE_V2.FAILED;
|
|
1588
|
+
j.updatedAt = t;
|
|
1589
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1590
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1591
|
+
flipped.push(j.id);
|
|
1592
|
+
}
|
|
1593
|
+
return { flipped, count: flipped.length };
|
|
1594
|
+
}
|
|
1595
|
+
export function getAutomationEngineGovStatsV2() {
|
|
1596
|
+
const profilesByStatus = {};
|
|
1597
|
+
for (const v of Object.values(AUGOV_PROFILE_MATURITY_V2))
|
|
1598
|
+
profilesByStatus[v] = 0;
|
|
1599
|
+
for (const p of _augovPsV2.values()) profilesByStatus[p.status]++;
|
|
1600
|
+
const flowsByStatus = {};
|
|
1601
|
+
for (const v of Object.values(AUGOV_FLOW_LIFECYCLE_V2)) flowsByStatus[v] = 0;
|
|
1602
|
+
for (const j of _augovJsV2.values()) flowsByStatus[j.status]++;
|
|
1603
|
+
return {
|
|
1604
|
+
totalAugovProfilesV2: _augovPsV2.size,
|
|
1605
|
+
totalAugovFlowsV2: _augovJsV2.size,
|
|
1606
|
+
maxActiveAugovProfilesPerOwner: _augovMaxActive,
|
|
1607
|
+
maxPendingAugovFlowsPerProfile: _augovMaxPending,
|
|
1608
|
+
augovProfileIdleMs: _augovIdleMs,
|
|
1609
|
+
augovFlowStuckMs: _augovStuckMs,
|
|
1610
|
+
profilesByStatus,
|
|
1611
|
+
flowsByStatus,
|
|
1612
|
+
};
|
|
1613
|
+
}
|