@twinsearth/agent-universe 3.4.5 → 3.6.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/README.md CHANGED
@@ -6,10 +6,18 @@
6
6
 
7
7
  [![CI](https://github.com/TwinsEarth/agent-universe/actions/workflows/ci.yml/badge.svg)](https://github.com/TwinsEarth/agent-universe/actions/workflows/ci.yml)
8
8
  [![Release](https://img.shields.io/github/v/release/TwinsEarth/agent-universe)](https://github.com/TwinsEarth/agent-universe/releases)
9
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
9
+ [![npm](https://img.shields.io/npm/v/@twinsearth/agent-universe?color=red)](https://www.npmjs.com/package/@twinsearth/agent-universe)
10
+
11
+ [![Platforms](https://img.shields.io/badge/platforms-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey)](https://github.com/TwinsEarth/agent-universe/actions/workflows/ci.yml)
10
12
  [![Rust](https://img.shields.io/badge/rust-2021%20edition-orange.svg)](https://www.rust-lang.org/)
13
+ [![MSRV](https://img.shields.io/badge/MSRV-1.88%2B-orange)](https://github.com/TwinsEarth/agent-universe/actions/workflows/ci.yml)
11
14
  [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/)
12
- [![npm](https://img.shields.io/badge/npm-%40twinsearth%2Fagent--universe-red.svg)](https://github.com/TwinsEarth/agent-universe/packages)
15
+ [![Node](https://img.shields.io/badge/node-18%2B-green.svg)](https://nodejs.org/)
16
+
17
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
18
+ [![Safety Gates](https://img.shields.io/badge/safety-no%20panic%20%E2%80%A2%20unsafe%20contained-success)](https://github.com/TwinsEarth/agent-universe/actions/workflows/ci.yml)
19
+ [![Contributors](https://img.shields.io/github/contributors/TwinsEarth/agent-universe)](https://github.com/TwinsEarth/agent-universe/graphs/contributors)
20
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
13
21
 
14
22
  ## 核心理念
15
23
 
@@ -87,6 +95,15 @@
87
95
  | `marketplace/` | **智能体市场 Agent Market**(v2.3.4):注册/发现/匹配/BFT验证/结算/信誉 |
88
96
  | `bin/` | **gsn-daemon** 守护进程 |
89
97
 
98
+ > **库面模块与运行面的区分(v3.5.9,DOC-05 / 自审 F-4)**:上表是 **gsn-core 代码库的
99
+ > 模块清单**,不等于「守护进程实际构造运行的能力」。其中 `topology/`、`scheduler/`、
100
+ > `memory/`、`swarm/`、`mesh/`、`nat/` 目前是 **library-only / 实验性模块**:它们的类型
101
+ > 被 `lib.rs` re-export、有单元测试,但**不在 `gsn-daemon` 的启动运行图中构造**;节点实际的
102
+ > 网络发现/广播/打洞走 **libp2p**(`net/` 的 Kademlia、GossipSub、AutoNAT、DCUtR、Relay),
103
+ > 调度与群体涌现的运行能力由官方插件以各自实现提供。各模块头注释有逐条标注,「接线启用
104
+ > 还是收敛删除」的待决记录与能力边界现状见
105
+ > [`docs/CAPABILITY-STATUS.md`](docs/CAPABILITY-STATUS.md)。
106
+
90
107
  ### Python SDK(aip-sdk-py)
91
108
 
92
109
  - Agent Interop Protocol 客户端
@@ -167,7 +184,7 @@ cargo run --release --bin gsn-daemon -- \
167
184
  | `GET /tasks` | 任务列表 |
168
185
  | `POST /agents` | 注册 AgentCard(同时落 SQLite 与 DHT) |
169
186
 
170
- > **当前实现状态**:gsn-daemon 已是**真实网络节点**——libp2p(Noise 加密 + Kademlia DHT + GossipSub)真实 bind P2P 端口,HTTP API 真实 bind API 端口,agents/tasks 通过 SQLite 真实落盘并在重启后恢复。已真机验证:两端口 `LISTEN`、各 API 端点返回正确、POST 注册可查、404 路径正确转义、kill 重启后数据仍在。核心业务逻辑(Agent Market 结算守恒、BFT-lite 验证、信誉)由 155 个 Rust 测试 + 17 个 Python 测试 + 12 个 JS 测试守护,跨语言签名测试保证三端身份/签名互验。链上结算与跨主机多节点 DHT 联调为下一步目标。
187
+ > **当前实现状态**:gsn-daemon 已是**真实网络节点**——libp2p(Noise 加密 + Kademlia DHT + GossipSub)真实 bind P2P 端口,HTTP API 真实 bind API 端口,agents/tasks 通过 SQLite 真实落盘并在重启后恢复。已真机验证:两端口 `LISTEN`、各 API 端点返回正确、POST 注册可查、404 路径正确转义、kill 重启后数据仍在。核心业务逻辑(Agent Market 结算守恒、BFT-lite 验证、信誉)由 618 个 Rust 测试 + 19 个 Python 测试 + 22 个 JS 测试守护(随版本增长,以发布时 cargo test / pytest / node 实测为准),跨语言签名测试保证三端身份/签名互验。链上结算与跨主机多节点 DHT 联调为下一步目标。
171
188
 
172
189
  ### 三大连接层:CLI · API · MCP(v2.3.5 引入,v2.3.6 深化)
173
190
 
@@ -219,14 +236,14 @@ gsn market stats # 市场统计
219
236
 
220
237
  业务错误返回 `422`,资源不存在返回 `404`,注册类成功返回 `201`,`OPTIONS` 返回 `204`。
221
238
 
222
- **③ MCP(18 个市场工具,支持 stdio 与 HTTP/SSE 两种传输)**
239
+ **③ MCP(20 个市场工具,支持 stdio 与 HTTP/SSE 两种传输)**
223
240
 
224
241
  - stdio:`gsn mcp`,逐行读写 JSON-RPC(日志走 stderr),可直接接入 Claude Desktop / Cursor 等;
225
242
  - HTTP:`POST /api/v1/mcp` 无状态 JSON-RPC,`GET /api/v1/mcp` 返回 `text/event-stream` 初始化帧。
226
243
 
227
- 工具命名 `market_*`,覆盖:`market_register_agent`、`market_discover_agents`、`market_publish_task`、`market_submit_bid`、`market_match_task`、`market_submit_result`、`market_verify_result`、`market_settle_task`、`market_open_dispute`、`market_arbitrate`、`market_deposit`、`market_balance`、`market_conservation`、`market_leaderboard`、`market_stats` 等共 18 个。`tools/call` 全部路由到市场 actor **真实执行**(非占位)。
244
+ 工具命名 `market_*`,覆盖:`market_register_agent`、`market_discover_agents`、`market_publish_task`、`market_submit_bid`、`market_match_task`、`market_submit_result`、`market_verify_result`、`market_settle_task`、`market_open_dispute`、`market_arbitrate`、`market_deposit`、`market_balance`、`market_conservation`、`market_leaderboard`、`market_stats` 等共 20 个。`tools/call` 全部路由到市场 actor **真实执行**(非占位)。
228
245
 
229
- > 三层均已真机验证:daemon 真实 bind P2P/API 端口,curl 走通「充值→注册→发布→投标→匹配→结果→验证→结算→守恒」完整闭环;MCP stdio 完成 `initialize` / `tools/list`(18 工具)/ `tools/call`;CLI 各子命令连接节点返回真实数据。由 155 个 Rust 测试守护,跨语言签名测试保证 Rust/Python/JS 三端身份、规范载荷与签名逐字节一致、可互验。
246
+ > 三层均已真机验证:daemon 真实 bind P2P/API 端口,curl 走通「充值→注册→发布→投标→匹配→结果→验证→结算→守恒」完整闭环;MCP stdio 完成 `initialize` / `tools/list`(20 工具)/ `tools/call`;CLI 各子命令连接节点返回真实数据。由 618 个 Rust 测试守护,跨语言签名测试保证 Rust/Python/JS 三端身份、规范载荷与签名逐字节一致、可互验。
230
247
 
231
248
  ### Python SDK 使用
232
249
 
@@ -445,7 +462,7 @@ AipIdentity.verifyObject(manifest, id.publicKey); // true
445
462
  const { McpHttpClient } = require('@twinsearth/agent-universe');
446
463
  const mcp = new McpHttpClient('http://127.0.0.1:4002');
447
464
  await mcp.initialize();
448
- const tools = await mcp.listTools(); // 18 个工具,字段为规范 inputSchema
465
+ const tools = await mcp.listTools(); // 20 个工具,字段为规范 inputSchema
449
466
  await mcp.callTool('market_stats', {}); // 经 daemon 真实路由执行
450
467
  ```
451
468
 
package/js/index.js CHANGED
@@ -9,7 +9,7 @@ const { AgentMarket, Bid, Reputation, MIN_STAKE } = require('./lib/market');
9
9
  const { McpHttpClient, McpError, MCP_PROTOCOL_VERSION } = require('./lib/mcp');
10
10
  const aca = require('./lib/aca');
11
11
 
12
- const version = '3.4.5';
12
+ const version = '3.6.0';
13
13
 
14
14
  /**
15
15
  * AgentUniverse 门面:聚合身份、网络、市场能力
package/js/lib/aca.js CHANGED
@@ -158,7 +158,7 @@ function buildManifest(identity, name, capabilities, opts = {}) {
158
158
  const manifest = {
159
159
  did: identity.did,
160
160
  name,
161
- version: opts.version || '3.4.5',
161
+ version: opts.version || '3.6.0',
162
162
  capabilities: [...capabilities],
163
163
  endpoints: opts.endpoints || [],
164
164
  hardware: {
package/js/lib/mcp.js CHANGED
@@ -18,12 +18,25 @@ class McpHttpClient {
18
18
  constructor(
19
19
  baseUrl = 'http://127.0.0.1:4002',
20
20
  path = '/api/v1/mcp',
21
- timeout = 10000
21
+ timeout = 10000,
22
+ authToken = null
22
23
  ) {
23
24
  this.endpoint = baseUrl.replace(/\/$/, '') + path;
24
25
  this.timeout = timeout;
25
26
  this._id = 0;
26
27
  this.initialized = false;
28
+ // v3.5.3(AU-15):可选 Bearer token。设置后所有 MCP 请求带
29
+ // `Authorization: Bearer <token>`;不设置则不发送该头(保持现状)。
30
+ this.authToken = authToken || null;
31
+ }
32
+
33
+ _headers() {
34
+ const h = {
35
+ 'Content-Type': 'application/json',
36
+ Accept: 'application/json',
37
+ };
38
+ if (this.authToken) h['Authorization'] = `Bearer ${this.authToken}`;
39
+ return h;
27
40
  }
28
41
 
29
42
  async _post(payload, awaitResponse = true) {
@@ -33,10 +46,7 @@ class McpHttpClient {
33
46
  try {
34
47
  res = await fetch(this.endpoint, {
35
48
  method: 'POST',
36
- headers: {
37
- 'Content-Type': 'application/json',
38
- Accept: 'application/json',
39
- },
49
+ headers: this._headers(),
40
50
  body: JSON.stringify(payload),
41
51
  signal: ctrl.signal,
42
52
  });
@@ -60,7 +70,7 @@ class McpHttpClient {
60
70
  method: 'initialize',
61
71
  params: {
62
72
  protocolVersion: MCP_PROTOCOL_VERSION,
63
- clientInfo: { name: 'agent-universe-js', version: '3.4.5' },
73
+ clientInfo: { name: 'agent-universe-js', version: '3.6.0' },
64
74
  capabilities: {},
65
75
  },
66
76
  });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@twinsearth/agent-universe",
3
- "version": "3.4.5",
3
+ "version": "3.6.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@twinsearth/agent-universe",
9
- "version": "3.4.5",
9
+ "version": "3.6.0",
10
10
  "license": "MIT",
11
11
  "engines": {
12
12
  "node": ">=18"
package/js/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/agent-universe",
3
- "version": "3.4.5",
3
+ "version": "3.6.0",
4
4
  "description": "Agent Universe - 群众化的 AGI 路线,去中心化的智能体共享 & 开源网络。使命:让科技造福全人类!",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/js/test/test.js CHANGED
@@ -25,6 +25,7 @@ const {
25
25
  verifyMessage,
26
26
  verifyReceipt,
27
27
  verifyReceiptResult,
28
+ McpHttpClient,
28
29
  } = require('../index');
29
30
 
30
31
  let passed = 0;
@@ -43,8 +44,8 @@ function test(name, fn) {
43
44
  console.log('Agent Universe JS SDK 测试\n');
44
45
 
45
46
  // 1. 版本号
46
- test('版本号为 3.4.5', () => {
47
- assert.strictEqual(version, '3.4.5');
47
+ test('版本号为 3.6.0', () => {
48
+ assert.strictEqual(version, '3.6.0');
48
49
  });
49
50
 
50
51
  // 2. 密钥对 + DID + 签名验证
@@ -101,7 +102,11 @@ test('ShardedIndex 分片落盘且分片号合法', () => {
101
102
  assert.ok(s >= 0 && s < 16);
102
103
  }
103
104
  assert.strictEqual(idx.size, 100);
104
- assert.strictEqual(shardOf('key-0', 16), shardOf('key-0', 16));
105
+ // v3.5.3(AU-39):旧断言 shardOf('key-0',16) === shardOf('key-0',16) 恒真(自身比自身)。
106
+ // 改为有意义的不变量:①同一 key 分片结果确定(两次调用一致);②结果落在合法区间 [0,16)。
107
+ const shard = shardOf('key-0', 16);
108
+ assert.strictEqual(shardOf('key-0', 16), shard);
109
+ assert.ok(Number.isInteger(shard) && shard >= 0 && shard < 16, `分片号合法: ${shard}`);
105
110
  // 分布:100 key 到 16 片,不应有大片为空(概率性,至少覆盖 8 片)
106
111
  const nonEmpty = idx.distribution().filter((n) => n > 0).length;
107
112
  assert.ok(nonEmpty >= 8, `非空分片 ${nonEmpty} >= 8`);
@@ -447,6 +452,17 @@ test('v2.7.1 stableStringify:undefined 键省略、BigInt/Date 显式拒绝、
447
452
  assert.strictEqual(stableStringify({ b: 1, a: 2 }), '{"a":2,"b":1}');
448
453
  });
449
454
 
455
+ // 18. MCP Bearer 注入(v3.5.3,AU-15)
456
+ test('McpHttpClient:带 token 发 Bearer 头、不带则不发', () => {
457
+ // 不设置 token → 不出现 Authorization 头。
458
+ const noAuth = new McpHttpClient();
459
+ assert.strictEqual(noAuth._headers().Authorization, undefined);
460
+ assert.strictEqual(noAuth._headers()['Content-Type'], 'application/json');
461
+ // 设置 token → 带正确的 Bearer 头。
462
+ const withAuth = new McpHttpClient('http://127.0.0.1:4002', '/api/v1/mcp', 10000, 'secret-xyz');
463
+ assert.strictEqual(withAuth._headers().Authorization, 'Bearer secret-xyz');
464
+ });
465
+
450
466
  console.log(`\n${passed} 项测试通过`);
451
467
  if (process.exitCode === 1) {
452
468
  console.error('存在失败测试');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/agent-universe",
3
- "version": "3.4.5",
3
+ "version": "3.6.0",
4
4
  "description": "Agent Universe - 群众化的 AGI 路线,去中心化的智能体共享 & 开源网络。使命:让科技造福全人类!",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",