@f2a/network 0.1.2 → 0.1.3

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 (136) hide show
  1. package/package.json +8 -1
  2. package/.github/workflows/ci.yml +0 -113
  3. package/.github/workflows/publish.yml +0 -60
  4. package/MONOREPO.md +0 -58
  5. package/SKILL.md +0 -137
  6. package/dist/adapters/openclaw.d.ts +0 -103
  7. package/dist/adapters/openclaw.d.ts.map +0 -1
  8. package/dist/adapters/openclaw.js +0 -297
  9. package/dist/adapters/openclaw.js.map +0 -1
  10. package/dist/core/connection-manager.d.ts +0 -80
  11. package/dist/core/connection-manager.d.ts.map +0 -1
  12. package/dist/core/connection-manager.js +0 -235
  13. package/dist/core/connection-manager.js.map +0 -1
  14. package/dist/core/connection-manager.test.d.ts +0 -2
  15. package/dist/core/connection-manager.test.d.ts.map +0 -1
  16. package/dist/core/connection-manager.test.js +0 -52
  17. package/dist/core/connection-manager.test.js.map +0 -1
  18. package/dist/core/identity.d.ts +0 -47
  19. package/dist/core/identity.d.ts.map +0 -1
  20. package/dist/core/identity.js +0 -130
  21. package/dist/core/identity.js.map +0 -1
  22. package/dist/core/identity.test.d.ts +0 -2
  23. package/dist/core/identity.test.d.ts.map +0 -1
  24. package/dist/core/identity.test.js +0 -43
  25. package/dist/core/identity.test.js.map +0 -1
  26. package/dist/core/serverless.d.ts +0 -155
  27. package/dist/core/serverless.d.ts.map +0 -1
  28. package/dist/core/serverless.js +0 -615
  29. package/dist/core/serverless.js.map +0 -1
  30. package/dist/daemon/webhook.test.d.ts +0 -2
  31. package/dist/daemon/webhook.test.d.ts.map +0 -1
  32. package/dist/daemon/webhook.test.js +0 -24
  33. package/dist/daemon/webhook.test.js.map +0 -1
  34. package/dist/protocol/messages.d.ts +0 -739
  35. package/dist/protocol/messages.d.ts.map +0 -1
  36. package/dist/protocol/messages.js +0 -188
  37. package/dist/protocol/messages.js.map +0 -1
  38. package/dist/protocol/messages.test.d.ts +0 -2
  39. package/dist/protocol/messages.test.d.ts.map +0 -1
  40. package/dist/protocol/messages.test.js +0 -55
  41. package/dist/protocol/messages.test.js.map +0 -1
  42. package/docs/F2A-PROTOCOL.md +0 -61
  43. package/docs/MOBILE_BOOTSTRAP_DESIGN.md +0 -126
  44. package/docs/a2a-lessons.md +0 -316
  45. package/docs/middleware-guide.md +0 -448
  46. package/docs/readme-update-checklist.md +0 -90
  47. package/docs/reputation-guide.md +0 -396
  48. package/docs/rfcs/001-reputation-system.md +0 -712
  49. package/docs/security-design.md +0 -247
  50. package/install.sh +0 -231
  51. package/packages/openclaw-adapter/README.md +0 -510
  52. package/packages/openclaw-adapter/openclaw.plugin.json +0 -106
  53. package/packages/openclaw-adapter/package.json +0 -40
  54. package/packages/openclaw-adapter/src/announcement-queue.test.ts +0 -449
  55. package/packages/openclaw-adapter/src/announcement-queue.ts +0 -403
  56. package/packages/openclaw-adapter/src/capability-detector.test.ts +0 -99
  57. package/packages/openclaw-adapter/src/capability-detector.ts +0 -183
  58. package/packages/openclaw-adapter/src/claim-handlers.test.ts +0 -974
  59. package/packages/openclaw-adapter/src/claim-handlers.ts +0 -482
  60. package/packages/openclaw-adapter/src/connector.business.test.ts +0 -583
  61. package/packages/openclaw-adapter/src/connector.ts +0 -795
  62. package/packages/openclaw-adapter/src/index.test.ts +0 -82
  63. package/packages/openclaw-adapter/src/index.ts +0 -18
  64. package/packages/openclaw-adapter/src/integration.e2e.test.ts +0 -829
  65. package/packages/openclaw-adapter/src/logger.ts +0 -51
  66. package/packages/openclaw-adapter/src/network-client.test.ts +0 -266
  67. package/packages/openclaw-adapter/src/network-client.ts +0 -251
  68. package/packages/openclaw-adapter/src/network-recovery.test.ts +0 -465
  69. package/packages/openclaw-adapter/src/node-manager.test.ts +0 -136
  70. package/packages/openclaw-adapter/src/node-manager.ts +0 -429
  71. package/packages/openclaw-adapter/src/plugin.test.ts +0 -439
  72. package/packages/openclaw-adapter/src/plugin.ts +0 -104
  73. package/packages/openclaw-adapter/src/reputation.test.ts +0 -221
  74. package/packages/openclaw-adapter/src/reputation.ts +0 -368
  75. package/packages/openclaw-adapter/src/task-guard.test.ts +0 -502
  76. package/packages/openclaw-adapter/src/task-guard.ts +0 -860
  77. package/packages/openclaw-adapter/src/task-queue.concurrency.test.ts +0 -462
  78. package/packages/openclaw-adapter/src/task-queue.edge-cases.test.ts +0 -284
  79. package/packages/openclaw-adapter/src/task-queue.persistence.test.ts +0 -408
  80. package/packages/openclaw-adapter/src/task-queue.ts +0 -668
  81. package/packages/openclaw-adapter/src/tool-handlers.test.ts +0 -906
  82. package/packages/openclaw-adapter/src/tool-handlers.ts +0 -574
  83. package/packages/openclaw-adapter/src/types.ts +0 -361
  84. package/packages/openclaw-adapter/src/webhook-pusher.test.ts +0 -188
  85. package/packages/openclaw-adapter/src/webhook-pusher.ts +0 -220
  86. package/packages/openclaw-adapter/src/webhook-server.test.ts +0 -580
  87. package/packages/openclaw-adapter/src/webhook-server.ts +0 -202
  88. package/packages/openclaw-adapter/tsconfig.json +0 -20
  89. package/src/cli/commands.test.ts +0 -157
  90. package/src/cli/commands.ts +0 -129
  91. package/src/cli/index.test.ts +0 -77
  92. package/src/cli/index.ts +0 -234
  93. package/src/core/autonomous-economy.test.ts +0 -291
  94. package/src/core/autonomous-economy.ts +0 -428
  95. package/src/core/e2ee-crypto.test.ts +0 -125
  96. package/src/core/e2ee-crypto.ts +0 -246
  97. package/src/core/f2a.test.ts +0 -269
  98. package/src/core/f2a.ts +0 -618
  99. package/src/core/p2p-network.test.ts +0 -199
  100. package/src/core/p2p-network.ts +0 -1432
  101. package/src/core/reputation-security.test.ts +0 -403
  102. package/src/core/reputation-security.ts +0 -562
  103. package/src/core/reputation.test.ts +0 -260
  104. package/src/core/reputation.ts +0 -576
  105. package/src/core/review-committee.test.ts +0 -380
  106. package/src/core/review-committee.ts +0 -401
  107. package/src/core/token-manager.test.ts +0 -133
  108. package/src/core/token-manager.ts +0 -140
  109. package/src/daemon/control-server.test.ts +0 -216
  110. package/src/daemon/control-server.ts +0 -292
  111. package/src/daemon/index.test.ts +0 -85
  112. package/src/daemon/index.ts +0 -89
  113. package/src/daemon/main.ts +0 -44
  114. package/src/daemon/start.ts +0 -29
  115. package/src/daemon/webhook.test.ts +0 -68
  116. package/src/daemon/webhook.ts +0 -105
  117. package/src/index.test.ts +0 -436
  118. package/src/index.ts +0 -72
  119. package/src/types/index.test.ts +0 -87
  120. package/src/types/index.ts +0 -341
  121. package/src/types/result.ts +0 -68
  122. package/src/utils/benchmark.ts +0 -237
  123. package/src/utils/logger.ts +0 -331
  124. package/src/utils/middleware.ts +0 -229
  125. package/src/utils/rate-limiter.ts +0 -207
  126. package/src/utils/signature.ts +0 -136
  127. package/src/utils/validation.ts +0 -186
  128. package/tests/docker/Dockerfile.node +0 -23
  129. package/tests/docker/Dockerfile.runner +0 -18
  130. package/tests/docker/docker-compose.test.yml +0 -73
  131. package/tests/integration/message-passing.test.ts +0 -109
  132. package/tests/integration/multi-node.test.ts +0 -92
  133. package/tests/integration/p2p-connection.test.ts +0 -83
  134. package/tests/integration/test-config.ts +0 -32
  135. package/tsconfig.json +0 -21
  136. package/vitest.config.ts +0 -26
