@resolveio/server-lib 22.0.17 → 22.0.18

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.
@@ -4193,7 +4193,7 @@ function buildAssistantToolErrorMessage(error) {
4193
4193
  if (normalized.includes('invalid character for a variable name') && (normalized.includes('now-') || normalized.includes('now+'))) {
4194
4194
  return 'The query used an unsupported relative date token. Please retry and I will normalize the date expression.';
4195
4195
  }
4196
- if (normalized.includes('unrecognized argument to $datesubtract: date') || normalized.includes('unrecognized argument to $dateadd: date')) {
4196
+ if (normalized.includes('unrecognized argument to $datesubtract:') || normalized.includes('unrecognized argument to $dateadd:')) {
4197
4197
  return 'The data query failed because of an invalid date expression argument. Please retry; date arithmetic arguments are now normalized automatically.';
4198
4198
  }
4199
4199
  if (normalized.includes('report builder bridge') && normalized.includes('not configured')) {
@@ -6204,6 +6204,45 @@ function normalizeAssistantDateArithmeticArgs(expression) {
6204
6204
  if (Object.prototype.hasOwnProperty.call(nextArgs, 'start')) {
6205
6205
  delete nextArgs.start;
6206
6206
  }
6207
+ var allowedKeys = new Set(['startDate', 'unit', 'amount', 'timezone']);
6208
+ var unknownKeys = Object.keys(nextArgs).filter(function (key) { return !allowedKeys.has(key); });
6209
+ if (!Object.prototype.hasOwnProperty.call(nextArgs, 'startDate')) {
6210
+ var startCandidateKey = unknownKeys.find(function (key) {
6211
+ var candidate = nextArgs[key];
6212
+ if (candidate instanceof Date) {
6213
+ return true;
6214
+ }
6215
+ if (typeof candidate === 'string') {
6216
+ return candidate.startsWith('$$') || candidate.startsWith('$');
6217
+ }
6218
+ if (candidate && typeof candidate === 'object' && !Array.isArray(candidate)) {
6219
+ return Object.keys(candidate).some(function (op) { return op.startsWith('$'); });
6220
+ }
6221
+ return false;
6222
+ });
6223
+ if (startCandidateKey) {
6224
+ nextArgs.startDate = nextArgs[startCandidateKey];
6225
+ delete nextArgs[startCandidateKey];
6226
+ }
6227
+ }
6228
+ if (!Object.prototype.hasOwnProperty.call(nextArgs, 'amount')) {
6229
+ var amountCandidateKey = Object.keys(nextArgs).find(function (key) {
6230
+ if (allowedKeys.has(key)) {
6231
+ return false;
6232
+ }
6233
+ var candidate = nextArgs[key];
6234
+ return typeof candidate === 'number' && Number.isFinite(candidate);
6235
+ });
6236
+ if (amountCandidateKey) {
6237
+ nextArgs.amount = nextArgs[amountCandidateKey];
6238
+ delete nextArgs[amountCandidateKey];
6239
+ }
6240
+ }
6241
+ Object.keys(nextArgs).forEach(function (key) {
6242
+ if (!allowedKeys.has(key)) {
6243
+ delete nextArgs[key];
6244
+ }
6245
+ });
6207
6246
  expression[operator] = nextArgs;
6208
6247
  };
6209
6248
  normalizeOperatorArgs('$dateAdd');
@@ -6237,10 +6276,8 @@ function isAssistantDateArithmeticArgumentError(error) {
6237
6276
  if (!message) {
6238
6277
  return false;
6239
6278
  }
6240
- return message.includes('unrecognized argument to $datesubtract: date')
6241
- || message.includes('unrecognized argument to $dateadd: date')
6242
- || message.includes('unrecognized argument to $datesubtract: start')
6243
- || message.includes('unrecognized argument to $dateadd: start');
6279
+ return message.includes('unrecognized argument to $datesubtract:')
6280
+ || message.includes('unrecognized argument to $dateadd:');
6244
6281
  }
6245
6282
  function didAssistantValueChange(before, after) {
6246
6283
  try {