@uipath/conversational-tool 1.202.0-preview.154 → 1.202.0-preview.156

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.
@@ -4,7 +4,7 @@ import {
4
4
  getLoginStatusAsync,
5
5
  getSdkUserAgentToken,
6
6
  package_default
7
- } from "./tool-ep93w80x.js";
7
+ } from "./tool-shsp9fns.js";
8
8
  import"./tool-1yh8g550.js";
9
9
 
10
10
  // src/api/cas-client.ts
@@ -7154,7 +7154,8 @@ var RESPONSE_TYPES = {
7154
7154
  JSON: "json",
7155
7155
  TEXT: "text",
7156
7156
  BLOB: "blob",
7157
- ARRAYBUFFER: "arraybuffer"
7157
+ ARRAYBUFFER: "arraybuffer",
7158
+ STREAM: "stream"
7158
7159
  };
7159
7160
  var EXTERNAL_USER_ID = "x-uipath-external-user-id";
7160
7161
  var CONVERSATIONAL_SURFACE_NAME = "x-uipath-conversational-surfacename";
@@ -7166,6 +7167,165 @@ var WEBSOCKET_QUERY_PARAMS = {
7166
7167
  CONVERSATIONAL_SURFACE_NAME,
7167
7168
  CONVERSATIONAL_SURFACE_VERSION
7168
7169
  };
