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.
- package/package.json +1 -1
- package/src/commands/a2a.js +196 -28
- package/src/commands/activitypub.js +364 -27
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +355 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +403 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +824 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +783 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- 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 +385 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +387 -27
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fflag.js +74 -22
- package/src/commands/fusion.js +205 -0
- package/src/commands/git.js +177 -37
- package/src/commands/governance.js +209 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/llm.js +217 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +386 -27
- package/src/commands/mcp.js +217 -0
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/memory.js +209 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +387 -27
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perception.js +209 -0
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +410 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/session.js +209 -0
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/skill.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +358 -32
- package/src/commands/sso.js +209 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/tokens.js +209 -0
- package/src/commands/topiccls.js +146 -33
- package/src/commands/trust.js +217 -0
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/wallet.js +209 -0
- package/src/commands/webfetch.js +141 -32
- package/src/commands/workflow.js +203 -0
- package/src/commands/zkp.js +184 -28
- package/src/index.js +180 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +622 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +616 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +630 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -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-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- 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 +626 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +308 -51
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +620 -47
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- 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 +622 -49
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-manager.js +334 -0
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/topic-classifier.js +297 -49
- 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/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/zkp-engine.js +286 -49
package/src/lib/a2a-protocol.js
CHANGED
|
@@ -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",
|
|
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",
|
|
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
|
-
[
|
|
835
|
-
|
|
836
|
-
|
|
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
|
-
[
|
|
842
|
-
|
|
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) {
|
|
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) {
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
export function
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
export function
|
|
864
|
-
|
|
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();
|
|
868
|
-
|
|
869
|
-
|
|
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 = {
|
|
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 {
|
|
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);
|
|
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) {
|
|
889
|
-
|
|
890
|
-
|
|
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) {
|
|
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({
|
|
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")
|
|
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))
|
|
1063
|
+
if (!_a2aAgents.has(agentId))
|
|
1064
|
+
throw new Error(`a2a agent ${agentId} not found`);
|
|
905
1065
|
const pending = _a2aCountPending(agentId);
|
|
906
|
-
if (pending >= _a2aMaxPendingPerAgent)
|
|
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 = {
|
|
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) {
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
export function
|
|
918
|
-
|
|
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 } = {}) {
|
|
921
|
-
|
|
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 = {};
|
|
925
|
-
|
|
926
|
-
|
|
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
|
}
|