@loomwork/plugin-a2a 0.0.0-stage → 0.1.1

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 (45) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +80 -2
  4. package/cards.d.ts +1 -0
  5. package/dist/A2AClientEffect.d.ts +11 -0
  6. package/dist/A2AClientEffect.d.ts.map +1 -0
  7. package/dist/A2AClientEffect.js +89 -0
  8. package/dist/A2AClientEffect.js.map +1 -0
  9. package/dist/A2AEffect.d.ts +13 -0
  10. package/dist/A2AEffect.d.ts.map +1 -0
  11. package/dist/A2AEffect.js +20 -0
  12. package/dist/A2AEffect.js.map +1 -0
  13. package/dist/A2APeerClient.d.ts +126 -0
  14. package/dist/A2APeerClient.d.ts.map +1 -0
  15. package/dist/A2APeerClient.js +167 -0
  16. package/dist/A2APeerClient.js.map +1 -0
  17. package/dist/A2AServer.d.ts +78 -0
  18. package/dist/A2AServer.d.ts.map +1 -0
  19. package/dist/A2AServer.js +239 -0
  20. package/dist/A2AServer.js.map +1 -0
  21. package/dist/AgentExecutor.d.ts +89 -0
  22. package/dist/AgentExecutor.d.ts.map +1 -0
  23. package/dist/AgentExecutor.js +126 -0
  24. package/dist/AgentExecutor.js.map +1 -0
  25. package/dist/index.d.ts +12 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +20 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/toAgentCard.d.ts +11 -0
  30. package/dist/toAgentCard.d.ts.map +1 -0
  31. package/dist/toAgentCard.js +19 -0
  32. package/dist/toAgentCard.js.map +1 -0
  33. package/dist/types.d.ts +41 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/types.js +3 -0
  36. package/dist/types.js.map +1 -0
  37. package/package.json +65 -3
  38. package/src/A2AClientEffect.ts +109 -0
  39. package/src/A2AEffect.ts +16 -0
  40. package/src/A2APeerClient.ts +298 -0
  41. package/src/A2AServer.ts +309 -0
  42. package/src/AgentExecutor.ts +192 -0
  43. package/src/index.ts +35 -0
  44. package/src/toAgentCard.ts +31 -0
  45. package/src/types.ts +41 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/NOTICE ADDED
