@hashgraphonline/standards-sdk 0.0.113 → 0.0.115

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 (135) hide show
  1. package/README.md +4 -2
  2. package/dist/cjs/hcs-10/base-client.d.ts +2 -0
  3. package/dist/cjs/hcs-10/base-client.d.ts.map +1 -1
  4. package/dist/cjs/hcs-10/browser.d.ts +2 -0
  5. package/dist/cjs/hcs-10/browser.d.ts.map +1 -1
  6. package/dist/cjs/hcs-10/connections-manager.d.ts +1 -0
  7. package/dist/cjs/hcs-10/connections-manager.d.ts.map +1 -1
  8. package/dist/cjs/hcs-10/errors.d.ts.map +1 -1
  9. package/dist/cjs/hcs-10/registrations.d.ts.map +1 -1
  10. package/dist/cjs/hcs-10/sdk.d.ts +2 -1
  11. package/dist/cjs/hcs-10/sdk.d.ts.map +1 -1
  12. package/dist/cjs/hcs-10/types.d.ts +2 -0
  13. package/dist/cjs/hcs-10/types.d.ts.map +1 -1
  14. package/dist/cjs/hcs-11/client.d.ts.map +1 -1
  15. package/dist/cjs/hcs-11/types.d.ts +1 -0
  16. package/dist/cjs/hcs-11/types.d.ts.map +1 -1
  17. package/dist/cjs/hcs-3/src/index.d.ts.map +1 -1
  18. package/dist/cjs/hcs-7/evm-bridge.d.ts.map +1 -1
  19. package/dist/cjs/hcs-7/redis-cache.d.ts.map +1 -1
  20. package/dist/cjs/hcs-7/wasm-bridge.d.ts.map +1 -1
  21. package/dist/cjs/{index-CHar8dVv-SclbHQNq.cjs → index-CHar8dVv-SvZhHmF3.cjs} +2 -2
  22. package/dist/cjs/{index-CHar8dVv-SclbHQNq.cjs.map → index-CHar8dVv-SvZhHmF3.cjs.map} +1 -1
  23. package/dist/cjs/index-CtGN9edr.cjs +11 -0
  24. package/dist/cjs/index-CtGN9edr.cjs.map +1 -0
  25. package/dist/cjs/services/mirror-node.d.ts +1 -1
  26. package/dist/cjs/services/mirror-node.d.ts.map +1 -1
  27. package/dist/cjs/standards-sdk.cjs +1 -1
  28. package/dist/cjs/utils/logger.d.ts +1 -1
  29. package/dist/cjs/utils/logger.d.ts.map +1 -1
  30. package/dist/cjs/utils/parsers/hts-parser.d.ts.map +1 -1
  31. package/dist/cjs/utils/parsers/scs-parser.d.ts.map +1 -1
  32. package/dist/cjs/utils/progress-reporter.d.ts.map +1 -1
  33. package/dist/cjs/utils/sleep.d.ts.map +1 -1
  34. package/dist/cjs/utils/transaction-parser-types.d.ts.map +1 -1
  35. package/dist/es/hcs-10/base-client.d.ts +2 -0
  36. package/dist/es/hcs-10/base-client.d.ts.map +1 -1
  37. package/dist/es/hcs-10/browser.d.ts +2 -0
  38. package/dist/es/hcs-10/browser.d.ts.map +1 -1
  39. package/dist/es/hcs-10/connections-manager.d.ts +1 -0
  40. package/dist/es/hcs-10/connections-manager.d.ts.map +1 -1
  41. package/dist/es/hcs-10/errors.d.ts.map +1 -1
  42. package/dist/es/hcs-10/registrations.d.ts.map +1 -1
  43. package/dist/es/hcs-10/sdk.d.ts +2 -1
  44. package/dist/es/hcs-10/sdk.d.ts.map +1 -1
  45. package/dist/es/hcs-10/types.d.ts +2 -0
  46. package/dist/es/hcs-10/types.d.ts.map +1 -1
  47. package/dist/es/hcs-11/client.d.ts.map +1 -1
  48. package/dist/es/hcs-11/types.d.ts +1 -0
  49. package/dist/es/hcs-11/types.d.ts.map +1 -1
  50. package/dist/es/hcs-3/src/index.d.ts.map +1 -1
  51. package/dist/es/hcs-7/evm-bridge.d.ts.map +1 -1
  52. package/dist/es/hcs-7/redis-cache.d.ts.map +1 -1
  53. package/dist/es/hcs-7/wasm-bridge.d.ts.map +1 -1
  54. package/dist/es/services/mirror-node.d.ts +1 -1
  55. package/dist/es/services/mirror-node.d.ts.map +1 -1
  56. package/dist/es/standards-sdk.es10.js +7 -16
  57. package/dist/es/standards-sdk.es10.js.map +1 -1
  58. package/dist/es/standards-sdk.es12.js.map +1 -1
  59. package/dist/es/standards-sdk.es13.js +5 -4
  60. package/dist/es/standards-sdk.es13.js.map +1 -1
  61. package/dist/es/standards-sdk.es14.js.map +1 -1
  62. package/dist/es/standards-sdk.es15.js +13 -3
  63. package/dist/es/standards-sdk.es15.js.map +1 -1
  64. package/dist/es/standards-sdk.es16.js.map +1 -1
  65. package/dist/es/standards-sdk.es17.js.map +1 -1
  66. package/dist/es/standards-sdk.es18.js.map +1 -1
  67. package/dist/es/standards-sdk.es19.js.map +1 -1
  68. package/dist/es/standards-sdk.es2.js +5 -1
  69. package/dist/es/standards-sdk.es2.js.map +1 -1
  70. package/dist/es/standards-sdk.es20.js.map +1 -1
  71. package/dist/es/standards-sdk.es21.js +9 -27
  72. package/dist/es/standards-sdk.es21.js.map +1 -1
  73. package/dist/es/standards-sdk.es22.js.map +1 -1
  74. package/dist/es/standards-sdk.es23.js.map +1 -1
  75. package/dist/es/standards-sdk.es25.js.map +1 -1
  76. package/dist/es/standards-sdk.es26.js.map +1 -1
  77. package/dist/es/standards-sdk.es27.js.map +1 -1
  78. package/dist/es/standards-sdk.es28.js.map +1 -1
  79. package/dist/es/standards-sdk.es29.js.map +1 -1
  80. package/dist/es/standards-sdk.es3.js +17 -9
  81. package/dist/es/standards-sdk.es3.js.map +1 -1
  82. package/dist/es/standards-sdk.es30.js.map +1 -1
  83. package/dist/es/standards-sdk.es31.js.map +1 -1
  84. package/dist/es/standards-sdk.es33.js.map +1 -1
  85. package/dist/es/standards-sdk.es4.js +4 -1
  86. package/dist/es/standards-sdk.es4.js.map +1 -1
  87. package/dist/es/standards-sdk.es5.js +4 -7
  88. package/dist/es/standards-sdk.es5.js.map +1 -1
  89. package/dist/es/standards-sdk.es6.js.map +1 -1
  90. package/dist/es/standards-sdk.es7.js +233 -114
  91. package/dist/es/standards-sdk.es7.js.map +1 -1
  92. package/dist/es/standards-sdk.es8.js +8 -9
  93. package/dist/es/standards-sdk.es8.js.map +1 -1
  94. package/dist/es/standards-sdk.es9.js +1 -3
  95. package/dist/es/standards-sdk.es9.js.map +1 -1
  96. package/dist/es/utils/logger.d.ts +1 -1
  97. package/dist/es/utils/logger.d.ts.map +1 -1
  98. package/dist/es/utils/parsers/hts-parser.d.ts.map +1 -1
  99. package/dist/es/utils/parsers/scs-parser.d.ts.map +1 -1
  100. package/dist/es/utils/progress-reporter.d.ts.map +1 -1
  101. package/dist/es/utils/sleep.d.ts.map +1 -1
  102. package/dist/es/utils/transaction-parser-types.d.ts.map +1 -1
  103. package/dist/umd/hcs-10/base-client.d.ts +2 -0
  104. package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
  105. package/dist/umd/hcs-10/browser.d.ts +2 -0
  106. package/dist/umd/hcs-10/browser.d.ts.map +1 -1
  107. package/dist/umd/hcs-10/connections-manager.d.ts +1 -0
  108. package/dist/umd/hcs-10/connections-manager.d.ts.map +1 -1
  109. package/dist/umd/hcs-10/errors.d.ts.map +1 -1
  110. package/dist/umd/hcs-10/registrations.d.ts.map +1 -1
  111. package/dist/umd/hcs-10/sdk.d.ts +2 -1
  112. package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
  113. package/dist/umd/hcs-10/types.d.ts +2 -0
  114. package/dist/umd/hcs-10/types.d.ts.map +1 -1
  115. package/dist/umd/hcs-11/client.d.ts.map +1 -1
  116. package/dist/umd/hcs-11/types.d.ts +1 -0
  117. package/dist/umd/hcs-11/types.d.ts.map +1 -1
  118. package/dist/umd/hcs-3/src/index.d.ts.map +1 -1
  119. package/dist/umd/hcs-7/evm-bridge.d.ts.map +1 -1
  120. package/dist/umd/hcs-7/redis-cache.d.ts.map +1 -1
  121. package/dist/umd/hcs-7/wasm-bridge.d.ts.map +1 -1
  122. package/dist/umd/services/mirror-node.d.ts +1 -1
  123. package/dist/umd/services/mirror-node.d.ts.map +1 -1
  124. package/dist/umd/standards-sdk.umd.js +6 -6
  125. package/dist/umd/standards-sdk.umd.js.map +1 -1
  126. package/dist/umd/utils/logger.d.ts +1 -1
  127. package/dist/umd/utils/logger.d.ts.map +1 -1
  128. package/dist/umd/utils/parsers/hts-parser.d.ts.map +1 -1
  129. package/dist/umd/utils/parsers/scs-parser.d.ts.map +1 -1
  130. package/dist/umd/utils/progress-reporter.d.ts.map +1 -1
  131. package/dist/umd/utils/sleep.d.ts.map +1 -1
  132. package/dist/umd/utils/transaction-parser-types.d.ts.map +1 -1
  133. package/package.json +10 -4
  134. package/dist/cjs/index-CcE0yY9g.cjs +0 -11
  135. package/dist/cjs/index-CcE0yY9g.cjs.map +0 -1