7170
+ function toSearchParams(params) {
7171
+ const searchParams = new URLSearchParams;
7172
+ if (!params)
7173
+ return searchParams;
7174
+ for (const [key, value2] of Object.entries(params)) {
7175
+ if (value2 === undefined || value2 === null)
7176
+ continue;
7177
+ if (Array.isArray(value2)) {
7178
+ value2.forEach((item) => {
7179
+ if (item !== undefined && item !== null)
7180
+ searchParams.append(key, String(item));
7181
+ });
7182
+ } else {
7183
+ searchParams.append(key, String(value2));
7184
+ }
7185
+ }
7186
+ return searchParams;
7187
+ }
7188
+ var DEFAULT_RETRYABLE_STATUS_CODES = [408, 429, 500, 502, 503, 504];
7189
+ var DEFAULT_RETRY_METHODS = ["GET", "HEAD", "PUT", "DELETE", "OPTIONS"];
7190
+ var DEFAULT_RETRY_OPTIONS = {
7191
+ maxRetries: 2,
7192
+ initialDelayMs: 500,
7193
+ backoffStrategy: "exponential",
7194
+ backoffFactor: 2,
7195
+ backoffMaxDelayMs: 30000,
7196
+ retryableStatusCodes: DEFAULT_RETRYABLE_STATUS_CODES,
7197
+ retryMethods: DEFAULT_RETRY_METHODS,
7198
+ retryNetworkErrors: true,
7199
+ respectRetryAfter: true,
7200
+ maxRetryAfterMs: Infinity
7201
+ };
7202
+ var DEFAULT_API_CLIENT_RETRY = {
7203
+ ...DEFAULT_RETRY_OPTIONS,
7204
+ maxRetries: 0
7205
+ };
7206
+ function resolveRetryOptions(settings, defaults = DEFAULT_RETRY_OPTIONS) {
7207
+ if (!settings)
7208
+ return defaults;
7209
+ const { retryDelay, useExponentialBackoff, ...live } = settings;
7210
+ const resolved = { ...defaults };
7211
+ for (const [key, value2] of Object.entries(live)) {
7212
+ if (value2 !== undefined) {
7213
+ resolved[key] = value2;
7214
+ }
7215
+ }
7216
+ if (retryDelay !== undefined && live.initialDelayMs === undefined) {
7217
+ resolved.initialDelayMs = retryDelay;
7218
+ }
7219
+ if (useExponentialBackoff !== undefined && live.backoffStrategy === undefined) {
7220
+ resolved.backoffStrategy = useExponentialBackoff ? "exponential" : "constant";
7221
+ }
7222
+ return resolved;
7223
+ }
7224
+ function computeBackoffDelay(attempt, settings) {
7225
+ const base = Math.max(0, settings.initialDelayMs);
7226
+ let delay;
7227
+ switch (settings.backoffStrategy) {
7228
+ case "constant":
7229
+ delay = base;
7230
+ break;
7231
+ case "linear":
7232
+ delay = base * (attempt + 1);
7233
+ break;
7234
+ default:
7235
+ delay = base * Math.pow(settings.backoffFactor, attempt);
7236
+ }
7237
+ return Math.min(delay, settings.backoffMaxDelayMs);
7238
+ }
7239
+ function parseRetryAfter(value2, now = Date.now()) {
7240
+ const trimmed = value2?.trim();
7241
+ if (!trimmed)
7242
+ return;
7243
+ const seconds = Number(trimmed);
7244
+ if (Number.isFinite(seconds))
7245
+ return Math.max(0, seconds * 1000);
7246
+ const date = Date.parse(trimmed);
7247
+ if (Number.isNaN(date))
7248
+ return;
7249
+ return Math.max(0, date - now);
7250
+ }
7251
+ function wait(durationMs) {
7252
+ return new Promise((resolve) => setTimeout(resolve, Math.max(0, durationMs)));
7253
+ }
7254
+ var RETRY_AFTER = "retry-after";
7255
+ function createAttemptSignal(timeoutMs, external) {
7256
+ if (timeoutMs === undefined || !Number.isFinite(timeoutMs))
7257
+ return { signal: external, dispose: () => {} };
7258
+ const controller = new AbortController;
7259
+ const timer = setTimeout(() => controller.abort(new Error(`Request timeout after ${timeoutMs}ms`)), timeoutMs);
7260
+ const onExternalAbort = () => controller.abort(external?.reason);
7261
+ if (external) {
7262
+ if (external.aborted) {
7263
+ controller.abort(external.reason);
7264
+ } else {
7265
+ external.addEventListener("abort", onExternalAbort);
7266
+ }
7267
+ }
7268
+ return {
7269
+ signal: controller.signal,
7270
+ dispose: () => {
7271
+ clearTimeout(timer);
7272
+ external?.removeEventListener("abort", onExternalAbort);
7273
+ }
7274
+ };
7275
+ }
7276
+ function delayBeforeRetry(durationMs, signal) {
7277
+ if (!signal)
7278
+ return wait(durationMs);
7279
+ if (signal.aborted)
7280
+ return Promise.reject(signal.reason);
7281
+ return new Promise((resolve, reject) => {
7282
+ const onAbort = () => {
7283
+ clearTimeout(timer);
7284
+ reject(signal.reason);
7285
+ };
7286
+ const timer = setTimeout(() => {
7287
+ signal.removeEventListener("abort", onAbort);
7288
+ resolve();
7289
+ }, Math.max(0, durationMs));
7290
+ signal.addEventListener("abort", onAbort);
7291
+ });
7292
+ }
7293
+ async function fetchWithRetry(url2, init, options) {
7294
+ const settings = options.retry;
7295
+ const method = (init.method ?? "GET").toUpperCase();
7296
+ const retriesAllowed = settings.retryMethods.includes(method) ? Math.max(0, settings.maxRetries) : 0;
7297
+ let attempt = 0;
7298
+ for (;; ) {
7299
+ const { signal, dispose } = createAttemptSignal(options.timeoutMs, options.signal);
7300
+ let response;
7301
+ let failure;
7302
+ try {
7303
+ response = await fetch(url2, { ...init, signal });
7304
+ } catch (error) {
7305
+ failure = error;
7306
+ } finally {
7307
+ dispose();
7308
+ }
7309
+ if (options.signal?.aborted && failure !== undefined)
7310
+ throw failure;
7311
+ if (response && !settings.retryableStatusCodes.includes(response.status))
7312
+ return response;
7313
+ if (failure !== undefined && !settings.retryNetworkErrors)
7314
+ throw failure;
7315
+ if (attempt >= retriesAllowed) {
7316
+ if (response)
7317
+ return response;
7318
+ throw failure;
7319
+ }
7320
+ const retryAfter = settings.respectRetryAfter && response ? parseRetryAfter(response.headers.get(RETRY_AFTER)) : undefined;
7321
+ const delay = retryAfter !== undefined ? Math.min(retryAfter, settings.maxRetryAfterMs) : computeBackoffDelay(attempt, settings);
7322
+ response?.body?.cancel().catch((error) => {
7323
+ console.warn("[UiPath SDK] Could not release a discarded response body:", error);
7324
+ });
7325
+ await delayBeforeRetry(delay, options.signal);
7326
+ attempt++;
7327
+ }
7328
+ }
7169
7329
 
