@resolveio/server-lib 22.1.14 → 22.1.15
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.
- package/methods/ai-terminal.js +86 -27
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +1 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -9562,23 +9562,15 @@ function applyAssistantDisplayTableToResponse(value, display) {
|
|
|
9562
9562
|
var rowCount = typeof normalizedDisplay.rowCount === 'number' && normalizedDisplay.rowCount > 0
|
|
9563
9563
|
? normalizedDisplay.rowCount
|
|
9564
9564
|
: 0;
|
|
9565
|
-
if (rowCount <= 0) {
|
|
9566
|
-
if (!cleaned_1) {
|
|
9567
|
-
return 'No rows matched your request.';
|
|
9568
|
-
}
|
|
9569
|
-
if (/\bno rows? matched\b/i.test(cleaned_1)) {
|
|
9570
|
-
return cleaned_1;
|
|
9571
|
-
}
|
|
9572
|
-
return "".concat(cleaned_1.trim(), "\n\nNo rows matched your request.").trim();
|
|
9573
|
-
}
|
|
9574
9565
|
var fallbackColumns = Array.isArray(normalizedDisplay.columns) && normalizedDisplay.columns.length
|
|
9575
9566
|
? normalizedDisplay.columns
|
|
9576
9567
|
: resolveAssistantEmptyDisplayColumns(cleaned_1 || value);
|
|
9577
9568
|
var normalizedColumns = fallbackColumns.length === 1
|
|
9578
9569
|
? __spreadArray(__spreadArray([], __read(fallbackColumns), false), ['Value'], false) : fallbackColumns;
|
|
9579
|
-
var rowSummary =
|
|
9580
|
-
|
|
9581
|
-
|
|
9570
|
+
var rowSummary = [(_a = {},
|
|
9571
|
+
_a[normalizedColumns[0]] = rowCount > 0 ? 'Rows matched' : 'No rows matched',
|
|
9572
|
+
_a[normalizedColumns[1]] = rowCount,
|
|
9573
|
+
_a)];
|
|
9582
9574
|
var tableDisplay = {
|
|
9583
9575
|
columns: normalizedColumns,
|
|
9584
9576
|
rows: rowSummary,
|
|
@@ -9590,10 +9582,19 @@ function applyAssistantDisplayTableToResponse(value, display) {
|
|
|
9590
9582
|
if (!emptyTable) {
|
|
9591
9583
|
return cleaned_1 || value;
|
|
9592
9584
|
}
|
|
9585
|
+
var noRowsNote = rowCount > 0 ? '' : 'No rows matched your request.';
|
|
9586
|
+
var base = cleaned_1
|
|
9587
|
+
? (noRowsNote && !/\bno rows? matched\b/i.test(cleaned_1)
|
|
9588
|
+
? "".concat(cleaned_1.trim(), "\n\n").concat(noRowsNote).trim()
|
|
9589
|
+
: cleaned_1.trim())
|
|
9590
|
+
: noRowsNote;
|
|
9593
9591
|
if (!cleaned_1) {
|
|
9594
|
-
|
|
9592
|
+
if (!base) {
|
|
9593
|
+
return emptyTable;
|
|
9594
|
+
}
|
|
9595
|
+
return "".concat(base, "\n\n").concat(emptyTable).trim();
|
|
9595
9596
|
}
|
|
9596
|
-
return "".concat(
|
|
9597
|
+
return "".concat(base, "\n\n").concat(emptyTable).trim();
|
|
9597
9598
|
}
|
|
9598
9599
|
var table = formatDisplayTableMarkdown(normalizedDisplay);
|
|
9599
9600
|
if (!table) {
|
|
@@ -10150,6 +10151,18 @@ function normalizeAssistantDateArithmeticArgs(expression) {
|
|
|
10150
10151
|
if (expression instanceof Date || expression instanceof RegExp || isMongoObjectId(expression)) {
|
|
10151
10152
|
return expression;
|
|
10152
10153
|
}
|
|
10154
|
+
var looksLikeDateOperand = function (candidate) {
|
|
10155
|
+
if (candidate instanceof Date) {
|
|
10156
|
+
return true;
|
|
10157
|
+
}
|
|
10158
|
+
if (typeof candidate === 'string') {
|
|
10159
|
+
return candidate.startsWith('$$') || candidate.startsWith('$');
|
|
10160
|
+
}
|
|
10161
|
+
if (candidate && typeof candidate === 'object' && !Array.isArray(candidate)) {
|
|
10162
|
+
return Object.keys(candidate).some(function (op) { return op.startsWith('$'); });
|
|
10163
|
+
}
|
|
10164
|
+
return false;
|
|
10165
|
+
};
|
|
10153
10166
|
var normalizeOperatorArgs = function (operator) {
|
|
10154
10167
|
if (!Object.prototype.hasOwnProperty.call(expression, operator)) {
|
|
10155
10168
|
return;
|
|
@@ -10325,6 +10338,54 @@ function normalizeAssistantDateArithmeticArgs(expression) {
|
|
|
10325
10338
|
});
|
|
10326
10339
|
expression.$dateTrunc = nextArgs;
|
|
10327
10340
|
};
|
|
10341
|
+
var normalizeDateToStringArgs = function () {
|
|
10342
|
+
if (!Object.prototype.hasOwnProperty.call(expression, '$dateToString')) {
|
|
10343
|
+
return;
|
|
10344
|
+
}
|
|
10345
|
+
var rawArgs = expression.$dateToString;
|
|
10346
|
+
if (!rawArgs || typeof rawArgs !== 'object' || Array.isArray(rawArgs)) {
|
|
10347
|
+
return;
|
|
10348
|
+
}
|
|
10349
|
+
if (rawArgs instanceof Date || rawArgs instanceof RegExp || isMongoObjectId(rawArgs)) {
|
|
10350
|
+
return;
|
|
10351
|
+
}
|
|
10352
|
+
var nextArgs = __assign({}, rawArgs);
|
|
10353
|
+
if (!Object.prototype.hasOwnProperty.call(nextArgs, 'date')) {
|
|
10354
|
+
if (Object.prototype.hasOwnProperty.call(nextArgs, 'startDate')) {
|
|
10355
|
+
nextArgs.date = nextArgs.startDate;
|
|
10356
|
+
}
|
|
10357
|
+
else if (Object.prototype.hasOwnProperty.call(nextArgs, 'start')) {
|
|
10358
|
+
nextArgs.date = nextArgs.start;
|
|
10359
|
+
}
|
|
10360
|
+
else {
|
|
10361
|
+
var dateCandidateKey = Object.keys(nextArgs).find(function (key) {
|
|
10362
|
+
if (key === 'format' || key === 'timezone' || key === 'onNull' || key === 'onError') {
|
|
10363
|
+
return false;
|
|
10364
|
+
}
|
|
10365
|
+
return looksLikeDateOperand(nextArgs[key]);
|
|
10366
|
+
});
|
|
10367
|
+
if (dateCandidateKey) {
|
|
10368
|
+
nextArgs.date = nextArgs[dateCandidateKey];
|
|
10369
|
+
delete nextArgs[dateCandidateKey];
|
|
10370
|
+
}
|
|
10371
|
+
}
|
|
10372
|
+
}
|
|
10373
|
+
delete nextArgs.startDate;
|
|
10374
|
+
delete nextArgs.start;
|
|
10375
|
+
if (!Object.prototype.hasOwnProperty.call(nextArgs, 'date')) {
|
|
10376
|
+
nextArgs.date = '$$NOW';
|
|
10377
|
+
}
|
|
10378
|
+
if (!Object.prototype.hasOwnProperty.call(nextArgs, 'format')) {
|
|
10379
|
+
nextArgs.format = '%Y-%m-%d';
|
|
10380
|
+
}
|
|
10381
|
+
var allowedKeys = new Set(['date', 'format', 'timezone', 'onNull']);
|
|
10382
|
+
Object.keys(nextArgs).forEach(function (key) {
|
|
10383
|
+
if (!allowedKeys.has(key)) {
|
|
10384
|
+
delete nextArgs[key];
|
|
10385
|
+
}
|
|
10386
|
+
});
|
|
10387
|
+
expression.$dateToString = nextArgs;
|
|
10388
|
+
};
|
|
10328
10389
|
var normalizeLetArgs = function () {
|
|
10329
10390
|
if (!Object.prototype.hasOwnProperty.call(expression, '$let')) {
|
|
10330
10391
|
return;
|
|
@@ -10362,18 +10423,6 @@ function normalizeAssistantDateArithmeticArgs(expression) {
|
|
|
10362
10423
|
};
|
|
10363
10424
|
var normalizeDatePartArgs = function () {
|
|
10364
10425
|
var operators = ['$year', '$month', '$week', '$isoWeek', '$isoWeekYear', '$dayOfMonth', '$dayOfYear'];
|
|
10365
|
-
var looksLikeDateOperand = function (candidate) {
|
|
10366
|
-
if (candidate instanceof Date) {
|
|
10367
|
-
return true;
|
|
10368
|
-
}
|
|
10369
|
-
if (typeof candidate === 'string') {
|
|
10370
|
-
return candidate.startsWith('$$') || candidate.startsWith('$');
|
|
10371
|
-
}
|
|
10372
|
-
if (candidate && typeof candidate === 'object' && !Array.isArray(candidate)) {
|
|
10373
|
-
return Object.keys(candidate).some(function (op) { return op.startsWith('$'); });
|
|
10374
|
-
}
|
|
10375
|
-
return false;
|
|
10376
|
-
};
|
|
10377
10426
|
operators.forEach(function (operator) {
|
|
10378
10427
|
if (!Object.prototype.hasOwnProperty.call(expression, operator)) {
|
|
10379
10428
|
return;
|
|
@@ -10415,6 +10464,7 @@ function normalizeAssistantDateArithmeticArgs(expression) {
|
|
|
10415
10464
|
normalizeOperatorArgs('$dateAdd');
|
|
10416
10465
|
normalizeOperatorArgs('$dateSubtract');
|
|
10417
10466
|
normalizeDateTruncArgs();
|
|
10467
|
+
normalizeDateToStringArgs();
|
|
10418
10468
|
normalizeLetArgs();
|
|
10419
10469
|
normalizeDatePartArgs();
|
|
10420
10470
|
return expression;
|
|
@@ -10449,6 +10499,7 @@ function isAssistantDateArithmeticArgumentError(error) {
|
|
|
10449
10499
|
return message.includes('unrecognized argument to $datesubtract:')
|
|
10450
10500
|
|| message.includes('unrecognized argument to $dateadd:')
|
|
10451
10501
|
|| message.includes('unrecognized argument to $datetrunc:')
|
|
10502
|
+
|| message.includes('unrecognized argument to $datetostring:')
|
|
10452
10503
|
|| message.includes('unrecognized option to $year:')
|
|
10453
10504
|
|| message.includes('unrecognized option to $month:')
|
|
10454
10505
|
|| message.includes('unrecognized option to $week:')
|
|
@@ -10462,6 +10513,8 @@ function isAssistantDateArithmeticArgumentError(error) {
|
|
|
10462
10513
|
|| message.includes("missing 'date' parameter to $datetrunc")
|
|
10463
10514
|
|| message.includes("requires 'unit' parameter to $datetrunc")
|
|
10464
10515
|
|| message.includes("requires 'date' parameter to $datetrunc")
|
|
10516
|
+
|| message.includes("requires 'date' parameter to $datetostring")
|
|
10517
|
+
|| message.includes("missing 'date' parameter to $datetostring")
|
|
10465
10518
|
|| message.includes('$datesubtract requires startdate, unit, and amount to be present')
|
|
10466
10519
|
|| message.includes('$dateadd requires startdate, unit, and amount to be present')
|
|
10467
10520
|
|| message.includes('undefined variable: now_start_of_month')
|
|
@@ -10494,13 +10547,19 @@ function isAssistantDottedOutputFieldError(error) {
|
|
|
10494
10547
|
if (!message) {
|
|
10495
10548
|
return false;
|
|
10496
10549
|
}
|
|
10497
|
-
return message.includes("fieldpath field names may not contain '.'")
|
|
10550
|
+
return message.includes("fieldpath field names may not contain '.'")
|
|
10551
|
+
|| (message.includes("field name '") && message.includes("cannot contain '.'"));
|
|
10498
10552
|
}
|
|
10499
10553
|
function extractAssistantDottedFieldPathFromError(error) {
|
|
10500
10554
|
var message = normalizeOptionalString(error === null || error === void 0 ? void 0 : error.message);
|
|
10501
10555
|
if (!message) {
|
|
10502
10556
|
return null;
|
|
10503
10557
|
}
|
|
10558
|
+
var fieldNameMatch = message.match(/field name\s+'([^']+)'/i);
|
|
10559
|
+
if (fieldNameMatch === null || fieldNameMatch === void 0 ? void 0 : fieldNameMatch[1]) {
|
|
10560
|
+
var normalized = normalizeOptionalString(fieldNameMatch[1]);
|
|
10561
|
+
return normalized.includes('.') ? normalized : null;
|
|
10562
|
+
}
|
|
10504
10563
|
var quotedMatch = message.match(/given\s+'([^']+)'/i);
|
|
10505
10564
|
if (quotedMatch && quotedMatch[1]) {
|
|
10506
10565
|
var normalized = normalizeOptionalString(quotedMatch[1]);
|