@f2a/network 0.1.2
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/.github/workflows/ci.yml +113 -0
- package/.github/workflows/publish.yml +60 -0
- package/LICENSE +21 -0
- package/MONOREPO.md +58 -0
- package/README.md +280 -0
- package/SKILL.md +137 -0
- package/dist/adapters/openclaw.d.ts +103 -0
- package/dist/adapters/openclaw.d.ts.map +1 -0
- package/dist/adapters/openclaw.js +297 -0
- package/dist/adapters/openclaw.js.map +1 -0
- package/dist/cli/commands.d.ts +17 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +107 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +203 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/autonomous-economy.d.ts +136 -0
- package/dist/core/autonomous-economy.d.ts.map +1 -0
- package/dist/core/autonomous-economy.js +255 -0
- package/dist/core/autonomous-economy.js.map +1 -0
- package/dist/core/connection-manager.d.ts +80 -0
- package/dist/core/connection-manager.d.ts.map +1 -0
- package/dist/core/connection-manager.js +235 -0
- package/dist/core/connection-manager.js.map +1 -0
- package/dist/core/connection-manager.test.d.ts +2 -0
- package/dist/core/connection-manager.test.d.ts.map +1 -0
- package/dist/core/connection-manager.test.js +52 -0
- package/dist/core/connection-manager.test.js.map +1 -0
- package/dist/core/e2ee-crypto.d.ts +90 -0
- package/dist/core/e2ee-crypto.d.ts.map +1 -0
- package/dist/core/e2ee-crypto.js +190 -0
- package/dist/core/e2ee-crypto.js.map +1 -0
- package/dist/core/f2a.d.ts +126 -0
- package/dist/core/f2a.d.ts.map +1 -0
- package/dist/core/f2a.js +425 -0
- package/dist/core/f2a.js.map +1 -0
- package/dist/core/identity.d.ts +47 -0
- package/dist/core/identity.d.ts.map +1 -0
- package/dist/core/identity.js +130 -0
- package/dist/core/identity.js.map +1 -0
- package/dist/core/identity.test.d.ts +2 -0
- package/dist/core/identity.test.d.ts.map +1 -0
- package/dist/core/identity.test.js +43 -0
- package/dist/core/identity.test.js.map +1 -0
- package/dist/core/p2p-network.d.ts +242 -0
- package/dist/core/p2p-network.d.ts.map +1 -0
- package/dist/core/p2p-network.js +1182 -0
- package/dist/core/p2p-network.js.map +1 -0
- package/dist/core/reputation-security.d.ts +168 -0
- package/dist/core/reputation-security.d.ts.map +1 -0
- package/dist/core/reputation-security.js +369 -0
- package/dist/core/reputation-security.js.map +1 -0
- package/dist/core/reputation.d.ts +179 -0
- package/dist/core/reputation.d.ts.map +1 -0
- package/dist/core/reputation.js +472 -0
- package/dist/core/reputation.js.map +1 -0
- package/dist/core/review-committee.d.ts +130 -0
- package/dist/core/review-committee.d.ts.map +1 -0
- package/dist/core/review-committee.js +251 -0
- package/dist/core/review-committee.js.map +1 -0
- package/dist/core/serverless.d.ts +155 -0
- package/dist/core/serverless.d.ts.map +1 -0
- package/dist/core/serverless.js +615 -0
- package/dist/core/serverless.js.map +1 -0
- package/dist/core/token-manager.d.ts +42 -0
- package/dist/core/token-manager.d.ts.map +1 -0
- package/dist/core/token-manager.js +122 -0
- package/dist/core/token-manager.js.map +1 -0
- package/dist/daemon/control-server.d.ts +55 -0
- package/dist/daemon/control-server.d.ts.map +1 -0
- package/dist/daemon/control-server.js +262 -0
- package/dist/daemon/control-server.js.map +1 -0
- package/dist/daemon/index.d.ts +35 -0
- package/dist/daemon/index.d.ts.map +1 -0
- package/dist/daemon/index.js +69 -0
- package/dist/daemon/index.js.map +1 -0
- package/dist/daemon/main.d.ts +6 -0
- package/dist/daemon/main.d.ts.map +1 -0
- package/dist/daemon/main.js +38 -0
- package/dist/daemon/main.js.map +1 -0
- package/dist/daemon/start.d.ts +6 -0
- package/dist/daemon/start.d.ts.map +1 -0
- package/dist/daemon/start.js +25 -0
- package/dist/daemon/start.js.map +1 -0
- package/dist/daemon/webhook.d.ts +30 -0
- package/dist/daemon/webhook.d.ts.map +1 -0
- package/dist/daemon/webhook.js +86 -0
- package/dist/daemon/webhook.js.map +1 -0
- package/dist/daemon/webhook.test.d.ts +2 -0
- package/dist/daemon/webhook.test.d.ts.map +1 -0
- package/dist/daemon/webhook.test.js +24 -0
- package/dist/daemon/webhook.test.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/messages.d.ts +739 -0
- package/dist/protocol/messages.d.ts.map +1 -0
- package/dist/protocol/messages.js +188 -0
- package/dist/protocol/messages.js.map +1 -0
- package/dist/protocol/messages.test.d.ts +2 -0
- package/dist/protocol/messages.test.d.ts.map +1 -0
- package/dist/protocol/messages.test.js +55 -0
- package/dist/protocol/messages.test.js.map +1 -0
- package/dist/types/index.d.ts +247 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/result.d.ts +28 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +16 -0
- package/dist/types/result.js.map +1 -0
- package/dist/utils/benchmark.d.ts +67 -0
- package/dist/utils/benchmark.d.ts.map +1 -0
- package/dist/utils/benchmark.js +179 -0
- package/dist/utils/benchmark.js.map +1 -0
- package/dist/utils/logger.d.ts +105 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +275 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/middleware.d.ts +85 -0
- package/dist/utils/middleware.d.ts.map +1 -0
- package/dist/utils/middleware.js +173 -0
- package/dist/utils/middleware.js.map +1 -0
- package/dist/utils/rate-limiter.d.ts +71 -0
- package/dist/utils/rate-limiter.d.ts.map +1 -0
- package/dist/utils/rate-limiter.js +160 -0
- package/dist/utils/rate-limiter.js.map +1 -0
- package/dist/utils/signature.d.ts +57 -0
- package/dist/utils/signature.d.ts.map +1 -0
- package/dist/utils/signature.js +102 -0
- package/dist/utils/signature.js.map +1 -0
- package/dist/utils/validation.d.ts +504 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +159 -0
- package/dist/utils/validation.js.map +1 -0
- package/docs/F2A-PROTOCOL.md +61 -0
- package/docs/MOBILE_BOOTSTRAP_DESIGN.md +126 -0
- package/docs/a2a-lessons.md +316 -0
- package/docs/middleware-guide.md +448 -0
- package/docs/readme-update-checklist.md +90 -0
- package/docs/reputation-guide.md +396 -0
- package/docs/rfcs/001-reputation-system.md +712 -0
- package/docs/security-design.md +247 -0
- package/install.sh +231 -0
- package/package.json +64 -0
- package/packages/openclaw-adapter/README.md +510 -0
- package/packages/openclaw-adapter/openclaw.plugin.json +106 -0
- package/packages/openclaw-adapter/package.json +40 -0
- package/packages/openclaw-adapter/src/announcement-queue.test.ts +449 -0
- package/packages/openclaw-adapter/src/announcement-queue.ts +403 -0
- package/packages/openclaw-adapter/src/capability-detector.test.ts +99 -0
- package/packages/openclaw-adapter/src/capability-detector.ts +183 -0
- package/packages/openclaw-adapter/src/claim-handlers.test.ts +974 -0
- package/packages/openclaw-adapter/src/claim-handlers.ts +482 -0
- package/packages/openclaw-adapter/src/connector.business.test.ts +583 -0
- package/packages/openclaw-adapter/src/connector.ts +795 -0
- package/packages/openclaw-adapter/src/index.test.ts +82 -0
- package/packages/openclaw-adapter/src/index.ts +18 -0
- package/packages/openclaw-adapter/src/integration.e2e.test.ts +829 -0
- package/packages/openclaw-adapter/src/logger.ts +51 -0
- package/packages/openclaw-adapter/src/network-client.test.ts +266 -0
- package/packages/openclaw-adapter/src/network-client.ts +251 -0
- package/packages/openclaw-adapter/src/network-recovery.test.ts +465 -0
- package/packages/openclaw-adapter/src/node-manager.test.ts +136 -0
- package/packages/openclaw-adapter/src/node-manager.ts +429 -0
- package/packages/openclaw-adapter/src/plugin.test.ts +439 -0
- package/packages/openclaw-adapter/src/plugin.ts +104 -0
- package/packages/openclaw-adapter/src/reputation.test.ts +221 -0
- package/packages/openclaw-adapter/src/reputation.ts +368 -0
- package/packages/openclaw-adapter/src/task-guard.test.ts +502 -0
- package/packages/openclaw-adapter/src/task-guard.ts +860 -0
- package/packages/openclaw-adapter/src/task-queue.concurrency.test.ts +462 -0
- package/packages/openclaw-adapter/src/task-queue.edge-cases.test.ts +284 -0
- package/packages/openclaw-adapter/src/task-queue.persistence.test.ts +408 -0
- package/packages/openclaw-adapter/src/task-queue.ts +668 -0
- package/packages/openclaw-adapter/src/tool-handlers.test.ts +906 -0
- package/packages/openclaw-adapter/src/tool-handlers.ts +574 -0
- package/packages/openclaw-adapter/src/types.ts +361 -0
- package/packages/openclaw-adapter/src/webhook-pusher.test.ts +188 -0
- package/packages/openclaw-adapter/src/webhook-pusher.ts +220 -0
- package/packages/openclaw-adapter/src/webhook-server.test.ts +580 -0
- package/packages/openclaw-adapter/src/webhook-server.ts +202 -0
- package/packages/openclaw-adapter/tsconfig.json +20 -0
- package/src/cli/commands.test.ts +157 -0
- package/src/cli/commands.ts +129 -0
- package/src/cli/index.test.ts +77 -0
- package/src/cli/index.ts +234 -0
- package/src/core/autonomous-economy.test.ts +291 -0
- package/src/core/autonomous-economy.ts +428 -0
- package/src/core/e2ee-crypto.test.ts +125 -0
- package/src/core/e2ee-crypto.ts +246 -0
- package/src/core/f2a.test.ts +269 -0
- package/src/core/f2a.ts +618 -0
- package/src/core/p2p-network.test.ts +199 -0
- package/src/core/p2p-network.ts +1432 -0
- package/src/core/reputation-security.test.ts +403 -0
- package/src/core/reputation-security.ts +562 -0
- package/src/core/reputation.test.ts +260 -0
- package/src/core/reputation.ts +576 -0
- package/src/core/review-committee.test.ts +380 -0
- package/src/core/review-committee.ts +401 -0
- package/src/core/token-manager.test.ts +133 -0
- package/src/core/token-manager.ts +140 -0
- package/src/daemon/control-server.test.ts +216 -0
- package/src/daemon/control-server.ts +292 -0
- package/src/daemon/index.test.ts +85 -0
- package/src/daemon/index.ts +89 -0
- package/src/daemon/main.ts +44 -0
- package/src/daemon/start.ts +29 -0
- package/src/daemon/webhook.test.ts +68 -0
- package/src/daemon/webhook.ts +105 -0
- package/src/index.test.ts +436 -0
- package/src/index.ts +72 -0
- package/src/types/index.test.ts +87 -0
- package/src/types/index.ts +341 -0
- package/src/types/result.ts +68 -0
- package/src/utils/benchmark.ts +237 -0
- package/src/utils/logger.ts +331 -0
- package/src/utils/middleware.ts +229 -0
- package/src/utils/rate-limiter.ts +207 -0
- package/src/utils/signature.ts +136 -0
- package/src/utils/validation.ts +186 -0
- package/tests/docker/Dockerfile.node +23 -0
- package/tests/docker/Dockerfile.runner +18 -0
- package/tests/docker/docker-compose.test.yml +73 -0
- package/tests/integration/message-passing.test.ts +109 -0
- package/tests/integration/multi-node.test.ts +92 -0
- package/tests/integration/p2p-connection.test.ts +83 -0
- package/tests/integration/test-config.ts +32 -0
- package/tsconfig.json +21 -0
- package/vitest.config.ts +26 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, develop]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main, develop]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
# Lint 检查
|
|
11
|
+
lint:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- uses: actions/setup-node@v4
|
|
17
|
+
with:
|
|
18
|
+
node-version: '20'
|
|
19
|
+
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: npm install
|
|
22
|
+
|
|
23
|
+
- name: Run lint
|
|
24
|
+
run: npm run lint || npm run build -- --noEmit
|
|
25
|
+
|
|
26
|
+
# 单元测试(Node 20 & 22)
|
|
27
|
+
unit-tests:
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
needs: lint
|
|
30
|
+
strategy:
|
|
31
|
+
matrix:
|
|
32
|
+
node-version: [20, 22]
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v4
|
|
35
|
+
|
|
36
|
+
- uses: actions/setup-node@v4
|
|
37
|
+
with:
|
|
38
|
+
node-version: ${{ matrix.node-version }}
|
|
39
|
+
|
|
40
|
+
- name: Install dependencies
|
|
41
|
+
run: npm install
|
|
42
|
+
|
|
43
|
+
- name: Build
|
|
44
|
+
run: npm run build
|
|
45
|
+
|
|
46
|
+
- name: Run unit tests
|
|
47
|
+
run: npm run test:unit
|
|
48
|
+
|
|
49
|
+
- name: Upload coverage
|
|
50
|
+
uses: codecov/codecov-action@v4
|
|
51
|
+
if: matrix.node-version == 20
|
|
52
|
+
with:
|
|
53
|
+
files: ./coverage/lcov.info
|
|
54
|
+
flags: unittests
|
|
55
|
+
|
|
56
|
+
# 集成测试(仅 push 触发)
|
|
57
|
+
integration-tests:
|
|
58
|
+
runs-on: ubuntu-latest
|
|
59
|
+
needs: unit-tests
|
|
60
|
+
if: github.event_name == 'push'
|
|
61
|
+
steps:
|
|
62
|
+
- uses: actions/checkout@v4
|
|
63
|
+
|
|
64
|
+
- uses: actions/setup-node@v4
|
|
65
|
+
with:
|
|
66
|
+
node-version: '20'
|
|
67
|
+
|
|
68
|
+
- name: Install dependencies
|
|
69
|
+
run: npm install
|
|
70
|
+
|
|
71
|
+
- name: Build
|
|
72
|
+
run: npm run build
|
|
73
|
+
|
|
74
|
+
- name: Run Docker integration tests
|
|
75
|
+
run: npm run test:docker
|
|
76
|
+
|
|
77
|
+
- name: Export logs on failure
|
|
78
|
+
if: failure()
|
|
79
|
+
run: docker compose -f tests/docker/docker-compose.test.yml logs > test-logs.txt
|
|
80
|
+
|
|
81
|
+
- name: Upload logs on failure
|
|
82
|
+
if: failure()
|
|
83
|
+
uses: actions/upload-artifact@v4
|
|
84
|
+
with:
|
|
85
|
+
name: integration-test-logs
|
|
86
|
+
path: test-logs.txt
|
|
87
|
+
|
|
88
|
+
- name: Upload coverage
|
|
89
|
+
uses: codecov/codecov-action@v4
|
|
90
|
+
with:
|
|
91
|
+
files: ./coverage/lcov.info
|
|
92
|
+
flags: integration
|
|
93
|
+
|
|
94
|
+
# 多节点测试(仅 main 分支)
|
|
95
|
+
multi-node-tests:
|
|
96
|
+
runs-on: ubuntu-latest
|
|
97
|
+
needs: integration-tests
|
|
98
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
99
|
+
steps:
|
|
100
|
+
- uses: actions/checkout@v4
|
|
101
|
+
|
|
102
|
+
- uses: actions/setup-node@v4
|
|
103
|
+
with:
|
|
104
|
+
node-version: '20'
|
|
105
|
+
|
|
106
|
+
- name: Install dependencies
|
|
107
|
+
run: npm install
|
|
108
|
+
|
|
109
|
+
- name: Build
|
|
110
|
+
run: npm run build
|
|
111
|
+
|
|
112
|
+
- name: Run 10-node test
|
|
113
|
+
run: npm run test:docker:10
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
name: Publish to NPM
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish-core:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
|
+
with:
|
|
17
|
+
node-version: '20'
|
|
18
|
+
registry-url: 'https://registry.npmjs.org'
|
|
19
|
+
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: npm install
|
|
22
|
+
|
|
23
|
+
- name: Build
|
|
24
|
+
run: npm run build
|
|
25
|
+
|
|
26
|
+
- name: Publish core package
|
|
27
|
+
run: npm publish --access public
|
|
28
|
+
env:
|
|
29
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
30
|
+
|
|
31
|
+
publish-adapter:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
needs: publish-core
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@v4
|
|
36
|
+
|
|
37
|
+
- uses: actions/setup-node@v4
|
|
38
|
+
with:
|
|
39
|
+
node-version: '20'
|
|
40
|
+
registry-url: 'https://registry.npmjs.org'
|
|
41
|
+
|
|
42
|
+
- name: Wait for package to be available
|
|
43
|
+
run: sleep 30
|
|
44
|
+
|
|
45
|
+
- name: Install dependencies
|
|
46
|
+
working-directory: packages/openclaw-adapter
|
|
47
|
+
run: |
|
|
48
|
+
# Replace file: reference with npm package reference
|
|
49
|
+
npm install @f2a/network@latest --save
|
|
50
|
+
npm install
|
|
51
|
+
|
|
52
|
+
- name: Build adapter
|
|
53
|
+
working-directory: packages/openclaw-adapter
|
|
54
|
+
run: npm run build
|
|
55
|
+
|
|
56
|
+
- name: Publish adapter package
|
|
57
|
+
working-directory: packages/openclaw-adapter
|
|
58
|
+
run: npm publish --access public
|
|
59
|
+
env:
|
|
60
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lucius.C
|
|
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/MONOREPO.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# F2A Monorepo
|
|
2
|
+
|
|
3
|
+
F2A (Friend-to-Agent) 是一个用于 OpenClaw Agents 的 P2P 网络协议。
|
|
4
|
+
|
|
5
|
+
## 仓库结构
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
F2A/
|
|
9
|
+
├── packages/ # 子包目录
|
|
10
|
+
│ └── openclaw-adapter/ # OpenClaw 插件
|
|
11
|
+
│ ├── package.json
|
|
12
|
+
│ ├── tsconfig.json
|
|
13
|
+
│ ├── README.md
|
|
14
|
+
│ └── src/
|
|
15
|
+
├── src/ # F2A 核心代码
|
|
16
|
+
│ ├── core/ # 核心 P2P 网络
|
|
17
|
+
│ ├── daemon/ # Daemon 服务
|
|
18
|
+
│ ├── cli/ # CLI 工具
|
|
19
|
+
│ └── types/ # 类型定义
|
|
20
|
+
├── docs/ # 文档
|
|
21
|
+
├── package.json # 根 package.json (workspaces)
|
|
22
|
+
└── tsconfig.json
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 包说明
|
|
26
|
+
|
|
27
|
+
| 包 | 路径 | 说明 |
|
|
28
|
+
|----|------|------|
|
|
29
|
+
| `f2a-network` | `./` | F2A P2P 网络核心 |
|
|
30
|
+
| `@f2a/openclaw-adapter` | `./packages/openclaw-adapter` | OpenClaw 插件 |
|
|
31
|
+
|
|
32
|
+
## 开发
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# 安装所有依赖
|
|
36
|
+
npm install
|
|
37
|
+
|
|
38
|
+
# 构建所有包
|
|
39
|
+
npm run build:all
|
|
40
|
+
|
|
41
|
+
# 测试所有包
|
|
42
|
+
npm run test:all
|
|
43
|
+
|
|
44
|
+
# 构建特定包
|
|
45
|
+
cd packages/openclaw-adapter
|
|
46
|
+
npm run build
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 发布
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# 发布核心包
|
|
53
|
+
npm publish
|
|
54
|
+
|
|
55
|
+
# 发布子包
|
|
56
|
+
cd packages/openclaw-adapter
|
|
57
|
+
npm publish --access public
|
|
58
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# F2A P2P 网络
|
|
2
|
+
|
|
3
|
+
> 基于 libp2p 的 OpenClaw Agent P2P 协作网络
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 目录
|
|
8
|
+
|
|
9
|
+
1. [运行 F2A 节点](#1-运行-f2a-节点) - 把机器变成一个 P2P 节点
|
|
10
|
+
2. [OpenClaw 插件](#2-openclaw-插件) - 在 OpenClaw 里使用 F2A
|
|
11
|
+
3. [开发指南](#3-开发指南) - 基于 F2A 开发
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 1. 运行 F2A 节点
|
|
16
|
+
|
|
17
|
+
### 1.1 安装
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# 克隆仓库
|
|
21
|
+
git clone https://github.com/LuciusCao/F2A.git
|
|
22
|
+
cd F2A
|
|
23
|
+
|
|
24
|
+
# 安装依赖
|
|
25
|
+
npm install
|
|
26
|
+
|
|
27
|
+
# 构建
|
|
28
|
+
npm run build
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
或者通过 NPM 安装:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# 安装 F2A 网络
|
|
35
|
+
npm install -g @f2a/network
|
|
36
|
+
|
|
37
|
+
# 启动节点
|
|
38
|
+
f2a-network
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 1.2 启动节点
|
|
42
|
+
|
|
43
|
+
**方式一:Daemon 模式(推荐)**
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# 启动后台服务
|
|
47
|
+
node dist/daemon/index.js
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**方式二:CLI 模式**
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# 查看状态
|
|
54
|
+
node dist/cli/index.js status
|
|
55
|
+
|
|
56
|
+
# 查看已连接节点
|
|
57
|
+
node dist/cli/index.js peers
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 1.3 配置
|
|
61
|
+
|
|
62
|
+
通过环境变量配置:
|
|
63
|
+
|
|
64
|
+
| 变量 | 默认值 | 说明 |
|
|
65
|
+
|------|--------|------|
|
|
66
|
+
| `F2A_CONTROL_PORT` | 9001 | HTTP 控制端口 |
|
|
67
|
+
| `F2A_CONTROL_TOKEN` | 自动生成 | 认证 Token(生产环境必须设置) |
|
|
68
|
+
| `F2A_P2P_PORT` | 9000 | P2P 网络端口 |
|
|
69
|
+
| `F2A_SIGNATURE_KEY` | - | 请求签名密钥(可选) |
|
|
70
|
+
|
|
71
|
+
**生产环境配置示例:**
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
export F2A_CONTROL_TOKEN=$(openssl rand -hex 32)
|
|
75
|
+
export F2A_SIGNATURE_KEY=$(openssl rand -hex 32)
|
|
76
|
+
export NODE_ENV=production
|
|
77
|
+
|
|
78
|
+
node dist/daemon/index.js
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 1.4 验证运行
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# 查看节点状态
|
|
85
|
+
curl http://localhost:9001/status \
|
|
86
|
+
-H "Authorization: Bearer $F2A_CONTROL_TOKEN"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 2. OpenClaw 插件
|
|
92
|
+
|
|
93
|
+
### 2.1 安装插件
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# 通过 OpenClaw 安装
|
|
97
|
+
openclaw plugins install @f2a/openclaw-adapter
|
|
98
|
+
|
|
99
|
+
# 或者手动安装
|
|
100
|
+
npm install -g @f2a/openclaw-adapter
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
然后在 OpenClaw 配置中启用:
|
|
104
|
+
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"plugins": {
|
|
108
|
+
"@f2a/openclaw-adapter": {
|
|
109
|
+
"enabled": true,
|
|
110
|
+
"config": {
|
|
111
|
+
"agentName": "我的Agent",
|
|
112
|
+
"autoStart": true,
|
|
113
|
+
"p2pPort": 9000,
|
|
114
|
+
"enableMDNS": true
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 2.2 配置详解
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"agentName": "显示名称",
|
|
126
|
+
"f2aPath": "F2A项目路径",
|
|
127
|
+
"autoStart": true,
|
|
128
|
+
"webhookPort": 9002,
|
|
129
|
+
"controlPort": 9001,
|
|
130
|
+
"p2pPort": 9000,
|
|
131
|
+
"enableMDNS": true,
|
|
132
|
+
"bootstrapPeers": [],
|
|
133
|
+
"maxQueuedTasks": 100,
|
|
134
|
+
"reputation": {
|
|
135
|
+
"enabled": true,
|
|
136
|
+
"initialScore": 50
|
|
137
|
+
},
|
|
138
|
+
"security": {
|
|
139
|
+
"requireConfirmation": false,
|
|
140
|
+
"whitelist": [],
|
|
141
|
+
"blacklist": []
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 2.3 使用方式
|
|
147
|
+
|
|
148
|
+
安装后,直接在 OpenClaw 对话中使用:
|
|
149
|
+
|
|
150
|
+
| 功能 | 示例对话 |
|
|
151
|
+
|------|----------|
|
|
152
|
+
| 发现Agents | "帮我找一下网络里能写代码的Agents" |
|
|
153
|
+
| 委托任务 | "让 MacBook-Pro 帮我写个斐波那契函数" |
|
|
154
|
+
| 广播任务 | "让所有人帮我检查这段代码的bug" |
|
|
155
|
+
| 查看状态 | "查看F2A网络状态" |
|
|
156
|
+
|
|
157
|
+
### 2.4 提供的工具
|
|
158
|
+
|
|
159
|
+
- `f2a_discover` - 发现网络中的 Agents
|
|
160
|
+
- `f2a_delegate` - 委托任务给指定 Agent
|
|
161
|
+
- `f2a_broadcast` - 广播任务给多个 Agents
|
|
162
|
+
- `f2a_announce` - 广播任务(认领模式)
|
|
163
|
+
- `f2a_claim` - 认领任务
|
|
164
|
+
- `f2a_status` - 查看网络状态
|
|
165
|
+
- `f2a_reputation` - 管理信誉
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 3. 开发指南
|
|
170
|
+
|
|
171
|
+
### 3.1 项目结构
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
F2A/
|
|
175
|
+
├── src/ # F2A 核心代码
|
|
176
|
+
│ ├── core/ # P2P网络、信誉系统
|
|
177
|
+
│ ├── daemon/ # 后台服务
|
|
178
|
+
│ ├── cli/ # 命令行工具
|
|
179
|
+
│ └── utils/ # 工具函数
|
|
180
|
+
├── packages/
|
|
181
|
+
│ └── openclaw-adapter/ # OpenClaw 插件
|
|
182
|
+
├── docs/ # 文档
|
|
183
|
+
└── tests/ # 测试
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 3.2 核心 API
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import { F2A } from 'f2a-network';
|
|
190
|
+
|
|
191
|
+
// 创建节点
|
|
192
|
+
const f2a = await F2A.create({
|
|
193
|
+
displayName: 'My Agent',
|
|
194
|
+
network: {
|
|
195
|
+
listenPort: 9000,
|
|
196
|
+
enableMDNS: true
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// 启动
|
|
201
|
+
await f2a.start();
|
|
202
|
+
|
|
203
|
+
// 注册能力
|
|
204
|
+
f2a.registerCapability({
|
|
205
|
+
name: 'code-generation',
|
|
206
|
+
description: 'Generate code',
|
|
207
|
+
tools: ['generate', 'refactor']
|
|
208
|
+
}, async (params) => {
|
|
209
|
+
return { code: '...' };
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// 发现 Agents
|
|
213
|
+
const agents = await f2a.discoverAgents('code-generation');
|
|
214
|
+
|
|
215
|
+
// 委托任务
|
|
216
|
+
const result = await f2a.delegateTask({
|
|
217
|
+
capability: 'code-generation',
|
|
218
|
+
description: 'Generate fibonacci function',
|
|
219
|
+
parameters: { language: 'python' }
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### 3.3 开发命令
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
# 构建
|
|
227
|
+
npm run build
|
|
228
|
+
|
|
229
|
+
# 测试
|
|
230
|
+
npm test
|
|
231
|
+
npm run test:coverage
|
|
232
|
+
|
|
233
|
+
# 构建所有包
|
|
234
|
+
npm run build:all
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### 3.4 文档
|
|
238
|
+
|
|
239
|
+
- [协议规范](docs/F2A-PROTOCOL.md)
|
|
240
|
+
- [中间件指南](docs/middleware-guide.md)
|
|
241
|
+
- [信誉系统指南](docs/reputation-guide.md)
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## 快速开始(最小步骤)
|
|
246
|
+
|
|
247
|
+
### 方式一:NPM 安装(推荐)
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# 1. 安装并启动 F2A 节点
|
|
251
|
+
npm install -g @f2a/network
|
|
252
|
+
f2a-network
|
|
253
|
+
|
|
254
|
+
# 2. 配置 OpenClaw 插件
|
|
255
|
+
openclaw plugins install @f2a/openclaw-adapter
|
|
256
|
+
|
|
257
|
+
# 3. 编辑配置文件,启用插件
|
|
258
|
+
# ~/.openclaw/config.json
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### 方式二:源码安装
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
# 1. 启动 F2A 节点
|
|
265
|
+
cd ~/projects/F2A
|
|
266
|
+
npm run build
|
|
267
|
+
node dist/daemon/index.js
|
|
268
|
+
|
|
269
|
+
# 2. 配置 OpenClaw 插件
|
|
270
|
+
# 编辑 ~/.openclaw/config.json,添加插件配置
|
|
271
|
+
|
|
272
|
+
# 3. 开始使用
|
|
273
|
+
# 在 OpenClaw 中对话:"帮我找一下网络里的Agents"
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## License
|
|
279
|
+
|
|
280
|
+
MIT
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: f2a-network
|
|
3
|
+
description: Activate when the user wants to discover, connect, or communicate with other OpenClaw Agents in the local network. Use for P2P networking, messaging between agents, invoking skills on remote agents, file sharing, or group chat.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# F2A - Friend-to-Agent P2P Network
|
|
7
|
+
|
|
8
|
+
## 概述
|
|
9
|
+
|
|
10
|
+
F2A 是一个 P2P 协作网络,让 OpenClaw Agent 能够:
|
|
11
|
+
- 发现局域网内的其他 Agent
|
|
12
|
+
- 与其他 Agent 建立加密通信
|
|
13
|
+
- 委托任务给其他 Agent
|
|
14
|
+
- 共享文件和能力
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
cd /path/to/f2a
|
|
20
|
+
npm install
|
|
21
|
+
npm run build
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 命令参考
|
|
25
|
+
|
|
26
|
+
### 启动/停止
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# 启动 Daemon(后台服务)
|
|
30
|
+
node dist/daemon/index.js
|
|
31
|
+
|
|
32
|
+
# 或使用 PM2
|
|
33
|
+
pm2 start dist/daemon/index.js --name f2a
|
|
34
|
+
|
|
35
|
+
# 停止
|
|
36
|
+
pm2 stop f2a
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### CLI 命令
|
|
40
|
+
|
|
41
|
+
| 命令 | 说明 |
|
|
42
|
+
|------|------|
|
|
43
|
+
| `status` | 查看节点状态 |
|
|
44
|
+
| `peers` | 查看已连接的 Peers |
|
|
45
|
+
| `discover [--capability <name>]` | 发现网络中的 Agents |
|
|
46
|
+
| `pending` | 查看待确认连接 |
|
|
47
|
+
| `confirm <id|index>` | 确认连接请求 |
|
|
48
|
+
| `reject <id|index>` | 拒绝连接请求 |
|
|
49
|
+
|
|
50
|
+
### 使用示例
|
|
51
|
+
|
|
52
|
+
#### 场景一:发现其他 Agent
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# 发现所有 Agent
|
|
56
|
+
node dist/cli/index.js discover
|
|
57
|
+
|
|
58
|
+
# 按能力过滤
|
|
59
|
+
node dist/cli/index.js discover --capability code-generation
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### 场景二:查看连接状态
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
node dist/cli/index.js status
|
|
66
|
+
node dist/cli/index.js peers
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### 场景三:管理连接请求
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# 查看待确认连接
|
|
73
|
+
node dist/cli/index.js pending
|
|
74
|
+
|
|
75
|
+
# 确认连接
|
|
76
|
+
node dist/cli/index.js confirm 1
|
|
77
|
+
|
|
78
|
+
# 拒绝连接
|
|
79
|
+
node dist/cli/index.js reject 2 --reason "unknown agent"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 环境变量
|
|
83
|
+
|
|
84
|
+
| 变量 | 默认值 | 说明 |
|
|
85
|
+
|------|--------|------|
|
|
86
|
+
| `F2A_CONTROL_PORT` | 9001 | HTTP 控制端口 |
|
|
87
|
+
| `F2A_CONTROL_TOKEN` | f2a-default-token | 认证 Token(生产环境务必修改) |
|
|
88
|
+
|
|
89
|
+
## 安全注意事项
|
|
90
|
+
|
|
91
|
+
⚠️ **默认 Token 不安全!** 生产环境请设置:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
export F2A_CONTROL_TOKEN=$(openssl rand -hex 32)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 故障排除
|
|
98
|
+
|
|
99
|
+
### 问题:无法发现其他 Agent
|
|
100
|
+
|
|
101
|
+
检查:
|
|
102
|
+
1. 是否在同一局域网?
|
|
103
|
+
2. 防火墙是否阻止了 UDP 8768 端口?
|
|
104
|
+
3. MDNS 是否被路由器禁用?
|
|
105
|
+
|
|
106
|
+
### 问题:连接被拒绝
|
|
107
|
+
|
|
108
|
+
检查:
|
|
109
|
+
1. 对方是否已启动 F2A?
|
|
110
|
+
2. Token 是否正确?
|
|
111
|
+
3. 是否在对方的黑名单中?
|
|
112
|
+
|
|
113
|
+
### 问题:端口被占用
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# 检查端口占用
|
|
117
|
+
lsof -i :9001
|
|
118
|
+
|
|
119
|
+
# 使用其他端口
|
|
120
|
+
F2A_CONTROL_PORT=9002 node dist/daemon/index.js
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 更多文档
|
|
124
|
+
|
|
125
|
+
- 详细文档:`docs/`
|
|
126
|
+
- 协议规范:`skill/references/protocol.md`
|
|
127
|
+
- 完整 README:`README.md`
|
|
128
|
+
|
|
129
|
+
## 日志查看
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# 使用 PM2 查看日志
|
|
133
|
+
pm2 logs f2a
|
|
134
|
+
|
|
135
|
+
# 或查看日志文件
|
|
136
|
+
tail -f ~/.f2a/f2a.log
|
|
137
|
+
```
|