@lpextend/node-sdk 1.1.2 → 1.1.3

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
@@ -182,6 +182,37 @@ var DomainResolver = class {
182
182
  account: this.accountId,
183
183
  service: "promptlibrary",
184
184
  baseURI: `${this.geo}.promptlibrary.liveperson.net`
185
+ },
186
+ // Conversation Builder domains (aliases for consistency with CB service naming)
187
+ {
188
+ account: this.accountId,
189
+ service: "cbBotPlatform",
190
+ baseURI: `${this.region}.bc-platform.liveperson.net`
191
+ },
192
+ {
193
+ account: this.accountId,
194
+ service: "cbIbc",
195
+ baseURI: `${this.region}.bc-nlu.liveperson.net`
196
+ },
197
+ {
198
+ account: this.accountId,
199
+ service: "cbKb",
200
+ baseURI: `${this.region}.bc-kb.liveperson.net`
201
+ },
202
+ {
203
+ account: this.accountId,
204
+ service: "cbMonitoring",
205
+ baseURI: `${this.region}.bc-mgmt.liveperson.net`
206
+ },
207
+ {
208
+ account: this.accountId,
209
+ service: "cbExternalIntegrations",
210
+ baseURI: `${this.region}.bc-intg.liveperson.net`
211
+ },
212
+ {
213
+ account: this.accountId,
214
+ service: "cbAiSearch",
215
+ baseURI: `${this.region}.kai.liveperson.net`
185
216
  }
186
217
  ];
187
218
  }
@@ -1686,6 +1717,425 @@ var LPPromptsAPI = class {
1686
1717
  }
1687
1718
  };
1688
1719
 
