chainlesschain 0.152.0 → 0.156.2

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.
Files changed (80) hide show
  1. package/README.md +52 -3
  2. package/package.json +1 -1
  3. package/src/commands/a2a.js +201 -0
  4. package/src/commands/agent.js +1250 -0
  5. package/src/commands/chat.js +605 -0
  6. package/src/commands/cli-anything.js +426 -0
  7. package/src/commands/compliance.js +412 -0
  8. package/src/commands/config.js +213 -0
  9. package/src/commands/cowork.js +1463 -0
  10. package/src/commands/crosschain.js +203 -0
  11. package/src/commands/dao.js +203 -0
  12. package/src/commands/economy.js +199 -0
  13. package/src/commands/encrypt.js +201 -0
  14. package/src/commands/evolution.js +199 -0
  15. package/src/commands/evomap.js +625 -0
  16. package/src/commands/hmemory.js +203 -0
  17. package/src/commands/inference.js +207 -0
  18. package/src/commands/kg.js +195 -0
  19. package/src/commands/llm.js +209 -0
  20. package/src/commands/memory.js +203 -0
  21. package/src/commands/orchestrate.js +406 -0
  22. package/src/commands/pipeline.js +199 -0
  23. package/src/commands/planmode.js +426 -0
  24. package/src/commands/plugin.js +209 -0
  25. package/src/commands/services.js +207 -0
  26. package/src/commands/setup.js +205 -0
  27. package/src/commands/skill.js +207 -0
  28. package/src/commands/start.js +209 -0
  29. package/src/commands/stream.js +213 -0
  30. package/src/commands/ui.js +225 -0
  31. package/src/commands/workflow.js +209 -0
  32. package/src/index.js +112 -0
  33. package/src/lib/a2a-protocol.js +332 -0
  34. package/src/lib/agent-coordinator.js +334 -0
  35. package/src/lib/agent-economy.js +334 -0
  36. package/src/lib/agent-router.js +333 -0
  37. package/src/lib/autonomous-agent.js +332 -0
  38. package/src/lib/chat-core.js +335 -0
  39. package/src/lib/cli-anything-bridge.js +341 -0
  40. package/src/lib/cli-context-engineering.js +351 -0
  41. package/src/lib/compliance-manager.js +334 -0
  42. package/src/lib/cowork-adapter.js +336 -0
  43. package/src/lib/cowork-evomap-adapter.js +341 -0
  44. package/src/lib/cowork-mcp-tools.js +341 -0
  45. package/src/lib/cowork-observe-html.js +341 -0
  46. package/src/lib/cowork-observe.js +341 -0
  47. package/src/lib/cowork-task-templates.js +342 -1
  48. package/src/lib/cowork-template-marketplace.js +340 -0
  49. package/src/lib/cross-chain.js +339 -0
  50. package/src/lib/crypto-manager.js +334 -0
  51. package/src/lib/dao-governance.js +339 -0
  52. package/src/lib/downloader.js +334 -0
  53. package/src/lib/evolution-system.js +334 -0
  54. package/src/lib/evomap-client.js +342 -0
  55. package/src/lib/evomap-federation.js +338 -0
  56. package/src/lib/evomap-manager.js +330 -0
  57. package/src/lib/execution-backend.js +330 -0
  58. package/src/lib/hashline.js +338 -0
  59. package/src/lib/hierarchical-memory.js +334 -0
  60. package/src/lib/inference-network.js +341 -0
  61. package/src/lib/interaction-adapter.js +330 -0
  62. package/src/lib/interactive-planner.js +354 -0
  63. package/src/lib/knowledge-graph.js +331 -0
  64. package/src/lib/pipeline-orchestrator.js +332 -0
  65. package/src/lib/plan-mode.js +336 -0
  66. package/src/lib/plugin-autodiscovery.js +334 -0
  67. package/src/lib/process-manager.js +336 -0
  68. package/src/lib/provider-options.js +346 -0
  69. package/src/lib/provider-stream.js +348 -0
  70. package/src/lib/service-manager.js +337 -0
  71. package/src/lib/session-core-singletons.js +341 -0
  72. package/src/lib/skill-mcp.js +336 -0
  73. package/src/lib/stix-parser.js +346 -0
  74. package/src/lib/sub-agent-context.js +343 -0
  75. package/src/lib/sub-agent-profiles.js +335 -0
  76. package/src/lib/sub-agent-registry.js +336 -0
  77. package/src/lib/todo-manager.js +336 -0
  78. package/src/lib/web-ui-server.js +348 -0
  79. package/src/lib/workflow-expr.js +346 -0
  80. package/src/lib/ws-chat-handler.js +337 -0
@@ -1051,3 +1051,212 @@ export function registerWfgovV2Commands(program) {
1051
1051
  );
1052
1052
  });
1053
1053
  }
