@uipath/uipath-python-bridge 1.202.0-preview.159 → 1.203.0-preview.160

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/index.js +413 -87
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -7935,7 +7935,7 @@ var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{1
7935
7935
  var EMAIL_PATTERN = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
7936
7936
  var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
7937
7937
  var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
7938
- var PADDED_BASE64_PATTERN = /[A-Za-z0-9+/]{16,}={1,2}(?![A-Za-z0-9+/=])/g;
7938
+ var PADDED_BASE64_PATTERN = /(?<![A-Za-z0-9+/])[A-Za-z0-9+/]{16,}={1,2}(?![A-Za-z0-9+/=])/g;
7939
7939
  var BASE64_WITH_PLUS_PATTERN = /[A-Za-z0-9+/]{40,}/g;
7940
7940
  var USER_HOME_PATTERN = /(?<![A-Za-z0-9._-])([/\\])(Users|home|Profiles)([/\\])([^/\\]+)/gi;
7941
7941
  var UNC_PATH_PATTERN = /(^|[\s"'<>|=,;([{])(\\\\[^\s"'<>|]+)/g;
@@ -7982,7 +7982,7 @@ var QUOTED_LITERAL_PATTERN = new RegExp([
7982
7982
  `(?<![A-Za-z0-9])"(?:[^\\
7983
7983
  ]|\\.){2,${QUOTED_LITERAL_MAX_SPAN}}?"(?![A-Za-z0-9])`
7984
7984
  ].join("|"), "g");
7985
- var JSON_BODY_PATTERN = /[{[][^{}[\]]*[:,][^{}[\]]*[\]}]/g;
7985
+ var JSON_BODY_PATTERN = /[{[][^{}[\]:,]*[:,][^{}[\]]*[\]}]/g;
7986
7986
  var COLLAPSED_BODY = "{…}";
7987
7987
  var COLLAPSED_BODY_MARKER = "\x01body\x01";
7988
7988
  var MAX_BODY_NESTING = 8;
@@ -7997,10 +7997,13 @@ function collapseJsonBodies(text) {
7997
7997
  }
7998
7998
  return out.split(COLLAPSED_BODY_MARKER).join(COLLAPSED_BODY);
7999
7999
  }
8000
- var TRAILING_PROSE_PUNCT = /[.,;:!?)\]}>'"]+$/;
8000
+ var TRAILING_PROSE_PUNCT = `.,;:!?)]}>'"`;
8001
8001
  function peelTrailingPunctuation(match) {
8002
- const trailing = match.match(TRAILING_PROSE_PUNCT)?.[0] ?? "";
8003
- return trailing ? [match.slice(0, -trailing.length), trailing] : [match, ""];
8002
+ let end = match.length;
8003
+ while (end > 0 && TRAILING_PROSE_PUNCT.includes(match[end - 1])) {
8004
+ end -= 1;
8005
+ }
8006
+ return [match.slice(0, end), match.slice(end)];
8004
8007
  }