1720
+ // src/api/conversation-builder.api.ts
1721
+ var ConversationBuilderAPI = class {
1722
+ constructor(accountId, debug = false, timeout = 3e4) {
1723
+ this.accountId = accountId;
1724
+ this.credentials = null;
1725
+ this.domainResolver = new DomainResolver(accountId);
1726
+ this.debug = debug;
1727
+ this.timeout = timeout;
1728
+ this.botGroups = new BotGroupsAPI(this);
1729
+ this.bots = new BotsAPI(this);
1730
+ this.dialogs = new DialogsAPI(this);
1731
+ this.interactions = new InteractionsAPI(this);
1732
+ this.nluDomains = new NLUDomainsAPI(this);
1733
+ this.knowledgeBases = new KnowledgeBasesAPI(this);
1734
+ this.botAgents = new BotAgentsAPI(this);
1735
+ this.integrations = new IntegrationsAPI(this);
1736
+ }
1737
+ /**
1738
+ * Set CB authentication credentials
1739
+ * Must be called before making any CB API calls
1740
+ */
1741
+ setCredentials(credentials) {
1742
+ this.credentials = credentials;
1743
+ this.log("CB credentials set", { organizationId: credentials.organizationId });
1744
+ }
1745
+ /**
1746
+ * Check if credentials are set
1747
+ */
1748
+ hasCredentials() {
1749
+ return this.credentials !== null;
1750
+ }
1751
+ /**
1752
+ * Get the current credentials
1753
+ * @throws If credentials not set
1754
+ */
1755
+ getCredentials() {
1756
+ if (!this.credentials) {
1757
+ throw new LPExtendSDKError(
1758
+ "CB credentials not set. Call setCredentials() first or use sentinel.authenticateCB().",
1759
+ ErrorCodes.UNAUTHORIZED
1760
+ );
1761
+ }
1762
+ return this.credentials;
1763
+ }
1764
+ /**
1765
+ * Get the account ID
1766
+ */
1767
+ getAccountId() {
1768
+ return this.accountId;
1769
+ }
1770
+ /**
1771
+ * Get domain for a CB service
1772
+ */
1773
+ async getDomain(service) {
1774
+ const domain = await this.domainResolver.getDomain(service);
1775
+ if (!domain) {
1776
+ throw new LPExtendSDKError(
1777
+ `Could not resolve domain for CB service: ${service}`,
1778
+ ErrorCodes.API_ERROR
1779
+ );
1780
+ }
1781
+ return domain;
1782
+ }
1783
+ /**
1784
+ * Make authenticated request to CB API
1785
+ */
1786
+ async request(service, path, options = {}) {
1787
+ const { cbToken, organizationId } = this.getCredentials();
1788
+ const domain = await this.getDomain(service);
1789
+ const method = options.method || "GET";
1790
+ let url = `https://${domain}${path}`;
1791
+ if (options.params) {
1792
+ const searchParams = new URLSearchParams();
1793
+ Object.entries(options.params).forEach(([key, value]) => {
1794
+ if (value !== void 0) {
1795
+ searchParams.set(key, String(value));
1796
+ }
1797
+ });
1798
+ const paramString = searchParams.toString();
1799
+ if (paramString) {
1800
+ url += (url.includes("?") ? "&" : "?") + paramString;
1801
+ }
1802
+ }
1803
+ const headers = {
1804
+ "Accept": "application/json",
1805
+ "Content-Type": "application/json; charset=utf-8",
1806
+ "authorization": cbToken,
1807
+ "organizationid": organizationId
1808
+ };
1809
+ this.log(`${method} ${url}`, { service });
1810
+ const controller = new AbortController();
1811
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
1812
+ try {
1813
+ const response = await fetch(url, {
1814
+ method,
1815
+ headers,
1816
+ body: options.body ? JSON.stringify(options.body) : void 0,
1817
+ signal: controller.signal
1818
+ });
1819
+ clearTimeout(timeoutId);
1820
+ if (!response.ok) {
1821
+ const errorBody = await response.json().catch(() => ({ message: "Unknown error" }));
1822
+ throw new LPExtendSDKError(
1823
+ `CB API Error: ${response.status} - ${errorBody.message || response.statusText}`,
1824
+ ErrorCodes.API_ERROR,
1825
+ response.status,
1826
+ errorBody
1827
+ );
1828
+ }
1829
+ const contentType = response.headers.get("content-type");
1830
+ if (!contentType?.includes("application/json") || response.status === 204) {
1831
+ return void 0;
1832
+ }
1833
+ return await response.json();
1834
+ } catch (error) {
1835
+ clearTimeout(timeoutId);
1836
+ if (error.name === "AbortError") {
1837
+ throw new LPExtendSDKError("CB API request timeout", ErrorCodes.TIMEOUT);
1838
+ }
1839
+ if (error instanceof LPExtendSDKError) {
1840
+ throw error;
1841
+ }
1842
+ throw new LPExtendSDKError(
1843
+ `CB API request failed: ${error.message}`,
1844
+ ErrorCodes.API_ERROR
1845
+ );
1846
+ }
1847
+ }
1848
+ /**
1849
+ * Debug logging
1850
+ */
1851
+ log(...args) {
1852
+ if (this.debug) {
1853
+ console.log("[LP-Extend-SDK:CB]", ...args);
1854
+ }
1855
+ }
1856
+ };
1857
+ var BotGroupsAPI = class {
1858
+ constructor(cb) {
1859
+ this.cb = cb;
1860
+ }
1861
+ /**
1862
+ * Get all bot groups
1863
+ */
1864
+ async getAll(params) {
1865
+ const queryParams = {};
1866
+ if (params?.expandAll) {
1867
+ queryParams["expand-all"] = true;
1868
+ } else {
1869
+ queryParams.page = params?.page ?? 1;
1870
+ queryParams.size = params?.size ?? 100;
1871
+ }
1872
+ return this.cb.request("cbBotPlatform", "/bot-groups", { params: queryParams });
1873
+ }
1874
+ /**
1875
+ * Get bots by group
1876
+ */
1877
+ async getBots(params) {
1878
+ const queryParams = {
1879
+ "sort-by": params?.sortBy ?? "botName:asc",
1880
+ page: params?.page ?? 1,
1881
+ size: params?.size ?? 10,
1882
+ "bot-group-id": params?.botGroupId ?? "un_assigned"
1883
+ };
1884
+ return this.cb.request("cbBotPlatform", "/bot-groups/bots", { params: queryParams });
1885
+ }
1886
+ };
1887
+ var BotsAPI = class {
1888
+ constructor(cb) {
1889
+ this.cb = cb;
1890
+ }
1891
+ /**
1892
+ * Get all bots (legacy chatbots endpoint)
1893
+ */
1894
+ async getAll() {
1895
+ return this.cb.request("botPlatform", "/bot-platform-manager-0.1/chatbots");
1896
+ }
1897
+ /**
1898
+ * Get chatbot by ID
1899
+ */
1900
+ async getById(chatBotId) {
1901
+ return this.cb.request("cbBotPlatform", "/chatbots", {
1902
+ params: { chatBotId }
1903
+ });
1904
+ }
1905
+ /**
1906
+ * Get global functions for a bot
1907
+ */
1908
+ async getGlobalFunctions(botId) {
1909
+ return this.cb.request("cbBotPlatform", `/bot/${botId}/globalFunctions`);
1910
+ }
1911
+ /**
1912
+ * Get LP app credentials for a bot
1913
+ */
1914
+ async getLPAppCredentials(chatBotId) {
1915
+ return this.cb.request("cbBotPlatform", "/auth/liveperson/app", {
1916
+ params: { chatBotId }
1917
+ });
1918
+ }
1919
+ /**
1920
+ * Get bot environment variables
1921
+ */
1922
+ async getEnvironment() {
1923
+ const data = await this.cb.request("cbBotPlatform", "/auth/botenvironment/");
1924
+ if (Array.isArray(data)) {
1925
+ return { success: true, successResult: data };
1926
+ }
1927
+ return data;
1928
+ }
1929
+ };
1930
+ var DialogsAPI = class {
1931
+ constructor(cb) {
1932
+ this.cb = cb;
1933
+ }
1934
+ /**
1935
+ * Get all dialogs for a bot
1936
+ */
1937
+ async getByBotId(botId) {
1938
+ return this.cb.request("cbBotPlatform", `/bots/${botId}/dialog/`);
1939
+ }
1940
+ /**
1941
+ * Get dialog template summaries
1942
+ */
1943
+ async getTemplateSummary() {
1944
+ return this.cb.request("cbBotPlatform", "/dialog/template/summary");
1945
+ }
1946
+ };
1947
+ var InteractionsAPI = class {
1948
+ constructor(cb) {
1949
+ this.cb = cb;
1950
+ }
1951
+ /**
1952
+ * Get all interactions for a bot
1953
+ */
1954
+ async getByBotId(botId) {
1955
+ return this.cb.request("cbBotPlatform", `/chat/${botId}/interaction/`);
1956
+ }
1957
+ };
1958
+ var NLUDomainsAPI = class {
1959
+ constructor(cb) {
1960
+ this.cb = cb;
1961
+ }
1962
+ /**
1963
+ * Get all NLU domains for the organization
1964
+ */
1965
+ async getAll() {
1966
+ return this.cb.request("cbIbc", "/api/cb/nlu/v1/domains/getByOrgId");
1967
+ }
1968
+ /**
1969
+ * Get intents for a domain
1970
+ */
1971
+ async getIntents(domainId) {
1972
+ const data = await this.cb.request("cbIbc", `/api/cb/nlu/v1/domains/${domainId}/intents`);
1973
+ if (Array.isArray(data)) {
1974
+ return { success: true, successResult: data };
1975
+ }
1976
+ return data;
1977
+ }
1978
+ };
1979
+ var KnowledgeBasesAPI = class {
1980
+ constructor(cb) {
1981
+ this.cb = cb;
1982
+ }
1983
+ /**
1984
+ * Get all knowledge bases
1985
+ */
1986
+ async getAll(includeMetrics = true) {
1987
+ return this.cb.request("cbKb", "/knowledgeDataSource", {
1988
+ params: { includeMetrics }
1989
+ });
1990
+ }
1991
+ /**
1992
+ * Get knowledge base by ID
1993
+ */
1994
+ async getById(kbId, includeMetrics = true) {
1995
+ return this.cb.request("cbKb", `/knowledgeDataSource/${kbId}`, {
1996
+ params: { includeMetrics }
1997
+ });
1998
+ }
1999
+ /**
2000
+ * Get content sources for a knowledge base
2001
+ */
2002
+ async getContentSources(kbId, includeKmsRecipeDetails = true) {
2003
+ return this.cb.request("cbKb", `/kb/${kbId}/content_sources`, {
2004
+ params: { includeKmsRecipeDetails }
2005
+ });
2006
+ }
2007
+ /**
2008
+ * Get articles for a knowledge base
2009
+ */
2010
+ async getArticles(kbId, params) {
2011
+ const body = {
2012
+ page: params?.page ?? 1,
2013
+ size: params?.size ?? 20,
2014
+ sortAscByLastModificationTime: params?.sortAscByLastModificationTime ?? false,
2015
+ articleIds: params?.articleIds ?? []
2016
+ };
2017
+ return this.cb.request("cbKb", `/kb/${kbId}/articles`, {
2018
+ method: "POST",
2019
+ body,
2020
+ params: { includeConflictingDetails: params?.includeConflictingDetails ?? true }
2021
+ });
2022
+ }
2023
+ /**
2024
+ * Search knowledge base using KAI
2025
+ */
2026
+ async search(kbId, searchRequest) {
2027
+ try {
2028
+ return await this.cb.request("cbAiSearch", `/v1/account/${this.cb.getAccountId()}/kb/${kbId}/search`, {
2029
+ method: "POST",
2030
+ body: searchRequest
2031
+ });
2032
+ } catch {
2033
+ return this.cb.request("cbKb", `/kb/${kbId}/search`, {
2034
+ method: "POST",
2035
+ body: searchRequest
2036
+ });
2037
+ }
2038
+ }
2039
+ /**
2040
+ * Get KAI On-Demand configurations
2041
+ */
2042
+ async getOnDemandConfigs() {
2043
+ return this.cb.request("cbKb", "/on-demand/configs");
2044
+ }
2045
+ /**
2046
+ * Get default prompt for KAI
2047
+ */
2048
+ async getDefaultPrompt() {
2049
+ return this.cb.request("cbKb", "/default-prompt");
2050
+ }
2051
+ };
2052
+ var BotAgentsAPI = class {
2053
+ constructor(cb) {
2054
+ this.cb = cb;
2055
+ }
2056
+ /**
2057
+ * Get bot instance status
2058
+ */
2059
+ async getInstanceStatus(botId) {
2060
+ return this.cb.request("cbMonitoring", `/sysadmin/nodejs/instance/status-v2/${botId}`);
2061
+ }
2062
+ /**
2063
+ * Start a bot agent
2064
+ */
2065
+ async start(botId, lpAccountId, lpAccountUser) {
2066
+ return this.cb.request("cbMonitoring", `/sysadmin/nodejs/instance/start/${botId}`, {
2067
+ method: "PUT",
2068
+ body: { lpAccountId, lpAccountUser }
2069
+ });
2070
+ }
2071
+ /**
2072
+ * Stop a bot agent
2073
+ */
2074
+ async stop(botId, lpAccountId, lpAccountUser) {
2075
+ return this.cb.request("cbMonitoring", `/sysadmin/nodejs/instance/stop/${botId}`, {
2076
+ method: "PUT",
2077
+ body: { lpAccountId, lpAccountUser }
2078
+ });
2079
+ }
2080
+ /**
2081
+ * Get all bot agents status
2082
+ */
2083
+ async getAllStatus(params) {
2084
+ return this.cb.request("cbMonitoring", "/sysadmin/nodejs/instance/status", {
2085
+ params: { environment: params?.environment ?? "PRODUCTION" }
2086
+ });
2087
+ }
2088
+ /**
2089
+ * Get PCS bots status
2090
+ */
2091
+ async getPCSStatus(params) {
2092
+ return this.cb.request("cbMonitoring", "/sysadmin/nodejs/instance/pcs/status", {
2093
+ params: { showBotsData: params?.showBotsData ?? true }
2094
+ });
2095
+ }
2096
+ /**
2097
+ * Get bot users
2098
+ */
2099
+ async getBotUsers() {
2100
+ return this.cb.request("cbExternalIntegrations", `/live-engage-service-0.1/le/accounts/${this.cb.getAccountId()}/bot_users`);
2101
+ }
2102
+ /**
2103
+ * Add a bot agent
2104
+ */
2105
+ async addAgent(lpUserId, chatBotId, request) {
2106
+ return this.cb.request("cbExternalIntegrations", `/live-engage-service-0.1/le/accounts/${this.cb.getAccountId()}/bot_users/${lpUserId}`, {
2107
+ method: "POST",
2108
+ body: request,
2109
+ params: { chatBotId }
2110
+ });
2111
+ }
2112
+ };
2113
+ var IntegrationsAPI = class {
2114
+ constructor(cb) {
2115
+ this.cb = cb;
2116
+ }
2117
+ /**
2118
+ * Get responders for a chatbot
2119
+ */
2120
+ async getResponders(chatBotId) {
2121
+ return this.cb.request("cbBotPlatform", "/responder", {
2122
+ params: { chatBotId }
2123
+ });
2124
+ }
2125
+ /**
2126
+ * Get LP skills
2127
+ */
2128
+ async getLPSkills() {
2129
+ return this.cb.request("cbExternalIntegrations", `/live-engage-service-0.1/le/accounts/${this.cb.getAccountId()}/skills`);
2130
+ }
2131
+ /**
2132
+ * Get credentials
2133
+ */
2134
+ async getCredentials() {
2135
+ return this.cb.request("cbExternalIntegrations", "/auth-service-0.1/credentials");
2136
+ }
2137
+ };
2138
+
1689
2139
  // src/sdk.ts