1054
+
1055
+ // === Iter26 V2 governance overlay ===
1056
+ export function registerWfexgovV2Commands(program) {
1057
+ const parent = program.commands.find((c) => c.name() === "workflow");
1058
+ if (!parent) return;
1059
+ const L = async () => await import("../lib/workflow-expr.js");
1060
+ parent
1061
+ .command("wfexgov-enums-v2")
1062
+ .description("Show V2 enums")
1063
+ .action(async () => {
1064
+ const m = await L();
1065
+ console.log(
1066
+ JSON.stringify(
1067
+ {
1068
+ profileMaturity: m.WFEXGOV_PROFILE_MATURITY_V2,
1069
+ evalLifecycle: m.WFEXGOV_EVAL_LIFECYCLE_V2,
1070
+ },
1071
+ null,
1072
+ 2,
1073
+ ),
1074
+ );
1075
+ });
1076
+ parent
1077
+ .command("wfexgov-config-v2")
1078
+ .description("Show V2 config")
1079
+ .action(async () => {
1080
+ const m = await L();
1081
+ console.log(
1082
+ JSON.stringify(
1083
+ {
1084
+ maxActive: m.getMaxActiveWfexgovProfilesPerOwnerV2(),
1085
+ maxPending: m.getMaxPendingWfexgovEvalsPerProfileV2(),
1086
+ idleMs: m.getWfexgovProfileIdleMsV2(),
1087
+ stuckMs: m.getWfexgovEvalStuckMsV2(),
1088
+ },
1089
+ null,
1090
+ 2,
1091
+ ),
1092
+ );
1093
+ });
1094
+ parent
1095
+ .command("wfexgov-set-max-active-v2 <n>")
1096
+ .description("Set max active")
1097
+ .action(async (n) => {
1098
+ (await L()).setMaxActiveWfexgovProfilesPerOwnerV2(Number(n));
1099
+ console.log("ok");
1100
+ });
1101
+ parent
1102
+ .command("wfexgov-set-max-pending-v2 <n>")
1103
+ .description("Set max pending")
1104
+ .action(async (n) => {
1105
+ (await L()).setMaxPendingWfexgovEvalsPerProfileV2(Number(n));
1106
+ console.log("ok");
1107
+ });
1108
+ parent
1109
+ .command("wfexgov-set-idle-ms-v2 <n>")
1110
+ .description("Set idle threshold ms")
1111
+ .action(async (n) => {
1112
+ (await L()).setWfexgovProfileIdleMsV2(Number(n));
1113
+ console.log("ok");
1114
+ });
1115
+ parent
1116
+ .command("wfexgov-set-stuck-ms-v2 <n>")
1117
+ .description("Set stuck threshold ms")
1118
+ .action(async (n) => {
1119
+ (await L()).setWfexgovEvalStuckMsV2(Number(n));
1120
+ console.log("ok");
1121
+ });
1122
+ parent
1123
+ .command("wfexgov-register-v2 <id> <owner>")
1124
+ .description("Register V2 profile")
1125
+ .option("--language <v>", "language")
1126
+ .action(async (id, owner, o) => {
1127
+ const m = await L();
1128
+ console.log(
1129
+ JSON.stringify(
1130
+ m.registerWfexgovProfileV2({ id, owner, language: o.language }),
1131
+ null,
1132
+ 2,
1133
+ ),
1134
+ );
1135
+ });
1136
+ parent
1137
+ .command("wfexgov-activate-v2 <id>")
1138
+ .description("Activate profile")
1139
+ .action(async (id) => {
1140
+ console.log(
1141
+ JSON.stringify((await L()).activateWfexgovProfileV2(id), null, 2),
1142
+ );
1143
+ });
1144
+ parent
1145
+ .command("wfexgov-pause-v2 <id>")
1146
+ .description("Pause profile")
1147
+ .action(async (id) => {
1148
+ console.log(
1149
+ JSON.stringify((await L()).pauseWfexgovProfileV2(id), null, 2),
1150
+ );
1151
+ });
1152
+ parent
1153
+ .command("wfexgov-archive-v2 <id>")
1154
+ .description("Archive profile")
1155
+ .action(async (id) => {
1156
+ console.log(
1157
+ JSON.stringify((await L()).archiveWfexgovProfileV2(id), null, 2),
1158
+ );
1159
+ });
1160
+ parent
1161
+ .command("wfexgov-touch-v2 <id>")
1162
+ .description("Touch profile")
1163
+ .action(async (id) => {
1164
+ console.log(
1165
+ JSON.stringify((await L()).touchWfexgovProfileV2(id), null, 2),
1166
+ );
1167
+ });
1168
+ parent
1169
+ .command("wfexgov-get-v2 <id>")
1170
+ .description("Get profile")
1171
+ .action(async (id) => {
1172
+ console.log(JSON.stringify((await L()).getWfexgovProfileV2(id), null, 2));
1173
+ });
1174
+ parent
1175
+ .command("wfexgov-list-v2")
1176
+ .description("List profiles")
1177
+ .action(async () => {
1178
+ console.log(JSON.stringify((await L()).listWfexgovProfilesV2(), null, 2));
1179
+ });
1180
+ parent
1181
+ .command("wfexgov-create-eval-v2 <id> <profileId>")
1182
+ .description("Create eval")
1183
+ .option("--expression <v>", "expression")
1184
+ .action(async (id, profileId, o) => {
1185
+ const m = await L();
1186
+ console.log(
1187
+ JSON.stringify(
1188
+ m.createWfexgovEvalV2({ id, profileId, expression: o.expression }),
1189
+ null,
1190
+ 2,
1191
+ ),
1192
+ );
1193
+ });
1194
+ parent
1195
+ .command("wfexgov-evaluating-eval-v2 <id>")
1196
+ .description("Mark eval as evaluating")
1197
+ .action(async (id) => {
1198
+ console.log(
1199
+ JSON.stringify((await L()).evaluatingWfexgovEvalV2(id), null, 2),
1200
+ );
1201
+ });
1202
+ parent
1203
+ .command("wfexgov-complete-eval-v2 <id>")
1204
+ .description("Complete eval")
1205
+ .action(async (id) => {
1206
+ console.log(
1207
+ JSON.stringify((await L()).completeEvalWfexgovV2(id), null, 2),
1208
+ );
1209
+ });
1210
+ parent
1211
+ .command("wfexgov-fail-eval-v2 <id> [reason]")
1212
+ .description("Fail eval")
1213
+ .action(async (id, reason) => {
1214
+ console.log(
1215
+ JSON.stringify((await L()).failWfexgovEvalV2(id, reason), null, 2),
1216
+ );
1217
+ });
1218
+ parent
1219
+ .command("wfexgov-cancel-eval-v2 <id> [reason]")
1220
+ .description("Cancel eval")
1221
+ .action(async (id, reason) => {
1222
+ console.log(
1223
+ JSON.stringify((await L()).cancelWfexgovEvalV2(id, reason), null, 2),
1224
+ );
1225
+ });
1226
+ parent
1227
+ .command("wfexgov-get-eval-v2 <id>")
1228
+ .description("Get eval")
1229
+ .action(async (id) => {
1230
+ console.log(JSON.stringify((await L()).getWfexgovEvalV2(id), null, 2));
1231
+ });
1232
+ parent
1233
+ .command("wfexgov-list-evals-v2")
1234
+ .description("List evals")
1235
+ .action(async () => {
1236
+ console.log(JSON.stringify((await L()).listWfexgovEvalsV2(), null, 2));
1237
+ });
1238
+ parent
1239
+ .command("wfexgov-auto-pause-idle-v2")
1240
+ .description("Auto-pause idle")
1241
+ .action(async () => {
1242
+ console.log(
1243
+ JSON.stringify((await L()).autoPauseIdleWfexgovProfilesV2(), null, 2),
1244
+ );
1245
+ });
1246
+ parent
1247
+ .command("wfexgov-auto-fail-stuck-v2")
1248
+ .description("Auto-fail stuck evals")
1249
+ .action(async () => {
1250
+ console.log(
1251
+ JSON.stringify((await L()).autoFailStuckWfexgovEvalsV2(), null, 2),
1252
+ );
1253
+ });
1254
+ parent
1255
+ .command("wfexgov-gov-stats-v2")
1256
+ .description("V2 gov stats")
1257
+ .action(async () => {
1258
+ console.log(
1259
+ JSON.stringify((await L()).getWorkflowExprGovStatsV2(), null, 2),
1260
+ );
1261
+ });
1262
+ }
package/src/index.js CHANGED
@@ -299,6 +299,62 @@ import { registerDevgovV2Commands } from "./commands/dev.js";
299
299
  import { registerTigovV2Commands } from "./commands/compliance.js";
