@uipath/llm-gateway-tool 1.203.0-preview.233 → 1.203.0-preview.237

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
@@ -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.203.0-preview.233",
2104
+ version: "1.203.0-preview.237",
2105
2105
  description: "CLI plugin for UiPath LLM Gateway model discovery.",
2106
2106
  private: false,
2107
2107
  repository: {
@@ -5033,7 +5033,165 @@ class FilterImplicitLimitError extends Error {
5033
5033
  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).";
5034
5034
  }
5035
5035
  }
5036
- function applyFilter(data, filter) {
5036
+ function countRecords(data) {
5037
+ if (Array.isArray(data))
5038
+ return data.length;
5039
+ return data == null ? 0 : 1;
5040
+ }
5041
+ function availableFields(data) {
5042
+ const records = Array.isArray(data) ? data : [data];
5043
+ const keys = new Set;
5044
+ for (const record of records) {
5045
+ if (record && typeof record === "object" && !Array.isArray(record)) {
5046
+ for (const key of Object.keys(record))
5047
+ keys.add(key);
5048
+ }
5049
+ }
5050
+ return [...keys];
5051
+ }
5052
+ function decodeQuotedIdentifier(whole, inner) {
5053
+ const [error, decoded] = catchError(() => JSON.parse(whole));
5054
+ if (!error && typeof decoded === "string")
5055
+ return decoded;
5056
+ return inner.replace(/\\(.)/g, "$1");
5057
+ }
5058
+ function referencedFields(filter) {
5059
+ const top = new Set;
5060
+ const nested = new Set;
5061
+ const withoutValueLiterals = filter.replace(/'(?:\\.|[^'\\])*'/g, " ").replace(/`(?:\\.|[^`\\])*`/g, " ");
5062
+ const isPathTail = (text, index) => text[index - 1] === "." && /[A-Za-z0-9_"]/.test(text[index - 2] ?? "");
5063
+ const quoted = [];
5064
+ const withoutLiterals = withoutValueLiterals.replace(/"((?:\\.|[^"\\])*)"/g, (whole, name, index) => {
5065
+ const isAlias = /^\s*:/.test(withoutValueLiterals.slice(index + whole.length));
5066
+ if (!isAlias) {
5067
+ quoted.push({
5068
+ name: decodeQuotedIdentifier(whole, name),
5069
+ index,
5070
+ tail: isPathTail(withoutValueLiterals, index)
5071
+ });
5072
+ }
5073
+ return `"${" ".repeat(whole.length - 2)}"`;
5074
+ });
5075
+ const descent = /[A-Za-z0-9_"]\s*[.[]/.exec(withoutLiterals);
5076
+ const rootEnd = descent ? descent.index + 1 : Number.POSITIVE_INFINITY;
5077
+ const place = (name, index, tail) => {
5078
+ if (tail || index >= rootEnd)
5079
+ nested.add(name);
5080
+ else
5081
+ top.add(name);
5082
+ };
5083
+ for (const entry of quoted)
5084
+ place(entry.name, entry.index, entry.tail);
5085
+ const identifiers = withoutLiterals.matchAll(/([A-Za-z_][A-Za-z0-9_]*)(\s*[:(])?/g);
5086
+ const reserved = new Set(["true", "false", "null", "and", "or", "not"]);
5087
+ for (const match of identifiers) {
5088
+ const [, name, trailing] = match;
5089
+ if (trailing || reserved.has(name))
5090
+ continue;
5091
+ place(name, match.index, isPathTail(withoutLiterals, match.index));
5092
+ }
5093
+ return {
5094
+ top: [...top],
5095
+ nested: [...nested].filter((name) => !top.has(name)),
5096
+ hasPredicate: /\[\s*\?/.test(withoutValueLiterals)
5097
+ };
5098
+ }
5099
+ function appearsBelowTopLevel(data, name) {
5100
+ let budget = 2000;
5101
+ const visit = (value, depth) => {
5102
+ if (budget-- <= 0 || depth > 4)
5103
+ return false;
5104
+ if (value === null || typeof value !== "object")
5105
+ return false;
5106
+ if (Array.isArray(value))
5107
+ return value.some((entry) => visit(entry, depth));
5108
+ const record = value;
5109
+ if (depth > 0 && Object.hasOwn(record, name))
5110
+ return true;
5111
+ return Object.values(record).some((entry) => visit(entry, depth + 1));
5112
+ };
5113
+ return visit(data, 0);
5114
+ }
5115
+ function alwaysNullKeys(records) {
5116
+ const objects = records.filter((r) => r != null && typeof r === "object" && !Array.isArray(r));
5117
+ if (objects.length === 0 || objects.length !== records.length)
5118
+ return [];
5119
+ const keys = [...new Set(objects.flatMap((o) => Object.keys(o)))];
5120
+ if (keys.length === 0)
5121
+ return [];
5122
+ const nullKeys = keys.filter((key) => objects.every((record) => record[key] === null));
5123
+ return nullKeys.length === keys.length ? nullKeys : [];
5124
+ }
5125
+ function carriesOnlyNulls(value) {
5126
+ if (value === null)
5127
+ return true;
5128
+ if (Array.isArray(value)) {
5129
+ return value.length > 0 && value.every(carriesOnlyNulls);
5130
+ }
5131
+ if (typeof value === "object" && value !== undefined) {
5132
+ const values = Object.values(value);
5133
+ return values.length > 0 && values.every(carriesOnlyNulls);
5134
+ }
5135
+ return false;
5136
+ }
5137
+ function nameList(names, cap2 = 12) {
5138
+ const shown = names.slice(0, cap2).map((n) => `\`${n}\``);
5139
+ const rest = names.length - shown.length;
5140
+ return shown.join(", ") + (rest > 0 ? `, and ${rest} more` : "");
5141
+ }
5142
+ function buildFilterWarning(filter, data, outcome) {
5143
+ const present = availableFields(data);
5144
+ const refs = referencedFields(filter);
5145
+ const unknown = refs.top.filter((name) => !present.includes(name) && !appearsBelowTopLevel(data, name));
5146
+ const unchecked = refs.nested.filter((name) => !present.includes(name));
5147
+ const count = countRecords(data);
5148
+ const scope = `${count} record(s)`;
5149
+ const isNotAField = (names) => `${nameList(names)} ${names.length === 1 ? "is not a field" : "are not fields"} on the ${scope} it read`;
5150
+ 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" : "";
5151
+ const withSoundness = (base) => soundness ? `${base}, and ${soundness}` : base;
5152
+ let detail;
5153
+ let lede;
5154
+ if (outcome.kind === "null-elements") {
5155
+ lede = "returned only null values";
5156
+ const projected = `all ${outcome.count} of the elements it projected are null`;
5157
+ if (unknown.length > 0) {
5158
+ detail = `${projected}, because ${isNotAField(unknown)}`;
5159
+ } else if (unchecked.length > 0) {
5160
+ detail = withSoundness(projected);
5161
+ } else {
5162
+ 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`;
5163
+ }
5164
+ } else if (outcome.kind === "null-rows") {
5165
+ lede = "returned only null values";
5166
+ const projected = `every value it projected is null on all ${outcome.count} row(s)`;
5167
+ detail = unknown.length > 0 ? `${projected}, because ${isNotAField(unknown)}` : withSoundness(projected);
5168
+ } else if (outcome.kind === "null-values") {
5169
+ lede = "returned only null values";
5170
+ const projected = `every key it projected (${nameList(outcome.keys)}) is null`;
5171
+ const sameSet = unknown.length === outcome.keys.length && outcome.keys.every((k) => unknown.includes(k));
5172
+ if (sameSet) {
5173
+ detail = `${isNotAField(outcome.keys)}, so every key it projected is null`;
5174
+ } else if (unknown.length > 0) {
5175
+ detail = `${projected}, because ${isNotAField(unknown)}`;
5176
+ } else {
5177
+ detail = withSoundness(`${projected} on all ${scope}`);
5178
+ }
5179
+ } else {
5180
+ lede = "returned nothing";
5181
+ if (unknown.length > 0) {
5182
+ detail = isNotAField(unknown);
5183
+ } else {
5184
+ const selection = refs.hasPredicate ? "no record matched" : "the expression resolved to no value";
5185
+ detail = withSoundness(`${selection} — it read ${scope}`);
5186
+ }
5187
+ }
5188
+ const fields = present.length > 0 ? ` Available fields: ${nameList(present)}.` : "";
5189
+ return `--output-filter ${JSON.stringify(filter)} ${lede}: ${detail}.${fields}`;
5190
+ }
5191
+ function appendWarning(existing, note) {
5192
+ return existing ? `${existing} ${note}` : note;
5193
+ }
5194
+ function applyFilter(data, filter, onWarning) {
5037
5195
  const codec = requireJmespath();
5038
5196
  let result;
5039
5197
  try {
@@ -5041,9 +5199,34 @@ function applyFilter(data, filter) {
5041
5199
  } catch (err) {
5042
5200
  throw new FilterEvaluationError(filter, err);
5043
5201
  }
5044
- if (result == null)
5202
+ const inputCount = countRecords(data);
5203
+ const warn = (outcome) => {
5204
+ if (inputCount === 0)
5205
+ return;
5206
+ const note = buildFilterWarning(filter, data, outcome);
5207
+ getOutputSink().writeErr(`[WARN] ${note}
5208
+ `);
5209
+ onWarning?.(note);
5210
+ };
5211
+ const warnIfAllNull = (records) => {
5212
+ const keys = alwaysNullKeys(records);
5213
+ if (keys.length > 0)
5214
+ warn({ kind: "null-values", keys });
5215
+ };
5216
+ if (result == null) {
5217
+ warn({ kind: "empty" });
5045
5218
  return [];
5219
+ }
5046
5220
  if (Array.isArray(result)) {
5221
+ if (result.length === 0) {
5222
+ warn({ kind: "empty" });
5223
+ } else if (result.every((entry) => entry === null)) {
5224
+ warn({ kind: "null-elements", count: result.length });
5225
+ } else if (result.every((entry) => Array.isArray(entry)) && carriesOnlyNulls(result)) {
5226
+ warn({ kind: "null-rows", count: result.length });
5227
+ } else {
5228
+ warnIfAllNull(result);
5229
+ }
5047
5230
  if (result.length > 0 && typeof result[0] !== "object") {
5048
5231
  const fieldMatch = filter.match(/\.(\w+)$/);
5049
5232
  const key = fieldMatch ? fieldMatch[1] : "Value";
@@ -5051,10 +5234,30 @@ function applyFilter(data, filter) {
5051
5234
  }
5052
5235
  return result;
5053
5236
  }
5054
- if (typeof result === "object")
5237
+ if (typeof result === "object") {
5238
+ warnIfAllNull([result]);
5055
5239
  return result;
5240
+ }
5056
5241
  return { Value: result };
5057
5242
  }
5243
+ function filterFailureData(envelope) {
5244
+ const filter = getOutputFilter();
5245
+ const data = envelope.Data;
5246
+ if (!filter || data == null)
5247
+ return;
5248
+ let note;
5249
+ const [filterError, filtered] = catchError(() => applyFilter(data, filter, (n) => {
5250
+ note = n;
5251
+ }));
5252
+ if (filterError) {
5253
+ envelope.Warning = appendWarning(envelope.Warning, `--output-filter was not applied, so Data is shown in full: ${filterError.message}`);
5254
+ return;
5255
+ }
5256
+ envelope.Data = filtered;
5257
+ if (note) {
5258
+ envelope.Warning = appendWarning(envelope.Warning, note);
5259
+ }
5260
+ }
5058
5261
  function defaultErrorCodeForResult(result) {
5059
5262
  switch (result) {
5060
5263
  case RESULTS.AuthenticationError:
@@ -5137,8 +5340,14 @@ var OutputFormatter;
5137
5340
  }
5138
5341
  const filter = getOutputFilter();
5139
5342
  if (filter) {
5140
- const filtered = applyFilter(data.Data, filter);
5343
+ let note;
5344
+ const filtered = applyFilter(data.Data, filter, (n) => {
5345
+ note = n;
5346
+ });
5141
5347
  data.Data = normalize ? normalizeDataKeys(filtered, verbatim, subtrees && { refs: subtrees.refs, mode: "skip" }) : filtered;
5348
+ if (note) {
5349
+ data.Warning = appendWarning(data.Warning, note);
5350
+ }
5142
5351
  }
5143
5352
  logOutput(normalizeOutputKeys(data), getOutputFormat(), options?.tableRowStyle);
5144
5353
  }
@@ -5166,6 +5375,7 @@ var OutputFormatter;
5166
5375
  delete envelope.TelemetryErrorClass;
5167
5376
  delete envelope.TelemetryTerminalOutcome;
5168
5377
  delete envelope.TelemetryTerminalSignal;
5378
+ filterFailureData(envelope);
5169
5379
  if (!suppressTelemetry) {
5170
5380
  telemetry.trackEvent(CommonTelemetryEvents.Error, {
5171
5381
  result: data.Result,
@@ -5214,13 +5424,20 @@ var OutputFormatter;
5214
5424
  OutputFormatter.log = log;
5215
5425
  function formatToString(data) {
5216
5426
  const filter = getOutputFilter();
5427
+ const envelope = data;
5217
5428
  if ("Data" in data && data.Data != null) {
5218
5429
  data.Data = normalizeDataKeys(data.Data);
5219
5430
  if (filter) {
5220
- data.Data = normalizeDataKeys(applyFilter(data.Data, filter));
5431
+ let note;
5432
+ data.Data = normalizeDataKeys(applyFilter(data.Data, filter, (n) => {
5433
+ note = n;
5434
+ }));
5435
+ if (note) {
5436
+ envelope.Warning = appendWarning(envelope.Warning, note);
5437
+ }
5221
5438
  }
5222
5439
  }
5223
- const output = normalizeOutputKeys(data);
5440
+ const output = normalizeOutputKeys(envelope);
5224
5441
  const lines = [];
5225
5442
  const sink = getOutputSink();
5226
5443
  printOutput(output, getOutputFormat(), (msg) => {
@@ -8398,4 +8615,4 @@ export {
8398
8615
  registerCommands
8399
8616
  };
8400
8617
 
8401
- //# debugId=474A898B5C0E76CA64756E2164756E21
8618
+ //# debugId=3BFC53DCEB78A7B264756E2164756E21
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.203.0-preview.233",
5
+ "version": "1.203.0-preview.237",
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": "641614a6f9817662baaf51dabdebbfa2a9334b1b"
27
+ "gitHead": "4ad3e17a66f2c7fb7fe1f0e3e04a5b6175a0a9a3"
28
28
  }