@hashgraphonline/standards-sdk 0.0.19 → 0.0.20

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.
@@ -58,7 +58,7 @@ export declare class BrowserHCSClient extends HCS10BaseClient {
58
58
  result?: TransactionReceipt;
59
59
  error?: string;
60
60
  }>;
61
- createAgent(pfpBuffer: Buffer, pfpFileName: string, agentName: string, agentDescription: string, capabilities: number[], metadata: AgentMetadata): Promise<{
61
+ createAgent(pfpBuffer: Buffer, pfpFileName: string, agentName: string, agentDescription: string, capabilities: number[], metadata: AgentMetadata, existingPfpTopicId?: string): Promise<{
62
62
  outboundTopicId: string;
63
63
  inboundTopicId: string;
64
64
  pfpTopicId: string;
@@ -66,7 +66,7 @@ export declare class BrowserHCSClient extends HCS10BaseClient {
66
66
  error?: string;
67
67
  success: boolean;
68
68
  }>;
69
- createAndRegisterAgent(name: string, description: string, capabilities: number[], metadata: AgentMetadata, pfpBuffer: Buffer, pfpFileName: string, network: NetworkType): Promise<BrowserAgentConfig>;
69
+ createAndRegisterAgent(name: string, description: string, capabilities: number[], metadata: AgentMetadata, pfpBuffer: Buffer, pfpFileName: string, network: NetworkType, existingPfpTopicId?: string): Promise<BrowserAgentConfig>;
70
70
  registerAgentWithGuardedRegistry(accountId: string, inboundTopicId: string, network?: string, maxAttempts?: number, delayMs?: number): Promise<{
71
71
  error?: string;
72
72
  success: boolean;
@@ -75,7 +75,7 @@ export declare class BrowserHCSClient extends HCS10BaseClient {
75
75
  confirmed?: boolean;
76
76
  validationErrors?: any[];
77
77
  }>;
78
- storeHCS11Profile(agentName: string, agentDescription: string, inboundTopicId: string, outboundTopicId: string, capabilities?: number[], metadata?: Record<string, any>, pfpBuffer?: Buffer, pfpFileName?: string): Promise<{
78
+ storeHCS11Profile(agentName: string, agentDescription: string, inboundTopicId: string, outboundTopicId: string, capabilities?: number[], metadata?: Record<string, any>, pfpBuffer?: Buffer, pfpFileName?: string, existingPfpTopicId?: string): Promise<{
79
79
  profileTopicId: string;
80
80
  pfpTopicId?: string;
81
81
  error?: string;
@@ -33163,7 +33163,7 @@ class BrowserHCSClient extends HCS10BaseClient {
33163
33163
  };
33164
33164
  return await this.submitPayload(topicId, payload);
33165
33165
  }
33166
- async createAgent(pfpBuffer, pfpFileName, agentName, agentDescription, capabilities, metadata) {
33166
+ async createAgent(pfpBuffer, pfpFileName, agentName, agentDescription, capabilities, metadata, existingPfpTopicId) {
33167
33167
  try {
33168
33168
  const outboundTopicResult = await this.createTopic(
33169
33169
  "hcs-10:0:60:1",
@@ -33193,16 +33193,20 @@ class BrowserHCSClient extends HCS10BaseClient {
33193
33193
  success: false
33194
33194
  };
33195
33195
  }
33196
- const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
33197
- if (!pfpResult.success) {
33198
- return {
33199
- outboundTopicId: outboundTopicResult.topicId,
33200
- inboundTopicId: inboundTopicResult.topicId,
33201
- pfpTopicId: "",
33202
- profileTopicId: "",
33203
- error: pfpResult.error || "Failed to inscribe profile picture",
33204
- success: false
33205
- };
33196
+ let pfpTopicId = existingPfpTopicId;
33197
+ if (!pfpTopicId) {
33198
+ const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
33199
+ if (!pfpResult.success) {
33200
+ return {
33201
+ outboundTopicId: outboundTopicResult.topicId,
33202
+ inboundTopicId: inboundTopicResult.topicId,
33203
+ pfpTopicId: "",
33204
+ profileTopicId: "",
33205
+ error: pfpResult.error || "Failed to inscribe profile picture",
33206
+ success: false
33207
+ };
33208
+ }
33209
+ pfpTopicId = pfpResult.pfpTopicId;
33206
33210
  }
33207
33211
  const profileResult = await this.storeHCS11Profile(
33208
33212
  agentName,
@@ -33212,13 +33216,14 @@ class BrowserHCSClient extends HCS10BaseClient {
33212
33216
  capabilities,
33213
33217
  metadata,
33214
33218
  pfpBuffer,
33215
- pfpFileName
33219
+ pfpFileName,
33220
+ pfpTopicId
33216
33221
  );
33217
33222
  if (!profileResult.success) {
33218
33223
  return {
33219
33224
  outboundTopicId: outboundTopicResult.topicId,
33220
33225
  inboundTopicId: inboundTopicResult.topicId,
33221
- pfpTopicId: pfpResult.pfpTopicId,
33226
+ pfpTopicId: pfpTopicId || "",
33222
33227
  profileTopicId: "",
33223
33228
  error: profileResult.error || "Failed to store profile",
33224
33229
  success: false
@@ -33227,7 +33232,7 @@ class BrowserHCSClient extends HCS10BaseClient {
33227
33232
  return {
33228
33233
  outboundTopicId: outboundTopicResult.topicId,
33229
33234
  inboundTopicId: inboundTopicResult.topicId,
33230
- pfpTopicId: pfpResult.pfpTopicId,
33235
+ pfpTopicId: pfpTopicId || "",
33231
33236
  profileTopicId: profileResult.profileTopicId,
33232
33237
  success: true
33233
33238
  };
@@ -33242,41 +33247,43 @@ class BrowserHCSClient extends HCS10BaseClient {
33242
33247
  };
33243
33248
  }
33244
33249
  }
33245
- async createAndRegisterAgent(name, description, capabilities, metadata, pfpBuffer, pfpFileName, network) {
33246
- const { accountId } = this.getAccountAndSigner();
33247
- const {
33248
- outboundTopicId,
33249
- inboundTopicId,
33250
- pfpTopicId,
33251
- profileTopicId,
33252
- error,
33253
- success
33254
- } = await this.createAgent(
33255
- pfpBuffer,
33256
- pfpFileName,
33257
- name,
33258
- description,
33259
- capabilities,
33260
- metadata
33261
- );
33262
- if (!success || error) {
33263
- throw new Error(error || "Failed to create agent");
33250
+ async createAndRegisterAgent(name, description, capabilities, metadata, pfpBuffer, pfpFileName, network, existingPfpTopicId) {
33251
+ try {
33252
+ const agentResult = await this.createAgent(
33253
+ pfpBuffer,
33254
+ pfpFileName,
33255
+ name,
33256
+ description,
33257
+ capabilities,
33258
+ metadata,
33259
+ existingPfpTopicId
33260
+ );
33261
+ if (!agentResult.success) {
33262
+ throw new Error(agentResult.error || "Failed to create agent");
33263
+ }
33264
+ const { accountId } = this.getAccountAndSigner();
33265
+ const registrationResult = await this.registerAgentWithGuardedRegistry(
33266
+ accountId,
33267
+ agentResult.inboundTopicId,
33268
+ network
33269
+ );
33270
+ if (!registrationResult.success) {
33271
+ throw new Error(
33272
+ registrationResult.error || "Failed to register agent with registry"
33273
+ );
33274
+ }
33275
+ return {
33276
+ accountId,
33277
+ operatorId: `${agentResult.outboundTopicId}@${accountId}`,
33278
+ inboundTopicId: agentResult.inboundTopicId,
33279
+ outboundTopicId: agentResult.outboundTopicId,
33280
+ profileTopicId: agentResult.profileTopicId,
33281
+ pfpTopicId: agentResult.pfpTopicId,
33282
+ client: this
33283
+ };
33284
+ } catch (error) {
33285
+ throw new Error(`Failed to create and register agent: ${error.message}`);
33264
33286
  }
33265
- const operatorId = `${inboundTopicId}@${accountId}`;
33266
- await this.registerAgentWithGuardedRegistry(
33267
- accountId,
33268
- inboundTopicId,
33269
- network
33270
- );
33271
- return {
33272
- accountId,
33273
- operatorId,
33274
- inboundTopicId,
33275
- outboundTopicId,
33276
- profileTopicId,
33277
- pfpTopicId,
33278
- client: this
33279
- };
33280
33287
  }
33281
33288
  async registerAgentWithGuardedRegistry(accountId, inboundTopicId, network = this.network, maxAttempts = 60, delayMs = 2e3) {
33282
33289
  try {
@@ -33327,10 +33334,10 @@ class BrowserHCSClient extends HCS10BaseClient {
33327
33334
  };
33328
33335
  }
33329
33336
  }
33330
- async storeHCS11Profile(agentName, agentDescription, inboundTopicId, outboundTopicId, capabilities = [], metadata = {}, pfpBuffer, pfpFileName) {
33337
+ async storeHCS11Profile(agentName, agentDescription, inboundTopicId, outboundTopicId, capabilities = [], metadata = {}, pfpBuffer, pfpFileName, existingPfpTopicId) {
33331
33338
  try {
33332
- let pfpTopicId;
33333
- if (pfpBuffer && pfpFileName) {
33339
+ let pfpTopicId = existingPfpTopicId;
33340
+ if (!pfpTopicId && pfpBuffer && pfpFileName) {
33334
33341
  const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
33335
33342
  if (!pfpResult.success) {
33336
33343
  this.logger.error(