@agentunion/fastaun 0.5.16 → 0.5.17

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 (46) hide show
  1. package/CHANGELOG.md +311 -276
  2. package/_packed_docs/CHANGELOG.md +311 -276
  3. package/_packed_docs/INDEX.md +8 -2
  4. package/_packed_docs/KITE_DOCS_GUIDE.md +2 -0
  5. package/_packed_docs/agent.md/SCHEMA.md +15 -15
  6. package/_packed_docs/aun/345/210/206/345/270/203/345/274/217/346/265/213/350/257/225/350/277/220/350/241/214/346/214/207/345/215/227.md +1178 -1178
  7. package/_packed_docs/aun/346/265/213/350/257/225/350/277/220/350/241/214/346/214/207/345/215/227.md +1213 -1213
  8. package/_packed_docs/protocol/06-/346/234/215/345/212/241/345/215/217/350/256/256.md +58 -43
  9. package/_packed_docs/protocol/10-Group-/345/255/220/345/215/217/350/256/256.md +80 -17
  10. package/_packed_docs/sdk/06-API/346/211/213/345/206/214.md +27 -6
  11. package/_packed_docs/sdk/07-/351/224/231/350/257/257/345/244/204/347/220/206.md +7 -4
  12. package/_packed_docs/sdk/09-group-rpc-manual.md +167 -35
  13. package/_packed_docs/sdk/09-message-rpc-manual.md +72 -42
  14. package/_packed_docs/sdk/09-storage-rpc-manual.md +23 -14
  15. package/_packed_docs/sdk/AUN_DOCS_GUIDE.md +16 -12
  16. package/_packed_docs/sdk/INDEX.md +12 -12
  17. package/dist/agent-md.d.ts +2 -0
  18. package/dist/agent-md.js +7 -1
  19. package/dist/agent-md.js.map +1 -1
  20. package/dist/client/delivery.d.ts +17 -0
  21. package/dist/client/delivery.js +140 -12
  22. package/dist/client/delivery.js.map +1 -1
  23. package/dist/client/group-state.d.ts +4 -0
  24. package/dist/client/group-state.js +63 -0
  25. package/dist/client/group-state.js.map +1 -1
  26. package/dist/client/rpc-pipeline.js +22 -5
  27. package/dist/client/rpc-pipeline.js.map +1 -1
  28. package/dist/client/v2-e2ee.d.ts +10 -1
  29. package/dist/client/v2-e2ee.js +187 -36
  30. package/dist/client/v2-e2ee.js.map +1 -1
  31. package/dist/client.js +53 -12
  32. package/dist/client.js.map +1 -1
  33. package/dist/facades.d.ts +5 -0
  34. package/dist/facades.js +5 -0
  35. package/dist/facades.js.map +1 -1
  36. package/dist/group-fs.js +7 -5
  37. package/dist/group-fs.js.map +1 -1
  38. package/dist/storage/vfs.d.ts +1 -0
  39. package/dist/storage/vfs.js +61 -6
  40. package/dist/storage/vfs.js.map +1 -1
  41. package/dist/tools/cross-sdk-agent.js +31 -1
  42. package/dist/tools/cross-sdk-agent.js.map +1 -1
  43. package/dist/types.d.ts +16 -1
  44. package/dist/version.d.ts +1 -1
  45. package/dist/version.js +1 -1
  46. package/package.json +8 -8
package/dist/client.js CHANGED
@@ -207,7 +207,7 @@ const SIGNED_METHODS = new Set([
207
207
  'collab.tag.create', 'collab.tag.restore',
208
208
  'collab.tag.rm', 'collab.tag.prune',
209
209
  'group.commit_state',
210
- 'group.ban', 'group.unban',
210
+ 'group.ban', 'group.unban', 'group.block', 'group.unblock', 'group.report_status',
211
211
  'group.dissolve', 'group.suspend', 'group.resume',
212
212
  ]);
