@lobehub/market-sdk 0.22.7 → 0.22.8-beta.0

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.
package/dist/index.mjs CHANGED
@@ -1380,12 +1380,298 @@ var MarketAdmin = class extends BaseSDK {
1380
1380
  };
1381
1381
 
1382
1382
  // src/market/market-sdk.ts
1383
- import debug11 from "debug";
1383
+ import debug13 from "debug";
1384
1384
 
1385
- // src/market/services/DiscoveryService.ts
1385
+ // src/market/services/AgentService.ts
1386
1386
  import debug9 from "debug";
1387
+ var log9 = debug9("lobe-market-sdk:agents");
1388
+ var AgentService = class extends BaseSDK {
1389
+ /**
1390
+ * Retrieves a list of agents from the marketplace
1391
+ *
1392
+ * Supports filtering, pagination, and localization of results.
1393
+ *
1394
+ * @param params - Query parameters for filtering and pagination
1395
+ * @param options - Optional request options
1396
+ * @returns Promise resolving to the agent list response containing items and pagination info
1397
+ */
1398
+ async getAgentList(params = {}, options) {
1399
+ const locale = params.locale || this.defaultLocale;
1400
+ const queryParams = { ...params, locale };
1401
+ const queryString = this.buildQueryString(queryParams);
1402
+ log9("Getting agent list: %O", queryParams);
1403
+ const result = await this.request(`/v1/agents${queryString}`, options);
1404
+ log9("Retrieved %d agents", result.items.length);
1405
+ return result;
1406
+ }
1407
+ /**
1408
+ * Retrieves detailed information about a specific agent
1409
+ *
1410
+ * Returns complete agent information including A2A AgentCard data,
1411
+ * configuration, skills, and localized content.
1412
+ *
1413
+ * @param id - Unique identifier of the agent
1414
+ * @param params - Query parameters for locale and version
1415
+ * @param options - Optional request options
1416
+ * @returns Promise resolving to the agent detail information
1417
+ */
1418
+ async getAgentDetail(id, params = {}, options) {
1419
+ const locale = params.locale || this.defaultLocale;
1420
+ const queryParams = { locale };
1421
+ if (params.version !== void 0) {
1422
+ queryParams.version = params.version.toString();
1423
+ }
1424
+ const queryString = this.buildQueryString(queryParams);
1425
+ log9("Getting agent detail: %O", { id, ...params });
1426
+ const result = await this.request(
1427
+ `/v1/agents/detail/${id}${queryString}`,
1428
+ options
1429
+ );
1430
+ log9("Agent detail successfully retrieved: %s", id);
1431
+ return result;
1432
+ }
1433
+ /**
1434
+ * Retrieves all published agent identifiers
1435
+ *
1436
+ * Returns a lightweight list of all published agent identifiers without
1437
+ * full agent metadata. This is useful for clients that need to know which
1438
+ * agents are available without fetching complete agent information.
1439
+ *
1440
+ * @param options - Optional request options
1441
+ * @returns Promise resolving to an array containing identifiers array and last modified time
1442
+ */
1443
+ async getPublishedIdentifiers(options) {
1444
+ log9("Getting published agent identifiers");
1445
+ const result = await this.request(
1446
+ "/v1/agents/identifiers",
1447
+ options
1448
+ );
1449
+ log9("Retrieved %d published agent identifiers", result.length);
1450
+ return result;
1451
+ }
1452
+ /**
1453
+ * Retrieves agent categories and their counts
1454
+ *
1455
+ * Returns a list of categories along with the number of agents in each category.
1456
+ * Useful for building category filters in a UI. Supports optional search filtering
1457
+ * via 'q' parameter and locale specification.
1458
+ *
1459
+ * @param params - Query parameters for filtering categories
1460
+ * @param options - Optional request options
1461
+ * @returns Promise resolving to an array of category items with counts
1462
+ */
1463
+ async getCategories(params = {}, options) {
1464
+ const locale = params.locale || this.defaultLocale;
1465
+ const queryParams = { ...params, locale };
1466
+ const queryString = this.buildQueryString(queryParams);
1467
+ log9("Getting agent categories: %O", queryParams);
1468
+ const result = await this.request(
1469
+ `/v1/agents/categories${queryString}`,
1470
+ options
1471
+ );
1472
+ log9("Retrieved %d categories", result.length);
1473
+ return result;
1474
+ }
1475
+ /**
1476
+ * Uploads an agent to the marketplace
1477
+ *
1478
+ * Allows users to upload new agents or update existing ones.
1479
+ * The agent data should conform to the A2A AgentCard specification.
1480
+ *
1481
+ * @param agentData - The agent data to upload
1482
+ * @param options - Optional request options
1483
+ * @returns Promise resolving to the upload response
1484
+ */
1485
+ async uploadAgent(agentData, options) {
1486
+ log9("Uploading agent: %s@%s", agentData.agentIdentifier, agentData.version.version);
1487
+ const result = await this.request("/v1/agents/upload", {
1488
+ body: JSON.stringify(agentData),
1489
+ headers: {
1490
+ "Content-Type": "application/json"
1491
+ },
1492
+ method: "POST",
1493
+ ...options
1494
+ });
1495
+ log9("Agent uploaded successfully: %O", result);
1496
+ return result;
1497
+ }
1498
+ /**
1499
+ * Creates a new agent in the marketplace
1500
+ *
1501
+ * @param agentData - The agent data to create
1502
+ * @param options - Optional request options
1503
+ * @returns Promise resolving to the created agent response
1504
+ */
1505
+ async createAgent(agentData, options) {
1506
+ log9("Creating agent: %s", agentData.identifier);
1507
+ const result = await this.request("/v1/agents/create", {
1508
+ body: JSON.stringify(agentData),
1509
+ headers: {
1510
+ "Content-Type": "application/json"
1511
+ },
1512
+ method: "POST",
1513
+ ...options
1514
+ });
1515
+ log9("Agent created successfully: %O", result);
1516
+ return result;
1517
+ }
1518
+ /**
1519
+ * Creates a new version for an existing agent
1520
+ *
1521
+ * @param versionData - The version data to create
1522
+ * @param options - Optional request options
1523
+ * @returns Promise resolving to the created version response
1524
+ */
1525
+ async createAgentVersion(versionData, options) {
1526
+ log9("Creating agent version: %s", versionData.identifier);
1527
+ const result = await this.request("/v1/agents/version/create", {
1528
+ body: JSON.stringify(versionData),
1529
+ headers: {
1530
+ "Content-Type": "application/json"
1531
+ },
1532
+ method: "POST",
1533
+ ...options
1534
+ });
1535
+ log9("Agent version created successfully: %O", result);
1536
+ return result;
1537
+ }
1538
+ /**
1539
+ * Modifies an existing agent
1540
+ *
1541
+ * @param agentData - The agent data to modify
1542
+ * @param options - Optional request options
1543
+ * @returns Promise resolving to the modified agent response
1544
+ */
1545
+ async modifyAgent(agentData, options) {
1546
+ log9("Modifying agent: %s", agentData.identifier);
1547
+ const result = await this.request("/v1/agents/modify", {
1548
+ body: JSON.stringify(agentData),
1549
+ headers: {
1550
+ "Content-Type": "application/json"
1551
+ },
1552
+ method: "POST",
1553
+ ...options
1554
+ });
1555
+ log9("Agent modified successfully: %O", result);
1556
+ return result;
1557
+ }
1558
+ /**
1559
+ * Modifies a specific version of an existing agent
1560
+ *
1561
+ * @param versionData - The version data to modify
1562
+ * @param options - Optional request options
1563
+ * @returns Promise resolving to the modified version response
1564
+ */
1565
+ async modifyAgentVersion(versionData, options) {
1566
+ log9("Modifying agent version: %s@%s", versionData.identifier, versionData.version);
1567
+ const result = await this.request("/v1/agents/version/modify", {
1568
+ body: JSON.stringify(versionData),
1569
+ headers: {
1570
+ "Content-Type": "application/json"
1571
+ },
1572
+ method: "POST",
1573
+ ...options
1574
+ });
1575
+ log9("Agent version modified successfully: %O", result);
1576
+ return result;
1577
+ }
1578
+ /**
1579
+ * Checks if an agent exists in the marketplace
1580
+ *
1581
+ * @param identifier - Unique identifier of the agent
1582
+ * @param options - Optional request options
1583
+ * @returns Promise resolving to true if agent exists, false otherwise
1584
+ */
1585
+ async checkAgentExists(identifier, options) {
1586
+ log9("Checking if agent exists: %s", identifier);
1587
+ try {
1588
+ await this.getAgentDetail(identifier, {}, options);
1589
+ log9("Agent exists: %s", identifier);
1590
+ return true;
1591
+ } catch (e) {
1592
+ log9("Agent does not exist: %s", identifier);
1593
+ return false;
1594
+ }
1595
+ }
1596
+ };
1597
+
1598
+ // src/market/services/AuthService.ts
1599
+ import debug10 from "debug";
1387
1600
  import urlJoin2 from "url-join";