@@ -0,0 +1,8 @@
1
+ Loom
2
+ Copyright 2026 Sushil Chhetri
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this project except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # @loomwork/plugin-a2a — talk to other agents over the A2A protocol
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Both directions of Google's Agent-to-Agent protocol. Outbound, `A2APeerClient` discovers a remote
4
+ agent's card and registers it as a Loom tool that agents, steps and the planner can call. Inbound,
5
+ `createA2AServer` exposes one Loom flow as an A2A agent over `node:http`. Use it to mesh Loom agents
6
+ with each other or with agents built on other frameworks. A peer agent is only as trustworthy as
7
+ whoever operates it, so read the notes on taint and descriptions below.
8
+
9
+ ```ts
10
+ import { EffectRuntime } from "@loomwork/effect-runtime";
11
+ import { A2APeerClient, createA2AServer } from "@loomwork/plugin-a2a";
12
+ import type { RegisteredFlow, WorkflowRuntime } from "@loomwork/workflow-runtime";
13
+
14
+ declare const runtime: WorkflowRuntime;
15
+ declare const triageFlow: RegisteredFlow;
16
+
17
+ // Outbound: a remote agent becomes a tool. `taintResults` marks its text as untrusted.
18
+ const effects = new EffectRuntime();
19
+ const peer = new A2APeerClient({
20
+ url: "https://peer.example.com",
21
+ headers: { authorization: `Bearer ${process.env.PEER_TOKEN}` },
22
+ taintResults: true,
23
+ });
24
+ const peerTool = await peer.registerInto(effects); // fetches /.well-known/agent.json
25
+ // Call it with { prompt, context? }; the result is { content, raw }.
26
+
27
+ // Inbound: serve a flow. The server refuses to start with no authentication.
28
+ const server = createA2AServer(
29
+ runtime,
30
+ triageFlow,
31
+ { name: "triage", description: "Triage tickets", version: "1.0.0", capabilities: {}, skills: [] },
32
+ {
33
+ port: 3001,
34
+ authenticate: (req) =>
35
+ req.headers.authorization === `Bearer ${process.env.A2A_TOKEN}` ? { actor: "partner-a" } : undefined,
36
+ }
37
+ );
38
+ await server.start();
39
+ ```
40
+
41
+ ## Surface
42
+
43
+ - **Client.** `A2APeerClient` (`discover`, `map`, `registerInto`), `fetchAgentCard`, and
44
+ `createA2AClientEffect(url, { headers, timeoutMs, pollIntervalMs })`. A task answered as finished in
45
+ the `/tasks/send` reply is returned as is; otherwise the client polls `/tasks/:id` (default 500 ms,
46
+ 60 s timeout).
47
+ - **Server.** `createA2AServer(runtime, flow, card, options)` serves `/.well-known/agent.json`,
48
+ `POST /tasks/send` and `GET /tasks/:id`. `LoomAgentExecutor` is the underlying submit and get logic.
49
+ - **Cards.** `toAgentCard(agent, options?)` derives a card from an `agent$` definition. It is also
50
+ available from the browser-safe subpath `@loomwork/plugin-a2a/cards`, which pulls in no `node:http`.
51
+
52
+ ## Behaviour that surprises people
53
+
54
+ - **`taintResults` marks the peer's text, not its task state.** `content`, `raw.artifacts` and `raw.error`
55
+ become tainted values the prompt boundary refuses in instruction positions, so `unwrapTainted()` them to
56
+ compute with. `raw.id` and `raw.status` stay plain for control flow. If you put those into a prompt, nothing marks them
57
+ ([docs/data-classification.md](../../docs/data-classification.md)). It is off by default.
58
+ - **A peer's description is withheld from the model.** An agent loop shows a neutral placeholder for the
59
+ peer unless you set `trustDescriptions: true`, because the card is written by the peer's operator.
60
+ Set it only for a peer you operate or trust; its card text then reaches the model as instructions
61
+ (ADR 0125 D14).
62
+ - **The server is closed by default.** It listens on `127.0.0.1`, throws at creation with neither
63
+ `authenticate` nor `authorize` unless you pass `insecure: true`, and under `security.strict` it
64
+ requires `authenticate` or `resolvePrincipal`. The principal needs a non-empty string `actor`, which
65
+ scopes task ownership. `authorize` alone gives every caller one shared task namespace.
66
+ - **Set `publicUrl` behind a proxy.** Otherwise the card advertises the bind address.
67
+ - **A task id becomes the execution id.** It must be non-empty, at most 200 characters, and not start
68
+ with `__loom_`. The client derives its ids from the execution and step, so replays are stable.
69
+
70
+ ## Status / See also
71
+
72
+ Unpublished for now: inside this repo use `workspace:*`; from a sibling checkout use a `link:` override
73
+ (see [AGENTS.md](../../AGENTS.md)).
74
+
75
+ - [ADR 0125](../../docs/adr/0125-tool-search.md) (D14): card text and `trustDescriptions`;
76
+ [ADR 0085](../../docs/adr/0085-untrusted-content-integrity-axis.md): the taint model.
77
+ - API reference: section "`@loomwork/plugin-a2a` — Agent-to-Agent" in
78
+ [docs/api-reference.org](../../docs/api-reference.org).
79
+ - Guides: [docs/data-classification.md](../../docs/data-classification.md),
80
+ [docs/user-guide.md](../../docs/user-guide.md), and the `a2a-mesh` and `agent-network` examples in
81
+ `loom-examples`.
package/cards.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./dist/toAgentCard";
@@ -0,0 +1,11 @@
1
+ import { A2AEffect } from "./A2AEffect";
2
+ import type { A2ATask, A2ATaskResult, A2ATaskStatus } from "./types";
3
+ export interface A2AClientOptions {
4
+ timeoutMs?: number;
5
+ headers?: Record<string, string>;
6
+ pollIntervalMs?: number;
7
+ }
8
+ export declare function createA2AClientEffect(agentUrl: string, options?: A2AClientOptions): A2AEffect<A2ATask, A2ATaskResult>;
9
+ declare const terminalStatuses: Set<A2ATaskStatus>;
10
+ export { terminalStatuses };
11
+ //# sourceMappingURL=A2AClientEffect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"A2AClientEffect.d.ts","sourceRoot":"","sources":["../src/A2AClientEffect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAErE,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,gBAAqB,GAC7B,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC,CA8DnC;AAED,QAAA,MAAM,gBAAgB,oBAAkD,CAAC;AA+BzE,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.terminalStatuses = void 0;
4
+ exports.createA2AClientEffect = createA2AClientEffect;
5
+ const A2AEffect_1 = require("./A2AEffect");
6
+ function createA2AClientEffect(agentUrl, options = {}) {
7
+ const { timeoutMs = 60_000, pollIntervalMs = 500, headers = {} } = options;
8
+ return new A2AEffect_1.A2AEffect(async (task, _ctx) => {
9
+ const baseHeaders = { "content-type": "application/json", ...headers };
10
+ const sendResp = await fetch(`${agentUrl}/tasks/send`, {
11
+ method: "POST",
12
+ headers: baseHeaders,
13
+ body: JSON.stringify(task),
14
+ });
15
+ if (!sendResp.ok) {
16
+ throw new Error(`A2A send error ${sendResp.status}: ${await sendResp.text()}`);
17
+ }
18
+ const sentBody = await sendResp.json();
19
+ // A malformed answer (not an object at all — e.g. a bare JSON string) used to reach the
20
+ // `"status" in sent` check below and throw a bare, unhelpful `TypeError`. Fail with a
21
+ // message in the style of the other A2A errors instead.
22
+ if (typeof sentBody !== "object" || sentBody === null) {
23
+ throw new Error("A2A send error: malformed answer");
24
+ }
25
+ const sent = sentBody;
26
+ // A peer that answers `/tasks/send` with the finished task (a synchronous agent — e.g. a
27
+ // thin shim whose send handler runs the graph and returns its artifact) has already given
28
+ // the result. Polling for it again cost every such call a full `pollIntervalMs` sleep plus
29
+ // a second request, and failed outright against a peer that does not keep the task (L18).
30
+ // A send that returns only `{ id }` (loom's own server: 202) is polled as before.
31
+ if (typeof sent.status === "string" && terminalStatuses.has(sent.status)) {
32
+ // A terminal task with no `id` is as malformed as one with no id at all — the caller
33
+ // can't reconcile it against the task it just submitted.
34
+ if (typeof sent.id !== "string") {
35
+ throw new Error("A2A send error: malformed answer");
36
+ }
37
+ return sent;
38
+ }
39
+ if (typeof sent.id !== "string") {
40
+ throw new Error("A2A send error: malformed answer");
41
+ }
42
+ const taskId = sent.id;
43
+ const deadline = Date.now() + timeoutMs;
44
+ while (Date.now() < deadline) {
45
+ await sleep(pollIntervalMs);
46
+ const statusResp = await fetch(`${agentUrl}/tasks/${encodeTaskIdSegment(taskId)}`, {
47
+ headers: baseHeaders,
48
+ });
49
+ if (!statusResp.ok) {
50
+ throw new Error(`A2A status error ${statusResp.status}: ${await statusResp.text()}`);
51
+ }
52
+ const result = (await statusResp.json());
53
+ if (result.status === "completed" || result.status === "failed") {
54
+ return result;
55
+ }
56
+ }
57
+ throw new Error(`A2A task ${taskId} timed out after ${timeoutMs}ms`);
58
+ });
59
+ }
60
+ const terminalStatuses = new Set(["completed", "failed"]);
61
+ exports.terminalStatuses = terminalStatuses;
62
+ function sleep(ms) {
63
+ return new Promise((resolve) => setTimeout(resolve, ms));
64
+ }
65
+ /**
66
+ * Escape only the characters that are unsafe in a SINGLE path segment: `/` (would otherwise
67
+ * split the segment — this is what stops a `../admin`-style id from being collapsed by URL
68
+ * dot-segment normalization into a request for a different route), `?` and `#` (would start a
69
+ * query string / fragment), and a literal `%` (would corrupt the escape sequence itself on
70
+ * decode). Everything else — INCLUDING `:` — is left byte-identical to the pre-encoding wire
71
+ * format.
72
+ *
73
+ * `:` matters because every loom task id contains one (`A2APeerClient` sets
74
+ * `task.id = `${executionId}:${stepId}``, plus `:${callKey}` for a decider-scope call, and `TenantScoped` uses `:` as its own separator). A
75
+ * full `encodeURIComponent` here would send `exec%3Astep` — a NEW client talking to an OLD
76
+ * `A2AServer` (or any third-party peer) that does not `decodeURIComponent` the path segment
77
+ * would then 404 every poll during a rolling upgrade. `A2AServer`'s `GET /tasks/:id` route still
78
+ * `decodeURIComponent`s the segment on the way in, which is a no-op for an id with no `%` in it
79
+ * and round-trips one of the escaped characters above, so both old- and new-server peers resolve
80
+ * the same id from the same request.
81
+ *
82
+ * Trade-off accepted deliberately: an id containing a literal `%` cannot be resolved by an old,
83
+ * non-decoding server (it would look up the literal `...%25...` instead of the real id) — but no
84
+ * loom-issued task id contains one.
85
+ */
86
+ function encodeTaskIdSegment(id) {
87
+ return id.replace(/[/?#%]/g, (c) => encodeURIComponent(c));
88
+ }
89
+ //# sourceMappingURL=A2AClientEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"A2AClientEffect.js","sourceRoot":"","sources":["../src/A2AClientEffect.ts"],"names":[],"mappings":";;;AAUA,sDAiEC;AA1ED,2CAAwC;AASxC,SAAgB,qBAAqB,CACnC,QAAgB,EAChB,UAA4B,EAAE;IAE9B,MAAM,EAAE,SAAS,GAAG,MAAM,EAAE,cAAc,GAAG,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAE3E,OAAO,IAAI,qBAAS,CAAyB,KAAK,EAAE,IAAa,EAAE,IAAmB,EAAE,EAAE;QACxF,MAAM,WAAW,GAAG,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,OAAO,EAAE,CAAC;QAEvE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,QAAQ,aAAa,EAAE;YACrD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,WAAW;YACpB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,CAAC,MAAM,KAAK,MAAM,QAAQ,CAAC,IAA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CAAC;gBACnB,MAAM,IAAI,KAAK,CAAC,oBAAoB,UAAU,CAAC,MAAM,KAAK,MAAM,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACvF,CAAC;YAED,MAAM,MAAM,GAAG,CAAC,MAAM,UAAU,CAAC,IAAI,EAAE,CAAkB,CAAC;YAE1D,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAChE,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,YAAY,MAAM,oBAAoB,SAAS,IAAI,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;AA+BhE,4CAAgB;AA7BzB,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAS,mBAAmB,CAAC,EAAU;IACrC,OAAO,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Effect, EffectContext } from "@loomwork/effect-runtime";
2
+ /**
3
+ * The effect that fronts a call to an agent-to-agent peer. Its kind, `"a2a"`, names this
4
+ * plugin's protocol; the kernel treats it as an ordinary custom kind (advisory metadata only,
5
+ * ADR 0115). Moved here from `@loomwork/effect-runtime`, which keeps a deprecated copy for one minor.
6
+ */
7
+ export declare class A2AEffect<TIn = unknown, TOut = unknown> implements Effect<TIn, TOut> {
8
+ private readonly fn;
9
+ readonly kind: "a2a";
10
+ constructor(fn: (input: TIn, ctx: EffectContext) => Promise<TOut>);
11
+ execute(input: TIn, ctx: EffectContext): Promise<TOut>;
12
+ }
13
+ //# sourceMappingURL=A2AEffect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"A2AEffect.d.ts","sourceRoot":"","sources":["../src/A2AEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEtE;;;;GAIG;AACH,qBAAa,SAAS,CAAC,GAAG,GAAG,OAAO,EAAE,IAAI,GAAG,OAAO,CAAE,YAAW,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC;IAGpE,OAAO,CAAC,QAAQ,CAAC,EAAE;IAF/B,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;gBAEF,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC;IAElF,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAGvD"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.A2AEffect = void 0;
4
+ /**
5
+ * The effect that fronts a call to an agent-to-agent peer. Its kind, `"a2a"`, names this
6
+ * plugin's protocol; the kernel treats it as an ordinary custom kind (advisory metadata only,
7
+ * ADR 0115). Moved here from `@loomwork/effect-runtime`, which keeps a deprecated copy for one minor.
8
+ */
9
+ class A2AEffect {
10
+ fn;
11
+ kind = "a2a";
12
+ constructor(fn) {
13
+ this.fn = fn;
14
+ }
15
+ execute(input, ctx) {
16
+ return this.fn(input, ctx);
17
+ }
18
+ }
19
+ exports.A2AEffect = A2AEffect;
20
+ //# sourceMappingURL=A2AEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"A2AEffect.js","sourceRoot":"","sources":["../src/A2AEffect.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACH,MAAa,SAAS;IAGS;IAFpB,IAAI,GAAG,KAAc,CAAC;IAE/B,YAA6B,EAAqD;QAArD,OAAE,GAAF,EAAE,CAAmD;IAAG,CAAC;IAEtF,OAAO,CAAC,KAAU,EAAE,GAAkB;QACpC,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC7B,CAAC;CACF;AARD,8BAQC"}
@@ -0,0 +1,126 @@
1
+ import type { TaintedValue } from "@loomwork/classify";
2
+ import type { AgentDefinition, ToolDefinition } from "@loomwork/core";
3
+ import type { Effect, EffectRuntime } from "@loomwork/effect-runtime";
4
+ import type { A2ATaskResult, AgentCard } from "./types";
5
+ /**
6
+ * Turns a remote A2A agent (Google ADK, a LangGraph/CrewAI A2A shim, or another
7
+ * Loom `createA2AServer`) into a callable Loom tool. This is the outbound half
8
+ * of the bidirectional mesh — the A2A analogue of `McpClient.registerInto`.
9
+ *
10
+ * The remote agent is discovered via its AgentCard (`/.well-known/agent.json`)
11
+ * and registered into an `EffectRuntime` so Loom agents, steps and the planner
12
+ * can invoke it like any other tool.
13
+ */
14
+ export interface A2APeerConfig<TTaint extends boolean = false> {
15
+ /** Base URL of the remote A2A agent (no trailing path). */
16
+ url: string;
17
+ /** Extra headers (auth etc.) sent on discovery and every task call. */
18
+ headers?: Record<string, string>;
19
+ /** Overall per-call timeout, forwarded to the underlying client effect. */
20
+ timeoutMs?: number;
21
+ /** Poll interval while waiting for the remote task to reach a terminal state. */
22
+ pollIntervalMs?: number;
23
+ /** Override the registered tool id. Defaults to a slug of the card name. */
24
+ toolId?: string;
25
+ /**
26
+ * Mark the peer's `content` as untrusted (ADR 0085), stamped `a2a:<toolId>`.
27
+ * The prompt boundary in `@loomwork/llm` then REFUSES it in any instruction
28
+ * position — system prompt, assistant turn, tool description — and fences it
29
+ * in a `user` message.
30
+ *
31
+ * A peer agent writes its own artifact text, and a peer is exactly as
32
+ * trustworthy as whoever operates it. This is the switch that makes that fact
33
+ * travel with the value.
34
+ *
35
+ * Everything the peer wrote as text is tainted: `content`, and `raw.artifacts` and `raw.error`,
36
+ * which hold the same words. Not the whole output, unlike `mcpInvoke$`: `raw.id` and `raw.status`
37
+ * feed control flow, and forcing an `unwrapTainted()` on code that never touches a prompt would be
38
+ * friction in the wrong place. `content` is the flattened text, so `peer.content` drops straight
39
+ * into an `LlmMessage` slot where the guard sees it.
40
+ *
41
+ * Typed, not just documented: the flag's literal type selects the output
42
+ * type, so a caller that does not opt in sees `A2APeerOutput` exactly as
43
+ * before and compiles unchanged.
44
+ */
45
+ taintResults?: TTaint;
46
+ /**
47
+ * Vouch for the peer's AgentCard text (ADR 0125 D14; the equivalent of MCP's `trustDescriptions`).
48
+ * Default false: an agent loop shows the model only a neutral placeholder for this peer's
49
+ * description, because the card is written by whoever operates the peer. Set it only for a peer you
50
+ * operate or trust; its card text then reaches the model as instructions, unguarded (a one-time
51
+ * `LOOM_AGENT_TRUSTED_TOOL_TEXT` warning says so).
52
+ */
53
+ trustDescriptions?: boolean;
54
+ }
55
+ /** Friendly input accepted by a peer tool — a plain prompt plus optional context. */
56
+ export interface A2APeerInput {
57
+ prompt: string;
58
+ context?: unknown;
59
+ }
60
+ /** Peer tool output — flattened artifact text plus the raw A2A result. */
61
+ export interface A2APeerOutput {
62
+ content: string;
63
+ raw: A2ATaskResult;
64
+ }
65
+ /** {@link A2APeerOutput} under `taintResults` — the text carries its provenance. */
66
+ export interface TaintedA2APeerOutput {
67
+ content: TaintedValue<string>;
68
+ raw: Omit<A2ATaskResult, "artifacts" | "error"> & {
69
+ artifacts?: TaintedValue<NonNullable<A2ATaskResult["artifacts"]>>;
70
+ error?: TaintedValue<string>;
71
+ };
72
+ }
73
+ /**
74
+ * The output shape implied by the `taintResults` flag. A `boolean` (rather than
75
+ * a literal) distributes to the union, which is the honest answer when the flag
76
+ * is only known at runtime.
77
+ */
78
+ export type A2APeerOutputFor<TTaint extends boolean> = TTaint extends true ? TaintedA2APeerOutput : A2APeerOutput;
79
+ /** The trio produced when mapping a remote agent: card, tool definition, effect. */
80
+ export interface MappedA2APeer<TTaint extends boolean = false> {
81
+ card: AgentCard;
82
+ definition: ToolDefinition<A2APeerInput, A2APeerOutputFor<TTaint>>;
83
+ effect: Effect<A2APeerInput, A2APeerOutputFor<TTaint>>;
84
+ }
85
+ /**
86
+ * Structural view of `@loomwork/registry`'s `AgentRegistry.register`. Declared here
87
+ * so `@loomwork/plugin-a2a` stays dependency-light and does not import the registry package
88
+ * (which itself avoids depending on a2a for the same reason).
89
+ */
90
+ export interface PeerAgentRegistrar {
91
+ register(definition: AgentDefinition, card?: RegisteredPeerCard): unknown;
92
+ }
93
+ interface RegisteredPeerCard {
94
+ name: string;
95
+ description?: string;
96
+ url?: string;
97
+ version: string;
98
+ capabilities?: {
99
+ streaming?: boolean;
100
+ };
101
+ skills?: Array<{
102
+ id: string;
103
+ name: string;
104
+ description?: string;
105
+ }>;
106
+ }
107
+ /** Fetch a remote agent's AgentCard from its well-known discovery endpoint. */
108
+ export declare function fetchAgentCard(url: string, headers?: Record<string, string>): Promise<AgentCard>;
109
+ export declare class A2APeerClient<TTaint extends boolean = false> {
110
+ private readonly config;
111
+ private card;
112
+ constructor(config: A2APeerConfig<TTaint>);
113
+ /** Fetch and cache the remote AgentCard. */
114
+ discover(): Promise<AgentCard>;
115
+ /** Discover the peer and build its Loom tool definition + effect (no registration). */
116
+ map(): Promise<MappedA2APeer<TTaint>>;
117
+ /**
118
+ * Discover the peer, register it as an effect, and return the tool definition.
119
+ * Pass a registry to also expose the peer to the planner/intent layer.
120
+ */
121
+ registerInto(effectRuntime: EffectRuntime, registry?: PeerAgentRegistrar): Promise<ToolDefinition<A2APeerInput, A2APeerOutputFor<TTaint>>>;
122
+ /** Adapter effect: friendly input -> A2ATask -> underlying client -> flattened output. */
123
+ private buildEffect;
124
+ }
125
+ export {};
126
+ //# sourceMappingURL=A2APeerClient.d.ts.map
@@ -0,0 +1 @@
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