@@ -1,316 +0,0 @@
1
- # F2A 借鉴 A2A 协议的设计改进
2
-
3
- > 本文档记录从 Google A2A (Agent2Agent) 协议中可以借鉴的设计思路,用于改进 F2A 协议。
4
-
5
- ---
6
-
7
- ## 1. Agent Card 概念
8
-
9
- ### 现状
10
- 当前 F2A 的发现消息仅包含基础信息:
11
- ```javascript
12
- {
13
- type: 'F2A_DISCOVER',
14
- agentId: 'xxx',
15
- publicKey: 'xxx',
16
- port: 9000
17
- }
18
- ```
19
-
20
- ### 借鉴 A2A 的改进
21
- 将发现消息扩展为包含更多元数据,类似 A2A 的 Agent Card:
22
- ```javascript
23
- {
24
- type: 'F2A_DISCOVER',
25
- agentId: 'xxx',
26
- publicKey: 'xxx',
27
- port: 9000,
28
- displayName: 'WeatherAgent',
29
- capabilities: ['chat', 'file_transfer', 'skill_invocation'],
30
- skills: [
31
- {
32
- name: 'weather',
33
- description: 'Get weather info for a location',
34
- parameters: {
35
- location: { type: 'string', required: true },
36
- units: { type: 'string', enum: ['celsius', 'fahrenheit'], default: 'celsius' }
37
- }
38
- },
39
- {
40
- name: 'translate',
41
- description: 'Translate text between languages'
42
- }
43
- ],
44
- authentication: {
45
- requireConfirmation: true,
46
- securityLevel: 'medium'
47
- }
48
- }
49
- ```
50
-
51
- ### 好处
52
- - **能力发现**: 其他 Agent 可以在连接前了解你能做什么
53
- - **动态协商**: 支持交互模式的协商(文本、文件、结构化数据)
54
- - **自描述**: 减少人工配置,实现真正的即插即用
55
-
56
- ---
57
-
58
- ## 2. 任务生命周期管理
59
-
60
- ### 现状
61
- F2A 目前只有简单的消息发送,缺乏任务状态跟踪:
62
- ```javascript
63
- p2p.sendToPeer(peerId, {
64
- type: 'message',
65
- content: '...'
66
- });
67
- ```
68
-
69
- ### 借鉴 A2A 的改进
70
- 引入 A2A 的任务状态机模型:
71
- ```
72
- submitted → working → input-required → completed
73
-
74
- failed / canceled
75
- ```
76
-
77
- ### 实现示例
78
- ```javascript
79
- // 发送任务
80
- const taskId = await p2p.sendTask(peerId, {
81
- skill: 'weather',
82
- parameters: { location: 'Beijing' }
83
- });
84
-
85
- // 任务状态流转
86
- p2p.on('task_update', ({ taskId, status, artifact }) => {
87
- switch (status) {
88
- case 'working':
89
- console.log(`任务 ${taskId} 处理中...`);
90
- break;
91
- case 'input-required':
92
- // 需要用户提供额外信息
93
- console.log(`需要更多信息: ${artifact.description}`);
94
- break;
95
- case 'completed':
96
- console.log(`任务完成: ${artifact.content}`);
97
- break;
98
- case 'failed':
99
- console.log(`任务失败: ${artifact.error}`);
100
- break;
101
- }
102
- });
103
-
104
- // 取消任务
105
- await p2p.cancelTask(peerId, taskId);
106
-
107
- // 查询任务状态
108
- const task = await p2p.getTask(peerId, taskId);
109
- ```
110
-
111
- ### 好处
112
- - **长任务支持**: 适合需要长时间运行的任务
113
- - **人机协作**: 支持 human-in-the-loop 场景
114
- - **可观测性**: 可以跟踪任务进度和状态
115
- - **容错性**: 支持任务取消和失败处理
116
-
117
- ---
118
-
119
- ## 3. 标准化消息格式
120
-
121
- ### 现状
122
- F2A 使用简单的 JSON 消息,缺乏严格的结构定义:
123
- ```javascript
124
- {
125
- type: 'message',
126
- content: '...'
127
- }
128
- ```
129
-
130
- ### 借鉴 A2A 的改进
131
- 参考 A2A 的 Protocol Buffer 定义,设计更严格的 JSON Schema:
132
-
133
- #### 3.1 消息结构标准化
134
- ```javascript
135
- // 基础消息结构
136
- {
137
- // 协议元数据
138
- "protocol": {
139
- "name": "F2A",
140
- "version": "1.0.0"
141
- },
142
-
143
- // 消息元数据
144
- "meta": {
145
- "messageId": "uuid",
146
- "timestamp": 1700000000000,
147
- "senderId": "f2a-xxx-xxx",
148
- "correlationId": "uuid" // 用于关联请求和响应
149
- },
150
-
151
- // 消息负载
152
- "payload": {
153
- "type": "task_request", // task_request | task_response | notification | etc.
154
- "data": { ... }
155
- },
156
-
157
- // 扩展字段
158
- "extensions": {
159
- "customField": "value"
160
- }
161
- }
162
- ```
163
-
164
- #### 3.2 Part 结构(内容单元)
165
- 借鉴 A2A 的 Part 概念,统一内容表示:
166
- ```javascript
167
- // 文本
168
- { "type": "text", "content": "Hello" }
169
-
170
- // 文件
171
- {
172
- "type": "file",
173
- "filename": "report.pdf",
174
- "mimeType": "application/pdf",
175
- "size": 1024000,
176
- "fileId": "uuid" // 引用文件传输系统的 ID
177
- }
178
-
179
- // 结构化数据
180
- {
181
- "type": "data",
182
- "mimeType": "application/json",
183
- "content": { "temperature": 25, "unit": "celsius" }
184
- }
185
-
186
- // 表单/输入请求
187
- {
188
- "type": "form",
189
- "fields": [
190
- { "name": "location", "type": "text", "required": true },
191
- { "name": "units", "type": "select", "options": ["C", "F"] }
192
- ]
193
- }
194
- ```
195
-
196
- #### 3.3 版本兼容性处理
197
- ```javascript
198
- {
199
- "protocol": {
200
- "name": "F2A",
201
- "version": "1.1.0", // 发送方版本
202
- "minCompatibleVersion": "1.0.0" // 最低兼容版本
203
- },
204
-
205
- // 接收方如果不支持某个字段,可以安全忽略
206
- "payload": {
207
- "type": "task_request",
208
- "data": { ... },
209
- "deprecatedField": "..." // 标记废弃的字段
210
- }
211
- }
212
- ```
213
-
214
- #### 3.4 扩展机制
215
- ```javascript
216
- {
217
- "payload": {
218
- "type": "task_request",
219
- "data": { ... }
220
- },
221
-
222
- // 厂商/应用特定扩展
223
- "extensions": {
224
- "com.example.customFeature": { ... },
225
- "org.f2a.streaming": { "enabled": true }
226
- }
227
- }
228
- ```
229
-
230
- ### 好处
231
- - **互操作性**: 严格的结构定义确保不同实现能正确通信
232
- - **向前兼容**: 版本机制支持平滑升级
233
- - **可扩展性**: 扩展机制允许自定义功能而不破坏核心协议
234
- - **类型安全**: 明确的字段类型减少解析错误
235
-
236
- ---
237
-
238
- ## 实施建议
239
-
240
- ### 优先级
241
- 1. **高**: Agent Card - 立即提升发现机制的能力
242
- 2. **中**: 任务生命周期 - 支持更复杂的协作场景
243
- 3. **低**: 消息格式标准化 - 在需要与其他系统集成时实施
244
-
245
- ### 向后兼容
246
- - 新字段使用可选(optional)方式添加
247
- - 保留旧版发现消息解析支持
248
- - 版本协商机制:连接时交换支持的协议版本
249
-
250
- ---
251
-
252
- ## 参考
253
-
254
- - [A2A Protocol Specification](https://a2a-protocol.org/latest/specification/)
255
- - [A2A GitHub Repository](https://github.com/a2aproject/A2A)
256
-
257
- ---
258
-
259
- # F2A 未来改进方向
260
-
261
- ## 1. mDNS 服务发现
262
-
263
- ### 现状
264
- 当前 F2A 使用 UDP 多播(239.255.255.250:8768)进行设备发现,但部分路由器会阻止该多播地址。
265
-
266
- ### mDNS 优势
267
- ```
268
- mDNS (Multicast DNS) - 224.0.0.251:5353
269
- - 更可靠:路由器通常允许(用于 AirDrop、打印机发现)
270
- - 服务类型:只发现 F2A Agent,不混杂其他流量
271
- - 元数据:可以携带 Agent ID、公钥、版本等 TXT 记录
272
- - 冲突解决:自动处理主机名冲突
273
- ```
274
-
275
- ### 推荐方案:混合发现机制
276
- ```javascript
277
- // 发现优先级
278
- 1. mDNS (Bonjour/Avahi) ← 首选
279
- 2. UDP 多播 239.255.0.250 ← 备用
280
- 3. UDP 广播 255.255.255.255 ← 最后手段
281
- ```
282
-
283
- ### 实现示例
284
- ```javascript
285
- const bonjour = require('bonjour')();
286
-
287
- // 发布 F2A 服务
288
- bonjour.publish({
289
- name: `F2A-${agentId.slice(0, 8)}`,
290
- type: 'f2a',
291
- port: 9000,
292
- txt: {
293
- agentId: 'f2a-xxx-xxx',
294
- publicKey: 'xxx...',
295
- version: '1.0.0',
296
- capabilities: 'chat,file_transfer'
297
- }
298
- });
299
-
300
- // 发现其他 F2A Agent
301
- bonjour.find({ type: 'f2a' }, (service) => {
302
- console.log('发现:', service.name);
303
- console.log('地址:', service.referer.address);
304
- console.log('端口:', service.port);
305
- console.log('元数据:', service.txt);
306
- });
307
- ```
308
-
309
- ### 参考
310
- - [Bonjour](https://github.com/watson/bonjour) - Node.js mDNS 实现
311
- - [Avahi](https://www.avahi.org/) - Linux mDNS/DNS-SD 实现
312
- - [RFC 6762](https://tools.ietf.org/html/rfc6762) - mDNS 标准
313
-
314
- ---
315
-
316
- *最后更新:2026-03-02*