@hashgraphonline/standards-sdk 0.0.122 → 0.0.123

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-CHar8dVv-BkACF223.cjs → index-CHar8dVv-ZN8JTP7M.cjs} +2 -2
  10. package/dist/cjs/{index-CHar8dVv-BkACF223.cjs.map → index-CHar8dVv-ZN8JTP7M.cjs.map} +1 -1
  11. package/dist/cjs/{index-DjDDRcKz.cjs → index-Clbwco-g.cjs} +3 -3
  12. package/dist/cjs/index-Clbwco-g.cjs.map +1 -0
  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 +566 -55
  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
@@ -904,7 +912,23 @@ class HCS10Client extends HCS10BaseClient {
904
912
  const createResult = await agentClient.createAgent(
905
913
  builder,
906
914
  60,
907
- state
915
+ state,
916
+ (data) => {
917
+ if (progressCallback) {
918
+ progressCallback({
919
+ stage: data.stage,
920
+ message: data.message,
921
+ progressPercent: data.progressPercent || 0,
922
+ details: {
923
+ ...data.details,
924
+ state: {
925
+ ...state,
926
+ ...data.details?.state
927
+ }
928
+ }
929
+ });
930
+ }
931
+ }
908
932
  );
909
933
  outboundTopicId = createResult.outboundTopicId;
910
934
  inboundTopicId = createResult.inboundTopicId;
@@ -1336,6 +1360,493 @@ class HCS10Client extends HCS10BaseClient {
1336
1360
  receipt
1337
1361
  };
1338
1362
  }
