chainlesschain 0.145.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/activitypub.js +207 -0
- package/src/commands/agent-network.js +217 -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/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +410 -0
- package/src/commands/cowork.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/evomap.js +205 -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/hook.js +209 -0
- package/src/commands/import.js +209 -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/llm.js +217 -0
- package/src/commands/matrix.js +207 -0
- package/src/commands/mcp.js +217 -0
- 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 +209 -0
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -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/plugin-ecosystem.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/session.js +209 -0
- package/src/commands/skill.js +207 -0
- package/src/commands/social.js +201 -0
- package/src/commands/sso.js +209 -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/wallet.js +209 -0
- package/src/commands/workflow.js +203 -0
- package/src/index.js +140 -0
- package/src/lib/activitypub-bridge.js +334 -0
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/automation-engine.js +335 -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/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -0
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/cowork-share.js +338 -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/evomap-governance.js +334 -0
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +341 -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/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/protocol-fusion.js +338 -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/session-manager.js +334 -0
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -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/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/workflow-engine.js +330 -0
|
@@ -964,3 +964,337 @@ export function getActivityPubBridgeStatsV2() {
|
|
|
964
964
|
activitiesByStatus,
|
|
965
965
|
};
|
|
966
966
|
}
|
|
967
|
+
|
|
968
|
+
// =====================================================================
|
|
969
|
+
// activitypub-bridge V2 governance overlay (iter21)
|
|
970
|
+
// =====================================================================
|
|
971
|
+
export const APGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
972
|
+
PENDING: "pending",
|
|
973
|
+
ACTIVE: "active",
|
|
974
|
+
SUSPENDED: "suspended",
|
|
975
|
+
ARCHIVED: "archived",
|
|
976
|
+
});
|
|
977
|
+
export const APGOV_DELIVERY_LIFECYCLE_V2 = Object.freeze({
|
|
978
|
+
QUEUED: "queued",
|
|
979
|
+
DELIVERING: "delivering",
|
|
980
|
+
DELIVERED: "delivered",
|
|
981
|
+
FAILED: "failed",
|
|
982
|
+
CANCELLED: "cancelled",
|
|
983
|
+
});
|
|
984
|
+
const _apgovPTrans = new Map([
|
|
985
|
+
[
|
|
986
|
+
APGOV_PROFILE_MATURITY_V2.PENDING,
|
|
987
|
+
new Set([
|
|
988
|
+
APGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
989
|
+
APGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
990
|
+
]),
|
|
991
|
+
],
|
|
992
|
+
[
|
|
993
|
+
APGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
994
|
+
new Set([
|
|
995
|
+
APGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
996
|
+
APGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
997
|
+
]),
|
|
998
|
+
],
|
|
999
|
+
[
|
|
1000
|
+
APGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1001
|
+
new Set([
|
|
1002
|
+
APGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1003
|
+
APGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1004
|
+
]),
|
|
1005
|
+
],
|
|
1006
|
+
[APGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1007
|
+
]);
|
|
1008
|
+
const _apgovPTerminal = new Set([APGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1009
|
+
const _apgovJTrans = new Map([
|
|
1010
|
+
[
|
|
1011
|
+
APGOV_DELIVERY_LIFECYCLE_V2.QUEUED,
|
|
1012
|
+
new Set([
|
|
1013
|
+
APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING,
|
|
1014
|
+
APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED,
|
|
1015
|
+
]),
|
|
1016
|
+
],
|
|
1017
|
+
[
|
|
1018
|
+
APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING,
|
|
1019
|
+
new Set([
|
|
1020
|
+
APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED,
|
|
1021
|
+
APGOV_DELIVERY_LIFECYCLE_V2.FAILED,
|
|
1022
|
+
APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED,
|
|
1023
|
+
]),
|
|
1024
|
+
],
|
|
1025
|
+
[APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED, new Set()],
|
|
1026
|
+
[APGOV_DELIVERY_LIFECYCLE_V2.FAILED, new Set()],
|
|
1027
|
+
[APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1028
|
+
]);
|
|
1029
|
+
const _apgovPsV2 = new Map();
|
|
1030
|
+
const _apgovJsV2 = new Map();
|
|
1031
|
+
let _apgovMaxActive = 8,
|
|
1032
|
+
_apgovMaxPending = 25,
|
|
1033
|
+
_apgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1034
|
+
_apgovStuckMs = 60 * 1000;
|
|
1035
|
+
function _apgovPos(n, label) {
|
|
1036
|
+
const v = Math.floor(Number(n));
|
|
1037
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1038
|
+
throw new Error(`${label} must be positive integer`);
|
|
1039
|
+
return v;
|
|
1040
|
+
}
|
|
1041
|
+
function _apgovCheckP(from, to) {
|
|
1042
|
+
const a = _apgovPTrans.get(from);
|
|
1043
|
+
if (!a || !a.has(to))
|
|
1044
|
+
throw new Error(`invalid apgov profile transition ${from} → ${to}`);
|
|
1045
|
+
}
|
|
1046
|
+
function _apgovCheckJ(from, to) {
|
|
1047
|
+
const a = _apgovJTrans.get(from);
|
|
1048
|
+
if (!a || !a.has(to))
|
|
1049
|
+
throw new Error(`invalid apgov delivery transition ${from} → ${to}`);
|
|
1050
|
+
}
|
|
1051
|
+
function _apgovCountActive(owner) {
|
|
1052
|
+
let c = 0;
|
|
1053
|
+
for (const p of _apgovPsV2.values())
|
|
1054
|
+
if (p.owner === owner && p.status === APGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
1055
|
+
return c;
|
|
1056
|
+
}
|
|
1057
|
+
function _apgovCountPending(profileId) {
|
|
1058
|
+
let c = 0;
|
|
1059
|
+
for (const j of _apgovJsV2.values())
|
|
1060
|
+
if (
|
|
1061
|
+
j.profileId === profileId &&
|
|
1062
|
+
(j.status === APGOV_DELIVERY_LIFECYCLE_V2.QUEUED ||
|
|
1063
|
+
j.status === APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING)
|
|
1064
|
+
)
|
|
1065
|
+
c++;
|
|
1066
|
+
return c;
|
|
1067
|
+
}
|
|
1068
|
+
export function setMaxActiveApgovProfilesPerOwnerV2(n) {
|
|
1069
|
+
_apgovMaxActive = _apgovPos(n, "maxActiveApgovProfilesPerOwner");
|
|
1070
|
+
}
|
|
1071
|
+
export function getMaxActiveApgovProfilesPerOwnerV2() {
|
|
1072
|
+
return _apgovMaxActive;
|
|
1073
|
+
}
|
|
1074
|
+
export function setMaxPendingApgovDeliverysPerProfileV2(n) {
|
|
1075
|
+
_apgovMaxPending = _apgovPos(n, "maxPendingApgovDeliverysPerProfile");
|
|
1076
|
+
}
|
|
1077
|
+
export function getMaxPendingApgovDeliverysPerProfileV2() {
|
|
1078
|
+
return _apgovMaxPending;
|
|
1079
|
+
}
|
|
1080
|
+
export function setApgovProfileIdleMsV2(n) {
|
|
1081
|
+
_apgovIdleMs = _apgovPos(n, "apgovProfileIdleMs");
|
|
1082
|
+
}
|
|
1083
|
+
export function getApgovProfileIdleMsV2() {
|
|
1084
|
+
return _apgovIdleMs;
|
|
1085
|
+
}
|
|
1086
|
+
export function setApgovDeliveryStuckMsV2(n) {
|
|
1087
|
+
_apgovStuckMs = _apgovPos(n, "apgovDeliveryStuckMs");
|
|
1088
|
+
}
|
|
1089
|
+
export function getApgovDeliveryStuckMsV2() {
|
|
1090
|
+
return _apgovStuckMs;
|
|
1091
|
+
}
|
|
1092
|
+
export function _resetStateActivityPubBridgeGovV2() {
|
|
1093
|
+
_apgovPsV2.clear();
|
|
1094
|
+
_apgovJsV2.clear();
|
|
1095
|
+
_apgovMaxActive = 8;
|
|
1096
|
+
_apgovMaxPending = 25;
|
|
1097
|
+
_apgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1098
|
+
_apgovStuckMs = 60 * 1000;
|
|
1099
|
+
}
|
|
1100
|
+
export function registerApgovProfileV2({ id, owner, actor, metadata } = {}) {
|
|
1101
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1102
|
+
if (_apgovPsV2.has(id)) throw new Error(`apgov profile ${id} already exists`);
|
|
1103
|
+
const now = Date.now();
|
|
1104
|
+
const p = {
|
|
1105
|
+
id,
|
|
1106
|
+
owner,
|
|
1107
|
+
actor: actor || "person",
|
|
1108
|
+
status: APGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1109
|
+
createdAt: now,
|
|
1110
|
+
updatedAt: now,
|
|
1111
|
+
lastTouchedAt: now,
|
|
1112
|
+
activatedAt: null,
|
|
1113
|
+
archivedAt: null,
|
|
1114
|
+
metadata: { ...(metadata || {}) },
|
|
1115
|
+
};
|
|
1116
|
+
_apgovPsV2.set(id, p);
|
|
1117
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1118
|
+
}
|
|
1119
|
+
export function activateApgovProfileV2(id) {
|
|
1120
|
+
const p = _apgovPsV2.get(id);
|
|
1121
|
+
if (!p) throw new Error(`apgov profile ${id} not found`);
|
|
1122
|
+
const isInitial = p.status === APGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1123
|
+
_apgovCheckP(p.status, APGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1124
|
+
if (isInitial && _apgovCountActive(p.owner) >= _apgovMaxActive)
|
|
1125
|
+
throw new Error(`max active apgov profiles for owner ${p.owner} reached`);
|
|
1126
|
+
const now = Date.now();
|
|
1127
|
+
p.status = APGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1128
|
+
p.updatedAt = now;
|
|
1129
|
+
p.lastTouchedAt = now;
|
|
1130
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1131
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1132
|
+
}
|
|
1133
|
+
export function suspendApgovProfileV2(id) {
|
|
1134
|
+
const p = _apgovPsV2.get(id);
|
|
1135
|
+
if (!p) throw new Error(`apgov profile ${id} not found`);
|
|
1136
|
+
_apgovCheckP(p.status, APGOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
1137
|
+
p.status = APGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1138
|
+
p.updatedAt = Date.now();
|
|
1139
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1140
|
+
}
|
|
1141
|
+
export function archiveApgovProfileV2(id) {
|
|
1142
|
+
const p = _apgovPsV2.get(id);
|
|
1143
|
+
if (!p) throw new Error(`apgov profile ${id} not found`);
|
|
1144
|
+
_apgovCheckP(p.status, APGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1145
|
+
const now = Date.now();
|
|
1146
|
+
p.status = APGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1147
|
+
p.updatedAt = now;
|
|
1148
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1149
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1150
|
+
}
|
|
1151
|
+
export function touchApgovProfileV2(id) {
|
|
1152
|
+
const p = _apgovPsV2.get(id);
|
|
1153
|
+
if (!p) throw new Error(`apgov profile ${id} not found`);
|
|
1154
|
+
if (_apgovPTerminal.has(p.status))
|
|
1155
|
+
throw new Error(`cannot touch terminal apgov profile ${id}`);
|
|
1156
|
+
const now = Date.now();
|
|
1157
|
+
p.lastTouchedAt = now;
|
|
1158
|
+
p.updatedAt = now;
|
|
1159
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1160
|
+
}
|
|
1161
|
+
export function getApgovProfileV2(id) {
|
|
1162
|
+
const p = _apgovPsV2.get(id);
|
|
1163
|
+
if (!p) return null;
|
|
1164
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1165
|
+
}
|
|
1166
|
+
export function listApgovProfilesV2() {
|
|
1167
|
+
return [..._apgovPsV2.values()].map((p) => ({
|
|
1168
|
+
...p,
|
|
1169
|
+
metadata: { ...p.metadata },
|
|
1170
|
+
}));
|
|
1171
|
+
}
|
|
1172
|
+
export function createApgovDeliveryV2({ id, profileId, inbox, metadata } = {}) {
|
|
1173
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1174
|
+
if (_apgovJsV2.has(id))
|
|
1175
|
+
throw new Error(`apgov delivery ${id} already exists`);
|
|
1176
|
+
if (!_apgovPsV2.has(profileId))
|
|
1177
|
+
throw new Error(`apgov profile ${profileId} not found`);
|
|
1178
|
+
if (_apgovCountPending(profileId) >= _apgovMaxPending)
|
|
1179
|
+
throw new Error(
|
|
1180
|
+
`max pending apgov deliverys for profile ${profileId} reached`,
|
|
1181
|
+
);
|
|
1182
|
+
const now = Date.now();
|
|
1183
|
+
const j = {
|
|
1184
|
+
id,
|
|
1185
|
+
profileId,
|
|
1186
|
+
inbox: inbox || "",
|
|
1187
|
+
status: APGOV_DELIVERY_LIFECYCLE_V2.QUEUED,
|
|
1188
|
+
createdAt: now,
|
|
1189
|
+
updatedAt: now,
|
|
1190
|
+
startedAt: null,
|
|
1191
|
+
settledAt: null,
|
|
1192
|
+
metadata: { ...(metadata || {}) },
|
|
1193
|
+
};
|
|
1194
|
+
_apgovJsV2.set(id, j);
|
|
1195
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1196
|
+
}
|
|
1197
|
+
export function deliveringApgovDeliveryV2(id) {
|
|
1198
|
+
const j = _apgovJsV2.get(id);
|
|
1199
|
+
if (!j) throw new Error(`apgov delivery ${id} not found`);
|
|
1200
|
+
_apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING);
|
|
1201
|
+
const now = Date.now();
|
|
1202
|
+
j.status = APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING;
|
|
1203
|
+
j.updatedAt = now;
|
|
1204
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1205
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1206
|
+
}
|
|
1207
|
+
export function completeDeliveryApgovV2(id) {
|
|
1208
|
+
const j = _apgovJsV2.get(id);
|
|
1209
|
+
if (!j) throw new Error(`apgov delivery ${id} not found`);
|
|
1210
|
+
_apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED);
|
|
1211
|
+
const now = Date.now();
|
|
1212
|
+
j.status = APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED;
|
|
1213
|
+
j.updatedAt = now;
|
|
1214
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1215
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1216
|
+
}
|
|
1217
|
+
export function failApgovDeliveryV2(id, reason) {
|
|
1218
|
+
const j = _apgovJsV2.get(id);
|
|
1219
|
+
if (!j) throw new Error(`apgov delivery ${id} not found`);
|
|
1220
|
+
_apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.FAILED);
|
|
1221
|
+
const now = Date.now();
|
|
1222
|
+
j.status = APGOV_DELIVERY_LIFECYCLE_V2.FAILED;
|
|
1223
|
+
j.updatedAt = now;
|
|
1224
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1225
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1226
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1227
|
+
}
|
|
1228
|
+
export function cancelApgovDeliveryV2(id, reason) {
|
|
1229
|
+
const j = _apgovJsV2.get(id);
|
|
1230
|
+
if (!j) throw new Error(`apgov delivery ${id} not found`);
|
|
1231
|
+
_apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED);
|
|
1232
|
+
const now = Date.now();
|
|
1233
|
+
j.status = APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED;
|
|
1234
|
+
j.updatedAt = now;
|
|
1235
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1236
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1237
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1238
|
+
}
|
|
1239
|
+
export function getApgovDeliveryV2(id) {
|
|
1240
|
+
const j = _apgovJsV2.get(id);
|
|
1241
|
+
if (!j) return null;
|
|
1242
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1243
|
+
}
|
|
1244
|
+
export function listApgovDeliverysV2() {
|
|
1245
|
+
return [..._apgovJsV2.values()].map((j) => ({
|
|
1246
|
+
...j,
|
|
1247
|
+
metadata: { ...j.metadata },
|
|
1248
|
+
}));
|
|
1249
|
+
}
|
|
1250
|
+
export function autoSuspendIdleApgovProfilesV2({ now } = {}) {
|
|
1251
|
+
const t = now ?? Date.now();
|
|
1252
|
+
const flipped = [];
|
|
1253
|
+
for (const p of _apgovPsV2.values())
|
|
1254
|
+
if (
|
|
1255
|
+
p.status === APGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1256
|
+
t - p.lastTouchedAt >= _apgovIdleMs
|
|
1257
|
+
) {
|
|
1258
|
+
p.status = APGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1259
|
+
p.updatedAt = t;
|
|
1260
|
+
flipped.push(p.id);
|
|
1261
|
+
}
|
|
1262
|
+
return { flipped, count: flipped.length };
|
|
1263
|
+
}
|
|
1264
|
+
export function autoFailStuckApgovDeliverysV2({ now } = {}) {
|
|
1265
|
+
const t = now ?? Date.now();
|
|
1266
|
+
const flipped = [];
|
|
1267
|
+
for (const j of _apgovJsV2.values())
|
|
1268
|
+
if (
|
|
1269
|
+
j.status === APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING &&
|
|
1270
|
+
j.startedAt != null &&
|
|
1271
|
+
t - j.startedAt >= _apgovStuckMs
|
|
1272
|
+
) {
|
|
1273
|
+
j.status = APGOV_DELIVERY_LIFECYCLE_V2.FAILED;
|
|
1274
|
+
j.updatedAt = t;
|
|
1275
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1276
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1277
|
+
flipped.push(j.id);
|
|
1278
|
+
}
|
|
1279
|
+
return { flipped, count: flipped.length };
|
|
1280
|
+
}
|
|
1281
|
+
export function getActivityPubBridgeGovStatsV2() {
|
|
1282
|
+
const profilesByStatus = {};
|
|
1283
|
+
for (const v of Object.values(APGOV_PROFILE_MATURITY_V2))
|
|
1284
|
+
profilesByStatus[v] = 0;
|
|
1285
|
+
for (const p of _apgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1286
|
+
const deliverysByStatus = {};
|
|
1287
|
+
for (const v of Object.values(APGOV_DELIVERY_LIFECYCLE_V2))
|
|
1288
|
+
deliverysByStatus[v] = 0;
|
|
1289
|
+
for (const j of _apgovJsV2.values()) deliverysByStatus[j.status]++;
|
|
1290
|
+
return {
|
|
1291
|
+
totalApgovProfilesV2: _apgovPsV2.size,
|
|
1292
|
+
totalApgovDeliverysV2: _apgovJsV2.size,
|
|
1293
|
+
maxActiveApgovProfilesPerOwner: _apgovMaxActive,
|
|
1294
|
+
maxPendingApgovDeliverysPerProfile: _apgovMaxPending,
|
|
1295
|
+
apgovProfileIdleMs: _apgovIdleMs,
|
|
1296
|
+
apgovDeliveryStuckMs: _apgovStuckMs,
|
|
1297
|
+
profilesByStatus,
|
|
1298
|
+
deliverysByStatus,
|
|
1299
|
+
};
|
|
1300
|
+
}
|
package/src/lib/agent-network.js
CHANGED
|
@@ -1506,3 +1506,344 @@ export function _resetStateAgentNetworkV2() {
|
|
|
1506
1506
|
_stateAnetV2.agentIdleMs = AGENT_DEFAULT_AGENT_IDLE_MS;
|
|
1507
1507
|
_stateAnetV2.taskStuckMs = AGENT_DEFAULT_TASK_STUCK_MS;
|
|
1508
1508
|
}
|
|
1509
|
+
|
|
1510
|
+
// =====================================================================
|
|
1511
|
+
// agent-network V2 governance overlay (iter20)
|
|
1512
|
+
// =====================================================================
|
|
1513
|
+
export const ANETGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
1514
|
+
PENDING: "pending",
|
|
1515
|
+
ACTIVE: "active",
|
|
1516
|
+
SUSPENDED: "suspended",
|
|
1517
|
+
ARCHIVED: "archived",
|
|
1518
|
+
});
|
|
1519
|
+
export const ANETGOV_DISPATCH_LIFECYCLE_V2 = Object.freeze({
|
|
1520
|
+
QUEUED: "queued",
|
|
1521
|
+
DISPATCHING: "dispatching",
|
|
1522
|
+
DISPATCHED: "dispatched",
|
|
1523
|
+
FAILED: "failed",
|
|
1524
|
+
CANCELLED: "cancelled",
|
|
1525
|
+
});
|
|
1526
|
+
const _anetgovPTrans = new Map([
|
|
1527
|
+
[
|
|
1528
|
+
ANETGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1529
|
+
new Set([
|
|
1530
|
+
ANETGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1531
|
+
ANETGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1532
|
+
]),
|
|
1533
|
+
],
|
|
1534
|
+
[
|
|
1535
|
+
ANETGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1536
|
+
new Set([
|
|
1537
|
+
ANETGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1538
|
+
ANETGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1539
|
+
]),
|
|
1540
|
+
],
|
|
1541
|
+
[
|
|
1542
|
+
ANETGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1543
|
+
new Set([
|
|
1544
|
+
ANETGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1545
|
+
ANETGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1546
|
+
]),
|
|
1547
|
+
],
|
|
1548
|
+
[ANETGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1549
|
+
]);
|
|
1550
|
+
const _anetgovPTerminal = new Set([ANETGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1551
|
+
const _anetgovJTrans = new Map([
|
|
1552
|
+
[
|
|
1553
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.QUEUED,
|
|
1554
|
+
new Set([
|
|
1555
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING,
|
|
1556
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.CANCELLED,
|
|
1557
|
+
]),
|
|
1558
|
+
],
|
|
1559
|
+
[
|
|
1560
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING,
|
|
1561
|
+
new Set([
|
|
1562
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHED,
|
|
1563
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.FAILED,
|
|
1564
|
+
ANETGOV_DISPATCH_LIFECYCLE_V2.CANCELLED,
|
|
1565
|
+
]),
|
|
1566
|
+
],
|
|
1567
|
+
[ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHED, new Set()],
|
|
1568
|
+
[ANETGOV_DISPATCH_LIFECYCLE_V2.FAILED, new Set()],
|
|
1569
|
+
[ANETGOV_DISPATCH_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1570
|
+
]);
|
|
1571
|
+
const _anetgovPsV2 = new Map();
|
|
1572
|
+
const _anetgovJsV2 = new Map();
|
|
1573
|
+
let _anetgovMaxActive = 10,
|
|
1574
|
+
_anetgovMaxPending = 25,
|
|
1575
|
+
_anetgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1576
|
+
_anetgovStuckMs = 60 * 1000;
|
|
1577
|
+
function _anetgovPos(n, label) {
|
|
1578
|
+
const v = Math.floor(Number(n));
|
|
1579
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1580
|
+
throw new Error(`${label} must be positive integer`);
|
|
1581
|
+
return v;
|
|
1582
|
+
}
|
|
1583
|
+
function _anetgovCheckP(from, to) {
|
|
1584
|
+
const a = _anetgovPTrans.get(from);
|
|
1585
|
+
if (!a || !a.has(to))
|
|
1586
|
+
throw new Error(`invalid anetgov profile transition ${from} → ${to}`);
|
|
1587
|
+
}
|
|
1588
|
+
function _anetgovCheckJ(from, to) {
|
|
1589
|
+
const a = _anetgovJTrans.get(from);
|
|
1590
|
+
if (!a || !a.has(to))
|
|
1591
|
+
throw new Error(`invalid anetgov dispatch transition ${from} → ${to}`);
|
|
1592
|
+
}
|
|
1593
|
+
function _anetgovCountActive(owner) {
|
|
1594
|
+
let c = 0;
|
|
1595
|
+
for (const p of _anetgovPsV2.values())
|
|
1596
|
+
if (p.owner === owner && p.status === ANETGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
1597
|
+
c++;
|
|
1598
|
+
return c;
|
|
1599
|
+
}
|
|
1600
|
+
function _anetgovCountPending(profileId) {
|
|
1601
|
+
let c = 0;
|
|
1602
|
+
for (const j of _anetgovJsV2.values())
|
|
1603
|
+
if (
|
|
1604
|
+
j.profileId === profileId &&
|
|
1605
|
+
(j.status === ANETGOV_DISPATCH_LIFECYCLE_V2.QUEUED ||
|
|
1606
|
+
j.status === ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING)
|
|
1607
|
+
)
|
|
1608
|
+
c++;
|
|
1609
|
+
return c;
|
|
1610
|
+
}
|
|
1611
|
+
export function setMaxActiveAnetgovProfilesPerOwnerV2(n) {
|
|
1612
|
+
_anetgovMaxActive = _anetgovPos(n, "maxActiveAnetgovProfilesPerOwner");
|
|
1613
|
+
}
|
|
1614
|
+
export function getMaxActiveAnetgovProfilesPerOwnerV2() {
|
|
1615
|
+
return _anetgovMaxActive;
|
|
1616
|
+
}
|
|
1617
|
+
export function setMaxPendingAnetgovDispatchsPerProfileV2(n) {
|
|
1618
|
+
_anetgovMaxPending = _anetgovPos(n, "maxPendingAnetgovDispatchsPerProfile");
|
|
1619
|
+
}
|
|
1620
|
+
export function getMaxPendingAnetgovDispatchsPerProfileV2() {
|
|
1621
|
+
return _anetgovMaxPending;
|
|
1622
|
+
}
|
|
1623
|
+
export function setAnetgovProfileIdleMsV2(n) {
|
|
1624
|
+
_anetgovIdleMs = _anetgovPos(n, "anetgovProfileIdleMs");
|
|
1625
|
+
}
|
|
1626
|
+
export function getAnetgovProfileIdleMsV2() {
|
|
1627
|
+
return _anetgovIdleMs;
|
|
1628
|
+
}
|
|
1629
|
+
export function setAnetgovDispatchStuckMsV2(n) {
|
|
1630
|
+
_anetgovStuckMs = _anetgovPos(n, "anetgovDispatchStuckMs");
|
|
1631
|
+
}
|
|
1632
|
+
export function getAnetgovDispatchStuckMsV2() {
|
|
1633
|
+
return _anetgovStuckMs;
|
|
1634
|
+
}
|
|
1635
|
+
export function _resetStateAgentNetworkGovV2() {
|
|
1636
|
+
_anetgovPsV2.clear();
|
|
1637
|
+
_anetgovJsV2.clear();
|
|
1638
|
+
_anetgovMaxActive = 10;
|
|
1639
|
+
_anetgovMaxPending = 25;
|
|
1640
|
+
_anetgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1641
|
+
_anetgovStuckMs = 60 * 1000;
|
|
1642
|
+
}
|
|
1643
|
+
export function registerAnetgovProfileV2({ id, owner, role, metadata } = {}) {
|
|
1644
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1645
|
+
if (_anetgovPsV2.has(id))
|
|
1646
|
+
throw new Error(`anetgov profile ${id} already exists`);
|
|
1647
|
+
const now = Date.now();
|
|
1648
|
+
const p = {
|
|
1649
|
+
id,
|
|
1650
|
+
owner,
|
|
1651
|
+
role: role || "worker",
|
|
1652
|
+
status: ANETGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1653
|
+
createdAt: now,
|
|
1654
|
+
updatedAt: now,
|
|
1655
|
+
lastTouchedAt: now,
|
|
1656
|
+
activatedAt: null,
|
|
1657
|
+
archivedAt: null,
|
|
1658
|
+
metadata: { ...(metadata || {}) },
|
|
1659
|
+
};
|
|
1660
|
+
_anetgovPsV2.set(id, p);
|
|
1661
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1662
|
+
}
|
|
1663
|
+
export function activateAnetgovProfileV2(id) {
|
|
1664
|
+
const p = _anetgovPsV2.get(id);
|
|
1665
|
+
if (!p) throw new Error(`anetgov profile ${id} not found`);
|
|
1666
|
+
const isInitial = p.status === ANETGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1667
|
+
_anetgovCheckP(p.status, ANETGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1668
|
+
if (isInitial && _anetgovCountActive(p.owner) >= _anetgovMaxActive)
|
|
1669
|
+
throw new Error(`max active anetgov profiles for owner ${p.owner} reached`);
|
|
1670
|
+
const now = Date.now();
|
|
1671
|
+
p.status = ANETGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1672
|
+
p.updatedAt = now;
|
|
1673
|
+
p.lastTouchedAt = now;
|
|
1674
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1675
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1676
|
+
}
|
|
1677
|
+
export function suspendAnetgovProfileV2(id) {
|
|
1678
|
+
const p = _anetgovPsV2.get(id);
|
|
1679
|
+
if (!p) throw new Error(`anetgov profile ${id} not found`);
|
|
1680
|
+
_anetgovCheckP(p.status, ANETGOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
1681
|
+
p.status = ANETGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1682
|
+
p.updatedAt = Date.now();
|
|
1683
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1684
|
+
}
|
|
1685
|
+
export function archiveAnetgovProfileV2(id) {
|
|
1686
|
+
const p = _anetgovPsV2.get(id);
|
|
1687
|
+
if (!p) throw new Error(`anetgov profile ${id} not found`);
|
|
1688
|
+
_anetgovCheckP(p.status, ANETGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1689
|
+
const now = Date.now();
|
|
1690
|
+
p.status = ANETGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1691
|
+
p.updatedAt = now;
|
|
1692
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1693
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1694
|
+
}
|
|
1695
|
+
export function touchAnetgovProfileV2(id) {
|
|
1696
|
+
const p = _anetgovPsV2.get(id);
|
|
1697
|
+
if (!p) throw new Error(`anetgov profile ${id} not found`);
|
|
1698
|
+
if (_anetgovPTerminal.has(p.status))
|
|
1699
|
+
throw new Error(`cannot touch terminal anetgov profile ${id}`);
|
|
1700
|
+
const now = Date.now();
|
|
1701
|
+
p.lastTouchedAt = now;
|
|
1702
|
+
p.updatedAt = now;
|
|
1703
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1704
|
+
}
|
|
1705
|
+
export function getAnetgovProfileV2(id) {
|
|
1706
|
+
const p = _anetgovPsV2.get(id);
|
|
1707
|
+
if (!p) return null;
|
|
1708
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1709
|
+
}
|
|
1710
|
+
export function listAnetgovProfilesV2() {
|
|
1711
|
+
return [..._anetgovPsV2.values()].map((p) => ({
|
|
1712
|
+
...p,
|
|
1713
|
+
metadata: { ...p.metadata },
|
|
1714
|
+
}));
|
|
1715
|
+
}
|
|
1716
|
+
export function createAnetgovDispatchV2({
|
|
1717
|
+
id,
|
|
1718
|
+
profileId,
|
|
1719
|
+
target,
|
|
1720
|
+
metadata,
|
|
1721
|
+
} = {}) {
|
|
1722
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1723
|
+
if (_anetgovJsV2.has(id))
|
|
1724
|
+
throw new Error(`anetgov dispatch ${id} already exists`);
|
|
1725
|
+
if (!_anetgovPsV2.has(profileId))
|
|
1726
|
+
throw new Error(`anetgov profile ${profileId} not found`);
|
|
1727
|
+
if (_anetgovCountPending(profileId) >= _anetgovMaxPending)
|
|
1728
|
+
throw new Error(
|
|
1729
|
+
`max pending anetgov dispatchs for profile ${profileId} reached`,
|
|
1730
|
+
);
|
|
1731
|
+
const now = Date.now();
|
|
1732
|
+
const j = {
|
|
1733
|
+
id,
|
|
1734
|
+
profileId,
|
|
1735
|
+
target: target || "",
|
|
1736
|
+
status: ANETGOV_DISPATCH_LIFECYCLE_V2.QUEUED,
|
|
1737
|
+
createdAt: now,
|
|
1738
|
+
updatedAt: now,
|
|
1739
|
+
startedAt: null,
|
|
1740
|
+
settledAt: null,
|
|
1741
|
+
metadata: { ...(metadata || {}) },
|
|
1742
|
+
};
|
|
1743
|
+
_anetgovJsV2.set(id, j);
|
|
1744
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1745
|
+
}
|
|
1746
|
+
export function dispatchingAnetgovDispatchV2(id) {
|
|
1747
|
+
const j = _anetgovJsV2.get(id);
|
|
1748
|
+
if (!j) throw new Error(`anetgov dispatch ${id} not found`);
|
|
1749
|
+
_anetgovCheckJ(j.status, ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING);
|
|
1750
|
+
const now = Date.now();
|
|
1751
|
+
j.status = ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING;
|
|
1752
|
+
j.updatedAt = now;
|
|
1753
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1754
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1755
|
+
}
|
|
1756
|
+
export function completeDispatchAnetgovV2(id) {
|
|
1757
|
+
const j = _anetgovJsV2.get(id);
|
|
1758
|
+
if (!j) throw new Error(`anetgov dispatch ${id} not found`);
|
|
1759
|
+
_anetgovCheckJ(j.status, ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHED);
|
|
1760
|
+
const now = Date.now();
|
|
1761
|
+
j.status = ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHED;
|
|
1762
|
+
j.updatedAt = now;
|
|
1763
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1764
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1765
|
+
}
|
|
1766
|
+
export function failAnetgovDispatchV2(id, reason) {
|
|
1767
|
+
const j = _anetgovJsV2.get(id);
|
|
1768
|
+
if (!j) throw new Error(`anetgov dispatch ${id} not found`);
|
|
1769
|
+
_anetgovCheckJ(j.status, ANETGOV_DISPATCH_LIFECYCLE_V2.FAILED);
|
|
1770
|
+
const now = Date.now();
|
|
1771
|
+
j.status = ANETGOV_DISPATCH_LIFECYCLE_V2.FAILED;
|
|
1772
|
+
j.updatedAt = now;
|
|
1773
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1774
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1775
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1776
|
+
}
|
|
1777
|
+
export function cancelAnetgovDispatchV2(id, reason) {
|
|
1778
|
+
const j = _anetgovJsV2.get(id);
|
|
1779
|
+
if (!j) throw new Error(`anetgov dispatch ${id} not found`);
|
|
1780
|
+
_anetgovCheckJ(j.status, ANETGOV_DISPATCH_LIFECYCLE_V2.CANCELLED);
|
|
1781
|
+
const now = Date.now();
|
|
1782
|
+
j.status = ANETGOV_DISPATCH_LIFECYCLE_V2.CANCELLED;
|
|
1783
|
+
j.updatedAt = now;
|
|
1784
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1785
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1786
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1787
|
+
}
|
|
1788
|
+
export function getAnetgovDispatchV2(id) {
|
|
1789
|
+
const j = _anetgovJsV2.get(id);
|
|
1790
|
+
if (!j) return null;
|
|
1791
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1792
|
+
}
|
|
1793
|
+
export function listAnetgovDispatchsV2() {
|
|
1794
|
+
return [..._anetgovJsV2.values()].map((j) => ({
|
|
1795
|
+
...j,
|
|
1796
|
+
metadata: { ...j.metadata },
|
|
1797
|
+
}));
|
|
1798
|
+
}
|
|
1799
|
+
export function autoSuspendIdleAnetgovProfilesV2({ now } = {}) {
|
|
1800
|
+
const t = now ?? Date.now();
|
|
1801
|
+
const flipped = [];
|
|
1802
|
+
for (const p of _anetgovPsV2.values())
|
|
1803
|
+
if (
|
|
1804
|
+
p.status === ANETGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1805
|
+
t - p.lastTouchedAt >= _anetgovIdleMs
|
|
1806
|
+
) {
|
|
1807
|
+
p.status = ANETGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1808
|
+
p.updatedAt = t;
|
|
1809
|
+
flipped.push(p.id);
|
|
1810
|
+
}
|
|
1811
|
+
return { flipped, count: flipped.length };
|
|
1812
|
+
}
|
|
1813
|
+
export function autoFailStuckAnetgovDispatchsV2({ now } = {}) {
|
|
1814
|
+
const t = now ?? Date.now();
|
|
1815
|
+
const flipped = [];
|
|
1816
|
+
for (const j of _anetgovJsV2.values())
|
|
1817
|
+
if (
|
|
1818
|
+
j.status === ANETGOV_DISPATCH_LIFECYCLE_V2.DISPATCHING &&
|
|
1819
|
+
j.startedAt != null &&
|
|
1820
|
+
t - j.startedAt >= _anetgovStuckMs
|
|
1821
|
+
) {
|
|
1822
|
+
j.status = ANETGOV_DISPATCH_LIFECYCLE_V2.FAILED;
|
|
1823
|
+
j.updatedAt = t;
|
|
1824
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1825
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1826
|
+
flipped.push(j.id);
|
|
1827
|
+
}
|
|
1828
|
+
return { flipped, count: flipped.length };
|
|
1829
|
+
}
|
|
1830
|
+
export function getAgentNetworkGovStatsV2() {
|
|
1831
|
+
const profilesByStatus = {};
|
|
1832
|
+
for (const v of Object.values(ANETGOV_PROFILE_MATURITY_V2))
|
|
1833
|
+
profilesByStatus[v] = 0;
|
|
1834
|
+
for (const p of _anetgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1835
|
+
const dispatchsByStatus = {};
|
|
1836
|
+
for (const v of Object.values(ANETGOV_DISPATCH_LIFECYCLE_V2))
|
|
1837
|
+
dispatchsByStatus[v] = 0;
|
|
1838
|
+
for (const j of _anetgovJsV2.values()) dispatchsByStatus[j.status]++;
|
|
1839
|
+
return {
|
|
1840
|
+
totalAnetgovProfilesV2: _anetgovPsV2.size,
|
|
1841
|
+
totalAnetgovDispatchsV2: _anetgovJsV2.size,
|
|
1842
|
+
maxActiveAnetgovProfilesPerOwner: _anetgovMaxActive,
|
|
1843
|
+
maxPendingAnetgovDispatchsPerProfile: _anetgovMaxPending,
|
|
1844
|
+
anetgovProfileIdleMs: _anetgovIdleMs,
|
|
1845
|
+
anetgovDispatchStuckMs: _anetgovStuckMs,
|
|
1846
|
+
profilesByStatus,
|
|
1847
|
+
dispatchsByStatus,
|
|
1848
|
+
};
|
|
1849
|
+
}
|