@lobehub/market-sdk 0.22.6 → 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
@@ -326,6 +326,28 @@ var AnalysisService = class extends BaseSDK {
326
326
  log2("Getting yearly market overview");
327
327
  return this.getMarketOverview({ period: "1y" });
328
328
  }
329
+ /**
330
+ * Retrieves install failure analysis for plugins within a date range
331
+ *
332
+ * Returns detailed analysis of plugin installation failures including failure counts,
333
+ * failure rates, and most common error messages for each plugin with failures.
334
+ *
335
+ * @param params - Query parameters for the failure analysis
336
+ * @returns Promise resolving to install failure analysis data
337
+ */
338
+ async getInstallFailureAnalysis(params) {
339
+ const { range, limit = 15 } = params;
340
+ log2("Getting install failure analysis for range: %o, limit: %d", range, limit);
341
+ const searchParams = new URLSearchParams();
342
+ searchParams.append("range", JSON.stringify(range));
343
+ if (limit !== 15) {
344
+ searchParams.append("limit", limit.toString());
345
+ }
346
+ const url = `/admin/analysis/plugin/install-failure?${searchParams.toString()}`;
347
+ const result = await this.request(url);
348
+ log2("Install failure analysis retrieved successfully for %d plugins", result.data.length);
349
+ return result.data;
350
+ }
329
351
  /**
330
352
  * Calculates growth rate between current and previous values
331
353
  *
@@ -1358,12 +1380,298 @@ var MarketAdmin = class extends BaseSDK {
1358
1380
  };
1359
1381
 
1360
1382
  // src/market/market-sdk.ts
1361
- import debug11 from "debug";
1383
+ import debug13 from "debug";
1362
1384
 
1363
- // src/market/services/DiscoveryService.ts
1385
+ // src/market/services/AgentService.ts
1364
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";
1365
1600
  import urlJoin2 from "url-join";
1366
- 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");
1367
1675
  var DiscoveryService = class extends BaseSDK {
1368
1676
  /**
1369
1677
  * Retrieves the service discovery document
@@ -1375,24 +1683,24 @@ var DiscoveryService = class extends BaseSDK {
1375
1683
  * @returns Promise resolving to the service discovery document
1376
1684
  */
1377
1685
  async getDiscoveryDocument() {
1378
- log9("Fetching discovery document");
1686
+ log11("Fetching discovery document");
1379
1687
  if (this.discoveryDoc) {
1380
- log9("Returning cached discovery document");
1688
+ log11("Returning cached discovery document");
1381
1689
  return this.discoveryDoc;
1382
1690
  }
1383
- const res = await fetch(urlJoin2(this.baseUrl, "/.well-known/discovery"));
1691
+ const res = await fetch(urlJoin3(this.baseUrl, "/.well-known/discovery"));
1384
1692
  if (!res.ok) {
1385
1693
  throw new Error(await res.text());
1386
1694
  }
1387
1695
  this.discoveryDoc = await res.json();
1388
- log9("Discovery document successfully fetched");
1696
+ log11("Discovery document successfully fetched");
1389
1697
  return this.discoveryDoc;
1390
1698
  }
1391
1699
  };
1392
1700
 
1393
1701
  // src/market/services/PluginsService.ts
