@resolveio/server-lib 22.0.11 → 22.0.12
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 +98 -20
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +1 -1
- package/services/codex-client.d.ts +14 -0
- package/services/codex-client.js +247 -30
- package/services/codex-client.js.map +1 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -1818,6 +1818,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1818
1818
|
assistantContent = buildAssistantCodexErrorMessage(null);
|
|
1819
1819
|
}
|
|
1820
1820
|
assistantContent = applyAssistantVerificationNotes(assistantContent, toolResult);
|
|
1821
|
+
assistantContent = applyAssistantDatedReportWindow(assistantContent, toolResult);
|
|
1821
1822
|
assistantContent = normalizeAssistantCurrencyText(assistantContent);
|
|
1822
1823
|
if (aiWorkerDebug) {
|
|
1823
1824
|
finishedAt = Date.now();
|
|
@@ -3041,7 +3042,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3041
3042
|
}
|
|
3042
3043
|
function verifyAssistantAggregateReliability(params) {
|
|
3043
3044
|
return __awaiter(this, void 0, void 0, function () {
|
|
3044
|
-
var collection, collectionBase, monthKey, amountKey, baseMap, groupIndex, groupPaths, dateField, mergedMatch, dateFieldsInMatch, baseMatchNoDate, primaryDateCondition, verifyPipeline, verifyDocs, _a, verifyMap, comparedMonths, paidCloserCount, grandCloserCount, sumPaidDiffPct, sumGrandDiffPct, maxPaidDiffPct, maxGrandDiffPct, sumPaidGrandGapPct, highVarianceMonths, checks, warnings, avgPaidDiffPct, avgGrandDiffPct, avgPaidGrandGapPct, baselineMetric, rollingWindow, normalizedMetric, bounds, fullMonthMatch, fullMonthDocs, fullMonthMap, fullMonthDiff, _b, alternateDateField, alternateDateCondition, bounds, alternateMatch, alternateDocs, alternateMap, alternateDiff, _c;
|
|
3045
|
+
var collection, collectionBase, monthKey, amountKey, baseMap, groupIndex, groupPaths, dateField, mergedMatch, dateFieldsInMatch, baseMatchNoDate, primaryDateCondition, verifyPipeline, verifyDocs, _a, verifyMap, comparedMonths, paidCloserCount, grandCloserCount, sumPaidDiffPct, sumGrandDiffPct, maxPaidDiffPct, maxGrandDiffPct, sumPaidGrandGapPct, highVarianceMonths, checks, warnings, avgPaidDiffPct, avgGrandDiffPct, avgPaidGrandGapPct, baselineMetric, rollingWindow, rollingWindowBounds, verificationWindow, rollingStart, rollingEnd, fullMonthStart, fullMonthEndExclusive, normalizedMetric, bounds, fullMonthMatch, fullMonthDocs, fullMonthMap, fullMonthDiff, _b, alternateDateField, alternateDateCondition, bounds, alternateMatch, alternateDocs, alternateMap, alternateDiff, _c;
|
|
3045
3046
|
var _d, _e;
|
|
3046
3047
|
var _f;
|
|
3047
3048
|
return __generator(this, function (_g) {
|
|
@@ -3182,13 +3183,29 @@ function verifyAssistantAggregateReliability(params) {
|
|
|
3182
3183
|
}
|
|
3183
3184
|
}
|
|
3184
3185
|
rollingWindow = detectAssistantRollingMonthWindow(params.pipeline || []);
|
|
3186
|
+
rollingWindowBounds = null;
|
|
3187
|
+
verificationWindow = null;
|
|
3185
3188
|
if ((rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.months) && (rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.upperNow)) {
|
|
3189
|
+
rollingWindowBounds = resolveAssistantRollingWindowBounds(rollingWindow.months);
|
|
3190
|
+
rollingStart = formatAssistantIsoDateOnly(rollingWindowBounds.rollingStart);
|
|
3191
|
+
rollingEnd = formatAssistantIsoDateOnly(rollingWindowBounds.now);
|
|
3192
|
+
fullMonthStart = formatAssistantIsoDateOnly(rollingWindowBounds.startOfWindow);
|
|
3193
|
+
fullMonthEndExclusive = formatAssistantIsoDateOnly(rollingWindowBounds.startOfCurrentMonth);
|
|
3194
|
+
verificationWindow = {
|
|
3195
|
+
type: 'rolling_last_n_months',
|
|
3196
|
+
months: rollingWindow.months,
|
|
3197
|
+
startDate: rollingStart,
|
|
3198
|
+
endDate: rollingEnd,
|
|
3199
|
+
timezone: 'UTC',
|
|
3200
|
+
fullMonthStartDate: fullMonthStart,
|
|
3201
|
+
fullMonthEndDateExclusive: fullMonthEndExclusive
|
|
3202
|
+
};
|
|
3186
3203
|
checks.push({
|
|
3187
3204
|
name: 'Date window shape',
|
|
3188
3205
|
status: 'warn',
|
|
3189
|
-
details: "Query uses rolling $$NOW bounds (last ".concat(rollingWindow.months, " months), which can include partial months.")
|
|
3206
|
+
details: "Query uses rolling $$NOW bounds (".concat(rollingStart, " to ").concat(rollingEnd, " UTC; last ").concat(rollingWindow.months, " months), which can include partial months.")
|
|
3190
3207
|
});
|
|
3191
|
-
warnings.push("Date window is rolling (last ".concat(rollingWindow.months, " months
|
|
3208
|
+
warnings.push("Date window is rolling (".concat(rollingStart, " to ").concat(rollingEnd, " UTC; last ").concat(rollingWindow.months, " months), so first/current months may be partial."));
|
|
3192
3209
|
}
|
|
3193
3210
|
else {
|
|
3194
3211
|
checks.push({
|
|
@@ -3198,8 +3215,8 @@ function verifyAssistantAggregateReliability(params) {
|
|
|
3198
3215
|
});
|
|
3199
3216
|
}
|
|
3200
3217
|
normalizedMetric = normalizeAssistantVerificationMetric(baselineMetric);
|
|
3201
|
-
if (!((rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.months) && (rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.upperNow))) return [3 /*break*/, 8];
|
|
3202
|
-
bounds =
|
|
3218
|
+
if (!((rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.months) && (rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.upperNow) && rollingWindowBounds)) return [3 /*break*/, 8];
|
|
3219
|
+
bounds = rollingWindowBounds;
|
|
3203
3220
|
fullMonthMatch = mergeAssistantMatch(baseMatchNoDate, (_d = {},
|
|
3204
3221
|
_d[dateField] = {
|
|
3205
3222
|
$gte: bounds.startOfWindow,
|
|
@@ -3247,8 +3264,8 @@ function verifyAssistantAggregateReliability(params) {
|
|
|
3247
3264
|
: '';
|
|
3248
3265
|
if (!alternateDateField) return [3 /*break*/, 12];
|
|
3249
3266
|
alternateDateCondition = null;
|
|
3250
|
-
if ((rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.months) && (rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.upperNow)) {
|
|
3251
|
-
bounds =
|
|
3267
|
+
if ((rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.months) && (rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.upperNow) && rollingWindowBounds) {
|
|
3268
|
+
bounds = rollingWindowBounds;
|
|
3252
3269
|
alternateDateCondition = {
|
|
3253
3270
|
$gte: bounds.rollingStart,
|
|
3254
3271
|
$lte: bounds.now
|
|
@@ -3296,16 +3313,7 @@ function verifyAssistantAggregateReliability(params) {
|
|
|
3296
3313
|
type: 'invoice_revenue_monthly',
|
|
3297
3314
|
checks: checks,
|
|
3298
3315
|
warnings: warnings,
|
|
3299
|
-
metrics: {
|
|
3300
|
-
baselineField: amountKey,
|
|
3301
|
-
dateField: dateField,
|
|
3302
|
-
comparedMonths: comparedMonths,
|
|
3303
|
-
avgDiffToPaidPct: (0, common_1.round)(avgPaidDiffPct * 100, 2),
|
|
3304
|
-
avgDiffToGrandPct: (0, common_1.round)(avgGrandDiffPct * 100, 2),
|
|
3305
|
-
maxDiffToPaidPct: (0, common_1.round)(maxPaidDiffPct * 100, 2),
|
|
3306
|
-
maxDiffToGrandPct: (0, common_1.round)(maxGrandDiffPct * 100, 2),
|
|
3307
|
-
avgPaidGrandGapPct: (0, common_1.round)(avgPaidGrandGapPct * 100, 2)
|
|
3308
|
-
}
|
|
3316
|
+
metrics: __assign({ baselineField: amountKey, dateField: dateField, comparedMonths: comparedMonths, avgDiffToPaidPct: (0, common_1.round)(avgPaidDiffPct * 100, 2), avgDiffToGrandPct: (0, common_1.round)(avgGrandDiffPct * 100, 2), maxDiffToPaidPct: (0, common_1.round)(maxPaidDiffPct * 100, 2), maxDiffToGrandPct: (0, common_1.round)(maxGrandDiffPct * 100, 2), avgPaidGrandGapPct: (0, common_1.round)(avgPaidGrandGapPct * 100, 2) }, (verificationWindow ? { window: verificationWindow } : {}))
|
|
3309
3317
|
}];
|
|
3310
3318
|
}
|
|
3311
3319
|
});
|
|
@@ -3508,6 +3516,12 @@ function resolveAssistantRollingWindowBounds(months) {
|
|
|
3508
3516
|
startOfWindow: startOfWindow
|
|
3509
3517
|
};
|
|
3510
3518
|
}
|
|
3519
|
+
function formatAssistantIsoDateOnly(value) {
|
|
3520
|
+
if (!(value instanceof Date) || Number.isNaN(value.getTime())) {
|
|
3521
|
+
return '';
|
|
3522
|
+
}
|
|
3523
|
+
return value.toISOString().slice(0, 10);
|
|
3524
|
+
}
|
|
3511
3525
|
function extractAssistantMongoDirective(content) {
|
|
3512
3526
|
var lines = String(content || '').split('\n');
|
|
3513
3527
|
var directiveIndex = -1;
|
|
@@ -3732,6 +3746,30 @@ function applyAssistantVerificationNotes(value, toolResult) {
|
|
|
3732
3746
|
}
|
|
3733
3747
|
return "".concat(content, "\n\n").concat(noteLines.join('\n')).trim();
|
|
3734
3748
|
}
|
|
3749
|
+
function applyAssistantDatedReportWindow(value, toolResult) {
|
|
3750
|
+
var _a, _b, _c;
|
|
3751
|
+
var content = normalizeOptionalString(value);
|
|
3752
|
+
var window = (_c = (_b = (_a = toolResult === null || toolResult === void 0 ? void 0 : toolResult.output) === null || _a === void 0 ? void 0 : _a.verification) === null || _b === void 0 ? void 0 : _b.metrics) === null || _c === void 0 ? void 0 : _c.window;
|
|
3753
|
+
if (!window || typeof window !== 'object') {
|
|
3754
|
+
return content || value || '';
|
|
3755
|
+
}
|
|
3756
|
+
var startDate = normalizeOptionalString(window.startDate);
|
|
3757
|
+
var endDate = normalizeOptionalString(window.endDate);
|
|
3758
|
+
if (!startDate || !endDate) {
|
|
3759
|
+
return content || value || '';
|
|
3760
|
+
}
|
|
3761
|
+
var months = normalizeOptionalNumber(window.months);
|
|
3762
|
+
var monthsText = months && months > 0 ? "; rolling last ".concat((0, common_1.round)(months), " month").concat((0, common_1.round)(months) === 1 ? '' : 's') : '';
|
|
3763
|
+
var line = "Report date range (UTC): ".concat(startDate, " to ").concat(endDate).concat(monthsText, ".");
|
|
3764
|
+
var normalizedLower = String(content || '').toLowerCase();
|
|
3765
|
+
if (normalizedLower.includes(startDate.toLowerCase()) && normalizedLower.includes(endDate.toLowerCase())) {
|
|
3766
|
+
return content || value || '';
|
|
3767
|
+
}
|
|
3768
|
+
if (!content) {
|
|
3769
|
+
return line;
|
|
3770
|
+
}
|
|
3771
|
+
return "".concat(line, "\n\n").concat(content).trim();
|
|
3772
|
+
}
|
|
3735
3773
|
function buildAssistantDebugPayload(params) {
|
|
3736
3774
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
|
|
3737
3775
|
var notes = [];
|
|
@@ -5581,9 +5619,49 @@ function stripAssistantMarkdownTables(value) {
|
|
|
5581
5619
|
if (!raw) {
|
|
5582
5620
|
return '';
|
|
5583
5621
|
}
|
|
5584
|
-
var
|
|
5585
|
-
var
|
|
5586
|
-
|
|
5622
|
+
var lines = raw.split('\n');
|
|
5623
|
+
var kept = [];
|
|
5624
|
+
for (var index = 0; index < lines.length; index += 1) {
|
|
5625
|
+
var line = lines[index];
|
|
5626
|
+
var nextLine = lines[index + 1];
|
|
5627
|
+
if (isAssistantMarkdownTableHeaderLine(line) && isAssistantMarkdownTableSeparatorLine(nextLine || '')) {
|
|
5628
|
+
index += 2;
|
|
5629
|
+
while (index < lines.length && isAssistantMarkdownTableRowLine(lines[index])) {
|
|
5630
|
+
index += 1;
|
|
5631
|
+
}
|
|
5632
|
+
while (index < lines.length && !normalizeOptionalString(lines[index])) {
|
|
5633
|
+
index += 1;
|
|
5634
|
+
}
|
|
5635
|
+
index -= 1;
|
|
5636
|
+
if (kept.length && normalizeOptionalString(kept[kept.length - 1])) {
|
|
5637
|
+
kept.push('');
|
|
5638
|
+
}
|
|
5639
|
+
continue;
|
|
5640
|
+
}
|
|
5641
|
+
kept.push(line);
|
|
5642
|
+
}
|
|
5643
|
+
return kept.join('\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
5644
|
+
}
|
|
5645
|
+
function isAssistantMarkdownTableHeaderLine(line) {
|
|
5646
|
+
var trimmed = normalizeOptionalString(line);
|
|
5647
|
+
if (!trimmed || !trimmed.includes('|')) {
|
|
5648
|
+
return false;
|
|
5649
|
+
}
|
|
5650
|
+
return /^\|.+\|$/.test(trimmed);
|
|
5651
|
+
}
|
|
5652
|
+
function isAssistantMarkdownTableSeparatorLine(line) {
|
|
5653
|
+
var trimmed = normalizeOptionalString(line);
|
|
5654
|
+
if (!trimmed || !trimmed.includes('|')) {
|
|
5655
|
+
return false;
|
|
5656
|
+
}
|
|
5657
|
+
return /^\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(trimmed);
|
|
5658
|
+
}
|
|
5659
|
+
function isAssistantMarkdownTableRowLine(line) {
|
|
5660
|
+
var trimmed = normalizeOptionalString(line);
|
|
5661
|
+
if (!trimmed || !trimmed.includes('|')) {
|
|
5662
|
+
return false;
|
|
5663
|
+
}
|
|
5664
|
+
return /^\|.*\|$/.test(trimmed);
|
|
5587
5665
|
}
|
|
5588
5666
|
function applyAssistantDisplayTableToResponse(value, display) {
|
|
5589
5667
|
if (!display || !Array.isArray(display.rows) || !display.rows.length) {
|