@agentunion/fastaun 0.4.3 → 0.4.4

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 (50) hide show
  1. package/CHANGELOG.md +198 -185
  2. package/_packed_docs/AUN_SDK_0.4.0_/350/256/276/350/256/241/345/257/271/346/257/224/345/210/206/346/236/220.md +194 -194
  3. package/_packed_docs/AUN_SDK_/351/207/215/346/236/204/345/256/236/346/226/275/350/256/241/345/210/222.md +596 -596
  4. package/_packed_docs/AUN_SDK_/351/207/215/346/236/204/350/256/276/350/256/241/346/226/271/346/241/210_v3.md +1698 -1697
  5. package/_packed_docs/CHANGELOG.md +198 -185
  6. package/_packed_docs/INDEX.md +17 -17
  7. package/_packed_docs/KITE_DOCS_GUIDE.md +11 -11
  8. package/_packed_docs/agent.md/SCHEMA.md +49 -49
  9. package/_packed_docs/agent.md/examples/signed-openclaw-lobster.md +22 -22
  10. package/_packed_docs/agent.md//350/277/234/347/250/213agent.md/347/274/223/345/255/230/344/270/216etag/351/200/217/344/274/240/346/226/271/346/241/210.md +327 -327
  11. package/_packed_docs/cli/AUN-CLI/350/256/276/350/256/241/346/226/207/346/241/243.md +686 -686
  12. package/_packed_docs/design/2026-05-22-aun-rpc-trace-enhancement.md +542 -542
  13. package/_packed_docs/design/E2EE_V2/347/256/200/345/214/226/344/270/2721DH/345/212/240Per-AID_Wrap/346/226/271/346/241/210.md +124 -124
  14. package/_packed_docs/design//350/267/250/350/257/255/350/250/200/345/256/271/345/231/250E2E/346/265/213/350/257/225/346/226/271/346/241/210.md +665 -665
  15. package/_packed_docs/protocol/01-/350/272/253/344/273/275/344/270/216/345/207/255/350/257/201/345/215/217/350/256/256-auth.md +2 -2
  16. package/_packed_docs/protocol/14-/344/272/244/344/272/222/346/234/272/345/210/266-/345/223/215/345/272/224/346/250/241/345/274/217/344/270/216/350/207/252/344/270/273/346/250/241/345/274/217.md +170 -170
  17. package/_packed_docs/protocol/15-/347/246/273/347/272/277/346/216/250/351/200/201/351/200/232/347/237/245/345/215/217/350/256/256.md +419 -419
  18. package/_packed_docs/protocol/README.md +1 -1
  19. package/_packed_docs/protocol/aun-docs-guide.md +1 -1
  20. package/_packed_docs/protocol//351/231/204/345/275/225A-/346/234/257/350/257/255/350/241/250.md +15 -15
  21. package/_packed_docs/protocol//351/231/204/345/275/225B-/346/211/251/345/261/225/346/200/247/346/214/207/345/215/227.md +4 -4
  22. package/_packed_docs/protocol//351/231/204/345/275/225J-/345/256/242/346/210/267/347/253/257/346/216/245/345/205/245/347/244/272/344/276/213.md +98 -98
  23. package/_packed_docs/protocol//351/231/204/345/275/225M-JWT/350/256/244/350/257/201/345/256/236/347/216/260/346/214/207/345/215/227.md +46 -46
  24. package/_packed_docs/protocol//351/231/204/345/275/225N-/345/210/206/345/270/203/345/274/217Trace/345/215/217/350/256/256.md +257 -257
  25. package/_packed_docs/python-sdk-v2-only-changelog.md +189 -189
  26. package/_packed_docs/sdk/01-/345/277/253/351/200/237/345/274/200/345/247/213.md +1 -1
  27. package/_packed_docs/sdk/05-E2EE/345/212/240/345/257/206/351/200/232/344/277/241.md +1 -1
  28. package/_packed_docs/sdk/06-API/346/211/213/345/206/214.md +1 -0
  29. package/_packed_docs/sdk/09-payload-reference.md +13 -13
  30. package/_packed_docs/sdk/E2EE_V2/346/266/210/346/201/257/351/200/232/344/277/241/346/227/266/345/272/217/345/233/276.md +171 -171
  31. package/dist/aid.d.ts +2 -1
  32. package/dist/aid.js +7 -6
  33. package/dist/aid.js.map +1 -1
  34. package/dist/auth.js +4 -0
  35. package/dist/auth.js.map +1 -1
  36. package/dist/client.d.ts +6 -0
  37. package/dist/client.js +204 -52
  38. package/dist/client.js.map +1 -1
  39. package/dist/keystore/file.d.ts +0 -2
  40. package/dist/keystore/file.js +6 -44
  41. package/dist/keystore/file.js.map +1 -1
  42. package/dist/tools/cross-sdk-agent.js +0 -9
  43. package/dist/tools/cross-sdk-agent.js.map +1 -1
  44. package/dist/transport.d.ts +1 -0
  45. package/dist/transport.js +7 -1
  46. package/dist/transport.js.map +1 -1
  47. package/dist/v2/session/keystore.js +2 -2
  48. package/dist/version.d.ts +1 -1
  49. package/dist/version.js +1 -1
  50. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,185 +1,198 @@
