@agentunion/fastaun 0.5.28 → 0.5.29

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 (60) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/_packed_docs/CHANGELOG.md +19 -0
  3. package/_packed_docs/INDEX.md +9 -4
  4. package/_packed_docs/KITE_DOCS_GUIDE.md +4 -3
  5. package/_packed_docs/cli//345/207/255/350/257/201/344/270/216/347/273/204/347/273/207/346/234/215/345/212/241CLI/345/274/200/345/217/221/344/270/216/344/275/277/347/224/250/346/214/207/345/215/227.md +869 -0
  6. package/_packed_docs/sdk/0.5.27-SDK/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +408 -0
  7. package/_packed_docs/sdk/0.5.27-SDK/345/274/200/345/217/221/344/270/216/347/247/273/346/244/215/346/214/207/345/215/227.md +410 -0
  8. package/_packed_docs/sdk/0.5.28-SDK/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +228 -0
  9. package/_packed_docs/sdk/0.5.28-SDK/345/274/200/345/217/221/344/270/216/347/247/273/346/244/215/346/214/207/345/215/227.md +146 -0
  10. package/_packed_docs/sdk/0.5.29-SDK/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +180 -0
  11. package/_packed_docs/sdk/0.5.29-SDK/345/274/200/345/217/221/344/270/216/347/247/273/346/244/215/346/214/207/345/215/227.md +164 -0
  12. package/_packed_docs/sdk/09-/347/273/204/347/273/207/346/234/215/345/212/241RPC/346/211/213/345/206/214.md +90 -90
  13. package/_packed_docs/sdk/AUN_DOCS_GUIDE.md +5 -3
  14. package/_packed_docs/sdk/INDEX.md +12 -4
  15. package/_packed_docs/sdk//345/207/255/350/257/201/344/270/216/347/273/204/347/273/207/346/234/215/345/212/241SDK/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +1 -1
  16. package/_packed_docs/sdk//345/207/255/350/257/201/344/270/216/347/273/204/347/273/207/346/234/215/345/212/241SDK/345/274/200/345/217/221/344/270/216/347/247/273/346/244/215/346/214/207/345/215/227.md +1 -1
  17. package/_packed_docs//346/216/247/345/210/266/346/266/210/346/201/257/344/270/216/350/256/276/345/244/207/350/203/275/345/212/233/345/215/217/345/225/206/346/226/271/346/241/210.md +426 -0
  18. package/_packed_docs//346/266/210/346/201/257/345/220/214/346/255/245/344/270/216/345/216/206/345/217/262/346/213/211/345/217/226/344/273/243/347/240/201/345/256/241/346/237/245/351/227/256/351/242/230/346/270/205/345/215/225.md +279 -229
  19. package/_packed_docs//351/243/216/346/216/247/345/223/215/345/272/224/344/270/216SDK/345/215/217/345/220/214/346/226/271/346/241/210.md +381 -0
  20. package/dist/agent-md-changes.d.ts +2 -14
  21. package/dist/agent-md-changes.js +41 -212
  22. package/dist/agent-md-changes.js.map +1 -1
  23. package/dist/agent-md-schema.js +2 -2
  24. package/dist/agent-md-schema.js.map +1 -1
  25. package/dist/agent-md.d.ts +4 -6
  26. package/dist/agent-md.js +53 -53
  27. package/dist/agent-md.js.map +1 -1
  28. package/dist/aid-store.d.ts +3 -1
  29. package/dist/aid-store.js +61 -40
  30. package/dist/aid-store.js.map +1 -1
  31. package/dist/client/control-messages.js +28 -6
  32. package/dist/client/control-messages.js.map +1 -1
  33. package/dist/client/delivery.js +2 -1
  34. package/dist/client/delivery.js.map +1 -1
  35. package/dist/client/group-state.js +2 -3
  36. package/dist/client/group-state.js.map +1 -1
  37. package/dist/client/lifecycle.js +0 -2
  38. package/dist/client/lifecycle.js.map +1 -1
  39. package/dist/client/v2-e2ee.js +8 -4
  40. package/dist/client/v2-e2ee.js.map +1 -1
  41. package/dist/client.d.ts +2 -2
  42. package/dist/client.js +96 -46
  43. package/dist/client.js.map +1 -1
  44. package/dist/discovery.js +2 -1
  45. package/dist/discovery.js.map +1 -1
  46. package/dist/ownership-v21.d.ts +2 -1
  47. package/dist/ownership-v21.js +17 -3
  48. package/dist/ownership-v21.js.map +1 -1
  49. package/dist/ownership-workflow.js +9 -5
  50. package/dist/ownership-workflow.js.map +1 -1
  51. package/dist/semantic-facade.js +4 -2
  52. package/dist/semantic-facade.js.map +1 -1
  53. package/dist/semantic-protocol.js +2 -0
  54. package/dist/semantic-protocol.js.map +1 -1
  55. package/dist/tools/cross-sdk-agent.d.ts +1 -1
  56. package/dist/tools/cross-sdk-agent.js +16 -34
  57. package/dist/tools/cross-sdk-agent.js.map +1 -1
  58. package/dist/version.d.ts +1 -1
  59. package/dist/version.js +1 -1
  60. package/package.json +8 -8