1363
+ /**
1364
+ * Creates a new MCP server with inbound and outbound topics.
1365
+ *
1366
+ * This method creates communication topics and profiles required for an MCP server,
1367
+ * registers the profile with the server's account, and handles profile picture
1368
+ * inscriptions if provided.
1369
+ *
1370
+ * @param builder The MCP server builder object
1371
+ * @param ttl Optional Time-To-Live for the topic memos, defaults to 60
1372
+ * @param existingState Optional existing state to resume from
1373
+ * @returns Object with topic IDs
1374
+ */
1375
+ async createMCPServer(builder, ttl = 60, existingState, progressCallback) {
1376
+ if (!this.keyType) {
1377
+ await this.initializeOperator();
1378
+ }
1379
+ const config = builder.build();
1380
+ const accountId = this.client.operatorAccountId?.toString();
1381
+ if (!accountId) {
1382
+ throw new Error("Failed to retrieve operator account ID");
1383
+ }
1384
+ const result = await this._createEntityTopics(
1385
+ ttl,
1386
+ {
1387
+ outboundTopicId: existingState?.outboundTopicId || "",
1388
+ inboundTopicId: existingState?.inboundTopicId || "",
1389
+ pfpTopicId: existingState?.pfpTopicId || config.existingPfpTopicId || "",
1390
+ profileTopicId: existingState?.profileTopicId || ""
1391
+ },
1392
+ accountId,
1393
+ InboundTopicType.PUBLIC,
1394
+ void 0,
1395
+ config.pfpBuffer,
1396
+ config.pfpFileName,
1397
+ progressCallback
1398
+ );
1399
+ if (!result.profileTopicId) {
1400
+ this.logger.info("Creating and storing HCS-11 MCP server profile");
1401
+ if (progressCallback) {
1402
+ progressCallback({
1403
+ stage: "preparing",
1404
+ message: "Creating MCP server profile",
1405
+ progressPercent: 60,
1406
+ details: {
1407
+ outboundTopicId: result.outboundTopicId,
1408
+ inboundTopicId: result.inboundTopicId,
1409
+ pfpTopicId: result.pfpTopicId,
1410
+ state: {
1411
+ currentStage: "profile",
1412
+ completedPercentage: 60
1413
+ }
1414
+ }
1415
+ });
1416
+ }
1417
+ const profile = this.hcs11Client.createMCPServerProfile(
1418
+ config.name,
1419
+ config.mcpServer,
1420
+ {
1421
+ alias: config.alias,
1422
+ bio: config.bio,
1423
+ socials: config.socials || [],
1424
+ inboundTopicId: result.inboundTopicId,
1425
+ outboundTopicId: result.outboundTopicId,
1426
+ profileImage: result.pfpTopicId ? `hcs://1/${result.pfpTopicId}` : void 0
1427
+ }
1428
+ );
1429
+ const profileResult = await this.hcs11Client.inscribeProfile(profile);
1430
+ if (!profileResult.success) {
1431
+ this.logger.error(
1432
+ `Failed to inscribe MCP server profile: ${profileResult.error}`
1433
+ );
1434
+ throw new Error(
1435
+ profileResult.error || "Failed to inscribe MCP server profile"
1436
+ );
1437
+ }
1438
+ result.profileTopicId = profileResult.profileTopicId;
1439
+ this.logger.info(
1440
+ `MCP server profile stored with topic ID: ${result.profileTopicId}`
1441
+ );
1442
+ const memoResult = await this.hcs11Client.updateAccountMemoWithProfile(
1443
+ accountId,
1444
+ result.profileTopicId
1445
+ );
1446
+ if (!memoResult.success) {
1447
+ this.logger.warn(
1448
+ `Failed to update account memo: ${memoResult.error}, but continuing with MCP server creation`
1449
+ );
1450
+ } else {
1451
+ this.logger.info(`Updated account memo with profile reference`);
1452
+ }
1453
+ if (progressCallback) {
1454
+ progressCallback({
1455
+ stage: "preparing",
1456
+ message: "MCP server profile created",
1457
+ progressPercent: 70,
1458
+ details: {
1459
+ outboundTopicId: result.outboundTopicId,
1460
+ inboundTopicId: result.inboundTopicId,
1461
+ pfpTopicId: result.pfpTopicId,
1462
+ profileTopicId: result.profileTopicId,
1463
+ state: {
1464
+ currentStage: "profile",
1465
+ completedPercentage: 70
1466
+ }
1467
+ }
1468
+ });
1469
+ }
1470
+ } else {
1471
+ this.logger.info(
1472
+ `Using existing profile topic ID: ${result.profileTopicId}`
1473
+ );
1474
+ }
1475
+ return result;
1476
+ }
1477
+ /**
1478
+ * Creates the base topic structure for an entity (agent or MCP server).
1479
+ *
1480
+ * @param ttl Time-To-Live for topic memos
1481
+ * @param existingTopics Object containing any existing topic IDs to reuse
1482
+ * @param accountId The account ID associated with the entity
1483
+ * @param inboundTopicType Type of inbound topic
1484
+ * @param feeConfig Optional fee configuration for fee-based topics
1485
+ * @param pfpBuffer Optional profile picture buffer
1486
+ * @param pfpFileName Optional profile picture filename
1487
+ * @param progressCallback Optional callback for reporting progress
1488
+ * @returns Object with created topic IDs
1489
+ */
1490
+ async _createEntityTopics(ttl, existingTopics, accountId, inboundTopicType, feeConfig, pfpBuffer, pfpFileName, progressCallback) {
1491
+ let { outboundTopicId, inboundTopicId, pfpTopicId, profileTopicId } = existingTopics;
1492
+ if (!outboundTopicId) {
1493
+ const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
1494
+ ttl
1495
+ });
1496
+ outboundTopicId = await this.createTopic(outboundMemo, true, true);
1497
+ this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
1498
+ if (progressCallback) {
1499
+ progressCallback({
1500
+ stage: "preparing",
1501
+ message: "Created outbound topic",
1502
+ progressPercent: 30,
1503
+ details: {
1504
+ outboundTopicId,
1505
+ state: {
1506
+ currentStage: "topics",
1507
+ completedPercentage: 30
1508
+ }
1509
+ }
1510
+ });
1511
+ }
1512
+ } else {
1513
+ this.logger.info(`Using existing outbound topic ID: ${outboundTopicId}`);
1514
+ }
1515
+ if (!inboundTopicId) {
1516
+ inboundTopicId = await this.createInboundTopic(
1517
+ accountId,
1518
+ inboundTopicType,
1519
+ ttl,
1520
+ inboundTopicType === InboundTopicType.FEE_BASED ? feeConfig : void 0
1521
+ );
1522
+ this.logger.info(`Created new inbound topic ID: ${inboundTopicId}`);
1523
+ if (progressCallback) {
1524
+ progressCallback({
1525
+ stage: "preparing",
1526
+ message: "Created inbound topic",
1527
+ progressPercent: 40,
1528
+ details: {
1529
+ outboundTopicId,
1530
+ inboundTopicId,
1531
+ state: {
1532
+ currentStage: "topics",
1533
+ completedPercentage: 40
1534
+ }
1535
+ }
1536
+ });
1537
+ }
1538
+ } else {
1539
+ this.logger.info(`Using existing inbound topic ID: ${inboundTopicId}`);
1540
+ }
1541
+ if (!pfpTopicId && pfpBuffer && pfpBuffer.length > 0 && pfpFileName) {
1542
+ this.logger.info("Inscribing new profile picture");
1543
+ if (progressCallback) {
1544
+ progressCallback({
1545
+ stage: "preparing",
1546
+ message: "Inscribing profile picture",
1547
+ progressPercent: 50,
1548
+ details: {
1549
+ outboundTopicId,
1550
+ inboundTopicId,
1551
+ state: {
1552
+ currentStage: "pfp",
1553
+ completedPercentage: 50
1554
+ }
1555
+ }
1556
+ });
1557
+ }
1558
+ const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
1559
+ pfpTopicId = pfpResult.pfpTopicId;
1560
+ this.logger.info(
1561
+ `Profile picture inscribed with topic ID: ${pfpTopicId}`
1562
+ );
1563
+ if (progressCallback) {
1564
+ progressCallback({
1565
+ stage: "preparing",
1566
+ message: "Profile picture inscribed",
1567
+ progressPercent: 55,
1568
+ details: {
1569
+ outboundTopicId,
1570
+ inboundTopicId,
1571
+ pfpTopicId,
1572
+ state: {
1573
+ currentStage: "pfp",
1574
+ completedPercentage: 55
1575
+ }
1576
+ }
1577
+ });
1578
+ }
1579
+ } else if (pfpTopicId) {
1580
+ this.logger.info(
1581
+ `Using existing profile picture with topic ID: ${pfpTopicId}`
1582
+ );
1583
+ }
1584
+ return {
1585
+ inboundTopicId,
1586
+ outboundTopicId,
1587
+ pfpTopicId,
1588
+ profileTopicId
1589
+ };
1590
+ }
1591
+ /**
1592
+ * Creates and registers an MCP server with a Guarded registry.
1593
+ *
1594
+ * This function creates a new account if needed, initializes an HCS10 client,
1595
+ * creates an MCP server with inbound and outbound topics, and registers
1596
+ * it with the Hashgraph Online Guarded Registry.
1597
+ *
1598
+ * @param builder The MCP server builder object with configuration
1599
+ * @param options Optional settings for registration process
1600
+ * @returns Registration result with success status and metadata
1601
+ */
1602
+ async createAndRegisterMCPServer(builder, options) {
1603
+ try {
1604
+ const config = builder.build();
1605
+ const progressCallback = options?.progressCallback;
1606
+ const baseUrl = options?.baseUrl || this.guardedRegistryBaseUrl;
1607
+ let state = options?.existingState || {
1608
+ currentStage: "init",
1609
+ completedPercentage: 0,
1610
+ createdResources: []
1611
+ };
1612
+ state.serverMetadata = {
1613
+ name: config.name,
1614
+ description: config.mcpServer.description,
1615
+ services: config.mcpServer.services
1616
+ };
1617
+ if (progressCallback) {
1618
+ progressCallback({
1619
+ stage: "preparing",
1620
+ message: "Starting MCP server creation process",
1621
+ progressPercent: 0,
1622
+ details: { state }
1623
+ });
1624
+ }
1625
+ let account = config.existingAccount;
1626
+ let serverClient;
1627
+ if (!state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
1628
+ if (!account) {
1629
+ if (state.createdResources && state.createdResources.some((r) => r.startsWith("account:"))) {
1630
+ const accountResource = state.createdResources.find(
1631
+ (r) => r.startsWith("account:")
1632
+ );
1633
+ const existingAccountId = accountResource?.split(":")[1];
1634
+ if (existingAccountId && config.existingAccount) {
1635
+ account = config.existingAccount;
1636
+ this.logger.info(
1637
+ `Resuming with existing account: ${existingAccountId}`
1638
+ );
1639
+ } else {
1640
+ account = await this.createAccount(options?.initialBalance);
1641
+ state.createdResources = state.createdResources || [];
1642
+ state.createdResources.push(`account:${account.accountId}`);
1643
+ }
1644
+ } else {
1645
+ account = await this.createAccount(options?.initialBalance);
1646
+ state.createdResources = state.createdResources || [];
1647
+ state.createdResources.push(`account:${account.accountId}`);
1648
+ }
1649
+ }
1650
+ if (progressCallback) {
1651
+ progressCallback({
1652
+ stage: "preparing",
1653
+ message: "Created account or using existing account",
1654
+ progressPercent: 20,
1655
+ details: { state, account }
1656
+ });
1657
+ }
1658
+ serverClient = new HCS10Client({
1659
+ network: config.network,
1660
+ operatorId: account.accountId,
1661
+ operatorPrivateKey: account.privateKey,
1662
+ operatorPublicKey: PrivateKey.fromString(
1663
+ account.privateKey
1664
+ ).publicKey.toString(),
1665
+ logLevel: "info",
1666
+ guardedRegistryBaseUrl: baseUrl
1667
+ });
1668
+ if (progressCallback) {
1669
+ progressCallback({
1670
+ stage: "preparing",
1671
+ message: "Initialized MCP server client",
1672
+ progressPercent: 25,
1673
+ details: { state }
1674
+ });
1675
+ }
1676
+ let outboundTopicId = state.outboundTopicId;
1677
+ let inboundTopicId = state.inboundTopicId;
1678
+ let pfpTopicId = state.pfpTopicId;
1679
+ let profileTopicId = state.profileTopicId;
1680
+ if (!outboundTopicId || !inboundTopicId || !profileTopicId) {
1681
+ if (pfpTopicId) {
1682
+ builder.setExistingProfilePicture(pfpTopicId);
1683
+ }
1684
+ const createResult = await serverClient.createMCPServer(
1685
+ builder,
1686
+ 60,
1687
+ state,
1688
+ (data) => {
1689
+ if (progressCallback) {
1690
+ progressCallback({
1691
+ stage: data.stage,
1692
+ message: data.message,
1693
+ progressPercent: data.progressPercent || 0,
1694
+ details: {
1695
+ ...data.details,
1696
+ state: {
1697
+ ...state,
1698
+ ...data.details?.state
1699
+ }
1700
+ }
1701
+ });
1702
+ }
1703
+ }
1704
+ );
1705
+ outboundTopicId = createResult.outboundTopicId;
1706
+ inboundTopicId = createResult.inboundTopicId;
1707
+ pfpTopicId = createResult.pfpTopicId;
1708
+ profileTopicId = createResult.profileTopicId;
1709
+ state.outboundTopicId = outboundTopicId;
1710
+ state.inboundTopicId = inboundTopicId;
1711
+ state.pfpTopicId = pfpTopicId;
1712
+ state.profileTopicId = profileTopicId;
1713
+ if (!state.createdResources) {
1714
+ state.createdResources = [];
1715
+ }
1716
+ if (pfpTopicId && !state.createdResources.includes(`pfp:${pfpTopicId}`)) {
1717
+ state.createdResources.push(`pfp:${pfpTopicId}`);
1718
+ }
1719
+ if (!state.createdResources.includes(`inbound:${inboundTopicId}`)) {
1720
+ state.createdResources.push(`inbound:${inboundTopicId}`);
1721
+ }
1722
+ if (!state.createdResources.includes(`outbound:${outboundTopicId}`)) {
1723
+ state.createdResources.push(`outbound:${outboundTopicId}`);
1724
+ }
1725
+ if (!state.createdResources.includes(`profile:${profileTopicId}`)) {
1726
+ state.createdResources.push(`profile:${profileTopicId}`);
1727
+ }
1728
+ }
1729
+ state.currentStage = "profile";
1730
+ state.completedPercentage = 60;
1731
+ if (progressCallback) {
1732
+ progressCallback({
1733
+ stage: "submitting",
1734
+ message: "Created MCP server with topics and profile",
1735
+ progressPercent: 60,
1736
+ details: {
1737
+ state,
1738
+ outboundTopicId,
1739
+ inboundTopicId,
1740
+ pfpTopicId,
1741
+ profileTopicId
1742
+ }
1743
+ });
1744
+ }
1745
+ } else {
1746
+ account = account || config.existingAccount;
1747
+ if (!account) {
1748
+ throw new Error(
1749
+ "Cannot resume registration without account information"
1750
+ );
1751
+ }
1752
+ serverClient = new HCS10Client({
1753
+ network: config.network,
1754
+ operatorId: account.accountId,
1755
+ operatorPrivateKey: account.privateKey,
1756
+ operatorPublicKey: PrivateKey.fromString(
1757
+ account.privateKey
1758
+ ).publicKey.toString(),
1759
+ logLevel: "info",
1760
+ guardedRegistryBaseUrl: baseUrl
1761
+ });
1762
+ this.logger.info("Resuming registration with existing state", {
1763
+ inboundTopicId: state.inboundTopicId,
1764
+ outboundTopicId: state.outboundTopicId,
1765
+ profileTopicId: state.profileTopicId,
1766
+ pfpTopicId: state.pfpTopicId
1767
+ });
1768
+ }
1769
+ const operatorId = `${state.inboundTopicId}@${account.accountId}`;
1770
+ if (state.currentStage !== "complete" || !state.createdResources?.includes(
1771
+ `registration:${state.inboundTopicId}`
1772
+ )) {
1773
+ const registrationResult = await serverClient.registerAgentWithGuardedRegistry(
1774
+ account.accountId,
1775
+ config.network,
1776
+ {
1777
+ progressCallback: (data) => {
1778
+ const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
1779
+ if (progressCallback) {
1780
+ progressCallback({
1781
+ stage: data.stage,
1782
+ message: data.message,
1783
+ progressPercent: adjustedPercent,
1784
+ details: {
1785
+ ...data.details,
1786
+ outboundTopicId: state.outboundTopicId,
1787
+ inboundTopicId: state.inboundTopicId,
1788
+ pfpTopicId: state.pfpTopicId,
1789
+ profileTopicId: state.profileTopicId,
1790
+ operatorId,
1791
+ state: data.details?.state || state
1792
+ }
1793
+ });
1794
+ }
1795
+ },
1796
+ existingState: state
1797
+ }
1798
+ );
1799
+ if (!registrationResult.success) {
1800
+ return {
1801
+ ...registrationResult,
1802
+ state
1803
+ };
1804
+ }
1805
+ state = registrationResult.state || state;
1806
+ }
1807
+ if (progressCallback) {
1808
+ progressCallback({
1809
+ stage: "completed",
1810
+ message: "MCP server creation and registration complete",
1811
+ progressPercent: 100,
1812
+ details: {
1813
+ outboundTopicId: state.outboundTopicId,
1814
+ inboundTopicId: state.inboundTopicId,
1815
+ pfpTopicId: state.pfpTopicId,
1816
+ profileTopicId: state.profileTopicId,
1817
+ operatorId,
1818
+ state
1819
+ }
1820
+ });
1821
+ }
1822
+ return {
1823
+ success: true,
1824
+ state,
1825
+ metadata: {
1826
+ accountId: account.accountId,
1827
+ privateKey: account.privateKey,
1828
+ operatorId,
1829
+ inboundTopicId: state.inboundTopicId,
1830
+ outboundTopicId: state.outboundTopicId,
1831
+ profileTopicId: state.profileTopicId,
1832
+ pfpTopicId: state.pfpTopicId
1833
+ }
1834
+ };
1835
+ } catch (e) {
1836
+ const error = e;
1837
+ const logMessage = `Failed to create and register MCP server: ${error.message}`;
1838
+ this.logger.error(logMessage);
1839
+ return {
1840
+ error: error.message,
1841
+ success: false,
1842
+ state: options?.existingState || {
1843
+ currentStage: "init",
1844
+ completedPercentage: 0,
1845
+ error: error.message
1846
+ }
1847
+ };
1848
+ }
1849
+ }
1339
1850
  }
1340
1851
  export {
1341
1852
  HCS10Client