1
- # Changelog
2
-
3
- 本文件记录 `@agentunion/fastaun` (Node.js) SDK 的版本变更。最新版本在最前面。
4
-
5
- 格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循 [SemVer](https://semver.org/lang/zh-CN/)。
6
-
7
- ---
8
-
9
- ## 0.4.3 — 2026-05-31
10
-
11
- ### Added
12
- - **`normalizeSlotId` / `slotIsolationKey`**:新增 slot_id 校验与隔离键提取工具函数,支持 `/` `:` 空格作为分隔符(首字符不允许)。
13
- - **keystore schema 迁移至 v2**:`instance_state` / `seq_tracker` 表新增 `slot_id_full` 列,保存完整 slot_id(隔离键仅用于索引);首次启动自动 `ALTER TABLE` 升级。
14
-
15
- ### Changed
16
- - **slot_id 存储策略**:keystore 读写统一使用 `slotIsolationKey` 作为索引键,`slot_id_full` 保存原始完整值,与 Python / Go SDK 对齐。
17
- - **`AUNClient` 构造**:传入 `aid` 参数时增加类型守卫(检查 `aunPath` 字段与 `isPrivateKeyValid` 方法),避免误传非 AID 对象。
18
-
19
- ---
20
-
21
- ## 0.4.2 — 2026-05-30
22
-
23
- ### Added
24
- - **`AIDStore` 新增具名返回类型**:`ResolveResult`、`FetchAgentMdResult`、`HeadAgentMdResult`、`CheckAgentMdResult`、`DiagnoseResult`、`RenewCertResult`、`RekeyResult`、`ChangeSeedResult`、`ListResult`,替代原来的 `Record<string, unknown>`。
25
- - **`AID` 新增 `verifySsl` 只读字段**:创建时由 `AIDStore` 注入,供内部 HTTP 请求使用。
26
- - **`AUNClientOptions` 新增 `rootCaPath` / `debug`**:支持私有部署自定义根证书路径,以及构造时直接传入调试开关。
27
-
28
- ### Changed
29
- - **移除 `discoveryPort`**:`AIDStore` 构造选项删除 `discoveryPort`,gateway URL 改为纯自动发现。
30
- - **`fetchAgentMd` 新增 `timeoutMs` 参数**(默认 30000ms),`resolve` 内部调用时透传 `opts.timeout`(默认 10000ms)。
31
- - **返回字段精简**:`fetchAgentMd` / `headAgentMd` / `checkAgentMd` / `diagnose` 移除冗余的 camelCase 别名字段,统一使用 snake_case。
32
- - **`resolve` 返回 `source` 字段精简**:移除 `certFromCache` / `agentMdFetched` camelCase 别名,只保留 `cert_from_cache` / `agent_md_fetched`。
33
- - **`AID._create` 透传 `verifySsl` / `rootCaPath` / `debug`**:`AIDStore` 在 `load` / `resolve` 时自动注入这三个配置项到 `AID` 实例。
34
-
35
- ---
36
-
37
- ## 0.4.0 2026-05-30
38
-
39
- > **破坏性重构版本。** 与 Python SDK 0.4.0 对齐:身份管理剥离为 `AID` / `AIDStore`;删除 `auth` / `custody` / `meta` 公开命名空间;引入 `Result` 与字符串错误码;连接状态机扩展为 9 态。
40
-
41
- ### Breaking Changes
42
- - **删除公开命名空间**:移除 `client.auth` / `client.custody` / `client.meta`。身份相关功能迁移到 `AIDStore` `AID`,其余 RPC 走 `client.call()`。
43
- - **构造函数签名变更**:`constructor(config?, debug?)` `constructor(aid?: AID, options?: AUNClientOptions)`;移除 `debug` 布尔参数。
44
- - **初始连接状态变更**:`'idle'` `'no_identity'`。
45
- - **目录约定变更**:`{aun_path}/AgentMDs/` `{aun_path}/AIDs/`。
46
-
47
- ### Added
48
- - **`AID` 类**:封装证书 + 可选私钥,提供 `sign` / `verify` / `signAgentMd` / `verifyAgentMd` / `isCertValid` / `isPrivateKeyValid`。
49
- - **`AIDStore` 类**:离线 `load` / `list` / `exists`,联网 `register` / `resolve` / `fetchAgentMd` / `checkAgentMd` / `diagnose` / `renewCert` / `rekey` / `changeSeed`。
50
- - **`Result<T>` 类型**:统一结果类型(`{ ok: true; data: T }` 或 `{ ok: false; error: ErrorInfo }`)。
51
- - **新增错误类**:`NotFoundError` / `IdentityConflictError` / `VersionConflictError` / `ClientSignatureError`。
52
- - **`ConnectionState` 枚举**:9 态(`NO_IDENTITY` / `STANDBY` / `CONNECTING` / `READY` / `RETRY_BACKOFF` / `RECONNECTING` / `CONNECTION_FAILED` / `CLOSED`)。
53
- - **实例级 `protected_headers`**:`setProtectedHeaders()` 自动合并到 `message.send` / `group.send` / `*.thought.put`。
54
- - **重连状态可观测**:`nextRetryAt` / `retryAttempt` / `retryMaxAttempts` / `lastError` / `lastErrorCode` 属性。
55
- - **客户端属性**:`currentAid` / `hasIdentity` / `canSign` / `canConnect` / `canSend`。
56
- - **导出**:`VERSION` 常量、`STATE_TO_PUBLIC` 映射表。
57
- - **keystore 扩展**:新增 `prekeys` / `group_current` / `group_old_epochs` / `e2ee_sessions` 表及相关读写方法;新增字段级加解密(旧 E2EE 互操作)。
58
-
59
- ### Fixed
60
- - **agent.md 请求超时**:新增 `fetchWithTimeout()` 防止挂起。
61
- - **agent.md 下载并发控制**:新增 `AGENT_MD_DOWNLOAD_CONCURRENCY` 限制。
62
-
63
- ### Removed
64
- - 删除 `ts/src/namespaces/auth.ts`、`ts/src/namespaces/custody.ts`、`ts/src/namespaces/meta.ts`。
65
-
66
- ---
67
-
68
- ## 0.3.6 2026-05-28
69
-
70
- ### Added
71
- - **Encrypted push 解密管线**:收到加密推送时即时尝试 V2 解密,成功则发 `message.received` / `group.message_created`(含明文 payload + e2ee 元数据),失败则发 `message.undecryptable` / `group.message_undecryptable`(含诊断字段 `_decrypt_error` / `_decrypt_stage` / `_envelope_type`)
72
- - **`auth.fetchPeerCert(gatewayUrl, aid)`**:公开 API 实现落地(v0.3.5 声明,v0.3.6 实现独立方法体)
73
- - **`storage.get_limits` RPC**:查询上传限制和配额使用情况
74
- - **`storage.check_upload` RPC**:上传预检(秒传检测 + 超限检测)
75
-
76
- ### Fixed
77
- - **Identity cache 自愈**:V2 session init 时检测 `private_key_pem` 缺失,自动从 keystore 重新加载并清理脏 instance_state
78
- - **`loadIdentity` 字段白名单**:只合并 `_INSTANCE_STATE_FIELDS` 定义的字段,防止 instance_state 表中的脏数据覆盖核心字段
79
- - **`.seed.migrated` 兼容**:`FileSecretStore` 解密失败时自动尝试 `.seed.migrated.*` 文件作为 fallback(半迁移状态兼容)
80
-
81
- ### Changed
82
- - **Auth namespace gateway_url 持久化**:`registerAid` / `authenticate` 成功后自动持久化 gateway_url 到 instance_state
83
-
84
- ---
85
-
86
- ## 0.3.5 — 2026-05-28
87
-
88
- ### Breaking Changes
89
- - **`createAid()` 兼容别名移除**:仅保留 `registerAid()`,旧 `createAid` 已删除
90
- - **注册与认证分离**:`authenticate()` 不再隐式注册;身份不完整时抛 `StateError`
91
-
92
- ### Added
93
- - **`IdentityConflictError`**:新增错误类型(继承 `AuthError`),AID 注册冲突时抛出
94
- - **`auth.loadIdentityOrNull()`**:公开 API,只读加载本地已注册身份,不存在时返回 null(`auth.loadIdentity()` 已有)
95
- - **`auth.fetchPeerCert()`**:公开 API,获取对端 AID 证书 PEM(本地缓存优先,未命中走 PKI HTTP + 链验证)(已有)
96
-
97
- ### Changed
98
- - **`registerAid` 半成品恢复**:本地有 keypair 无 cert 时,查服务端恢复;服务端无记录则用现有 keypair 注册(不再直接拒绝)
99
- - **agent.md 下载**:改为无条件 GET(移除条件头);304 时本地有缓存直接用,无缓存重试
100
- - **错误消息**:所有 `createAid` 引用更新为 `registerAid`
101
- - **`.seed` fallback 迁移**:`FileSecretStore` 启动时检测旧 `.seed` 文件,自动迁移到 `seed_password` 派生方式
102
- - **`ChangeSeed` API**:`FileKeyStore.ChangeSeed()` / `FileKeyStore.changeSeed()` 支持运行时更换 seed
103
-
104
- ### Removed
105
- - **`namespaces/auth.ts` 中 `createAid` 兼容别名**
106
-
107
- ---
108
-
109
- ## 0.3.3 — 2026-05-25
110
-
111
- ### Added
112
- - **V2 Thought 加解密**:`group.thought.get` / `message.thought.get` 返回值自动解密;发送端自动加密;`attachV2EnvelopeMetadata` 附加 E2EE 元数据
113
- - **V2 Sender IK 延迟解密**:`_v2SenderIKPending` / `_v2SenderIKFetching` 机制,对端 IK 未缓存时挂起消息、异步拉取后重试解密
114
- - **agent.md 本地缓存体系**:`setAgentMdPath` / `publishAgentMd()` / `fetchAgentMd(aid?)`;基于文件系统的 list.json 索引 + 按 AID 存储 + etag 比对 + 自动拉取缺失
115
- - **KeyStore agent_md_cache 持久化**:文件系统 + SQLite 双后端支持
116
- - **V2 辅助函数**:`getV2DeviceId` / `_v2B64ToBytesStrict` / `_v2BytesEqual` / `_v2ConcatBytes` / `_v2LengthPrefixedTextKey` / `_v2LengthPrefixedBytes`
117
- - **V2 envelope 元数据**:`attachV2EnvelopeMetadata` / `attachV2EnvelopeMetadataFromSource` / `extractV2EnvelopeFromSource` / `metadataWithoutAuth`
118
- - **签名跳过策略**:对内部方法和系统事件跳过签名验证
119
-
120
- ### Changed
121
- - **V2 消息处理路径重构**:统一 P2P/Group 解密入口,支持 sender IK pending 延迟模式
122
- - **V2 SPK rotation**:thought 解密失败时触发 group SPK rotation / registration after peer fallback
123
- - **消息调试日志增强**:thought.get 全链路 debug 日志
124
-
125
- ### Fixed
126
- - **service-plane envelope 解包**:修复 Kernel trace 字段传递丢失
127
- - **trace 树状展示**:enter/exit 配对 + 嵌套缩进
128
-
129
- ---
130
-
131
- ## 0.3.1 — 2026-05-22
132
-
133
- ### Added
134
- - **`auth.checkAid` handler**:本地证书自检(解析有效期、公钥)+ 远端注册状态查询;新增 `parseCertValidity` / `parseAsn1Time` ASN.1 时间解析
135
- - **RPC trace 增强**:`RPCTransport` 增加 `setTraceMode()` / `setTraceObserver()`;`sortTraceSpansForDisplay` / `formatTraceTree` / `traceDisplay` 树状展示按 ts 排序 + 嵌套缩进;`TraceObserver` 类型导出
136
- - **V2 群组 SPK 生命周期**:`V2KeyStore.saveGroupSPK` / `loadGroupSPK` / `loadCurrentGroupSPK`;`V2Session.ensureGroupRegistered` / `rotateGroupSPK` / `_publishGroupSPK`;`DESTROY_DELAY_MS = 7d`
137
- - **V2 P2P push 解密**:`AUNClient._onV2PushNotification` / `_decryptV2PushMessage` 实现带 payload 的就地解密 + 失败回退到 pull
138
-
139
- ### Changed
140
- - **`SeqTracker.forceContiguousSeq`**:原 `contiguousSeq = minSeq` 跳过空洞(会丢消息),改为 `contiguousSeq = minSeq - 1` 由连续前缀自然推进,避免误丢
141
-
142
- ### Fixed
143
- - **`client.ts:4026` 类型错误**:`_publishOrderedMessage` 的 `decrypted` 实参补 `as EventPayload` 断言(`Record<string, unknown>` 与 `JsonValue | Error` 不兼容)
144
- - short RPC 请求增加 `debug` 完整报文日志,便于跨语言诊断
145
-
146
- ---
147
-
148
- ## 0.3.0 2026-05-21 ⚠️ BREAKING CHANGE
149
-
150
- > **V2-only 版本**:移除全部 V1 E2EE(含群组加密),新增 V2 加密原语,API 不向后兼容。
151
-
152
- ### BREAKING
153
- - **移除 V1 E2EE 全部实现**:`GroupE2EEManager`、V1 epoch key 逻辑全部删除
154
- - **移除 V1 群组加密测试**:`e2ee.test.ts`、`e2ee-group.test.ts`、`epoch-key-server.spec.ts` 等
155
- - **E2EE 接口简化**:`e2ee.ts` 仅保留 V2 路径,V1 加解密方法不再可用
156
- - **配置变更**:`AUNConfig` 移除 V1 相关配置项
157
- - **KeyStore 重构**:`keystore/` 目录结构调整,`aid-db.ts` / `file.ts` 接口变更
158
-
159
- ### Added
160
- - **agent.md 主 API**:`AUNClient.publishAgentMd(path)` / `AUNClient.fetchAgentMd(aid?, savePath?)`
161
- - **V2 加密原语**(跨语言 golden vector 一致性):ECDH P-256、HKDF-SHA256、AES-256-GCM、ECDSA-SHA256 RAW (RFC 6979)、1DH/3DH wrap_key、Recipients Sort + Merkle Digest、State Commitment
162
-
163
- ### Removed
164
- - `AUNClient.setLocalAgentMdPath()` / `getLocalAgentMdEtag()` / `getRemoteAgentMdEtag()` — 由主 API 自动维护
165
-
166
- ### Deprecated
167
- - `client.auth.signAgentMd` / `verifyAgentMd` / `uploadAgentMd` / `downloadAgentMd` — 建议迁移到 `client.publishAgentMd` / `client.fetchAgentMd`
168
-
169
- ---
170
-
171
- ## 0.2.20 — 2026-05-18
172
-
173
- ### Added
174
- - **agent.md 版本一致性 API**:`AUNClient.setLocalAgentMdPath(path)` / `getLocalAgentMdEtag()` / `getRemoteAgentMdEtag()`。Node `fs.readFileSync` + `crypto.createHash` 计算 etag,浏览器场景返回空串并 warn。SDK 自动从 RPC envelope `_meta.agent_md_etag` 提取服务端 etag,应用层订阅 `message.received` / `group.message_created` 等事件时 payload 多 `_agent_md.{local_etag, remote_etag}` 字段供版本比对。
175
- - **`downloadAgentMd` 条件请求缓存**:内部维护 ETag/Last-Modified,未变化时返回上次缓存内容;外部 API 形态不变。
176
- - **transport meta observer**:`RPCTransport.setMetaObserver(fn)` 透传 envelope `_meta`,observer 抛错被吞,不影响 RPC result。
177
-
178
- ### Changed
179
- - **RPC call 默认超时 10s → 35s**:与服务端 30s handler timeout 对齐,留 5s buffer。
180
- - **multi-device 架构**:对端无 prekey `_sendEncrypted` 直接抛错(`no registered device prekeys for ...`),不再降级到 `long_term_key`。
181
-
182
- ### Docs
183
- - 仓库根 `docs/`(agent.md 规范、protocol、SDK 手册)随 npm tarball 打包到 `_packed_docs/`,安装后可读。`.gitignore` 排除项(如内部测试指南)不进包。
184
-
185
- ---
1
+ # Changelog
2
+
3
+ 本文件记录 `@agentunion/fastaun` (Node.js) SDK 的版本变更。最新版本在最前面。
4
+
5
+ 格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循 [SemVer](https://semver.org/lang/zh-CN/)。
6
+
7
+ ---
8
+
9
+ ## 0.4.4 — 2026-05-31
10
+
11
+ ### Added
12
+ - **`AID` 新增 `privateKeyPem` 只读字段**:`AIDStore.load()` 加载时注入明文私钥,`AUNClient` 直接从 `AID` 读取,无需再经 keystore 解密。
13
+
14
+ ### Changed
15
+ - **`AUNClient` 剥离私钥读写**:V2 session 初始化、`_signClientOperation`、propose_state 签名均改从 `_currentAid.privateKeyPem` 读取,删除 keystore fallback 重解密路径。
16
+ - **`auth._persistIdentity` 不再写私钥**:写入前剥离 `private_key_pem` / `public_key_der_b64` / `curve`,AUNClient keystore 只持久化 token / cert / instance_state。
17
+ - **`AUNClient` keystore 构造不再传 `encryptionSeed`**:seed 作用域收窄至 AIDStore,不外漏。
18
+ - **SQLite 明文化清理**:删除 `_protectText` / `_revealText` 等加密兼容残留,所有 SQLite 字段直接明文读写。
19
+
20
+ ---
21
+
22
+ ## 0.4.3 — 2026-05-31
23
+
24
+ ### Added
25
+ - **`normalizeSlotId` / `slotIsolationKey`**:新增 slot_id 校验与隔离键提取工具函数,支持 `/` `:` 空格作为分隔符(首字符不允许)。
26
+ - **keystore schema 迁移至 v2**:`instance_state` / `seq_tracker` 表新增 `slot_id_full` 列,保存完整 slot_id(隔离键仅用于索引);首次启动自动 `ALTER TABLE` 升级。
27
+
28
+ ### Changed
29
+ - **slot_id 存储策略**:keystore 读写统一使用 `slotIsolationKey` 作为索引键,`slot_id_full` 保存原始完整值,与 Python / Go SDK 对齐。
30
+ - **`AUNClient` 构造**:传入 `aid` 参数时增加类型守卫(检查 `aunPath` 字段与 `isPrivateKeyValid` 方法),避免误传非 AID 对象。
31
+
32
+ ---
33
+
34
+ ## 0.4.2 — 2026-05-30
35
+
36
+ ### Added
37
+ - **`AIDStore` 新增具名返回类型**:`ResolveResult`、`FetchAgentMdResult`、`HeadAgentMdResult`、`CheckAgentMdResult`、`DiagnoseResult`、`RenewCertResult`、`RekeyResult`、`ChangeSeedResult`、`ListResult`,替代原来的 `Record<string, unknown>`。
38
+ - **`AID` 新增 `verifySsl` 只读字段**:创建时由 `AIDStore` 注入,供内部 HTTP 请求使用。
39
+ - **`AUNClientOptions` 新增 `rootCaPath` / `debug`**:支持私有部署自定义根证书路径,以及构造时直接传入调试开关。
40
+
41
+ ### Changed
42
+ - **移除 `discoveryPort`**:`AIDStore` 构造选项删除 `discoveryPort`,gateway URL 改为纯自动发现。
43
+ - **`fetchAgentMd` 新增 `timeoutMs` 参数**(默认 30000ms),`resolve` 内部调用时透传 `opts.timeout`(默认 10000ms)。
44
+ - **返回字段精简**:`fetchAgentMd` / `headAgentMd` / `checkAgentMd` / `diagnose` 移除冗余的 camelCase 别名字段,统一使用 snake_case。
45
+ - **`resolve` 返回 `source` 字段精简**:移除 `certFromCache` / `agentMdFetched` camelCase 别名,只保留 `cert_from_cache` / `agent_md_fetched`。
46
+ - **`AID._create` 透传 `verifySsl` / `rootCaPath` / `debug`**:`AIDStore` 在 `load` / `resolve` 时自动注入这三个配置项到 `AID` 实例。
47
+
48
+ ---
49
+
50
+ ## 0.4.0 2026-05-30
51
+
52
+ > **破坏性重构版本。** Python SDK 0.4.0 对齐:身份管理剥离为 `AID` / `AIDStore`;删除 `auth` / `custody` / `meta` 公开命名空间;引入 `Result` 与字符串错误码;连接状态机扩展为 9 态。
53
+
54
+ ### Breaking Changes
55
+ - **删除公开命名空间**:移除 `client.auth` / `client.custody` / `client.meta`。身份相关功能迁移到 `AIDStore` `AID`,其余 RPC `client.call()`。
56
+ - **构造函数签名变更**:`constructor(config?, debug?)` `constructor(aid?: AID, options?: AUNClientOptions)`;移除 `debug` 布尔参数。
57
+ - **初始连接状态变更**:`'idle'` `'no_identity'`。
58
+ - **目录约定变更**:`{aun_path}/AgentMDs/` → `{aun_path}/AIDs/`。
59
+
60
+ ### Added
61
+ - **`AID` 类**:封装证书 + 可选私钥,提供 `sign` / `verify` / `signAgentMd` / `verifyAgentMd` / `isCertValid` / `isPrivateKeyValid`。
62
+ - **`AIDStore` 类**:离线 `load` / `list` / `exists`,联网 `register` / `resolve` / `fetchAgentMd` / `checkAgentMd` / `diagnose` / `renewCert` / `rekey` / `changeSeed`。
63
+ - **`Result<T>` 类型**:统一结果类型(`{ ok: true; data: T }` 或 `{ ok: false; error: ErrorInfo }`)。
64
+ - **新增错误类**:`NotFoundError` / `IdentityConflictError` / `VersionConflictError` / `ClientSignatureError`。
65
+ - **`ConnectionState` 枚举**:9 态(`NO_IDENTITY` / `STANDBY` / `CONNECTING` / `READY` / `RETRY_BACKOFF` / `RECONNECTING` / `CONNECTION_FAILED` / `CLOSED`)。
66
+ - **实例级 `protected_headers`**:`setProtectedHeaders()` 自动合并到 `message.send` / `group.send` / `*.thought.put`。
67
+ - **重连状态可观测**:`nextRetryAt` / `retryAttempt` / `retryMaxAttempts` / `lastError` / `lastErrorCode` 属性。
68
+ - **客户端属性**:`currentAid` / `hasIdentity` / `canSign` / `canConnect` / `canSend`。
69
+ - **导出**:`VERSION` 常量、`STATE_TO_PUBLIC` 映射表。
70
+ - **keystore 扩展**:新增 `prekeys` / `group_current` / `group_old_epochs` / `e2ee_sessions` 表及相关读写方法;新增字段级加解密(旧 E2EE 互操作)。
71
+
72
+ ### Fixed
73
+ - **agent.md 请求超时**:新增 `fetchWithTimeout()` 防止挂起。
74
+ - **agent.md 下载并发控制**:新增 `AGENT_MD_DOWNLOAD_CONCURRENCY` 限制。
75
+
76
+ ### Removed
77
+ - 删除 `ts/src/namespaces/auth.ts`、`ts/src/namespaces/custody.ts`、`ts/src/namespaces/meta.ts`。
78
+
79
+ ---
80
+
81
+ ## 0.3.6 — 2026-05-28
82
+
83
+ ### Added
84
+ - **Encrypted push 解密管线**:收到加密推送时即时尝试 V2 解密,成功则发 `message.received` / `group.message_created`(含明文 payload + e2ee 元数据),失败则发 `message.undecryptable` / `group.message_undecryptable`(含诊断字段 `_decrypt_error` / `_decrypt_stage` / `_envelope_type`)
85
+ - **`auth.fetchPeerCert(gatewayUrl, aid)`**:公开 API 实现落地(v0.3.5 声明,v0.3.6 实现独立方法体)
86
+ - **`storage.get_limits` RPC**:查询上传限制和配额使用情况
87
+ - **`storage.check_upload` RPC**:上传预检(秒传检测 + 超限检测)
88
+
89
+ ### Fixed
90
+ - **Identity cache 自愈**:V2 session init 时检测 `private_key_pem` 缺失,自动从 keystore 重新加载并清理脏 instance_state
91
+ - **`loadIdentity` 字段白名单**:只合并 `_INSTANCE_STATE_FIELDS` 定义的字段,防止 instance_state 表中的脏数据覆盖核心字段
92
+ - **`.seed.migrated` 兼容**:`FileSecretStore` 解密失败时自动尝试 `.seed.migrated.*` 文件作为 fallback(半迁移状态兼容)
93
+
94
+ ### Changed
95
+ - **Auth namespace gateway_url 持久化**:`registerAid` / `authenticate` 成功后自动持久化 gateway_url 到 instance_state
96
+
97
+ ---
98
+
99
+ ## 0.3.5 2026-05-28
100
+
101
+ ### Breaking Changes
102
+ - **`createAid()` 兼容别名移除**:仅保留 `registerAid()`,旧 `createAid` 已删除
103
+ - **注册与认证分离**:`authenticate()` 不再隐式注册;身份不完整时抛 `StateError`
104
+
105
+ ### Added
106
+ - **`IdentityConflictError`**:新增错误类型(继承 `AuthError`),AID 注册冲突时抛出
107
+ - **`auth.loadIdentityOrNull()`**:公开 API,只读加载本地已注册身份,不存在时返回 null(`auth.loadIdentity()` 已有)
108
+ - **`auth.fetchPeerCert()`**:公开 API,获取对端 AID 证书 PEM(本地缓存优先,未命中走 PKI HTTP + 链验证)(已有)
109
+
110
+ ### Changed
111
+ - **`registerAid` 半成品恢复**:本地有 keypair 无 cert 时,查服务端恢复;服务端无记录则用现有 keypair 注册(不再直接拒绝)
112
+ - **agent.md 下载**:改为无条件 GET(移除条件头);304 时本地有缓存直接用,无缓存重试
113
+ - **错误消息**:所有 `createAid` 引用更新为 `registerAid`
114
+ - **`.seed` fallback 迁移**:`FileSecretStore` 启动时检测旧 `.seed` 文件,自动迁移到 `seed_password` 派生方式
115
+ - **`ChangeSeed` API**:`FileKeyStore.ChangeSeed()` / `FileKeyStore.changeSeed()` 支持运行时更换 seed
116
+
117
+ ### Removed
118
+ - **`namespaces/auth.ts` 中 `createAid` 兼容别名**
119
+
120
+ ---
121
+
122
+ ## 0.3.3 2026-05-25
123
+
124
+ ### Added
125
+ - **V2 Thought 加解密**:`group.thought.get` / `message.thought.get` 返回值自动解密;发送端自动加密;`attachV2EnvelopeMetadata` 附加 E2EE 元数据
126
+ - **V2 Sender IK 延迟解密**:`_v2SenderIKPending` / `_v2SenderIKFetching` 机制,对端 IK 未缓存时挂起消息、异步拉取后重试解密
127
+ - **agent.md 本地缓存体系**:`setAgentMdPath` / `publishAgentMd()` / `fetchAgentMd(aid?)`;基于文件系统的 list.json 索引 + 按 AID 存储 + etag 比对 + 自动拉取缺失
128
+ - **KeyStore agent_md_cache 持久化**:文件系统 + SQLite 双后端支持
129
+ - **V2 辅助函数**:`getV2DeviceId` / `_v2B64ToBytesStrict` / `_v2BytesEqual` / `_v2ConcatBytes` / `_v2LengthPrefixedTextKey` / `_v2LengthPrefixedBytes`
130
+ - **V2 envelope 元数据**:`attachV2EnvelopeMetadata` / `attachV2EnvelopeMetadataFromSource` / `extractV2EnvelopeFromSource` / `metadataWithoutAuth`
131
+ - **签名跳过策略**:对内部方法和系统事件跳过签名验证
132
+
133
+ ### Changed
134
+ - **V2 消息处理路径重构**:统一 P2P/Group 解密入口,支持 sender IK pending 延迟模式
135
+ - **V2 SPK rotation**:thought 解密失败时触发 group SPK rotation / registration after peer fallback
136
+ - **消息调试日志增强**:thought.get 全链路 debug 日志
137
+
138
+ ### Fixed
139
+ - **service-plane envelope 解包**:修复 Kernel trace 字段传递丢失
140
+ - **trace 树状展示**:enter/exit 配对 + 嵌套缩进
141
+
142
+ ---
143
+
144
+ ## 0.3.1 2026-05-22
145
+
146
+ ### Added
147
+ - **`auth.checkAid` handler**:本地证书自检(解析有效期、公钥)+ 远端注册状态查询;新增 `parseCertValidity` / `parseAsn1Time` ASN.1 时间解析
148
+ - **RPC trace 增强**:`RPCTransport` 增加 `setTraceMode()` / `setTraceObserver()`;`sortTraceSpansForDisplay` / `formatTraceTree` / `traceDisplay` 树状展示按 ts 排序 + 嵌套缩进;`TraceObserver` 类型导出
149
+ - **V2 群组 SPK 生命周期**:`V2KeyStore.saveGroupSPK` / `loadGroupSPK` / `loadCurrentGroupSPK`;`V2Session.ensureGroupRegistered` / `rotateGroupSPK` / `_publishGroupSPK`;`DESTROY_DELAY_MS = 7d`
150
+ - **V2 P2P push 解密**:`AUNClient._onV2PushNotification` / `_decryptV2PushMessage` 实现带 payload 的就地解密 + 失败回退到 pull
151
+
152
+ ### Changed
153
+ - **`SeqTracker.forceContiguousSeq`**:原 `contiguousSeq = minSeq` 跳过空洞(会丢消息),改为 `contiguousSeq = minSeq - 1` 由连续前缀自然推进,避免误丢
154
+
155
+ ### Fixed
156
+ - **`client.ts:4026` 类型错误**:`_publishOrderedMessage` `decrypted` 实参补 `as EventPayload` 断言(`Record<string, unknown>` 与 `JsonValue | Error` 不兼容)
157
+ - short RPC 请求增加 `debug` 完整报文日志,便于跨语言诊断
158
+
159
+ ---
160
+
161
+ ## 0.3.0 2026-05-21 ⚠️ BREAKING CHANGE
162
+
163
+ > **V2-only 版本**:移除全部 V1 E2EE(含群组加密),新增 V2 加密原语,API 不向后兼容。
164
+
165
+ ### BREAKING
166
+ - **移除 V1 E2EE 全部实现**:`GroupE2EEManager`、V1 epoch key 逻辑全部删除
167
+ - **移除 V1 群组加密测试**:`e2ee.test.ts`、`e2ee-group.test.ts`、`epoch-key-server.spec.ts`
168
+ - **E2EE 接口简化**:`e2ee.ts` 仅保留 V2 路径,V1 加解密方法不再可用
169
+ - **配置变更**:`AUNConfig` 移除 V1 相关配置项
170
+ - **KeyStore 重构**:`keystore/` 目录结构调整,`aid-db.ts` / `file.ts` 接口变更
171
+
172
+ ### Added
173
+ - **agent.md 主 API**:`AUNClient.publishAgentMd(path)` / `AUNClient.fetchAgentMd(aid?, savePath?)`
174
+ - **V2 加密原语**(跨语言 golden vector 一致性):ECDH P-256、HKDF-SHA256、AES-256-GCM、ECDSA-SHA256 RAW (RFC 6979)、1DH/3DH wrap_key、Recipients Sort + Merkle Digest、State Commitment
175
+
176
+ ### Removed
177
+ - `AUNClient.setLocalAgentMdPath()` / `getLocalAgentMdEtag()` / `getRemoteAgentMdEtag()` — 由主 API 自动维护
178
+
179
+ ### Deprecated
180
+ - `client.auth.signAgentMd` / `verifyAgentMd` / `uploadAgentMd` / `downloadAgentMd` 建议迁移到 `client.publishAgentMd` / `client.fetchAgentMd`
181
+
182
+ ---
183
+
184
+ ## 0.2.20 — 2026-05-18
185
+
186
+ ### Added
187
+ - **agent.md 版本一致性 API**:`AUNClient.setLocalAgentMdPath(path)` / `getLocalAgentMdEtag()` / `getRemoteAgentMdEtag()`。Node 用 `fs.readFileSync` + `crypto.createHash` 计算 etag,浏览器场景返回空串并 warn。SDK 自动从 RPC envelope `_meta.agent_md_etag` 提取服务端 etag,应用层订阅 `message.received` / `group.message_created` 等事件时 payload 多 `_agent_md.{local_etag, remote_etag}` 字段供版本比对。
188
+ - **`downloadAgentMd` 条件请求缓存**:内部维护 ETag/Last-Modified,未变化时返回上次缓存内容;外部 API 形态不变。
189
+ - **transport meta observer**:`RPCTransport.setMetaObserver(fn)` 透传 envelope `_meta`,observer 抛错被吞,不影响 RPC result。
190
+
191
+ ### Changed
192
+ - **RPC call 默认超时 10s → 35s**:与服务端 30s handler timeout 对齐,留 5s buffer。
193
+ - **multi-device 架构**:对端无 prekey 时 `_sendEncrypted` 直接抛错(`no registered device prekeys for ...`),不再降级到 `long_term_key`。
194
+
195
+ ### Docs
196
+ - 仓库根 `docs/`(agent.md 规范、protocol、SDK 手册)随 npm tarball 打包到 `_packed_docs/`,安装后可读。`.gitignore` 排除项(如内部测试指南)不进包。
197
+
198
+ ---