@agentunion/fastaun 0.5.15 → 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 (48) hide show
  1. package/CHANGELOG.md +311 -271
  2. package/_packed_docs/CHANGELOG.md +311 -271
  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 +7 -0
  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-schema.js +6 -0
  18. package/dist/agent-md-schema.js.map +1 -1
  19. package/dist/agent-md.d.ts +3 -0
  20. package/dist/agent-md.js +9 -1
  21. package/dist/agent-md.js.map +1 -1
  22. package/dist/client/delivery.d.ts +17 -0
  23. package/dist/client/delivery.js +140 -12
  24. package/dist/client/delivery.js.map +1 -1
  25. package/dist/client/group-state.d.ts +4 -0
  26. package/dist/client/group-state.js +63 -0
  27. package/dist/client/group-state.js.map +1 -1
  28. package/dist/client/rpc-pipeline.js +22 -5
  29. package/dist/client/rpc-pipeline.js.map +1 -1
  30. package/dist/client/v2-e2ee.d.ts +10 -1
  31. package/dist/client/v2-e2ee.js +187 -36
  32. package/dist/client/v2-e2ee.js.map +1 -1
  33. package/dist/client.js +56 -13
  34. package/dist/client.js.map +1 -1
  35. package/dist/facades.d.ts +5 -0
  36. package/dist/facades.js +5 -0
  37. package/dist/facades.js.map +1 -1
  38. package/dist/group-fs.js +7 -5
  39. package/dist/group-fs.js.map +1 -1
  40. package/dist/storage/vfs.d.ts +1 -0
  41. package/dist/storage/vfs.js +61 -6
  42. package/dist/storage/vfs.js.map +1 -1
  43. package/dist/tools/cross-sdk-agent.js +31 -1
  44. package/dist/tools/cross-sdk-agent.js.map +1 -1
  45. package/dist/types.d.ts +16 -1
  46. package/dist/version.d.ts +1 -1
  47. package/dist/version.js +1 -1
  48. 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,8 +1210,11 @@ 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
- for (const key of ['name', 'description', 'group_description', 'group_agent_md', 'groupAgentMd', 'content']) {
1217
+ for (const key of ['name', 'description', 'group_description', 'avatar', 'group_agent_md', 'groupAgentMd', 'content']) {
1187
1218
  if (key in payload)
1188
1219
  bindParams[key] = payload[key];
1189
1220
  }
@@ -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') {
@@ -1282,6 +1326,7 @@ export class AUNClient {
1282
1326
  const description = (value('description', 'group_description') || `AUN group ${name}`)
1283
1327
  .replace(/\s+/g, ' ')
1284
1328
  .slice(0, 100);
1329
+ const avatar = Array.from(value('avatar')).slice(0, 256).join('');
1285
1330
  return [
1286
1331
  '---',
1287
1332
  `aid: ${JSON.stringify(groupAid)}`,
@@ -1289,6 +1334,7 @@ export class AUNClient {
1289
1334
  'type: "group"',
1290
1335
  'version: "1.0.0"',
1291
1336
  `description: ${JSON.stringify(description)}`,
1337
+ ...(avatar ? [`avatar: ${JSON.stringify(avatar)}`] : []),
1292
1338
  '---',
1293
1339
  '',
1294
1340
  `# ${name}`,
@@ -3021,8 +3067,8 @@ export class AUNClient {
3021
3067
  return await this._v2E2EE.pullV2(afterSeq, limit, opts);
3022
3068
  }
3023
3069
  /** V2 P2P ack,并触发旧 SPK 销毁自检。 */
3024
- async _ackV2(upToSeq) {
3025
- return await this._v2E2EE.ackV2(upToSeq);
3070
+ async _ackV2(upToSeq, opts) {
3071
+ return await this._v2E2EE.ackV2(upToSeq, opts);
3026
3072
  }
3027
3073
  /** V2 Group 加密发送,推测性缓存失败后刷新 bootstrap 重试一次。 */
3028
3074
  async _sendGroupV2(groupId, payload, opts) {
@@ -3132,7 +3178,6 @@ export class AUNClient {
3132
3178
  seq: msg.seq,
3133
3179
  timestamp: (msg.t_server ?? msg.timestamp),
3134
3180
  device_id: String(msg.device_id ?? ''),
3135
- slot_id: String(msg.slot_id ?? ''),
3136
3181
  _decrypt_error: String(formatCaughtError(exc)),
3137
3182
  _decrypt_stage: 'spk_lookup',
3138
3183
  _envelope_type: String(envelope.type ?? ''),
@@ -3173,7 +3218,6 @@ export class AUNClient {
3173
3218
  seq: msg.seq,
3174
3219
  timestamp: (msg.t_server ?? msg.timestamp),
3175
3220
  device_id: String(msg.device_id ?? ''),
3176
- slot_id: String(msg.slot_id ?? ''),
3177
3221
  _decrypt_error: 'sender_ik_not_found',
3178
3222
  _decrypt_stage: 'sender_ik',
3179
3223
  _envelope_type: String(envelope.type ?? ''),
@@ -3203,7 +3247,6 @@ export class AUNClient {
3203
3247
  seq: msg.seq,
3204
3248
  timestamp: (msg.t_server ?? msg.timestamp),
3205
3249
  device_id: String(msg.device_id ?? ''),
3206
- slot_id: String(msg.slot_id ?? ''),
3207
3250
  _decrypt_error: String(formatCaughtError(exc)),
3208
3251
  _decrypt_stage: 'decrypt',
3209
3252
  _envelope_type: String(envelope.type ?? ''),
@@ -3233,12 +3276,12 @@ export class AUNClient {
3233
3276
  encrypted: true,
3234
3277
  e2ee,
3235
3278
  };
3279
+ if (senderDeviceId)
3280
+ result.sender_device_id = senderDeviceId;
3236
3281
  const explicitDirection = String(msg.direction ?? '').trim();
3237
3282
  result.direction = explicitDirection || (fromAid && fromAid === this._aid ? 'outbound_sync' : 'inbound');
3238
3283
  if (msg.device_id !== undefined)
3239
3284
  result.device_id = msg.device_id;
3240
- if (msg.slot_id !== undefined)
3241
- result.slot_id = msg.slot_id;
3242
3285
  attachGatewayProximity(result, msg);
3243
3286
  this._attachV2EnvelopeMetadata(result, e2ee);
3244
3287
  if (groupIdForKeys)