agentalk 0.1.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 +21 -0
- package/README.md +445 -0
- package/README.zh-CN.md +445 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +141 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +29 -0
- package/dist/client.js +151 -0
- package/dist/client.js.map +1 -0
- package/dist/commands/agent.d.ts +4 -0
- package/dist/commands/agent.js +13 -0
- package/dist/commands/agent.js.map +1 -0
- package/dist/commands/send.d.ts +10 -0
- package/dist/commands/send.js +19 -0
- package/dist/commands/send.js.map +1 -0
- package/dist/commands/stream.d.ts +8 -0
- package/dist/commands/stream.js +19 -0
- package/dist/commands/stream.js.map +1 -0
- package/dist/commands/task.d.ts +17 -0
- package/dist/commands/task.js +53 -0
- package/dist/commands/task.js.map +1 -0
- package/dist/format.d.ts +9 -0
- package/dist/format.js +182 -0
- package/dist/format.js.map +1 -0
- package/dist/types.d.ts +149 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# ⚡ agentalk
|
|
4
|
+
|
|
5
|
+
**AI 智能体的 curl — 通用 A2A 协议命令行工具**
|
|
6
|
+
|
|
7
|
+
从终端发现、对话、流式交互、管理任何兼容 A2A 协议的智能体。
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/agentalk)
|
|
10
|
+
[](https://github.com/IchenDEV/agentalk/blob/main/LICENSE)
|
|
11
|
+
[](https://nodejs.org)
|
|
12
|
+
[](https://www.typescriptlang.org/)
|
|
13
|
+
[](https://google.github.io/A2A/)
|
|
14
|
+
[](#快速开始)
|
|
15
|
+
[](https://github.com/IchenDEV/agentalk/pulls)
|
|
16
|
+
|
|
17
|
+
<br />
|
|
18
|
+
|
|
19
|
+
[🇬🇧 English](./README.md) · [报告 Bug](https://github.com/IchenDEV/agentalk/issues) · [功能建议](https://github.com/IchenDEV/agentalk/issues)
|
|
20
|
+
|
|
21
|
+
<br />
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
╭──────────────────────────────────────────────────╮
|
|
25
|
+
│ │
|
|
26
|
+
│ $ agentalk agent https://my-agent.example.com │
|
|
27
|
+
│ │
|
|
28
|
+
│ 🤖 食谱助手 │
|
|
29
|
+
│ v1.0.0 │
|
|
30
|
+
│ 帮你搜索食谱和烹饪指南 │
|
|
31
|
+
│ │
|
|
32
|
+
│ Skills: │
|
|
33
|
+
│ • 食谱搜索 (recipe-search) │
|
|
34
|
+
│ 根据食材或菜系搜索食谱 │
|
|
35
|
+
│ │
|
|
36
|
+
│ $ agentalk send https://my-agent.example.com \ │
|
|
37
|
+
│ -m "帮我找一道意面食谱" │
|
|
38
|
+
│ │
|
|
39
|
+
│ agent: 这是一道经典的卡博纳拉意面... │
|
|
40
|
+
│ │
|
|
41
|
+
╰──────────────────────────────────────────────────╯
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 目录
|
|
49
|
+
|
|
50
|
+
- [为什么选择 agentalk?](#为什么选择-agentalk)
|
|
51
|
+
- [快速开始](#快速开始)
|
|
52
|
+
- [使用方法](#使用方法)
|
|
53
|
+
- [发现智能体](#-发现智能体)
|
|
54
|
+
- [发送消息](#-发送消息)
|
|
55
|
+
- [流式响应](#-流式响应)
|
|
56
|
+
- [管理任务](#-管理任务)
|
|
57
|
+
- [命令速查](#命令速查)
|
|
58
|
+
- [实用技巧](#实用技巧)
|
|
59
|
+
- [任务状态说明](#任务状态说明)
|
|
60
|
+
- [架构](#架构)
|
|
61
|
+
- [本地开发](#本地开发)
|
|
62
|
+
- [贡献指南](#贡献指南)
|
|
63
|
+
- [开源协议](#开源协议)
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 为什么选择 agentalk?
|
|
68
|
+
|
|
69
|
+
[A2A(Agent-to-Agent)协议](https://google.github.io/A2A/) 是 Google 发起的开放标准,让 AI 智能体之间可以互相通信。**agentalk** 把这个协议带到了你的终端。
|
|
70
|
+
|
|
71
|
+
<table>
|
|
72
|
+
<tr>
|
|
73
|
+
<td width="50">🔍</td>
|
|
74
|
+
<td><strong>发现</strong></td>
|
|
75
|
+
<td>获取并查看 Agent Card,了解智能体的能力</td>
|
|
76
|
+
</tr>
|
|
77
|
+
<tr>
|
|
78
|
+
<td>💬</td>
|
|
79
|
+
<td><strong>对话</strong></td>
|
|
80
|
+
<td>发送消息,获取结构化响应</td>
|
|
81
|
+
</tr>
|
|
82
|
+
<tr>
|
|
83
|
+
<td>🌊</td>
|
|
84
|
+
<td><strong>流式</strong></td>
|
|
85
|
+
<td>通过 SSE 实时流式接收长任务输出</td>
|
|
86
|
+
</tr>
|
|
87
|
+
<tr>
|
|
88
|
+
<td>📋</td>
|
|
89
|
+
<td><strong>任务</strong></td>
|
|
90
|
+
<td>完整的任务生命周期管理 — 查询、列表、取消</td>
|
|
91
|
+
</tr>
|
|
92
|
+
<tr>
|
|
93
|
+
<td>🎨</td>
|
|
94
|
+
<td><strong>美化输出</strong></td>
|
|
95
|
+
<td>彩色人类可读格式;<code>--json</code> 切换机器可读</td>
|
|
96
|
+
</tr>
|
|
97
|
+
<tr>
|
|
98
|
+
<td>🔒</td>
|
|
99
|
+
<td><strong>认证支持</strong></td>
|
|
100
|
+
<td>通过 HTTP Header 传递 Bearer Token、API Key 等</td>
|
|
101
|
+
</tr>
|
|
102
|
+
<tr>
|
|
103
|
+
<td>🏢</td>
|
|
104
|
+
<td><strong>多租户</strong></td>
|
|
105
|
+
<td>内置租户隔离,使用 <code>--tenant</code> 切换</td>
|
|
106
|
+
</tr>
|
|
107
|
+
</table>
|
|
108
|
+
|
|
109
|
+
## 快速开始
|
|
110
|
+
|
|
111
|
+
### 全局安装
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pnpm add -g agentalk
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 或通过 pnpm dlx 直接运行
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
pnpm dlx agentalk agent https://agent.example.com
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
> [!TIP]
|
|
124
|
+
> 无需任何配置。指向任何 A2A 兼容的智能体 URL 即可使用。
|
|
125
|
+
|
|
126
|
+
## 使用方法
|
|
127
|
+
|
|
128
|
+
### 🔍 发现智能体
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
agentalk agent https://agent.example.com
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
<details>
|
|
135
|
+
<summary>📸 <strong>输出示例</strong></summary>
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
🤖 Recipe Agent
|
|
139
|
+
v1.0.0
|
|
140
|
+
帮助用户搜索食谱和烹饪指南的智能体
|
|
141
|
+
|
|
142
|
+
Provider:
|
|
143
|
+
Google (https://ai.google.dev)
|
|
144
|
+
|
|
145
|
+
Capabilities:
|
|
146
|
+
streaming, push-notifications
|
|
147
|
+
|
|
148
|
+
Skills:
|
|
149
|
+
• Recipe Search (recipe-search)
|
|
150
|
+
根据食材或菜系搜索食谱
|
|
151
|
+
tags: cooking, recipes, food
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
</details>
|
|
155
|
+
|
|
156
|
+
### 💬 发送消息
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# 简单消息
|
|
160
|
+
agentalk send https://agent.example.com -m "你能做什么?"
|
|
161
|
+
|
|
162
|
+
# 带上下文的多轮对话
|
|
163
|
+
agentalk send https://agent.example.com -m "继续说" -c ctx_abc123
|
|
164
|
+
|
|
165
|
+
# 继续已有任务
|
|
166
|
+
agentalk send https://agent.example.com -m "好的,继续" -t task_xyz
|
|
167
|
+
|
|
168
|
+
# 异步发送(不等待完成)
|
|
169
|
+
agentalk send https://agent.example.com -m "处理这份报告" --async
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 🌊 流式响应
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
agentalk stream https://agent.example.com -m "生成一份详细分析"
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
<details>
|
|
179
|
+
<summary>📸 <strong>输出示例</strong>(实时流式)</summary>
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
[task-42] status → working
|
|
183
|
+
agent: 正在分析数据...
|
|
184
|
+
agent: 以下是主要发现:
|
|
185
|
+
[task-42] 📎 report.md: # 分析报告 ... (final)
|
|
186
|
+
[task-42] status → completed
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
</details>
|
|
190
|
+
|
|
191
|
+
### 📋 管理任务
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
agentalk task get https://agent.example.com task_abc123 # 查看状态
|
|
195
|
+
agentalk task list https://agent.example.com # 列出所有
|
|
196
|
+
agentalk task list https://agent.example.com -s TASK_STATE_COMPLETED # 按状态过滤
|
|
197
|
+
agentalk task cancel https://agent.example.com task_abc123 # 取消任务
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## 命令速查
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
agentalk [选项] [命令]
|
|
206
|
+
|
|
207
|
+
命令:
|
|
208
|
+
agent <url> 获取并展示 Agent Card
|
|
209
|
+
send [选项] <url> 向智能体发送消息
|
|
210
|
+
stream [选项] <url> 发送消息并流式接收响应(SSE)
|
|
211
|
+
task get <url> <taskId> 通过 ID 获取任务
|
|
212
|
+
task list [选项] <url> 列出任务
|
|
213
|
+
task cancel <url> <taskId> 取消任务
|
|
214
|
+
|
|
215
|
+
全局选项:
|
|
216
|
+
--json 输出原始 JSON(方便管道和脚本处理)
|
|
217
|
+
-H, --header <key:value> 添加 HTTP 头(可重复使用)
|
|
218
|
+
--tenant <id> 租户 ID(多租户场景)
|
|
219
|
+
-V, --version 显示版本号
|
|
220
|
+
-h, --help 显示帮助信息
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
<details>
|
|
224
|
+
<summary><code>send</code> 选项</summary>
|
|
225
|
+
|
|
226
|
+
| 参数 | 说明 |
|
|
227
|
+
|------|------|
|
|
228
|
+
| `-m, --message <text>` | 消息内容 **(必填)** |
|
|
229
|
+
| `-c, --context <id>` | 上下文 ID,用于多轮对话 |
|
|
230
|
+
| `-t, --task <id>` | 任务 ID,继续已有任务 |
|
|
231
|
+
| `--output-modes <modes>` | 可接受的输出 MIME 类型(逗号分隔) |
|
|
232
|
+
| `--history-length <n>` | 返回的最大历史消息数 |
|
|
233
|
+
| `--async` | 立即返回,不等待任务完成 |
|
|
234
|
+
|
|
235
|
+
</details>
|
|
236
|
+
|
|
237
|
+
<details>
|
|
238
|
+
<summary><code>stream</code> 选项</summary>
|
|
239
|
+
|
|
240
|
+
| 参数 | 说明 |
|
|
241
|
+
|------|------|
|
|
242
|
+
| `-m, --message <text>` | 消息内容 **(必填)** |
|
|
243
|
+
| `-c, --context <id>` | 上下文 ID,用于多轮对话 |
|
|
244
|
+
| `-t, --task <id>` | 任务 ID,继续已有任务 |
|
|
245
|
+
| `--output-modes <modes>` | 可接受的输出 MIME 类型(逗号分隔) |
|
|
246
|
+
|
|
247
|
+
</details>
|
|
248
|
+
|
|
249
|
+
<details>
|
|
250
|
+
<summary><code>task list</code> 选项</summary>
|
|
251
|
+
|
|
252
|
+
| 参数 | 说明 |
|
|
253
|
+
|------|------|
|
|
254
|
+
| `-c, --context <id>` | 按上下文 ID 过滤 |
|
|
255
|
+
| `-s, --status <state>` | 按任务状态过滤 |
|
|
256
|
+
| `--history-length <n>` | 每个任务的最大历史消息数 |
|
|
257
|
+
| `--artifacts` | 包含产物(Artifacts) |
|
|
258
|
+
| `--page-size <n>` | 每页结果数 |
|
|
259
|
+
| `--page-token <token>` | 分页令牌 |
|
|
260
|
+
|
|
261
|
+
</details>
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## 实用技巧
|
|
266
|
+
|
|
267
|
+
### 配合 jq 处理 JSON
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
# 提取任务状态
|
|
271
|
+
agentalk --json task get https://agent.example.com task_123 | jq '.status.state'
|
|
272
|
+
|
|
273
|
+
# 获取所有技能名称
|
|
274
|
+
agentalk --json agent https://agent.example.com | jq '.skills[].name'
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### 带认证使用
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
# Bearer Token
|
|
281
|
+
agentalk agent https://agent.example.com -H "Authorization: Bearer sk-xxx"
|
|
282
|
+
|
|
283
|
+
# API Key
|
|
284
|
+
agentalk send https://agent.example.com -m "你好" -H "X-API-Key: key_xxx"
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### 多轮对话
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
# 1. 开始对话 — 获取 contextId
|
|
291
|
+
CTX=$(agentalk --json send https://agent.example.com -m "帮我规划一次东京旅行" \
|
|
292
|
+
| jq -r '.task.contextId')
|
|
293
|
+
|
|
294
|
+
# 2. 带上下文继续
|
|
295
|
+
agentalk send https://agent.example.com -m "改成 5 天的行程" -c "$CTX"
|
|
296
|
+
|
|
297
|
+
# 3. 在同一任务上继续
|
|
298
|
+
agentalk send https://agent.example.com -m "加上餐厅推荐" -c "$CTX" -t task-xyz
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### 多租户场景
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
agentalk --tenant org_acme send https://agent.example.com -m "你好"
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## 任务状态说明
|
|
310
|
+
|
|
311
|
+
| 状态 | 图标 | 说明 |
|
|
312
|
+
|------|------|------|
|
|
313
|
+
| `TASK_STATE_SUBMITTED` | 📥 | 任务已提交,等待处理 |
|
|
314
|
+
| `TASK_STATE_WORKING` | ⏳ | 智能体正在处理中 |
|
|
315
|
+
| `TASK_STATE_COMPLETED` | ✅ | 任务成功完成 |
|
|
316
|
+
| `TASK_STATE_FAILED` | ❌ | 任务处理失败 |
|
|
317
|
+
| `TASK_STATE_CANCELED` | 🚫 | 任务已取消 |
|
|
318
|
+
| `TASK_STATE_INPUT_REQUIRED` | 💬 | 智能体需要更多输入 |
|
|
319
|
+
| `TASK_STATE_REJECTED` | ⛔ | 智能体拒绝了该任务 |
|
|
320
|
+
| `TASK_STATE_AUTH_REQUIRED` | 🔐 | 需要认证 |
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## 架构
|
|
325
|
+
|
|
326
|
+
```mermaid
|
|
327
|
+
graph LR
|
|
328
|
+
subgraph CLI["🖥️ CLI 层"]
|
|
329
|
+
A[cli.ts<br/>Commander.js] --> B[commands/agent.ts]
|
|
330
|
+
A --> C[commands/send.ts]
|
|
331
|
+
A --> D[commands/stream.ts]
|
|
332
|
+
A --> E[commands/task.ts]
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
subgraph Core["⚙️ 核心层"]
|
|
336
|
+
F[client.ts<br/>A2AClient]
|
|
337
|
+
G[format.ts<br/>chalk 美化输出]
|
|
338
|
+
H[types.ts<br/>A2A v1.0 类型]
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
B & C & D & E --> F
|
|
342
|
+
B & C & D & E --> G
|
|
343
|
+
F --> H
|
|
344
|
+
|
|
345
|
+
subgraph Remote["☁️ 远程智能体"]
|
|
346
|
+
I["/.well-known/agent.json"]
|
|
347
|
+
J["POST /"]
|
|
348
|
+
K["POST /stream (SSE)"]
|
|
349
|
+
L["GET/POST /tasks/*"]
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
F -->|HTTP| I & J & K & L
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
<details>
|
|
356
|
+
<summary>📁 <strong>项目结构</strong></summary>
|
|
357
|
+
|
|
358
|
+
```
|
|
359
|
+
src/
|
|
360
|
+
├── cli.ts # 入口 — Commander.js CLI 配置
|
|
361
|
+
├── client.ts # A2AClient — 封装所有 A2A HTTP 操作
|
|
362
|
+
├── format.ts # 美化输出格式化器(基于 chalk)
|
|
363
|
+
├── types.ts # 完整的 A2A Protocol v1.0 TypeScript 类型
|
|
364
|
+
├── commands/
|
|
365
|
+
│ ├── agent.ts # `agentalk agent` 命令
|
|
366
|
+
│ ├── send.ts # `agentalk send` 命令
|
|
367
|
+
│ ├── stream.ts # `agentalk stream` 命令
|
|
368
|
+
│ └── task.ts # `agentalk task {get,list,cancel}` 命令
|
|
369
|
+
└── test/
|
|
370
|
+
├── client.test.ts # A2AClient 单元测试(mock fetch)
|
|
371
|
+
├── format.test.ts # 格式化器单元测试
|
|
372
|
+
└── cli.test.ts # CLI 集成测试
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
</details>
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## 本地开发
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
# 安装依赖
|
|
383
|
+
pnpm install
|
|
384
|
+
|
|
385
|
+
# 构建
|
|
386
|
+
pnpm build
|
|
387
|
+
|
|
388
|
+
# 监听模式
|
|
389
|
+
pnpm dev
|
|
390
|
+
|
|
391
|
+
# 运行测试(72 个测试用例)
|
|
392
|
+
pnpm test
|
|
393
|
+
|
|
394
|
+
# 全局链接,方便本地调试
|
|
395
|
+
pnpm link --global
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### 环境要求
|
|
399
|
+
|
|
400
|
+
| 依赖 | 版本 |
|
|
401
|
+
|------|------|
|
|
402
|
+
| Node.js | ≥ 22 |
|
|
403
|
+
| TypeScript | ≥ 5.7 |
|
|
404
|
+
|
|
405
|
+
> [!NOTE]
|
|
406
|
+
> 使用原生 `fetch`(无需 polyfill)和 `node:test` 实现零依赖测试。
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
|
|
410
|
+
## 贡献指南
|
|
411
|
+
|
|
412
|
+
欢迎贡献!步骤如下:
|
|
413
|
+
|
|
414
|
+
1. Fork 本仓库
|
|
415
|
+
2. 创建分支(`git checkout -b feat/amazing-feature`)
|
|
416
|
+
3. 开发你的功能
|
|
417
|
+
4. 运行测试(`pnpm test`)
|
|
418
|
+
5. 提交代码(`git commit -m 'feat: add amazing feature'`)
|
|
419
|
+
6. 推送分支(`git push origin feat/amazing-feature`)
|
|
420
|
+
7. 发起 Pull Request
|
|
421
|
+
|
|
422
|
+
> [!NOTE]
|
|
423
|
+
> 请遵循 [Conventional Commits](https://www.conventionalcommits.org/) 规范编写提交信息。
|
|
424
|
+
|
|
425
|
+
---
|
|
426
|
+
|
|
427
|
+
## 相关链接
|
|
428
|
+
|
|
429
|
+
| 资源 | 链接 |
|
|
430
|
+
|------|------|
|
|
431
|
+
| A2A 协议规范 | [google.github.io/A2A](https://google.github.io/A2A/) |
|
|
432
|
+
| A2A GitHub | [github.com/google/A2A](https://github.com/google/A2A) |
|
|
433
|
+
| npm 包 | [npmjs.com/package/agentalk](https://www.npmjs.com/package/agentalk) |
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
<div align="center">
|
|
438
|
+
|
|
439
|
+
**[MIT](./LICENSE) © 2026**
|
|
440
|
+
|
|
441
|
+
用 ❤️ 为 A2A 生态而造
|
|
442
|
+
|
|
443
|
+
[⬆ 回到顶部](#-agentalk)
|
|
444
|
+
|
|
445
|
+
</div>
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { agentCommand } from "./commands/agent.js";
|
|
5
|
+
import { sendCommand } from "./commands/send.js";
|
|
6
|
+
import { streamCommand } from "./commands/stream.js";
|
|
7
|
+
import { taskGetCommand, taskCancelCommand, taskListCommand } from "./commands/task.js";
|
|
8
|
+
const program = new Command();
|
|
9
|
+
function parseHeaders(val, prev) {
|
|
10
|
+
const [key, ...rest] = val.split(":");
|
|
11
|
+
prev[key.trim()] = rest.join(":").trim();
|
|
12
|
+
return prev;
|
|
13
|
+
}
|
|
14
|
+
program
|
|
15
|
+
.name("agentalk")
|
|
16
|
+
.description("A2A Protocol CLI client — discover and interact with A2A agents")
|
|
17
|
+
.version("0.1.0");
|
|
18
|
+
// Global options
|
|
19
|
+
program
|
|
20
|
+
.option("--json", "Output raw JSON")
|
|
21
|
+
.option("-H, --header <key:value>", "Add HTTP header (repeatable)", parseHeaders, {})
|
|
22
|
+
.option("--tenant <id>", "Tenant ID");
|
|
23
|
+
// agentalk agent <url>
|
|
24
|
+
program
|
|
25
|
+
.command("agent")
|
|
26
|
+
.description("Fetch and display an agent card")
|
|
27
|
+
.argument("<url>", "Agent base URL")
|
|
28
|
+
.action(async (url) => {
|
|
29
|
+
const opts = program.opts();
|
|
30
|
+
await agentCommand(url, { json: opts.json, headers: opts.header, tenant: opts.tenant });
|
|
31
|
+
});
|
|
32
|
+
// agentalk send <url>
|
|
33
|
+
program
|
|
34
|
+
.command("send")
|
|
35
|
+
.description("Send a message to an agent")
|
|
36
|
+
.argument("<url>", "Agent base URL")
|
|
37
|
+
.requiredOption("-m, --message <text>", "Message text to send")
|
|
38
|
+
.option("-c, --context <id>", "Context ID")
|
|
39
|
+
.option("-t, --task <id>", "Task ID (continue existing task)")
|
|
40
|
+
.option("--output-modes <modes>", "Accepted output MIME types (comma-separated)")
|
|
41
|
+
.option("--history-length <n>", "Max history messages to return")
|
|
42
|
+
.option("--async", "Return immediately without waiting for completion")
|
|
43
|
+
.action(async (url, cmdOpts) => {
|
|
44
|
+
const opts = program.opts();
|
|
45
|
+
await sendCommand(url, {
|
|
46
|
+
...cmdOpts,
|
|
47
|
+
message: cmdOpts.message,
|
|
48
|
+
context: cmdOpts.context,
|
|
49
|
+
task: cmdOpts.task,
|
|
50
|
+
outputModes: cmdOpts.outputModes,
|
|
51
|
+
historyLength: cmdOpts.historyLength,
|
|
52
|
+
async: cmdOpts.async,
|
|
53
|
+
json: opts.json,
|
|
54
|
+
headers: opts.header,
|
|
55
|
+
tenant: opts.tenant,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
// agentalk stream <url>
|
|
59
|
+
program
|
|
60
|
+
.command("stream")
|
|
61
|
+
.description("Send a message and stream the response (SSE)")
|
|
62
|
+
.argument("<url>", "Agent base URL")
|
|
63
|
+
.requiredOption("-m, --message <text>", "Message text to send")
|
|
64
|
+
.option("-c, --context <id>", "Context ID")
|
|
65
|
+
.option("-t, --task <id>", "Task ID")
|
|
66
|
+
.option("--output-modes <modes>", "Accepted output MIME types (comma-separated)")
|
|
67
|
+
.action(async (url, cmdOpts) => {
|
|
68
|
+
const opts = program.opts();
|
|
69
|
+
await streamCommand(url, {
|
|
70
|
+
...cmdOpts,
|
|
71
|
+
message: cmdOpts.message,
|
|
72
|
+
context: cmdOpts.context,
|
|
73
|
+
task: cmdOpts.task,
|
|
74
|
+
outputModes: cmdOpts.outputModes,
|
|
75
|
+
json: opts.json,
|
|
76
|
+
headers: opts.header,
|
|
77
|
+
tenant: opts.tenant,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
// agentalk task <subcommand>
|
|
81
|
+
const task = program.command("task").description("Task management commands");
|
|
82
|
+
// agentalk task get <url> <taskId>
|
|
83
|
+
task
|
|
84
|
+
.command("get")
|
|
85
|
+
.description("Get a task by ID")
|
|
86
|
+
.argument("<url>", "Agent base URL")
|
|
87
|
+
.argument("<taskId>", "Task ID")
|
|
88
|
+
.option("--history-length <n>", "Max history messages to return")
|
|
89
|
+
.action(async (url, taskId, cmdOpts) => {
|
|
90
|
+
const opts = program.opts();
|
|
91
|
+
await taskGetCommand(url, taskId, {
|
|
92
|
+
historyLength: cmdOpts.historyLength,
|
|
93
|
+
json: opts.json,
|
|
94
|
+
headers: opts.header,
|
|
95
|
+
tenant: opts.tenant,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
// agentalk task cancel <url> <taskId>
|
|
99
|
+
task
|
|
100
|
+
.command("cancel")
|
|
101
|
+
.description("Cancel a task")
|
|
102
|
+
.argument("<url>", "Agent base URL")
|
|
103
|
+
.argument("<taskId>", "Task ID")
|
|
104
|
+
.action(async (url, taskId) => {
|
|
105
|
+
const opts = program.opts();
|
|
106
|
+
await taskCancelCommand(url, taskId, {
|
|
107
|
+
json: opts.json,
|
|
108
|
+
headers: opts.header,
|
|
109
|
+
tenant: opts.tenant,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
// agentalk task list <url>
|
|
113
|
+
task
|
|
114
|
+
.command("list")
|
|
115
|
+
.description("List tasks")
|
|
116
|
+
.argument("<url>", "Agent base URL")
|
|
117
|
+
.option("-c, --context <id>", "Filter by context ID")
|
|
118
|
+
.option("-s, --status <state>", "Filter by task state")
|
|
119
|
+
.option("--history-length <n>", "Max history messages per task")
|
|
120
|
+
.option("--artifacts", "Include artifacts")
|
|
121
|
+
.option("--page-size <n>", "Results per page")
|
|
122
|
+
.option("--page-token <token>", "Pagination token")
|
|
123
|
+
.action(async (url, cmdOpts) => {
|
|
124
|
+
const opts = program.opts();
|
|
125
|
+
await taskListCommand(url, {
|
|
126
|
+
context: cmdOpts.context,
|
|
127
|
+
status: cmdOpts.status,
|
|
128
|
+
historyLength: cmdOpts.historyLength,
|
|
129
|
+
artifacts: cmdOpts.artifacts,
|
|
130
|
+
pageSize: cmdOpts.pageSize,
|
|
131
|
+
pageToken: cmdOpts.pageToken,
|
|
132
|
+
json: opts.json,
|
|
133
|
+
headers: opts.header,
|
|
134
|
+
tenant: opts.tenant,
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
program.parseAsync().catch((err) => {
|
|
138
|
+
console.error(chalk.red("Error:"), err.message);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
});
|
|
141
|
+
//# sourceMapping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AE,EAAE;IAC9D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC5B,MAAM,eAAe,CAAC,GAAG,EAAE;QACzB,OAAO,EAAE,OAAO,CAAC,OAA6B;QAC9C,MAAM,EAAE,OAAO,CAAC,MAA4B;QAC5C,aAAa,EAAE,OAAO,CAAC,aAAmC;QAC1D,SAAS,EAAE,OAAO,CAAC,SAAgC;QACnD,QAAQ,EAAE,OAAO,CAAC,QAA8B;QAChD,SAAS,EAAE,OAAO,CAAC,SAA+B;QAClD,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,IAAI,CAAC,MAAM;QACpB,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,GAAU,EAAE,EAAE;IACxC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AgentCard, SendMessageResponse, Task, ListTasksRequest, ListTasksResponse, StreamResponse, Message } from "./types.js";
|
|
2
|
+
export interface ClientOptions {
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
tenant?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class A2AClient {
|
|
7
|
+
private baseUrl;
|
|
8
|
+
private headers;
|
|
9
|
+
private tenant?;
|
|
10
|
+
constructor(baseUrl: string, options?: ClientOptions);
|
|
11
|
+
private url;
|
|
12
|
+
private request;
|
|
13
|
+
getAgentCard(cardUrl?: string): Promise<AgentCard>;
|
|
14
|
+
sendMessage(message: string | Message, options?: {
|
|
15
|
+
contextId?: string;
|
|
16
|
+
taskId?: string;
|
|
17
|
+
acceptedOutputModes?: string[];
|
|
18
|
+
historyLength?: number;
|
|
19
|
+
returnImmediately?: boolean;
|
|
20
|
+
}): Promise<SendMessageResponse>;
|
|
21
|
+
sendMessageStream(message: string | Message, options?: {
|
|
22
|
+
contextId?: string;
|
|
23
|
+
taskId?: string;
|
|
24
|
+
acceptedOutputModes?: string[];
|
|
25
|
+
}): AsyncGenerator<StreamResponse>;
|
|
26
|
+
getTask(taskId: string, historyLength?: number): Promise<Task>;
|
|
27
|
+
cancelTask(taskId: string): Promise<Task>;
|
|
28
|
+
listTasks(options?: Omit<ListTasksRequest, "tenant">): Promise<ListTasksResponse>;
|
|
29
|
+
}
|