@@ -16,7 +16,8 @@ class HCS10Client extends HCS10BaseClient {
16
16
  logLevel: config.logLevel,
17
17
  prettyPrint: config.prettyPrint,
18
18
  feeAmount: config.feeAmount,
19
- mirrorNode: config.mirrorNode
19
+ mirrorNode: config.mirrorNode,
20
+ silent: config.silent
20
21
  });
21
22
  this.client = config.network === "mainnet" ? Client.forMainnet() : Client.forTestnet();
22
23
  this.operatorPrivateKey = PrivateKey.fromString(config.operatorPrivateKey);
@@ -27,7 +28,8 @@ class HCS10Client extends HCS10BaseClient {
27
28
  );
28
29
  this.logger = Logger.getInstance({
29
30
  level: config.logLevel || "info",
30
- module: "HCS-SDK"
31
+ module: "HCS-SDK",
32
+ silent: config.silent
31
33
  });
32
34
  this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://moonscape.tech";
33
35
  this.hcs11Client = new HCS11Client({
@@ -36,7 +38,8 @@ class HCS10Client extends HCS10BaseClient {
36
38
  operatorId: config.operatorId,
37
39
  privateKey: config.operatorPrivateKey
38
40
  },
39
- logLevel: config.logLevel
41
+ logLevel: config.logLevel,
42
+ silent: config.silent
40
43
  });