package/dist/agent-md.js CHANGED
@@ -193,21 +193,6 @@ function requestText(url, opts) {
193
193
  });
194
194
  }
195
195
  export class AgentMdManager {
196
- static _commitListeners = new Map();
197
- static _commitRoot(aunPath) {
198
- const root = path.resolve(aunPath, 'AIDs');
199
- return process.platform === 'win32' ? root.toLowerCase() : root;
200
- }
201
- static subscribeCommits(aunPath, callback) {
202
- const root = this._commitRoot(aunPath), listeners = this._commitListeners.get(root) ?? new Set();
203
- listeners.add(callback);
204
- this._commitListeners.set(root, listeners);
205
- return () => {
206
- listeners.delete(callback);
207
- if (!listeners.size && this._commitListeners.get(root) === listeners)
208
- this._commitListeners.delete(root);
209
- };
210
- }
211
196
  _aunPath;
212
197
  _verifySsl;
213
198
  _log;
@@ -336,9 +321,6 @@ export class AgentMdManager {
336
321
  loadRecord(aid) {
337
322
  return this._loadRecord(aid);
338
323
  }
339
- listRecordedAids() {
340
- return fs.readdirSync(this.root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && fs.existsSync(path.join(this.root, entry.name, 'agentmd.json'))).map((entry) => this.safeAid(entry.name));
341
- }
342
324
  updateRecord(aid, change) {
343
325
  const target = this.safeAid(aid);
344
326
  this._withRecordLock(target, () => {
@@ -350,11 +332,24 @@ export class AgentMdManager {
350
332
  this._cache.delete(target);
351
333
  }
352
334
  setOnCommitted(callback) { this._onCommitted = callback; }
335
+ async _saveCommittedRecord(aid, fields, strict = false) {
336
+ const pending = this._loadRecord(aid, true)?.pending_agent_md_notice;
337
+ const saved = this._saveRecord(aid, fields, strict);
338
+ if (saved.aid && pending?.message_id && this._onCommitted) {
339
+ const notice = (Array.isArray(saved.agent_md_change_outbox) ? saved.agent_md_change_outbox : []).find((item) => item.message_id === pending.message_id);
340
+ if (notice) {
341
+ try {
342
+ await this._onCommitted(aid, notice);
343
+ }
344
+ catch { }
345
+ }
346
+ }
347
+ return saved;
348
+ }
353
349
  _saveRecord(aid, fields, strict = false, observation) {
354
350
  const target = String(aid ?? '').trim();
355
351
  if (!target)
356
352
  return {};
357
- let completedNotice = false;
358
353
  try {
359
354
  const inputFields = { ...fields };
360
355
  const hasContent = Object.prototype.hasOwnProperty.call(inputFields, 'content') && inputFields.content !== undefined && inputFields.content !== null;
@@ -369,7 +364,6 @@ export class AgentMdManager {
369
364
  outbox.push(notice);
370
365
  inputFields.agent_md_change_outbox = outbox;
371
366
  inputFields.pending_agent_md_notice = {};
372
- completedNotice = true;
373
367
  }
374
368
  if (observation && (this.root !== observation.root || String(next.remote_etag ?? '') !== observation.etag || Number(next.observation_version ?? 0) !== observation.version))
375
369
  throw ownershipFailure('unavailable', 'agent.md observation changed during download', true);
@@ -402,17 +396,6 @@ export class AgentMdManager {
402
396
  loaded.content = current.content;
403
397
  }
404
398
  this._cache.set(target, { ...loaded });
405
- if (completedNotice) {
406
- const listeners = new Set(AgentMdManager._commitListeners.get(AgentMdManager._commitRoot(this._aunPath)));
407
- if (this._onCommitted)
408
- listeners.add(this._onCommitted);
409
- for (const callback of listeners) {
410
- try {
411
- callback(target);
412
- }
413
- catch { }
414
- }
415
- }
416
399
  return { ...loaded };
417
400
  }
418
401
  catch (err) {
@@ -658,15 +641,15 @@ export class AgentMdManager {
658
641
  if (!identity || identity.aid !== aid || this._currentAid()?.aid !== aid || this._ownerAid() !== aid)
659
642
  throw ownershipFailure('forbidden', 'body recovery requires its current subject identity');
660
643
  await this._verifyDocument(pending.content, aid, identity, true, true);
661
- const remote = await this.readAgentMdFresh(aid);
662
- if (!remote.exists || !isDeepStrictEqual(legacyRelationship(meta), legacyRelationship(validateAgentMdReadDocument(remote.content, { expectedAid: aid }).frontmatter)))
663
- throw ownershipFailure('conflict', 'pending agent.md relationship material changed');
644
+ const remote = await this.readOwnershipFresh(aid);
645
+ if (remote.lock === 'locked' && (!remote.exists || !isDeepStrictEqual(legacyRelationship(meta), legacyRelationship(validateAgentMdReadDocument(remote.content, { expectedAid: aid }).frontmatter))))
646
+ throw ownershipFailure('conflict', 'locked agent.md relationship material must remain unchanged');
664
647
  if (remote.etag === pending.content_etag && remote.content === pending.content) {
665
- this.saveRecord(aid, { content: pending.content, remote_etag: remote.etag, pending_operation: '', pending_content: '', pending_content_etag: '', pending_error: '', pending_condition: {}, pending_relation: {}, pending_authorization: '' });
648
+ await this._saveCommittedRecord(aid, { content: pending.content, remote_etag: remote.etag, pending_operation: '', pending_content: '', pending_content_etag: '', pending_error: '', pending_condition: {}, pending_relation: {}, pending_authorization: '' });
666
649
  this._clearConfirmedDraft(aid, pending.content);
667
650
  return true;
668
651
  }
669
- if (!condition.if_match || remote.etag !== condition.if_match)
652
+ if (condition.if_match && (!remote.exists || remote.etag !== condition.if_match) || condition.if_none_match === '*' && remote.exists)
670
653
  throw ownershipFailure('conflict', 'pending agent.md original document condition changed');
671
654
  await this._uploadPrepared(aid, pending.content, identity, condition);
672
655
  return true;
@@ -689,7 +672,7 @@ export class AgentMdManager {
689
672
  await this._verifyDocument(pending.content, aid, identity, true);
690
673
  const remote = await this._readEntityFresh(aid);
691
674
  if (remote.exists && remote.content === pending.content && remote.etag === pending.content_etag) {
692
- const saved = this.saveRecord(aid, { content: pending.content, remote_etag: remote.etag, pending_operation: '', pending_content: '', pending_content_etag: '', pending_error: '', pending_condition: {}, pending_relation: {}, pending_authorization: '' });
675
+ const saved = await this._saveCommittedRecord(aid, { content: pending.content, remote_etag: remote.etag, pending_operation: '', pending_content: '', pending_content_etag: '', pending_error: '', pending_condition: {}, pending_relation: {}, pending_authorization: '' });
693
676
  if (!saved.aid)
694
677
  throw new StateError('agent.md pending completion persistence failed');
695
678
  this._clearConfirmedDraft(aid, pending.content);
@@ -713,9 +696,9 @@ export class AgentMdManager {
713
696
  throw new StateError('pending agent.md requires a signer identity');
714
697
  if (!multipleSignatures)
715
698
  verifyAgentMdBodyUpdate(pending.content, identity.certPem, aid);
716
- const remote = await this.readAgentMdFresh(aid);
699
+ const remote = await this.readOwnershipFresh(aid);
717
700
  if (remote.exists && remote.etag === pending.content_etag && remote.content === pending.content) {
718
- const saved = this.saveRecord(aid, { content: pending.content, remote_etag: remote.etag, pending_operation: '', pending_content: '', pending_content_etag: '', pending_error: '', pending_condition: {}, pending_relation: {}, pending_authorization: '' });
701
+ const saved = await this._saveCommittedRecord(aid, { content: pending.content, remote_etag: remote.etag, pending_operation: '', pending_content: '', pending_content_etag: '', pending_error: '', pending_condition: {}, pending_relation: {}, pending_authorization: '' });
719
702
  if (!saved.aid)
720
703
  throw new StateError('agent.md pending completion persistence failed');
721
704
  this._clearConfirmedDraft(aid, pending.content);
@@ -723,8 +706,8 @@ export class AgentMdManager {
723
706
  }
724
707
  if (condition.if_match && (!remote.exists || remote.etag !== condition.if_match) || condition.if_none_match === '*' && remote.exists)
725
708
  throw ownershipFailure('conflict', 'pending agent.md original document condition changed');
726
- if (remote.exists && legacyRelationship(validateAgentMdReadDocument(remote.content, { expectedAid: aid }).frontmatter))
727
- throw ownershipFailure('conflict', 'legacy relationship material cannot be removed or replaced');
709
+ if (remote.lock === 'locked' && remote.exists && legacyRelationship(validateAgentMdReadDocument(remote.content, { expectedAid: aid }).frontmatter))
710
+ throw ownershipFailure('conflict', 'locked agent.md relationship material must remain unchanged');
728
711
  await this._uploadPrepared(aid, pending.content, identity, condition);
729
712
  return true;
730
713
  }
@@ -746,19 +729,24 @@ export class AgentMdManager {
746
729
  let condition = originalCondition;
747
730
  let relation = entityContext ?? (this._pendingUpload(target, draftStrict))?.relation;
748
731
  if (!condition) {
749
- const fresh = entity ? await this._readEntityFresh(target) : legacy ? await this._readLegacyBodyBase(target) : await this.readAgentMdFresh(target);
732
+ const fresh = entity ? await this._readEntityFresh(target) : await this._readBodyOriginalFresh(target);
750
733
  condition = fresh.exists ? { if_match: fresh.etag } : { if_none_match: '*' };
751
734
  if (!entity) {
752
- if (legacy) {
753
- if (!fresh.exists || !fresh.etag || !isDeepStrictEqual(legacy, legacyRelationship(validateAgentMdReadDocument(fresh.content, { expectedAid: target }).frontmatter)))
754
- throw ownershipFailure('conflict', 'legacy relationship material must remain unchanged');
735
+ // 锁未知时按 locked 处理:关系字段必须与原件完全一致
736
+ const locked = 'lock' in fresh && fresh.lock !== 'unlocked';
737
+ const original = fresh.exists ? legacyRelationship(validateAgentMdReadDocument(fresh.content, { expectedAid: target }).frontmatter) : undefined;
738
+ if (locked && !isDeepStrictEqual(legacy, original))
739
+ throw ownershipFailure('conflict', 'locked agent.md relationship material must remain unchanged');
740
+ if (original)
741
+ await this._verifyLegacyBodyContent(target, fresh.content);
742
+ if (legacy && locked)
755
743
  relation = { legacy: true, base_content: fresh.content, base_content_etag: AgentMdManager.contentEtag(fresh.content), base_etag: fresh.etag, fields: legacy };
744
+ else if (legacy) {
745
+ const statement = parseOwnershipFile(signedContent, 'agent', { expectedSubAid: target }).statement;
746
+ relation = { relation_version: statement.relation_version, lock: 'unlocked', owner_aid: statement.owner_aid, statement };
756
747
  }
757
- else {
758
- if (fresh.exists && legacyRelationship(validateAgentMdReadDocument(fresh.content, { expectedAid: target }).frontmatter))
759
- throw ownershipFailure('conflict', 'legacy relationship material cannot be removed or replaced');
748
+ else
760
749
  relation = undefined;
761
- }
762
750
  }
763
751
  }
764
752
  const uploader = this._currentAid();
@@ -767,7 +755,8 @@ export class AgentMdManager {
767
755
  const ownership = isJsonObject(meta.ownership) ? meta.ownership : {};
768
756
  const statement = isJsonObject(ownership.statement) ? ownership.statement : {};
769
757
  const noticeOwner = String(statement.owner_aid ?? ownership.owner_aid ?? meta.owner ?? '').trim();
770
- const previousNotice = existing?.pending_content === signedContent && isJsonObject(existing.pending_agent_md_notice) ? existing.pending_agent_md_notice : null;
758
+ const previousNotice = existing?.pending_content === signedContent && isJsonObject(existing.pending_agent_md_notice) ? existing.pending_agent_md_notice
759
+ : (Array.isArray(existing?.agent_md_change_outbox) ? existing.agent_md_change_outbox : []).find((item) => item.aid === target && item.owner_aid === noticeOwner && item.sender_aid === (uploader?.aid ?? this._ownerAid()) && item.etag === AgentMdManager.contentEtag(signedContent));
771
760
  const notice = previousNotice ?? { sender_aid: uploader?.aid ?? this._ownerAid(), owner_aid: noticeOwner, aid: target, document_type: String(meta.type ?? 'agent'), message_id: crypto.randomUUID() };
772
761
  const pending = this._saveRecord(target, { pending_operation: 'replace', pending_target_aid: target, pending_content: signedContent, pending_content_etag: AgentMdManager.contentEtag(signedContent), pending_error: '', pending_condition: condition, pending_relation: relation, pending_authorization: entityAuthorization, pending_agent_md_notice: notice }, draftStrict);
773
762
  const savedCondition = pending.pending_condition;
@@ -781,7 +770,7 @@ export class AgentMdManager {
781
770
  const authorization = entity ? entityAuthorization : delegated ? this._ownerUploadAuthorization(target, signedContent, owner) : '';
782
771
  const result = await this._uploadHttp(target, signedContent, authorization, condition);
783
772
  const remoteEtag = String(result.etag ?? '').trim();
784
- const saved = this._saveRecord(target, {
773
+ const saved = await this._saveCommittedRecord(target, {
785
774
  content: signedContent, local_etag: AgentMdManager.contentEtag(signedContent), remote_etag: remoteEtag || undefined,
786
775
  last_modified: String(result.last_modified ?? result.lastModified ?? '').trim(), fetched_at: Date.now(), checked_at: Date.now(),
787
776
  remote_status: remoteEtag ? 'found' : 'unknown', last_error: '',
@@ -808,8 +797,19 @@ export class AgentMdManager {
808
797
  throw ownershipFailure('invalid', 'stored legacy agent.md signature is invalid');
809
798
  return parsed;
810
799
  }
800
+ // 普通正文更新先严格读取以取得 NS 锁;关系 invalid/unavailable 时不阻断,回落普通原件读取,锁未知
801
+ async _readBodyOriginalFresh(target) {
802
+ try {
803
+ return await this.readOwnershipFresh(target);
804
+ }
805
+ catch (error) {
806
+ if (!(error instanceof AUNError) || !['invalid', 'unavailable'].includes(error.stringCode))
807
+ throw error;
808
+ return { ...await this.readAgentMdFresh(target), lock: 'unknown' };
809
+ }
810
+ }
811
811
  async _readLegacyBodyBase(target) {
812
- const response = await this.readAgentMdFresh(target);
812
+ const response = await this._readBodyOriginalFresh(target);
813
813
  if (response.exists)
814
814
  await this._verifyLegacyBodyContent(target, response.content);
815
815
  return response;
@@ -832,7 +832,7 @@ export class AgentMdManager {
832
832
  if (!remote.exists)
833
833
  throw ownershipFailure('conflict', 'pending legacy agent.md original document is missing');
834
834
  if (remote.content === pending.content && remote.etag === pending.content_etag) {
835
- const saved = this.saveRecord(target, { content: pending.content, remote_etag: remote.etag, pending_operation: '', pending_content: '', pending_content_etag: '', pending_error: '', pending_condition: {}, pending_relation: {}, pending_authorization: '' });
835
+ const saved = await this._saveCommittedRecord(target, { content: pending.content, remote_etag: remote.etag, pending_operation: '', pending_content: '', pending_content_etag: '', pending_error: '', pending_condition: {}, pending_relation: {}, pending_authorization: '' });
836
836
  if (!saved.aid)
837
837
  throw new StateError('agent.md pending completion persistence failed');
838
838
  this._clearConfirmedDraft(target, pending.content);