1394
- import debug10 from "debug";
1395
- var log10 = debug10("lobe-market-sdk:plugins");
1702
+ import debug12 from "debug";
1703
+ var log12 = debug12("lobe-market-sdk:plugins");
1396
1704
  var PluginsService = class extends BaseSDK {
1397
1705
  /**
1398
1706
  * Retrieves a list of plugins from the marketplace
@@ -1407,9 +1715,9 @@ var PluginsService = class extends BaseSDK {
1407
1715
  const locale = params.locale || this.defaultLocale;
1408
1716
  const queryParams = { ...params, locale };
1409
1717
  const queryString = this.buildQueryString(queryParams);
1410
- log10("Getting plugin list: %O", queryParams);
1718
+ log12("Getting plugin list: %O", queryParams);
1411
1719
  const result = await this.request(`/v1/plugins${queryString}`, options);
1412
- log10("Retrieved %d plugins", result.items.length);
1720
+ log12("Retrieved %d plugins", result.items.length);
1413
1721
  return result;
1414
1722
  }
1415
1723
  /**
@@ -1427,12 +1735,12 @@ var PluginsService = class extends BaseSDK {
1427
1735
  const locale = params.locale || this.defaultLocale;
1428
1736
  const queryParams = { ...params, locale };
1429
1737
  const queryString = this.buildQueryString(queryParams);
1430
- log10("Getting plugin categories: %O", queryParams);
1738
+ log12("Getting plugin categories: %O", queryParams);
1431
1739
  const result = await this.request(
1432
1740
  `/v1/plugins/categories${queryString}`,
1433
1741
  options
1434
1742
  );
1435
- log10("Retrieved %d categories", result.length);
1743
+ log12("Retrieved %d categories", result.length);
1436
1744
  return result;
1437
1745
  }
1438
1746
  /**
@@ -1445,12 +1753,12 @@ var PluginsService = class extends BaseSDK {
1445
1753
  * @returns Promise resolving to an array containing identifiers array and last modified time
1446
1754
  */
1447
1755
  async getPublishedIdentifiers(options) {
1448
- log10("Getting published plugin identifiers");
1756
+ log12("Getting published plugin identifiers");
1449
1757
  const result = await this.request(
1450
1758
  "/v1/plugins/identifiers",
1451
1759
  options
1452
1760
  );
1453
- log10("Retrieved %d published plugin identifiers", result.length);
1761
+ log12("Retrieved %d published plugin identifiers", result.length);
1454
1762
  return result;
1455
1763
  }
1456
1764
  /**
@@ -1470,7 +1778,7 @@ var PluginsService = class extends BaseSDK {
1470
1778
  version,
1471
1779
  identifier
1472
1780
  }, options) {
1473
- log10("Getting plugin manifest: %O", { identifier, locale, version });
1781
+ log12("Getting plugin manifest: %O", { identifier, locale, version });
1474
1782
  const localeParam = locale || this.defaultLocale;
1475
1783
  const params = { locale: localeParam };
1476
1784
  if (version) {
@@ -1481,7 +1789,7 @@ var PluginsService = class extends BaseSDK {
1481
1789
  `/v1/plugins/${identifier}/manifest${queryString}`,
1482
1790
  options
1483
1791
  );
1484
- log10("Plugin manifest successfully retrieved: %s", identifier);
1792
+ log12("Plugin manifest successfully retrieved: %s", identifier);
1485
1793
  return manifest;
1486
1794
  }
1487
1795
  /**
@@ -1498,7 +1806,7 @@ var PluginsService = class extends BaseSDK {
1498
1806
  version,
1499
1807
  identifier
1500
1808
  }, options) {
1501
- log10("Getting plugin detail: %O", { identifier, locale, version });
1809
+ log12("Getting plugin detail: %O", { identifier, locale, version });
1502
1810
  const localeParam = locale || this.defaultLocale;
1503
1811
  const params = { locale: localeParam };
1504
1812
  if (version) {
@@ -1509,7 +1817,7 @@ var PluginsService = class extends BaseSDK {
1509
1817
  `/v1/plugins/${identifier}${queryString}`,
1510
1818
  options
1511
1819
  );
1512
- log10("Plugin manifest successfully retrieved: %s", identifier);
1820
+ log12("Plugin manifest successfully retrieved: %s", identifier);
1513
1821
  return manifest;
1514
1822
  }
1515
1823
  /**
@@ -1524,7 +1832,7 @@ var PluginsService = class extends BaseSDK {
1524
1832
  *
1525
1833
  */
1526
1834
  async reportInstallation(reportData) {
1527
- log10("Reporting installation for %s@%s", reportData.identifier, reportData.version);
1835
+ log12("Reporting installation for %s@%s", reportData.identifier, reportData.version);
1528
1836
  const result = await this.request("/v1/plugins/report/installation", {
1529
1837
  body: JSON.stringify(reportData),
1530
1838
  headers: {
@@ -1532,7 +1840,7 @@ var PluginsService = class extends BaseSDK {
1532
1840
  },
1533
1841
  method: "POST"
1534
1842
  });
1535
- log10("Installation report submitted successfully: %O", result);
1843
+ log12("Installation report submitted successfully: %O", result);
1536
1844
  return result;
1537
1845
  }
1538
1846
  /**
@@ -1546,7 +1854,7 @@ var PluginsService = class extends BaseSDK {
1546
1854
  * @returns Promise resolving to the report submission response
1547
1855
  */
1548
1856
  async reportCall(reportData) {
1549
- log10(
1857
+ log12(
1550
1858
  "Reporting call for %s@%s - %s:%s",
1551
1859
  reportData.identifier,
1552
1860
  reportData.version,
@@ -1560,13 +1868,13 @@ var PluginsService = class extends BaseSDK {
1560
1868
  },
1561
1869
  method: "POST"
1562
1870
  });
1563
- log10("Call report submitted successfully: %O", result);
1871
+ log12("Call report submitted successfully: %O", result);
1564
1872
  return result;
1565
1873
  }
1566
1874
  };
1567
1875
 
1568
1876
  // src/market/market-sdk.ts
1569
- var log11 = debug11("lobe-market-sdk");
1877
+ var log13 = debug13("lobe-market-sdk");
1570
1878
  var MarketSDK = class extends BaseSDK {
1571
1879
  /**
1572
1880
  * Creates a new MarketSDK instance
@@ -1579,7 +1887,9 @@ var MarketSDK = class extends BaseSDK {
1579
1887
  tokenExpiry: void 0
1580
1888
  };
1581
1889
  super(options, void 0, sharedTokenState);
1582
- 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);
1583
1893
  this.plugins = new PluginsService(options, this.headers, sharedTokenState);
1584
1894
  this.discovery = new DiscoveryService(options, this.headers, sharedTokenState);
1585
1895
  }
@@ -1604,20 +1914,11 @@ var MarketSDK = class extends BaseSDK {
1604
1914
  * @param request - Client registration request data
1605
1915
  * @returns Promise resolving to the client registration response with credentials
1606
1916
  * @throws Error if registration fails
1917
+ * @deprecated Use auth.registerClient() instead
1607
1918
  */
1608
1919
  async registerClient(request) {
1609
- log11("Registering client: %s (%s)", request.clientName, request.clientType);
1610
- try {
1611
- const response = await this.request("v1/clients/register", {
1612
- body: JSON.stringify(request),
1613
- method: "POST"
1614
- });
1615
- log11("Client registered successfully: %s", response.client_id);
1616
- return response;
1617
- } catch (error) {
1618
- console.error("Client registration failed: %o", error);
1619
- throw error;
1620
- }
1920
+ log13("Registering client (deprecated method, use auth.registerClient): %s", request.clientName);
1921
+ return this.auth.registerClient(request);
1621
1922
  }
1622
1923
  };
1623
1924