1388
- var log9 = debug9("lobe-market-sdk:discovery");
1601
+ var log10 = debug10("lobe-market-sdk:auth");
1602
+ var AuthService = class extends BaseSDK {
1603
+ /**
1604
+ * Retrieves user information from the OIDC userinfo endpoint
1605
+ *
1606
+ * Requires a valid access token in the Authorization header.
1607
+ *
1608
+ * @param accessToken - The access token to use for authentication
1609
+ * @param options - Optional request options
1610
+ * @returns Promise resolving to the user information
1611
+ */
1612
+ async getUserInfo(accessToken, options) {
1613
+ log10("Getting user info");
1614
+ const userInfoUrl = urlJoin2(this.baseUrl, "market-oidc/userinfo");
1615
+ const response = await fetch(userInfoUrl, {
1616
+ headers: {
1617
+ "Authorization": `Bearer ${accessToken}`,
1618
+ "Content-Type": "application/json"
1619
+ },
1620
+ method: "GET",
1621
+ ...options
1622
+ });
1623
+ if (!response.ok) {
1624
+ const errorMsg = `Failed to fetch user info: ${response.status} ${response.statusText}`;
1625
+ log10("Error: %s", errorMsg);
1626
+ throw new Error(errorMsg);
1627
+ }
1628
+ const userInfo = await response.json();
1629
+ log10("User info retrieved successfully");
1630
+ return userInfo;
1631
+ }
1632
+ /**
1633
+ * Registers a new OAuth client with the marketplace
1634
+ *
1635
+ * This is typically used for device registration or application setup.
1636
+ * Returns client credentials that can be used for M2M authentication.
1637
+ *
1638
+ * @param clientData - The client registration data
1639
+ * @param options - Optional request options
1640
+ * @returns Promise resolving to the client credentials
1641
+ */
1642
+ async registerClient(clientData, options) {
1643
+ log10("Registering client: %s (%s)", clientData.clientName, clientData.clientType);
1644
+ const result = await this.request("/v1/clients/register", {
1645
+ body: JSON.stringify(clientData),
1646
+ headers: {
1647
+ "Content-Type": "application/json"
1648
+ },
1649
+ method: "POST",
1650
+ ...options
1651
+ });
1652
+ log10("Client registered successfully: %s", result.client_id);
1653
+ return result;
1654
+ }
1655
+ /**
1656
+ * Fetches an M2M (Machine-to-Machine) access token
1657
+ *
1658
+ * Uses client credentials to obtain an access token for server-to-server communication.
1659
+ * This method requires clientId and clientSecret to be set in the SDK options.
1660
+ *
1661
+ * @returns Promise resolving to the access token and expiration time
1662
+ */
1663
+ async getM2MToken() {
1664
+ log10("Fetching M2M token");
1665
+ const tokenInfo = await this.fetchM2MToken();
1666
+ log10("M2M token fetched successfully");
1667
+ return tokenInfo;
1668
+ }
1669
+ };
1670
+
1671
+ // src/market/services/DiscoveryService.ts
1672
+ import debug11 from "debug";
1673
+ import urlJoin3 from "url-join";
1674
+ var log11 = debug11("lobe-market-sdk:discovery");
1389
1675
  var DiscoveryService = class extends BaseSDK {
1390
1676
  /**
1391
1677
  * Retrieves the service discovery document
@@ -1397,24 +1683,24 @@ var DiscoveryService = class extends BaseSDK {
1397
1683
  * @returns Promise resolving to the service discovery document
1398
1684
  */
1399
1685
  async getDiscoveryDocument() {
1400
- log9("Fetching discovery document");
1686
+ log11("Fetching discovery document");
1401
1687
  if (this.discoveryDoc) {
1402
- log9("Returning cached discovery document");
1688
+ log11("Returning cached discovery document");
1403
1689
  return this.discoveryDoc;
1404
1690
  }
1405
- const res = await fetch(urlJoin2(this.baseUrl, "/.well-known/discovery"));
1691
+ const res = await fetch(urlJoin3(this.baseUrl, "/.well-known/discovery"));
1406
1692
  if (!res.ok) {
1407
1693
  throw new Error(await res.text());
1408
1694
  }
1409
1695
  this.discoveryDoc = await res.json();
1410
- log9("Discovery document successfully fetched");
1696
+ log11("Discovery document successfully fetched");
1411
1697
  return this.discoveryDoc;
1412
1698
  }
1413
1699
  };