41
44
  }
42
45
  getClient() {
@@ -120,26 +123,39 @@ class HCS10Client extends HCS10BaseClient {
120
123
  * Creates a new agent with inbound and outbound topics
121
124
  * @param builder The agent builder object
122
125
  * @param ttl Optional Time-To-Live for the topic memos, defaults to 60
126
+ * @param existingState Optional existing state to resume from
123
127
  * @returns Object with topic IDs
124
128
  */
125
- async createAgent(builder, ttl = 60) {
129
+ async createAgent(builder, ttl = 60, existingState) {
126
130
  const config = builder.build();
127
- const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
128
- ttl
129
- });
130
- const outboundTopicId = await this.createTopic(outboundMemo, true, true);
131
- this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
131
+ let outboundTopicId = existingState?.outboundTopicId || "";
132
+ let inboundTopicId = existingState?.inboundTopicId || "";
133
+ let pfpTopicId = existingState?.pfpTopicId || config.existingPfpTopicId || "";
134
+ let profileTopicId = existingState?.profileTopicId || "";
132
135
  const accountId = this.client.operatorAccountId?.toString();
133
136
  if (!accountId) {
134
137
  throw new Error("Failed to retrieve operator account ID");
135
138
  }
136
- const inboundTopicId = await this.createInboundTopic(
137
- accountId,
138
- config.inboundTopicType,
139
- ttl,
140
- config.inboundTopicType === InboundTopicType.FEE_BASED ? config.feeConfig : void 0
141
- );
142
- let pfpTopicId = config.existingPfpTopicId || "";
139
+ if (!outboundTopicId) {
140
+ const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
141
+ ttl
142
+ });
143
+ outboundTopicId = await this.createTopic(outboundMemo, true, true);
144
+ this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
145
+ } else {
146
+ this.logger.info(`Using existing outbound topic ID: ${outboundTopicId}`);
147
+ }
148
+ if (!inboundTopicId) {
149
+ inboundTopicId = await this.createInboundTopic(
150
+ accountId,
151
+ config.inboundTopicType,
152
+ ttl,
153
+ config.inboundTopicType === InboundTopicType.FEE_BASED ? config.feeConfig : void 0
154
+ );
155
+ this.logger.info(`Created new inbound topic ID: ${inboundTopicId}`);
156
+ } else {
157
+ this.logger.info(`Using existing inbound topic ID: ${inboundTopicId}`);
158
+ }
143
159
  if (!pfpTopicId && config.pfpBuffer && config.pfpBuffer.length > 0) {
144
160
  this.logger.info("Inscribing new profile picture");
145
161
  const pfpResult = await this.inscribePfp(
@@ -150,24 +166,28 @@ class HCS10Client extends HCS10BaseClient {
150
166
  this.logger.info(
151
167
  `Profile picture inscribed with topic ID: ${pfpTopicId}`
152
168
  );
153
- } else if (config.existingPfpTopicId) {
169
+ } else if (pfpTopicId) {
154
170
  this.logger.info(
155
- `Using existing profile picture with topic ID: ${config.existingPfpTopicId}`
171
+ `Using existing profile picture with topic ID: ${pfpTopicId}`
156
172
  );
157
173
  }
158
- const profileResult = await this.storeHCS11Profile(
159
- config.name,
160
- config.bio,
161
- inboundTopicId,
162
- outboundTopicId,
163
- config.capabilities,
164
- config.metadata,
165
- config.pfpBuffer && config.pfpBuffer.length > 0 ? config.pfpBuffer : void 0,
166
- config.pfpFileName,
167
- config.existingPfpTopicId
168
- );
169
- const profileTopicId = profileResult.profileTopicId;
170
- this.logger.info(`Profile stored with topic ID: ${profileTopicId}`);
174
+ if (!profileTopicId) {
175
+ const profileResult = await this.storeHCS11Profile(
176
+ config.name,
177
+ config.bio,
178
+ inboundTopicId,
179
+ outboundTopicId,
180
+ config.capabilities,
181
+ config.metadata,
182
+ config.pfpBuffer && config.pfpBuffer.length > 0 && !pfpTopicId ? config.pfpBuffer : void 0,
183
+ config.pfpFileName,
184
+ pfpTopicId
185
+ );
186
+ profileTopicId = profileResult.profileTopicId;
187
+ this.logger.info(`Profile stored with topic ID: ${profileTopicId}`);
188
+ } else {
189
+ this.logger.info(`Using existing profile topic ID: ${profileTopicId}`);
190
+ }
171
191
  return {
172
192
  inboundTopicId,
173
193
  outboundTopicId,
@@ -440,9 +460,7 @@ class HCS10Client extends HCS10BaseClient {
440
460
  "Connection accepted. Looking forward to collaborating!"
441
461
  );
442
462
  const accountTopics = await this.retrieveCommunicationTopics(accountId);
443
- const requestingAccountTopics = await this.retrieveCommunicationTopics(
444
- requestingAccountId
445
- );
463
+ const requestingAccountTopics = await this.retrieveCommunicationTopics(requestingAccountId);
446
464
  const requestingAccountOperatorId = `${requestingAccountTopics.inboundTopic}@${requestingAccountId}`;
447
465
  await this.recordOutboundConnectionConfirmation({
448
466
  outboundTopicId: accountTopics.outboundTopic,
@@ -757,86 +775,181 @@ class HCS10Client extends HCS10BaseClient {
757
775
  const config = builder.build();
758
776
  const progressCallback = options?.progressCallback;
759
777
  const baseUrl = options?.baseUrl || this.guardedRegistryBaseUrl;
760
- let state = options?.existingState || void 0;
778
+ let state = options?.existingState || {
779
+ currentStage: "init",
780
+ completedPercentage: 0,
781
+ createdResources: []
782
+ };
783
+ state.agentMetadata = config.metadata;
761
784
  if (progressCallback) {
762
785
  progressCallback({
763
786
  stage: "preparing",
764
- message: "Preparing agent registration",
765
- progressPercent: 10,
787
+ message: "Starting agent creation process",
788
+ progressPercent: 0,
766
789
  details: { state }
767
790
  });
768
791
  }
769
- const account = config.existingAccount || await this.createAccount(options?.initialBalance);
770
- if (progressCallback) {
771
- progressCallback({
772
- stage: "preparing",
773
- message: "Created account or using existing account",
774
- progressPercent: 20,
775
- details: { state, account }
776
- });
777
- }
778
- const agentClient = new HCS10Client({
779
- network: config.network,
780
- operatorId: account.accountId,
781
- operatorPrivateKey: account.privateKey,
782
- operatorPublicKey: PrivateKey.fromString(
783
- account.privateKey
784
- ).publicKey.toString(),
785
- logLevel: "info",
786
- guardedRegistryBaseUrl: baseUrl
787
- });
788
- if (progressCallback) {
789
- progressCallback({
790
- stage: "preparing",
791
- message: "Initialized agent client",
792
- progressPercent: 30,
793
- details: { state }
792
+ let account = config.existingAccount;
793
+ let agentClient;
794
+ if (!state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
795
+ if (!account) {
796
+ if (state.createdResources && state.createdResources.some((r) => r.startsWith("account:"))) {
797
+ const accountResource = state.createdResources.find(
798
+ (r) => r.startsWith("account:")
799
+ );
800
+ const existingAccountId = accountResource?.split(":")[1];
801
+ if (existingAccountId && config.existingAccount) {
802
+ account = config.existingAccount;
803
+ this.logger.info(
804
+ `Resuming with existing account: ${existingAccountId}`
805
+ );
806
+ } else {
807
+ account = await this.createAccount(options?.initialBalance);
808
+ state.createdResources = state.createdResources || [];
809
+ state.createdResources.push(`account:${account.accountId}`);
810
+ }
811
+ } else {
812
+ account = await this.createAccount(options?.initialBalance);
813
+ state.createdResources = state.createdResources || [];
814
+ state.createdResources.push(`account:${account.accountId}`);
815
+ }
816
+ }
817
+ if (progressCallback) {
818
+ progressCallback({
819
+ stage: "preparing",
820
+ message: "Created account or using existing account",
821
+ progressPercent: 20,
822
+ details: { state, account }
823
+ });
824
+ }
825
+ agentClient = new HCS10Client({
826
+ network: config.network,
827
+ operatorId: account.accountId,
828
+ operatorPrivateKey: account.privateKey,
829
+ operatorPublicKey: PrivateKey.fromString(
830
+ account.privateKey
831
+ ).publicKey.toString(),
832
+ logLevel: "info",
833
+ guardedRegistryBaseUrl: baseUrl
794
834
  });
795
- }
796
- const { outboundTopicId, inboundTopicId, pfpTopicId, profileTopicId } = await agentClient.createAgent(builder);
797
- if (progressCallback) {
798
- progressCallback({
799
- stage: "submitting",
800
- message: "Created agent with topics and profile",
801
- progressPercent: 60,
802
- details: {
803
- state,
804
- outboundTopicId,
805
- inboundTopicId,
806
- pfpTopicId,
807
- profileTopicId
835
+ if (progressCallback) {
836
+ progressCallback({
837
+ stage: "preparing",
838
+ message: "Initialized agent client",
839
+ progressPercent: 25,
840
+ details: { state }
841
+ });
842
+ }
843
+ let outboundTopicId = state.outboundTopicId;
844
+ let inboundTopicId = state.inboundTopicId;
845
+ let pfpTopicId = state.pfpTopicId;
846
+ let profileTopicId = state.profileTopicId;
847
+ if (!outboundTopicId || !inboundTopicId || !profileTopicId) {
848
+ if (pfpTopicId) {
849
+ builder.setExistingProfilePicture(pfpTopicId);
808
850
  }
851
+ const createResult = await agentClient.createAgent(builder, 60, state);
852
+ outboundTopicId = createResult.outboundTopicId;
853
+ inboundTopicId = createResult.inboundTopicId;
854
+ pfpTopicId = createResult.pfpTopicId;
855
+ profileTopicId = createResult.profileTopicId;
856
+ state.outboundTopicId = outboundTopicId;
857
+ state.inboundTopicId = inboundTopicId;
858
+ state.pfpTopicId = pfpTopicId;
859
+ state.profileTopicId = profileTopicId;
860
+ if (!state.createdResources) {
861
+ state.createdResources = [];
862
+ }
863
+ if (pfpTopicId && !state.createdResources.includes(`pfp:${pfpTopicId}`)) {
864
+ state.createdResources.push(`pfp:${pfpTopicId}`);
865
+ }
866
+ if (!state.createdResources.includes(`inbound:${inboundTopicId}`)) {
867
+ state.createdResources.push(`inbound:${inboundTopicId}`);
868
+ }
869
+ if (!state.createdResources.includes(`outbound:${outboundTopicId}`)) {
870
+ state.createdResources.push(`outbound:${outboundTopicId}`);
871
+ }
872
+ if (!state.createdResources.includes(`profile:${profileTopicId}`)) {
873
+ state.createdResources.push(`profile:${profileTopicId}`);
874
+ }
875
+ }
876
+ state.currentStage = "profile";
877
+ state.completedPercentage = 60;
878
+ if (progressCallback) {
879
+ progressCallback({
880
+ stage: "submitting",
881
+ message: "Created agent with topics and profile",
882
+ progressPercent: 60,
883
+ details: {
884
+ state,
885
+ outboundTopicId,
886
+ inboundTopicId,
887
+ pfpTopicId,
888
+ profileTopicId
889
+ }
890
+ });
891
+ }
892
+ } else {
893
+ account = account || config.existingAccount;
894
+ if (!account) {
895
+ throw new Error(
896
+ "Cannot resume registration without account information"
897
+ );
898
+ }
899
+ agentClient = new HCS10Client({
900
+ network: config.network,
901
+ operatorId: account.accountId,
902
+ operatorPrivateKey: account.privateKey,
903
+ operatorPublicKey: PrivateKey.fromString(
904
+ account.privateKey
905
+ ).publicKey.toString(),
906
+ logLevel: "info",
907
+ guardedRegistryBaseUrl: baseUrl
908
+ });
909
+ this.logger.info("Resuming registration with existing state", {
910
+ inboundTopicId: state.inboundTopicId,
911
+ outboundTopicId: state.outboundTopicId,
912
+ profileTopicId: state.profileTopicId,
913
+ pfpTopicId: state.pfpTopicId
809
914
  });
810
915
  }
811
- const operatorId = `${inboundTopicId}@${account.accountId}`;
812
- const registrationResult = await agentClient.registerAgentWithGuardedRegistry(
813
- account.accountId,
814
- config.network,
815
- {
816
- progressCallback: (data) => {
817
- const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
818
- if (progressCallback) {
819
- progressCallback({
820
- stage: data.stage,
821
- message: data.message,
822
- progressPercent: adjustedPercent,
823
- details: {
824
- ...data.details,
825
- outboundTopicId,
826
- inboundTopicId,
827
- pfpTopicId,
828
- profileTopicId,
829
- operatorId,
830
- state: data.details?.state || state
831
- }
832
- });
833
- }
834
- },
835
- existingState: state
916
+ const operatorId = `${state.inboundTopicId}@${account.accountId}`;
917
+ if (state.currentStage !== "complete" || !state.createdResources?.includes(
918
+ `registration:${state.inboundTopicId}`
919
+ )) {
920
+ const registrationResult = await agentClient.registerAgentWithGuardedRegistry(
921
+ account.accountId,
922
+ config.network,
923
+ {
924
+ progressCallback: (data) => {
925
+ const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
926
+ if (progressCallback) {
927
+ progressCallback({
928
+ stage: data.stage,
929
+ message: data.message,
930
+ progressPercent: adjustedPercent,
931
+ details: {
932
+ ...data.details,
933
+ outboundTopicId: state.outboundTopicId,
934
+ inboundTopicId: state.inboundTopicId,
935
+ pfpTopicId: state.pfpTopicId,
936
+ profileTopicId: state.profileTopicId,
937
+ operatorId,
938
+ state: data.details?.state || state
939
+ }
940
+ });
941
+ }
942
+ },
943
+ existingState: state
944
+ }
945
+ );
946
+ if (!registrationResult.success) {
947
+ return {
948
+ ...registrationResult,
949
+ state
950
+ };
836
951
  }
837
- );
838
- if (!registrationResult.success) {
839
- return registrationResult;
952
+ state = registrationResult.state || state;
840
953
  }
841
954
  if (progressCallback) {
842
955
  progressCallback({
@@ -844,25 +957,26 @@ class HCS10Client extends HCS10BaseClient {
844
957
  message: "Agent creation and registration complete",
845
958
  progressPercent: 100,
846
959
  details: {
847
- outboundTopicId,
848
- inboundTopicId,
849
- pfpTopicId,
850
- profileTopicId,
960
+ outboundTopicId: state.outboundTopicId,
961
+ inboundTopicId: state.inboundTopicId,
962
+ pfpTopicId: state.pfpTopicId,
963
+ profileTopicId: state.profileTopicId,
851
964
  operatorId,
852
- state: registrationResult.state
965
+ state
853
966
  }
854
967
  });
855
968
  }
856
969
  return {
857
- ...registrationResult,
970
+ success: true,
971
+ state,
858
972
  metadata: {
859
973
  accountId: account.accountId,
860
974
  privateKey: account.privateKey,
861
975
  operatorId,
862
- inboundTopicId,
863
- outboundTopicId,
864
- profileTopicId,
865
- pfpTopicId
976
+ inboundTopicId: state.inboundTopicId,
977
+ outboundTopicId: state.outboundTopicId,
978
+ profileTopicId: state.profileTopicId,
979
+ pfpTopicId: state.pfpTopicId
866
980
  }
867
981
  };
868
982
  } catch (e) {
@@ -871,7 +985,12 @@ class HCS10Client extends HCS10BaseClient {
871
985
  this.logger.error(logMessage);
872
986
  return {
873
987
  error: error.message,
874
- success: false
988
+ success: false,
989
+ state: options?.existingState || {
990
+ currentStage: "init",
991
+ completedPercentage: 0,
992
+ error: error.message
993
+ }
875
994
  };
876
995
  }
877
996
  }