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
package/src/lib/agent-economy.js
CHANGED
|
@@ -1204,3 +1204,337 @@ export function getAgentEconomyGovStatsV2() {
|
|
|
1204
1204
|
txsByStatus,
|
|
1205
1205
|
};
|
|
1206
1206
|
}
|
|
1207
|
+
|
|
1208
|
+
// === Iter28 V2 governance overlay: Aecogov ===
|
|
1209
|
+
export const AECOGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
1210
|
+
PENDING: "pending",
|
|
1211
|
+
ACTIVE: "active",
|
|
1212
|
+
PAUSED: "paused",
|
|
1213
|
+
ARCHIVED: "archived",
|
|
1214
|
+
});
|
|
1215
|
+
export const AECOGOV_TRADE_LIFECYCLE_V2 = Object.freeze({
|
|
1216
|
+
QUEUED: "queued",
|
|
1217
|
+
TRADING: "trading",
|
|
1218
|
+
SETTLED: "settled",
|
|
1219
|
+
FAILED: "failed",
|
|
1220
|
+
CANCELLED: "cancelled",
|
|
1221
|
+
});
|
|
1222
|
+
const _aecogovPTrans = new Map([
|
|
1223
|
+
[
|
|
1224
|
+
AECOGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1225
|
+
new Set([
|
|
1226
|
+
AECOGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1227
|
+
AECOGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1228
|
+
]),
|
|
1229
|
+
],
|
|
1230
|
+
[
|
|
1231
|
+
AECOGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1232
|
+
new Set([
|
|
1233
|
+
AECOGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
1234
|
+
AECOGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1235
|
+
]),
|
|
1236
|
+
],
|
|
1237
|
+
[
|
|
1238
|
+
AECOGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
1239
|
+
new Set([
|
|
1240
|
+
AECOGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1241
|
+
AECOGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1242
|
+
]),
|
|
1243
|
+
],
|
|
1244
|
+
[AECOGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1245
|
+
]);
|
|
1246
|
+
const _aecogovPTerminal = new Set([AECOGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1247
|
+
const _aecogovJTrans = new Map([
|
|
1248
|
+
[
|
|
1249
|
+
AECOGOV_TRADE_LIFECYCLE_V2.QUEUED,
|
|
1250
|
+
new Set([
|
|
1251
|
+
AECOGOV_TRADE_LIFECYCLE_V2.TRADING,
|
|
1252
|
+
AECOGOV_TRADE_LIFECYCLE_V2.CANCELLED,
|
|
1253
|
+
]),
|
|
1254
|
+
],
|
|
1255
|
+
[
|
|
1256
|
+
AECOGOV_TRADE_LIFECYCLE_V2.TRADING,
|
|
1257
|
+
new Set([
|
|
1258
|
+
AECOGOV_TRADE_LIFECYCLE_V2.SETTLED,
|
|
1259
|
+
AECOGOV_TRADE_LIFECYCLE_V2.FAILED,
|
|
1260
|
+
AECOGOV_TRADE_LIFECYCLE_V2.CANCELLED,
|
|
1261
|
+
]),
|
|
1262
|
+
],
|
|
1263
|
+
[AECOGOV_TRADE_LIFECYCLE_V2.SETTLED, new Set()],
|
|
1264
|
+
[AECOGOV_TRADE_LIFECYCLE_V2.FAILED, new Set()],
|
|
1265
|
+
[AECOGOV_TRADE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1266
|
+
]);
|
|
1267
|
+
const _aecogovPsV2 = new Map();
|
|
1268
|
+
const _aecogovJsV2 = new Map();
|
|
1269
|
+
let _aecogovMaxActive = 8,
|
|
1270
|
+
_aecogovMaxPending = 25,
|
|
1271
|
+
_aecogovIdleMs = 2592000000,
|
|
1272
|
+
_aecogovStuckMs = 60 * 1000;
|
|
1273
|
+
function _aecogovPos(n, label) {
|
|
1274
|
+
const v = Math.floor(Number(n));
|
|
1275
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1276
|
+
throw new Error(`${label} must be positive integer`);
|
|
1277
|
+
return v;
|
|
1278
|
+
}
|
|
1279
|
+
function _aecogovCheckP(from, to) {
|
|
1280
|
+
const a = _aecogovPTrans.get(from);
|
|
1281
|
+
if (!a || !a.has(to))
|
|
1282
|
+
throw new Error(`invalid aecogov profile transition ${from} → ${to}`);
|
|
1283
|
+
}
|
|
1284
|
+
function _aecogovCheckJ(from, to) {
|
|
1285
|
+
const a = _aecogovJTrans.get(from);
|
|
1286
|
+
if (!a || !a.has(to))
|
|
1287
|
+
throw new Error(`invalid aecogov trade transition ${from} → ${to}`);
|
|
1288
|
+
}
|
|
1289
|
+
function _aecogovCountActive(owner) {
|
|
1290
|
+
let c = 0;
|
|
1291
|
+
for (const p of _aecogovPsV2.values())
|
|
1292
|
+
if (p.owner === owner && p.status === AECOGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
1293
|
+
c++;
|
|
1294
|
+
return c;
|
|
1295
|
+
}
|
|
1296
|
+
function _aecogovCountPending(profileId) {
|
|
1297
|
+
let c = 0;
|
|
1298
|
+
for (const j of _aecogovJsV2.values())
|
|
1299
|
+
if (
|
|
1300
|
+
j.profileId === profileId &&
|
|
1301
|
+
(j.status === AECOGOV_TRADE_LIFECYCLE_V2.QUEUED ||
|
|
1302
|
+
j.status === AECOGOV_TRADE_LIFECYCLE_V2.TRADING)
|
|
1303
|
+
)
|
|
1304
|
+
c++;
|
|
1305
|
+
return c;
|
|
1306
|
+
}
|
|
1307
|
+
export function setMaxActiveAecoProfilesPerOwnerV2(n) {
|
|
1308
|
+
_aecogovMaxActive = _aecogovPos(n, "maxActiveAecoProfilesPerOwner");
|
|
1309
|
+
}
|
|
1310
|
+
export function getMaxActiveAecoProfilesPerOwnerV2() {
|
|
1311
|
+
return _aecogovMaxActive;
|
|
1312
|
+
}
|
|
1313
|
+
export function setMaxPendingAecoTradesPerProfileV2(n) {
|
|
1314
|
+
_aecogovMaxPending = _aecogovPos(n, "maxPendingAecoTradesPerProfile");
|
|
1315
|
+
}
|
|
1316
|
+
export function getMaxPendingAecoTradesPerProfileV2() {
|
|
1317
|
+
return _aecogovMaxPending;
|
|
1318
|
+
}
|
|
1319
|
+
export function setAecoProfileIdleMsV2(n) {
|
|
1320
|
+
_aecogovIdleMs = _aecogovPos(n, "aecogovProfileIdleMs");
|
|
1321
|
+
}
|
|
1322
|
+
export function getAecoProfileIdleMsV2() {
|
|
1323
|
+
return _aecogovIdleMs;
|
|
1324
|
+
}
|
|
1325
|
+
export function setAecoTradeStuckMsV2(n) {
|
|
1326
|
+
_aecogovStuckMs = _aecogovPos(n, "aecogovTradeStuckMs");
|
|
1327
|
+
}
|
|
1328
|
+
export function getAecoTradeStuckMsV2() {
|
|
1329
|
+
return _aecogovStuckMs;
|
|
1330
|
+
}
|
|
1331
|
+
export function _resetStateAecogovV2() {
|
|
1332
|
+
_aecogovPsV2.clear();
|
|
1333
|
+
_aecogovJsV2.clear();
|
|
1334
|
+
_aecogovMaxActive = 8;
|
|
1335
|
+
_aecogovMaxPending = 25;
|
|
1336
|
+
_aecogovIdleMs = 2592000000;
|
|
1337
|
+
_aecogovStuckMs = 60 * 1000;
|
|
1338
|
+
}
|
|
1339
|
+
export function registerAecoProfileV2({ id, owner, market, metadata } = {}) {
|
|
1340
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1341
|
+
if (_aecogovPsV2.has(id))
|
|
1342
|
+
throw new Error(`aecogov profile ${id} already exists`);
|
|
1343
|
+
const now = Date.now();
|
|
1344
|
+
const p = {
|
|
1345
|
+
id,
|
|
1346
|
+
owner,
|
|
1347
|
+
market: market || "default",
|
|
1348
|
+
status: AECOGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1349
|
+
createdAt: now,
|
|
1350
|
+
updatedAt: now,
|
|
1351
|
+
lastTouchedAt: now,
|
|
1352
|
+
activatedAt: null,
|
|
1353
|
+
archivedAt: null,
|
|
1354
|
+
metadata: { ...(metadata || {}) },
|
|
1355
|
+
};
|
|
1356
|
+
_aecogovPsV2.set(id, p);
|
|
1357
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1358
|
+
}
|
|
1359
|
+
export function activateAecoProfileV2(id) {
|
|
1360
|
+
const p = _aecogovPsV2.get(id);
|
|
1361
|
+
if (!p) throw new Error(`aecogov profile ${id} not found`);
|
|
1362
|
+
const isInitial = p.status === AECOGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1363
|
+
_aecogovCheckP(p.status, AECOGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1364
|
+
if (isInitial && _aecogovCountActive(p.owner) >= _aecogovMaxActive)
|
|
1365
|
+
throw new Error(`max active aecogov profiles for owner ${p.owner} reached`);
|
|
1366
|
+
const now = Date.now();
|
|
1367
|
+
p.status = AECOGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1368
|
+
p.updatedAt = now;
|
|
1369
|
+
p.lastTouchedAt = now;
|
|
1370
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1371
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1372
|
+
}
|
|
1373
|
+
export function pausedAecoProfileV2(id) {
|
|
1374
|
+
const p = _aecogovPsV2.get(id);
|
|
1375
|
+
if (!p) throw new Error(`aecogov profile ${id} not found`);
|
|
1376
|
+
_aecogovCheckP(p.status, AECOGOV_PROFILE_MATURITY_V2.PAUSED);
|
|
1377
|
+
p.status = AECOGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
1378
|
+
p.updatedAt = Date.now();
|
|
1379
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1380
|
+
}
|
|
1381
|
+
export function archiveAecoProfileV2(id) {
|
|
1382
|
+
const p = _aecogovPsV2.get(id);
|
|
1383
|
+
if (!p) throw new Error(`aecogov profile ${id} not found`);
|
|
1384
|
+
_aecogovCheckP(p.status, AECOGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1385
|
+
const now = Date.now();
|
|
1386
|
+
p.status = AECOGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1387
|
+
p.updatedAt = now;
|
|
1388
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1389
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1390
|
+
}
|
|
1391
|
+
export function touchAecoProfileV2(id) {
|
|
1392
|
+
const p = _aecogovPsV2.get(id);
|
|
1393
|
+
if (!p) throw new Error(`aecogov profile ${id} not found`);
|
|
1394
|
+
if (_aecogovPTerminal.has(p.status))
|
|
1395
|
+
throw new Error(`cannot touch terminal aecogov profile ${id}`);
|
|
1396
|
+
const now = Date.now();
|
|
1397
|
+
p.lastTouchedAt = now;
|
|
1398
|
+
p.updatedAt = now;
|
|
1399
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1400
|
+
}
|
|
1401
|
+
export function getAecoProfileV2(id) {
|
|
1402
|
+
const p = _aecogovPsV2.get(id);
|
|
1403
|
+
if (!p) return null;
|
|
1404
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1405
|
+
}
|
|
1406
|
+
export function listAecoProfilesV2() {
|
|
1407
|
+
return [..._aecogovPsV2.values()].map((p) => ({
|
|
1408
|
+
...p,
|
|
1409
|
+
metadata: { ...p.metadata },
|
|
1410
|
+
}));
|
|
1411
|
+
}
|
|
1412
|
+
export function createAecoTradeV2({ id, profileId, orderId, metadata } = {}) {
|
|
1413
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1414
|
+
if (_aecogovJsV2.has(id))
|
|
1415
|
+
throw new Error(`aecogov trade ${id} already exists`);
|
|
1416
|
+
if (!_aecogovPsV2.has(profileId))
|
|
1417
|
+
throw new Error(`aecogov profile ${profileId} not found`);
|
|
1418
|
+
if (_aecogovCountPending(profileId) >= _aecogovMaxPending)
|
|
1419
|
+
throw new Error(
|
|
1420
|
+
`max pending aecogov trades for profile ${profileId} reached`,
|
|
1421
|
+
);
|
|
1422
|
+
const now = Date.now();
|
|
1423
|
+
const j = {
|
|
1424
|
+
id,
|
|
1425
|
+
profileId,
|
|
1426
|
+
orderId: orderId || "",
|
|
1427
|
+
status: AECOGOV_TRADE_LIFECYCLE_V2.QUEUED,
|
|
1428
|
+
createdAt: now,
|
|
1429
|
+
updatedAt: now,
|
|
1430
|
+
startedAt: null,
|
|
1431
|
+
settledAt: null,
|
|
1432
|
+
metadata: { ...(metadata || {}) },
|
|
1433
|
+
};
|
|
1434
|
+
_aecogovJsV2.set(id, j);
|
|
1435
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1436
|
+
}
|
|
1437
|
+
export function tradingAecoTradeV2(id) {
|
|
1438
|
+
const j = _aecogovJsV2.get(id);
|
|
1439
|
+
if (!j) throw new Error(`aecogov trade ${id} not found`);
|
|
1440
|
+
_aecogovCheckJ(j.status, AECOGOV_TRADE_LIFECYCLE_V2.TRADING);
|
|
1441
|
+
const now = Date.now();
|
|
1442
|
+
j.status = AECOGOV_TRADE_LIFECYCLE_V2.TRADING;
|
|
1443
|
+
j.updatedAt = now;
|
|
1444
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1445
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1446
|
+
}
|
|
1447
|
+
export function completeTradeAecoV2(id) {
|
|
1448
|
+
const j = _aecogovJsV2.get(id);
|
|
1449
|
+
if (!j) throw new Error(`aecogov trade ${id} not found`);
|
|
1450
|
+
_aecogovCheckJ(j.status, AECOGOV_TRADE_LIFECYCLE_V2.SETTLED);
|
|
1451
|
+
const now = Date.now();
|
|
1452
|
+
j.status = AECOGOV_TRADE_LIFECYCLE_V2.SETTLED;
|
|
1453
|
+
j.updatedAt = now;
|
|
1454
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1455
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1456
|
+
}
|
|
1457
|
+
export function failAecoTradeV2(id, reason) {
|
|
1458
|
+
const j = _aecogovJsV2.get(id);
|
|
1459
|
+
if (!j) throw new Error(`aecogov trade ${id} not found`);
|
|
1460
|
+
_aecogovCheckJ(j.status, AECOGOV_TRADE_LIFECYCLE_V2.FAILED);
|
|
1461
|
+
const now = Date.now();
|
|
1462
|
+
j.status = AECOGOV_TRADE_LIFECYCLE_V2.FAILED;
|
|
1463
|
+
j.updatedAt = now;
|
|
1464
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1465
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1466
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1467
|
+
}
|
|
1468
|
+
export function cancelAecoTradeV2(id, reason) {
|
|
1469
|
+
const j = _aecogovJsV2.get(id);
|
|
1470
|
+
if (!j) throw new Error(`aecogov trade ${id} not found`);
|
|
1471
|
+
_aecogovCheckJ(j.status, AECOGOV_TRADE_LIFECYCLE_V2.CANCELLED);
|
|
1472
|
+
const now = Date.now();
|
|
1473
|
+
j.status = AECOGOV_TRADE_LIFECYCLE_V2.CANCELLED;
|
|
1474
|
+
j.updatedAt = now;
|
|
1475
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1476
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1477
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1478
|
+
}
|
|
1479
|
+
export function getAecoTradeV2(id) {
|
|
1480
|
+
const j = _aecogovJsV2.get(id);
|
|
1481
|
+
if (!j) return null;
|
|
1482
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1483
|
+
}
|
|
1484
|
+
export function listAecoTradesV2() {
|
|
1485
|
+
return [..._aecogovJsV2.values()].map((j) => ({
|
|
1486
|
+
...j,
|
|
1487
|
+
metadata: { ...j.metadata },
|
|
1488
|
+
}));
|
|
1489
|
+
}
|
|
1490
|
+
export function autoPausedIdleAecoProfilesV2({ now } = {}) {
|
|
1491
|
+
const t = now ?? Date.now();
|
|
1492
|
+
const flipped = [];
|
|
1493
|
+
for (const p of _aecogovPsV2.values())
|
|
1494
|
+
if (
|
|
1495
|
+
p.status === AECOGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1496
|
+
t - p.lastTouchedAt >= _aecogovIdleMs
|
|
1497
|
+
) {
|
|
1498
|
+
p.status = AECOGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
1499
|
+
p.updatedAt = t;
|
|
1500
|
+
flipped.push(p.id);
|
|
1501
|
+
}
|
|
1502
|
+
return { flipped, count: flipped.length };
|
|
1503
|
+
}
|
|
1504
|
+
export function autoFailStuckAecoTradesV2({ now } = {}) {
|
|
1505
|
+
const t = now ?? Date.now();
|
|
1506
|
+
const flipped = [];
|
|
1507
|
+
for (const j of _aecogovJsV2.values())
|
|
1508
|
+
if (
|
|
1509
|
+
j.status === AECOGOV_TRADE_LIFECYCLE_V2.TRADING &&
|
|
1510
|
+
j.startedAt != null &&
|
|
1511
|
+
t - j.startedAt >= _aecogovStuckMs
|
|
1512
|
+
) {
|
|
1513
|
+
j.status = AECOGOV_TRADE_LIFECYCLE_V2.FAILED;
|
|
1514
|
+
j.updatedAt = t;
|
|
1515
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1516
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1517
|
+
flipped.push(j.id);
|
|
1518
|
+
}
|
|
1519
|
+
return { flipped, count: flipped.length };
|
|
1520
|
+
}
|
|
1521
|
+
export function getAecogovStatsV2() {
|
|
1522
|
+
const profilesByStatus = {};
|
|
1523
|
+
for (const v of Object.values(AECOGOV_PROFILE_MATURITY_V2))
|
|
1524
|
+
profilesByStatus[v] = 0;
|
|
1525
|
+
for (const p of _aecogovPsV2.values()) profilesByStatus[p.status]++;
|
|
1526
|
+
const tradesByStatus = {};
|
|
1527
|
+
for (const v of Object.values(AECOGOV_TRADE_LIFECYCLE_V2))
|
|
1528
|
+
tradesByStatus[v] = 0;
|
|
1529
|
+
for (const j of _aecogovJsV2.values()) tradesByStatus[j.status]++;
|
|
1530
|
+
return {
|
|
1531
|
+
totalAecoProfilesV2: _aecogovPsV2.size,
|
|
1532
|
+
totalAecoTradesV2: _aecogovJsV2.size,
|
|
1533
|
+
maxActiveAecoProfilesPerOwner: _aecogovMaxActive,
|
|
1534
|
+
maxPendingAecoTradesPerProfile: _aecogovMaxPending,
|
|
1535
|
+
aecogovProfileIdleMs: _aecogovIdleMs,
|
|
1536
|
+
aecogovTradeStuckMs: _aecogovStuckMs,
|
|
1537
|
+
profilesByStatus,
|
|
1538
|
+
tradesByStatus,
|
|
1539
|
+
};
|
|
1540
|
+
}
|
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
|
+
}
|