pi-a2a-adaptor 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ww2521
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # pi-a2a-adaptor
2
+
3
+ > A2A protocol client for [pi coding agent](https://pi.dev) — fully compatible with [fasta2a](https://github.com/datalayer/fasta2a) and the [A2A Protocol](https://a2a-protocol.org).
4
+
5
+ ## Overview
6
+
7
+ **pi-a2a-adaptor** enables [pi coding agent](https://pi.dev) to discover, communicate with, and orchestrate other A2A-compliant agents. It provides a full A2A client implementation that strictly follows the A2A protocol wire format (tested against fasta2a v0.6.1).
8
+
9
+ Inspired by [pi-a2a-communication](https://github.com/DrOlu/pi-a2a-communication), this project is a ground-up rewrite that strictly implements the latest A2A protocol specification, making it fully compatible with [fasta2a](https://github.com/datalayer/fasta2a) and other A2A-compliant servers.
10
+
11
+ ## Features
12
+
13
+ - **Agent Discovery** — Auto-discover remote agents via `/.well-known/agent-card.json`
14
+ - **Task Management** — Send tasks, poll status, cancel, and list remote tasks
15
+ - **Streaming** — SSE-based real-time task progress via `message/stream`
16
+ - **Task Orchestration** — Chain and parallel task execution with artifact passing
17
+ - **Long-running Tasks** — Configurable polling with timeout for tasks that take minutes
18
+ - **Push Notifications** — Register callback URLs for async task completion
19
+ - **11 Commands** — Full CLI interface via `/a2a-*` commands
20
+ - **2 Tools** — LLM-callable tools for single and parallel agent calls
21
+
22
+ ## Quick Start
23
+
24
+ ### Install as pi Extension
25
+
26
+ ```bash
27
+ # Clone into pi's global extensions directory
28
+ git clone https://github.com/ww2521/pi-a2a-adaptor.git ~/.pi/agent/extensions/pi-a2a-adaptor
29
+ ```
30
+
31
+ > **No build step required.** pi uses [jiti](https://github.com/unjs/jiti) to load TypeScript directly.
32
+
33
+ ### Reload pi
34
+
35
+ ```
36
+ /reload
37
+ ```
38
+
39
+ ### Discover an Agent
40
+
41
+ ```
42
+ /a2a-discover https://your-agent.example.com
43
+ ```
44
+
45
+ ### Send a Task
46
+
47
+ ```
48
+ /a2a-send https://your-agent.example.com "Analyze this code for bugs"
49
+ ```
50
+
51
+ ### Broadcast to Multiple Agents
52
+
53
+ ```
54
+ /a2a-broadcast "Review this code for security issues" --agents https://agent1.com,https://agent2.com
55
+ ```
56
+
57
+ ### Chain Tasks (Pipeline)
58
+
59
+ ```
60
+ /a2a-chain scout "Find bugs in main.py" | worker "Fix {previous}"
61
+ ```
62
+
63
+ ## Commands
64
+
65
+ | Command | Description |
66
+ |---|---|
67
+ | `/a2a-discover <url>` | Discover an A2A agent at a URL |
68
+ | `/a2a-agents` | List all discovered agents |
69
+ | `/a2a-send <agent> <message>` | Send a task to an agent (auto-polls for completion) |
70
+ | `/a2a-broadcast <msg> --agents <urls>` | Broadcast to multiple agents in parallel |
71
+ | `/a2a-chain <agent1> <task1> \| <agent2> <task2>` | Chain tasks sequentially (`{previous}` placeholder) |
72
+ | `/a2a-status <task-id> <agent-url>` | Get task status |
73
+ | `/a2a-cancel <task-id> <agent-url>` | Cancel a task |
74
+ | `/a2a-list <agent-url> [context-id]` | List tasks on a remote agent |
75
+ | `/a2a-resubscribe <task-id> <agent-url>` | Resubscribe to a task's event stream |
76
+ | `/a2a-config <key> <value>` | Configure timeout, retries, cache TTL, etc. |
77
+ | `/a2a-help` | Show help |
78
+
79
+ ## LLM Tools
80
+
81
+ - **`a2a_call`** — Call a single A2A agent with a task message
82
+ - **`a2a_parallel`** — Call multiple A2A agents in parallel with the same message
83
+
84
+ ## Protocol Compliance
85
+
86
+ This client implements the A2A protocol wire format as used by [fasta2a v0.6.1](https://github.com/datalayer/fasta2a):
87
+
88
+ | Feature | Implementation |
89
+ |---|---|
90
+ | JSON-RPC methods | `message/send`, `message/stream`, `tasks/get`, `tasks/cancel`, `tasks/list`, `tasks/resubscribe`, `tasks/pushNotification/*` |
91
+ | Dispatch endpoint | `POST /` (unified JSON-RPC) |
92
+ | Agent Card | `GET /.well-known/agent-card.json` |
93
+ | Part types | discriminated union via `kind` (`"text"`, `"file"`, `"data"`) |
94
+ | SSE events | JSON-RPC envelope with `result.kind` (`"task"`, `"status-update"`, `"artifact-update"`) |
95
+ | Task states | `submitted`, `working`, `inputRequired`, `completed`, `failed`, `canceled`, `rejected` |
96
+
97
+ ## Project Structure
98
+
99
+ ```
100
+ pi-a2a-adaptor/
101
+ ├── src/
102
+ │ ├── client.ts # A2AClient core (HTTP, SSE, polling)
103
+ │ ├── registry.ts # AgentRegistry with TTL caching
104
+ │ ├── task-manager.ts # TaskManager (chain / parallel)
105
+ │ ├── types.ts # Full A2A type definitions
106
+ │ └── errors.ts # Semantic error types
107
+ ├── pi-extension/
108
+ │ └── index.ts # pi extension entry (commands + tools)
109
+ └── tests/
110
+ └── a2a-client.test.ts # 60 integration tests
111
+ ```
112
+
113
+ ## Testing
114
+
115
+ ```bash
116
+ npm install
117
+ npx vitest run
118
+ ```
119
+
120
+ The test suite runs 60 integration tests against a mock A2A server that implements the fasta2a wire format, covering:
121
+
122
+ - Agent Card discovery
123
+ - `message/send` (sync and async with polling)
124
+ - `message/stream` (SSE event parsing)
125
+ - `tasks/get`, `tasks/cancel`, `tasks/list`
126
+ - `tasks/resubscribe`
127
+ - Push notification lifecycle (set / get / list / delete)
128
+ - Part types (text, file-bytes, file-uri, data)
129
+ - Long-running task polling with timeout
130
+ - Error code handling
131
+
132
+ ## Configuration
133
+
134
+ Edit `~/.pi/agent/settings.json` or use `/a2a-config` at runtime:
135
+
136
+ ```
137
+ /a2a-config timeout 60000
138
+ /a2a-config retryAttempts 3
139
+ /a2a-config cacheTtl 300000
140
+ /a2a-config verifySsl true
141
+ ```
142
+
143
+ ## Development
144
+
145
+ ```bash
146
+ # Type check
147
+ npx tsc --noEmit
148
+
149
+ # Run tests
150
+ npx vitest run
151
+
152
+ # Run tests in watch mode
153
+ npx vitest
154
+ ```
155
+
156
+ ## License
157
+
158
+ MIT
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "pi-a2a-adaptor",
3
+ "version": "1.0.0",
4
+ "description": "A2A protocol extension for Pi — discover, call, chain, and broadcast tasks to remote AI agents",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "keywords": [
8
+ "pi-package",
9
+ "a2a",
10
+ "agent2agent",
11
+ "agent-protocol",
12
+ "pi-extension"
13
+ ],
14
+ "files": [
15
+ "src",
16
+ "pi-extension",
17
+ "README.md"
18
+ ],
19
+ "pi": {
20
+ "extensions": [
21
+ "./pi-extension/index.ts"
22
+ ]
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^25.9.3",
26
+ "typescript": "^6.0.3",
27
+ "vitest": "^4.1.9"
28
+ }
29
+ }