chainlesschain 0.143.0 → 0.152.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +364 -27
  4. package/src/commands/agent-network.js +217 -0
  5. package/src/commands/agent.js +587 -103
  6. package/src/commands/audit.js +206 -0
  7. package/src/commands/automation.js +201 -0
  8. package/src/commands/bi.js +355 -27
  9. package/src/commands/bm25.js +111 -27
  10. package/src/commands/browse.js +403 -29
  11. package/src/commands/ccron.js +128 -28
  12. package/src/commands/chat.js +207 -0
  13. package/src/commands/codegen.js +207 -0
  14. package/src/commands/collab.js +211 -0
  15. package/src/commands/compliance.js +824 -34
  16. package/src/commands/compt.js +127 -29
  17. package/src/commands/consol.js +8 -2
  18. package/src/commands/cowork.js +783 -34
  19. package/src/commands/crosschain.js +182 -28
  20. package/src/commands/dao.js +182 -28
  21. package/src/commands/dbevo.js +227 -0
  22. package/src/commands/dev.js +207 -0
  23. package/src/commands/did-v2.js +217 -0
  24. package/src/commands/did.js +221 -0
  25. package/src/commands/dlp.js +385 -27
  26. package/src/commands/economy.js +205 -50
  27. package/src/commands/evolution.js +203 -50
  28. package/src/commands/evomap.js +387 -27
  29. package/src/commands/export.js +213 -0
  30. package/src/commands/federation.js +209 -0
  31. package/src/commands/fflag.js +74 -22
  32. package/src/commands/fusion.js +205 -0
  33. package/src/commands/git.js +177 -37
  34. package/src/commands/governance.js +209 -0
  35. package/src/commands/hardening.js +209 -0
  36. package/src/commands/hmemory.js +204 -50
  37. package/src/commands/hook.js +209 -0
  38. package/src/commands/import.js +209 -0
  39. package/src/commands/incentive.js +209 -0
  40. package/src/commands/inference.js +170 -34
  41. package/src/commands/infra.js +203 -0
  42. package/src/commands/instinct.js +209 -0
  43. package/src/commands/ipfs.js +207 -0
  44. package/src/commands/itbudget.js +149 -33
  45. package/src/commands/kg.js +206 -0
  46. package/src/commands/llm.js +217 -0
  47. package/src/commands/lowcode.js +195 -38
  48. package/src/commands/marketplace.js +206 -0
  49. package/src/commands/matrix.js +386 -27
  50. package/src/commands/mcp.js +217 -0
  51. package/src/commands/mcpscaf.js +145 -33
  52. package/src/commands/meminj.js +145 -33
  53. package/src/commands/memory.js +209 -0
  54. package/src/commands/multimodal.js +203 -0
  55. package/src/commands/nlprog.js +225 -0
  56. package/src/commands/nostr.js +387 -27
  57. package/src/commands/note.js +205 -0
  58. package/src/commands/ops.js +219 -0
  59. package/src/commands/orchestrate.js +217 -0
  60. package/src/commands/orchgov.js +144 -33
  61. package/src/commands/org.js +209 -0
  62. package/src/commands/p2p.js +209 -0
  63. package/src/commands/pdfp.js +109 -27
  64. package/src/commands/perception.js +209 -0
  65. package/src/commands/perf.js +169 -32
  66. package/src/commands/perm.js +144 -33
  67. package/src/commands/permmem.js +203 -0
  68. package/src/commands/pipeline.js +207 -52
  69. package/src/commands/planmode.js +141 -32
  70. package/src/commands/plugin-ecosystem.js +209 -0
  71. package/src/commands/pqc.js +213 -0
  72. package/src/commands/privacy.js +203 -0
  73. package/src/commands/promcomp.js +111 -27
  74. package/src/commands/quantization.js +207 -0
  75. package/src/commands/rcache.js +205 -0
  76. package/src/commands/recommend.js +410 -34
  77. package/src/commands/reputation.js +208 -0
  78. package/src/commands/runtime.js +205 -0
  79. package/src/commands/sandbox.js +206 -0
  80. package/src/commands/scim.js +209 -0
  81. package/src/commands/seshhook.js +145 -33
  82. package/src/commands/seshsearch.js +141 -33
  83. package/src/commands/seshtail.js +144 -33
  84. package/src/commands/seshu.js +152 -33
  85. package/src/commands/session.js +209 -0
  86. package/src/commands/sganal.js +123 -29
  87. package/src/commands/siem.js +201 -34
  88. package/src/commands/skill.js +207 -0
  89. package/src/commands/sla.js +212 -0
  90. package/src/commands/slotfill.js +146 -33
  91. package/src/commands/social.js +358 -32
  92. package/src/commands/sso.js +209 -0
  93. package/src/commands/stress.js +206 -0
  94. package/src/commands/svccont.js +145 -33
  95. package/src/commands/sync.js +209 -0
  96. package/src/commands/tech.js +209 -0
  97. package/src/commands/tenant.js +217 -0
  98. package/src/commands/terraform.js +206 -0
  99. package/src/commands/tms.js +171 -33
  100. package/src/commands/tokens.js +209 -0
  101. package/src/commands/topiccls.js +146 -33
  102. package/src/commands/trust.js +217 -0
  103. package/src/commands/uprof.js +141 -32
  104. package/src/commands/vcheck.js +122 -28
  105. package/src/commands/wallet.js +209 -0
  106. package/src/commands/webfetch.js +141 -32
  107. package/src/commands/workflow.js +203 -0
  108. package/src/commands/zkp.js +184 -28
  109. package/src/index.js +180 -0
  110. package/src/lib/a2a-protocol.js +319 -51
  111. package/src/lib/activitypub-bridge.js +622 -50
  112. package/src/lib/agent-economy.js +304 -51
  113. package/src/lib/agent-network.js +341 -0
  114. package/src/lib/aiops.js +346 -0
  115. package/src/lib/app-builder.js +279 -46
  116. package/src/lib/audit-logger.js +321 -0
  117. package/src/lib/automation-engine.js +335 -0
  118. package/src/lib/autonomous-agent.js +284 -48
  119. package/src/lib/autonomous-developer.js +332 -0
  120. package/src/lib/bi-engine.js +616 -49
  121. package/src/lib/bm25-search.js +301 -49
  122. package/src/lib/browser-automation.js +630 -49
  123. package/src/lib/chat-core.js +336 -0
  124. package/src/lib/claude-code-bridge.js +341 -0
  125. package/src/lib/code-agent.js +339 -0
  126. package/src/lib/collaboration-governance.js +334 -0
  127. package/src/lib/community-governance.js +346 -0
  128. package/src/lib/compliance-framework-reporter.js +305 -51
  129. package/src/lib/compliance-manager.js +330 -0
  130. package/src/lib/compression-telemetry.js +301 -49
  131. package/src/lib/content-recommendation.js +351 -0
  132. package/src/lib/content-recommender.js +317 -52
  133. package/src/lib/cowork-cron.js +298 -49
  134. package/src/lib/cowork-learning.js +333 -0
  135. package/src/lib/cowork-share.js +338 -0
  136. package/src/lib/cowork-task-runner.js +308 -51
  137. package/src/lib/cowork-workflow.js +327 -0
  138. package/src/lib/cross-chain.js +311 -51
  139. package/src/lib/dao-governance.js +280 -46
  140. package/src/lib/dbevo.js +351 -0
  141. package/src/lib/decentral-infra.js +330 -0
  142. package/src/lib/did-manager.js +341 -0
  143. package/src/lib/did-v2-manager.js +341 -0
  144. package/src/lib/dlp-engine.js +626 -49
  145. package/src/lib/evolution-system.js +278 -47
  146. package/src/lib/evomap-governance.js +334 -0
  147. package/src/lib/evomap-manager.js +280 -46
  148. package/src/lib/execution-backend.js +294 -48
  149. package/src/lib/feature-flags.js +294 -49
  150. package/src/lib/federation-hardening.js +340 -0
  151. package/src/lib/git-integration.js +285 -47
  152. package/src/lib/hardening-manager.js +341 -0
  153. package/src/lib/hierarchical-memory.js +284 -48
  154. package/src/lib/hook-manager.js +341 -0
  155. package/src/lib/inference-network.js +308 -51
  156. package/src/lib/instinct-manager.js +346 -0
  157. package/src/lib/ipfs-storage.js +334 -0
  158. package/src/lib/iteration-budget.js +302 -50
  159. package/src/lib/knowledge-exporter.js +341 -0
  160. package/src/lib/knowledge-graph.js +333 -0
  161. package/src/lib/knowledge-importer.js +341 -0
  162. package/src/lib/llm-providers.js +346 -0
  163. package/src/lib/matrix-bridge.js +620 -47
  164. package/src/lib/mcp-registry.js +346 -0
  165. package/src/lib/mcp-scaffold.js +318 -54
  166. package/src/lib/memory-injection.js +288 -49
  167. package/src/lib/memory-manager.js +336 -0
  168. package/src/lib/multimodal.js +330 -0
  169. package/src/lib/nl-programming.js +341 -0
  170. package/src/lib/nostr-bridge.js +622 -49
  171. package/src/lib/note-versioning.js +339 -0
  172. package/src/lib/orchestrator.js +293 -48
  173. package/src/lib/org-manager.js +336 -0
  174. package/src/lib/p2p-manager.js +341 -0
  175. package/src/lib/pdf-parser.js +298 -49
  176. package/src/lib/perception.js +346 -0
  177. package/src/lib/perf-tuning.js +309 -50
  178. package/src/lib/permanent-memory.js +327 -0
  179. package/src/lib/permission-engine.js +287 -49
  180. package/src/lib/pipeline-orchestrator.js +289 -49
  181. package/src/lib/plan-mode.js +298 -51
  182. package/src/lib/plugin-ecosystem.js +346 -0
  183. package/src/lib/pqc-manager.js +346 -0
  184. package/src/lib/privacy-computing.js +335 -0
  185. package/src/lib/protocol-fusion.js +338 -0
  186. package/src/lib/quantization.js +337 -0
  187. package/src/lib/reputation-optimizer.js +340 -0
  188. package/src/lib/response-cache.js +333 -0
  189. package/src/lib/sandbox-v2.js +327 -0
  190. package/src/lib/scim-manager.js +346 -0
  191. package/src/lib/service-container.js +313 -52
  192. package/src/lib/session-consolidator.js +296 -49
  193. package/src/lib/session-hooks.js +312 -53
  194. package/src/lib/session-manager.js +334 -0
  195. package/src/lib/session-search.js +304 -51
  196. package/src/lib/session-tail.js +288 -49
  197. package/src/lib/session-usage.js +298 -52
  198. package/src/lib/siem-exporter.js +298 -51
  199. package/src/lib/skill-loader.js +334 -0
  200. package/src/lib/skill-marketplace.js +345 -0
  201. package/src/lib/sla-manager.js +341 -0
  202. package/src/lib/slot-filler.js +303 -51
  203. package/src/lib/social-graph-analytics.js +295 -49
  204. package/src/lib/social-graph.js +272 -49
  205. package/src/lib/social-manager.js +330 -0
  206. package/src/lib/sso-manager.js +340 -0
  207. package/src/lib/stress-tester.js +342 -0
  208. package/src/lib/sub-agent-registry.js +302 -53
  209. package/src/lib/sync-manager.js +336 -0
  210. package/src/lib/task-model-selector.js +302 -50
  211. package/src/lib/tech-learning-engine.js +341 -0
  212. package/src/lib/tenant-saas.js +341 -0
  213. package/src/lib/terraform-manager.js +333 -0
  214. package/src/lib/threat-intel.js +330 -0
  215. package/src/lib/todo-manager.js +281 -47
  216. package/src/lib/token-incentive.js +341 -0
  217. package/src/lib/token-tracker.js +336 -0
  218. package/src/lib/topic-classifier.js +297 -49
  219. package/src/lib/trust-security.js +343 -0
  220. package/src/lib/ueba.js +340 -0
  221. package/src/lib/universal-runtime.js +330 -0
  222. package/src/lib/user-profile.js +294 -50
  223. package/src/lib/version-checker.js +304 -50
  224. package/src/lib/wallet-manager.js +336 -0
  225. package/src/lib/web-fetch.js +292 -51
  226. package/src/lib/workflow-engine.js +330 -0
  227. package/src/lib/zkp-engine.js +286 -49
