@hashgraphonline/standards-sdk 0.0.122 → 0.0.124

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 (53) hide show
  1. package/dist/cjs/hcs-10/sdk.d.ts +47 -3
  2. package/dist/cjs/hcs-10/sdk.d.ts.map +1 -1
  3. package/dist/cjs/hcs-10/types.d.ts +17 -0
  4. package/dist/cjs/hcs-10/types.d.ts.map +1 -1
  5. package/dist/cjs/hcs-11/mcp-server-builder.d.ts +4 -0
  6. package/dist/cjs/hcs-11/mcp-server-builder.d.ts.map +1 -1
  7. package/dist/cjs/hcs-11/types.d.ts +4 -0
  8. package/dist/cjs/hcs-11/types.d.ts.map +1 -1
  9. package/dist/cjs/{index-DjDDRcKz.cjs → index-ByrQ9sMv.cjs} +3 -3
  10. package/dist/cjs/index-ByrQ9sMv.cjs.map +1 -0
  11. package/dist/cjs/{index-CHar8dVv-BkACF223.cjs → index-CHar8dVv-C3O0C2Vj.cjs} +2 -2
  12. package/dist/cjs/{index-CHar8dVv-BkACF223.cjs.map → index-CHar8dVv-C3O0C2Vj.cjs.map} +1 -1
  13. package/dist/cjs/services/mirror-node.d.ts.map +1 -1
  14. package/dist/cjs/standards-sdk.cjs +1 -1
  15. package/dist/es/hcs-10/sdk.d.ts +47 -3
  16. package/dist/es/hcs-10/sdk.d.ts.map +1 -1
  17. package/dist/es/hcs-10/types.d.ts +17 -0
  18. package/dist/es/hcs-10/types.d.ts.map +1 -1
  19. package/dist/es/hcs-11/mcp-server-builder.d.ts +4 -0
  20. package/dist/es/hcs-11/mcp-server-builder.d.ts.map +1 -1
  21. package/dist/es/hcs-11/types.d.ts +4 -0
  22. package/dist/es/hcs-11/types.d.ts.map +1 -1
  23. package/dist/es/services/mirror-node.d.ts.map +1 -1
  24. package/dist/es/standards-sdk.es13.js +10 -0
  25. package/dist/es/standards-sdk.es13.js.map +1 -1
  26. package/dist/es/standards-sdk.es15.js.map +1 -1
  27. package/dist/es/standards-sdk.es23.js +2 -2
  28. package/dist/es/standards-sdk.es23.js.map +1 -1
  29. package/dist/es/standards-sdk.es26.js +1 -1
  30. package/dist/es/standards-sdk.es28.js +1 -1
  31. package/dist/es/standards-sdk.es29.js +1 -1
  32. package/dist/es/standards-sdk.es30.js +1 -1
  33. package/dist/es/standards-sdk.es31.js +1 -1
  34. package/dist/es/standards-sdk.es32.js +1 -1
  35. package/dist/es/standards-sdk.es34.js +7134 -41
  36. package/dist/es/standards-sdk.es34.js.map +1 -1
  37. package/dist/es/standards-sdk.es35.js +41 -7134
  38. package/dist/es/standards-sdk.es35.js.map +1 -1
  39. package/dist/es/standards-sdk.es7.js +575 -58
  40. package/dist/es/standards-sdk.es7.js.map +1 -1
  41. package/dist/umd/hcs-10/sdk.d.ts +47 -3
  42. package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
  43. package/dist/umd/hcs-10/types.d.ts +17 -0
  44. package/dist/umd/hcs-10/types.d.ts.map +1 -1
  45. package/dist/umd/hcs-11/mcp-server-builder.d.ts +4 -0
  46. package/dist/umd/hcs-11/mcp-server-builder.d.ts.map +1 -1
  47. package/dist/umd/hcs-11/types.d.ts +4 -0
  48. package/dist/umd/hcs-11/types.d.ts.map +1 -1
  49. package/dist/umd/services/mirror-node.d.ts.map +1 -1
  50. package/dist/umd/standards-sdk.umd.js +19 -19
  51. package/dist/umd/standards-sdk.umd.js.map +1 -1
  52. package/package.json +1 -1
  53. package/dist/cjs/index-DjDDRcKz.cjs.map +0 -1