300
300
  import { registerUebgovV2Commands } from "./commands/compliance.js";
301
301
 
302
+ // Iter25 V2 governance overlays
303
+ import { registerCttgovV2Commands } from "./commands/cowork.js";
304
+ import { registerCtmgovV2Commands } from "./commands/cowork.js";
305
+ import { registerClibgovV2Commands } from "./commands/cli-anything.js";
306
+ import { registerArgovV2Commands } from "./commands/orchestrate.js";
307
+ import { registerSaregovV2Commands } from "./commands/agent.js";
308
+ import { registerTodogovV2Commands } from "./commands/agent.js";
309
+ import { registerEbgovV2Commands } from "./commands/agent.js";
310
+ import { registerEvfedgovV2Commands } from "./commands/evomap.js";
311
+
312
+ // Iter26 V2 governance overlays
313
+ import { registerPlannergovV2Commands } from "./commands/planmode.js";
314
+ import { registerCtxenggovV2Commands } from "./commands/cli-anything.js";
315
+ import { registerSactxgovV2Commands } from "./commands/agent.js";
316
+ import { registerIagovV2Commands } from "./commands/chat.js";
317
+ import { registerWfexgovV2Commands } from "./commands/workflow.js";
318
+ import { registerPadgovV2Commands } from "./commands/plugin.js";
319
+ import { registerHlgovV2Commands } from "./commands/memory.js";
320
+ import { registerWebuigovV2Commands } from "./commands/ui.js";
321
+
322
+ // Iter27 V2 governance overlays
323
+ import { registerDlgovV2Commands } from "./commands/setup.js";
324
+ import { registerSmcpgovV2Commands } from "./commands/skill.js";
325
+ import { registerCmcpgovV2Commands } from "./commands/cowork.js";
326
+ import { registerStixgovV2Commands } from "./commands/compliance.js";
327
+ import { registerSapgovV2Commands } from "./commands/agent.js";
328
+ import { registerCobsgovV2Commands } from "./commands/cowork.js";
329
+ import { registerPmgrgovV2Commands } from "./commands/start.js";
330
+ import { registerWscgovV2Commands } from "./commands/chat.js";
331
+ import { registerEvcligovV2Commands } from "./commands/evomap.js";
332
+ import { registerPoptgovV2Commands } from "./commands/llm.js";
333
+ import { registerScsgovV2Commands } from "./commands/config.js";
334
+ import { registerSmgrgovV2Commands } from "./commands/services.js";
335
+ import { registerCeadgovV2Commands } from "./commands/cowork.js";
336
+ import { registerPstrmgovV2Commands } from "./commands/stream.js";
337
+ import { registerCohtgovV2Commands } from "./commands/cowork.js";
338
+ import { registerCadpgovV2Commands } from "./commands/cowork.js";
339
+
340
+ // Iter28 V2 governance overlays
341
+ import { registerA2apV2Commands } from "./commands/a2a.js";
342
+ import { registerAcrdV2Commands } from "./commands/orchestrate.js";
343
+ import { registerAecoV2Commands } from "./commands/economy.js";
344
+ import { registerAutagV2Commands } from "./commands/agent.js";
345
+ import { registerCcoreV2Commands } from "./commands/chat.js";
346
+ import { registerCmpmV2Commands } from "./commands/compliance.js";
347
+ import { registerCrchV2Commands } from "./commands/crosschain.js";
348
+ import { registerCryV2Commands } from "./commands/encrypt.js";
349
+ import { registerDaomV2Commands } from "./commands/dao.js";
350
+ import { registerEsysV2Commands } from "./commands/evolution.js";
351
+ import { registerEmgrV2Commands } from "./commands/evomap.js";
352
+ import { registerHmemV2Commands } from "./commands/hmemory.js";
353
+ import { registerInfnetV2Commands } from "./commands/inference.js";
354
+ import { registerKgV2Commands } from "./commands/kg.js";
355
+ import { registerPmodeV2Commands } from "./commands/planmode.js";
356
+ import { registerPipoV2Commands } from "./commands/pipeline.js";
357
+
302
358
  export function createProgram() {
303
359
  const program = new Command();
304
360
 
@@ -608,5 +664,61 @@ export function createProgram() {
608
664
  registerTigovV2Commands(program);
609
665
  registerUebgovV2Commands(program);
610
666
 
667
+ // Iter25 V2 governance overlays
668
+ registerCttgovV2Commands(program);
669
+ registerCtmgovV2Commands(program);
670
+ registerClibgovV2Commands(program);
671
+ registerArgovV2Commands(program);
672
+ registerSaregovV2Commands(program);
673
+ registerTodogovV2Commands(program);
674
+ registerEbgovV2Commands(program);
675
+ registerEvfedgovV2Commands(program);
676
+
677
+ // Iter26 V2 governance overlays
678
+ registerPlannergovV2Commands(program);
679
+ registerCtxenggovV2Commands(program);
680
+ registerSactxgovV2Commands(program);
681
+ registerIagovV2Commands(program);
682
+ registerWfexgovV2Commands(program);
683
+ registerPadgovV2Commands(program);
684
+ registerHlgovV2Commands(program);
685
+ registerWebuigovV2Commands(program);
686
+
687
+ // Iter27 V2 governance overlays
688
+ registerDlgovV2Commands(program);
689
+ registerSmcpgovV2Commands(program);
690
+ registerCmcpgovV2Commands(program);
691
+ registerStixgovV2Commands(program);
692
+ registerSapgovV2Commands(program);
693
+ registerCobsgovV2Commands(program);
694
+ registerPmgrgovV2Commands(program);
695
+ registerWscgovV2Commands(program);
696
+ registerEvcligovV2Commands(program);
697
+ registerPoptgovV2Commands(program);
698
+ registerScsgovV2Commands(program);
699
+ registerSmgrgovV2Commands(program);
700
+ registerCeadgovV2Commands(program);
701
+ registerPstrmgovV2Commands(program);
702
+ registerCohtgovV2Commands(program);
703
+ registerCadpgovV2Commands(program);
704
+
705
+ // Iter28 V2 governance overlays
706
+ registerA2apV2Commands(program);
707
+ registerAcrdV2Commands(program);
708
+ registerAecoV2Commands(program);
709
+ registerAutagV2Commands(program);
710
+ registerCcoreV2Commands(program);
711
+ registerCmpmV2Commands(program);
712
+ registerCrchV2Commands(program);
713
+ registerCryV2Commands(program);
714
+ registerDaomV2Commands(program);
715
+ registerEsysV2Commands(program);
716
+ registerEmgrV2Commands(program);
717
+ registerHmemV2Commands(program);
718
+ registerInfnetV2Commands(program);
719
+ registerKgV2Commands(program);
720
+ registerPmodeV2Commands(program);
721
+ registerPipoV2Commands(program);
722
+
611
723
  return program;
612
724
  }
@@ -1193,3 +1193,335 @@ export function getA2aProtocolGovStatsV2() {
1193
1193
  messagesByStatus,
1194
1194
  };
1195
1195
  }
