@uipath/llm-gateway-tool 1.202.1-preview.217 → 1.202.1-preview.238

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 +225 -8
  2. package/package.json +2 -2
package/dist/tool.js CHANGED
@@ -2100,7 +2100,7 @@ var require_commander = __commonJS(function(exports) {
2100
2100
  var package_default = {
2101
2101
  name: "@uipath/llm-gateway-tool",
2102
2102
  license: "SEE LICENSE IN LICENSE.txt",
2103
- version: "1.202.1-preview.217",
2103
+ version: "1.202.1-preview.238",
2104
2104
  description: "CLI plugin for UiPath LLM Gateway model discovery.",
2105
2105
  private: false,
2106
2106
  repository: {
@@ -4786,7 +4786,165 @@ class FilterImplicitLimitError extends Error {
4786
4786
  this.instructions = "Pass --limit <n> to choose how many records the filter applies to. " + "To filter over all records, pass the command's maximum accepted --limit (see the option's description in --help).";
4787
4787
  }
4788
4788
  }
4789
- function applyFilter(data, filter) {
4789
+ function countRecords(data) {
4790
+ if (Array.isArray(data))
4791
+ return data.length;
4792
+ return data == null ? 0 : 1;
4793
+ }
4794
+ function availableFields(data) {
4795
+ const records = Array.isArray(data) ? data : [data];
4796
+ const keys = new Set;
4797
+ for (const record of records) {
4798
+ if (record && typeof record === "object" && !Array.isArray(record)) {
4799
+ for (const key of Object.keys(record))
4800
+ keys.add(key);
4801
+ }
4802
+ }
4803
+ return [...keys];
4804
+ }
4805
+ function decodeQuotedIdentifier(whole, inner) {
4806
+ const [error, decoded] = catchError(() => JSON.parse(whole));
4807
+ if (!error && typeof decoded === "string")
4808
+ return decoded;
4809
+ return inner.replace(/\\(.)/g, "$1");
4810
+ }
4811
+ function referencedFields(filter) {
4812
+ const top = new Set;
4813
+ const nested = new Set;
4814
+ const withoutValueLiterals = filter.replace(/'(?:\\.|[^'\\])*'/g, " ").replace(/`(?:\\.|[^`\\])*`/g, " ");
4815
+ const isPathTail = (text, index) => text[index - 1] === "." && /[A-Za-z0-9_"]/.test(text[index - 2] ?? "");
4816
+ const quoted = [];
4817
+ const withoutLiterals = withoutValueLiterals.replace(/"((?:\\.|[^"\\])*)"/g, (whole, name, index) => {
4818
+ const isAlias = /^\s*:/.test(withoutValueLiterals.slice(index + whole.length));
4819
+ if (!isAlias) {
4820
+ quoted.push({
4821
+ name: decodeQuotedIdentifier(whole, name),
4822
+ index,
4823
+ tail: isPathTail(withoutValueLiterals, index)
4824
+ });
4825
+ }
4826
+ return `"${" ".repeat(whole.length - 2)}"`;
4827
+ });
4828
+ const descent = /[A-Za-z0-9_"]\s*[.[]/.exec(withoutLiterals);
4829
+ const rootEnd = descent ? descent.index + 1 : Number.POSITIVE_INFINITY;
4830
+ const place = (name, index, tail) => {
4831
+ if (tail || index >= rootEnd)
4832
+ nested.add(name);
4833
+ else
4834
+ top.add(name);
4835
+ };
4836
+ for (const entry of quoted)
4837
+ place(entry.name, entry.index, entry.tail);
4838
+ const identifiers = withoutLiterals.matchAll(/([A-Za-z_][A-Za-z0-9_]*)(\s*[:(])?/g);
4839
+ const reserved = new Set(["true", "false", "null", "and", "or", "not"]);
4840
+ for (const match of identifiers) {
4841
+ const [, name, trailing] = match;
4842
+ if (trailing || reserved.has(name))
4843
+ continue;
4844
+ place(name, match.index, isPathTail(withoutLiterals, match.index));
4845
+ }
4846
+ return {
4847
+ top: [...top],
4848
+ nested: [...nested].filter((name) => !top.has(name)),
4849
+ hasPredicate: /\[\s*\?/.test(withoutValueLiterals)
4850
+ };
4851
+ }
4852
+ function appearsBelowTopLevel(data, name) {
4853
+ let budget = 2000;
4854
+ const visit = (value, depth) => {
4855
+ if (budget-- <= 0 || depth > 4)
4856
+ return false;
4857
+ if (value === null || typeof value !== "object")
4858
+ return false;
4859
+ if (Array.isArray(value))
4860
+ return value.some((entry) => visit(entry, depth));
4861
+ const record = value;
4862
+ if (depth > 0 && Object.hasOwn(record, name))
4863
+ return true;
4864
+ return Object.values(record).some((entry) => visit(entry, depth + 1));
4865
+ };
4866
+ return visit(data, 0);
4867
+ }
4868
+ function alwaysNullKeys(records) {
4869
+ const objects = records.filter((r) => r != null && typeof r === "object" && !Array.isArray(r));
4870
+ if (objects.length === 0 || objects.length !== records.length)
4871
+ return [];
4872
+ const keys = [...new Set(objects.flatMap((o) => Object.keys(o)))];
4873
+ if (keys.length === 0)
4874
+ return [];
4875
+ const nullKeys = keys.filter((key) => objects.every((record) => record[key] === null));
4876
+ return nullKeys.length === keys.length ? nullKeys : [];
4877
+ }
4878
+ function carriesOnlyNulls(value) {
4879
+ if (value === null)
4880
+ return true;
4881
+ if (Array.isArray(value)) {
4882
+ return value.length > 0 && value.every(carriesOnlyNulls);
4883
+ }
4884
+ if (typeof value === "object" && value !== undefined) {
4885
+ const values = Object.values(value);
4886
+ return values.length > 0 && values.every(carriesOnlyNulls);
4887
+ }
4888
+ return false;
4889
+ }
4890
+ function nameList(names, cap2 = 12) {
4891
+ const shown = names.slice(0, cap2).map((n) => `\`${n}\``);
4892
+ const rest = names.length - shown.length;
4893
+ return shown.join(", ") + (rest > 0 ? `, and ${rest} more` : "");
4894
+ }
4895
+ function buildFilterWarning(filter, data, outcome) {
4896
+ const present = availableFields(data);
4897
+ const refs = referencedFields(filter);
4898
+ const unknown = refs.top.filter((name) => !present.includes(name) && !appearsBelowTopLevel(data, name));
4899
+ const unchecked = refs.nested.filter((name) => !present.includes(name));
4900
+ const count = countRecords(data);
4901
+ const scope = `${count} record(s)`;
4902
+ const isNotAField = (names) => `${nameList(names)} ${names.length === 1 ? "is not a field" : "are not fields"} on the ${scope} it read`;
4903
+ const soundness = unchecked.length > 0 ? `${nameList(unchecked)} ${unchecked.length === 1 ? "reads" : "read"} below the top level, so ${unchecked.length === 1 ? "it was" : "they were"} not checked against the record keys` : refs.top.length > 0 ? "every field it names exists" : "";
4904
+ const withSoundness = (base) => soundness ? `${base}, and ${soundness}` : base;
4905
+ let detail;
4906
+ let lede;
4907
+ if (outcome.kind === "null-elements") {
4908
+ lede = "returned only null values";
4909
+ const projected = `all ${outcome.count} of the elements it projected are null`;
4910
+ if (unknown.length > 0) {
4911
+ detail = `${projected}, because ${isNotAField(unknown)}`;
4912
+ } else if (unchecked.length > 0) {
4913
+ detail = withSoundness(projected);
4914
+ } else {
4915
+ detail = `${projected}, and every field it names exists — a multi-select list ` + `(\`[A, B]\`) reads each entry against \`Data\` itself, so on a list ` + `result use \`[].[A, B]\` or \`[].{a: A, b: B}\` to read the records`;
4916
+ }
4917
+ } else if (outcome.kind === "null-rows") {
4918
+ lede = "returned only null values";
4919
+ const projected = `every value it projected is null on all ${outcome.count} row(s)`;
4920
+ detail = unknown.length > 0 ? `${projected}, because ${isNotAField(unknown)}` : withSoundness(projected);
4921
+ } else if (outcome.kind === "null-values") {
4922
+ lede = "returned only null values";
4923
+ const projected = `every key it projected (${nameList(outcome.keys)}) is null`;
4924
+ const sameSet = unknown.length === outcome.keys.length && outcome.keys.every((k) => unknown.includes(k));
4925
+ if (sameSet) {
4926
+ detail = `${isNotAField(outcome.keys)}, so every key it projected is null`;
4927
+ } else if (unknown.length > 0) {
4928
+ detail = `${projected}, because ${isNotAField(unknown)}`;
4929
+ } else {
4930
+ detail = withSoundness(`${projected} on all ${scope}`);
4931
+ }
4932
+ } else {
4933
+ lede = "returned nothing";
4934
+ if (unknown.length > 0) {
4935
+ detail = isNotAField(unknown);
4936
+ } else {
4937
+ const selection = refs.hasPredicate ? "no record matched" : "the expression resolved to no value";
4938
+ detail = withSoundness(`${selection} — it read ${scope}`);
4939
+ }
4940
+ }
4941
+ const fields = present.length > 0 ? ` Available fields: ${nameList(present)}.` : "";
4942
+ return `--output-filter ${JSON.stringify(filter)} ${lede}: ${detail}.${fields}`;
4943
+ }
4944
+ function appendWarning(existing, note) {
4945
+ return existing ? `${existing} ${note}` : note;
4946
+ }
4947
+ function applyFilter(data, filter, onWarning) {
4790
4948
  const codec = requireJmespath();
4791
4949
  let result;
4792
4950
  try {
@@ -4794,9 +4952,34 @@ function applyFilter(data, filter) {
4794
4952
  } catch (err) {
4795
4953
  throw new FilterEvaluationError(filter, err);
4796
4954
  }
4797
- if (result == null)
4955
+ const inputCount = countRecords(data);
4956
+ const warn = (outcome) => {
4957
+ if (inputCount === 0)
4958
+ return;
4959
+ const note = buildFilterWarning(filter, data, outcome);
4960
+ getOutputSink().writeErr(`[WARN] ${note}
4961
+ `);
4962
+ onWarning?.(note);
4963
+ };
4964
+ const warnIfAllNull = (records) => {
4965
+ const keys = alwaysNullKeys(records);
4966
+ if (keys.length > 0)
4967
+ warn({ kind: "null-values", keys });
4968
+ };
4969
+ if (result == null) {
4970
+ warn({ kind: "empty" });
4798
4971
  return [];
4972
+ }
4799
4973
  if (Array.isArray(result)) {
4974
+ if (result.length === 0) {
4975
+ warn({ kind: "empty" });
4976
+ } else if (result.every((entry) => entry === null)) {
4977
+ warn({ kind: "null-elements", count: result.length });
4978
+ } else if (result.every((entry) => Array.isArray(entry)) && carriesOnlyNulls(result)) {
4979
+ warn({ kind: "null-rows", count: result.length });
4980
+ } else {
4981
+ warnIfAllNull(result);
4982
+ }
4800
4983
  if (result.length > 0 && typeof result[0] !== "object") {
4801
4984
  const fieldMatch = filter.match(/\.(\w+)$/);
4802
4985
  const key = fieldMatch ? fieldMatch[1] : "Value";
@@ -4804,10 +4987,30 @@ function applyFilter(data, filter) {
4804
4987
  }
4805
4988
  return result;
4806
4989
  }
4807
- if (typeof result === "object")
4990
+ if (typeof result === "object") {
4991
+ warnIfAllNull([result]);
4808
4992
  return result;
4993
+ }
4809
4994
  return { Value: result };
4810
4995
  }
4996
+ function filterFailureData(envelope) {
4997
+ const filter = getOutputFilter();
4998
+ const data = envelope.Data;
4999
+ if (!filter || data == null)
5000
+ return;
5001
+ let note;
5002
+ const [filterError, filtered] = catchError(() => applyFilter(data, filter, (n) => {
5003
+ note = n;
5004
+ }));
5005
+ if (filterError) {
5006
+ envelope.Warning = appendWarning(envelope.Warning, `--output-filter was not applied, so Data is shown in full: ${filterError.message}`);
5007
+ return;
5008
+ }
5009
+ envelope.Data = filtered;
5010
+ if (note) {
5011
+ envelope.Warning = appendWarning(envelope.Warning, note);
5012
+ }
5013
+ }
4811
5014
  function defaultErrorCodeForResult(result) {
4812
5015
  switch (result) {
4813
5016
  case RESULTS.AuthenticationError:
@@ -4890,8 +5093,14 @@ var OutputFormatter;
4890
5093
  }
4891
5094
  const filter = getOutputFilter();
4892
5095
  if (filter) {
4893
- const filtered = applyFilter(data.Data, filter);
5096
+ let note;
5097
+ const filtered = applyFilter(data.Data, filter, (n) => {
5098
+ note = n;
5099
+ });
4894
5100
  data.Data = normalize ? normalizeDataKeys(filtered, verbatim, subtrees && { refs: subtrees.refs, mode: "skip" }) : filtered;
5101
+ if (note) {
5102
+ data.Warning = appendWarning(data.Warning, note);
5103
+ }
4895
5104
  }
4896
5105
  logOutput(normalizeOutputKeys(data), getOutputFormat(), options?.tableRowStyle);
4897
5106
  }
@@ -4919,6 +5128,7 @@ var OutputFormatter;
4919
5128
  delete envelope.TelemetryErrorClass;
4920
5129
  delete envelope.TelemetryTerminalOutcome;
4921
5130
  delete envelope.TelemetryTerminalSignal;
5131
+ filterFailureData(envelope);
4922
5132
  if (!suppressTelemetry) {
4923
5133
  telemetry.trackEvent(CommonTelemetryEvents.Error, {
4924
5134
  result: data.Result,
@@ -4967,13 +5177,20 @@ var OutputFormatter;
4967
5177
  OutputFormatter.log = log;
4968
5178
  function formatToString(data) {
4969
5179
  const filter = getOutputFilter();
5180
+ const envelope = data;
4970
5181
  if ("Data" in data && data.Data != null) {
4971
5182
  data.Data = normalizeDataKeys(data.Data);
4972
5183
  if (filter) {
4973
- data.Data = normalizeDataKeys(applyFilter(data.Data, filter));
5184
+ let note;
5185
+ data.Data = normalizeDataKeys(applyFilter(data.Data, filter, (n) => {
5186
+ note = n;
5187
+ }));
5188
+ if (note) {
5189
+ envelope.Warning = appendWarning(envelope.Warning, note);
5190
+ }
4974
5191
  }
4975
5192
  }
4976
- const output = normalizeOutputKeys(data);
5193
+ const output = normalizeOutputKeys(envelope);
4977
5194
  const lines = [];
4978
5195
  const sink = getOutputSink();
4979
5196
  printOutput(output, getOutputFormat(), (msg) => {
@@ -8147,4 +8364,4 @@ export {
8147
8364
  registerCommands
8148
8365
  };
8149
8366
 
8150
- //# debugId=BBC3545233A43F6264756E2164756E21
8367
+ //# debugId=CDEB59F2BE77236564756E2164756E21
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uipath/llm-gateway-tool",
3
3
  "license": "SEE LICENSE IN LICENSE.txt",
4
- "version": "1.202.1-preview.217",
4
+ "version": "1.202.1-preview.238",
5
5
  "description": "CLI plugin for UiPath LLM Gateway model discovery.",
6
6
  "private": false,
7
7
  "repository": {
@@ -23,5 +23,5 @@
23
23
  "files": [
24
24
  "dist"
25
25
  ],
26
- "gitHead": "bd513110d03342230901ece289a303e5a0009404"
26
+ "gitHead": "537e43df1d3583633cfd3a0b88634f9ce3ba9d6b"
27
27
  }