@@ -821,25 +821,53 @@ export function _resetV2State() {
821
821
 
822
822
  export { _v2Tasks, _v2Cards, _v2TypedSubs };
823
823
 
824
-
825
824
  // ===== V2 Surface: A2A Protocol governance overlay (CLI v0.136.0) =====
826
825
  export const A2A_AGENT_MATURITY_V2 = Object.freeze({
827
- PENDING: "pending", ACTIVE: "active", SUSPENDED: "suspended", RETIRED: "retired",
826
+ PENDING: "pending",
827
+ ACTIVE: "active",
828
+ SUSPENDED: "suspended",
829
+ RETIRED: "retired",
828
830
  });
829
831
  export const A2A_MESSAGE_LIFECYCLE_V2 = Object.freeze({
830
- QUEUED: "queued", SENDING: "sending", DELIVERED: "delivered", FAILED: "failed", CANCELLED: "cancelled",
832
+ QUEUED: "queued",
833
+ SENDING: "sending",
834
+ DELIVERED: "delivered",
835
+ FAILED: "failed",
836
+ CANCELLED: "cancelled",
831
837
  });
832
838
 
833
839
  const _a2aAgentTrans = new Map([
834
- [A2A_AGENT_MATURITY_V2.PENDING, new Set([A2A_AGENT_MATURITY_V2.ACTIVE, A2A_AGENT_MATURITY_V2.RETIRED])],
835
- [A2A_AGENT_MATURITY_V2.ACTIVE, new Set([A2A_AGENT_MATURITY_V2.SUSPENDED, A2A_AGENT_MATURITY_V2.RETIRED])],
836
- [A2A_AGENT_MATURITY_V2.SUSPENDED, new Set([A2A_AGENT_MATURITY_V2.ACTIVE, A2A_AGENT_MATURITY_V2.RETIRED])],
840
+ [
841
+ A2A_AGENT_MATURITY_V2.PENDING,
842
+ new Set([A2A_AGENT_MATURITY_V2.ACTIVE, A2A_AGENT_MATURITY_V2.RETIRED]),
843
+ ],
844
+ [
845
+ A2A_AGENT_MATURITY_V2.ACTIVE,
846
+ new Set([A2A_AGENT_MATURITY_V2.SUSPENDED, A2A_AGENT_MATURITY_V2.RETIRED]),
847
+ ],
848
+ [
849
+ A2A_AGENT_MATURITY_V2.SUSPENDED,
850
+ new Set([A2A_AGENT_MATURITY_V2.ACTIVE, A2A_AGENT_MATURITY_V2.RETIRED]),
851
+ ],
837
852
  [A2A_AGENT_MATURITY_V2.RETIRED, new Set()],
838
853
  ]);
839
854
  const _a2aAgentTerminal = new Set([A2A_AGENT_MATURITY_V2.RETIRED]);
840
855
  const _a2aMsgTrans = new Map([
841
- [A2A_MESSAGE_LIFECYCLE_V2.QUEUED, new Set([A2A_MESSAGE_LIFECYCLE_V2.SENDING, A2A_MESSAGE_LIFECYCLE_V2.CANCELLED])],
842
- [A2A_MESSAGE_LIFECYCLE_V2.SENDING, new Set([A2A_MESSAGE_LIFECYCLE_V2.DELIVERED, A2A_MESSAGE_LIFECYCLE_V2.FAILED, A2A_MESSAGE_LIFECYCLE_V2.CANCELLED])],
856
+ [
857
+ A2A_MESSAGE_LIFECYCLE_V2.QUEUED,
858
+ new Set([
859
+ A2A_MESSAGE_LIFECYCLE_V2.SENDING,
860
+ A2A_MESSAGE_LIFECYCLE_V2.CANCELLED,
861
+ ]),
862
+ ],
863
+ [
864
+ A2A_MESSAGE_LIFECYCLE_V2.SENDING,
865
+ new Set([
866
+ A2A_MESSAGE_LIFECYCLE_V2.DELIVERED,
867
+ A2A_MESSAGE_LIFECYCLE_V2.FAILED,
868
+ A2A_MESSAGE_LIFECYCLE_V2.CANCELLED,
869
+ ]),
870
+ ],
843
871
  [A2A_MESSAGE_LIFECYCLE_V2.DELIVERED, new Set()],
844
872
  [A2A_MESSAGE_LIFECYCLE_V2.FAILED, new Set()],
845
873
  [A2A_MESSAGE_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -852,21 +880,45 @@ let _a2aMaxPendingPerAgent = 20;
852
880
  let _a2aAgentIdleMs = 6 * 60 * 60 * 1000;
853
881
  let _a2aMsgStuckMs = 3 * 60 * 1000;
854
882
 
855
- function _a2aPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
883
+ function _a2aPos(n, lbl) {
884
+ const v = Math.floor(Number(n));
885
+ if (!Number.isFinite(v) || v <= 0)
886
+ throw new Error(`${lbl} must be positive integer`);
887
+ return v;
888
+ }
856
889
 
857
- export function setMaxActiveA2aAgentsPerOwnerV2(n) { _a2aMaxActivePerOwner = _a2aPos(n, "maxActiveA2aAgentsPerOwner"); }
858
- export function getMaxActiveA2aAgentsPerOwnerV2() { return _a2aMaxActivePerOwner; }
859
- export function setMaxPendingA2aMessagesPerAgentV2(n) { _a2aMaxPendingPerAgent = _a2aPos(n, "maxPendingA2aMessagesPerAgent"); }
860
- export function getMaxPendingA2aMessagesPerAgentV2() { return _a2aMaxPendingPerAgent; }
861
- export function setA2aAgentIdleMsV2(n) { _a2aAgentIdleMs = _a2aPos(n, "a2aAgentIdleMs"); }
862
- export function getA2aAgentIdleMsV2() { return _a2aAgentIdleMs; }
863
- export function setA2aMessageStuckMsV2(n) { _a2aMsgStuckMs = _a2aPos(n, "a2aMessageStuckMs"); }
864
- export function getA2aMessageStuckMsV2() { return _a2aMsgStuckMs; }
890
+ export function setMaxActiveA2aAgentsPerOwnerV2(n) {
891
+ _a2aMaxActivePerOwner = _a2aPos(n, "maxActiveA2aAgentsPerOwner");
892
+ }
893
+ export function getMaxActiveA2aAgentsPerOwnerV2() {
894
+ return _a2aMaxActivePerOwner;
895
+ }
896
+ export function setMaxPendingA2aMessagesPerAgentV2(n) {
897
+ _a2aMaxPendingPerAgent = _a2aPos(n, "maxPendingA2aMessagesPerAgent");
898
+ }
899
+ export function getMaxPendingA2aMessagesPerAgentV2() {
900
+ return _a2aMaxPendingPerAgent;
901
+ }
902
+ export function setA2aAgentIdleMsV2(n) {
903
+ _a2aAgentIdleMs = _a2aPos(n, "a2aAgentIdleMs");
904
+ }
905
+ export function getA2aAgentIdleMsV2() {
906
+ return _a2aAgentIdleMs;
907
+ }
908
+ export function setA2aMessageStuckMsV2(n) {
909
+ _a2aMsgStuckMs = _a2aPos(n, "a2aMessageStuckMs");
910
+ }
911
+ export function getA2aMessageStuckMsV2() {
912
+ return _a2aMsgStuckMs;
913
+ }
865
914
 
866
915
  export function _resetStateA2aProtocolV2() {
867
- _a2aAgents.clear(); _a2aMsgs.clear();
868
- _a2aMaxActivePerOwner = 12; _a2aMaxPendingPerAgent = 20;
869
- _a2aAgentIdleMs = 6 * 60 * 60 * 1000; _a2aMsgStuckMs = 3 * 60 * 1000;
916
+ _a2aAgents.clear();
917
+ _a2aMsgs.clear();
918
+ _a2aMaxActivePerOwner = 12;
919
+ _a2aMaxPendingPerAgent = 20;
920
+ _a2aAgentIdleMs = 6 * 60 * 60 * 1000;
921
+ _a2aMsgStuckMs = 3 * 60 * 1000;
870
922
  }
871
923
 
872
924
  export function registerA2aAgentV2({ id, owner, capabilities, metadata } = {}) {
@@ -874,54 +926,270 @@ export function registerA2aAgentV2({ id, owner, capabilities, metadata } = {}) {
874
926
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
875
927
  if (_a2aAgents.has(id)) throw new Error(`a2a agent ${id} already registered`);
876
928
  const now = Date.now();
877
- const a = { id, owner, capabilities: Array.isArray(capabilities) ? [...capabilities] : [], status: A2A_AGENT_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, retiredAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
929
+ const a = {
930
+ id,
931
+ owner,
932
+ capabilities: Array.isArray(capabilities) ? [...capabilities] : [],
933
+ status: A2A_AGENT_MATURITY_V2.PENDING,
934
+ createdAt: now,
935
+ updatedAt: now,
936
+ activatedAt: null,
937
+ retiredAt: null,
938
+ lastTouchedAt: now,
939
+ metadata: { ...(metadata || {}) },
940
+ };
878
941
  _a2aAgents.set(id, a);
879
- return { ...a, capabilities: [...a.capabilities], metadata: { ...a.metadata } };
942
+ return {
943
+ ...a,
944
+ capabilities: [...a.capabilities],
945
+ metadata: { ...a.metadata },
946
+ };
947
+ }
948
+ function _a2aCheckA(from, to) {
949
+ const al = _a2aAgentTrans.get(from);
950
+ if (!al || !al.has(to))
951
+ throw new Error(`invalid a2a agent transition ${from} → ${to}`);
952
+ }
953
+ function _a2aCountActive(owner) {
954
+ let n = 0;
955
+ for (const a of _a2aAgents.values())
956
+ if (a.owner === owner && a.status === A2A_AGENT_MATURITY_V2.ACTIVE) n++;
957
+ return n;
880
958
  }
881
- function _a2aCheckA(from, to) { const al = _a2aAgentTrans.get(from); if (!al || !al.has(to)) throw new Error(`invalid a2a agent transition ${from} → ${to}`); }
882
- function _a2aCountActive(owner) { let n = 0; for (const a of _a2aAgents.values()) if (a.owner === owner && a.status === A2A_AGENT_MATURITY_V2.ACTIVE) n++; return n; }
883
959
 
884
960
  export function activateA2aAgentV2(id) {
885
- const a = _a2aAgents.get(id); if (!a) throw new Error(`a2a agent ${id} not found`);
961
+ const a = _a2aAgents.get(id);
962
+ if (!a) throw new Error(`a2a agent ${id} not found`);
886
963
  _a2aCheckA(a.status, A2A_AGENT_MATURITY_V2.ACTIVE);
887
964
  const recovery = a.status === A2A_AGENT_MATURITY_V2.SUSPENDED;
888
- if (!recovery) { const c = _a2aCountActive(a.owner); if (c >= _a2aMaxActivePerOwner) throw new Error(`max active a2a agents per owner (${_a2aMaxActivePerOwner}) reached for ${a.owner}`); }
889
- const now = Date.now(); a.status = A2A_AGENT_MATURITY_V2.ACTIVE; a.updatedAt = now; a.lastTouchedAt = now; if (!a.activatedAt) a.activatedAt = now;
890
- return { ...a, capabilities: [...a.capabilities], metadata: { ...a.metadata } };
965
+ if (!recovery) {
966
+ const c = _a2aCountActive(a.owner);
967
+ if (c >= _a2aMaxActivePerOwner)
968
+ throw new Error(
969
+ `max active a2a agents per owner (${_a2aMaxActivePerOwner}) reached for ${a.owner}`,
970
+ );
971
+ }
972
+ const now = Date.now();
973
+ a.status = A2A_AGENT_MATURITY_V2.ACTIVE;
974
+ a.updatedAt = now;
975
+ a.lastTouchedAt = now;
976
+ if (!a.activatedAt) a.activatedAt = now;
977
+ return {
978
+ ...a,
979
+ capabilities: [...a.capabilities],
980
+ metadata: { ...a.metadata },
981
+ };
982
+ }
983
+ export function suspendA2aAgentV2(id) {
984
+ const a = _a2aAgents.get(id);
985
+ if (!a) throw new Error(`a2a agent ${id} not found`);
986
+ _a2aCheckA(a.status, A2A_AGENT_MATURITY_V2.SUSPENDED);
987
+ a.status = A2A_AGENT_MATURITY_V2.SUSPENDED;
988
+ a.updatedAt = Date.now();
989
+ return {
990
+ ...a,
991
+ capabilities: [...a.capabilities],
992
+ metadata: { ...a.metadata },
993
+ };
994
+ }
995
+ export function retireA2aAgentV2(id) {
996
+ const a = _a2aAgents.get(id);
997
+ if (!a) throw new Error(`a2a agent ${id} not found`);
998
+ _a2aCheckA(a.status, A2A_AGENT_MATURITY_V2.RETIRED);
999
+ const now = Date.now();
1000
+ a.status = A2A_AGENT_MATURITY_V2.RETIRED;
1001
+ a.updatedAt = now;
1002
+ if (!a.retiredAt) a.retiredAt = now;
1003
+ return {
1004
+ ...a,
1005
+ capabilities: [...a.capabilities],
1006
+ metadata: { ...a.metadata },
1007
+ };
1008
+ }
1009
+ export function touchA2aAgentV2(id) {
1010
+ const a = _a2aAgents.get(id);
1011
+ if (!a) throw new Error(`a2a agent ${id} not found`);
1012
+ if (_a2aAgentTerminal.has(a.status))
1013
+ throw new Error(`cannot touch terminal a2a agent ${id}`);
1014
+ const now = Date.now();
1015
+ a.lastTouchedAt = now;
1016
+ a.updatedAt = now;
1017
+ return {
1018
+ ...a,
1019
+ capabilities: [...a.capabilities],
1020
+ metadata: { ...a.metadata },
1021
+ };
1022
+ }
1023
+ export function getA2aAgentV2(id) {
1024
+ const a = _a2aAgents.get(id);
1025
+ if (!a) return null;
1026
+ return {
1027
+ ...a,
1028
+ capabilities: [...a.capabilities],
1029
+ metadata: { ...a.metadata },
1030
+ };
1031
+ }
1032
+ export function listA2aAgentsV2() {
1033
+ return [..._a2aAgents.values()].map((a) => ({
1034
+ ...a,
1035
+ capabilities: [...a.capabilities],
1036
+ metadata: { ...a.metadata },
1037
+ }));
891
1038
  }
892
- export function suspendA2aAgentV2(id) { const a = _a2aAgents.get(id); if (!a) throw new Error(`a2a agent ${id} not found`); _a2aCheckA(a.status, A2A_AGENT_MATURITY_V2.SUSPENDED); a.status = A2A_AGENT_MATURITY_V2.SUSPENDED; a.updatedAt = Date.now(); return { ...a, capabilities: [...a.capabilities], metadata: { ...a.metadata } }; }
893
- export function retireA2aAgentV2(id) { const a = _a2aAgents.get(id); if (!a) throw new Error(`a2a agent ${id} not found`); _a2aCheckA(a.status, A2A_AGENT_MATURITY_V2.RETIRED); const now = Date.now(); a.status = A2A_AGENT_MATURITY_V2.RETIRED; a.updatedAt = now; if (!a.retiredAt) a.retiredAt = now; return { ...a, capabilities: [...a.capabilities], metadata: { ...a.metadata } }; }
894
- export function touchA2aAgentV2(id) { const a = _a2aAgents.get(id); if (!a) throw new Error(`a2a agent ${id} not found`); if (_a2aAgentTerminal.has(a.status)) throw new Error(`cannot touch terminal a2a agent ${id}`); const now = Date.now(); a.lastTouchedAt = now; a.updatedAt = now; return { ...a, capabilities: [...a.capabilities], metadata: { ...a.metadata } }; }
895
- export function getA2aAgentV2(id) { const a = _a2aAgents.get(id); if (!a) return null; return { ...a, capabilities: [...a.capabilities], metadata: { ...a.metadata } }; }
896
- export function listA2aAgentsV2() { return [..._a2aAgents.values()].map((a) => ({ ...a, capabilities: [...a.capabilities], metadata: { ...a.metadata } })); }
897
1039
 
898
- function _a2aCountPending(aid) { let n = 0; for (const m of _a2aMsgs.values()) if (m.agentId === aid && (m.status === A2A_MESSAGE_LIFECYCLE_V2.QUEUED || m.status === A2A_MESSAGE_LIFECYCLE_V2.SENDING)) n++; return n; }
1040
+ function _a2aCountPending(aid) {
1041
+ let n = 0;
1042
+ for (const m of _a2aMsgs.values())
1043
+ if (
1044
+ m.agentId === aid &&
1045
+ (m.status === A2A_MESSAGE_LIFECYCLE_V2.QUEUED ||
1046
+ m.status === A2A_MESSAGE_LIFECYCLE_V2.SENDING)
1047
+ )
1048
+ n++;
1049
+ return n;
1050
+ }
899
1051
 
900
- export function createA2aMessageV2({ id, agentId, peerId, payload, metadata } = {}) {
1052
+ export function createA2aMessageV2({
1053
+ id,
1054
+ agentId,
1055
+ peerId,
1056
+ payload,
1057
+ metadata,
1058
+ } = {}) {
901
1059
  if (!id || typeof id !== "string") throw new Error("id is required");
902
- if (!agentId || typeof agentId !== "string") throw new Error("agentId is required");
1060
+ if (!agentId || typeof agentId !== "string")
1061
+ throw new Error("agentId is required");
903
1062
  if (_a2aMsgs.has(id)) throw new Error(`a2a message ${id} already exists`);
904
- if (!_a2aAgents.has(agentId)) throw new Error(`a2a agent ${agentId} not found`);
1063
+ if (!_a2aAgents.has(agentId))
1064
+ throw new Error(`a2a agent ${agentId} not found`);
905
1065
  const pending = _a2aCountPending(agentId);
906
- if (pending >= _a2aMaxPendingPerAgent) throw new Error(`max pending a2a messages per agent (${_a2aMaxPendingPerAgent}) reached for ${agentId}`);
1066
+ if (pending >= _a2aMaxPendingPerAgent)
1067
+ throw new Error(
1068
+ `max pending a2a messages per agent (${_a2aMaxPendingPerAgent}) reached for ${agentId}`,
1069
+ );
907
1070
  const now = Date.now();
908
- const m = { id, agentId, peerId: peerId || "", payload: payload || "", status: A2A_MESSAGE_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
1071
+ const m = {
1072
+ id,
1073
+ agentId,
1074
+ peerId: peerId || "",
1075
+ payload: payload || "",
1076
+ status: A2A_MESSAGE_LIFECYCLE_V2.QUEUED,
1077
+ createdAt: now,
1078
+ updatedAt: now,
1079
+ startedAt: null,
1080
+ settledAt: null,
1081
+ metadata: { ...(metadata || {}) },
1082
+ };
909
1083
  _a2aMsgs.set(id, m);
910
1084
  return { ...m, metadata: { ...m.metadata } };
911
1085
  }
912
- function _a2aCheckM(from, to) { const al = _a2aMsgTrans.get(from); if (!al || !al.has(to)) throw new Error(`invalid a2a message transition ${from} → ${to}`); }
913
- export function startA2aMessageV2(id) { const m = _a2aMsgs.get(id); if (!m) throw new Error(`a2a message ${id} not found`); _a2aCheckM(m.status, A2A_MESSAGE_LIFECYCLE_V2.SENDING); const now = Date.now(); m.status = A2A_MESSAGE_LIFECYCLE_V2.SENDING; m.updatedAt = now; if (!m.startedAt) m.startedAt = now; return { ...m, metadata: { ...m.metadata } }; }
914
- export function deliverA2aMessageV2(id) { const m = _a2aMsgs.get(id); if (!m) throw new Error(`a2a message ${id} not found`); _a2aCheckM(m.status, A2A_MESSAGE_LIFECYCLE_V2.DELIVERED); const now = Date.now(); m.status = A2A_MESSAGE_LIFECYCLE_V2.DELIVERED; m.updatedAt = now; if (!m.settledAt) m.settledAt = now; return { ...m, metadata: { ...m.metadata } }; }
915
- export function failA2aMessageV2(id, reason) { const m = _a2aMsgs.get(id); if (!m) throw new Error(`a2a message ${id} not found`); _a2aCheckM(m.status, A2A_MESSAGE_LIFECYCLE_V2.FAILED); const now = Date.now(); m.status = A2A_MESSAGE_LIFECYCLE_V2.FAILED; m.updatedAt = now; if (!m.settledAt) m.settledAt = now; if (reason) m.metadata.failReason = String(reason); return { ...m, metadata: { ...m.metadata } }; }
916
- export function cancelA2aMessageV2(id, reason) { const m = _a2aMsgs.get(id); if (!m) throw new Error(`a2a message ${id} not found`); _a2aCheckM(m.status, A2A_MESSAGE_LIFECYCLE_V2.CANCELLED); const now = Date.now(); m.status = A2A_MESSAGE_LIFECYCLE_V2.CANCELLED; m.updatedAt = now; if (!m.settledAt) m.settledAt = now; if (reason) m.metadata.cancelReason = String(reason); return { ...m, metadata: { ...m.metadata } }; }
917
- export function getA2aMessageV2(id) { const m = _a2aMsgs.get(id); if (!m) return null; return { ...m, metadata: { ...m.metadata } }; }
918
- export function listA2aMessagesV2() { return [..._a2aMsgs.values()].map((m) => ({ ...m, metadata: { ...m.metadata } })); }
1086
+ function _a2aCheckM(from, to) {
1087
+ const al = _a2aMsgTrans.get(from);
1088
+ if (!al || !al.has(to))
1089
+ throw new Error(`invalid a2a message transition ${from} ${to}`);
1090
+ }
1091
+ export function startA2aMessageV2(id) {
1092
+ const m = _a2aMsgs.get(id);
1093
+ if (!m) throw new Error(`a2a message ${id} not found`);
1094
+ _a2aCheckM(m.status, A2A_MESSAGE_LIFECYCLE_V2.SENDING);
1095
+ const now = Date.now();
1096
+ m.status = A2A_MESSAGE_LIFECYCLE_V2.SENDING;
1097
+ m.updatedAt = now;
1098
+ if (!m.startedAt) m.startedAt = now;
1099
+ return { ...m, metadata: { ...m.metadata } };
1100
+ }
1101
+ export function deliverA2aMessageV2(id) {
1102
+ const m = _a2aMsgs.get(id);
1103
+ if (!m) throw new Error(`a2a message ${id} not found`);
1104
+ _a2aCheckM(m.status, A2A_MESSAGE_LIFECYCLE_V2.DELIVERED);
1105
+ const now = Date.now();
1106
+ m.status = A2A_MESSAGE_LIFECYCLE_V2.DELIVERED;
1107
+ m.updatedAt = now;
1108
+ if (!m.settledAt) m.settledAt = now;
1109
+ return { ...m, metadata: { ...m.metadata } };
1110
+ }
1111
+ export function failA2aMessageV2(id, reason) {
1112
+ const m = _a2aMsgs.get(id);
1113
+ if (!m) throw new Error(`a2a message ${id} not found`);
1114
+ _a2aCheckM(m.status, A2A_MESSAGE_LIFECYCLE_V2.FAILED);
1115
+ const now = Date.now();
1116
+ m.status = A2A_MESSAGE_LIFECYCLE_V2.FAILED;
1117
+ m.updatedAt = now;
1118
+ if (!m.settledAt) m.settledAt = now;
1119
+ if (reason) m.metadata.failReason = String(reason);
1120
+ return { ...m, metadata: { ...m.metadata } };
1121
+ }
1122
+ export function cancelA2aMessageV2(id, reason) {
1123
+ const m = _a2aMsgs.get(id);
1124
+ if (!m) throw new Error(`a2a message ${id} not found`);
1125
+ _a2aCheckM(m.status, A2A_MESSAGE_LIFECYCLE_V2.CANCELLED);
1126
+ const now = Date.now();
1127
+ m.status = A2A_MESSAGE_LIFECYCLE_V2.CANCELLED;
1128
+ m.updatedAt = now;
1129
+ if (!m.settledAt) m.settledAt = now;
1130
+ if (reason) m.metadata.cancelReason = String(reason);
1131
+ return { ...m, metadata: { ...m.metadata } };
1132
+ }
1133
+ export function getA2aMessageV2(id) {
1134
+ const m = _a2aMsgs.get(id);
1135
+ if (!m) return null;
1136
+ return { ...m, metadata: { ...m.metadata } };
1137
+ }
1138
+ export function listA2aMessagesV2() {
1139
+ return [..._a2aMsgs.values()].map((m) => ({
1140
+ ...m,
1141
+ metadata: { ...m.metadata },
1142
+ }));
1143
+ }
919
1144
 
920
- export function autoSuspendIdleA2aAgentsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const a of _a2aAgents.values()) if (a.status === A2A_AGENT_MATURITY_V2.ACTIVE && (t - a.lastTouchedAt) >= _a2aAgentIdleMs) { a.status = A2A_AGENT_MATURITY_V2.SUSPENDED; a.updatedAt = t; flipped.push(a.id); } return { flipped, count: flipped.length }; }
921
- export function autoFailStuckA2aMessagesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const m of _a2aMsgs.values()) if (m.status === A2A_MESSAGE_LIFECYCLE_V2.SENDING && m.startedAt != null && (t - m.startedAt) >= _a2aMsgStuckMs) { m.status = A2A_MESSAGE_LIFECYCLE_V2.FAILED; m.updatedAt = t; if (!m.settledAt) m.settledAt = t; m.metadata.failReason = "auto-fail-stuck"; flipped.push(m.id); } return { flipped, count: flipped.length }; }
1145
+ export function autoSuspendIdleA2aAgentsV2({ now } = {}) {
1146
+ const t = now ?? Date.now();
1147
+ const flipped = [];
1148
+ for (const a of _a2aAgents.values())
1149
+ if (
1150
+ a.status === A2A_AGENT_MATURITY_V2.ACTIVE &&
1151
+ t - a.lastTouchedAt >= _a2aAgentIdleMs
1152
+ ) {
1153
+ a.status = A2A_AGENT_MATURITY_V2.SUSPENDED;
1154
+ a.updatedAt = t;
1155
+ flipped.push(a.id);
1156
+ }
1157
+ return { flipped, count: flipped.length };
1158
+ }
1159
+ export function autoFailStuckA2aMessagesV2({ now } = {}) {
1160
+ const t = now ?? Date.now();
1161
+ const flipped = [];
1162
+ for (const m of _a2aMsgs.values())
1163
+ if (
1164
+ m.status === A2A_MESSAGE_LIFECYCLE_V2.SENDING &&
1165
+ m.startedAt != null &&
1166
+ t - m.startedAt >= _a2aMsgStuckMs
1167
+ ) {
1168
+ m.status = A2A_MESSAGE_LIFECYCLE_V2.FAILED;
1169
+ m.updatedAt = t;
1170
+ if (!m.settledAt) m.settledAt = t;
1171
+ m.metadata.failReason = "auto-fail-stuck";
1172
+ flipped.push(m.id);
1173
+ }
1174
+ return { flipped, count: flipped.length };
1175
+ }
922
1176
 
923
1177
  export function getA2aProtocolGovStatsV2() {
924
- const agentsByStatus = {}; for (const s of Object.values(A2A_AGENT_MATURITY_V2)) agentsByStatus[s] = 0; for (const a of _a2aAgents.values()) agentsByStatus[a.status]++;
925
- const messagesByStatus = {}; for (const s of Object.values(A2A_MESSAGE_LIFECYCLE_V2)) messagesByStatus[s] = 0; for (const m of _a2aMsgs.values()) messagesByStatus[m.status]++;
926
- return { totalAgentsV2: _a2aAgents.size, totalMessagesV2: _a2aMsgs.size, maxActiveA2aAgentsPerOwner: _a2aMaxActivePerOwner, maxPendingA2aMessagesPerAgent: _a2aMaxPendingPerAgent, a2aAgentIdleMs: _a2aAgentIdleMs, a2aMessageStuckMs: _a2aMsgStuckMs, agentsByStatus, messagesByStatus };
1178
+ const agentsByStatus = {};
1179
+ for (const s of Object.values(A2A_AGENT_MATURITY_V2)) agentsByStatus[s] = 0;
1180
+ for (const a of _a2aAgents.values()) agentsByStatus[a.status]++;
1181
+ const messagesByStatus = {};
1182
+ for (const s of Object.values(A2A_MESSAGE_LIFECYCLE_V2))
1183
+ messagesByStatus[s] = 0;
1184
+ for (const m of _a2aMsgs.values()) messagesByStatus[m.status]++;
1185
+ return {
1186
+ totalAgentsV2: _a2aAgents.size,
1187
+ totalMessagesV2: _a2aMsgs.size,
1188
+ maxActiveA2aAgentsPerOwner: _a2aMaxActivePerOwner,
1189
+ maxPendingA2aMessagesPerAgent: _a2aMaxPendingPerAgent,
1190
+ a2aAgentIdleMs: _a2aAgentIdleMs,
1191
+ a2aMessageStuckMs: _a2aMsgStuckMs,
1192
+ agentsByStatus,
1193
+ messagesByStatus,
1194
+ };
927
1195
  }