1196
+
1197
+ // === Iter28 V2 governance overlay: A2apgov ===
1198
+ export const A2APGOV_PROFILE_MATURITY_V2 = Object.freeze({
1199
+ PENDING: "pending",
1200
+ ACTIVE: "active",
1201
+ STALE: "stale",
1202
+ ARCHIVED: "archived",
1203
+ });
1204
+ export const A2APGOV_MSG_LIFECYCLE_V2 = Object.freeze({
1205
+ QUEUED: "queued",
1206
+ DISPATCHING: "dispatching",
1207
+ DELIVERED: "delivered",
1208
+ FAILED: "failed",
1209
+ CANCELLED: "cancelled",
1210
+ });
1211
+ const _a2apgovPTrans = new Map([
1212
+ [
1213
+ A2APGOV_PROFILE_MATURITY_V2.PENDING,
1214
+ new Set([
1215
+ A2APGOV_PROFILE_MATURITY_V2.ACTIVE,
1216
+ A2APGOV_PROFILE_MATURITY_V2.ARCHIVED,
1217
+ ]),
1218
+ ],
1219
+ [
1220
+ A2APGOV_PROFILE_MATURITY_V2.ACTIVE,
1221
+ new Set([
1222
+ A2APGOV_PROFILE_MATURITY_V2.STALE,
1223
+ A2APGOV_PROFILE_MATURITY_V2.ARCHIVED,
1224
+ ]),
1225
+ ],
1226
+ [
1227
+ A2APGOV_PROFILE_MATURITY_V2.STALE,
1228
+ new Set([
1229
+ A2APGOV_PROFILE_MATURITY_V2.ACTIVE,
1230
+ A2APGOV_PROFILE_MATURITY_V2.ARCHIVED,
1231
+ ]),
1232
+ ],
1233
+ [A2APGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1234
+ ]);
1235
+ const _a2apgovPTerminal = new Set([A2APGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1236
+ const _a2apgovJTrans = new Map([
1237
+ [
1238
+ A2APGOV_MSG_LIFECYCLE_V2.QUEUED,
1239
+ new Set([
1240
+ A2APGOV_MSG_LIFECYCLE_V2.DISPATCHING,
1241
+ A2APGOV_MSG_LIFECYCLE_V2.CANCELLED,
1242
+ ]),
1243
+ ],
1244
+ [
1245
+ A2APGOV_MSG_LIFECYCLE_V2.DISPATCHING,
1246
+ new Set([
1247
+ A2APGOV_MSG_LIFECYCLE_V2.DELIVERED,
1248
+ A2APGOV_MSG_LIFECYCLE_V2.FAILED,
1249
+ A2APGOV_MSG_LIFECYCLE_V2.CANCELLED,
1250
+ ]),
1251
+ ],
1252
+ [A2APGOV_MSG_LIFECYCLE_V2.DELIVERED, new Set()],
1253
+ [A2APGOV_MSG_LIFECYCLE_V2.FAILED, new Set()],
1254
+ [A2APGOV_MSG_LIFECYCLE_V2.CANCELLED, new Set()],
1255
+ ]);
1256
+ const _a2apgovPsV2 = new Map();
1257
+ const _a2apgovJsV2 = new Map();
1258
+ let _a2apgovMaxActive = 8,
1259
+ _a2apgovMaxPending = 20,
1260
+ _a2apgovIdleMs = 2592000000,
1261
+ _a2apgovStuckMs = 60 * 1000;
1262
+ function _a2apgovPos(n, label) {
1263
+ const v = Math.floor(Number(n));
1264
+ if (!Number.isFinite(v) || v <= 0)
1265
+ throw new Error(`${label} must be positive integer`);
1266
+ return v;
1267
+ }
1268
+ function _a2apgovCheckP(from, to) {
1269
+ const a = _a2apgovPTrans.get(from);
1270
+ if (!a || !a.has(to))
1271
+ throw new Error(`invalid a2apgov profile transition ${from} → ${to}`);
1272
+ }
1273
+ function _a2apgovCheckJ(from, to) {
1274
+ const a = _a2apgovJTrans.get(from);
1275
+ if (!a || !a.has(to))
1276
+ throw new Error(`invalid a2apgov msg transition ${from} → ${to}`);
1277
+ }
1278
+ function _a2apgovCountActive(owner) {
1279
+ let c = 0;
1280
+ for (const p of _a2apgovPsV2.values())
1281
+ if (p.owner === owner && p.status === A2APGOV_PROFILE_MATURITY_V2.ACTIVE)
1282
+ c++;
1283
+ return c;
1284
+ }
1285
+ function _a2apgovCountPending(profileId) {
1286
+ let c = 0;
1287
+ for (const j of _a2apgovJsV2.values())
1288
+ if (
1289
+ j.profileId === profileId &&
1290
+ (j.status === A2APGOV_MSG_LIFECYCLE_V2.QUEUED ||
1291
+ j.status === A2APGOV_MSG_LIFECYCLE_V2.DISPATCHING)
1292
+ )
1293
+ c++;
1294
+ return c;
1295
+ }
1296
+ export function setMaxActiveA2apProfilesPerOwnerV2(n) {
1297
+ _a2apgovMaxActive = _a2apgovPos(n, "maxActiveA2apProfilesPerOwner");
1298
+ }
1299
+ export function getMaxActiveA2apProfilesPerOwnerV2() {
1300
+ return _a2apgovMaxActive;
1301
+ }
1302
+ export function setMaxPendingA2apMsgsPerProfileV2(n) {
1303
+ _a2apgovMaxPending = _a2apgovPos(n, "maxPendingA2apMsgsPerProfile");
1304
+ }
1305
+ export function getMaxPendingA2apMsgsPerProfileV2() {
1306
+ return _a2apgovMaxPending;
1307
+ }
1308
+ export function setA2apProfileIdleMsV2(n) {
1309
+ _a2apgovIdleMs = _a2apgovPos(n, "a2apgovProfileIdleMs");
1310
+ }
1311
+ export function getA2apProfileIdleMsV2() {
1312
+ return _a2apgovIdleMs;
1313
+ }
1314
+ export function setA2apMsgStuckMsV2(n) {
1315
+ _a2apgovStuckMs = _a2apgovPos(n, "a2apgovMsgStuckMs");
1316
+ }
1317
+ export function getA2apMsgStuckMsV2() {
1318
+ return _a2apgovStuckMs;
1319
+ }
1320
+ export function _resetStateA2apgovV2() {
1321
+ _a2apgovPsV2.clear();
1322
+ _a2apgovJsV2.clear();
1323
+ _a2apgovMaxActive = 8;
1324
+ _a2apgovMaxPending = 20;
1325
+ _a2apgovIdleMs = 2592000000;
1326
+ _a2apgovStuckMs = 60 * 1000;
1327
+ }
1328
+ export function registerA2apProfileV2({ id, owner, endpoint, metadata } = {}) {
1329
+ if (!id || !owner) throw new Error("id and owner required");
1330
+ if (_a2apgovPsV2.has(id))
1331
+ throw new Error(`a2apgov profile ${id} already exists`);
1332
+ const now = Date.now();
1333
+ const p = {
1334
+ id,
1335
+ owner,
1336
+ endpoint: endpoint || "default",
1337
+ status: A2APGOV_PROFILE_MATURITY_V2.PENDING,
1338
+ createdAt: now,
1339
+ updatedAt: now,
1340
+ lastTouchedAt: now,
1341
+ activatedAt: null,
1342
+ archivedAt: null,
1343
+ metadata: { ...(metadata || {}) },
1344
+ };
1345
+ _a2apgovPsV2.set(id, p);
1346
+ return { ...p, metadata: { ...p.metadata } };
1347
+ }
1348
+ export function activateA2apProfileV2(id) {
1349
+ const p = _a2apgovPsV2.get(id);
1350
+ if (!p) throw new Error(`a2apgov profile ${id} not found`);
1351
+ const isInitial = p.status === A2APGOV_PROFILE_MATURITY_V2.PENDING;
1352
+ _a2apgovCheckP(p.status, A2APGOV_PROFILE_MATURITY_V2.ACTIVE);
1353
+ if (isInitial && _a2apgovCountActive(p.owner) >= _a2apgovMaxActive)
1354
+ throw new Error(`max active a2apgov profiles for owner ${p.owner} reached`);
1355
+ const now = Date.now();
1356
+ p.status = A2APGOV_PROFILE_MATURITY_V2.ACTIVE;
1357
+ p.updatedAt = now;
1358
+ p.lastTouchedAt = now;
1359
+ if (!p.activatedAt) p.activatedAt = now;
1360
+ return { ...p, metadata: { ...p.metadata } };
1361
+ }
1362
+ export function staleA2apProfileV2(id) {
1363
+ const p = _a2apgovPsV2.get(id);
1364
+ if (!p) throw new Error(`a2apgov profile ${id} not found`);
1365
+ _a2apgovCheckP(p.status, A2APGOV_PROFILE_MATURITY_V2.STALE);
1366
+ p.status = A2APGOV_PROFILE_MATURITY_V2.STALE;
1367
+ p.updatedAt = Date.now();
1368
+ return { ...p, metadata: { ...p.metadata } };
1369
+ }
1370
+ export function archiveA2apProfileV2(id) {
1371
+ const p = _a2apgovPsV2.get(id);
1372
+ if (!p) throw new Error(`a2apgov profile ${id} not found`);
1373
+ _a2apgovCheckP(p.status, A2APGOV_PROFILE_MATURITY_V2.ARCHIVED);
1374
+ const now = Date.now();
1375
+ p.status = A2APGOV_PROFILE_MATURITY_V2.ARCHIVED;
1376
+ p.updatedAt = now;
1377
+ if (!p.archivedAt) p.archivedAt = now;
1378
+ return { ...p, metadata: { ...p.metadata } };
1379
+ }
1380
+ export function touchA2apProfileV2(id) {
1381
+ const p = _a2apgovPsV2.get(id);
1382
+ if (!p) throw new Error(`a2apgov profile ${id} not found`);
1383
+ if (_a2apgovPTerminal.has(p.status))
1384
+ throw new Error(`cannot touch terminal a2apgov profile ${id}`);
1385
+ const now = Date.now();
1386
+ p.lastTouchedAt = now;
1387
+ p.updatedAt = now;
1388
+ return { ...p, metadata: { ...p.metadata } };
1389
+ }
1390
+ export function getA2apProfileV2(id) {
1391
+ const p = _a2apgovPsV2.get(id);
1392
+ if (!p) return null;
1393
+ return { ...p, metadata: { ...p.metadata } };
1394
+ }
1395
+ export function listA2apProfilesV2() {
1396
+ return [..._a2apgovPsV2.values()].map((p) => ({
1397
+ ...p,
1398
+ metadata: { ...p.metadata },
1399
+ }));
1400
+ }
1401
+ export function createA2apMsgV2({ id, profileId, messageId, metadata } = {}) {
1402
+ if (!id || !profileId) throw new Error("id and profileId required");
1403
+ if (_a2apgovJsV2.has(id)) throw new Error(`a2apgov msg ${id} already exists`);
1404
+ if (!_a2apgovPsV2.has(profileId))
1405
+ throw new Error(`a2apgov profile ${profileId} not found`);
1406
+ if (_a2apgovCountPending(profileId) >= _a2apgovMaxPending)
1407
+ throw new Error(
1408
+ `max pending a2apgov msgs for profile ${profileId} reached`,
1409
+ );
1410
+ const now = Date.now();
1411
+ const j = {
1412
+ id,
1413
+ profileId,
1414
+ messageId: messageId || "",
1415
+ status: A2APGOV_MSG_LIFECYCLE_V2.QUEUED,
1416
+ createdAt: now,
1417
+ updatedAt: now,
1418
+ startedAt: null,
1419
+ settledAt: null,
1420
+ metadata: { ...(metadata || {}) },
1421
+ };
1422
+ _a2apgovJsV2.set(id, j);
1423
+ return { ...j, metadata: { ...j.metadata } };
1424
+ }
1425
+ export function dispatchingA2apMsgV2(id) {
1426
+ const j = _a2apgovJsV2.get(id);
1427
+ if (!j) throw new Error(`a2apgov msg ${id} not found`);
1428
+ _a2apgovCheckJ(j.status, A2APGOV_MSG_LIFECYCLE_V2.DISPATCHING);
1429
+ const now = Date.now();
1430
+ j.status = A2APGOV_MSG_LIFECYCLE_V2.DISPATCHING;
1431
+ j.updatedAt = now;
1432
+ if (!j.startedAt) j.startedAt = now;
1433
+ return { ...j, metadata: { ...j.metadata } };
1434
+ }
1435
+ export function completeMsgA2apV2(id) {
1436
+ const j = _a2apgovJsV2.get(id);
1437
+ if (!j) throw new Error(`a2apgov msg ${id} not found`);
1438
+ _a2apgovCheckJ(j.status, A2APGOV_MSG_LIFECYCLE_V2.DELIVERED);
1439
+ const now = Date.now();
1440
+ j.status = A2APGOV_MSG_LIFECYCLE_V2.DELIVERED;
1441
+ j.updatedAt = now;
1442
+ if (!j.settledAt) j.settledAt = now;
1443
+ return { ...j, metadata: { ...j.metadata } };
1444
+ }
1445
+ export function failA2apMsgV2(id, reason) {
1446
+ const j = _a2apgovJsV2.get(id);
1447
+ if (!j) throw new Error(`a2apgov msg ${id} not found`);
1448
+ _a2apgovCheckJ(j.status, A2APGOV_MSG_LIFECYCLE_V2.FAILED);
1449
+ const now = Date.now();
1450
+ j.status = A2APGOV_MSG_LIFECYCLE_V2.FAILED;
1451
+ j.updatedAt = now;
1452
+ if (!j.settledAt) j.settledAt = now;
1453
+ if (reason) j.metadata.failReason = String(reason);
1454
+ return { ...j, metadata: { ...j.metadata } };
1455
+ }
1456
+ export function cancelA2apMsgV2(id, reason) {
1457
+ const j = _a2apgovJsV2.get(id);
1458
+ if (!j) throw new Error(`a2apgov msg ${id} not found`);
1459
+ _a2apgovCheckJ(j.status, A2APGOV_MSG_LIFECYCLE_V2.CANCELLED);
1460
+ const now = Date.now();
1461
+ j.status = A2APGOV_MSG_LIFECYCLE_V2.CANCELLED;
1462
+ j.updatedAt = now;
1463
+ if (!j.settledAt) j.settledAt = now;
1464
+ if (reason) j.metadata.cancelReason = String(reason);
1465
+ return { ...j, metadata: { ...j.metadata } };
1466
+ }
1467
+ export function getA2apMsgV2(id) {
1468
+ const j = _a2apgovJsV2.get(id);
1469
+ if (!j) return null;
1470
+ return { ...j, metadata: { ...j.metadata } };
1471
+ }
1472
+ export function listA2apMsgsV2() {
1473
+ return [..._a2apgovJsV2.values()].map((j) => ({
1474
+ ...j,
1475
+ metadata: { ...j.metadata },
1476
+ }));
1477
+ }
1478
+ export function autoStaleIdleA2apProfilesV2({ now } = {}) {
1479
+ const t = now ?? Date.now();
1480
+ const flipped = [];
1481
+ for (const p of _a2apgovPsV2.values())
1482
+ if (
1483
+ p.status === A2APGOV_PROFILE_MATURITY_V2.ACTIVE &&
1484
+ t - p.lastTouchedAt >= _a2apgovIdleMs
1485
+ ) {
1486
+ p.status = A2APGOV_PROFILE_MATURITY_V2.STALE;
1487
+ p.updatedAt = t;
1488
+ flipped.push(p.id);
1489
+ }
1490
+ return { flipped, count: flipped.length };
1491
+ }
1492
+ export function autoFailStuckA2apMsgsV2({ now } = {}) {
1493
+ const t = now ?? Date.now();
1494
+ const flipped = [];
1495
+ for (const j of _a2apgovJsV2.values())
1496
+ if (
1497
+ j.status === A2APGOV_MSG_LIFECYCLE_V2.DISPATCHING &&
1498
+ j.startedAt != null &&
1499
+ t - j.startedAt >= _a2apgovStuckMs
1500
+ ) {
1501
+ j.status = A2APGOV_MSG_LIFECYCLE_V2.FAILED;
1502
+ j.updatedAt = t;
1503
+ if (!j.settledAt) j.settledAt = t;
1504
+ j.metadata.failReason = "auto-fail-stuck";
1505
+ flipped.push(j.id);
1506
+ }
1507
+ return { flipped, count: flipped.length };
1508
+ }
1509
+ export function getA2apgovStatsV2() {
1510
+ const profilesByStatus = {};
1511
+ for (const v of Object.values(A2APGOV_PROFILE_MATURITY_V2))
1512
+ profilesByStatus[v] = 0;
1513
+ for (const p of _a2apgovPsV2.values()) profilesByStatus[p.status]++;
1514
+ const msgsByStatus = {};
1515
+ for (const v of Object.values(A2APGOV_MSG_LIFECYCLE_V2)) msgsByStatus[v] = 0;
1516
+ for (const j of _a2apgovJsV2.values()) msgsByStatus[j.status]++;
1517
+ return {
1518
+ totalA2apProfilesV2: _a2apgovPsV2.size,
1519
+ totalA2apMsgsV2: _a2apgovJsV2.size,
1520
+ maxActiveA2apProfilesPerOwner: _a2apgovMaxActive,
1521
+ maxPendingA2apMsgsPerProfile: _a2apgovMaxPending,
1522
+ a2apgovProfileIdleMs: _a2apgovIdleMs,
1523
+ a2apgovMsgStuckMs: _a2apgovStuckMs,
1524
+ profilesByStatus,
1525
+ msgsByStatus,
1526
+ };
1527
+ }