1690
2140
  var LPExtendSDK = class {
1691
2141
  /**
@@ -1718,6 +2168,7 @@ var LPExtendSDK = class {
1718
2168
  this.messaging = new MessagingAPI(this.http);
1719
2169
  this.sentinel = new SentinelAPI(this.http);
1720
2170
  this.prompts = new LPPromptsAPI(this.http);
2171
+ this.conversationBuilder = new ConversationBuilderAPI(config.accountId, this.debug, timeout);
1721
2172
  this.log("SDK initialized with scopes:", this.grantedScopes);
1722
2173
  }
1723
2174
  /**
@@ -1766,9 +2217,9 @@ async function createSDK(config) {
1766
2217
  if (!config.accountId) {
1767
2218
  throw new LPExtendSDKError("accountId is required", ErrorCodes.INVALID_CONFIG);
1768
2219
  }
1769
- if (!config.accessToken && !config.extendToken && !config.shellToken) {
2220
+ if (!config.accessToken && !config.extendToken && !config.shellToken && !config.apiKey) {
1770
2221
  throw new LPExtendSDKError(
1771
- "Either accessToken, extendToken, or shellToken is required",
2222
+ "Either accessToken, apiKey, extendToken, or shellToken is required",
1772
2223
  ErrorCodes.INVALID_CONFIG
1773
2224
  );
1774
2225
  }
@@ -1776,7 +2227,9 @@ async function createSDK(config) {
1776
2227
  const timeout = config.timeout ?? 3e4;
1777
2228
  let shellBaseUrl = config.shellBaseUrl;
1778
2229
  if (!shellBaseUrl) {
1779
- if (typeof window !== "undefined") {
2230
+ if (typeof process !== "undefined" && process.env?.LPEXTEND_SHELL_URL) {
2231
+ shellBaseUrl = process.env.LPEXTEND_SHELL_URL;
2232
+ } else if (typeof window !== "undefined") {
1780
2233
  try {
1781
2234
  if (window.self !== window.top && document.referrer) {
1782
2235
  const url = new URL(document.referrer);
@@ -1785,15 +2238,109 @@ async function createSDK(config) {
1785
2238
  } catch {
1786
2239
  }
1787
2240
  shellBaseUrl = shellBaseUrl || window.location.origin;
1788
- } else {
2241
+ } else if (config.apiKey || config.extendToken || config.shellToken) {
1789
2242
  throw new LPExtendSDKError(
1790
- "shellBaseUrl is required in non-browser environments",
2243
+ "shellBaseUrl is required when using apiKey, extendToken, or shellToken in non-browser environments. Set LPEXTEND_SHELL_URL environment variable or pass shellBaseUrl in config.",
1791
2244
  ErrorCodes.INVALID_CONFIG
1792
2245
  );
1793
2246
  }
1794
2247
  }
1795
2248
  let accessToken = config.accessToken;
1796
- if (!accessToken && config.extendToken) {
2249
+ if (!accessToken && config.apiKey && config.extendToken) {
2250
+ const verifyUrl = `${shellBaseUrl}/api/v1/apps/verify`;
2251
+ if (debug) {
2252
+ console.log("[LP-Extend-SDK] Verifying ExtendJWT with API key");
2253
+ console.log("[LP-Extend-SDK] Shell URL:", shellBaseUrl);
2254
+ console.log("[LP-Extend-SDK] Verify URL:", verifyUrl);
2255
+ console.log("[LP-Extend-SDK] API Key:", config.apiKey.substring(0, 20) + "...");
2256
+ console.log("[LP-Extend-SDK] ExtendToken length:", config.extendToken.length);
2257
+ }
2258
+ const authController = new AbortController();
2259
+ const authTimeoutId = setTimeout(() => authController.abort(), timeout);
2260
+ try {
2261
+ const authResponse = await fetch(verifyUrl, {
2262
+ method: "POST",
2263
+ headers: {
2264
+ "Content-Type": "application/json",
2265
+ "X-LPExtend-API-Key": config.apiKey
2266
+ },
2267
+ body: JSON.stringify({
2268
+ token: config.extendToken
2269
+ }),
2270
+ signal: authController.signal
2271
+ });
2272
+ clearTimeout(authTimeoutId);
2273
+ if (!authResponse.ok) {
2274
+ const errorData = await authResponse.json().catch(() => ({}));
2275
+ if (authResponse.status === 401) {
2276
+ throw new LPExtendSDKError(
2277
+ errorData.message || "Invalid API key or ExtendJWT",
2278
+ ErrorCodes.UNAUTHORIZED,
2279
+ authResponse.status,
2280
+ errorData
2281
+ );
2282
+ }
2283
+ if (authResponse.status === 403) {
2284
+ throw new LPExtendSDKError(
2285
+ errorData.message || "App not authorized for this account",
2286
+ ErrorCodes.APP_NOT_REGISTERED,
2287
+ authResponse.status,
2288
+ errorData
2289
+ );
2290
+ }
2291
+ throw new LPExtendSDKError(
2292
+ errorData.message || `Token verification failed: ${authResponse.status}`,
2293
+ ErrorCodes.API_ERROR,
2294
+ authResponse.status,
2295
+ errorData
2296
+ );
2297
+ }
2298
+ const authData = await authResponse.json();
2299
+ accessToken = authData.lpAccessToken;
2300
+ if (debug) {
2301
+ console.log("[LP-Extend-SDK] ExtendJWT verified with API key");
2302
+ console.log("[LP-Extend-SDK] User:", authData.user?.lpUserId, "Account:", authData.user?.lpAccountId);
2303
+ console.log("[LP-Extend-SDK] Allowed APIs:", authData.allowedApis);
2304
+ }
2305
+ const resolvedConfig = { ...config, accessToken };
2306
+ const initResult = {
2307
+ appId: config.appId,
2308
+ accountId: authData.user?.lpAccountId || config.accountId,
2309
+ grantedScopes: authData.allowedApis || [],
2310
+ appName: config.appId,
2311
+ version: "1.0.0"
2312
+ };
2313
+ return new LPExtendSDK(resolvedConfig, initResult);
2314
+ } catch (error) {
2315
+ clearTimeout(authTimeoutId);
2316
+ if (debug) {
2317
+ console.error("[LP-Extend-SDK] ExtendJWT verification error:", {
2318
+ name: error.name,
2319
+ message: error.message,
2320
+ cause: error.cause?.message || error.cause,
2321
+ verifyUrl
2322
+ });
2323
+ }
2324
+ if (error instanceof LPExtendSDKError) {
2325
+ throw error;
2326
+ }
2327
+ if (error.name === "AbortError") {
2328
+ throw new LPExtendSDKError("Token verification timeout", ErrorCodes.TIMEOUT);
2329
+ }
2330
+ const errorMessage = error.cause?.message || error.message;
2331
+ throw new LPExtendSDKError(
2332
+ `ExtendJWT verification failed: ${errorMessage}`,
2333
+ ErrorCodes.INIT_FAILED
2334
+ );
2335
+ }
2336
+ }
2337
+ if (!accessToken && config.apiKey && !config.extendToken) {
2338
+ throw new LPExtendSDKError(
2339
+ "API key authentication requires extendToken. The ExtendJWT is passed from the shell to your app when opened in an iframe.",
2340
+ ErrorCodes.INVALID_CONFIG
2341
+ );
2342
+ }
2343
+ if (!accessToken && config.extendToken && !config.apiKey) {
1797
2344
  if (debug) {
1798
2345
  console.log("[LP-Extend-SDK] Verifying ExtendJWT with shell");
1799
2346
  }
@@ -1836,6 +2383,20 @@ async function createSDK(config) {
1836
2383
  console.log("[LP-Extend-SDK] ExtendJWT verified, got LP access token");
1837
2384
  console.log("[LP-Extend-SDK] User:", authData.lpUserId, "Account:", authData.lpAccountId);
1838
2385
  }
2386
+ const grantedScopes = config.scopes || ["*"];
2387
+ if (debug) {
2388
+ console.log("[LP-Extend-SDK] ExtendJWT auth grants all scopes:", grantedScopes);
2389
+ console.log("[LP-Extend-SDK] SDK will call LP APIs directly");
2390
+ }
2391
+ const resolvedConfig = { ...config, accessToken };
2392
+ const initResult = {
2393
+ appId: config.appId,
2394
+ accountId: config.accountId,
2395
+ grantedScopes,
2396
+ appName: config.appId,
2397
+ version: "1.0.0"
2398
+ };
2399
+ return new LPExtendSDK(resolvedConfig, initResult);
1839
2400
  } catch (error) {
1840
2401
  clearTimeout(extendTimeoutId);
1841
2402
  if (error instanceof LPExtendSDKError) {
@@ -2000,6 +2561,51 @@ async function createSDK(config) {
2000
2561
  async function initializeSDK(config) {
2001
2562
  return createSDK(config);
2002
2563
  }
2564
+ async function createSDKFromEnv(extendToken) {
2565
+ const apiKey = process.env.LPEXTEND_API_KEY;
2566
+ const appId = process.env.APP_ID;
2567
+ const accountId = process.env.LP_ACCOUNT_ID;
2568
+ const shellBaseUrl = process.env.LPEXTEND_SHELL_URL;
2569
+ const debug = process.env.LPEXTEND_DEBUG === "true";
2570
+ if (!apiKey) {
2571
+ throw new LPExtendSDKError(
2572
+ "LPEXTEND_API_KEY environment variable is required",
2573
+ ErrorCodes.INVALID_CONFIG
2574
+ );
2575
+ }
2576
+ if (!appId) {
2577
+ throw new LPExtendSDKError(
2578
+ "APP_ID environment variable is required",
2579
+ ErrorCodes.INVALID_CONFIG
2580
+ );
2581
+ }
2582
+ if (!accountId) {
2583
+ throw new LPExtendSDKError(
2584
+ "LP_ACCOUNT_ID environment variable is required",
2585
+ ErrorCodes.INVALID_CONFIG
2586
+ );
2587
+ }
2588
+ if (!shellBaseUrl) {
2589
+ throw new LPExtendSDKError(
2590
+ "LPEXTEND_SHELL_URL environment variable is required",
2591
+ ErrorCodes.INVALID_CONFIG
2592
+ );
2593
+ }
2594
+ if (!extendToken) {
2595
+ throw new LPExtendSDKError(
2596
+ "extendToken is required. This is passed from the shell to your app when opened.",
2597
+ ErrorCodes.INVALID_CONFIG
2598
+ );
2599
+ }
2600
+ return createSDK({
2601
+ appId,
2602
+ accountId,
2603
+ apiKey,
2604
+ extendToken,
2605
+ shellBaseUrl,
2606
+ debug
2607
+ });
2608
+ }
2003
2609
  var VERSION = "1.0.0";
2004
2610
  var Scopes = {
2005
2611
  // Account Configuration
@@ -2115,6 +2721,6 @@ async function getShellToken(config) {
2115
2721
  }
2116
2722
  }
2117
2723
 
2118
- export { AIStudioAPI, AIStudioUsersAPI, AgentActivityAPI, AgentGroupsAPI, AgentMetricsAPI, AutomaticMessagesAPI, CampaignsAPI, CategoriesAPI, ConnectToMessagingAPI, ConversationsAPI, EngagementsAPI, ErrorCodes, EvaluatorsAPI, FlowsAPI, GeneratorsAPI, KnowledgebasesAPI, LOBsAPI, LPExtendSDK, LPExtendSDKError, LPPromptsAPI, MessagingAPI, MessagingHistoryAPI, MessagingOperationsAPI, OutboundReportingAPI, PredefinedContentAPI, ProfilesAPI, PromptLibraryAPI, QueryAPI, Scopes, SentinelAPI, SimulationsAPI, SkillsAPI, SpecialOccasionsAPI, SummaryAPI, TranscriptAnalysisAPI, UsersAPI, VERSION, WorkingHoursAPI, createSDK, getShellToken, initializeSDK };
2724
+ export { AIStudioAPI, AIStudioUsersAPI, AgentActivityAPI, AgentGroupsAPI, AgentMetricsAPI, AutomaticMessagesAPI, BotAgentsAPI, BotGroupsAPI, BotsAPI, CampaignsAPI, CategoriesAPI, ConnectToMessagingAPI, ConversationBuilderAPI, ConversationsAPI, DialogsAPI, EngagementsAPI, ErrorCodes, EvaluatorsAPI, FlowsAPI, GeneratorsAPI, IntegrationsAPI, InteractionsAPI, KnowledgeBasesAPI, KnowledgebasesAPI, LOBsAPI, LPExtendSDK, LPExtendSDKError, LPPromptsAPI, MessagingAPI, MessagingHistoryAPI, MessagingOperationsAPI, NLUDomainsAPI, OutboundReportingAPI, PredefinedContentAPI, ProfilesAPI, PromptLibraryAPI, QueryAPI, Scopes, SentinelAPI, SimulationsAPI, SkillsAPI, SpecialOccasionsAPI, SummaryAPI, TranscriptAnalysisAPI, UsersAPI, VERSION, WorkingHoursAPI, createSDK, createSDKFromEnv, getShellToken, initializeSDK };
2119
2725
  //# sourceMappingURL=index.mjs.map
2120
2726
  //# sourceMappingURL=index.mjs.map