@twinsearth/agent-universe 2.7.0 → 2.7.1

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/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 = '2.7.0';
12
+ const version = '2.7.1';
13
13
 
14
14
  /**
15
15
  * AgentUniverse 门面:聚合身份、网络、市场能力
package/js/lib/aca.js CHANGED
@@ -27,11 +27,27 @@ function nowSec() {
27
27
 
28
28
  /** 稳定 JSON 序列化:紧凑、对象键按字典序、非 ASCII 原样输出 */
29
29
  function stableStringify(value) {
30
+ // v2.7.1(GAP §9.1):禁止静默产出非法 JSON 或错误载荷。
31
+ // - BigInt:JSON.stringify 会抛晦涩的 "Do not know how to serialize",这里显式抛类型错误;
32
+ // - Date:此前 typeof object 且 own keys 为空,静默变成 {},载荷错误却签名看似有效;
33
+ // - 顶层 undefined:JSON.stringify 返回 undefined(非字符串),会拼出裸标记。
34
+ if (typeof value === 'bigint') {
35
+ throw new TypeError('stableStringify: BigInt 不可进入签名载荷(Rust 侧无对应整数类型)');
36
+ }
37
+ if (value instanceof Date) {
38
+ throw new TypeError('stableStringify: Date 不可签名;请先传 epoch 毫秒数或 ISO 字符串');
39
+ }
30
40
  if (value === null || typeof value !== 'object') {
41
+ // 顶层 undefined 走到这里:JSON.stringify(undefined) 返回 undefined,
42
+ // 若被拼进对象/数组会变成裸标记。显式拒绝。
43
+ if (value === undefined) {
44
+ throw new TypeError('stableStringify: 顶层 undefined 不可序列化;对象中的 undefined 键会被省略');
45
+ }
31
46
  return JSON.stringify(value);
32
47
  }
33
48
  if (Array.isArray(value)) {
34
- return '[' + value.map(stableStringify).join(',') + ']';
49
+ // 数组空位/undefined 元素转 null(JSON 合法),保持位置。
50
+ return '[' + value.map((v) => (v === undefined ? 'null' : stableStringify(v))).join(',') + ']';
35
51
  }
36
52
  // v2.6.4(GAP §4.4):按 Unicode 码点序排序,而非 JS 默认的 UTF-16 码元序。
37
53
  // 否则含 astral(补充平面,如 emoji)键名时,JS 与 Rust BTreeMap 的键序分歧,
@@ -49,6 +65,7 @@ function stableStringify(value) {
49
65
  return (
50
66
  '{' +
51
67
  keys
68
+ .filter((k) => value[k] !== undefined)
52
69
  .map((k) => JSON.stringify(k) + ':' + stableStringify(value[k]))
53
70
  .join(',') +
54
71
  '}'
@@ -141,7 +158,7 @@ function buildManifest(identity, name, capabilities, opts = {}) {
141
158
  const manifest = {
142
159
  did: identity.did,
143
160
  name,
144
- version: opts.version || '2.7.0',
161
+ version: opts.version || '2.7.1',
145
162
  capabilities: [...capabilities],
146
163
  endpoints: opts.endpoints || [],
147
164
  hardware: {
package/js/lib/mcp.js CHANGED
@@ -60,7 +60,7 @@ class McpHttpClient {
60
60
  method: 'initialize',
61
61
  params: {
62
62
  protocolVersion: MCP_PROTOCOL_VERSION,
63
- clientInfo: { name: 'agent-universe-js', version: '2.7.0' },
63
+ clientInfo: { name: 'agent-universe-js', version: '2.7.1' },
64
64
  capabilities: {},
65
65
  },
66
66
  });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@twinsearth/agent-universe",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@twinsearth/agent-universe",
9
- "version": "2.7.0",
9
+ "version": "2.7.1",
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": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "Agent Universe - 群众化的 AGI 路线,去中心化的智能体共享 & 开源网络。使命:让科技造福全人类!",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/js/test/test.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // test/test.js
2
- // Agent Universe JS SDK 测试(20 项)
2
+ // Agent Universe JS SDK 测试(21 项)
3
3
 
4
4
  const assert = require('node:assert');
5
5
  const fs = require('node:fs');
@@ -43,8 +43,8 @@ function test(name, fn) {
43
43
  console.log('Agent Universe JS SDK 测试\n');
44
44
 
45
45
  // 1. 版本号
46
- test('版本号为 2.7.0', () => {
47
- assert.strictEqual(version, '2.7.0');
46
+ test('版本号为 2.7.1', () => {
47
+ assert.strictEqual(version, '2.7.1');
48
48
  });
49
49
 
50
50
  // 2. 密钥对 + DID + 签名验证
@@ -430,6 +430,23 @@ test('v2.6.4 canonical 键序按码点序,BMP私用区与astral分歧被修复
430
430
  assert.strictEqual(s1, '{"":2,"😀":1}', '键序必须是码点序(bmp 在前)');
431
431
  });
432
432
 
433
+ // 17. v2.7.1 stableStringify 拒绝非法/静默错误载荷(GAP §9.1)
434
+ test('v2.7.1 stableStringify:undefined 键省略、BigInt/Date 显式拒绝、数组空值转 null', () => {
435
+ const { stableStringify } = require('../lib/aca');
436
+ // 对象中的 undefined 键被省略,不再产出裸 undefined
437
+ assert.strictEqual(stableStringify({ a: undefined, b: 1 }), '{"b":1}');
438
+ // 数组空位/undefined 元素转 null,保持合法 JSON
439
+ assert.strictEqual(stableStringify([1, undefined, 2]), '[1,null,2]');
440
+ // BigInt 抛明确类型错误,而不是 Node 的晦涩异常
441
+ assert.throws(() => stableStringify({ n: 1n }), /BigInt/);
442
+ // Date 不再静默变成 {}
443
+ assert.throws(() => stableStringify({ d: new Date(0) }), /Date/);
444
+ // 顶层 undefined 拒绝
445
+ assert.throws(() => stableStringify(undefined), /undefined/);
446
+ // 正常路径不受影响
447
+ assert.strictEqual(stableStringify({ b: 1, a: 2 }), '{"a":2,"b":1}');
448
+ });
449
+
433
450
  console.log(`\n${passed} 项测试通过`);
434
451
  if (process.exitCode === 1) {
435
452
  console.error('存在失败测试');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/agent-universe",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "Agent Universe - 群众化的 AGI 路线,去中心化的智能体共享 & 开源网络。使命:让科技造福全人类!",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",