@uipath/docsai-tool 1.204.0 → 1.205.0-preview.258

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.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  Command,
4
4
  metadata,
5
5
  registerCommands
6
- } from "./tool-33s418j7.js";
6
+ } from "./tool-bjng7m60.js";
7
7
  import"./tool-1yh8g550.js";
8
8
 
9
9
  // src/index.ts
@@ -9095,7 +9095,7 @@ var package_default = {
9095
9095
  name: "@uipath/docsai-tool",
9096
9096
  author: "UiPath",
9097
9097
  license: "SEE LICENSE IN LICENSE.txt",
9098
- version: "1.204.0",
9098
+ version: "1.205.0-preview.258",
9099
9099
  description: "Search UiPath documentation with AI-powered answers.",
9100
9100
  private: false,
9101
9101
  repository: {
@@ -9318,6 +9318,16 @@ class NodeFileSystem {
9318
9318
  async rename(oldPath, newPath) {
9319
9319
  await fs.rename(oldPath, newPath);
9320
9320
  }
9321
+ async isSymbolicLink(filePath) {
9322
+ try {
9323
+ return (await fs.lstat(filePath)).isSymbolicLink();
9324
+ } catch (error) {
9325
+ if (this.isEnoent(error) || this.hasErrnoCode(error, "ENOTDIR")) {
9326
+ return false;
9327
+ }
9328
+ throw error;
9329
+ }
9330
+ }
9321
9331
  async realpath(filePath) {
9322
9332
  try {
9323
9333
  return await fs.realpath(filePath);
@@ -9958,6 +9968,10 @@ var LOCAL_PERMISSION_ERROR_CODES = new Set([
9958
9968
 
9959
9969
  // ../common/src/error-handler.ts
9960
9970
  var DEFAULT_401 = "Unauthorized (401). The session is missing or expired, or its token carries no scope for this API. Run `uip login status --detailed` to see the session and its scopes.";
9971
+ var DEFAULT_403 = "Forbidden (403). The account lacks permission for this operation, or the token carries no scope for this API. Run `uip login status --detailed` to see the token's scopes.";
9972
+ var DEFAULT_405 = "Method Not Allowed (405). The endpoint may not exist or the base URL may be incorrect.";
9973
+ var DEFAULT_413 = "Payload too large (413). The upload exceeded the server or CDN size limit. Reduce the package size — for example, exclude unused dependencies or remove large files from the project — and try again.";
9974
+ var HTML_RESPONSE_MESSAGE = "Received HTML instead of the expected JSON response.";
9961
9975
  var NETWORK_ERROR_CODES = new Set([
9962
9976
  "ECONNREFUSED",
9963
9977
  "ECONNRESET",
@@ -9982,19 +9996,324 @@ var TLS_ERROR_CODES = new Set([
9982
9996
  var TLS_INSTRUCTIONS = "The server's TLS certificate could not be verified. Most often a " + "corporate proxy/firewall re-signs HTTPS with a root CA that Node does " + "not trust — set NODE_EXTRA_CA_CERTS to that CA's PEM file (and HTTPS_PROXY " + "if you connect through a proxy). If the certificate is instead expired or " + "its hostname does not match, fix the endpoint URL or the system clock. " + "Then retry.";
9983
9997
  var NETWORK_INSTRUCTIONS = "Could not reach the UiPath service. Check your network connection and " + "VPN, confirm any HTTP_PROXY/HTTPS_PROXY/NO_PROXY settings are correct, " + "then retry.";
9984
9998
  var LOCAL_PERMISSION_MESSAGE_PATTERN = new RegExp(`\\b(${[...LOCAL_PERMISSION_ERROR_CODES].join("|")})\\b`);
9985
- function extractErrorMessageSync(error) {
9986
- if (error instanceof Error) {
9987
- return error.message;
9999
+ function localPermissionInstructions(code, path2) {
10000
+ const target = path2 !== undefined ? `'${path2}'` : "a local file or resource";
10001
+ if (code === "EROFS") {
10002
+ return `The filesystem containing ${target} is read-only (EROFS), so the ` + "CLI could not write to it. This is a local environment problem, " + "not a UiPath service error — retrying will not help. Use a " + "writable location, or give this environment write access to the " + "path.";
10003
+ }
10004
+ const onWindows = typeof process !== "undefined" && process.platform === "win32";
10005
+ const remedy = onWindows ? "Re-run from an elevated terminal, close any program holding " + "the file open, or grant your user access to the path." : "Grant this user (or the sandbox the command runs in) access " + "to the path, or run the command outside the sandbox.";
10006
+ return `The operating system denied access to ${target} (${code}). This is ` + "a local permission problem, not a UiPath service error — retrying " + `without a permission change will not help. ${remedy}`;
10007
+ }
10008
+ function describeConnectivityError(error) {
10009
+ for (const cur of walkErrorGraph(error)) {
10010
+ const code = typeof cur.code === "string" ? cur.code : undefined;
10011
+ const message = typeof cur.message === "string" ? cur.message : undefined;
10012
+ if (code && TLS_ERROR_CODES.has(code)) {
10013
+ return {
10014
+ code,
10015
+ kind: "tls",
10016
+ message: message ?? code,
10017
+ instructions: TLS_INSTRUCTIONS
10018
+ };
10019
+ }
10020
+ if (code && NETWORK_ERROR_CODES.has(code)) {
10021
+ return {
10022
+ code,
10023
+ kind: "network",
10024
+ message: message ?? code,
10025
+ instructions: NETWORK_INSTRUCTIONS
10026
+ };
10027
+ }
10028
+ }
10029
+ return;
10030
+ }
10031
+ function describePermissionError(error) {
10032
+ for (const cur of walkErrorGraph(error)) {
10033
+ const message = typeof cur.message === "string" ? cur.message : undefined;
10034
+ const code = matchLocalPermissionCode(cur.code, message);
10035
+ if (!code)
10036
+ continue;
10037
+ const path2 = localPermissionPath(cur.path, message);
10038
+ return {
10039
+ code,
10040
+ message: message ?? code,
10041
+ ...path2 !== undefined ? { path: path2 } : {},
10042
+ instructions: localPermissionInstructions(code, path2)
10043
+ };
10044
+ }
10045
+ return;
10046
+ }
10047
+ function matchLocalPermissionCode(code, message) {
10048
+ if (typeof code === "string" && LOCAL_PERMISSION_ERROR_CODES.has(code)) {
10049
+ return code;
10050
+ }
10051
+ const match = message ? LOCAL_PERMISSION_MESSAGE_PATTERN.exec(message) : null;
10052
+ return match ? match[1] : undefined;
10053
+ }
10054
+ function localPermissionPath(path2, message) {
10055
+ if (typeof path2 === "string")
10056
+ return path2;
10057
+ return message ? /'([^']+)'/.exec(message)?.[1] : undefined;
10058
+ }
10059
+ function isHtmlDocument(body) {
10060
+ return /^\s*(<!doctype html|<html\b)/i.test(body);
10061
+ }
10062
+ function retryHintForRetryAfter(seconds) {
10063
+ if (seconds <= 1) {
10064
+ return "RetryAfter1Second";
10065
+ }
10066
+ if (seconds <= 10) {
10067
+ return "RetryAfter10Seconds";
10068
+ }
10069
+ if (seconds <= 30) {
10070
+ return "RetryAfter30Seconds";
10071
+ }
10072
+ return "RetryAfter60Seconds";
10073
+ }
10074
+ function classifyError(status, error) {
10075
+ if (status === 400 || status === 409 || status === 422) {
10076
+ return { errorCode: "invalid_argument", retry: "RetryWillNotFix" };
10077
+ }
10078
+ if (status === 401) {
10079
+ return {
10080
+ errorCode: "authentication_required",
10081
+ retry: "RetryWillNotFix"
10082
+ };
10083
+ }
10084
+ if (status === 403) {
10085
+ return { errorCode: "permission_denied", retry: "RetryWillNotFix" };
10086
+ }
10087
+ if (status === 404) {
10088
+ return { errorCode: "not_found", retry: "RetryWillNotFix" };
10089
+ }
10090
+ if (status === 405) {
10091
+ return { errorCode: "method_not_allowed", retry: "RetryWillNotFix" };
10092
+ }
10093
+ if (status === 413) {
10094
+ return { errorCode: "invalid_argument", retry: "RetryWillNotFix" };
10095
+ }
10096
+ if (status === 408) {
10097
+ return { errorCode: "timeout", retry: "RetryLater" };
10098
+ }
10099
+ if (status === 429) {
10100
+ return { errorCode: "rate_limited", retry: "RetryLater" };
10101
+ }
10102
+ if (status !== undefined && status >= 500 && status < 600) {
10103
+ return { errorCode: "server_error", retry: "RetryLater" };
10104
+ }
10105
+ if (status === undefined && describePermissionError(error)) {
10106
+ return {
10107
+ errorCode: "local_permission_denied",
10108
+ retry: "RetryWillNotFix"
10109
+ };
9988
10110
  }
9989
- if (typeof error === "object" && error !== null) {
9990
- if ("status" in error && error.status === 401) {
9991
- return DEFAULT_401;
10111
+ const connectivity = describeConnectivityError(error);
10112
+ if (connectivity) {
10113
+ return {
10114
+ errorCode: "network_error",
10115
+ retry: connectivity.kind === "tls" ? "RetryWillNotFix" : "RetryLater"
10116
+ };
10117
+ }
10118
+ return { errorCode: "unknown_error", retry: "RetryWillNotFix" };
10119
+ }
10120
+ function formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus) {
10121
+ if (extractedMessage) {
10122
+ return `HTTP ${status}: ${extractedMessage}`;
10123
+ }
10124
+ return inferredStatus !== undefined ? rawMessage : `HTTP ${status}: ${rawMessage}`;
10125
+ }
10126
+ async function extractErrorDetails(error, options) {
10127
+ const err = error !== null && error !== undefined && typeof error === "object" ? error : {};
10128
+ const response = err.response;
10129
+ const rawMessage = typeof err.message === "string" ? err.message : "Unknown error";
10130
+ const explicitStatus = err.status ?? response?.status;
10131
+ const inferredStatus = explicitStatus === undefined ? parseHttpStatusFromMessage(rawMessage) : undefined;
10132
+ const status = explicitStatus ?? inferredStatus;
10133
+ const isSuccessfulResponse = status !== undefined && status >= 200 && status < 300;
10134
+ let rawBody;
10135
+ let extractedMessage;
10136
+ let parsedBody;
10137
+ const textFn = response?.text?.bind(response);
10138
+ if (textFn) {
10139
+ const [bodyError, body] = await catchError((async () => textFn())());
10140
+ if (!bodyError && body) {
10141
+ rawBody = body;
10142
+ const [parseError, parsed] = catchError(() => JSON.parse(body));
10143
+ if (!parseError && parsed && typeof parsed === "object") {
10144
+ parsedBody = parsed;
10145
+ if (parsedBody.errors && typeof parsedBody.errors === "object") {
10146
+ for (const field of Object.values(parsedBody.errors)) {
10147
+ if (Array.isArray(field) && field.length > 0) {
10148
+ const first = field[0];
10149
+ if (first && typeof first.message === "string") {
10150
+ extractedMessage = first.message;
10151
+ break;
10152
+ }
10153
+ }
10154
+ }
10155
+ }
10156
+ if (!extractedMessage) {
10157
+ extractedMessage = typeof parsedBody.message === "string" ? parsedBody.message : typeof parsedBody.errorMessage === "string" ? parsedBody.errorMessage : typeof parsedBody.title === "string" ? parsedBody.title : undefined;
10158
+ }
10159
+ if (!extractedMessage) {
10160
+ extractedMessage = body;
10161
+ }
10162
+ if (extractedMessage && typeof parsedBody.detail === "string" && parsedBody.detail.length > 0 && !extractedMessage.includes(parsedBody.detail)) {
10163
+ extractedMessage = `${extractedMessage}: ${parsedBody.detail}`;
10164
+ }
10165
+ } else {
10166
+ extractedMessage = isHtmlDocument(body) ? HTML_RESPONSE_MESSAGE : body;
10167
+ }
10168
+ }
10169
+ }
10170
+ let message;
10171
+ let result = "Failure";
10172
+ const classificationStatus = status ?? findHttpStatusInGraph(error);
10173
+ const classification = classifyError(classificationStatus, error);
10174
+ let retry = classification.retry;
10175
+ if (status === 401) {
10176
+ message = DEFAULT_401;
10177
+ result = "AuthenticationError";
10178
+ } else if (status === 403) {
10179
+ message = options?.forbiddenMessage ?? DEFAULT_403;
10180
+ result = "AuthenticationError";
10181
+ } else if (status === 405) {
10182
+ message = DEFAULT_405;
10183
+ } else if (status === 413) {
10184
+ message = DEFAULT_413;
10185
+ } else if (status === 400 || status === 422) {
10186
+ message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
10187
+ result = "ValidationError";
10188
+ } else if (status === 429) {
10189
+ message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
10190
+ } else if (extractedMessage) {
10191
+ if (isSuccessfulResponse && rawMessage !== "Unknown error") {
10192
+ message = rawMessage;
10193
+ } else {
10194
+ message = status ? `HTTP ${status}: ${extractedMessage}` : extractedMessage;
10195
+ }
10196
+ } else if (status) {
10197
+ if (inferredStatus !== undefined) {
10198
+ message = rawMessage;
10199
+ } else if (rawMessage === "Unknown error" && response) {
10200
+ const statusText = response.statusText;
10201
+ message = statusText ? `HTTP ${status} ${statusText}` : `HTTP ${status} - request failed`;
10202
+ } else {
10203
+ message = `HTTP ${status}: ${rawMessage}`;
10204
+ }
10205
+ } else {
10206
+ message = rawMessage;
10207
+ }
10208
+ if (status === undefined) {
10209
+ const connectivity = describeConnectivityError(error);
10210
+ if (connectivity && connectivity.message !== message && !message.includes(connectivity.message)) {
10211
+ message = `${message}: ${connectivity.message}`;
10212
+ }
10213
+ }
10214
+ const permission = status === undefined ? describePermissionError(error) : undefined;
10215
+ if (permission) {
10216
+ if (permission.message !== message && !message.includes(permission.message)) {
10217
+ message = `${message}: ${permission.message}`;
10218
+ }
10219
+ if (!message.includes(permission.instructions)) {
10220
+ const punctuated = message.endsWith(".") ? message : `${message}.`;
10221
+ message = `${punctuated} ${permission.instructions}`;
10222
+ }
10223
+ }
10224
+ let details = rawMessage;
10225
+ if (rawBody) {
10226
+ if (parsedBody) {
10227
+ const extra = {};
10228
+ if (parsedBody.errorCode)
10229
+ extra.errorCode = parsedBody.errorCode;
10230
+ if (parsedBody.detail)
10231
+ extra.detail = parsedBody.detail;
10232
+ if (parsedBody.details)
10233
+ extra.details = parsedBody.details;
10234
+ if (parsedBody.errors != null)
10235
+ extra.errors = parsedBody.errors;
10236
+ if (parsedBody.data && typeof parsedBody.data === "object" && Object.keys(parsedBody.data).length > 0) {
10237
+ extra.data = parsedBody.data;
10238
+ }
10239
+ details = Object.keys(extra).length > 0 ? JSON.stringify(extra) : rawBody;
10240
+ } else {
10241
+ details = rawBody;
9992
10242
  }
9993
- if ("message" in error && typeof error.message === "string") {
9994
- return error.message;
10243
+ } else if (typeof err.message === "string") {
10244
+ details = err.message;
10245
+ } else {
10246
+ details = describeThrownValue(error);
10247
+ }
10248
+ const context = {};
10249
+ if (classificationStatus) {
10250
+ context.httpStatus = classificationStatus;
10251
+ }
10252
+ if (parsedBody?.errorCode && typeof parsedBody.errorCode === "string") {
10253
+ context.errorCode = parsedBody.errorCode;
10254
+ } else if (parsedBody?.code && typeof parsedBody.code === "string") {
10255
+ context.errorCode = parsedBody.code;
10256
+ }
10257
+ if (parsedBody?.requestId && typeof parsedBody.requestId === "string") {
10258
+ context.requestId = parsedBody.requestId;
10259
+ }
10260
+ if (parsedBody?.traceId && typeof parsedBody.traceId === "string") {
10261
+ context.traceId = parsedBody.traceId;
10262
+ }
10263
+ if (permission?.path !== undefined) {
10264
+ context.path = permission.path;
10265
+ }
10266
+ if (status === 429) {
10267
+ const resp = response;
10268
+ const headersObj = resp?.headers;
10269
+ let retryAfterValue;
10270
+ if (headersObj && typeof headersObj === "object" && typeof headersObj.get === "function") {
10271
+ retryAfterValue = headersObj.get("retry-after") ?? undefined;
10272
+ }
10273
+ if (!retryAfterValue && headersObj && typeof headersObj === "object") {
10274
+ const headers = headersObj;
10275
+ retryAfterValue = headers["retry-after"] ?? headers["Retry-After"];
10276
+ }
10277
+ if (retryAfterValue) {
10278
+ const seconds = Number(retryAfterValue);
10279
+ if (!Number.isNaN(seconds)) {
10280
+ context.retryAfter = seconds;
10281
+ retry = retryHintForRetryAfter(seconds);
10282
+ }
10283
+ }
10284
+ }
10285
+ const hasContext = Object.keys(context).length > 0;
10286
+ let parsedErrors;
10287
+ if (parsedBody?.errors && typeof parsedBody.errors === "object") {
10288
+ const errors = {};
10289
+ for (const [field, raw] of Object.entries(parsedBody.errors)) {
10290
+ if (Array.isArray(raw)) {
10291
+ const messages = raw.map((entry) => {
10292
+ if (typeof entry === "string")
10293
+ return entry;
10294
+ if (entry && typeof entry === "object" && typeof entry.message === "string") {
10295
+ return entry.message;
10296
+ }
10297
+ return String(entry);
10298
+ }).filter(Boolean);
10299
+ if (messages.length > 0)
10300
+ errors[field] = messages;
10301
+ } else if (typeof raw === "string") {
10302
+ errors[field] = [raw];
10303
+ }
9995
10304
  }
10305
+ if (Object.keys(errors).length > 0)
10306
+ parsedErrors = errors;
9996
10307
  }
9997
- return describeThrownValue(error);
10308
+ return {
10309
+ result,
10310
+ errorCode: classification.errorCode,
10311
+ message,
10312
+ retry,
10313
+ details,
10314
+ ...hasContext ? { context } : {},
10315
+ ...parsedErrors ? { parsedErrors } : {}
10316
+ };
9998
10317
  }
9999
10318
  // ../common/src/exit-code.ts
10000
10319
  function setExitCode(code) {
@@ -10040,7 +10359,7 @@ function setGlobalLogFilePath(path2) {
10040
10359
  function getGlobalLogFilePath() {
10041
10360
  return logFilePathSlot.get("");
10042
10361
  }
10043
- var DEFAULT_LOG_LEVEL = 3 /* ERROR */;
10362
+ var DEFAULT_LOG_LEVEL = 2 /* WARN */;
10044
10363
 
10045
10364
  class SimpleLogger {
10046
10365
  __brand = "SimpleLogger";
@@ -10307,7 +10626,9 @@ var ErrorDimensions = {
10307
10626
  Result: "Result",
10308
10627
  ErrorCode: "ErrorCode",
10309
10628
  Retry: "Retry",
10310
- ErrorMessage: "ErrorMessage"
10629
+ ErrorMessage: "ErrorMessage",
10630
+ HttpStatus: "HttpStatus",
10631
+ UpstreamErrorCode: "UpstreamErrorCode"
10311
10632
  };
10312
10633
  var AuthDimensions = {
10313
10634
  AuthenticationMethod: "AuthenticationMethod",
@@ -10602,7 +10923,7 @@ function classifyFromError(error) {
10602
10923
  }
10603
10924
  return;
10604
10925
  }
10605
- function classifyError(input) {
10926
+ function classifyError2(input) {
10606
10927
  const recorded = input.recordedFailure;
10607
10928
  if (recorded?.errorClass) {
10608
10929
  return recorded.errorClass;
@@ -10627,7 +10948,7 @@ function takeRecordedCommandFailureTelemetry() {
10627
10948
  function buildCommandTerminalTelemetryProperties(input) {
10628
10949
  const cancelled = isCancellationError(input.error, input.exitCode, input.pollSignal);
10629
10950
  const outcome = input.recordedFailure?.terminalOutcome ?? (input.exitCode === 0 ? "success" : cancelled ? "cancelled" : "failure");
10630
- const errorClass = outcome === "success" || outcome === "no_op" ? undefined : outcome === "cancelled" ? "user_cancelled" : classifyError(input);
10951
+ const errorClass = outcome === "success" || outcome === "no_op" ? undefined : outcome === "cancelled" ? "user_cancelled" : classifyError2(input);
10631
10952
  const terminalSignal = terminalSignalFor(input, outcome);
10632
10953
  return {
10633
10954
  [CommandDimensions.ExitCode]: input.exitCode,
@@ -11295,7 +11616,9 @@ var CLI_ERROR_CODES = [
11295
11616
  "timeout",
11296
11617
  "server_error",
11297
11618
  "method_not_allowed",
11619
+ "not_supported",
11298
11620
  "configuration_error",
11621
+ "execution_failed",
11299
11622
  "unknown_error"
11300
11623
  ];
11301
11624
  var RETRY_HINTS = [
@@ -12252,7 +12575,9 @@ var OutputFormatter;
12252
12575
  [ErrorDimensions.Result]: data.Result,
12253
12576
  [ErrorDimensions.ErrorCode]: data.ErrorCode,
12254
12577
  [ErrorDimensions.Retry]: data.Retry,
12255
- [ErrorDimensions.ErrorMessage]: data.Message
12578
+ [ErrorDimensions.ErrorMessage]: data.Message,
12579
+ [ErrorDimensions.HttpStatus]: data.Context?.httpStatus?.toString(),
12580
+ [ErrorDimensions.UpstreamErrorCode]: data.Context?.errorCode
12256
12581
  });
12257
12582
  }
12258
12583
  logOutput(normalizeOutputKeys(envelope), getOutputFormat());
@@ -13222,22 +13547,12 @@ var resolveConfigAsync = async ({
13222
13547
  baseUrl = DEFAULT_BASE_URL;
13223
13548
  }
13224
13549
  baseUrl = normalizeAndValidateBaseUrl(baseUrl);
13225
- let clientId = customClientId;
13226
- if (!clientId && fileAuth.clientId) {
13227
- clientId = fileAuth.clientId;
13228
- }
13229
- if (!clientId) {
13230
- clientId = DEFAULT_CLIENT_ID;
13231
- }
13232
- let clientSecret = customClientSecret;
13233
- if (!clientSecret && fileAuth.clientSecret) {
13234
- clientSecret = fileAuth.clientSecret;
13235
- }
13236
- const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(clientSecret) || Boolean(customClientAssertion));
13550
+ const clientId = customClientId || DEFAULT_CLIENT_ID;
13551
+ const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(customClientSecret) || Boolean(customClientAssertion));
13237
13552
  const scopes = resolveScopes(isExternalAppAuth, customScopes, fileAuth.scopes);
13238
13553
  return {
13239
13554
  clientId,
13240
- clientSecret,
13555
+ clientSecret: customClientSecret,
13241
13556
  scopes,
13242
13557
  baseUrl,
13243
13558
  authorizationEndpoint: `${baseUrl}/identity_/connect/authorize`,
@@ -13411,6 +13726,16 @@ var resolveIdentityType = (claims, authFlow, email) => {
13411
13726
  }
13412
13727
  return;
13413
13728
  };
13729
+ var resolveApplicationSubtype = (claims, authFlow) => {
13730
+ switch (asString(claims?.sub_type)) {
13731
+ case "service.external":
13732
+ return "External";
13733
+ case "service.internal":
13734
+ return "Internal";
13735
+ default:
13736
+ return authFlow === "client_credentials" || authFlow === "federated_credentials" ? "External" : undefined;
13737
+ }
13738
+ };
13414
13739
  var looksLikeEmail = (value) => value?.includes("@") ?? false;
13415
13740
  var pickEmail = (claims) => {
13416
13741
  for (const candidate of [claims?.email, claims?.preferred_username]) {
@@ -13452,6 +13777,12 @@ var resolveSessionIdentity = (accessToken, authFlow) => {
13452
13777
  const clientId = asString(claims?.client_id);
13453
13778
  if (clientId)
13454
13779
  identity.clientId = clientId;
13780
+ const subType = asString(claims?.sub_type);
13781
+ if (subType)
13782
+ identity.subType = subType;
13783
+ const applicationSubtype = resolveApplicationSubtype(claims, authFlow);
13784
+ if (applicationSubtype)
13785
+ identity.applicationSubtype = applicationSubtype;
13455
13786
  return identity;
13456
13787
  };
13457
13788
  var readTokenScopes = (accessToken) => accessToken ? pickScopes(decodeClaims(accessToken)) : undefined;
@@ -13744,6 +14075,40 @@ var tryRobotClientFallback = async (options = {}) => {
13744
14075
  }
13745
14076
  };
13746
14077
 
14078
+ // ../auth/src/tenantSelection.ts
14079
+ var LOGIN_STATUS_HINT = "Run 'uip login status' to see the organization the CLI is signed in to.";
14080
+ var organizationHint = (organizationId) => `The request used '${organizationId}' as the organization. ${LOGIN_STATUS_HINT}`;
14081
+ var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
14082
+ var describeNonJsonResponse = (organizationId, response, parseError) => {
14083
+ if (response.redirected) {
14084
+ return `Could not find organization '${organizationId}': the request was ` + `redirected to a sign-in page instead of the organization's tenant ` + `list. ${LOGIN_STATUS_HINT}`;
14085
+ }
14086
+ const contentType = response.headers.get("content-type") ?? "unknown";
14087
+ return `The organization service returned a '${contentType}' response instead ` + `of JSON: ${parseError.message}. ${organizationHint(organizationId)}`;
14088
+ };
14089
+ var fetchTenantsAndOrganizations = async (baseUrl, accessToken, organizationId, signal) => {
14090
+ const url = `${baseUrl}/${organizationId}/portal_/api/filtering/leftnav/tenantsAndOrganizationInfo`;
14091
+ const response = await fetch(url, {
14092
+ headers: {
14093
+ Authorization: `Bearer ${accessToken}`
14094
+ },
14095
+ ...signal ? { signal } : {}
14096
+ });
14097
+ if (!response.ok) {
14098
+ if (response.status === 401) {
14099
+ throw new Error(`Unauthorized: the access token was rejected, it was not ` + `issued for organization '${organizationId}', or ` + `'${organizationId}' was not accepted as an organization ` + `URL segment in this environment. ` + LOGIN_STATUS_HINT);
14100
+ }
14101
+ const errorText = await response.text();
14102
+ const message = `Failed to get tenants and organizations: ${response.status} ${errorText}`;
14103
+ throw new Error(IDENTIFIER_STATUSES.has(response.status) ? `${message}. ${organizationHint(organizationId)}` : message);
14104
+ }
14105
+ const [parseError, data] = await catchError2(response.json());
14106
+ if (parseError) {
14107
+ throw new Error(describeNonJsonResponse(organizationId, response, parseError));
14108
+ }
14109
+ return data;
14110
+ };
14111
+
13747
14112
  // ../auth/src/tokenRefresh.ts
13748
14113
  var TOKEN_REFRESH_REAUTHENTICATE_MESSAGE = "Token refresh failed. Run 'uip login' to re-authenticate.";
13749
14114
 
@@ -13956,6 +14321,8 @@ var saveEnvFileAsync = async ({
13956
14321
  };
13957
14322
 
13958
14323
  // ../auth/src/loginStatus.ts
14324
+ var defaultRobotTenantIdCache = new Map;
14325
+ var ROBOT_TENANT_LOOKUP_TIMEOUT_MS = 5000;
13959
14326
  var getLoginStatusAsync = async (options = {}) => {
13960
14327
  return getLoginStatusWithDeps(options);
13961
14328
  };
@@ -13968,12 +14335,20 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
13968
14335
  refreshToken: refreshTokenFn = refreshAccessToken,
13969
14336
  resolveConfig = resolveConfigAsync,
13970
14337
  robotFallback = tryRobotClientFallback,
14338
+ fetchTenantsAndOrgs = fetchTenantsAndOrganizations,
14339
+ robotTenantIdCache = defaultRobotTenantIdCache,
14340
+ robotTenantLookupTimeoutMs = ROBOT_TENANT_LOOKUP_TIMEOUT_MS,
13971
14341
  loadBreaker = loadRefreshBreaker,
13972
14342
  saveBreaker = saveRefreshBreaker,
13973
14343
  clearBreaker = clearRefreshBreaker
13974
14344
  } = deps;
14345
+ const robotDeps = {
14346
+ fetchTenantsAndOrgs,
14347
+ cache: robotTenantIdCache,
14348
+ lookupTimeoutMs: robotTenantLookupTimeoutMs
14349
+ };
13975
14350
  if (isRobotAuthEnforced()) {
13976
- return resolveRobotEnforcedStatus(robotFallback);
14351
+ return resolveRobotEnforcedStatus(robotFallback, robotDeps);
13977
14352
  }
13978
14353
  if (isEnvAuthEnabled()) {
13979
14354
  return readAuthFromEnv();
@@ -13991,7 +14366,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
13991
14366
  hint: `No credentials found for profile "${activeProfile}". Run 'uip login --profile ${activeProfile}' to authenticate this profile.`
13992
14367
  };
13993
14368
  }
13994
- return resolveBorrowedRobotStatus(robotFallback);
14369
+ return resolveBorrowedRobotStatus(robotFallback, robotDeps);
13995
14370
  }
13996
14371
  const loaded = await loadFileCredentials(loadEnvFile, absolutePath);
13997
14372
  if ("status" in loaded) {
@@ -14033,7 +14408,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
14033
14408
  }
14034
14409
  return buildFileStatus(tokens, credentials, globalHint);
14035
14410
  };
14036
- async function resolveRobotEnforcedStatus(robotFallback) {
14411
+ async function resolveRobotEnforcedStatus(robotFallback, deps) {
14037
14412
  if (isEnvAuthEnabled()) {
14038
14413
  throw new EnvAuthConfigError(`${ENV_AUTH_ENABLE_VAR}=true and ${ENFORCE_ROBOT_AUTH_VAR}=true ` + `are mutually exclusive. Unset one of them and re-run.`);
14039
14414
  }
@@ -14044,11 +14419,11 @@ async function resolveRobotEnforcedStatus(robotFallback) {
14044
14419
  hint: `${ENFORCE_ROBOT_AUTH_VAR}=true but the UiPath Robot ` + `session is unavailable. Start and sign in to the Assistant, ` + `or unset ${ENFORCE_ROBOT_AUTH_VAR} to fall back to file or ` + `env-var authentication.`
14045
14420
  };
14046
14421
  }
14047
- return buildRobotStatus(robotCreds);
14422
+ return buildRobotStatus(robotCreds, deps);
14048
14423
  }
14049
- async function resolveBorrowedRobotStatus(robotFallback) {
14424
+ async function resolveBorrowedRobotStatus(robotFallback, deps) {
14050
14425
  const robotCreds = await robotFallback();
14051
- return robotCreds ? buildRobotStatus(robotCreds) : { loginStatus: "Not logged in" };
14426
+ return robotCreds ? buildRobotStatus(robotCreds, deps) : { loginStatus: "Not logged in" };
14052
14427
  }
14053
14428
  async function loadFileCredentials(loadEnvFile, absolutePath) {
14054
14429
  let credentials;
@@ -14183,9 +14558,10 @@ function identityFields(accessToken, credentials) {
14183
14558
  ...scopes ? { scopes } : {}
14184
14559
  };
14185
14560
  }
14186
- function buildRobotStatus(robotCreds) {
14561
+ async function buildRobotStatus(robotCreds, deps) {
14187
14562
  const identity = resolveSessionIdentity(robotCreds.accessToken);
14188
14563
  const scopes = readTokenScopes(robotCreds.accessToken);
14564
+ const tenant = robotCreds.tenantId ? { tenantId: robotCreds.tenantId } : await resolveRobotTenantId(robotCreds, deps);
14189
14565
  return {
14190
14566
  loginStatus: "Logged in",
14191
14567
  accessToken: robotCreds.accessToken,
@@ -14193,14 +14569,62 @@ function buildRobotStatus(robotCreds) {
14193
14569
  organizationName: robotCreds.organizationName,
14194
14570
  organizationId: robotCreds.organizationId,
14195
14571
  tenantName: robotCreds.tenantName,
14196
- tenantId: robotCreds.tenantId,
14572
+ tenantId: tenant.tenantId,
14197
14573
  issuer: robotCreds.issuer,
14198
14574
  expiration: getTokenExpiration(robotCreds.accessToken),
14199
14575
  source: "robot" /* Robot */,
14576
+ ...tenant.hint ? { hint: tenant.hint } : {},
14200
14577
  ...identity ? { identity } : {},
14201
14578
  ...scopes ? { scopes } : {}
14202
14579
  };
14203
14580
  }
14581
+ async function resolveRobotTenantId(robotCreds, deps) {
14582
+ const { baseUrl, accessToken, tenantName } = robotCreds;
14583
+ const organization = robotCreds.organizationName ?? robotCreds.organizationId;
14584
+ if (!tenantName || !organization) {
14585
+ return {};
14586
+ }
14587
+ const key = `${baseUrl}|${organization}|${tenantName}|${accessToken}`;
14588
+ let pending = deps.cache.get(key);
14589
+ if (!pending) {
14590
+ pending = catchError2(lookupRobotTenantId({ baseUrl, accessToken, organization, tenantName }, deps)).then(([error, resolution]) => {
14591
+ const settled = error ? { hint: tenantLookupFailureHint(tenantName, error.message) } : resolution;
14592
+ if (!settled.tenantId) {
14593
+ deps.cache.delete(key);
14594
+ }
14595
+ return settled;
14596
+ });
14597
+ deps.cache.set(key, pending);
14598
+ }
14599
+ return pending;
14600
+ }
14601
+ async function lookupRobotTenantId(target, deps) {
14602
+ const { baseUrl, accessToken, organization, tenantName } = target;
14603
+ const [error, data] = await catchError2(deps.fetchTenantsAndOrgs(baseUrl, accessToken, organization, AbortSignal.timeout(deps.lookupTimeoutMs)));
14604
+ if (error) {
14605
+ const reason = error.name === "TimeoutError" ? `the tenant list did not answer within ${deps.lookupTimeoutMs} ms.` : error.message;
14606
+ return { hint: tenantLookupFailureHint(tenantName, reason) };
14607
+ }
14608
+ const rows = data?.tenants;
14609
+ const tenants = Array.isArray(rows) ? rows.filter((tenant) => typeof tenant?.id === "string" && typeof tenant?.name === "string") : [];
14610
+ const wantedName = decodePathSegment(tenantName);
14611
+ const wanted = wantedName.toLowerCase();
14612
+ const match = tenants.find((tenant) => tenant.name === wantedName) ?? tenants.find((tenant) => tenant.name.toLowerCase() === wanted);
14613
+ if (!match) {
14614
+ const names = tenants.map((tenant) => tenant.name).join(", ");
14615
+ return {
14616
+ hint: `The Robot session targets tenant '${tenantName}', but ` + `organization '${organization}' lists no tenant of that name` + `${names ? ` (available: ${names})` : ""}. Commands that need ` + `the tenant id will fail until it can be resolved.`
14617
+ };
14618
+ }
14619
+ return { tenantId: match.id };
14620
+ }
14621
+ function tenantLookupFailureHint(tenantName, reason) {
14622
+ return `Could not resolve the id of tenant '${tenantName}' from the ` + `Robot session: ${reason} Commands that need the tenant id will ` + `fail until it can be resolved.`;
14623
+ }
14624
+ function decodePathSegment(segment) {
14625
+ const [error, decoded] = catchError2(() => decodeURIComponent(segment));
14626
+ return error ? segment : decoded;
14627
+ }
14204
14628
  var isFileNotFoundError = (error) => {
14205
14629
  if (!(error instanceof Object))
14206
14630
  return false;
@@ -14436,9 +14860,6 @@ function normalizeTokenRefreshUnavailableFailure() {
14436
14860
  function errorMessage(error) {
14437
14861
  return error instanceof Error ? error.message : String(error);
14438
14862
  }
14439
- // ../auth/src/tenantSelection.ts
14440
- var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
14441
-
14442
14863
  // ../auth/src/selectTenant.ts
14443
14864
  var TENANT_SELECTION_REQUIRED_CODE = "TENANT_SELECTION_REQUIRED";
14444
14865
  var INVALID_TENANT_CODE = "INVALID_TENANT";
@@ -23819,6 +24240,24 @@ function printReadableResponse(parsed) {
23819
24240
  }
23820
24241
  write("");
23821
24242
  }
24243
+ function withHttpStatus(error2) {
24244
+ const code = error2?.code;
24245
+ if (!(error2 instanceof Error) || typeof code !== "number" || code < 100 || code > 599) {
24246
+ return error2;
24247
+ }
24248
+ return { message: error2.message, status: code, cause: error2 };
24249
+ }
24250
+ async function reportQueryError(error2) {
24251
+ const details = await extractErrorDetails(withHttpStatus(error2));
24252
+ OutputFormatter.error({
24253
+ Result: details.result,
24254
+ Message: "Error querying DocsAI",
24255
+ Instructions: details.message,
24256
+ ErrorCode: details.errorCode,
24257
+ Retry: details.retry
24258
+ });
24259
+ processContext.exit(1);
24260
+ }
23822
24261
  var registerAskCommand = (program2) => {
23823
24262
  program2.command("ask").description("Search UiPath documentation").argument("<query>", "The question to ask").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).addOption(new Option("--source <source>", "Source to search: docs or technical_solution_articles").choices(["docs", "technical_solution_articles"]).default("docs")).examples(ASK_EXAMPLES).trackedAction(processContext, async (query, options) => {
23824
24263
  if (!query.trim()) {
@@ -23832,13 +24271,7 @@ var registerAskCommand = (program2) => {
23832
24271
  }
23833
24272
  const [clientError, client] = await catchError(createMcpClient(options.tenant));
23834
24273
  if (clientError) {
23835
- const errorMessage2 = extractErrorMessageSync(clientError);
23836
- OutputFormatter.error({
23837
- Result: RESULTS.Failure,
23838
- Message: "Error querying DocsAI",
23839
- Instructions: errorMessage2
23840
- });
23841
- processContext.exit(1);
24274
+ await reportQueryError(clientError);
23842
24275
  return;
23843
24276
  }
23844
24277
  const [callError, result] = await catchError(client.callTool("SearchDocumentation", {
@@ -23847,13 +24280,7 @@ var registerAskCommand = (program2) => {
23847
24280
  }));
23848
24281
  await catchError(client.close());
23849
24282
  if (callError) {
23850
- const errorMessage2 = extractErrorMessageSync(callError);
23851
- OutputFormatter.error({
23852
- Result: RESULTS.Failure,
23853
- Message: "Error querying DocsAI",
23854
- Instructions: errorMessage2
23855
- });
23856
- processContext.exit(1);
24283
+ await reportQueryError(callError);
23857
24284
  return;
23858
24285
  }
23859
24286
  if (result.isError) {
@@ -23892,4 +24319,4 @@ var registerCommands = async (program2) => {
23892
24319
 
23893
24320
  export { Command, metadata, registerCommands };
23894
24321
 
23895
- //# debugId=C996B6249E88B59B64756E2164756E21
24322
+ //# debugId=DBBA59350CAA52BA64756E2164756E21
package/dist/tool.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  metadata,
3
3
  registerCommands
4
- } from "./tool-33s418j7.js";
4
+ } from "./tool-bjng7m60.js";
5
5
  import"./tool-1yh8g550.js";
6
6
  export {
7
7
  metadata,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@uipath/docsai-tool",
3
3
  "author": "UiPath",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
- "version": "1.204.0",
5
+ "version": "1.205.0-preview.258",
6
6
  "description": "Search UiPath documentation with AI-powered answers.",
7
7
  "private": false,
8
8
  "repository": {
@@ -27,5 +27,5 @@
27
27
  "files": [
28
28
  "dist"
29
29
  ],
30
- "gitHead": "699c58dabb59414557755a8933bcbe40aa420df3"
30
+ "gitHead": "8f629ee9fa89abf94f197436a60cb3b9620f8b27"
31
31
  }