8005
8008
  function redactUrl(raw) {
8006
8009
  try {
@@ -8711,7 +8714,8 @@ function readRegistryValue(keyPath, valueName) {
8711
8714
  }
8712
8715
  const [error, output] = catchError(() => execFileSync2("reg", ["query", keyPath, "/v", valueName], {
8713
8716
  encoding: "utf-8",
8714
- stdio: ["pipe", "pipe", "pipe"]
8717
+ stdio: ["pipe", "pipe", "pipe"],
8718
+ windowsHide: true
8715
8719
  }));
8716
8720
  if (error) {
8717
8721
  return "";
@@ -9207,6 +9211,7 @@ class TelemetryService {
9207
9211
  }
9208
9212
  }
9209
9213
  // ../common/src/timings.ts
9214
+ init_src();
9210
9215
  var TIMINGS_ENV_VAR = "UIP_TIMINGS";
9211
9216
  function createStorage2() {
9212
9217
  const [error, mod] = catchError(() => __require("node:async_hooks"));
@@ -9394,28 +9399,32 @@ function isPlainRecord(value) {
9394
9399
  const prototype = Object.getPrototypeOf(value);
9395
9400
  return prototype === Object.prototype || prototype === null;
9396
9401
  }
9397
- function extractPagedRows(value) {
9402
+ function splitPagedEnvelope(value) {
9398
9403
  if (Array.isArray(value) || !isPlainRecord(value))
9399
9404
  return null;
9400
- const entries = Object.values(value);
9405
+ const entries = Object.entries(value);
9401
9406
  if (entries.length === 0)
9402
9407
  return null;
9403
- let rows = null;
9404
- let hasScalarSibling = false;
9405
- for (const entry of entries) {
9408
+ let found = null;
9409
+ const meta = Object.create(null);
9410
+ for (const [key, entry] of entries) {
9406
9411
  if (Array.isArray(entry)) {
9407
- if (rows !== null)
9412
+ if (found !== null)
9408
9413
  return null;
9409
- rows = entry;
9414
+ found = { key, rows: entry };
9410
9415
  } else if (entry !== null && typeof entry === "object") {
9411
9416
  return null;
9412
9417
  } else {
9413
- hasScalarSibling = true;
9418
+ meta[key] = entry;
9414
9419
  }
9415
9420
  }
9416
- if (rows === null || !hasScalarSibling)
9421
+ if (found === null || Object.keys(meta).length === 0)
9417
9422
  return null;
9418
- return rows;
9423
+ return { ...found, meta };
9424
+ }
9425
+ function extractPagedRows(value) {
9426
+ const paged = splitPagedEnvelope(value);
9427
+ return paged === null ? null : paged.rows;
9419
9428
  }
9420
9429
  function toLowerCamelCaseKey(key) {
9421
9430
  if (!key)
@@ -9519,6 +9528,9 @@ function printOutput(data, format = "json", logFn, asciiSafe = false, tableRowSt
9519
9528
  }
9520
9529
  break;
9521
9530
  }
9531
+ case "markdown":
9532
+ logFn(renderMarkdown(data));
9533
+ break;
9522
9534
  default: {
9523
9535
  const hasData = "Data" in data && data.Data != null;
9524
9536
  const pagedRows = hasData ? extractPagedRows(data.Data) : null;
@@ -9543,6 +9555,10 @@ function logOutput(data, format = "json", tableRowStyle) {
9543
9555
  printOutput(data, format, (msg) => sink.writeOut(`${msg}
9544
9556
  `), needsAsciiSafeJson(sink), styleFn);
9545
9557
  }
9558
+ var PLUMBING_KEYS = new Set(["code", "log"]);
9559
+ function isPlumbingKey(key) {
9560
+ return PLUMBING_KEYS.has(key.toLowerCase());
9561
+ }
9546
9562
  function cellToString(val) {
9547
9563
  return val != null && typeof val === "object" ? JSON.stringify(val) : String(val ?? "");
9548
9564
  }
@@ -9558,7 +9574,7 @@ function wrapText(text, width) {
9558
9574
  function printTable(data, logFn, externalLogValue, tableRowStyle) {
9559
9575
  if (data.length === 0)
9560
9576
  return;
9561
- const keys = Object.keys(data[0]).filter((key) => !["code", "log"].includes(key.toLowerCase()));
9577
+ const keys = Object.keys(data[0]).filter((key) => !isPlumbingKey(key));
9562
9578
  const maxWidths = keys.map((key) => Math.max(key.length, ...data.map((item) => cellToString(item[key]).length)));
9563
9579
  const header = keys.map((key, i) => key.padEnd(maxWidths[i])).join(" | ");
9564
9580
  logFn(header);
@@ -9580,7 +9596,7 @@ function isNonEmptyPlainObject(value) {
9580
9596
  }
9581
9597
  var NESTED_INDENT = " ";
9582
9598
  function printVerticalTable(data, logFn = console.log, externalLogValue) {
9583
- const keys = Object.keys(data).filter((key) => !["code", "log"].includes(key.toLowerCase()));
9599
+ const keys = Object.keys(data).filter((key) => !isPlumbingKey(key));
9584
9600
  if (keys.length === 0)
9585
9601
  return;
9586
9602
  const isBlockValue = (value) => isPlainObjectArray(value) || isNonEmptyPlainObject(value);
@@ -9611,7 +9627,7 @@ function printVerticalTable(data, logFn = console.log, externalLogValue) {
9611
9627
  function printResizableTable(data, logFn = console.log, externalLogValue, availableWidth, tableRowStyle) {
9612
9628
  if (data.length === 0)
9613
9629
  return;
9614
- const keys = Object.keys(data[0]).filter((key) => !["code", "log"].includes(key.toLowerCase()));
9630
+ const keys = Object.keys(data[0]).filter((key) => !isPlumbingKey(key));
9615
9631
  if (keys.length === 0)
9616
9632
  return;
9617
9633
  if (!process.stdout.isTTY) {
@@ -9685,6 +9701,220 @@ function printResizableTable(data, logFn = console.log, externalLogValue, availa
9685
9701
  logFn(`Log: ${externalLogValue}`);
9686
9702
  }
9687
9703
  }
9704
+ var MARKDOWN_MAX_CELL = 200;
9705
+ var MARKDOWN_MAX_DEPTH = 3;
9706
+ function markdownHeading(depth) {
9707
+ return "#".repeat(Math.min(3 + depth, 6));
9708
+ }
9709
+ var BACKTICK_RUN = /`+/g;
9710
+ function fencedBlock(text) {
9711
+ const first = text.trimStart()[0];
9712
+ const language = first === "<" ? "xml" : first === "{" || first === "[" ? "json" : "";
9713
+ const longestRun = Math.max(0, ...Array.from(text.matchAll(BACKTICK_RUN), (match) => match[0].length));
9714
+ const fence = "`".repeat(Math.max(3, longestRun + 1));
9715
+ return `${fence}${language}
9716
+ ${text}
9717
+ ${fence}`;
9718
+ }
9719
+ function collapseNewlineRuns(text) {
9720
+ return text.split(/(\s+)/).map((part, index) => index % 2 === 1 && part.includes(`
9721
+ `) ? " " : part).join("");
9722
+ }
9723
+ function markdownCell(value) {
9724
+ const text = value instanceof Date ? value.toISOString() : cellToString(value);
9725
+ return collapseNewlineRuns(text).replace(/\|/g, "\\|");
9726
+ }
9727
+ function markdownLabel(key) {
9728
+ return collapseNewlineRuns(key).replace(/[\\`*|]/g, "\\$&");
9729
+ }
9730
+ function withoutPlumbing(record) {
9731
+ const kept = Object.create(null);
9732
+ for (const [key, value] of Object.entries(record)) {
9733
+ if (!isPlumbingKey(key))
9734
+ kept[key] = value;
9735
+ }
9736
+ return kept;
9737
+ }
9738
+ function rowsWithoutPlumbing(rows) {
9739
+ return rows.map((row) => isPlainRecord(row) ? withoutPlumbing(row) : row);
9740
+ }
9741
+ function markdownTable(rows) {
9742
+ const columns = [];
9743
+ const seen = new Set;
9744
+ for (const row of rows) {
9745
+ for (const key of Object.keys(row)) {
9746
+ if (!seen.has(key)) {
9747
+ seen.add(key);
9748
+ columns.push(key);
9749
+ }
9750
+ }
9751
+ }
9752
+ if (columns.length === 0)
9753
+ return null;
9754
+ const cells = rows.map((row) => columns.map((key) => markdownCell(row[key])));
9755
+ if (cells.some((row) => row.some((c) => c.length > MARKDOWN_MAX_CELL))) {
9756
+ return null;
9757
+ }
9758
+ return [
9759
+ `| ${columns.map(markdownLabel).join(" | ")} |`,
9760
+ `| ${columns.map(() => "---").join(" | ")} |`,
9761
+ ...cells.map((row) => `| ${row.join(" | ")} |`)
9762
+ ].join(`
9763
+ `);
9764
+ }
9765
+ function extractMessageSequence(rows) {
9766
+ const messages = [];
9767
+ for (const row of rows) {
9768
+ const message = extractSingleMessage(row);
9769
+ if (message === null)
9770
+ return null;
9771
+ messages.push(message);
9772
+ }
9773
+ return messages.join(`
9774
+
9775
+ `);
9776
+ }
9777
+ function markdownRows(rows, depth) {
9778
+ if (rows.length === 0)
9779
+ return "(none)";
9780
+ if (!isPlainObjectArray(rows)) {
9781
+ return rows.map((item) => `- ${markdownCell(item)}`).join(`
9782
+ `);
9783
+ }
9784
+ const prose = extractMessageSequence(rows);
9785
+ if (prose !== null)
9786
+ return prose;
9787
+ const table = markdownTable(rows);
9788
+ if (table !== null)
9789
+ return table;
9790
+ if (depth >= MARKDOWN_MAX_DEPTH) {
9791
+ return fencedBlock(JSON.stringify(rows, null, 2));
9792
+ }
9793
+ return rows.map((row, index) => [
9794
+ `${markdownHeading(depth)} ${index + 1}`,
9795
+ markdownObject(row, depth + 1)
9796
+ ].join(`
9797
+
9798
+ `)).join(`
9799
+
9800
+ `);
9801
+ }
9802
+ function markdownObject(obj, depth) {
9803
+ const scalars = [];
9804
+ const blocks = [];
9805
+ for (const [key, value] of Object.entries(obj)) {
9806
+ if (value === undefined)
9807
+ continue;
9808
+ const label = markdownLabel(key);
9809
+ if (Array.isArray(value)) {
9810
+ blocks.push(`${markdownHeading(depth)} ${label}
9811
+
9812
+ ${markdownRows(value, depth + 1)}`);
9813
+ } else if (isNonEmptyPlainObject(value)) {
9814
+ const nested = depth < MARKDOWN_MAX_DEPTH ? markdownObject(value, depth + 1) : fencedBlock(JSON.stringify(value, null, 2));
9815
+ if (nested !== "") {
9816
+ blocks.push(`${markdownHeading(depth)} ${label}
9817
+
9818
+ ${nested}`);
9819
+ }
9820
+ } else if (typeof value === "string" && value.includes(`
9821
+ `)) {
9822
+ blocks.push(`**${label}:**
9823
+
9824
+ ${fencedBlock(value)}`);
9825
+ } else {
9826
+ scalars.push(`**${label}:** ${markdownCell(value)}`);
9827
+ }
9828
+ }
9829
+ const sections = scalars.length > 0 ? [scalars.join(`
9830
+ `)] : [];
9831
+ sections.push(...blocks);
9832
+ return sections.join(`
9833
+
9834
+ `);
9835
+ }
9836
+ function extractSingleMessage(payload) {
9837
+ if (!isPlainRecord(payload))
9838
+ return null;
9839
+ const keys = Object.keys(payload);
9840
+ if (keys.length !== 1 || keys[0].toLowerCase() !== "message")
9841
+ return null;
9842
+ const value = payload[keys[0]];
9843
+ return typeof value === "string" ? value : null;
9844
+ }
9845
+ function markdownPayload(payload) {
9846
+ const message = extractSingleMessage(payload);
9847
+ if (message !== null)
9848
+ return message;
9849
+ if (Array.isArray(payload)) {
9850
+ return markdownRows(rowsWithoutPlumbing(payload), 0);
9851
+ }
9852
+ const visible = withoutPlumbing(payload);
9853
+ const paged = splitPagedEnvelope(visible);
9854
+ if (paged !== null) {
9855
+ const meta = markdownObject(paged.meta, 0);
9856
+ const rows = `${markdownHeading(0)} ${markdownLabel(paged.key)}
9857
+
9858
+ ${markdownRows(rowsWithoutPlumbing(paged.rows), 1)}`;
9859
+ return meta === "" ? rows : `${meta}
9860
+
9861
+ ${rows}`;
9862
+ }
9863
+ return markdownObject(visible, 0);
9864
+ }
9865
+ function isPaginationWorthShowing(value) {
9866
+ if (typeof value !== "object" || value === null)
9867
+ return false;
9868
+ const page = value;
9869
+ return page.HasMore === true || typeof page.Offset === "number" && page.Offset > 0;
9870
+ }
9871
+ function markdownEnvelopeNotes(data) {
9872
+ const envelope = data;
9873
+ const notes = [];
9874
+ const warning = envelope.Warning;
9875
+ if (typeof warning === "string" && warning !== "") {
9876
+ notes.push(`> **Warning:** ${warning}`);
9877
+ }
9878
+ const instructions = envelope.Instructions;
9879
+ if (typeof instructions === "string" && instructions !== "") {
9880
+ notes.push(`> ${instructions}`);
9881
+ }
9882
+ const pagination = envelope.Pagination;
9883
+ if (isPaginationWorthShowing(pagination)) {
9884
+ const body = markdownObject(pagination, 1);
9885
+ if (body !== "") {
9886
+ notes.push(`${markdownHeading(0)} Pagination
9887
+
9888
+ ${body}`);
9889
+ }
9890
+ }
9891
+ const log = envelope.Log;
9892
+ if (typeof log === "string" && log !== "") {
9893
+ notes.push(`**Log:** ${log}`);
9894
+ }
9895
+ return notes;
9896
+ }
9897
+ function renderMarkdown(data) {
9898
+ if (data.Result !== RESULTS.Success) {
9899
+ const failure = data;
9900
+ const sections = [`**Failed:** ${failure.Message}`];
9901
+ if (failure.Data != null) {
9902
+ sections.push(markdownPayload(failure.Data));
9903
+ }
9904
+ if (failure.Instructions) {
9905
+ sections.push(`> ${failure.Instructions}`);
9906
+ }
9907
+ return sections.filter((section) => section !== "").join(`
9908
+
9909
+ `);
9910
+ }
9911
+ if (!("Data" in data) || data.Data == null) {
9912
+ return markdownObject(withoutPlumbing(data), 0);
9913
+ }
9914
+ return [markdownPayload(data.Data), ...markdownEnvelopeNotes(data)].filter((section) => section !== "").join(`
9915
+
9916
+ `);
9917
+ }
9688
9918
  function toYaml(data) {
9689
9919
  const codec = getYamlCodec();
9690
9920
  if (!codec) {
@@ -11466,16 +11696,7 @@ var resolveEnvFilePathAsync = async (envFilePath = DEFAULT_ENV_FILENAME, opts) =
11466
11696
  errorMessage: location.source === "absolute" ? `Environment file not found: ${envFilePath}` : `Unable to locate environment file: ${envFilePath}. Run 'uip login' to authenticate.`
11467
11697
  };
11468
11698
  };
11469
- var loadEnvFileAsync = async ({ envPath }) => {
11470
- const fs7 = getFileSystem();
11471
- const absolutePath = fs7.path.isAbsolute(envPath) ? envPath : fs7.path.join(fs7.env.cwd(), envPath);
11472
- if (!await fs7.exists(absolutePath)) {
11473
- throw new Error(`Environment file not found: ${envPath}`);
11474
- }
11475
- const content = await fs7.readFile(absolutePath, "utf-8");
11476
- if (content === null) {
11477
- throw new Error(`Environment file not found: ${envPath}`);
11478
- }
11699
+ var parseEnvContent = (content) => {
11479
11700
  const env = {};
11480
11701
  for (const line of content.split(`
11481
11702
  `)) {
@@ -11496,6 +11717,18 @@ var loadEnvFileAsync = async ({ envPath }) => {
11496
11717
  }
11497
11718
  return env;
11498
11719
  };
11720
+ var loadEnvFileAsync = async ({ envPath }) => {
11721
+ const fs7 = getFileSystem();
11722
+ const absolutePath = fs7.path.isAbsolute(envPath) ? envPath : fs7.path.join(fs7.env.cwd(), envPath);
11723
+ if (!await fs7.exists(absolutePath)) {
11724
+ throw new Error(`Environment file not found: ${envPath}`);
11725
+ }
11726
+ const content = await fs7.readFile(absolutePath, "utf-8");
11727
+ if (content === null) {
11728
+ throw new Error(`Environment file not found: ${envPath}`);
11729
+ }
11730
+ return parseEnvContent(content);
11731
+ };
11499
11732
  var saveEnvFileAsync = async ({
11500
11733
  envPath,
11501
11734
  data,
@@ -12034,6 +12267,8 @@ var getAuthEnv = async (options = {}) => {
12034
12267
  }
12035
12268
  return { authEnv, loginStatus: status };
12036
12269
  };
12270
+ // ../auth/src/authProfileDetails.ts
12271
+ init_src();
12037
12272
  // ../auth/src/index.ts
12038
12273
  init_constants();
12039
12274
 
@@ -12111,7 +12346,8 @@ var fail = (reason, message, instructions, extras = {}) => ({
12111
12346
  async function runUipathPythonCommand(args, options = {}) {
12112
12347
  const fs7 = getFileSystem();
12113
12348
  const cacheFile = fs7.path.join(fs7.env.homedir(), UIPATH_HOME_DIR, getCacheFileName());
12114
- const setupHint = `Run 'uip ${options.commandPrefix ?? "codedagent"} setup' first to configure the environment. ` + "If you are using a virtual environment, activate it first.";
12349
+ const setupCommand = `uip ${options.commandPrefix ?? "codedagent"} setup`;
12350
+ const setupHint = `Run '${setupCommand}' first to configure the environment. ` + `Activate the project's virtual environment and run ${setupCommand} --force.`;
12115
12351
  const cache = await readCache(cacheFile);
12116
12352
  if (!cache?.uipathExePath) {
12117
12353
  return fail("python_not_configured", "Python not configured.", setupHint);
@@ -12261,67 +12497,42 @@ class PythonService {
12261
12497
  return result;
12262
12498
  }
12263
12499
  async _setupInternal(packageName, force) {
12264
- const fs7 = getFileSystem();
12265
- let pythonPath;
12266
- let version;
12500
+ const virtualEnv = process.env.VIRTUAL_ENV || undefined;
12267
12501
  if (!force) {
12268
- logger.debug("Checking cache...");
12269
- const cached = await this.loadCache();
12270
- if (cached?.uipathExePath && await fs7.exists(cached.uipathExePath)) {
12271
- pythonPath = cached.pythonPath;
12272
- version = cached.version;
12273
- this.uipathExePath = cached.uipathExePath;
12274
- logger.info(`Using cached uipath executable: ${this.uipathExePath}`);
12275
- this.packageVersion = cached.packageVersion;
12276
- if (!this.packageVersion) {
12277
- const versionResult2 = await this.getUipathVersion(this.uipathExePath);
12278
- if ("error" in versionResult2) {
12279
- return {
12280
- success: false,
12281
- pythonPath,
12282
- pythonVersion: version,
12283
- packageInstalled: true,
12284
- error: versionResult2.error
12285
- };
12286
- }
12287
- this.packageVersion = versionResult2.version;
12288
- }
12289
- await this.saveCache({
12290
- pythonPath,
12291
- version,
12292
- lastValidated: new Date().toISOString(),
12293
- packageName,
12294
- uipathExePath: this.uipathExePath,
12295
- packageVersion: this.packageVersion
12296
- });
12297
- return {
12298
- success: true,
12299
- pythonPath,
12300
- pythonVersion: version,
12301
- packageInstalled: true,
12302
- packageVersion: this.packageVersion
12303
- };
12304
- } else if (cached) {
12305
- logger.warn("Cached Python path no longer exists, re-detecting...");
12306
- }
12502
+ const reused = await this.reuseCache(packageName, virtualEnv);
12503
+ if (reused)
12504
+ return reused;
12307
12505
  }
12308
12506
  logger.info("Checking Python...");
12309
- const detection = await this.detectPython();
12507
+ const detection = virtualEnv ? await this.detectVenvPython(virtualEnv) : await this.detectPython();
12310
12508
  if (!detection.success || !detection.pythonPath || !detection.version) {
12311
12509
  return {
12312
12510
  success: false,
12313
12511
  error: detection.error || "Failed to detect Python"
12314
12512
  };
12315
12513
  }
12316
- pythonPath = detection.pythonPath;
12317
- version = detection.version;
12514
+ const pythonPath = detection.pythonPath;
12515
+ const version = detection.version;
12516
+ const source = detection.source ?? "path";
12318
12517
  this.uipathExePath = detection.uipathExePath;
12319
12518
  if (!this.uipathExePath) {
12519
+ if (virtualEnv) {
12520
+ return {
12521
+ success: false,
12522
+ pythonPath,
12523
+ pythonVersion: version,
12524
+ packageInstalled: false,
12525
+ source,
12526
+ error: `Package '${packageName}' is not installed in the active virtual environment: ${virtualEnv}`,
12527
+ instructions: `Install it inside the active virtual environment (uv pip install ${packageName} or the framework package), then re-run uip codedagent setup --force.`
12528
+ };
12529
+ }
12320
12530
  return {
12321
12531
  success: false,
12322
12532
  pythonPath,
12323
12533
  pythonVersion: version,
12324
12534
  packageInstalled: false,
12535
+ source,
12325
12536
  error: `Package '${packageName}' is not installed.
12326
12537
 
12327
12538
  To install the package, run:
@@ -12335,6 +12546,8 @@ To install the package, run:
12335
12546
  pythonPath,
12336
12547
  pythonVersion: version,
12337
12548
  packageInstalled: true,
12549
+ uipathExePath: this.uipathExePath,
12550
+ source,
12338
12551
  error: versionResult.error
12339
12552
  };
12340
12553
  }
@@ -12345,14 +12558,104 @@ To install the package, run:
12345
12558
  lastValidated: new Date().toISOString(),
12346
12559
  packageName,
12347
12560
  uipathExePath: this.uipathExePath,
12348
- packageVersion: this.packageVersion
12561
+ packageVersion: this.packageVersion,
12562
+ source
12349
12563
  });
12350
12564
  return {
12351
12565
  success: true,
12352
12566
  pythonPath,
12353
12567
  pythonVersion: version,
12354
12568
  packageInstalled: true,
12355
- packageVersion: this.packageVersion
12569
+ packageVersion: this.packageVersion,
12570
+ uipathExePath: this.uipathExePath,
12571
+ source
12572
+ };
12573
+ }
12574
+ async reuseCache(packageName, virtualEnv) {
12575
+ const fs7 = getFileSystem();
12576
+ logger.debug("Checking cache...");
12577
+ const cached = await this.loadCache();
12578
+ if (!cached)
12579
+ return null;
12580
+ if (!cached.uipathExePath || !await fs7.exists(cached.uipathExePath)) {
12581
+ logger.warn("Cached Python path no longer exists, re-detecting...");
12582
+ return null;
12583
+ }
12584
+ if (virtualEnv && !isPathInside(cached.uipathExePath, virtualEnv)) {
12585
+ logger.warn(`Cached uipath executable ${cached.uipathExePath} is outside the active virtual environment ${virtualEnv}, re-detecting...`);
12586
+ return null;
12587
+ }
12588
+ const pythonPath = cached.pythonPath;
12589
+ const version = cached.version;
12590
+ this.uipathExePath = cached.uipathExePath;
12591
+ const source = cached.source ?? (virtualEnv ? "venv" : "path");
12592
+ logger.info(`Using cached uipath executable: ${this.uipathExePath}`);
12593
+ this.packageVersion = cached.packageVersion;
12594
+ if (!this.packageVersion) {
12595
+ const versionResult = await this.getUipathVersion(this.uipathExePath);
12596
+ if ("error" in versionResult) {
12597
+ return {
12598
+ success: false,
12599
+ pythonPath,
12600
+ pythonVersion: version,
12601
+ packageInstalled: true,
12602
+ uipathExePath: this.uipathExePath,
12603
+ source,
12604
+ error: versionResult.error
12605
+ };
12606
+ }
12607
+ this.packageVersion = versionResult.version;
12608
+ }
12609
+ await this.saveCache({
12610
+ pythonPath,
12611
+ version,
12612
+ lastValidated: new Date().toISOString(),
12613
+ packageName,
12614
+ uipathExePath: this.uipathExePath,
12615
+ packageVersion: this.packageVersion,
12616
+ source
12617
+ });
12618
+ return {
12619
+ success: true,
12620
+ pythonPath,
12621
+ pythonVersion: version,
12622
+ packageInstalled: true,
12623
+ packageVersion: this.packageVersion,
12624
+ uipathExePath: this.uipathExePath,
12625
+ source
12626
+ };
12627
+ }
12628
+ async detectVenvPython(virtualEnv) {
12629
+ const fs7 = getFileSystem();
12630
+ const isWindows = platform2() === "win32";
12631
+ const command = isWindows ? fs7.path.join(virtualEnv, "Scripts", "python.exe") : fs7.path.join(virtualEnv, "bin", "python");
12632
+ const checkedVersions = [];
12633
+ const searchedCommands = [];
12634
+ const version = await this.checkPythonVersion(command, [], checkedVersions, searchedCommands);
12635
+ if (!version) {
12636
+ return {
12637
+ success: false,
12638
+ error: this.buildNotFoundError(checkedVersions, searchedCommands)
12639
+ };
12640
+ }
12641
+ const metadataPath = await this.findUipathExeFromMetadata(fs7, command, []);
12642
+ let uipathExePath = metadataPath;
12643
+ if (!uipathExePath) {
12644
+ const candidate = isWindows ? fs7.path.join(virtualEnv, "Scripts", "uipath.exe") : fs7.path.join(virtualEnv, "bin", "uipath");
12645
+ logger.debug(`Checking for uipath executable at: ${candidate}`);
12646
+ if (await fs7.exists(candidate)) {
12647
+ logger.info(`Found uipath executable at: ${candidate}`);
12648
+ uipathExePath = candidate;
12649
+ } else {
12650
+ logger.error(`uipath executable not found in virtual environment. Checked: ${candidate}`);
12651
+ }
12652
+ }
12653
+ return {
12654
+ success: true,
12655
+ pythonPath: command,
12656
+ version,
12657
+ uipathExePath,
12658
+ source: "venv"
12356
12659
  };
12357
12660
  }
12358
12661
  async detectPython() {
@@ -12371,6 +12674,20 @@ To install the package, run:
12371
12674
  }
12372
12675
  async checkPythonCommand(command, args, checkedVersions, searchedCommands) {
12373
12676
  const fs7 = getFileSystem();
12677
+ const version = await this.checkPythonVersion(command, args, checkedVersions, searchedCommands);
12678
+ if (!version)
12679
+ return null;
12680
+ const commandStr = args.length > 0 ? `${command} ${args.join(" ")}` : command;
12681
+ const uipathExePath = await this.findUipathExe(fs7, command, args);
12682
+ return {
12683
+ success: true,
12684
+ pythonPath: commandStr,
12685
+ version,
12686
+ uipathExePath,
12687
+ source: "path"
12688
+ };
12689
+ }
12690
+ async checkPythonVersion(command, args, checkedVersions, searchedCommands) {
12374
12691
  const commandStr = args.length > 0 ? `${command} ${args.join(" ")}` : command;
12375
12692
  searchedCommands.push(commandStr);
12376
12693
  logger.debug(`Checking Python command: ${commandStr}`);
@@ -12408,13 +12725,7 @@ To install the package, run:
12408
12725
  return null;
12409
12726
  }
12410
12727
  logger.info(`Found valid Python: ${commandStr} - ${version}`);
12411
- const uipathExePath = await this.findUipathExe(fs7, command, args);
12412
- return {
12413
- success: true,
12414
- pythonPath: commandStr,
12415
- version,
12416
- uipathExePath
12417
- };
12728
+ return version;
12418
12729
  }
12419
12730
  async findUipathExe(fs7, command, args) {
12420
12731
  const metadataPath = await this.findUipathExeFromMetadata(fs7, command, args);
@@ -12452,6 +12763,7 @@ To install the package, run:
12452
12763
  async findUipathExeFromMetadata(fs7, command, args) {
12453
12764
  const script = `
12454
12765
  from importlib.metadata import distribution, PackageNotFoundError
12766
+ import os
12455
12767
  import sys
12456
12768
  try:
12457
12769
  d = distribution("uipath")
@@ -12459,7 +12771,7 @@ except PackageNotFoundError:
12459
12771
  sys.exit(2)
12460
12772
  for f in d.files or []:
12461
12773
  if f.name.lower() in ("uipath", "uipath.exe"):
12462
- print(str(f.locate()))
12774
+ print(os.path.normpath(str(f.locate())))
12463
12775
  sys.exit(0)
12464
12776
  sys.exit(3)
12465
12777
  `;
@@ -12644,6 +12956,17 @@ Please install one of the required Python versions:
12644
12956
  logger.info(`Cache saved to ${this.cacheFile}`);
12645
12957
  }
12646
12958
  }
12959
+ function isPathInside(target, root) {
12960
+ const normalize = (value) => {
12961
+ let normalized = value.replace(/\\/g, "/").replace(/\/+$/, "");
12962
+ if (platform2() === "win32")
12963
+ normalized = normalized.toLowerCase();
12964
+ return normalized;
12965
+ };
12966
+ const normalizedTarget = normalize(target);
12967
+ const normalizedRoot = normalize(root);
12968
+ return normalizedTarget === normalizedRoot || normalizedTarget.startsWith(`${normalizedRoot}/`);
12969
+ }
12647
12970
  // src/register.ts
12648
12971
  init_src();
12649
12972
  function createSetupCommand(config) {
@@ -12694,7 +13017,9 @@ Searching for Python installations: ${allowedVersions}`);
12694
13017
  PythonPath: result.pythonPath,
12695
13018
  Package: packageName,
12696
13019
  PackageInstalled: result.packageInstalled ? "Yes" : "No",
12697
- PackageVersion: result.packageVersion ?? "N/A"
13020
+ PackageVersion: result.packageVersion ?? "N/A",
13021
+ UipathPath: result.uipathExePath,
13022
+ Source: result.source
12698
13023
  }
12699
13024
  });
12700
13025
  processContext.exit(0);
@@ -12740,9 +13065,10 @@ export {
12740
13065
  getAllowedPythonVersions,
12741
13066
  getCacheFileName,
12742
13067
  getPackageName,
13068
+ isPathInside,
12743
13069
  processCommandArgs,
12744
13070
  readCache,
12745
13071
  runUipathPythonCommand
12746
13072
  };
12747
13073
 
12748
- //# debugId=905F4C0FDB5AC82464756E2164756E21
13074
+ //# debugId=219233FAB6B0AA4C64756E2164756E21
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@uipath/uipath-python-bridge",
3
+ "author": "UiPath",
3
4
  "license": "SEE LICENSE IN LICENSE.txt",
4
- "version": "1.202.0-preview.159",
5
+ "version": "1.203.0-preview.160",
5
6
  "description": "Shared Python detection, caching, and CLI bridge for UiPath Python SDK tools.",
6
7
  "keywords": [
7
8
  "uip",
@@ -24,5 +25,5 @@
24
25
  "publishConfig": {
25
26
  "registry": "https://registry.npmjs.org/"
26
27
  },
27
- "gitHead": "a3f23209784c6cec7155e735fa051b48ca49e8d7"
28
+ "gitHead": "3a42062ba731afca4595ba9aa8a80afc9667528d"
28
29
  }