7170
7330
  class ApiClient {
7171
7331
  constructor(config, executionContext, tokenManager, clientConfig = {}) {
@@ -7200,28 +7360,16 @@ class ApiClient {
7200
7360
  [UIPATH_TRACEPARENT_ID]: traceparentValue,
7201
7361
  ...options.headers
7202
7362
  };
7203
- const searchParams = new URLSearchParams;
7204
- if (options.params) {
7205
- Object.entries(options.params).forEach(([key, value2]) => {
7206
- if (Array.isArray(value2)) {
7207
- value2.forEach((item) => searchParams.append(key, String(item)));
7208
- } else {
7209
- searchParams.append(key, String(value2));
7210
- }
7211
- });
7212
- }
7363
+ const searchParams = toSearchParams(options.params);
7213
7364
  const fullUrl = searchParams.toString() ? `${url2}?${searchParams.toString()}` : url2;
7214
7365
  let body = undefined;
7215
7366
  if (options.body) {
7216
7367
  body = isFormData ? options.body : JSON.stringify(options.body);
7217
7368
  }
7369
+ const retrySettings = resolveRetryOptions(options.retry ?? options.retryOptions, DEFAULT_API_CLIENT_RETRY);
7370
+ const timeoutMs = options.timeoutMs ?? options.timeoutOptions?.timeout;
7218
7371
  try {
7219
- const response = await fetch(fullUrl, {
7220
- method,
7221
- headers,
7222
- body,
7223
- signal: options.signal
7224
- });
7372
+ const response = await fetchWithRetry(fullUrl, { method, headers, body }, { retry: retrySettings, timeoutMs, signal: options.signal });
7225
7373
  if (!response.ok) {
7226
7374
  const errorInfo = await errorResponseParser.parse(response);
7227
7375
  throw ErrorFactory.createFromHttpStatus(response.status, errorInfo);
@@ -7685,6 +7833,12 @@ class PaginationHelpers {
7685
7833
  });
7686
7834
  }
7687
7835
  }
7836
+ function missingConfigMessage() {
7837
+ if (isBrowser) {
7838
+ return "UiPath SDK configuration not found. " + "Ensure @uipath/coded-apps plugin is set up in your bundler to inject configuration during development and build.";
7839
+ }
7840
+ return "UiPath SDK configuration not found. " + "In a UiPath coded function, pass the handler context: new UiPath(ctx). " + "Otherwise pass { baseUrl, orgName, tenantName, secret }, " + "or set UIPATH_BASE_URL, UIPATH_ORG_NAME, UIPATH_TENANT_NAME and UIPATH_ACCESS_TOKEN.";
7841
+ }
7688
7842
  var REGISTRY_KEY = Symbol.for("@uipath/sdk-internals-registry");
7689
7843
  var getGlobalStore = () => {
7690
7844
  const globalObj = globalThis;
@@ -7693,6 +7847,7 @@ var getGlobalStore = () => {
7693
7847
  }
7694
7848
  return globalObj[REGISTRY_KEY];
7695
7849
  };
7850
+ var looksLikeUiPath = (instance) => typeof instance.initialize === "function";
7696
7851
 
7697
7852
  class SDKInternalsRegistry {
7698
7853
  static get store() {
@@ -7704,6 +7859,9 @@ class SDKInternalsRegistry {
7704
7859
  static get(instance) {
7705
7860
  const internals = this.store.get(instance);
7706
7861
  if (!internals) {
7862
+ if (looksLikeUiPath(instance)) {
7863
+ throw new Error("Cannot create a service: the UiPath instance was never configured. " + missingConfigMessage());
7864
+ }
7707
7865
  throw new Error("Invalid SDK instance. Make sure to pass a valid UiPath instance to the service constructor.");
7708
7866
  }
7709
7867
  return internals;
@@ -8027,6 +8185,16 @@ var AgentMap = {
8027
8185
  var UserSettingsMap = {
8028
8186
  ...CommonFieldMap
8029
8187
  };
8188
+ var ConnectionState;
8189
+ (function(ConnectionState2) {
8190
+ ConnectionState2["Enabled"] = "Enabled";
8191
+ ConnectionState2["Disabled"] = "Disabled";
8192
+ ConnectionState2["Expired"] = "Expired";
8193
+ ConnectionState2["Failed"] = "Failed";
8194
+ })(ConnectionState || (ConnectionState = {}));
8195
+ var ConnectionAuthMap = {
8196
+ expiresAt: "expiresTime"
8197
+ };
8030
8198
  var AUTOPILOT_BASE = "autopilotforeveryone_";
8031
8199
  var API_VERSION = "v1";
8032
8200
  var CONVERSATION_ENDPOINTS = {
@@ -8050,7 +8218,9 @@ var ATTACHMENT_ENDPOINTS = {
8050
8218
  };
8051
8219
  var AGENT_ENDPOINTS = {
8052
8220
  LIST: `${AUTOPILOT_BASE}/api/${API_VERSION}/agent`,
8053
- GET: (folderId, agentId) => `${AUTOPILOT_BASE}/api/${API_VERSION}/agent/${folderId}/${agentId}`
8221
+ GET: (folderId, agentId) => `${AUTOPILOT_BASE}/api/${API_VERSION}/agent/${folderId}/${agentId}`,
8222
+ CONNECTIONS: (folderId, agentId) => `${AUTOPILOT_BASE}/api/${API_VERSION}/agent/${folderId}/${agentId}/connections`,
8223
+ CONNECTION_AUTH: `${AUTOPILOT_BASE}/api/${API_VERSION}/agent/connections/auth`
8054
8224
  };
8055
8225
  var USER_ENDPOINTS = {
8056
8226
  SETTINGS: `${AUTOPILOT_BASE}/api/${API_VERSION}/user/settings`
@@ -10772,6 +10942,29 @@ class ConversationalAgentService extends BaseService {
10772
10942
  const mimeType = resolveCitationMimeType(source, blob.type);
10773
10943
  return mimeType && mimeType !== blob.type ? blob.slice(0, blob.size, mimeType) : blob;
10774
10944
  }
10945
+ async getAvailableConnections(agentId, folderId) {
10946
+ const response = await this.get(AGENT_ENDPOINTS.CONNECTIONS(folderId, agentId));
10947
+ return response.data;
10948
+ }
10949
+ async updateConnectionSelections(agentId, folderId, request) {
10950
+ const response = await this.put(AGENT_ENDPOINTS.CONNECTIONS(folderId, agentId), request);
10951
+ return response.data;
10952
+ }
10953
+ async getAddConnectionUrl(item) {
10954
+ try {
10955
+ const { authUrl } = await this.fetchConnectionAuthUrl(item.connectorKey);
10956
+ return authUrl;
10957
+ } catch {
10958
+ return item.connectionsUrl ?? item.configurationUrl ?? null;
10959
+ }
10960
+ }
10961
+ async getConnectionAuthUrl(connectorKey) {
10962
+ return this.fetchConnectionAuthUrl(connectorKey);
10963
+ }
10964
+ async fetchConnectionAuthUrl(connectorKey) {
10965
+ const response = await this.post(AGENT_ENDPOINTS.CONNECTION_AUTH, { connectorKey });
10966
+ return transformData(response.data, ConnectionAuthMap);
10967
+ }
10775
10968
  async getFeatureFlags() {
10776
10969
  const response = await this.get(FEATURE_ENDPOINTS.FEATURE_FLAGS);
10777
10970
  return response.data;
@@ -10786,6 +10979,18 @@ __decorate([
10786
10979
  __decorate([
10787
10980
  track("ConversationalAgent.DownloadCitationSource")
10788
10981
  ], ConversationalAgentService.prototype, "downloadCitationSource", null);
10982
+ __decorate([
10983
+ track("ConversationalAgent.GetAvailableConnections")
10984
+ ], ConversationalAgentService.prototype, "getAvailableConnections", null);
10985
+ __decorate([
10986
+ track("ConversationalAgent.UpdateConnectionSelections")
10987
+ ], ConversationalAgentService.prototype, "updateConnectionSelections", null);
10988
+ __decorate([
10989
+ track("ConversationalAgent.GetAddConnectionUrl")
10990
+ ], ConversationalAgentService.prototype, "getAddConnectionUrl", null);
10991
+ __decorate([
10992
+ track("ConversationalAgent.GetConnectionAuthUrl")
10993
+ ], ConversationalAgentService.prototype, "getConnectionAuthUrl", null);
10789
10994
  export {
10790
10995
  AgentMap,
10791
10996
  AsyncInputStreamEventHelper,
@@ -10793,6 +10998,8 @@ export {
10793
10998
  AsyncToolCallEventHelper,
10794
10999
  AsyncToolCallEventHelperImpl,
10795
11000
  CitationErrorType,
11001
+ ConnectionAuthMap,
11002
+ ConnectionState,
10796
11003
  ContentPartEventHelper,
10797
11004
  ContentPartEventHelperImpl,
10798
11005
  ContentPartHelper,
@@ -10844,4 +11051,4 @@ export {
10844
11051
  transformMessage
10845
11052
  };
10846
11053
 
10847
- //# debugId=EFB6E7334C72C1DA64756E2164756E21
11054
+ //# debugId=C2A4B4AA6694029164756E2164756E21
package/dist/index.js CHANGED
@@ -2,11 +2,11 @@
2
2
  import {
3
3
  metadata,
4
4
  registerCommands
5
- } from "./tool-nd7q6550.js";
5
+ } from "./tool-s6st9bcb.js";
6
6
  import"./tool-nkyhbf79.js";
7
7
  import {
8
8
  Command
9
- } from "./tool-ep93w80x.js";
9
+ } from "./tool-shsp9fns.js";
10
10
  import"./tool-mpvp5rqs.js";
11
11
  import"./tool-1yh8g550.js";
12
12