1414
1700
 
1415
1701
  // src/market/services/PluginsService.ts
1416
- import debug10 from "debug";
1417
- var log10 = debug10("lobe-market-sdk:plugins");
1702
+ import debug12 from "debug";
1703
+ var log12 = debug12("lobe-market-sdk:plugins");
1418
1704
  var PluginsService = class extends BaseSDK {
1419
1705
  /**
1420
1706
  * Retrieves a list of plugins from the marketplace
@@ -1429,9 +1715,9 @@ var PluginsService = class extends BaseSDK {
1429
1715
  const locale = params.locale || this.defaultLocale;
1430
1716
  const queryParams = { ...params, locale };
1431
1717
  const queryString = this.buildQueryString(queryParams);
1432
- log10("Getting plugin list: %O", queryParams);
1718
+ log12("Getting plugin list: %O", queryParams);
1433
1719
  const result = await this.request(`/v1/plugins${queryString}`, options);
1434
- log10("Retrieved %d plugins", result.items.length);
1720
+ log12("Retrieved %d plugins", result.items.length);
1435
1721
  return result;
1436
1722
  }
1437
1723
  /**
@@ -1449,12 +1735,12 @@ var PluginsService = class extends BaseSDK {
1449
1735
  const locale = params.locale || this.defaultLocale;
1450
1736
  const queryParams = { ...params, locale };
1451
1737
  const queryString = this.buildQueryString(queryParams);
1452
- log10("Getting plugin categories: %O", queryParams);
1738
+ log12("Getting plugin categories: %O", queryParams);
1453
1739
  const result = await this.request(
1454
1740
  `/v1/plugins/categories${queryString}`,
1455
1741
  options
1456
1742
  );
1457
- log10("Retrieved %d categories", result.length);
1743
+ log12("Retrieved %d categories", result.length);
1458
1744
  return result;
1459
1745
  }
1460
1746
  /**
@@ -1467,12 +1753,12 @@ var PluginsService = class extends BaseSDK {
1467
1753
  * @returns Promise resolving to an array containing identifiers array and last modified time
1468
1754
  */
1469
1755
  async getPublishedIdentifiers(options) {
1470
- log10("Getting published plugin identifiers");
1756
+ log12("Getting published plugin identifiers");
1471
1757
  const result = await this.request(
1472
1758
  "/v1/plugins/identifiers",
1473
1759
  options
1474
1760
  );
1475
- log10("Retrieved %d published plugin identifiers", result.length);
1761
+ log12("Retrieved %d published plugin identifiers", result.length);
1476
1762
  return result;
1477
1763
  }
1478
1764
  /**
@@ -1492,7 +1778,7 @@ var PluginsService = class extends BaseSDK {
1492
1778
  version,
1493
1779
  identifier
1494
1780
  }, options) {
1495
- log10("Getting plugin manifest: %O", { identifier, locale, version });
1781
+ log12("Getting plugin manifest: %O", { identifier, locale, version });
1496
1782
  const localeParam = locale || this.defaultLocale;
1497
1783
  const params = { locale: localeParam };
1498
1784
  if (version) {
@@ -1503,7 +1789,7 @@ var PluginsService = class extends BaseSDK {
1503
1789
  `/v1/plugins/${identifier}/manifest${queryString}`,
1504
1790
  options
1505
1791
  );
1506
- log10("Plugin manifest successfully retrieved: %s", identifier);
1792
+ log12("Plugin manifest successfully retrieved: %s", identifier);
1507
1793
  return manifest;
1508
1794
  }
1509
1795
  /**
@@ -1520,7 +1806,7 @@ var PluginsService = class extends BaseSDK {
1520
1806
  version,
1521
1807
  identifier
1522
1808
  }, options) {
1523
- log10("Getting plugin detail: %O", { identifier, locale, version });
1809
+ log12("Getting plugin detail: %O", { identifier, locale, version });
1524
1810
  const localeParam = locale || this.defaultLocale;
1525
1811
  const params = { locale: localeParam };
1526
1812
  if (version) {
@@ -1531,7 +1817,7 @@ var PluginsService = class extends BaseSDK {
1531
1817
  `/v1/plugins/${identifier}${queryString}`,
1532
1818
  options
1533
1819
  );
1534
- log10("Plugin manifest successfully retrieved: %s", identifier);
1820
+ log12("Plugin manifest successfully retrieved: %s", identifier);
1535
1821
  return manifest;
1536
1822
  }
1537
1823
  /**
@@ -1546,7 +1832,7 @@ var PluginsService = class extends BaseSDK {
1546
1832
  *
1547
1833
  */
1548
1834
  async reportInstallation(reportData) {
1549
- log10("Reporting installation for %s@%s", reportData.identifier, reportData.version);
1835
+ log12("Reporting installation for %s@%s", reportData.identifier, reportData.version);
1550
1836
  const result = await this.request("/v1/plugins/report/installation", {
1551
1837
  body: JSON.stringify(reportData),
1552
1838
  headers: {
@@ -1554,7 +1840,7 @@ var PluginsService = class extends BaseSDK {
1554
1840
  },
1555
1841
  method: "POST"
1556
1842
  });
1557
- log10("Installation report submitted successfully: %O", result);
1843
+ log12("Installation report submitted successfully: %O", result);
1558
1844
  return result;
1559
1845
  }
1560
1846
  /**
@@ -1568,7 +1854,7 @@ var PluginsService = class extends BaseSDK {
1568
1854
  * @returns Promise resolving to the report submission response
1569
1855
  */
1570
1856
  async reportCall(reportData) {
1571
- log10(
1857
+ log12(
1572
1858
  "Reporting call for %s@%s - %s:%s",
1573
1859
  reportData.identifier,
1574
1860
  reportData.version,
@@ -1582,13 +1868,13 @@ var PluginsService = class extends BaseSDK {
1582
1868
  },
1583
1869
  method: "POST"
1584
1870
  });
1585
- log10("Call report submitted successfully: %O", result);
1871
+ log12("Call report submitted successfully: %O", result);
1586
1872
  return result;
1587
1873
  }
1588
1874
  };
1589
1875
 
1590
1876
  // src/market/market-sdk.ts
1591
- var log11 = debug11("lobe-market-sdk");
1877
+ var log13 = debug13("lobe-market-sdk");
1592
1878
  var MarketSDK = class extends BaseSDK {
1593
1879
  /**
1594
1880
  * Creates a new MarketSDK instance
@@ -1601,7 +1887,9 @@ var MarketSDK = class extends BaseSDK {
1601
1887
  tokenExpiry: void 0
1602
1888
  };
1603
1889
  super(options, void 0, sharedTokenState);
1604
- log11("MarketSDK instance created");
1890
+ log13("MarketSDK instance created");
1891
+ this.agents = new AgentService(options, this.headers, sharedTokenState);
1892
+ this.auth = new AuthService(options, this.headers, sharedTokenState);
1605
1893
  this.plugins = new PluginsService(options, this.headers, sharedTokenState);
1606
1894
  this.discovery = new DiscoveryService(options, this.headers, sharedTokenState);
1607
1895
  }
@@ -1626,20 +1914,11 @@ var MarketSDK = class extends BaseSDK {
1626
1914
  * @param request - Client registration request data
1627
1915
  * @returns Promise resolving to the client registration response with credentials
1628
1916
  * @throws Error if registration fails
1917
+ * @deprecated Use auth.registerClient() instead
1629
1918
  */
1630
1919
  async registerClient(request) {
1631
- log11("Registering client: %s (%s)", request.clientName, request.clientType);
1632
- try {
1633
- const response = await this.request("v1/clients/register", {
1634
- body: JSON.stringify(request),
1635
- method: "POST"
1636
- });
1637
- log11("Client registered successfully: %s", response.client_id);
1638
- return response;
1639
- } catch (error) {
1640
- console.error("Client registration failed: %o", error);
1641
- throw error;
1642
- }
1920
+ log13("Registering client (deprecated method, use auth.registerClient): %s", request.clientName);
1921
+ return this.auth.registerClient(request);
1643
1922
  }
1644
1923
  };
1645
1924