chainlesschain 0.145.0 → 0.156.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/README.md +52 -3
- package/package.json +1 -1
- package/src/commands/a2a.js +201 -0
- package/src/commands/activitypub.js +207 -0
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +1250 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +203 -0
- package/src/commands/browse.js +213 -0
- package/src/commands/chat.js +605 -0
- package/src/commands/cli-anything.js +426 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +822 -0
- package/src/commands/config.js +213 -0
- package/src/commands/cowork.js +1666 -0
- package/src/commands/crosschain.js +203 -0
- package/src/commands/dao.js +203 -0
- 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 +213 -0
- package/src/commands/economy.js +199 -0
- package/src/commands/encrypt.js +201 -0
- package/src/commands/evolution.js +199 -0
- package/src/commands/evomap.js +830 -0
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fusion.js +205 -0
- package/src/commands/governance.js +209 -0
- package/src/commands/hmemory.js +203 -0
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/inference.js +207 -0
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/kg.js +195 -0
- package/src/commands/llm.js +426 -0
- package/src/commands/matrix.js +207 -0
- package/src/commands/mcp.js +217 -0
- package/src/commands/memory.js +412 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +209 -0
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +406 -0
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/perception.js +209 -0
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +199 -0
- package/src/commands/planmode.js +426 -0
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/plugin.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +233 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/services.js +207 -0
- package/src/commands/session.js +209 -0
- package/src/commands/setup.js +205 -0
- package/src/commands/skill.js +414 -0
- package/src/commands/social.js +201 -0
- package/src/commands/sso.js +209 -0
- package/src/commands/start.js +209 -0
- package/src/commands/stream.js +213 -0
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/tokens.js +209 -0
- package/src/commands/trust.js +217 -0
- package/src/commands/ui.js +225 -0
- package/src/commands/wallet.js +209 -0
- package/src/commands/workflow.js +412 -0
- package/src/index.js +252 -0
- package/src/lib/a2a-protocol.js +332 -0
- package/src/lib/activitypub-bridge.js +334 -0
- package/src/lib/agent-coordinator.js +334 -0
- package/src/lib/agent-economy.js +334 -0
- package/src/lib/agent-network.js +341 -0
- package/src/lib/agent-router.js +333 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +332 -0
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +333 -0
- package/src/lib/browser-automation.js +334 -0
- package/src/lib/chat-core.js +335 -0
- package/src/lib/cli-anything-bridge.js +341 -0
- package/src/lib/cli-context-engineering.js +351 -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-manager.js +334 -0
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/cowork-adapter.js +336 -0
- package/src/lib/cowork-evomap-adapter.js +341 -0
- package/src/lib/cowork-mcp-tools.js +341 -0
- package/src/lib/cowork-observe-html.js +341 -0
- package/src/lib/cowork-observe.js +341 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-templates.js +342 -1
- package/src/lib/cowork-template-marketplace.js +340 -0
- package/src/lib/cross-chain.js +339 -0
- package/src/lib/crypto-manager.js +334 -0
- package/src/lib/dao-governance.js +339 -0
- 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 +339 -0
- package/src/lib/downloader.js +334 -0
- package/src/lib/evolution-system.js +334 -0
- package/src/lib/evomap-client.js +342 -0
- package/src/lib/evomap-federation.js +338 -0
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +330 -0
- package/src/lib/execution-backend.js +330 -0
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/hashline.js +338 -0
- package/src/lib/hierarchical-memory.js +334 -0
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +341 -0
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/interaction-adapter.js +330 -0
- package/src/lib/interactive-planner.js +354 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +331 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-registry.js +346 -0
- 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 +336 -0
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/pipeline-orchestrator.js +332 -0
- package/src/lib/plan-mode.js +336 -0
- package/src/lib/plugin-autodiscovery.js +334 -0
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/process-manager.js +336 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/provider-options.js +346 -0
- package/src/lib/provider-stream.js +348 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-manager.js +337 -0
- package/src/lib/session-core-singletons.js +341 -0
- package/src/lib/session-manager.js +334 -0
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-mcp.js +336 -0
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stix-parser.js +346 -0
- package/src/lib/sub-agent-context.js +343 -0
- package/src/lib/sub-agent-profiles.js +335 -0
- package/src/lib/sub-agent-registry.js +336 -0
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +336 -0
- package/src/lib/token-tracker.js +336 -0
- 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/wallet-manager.js +336 -0
- package/src/lib/web-ui-server.js +348 -0
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/workflow-expr.js +346 -0
- package/src/lib/ws-chat-handler.js +337 -0
|
@@ -950,3 +950,341 @@ export function _resetStateV2() {
|
|
|
950
950
|
_pfBridgeIdleMs = PF_DEFAULT_BRIDGE_IDLE_MS;
|
|
951
951
|
_pfTranslationStuckMs = PF_DEFAULT_TRANSLATION_STUCK_MS;
|
|
952
952
|
}
|
|
953
|
+
|
|
954
|
+
// =====================================================================
|
|
955
|
+
// protocol-fusion V2 governance overlay (iter23)
|
|
956
|
+
// =====================================================================
|
|
957
|
+
export const PFGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
958
|
+
PENDING: "pending",
|
|
959
|
+
ACTIVE: "active",
|
|
960
|
+
DEGRADED: "degraded",
|
|
961
|
+
ARCHIVED: "archived",
|
|
962
|
+
});
|
|
963
|
+
export const PFGOV_ROUTE_LIFECYCLE_V2 = Object.freeze({
|
|
964
|
+
QUEUED: "queued",
|
|
965
|
+
ROUTING: "routing",
|
|
966
|
+
ROUTED: "routed",
|
|
967
|
+
FAILED: "failed",
|
|
968
|
+
CANCELLED: "cancelled",
|
|
969
|
+
});
|
|
970
|
+
const _pfgovPTrans = new Map([
|
|
971
|
+
[
|
|
972
|
+
PFGOV_PROFILE_MATURITY_V2.PENDING,
|
|
973
|
+
new Set([
|
|
974
|
+
PFGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
975
|
+
PFGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
976
|
+
]),
|
|
977
|
+
],
|
|
978
|
+
[
|
|
979
|
+
PFGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
980
|
+
new Set([
|
|
981
|
+
PFGOV_PROFILE_MATURITY_V2.DEGRADED,
|
|
982
|
+
PFGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
983
|
+
]),
|
|
984
|
+
],
|
|
985
|
+
[
|
|
986
|
+
PFGOV_PROFILE_MATURITY_V2.DEGRADED,
|
|
987
|
+
new Set([
|
|
988
|
+
PFGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
989
|
+
PFGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
990
|
+
]),
|
|
991
|
+
],
|
|
992
|
+
[PFGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
993
|
+
]);
|
|
994
|
+
const _pfgovPTerminal = new Set([PFGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
995
|
+
const _pfgovJTrans = new Map([
|
|
996
|
+
[
|
|
997
|
+
PFGOV_ROUTE_LIFECYCLE_V2.QUEUED,
|
|
998
|
+
new Set([
|
|
999
|
+
PFGOV_ROUTE_LIFECYCLE_V2.ROUTING,
|
|
1000
|
+
PFGOV_ROUTE_LIFECYCLE_V2.CANCELLED,
|
|
1001
|
+
]),
|
|
1002
|
+
],
|
|
1003
|
+
[
|
|
1004
|
+
PFGOV_ROUTE_LIFECYCLE_V2.ROUTING,
|
|
1005
|
+
new Set([
|
|
1006
|
+
PFGOV_ROUTE_LIFECYCLE_V2.ROUTED,
|
|
1007
|
+
PFGOV_ROUTE_LIFECYCLE_V2.FAILED,
|
|
1008
|
+
PFGOV_ROUTE_LIFECYCLE_V2.CANCELLED,
|
|
1009
|
+
]),
|
|
1010
|
+
],
|
|
1011
|
+
[PFGOV_ROUTE_LIFECYCLE_V2.ROUTED, new Set()],
|
|
1012
|
+
[PFGOV_ROUTE_LIFECYCLE_V2.FAILED, new Set()],
|
|
1013
|
+
[PFGOV_ROUTE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1014
|
+
]);
|
|
1015
|
+
const _pfgovPsV2 = new Map();
|
|
1016
|
+
const _pfgovJsV2 = new Map();
|
|
1017
|
+
let _pfgovMaxActive = 6,
|
|
1018
|
+
_pfgovMaxPending = 15,
|
|
1019
|
+
_pfgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1020
|
+
_pfgovStuckMs = 60 * 1000;
|
|
1021
|
+
function _pfgovPos(n, label) {
|
|
1022
|
+
const v = Math.floor(Number(n));
|
|
1023
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1024
|
+
throw new Error(`${label} must be positive integer`);
|
|
1025
|
+
return v;
|
|
1026
|
+
}
|
|
1027
|
+
function _pfgovCheckP(from, to) {
|
|
1028
|
+
const a = _pfgovPTrans.get(from);
|
|
1029
|
+
if (!a || !a.has(to))
|
|
1030
|
+
throw new Error(`invalid pfgov profile transition ${from} → ${to}`);
|
|
1031
|
+
}
|
|
1032
|
+
function _pfgovCheckJ(from, to) {
|
|
1033
|
+
const a = _pfgovJTrans.get(from);
|
|
1034
|
+
if (!a || !a.has(to))
|
|
1035
|
+
throw new Error(`invalid pfgov route transition ${from} → ${to}`);
|
|
1036
|
+
}
|
|
1037
|
+
function _pfgovCountActive(owner) {
|
|
1038
|
+
let c = 0;
|
|
1039
|
+
for (const p of _pfgovPsV2.values())
|
|
1040
|
+
if (p.owner === owner && p.status === PFGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
1041
|
+
return c;
|
|
1042
|
+
}
|
|
1043
|
+
function _pfgovCountPending(profileId) {
|
|
1044
|
+
let c = 0;
|
|
1045
|
+
for (const j of _pfgovJsV2.values())
|
|
1046
|
+
if (
|
|
1047
|
+
j.profileId === profileId &&
|
|
1048
|
+
(j.status === PFGOV_ROUTE_LIFECYCLE_V2.QUEUED ||
|
|
1049
|
+
j.status === PFGOV_ROUTE_LIFECYCLE_V2.ROUTING)
|
|
1050
|
+
)
|
|
1051
|
+
c++;
|
|
1052
|
+
return c;
|
|
1053
|
+
}
|
|
1054
|
+
export function setMaxActivePfgovProfilesPerOwnerV2(n) {
|
|
1055
|
+
_pfgovMaxActive = _pfgovPos(n, "maxActivePfgovProfilesPerOwner");
|
|
1056
|
+
}
|
|
1057
|
+
export function getMaxActivePfgovProfilesPerOwnerV2() {
|
|
1058
|
+
return _pfgovMaxActive;
|
|
1059
|
+
}
|
|
1060
|
+
export function setMaxPendingPfgovRoutesPerProfileV2(n) {
|
|
1061
|
+
_pfgovMaxPending = _pfgovPos(n, "maxPendingPfgovRoutesPerProfile");
|
|
1062
|
+
}
|
|
1063
|
+
export function getMaxPendingPfgovRoutesPerProfileV2() {
|
|
1064
|
+
return _pfgovMaxPending;
|
|
1065
|
+
}
|
|
1066
|
+
export function setPfgovProfileIdleMsV2(n) {
|
|
1067
|
+
_pfgovIdleMs = _pfgovPos(n, "pfgovProfileIdleMs");
|
|
1068
|
+
}
|
|
1069
|
+
export function getPfgovProfileIdleMsV2() {
|
|
1070
|
+
return _pfgovIdleMs;
|
|
1071
|
+
}
|
|
1072
|
+
export function setPfgovRouteStuckMsV2(n) {
|
|
1073
|
+
_pfgovStuckMs = _pfgovPos(n, "pfgovRouteStuckMs");
|
|
1074
|
+
}
|
|
1075
|
+
export function getPfgovRouteStuckMsV2() {
|
|
1076
|
+
return _pfgovStuckMs;
|
|
1077
|
+
}
|
|
1078
|
+
export function _resetStateProtocolFusionGovV2() {
|
|
1079
|
+
_pfgovPsV2.clear();
|
|
1080
|
+
_pfgovJsV2.clear();
|
|
1081
|
+
_pfgovMaxActive = 6;
|
|
1082
|
+
_pfgovMaxPending = 15;
|
|
1083
|
+
_pfgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1084
|
+
_pfgovStuckMs = 60 * 1000;
|
|
1085
|
+
}
|
|
1086
|
+
export function registerPfgovProfileV2({ id, owner, protocol, metadata } = {}) {
|
|
1087
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1088
|
+
if (_pfgovPsV2.has(id)) throw new Error(`pfgov profile ${id} already exists`);
|
|
1089
|
+
const now = Date.now();
|
|
1090
|
+
const p = {
|
|
1091
|
+
id,
|
|
1092
|
+
owner,
|
|
1093
|
+
protocol: protocol || "hybrid",
|
|
1094
|
+
status: PFGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1095
|
+
createdAt: now,
|
|
1096
|
+
updatedAt: now,
|
|
1097
|
+
lastTouchedAt: now,
|
|
1098
|
+
activatedAt: null,
|
|
1099
|
+
archivedAt: null,
|
|
1100
|
+
metadata: { ...(metadata || {}) },
|
|
1101
|
+
};
|
|
1102
|
+
_pfgovPsV2.set(id, p);
|
|
1103
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1104
|
+
}
|
|
1105
|
+
export function activatePfgovProfileV2(id) {
|
|
1106
|
+
const p = _pfgovPsV2.get(id);
|
|
1107
|
+
if (!p) throw new Error(`pfgov profile ${id} not found`);
|
|
1108
|
+
const isInitial = p.status === PFGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1109
|
+
_pfgovCheckP(p.status, PFGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1110
|
+
if (isInitial && _pfgovCountActive(p.owner) >= _pfgovMaxActive)
|
|
1111
|
+
throw new Error(`max active pfgov profiles for owner ${p.owner} reached`);
|
|
1112
|
+
const now = Date.now();
|
|
1113
|
+
p.status = PFGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1114
|
+
p.updatedAt = now;
|
|
1115
|
+
p.lastTouchedAt = now;
|
|
1116
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1117
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1118
|
+
}
|
|
1119
|
+
export function degradePfgovProfileV2(id) {
|
|
1120
|
+
const p = _pfgovPsV2.get(id);
|
|
1121
|
+
if (!p) throw new Error(`pfgov profile ${id} not found`);
|
|
1122
|
+
_pfgovCheckP(p.status, PFGOV_PROFILE_MATURITY_V2.DEGRADED);
|
|
1123
|
+
p.status = PFGOV_PROFILE_MATURITY_V2.DEGRADED;
|
|
1124
|
+
p.updatedAt = Date.now();
|
|
1125
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1126
|
+
}
|
|
1127
|
+
export function archivePfgovProfileV2(id) {
|
|
1128
|
+
const p = _pfgovPsV2.get(id);
|
|
1129
|
+
if (!p) throw new Error(`pfgov profile ${id} not found`);
|
|
1130
|
+
_pfgovCheckP(p.status, PFGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1131
|
+
const now = Date.now();
|
|
1132
|
+
p.status = PFGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1133
|
+
p.updatedAt = now;
|
|
1134
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1135
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1136
|
+
}
|
|
1137
|
+
export function touchPfgovProfileV2(id) {
|
|
1138
|
+
const p = _pfgovPsV2.get(id);
|
|
1139
|
+
if (!p) throw new Error(`pfgov profile ${id} not found`);
|
|
1140
|
+
if (_pfgovPTerminal.has(p.status))
|
|
1141
|
+
throw new Error(`cannot touch terminal pfgov profile ${id}`);
|
|
1142
|
+
const now = Date.now();
|
|
1143
|
+
p.lastTouchedAt = now;
|
|
1144
|
+
p.updatedAt = now;
|
|
1145
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1146
|
+
}
|
|
1147
|
+
export function getPfgovProfileV2(id) {
|
|
1148
|
+
const p = _pfgovPsV2.get(id);
|
|
1149
|
+
if (!p) return null;
|
|
1150
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1151
|
+
}
|
|
1152
|
+
export function listPfgovProfilesV2() {
|
|
1153
|
+
return [..._pfgovPsV2.values()].map((p) => ({
|
|
1154
|
+
...p,
|
|
1155
|
+
metadata: { ...p.metadata },
|
|
1156
|
+
}));
|
|
1157
|
+
}
|
|
1158
|
+
export function createPfgovRouteV2({
|
|
1159
|
+
id,
|
|
1160
|
+
profileId,
|
|
1161
|
+
destination,
|
|
1162
|
+
metadata,
|
|
1163
|
+
} = {}) {
|
|
1164
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1165
|
+
if (_pfgovJsV2.has(id)) throw new Error(`pfgov route ${id} already exists`);
|
|
1166
|
+
if (!_pfgovPsV2.has(profileId))
|
|
1167
|
+
throw new Error(`pfgov profile ${profileId} not found`);
|
|
1168
|
+
if (_pfgovCountPending(profileId) >= _pfgovMaxPending)
|
|
1169
|
+
throw new Error(
|
|
1170
|
+
`max pending pfgov routes for profile ${profileId} reached`,
|
|
1171
|
+
);
|
|
1172
|
+
const now = Date.now();
|
|
1173
|
+
const j = {
|
|
1174
|
+
id,
|
|
1175
|
+
profileId,
|
|
1176
|
+
destination: destination || "",
|
|
1177
|
+
status: PFGOV_ROUTE_LIFECYCLE_V2.QUEUED,
|
|
1178
|
+
createdAt: now,
|
|
1179
|
+
updatedAt: now,
|
|
1180
|
+
startedAt: null,
|
|
1181
|
+
settledAt: null,
|
|
1182
|
+
metadata: { ...(metadata || {}) },
|
|
1183
|
+
};
|
|
1184
|
+
_pfgovJsV2.set(id, j);
|
|
1185
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1186
|
+
}
|
|
1187
|
+
export function routingPfgovRouteV2(id) {
|
|
1188
|
+
const j = _pfgovJsV2.get(id);
|
|
1189
|
+
if (!j) throw new Error(`pfgov route ${id} not found`);
|
|
1190
|
+
_pfgovCheckJ(j.status, PFGOV_ROUTE_LIFECYCLE_V2.ROUTING);
|
|
1191
|
+
const now = Date.now();
|
|
1192
|
+
j.status = PFGOV_ROUTE_LIFECYCLE_V2.ROUTING;
|
|
1193
|
+
j.updatedAt = now;
|
|
1194
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1195
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1196
|
+
}
|
|
1197
|
+
export function completeRoutePfgovV2(id) {
|
|
1198
|
+
const j = _pfgovJsV2.get(id);
|
|
1199
|
+
if (!j) throw new Error(`pfgov route ${id} not found`);
|
|
1200
|
+
_pfgovCheckJ(j.status, PFGOV_ROUTE_LIFECYCLE_V2.ROUTED);
|
|
1201
|
+
const now = Date.now();
|
|
1202
|
+
j.status = PFGOV_ROUTE_LIFECYCLE_V2.ROUTED;
|
|
1203
|
+
j.updatedAt = now;
|
|
1204
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1205
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1206
|
+
}
|
|
1207
|
+
export function failPfgovRouteV2(id, reason) {
|
|
1208
|
+
const j = _pfgovJsV2.get(id);
|
|
1209
|
+
if (!j) throw new Error(`pfgov route ${id} not found`);
|
|
1210
|
+
_pfgovCheckJ(j.status, PFGOV_ROUTE_LIFECYCLE_V2.FAILED);
|
|
1211
|
+
const now = Date.now();
|
|
1212
|
+
j.status = PFGOV_ROUTE_LIFECYCLE_V2.FAILED;
|
|
1213
|
+
j.updatedAt = now;
|
|
1214
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1215
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1216
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1217
|
+
}
|
|
1218
|
+
export function cancelPfgovRouteV2(id, reason) {
|
|
1219
|
+
const j = _pfgovJsV2.get(id);
|
|
1220
|
+
if (!j) throw new Error(`pfgov route ${id} not found`);
|
|
1221
|
+
_pfgovCheckJ(j.status, PFGOV_ROUTE_LIFECYCLE_V2.CANCELLED);
|
|
1222
|
+
const now = Date.now();
|
|
1223
|
+
j.status = PFGOV_ROUTE_LIFECYCLE_V2.CANCELLED;
|
|
1224
|
+
j.updatedAt = now;
|
|
1225
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1226
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1227
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1228
|
+
}
|
|
1229
|
+
export function getPfgovRouteV2(id) {
|
|
1230
|
+
const j = _pfgovJsV2.get(id);
|
|
1231
|
+
if (!j) return null;
|
|
1232
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1233
|
+
}
|
|
1234
|
+
export function listPfgovRoutesV2() {
|
|
1235
|
+
return [..._pfgovJsV2.values()].map((j) => ({
|
|
1236
|
+
...j,
|
|
1237
|
+
metadata: { ...j.metadata },
|
|
1238
|
+
}));
|
|
1239
|
+
}
|
|
1240
|
+
export function autoDegradeIdlePfgovProfilesV2({ now } = {}) {
|
|
1241
|
+
const t = now ?? Date.now();
|
|
1242
|
+
const flipped = [];
|
|
1243
|
+
for (const p of _pfgovPsV2.values())
|
|
1244
|
+
if (
|
|
1245
|
+
p.status === PFGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1246
|
+
t - p.lastTouchedAt >= _pfgovIdleMs
|
|
1247
|
+
) {
|
|
1248
|
+
p.status = PFGOV_PROFILE_MATURITY_V2.DEGRADED;
|
|
1249
|
+
p.updatedAt = t;
|
|
1250
|
+
flipped.push(p.id);
|
|
1251
|
+
}
|
|
1252
|
+
return { flipped, count: flipped.length };
|
|
1253
|
+
}
|
|
1254
|
+
export function autoFailStuckPfgovRoutesV2({ now } = {}) {
|
|
1255
|
+
const t = now ?? Date.now();
|
|
1256
|
+
const flipped = [];
|
|
1257
|
+
for (const j of _pfgovJsV2.values())
|
|
1258
|
+
if (
|
|
1259
|
+
j.status === PFGOV_ROUTE_LIFECYCLE_V2.ROUTING &&
|
|
1260
|
+
j.startedAt != null &&
|
|
1261
|
+
t - j.startedAt >= _pfgovStuckMs
|
|
1262
|
+
) {
|
|
1263
|
+
j.status = PFGOV_ROUTE_LIFECYCLE_V2.FAILED;
|
|
1264
|
+
j.updatedAt = t;
|
|
1265
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1266
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1267
|
+
flipped.push(j.id);
|
|
1268
|
+
}
|
|
1269
|
+
return { flipped, count: flipped.length };
|
|
1270
|
+
}
|
|
1271
|
+
export function getProtocolFusionGovStatsV2() {
|
|
1272
|
+
const profilesByStatus = {};
|
|
1273
|
+
for (const v of Object.values(PFGOV_PROFILE_MATURITY_V2))
|
|
1274
|
+
profilesByStatus[v] = 0;
|
|
1275
|
+
for (const p of _pfgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1276
|
+
const routesByStatus = {};
|
|
1277
|
+
for (const v of Object.values(PFGOV_ROUTE_LIFECYCLE_V2))
|
|
1278
|
+
routesByStatus[v] = 0;
|
|
1279
|
+
for (const j of _pfgovJsV2.values()) routesByStatus[j.status]++;
|
|
1280
|
+
return {
|
|
1281
|
+
totalPfgovProfilesV2: _pfgovPsV2.size,
|
|
1282
|
+
totalPfgovRoutesV2: _pfgovJsV2.size,
|
|
1283
|
+
maxActivePfgovProfilesPerOwner: _pfgovMaxActive,
|
|
1284
|
+
maxPendingPfgovRoutesPerProfile: _pfgovMaxPending,
|
|
1285
|
+
pfgovProfileIdleMs: _pfgovIdleMs,
|
|
1286
|
+
pfgovRouteStuckMs: _pfgovStuckMs,
|
|
1287
|
+
profilesByStatus,
|
|
1288
|
+
routesByStatus,
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
@@ -131,3 +131,349 @@ export function mergeProviderOptions(provider, modelId, callOverrides = {}) {
|
|
|
131
131
|
const modelLayer = inferModelOverrides(modelId);
|
|
132
132
|
return deepMerge(defaults, modelLayer, callOverrides || {});
|
|
133
133
|
}
|
|
134
|
+
|
|
135
|
+
// =====================================================================
|
|
136
|
+
// provider-options V2 governance overlay (iter27)
|
|
137
|
+
// =====================================================================
|
|
138
|
+
export const POPTGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
139
|
+
PENDING: "pending",
|
|
140
|
+
ACTIVE: "active",
|
|
141
|
+
STALE: "stale",
|
|
142
|
+
ARCHIVED: "archived",
|
|
143
|
+
});
|
|
144
|
+
export const POPTGOV_RESOLVE_LIFECYCLE_V2 = Object.freeze({
|
|
145
|
+
QUEUED: "queued",
|
|
146
|
+
RESOLVING: "resolving",
|
|
147
|
+
RESOLVED: "resolved",
|
|
148
|
+
FAILED: "failed",
|
|
149
|
+
CANCELLED: "cancelled",
|
|
150
|
+
});
|
|
151
|
+
const _poptgovPTrans = new Map([
|
|
152
|
+
[
|
|
153
|
+
POPTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
154
|
+
new Set([
|
|
155
|
+
POPTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
156
|
+
POPTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
157
|
+
]),
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
POPTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
161
|
+
new Set([
|
|
162
|
+
POPTGOV_PROFILE_MATURITY_V2.STALE,
|
|
163
|
+
POPTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
164
|
+
]),
|
|
165
|
+
],
|
|
166
|
+
[
|
|
167
|
+
POPTGOV_PROFILE_MATURITY_V2.STALE,
|
|
168
|
+
new Set([
|
|
169
|
+
POPTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
170
|
+
POPTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
171
|
+
]),
|
|
172
|
+
],
|
|
173
|
+
[POPTGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
174
|
+
]);
|
|
175
|
+
const _poptgovPTerminal = new Set([POPTGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
176
|
+
const _poptgovJTrans = new Map([
|
|
177
|
+
[
|
|
178
|
+
POPTGOV_RESOLVE_LIFECYCLE_V2.QUEUED,
|
|
179
|
+
new Set([
|
|
180
|
+
POPTGOV_RESOLVE_LIFECYCLE_V2.RESOLVING,
|
|
181
|
+
POPTGOV_RESOLVE_LIFECYCLE_V2.CANCELLED,
|
|
182
|
+
]),
|
|
183
|
+
],
|
|
184
|
+
[
|
|
185
|
+
POPTGOV_RESOLVE_LIFECYCLE_V2.RESOLVING,
|
|
186
|
+
new Set([
|
|
187
|
+
POPTGOV_RESOLVE_LIFECYCLE_V2.RESOLVED,
|
|
188
|
+
POPTGOV_RESOLVE_LIFECYCLE_V2.FAILED,
|
|
189
|
+
POPTGOV_RESOLVE_LIFECYCLE_V2.CANCELLED,
|
|
190
|
+
]),
|
|
191
|
+
],
|
|
192
|
+
[POPTGOV_RESOLVE_LIFECYCLE_V2.RESOLVED, new Set()],
|
|
193
|
+
[POPTGOV_RESOLVE_LIFECYCLE_V2.FAILED, new Set()],
|
|
194
|
+
[POPTGOV_RESOLVE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
195
|
+
]);
|
|
196
|
+
const _poptgovPsV2 = new Map();
|
|
197
|
+
const _poptgovJsV2 = new Map();
|
|
198
|
+
let _poptgovMaxActive = 8,
|
|
199
|
+
_poptgovMaxPending = 20,
|
|
200
|
+
_poptgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
201
|
+
_poptgovStuckMs = 60 * 1000;
|
|
202
|
+
function _poptgovPos(n, label) {
|
|
203
|
+
const v = Math.floor(Number(n));
|
|
204
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
205
|
+
throw new Error(`${label} must be positive integer`);
|
|
206
|
+
return v;
|
|
207
|
+
}
|
|
208
|
+
function _poptgovCheckP(from, to) {
|
|
209
|
+
const a = _poptgovPTrans.get(from);
|
|
210
|
+
if (!a || !a.has(to))
|
|
211
|
+
throw new Error(`invalid poptgov profile transition ${from} → ${to}`);
|
|
212
|
+
}
|
|
213
|
+
function _poptgovCheckJ(from, to) {
|
|
214
|
+
const a = _poptgovJTrans.get(from);
|
|
215
|
+
if (!a || !a.has(to))
|
|
216
|
+
throw new Error(`invalid poptgov resolve transition ${from} → ${to}`);
|
|
217
|
+
}
|
|
218
|
+
function _poptgovCountActive(owner) {
|
|
219
|
+
let c = 0;
|
|
220
|
+
for (const p of _poptgovPsV2.values())
|
|
221
|
+
if (p.owner === owner && p.status === POPTGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
222
|
+
c++;
|
|
223
|
+
return c;
|
|
224
|
+
}
|
|
225
|
+
function _poptgovCountPending(profileId) {
|
|
226
|
+
let c = 0;
|
|
227
|
+
for (const j of _poptgovJsV2.values())
|
|
228
|
+
if (
|
|
229
|
+
j.profileId === profileId &&
|
|
230
|
+
(j.status === POPTGOV_RESOLVE_LIFECYCLE_V2.QUEUED ||
|
|
231
|
+
j.status === POPTGOV_RESOLVE_LIFECYCLE_V2.RESOLVING)
|
|
232
|
+
)
|
|
233
|
+
c++;
|
|
234
|
+
return c;
|
|
235
|
+
}
|
|
236
|
+
export function setMaxActivePoptgovProfilesPerOwnerV2(n) {
|
|
237
|
+
_poptgovMaxActive = _poptgovPos(n, "maxActivePoptgovProfilesPerOwner");
|
|
238
|
+
}
|
|
239
|
+
export function getMaxActivePoptgovProfilesPerOwnerV2() {
|
|
240
|
+
return _poptgovMaxActive;
|
|
241
|
+
}
|
|
242
|
+
export function setMaxPendingPoptgovResolvesPerProfileV2(n) {
|
|
243
|
+
_poptgovMaxPending = _poptgovPos(n, "maxPendingPoptgovResolvesPerProfile");
|
|
244
|
+
}
|
|
245
|
+
export function getMaxPendingPoptgovResolvesPerProfileV2() {
|
|
246
|
+
return _poptgovMaxPending;
|
|
247
|
+
}
|
|
248
|
+
export function setPoptgovProfileIdleMsV2(n) {
|
|
249
|
+
_poptgovIdleMs = _poptgovPos(n, "poptgovProfileIdleMs");
|
|
250
|
+
}
|
|
251
|
+
export function getPoptgovProfileIdleMsV2() {
|
|
252
|
+
return _poptgovIdleMs;
|
|
253
|
+
}
|
|
254
|
+
export function setPoptgovResolveStuckMsV2(n) {
|
|
255
|
+
_poptgovStuckMs = _poptgovPos(n, "poptgovResolveStuckMs");
|
|
256
|
+
}
|
|
257
|
+
export function getPoptgovResolveStuckMsV2() {
|
|
258
|
+
return _poptgovStuckMs;
|
|
259
|
+
}
|
|
260
|
+
export function _resetStateProviderOptionsGovV2() {
|
|
261
|
+
_poptgovPsV2.clear();
|
|
262
|
+
_poptgovJsV2.clear();
|
|
263
|
+
_poptgovMaxActive = 8;
|
|
264
|
+
_poptgovMaxPending = 20;
|
|
265
|
+
_poptgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
266
|
+
_poptgovStuckMs = 60 * 1000;
|
|
267
|
+
}
|
|
268
|
+
export function registerPoptgovProfileV2({
|
|
269
|
+
id,
|
|
270
|
+
owner,
|
|
271
|
+
provider,
|
|
272
|
+
metadata,
|
|
273
|
+
} = {}) {
|
|
274
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
275
|
+
if (_poptgovPsV2.has(id))
|
|
276
|
+
throw new Error(`poptgov profile ${id} already exists`);
|
|
277
|
+
const now = Date.now();
|
|
278
|
+
const p = {
|
|
279
|
+
id,
|
|
280
|
+
owner,
|
|
281
|
+
provider: provider || "default",
|
|
282
|
+
status: POPTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
283
|
+
createdAt: now,
|
|
284
|
+
updatedAt: now,
|
|
285
|
+
lastTouchedAt: now,
|
|
286
|
+
activatedAt: null,
|
|
287
|
+
archivedAt: null,
|
|
288
|
+
metadata: { ...(metadata || {}) },
|
|
289
|
+
};
|
|
290
|
+
_poptgovPsV2.set(id, p);
|
|
291
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
292
|
+
}
|
|
293
|
+
export function activatePoptgovProfileV2(id) {
|
|
294
|
+
const p = _poptgovPsV2.get(id);
|
|
295
|
+
if (!p) throw new Error(`poptgov profile ${id} not found`);
|
|
296
|
+
const isInitial = p.status === POPTGOV_PROFILE_MATURITY_V2.PENDING;
|
|
297
|
+
_poptgovCheckP(p.status, POPTGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
298
|
+
if (isInitial && _poptgovCountActive(p.owner) >= _poptgovMaxActive)
|
|
299
|
+
throw new Error(`max active poptgov profiles for owner ${p.owner} reached`);
|
|
300
|
+
const now = Date.now();
|
|
301
|
+
p.status = POPTGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
302
|
+
p.updatedAt = now;
|
|
303
|
+
p.lastTouchedAt = now;
|
|
304
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
305
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
306
|
+
}
|
|
307
|
+
export function stalePoptgovProfileV2(id) {
|
|
308
|
+
const p = _poptgovPsV2.get(id);
|
|
309
|
+
if (!p) throw new Error(`poptgov profile ${id} not found`);
|
|
310
|
+
_poptgovCheckP(p.status, POPTGOV_PROFILE_MATURITY_V2.STALE);
|
|
311
|
+
p.status = POPTGOV_PROFILE_MATURITY_V2.STALE;
|
|
312
|
+
p.updatedAt = Date.now();
|
|
313
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
314
|
+
}
|
|
315
|
+
export function archivePoptgovProfileV2(id) {
|
|
316
|
+
const p = _poptgovPsV2.get(id);
|
|
317
|
+
if (!p) throw new Error(`poptgov profile ${id} not found`);
|
|
318
|
+
_poptgovCheckP(p.status, POPTGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
319
|
+
const now = Date.now();
|
|
320
|
+
p.status = POPTGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
321
|
+
p.updatedAt = now;
|
|
322
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
323
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
324
|
+
}
|
|
325
|
+
export function touchPoptgovProfileV2(id) {
|
|
326
|
+
const p = _poptgovPsV2.get(id);
|
|
327
|
+
if (!p) throw new Error(`poptgov profile ${id} not found`);
|
|
328
|
+
if (_poptgovPTerminal.has(p.status))
|
|
329
|
+
throw new Error(`cannot touch terminal poptgov profile ${id}`);
|
|
330
|
+
const now = Date.now();
|
|
331
|
+
p.lastTouchedAt = now;
|
|
332
|
+
p.updatedAt = now;
|
|
333
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
334
|
+
}
|
|
335
|
+
export function getPoptgovProfileV2(id) {
|
|
336
|
+
const p = _poptgovPsV2.get(id);
|
|
337
|
+
if (!p) return null;
|
|
338
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
339
|
+
}
|
|
340
|
+
export function listPoptgovProfilesV2() {
|
|
341
|
+
return [..._poptgovPsV2.values()].map((p) => ({
|
|
342
|
+
...p,
|
|
343
|
+
metadata: { ...p.metadata },
|
|
344
|
+
}));
|
|
345
|
+
}
|
|
346
|
+
export function createPoptgovResolveV2({
|
|
347
|
+
id,
|
|
348
|
+
profileId,
|
|
349
|
+
option,
|
|
350
|
+
metadata,
|
|
351
|
+
} = {}) {
|
|
352
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
353
|
+
if (_poptgovJsV2.has(id))
|
|
354
|
+
throw new Error(`poptgov resolve ${id} already exists`);
|
|
355
|
+
if (!_poptgovPsV2.has(profileId))
|
|
356
|
+
throw new Error(`poptgov profile ${profileId} not found`);
|
|
357
|
+
if (_poptgovCountPending(profileId) >= _poptgovMaxPending)
|
|
358
|
+
throw new Error(
|
|
359
|
+
`max pending poptgov resolves for profile ${profileId} reached`,
|
|
360
|
+
);
|
|
361
|
+
const now = Date.now();
|
|
362
|
+
const j = {
|
|
363
|
+
id,
|
|
364
|
+
profileId,
|
|
365
|
+
option: option || "",
|
|
366
|
+
status: POPTGOV_RESOLVE_LIFECYCLE_V2.QUEUED,
|
|
367
|
+
createdAt: now,
|
|
368
|
+
updatedAt: now,
|
|
369
|
+
startedAt: null,
|
|
370
|
+
settledAt: null,
|
|
371
|
+
metadata: { ...(metadata || {}) },
|
|
372
|
+
};
|
|
373
|
+
_poptgovJsV2.set(id, j);
|
|
374
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
375
|
+
}
|
|
376
|
+
export function resolvingPoptgovResolveV2(id) {
|
|
377
|
+
const j = _poptgovJsV2.get(id);
|
|
378
|
+
if (!j) throw new Error(`poptgov resolve ${id} not found`);
|
|
379
|
+
_poptgovCheckJ(j.status, POPTGOV_RESOLVE_LIFECYCLE_V2.RESOLVING);
|
|
380
|
+
const now = Date.now();
|
|
381
|
+
j.status = POPTGOV_RESOLVE_LIFECYCLE_V2.RESOLVING;
|
|
382
|
+
j.updatedAt = now;
|
|
383
|
+
if (!j.startedAt) j.startedAt = now;
|
|
384
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
385
|
+
}
|
|
386
|
+
export function completeResolvePoptgovV2(id) {
|
|
387
|
+
const j = _poptgovJsV2.get(id);
|
|
388
|
+
if (!j) throw new Error(`poptgov resolve ${id} not found`);
|
|
389
|
+
_poptgovCheckJ(j.status, POPTGOV_RESOLVE_LIFECYCLE_V2.RESOLVED);
|
|
390
|
+
const now = Date.now();
|
|
391
|
+
j.status = POPTGOV_RESOLVE_LIFECYCLE_V2.RESOLVED;
|
|
392
|
+
j.updatedAt = now;
|
|
393
|
+
if (!j.settledAt) j.settledAt = now;
|
|
394
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
395
|
+
}
|
|
396
|
+
export function failPoptgovResolveV2(id, reason) {
|
|
397
|
+
const j = _poptgovJsV2.get(id);
|
|
398
|
+
if (!j) throw new Error(`poptgov resolve ${id} not found`);
|
|
399
|
+
_poptgovCheckJ(j.status, POPTGOV_RESOLVE_LIFECYCLE_V2.FAILED);
|
|
400
|
+
const now = Date.now();
|
|
401
|
+
j.status = POPTGOV_RESOLVE_LIFECYCLE_V2.FAILED;
|
|
402
|
+
j.updatedAt = now;
|
|
403
|
+
if (!j.settledAt) j.settledAt = now;
|
|
404
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
405
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
406
|
+
}
|
|
407
|
+
export function cancelPoptgovResolveV2(id, reason) {
|
|
408
|
+
const j = _poptgovJsV2.get(id);
|
|
409
|
+
if (!j) throw new Error(`poptgov resolve ${id} not found`);
|
|
410
|
+
_poptgovCheckJ(j.status, POPTGOV_RESOLVE_LIFECYCLE_V2.CANCELLED);
|
|
411
|
+
const now = Date.now();
|
|
412
|
+
j.status = POPTGOV_RESOLVE_LIFECYCLE_V2.CANCELLED;
|
|
413
|
+
j.updatedAt = now;
|
|
414
|
+
if (!j.settledAt) j.settledAt = now;
|
|
415
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
416
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
417
|
+
}
|
|
418
|
+
export function getPoptgovResolveV2(id) {
|
|
419
|
+
const j = _poptgovJsV2.get(id);
|
|
420
|
+
if (!j) return null;
|
|
421
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
422
|
+
}
|
|
423
|
+
export function listPoptgovResolvesV2() {
|
|
424
|
+
return [..._poptgovJsV2.values()].map((j) => ({
|
|
425
|
+
...j,
|
|
426
|
+
metadata: { ...j.metadata },
|
|
427
|
+
}));
|
|
428
|
+
}
|
|
429
|
+
export function autoStaleIdlePoptgovProfilesV2({ now } = {}) {
|
|
430
|
+
const t = now ?? Date.now();
|
|
431
|
+
const flipped = [];
|
|
432
|
+
for (const p of _poptgovPsV2.values())
|
|
433
|
+
if (
|
|
434
|
+
p.status === POPTGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
435
|
+
t - p.lastTouchedAt >= _poptgovIdleMs
|
|
436
|
+
) {
|
|
437
|
+
p.status = POPTGOV_PROFILE_MATURITY_V2.STALE;
|
|
438
|
+
p.updatedAt = t;
|
|
439
|
+
flipped.push(p.id);
|
|
440
|
+
}
|
|
441
|
+
return { flipped, count: flipped.length };
|
|
442
|
+
}
|
|
443
|
+
export function autoFailStuckPoptgovResolvesV2({ now } = {}) {
|
|
444
|
+
const t = now ?? Date.now();
|
|
445
|
+
const flipped = [];
|
|
446
|
+
for (const j of _poptgovJsV2.values())
|
|
447
|
+
if (
|
|
448
|
+
j.status === POPTGOV_RESOLVE_LIFECYCLE_V2.RESOLVING &&
|
|
449
|
+
j.startedAt != null &&
|
|
450
|
+
t - j.startedAt >= _poptgovStuckMs
|
|
451
|
+
) {
|
|
452
|
+
j.status = POPTGOV_RESOLVE_LIFECYCLE_V2.FAILED;
|
|
453
|
+
j.updatedAt = t;
|
|
454
|
+
if (!j.settledAt) j.settledAt = t;
|
|
455
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
456
|
+
flipped.push(j.id);
|
|
457
|
+
}
|
|
458
|
+
return { flipped, count: flipped.length };
|
|
459
|
+
}
|
|
460
|
+
export function getProviderOptionsGovStatsV2() {
|
|
461
|
+
const profilesByStatus = {};
|
|
462
|
+
for (const v of Object.values(POPTGOV_PROFILE_MATURITY_V2))
|
|
463
|
+
profilesByStatus[v] = 0;
|
|
464
|
+
for (const p of _poptgovPsV2.values()) profilesByStatus[p.status]++;
|
|
465
|
+
const resolvesByStatus = {};
|
|
466
|
+
for (const v of Object.values(POPTGOV_RESOLVE_LIFECYCLE_V2))
|
|
467
|
+
resolvesByStatus[v] = 0;
|
|
468
|
+
for (const j of _poptgovJsV2.values()) resolvesByStatus[j.status]++;
|
|
469
|
+
return {
|
|
470
|
+
totalPoptgovProfilesV2: _poptgovPsV2.size,
|
|
471
|
+
totalPoptgovResolvesV2: _poptgovJsV2.size,
|
|
472
|
+
maxActivePoptgovProfilesPerOwner: _poptgovMaxActive,
|
|
473
|
+
maxPendingPoptgovResolvesPerProfile: _poptgovMaxPending,
|
|
474
|
+
poptgovProfileIdleMs: _poptgovIdleMs,
|
|
475
|
+
poptgovResolveStuckMs: _poptgovStuckMs,
|
|
476
|
+
profilesByStatus,
|
|
477
|
+
resolvesByStatus,
|
|
478
|
+
};
|
|
479
|
+
}
|