@uipath/llm-gateway-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.
Files changed (2) hide show
  1. package/dist/tool.js +141 -29
  2. package/package.json +2 -2
package/dist/tool.js CHANGED
@@ -2101,7 +2101,7 @@ var package_default = {
2101
2101
  name: "@uipath/llm-gateway-tool",
2102
2102
  author: "UiPath",
2103
2103
  license: "SEE LICENSE IN LICENSE.txt",
2104
- version: "1.204.0",
2104
+ version: "1.205.0-preview.258",
2105
2105
  description: "CLI plugin for UiPath LLM Gateway model discovery.",
2106
2106
  private: false,
2107
2107
  repository: {
@@ -2320,6 +2320,16 @@ class NodeFileSystem {
2320
2320
  async rename(oldPath, newPath) {
2321
2321
  await fs.rename(oldPath, newPath);
2322
2322
  }
2323
+ async isSymbolicLink(filePath) {
2324
+ try {
2325
+ return (await fs.lstat(filePath)).isSymbolicLink();
2326
+ } catch (error) {
2327
+ if (this.isEnoent(error) || this.hasErrnoCode(error, "ENOTDIR")) {
2328
+ return false;
2329
+ }
2330
+ throw error;
2331
+ }
2332
+ }
2323
2333
  async realpath(filePath) {
2324
2334
  try {
2325
2335
  return await fs.realpath(filePath);
@@ -3355,7 +3365,7 @@ function setGlobalLogFilePath(path2) {
3355
3365
  function getGlobalLogFilePath() {
3356
3366
  return logFilePathSlot.get("");
3357
3367
  }
3358
- var DEFAULT_LOG_LEVEL = 3 /* ERROR */;
3368
+ var DEFAULT_LOG_LEVEL = 2 /* WARN */;
3359
3369
 
3360
3370
  class SimpleLogger {
3361
3371
  __brand = "SimpleLogger";
@@ -3622,7 +3632,9 @@ var ErrorDimensions = {
3622
3632
  Result: "Result",
3623
3633
  ErrorCode: "ErrorCode",
3624
3634
  Retry: "Retry",
3625
- ErrorMessage: "ErrorMessage"
3635
+ ErrorMessage: "ErrorMessage",
3636
+ HttpStatus: "HttpStatus",
3637
+ UpstreamErrorCode: "UpstreamErrorCode"
3626
3638
  };
3627
3639
  var AuthDimensions = {
3628
3640
  AuthenticationMethod: "AuthenticationMethod",
@@ -4610,7 +4622,9 @@ var CLI_ERROR_CODES = [
4610
4622
  "timeout",
4611
4623
  "server_error",
4612
4624
  "method_not_allowed",
4625
+ "not_supported",
4613
4626
  "configuration_error",
4627
+ "execution_failed",
4614
4628
  "unknown_error"
4615
4629
  ];
4616
4630
  var RETRY_HINTS = [
@@ -5567,7 +5581,9 @@ var OutputFormatter;
5567
5581
  [ErrorDimensions.Result]: data.Result,
5568
5582
  [ErrorDimensions.ErrorCode]: data.ErrorCode,
5569
5583
  [ErrorDimensions.Retry]: data.Retry,
5570
- [ErrorDimensions.ErrorMessage]: data.Message
5584
+ [ErrorDimensions.ErrorMessage]: data.Message,
5585
+ [ErrorDimensions.HttpStatus]: data.Context?.httpStatus?.toString(),
5586
+ [ErrorDimensions.UpstreamErrorCode]: data.Context?.errorCode
5571
5587
  });
5572
5588
  }
5573
5589
  logOutput(normalizeOutputKeys(envelope), getOutputFormat());
@@ -6520,22 +6536,12 @@ var resolveConfigAsync = async ({
6520
6536
  baseUrl = DEFAULT_BASE_URL;
6521
6537
  }
6522
6538
  baseUrl = normalizeAndValidateBaseUrl(baseUrl);
6523
- let clientId = customClientId;
6524
- if (!clientId && fileAuth.clientId) {
6525
- clientId = fileAuth.clientId;
6526
- }
6527
- if (!clientId) {
6528
- clientId = DEFAULT_CLIENT_ID;
6529
- }
6530
- let clientSecret = customClientSecret;
6531
- if (!clientSecret && fileAuth.clientSecret) {
6532
- clientSecret = fileAuth.clientSecret;
6533
- }
6534
- const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(clientSecret) || Boolean(customClientAssertion));
6539
+ const clientId = customClientId || DEFAULT_CLIENT_ID;
6540
+ const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(customClientSecret) || Boolean(customClientAssertion));
6535
6541
  const scopes = resolveScopes(isExternalAppAuth, customScopes, fileAuth.scopes);
6536
6542
  return {
6537
6543
  clientId,
6538
- clientSecret,
6544
+ clientSecret: customClientSecret,
6539
6545
  scopes,
6540
6546
  baseUrl,
6541
6547
  authorizationEndpoint: `${baseUrl}/identity_/connect/authorize`,
@@ -6709,6 +6715,16 @@ var resolveIdentityType = (claims, authFlow, email) => {
6709
6715
  }
6710
6716
  return;
6711
6717
  };
6718
+ var resolveApplicationSubtype = (claims, authFlow) => {
6719
+ switch (asString(claims?.sub_type)) {
6720
+ case "service.external":
6721
+ return "External";
6722
+ case "service.internal":
6723
+ return "Internal";
6724
+ default:
6725
+ return authFlow === "client_credentials" || authFlow === "federated_credentials" ? "External" : undefined;
6726
+ }
6727
+ };
6712
6728
  var looksLikeEmail = (value) => value?.includes("@") ?? false;
6713
6729
  var pickEmail = (claims) => {
6714
6730
  for (const candidate of [claims?.email, claims?.preferred_username]) {
@@ -6750,6 +6766,12 @@ var resolveSessionIdentity = (accessToken, authFlow) => {
6750
6766
  const clientId = asString(claims?.client_id);
6751
6767
  if (clientId)
6752
6768
  identity.clientId = clientId;
6769
+ const subType = asString(claims?.sub_type);
6770
+ if (subType)
6771
+ identity.subType = subType;
6772
+ const applicationSubtype = resolveApplicationSubtype(claims, authFlow);
6773
+ if (applicationSubtype)
6774
+ identity.applicationSubtype = applicationSubtype;
6753
6775
  return identity;
6754
6776
  };
6755
6777
  var readTokenScopes = (accessToken) => accessToken ? pickScopes(decodeClaims(accessToken)) : undefined;
@@ -7042,6 +7064,40 @@ var tryRobotClientFallback = async (options = {}) => {
7042
7064
  }
7043
7065
  };
7044
7066
 
7067
+ // ../../auth/src/tenantSelection.ts
7068
+ var LOGIN_STATUS_HINT = "Run 'uip login status' to see the organization the CLI is signed in to.";
7069
+ var organizationHint = (organizationId) => `The request used '${organizationId}' as the organization. ${LOGIN_STATUS_HINT}`;
7070
+ var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
7071
+ var describeNonJsonResponse = (organizationId, response, parseError) => {
7072
+ if (response.redirected) {
7073
+ 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}`;
7074
+ }
7075
+ const contentType = response.headers.get("content-type") ?? "unknown";
7076
+ return `The organization service returned a '${contentType}' response instead ` + `of JSON: ${parseError.message}. ${organizationHint(organizationId)}`;
7077
+ };
7078
+ var fetchTenantsAndOrganizations = async (baseUrl, accessToken, organizationId, signal) => {
7079
+ const url = `${baseUrl}/${organizationId}/portal_/api/filtering/leftnav/tenantsAndOrganizationInfo`;
7080
+ const response = await fetch(url, {
7081
+ headers: {
7082
+ Authorization: `Bearer ${accessToken}`
7083
+ },
7084
+ ...signal ? { signal } : {}
7085
+ });
7086
+ if (!response.ok) {
7087
+ if (response.status === 401) {
7088
+ 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);
7089
+ }
7090
+ const errorText = await response.text();
7091
+ const message = `Failed to get tenants and organizations: ${response.status} ${errorText}`;
7092
+ throw new Error(IDENTIFIER_STATUSES.has(response.status) ? `${message}. ${organizationHint(organizationId)}` : message);
7093
+ }
7094
+ const [parseError, data] = await catchError2(response.json());
7095
+ if (parseError) {
7096
+ throw new Error(describeNonJsonResponse(organizationId, response, parseError));
7097
+ }
7098
+ return data;
7099
+ };
7100
+
7045
7101
  // ../../auth/src/tokenRefresh.ts
7046
7102
  var TOKEN_REFRESH_REAUTHENTICATE_MESSAGE = "Token refresh failed. Run 'uip login' to re-authenticate.";
7047
7103
 
@@ -7254,6 +7310,8 @@ var saveEnvFileAsync = async ({
7254
7310
  };
7255
7311
 
7256
7312
  // ../../auth/src/loginStatus.ts
7313
+ var defaultRobotTenantIdCache = new Map;
7314
+ var ROBOT_TENANT_LOOKUP_TIMEOUT_MS = 5000;
7257
7315
  var getLoginStatusAsync = async (options = {}) => {
7258
7316
  return getLoginStatusWithDeps(options);
7259
7317
  };
@@ -7266,12 +7324,20 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
7266
7324
  refreshToken: refreshTokenFn = refreshAccessToken,
7267
7325
  resolveConfig = resolveConfigAsync,
7268
7326
  robotFallback = tryRobotClientFallback,
7327
+ fetchTenantsAndOrgs = fetchTenantsAndOrganizations,
7328
+ robotTenantIdCache = defaultRobotTenantIdCache,
7329
+ robotTenantLookupTimeoutMs = ROBOT_TENANT_LOOKUP_TIMEOUT_MS,
7269
7330
  loadBreaker = loadRefreshBreaker,
7270
7331
  saveBreaker = saveRefreshBreaker,
7271
7332
  clearBreaker = clearRefreshBreaker
7272
7333
  } = deps;
7334
+ const robotDeps = {
7335
+ fetchTenantsAndOrgs,
7336
+ cache: robotTenantIdCache,
7337
+ lookupTimeoutMs: robotTenantLookupTimeoutMs
7338
+ };
7273
7339
  if (isRobotAuthEnforced()) {
7274
- return resolveRobotEnforcedStatus(robotFallback);
7340
+ return resolveRobotEnforcedStatus(robotFallback, robotDeps);
7275
7341
  }
7276
7342
  if (isEnvAuthEnabled()) {
7277
7343
  return readAuthFromEnv();
@@ -7289,7 +7355,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
7289
7355
  hint: `No credentials found for profile "${activeProfile}". Run 'uip login --profile ${activeProfile}' to authenticate this profile.`
7290
7356
  };
7291
7357
  }
7292
- return resolveBorrowedRobotStatus(robotFallback);
7358
+ return resolveBorrowedRobotStatus(robotFallback, robotDeps);
7293
7359
  }
7294
7360
  const loaded = await loadFileCredentials(loadEnvFile, absolutePath);
7295
7361
  if ("status" in loaded) {
@@ -7331,7 +7397,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
7331
7397
  }
7332
7398
  return buildFileStatus(tokens, credentials, globalHint);
7333
7399
  };
7334
- async function resolveRobotEnforcedStatus(robotFallback) {
7400
+ async function resolveRobotEnforcedStatus(robotFallback, deps) {
7335
7401
  if (isEnvAuthEnabled()) {
7336
7402
  throw new EnvAuthConfigError(`${ENV_AUTH_ENABLE_VAR}=true and ${ENFORCE_ROBOT_AUTH_VAR}=true ` + `are mutually exclusive. Unset one of them and re-run.`);
7337
7403
  }
@@ -7342,11 +7408,11 @@ async function resolveRobotEnforcedStatus(robotFallback) {
7342
7408
  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.`
7343
7409
  };
7344
7410
  }
7345
- return buildRobotStatus(robotCreds);
7411
+ return buildRobotStatus(robotCreds, deps);
7346
7412
  }
7347
- async function resolveBorrowedRobotStatus(robotFallback) {
7413
+ async function resolveBorrowedRobotStatus(robotFallback, deps) {
7348
7414
  const robotCreds = await robotFallback();
7349
- return robotCreds ? buildRobotStatus(robotCreds) : { loginStatus: "Not logged in" };
7415
+ return robotCreds ? buildRobotStatus(robotCreds, deps) : { loginStatus: "Not logged in" };
7350
7416
  }
7351
7417
  async function loadFileCredentials(loadEnvFile, absolutePath) {
7352
7418
  let credentials;
@@ -7481,9 +7547,10 @@ function identityFields(accessToken, credentials) {
7481
7547
  ...scopes ? { scopes } : {}
7482
7548
  };
7483
7549
  }
7484
- function buildRobotStatus(robotCreds) {
7550
+ async function buildRobotStatus(robotCreds, deps) {
7485
7551
  const identity = resolveSessionIdentity(robotCreds.accessToken);
7486
7552
  const scopes = readTokenScopes(robotCreds.accessToken);
7553
+ const tenant = robotCreds.tenantId ? { tenantId: robotCreds.tenantId } : await resolveRobotTenantId(robotCreds, deps);
7487
7554
  return {
7488
7555
  loginStatus: "Logged in",
7489
7556
  accessToken: robotCreds.accessToken,
@@ -7491,14 +7558,62 @@ function buildRobotStatus(robotCreds) {
7491
7558
  organizationName: robotCreds.organizationName,
7492
7559
  organizationId: robotCreds.organizationId,
7493
7560
  tenantName: robotCreds.tenantName,
7494
- tenantId: robotCreds.tenantId,
7561
+ tenantId: tenant.tenantId,
7495
7562
  issuer: robotCreds.issuer,
7496
7563
  expiration: getTokenExpiration(robotCreds.accessToken),
7497
7564
  source: "robot" /* Robot */,
7565
+ ...tenant.hint ? { hint: tenant.hint } : {},
7498
7566
  ...identity ? { identity } : {},
7499
7567
  ...scopes ? { scopes } : {}
7500
7568
  };
7501
7569
  }
7570
+ async function resolveRobotTenantId(robotCreds, deps) {
7571
+ const { baseUrl, accessToken, tenantName } = robotCreds;
7572
+ const organization = robotCreds.organizationName ?? robotCreds.organizationId;
7573
+ if (!tenantName || !organization) {
7574
+ return {};
7575
+ }
7576
+ const key = `${baseUrl}|${organization}|${tenantName}|${accessToken}`;
7577
+ let pending = deps.cache.get(key);
7578
+ if (!pending) {
7579
+ pending = catchError2(lookupRobotTenantId({ baseUrl, accessToken, organization, tenantName }, deps)).then(([error, resolution]) => {
7580
+ const settled = error ? { hint: tenantLookupFailureHint(tenantName, error.message) } : resolution;
7581
+ if (!settled.tenantId) {
7582
+ deps.cache.delete(key);
7583
+ }
7584
+ return settled;
7585
+ });
7586
+ deps.cache.set(key, pending);
7587
+ }
7588
+ return pending;
7589
+ }
7590
+ async function lookupRobotTenantId(target, deps) {
7591
+ const { baseUrl, accessToken, organization, tenantName } = target;
7592
+ const [error, data] = await catchError2(deps.fetchTenantsAndOrgs(baseUrl, accessToken, organization, AbortSignal.timeout(deps.lookupTimeoutMs)));
7593
+ if (error) {
7594
+ const reason = error.name === "TimeoutError" ? `the tenant list did not answer within ${deps.lookupTimeoutMs} ms.` : error.message;
7595
+ return { hint: tenantLookupFailureHint(tenantName, reason) };
7596
+ }
7597
+ const rows = data?.tenants;
7598
+ const tenants = Array.isArray(rows) ? rows.filter((tenant) => typeof tenant?.id === "string" && typeof tenant?.name === "string") : [];
7599
+ const wantedName = decodePathSegment(tenantName);
7600
+ const wanted = wantedName.toLowerCase();
7601
+ const match = tenants.find((tenant) => tenant.name === wantedName) ?? tenants.find((tenant) => tenant.name.toLowerCase() === wanted);
7602
+ if (!match) {
7603
+ const names = tenants.map((tenant) => tenant.name).join(", ");
7604
+ return {
7605
+ 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.`
7606
+ };
7607
+ }
7608
+ return { tenantId: match.id };
7609
+ }
7610
+ function tenantLookupFailureHint(tenantName, reason) {
7611
+ 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.`;
7612
+ }
7613
+ function decodePathSegment(segment) {
7614
+ const [error, decoded] = catchError2(() => decodeURIComponent(segment));
7615
+ return error ? segment : decoded;
7616
+ }
7502
7617
  var isFileNotFoundError = (error) => {
7503
7618
  if (!(error instanceof Object))
7504
7619
  return false;
@@ -7734,9 +7849,6 @@ function normalizeTokenRefreshUnavailableFailure() {
7734
7849
  function errorMessage(error) {
7735
7850
  return error instanceof Error ? error.message : String(error);
7736
7851
  }
7737
- // ../../auth/src/tenantSelection.ts
7738
- var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
7739
-
7740
7852
  // ../../auth/src/selectTenant.ts
7741
7853
  var TENANT_SELECTION_REQUIRED_CODE = "TENANT_SELECTION_REQUIRED";
7742
7854
  var INVALID_TENANT_CODE = "INVALID_TENANT";
@@ -7999,4 +8111,4 @@ export {
7999
8111
  registerCommands
8000
8112
  };
8001
8113
 
8002
- //# debugId=9AC7E5927339E7C364756E2164756E21
8114
+ //# debugId=4724EBCFF5DF15F864756E2164756E21
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@uipath/llm-gateway-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": "CLI plugin for UiPath LLM Gateway model discovery.",
7
7
  "private": false,
8
8
  "repository": {
@@ -24,5 +24,5 @@
24
24
  "files": [
25
25
  "dist"
26
26
  ],
27
- "gitHead": "699c58dabb59414557755a8933bcbe40aa420df3"
27
+ "gitHead": "8f629ee9fa89abf94f197436a60cb3b9620f8b27"
28
28
  }