@@ -175,77 +175,85 @@ class HCS10Client extends HCS10BaseClient {
175
175
  * @param existingState Optional existing state to resume from
176
176
  * @returns Object with topic IDs
177
177
  */
178
- async createAgent(builder, ttl = 60, existingState) {
178
+ async createAgent(builder, ttl = 60, existingState, progressCallback) {
179
179
  if (!this.keyType) {
180
180
  await this.initializeOperator();
181
181
  }
182
182
  const config = builder.build();
183
- let outboundTopicId = existingState?.outboundTopicId || "";
184
- let inboundTopicId = existingState?.inboundTopicId || "";
185
- let pfpTopicId = existingState?.pfpTopicId || config.existingPfpTopicId || "";
186
- let profileTopicId = existingState?.profileTopicId || "";
187
183
  const accountId = this.client.operatorAccountId?.toString();
188
184
  if (!accountId) {
189
185
  throw new Error("Failed to retrieve operator account ID");
190
186
  }
191
- if (!outboundTopicId) {
192
- const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
193
- ttl
194
- });
195
- outboundTopicId = await this.createTopic(outboundMemo, true, true);
196
- this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
197
- } else {
198
- this.logger.info(`Using existing outbound topic ID: ${outboundTopicId}`);
199
- }
200
- if (!inboundTopicId) {
201
- inboundTopicId = await this.createInboundTopic(
202
- accountId,
203
- config.inboundTopicType,
204
- ttl,
205
- config.inboundTopicType === InboundTopicType.FEE_BASED ? config.feeConfig : void 0
206
- );
207
- this.logger.info(`Created new inbound topic ID: ${inboundTopicId}`);
208
- } else {
209
- this.logger.info(`Using existing inbound topic ID: ${inboundTopicId}`);
210
- }
211
- if (!pfpTopicId && config.pfpBuffer && config.pfpBuffer.length > 0) {
212
- this.logger.info("Inscribing new profile picture");
213
- const pfpResult = await this.inscribePfp(
214
- config.pfpBuffer,
215
- config.pfpFileName
216
- );
217
- pfpTopicId = pfpResult.pfpTopicId;
218
- this.logger.info(
219
- `Profile picture inscribed with topic ID: ${pfpTopicId}`
220
- );
221
- } else if (pfpTopicId) {
222
- this.logger.info(
223
- `Using existing profile picture with topic ID: ${pfpTopicId}`
224
- );
225
- }
226
- if (!profileTopicId) {
187
+ const result = await this._createEntityTopics(
188
+ ttl,
189
+ {
190
+ outboundTopicId: existingState?.outboundTopicId || "",
191
+ inboundTopicId: existingState?.inboundTopicId || "",
192
+ pfpTopicId: existingState?.pfpTopicId || config.existingPfpTopicId || "",
193
+ profileTopicId: existingState?.profileTopicId || ""
194
+ },
195
+ accountId,
196
+ config.inboundTopicType,
197
+ config.feeConfig,
198
+ config.pfpBuffer,
199
+ config.pfpFileName,
200
+ progressCallback
201
+ );
202
+ if (!result.profileTopicId) {
203
+ if (progressCallback) {
204
+ progressCallback({
205
+ stage: "preparing",
206
+ message: "Creating agent profile",
207
+ progressPercent: 60,
208
+ details: {
209
+ outboundTopicId: result.outboundTopicId,
210
+ inboundTopicId: result.inboundTopicId,
211
+ pfpTopicId: result.pfpTopicId,
212
+ state: {
213
+ currentStage: "profile",
214
+ completedPercentage: 60
215
+ }
216
+ }
217
+ });
218
+ }
227
219
  const profileResult = await this.storeHCS11Profile(
228
220
  config.name,
229
221
  config.bio,
230
- inboundTopicId,
231
- outboundTopicId,
222
+ result.inboundTopicId,
223
+ result.outboundTopicId,
232
224
  config.capabilities,
233
225
  config.metadata,
234
- config.pfpBuffer && config.pfpBuffer.length > 0 && !pfpTopicId ? config.pfpBuffer : void 0,
226
+ config.pfpBuffer && config.pfpBuffer.length > 0 && !result.pfpTopicId ? config.pfpBuffer : void 0,
235
227
  config.pfpFileName,
236
- pfpTopicId
228
+ result.pfpTopicId
229
+ );
230
+ result.profileTopicId = profileResult.profileTopicId;
231
+ this.logger.info(
232
+ `Profile stored with topic ID: ${result.profileTopicId}`
237
233
  );
238
- profileTopicId = profileResult.profileTopicId;
239
- this.logger.info(`Profile stored with topic ID: ${profileTopicId}`);
234
+ if (progressCallback) {
235
+ progressCallback({
236
+ stage: "preparing",
237
+ message: "Agent profile created",
238
+ progressPercent: 70,
239
+ details: {
240
+ outboundTopicId: result.outboundTopicId,
241
+ inboundTopicId: result.inboundTopicId,
242
+ pfpTopicId: result.pfpTopicId,
243
+ profileTopicId: result.profileTopicId,
244
+ state: {
245
+ currentStage: "profile",
246
+ completedPercentage: 70
247
+ }
248
+ }
249
+ });
250
+ }
240
251
  } else {
241
- this.logger.info(`Using existing profile topic ID: ${profileTopicId}`);
252
+ this.logger.info(
253
+ `Using existing profile topic ID: ${result.profileTopicId}`
254
+ );
242
255
  }
243
- return {
244
- inboundTopicId,
245
- outboundTopicId,
246
- pfpTopicId,
247
- profileTopicId
248
- };
256
+ return result;
249
257
  }
250
258
  /**
251
259
  * Inscribes a profile picture to Hedera
@@ -875,13 +883,15 @@ class HCS10Client extends HCS10BaseClient {
875
883
  details: { state, account }
876
884
  });
877
885
  }
886
+ const keyType = this.keyType || detectKeyTypeFromString(account.privateKey);
887
+ const privateKey = keyType === "ed25519" ? PrivateKey.fromStringED25519(account.privateKey) : PrivateKey.fromStringECDSA(account.privateKey);
888
+ const publicKey = privateKey.publicKey.toString();
878
889
  agentClient = new HCS10Client({
879
890
  network: config.network,
880
891
  operatorId: account.accountId,
881
892
  operatorPrivateKey: account.privateKey,
882
- operatorPublicKey: PrivateKey.fromString(
883
- account.privateKey
884
- ).publicKey.toString(),
893
+ operatorPublicKey: publicKey,
894
+ keyType: keyType === "ed25519" ? "ed25519" : "ecdsa",
885
895
  logLevel: "info",
886
896
  guardedRegistryBaseUrl: baseUrl
887
897
  });
@@ -904,7 +914,23 @@ class HCS10Client extends HCS10BaseClient {
904
914
  const createResult = await agentClient.createAgent(
905
915
  builder,
906
916
  60,
907
- state
917
+ state,
918
+ (data) => {
919
+ if (progressCallback) {
920
+ progressCallback({
921
+ stage: data.stage,
922
+ message: data.message,
923
+ progressPercent: data.progressPercent || 0,
924
+ details: {
925
+ ...data.details,
926
+ state: {
927
+ ...state,
928
+ ...data.details?.state
929
+ }
930
+ }
931
+ });
932
+ }
933
+ }
908
934
  );
909
935
  outboundTopicId = createResult.outboundTopicId;
910
936
  inboundTopicId = createResult.inboundTopicId;
@@ -1336,6 +1362,497 @@ class HCS10Client extends HCS10BaseClient {
1336
1362
  receipt
1337
1363
  };
1338
1364
  }
1365
+ /**
1366
+ * Creates a new MCP server with inbound and outbound topics.
1367
+ *
1368
+ * This method creates communication topics and profiles required for an MCP server,
1369
+ * registers the profile with the server's account, and handles profile picture
1370
+ * inscriptions if provided.
1371
+ *
1372
+ * @param builder The MCP server builder object
1373
+ * @param ttl Optional Time-To-Live for the topic memos, defaults to 60
1374
+ * @param existingState Optional existing state to resume from
1375
+ * @returns Object with topic IDs
1376
+ */
1377
+ async createMCPServer(builder, ttl = 60, existingState, progressCallback) {
1378
+ if (!this.keyType) {
1379
+ await this.initializeOperator();
1380
+ }
1381
+ const config = builder.build();
1382
+ const accountId = this.client.operatorAccountId?.toString();
1383
+ if (!accountId) {
1384
+ throw new Error("Failed to retrieve operator account ID");
1385
+ }
1386
+ const result = await this._createEntityTopics(
1387
+ ttl,
1388
+ {
1389
+ outboundTopicId: existingState?.outboundTopicId || "",
1390
+ inboundTopicId: existingState?.inboundTopicId || "",
1391
+ pfpTopicId: existingState?.pfpTopicId || config.existingPfpTopicId || "",
1392
+ profileTopicId: existingState?.profileTopicId || ""
1393
+ },
1394
+ accountId,
1395
+ InboundTopicType.PUBLIC,
1396
+ void 0,
1397
+ config.pfpBuffer,
1398
+ config.pfpFileName,
1399
+ progressCallback
1400
+ );
1401
+ if (!result.profileTopicId) {
1402
+ this.logger.info("Creating and storing HCS-11 MCP server profile");
1403
+ if (progressCallback) {
1404
+ progressCallback({
1405
+ stage: "preparing",
1406
+ message: "Creating MCP server profile",
1407
+ progressPercent: 60,
1408
+ details: {
1409
+ outboundTopicId: result.outboundTopicId,
1410
+ inboundTopicId: result.inboundTopicId,
1411
+ pfpTopicId: result.pfpTopicId,
1412
+ state: {
1413
+ currentStage: "profile",
1414
+ completedPercentage: 60
1415
+ }
1416
+ }
1417
+ });
1418
+ }
1419
+ await this.hcs11Client.initializeOperator();
1420
+ const profile = this.hcs11Client.createMCPServerProfile(
1421
+ config.name,
1422
+ config.mcpServer,
1423
+ {
1424
+ alias: config.alias,
1425
+ bio: config.bio,
1426
+ socials: config.socials || [],
1427
+ inboundTopicId: result.inboundTopicId,
1428
+ outboundTopicId: result.outboundTopicId,
1429
+ profileImage: result.pfpTopicId ? `hcs://1/${result.pfpTopicId}` : void 0
1430
+ }
1431
+ );
1432
+ const profileResult = await this.hcs11Client.inscribeProfile(profile);
1433
+ if (!profileResult.success) {
1434
+ this.logger.error(
1435
+ `Failed to inscribe MCP server profile: ${profileResult.error}`
1436
+ );
1437
+ throw new Error(
1438
+ profileResult.error || "Failed to inscribe MCP server profile"
1439
+ );
1440
+ }
1441
+ result.profileTopicId = profileResult.profileTopicId;
1442
+ this.logger.info(
1443
+ `MCP server profile stored with topic ID: ${result.profileTopicId}`
1444
+ );
1445
+ const memoResult = await this.hcs11Client.updateAccountMemoWithProfile(
1446
+ accountId,
1447
+ result.profileTopicId
1448
+ );
1449
+ if (!memoResult.success) {
1450
+ this.logger.warn(
1451
+ `Failed to update account memo: ${memoResult.error}, but continuing with MCP server creation`
1452
+ );
1453
+ } else {
1454
+ this.logger.info(`Updated account memo with profile reference`);
1455
+ }
1456
+ if (progressCallback) {
1457
+ progressCallback({
1458
+ stage: "preparing",
1459
+ message: "MCP server profile created",
1460
+ progressPercent: 70,
1461
+ details: {
1462
+ outboundTopicId: result.outboundTopicId,
1463
+ inboundTopicId: result.inboundTopicId,
1464
+ pfpTopicId: result.pfpTopicId,
1465
+ profileTopicId: result.profileTopicId,
1466
+ state: {
1467
+ currentStage: "profile",
1468
+ completedPercentage: 70
1469
+ }
1470
+ }
1471
+ });
1472
+ }
1473
+ } else {
1474
+ this.logger.info(
1475
+ `Using existing profile topic ID: ${result.profileTopicId}`
1476
+ );
1477
+ }
1478
+ return result;
1479
+ }
1480
+ /**
1481
+ * Creates the base topic structure for an entity (agent or MCP server).
1482
+ *
1483
+ * @param ttl Time-To-Live for topic memos
1484
+ * @param existingTopics Object containing any existing topic IDs to reuse
1485
+ * @param accountId The account ID associated with the entity
1486
+ * @param inboundTopicType Type of inbound topic
1487
+ * @param feeConfig Optional fee configuration for fee-based topics
1488
+ * @param pfpBuffer Optional profile picture buffer
1489
+ * @param pfpFileName Optional profile picture filename
1490
+ * @param progressCallback Optional callback for reporting progress
1491
+ * @returns Object with created topic IDs
1492
+ */
1493
+ async _createEntityTopics(ttl, existingTopics, accountId, inboundTopicType, feeConfig, pfpBuffer, pfpFileName, progressCallback) {
1494
+ let { outboundTopicId, inboundTopicId, pfpTopicId, profileTopicId } = existingTopics;
1495
+ if (!outboundTopicId) {
1496
+ const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
1497
+ ttl
1498
+ });
1499
+ outboundTopicId = await this.createTopic(outboundMemo, true, true);
1500
+ this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
1501
+ if (progressCallback) {
1502
+ progressCallback({
1503
+ stage: "preparing",
1504
+ message: "Created outbound topic",
1505
+ progressPercent: 30,
1506
+ details: {
1507
+ outboundTopicId,
1508
+ state: {
1509
+ currentStage: "topics",
1510
+ completedPercentage: 30
1511
+ }
1512
+ }
1513
+ });
1514
+ }
1515
+ } else {
1516
+ this.logger.info(`Using existing outbound topic ID: ${outboundTopicId}`);
1517
+ }
1518
+ if (!inboundTopicId) {
1519
+ inboundTopicId = await this.createInboundTopic(
1520
+ accountId,
1521
+ inboundTopicType,
1522
+ ttl,
1523
+ inboundTopicType === InboundTopicType.FEE_BASED ? feeConfig : void 0
1524
+ );
1525
+ this.logger.info(`Created new inbound topic ID: ${inboundTopicId}`);
1526
+ if (progressCallback) {
1527
+ progressCallback({
1528
+ stage: "preparing",
1529
+ message: "Created inbound topic",
1530
+ progressPercent: 40,
1531
+ details: {
1532
+ outboundTopicId,
1533
+ inboundTopicId,
1534
+ state: {
1535
+ currentStage: "topics",
1536
+ completedPercentage: 40
1537
+ }
1538
+ }
1539
+ });
1540
+ }
1541
+ } else {
1542
+ this.logger.info(`Using existing inbound topic ID: ${inboundTopicId}`);
1543
+ }
1544
+ if (!pfpTopicId && pfpBuffer && pfpBuffer.length > 0 && pfpFileName) {
1545
+ this.logger.info("Inscribing new profile picture");
1546
+ if (progressCallback) {
1547
+ progressCallback({
1548
+ stage: "preparing",
1549
+ message: "Inscribing profile picture",
1550
+ progressPercent: 50,
1551
+ details: {
1552
+ outboundTopicId,
1553
+ inboundTopicId,
1554
+ state: {
1555
+ currentStage: "pfp",
1556
+ completedPercentage: 50
1557
+ }
1558
+ }
1559
+ });
1560
+ }
1561
+ const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
1562
+ pfpTopicId = pfpResult.pfpTopicId;
1563
+ this.logger.info(
1564
+ `Profile picture inscribed with topic ID: ${pfpTopicId}`
1565
+ );
1566
+ if (progressCallback) {
1567
+ progressCallback({
1568
+ stage: "preparing",
1569
+ message: "Profile picture inscribed",
1570
+ progressPercent: 55,
1571
+ details: {
1572
+ outboundTopicId,
1573
+ inboundTopicId,
1574
+ pfpTopicId,
1575
+ state: {
1576
+ currentStage: "pfp",
1577
+ completedPercentage: 55
1578
+ }
1579
+ }
1580
+ });
1581
+ }
1582
+ } else if (pfpTopicId) {
1583
+ this.logger.info(
1584
+ `Using existing profile picture with topic ID: ${pfpTopicId}`
1585
+ );
1586
+ }
1587
+ return {
1588
+ inboundTopicId,
1589
+ outboundTopicId,
1590
+ pfpTopicId,
1591
+ profileTopicId
1592
+ };
1593
+ }
1594
+ /**
1595
+ * Creates and registers an MCP server with a Guarded registry.
1596
+ *
1597
+ * This function creates a new account if needed, initializes an HCS10 client,
1598
+ * creates an MCP server with inbound and outbound topics, and registers
1599
+ * it with the Hashgraph Online Guarded Registry.
1600
+ *
1601
+ * @param builder The MCP server builder object with configuration
1602
+ * @param options Optional settings for registration process
1603
+ * @returns Registration result with success status and metadata
1604
+ */
1605
+ async createAndRegisterMCPServer(builder, options) {
1606
+ try {
1607
+ const config = builder.build();
1608
+ const progressCallback = options?.progressCallback;
1609
+ const baseUrl = options?.baseUrl || this.guardedRegistryBaseUrl;
1610
+ let state = options?.existingState || {
1611
+ currentStage: "init",
1612
+ completedPercentage: 0,
1613
+ createdResources: []
1614
+ };
1615
+ state.serverMetadata = {
1616
+ name: config.name,
1617
+ description: config.mcpServer.description,
1618
+ services: config.mcpServer.services
1619
+ };
1620
+ if (progressCallback) {
1621
+ progressCallback({
1622
+ stage: "preparing",
1623
+ message: "Starting MCP server creation process",
1624
+ progressPercent: 0,
1625
+ details: { state }
1626
+ });
1627
+ }
1628
+ let account = config.existingAccount;
1629
+ let serverClient;
1630
+ if (!state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
1631
+ if (!account) {
1632
+ if (state.createdResources && state.createdResources.some((r) => r.startsWith("account:"))) {
1633
+ const accountResource = state.createdResources.find(
1634
+ (r) => r.startsWith("account:")
1635
+ );
1636
+ const existingAccountId = accountResource?.split(":")[1];
1637
+ if (existingAccountId && config.existingAccount) {
1638
+ account = config.existingAccount;
1639
+ this.logger.info(
1640
+ `Resuming with existing account: ${existingAccountId}`
1641
+ );
1642
+ } else {
1643
+ account = await this.createAccount(options?.initialBalance);
1644
+ state.createdResources = state.createdResources || [];
1645
+ state.createdResources.push(`account:${account.accountId}`);
1646
+ }
1647
+ } else {
1648
+ account = await this.createAccount(options?.initialBalance);
1649
+ state.createdResources = state.createdResources || [];
1650
+ state.createdResources.push(`account:${account.accountId}`);
1651
+ }
1652
+ }
1653
+ if (progressCallback) {
1654
+ progressCallback({
1655
+ stage: "preparing",
1656
+ message: "Created account or using existing account",
1657
+ progressPercent: 20,
1658
+ details: { state, account }
1659
+ });
1660
+ }
1661
+ const keyType = this.keyType || detectKeyTypeFromString(account.privateKey);
1662
+ const privateKey = keyType === "ed25519" ? PrivateKey.fromStringED25519(account.privateKey) : PrivateKey.fromStringECDSA(account.privateKey);
1663
+ const publicKey = privateKey.publicKey.toString();
1664
+ serverClient = new HCS10Client({
1665
+ network: config.network,
1666
+ operatorId: account.accountId,
1667
+ operatorPrivateKey: account.privateKey,
1668
+ operatorPublicKey: publicKey,
1669
+ logLevel: "info",
1670
+ guardedRegistryBaseUrl: baseUrl
1671
+ });
1672
+ if (progressCallback) {
1673
+ progressCallback({
1674
+ stage: "preparing",
1675
+ message: "Initialized MCP server client",
1676
+ progressPercent: 25,
1677
+ details: { state }
1678
+ });
1679
+ }
1680
+ let outboundTopicId = state.outboundTopicId;
1681
+ let inboundTopicId = state.inboundTopicId;
1682
+ let pfpTopicId = state.pfpTopicId;
1683
+ let profileTopicId = state.profileTopicId;
1684
+ if (!outboundTopicId || !inboundTopicId || !profileTopicId) {
1685
+ if (pfpTopicId) {
1686
+ builder.setExistingProfilePicture(pfpTopicId);
1687
+ }
1688
+ const createResult = await serverClient.createMCPServer(
1689
+ builder,
1690
+ 60,
1691
+ state,
1692
+ (data) => {
1693
+ if (progressCallback) {
1694
+ progressCallback({
1695
+ stage: data.stage,
1696
+ message: data.message,
1697
+ progressPercent: data.progressPercent || 0,
1698
+ details: {
1699
+ ...data.details,
1700
+ state: {
1701
+ ...state,
1702
+ ...data.details?.state
1703
+ }
1704
+ }
1705
+ });
1706
+ }
1707
+ }
1708
+ );
1709
+ outboundTopicId = createResult.outboundTopicId;
1710
+ inboundTopicId = createResult.inboundTopicId;
1711
+ pfpTopicId = createResult.pfpTopicId;
1712
+ profileTopicId = createResult.profileTopicId;
1713
+ state.outboundTopicId = outboundTopicId;
1714
+ state.inboundTopicId = inboundTopicId;
1715
+ state.pfpTopicId = pfpTopicId;
1716
+ state.profileTopicId = profileTopicId;
1717
+ if (!state.createdResources) {
1718
+ state.createdResources = [];
1719
+ }
1720
+ if (pfpTopicId && !state.createdResources.includes(`pfp:${pfpTopicId}`)) {
1721
+ state.createdResources.push(`pfp:${pfpTopicId}`);
1722
+ }
1723
+ if (!state.createdResources.includes(`inbound:${inboundTopicId}`)) {
1724
+ state.createdResources.push(`inbound:${inboundTopicId}`);
1725
+ }
1726
+ if (!state.createdResources.includes(`outbound:${outboundTopicId}`)) {
1727
+ state.createdResources.push(`outbound:${outboundTopicId}`);
1728
+ }
1729
+ if (!state.createdResources.includes(`profile:${profileTopicId}`)) {
1730
+ state.createdResources.push(`profile:${profileTopicId}`);
1731
+ }
1732
+ }
1733
+ state.currentStage = "profile";
1734
+ state.completedPercentage = 60;
1735
+ if (progressCallback) {
1736
+ progressCallback({
1737
+ stage: "submitting",
1738
+ message: "Created MCP server with topics and profile",
1739
+ progressPercent: 60,
1740
+ details: {
1741
+ state,
1742
+ outboundTopicId,
1743
+ inboundTopicId,
1744
+ pfpTopicId,
1745
+ profileTopicId
1746
+ }
1747
+ });
1748
+ }
1749
+ } else {
1750
+ account = account || config.existingAccount;
1751
+ if (!account) {
1752
+ throw new Error(
1753
+ "Cannot resume registration without account information"
1754
+ );
1755
+ }
1756
+ const keyType = this.keyType || detectKeyTypeFromString(account.privateKey);
1757
+ const privateKey = keyType === "ed25519" ? PrivateKey.fromStringED25519(account.privateKey) : PrivateKey.fromStringECDSA(account.privateKey);
1758
+ const publicKey = privateKey.publicKey.toString();
1759
+ serverClient = new HCS10Client({
1760
+ network: config.network,
1761
+ operatorId: account.accountId,
1762
+ operatorPrivateKey: account.privateKey,
1763
+ operatorPublicKey: publicKey,
1764
+ keyType: keyType === "ed25519" ? "ed25519" : "ecdsa",
1765
+ logLevel: "info",
1766
+ guardedRegistryBaseUrl: baseUrl
1767
+ });
1768
+ this.logger.info("Resuming registration with existing state", {
1769
+ inboundTopicId: state.inboundTopicId,
1770
+ outboundTopicId: state.outboundTopicId,
1771
+ profileTopicId: state.profileTopicId,
1772
+ pfpTopicId: state.pfpTopicId
1773
+ });
1774
+ }
1775
+ const operatorId = `${state.inboundTopicId}@${account.accountId}`;
1776
+ if (state.currentStage !== "complete" || !state.createdResources?.includes(
1777
+ `registration:${state.inboundTopicId}`
1778
+ )) {
1779
+ const registrationResult = await serverClient.registerAgentWithGuardedRegistry(
1780
+ account.accountId,
1781
+ config.network,
1782
+ {
1783
+ progressCallback: (data) => {
1784
+ const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
1785
+ if (progressCallback) {
1786
+ progressCallback({
1787
+ stage: data.stage,
1788
+ message: data.message,
1789
+ progressPercent: adjustedPercent,
1790
+ details: {
1791
+ ...data.details,
1792
+ outboundTopicId: state.outboundTopicId,
1793
+ inboundTopicId: state.inboundTopicId,
1794
+ pfpTopicId: state.pfpTopicId,
1795
+ profileTopicId: state.profileTopicId,
1796
+ operatorId,
1797
+ state: data.details?.state || state
1798
+ }
1799
+ });
1800
+ }
1801
+ },
1802
+ existingState: state
1803
+ }
1804
+ );
1805
+ if (!registrationResult.success) {
1806
+ return {
1807
+ ...registrationResult,
1808
+ state
1809
+ };
1810
+ }
1811
+ state = registrationResult.state || state;
1812
+ }
1813
+ if (progressCallback) {
1814
+ progressCallback({
1815
+ stage: "completed",
1816
+ message: "MCP server creation and registration complete",
1817
+ progressPercent: 100,
1818
+ details: {
1819
+ outboundTopicId: state.outboundTopicId,
1820
+ inboundTopicId: state.inboundTopicId,
1821
+ pfpTopicId: state.pfpTopicId,
1822
+ profileTopicId: state.profileTopicId,
1823
+ operatorId,
1824
+ state
1825
+ }
1826
+ });
1827
+ }
1828
+ return {
1829
+ success: true,
1830
+ state,
1831
+ metadata: {
1832
+ accountId: account.accountId,
1833
+ privateKey: account.privateKey,
1834
+ operatorId,
1835
+ inboundTopicId: state.inboundTopicId,
1836
+ outboundTopicId: state.outboundTopicId,
1837
+ profileTopicId: state.profileTopicId,
1838
+ pfpTopicId: state.pfpTopicId
1839
+ }
1840
+ };
1841
+ } catch (e) {
1842
+ const error = e;
1843
+ const logMessage = `Failed to create and register MCP server: ${error.message}`;
1844
+ this.logger.error(logMessage);
1845
+ return {
1846
+ error: error.message,
1847
+ success: false,
1848
+ state: options?.existingState || {
1849
+ currentStage: "init",
1850
+ completedPercentage: 0,
1851
+ error: error.message
1852
+ }
1853
+ };
1854
+ }
1855
+ }
1339
1856
  }
1340
1857
  export {
1341
1858
  HCS10Client