213
213
  function clampReconnectDelayMs(value, fallback, upper = RECONNECT_MAX_BASE_DELAY_MS) {
@@ -334,6 +334,7 @@ function createAgentMdManagerForRuntime(opts) {
334
334
  return new AgentMdManager({
335
335
  aunPath: opts.config().aunPath,
336
336
  verifySsl: opts.config().verifySsl,
337
+ onChanged: (aid) => opts.dispatcher().enqueue('agentmd.changed', aid),
337
338
  discoveryPort: opts.config().discoveryPort,
338
339
  uploadViaGatewayHost: true,
339
340
  logger: opts.logger(),
@@ -608,6 +609,7 @@ export class AUNClient {
608
609
  this._agentMdManager = createAgentMdManagerForRuntime({
609
610
  config: () => this._configModel,
610
611
  logger: () => this._logger.for('aun_core.agent_md'),
612
+ dispatcher: () => this._dispatcher,
611
613
  ownerAid: () => this._aid,
612
614
  currentAid: () => this._currentAid,
613
615
  gateway: {
@@ -893,6 +895,7 @@ export class AUNClient {
893
895
  this._agentMdManager = createAgentMdManagerForRuntime({
894
896
  config: () => this._configModel,
895
897
  logger: () => this._logger.for('aun_core.agent_md'),
898
+ dispatcher: () => this._dispatcher,
896
899
  ownerAid: () => this._aid,
897
900
  currentAid: () => this._currentAid,
898
901
  gateway: {
@@ -1111,14 +1114,22 @@ export class AUNClient {
1111
1114
  continue;
1112
1115
  const group = raw;
1113
1116
  const role = String(group.role ?? group.my_role ?? '').trim().toLowerCase();
1114
- if (role !== 'owner')
1115
- continue;
1116
1117
  const groupId = String(group.group_id ?? group.groupId ?? group.group_aid ?? group.groupAid ?? '').trim();
1117
1118
  const groupAid = String(group.group_aid ?? group.groupAid ?? groupId).trim();
1118
1119
  if (!groupId || !groupAid)
1119
1120
  continue;
1121
+ const keystore = store._keystore;
1122
+ const pendingTransfer = keystore && typeof keystore.loadPendingGroupBind === 'function'
1123
+ ? keystore.loadPendingGroupBind(`complete:${groupId}`)
1124
+ : null;
1125
+ if (role !== 'owner' && !pendingTransfer)
1126
+ continue;
1120
1127
  try {
1121
1128
  await this._runGroupIdentityOperation(groupId, async () => {
1129
+ if (pendingTransfer) {
1130
+ await this.completeGroupTransfer({ group_id: groupId, group_aid: groupAid }, { aidStore: store });
1131
+ return;
1132
+ }
1122
1133
  const loaded = store.load(groupAid);
1123
1134
  if (!loaded.ok || !loaded.data?.aid?.isPrivateKeyValid()) {
1124
1135
  await this.bindGroupAid({ group_id: groupId, group_aid: groupAid }, { aidStore: store });
@@ -1175,6 +1186,23 @@ export class AUNClient {
1175
1186
  if (!isNamed) {
1176
1187
  delete payload.public_key;
1177
1188
  delete payload.curve;
1189
+ const keystore = store._keystore;
1190
+ const pendingName = String(payload.name ?? '').trim().toLowerCase();
1191
+ const pendingKey = `create-anonymous:${crypto.createHash('sha256').update(pendingName, 'utf8').digest('hex')}`;
1192
+ let keyPair = null;
1193
+ if (keystore && typeof keystore.loadPendingGroupBind === 'function') {
1194
+ keyPair = keystore.loadPendingGroupBind(pendingKey);
1195
+ }
1196
+ if (!keyPair || !keyPair.public_key_der_b64 || !keyPair.private_key_pem) {
1197
+ keyPair = new CryptoProvider().generateIdentity();
1198
+ if (keystore && typeof keystore.savePendingGroupBind === 'function') {
1199
+ keystore.savePendingGroupBind(pendingKey, keyPair);
1200
+ }
1201
+ }
1202
+ if (!keyPair?.public_key_der_b64 || !keyPair.private_key_pem) {
1203
+ throw new ValidationError('createGroup: failed to generate or load key pair');
1204
+ }
1205
+ payload._create_request_id = `anon:${crypto.createHash('sha256').update(keyPair.public_key_der_b64, 'utf8').digest('hex')}`;
1178
1206
  const created = await this.call('group.create', payload);
1179
1207
  const createdMap = isJsonObject(created) ? created : {};
1180
1208
  const createdGroup = isJsonObject(createdMap.group) ? createdMap.group : {};
@@ -1182,6 +1210,9 @@ export class AUNClient {
1182
1210
  if (!groupId) {
1183
1211
  throw new ValidationError('group.create response missing group.group_id');
1184
1212
  }
1213
+ if (keystore && typeof keystore.savePendingGroupBind === 'function') {
1214
+ keystore.savePendingGroupBind(`bind:${groupId}`, keyPair);
1215
+ }
1185
1216
  const bindParams = { group_id: groupId };
1186
1217
  for (const key of ['name', 'description', 'group_description', 'avatar', 'group_agent_md', 'groupAgentMd', 'content']) {
1187
1218
  if (key in payload)
@@ -1193,15 +1224,28 @@ export class AUNClient {
1193
1224
  const result = { ...createdMap, ...boundMap, group: { ...createdGroup, ...boundGroup } };
1194
1225
  const postprocessParams = { ...payload };
1195
1226
  delete postprocessParams._defer_group_ready_postprocess;
1227
+ delete postprocessParams._create_request_id;
1196
1228
  const processed = await this._groupState.postprocessResult('group.create', postprocessParams, result);
1197
- return await this._inviteInitialGroupMembers(processed, groupId, initialMembers);
1229
+ const completed = await this._inviteInitialGroupMembers(processed, groupId, initialMembers);
1230
+ if (keystore && typeof keystore.clearPendingGroupBind === 'function') {
1231
+ keystore.clearPendingGroupBind(pendingKey);
1232
+ }
1233
+ return completed;
1198
1234
  }
1199
- const pendingKey = `create:${String(payload.group_name).trim().toLowerCase()}`;
1235
+ const groupName = String(payload.group_name).trim().toLowerCase();
1236
+ const pendingKey = `create:${groupName}`;
1200
1237
  const keystore = store._keystore;
1201
1238
  let keyPair = null;
1202
1239
  if (keystore && typeof keystore.loadPendingGroupBind === 'function') {
1203
1240
  keyPair = keystore.loadPendingGroupBind(pendingKey);
1204
1241
  }
1242
+ if ((!keyPair || !keyPair.public_key_der_b64 || !keyPair.private_key_pem)
1243
+ && keystore && typeof keystore.loadIdentity === 'function') {
1244
+ const ownerAid = String(this._aid ?? '').trim();
1245
+ const dot = ownerAid.indexOf('.');
1246
+ if (dot >= 0)
1247
+ keyPair = keystore.loadIdentity(`${groupName}.${ownerAid.slice(dot + 1).toLowerCase()}`);
1248
+ }
1205
1249
  if (!keyPair || !keyPair.public_key_der_b64 || !keyPair.private_key_pem) {
1206
1250
  keyPair = new CryptoProvider().generateIdentity();
1207
1251
  if (keystore && typeof keystore.savePendingGroupBind === 'function') {
@@ -3023,8 +3067,8 @@ export class AUNClient {
3023
3067
  return await this._v2E2EE.pullV2(afterSeq, limit, opts);
3024
3068
  }
3025
3069
  /** V2 P2P ack,并触发旧 SPK 销毁自检。 */
3026
- async _ackV2(upToSeq) {
3027
- return await this._v2E2EE.ackV2(upToSeq);
3070
+ async _ackV2(upToSeq, opts) {
3071
+ return await this._v2E2EE.ackV2(upToSeq, opts);
3028
3072
  }
3029
3073
  /** V2 Group 加密发送,推测性缓存失败后刷新 bootstrap 重试一次。 */
3030
3074
  async _sendGroupV2(groupId, payload, opts) {
@@ -3134,7 +3178,6 @@ export class AUNClient {
3134
3178
  seq: msg.seq,
3135
3179
  timestamp: (msg.t_server ?? msg.timestamp),
3136
3180
  device_id: String(msg.device_id ?? ''),
3137
- slot_id: String(msg.slot_id ?? ''),
3138
3181
  _decrypt_error: String(formatCaughtError(exc)),
3139
3182
  _decrypt_stage: 'spk_lookup',
3140
3183
  _envelope_type: String(envelope.type ?? ''),
@@ -3175,7 +3218,6 @@ export class AUNClient {
3175
3218
  seq: msg.seq,
3176
3219
  timestamp: (msg.t_server ?? msg.timestamp),
3177
3220
  device_id: String(msg.device_id ?? ''),
3178
- slot_id: String(msg.slot_id ?? ''),
3179
3221
  _decrypt_error: 'sender_ik_not_found',
3180
3222
  _decrypt_stage: 'sender_ik',
3181
3223
  _envelope_type: String(envelope.type ?? ''),
@@ -3205,7 +3247,6 @@ export class AUNClient {
3205
3247
  seq: msg.seq,
3206
3248
  timestamp: (msg.t_server ?? msg.timestamp),
3207
3249
  device_id: String(msg.device_id ?? ''),
3208
- slot_id: String(msg.slot_id ?? ''),
3209
3250
  _decrypt_error: String(formatCaughtError(exc)),
3210
3251
  _decrypt_stage: 'decrypt',
3211
3252
  _envelope_type: String(envelope.type ?? ''),
@@ -3235,12 +3276,12 @@ export class AUNClient {
3235
3276
  encrypted: true,
3236
3277
  e2ee,
3237
3278
  };
3279
+ if (senderDeviceId)
3280
+ result.sender_device_id = senderDeviceId;
3238
3281
  const explicitDirection = String(msg.direction ?? '').trim();
3239
3282
  result.direction = explicitDirection || (fromAid && fromAid === this._aid ? 'outbound_sync' : 'inbound');
3240
3283
  if (msg.device_id !== undefined)
3241
3284
  result.device_id = msg.device_id;
3242
- if (msg.slot_id !== undefined)
3243
- result.slot_id = msg.slot_id;
3244
3285
  attachGatewayProximity(result, msg);
3245
3286
  this._attachV2EnvelopeMetadata(result, e2ee);
3246
3287
  if (groupIdForKeys)