@resolveio/server-lib 22.3.199 → 22.3.201
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.d.ts +20 -1
- package/methods/ai-terminal.js +985 -577
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +1 -1
- package/util/ai-run-evidence-adapters.js +2940 -151
- package/util/ai-run-evidence-adapters.js.map +1 -1
- package/util/ai-run-evidence.js +247 -3
- package/util/ai-run-evidence.js.map +1 -1
- package/util/ai-runner-manager-policy.d.ts +20 -0
- package/util/ai-runner-manager-policy.js +158 -13
- package/util/ai-runner-manager-policy.js.map +1 -1
- package/util/aicoder-runner-v6.d.ts +2 -0
- package/util/aicoder-runner-v6.js +178 -39
- package/util/aicoder-runner-v6.js.map +1 -1
- package/util/support-runner-v5.d.ts +375 -4
- package/util/support-runner-v5.js +2027 -100
- package/util/support-runner-v5.js.map +1 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -117,6 +117,7 @@ exports.resolveAssistantHeuristicDirectiveForTesting = resolveAssistantHeuristic
|
|
|
117
117
|
exports.buildAssistantDatedPivotDisplay = buildAssistantDatedPivotDisplay;
|
|
118
118
|
exports.buildAssistantToolFallbackResponseForTesting = buildAssistantToolFallbackResponseForTesting;
|
|
119
119
|
exports.deriveAssistantCommandExecutionStatus = deriveAssistantCommandExecutionStatus;
|
|
120
|
+
exports.expandAssistantFieldTokensForTesting = expandAssistantFieldTokensForTesting;
|
|
120
121
|
exports.normalizeIdsForTargetField = normalizeIdsForTargetField;
|
|
121
122
|
exports.serializeMongoValue = serializeMongoValue;
|
|
122
123
|
exports.flattenForTable = flattenForTable;
|
|
@@ -205,7 +206,13 @@ var AI_ASSISTANT_DISPLAY_STRING_LIMIT = 160;
|
|
|
205
206
|
var AI_ASSISTANT_ID_DISPLAY_LOOKUP_MAX_FIELDS = 4;
|
|
206
207
|
var AI_ASSISTANT_ID_DISPLAY_LOOKUP_MAX_IDS = 60;
|
|
207
208
|
var AI_ASSISTANT_ID_DISPLAY_LOOKUP_MAX_COLLECTIONS = 3;
|
|
208
|
-
var
|
|
209
|
+
var AI_ASSISTANT_PROGRESS_READING = 'Reading your request';
|
|
210
|
+
var AI_ASSISTANT_PROGRESS_CONTEXT = 'Checking app context';
|
|
211
|
+
var AI_ASSISTANT_PROGRESS_NAVIGATION = 'Checking app navigation';
|
|
212
|
+
var AI_ASSISTANT_PROGRESS_DATA_LOOKUP = 'Preparing a data lookup';
|
|
213
|
+
var AI_ASSISTANT_PROGRESS_DATA_RUNNING = 'Checking available data';
|
|
214
|
+
var AI_ASSISTANT_PROGRESS_DRAFT = 'Preparing the answer';
|
|
215
|
+
var AI_ASSISTANT_PROGRESS_PLACEHOLDER = AI_ASSISTANT_PROGRESS_READING;
|
|
209
216
|
var AI_ASSISTANT_READ_PREFERENCE = 'secondaryPreferred';
|
|
210
217
|
var AI_ASSISTANT_PROBE_LIMIT = 3;
|
|
211
218
|
var AI_ASSISTANT_COLLECTION_OVERRIDE_SCORE_GAP = 20;
|
|
@@ -390,93 +397,6 @@ var AI_ASSISTANT_COLLECTION_STOPWORDS = new Set([
|
|
|
390
397
|
'missing',
|
|
391
398
|
'overdue'
|
|
392
399
|
]);
|
|
393
|
-
var AI_ASSISTANT_COLLECTION_DOMAIN_TOKENS = new Set([
|
|
394
|
-
'blend',
|
|
395
|
-
'blends',
|
|
396
|
-
'chemical',
|
|
397
|
-
'chemicals',
|
|
398
|
-
'invoice',
|
|
399
|
-
'invoices',
|
|
400
|
-
'revenue',
|
|
401
|
-
'revenues',
|
|
402
|
-
'sales',
|
|
403
|
-
'sale',
|
|
404
|
-
'billing',
|
|
405
|
-
'billings',
|
|
406
|
-
'payment',
|
|
407
|
-
'payments',
|
|
408
|
-
'paid',
|
|
409
|
-
'income',
|
|
410
|
-
'finance',
|
|
411
|
-
'financial',
|
|
412
|
-
'work',
|
|
413
|
-
'order',
|
|
414
|
-
'orders',
|
|
415
|
-
'delivery',
|
|
416
|
-
'deliveries',
|
|
417
|
-
'asset',
|
|
418
|
-
'assets',
|
|
419
|
-
'treatment',
|
|
420
|
-
'treatments',
|
|
421
|
-
'treatmentplan',
|
|
422
|
-
'treatmentplans',
|
|
423
|
-
'dispatch',
|
|
424
|
-
'driver',
|
|
425
|
-
'drivers',
|
|
426
|
-
'treater',
|
|
427
|
-
'specialty',
|
|
428
|
-
'specialtyjob',
|
|
429
|
-
'specialtyjobs',
|
|
430
|
-
'bol',
|
|
431
|
-
'bols',
|
|
432
|
-
'lading',
|
|
433
|
-
'pso',
|
|
434
|
-
'psos',
|
|
435
|
-
'po',
|
|
436
|
-
'pos',
|
|
437
|
-
'ats',
|
|
438
|
-
'automated',
|
|
439
|
-
'automation',
|
|
440
|
-
'continuous',
|
|
441
|
-
'isotank',
|
|
442
|
-
'isotanks',
|
|
443
|
-
'trailer',
|
|
444
|
-
'trailers',
|
|
445
|
-
'chemicaltrailer',
|
|
446
|
-
'chemicaltrailers',
|
|
447
|
-
'vac',
|
|
448
|
-
'vactruck',
|
|
449
|
-
'vactrucks',
|
|
450
|
-
'purchase',
|
|
451
|
-
'purchasing',
|
|
452
|
-
'purchaseorder',
|
|
453
|
-
'purchaseorders',
|
|
454
|
-
'batchjob',
|
|
455
|
-
'batchjobs',
|
|
456
|
-
'production',
|
|
457
|
-
'salesorder',
|
|
458
|
-
'salesorders',
|
|
459
|
-
'truck',
|
|
460
|
-
'trucktreat',
|
|
461
|
-
'trucktreating',
|
|
462
|
-
'product',
|
|
463
|
-
'products',
|
|
464
|
-
'item',
|
|
465
|
-
'items',
|
|
466
|
-
'inventory',
|
|
467
|
-
'treating',
|
|
468
|
-
'batchtreat',
|
|
469
|
-
'batchtreating',
|
|
470
|
-
'route',
|
|
471
|
-
'routes',
|
|
472
|
-
'well',
|
|
473
|
-
'wells',
|
|
474
|
-
'sample',
|
|
475
|
-
'samples',
|
|
476
|
-
'customer',
|
|
477
|
-
'customers',
|
|
478
|
-
'support'
|
|
479
|
-
]);
|
|
480
400
|
var AI_ASSISTANT_COLLECTION_GENERIC_TOKENS = new Set([
|
|
481
401
|
'ticket',
|
|
482
402
|
'tickets',
|
|
@@ -493,20 +413,15 @@ var AI_ASSISTANT_COLLECTION_GENERIC_TOKENS = new Set([
|
|
|
493
413
|
'show'
|
|
494
414
|
]);
|
|
495
415
|
var AI_ASSISTANT_INVOICE_PERMISSION_PATTERN = /invoice/i;
|
|
496
|
-
var
|
|
416
|
+
var AI_ASSISTANT_BASE_FIELD_TOKEN_SYNONYMS = {
|
|
497
417
|
volume: ['quantity', 'qty', 'amount', 'gallons', 'gallon', 'liters', 'liter', 'litre'],
|
|
498
418
|
quantity: ['volume', 'qty', 'amount', 'gallons', 'gallon'],
|
|
499
|
-
product: ['item', '
|
|
419
|
+
product: ['item', 'material', 'name', 'title', 'label'],
|
|
500
420
|
customer: ['client', 'account', 'company'],
|
|
501
|
-
well: ['location', 'site', 'pad', 'api'],
|
|
502
421
|
batch: ['lot'],
|
|
503
422
|
lot: ['batch'],
|
|
504
423
|
date: ['created', 'createdat', 'created_at', 'date_created', 'updated', 'updatedat', 'updated_at', 'date_updated'],
|
|
505
|
-
total: ['sum', 'amount', 'total_amount', 'total_quantity']
|
|
506
|
-
revenue: ['sales', 'billing', 'paid', 'payment', 'total', 'amount', 'grand', 'subtotal', 'sub_total', 'paid_total', 'grand_total'],
|
|
507
|
-
sales: ['revenue', 'billing', 'paid', 'payment', 'total', 'amount', 'grand', 'subtotal', 'sub_total'],
|
|
508
|
-
billing: ['revenue', 'sales', 'paid', 'payment', 'total', 'amount', 'grand', 'subtotal', 'sub_total'],
|
|
509
|
-
payment: ['paid', 'revenue', 'sales', 'billing', 'total', 'amount']
|
|
424
|
+
total: ['sum', 'amount', 'total_amount', 'total_quantity']
|
|
510
425
|
};
|
|
511
426
|
var AI_ASSISTANT_ID_LOOKUP_HINTS = {
|
|
512
427
|
user: ['users', 'user-versions']
|
|
@@ -621,7 +536,7 @@ function buildAssistantSystemPromptText(platformPrompt) {
|
|
|
621
536
|
'- If a report-* collection is unavailable, keep using REPORT_BUILDER_READ/REPORT_BUILDER_AGG with the best-matched collection family; the bridge can safely fall back to direct collection access.',
|
|
622
537
|
'- Map user wording to internal collections/fields through a validated structured contract. Do not ask for property names unless required to run a query.',
|
|
623
538
|
'- Use app heuristics and context hints as weak signals only. Verify collection and field guesses before relying on them.',
|
|
624
|
-
'- Distinguish the root business object from related measured details.
|
|
539
|
+
'- Distinguish the root business object from related measured details. If the user asks for a primary object plus related quantities/details, root the query in the primary object and join related detail only when verified.',
|
|
625
540
|
'- Do not guess or invent collections/fields. If unsure, verify in the codebase or run a small REPORT_BUILDER_READ probe (limit 1-5) to learn the shape.',
|
|
626
541
|
'- Prefer running a small REPORT_BUILDER_READ probe over asking multiple questions.',
|
|
627
542
|
'- Form a concrete hypothesis about collection/field/date mapping, then verify it with codebase context or a tiny probe before answering.',
|
|
@@ -630,7 +545,7 @@ function buildAssistantSystemPromptText(platformPrompt) {
|
|
|
630
545
|
'- Ask at most one clarifying question only when required to run a query or resolve missing details.',
|
|
631
546
|
'- If a field starts with id_ and refers to another collection, treat it as a foreign key and look up the related record when needed.',
|
|
632
547
|
'- When resolving id_* fields, prefer lookup definitions from collection schemas/report-builder lookup tables to choose the target collection and name fields.',
|
|
633
|
-
'- When the user provides a
|
|
548
|
+
'- When the user provides a business entity name, create candidate filters and verify them with a tiny scoped probe or ID/name lookup before answering. Regex/text matching is only a candidate-generation step.',
|
|
634
549
|
'- Use the codebase context to choose correct collections/fields/workflows and use REPORT_BUILDER_READ/REPORT_BUILDER_AGG to answer with real data when needed.',
|
|
635
550
|
'- Process (fast path): Queue -> Structured planning contract -> Verified data probe/query -> Actionability contract -> Draft response. This should be fast, but every data answer must have a verified query result class before it is presented.',
|
|
636
551
|
'- Assume a relevant collection exists; if verification reads return zero data, report no data found instead of interrogating the user.',
|
|
@@ -693,7 +608,7 @@ function buildAssistantSystemPromptText(platformPrompt) {
|
|
|
693
608
|
'- Before issuing REPORT_BUILDER_READ or REPORT_BUILDER_AGG, verify the collection name and key fields by checking collection/model definitions in the current app (look for "collectionName:" and date fields like date_created/date_completed/createdAt). Do not invent collection names.',
|
|
694
609
|
'- When a request names multiple business concepts, root the query in the concept being counted/listed/summarized, then use $lookup/$unwind for related detail concepts.',
|
|
695
610
|
'- For creation-date questions when both date_created and createdAt exist, match both with $or so results are not missed.',
|
|
696
|
-
'- When grouping by fields that can be arrays
|
|
611
|
+
'- When grouping by fields that can be arrays, use app-provided domain instructions and schema context to decide whether to $unwind and which id/name fields to group by.',
|
|
697
612
|
'- Use REPORT_BUILDER_READ/REPORT_BUILDER_AGG only to produce summaries/snapshots/health checks (not raw dumps) when permitted.',
|
|
698
613
|
'- If the user explicitly asks for IDs, set options.includeIds: true.',
|
|
699
614
|
'- If a data question returns zero results, verify the collection/date field with a tiny read (limit 1-5) or a date field fallback before concluding there is no data.',
|
|
@@ -1811,7 +1726,8 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1811
1726
|
hasAttachments: attachments.length > 0,
|
|
1812
1727
|
user: user,
|
|
1813
1728
|
isSuperAdmin: isSuperAdmin,
|
|
1814
|
-
contextRoute: normalizeOptionalString((_c = input === null || input === void 0 ? void 0 : input.context) === null || _c === void 0 ? void 0 : _c.route)
|
|
1729
|
+
contextRoute: normalizeOptionalString((_c = input === null || input === void 0 ? void 0 : input.context) === null || _c === void 0 ? void 0 : _c.route),
|
|
1730
|
+
appId: normalizeOptionalString(input === null || input === void 0 ? void 0 : input.id_app)
|
|
1815
1731
|
});
|
|
1816
1732
|
if (!navigationFastPath) return [3 /*break*/, 11];
|
|
1817
1733
|
userMsg = {
|
|
@@ -1952,7 +1868,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1952
1868
|
createdAt: now,
|
|
1953
1869
|
updatedAt: now
|
|
1954
1870
|
};
|
|
1955
|
-
initialProgress = [
|
|
1871
|
+
initialProgress = [AI_ASSISTANT_PROGRESS_READING];
|
|
1956
1872
|
assistantDoc = {
|
|
1957
1873
|
id_conversation: conversation._id,
|
|
1958
1874
|
role: 'assistant',
|
|
@@ -1970,10 +1886,10 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1970
1886
|
insertResult = _d.sent();
|
|
1971
1887
|
assistantMessageId = (insertResult === null || insertResult === void 0 ? void 0 : insertResult._id) || (insertResult === null || insertResult === void 0 ? void 0 : insertResult.insertedId);
|
|
1972
1888
|
enqueueAssistantCodexRun(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1973
|
-
var runStart, fastModeEnabled, alwaysAllowProbeEnabled, plannerEnabled, runBudgetMs, assistantMongoMaxTimeMs, assistantSystemPrompt, runDeadlineMs, steps, recordStep, requestClassification, dataQuestion, progressTracker, streamProgress, remainingRunBudgetMs, hasRunBudget, applyCodexStageBudget, assistantContent, toolResult, assistantDebug, directiveSource, lastDirective, heuristicDirectivePrecomputed, usedDeterministicHeuristicFastPath, requestedTimeGrain, requestedBreakdownDimensions, enforceDatedDirective, enforceGroupedDirective, datedDirectiveRetryUsed, datedDirectiveResolved, toolResponseDebug, toolError, toolTelemetry, termHints, collectionHints, fieldHints, schemaHints, methodHints, publicationHints, collectionTokenization, collectionRanking, collectionSelection, collectionOverride, collectionNames, plannerUsed, plannerSkipReason, plannerOutput, plannerRaw, timingBreakdown, codexUsage, accumulateCodexUsage, contextRoute, contextMode, hintSeed, termExpansion, hintText, baseTokens, expandedTokens, baseWeights, expandedWeights, dbName, db, surfaceHints, _a, allowedRoutes, rankedAllowedRoutes, routeHints, appCollectionHints, rankedCollectionHints, rankedCollections, hintCollections, schemaHintCollections, assistantContext, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerBudgetAvailable, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective,
|
|
1974
|
-
var _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18
|
|
1975
|
-
return __generator(this, function (
|
|
1976
|
-
switch (
|
|
1889
|
+
var runStart, fastModeEnabled, alwaysAllowProbeEnabled, plannerEnabled, runBudgetMs, assistantMongoMaxTimeMs, assistantSystemPrompt, runDeadlineMs, steps, recordStep, requestClassification, dataQuestion, progressTracker, streamProgress, remainingRunBudgetMs, hasRunBudget, applyCodexStageBudget, assistantContent, toolResult, assistantDebug, directiveSource, lastDirective, heuristicDirectivePrecomputed, usedDeterministicHeuristicFastPath, requestedTimeGrain, requestedBreakdownDimensions, enforceDatedDirective, enforceGroupedDirective, datedDirectiveRetryUsed, datedDirectiveResolved, toolResponseDebug, toolError, toolTelemetry, termHints, collectionHints, fieldHints, schemaHints, methodHints, publicationHints, collectionTokenization, collectionRanking, collectionSelection, collectionOverride, collectionNames, plannerUsed, plannerSkipReason, plannerOutput, plannerRaw, timingBreakdown, codexUsage, accumulateCodexUsage, contextRoute, contextMode, hintSeed, termExpansion, hintText, baseTokens, expandedTokens, baseWeights, expandedWeights, dbName, db, surfaceHints, _a, allowedRoutes, rankedAllowedRoutes, routeHints, appCollectionHints, rankedCollectionHints, rankedCollections, hintCollections, schemaHintCollections, assistantContext, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerBudgetAvailable, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, error_2, initialStart, extractedDirective, error_3, directivePrompt, forcedStart, forcedDirective, error_4, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, error_5, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, error_6, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, error_7, heuristicDirective, requestedCollection, allowCollectionOverride, cleanedResponseText, deniedModuleByIntent, permissionLabel, effectiveDirective, effectiveDirectiveMetadata, directiveAcknowledgementText, directiveProgressMessages, deterministicDataIntentDirective, rankedCollections_1, directiveHintsBase_1, buildToolRequestForDirective, executionDirective, probeFieldHints, aggregateProbeDisabled, probeEnabled, probeBudgetAllowed, probeDirective, probeRequest, probeStart, probeResponse, _c, probeDurationMs, probeRowCount, probeRewrite, probeError_1, probeDurationMs, probeErrorMessage, toolRequest, requestedToolCollection, toolStart, toolResponse, _d, toolDurationMs, toolPayload, resolvedToolCollection, zeroRowResult, followupCodexEnabled, skipFollowupCodex, followupPrompt, followupStart, followupText, _e, error_8, errorMessage, existingFinal, error_9, runBudgetExceeded, includeToolExecutionTelemetry, toolExecutionTelemetry, finishedAt, finalNow, finishedAt, codexMs, draftingMs, answerQualityEvidence, finalMetadata, finalUsage, finalUsageLedgerEntry, usageClientId, usageError_1, finalAssistantDoc, setPayload, finalizeError_1, failedAt, fallbackContent, failureMetadata, persistError_1, _f;
|
|
1890
|
+
var _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
|
|
1891
|
+
return __generator(this, function (_19) {
|
|
1892
|
+
switch (_19.label) {
|
|
1977
1893
|
case 0:
|
|
1978
1894
|
runStart = Date.now();
|
|
1979
1895
|
fastModeEnabled = resolveAssistantFastModeEnabled(input.config);
|
|
@@ -2101,8 +2017,8 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2101
2017
|
codexUsage.output_tokens += outputTokens;
|
|
2102
2018
|
codexUsage.total_tokens += inputTokens + outputTokens;
|
|
2103
2019
|
};
|
|
2104
|
-
contextRoute = normalizeOptionalString((
|
|
2105
|
-
contextMode = normalizeOptionalString((
|
|
2020
|
+
contextRoute = normalizeOptionalString((_g = input === null || input === void 0 ? void 0 : input.context) === null || _g === void 0 ? void 0 : _g.route);
|
|
2021
|
+
contextMode = normalizeOptionalString((_h = input === null || input === void 0 ? void 0 : input.context) === null || _h === void 0 ? void 0 : _h.mode);
|
|
2106
2022
|
recordStep('Queued', { requestId: requestId || undefined });
|
|
2107
2023
|
if (changeHistoryFastPathBypassedReason) {
|
|
2108
2024
|
recordStep('Planning: change-history fast path unavailable', {
|
|
@@ -2114,9 +2030,9 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2114
2030
|
source: requestClassification.source,
|
|
2115
2031
|
dataQuestion: dataQuestion
|
|
2116
2032
|
});
|
|
2117
|
-
|
|
2033
|
+
_19.label = 1;
|
|
2118
2034
|
case 1:
|
|
2119
|
-
|
|
2035
|
+
_19.trys.push([1, 68, 69, 70]);
|
|
2120
2036
|
hintSeed = [message, contextRoute].filter(Boolean).join(' ');
|
|
2121
2037
|
termExpansion = expandAssistantTermSynonyms(hintSeed);
|
|
2122
2038
|
hintText = termExpansion.expanded || hintSeed;
|
|
@@ -2137,19 +2053,19 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2137
2053
|
recordStep('Planning: term expansion', {
|
|
2138
2054
|
termMatches: termExpansion.matches.length ? termExpansion.matches : undefined
|
|
2139
2055
|
});
|
|
2140
|
-
|
|
2056
|
+
_19.label = 2;
|
|
2141
2057
|
case 2:
|
|
2142
|
-
|
|
2058
|
+
_19.trys.push([2, 5, , 6]);
|
|
2143
2059
|
dbName = resolveAssistantDatabaseName(undefined, input.mongo);
|
|
2144
2060
|
db = resolveio_server_app_1.ResolveIOServer.getMongoConnection().db(dbName);
|
|
2145
2061
|
return [4 /*yield*/, listAssistantCollections(db, dbName)];
|
|
2146
2062
|
case 3:
|
|
2147
|
-
collectionNames =
|
|
2063
|
+
collectionNames = _19.sent();
|
|
2148
2064
|
collectionHints = resolveCollectionHintsFromTokens(expandedTokens, collectionNames, 5);
|
|
2149
2065
|
collectionRanking = buildCollectionRankingDebugFromTokens(expandedTokens, collectionNames, 8);
|
|
2150
2066
|
return [4 /*yield*/, resolveAssistantSurfaceHints(hintSeed, contextRoute, collectionNames)];
|
|
2151
2067
|
case 4:
|
|
2152
|
-
surfaceHints =
|
|
2068
|
+
surfaceHints = _19.sent();
|
|
2153
2069
|
methodHints = surfaceHints.methodHints;
|
|
2154
2070
|
publicationHints = surfaceHints.publicationHints;
|
|
2155
2071
|
if (surfaceHints.collectionHints.length) {
|
|
@@ -2157,7 +2073,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2157
2073
|
}
|
|
2158
2074
|
return [3 /*break*/, 6];
|
|
2159
2075
|
case 5:
|
|
2160
|
-
_a =
|
|
2076
|
+
_a = _19.sent();
|
|
2161
2077
|
collectionHints = [];
|
|
2162
2078
|
collectionRanking = collectionRanking || ((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens)
|
|
2163
2079
|
? buildCollectionRankingDebugFromTokens(collectionTokenization.expandedTokens || [], [], 0)
|
|
@@ -2194,7 +2110,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2194
2110
|
hintCollections = mergeAssistantHintValues(collectionHints, rankedCollections)
|
|
2195
2111
|
.slice(0, AI_ASSISTANT_CONTEXT_MAX_COLLECTIONS);
|
|
2196
2112
|
schemaHintCollections = mergeAssistantHintValues(hintCollections, rankedCollections, collectionHints).slice(0, AI_ASSISTANT_CONTEXT_MAX_SCHEMA_COLLECTIONS);
|
|
2197
|
-
fieldHints = buildAssistantFieldHints(message, hintCollections);
|
|
2113
|
+
fieldHints = buildAssistantFieldHints(message, hintCollections, { appId: input.id_app });
|
|
2198
2114
|
schemaHints = buildAssistantSchemaHints(schemaHintCollections, {
|
|
2199
2115
|
maxCollections: AI_ASSISTANT_CONTEXT_MAX_SCHEMA_COLLECTIONS
|
|
2200
2116
|
});
|
|
@@ -2221,23 +2137,28 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2221
2137
|
recentToolError: recentToolError,
|
|
2222
2138
|
changeHistoryFastPathBypassedReason: changeHistoryFastPathBypassedReason
|
|
2223
2139
|
});
|
|
2224
|
-
heuristicDirectivePrecomputed =
|
|
2225
|
-
|
|
2226
|
-
: null;
|
|
2227
|
-
hasDeterministicHeuristicFastPath = dataQuestion
|
|
2228
|
-
&& isAssistantExecutableDirective(heuristicDirectivePrecomputed)
|
|
2140
|
+
heuristicDirectivePrecomputed = buildAssistantHeuristicDirective(message, collectionHints, collectionNames, input.id_app);
|
|
2141
|
+
hasDeterministicHeuristicFastPath = isAssistantExecutableDirective(heuristicDirectivePrecomputed)
|
|
2229
2142
|
&& isAssistantDeterministicHeuristicDirective(heuristicDirectivePrecomputed);
|
|
2143
|
+
if (hasDeterministicHeuristicFastPath && !dataQuestion) {
|
|
2144
|
+
requestClassification = __assign(__assign({}, requestClassification), { type: requestClassification.type === 'navigation' ? 'mixed' : 'data', dataQuestion: true, source: requestClassification.type === 'navigation' ? 'merged' : 'heuristic' });
|
|
2145
|
+
dataQuestion = true;
|
|
2146
|
+
recordStep('Planning: app data intent classified request', {
|
|
2147
|
+
collection: normalizeOptionalString((_j = heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.payload) === null || _j === void 0 ? void 0 : _j.collection) || undefined,
|
|
2148
|
+
heuristic: normalizeOptionalString(heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.rawLine) || undefined
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2230
2151
|
if (hasDeterministicHeuristicFastPath) {
|
|
2231
2152
|
recordStep('Planning: heuristic directive fast path', {
|
|
2232
2153
|
type: heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.type,
|
|
2233
|
-
collection: normalizeOptionalString((
|
|
2154
|
+
collection: normalizeOptionalString((_k = heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.payload) === null || _k === void 0 ? void 0 : _k.collection) || undefined,
|
|
2234
2155
|
heuristic: normalizeOptionalString(heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.rawLine) || undefined
|
|
2235
2156
|
});
|
|
2236
2157
|
}
|
|
2237
2158
|
prompt_1 = buildAssistantCodexPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, assistantSystemPrompt);
|
|
2238
2159
|
return [4 /*yield*/, resolveAssistantWorkspaceRoot()];
|
|
2239
2160
|
case 7:
|
|
2240
|
-
workspaceRoot =
|
|
2161
|
+
workspaceRoot = _19.sent();
|
|
2241
2162
|
codexConfig = resolveCodexSettings({
|
|
2242
2163
|
model: codexModel,
|
|
2243
2164
|
fallbackModels: codexFallbackModels
|
|
@@ -2286,20 +2207,20 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2286
2207
|
publicationHints: publicationHints,
|
|
2287
2208
|
inputClientId: input.id_client
|
|
2288
2209
|
});
|
|
2289
|
-
|
|
2210
|
+
_19.label = 8;
|
|
2290
2211
|
case 8:
|
|
2291
|
-
|
|
2212
|
+
_19.trys.push([8, 10, , 11]);
|
|
2292
2213
|
plannerStart = Date.now();
|
|
2293
2214
|
return [4 /*yield*/, runCodexInWorkerThread(plannerPrompt, applyCodexStageBudget(plannerRunOptions), codexConfig, streamProgress)];
|
|
2294
2215
|
case 9:
|
|
2295
|
-
plannerRaw =
|
|
2216
|
+
plannerRaw = _19.sent();
|
|
2296
2217
|
accumulateCodexUsage(plannerPrompt, plannerRaw);
|
|
2297
2218
|
timingBreakdown.plannerMs = Date.now() - plannerStart;
|
|
2298
2219
|
plannerOutput = parseJsonObject(plannerRaw);
|
|
2299
2220
|
recordStep('Planning: planner result', { parsed: !!plannerOutput });
|
|
2300
2221
|
return [3 /*break*/, 11];
|
|
2301
2222
|
case 10:
|
|
2302
|
-
_b =
|
|
2223
|
+
_b = _19.sent();
|
|
2303
2224
|
recordStep('Planning: planner result', { parsed: false });
|
|
2304
2225
|
return [3 /*break*/, 11];
|
|
2305
2226
|
case 11: return [3 /*break*/, 13];
|
|
@@ -2319,9 +2240,12 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2319
2240
|
}
|
|
2320
2241
|
recordStep('Planning: planner skipped', { reason: plannerSkipReason });
|
|
2321
2242
|
}
|
|
2322
|
-
|
|
2243
|
+
_19.label = 13;
|
|
2323
2244
|
case 13:
|
|
2324
2245
|
requestClassification = classifyAssistantRequestType(message, plannerOutput || undefined);
|
|
2246
|
+
if (hasDeterministicHeuristicFastPath && !requestClassification.dataQuestion) {
|
|
2247
|
+
requestClassification = __assign(__assign({}, requestClassification), { type: requestClassification.type === 'navigation' ? 'mixed' : 'data', dataQuestion: true, source: requestClassification.type === 'navigation' ? 'merged' : 'heuristic' });
|
|
2248
|
+
}
|
|
2325
2249
|
dataQuestion = requestClassification.dataQuestion;
|
|
2326
2250
|
requestedTimeGrain = resolveAssistantRequestedTimeGrain(message, plannerOutput || undefined);
|
|
2327
2251
|
requestedBreakdownDimensions = extractAssistantRequestedBreakdownDimensions(message);
|
|
@@ -2361,12 +2285,12 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2361
2285
|
directiveSource = 'forced';
|
|
2362
2286
|
lastDirective = heuristicDirectiveFastPath;
|
|
2363
2287
|
usedDeterministicHeuristicFastPath = true;
|
|
2364
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2288
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_l = directive.payload) === null || _l === void 0 ? void 0 : _l.collection) || '');
|
|
2365
2289
|
recordStep('Directive resolved', {
|
|
2366
2290
|
source: directiveSource,
|
|
2367
2291
|
type: directive.type,
|
|
2368
|
-
collection: normalizeOptionalString((
|
|
2369
|
-
permissionView: normalizeOptionalString((
|
|
2292
|
+
collection: normalizeOptionalString((_m = directive.payload) === null || _m === void 0 ? void 0 : _m.collection) || undefined,
|
|
2293
|
+
permissionView: normalizeOptionalString((_o = directive.payload) === null || _o === void 0 ? void 0 : _o.permissionView) || undefined,
|
|
2370
2294
|
reportStyle: 'heuristic_fast_path',
|
|
2371
2295
|
timeGrain: requestedTimeGrain || undefined
|
|
2372
2296
|
});
|
|
@@ -2375,13 +2299,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2375
2299
|
recordStep('Directive: determine tool', { type: 'data-question' });
|
|
2376
2300
|
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode, assistantSystemPrompt);
|
|
2377
2301
|
if (!hasRunBudget('Directive: determine tool')) return [3 /*break*/, 17];
|
|
2378
|
-
|
|
2302
|
+
_19.label = 14;
|
|
2379
2303
|
case 14:
|
|
2380
|
-
|
|
2304
|
+
_19.trys.push([14, 16, , 17]);
|
|
2381
2305
|
directiveStart = Date.now();
|
|
2382
2306
|
return [4 /*yield*/, runCodexInWorkerThread(directivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2383
2307
|
case 15:
|
|
2384
|
-
directiveText =
|
|
2308
|
+
directiveText = _19.sent();
|
|
2385
2309
|
accumulateCodexUsage(directivePrompt, directiveText);
|
|
2386
2310
|
timingBreakdown.directiveMs = Date.now() - directiveStart;
|
|
2387
2311
|
forcedDirective = extractAssistantMongoDirective(directiveText);
|
|
@@ -2389,29 +2313,32 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2389
2313
|
directive = forcedDirective;
|
|
2390
2314
|
directiveSource = 'model';
|
|
2391
2315
|
lastDirective = forcedDirective;
|
|
2392
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2316
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_p = directive.payload) === null || _p === void 0 ? void 0 : _p.collection) || '');
|
|
2393
2317
|
recordStep('Directive resolved', {
|
|
2394
2318
|
source: directiveSource,
|
|
2395
2319
|
type: directive.type,
|
|
2396
|
-
collection: normalizeOptionalString((
|
|
2397
|
-
permissionView: normalizeOptionalString((
|
|
2320
|
+
collection: normalizeOptionalString((_q = directive.payload) === null || _q === void 0 ? void 0 : _q.collection) || undefined,
|
|
2321
|
+
permissionView: normalizeOptionalString((_r = directive.payload) === null || _r === void 0 ? void 0 : _r.permissionView) || undefined
|
|
2398
2322
|
});
|
|
2399
2323
|
}
|
|
2400
2324
|
return [3 /*break*/, 17];
|
|
2401
2325
|
case 16:
|
|
2402
|
-
|
|
2326
|
+
error_2 = _19.sent();
|
|
2327
|
+
recordStep('Directive: determine tool failed', {
|
|
2328
|
+
message: normalizeOptionalString(error_2 === null || error_2 === void 0 ? void 0 : error_2.message) || 'Unknown error'
|
|
2329
|
+
});
|
|
2403
2330
|
return [3 /*break*/, 17];
|
|
2404
2331
|
case 17:
|
|
2405
2332
|
if (!(!directive && !dataQuestion)) return [3 /*break*/, 21];
|
|
2406
2333
|
recordStep('Response: draft initial answer', { mode: 'full' });
|
|
2407
2334
|
if (!hasRunBudget('Response: initial draft')) return [3 /*break*/, 21];
|
|
2408
|
-
|
|
2335
|
+
_19.label = 18;
|
|
2409
2336
|
case 18:
|
|
2410
|
-
|
|
2337
|
+
_19.trys.push([18, 20, , 21]);
|
|
2411
2338
|
initialStart = Date.now();
|
|
2412
2339
|
return [4 /*yield*/, runCodexInWorkerThread(prompt_1, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2413
2340
|
case 19:
|
|
2414
|
-
responseText =
|
|
2341
|
+
responseText = _19.sent();
|
|
2415
2342
|
accumulateCodexUsage(prompt_1, responseText);
|
|
2416
2343
|
timingBreakdown.initialResponseMs = Date.now() - initialStart;
|
|
2417
2344
|
extractedDirective = extractAssistantMongoDirective(responseText);
|
|
@@ -2419,19 +2346,19 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2419
2346
|
if (directive) {
|
|
2420
2347
|
directiveSource = 'model';
|
|
2421
2348
|
lastDirective = directive;
|
|
2422
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2349
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_s = directive.payload) === null || _s === void 0 ? void 0 : _s.collection) || '');
|
|
2423
2350
|
recordStep('Directive resolved', {
|
|
2424
2351
|
source: directiveSource,
|
|
2425
2352
|
type: directive.type,
|
|
2426
|
-
collection: normalizeOptionalString((
|
|
2427
|
-
permissionView: normalizeOptionalString((
|
|
2353
|
+
collection: normalizeOptionalString((_t = directive.payload) === null || _t === void 0 ? void 0 : _t.collection) || undefined,
|
|
2354
|
+
permissionView: normalizeOptionalString((_u = directive.payload) === null || _u === void 0 ? void 0 : _u.permissionView) || undefined
|
|
2428
2355
|
});
|
|
2429
2356
|
}
|
|
2430
2357
|
return [3 /*break*/, 21];
|
|
2431
2358
|
case 20:
|
|
2432
|
-
|
|
2359
|
+
error_3 = _19.sent();
|
|
2433
2360
|
recordStep('Response: initial draft failed', {
|
|
2434
|
-
message: normalizeOptionalString(
|
|
2361
|
+
message: normalizeOptionalString(error_3 === null || error_3 === void 0 ? void 0 : error_3.message) || 'Unknown error'
|
|
2435
2362
|
});
|
|
2436
2363
|
return [3 /*break*/, 21];
|
|
2437
2364
|
case 21:
|
|
@@ -2439,13 +2366,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2439
2366
|
recordStep('Directive: forced retry', { mode: 'directive-only' });
|
|
2440
2367
|
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode, assistantSystemPrompt);
|
|
2441
2368
|
if (!hasRunBudget('Directive: forced retry')) return [3 /*break*/, 25];
|
|
2442
|
-
|
|
2369
|
+
_19.label = 22;
|
|
2443
2370
|
case 22:
|
|
2444
|
-
|
|
2371
|
+
_19.trys.push([22, 24, , 25]);
|
|
2445
2372
|
forcedStart = Date.now();
|
|
2446
2373
|
return [4 /*yield*/, runCodexInWorkerThread(directivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2447
2374
|
case 23:
|
|
2448
|
-
directiveText =
|
|
2375
|
+
directiveText = _19.sent();
|
|
2449
2376
|
accumulateCodexUsage(directivePrompt, directiveText);
|
|
2450
2377
|
timingBreakdown.forcedDirectiveMs = Date.now() - forcedStart;
|
|
2451
2378
|
forcedDirective = extractAssistantMongoDirective(directiveText);
|
|
@@ -2453,17 +2380,20 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2453
2380
|
directive = forcedDirective;
|
|
2454
2381
|
directiveSource = 'forced';
|
|
2455
2382
|
lastDirective = forcedDirective;
|
|
2456
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2383
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_v = directive.payload) === null || _v === void 0 ? void 0 : _v.collection) || '');
|
|
2457
2384
|
recordStep('Directive resolved', {
|
|
2458
2385
|
source: directiveSource,
|
|
2459
2386
|
type: directive.type,
|
|
2460
|
-
collection: normalizeOptionalString((
|
|
2461
|
-
permissionView: normalizeOptionalString((
|
|
2387
|
+
collection: normalizeOptionalString((_w = directive.payload) === null || _w === void 0 ? void 0 : _w.collection) || undefined,
|
|
2388
|
+
permissionView: normalizeOptionalString((_x = directive.payload) === null || _x === void 0 ? void 0 : _x.permissionView) || undefined
|
|
2462
2389
|
});
|
|
2463
2390
|
}
|
|
2464
2391
|
return [3 /*break*/, 25];
|
|
2465
2392
|
case 24:
|
|
2466
|
-
|
|
2393
|
+
error_4 = _19.sent();
|
|
2394
|
+
recordStep('Directive: forced retry failed', {
|
|
2395
|
+
message: normalizeOptionalString(error_4 === null || error_4 === void 0 ? void 0 : error_4.message) || 'Unknown error'
|
|
2396
|
+
});
|
|
2467
2397
|
return [3 /*break*/, 25];
|
|
2468
2398
|
case 25:
|
|
2469
2399
|
if (!(directive
|
|
@@ -2482,13 +2412,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2482
2412
|
strict: true
|
|
2483
2413
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2484
2414
|
if (!hasRunBudget('Directive: dated retry')) return [3 /*break*/, 29];
|
|
2485
|
-
|
|
2415
|
+
_19.label = 26;
|
|
2486
2416
|
case 26:
|
|
2487
|
-
|
|
2417
|
+
_19.trys.push([26, 28, , 29]);
|
|
2488
2418
|
strictStart = Date.now();
|
|
2489
2419
|
return [4 /*yield*/, runCodexInWorkerThread(strictDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2490
2420
|
case 27:
|
|
2491
|
-
strictDirectiveText =
|
|
2421
|
+
strictDirectiveText = _19.sent();
|
|
2492
2422
|
accumulateCodexUsage(strictDirectivePrompt, strictDirectiveText);
|
|
2493
2423
|
timingBreakdown.forcedDirectiveMs += Date.now() - strictStart;
|
|
2494
2424
|
strictDirective = extractAssistantMongoDirective(strictDirectiveText);
|
|
@@ -2499,19 +2429,22 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2499
2429
|
directiveSource = 'forced';
|
|
2500
2430
|
lastDirective = strictDirective;
|
|
2501
2431
|
datedDirectiveRetryUsed = true;
|
|
2502
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2432
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_y = directive.payload) === null || _y === void 0 ? void 0 : _y.collection) || '');
|
|
2503
2433
|
recordStep('Directive resolved', {
|
|
2504
2434
|
source: directiveSource,
|
|
2505
2435
|
type: directive.type,
|
|
2506
|
-
collection: normalizeOptionalString((
|
|
2507
|
-
permissionView: normalizeOptionalString((
|
|
2436
|
+
collection: normalizeOptionalString((_z = directive.payload) === null || _z === void 0 ? void 0 : _z.collection) || undefined,
|
|
2437
|
+
permissionView: normalizeOptionalString((_0 = directive.payload) === null || _0 === void 0 ? void 0 : _0.permissionView) || undefined,
|
|
2508
2438
|
reportStyle: strictDirectiveIsDated ? 'dated' : 'aggregate_fallback',
|
|
2509
2439
|
timeGrain: requestedTimeGrain || undefined
|
|
2510
2440
|
});
|
|
2511
2441
|
}
|
|
2512
2442
|
return [3 /*break*/, 29];
|
|
2513
2443
|
case 28:
|
|
2514
|
-
|
|
2444
|
+
error_5 = _19.sent();
|
|
2445
|
+
recordStep('Directive: dated retry failed', {
|
|
2446
|
+
message: normalizeOptionalString(error_5 === null || error_5 === void 0 ? void 0 : error_5.message) || 'Unknown error'
|
|
2447
|
+
});
|
|
2515
2448
|
return [3 /*break*/, 29];
|
|
2516
2449
|
case 29:
|
|
2517
2450
|
if (!(directive
|
|
@@ -2530,13 +2463,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2530
2463
|
strict: true
|
|
2531
2464
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2532
2465
|
if (!hasRunBudget('Directive: dated guard retry')) return [3 /*break*/, 33];
|
|
2533
|
-
|
|
2466
|
+
_19.label = 30;
|
|
2534
2467
|
case 30:
|
|
2535
|
-
|
|
2468
|
+
_19.trys.push([30, 32, , 33]);
|
|
2536
2469
|
guardStart = Date.now();
|
|
2537
2470
|
return [4 /*yield*/, runCodexInWorkerThread(guardDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2538
2471
|
case 31:
|
|
2539
|
-
guardDirectiveText =
|
|
2472
|
+
guardDirectiveText = _19.sent();
|
|
2540
2473
|
accumulateCodexUsage(guardDirectivePrompt, guardDirectiveText);
|
|
2541
2474
|
timingBreakdown.forcedDirectiveMs += Date.now() - guardStart;
|
|
2542
2475
|
guardDirective = extractAssistantMongoDirective(guardDirectiveText);
|
|
@@ -2545,19 +2478,22 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2545
2478
|
directiveSource = 'forced';
|
|
2546
2479
|
lastDirective = guardDirective;
|
|
2547
2480
|
datedDirectiveRetryUsed = true;
|
|
2548
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2481
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_1 = directive.payload) === null || _1 === void 0 ? void 0 : _1.collection) || '');
|
|
2549
2482
|
recordStep('Directive resolved', {
|
|
2550
2483
|
source: directiveSource,
|
|
2551
2484
|
type: directive.type,
|
|
2552
|
-
collection: normalizeOptionalString((
|
|
2553
|
-
permissionView: normalizeOptionalString((
|
|
2485
|
+
collection: normalizeOptionalString((_2 = directive.payload) === null || _2 === void 0 ? void 0 : _2.collection) || undefined,
|
|
2486
|
+
permissionView: normalizeOptionalString((_3 = directive.payload) === null || _3 === void 0 ? void 0 : _3.permissionView) || undefined,
|
|
2554
2487
|
reportStyle: isAssistantDirectiveDated(guardDirective) ? 'dated' : 'aggregate_fallback',
|
|
2555
2488
|
timeGrain: requestedTimeGrain || undefined
|
|
2556
2489
|
});
|
|
2557
2490
|
}
|
|
2558
2491
|
return [3 /*break*/, 33];
|
|
2559
2492
|
case 32:
|
|
2560
|
-
|
|
2493
|
+
error_6 = _19.sent();
|
|
2494
|
+
recordStep('Directive: dated guard retry failed', {
|
|
2495
|
+
message: normalizeOptionalString(error_6 === null || error_6 === void 0 ? void 0 : error_6.message) || 'Unknown error'
|
|
2496
|
+
});
|
|
2561
2497
|
return [3 /*break*/, 33];
|
|
2562
2498
|
case 33:
|
|
2563
2499
|
if (!(directive
|
|
@@ -2576,13 +2512,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2576
2512
|
strict: true
|
|
2577
2513
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2578
2514
|
if (!hasRunBudget('Directive: grouped guard retry')) return [3 /*break*/, 37];
|
|
2579
|
-
|
|
2515
|
+
_19.label = 34;
|
|
2580
2516
|
case 34:
|
|
2581
|
-
|
|
2517
|
+
_19.trys.push([34, 36, , 37]);
|
|
2582
2518
|
groupedStart = Date.now();
|
|
2583
2519
|
return [4 /*yield*/, runCodexInWorkerThread(groupedDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2584
2520
|
case 35:
|
|
2585
|
-
groupedDirectiveText =
|
|
2521
|
+
groupedDirectiveText = _19.sent();
|
|
2586
2522
|
accumulateCodexUsage(groupedDirectivePrompt, groupedDirectiveText);
|
|
2587
2523
|
timingBreakdown.forcedDirectiveMs += Date.now() - groupedStart;
|
|
2588
2524
|
groupedDirective = extractAssistantMongoDirective(groupedDirectiveText);
|
|
@@ -2591,12 +2527,12 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2591
2527
|
directiveSource = 'forced';
|
|
2592
2528
|
lastDirective = groupedDirective;
|
|
2593
2529
|
datedDirectiveRetryUsed = true;
|
|
2594
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2530
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_4 = directive.payload) === null || _4 === void 0 ? void 0 : _4.collection) || '');
|
|
2595
2531
|
recordStep('Directive resolved', {
|
|
2596
2532
|
source: directiveSource,
|
|
2597
2533
|
type: directive.type,
|
|
2598
|
-
collection: normalizeOptionalString((
|
|
2599
|
-
permissionView: normalizeOptionalString((
|
|
2534
|
+
collection: normalizeOptionalString((_5 = directive.payload) === null || _5 === void 0 ? void 0 : _5.collection) || undefined,
|
|
2535
|
+
permissionView: normalizeOptionalString((_6 = directive.payload) === null || _6 === void 0 ? void 0 : _6.permissionView) || undefined,
|
|
2600
2536
|
reportStyle: isAssistantDirectiveDated(groupedDirective)
|
|
2601
2537
|
? 'dated'
|
|
2602
2538
|
: 'grouped',
|
|
@@ -2606,7 +2542,10 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2606
2542
|
}
|
|
2607
2543
|
return [3 /*break*/, 37];
|
|
2608
2544
|
case 36:
|
|
2609
|
-
|
|
2545
|
+
error_7 = _19.sent();
|
|
2546
|
+
recordStep('Directive: grouped guard retry failed', {
|
|
2547
|
+
message: normalizeOptionalString(error_7 === null || error_7 === void 0 ? void 0 : error_7.message) || 'Unknown error'
|
|
2548
|
+
});
|
|
2610
2549
|
return [3 /*break*/, 37];
|
|
2611
2550
|
case 37:
|
|
2612
2551
|
if (!directive && dataQuestion) {
|
|
@@ -2618,23 +2557,24 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2618
2557
|
recordStep('Directive resolved', {
|
|
2619
2558
|
source: directiveSource,
|
|
2620
2559
|
type: directive.type,
|
|
2621
|
-
collection: normalizeOptionalString((
|
|
2622
|
-
permissionView: normalizeOptionalString((
|
|
2560
|
+
collection: normalizeOptionalString((_7 = directive.payload) === null || _7 === void 0 ? void 0 : _7.collection) || undefined,
|
|
2561
|
+
permissionView: normalizeOptionalString((_8 = directive.payload) === null || _8 === void 0 ? void 0 : _8.permissionView) || undefined,
|
|
2623
2562
|
reportStyle: 'heuristic_fallback'
|
|
2624
2563
|
});
|
|
2625
2564
|
}
|
|
2626
2565
|
}
|
|
2627
2566
|
if (directive) {
|
|
2628
|
-
requestedCollection = normalizeOptionalString((
|
|
2567
|
+
requestedCollection = normalizeOptionalString((_9 = directive.payload) === null || _9 === void 0 ? void 0 : _9.collection);
|
|
2629
2568
|
allowCollectionOverride = !isAssistantDeterministicHeuristicDirective(directive);
|
|
2630
2569
|
collectionOverride = allowCollectionOverride
|
|
2631
2570
|
? resolveCollectionOverrideWithContext({
|
|
2632
2571
|
message: message,
|
|
2633
2572
|
collectionRanking: collectionRanking,
|
|
2634
2573
|
requestedCollection: requestedCollection,
|
|
2635
|
-
permissionView: normalizeOptionalString((
|
|
2574
|
+
permissionView: normalizeOptionalString((_10 = directive.payload) === null || _10 === void 0 ? void 0 : _10.permissionView) || contextRoute,
|
|
2636
2575
|
collectionNames: collectionNames,
|
|
2637
|
-
collectionHints: collectionHints
|
|
2576
|
+
collectionHints: collectionHints,
|
|
2577
|
+
appId: input.id_app
|
|
2638
2578
|
})
|
|
2639
2579
|
: null;
|
|
2640
2580
|
if (collectionOverride) {
|
|
@@ -2658,7 +2598,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2658
2598
|
});
|
|
2659
2599
|
if (!deniedModuleByIntent) return [3 /*break*/, 38];
|
|
2660
2600
|
permissionLabel = formatAssistantModulePermissionLabel(deniedModuleByIntent);
|
|
2661
|
-
progressTracker.push(
|
|
2601
|
+
progressTracker.push(AI_ASSISTANT_PROGRESS_DATA_LOOKUP);
|
|
2662
2602
|
recordStep('Grabbing Data: denied', {
|
|
2663
2603
|
reason: "".concat(deniedModuleByIntent, "_permission_required")
|
|
2664
2604
|
});
|
|
@@ -2722,14 +2662,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2722
2662
|
progressTracker.push(directiveAcknowledgementText);
|
|
2723
2663
|
}
|
|
2724
2664
|
else {
|
|
2725
|
-
progressTracker.push(deterministicDataIntentDirective ?
|
|
2665
|
+
progressTracker.push(deterministicDataIntentDirective ? AI_ASSISTANT_PROGRESS_DATA_RUNNING : AI_ASSISTANT_PROGRESS_DATA_LOOKUP);
|
|
2726
2666
|
}
|
|
2727
2667
|
directiveProgressMessages.slice(0, 2).forEach(function (messageText) { return progressTracker.push(messageText); });
|
|
2728
2668
|
executionDirective = effectiveDirective;
|
|
2729
2669
|
probeFieldHints = [];
|
|
2730
|
-
|
|
2670
|
+
_19.label = 39;
|
|
2731
2671
|
case 39:
|
|
2732
|
-
|
|
2672
|
+
_19.trys.push([39, 64, , 65]);
|
|
2733
2673
|
if (!(!alwaysAllowProbeEnabled && !hasRunBudget('Grabbing Data', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS))) return [3 /*break*/, 40];
|
|
2734
2674
|
assistantContent = buildAssistantRunBudgetExceededMessage();
|
|
2735
2675
|
toolTelemetry.final = {
|
|
@@ -2761,20 +2701,20 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2761
2701
|
attempted: true
|
|
2762
2702
|
};
|
|
2763
2703
|
probeStart = Date.now();
|
|
2764
|
-
|
|
2704
|
+
_19.label = 41;
|
|
2765
2705
|
case 41:
|
|
2766
|
-
|
|
2706
|
+
_19.trys.push([41, 46, , 47]);
|
|
2767
2707
|
if (!(probeDirective.type === 'aggregate')) return [3 /*break*/, 43];
|
|
2768
2708
|
return [4 /*yield*/, executeAiAssistantReportBuilderAggregate(probeRequest, context)];
|
|
2769
2709
|
case 42:
|
|
2770
|
-
|
|
2710
|
+
_c = _19.sent();
|
|
2771
2711
|
return [3 /*break*/, 45];
|
|
2772
2712
|
case 43: return [4 /*yield*/, executeAiAssistantReportBuilderRead(probeRequest, context)];
|
|
2773
2713
|
case 44:
|
|
2774
|
-
|
|
2775
|
-
|
|
2714
|
+
_c = _19.sent();
|
|
2715
|
+
_19.label = 45;
|
|
2776
2716
|
case 45:
|
|
2777
|
-
probeResponse =
|
|
2717
|
+
probeResponse = _c;
|
|
2778
2718
|
probeDurationMs = Date.now() - probeStart;
|
|
2779
2719
|
timingBreakdown.toolMs += probeDurationMs;
|
|
2780
2720
|
probeRowCount = Array.isArray(probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.documents)
|
|
@@ -2794,7 +2734,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2794
2734
|
};
|
|
2795
2735
|
recordStep('Grabbing Data: probe complete', {
|
|
2796
2736
|
rowCount: probeRowCount,
|
|
2797
|
-
collection: normalizeOptionalString(((
|
|
2737
|
+
collection: normalizeOptionalString(((_11 = probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.debug) === null || _11 === void 0 ? void 0 : _11.collectionResolved) || ((_12 = probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.debug) === null || _12 === void 0 ? void 0 : _12.collection)) || undefined
|
|
2798
2738
|
});
|
|
2799
2739
|
if (probeRewrite.notes.length || probeFieldHints.length) {
|
|
2800
2740
|
recordStep('Grabbing Data: probe rewrite', {
|
|
@@ -2804,7 +2744,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2804
2744
|
}
|
|
2805
2745
|
return [3 /*break*/, 47];
|
|
2806
2746
|
case 46:
|
|
2807
|
-
probeError_1 =
|
|
2747
|
+
probeError_1 = _19.sent();
|
|
2808
2748
|
probeDurationMs = Date.now() - probeStart;
|
|
2809
2749
|
probeErrorMessage = normalizeOptionalString(probeError_1 === null || probeError_1 === void 0 ? void 0 : probeError_1.message) || 'Unknown error';
|
|
2810
2750
|
toolTelemetry.probe = {
|
|
@@ -2823,7 +2763,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2823
2763
|
attempted: false,
|
|
2824
2764
|
skippedReason: 'probe_directive_missing_payload'
|
|
2825
2765
|
};
|
|
2826
|
-
|
|
2766
|
+
_19.label = 49;
|
|
2827
2767
|
case 49: return [3 /*break*/, 51];
|
|
2828
2768
|
case 50:
|
|
2829
2769
|
if (probeEnabled) {
|
|
@@ -2838,7 +2778,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2838
2778
|
skippedReason: 'aggregate_probe_disabled'
|
|
2839
2779
|
};
|
|
2840
2780
|
}
|
|
2841
|
-
|
|
2781
|
+
_19.label = 51;
|
|
2842
2782
|
case 51:
|
|
2843
2783
|
if (!(!alwaysAllowProbeEnabled && !hasRunBudget('Grabbing Data: final', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS))) return [3 /*break*/, 52];
|
|
2844
2784
|
assistantContent = buildAssistantRunBudgetExceededMessage();
|
|
@@ -2868,14 +2808,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2868
2808
|
if (!(executionDirective.type === 'aggregate')) return [3 /*break*/, 54];
|
|
2869
2809
|
return [4 /*yield*/, executeAiAssistantReportBuilderAggregate(toolRequest, context)];
|
|
2870
2810
|
case 53:
|
|
2871
|
-
|
|
2811
|
+
_d = _19.sent();
|
|
2872
2812
|
return [3 /*break*/, 56];
|
|
2873
2813
|
case 54: return [4 /*yield*/, executeAiAssistantReportBuilderRead(toolRequest, context)];
|
|
2874
2814
|
case 55:
|
|
2875
|
-
|
|
2876
|
-
|
|
2815
|
+
_d = _19.sent();
|
|
2816
|
+
_19.label = 56;
|
|
2877
2817
|
case 56:
|
|
2878
|
-
toolResponse =
|
|
2818
|
+
toolResponse = _d;
|
|
2879
2819
|
toolDurationMs = Date.now() - toolStart;
|
|
2880
2820
|
timingBreakdown.toolMs += toolDurationMs;
|
|
2881
2821
|
toolResponseDebug = (toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) && typeof toolResponse.debug === 'object'
|
|
@@ -2884,8 +2824,8 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2884
2824
|
toolPayload = buildAssistantToolResultPayload(executionDirective, toolResponse, message);
|
|
2885
2825
|
toolResult = toolPayload.result;
|
|
2886
2826
|
resolvedToolCollection = normalizeOptionalString(toolPayload.result.output.collection
|
|
2887
|
-
|| ((
|
|
2888
|
-
|| ((
|
|
2827
|
+
|| ((_13 = toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) === null || _13 === void 0 ? void 0 : _13.collectionResolved)
|
|
2828
|
+
|| ((_14 = toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) === null || _14 === void 0 ? void 0 : _14.collection)
|
|
2889
2829
|
|| requestedToolCollection);
|
|
2890
2830
|
toolTelemetry.final = {
|
|
2891
2831
|
attempted: true,
|
|
@@ -2901,7 +2841,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2901
2841
|
total: toolPayload.result.output.total,
|
|
2902
2842
|
columns: toolPayload.result.output.columns
|
|
2903
2843
|
});
|
|
2904
|
-
progressTracker.push(
|
|
2844
|
+
progressTracker.push(AI_ASSISTANT_PROGRESS_DRAFT);
|
|
2905
2845
|
zeroRowResult = toolPayload.result.output.rowCount <= 0;
|
|
2906
2846
|
toolTelemetry.outcome = zeroRowResult ? { zeroRows: true } : undefined;
|
|
2907
2847
|
followupCodexEnabled = resolveAssistantFollowupCodexEnabled(input.config);
|
|
@@ -2924,20 +2864,20 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2924
2864
|
recordStep('Drafting response');
|
|
2925
2865
|
followupPrompt = buildAssistantCodexToolFollowupPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, toolPayload.prompt, assistantSystemPrompt);
|
|
2926
2866
|
if (!hasRunBudget('Drafting response: followup')) return [3 /*break*/, 62];
|
|
2927
|
-
|
|
2867
|
+
_19.label = 58;
|
|
2928
2868
|
case 58:
|
|
2929
|
-
|
|
2869
|
+
_19.trys.push([58, 60, , 61]);
|
|
2930
2870
|
followupStart = Date.now();
|
|
2931
2871
|
return [4 /*yield*/, runCodexInWorkerThread(followupPrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2932
2872
|
case 59:
|
|
2933
|
-
followupText =
|
|
2873
|
+
followupText = _19.sent();
|
|
2934
2874
|
accumulateCodexUsage(followupPrompt, followupText);
|
|
2935
2875
|
timingBreakdown.followupMs = Date.now() - followupStart;
|
|
2936
2876
|
assistantContent = sanitizeAssistantResponse(followupText);
|
|
2937
2877
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2938
2878
|
return [3 /*break*/, 61];
|
|
2939
2879
|
case 60:
|
|
2940
|
-
|
|
2880
|
+
_e = _19.sent();
|
|
2941
2881
|
assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
|
|
2942
2882
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2943
2883
|
return [3 /*break*/, 61];
|
|
@@ -2945,13 +2885,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2945
2885
|
case 62:
|
|
2946
2886
|
assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
|
|
2947
2887
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2948
|
-
|
|
2888
|
+
_19.label = 63;
|
|
2949
2889
|
case 63: return [3 /*break*/, 65];
|
|
2950
2890
|
case 64:
|
|
2951
|
-
|
|
2952
|
-
assistantContent = buildAssistantToolErrorMessage(
|
|
2953
|
-
toolError =
|
|
2954
|
-
errorMessage = normalizeOptionalString(
|
|
2891
|
+
error_8 = _19.sent();
|
|
2892
|
+
assistantContent = buildAssistantToolErrorMessage(error_8);
|
|
2893
|
+
toolError = error_8;
|
|
2894
|
+
errorMessage = normalizeOptionalString(error_8 === null || error_8 === void 0 ? void 0 : error_8.message) || 'Unknown error';
|
|
2955
2895
|
existingFinal = toolTelemetry.final && typeof toolTelemetry.final === 'object'
|
|
2956
2896
|
? toolTelemetry.final
|
|
2957
2897
|
: { attempted: false };
|
|
@@ -2960,14 +2900,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2960
2900
|
return [3 /*break*/, 65];
|
|
2961
2901
|
case 65: return [3 /*break*/, 67];
|
|
2962
2902
|
case 66:
|
|
2963
|
-
progressTracker.push(
|
|
2903
|
+
progressTracker.push(AI_ASSISTANT_PROGRESS_DRAFT);
|
|
2964
2904
|
recordStep('Drafting response');
|
|
2965
|
-
|
|
2905
|
+
_19.label = 67;
|
|
2966
2906
|
case 67: return [3 /*break*/, 70];
|
|
2967
2907
|
case 68:
|
|
2968
|
-
|
|
2969
|
-
assistantContent = buildAssistantCodexErrorMessage(
|
|
2970
|
-
recordStep('Error', { message: normalizeOptionalString(
|
|
2908
|
+
error_9 = _19.sent();
|
|
2909
|
+
assistantContent = buildAssistantCodexErrorMessage(error_9);
|
|
2910
|
+
recordStep('Error', { message: normalizeOptionalString(error_9 === null || error_9 === void 0 ? void 0 : error_9.message) || 'Unknown error' });
|
|
2971
2911
|
return [3 /*break*/, 70];
|
|
2972
2912
|
case 69:
|
|
2973
2913
|
progressTracker.stop();
|
|
@@ -2983,10 +2923,10 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2983
2923
|
assistantContent = applyAssistantDatedReportWindow(assistantContent, toolResult);
|
|
2984
2924
|
assistantContent = applyAssistantLotNumberResponseGuard(assistantContent, message, toolResult);
|
|
2985
2925
|
assistantContent = normalizeAssistantCurrencyText(assistantContent);
|
|
2986
|
-
if (toolError && !normalizeOptionalString((
|
|
2926
|
+
if (toolError && !normalizeOptionalString((_15 = toolTelemetry === null || toolTelemetry === void 0 ? void 0 : toolTelemetry.outcome) === null || _15 === void 0 ? void 0 : _15.error)) {
|
|
2987
2927
|
toolTelemetry.outcome = __assign(__assign({}, (toolTelemetry.outcome || {})), { error: normalizeOptionalString(toolError === null || toolError === void 0 ? void 0 : toolError.message) || 'tool_error' });
|
|
2988
2928
|
}
|
|
2989
|
-
if (((
|
|
2929
|
+
if (((_16 = toolResult === null || toolResult === void 0 ? void 0 : toolResult.output) === null || _16 === void 0 ? void 0 : _16.rowCount) === 0 && !((_17 = toolTelemetry === null || toolTelemetry === void 0 ? void 0 : toolTelemetry.outcome) === null || _17 === void 0 ? void 0 : _17.zeroRows)) {
|
|
2990
2930
|
toolTelemetry.outcome = __assign(__assign({}, (toolTelemetry.outcome || {})), { zeroRows: true });
|
|
2991
2931
|
}
|
|
2992
2932
|
includeToolExecutionTelemetry = dataQuestion
|
|
@@ -3016,9 +2956,9 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3016
2956
|
});
|
|
3017
2957
|
}
|
|
3018
2958
|
finalNow = new Date();
|
|
3019
|
-
|
|
2959
|
+
_19.label = 71;
|
|
3020
2960
|
case 71:
|
|
3021
|
-
|
|
2961
|
+
_19.trys.push([71, 83, , 94]);
|
|
3022
2962
|
if (canViewDebug) {
|
|
3023
2963
|
finishedAt = Date.now();
|
|
3024
2964
|
codexMs = timingBreakdown.directiveMs
|
|
@@ -3121,10 +3061,10 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3121
3061
|
if (!finalUsage) return [3 /*break*/, 76];
|
|
3122
3062
|
return [4 /*yield*/, resolveClientId(conversation, input.id_client, context === null || context === void 0 ? void 0 : context.id_user)];
|
|
3123
3063
|
case 72:
|
|
3124
|
-
usageClientId =
|
|
3125
|
-
|
|
3064
|
+
usageClientId = _19.sent();
|
|
3065
|
+
_19.label = 73;
|
|
3126
3066
|
case 73:
|
|
3127
|
-
|
|
3067
|
+
_19.trys.push([73, 75, , 76]);
|
|
3128
3068
|
finalUsageLedgerEntry = buildAssistantAIRunUsageLedgerEntry({
|
|
3129
3069
|
idClient: usageClientId || '',
|
|
3130
3070
|
model: finalUsage.model,
|
|
@@ -3145,10 +3085,10 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3145
3085
|
});
|
|
3146
3086
|
return [4 /*yield*/, (0, openai_usage_ledger_manager_1.recordOpenAIUsage)(finalUsageLedgerEntry)];
|
|
3147
3087
|
case 74:
|
|
3148
|
-
|
|
3088
|
+
_19.sent();
|
|
3149
3089
|
return [3 /*break*/, 76];
|
|
3150
3090
|
case 75:
|
|
3151
|
-
usageError_1 =
|
|
3091
|
+
usageError_1 = _19.sent();
|
|
3152
3092
|
console.error(new Date(), 'Failed to record AI usage', usageError_1);
|
|
3153
3093
|
return [3 /*break*/, 76];
|
|
3154
3094
|
case 76:
|
|
@@ -3164,11 +3104,11 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3164
3104
|
}
|
|
3165
3105
|
return [4 /*yield*/, updateAssistantMessageWithFallback(assistantMessageId, setPayload)];
|
|
3166
3106
|
case 77:
|
|
3167
|
-
|
|
3168
|
-
|
|
3107
|
+
_19.sent();
|
|
3108
|
+
_19.label = 78;
|
|
3169
3109
|
case 78: return [4 /*yield*/, touchConversation(conversation._id, finalNow, assistantMessageId ? String(assistantMessageId) : undefined)];
|
|
3170
3110
|
case 79:
|
|
3171
|
-
|
|
3111
|
+
_19.sent();
|
|
3172
3112
|
return [4 /*yield*/, recordAssistantAnswerAIRun({
|
|
3173
3113
|
runId: buildAssistantAIRunId('codex_query', [conversation._id, assistantMessageId || requestId]),
|
|
3174
3114
|
requestId: requestId || undefined,
|
|
@@ -3177,7 +3117,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3177
3117
|
userMessage: __assign(__assign({}, userDoc), { _id: userMessageId ? String(userMessageId) : undefined }),
|
|
3178
3118
|
assistantMessage: finalAssistantDoc,
|
|
3179
3119
|
usageLedgerEntry: finalUsageLedgerEntry || undefined,
|
|
3180
|
-
correctnessChecks: ((
|
|
3120
|
+
correctnessChecks: ((_18 = toolTelemetry === null || toolTelemetry === void 0 ? void 0 : toolTelemetry.outcome) === null || _18 === void 0 ? void 0 : _18.error) ? [{
|
|
3181
3121
|
assertion: 'assistant_tool_execution',
|
|
3182
3122
|
status: 'fail',
|
|
3183
3123
|
observed: toolTelemetry.outcome.error,
|
|
@@ -3187,21 +3127,21 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3187
3127
|
now: finalNow
|
|
3188
3128
|
})];
|
|
3189
3129
|
case 80:
|
|
3190
|
-
|
|
3130
|
+
_19.sent();
|
|
3191
3131
|
if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 82];
|
|
3192
3132
|
return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
|
|
3193
3133
|
case 81:
|
|
3194
|
-
|
|
3195
|
-
|
|
3134
|
+
_19.sent();
|
|
3135
|
+
_19.label = 82;
|
|
3196
3136
|
case 82: return [2 /*return*/, finalAssistantDoc];
|
|
3197
3137
|
case 83:
|
|
3198
|
-
finalizeError_1 =
|
|
3138
|
+
finalizeError_1 = _19.sent();
|
|
3199
3139
|
failedAt = new Date();
|
|
3200
3140
|
fallbackContent = assistantContent || buildAssistantCodexErrorMessage(finalizeError_1);
|
|
3201
3141
|
failureMetadata = __assign(__assign(__assign(__assign(__assign({ model: codexModel }, (codexFallbackModels.length ? { model_fallbacks: codexFallbackModels } : {})), (requestId ? { request_id: requestId } : {})), { pending: false, failed: true }), (toolExecutionTelemetry ? { tool_execution: toolExecutionTelemetry } : {})), { error_message: normalizeOptionalString(finalizeError_1 === null || finalizeError_1 === void 0 ? void 0 : finalizeError_1.message) || 'Unknown error' });
|
|
3202
|
-
|
|
3142
|
+
_19.label = 84;
|
|
3203
3143
|
case 84:
|
|
3204
|
-
|
|
3144
|
+
_19.trys.push([84, 88, , 89]);
|
|
3205
3145
|
if (!assistantMessageId) return [3 /*break*/, 86];
|
|
3206
3146
|
return [4 /*yield*/, updateAssistantMessageWithFallback(assistantMessageId, {
|
|
3207
3147
|
content: fallbackContent,
|
|
@@ -3209,27 +3149,27 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3209
3149
|
updatedAt: failedAt
|
|
3210
3150
|
})];
|
|
3211
3151
|
case 85:
|
|
3212
|
-
|
|
3213
|
-
|
|
3152
|
+
_19.sent();
|
|
3153
|
+
_19.label = 86;
|
|
3214
3154
|
case 86: return [4 /*yield*/, touchConversation(conversation._id, failedAt, assistantMessageId ? String(assistantMessageId) : undefined)];
|
|
3215
3155
|
case 87:
|
|
3216
|
-
|
|
3156
|
+
_19.sent();
|
|
3217
3157
|
return [3 /*break*/, 89];
|
|
3218
3158
|
case 88:
|
|
3219
|
-
persistError_1 =
|
|
3159
|
+
persistError_1 = _19.sent();
|
|
3220
3160
|
console.error(new Date(), 'AI assistant finalize fallback update failed', persistError_1);
|
|
3221
3161
|
return [3 /*break*/, 89];
|
|
3222
3162
|
case 89:
|
|
3223
3163
|
if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 93];
|
|
3224
|
-
|
|
3164
|
+
_19.label = 90;
|
|
3225
3165
|
case 90:
|
|
3226
|
-
|
|
3166
|
+
_19.trys.push([90, 92, , 93]);
|
|
3227
3167
|
return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
|
|
3228
3168
|
case 91:
|
|
3229
|
-
|
|
3169
|
+
_19.sent();
|
|
3230
3170
|
return [3 /*break*/, 93];
|
|
3231
3171
|
case 92:
|
|
3232
|
-
|
|
3172
|
+
_f = _19.sent();
|
|
3233
3173
|
return [3 /*break*/, 93];
|
|
3234
3174
|
case 93:
|
|
3235
3175
|
console.error(new Date(), 'AI assistant run finalize failed:', finalizeError_1);
|
|
@@ -3477,7 +3417,7 @@ function executeAiAssistantReportIssue(payload, context) {
|
|
|
3477
3417
|
}
|
|
3478
3418
|
function executeAiAssistantMongoRead(payload, context) {
|
|
3479
3419
|
return __awaiter(this, void 0, void 0, function () {
|
|
3480
|
-
var input, rawCollection, retryState, triedCollections, dbName, db, idApp, requestHints, lockRequestedCollection, crossCollectionRetryEnabled, collectionResolution, collection, preservePrimaryHintCollection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasReadRuntimeBudget, resolveReadMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, buildFindOptions, buildCountOptions, runFindWithRepair, initialRead, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackRead, fallbackDocs, expanded, fallbackRead, fallbackDocs, nameFallback, fallbackRead, fallbackDocs, _c, multiTermFallback, fallbackRead, fallbackDocs, _d, chemicalLookup, fallbackRead, fallbackDocs, queryFields, _e, aliases, rewrittenQuery, fallbackRead, fallbackDocs, _f, activeFallback, fallbackRead, fallbackDocs, _g, idLookup, fallbackRead, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, existingFallbacks, rejectedQuality,
|
|
3420
|
+
var input, rawCollection, retryState, triedCollections, dbName, db, idApp, requestHints, lockRequestedCollection, crossCollectionRetryEnabled, collectionResolution, collection, preservePrimaryHintCollection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasReadRuntimeBudget, resolveReadMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, buildFindOptions, buildCountOptions, runFindWithRepair, initialRead, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackRead, fallbackDocs, expanded, fallbackRead, fallbackDocs, nameFallback, fallbackRead, fallbackDocs, _c, multiTermFallback, fallbackRead, fallbackDocs, _d, chemicalLookup, fallbackRead, fallbackDocs, queryFields, _e, aliases, rewrittenQuery, fallbackRead, fallbackDocs, _f, activeFallback, fallbackRead, fallbackDocs, _g, idLookup, fallbackRead, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, existingFallbacks, rejectedQuality, error_10, existingErrors, e_1_1, nameFields, dateFields, diagnostics, countOptions, queryNoName, _h, queryNoDate, _j, _k, _l, _m, allCollections, base, alt, altCount, _o, total, sanitizedDocuments, requestedFields, missingFields, _p, projectionAliases, expandedProjection, refreshedDocs, includeIds, fieldAliases, displayDocs, idLookupDisplay, priorityFields, displayMaxRows, display;
|
|
3481
3421
|
var e_1, _q;
|
|
3482
3422
|
var _this = this;
|
|
3483
3423
|
var _r, _s;
|
|
@@ -3621,7 +3561,7 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3621
3561
|
: { readPreference: AI_ASSISTANT_READ_PREFERENCE };
|
|
3622
3562
|
};
|
|
3623
3563
|
runFindWithRepair = function (query, stage) { return __awaiter(_this, void 0, void 0, function () {
|
|
3624
|
-
var stageFindOptions, docs,
|
|
3564
|
+
var stageFindOptions, docs, error_11, repaired, docs;
|
|
3625
3565
|
return __generator(this, function (_a) {
|
|
3626
3566
|
switch (_a.label) {
|
|
3627
3567
|
case 0:
|
|
@@ -3637,13 +3577,13 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3637
3577
|
docs = _a.sent();
|
|
3638
3578
|
return [2 /*return*/, { documents: docs, query: query }];
|
|
3639
3579
|
case 3:
|
|
3640
|
-
|
|
3641
|
-
if (!isAssistantDateArithmeticArgumentError(
|
|
3642
|
-
throw
|
|
3580
|
+
error_11 = _a.sent();
|
|
3581
|
+
if (!isAssistantDateArithmeticArgumentError(error_11)) {
|
|
3582
|
+
throw error_11;
|
|
3643
3583
|
}
|
|
3644
3584
|
repaired = repairAssistantDateArithmeticInQuery(query);
|
|
3645
3585
|
if (!repaired.changed || containsForbiddenMongoOperators(repaired.query)) {
|
|
3646
|
-
throw
|
|
3586
|
+
throw error_11;
|
|
3647
3587
|
}
|
|
3648
3588
|
return [4 /*yield*/, db.collection(collection).find(repaired.query, stageFindOptions).toArray()];
|
|
3649
3589
|
case 4:
|
|
@@ -3821,7 +3761,7 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3821
3761
|
case 24:
|
|
3822
3762
|
probeDocs = _e;
|
|
3823
3763
|
if (!probeDocs.length) return [3 /*break*/, 26];
|
|
3824
|
-
aliases = resolveFieldAliases(probeDocs, queryFields, schemaFields);
|
|
3764
|
+
aliases = resolveFieldAliases(probeDocs, queryFields, schemaFields, idApp);
|
|
3825
3765
|
if (!Object.keys(aliases).length) return [3 /*break*/, 26];
|
|
3826
3766
|
fallbackMeta.queryFieldAliases = {
|
|
3827
3767
|
aliases: aliases,
|
|
@@ -4013,14 +3953,14 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
4013
3953
|
}
|
|
4014
3954
|
return [3 /*break*/, 45];
|
|
4015
3955
|
case 44:
|
|
4016
|
-
|
|
3956
|
+
error_10 = _t.sent();
|
|
4017
3957
|
if (fallbackMeta.collectionRetry && typeof fallbackMeta.collectionRetry === 'object') {
|
|
4018
3958
|
existingErrors = Array.isArray(fallbackMeta.collectionRetry.errors)
|
|
4019
3959
|
? fallbackMeta.collectionRetry.errors
|
|
4020
3960
|
: [];
|
|
4021
3961
|
existingErrors.push({
|
|
4022
3962
|
collection: candidateCollection,
|
|
4023
|
-
error: normalizeOptionalString(
|
|
3963
|
+
error: normalizeOptionalString(error_10 === null || error_10 === void 0 ? void 0 : error_10.message) || 'Unknown error'
|
|
4024
3964
|
});
|
|
4025
3965
|
fallbackMeta.collectionRetry.errors = existingErrors;
|
|
4026
3966
|
}
|
|
@@ -4235,7 +4175,7 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
4235
4175
|
}
|
|
4236
4176
|
function executeAiAssistantMongoAggregate(payload, context) {
|
|
4237
4177
|
return __awaiter(this, void 0, void 0, function () {
|
|
4238
|
-
var input, rawCollection, retryState, triedCollections, dbName, db, idApp, requestHints, lockRequestedCollection, crossCollectionRetryEnabled, collectionResolution, collection, preservePrimaryHintCollection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasAggregateRuntimeBudget, resolveAggregateMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, executedPipeline, dateField, buildAggregateOptions, buildAggregateCountOptions, runAggregateWithRepair, initialAggregate, documents, probeDocs, fallback, fallbackPipeline, fallbackAggregate, fallbackDocs, createdFallback, createdPipeline, createdAggregate, createdDocs, expanded, expandedAggregate, expandedDocs, completionFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, unwindFallback, shouldUnwind, _c, _d, fallbackPipeline, fallbackAggregate, fallbackDocs, nameFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, _e, _loop_1, i, state_1, matchFields_1, _f, aliases, rewrittenPipeline, fallbackAggregate, fallbackDocs, _g, activeFallback, fallbackAggregate, fallbackDocs, _loop_2, i, state_2, nestedFallbacks, nestedFallbacks_1, nestedFallbacks_1_1, nestedFallback, fallbackPayload, fallbackResult, existingFallbacks,
|
|
4178
|
+
var input, rawCollection, retryState, triedCollections, dbName, db, idApp, requestHints, lockRequestedCollection, crossCollectionRetryEnabled, collectionResolution, collection, preservePrimaryHintCollection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasAggregateRuntimeBudget, resolveAggregateMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, noDataFallbacksEnabled, limitedPipeline, executedPipeline, dateField, buildAggregateOptions, buildAggregateCountOptions, runAggregateWithRepair, initialAggregate, documents, probeDocs, fallback, fallbackPipeline, fallbackAggregate, fallbackDocs, createdFallback, createdPipeline, createdAggregate, createdDocs, expanded, expandedAggregate, expandedDocs, completionFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, unwindFallback, shouldUnwind, _c, _d, fallbackPipeline, fallbackAggregate, fallbackDocs, nameFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, _e, _loop_1, i, state_1, matchFields_1, _f, aliases, rewrittenPipeline, fallbackAggregate, fallbackDocs, _g, activeFallback, fallbackAggregate, fallbackDocs, _loop_2, i, state_2, nestedFallbacks, nestedFallbacks_1, nestedFallbacks_1_1, nestedFallback, fallbackPayload, fallbackResult, existingFallbacks, error_12, errorMessage, existingErrors, e_2_1, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, fallbackAcceptanceOptions, crossCollectionCandidates, crossCollectionCandidates_2, crossCollectionCandidates_2_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, fallbackQuality, existingFallbacks, rejectedQuality, error_13, existingErrors, e_3_1, matchStages, diagnostics, combinedMatch, nameFields, dateFields, countOptions, queryNoName, _h, queryNoDate, _j, _k, _l, _m, allCollections, base, alt, altCount, _o, verification, _p, sanitizedDocuments, includeIds, displayDocs, idLookupDisplay, display;
|
|
4239
4179
|
var e_2, _q, e_3, _r;
|
|
4240
4180
|
var _this = this;
|
|
4241
4181
|
var _s, _t;
|
|
@@ -4371,6 +4311,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4371
4311
|
}
|
|
4372
4312
|
pipelineWithScope = buildAssistantAggregatePipeline(scopedQuery, sanitizedPipeline);
|
|
4373
4313
|
normalizedOptions = normalizeAssistantAggregateOptions(input.options);
|
|
4314
|
+
noDataFallbacksEnabled = normalizedOptions.disableNoDataFallbacks !== true;
|
|
4374
4315
|
limitedPipeline = applyAssistantAggregateLimit(pipelineWithScope, normalizedOptions.limit, normalizedOptions.maxLimit, normalizedOptions.defaultLimit);
|
|
4375
4316
|
executedPipeline = limitedPipeline;
|
|
4376
4317
|
dateField = findAggregateDateField(executedPipeline);
|
|
@@ -4388,7 +4329,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4388
4329
|
: { readPreference: AI_ASSISTANT_READ_PREFERENCE };
|
|
4389
4330
|
};
|
|
4390
4331
|
runAggregateWithRepair = function (pipeline, stage) { return __awaiter(_this, void 0, void 0, function () {
|
|
4391
|
-
var aggregateOptions, docs,
|
|
4332
|
+
var aggregateOptions, docs, error_14, isDateRepair, isRankSortByRepair, isDottedOutputFieldRepair, isPositionalPathRepair, repaired, dottedFieldPath, dottedFieldReferenceRepairUsed, pathReferenceRepair, docs;
|
|
4392
4333
|
return __generator(this, function (_a) {
|
|
4393
4334
|
switch (_a.label) {
|
|
4394
4335
|
case 0:
|
|
@@ -4406,13 +4347,13 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4406
4347
|
docs = _a.sent();
|
|
4407
4348
|
return [2 /*return*/, { documents: docs, pipeline: pipeline }];
|
|
4408
4349
|
case 3:
|
|
4409
|
-
|
|
4410
|
-
isDateRepair = isAssistantDateArithmeticArgumentError(
|
|
4411
|
-
isRankSortByRepair = isAssistantRankSortByError(
|
|
4412
|
-
isDottedOutputFieldRepair = isAssistantDottedOutputFieldError(
|
|
4413
|
-
isPositionalPathRepair = isAssistantPositionalPathError(
|
|
4350
|
+
error_14 = _a.sent();
|
|
4351
|
+
isDateRepair = isAssistantDateArithmeticArgumentError(error_14);
|
|
4352
|
+
isRankSortByRepair = isAssistantRankSortByError(error_14);
|
|
4353
|
+
isDottedOutputFieldRepair = isAssistantDottedOutputFieldError(error_14);
|
|
4354
|
+
isPositionalPathRepair = isAssistantPositionalPathError(error_14);
|
|
4414
4355
|
if (!isDateRepair && !isRankSortByRepair && !isDottedOutputFieldRepair && !isPositionalPathRepair) {
|
|
4415
|
-
throw
|
|
4356
|
+
throw error_14;
|
|
4416
4357
|
}
|
|
4417
4358
|
repaired = isDateRepair
|
|
4418
4359
|
? repairAssistantDateArithmeticInPipeline(pipeline)
|
|
@@ -4424,7 +4365,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4424
4365
|
dottedFieldPath = null;
|
|
4425
4366
|
dottedFieldReferenceRepairUsed = false;
|
|
4426
4367
|
if (isDottedOutputFieldRepair) {
|
|
4427
|
-
dottedFieldPath = extractAssistantDottedFieldPathFromError(
|
|
4368
|
+
dottedFieldPath = extractAssistantDottedFieldPathFromError(error_14);
|
|
4428
4369
|
if (dottedFieldPath) {
|
|
4429
4370
|
pathReferenceRepair = repairAssistantFieldPathReferenceInPipeline(repaired.pipeline, dottedFieldPath);
|
|
4430
4371
|
if (pathReferenceRepair.changed) {
|
|
@@ -4437,7 +4378,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4437
4378
|
}
|
|
4438
4379
|
}
|
|
4439
4380
|
if (!repaired.changed || containsForbiddenMongoOperators(repaired.pipeline)) {
|
|
4440
|
-
throw
|
|
4381
|
+
throw error_14;
|
|
4441
4382
|
}
|
|
4442
4383
|
return [4 /*yield*/, db.collection(collection)
|
|
4443
4384
|
.aggregate(repaired.pipeline, aggregateOptions)
|
|
@@ -4491,7 +4432,13 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4491
4432
|
executedPipeline = initialAggregate.pipeline;
|
|
4492
4433
|
dateField = findAggregateDateField(executedPipeline);
|
|
4493
4434
|
probeDocs = null;
|
|
4494
|
-
if (!
|
|
4435
|
+
if (!documents.length && !noDataFallbacksEnabled && canViewDebug) {
|
|
4436
|
+
fallbackMeta.noDataFallbacks = {
|
|
4437
|
+
skipped: true,
|
|
4438
|
+
reason: 'disabled_by_options'
|
|
4439
|
+
};
|
|
4440
|
+
}
|
|
4441
|
+
if (!(!documents.length && noDataFallbacksEnabled && dateField)) return [3 /*break*/, 11];
|
|
4495
4442
|
fallback = resolveAggregateDateFieldFallback(executedPipeline);
|
|
4496
4443
|
if (!fallback) return [3 /*break*/, 9];
|
|
4497
4444
|
fallbackMeta.dateField = __assign(__assign({}, fallback), { attempted: true, used: false });
|
|
@@ -4524,7 +4471,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4524
4471
|
}
|
|
4525
4472
|
_u.label = 11;
|
|
4526
4473
|
case 11:
|
|
4527
|
-
if (
|
|
4474
|
+
if (!(!documents.length && noDataFallbacksEnabled)) return [3 /*break*/, 13];
|
|
4528
4475
|
expanded = expandAggregateDateMatchFallback(executedPipeline, schemaFields);
|
|
4529
4476
|
if (!expanded) return [3 /*break*/, 13];
|
|
4530
4477
|
fallbackMeta.dateFieldsExpanded = {
|
|
@@ -4544,7 +4491,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4544
4491
|
}
|
|
4545
4492
|
_u.label = 13;
|
|
4546
4493
|
case 13:
|
|
4547
|
-
if (
|
|
4494
|
+
if (!(!documents.length && noDataFallbacksEnabled)) return [3 /*break*/, 17];
|
|
4548
4495
|
completionFallback = resolveAggregateCompletionFallback(executedPipeline);
|
|
4549
4496
|
if (!completionFallback) return [3 /*break*/, 15];
|
|
4550
4497
|
fallbackMeta.completion = {
|
|
@@ -4592,7 +4539,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4592
4539
|
}
|
|
4593
4540
|
_u.label = 17;
|
|
4594
4541
|
case 17:
|
|
4595
|
-
if (!(documents.length <= 1)) return [3 /*break*/, 26];
|
|
4542
|
+
if (!(documents.length <= 1 && noDataFallbacksEnabled)) return [3 /*break*/, 26];
|
|
4596
4543
|
unwindFallback = resolveAggregateUnwindFallback(executedPipeline);
|
|
4597
4544
|
if (!unwindFallback) return [3 /*break*/, 26];
|
|
4598
4545
|
fallbackMeta.unwind = { path: unwindFallback.path, attempted: true, used: false };
|
|
@@ -4641,7 +4588,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4641
4588
|
fallbackMeta.unwind.skipped = 'not_array';
|
|
4642
4589
|
_u.label = 26;
|
|
4643
4590
|
case 26:
|
|
4644
|
-
if (
|
|
4591
|
+
if (!(!documents.length && noDataFallbacksEnabled)) return [3 /*break*/, 28];
|
|
4645
4592
|
nameFallback = resolveAggregateNameMatchFallback(executedPipeline);
|
|
4646
4593
|
if (!nameFallback) return [3 /*break*/, 28];
|
|
4647
4594
|
fallbackMeta.nameMatch = {
|
|
@@ -4663,7 +4610,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4663
4610
|
}
|
|
4664
4611
|
_u.label = 28;
|
|
4665
4612
|
case 28:
|
|
4666
|
-
if (
|
|
4613
|
+
if (!(!documents.length && noDataFallbacksEnabled)) return [3 /*break*/, 34];
|
|
4667
4614
|
_e = probeDocs;
|
|
4668
4615
|
if (_e) return [3 /*break*/, 30];
|
|
4669
4616
|
return [4 /*yield*/, fetchAssistantProbeDocs({
|
|
@@ -4735,7 +4682,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4735
4682
|
i += 1;
|
|
4736
4683
|
return [3 /*break*/, 31];
|
|
4737
4684
|
case 34:
|
|
4738
|
-
if (
|
|
4685
|
+
if (!(!documents.length && noDataFallbacksEnabled)) return [3 /*break*/, 38];
|
|
4739
4686
|
matchFields_1 = new Set();
|
|
4740
4687
|
(executedPipeline || []).forEach(function (stage) {
|
|
4741
4688
|
if (stage && typeof stage === 'object' && stage.$match && typeof stage.$match === 'object') {
|
|
@@ -4762,7 +4709,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4762
4709
|
case 36:
|
|
4763
4710
|
probeDocs = _f;
|
|
4764
4711
|
if (!probeDocs.length) return [3 /*break*/, 38];
|
|
4765
|
-
aliases = resolveFieldAliases(probeDocs, Array.from(matchFields_1), schemaFields);
|
|
4712
|
+
aliases = resolveFieldAliases(probeDocs, Array.from(matchFields_1), schemaFields, idApp);
|
|
4766
4713
|
if (!Object.keys(aliases).length) return [3 /*break*/, 38];
|
|
4767
4714
|
fallbackMeta.queryFieldAliases = {
|
|
4768
4715
|
aliases: aliases,
|
|
@@ -4786,7 +4733,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4786
4733
|
}
|
|
4787
4734
|
_u.label = 38;
|
|
4788
4735
|
case 38:
|
|
4789
|
-
if (
|
|
4736
|
+
if (!(!documents.length && noDataFallbacksEnabled)) return [3 /*break*/, 42];
|
|
4790
4737
|
_g = probeDocs;
|
|
4791
4738
|
if (_g) return [3 /*break*/, 40];
|
|
4792
4739
|
return [4 /*yield*/, fetchAssistantProbeDocs({
|
|
@@ -4822,7 +4769,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4822
4769
|
}
|
|
4823
4770
|
_u.label = 42;
|
|
4824
4771
|
case 42:
|
|
4825
|
-
if (
|
|
4772
|
+
if (!(!documents.length && noDataFallbacksEnabled)) return [3 /*break*/, 46];
|
|
4826
4773
|
_loop_2 = function (i) {
|
|
4827
4774
|
var stage, _w, idLookup, rewrittenPipeline, fallbackAggregate, fallbackDocs;
|
|
4828
4775
|
return __generator(this, function (_x) {
|
|
@@ -4894,7 +4841,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4894
4841
|
i += 1;
|
|
4895
4842
|
return [3 /*break*/, 43];
|
|
4896
4843
|
case 46:
|
|
4897
|
-
if (!(!documents.length && hasAggregateRuntimeBudget('relationship_retry'))) return [3 /*break*/, 57];
|
|
4844
|
+
if (!(!documents.length && noDataFallbacksEnabled && hasAggregateRuntimeBudget('relationship_retry'))) return [3 /*break*/, 57];
|
|
4898
4845
|
return [4 /*yield*/, resolveAssistantNestedAggregateFallbacks({
|
|
4899
4846
|
db: db,
|
|
4900
4847
|
dbName: dbName,
|
|
@@ -4953,8 +4900,8 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4953
4900
|
}
|
|
4954
4901
|
return [3 /*break*/, 53];
|
|
4955
4902
|
case 52:
|
|
4956
|
-
|
|
4957
|
-
errorMessage = normalizeOptionalString(
|
|
4903
|
+
error_12 = _u.sent();
|
|
4904
|
+
errorMessage = normalizeOptionalString(error_12 === null || error_12 === void 0 ? void 0 : error_12.message) || 'Unknown error';
|
|
4958
4905
|
existingErrors = Array.isArray(fallbackMeta.relationshipRetry.errors)
|
|
4959
4906
|
? fallbackMeta.relationshipRetry.errors
|
|
4960
4907
|
: [];
|
|
@@ -4979,7 +4926,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4979
4926
|
finally { if (e_2) throw e_2.error; }
|
|
4980
4927
|
return [7 /*endfinally*/];
|
|
4981
4928
|
case 57:
|
|
4982
|
-
if (!(!documents.length && hasAggregateRuntimeBudget('report_fallback'))) return [3 /*break*/, 60];
|
|
4929
|
+
if (!(!documents.length && noDataFallbacksEnabled && hasAggregateRuntimeBudget('report_fallback'))) return [3 /*break*/, 60];
|
|
4983
4930
|
return [4 /*yield*/, resolveBaseCollectionFromReport(db, dbName, collection)];
|
|
4984
4931
|
case 58:
|
|
4985
4932
|
baseCollection = _u.sent();
|
|
@@ -5011,7 +4958,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
5011
4958
|
case 60:
|
|
5012
4959
|
hasActiveStatusFilters = collectAssistantActiveMatchFieldsFromPipeline(normalizedPipeline).length > 0
|
|
5013
4960
|
|| collectAssistantActiveMatchFieldsFromPipeline(executedPipeline).length > 0;
|
|
5014
|
-
if (!(!documents.length && crossCollectionRetryEnabled && !hasActiveStatusFilters && hasAggregateRuntimeBudget('collection_retry'))) return [3 /*break*/, 72];
|
|
4961
|
+
if (!(!documents.length && noDataFallbacksEnabled && crossCollectionRetryEnabled && !hasActiveStatusFilters && hasAggregateRuntimeBudget('collection_retry'))) return [3 /*break*/, 72];
|
|
5015
4962
|
fallbackAcceptanceOptions = buildAssistantAggregateFallbackAcceptanceOptions(executedPipeline || []);
|
|
5016
4963
|
return [4 /*yield*/, resolveAssistantAvailableCrossCollectionFallbacks(db, dbName, collection, triedCollections, {
|
|
5017
4964
|
fieldHints: collectAggregateReferencedFieldPaths(executedPipeline || [])
|
|
@@ -5079,14 +5026,14 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
5079
5026
|
}
|
|
5080
5027
|
return [3 /*break*/, 67];
|
|
5081
5028
|
case 66:
|
|
5082
|
-
|
|
5029
|
+
error_13 = _u.sent();
|
|
5083
5030
|
if (fallbackMeta.collectionRetry && typeof fallbackMeta.collectionRetry === 'object') {
|
|
5084
5031
|
existingErrors = Array.isArray(fallbackMeta.collectionRetry.errors)
|
|
5085
5032
|
? fallbackMeta.collectionRetry.errors
|
|
5086
5033
|
: [];
|
|
5087
5034
|
existingErrors.push({
|
|
5088
5035
|
collection: candidateCollection,
|
|
5089
|
-
error: normalizeOptionalString(
|
|
5036
|
+
error: normalizeOptionalString(error_13 === null || error_13 === void 0 ? void 0 : error_13.message) || 'Unknown error'
|
|
5090
5037
|
});
|
|
5091
5038
|
fallbackMeta.collectionRetry.errors = existingErrors;
|
|
5092
5039
|
}
|
|
@@ -5107,7 +5054,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
5107
5054
|
return [7 /*endfinally*/];
|
|
5108
5055
|
case 71: return [3 /*break*/, 73];
|
|
5109
5056
|
case 72:
|
|
5110
|
-
if (!documents.length && crossCollectionRetryEnabled && hasActiveStatusFilters && canViewDebug) {
|
|
5057
|
+
if (!documents.length && noDataFallbacksEnabled && crossCollectionRetryEnabled && hasActiveStatusFilters && canViewDebug) {
|
|
5111
5058
|
fallbackMeta.collectionRetry = {
|
|
5112
5059
|
from: collection,
|
|
5113
5060
|
root: retryRootCollection,
|
|
@@ -5118,7 +5065,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
5118
5065
|
}
|
|
5119
5066
|
_u.label = 73;
|
|
5120
5067
|
case 73:
|
|
5121
|
-
if (!(!documents.length && canViewDebug && hasAggregateRuntimeBudget('zero_diagnostics', 20))) return [3 /*break*/, 90];
|
|
5068
|
+
if (!(!documents.length && noDataFallbacksEnabled && canViewDebug && hasAggregateRuntimeBudget('zero_diagnostics', 20))) return [3 /*break*/, 90];
|
|
5122
5069
|
matchStages = (executedPipeline || []).filter(function (stage) { return stage && typeof stage === 'object' && stage.$match && typeof stage.$match === 'object'; });
|
|
5123
5070
|
diagnostics = {};
|
|
5124
5071
|
if (!matchStages.length) return [3 /*break*/, 90];
|
|
@@ -6951,18 +6898,108 @@ function extractAssistantDataIntentCustomerText(message) {
|
|
|
6951
6898
|
if (!value) {
|
|
6952
6899
|
return '';
|
|
6953
6900
|
}
|
|
6954
|
-
value = value.replace(/\b(
|
|
6955
|
-
value = value.replace(/\b(
|
|
6956
|
-
value = value.replace(/\b(
|
|
6901
|
+
value = value.replace(/\b(january|jan|february|feb|march|mar|april|apr|may|june|jun|july|jul|august|aug|september|sep|october|oct|november|nov|december|dec)\s+[0-9]{4}\b/gi, ' ');
|
|
6902
|
+
value = value.replace(/\b(?:last|past)\s+[0-9]+\s+(?:days?|weeks?|months?)\b/gi, ' ');
|
|
6903
|
+
value = value.replace(/\b(?:this|current)\s+(?:week|month|quarter|year)\b/gi, ' ');
|
|
6904
|
+
value = value.replace(/\b(?:last|past)\s+(?:week|month|quarter|year)\b/gi, ' ');
|
|
6905
|
+
value = value.replace(/\byear\s+to\s+date\b/gi, ' ');
|
|
6906
|
+
value = value.replace(/\b(summarize|summary|show|list|give|pull|find|tell|me|about|of|the|a|an|and|amount|quantity|qty|total|totals|for|to|them|their|by|what|which|were|was|is|are|did|do|get|report)\b/gi, ' ');
|
|
6907
|
+
value = value.replace(/\b(work\s*orders?|wos?|jobs?|invoices?|invoice|billed|billing|revenue|charged|chemicals?|chemical|sent|shipped|shipment|shipments|delivered|planned|inventory|on\s+hand|stock|ytd|completed|reviewed|closed|monthly|month)\b/gi, ' ');
|
|
6908
|
+
value = value.replace(/\b(last|past|current)\b/gi, ' ');
|
|
6957
6909
|
value = value.replace(/[^a-z0-9&.' -]+/gi, ' ');
|
|
6958
6910
|
return normalizeOptionalString(value.replace(/\s+/g, ' '));
|
|
6959
6911
|
}
|
|
6960
6912
|
function resolveAssistantDataIntentDateWindow(message) {
|
|
6961
6913
|
var text = normalizeOptionalString(message).toLowerCase();
|
|
6914
|
+
var now = new Date();
|
|
6915
|
+
var monthNames = {
|
|
6916
|
+
january: 0,
|
|
6917
|
+
jan: 0,
|
|
6918
|
+
february: 1,
|
|
6919
|
+
feb: 1,
|
|
6920
|
+
march: 2,
|
|
6921
|
+
mar: 2,
|
|
6922
|
+
april: 3,
|
|
6923
|
+
apr: 3,
|
|
6924
|
+
may: 4,
|
|
6925
|
+
june: 5,
|
|
6926
|
+
jun: 5,
|
|
6927
|
+
july: 6,
|
|
6928
|
+
jul: 6,
|
|
6929
|
+
august: 7,
|
|
6930
|
+
aug: 7,
|
|
6931
|
+
september: 8,
|
|
6932
|
+
sep: 8,
|
|
6933
|
+
october: 9,
|
|
6934
|
+
oct: 9,
|
|
6935
|
+
november: 10,
|
|
6936
|
+
nov: 10,
|
|
6937
|
+
december: 11,
|
|
6938
|
+
dec: 11
|
|
6939
|
+
};
|
|
6940
|
+
var monthMatch = text.match(/\b(january|jan|february|feb|march|mar|april|apr|may|june|jun|july|jul|august|aug|september|sep|october|oct|november|nov|december|dec)\s+([0-9]{4})\b/);
|
|
6941
|
+
if (monthMatch) {
|
|
6942
|
+
var month = monthNames[monthMatch[1]];
|
|
6943
|
+
var year_1 = Number(monthMatch[2]);
|
|
6944
|
+
if (Number.isFinite(year_1) && month >= 0) {
|
|
6945
|
+
return {
|
|
6946
|
+
start: new Date(Date.UTC(year_1, month, 1, 0, 0, 0, 0)).toISOString(),
|
|
6947
|
+
end: new Date(Date.UTC(year_1, month + 1, 0, 23, 59, 59, 999)).toISOString(),
|
|
6948
|
+
year: year_1
|
|
6949
|
+
};
|
|
6950
|
+
}
|
|
6951
|
+
}
|
|
6952
|
+
if (/\blast\s+month\b/.test(text)) {
|
|
6953
|
+
var start = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - 1, 1, 0, 0, 0, 0));
|
|
6954
|
+
var end = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 0, 23, 59, 59, 999));
|
|
6955
|
+
return {
|
|
6956
|
+
start: start.toISOString(),
|
|
6957
|
+
end: end.toISOString(),
|
|
6958
|
+
year: start.getUTCFullYear()
|
|
6959
|
+
};
|
|
6960
|
+
}
|
|
6961
|
+
var lastWindowMatch = text.match(/\b(?:last|past)\s+([0-9]+)\s+(days?|weeks?|months?)\b/);
|
|
6962
|
+
if (lastWindowMatch) {
|
|
6963
|
+
var amount = Math.max(1, Math.min(Number(lastWindowMatch[1]) || 1, 36));
|
|
6964
|
+
var unit = lastWindowMatch[2];
|
|
6965
|
+
var start = new Date(now.getTime());
|
|
6966
|
+
if (/week/.test(unit)) {
|
|
6967
|
+
start.setUTCDate(start.getUTCDate() - (amount * 7));
|
|
6968
|
+
}
|
|
6969
|
+
else if (/month/.test(unit)) {
|
|
6970
|
+
start.setUTCMonth(start.getUTCMonth() - amount);
|
|
6971
|
+
}
|
|
6972
|
+
else {
|
|
6973
|
+
start.setUTCDate(start.getUTCDate() - amount);
|
|
6974
|
+
}
|
|
6975
|
+
start.setUTCHours(0, 0, 0, 0);
|
|
6976
|
+
return {
|
|
6977
|
+
start: start.toISOString(),
|
|
6978
|
+
end: new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 23, 59, 59, 999)).toISOString(),
|
|
6979
|
+
year: now.getUTCFullYear()
|
|
6980
|
+
};
|
|
6981
|
+
}
|
|
6982
|
+
if (/\b(?:this|current)\s+month\b/.test(text)) {
|
|
6983
|
+
return {
|
|
6984
|
+
start: new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1, 0, 0, 0, 0)).toISOString(),
|
|
6985
|
+
end: new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 23, 59, 59, 999)).toISOString(),
|
|
6986
|
+
year: now.getUTCFullYear()
|
|
6987
|
+
};
|
|
6988
|
+
}
|
|
6989
|
+
if (/\b(?:this|current)\s+week\b/.test(text)) {
|
|
6990
|
+
var start = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 0, 0, 0, 0));
|
|
6991
|
+
var day = start.getUTCDay();
|
|
6992
|
+
var offset = day === 0 ? 6 : day - 1;
|
|
6993
|
+
start.setUTCDate(start.getUTCDate() - offset);
|
|
6994
|
+
return {
|
|
6995
|
+
start: start.toISOString(),
|
|
6996
|
+
end: new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 23, 59, 59, 999)).toISOString(),
|
|
6997
|
+
year: now.getUTCFullYear()
|
|
6998
|
+
};
|
|
6999
|
+
}
|
|
6962
7000
|
if (!/\b(this\s+year|ytd|year\s+to\s+date|current\s+year)\b/.test(text)) {
|
|
6963
7001
|
return {};
|
|
6964
7002
|
}
|
|
6965
|
-
var now = new Date();
|
|
6966
7003
|
var year = now.getUTCFullYear();
|
|
6967
7004
|
return {
|
|
6968
7005
|
start: new Date(Date.UTC(year, 0, 1, 0, 0, 0, 0)).toISOString(),
|
|
@@ -6970,19 +7007,21 @@ function resolveAssistantDataIntentDateWindow(message) {
|
|
|
6970
7007
|
year: year
|
|
6971
7008
|
};
|
|
6972
7009
|
}
|
|
7010
|
+
function applyAssistantDataIntentTextTemplate(value, params) {
|
|
7011
|
+
return String(value || '')
|
|
7012
|
+
.replace(/\{\{customer\}\}/g, params.customerText)
|
|
7013
|
+
.replace(/\{\{year\}\}/g, params.dateWindow.year ? String(params.dateWindow.year) : '')
|
|
7014
|
+
.replace(/\{\{date_start\}\}/g, params.dateWindow.start || '')
|
|
7015
|
+
.replace(/\{\{date_end\}\}/g, params.dateWindow.end || '');
|
|
7016
|
+
}
|
|
6973
7017
|
function buildAssistantDataIntentAcknowledgement(intent, customerText, dateWindow) {
|
|
6974
|
-
var
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
return "I understand you want a summary of chemicals sent to ".concat(customer, " jobs").concat(yearText, ". Let me pull the work-order shipment data for you.");
|
|
6978
|
-
}
|
|
6979
|
-
if (intent.id === 'snf_invoice_chemical_quantities') {
|
|
6980
|
-
return "I understand you want invoice and billed chemical details for ".concat(customer).concat(yearText, ". Let me pull the invoice data for you.");
|
|
6981
|
-
}
|
|
6982
|
-
if (intent.id === 'snf_planned_job_chemicals') {
|
|
6983
|
-
return "I understand you want planned chemicals for ".concat(customer, " jobs").concat(yearText, ". Let me pull the job setup data for you.");
|
|
7018
|
+
var template = normalizeOptionalString(intent.acknowledgement);
|
|
7019
|
+
if (template) {
|
|
7020
|
+
return applyAssistantDataIntentTextTemplate(template, { customerText: customerText, dateWindow: dateWindow }).trim();
|
|
6984
7021
|
}
|
|
6985
|
-
|
|
7022
|
+
var yearText = dateWindow.year ? " for ".concat(dateWindow.year) : '';
|
|
7023
|
+
var target = customerText ? " for ".concat(customerText) : '';
|
|
7024
|
+
return "I understand the data you want".concat(target).concat(yearText, ". Let me pull the matching records for you.");
|
|
6986
7025
|
}
|
|
6987
7026
|
function buildAssistantDataIntentMatchStage(customerText, dateField, dateWindow, customerPaths) {
|
|
6988
7027
|
var _a;
|
|
@@ -7010,6 +7049,101 @@ function buildAssistantDataIntentMatchStage(customerText, dateField, dateWindow,
|
|
|
7010
7049
|
}
|
|
7011
7050
|
return and.length ? { $match: { $and: and } } : { $match: {} };
|
|
7012
7051
|
}
|
|
7052
|
+
function applyAssistantDataIntentPipelineTemplate(value, params) {
|
|
7053
|
+
if (Array.isArray(value)) {
|
|
7054
|
+
return value.map(function (entry) { return applyAssistantDataIntentPipelineTemplate(entry, params); });
|
|
7055
|
+
}
|
|
7056
|
+
if (value && typeof value === 'object') {
|
|
7057
|
+
return Object.keys(value).reduce(function (acc, key) {
|
|
7058
|
+
acc[key] = applyAssistantDataIntentPipelineTemplate(value[key], params);
|
|
7059
|
+
return acc;
|
|
7060
|
+
}, {});
|
|
7061
|
+
}
|
|
7062
|
+
if (typeof value !== 'string') {
|
|
7063
|
+
return value;
|
|
7064
|
+
}
|
|
7065
|
+
if (value === '{{date_start}}') {
|
|
7066
|
+
return params.dateWindow.start ? new Date(params.dateWindow.start) : undefined;
|
|
7067
|
+
}
|
|
7068
|
+
if (value === '{{date_end}}') {
|
|
7069
|
+
return params.dateWindow.end ? new Date(params.dateWindow.end) : undefined;
|
|
7070
|
+
}
|
|
7071
|
+
if (value === '{{year}}') {
|
|
7072
|
+
return params.dateWindow.year || '';
|
|
7073
|
+
}
|
|
7074
|
+
if (value === '{{customer}}') {
|
|
7075
|
+
return params.customerText;
|
|
7076
|
+
}
|
|
7077
|
+
return applyAssistantDataIntentTextTemplate(value, params);
|
|
7078
|
+
}
|
|
7079
|
+
function isAssistantEmptyPipelineObject(value) {
|
|
7080
|
+
return !!value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length;
|
|
7081
|
+
}
|
|
7082
|
+
function removeUndefinedAssistantPipelineValues(value, parentKey) {
|
|
7083
|
+
if (parentKey === void 0) { parentKey = ''; }
|
|
7084
|
+
if (value instanceof Date) {
|
|
7085
|
+
return value;
|
|
7086
|
+
}
|
|
7087
|
+
if (Array.isArray(value)) {
|
|
7088
|
+
return value
|
|
7089
|
+
.map(function (entry) { return removeUndefinedAssistantPipelineValues(entry, parentKey); })
|
|
7090
|
+
.filter(function (entry) { return entry !== undefined; });
|
|
7091
|
+
}
|
|
7092
|
+
if (value && typeof value === 'object') {
|
|
7093
|
+
var cleaned = Object.keys(value).reduce(function (acc, key) {
|
|
7094
|
+
var nextValue = removeUndefinedAssistantPipelineValues(value[key], key);
|
|
7095
|
+
if (nextValue !== undefined) {
|
|
7096
|
+
acc[key] = nextValue;
|
|
7097
|
+
}
|
|
7098
|
+
return acc;
|
|
7099
|
+
}, {});
|
|
7100
|
+
if (isAssistantEmptyPipelineObject(cleaned) && parentKey && !parentKey.startsWith('$')) {
|
|
7101
|
+
return undefined;
|
|
7102
|
+
}
|
|
7103
|
+
return cleaned;
|
|
7104
|
+
}
|
|
7105
|
+
return value;
|
|
7106
|
+
}
|
|
7107
|
+
function buildAssistantConfiguredDataIntentPipeline(intent, customerText, dateWindow) {
|
|
7108
|
+
if (!Array.isArray(intent.pipeline) || !intent.pipeline.length) {
|
|
7109
|
+
return [];
|
|
7110
|
+
}
|
|
7111
|
+
return removeUndefinedAssistantPipelineValues(applyAssistantDataIntentPipelineTemplate(intent.pipeline, {
|
|
7112
|
+
customerText: customerText,
|
|
7113
|
+
dateWindow: dateWindow
|
|
7114
|
+
}));
|
|
7115
|
+
}
|
|
7116
|
+
function buildAssistantGenericDataIntentPipeline(intent, customerText, dateWindow) {
|
|
7117
|
+
var _a;
|
|
7118
|
+
var pipeline = [
|
|
7119
|
+
buildAssistantDataIntentMatchStage(customerText, intent.dateField, dateWindow, ['customer', 'job.customer', 'jca.customer'])
|
|
7120
|
+
];
|
|
7121
|
+
var quantityField = normalizeOptionalString(intent.quantityField || intent.metricField);
|
|
7122
|
+
if (!quantityField) {
|
|
7123
|
+
pipeline.push({ $limit: 20 });
|
|
7124
|
+
return pipeline;
|
|
7125
|
+
}
|
|
7126
|
+
var firstPath = quantityField.split('.')[0];
|
|
7127
|
+
if (firstPath && quantityField.includes('.')) {
|
|
7128
|
+
pipeline.push({ $unwind: "$".concat(firstPath) });
|
|
7129
|
+
pipeline.push({ $match: (_a = {}, _a[quantityField] = { $gt: 0 }, _a) });
|
|
7130
|
+
}
|
|
7131
|
+
pipeline.push({
|
|
7132
|
+
$group: {
|
|
7133
|
+
_id: null,
|
|
7134
|
+
total_quantity: { $sum: "$".concat(quantityField) },
|
|
7135
|
+
row_count: { $sum: 1 }
|
|
7136
|
+
}
|
|
7137
|
+
});
|
|
7138
|
+
pipeline.push({
|
|
7139
|
+
$project: {
|
|
7140
|
+
_id: 0,
|
|
7141
|
+
total_quantity: 1,
|
|
7142
|
+
row_count: 1
|
|
7143
|
+
}
|
|
7144
|
+
});
|
|
7145
|
+
return pipeline;
|
|
7146
|
+
}
|
|
7013
7147
|
function buildAssistantAppDataIntentDirective(message, collectionNames, appId) {
|
|
7014
7148
|
if (collectionNames === void 0) { collectionNames = []; }
|
|
7015
7149
|
var intent = selectAssistantAppDataIntent(message, collectionNames, appId);
|
|
@@ -7030,113 +7164,21 @@ function buildAssistantAppDataIntentDirective(message, collectionNames, appId) {
|
|
|
7030
7164
|
acknowledgementText: acknowledgementText,
|
|
7031
7165
|
progress: progress,
|
|
7032
7166
|
assumptions: intent.assumptions,
|
|
7033
|
-
fallbackCollections: intent.fallbackCollections
|
|
7167
|
+
fallbackCollections: intent.fallbackCollections,
|
|
7168
|
+
customerText: customerText,
|
|
7169
|
+
dateWindow: dateWindow
|
|
7034
7170
|
};
|
|
7035
7171
|
var basePayload = function (pipeline) { return ({
|
|
7036
7172
|
collection: intent.collection,
|
|
7037
7173
|
permissionView: intent.permissionView || resolveDefaultAssistantPermissionView(intent.collection),
|
|
7038
7174
|
pipeline: pipeline,
|
|
7039
|
-
options: {
|
|
7040
|
-
allowDiskUse: true,
|
|
7041
|
-
limit: 20
|
|
7042
|
-
}
|
|
7175
|
+
options: __assign(__assign({ disableNoDataFallbacks: true }, (intent.options || {})), { allowDiskUse: true, limit: 20 })
|
|
7043
7176
|
}); };
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
{ $match: { 'chemicals.shipped.quantity': { $gt: 0 } } },
|
|
7050
|
-
{
|
|
7051
|
-
$group: {
|
|
7052
|
-
_id: {
|
|
7053
|
-
id_job: '$job.id_job',
|
|
7054
|
-
job: '$job.job',
|
|
7055
|
-
chemical: '$chemicals.chemical',
|
|
7056
|
-
unit: '$chemicals.unit'
|
|
7057
|
-
},
|
|
7058
|
-
qty_sent: { $sum: '$chemicals.shipped.quantity' },
|
|
7059
|
-
work_order_ids: { $addToSet: '$_id' }
|
|
7060
|
-
}
|
|
7061
|
-
},
|
|
7062
|
-
{
|
|
7063
|
-
$project: {
|
|
7064
|
-
_id: 0,
|
|
7065
|
-
id_job: '$_id.id_job',
|
|
7066
|
-
job: '$_id.job',
|
|
7067
|
-
chemical: '$_id.chemical',
|
|
7068
|
-
unit: '$_id.unit',
|
|
7069
|
-
qty_sent: 1,
|
|
7070
|
-
work_order_count: { $size: '$work_order_ids' }
|
|
7071
|
-
}
|
|
7072
|
-
},
|
|
7073
|
-
{ $sort: { qty_sent: -1, job: 1, chemical: 1 } }
|
|
7074
|
-
];
|
|
7075
|
-
return { type: 'aggregate', payload: basePayload(pipeline), cleaned: '', rawLine: "HEURISTIC_AGG(app-data-intent:".concat(intent.id, ")"), metadata: metadata };
|
|
7076
|
-
}
|
|
7077
|
-
if (intent.id === 'snf_invoice_chemical_quantities') {
|
|
7078
|
-
var pipeline = [
|
|
7079
|
-
buildAssistantDataIntentMatchStage(customerText, intent.dateField || 'date_created', dateWindow, ['customer', 'job.customer']),
|
|
7080
|
-
{ $unwind: '$items_chemicals' },
|
|
7081
|
-
{
|
|
7082
|
-
$group: {
|
|
7083
|
-
_id: {
|
|
7084
|
-
id_job: '$id_job',
|
|
7085
|
-
job: '$job',
|
|
7086
|
-
chemical: '$items_chemicals.chemical',
|
|
7087
|
-
unit: '$items_chemicals.unit'
|
|
7088
|
-
},
|
|
7089
|
-
quantity: { $sum: '$items_chemicals.quantity' },
|
|
7090
|
-
price_total: { $sum: '$items_chemicals.price_total' },
|
|
7091
|
-
invoice_ids: { $addToSet: '$_id' }
|
|
7092
|
-
}
|
|
7093
|
-
},
|
|
7094
|
-
{
|
|
7095
|
-
$project: {
|
|
7096
|
-
_id: 0,
|
|
7097
|
-
id_job: '$_id.id_job',
|
|
7098
|
-
job: '$_id.job',
|
|
7099
|
-
chemical: '$_id.chemical',
|
|
7100
|
-
unit: '$_id.unit',
|
|
7101
|
-
quantity: 1,
|
|
7102
|
-
price_total: 1,
|
|
7103
|
-
invoice_count: { $size: '$invoice_ids' }
|
|
7104
|
-
}
|
|
7105
|
-
},
|
|
7106
|
-
{ $sort: { price_total: -1, quantity: -1, job: 1 } }
|
|
7107
|
-
];
|
|
7108
|
-
return { type: 'aggregate', payload: basePayload(pipeline), cleaned: '', rawLine: "HEURISTIC_AGG(app-data-intent:".concat(intent.id, ")"), metadata: metadata };
|
|
7109
|
-
}
|
|
7110
|
-
if (intent.id === 'snf_planned_job_chemicals') {
|
|
7111
|
-
var pipeline = [
|
|
7112
|
-
buildAssistantDataIntentMatchStage(customerText, intent.dateField || 'date_job_created', dateWindow, ['customer', 'jca.customer']),
|
|
7113
|
-
{ $unwind: '$planned_chemicals' },
|
|
7114
|
-
{
|
|
7115
|
-
$group: {
|
|
7116
|
-
_id: {
|
|
7117
|
-
id_job: '$_id',
|
|
7118
|
-
job: '$job',
|
|
7119
|
-
chemical: '$planned_chemicals.chemical',
|
|
7120
|
-
unit: '$planned_chemicals.unit'
|
|
7121
|
-
},
|
|
7122
|
-
planned_quantity: { $sum: '$planned_chemicals.quantity' }
|
|
7123
|
-
}
|
|
7124
|
-
},
|
|
7125
|
-
{
|
|
7126
|
-
$project: {
|
|
7127
|
-
_id: 0,
|
|
7128
|
-
id_job: '$_id.id_job',
|
|
7129
|
-
job: '$_id.job',
|
|
7130
|
-
chemical: '$_id.chemical',
|
|
7131
|
-
unit: '$_id.unit',
|
|
7132
|
-
planned_quantity: 1
|
|
7133
|
-
}
|
|
7134
|
-
},
|
|
7135
|
-
{ $sort: { planned_quantity: -1, job: 1 } }
|
|
7136
|
-
];
|
|
7137
|
-
return { type: 'aggregate', payload: basePayload(pipeline), cleaned: '', rawLine: "HEURISTIC_AGG(app-data-intent:".concat(intent.id, ")"), metadata: metadata };
|
|
7138
|
-
}
|
|
7139
|
-
return null;
|
|
7177
|
+
var configuredPipeline = buildAssistantConfiguredDataIntentPipeline(intent, customerText, dateWindow);
|
|
7178
|
+
var pipeline = configuredPipeline.length
|
|
7179
|
+
? configuredPipeline
|
|
7180
|
+
: buildAssistantGenericDataIntentPipeline(intent, customerText, dateWindow);
|
|
7181
|
+
return { type: 'aggregate', payload: basePayload(pipeline), cleaned: '', rawLine: "HEURISTIC_AGG(app-data-intent:".concat(intent.id, ")"), metadata: metadata };
|
|
7140
7182
|
}
|
|
7141
7183
|
function isAssistantDeterministicHeuristicDirective(directive) {
|
|
7142
7184
|
return isAssistantSchemaHoursHeuristicDirective(directive)
|
|
@@ -7841,7 +7883,7 @@ function buildAssistantToolResultPayload(directive, toolResponse, requestMessage
|
|
|
7841
7883
|
? toolResponse.verification
|
|
7842
7884
|
: undefined;
|
|
7843
7885
|
var directiveMetadata = directive.metadata && typeof directive.metadata === 'object' ? directive.metadata : {};
|
|
7844
|
-
var mergedDebug = __assign(__assign(__assign(__assign(__assign({}, ((toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) && typeof toolResponse.debug === 'object' ? toolResponse.debug : {})), (normalizeOptionalString(directiveMetadata.intentId) ? { intentId: normalizeOptionalString(directiveMetadata.intentId) } : {})), (normalizeOptionalString(directiveMetadata.acknowledgementText) ? { acknowledgementText: normalizeOptionalString(directiveMetadata.acknowledgementText) } : {})), (normalizeOptionalString(directiveMetadata.recipeUsed) ? { recipeUsed: normalizeOptionalString(directiveMetadata.recipeUsed) } : {})), (Array.isArray(directiveMetadata.assumptions) && directiveMetadata.assumptions.length ? { assumptions: directiveMetadata.assumptions } : {}));
|
|
7886
|
+
var mergedDebug = __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, ((toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) && typeof toolResponse.debug === 'object' ? toolResponse.debug : {})), (normalizeOptionalString(directiveMetadata.intentId) ? { intentId: normalizeOptionalString(directiveMetadata.intentId) } : {})), (normalizeOptionalString(directiveMetadata.acknowledgementText) ? { acknowledgementText: normalizeOptionalString(directiveMetadata.acknowledgementText) } : {})), (normalizeOptionalString(directiveMetadata.recipeUsed) ? { recipeUsed: normalizeOptionalString(directiveMetadata.recipeUsed) } : {})), (normalizeOptionalString(directiveMetadata.customerText) ? { customerText: normalizeOptionalString(directiveMetadata.customerText) } : {})), (directiveMetadata.dateWindow && typeof directiveMetadata.dateWindow === 'object' ? { dateWindow: directiveMetadata.dateWindow } : {})), (Array.isArray(directiveMetadata.assumptions) && directiveMetadata.assumptions.length ? { assumptions: directiveMetadata.assumptions } : {}));
|
|
7845
7887
|
var result = {
|
|
7846
7888
|
type: directive.type === 'aggregate' ? 'mongo_agg' : 'mongo_read',
|
|
7847
7889
|
input: directivePayload,
|
|
@@ -8033,21 +8075,46 @@ function buildAssistantDisplayLeadSummary(display) {
|
|
|
8033
8075
|
? "First row: ".concat(details.join(', '), ".")
|
|
8034
8076
|
: "Result: ".concat(details.join(', '), ".");
|
|
8035
8077
|
}
|
|
8078
|
+
function formatAssistantEvidenceDate(value) {
|
|
8079
|
+
var normalized = normalizeOptionalString(value);
|
|
8080
|
+
if (!normalized) {
|
|
8081
|
+
return '';
|
|
8082
|
+
}
|
|
8083
|
+
var date = new Date(normalized);
|
|
8084
|
+
if (!Number.isNaN(date.getTime())) {
|
|
8085
|
+
return date.toISOString().slice(0, 10);
|
|
8086
|
+
}
|
|
8087
|
+
return normalized.slice(0, 10);
|
|
8088
|
+
}
|
|
8036
8089
|
function buildAssistantToolFallbackResponse(result) {
|
|
8037
8090
|
var _a, _b;
|
|
8038
8091
|
var rowCount = Math.max(0, Number(result.output.rowCount || 0));
|
|
8039
8092
|
var source = normalizeOptionalString(result.output.collection);
|
|
8040
8093
|
var debug = result.output.debug && typeof result.output.debug === 'object' ? result.output.debug : {};
|
|
8041
8094
|
var intentId = normalizeOptionalString(debug.intentId);
|
|
8095
|
+
var customerText = normalizeOptionalString(debug.customerText);
|
|
8096
|
+
var dateWindow = debug.dateWindow && typeof debug.dateWindow === 'object'
|
|
8097
|
+
? debug.dateWindow
|
|
8098
|
+
: {};
|
|
8099
|
+
var dateStart = formatAssistantEvidenceDate(dateWindow.start);
|
|
8100
|
+
var dateEnd = formatAssistantEvidenceDate(dateWindow.end);
|
|
8101
|
+
var targetText = customerText ? " for ".concat(customerText) : '';
|
|
8102
|
+
var dateText = dateStart || dateEnd ? " from ".concat(dateStart || 'the beginning', " through ").concat(dateEnd || 'the end') : '';
|
|
8042
8103
|
var lines = rowCount > 0
|
|
8043
|
-
? ["I found ".concat(rowCount === 1 ? '1 matching row' : "".concat(rowCount, " matching rows")).concat(source ? " from ".concat(source) : '', ".")]
|
|
8104
|
+
? ["I found ".concat(rowCount === 1 ? '1 matching row' : "".concat(rowCount, " matching rows")).concat(source ? " from ".concat(source) : '').concat(targetText).concat(dateText, ".")]
|
|
8044
8105
|
: [intentId
|
|
8045
|
-
? "I checked the ".concat(source || 'selected', " data
|
|
8106
|
+
? "I checked the ".concat(source || 'selected', " data").concat(targetText).concat(dateText, ", but I did not find matching rows for those filters.")
|
|
8046
8107
|
: "I checked the data".concat(source ? " in ".concat(source) : '', ", but no matching rows were returned.")];
|
|
8047
8108
|
if (source) {
|
|
8048
8109
|
lines.push("- Source: ".concat(source));
|
|
8049
8110
|
}
|
|
8050
8111
|
lines.push("- Rows returned: ".concat(rowCount));
|
|
8112
|
+
if (customerText) {
|
|
8113
|
+
lines.push("- Filter: ".concat(customerText));
|
|
8114
|
+
}
|
|
8115
|
+
if (dateStart || dateEnd) {
|
|
8116
|
+
lines.push("- Date window: ".concat(dateStart || 'open', " to ").concat(dateEnd || 'open'));
|
|
8117
|
+
}
|
|
8051
8118
|
if (typeof result.output.total === 'number') {
|
|
8052
8119
|
lines.push("- Total: ".concat(result.output.total));
|
|
8053
8120
|
}
|
|
@@ -8058,14 +8125,6 @@ function buildAssistantToolFallbackResponse(result) {
|
|
|
8058
8125
|
if (assumptions.length) {
|
|
8059
8126
|
lines.push("- Assumptions: ".concat(assumptions.slice(0, 3).join('; ')));
|
|
8060
8127
|
}
|
|
8061
|
-
if (intentId === 'snf_job_chemical_shipments') {
|
|
8062
|
-
lines.push('- I treated "sent" as shipped chemical quantity from completed/reviewed/closed work orders.');
|
|
8063
|
-
lines.push('- If you meant billed quantities or dollars, ask for invoiced/billed chemicals instead.');
|
|
8064
|
-
}
|
|
8065
|
-
else if (intentId === 'snf_invoice_chemical_quantities') {
|
|
8066
|
-
lines.push('- I treated the request as billed invoice chemical quantities and invoice totals.');
|
|
8067
|
-
lines.push('- If you meant field shipments, ask for chemicals shipped/sent on work orders.');
|
|
8068
|
-
}
|
|
8069
8128
|
}
|
|
8070
8129
|
var leadSummary = buildAssistantDisplayLeadSummary(result.output.display);
|
|
8071
8130
|
if (leadSummary) {
|
|
@@ -8581,10 +8640,10 @@ function deriveAssistantStreamStatus(event) {
|
|
|
8581
8640
|
return null;
|
|
8582
8641
|
}
|
|
8583
8642
|
if (event.type === 'thread.started' || event.type === 'turn.started') {
|
|
8584
|
-
return
|
|
8643
|
+
return AI_ASSISTANT_PROGRESS_CONTEXT;
|
|
8585
8644
|
}
|
|
8586
8645
|
if (event.type === 'turn.completed') {
|
|
8587
|
-
return
|
|
8646
|
+
return AI_ASSISTANT_PROGRESS_DRAFT;
|
|
8588
8647
|
}
|
|
8589
8648
|
if (event.type === 'item.started' || event.type === 'item.updated' || event.type === 'item.completed') {
|
|
8590
8649
|
var itemType = String(((_a = event === null || event === void 0 ? void 0 : event.item) === null || _a === void 0 ? void 0 : _a.type) || '').trim().toLowerCase();
|
|
@@ -8592,7 +8651,7 @@ function deriveAssistantStreamStatus(event) {
|
|
|
8592
8651
|
return null;
|
|
8593
8652
|
}
|
|
8594
8653
|
if (itemType === 'mcp_tool_call') {
|
|
8595
|
-
return
|
|
8654
|
+
return AI_ASSISTANT_PROGRESS_NAVIGATION;
|
|
8596
8655
|
}
|
|
8597
8656
|
if (itemType === 'command_execution') {
|
|
8598
8657
|
return deriveAssistantCommandExecutionStatus((_b = event === null || event === void 0 ? void 0 : event.item) === null || _b === void 0 ? void 0 : _b.command);
|
|
@@ -8601,13 +8660,13 @@ function deriveAssistantStreamStatus(event) {
|
|
|
8601
8660
|
return 'Searching references';
|
|
8602
8661
|
}
|
|
8603
8662
|
if (itemType === 'file_change') {
|
|
8604
|
-
return
|
|
8663
|
+
return AI_ASSISTANT_PROGRESS_DRAFT;
|
|
8605
8664
|
}
|
|
8606
8665
|
if (itemType === 'agent_message') {
|
|
8607
|
-
return
|
|
8666
|
+
return AI_ASSISTANT_PROGRESS_DRAFT;
|
|
8608
8667
|
}
|
|
8609
8668
|
if (itemType === 'reasoning') {
|
|
8610
|
-
return
|
|
8669
|
+
return AI_ASSISTANT_PROGRESS_CONTEXT;
|
|
8611
8670
|
}
|
|
8612
8671
|
}
|
|
8613
8672
|
return null;
|
|
@@ -8620,13 +8679,13 @@ function normalizeAssistantStreamProgressStatus(status, dataMode) {
|
|
|
8620
8679
|
}
|
|
8621
8680
|
var normalized = trimmed.toLowerCase();
|
|
8622
8681
|
if (normalized === 'planning') {
|
|
8623
|
-
return
|
|
8682
|
+
return AI_ASSISTANT_PROGRESS_CONTEXT;
|
|
8624
8683
|
}
|
|
8625
8684
|
if (normalized === 'drafting response') {
|
|
8626
|
-
return
|
|
8685
|
+
return AI_ASSISTANT_PROGRESS_DRAFT;
|
|
8627
8686
|
}
|
|
8628
8687
|
if (normalized === 'searching files' || normalized === 'finding files' || normalized === 'opening files' || normalized === 'scanning files') {
|
|
8629
|
-
return
|
|
8688
|
+
return AI_ASSISTANT_PROGRESS_DATA_RUNNING;
|
|
8630
8689
|
}
|
|
8631
8690
|
return trimmed;
|
|
8632
8691
|
}
|
|
@@ -8896,24 +8955,34 @@ function isUnsafeFieldAlias(requestedTokens, candidateTokens) {
|
|
|
8896
8955
|
}
|
|
8897
8956
|
return false;
|
|
8898
8957
|
}
|
|
8899
|
-
function
|
|
8958
|
+
function resolveAssistantFieldTokenSynonyms(token, appId) {
|
|
8959
|
+
var key = normalizeCollectionKey(token);
|
|
8960
|
+
if (!key) {
|
|
8961
|
+
return [];
|
|
8962
|
+
}
|
|
8963
|
+
var base = AI_ASSISTANT_BASE_FIELD_TOKEN_SYNONYMS[key] || [];
|
|
8964
|
+
var profile = resolveAssistantAppHeuristicProfile(appId);
|
|
8965
|
+
var appSynonyms = profile.fieldSynonyms[key] || [];
|
|
8966
|
+
return mergeAssistantHintValues(base, appSynonyms);
|
|
8967
|
+
}
|
|
8968
|
+
function expandFieldTokens(tokens, appId) {
|
|
8900
8969
|
var expanded = new Set();
|
|
8901
8970
|
tokens.forEach(function (token) {
|
|
8902
8971
|
if (!token) {
|
|
8903
8972
|
return;
|
|
8904
8973
|
}
|
|
8905
8974
|
expanded.add(token);
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
}
|
|
8912
|
-
});
|
|
8913
|
-
}
|
|
8975
|
+
resolveAssistantFieldTokenSynonyms(token, appId).forEach(function (synonym) {
|
|
8976
|
+
if (synonym) {
|
|
8977
|
+
expanded.add(synonym);
|
|
8978
|
+
}
|
|
8979
|
+
});
|
|
8914
8980
|
});
|
|
8915
8981
|
return Array.from(expanded);
|
|
8916
8982
|
}
|
|
8983
|
+
function expandAssistantFieldTokensForTesting(tokens, appId) {
|
|
8984
|
+
return expandFieldTokens(tokens, appId);
|
|
8985
|
+
}
|
|
8917
8986
|
function getValueAtPath(obj, path) {
|
|
8918
8987
|
if (!obj || typeof obj !== 'object') {
|
|
8919
8988
|
return undefined;
|
|
@@ -9643,7 +9712,7 @@ function collectFieldCandidates(docs) {
|
|
|
9643
9712
|
});
|
|
9644
9713
|
return candidates;
|
|
9645
9714
|
}
|
|
9646
|
-
function resolveFieldAliases(docs, requestedFields, schemaFields) {
|
|
9715
|
+
function resolveFieldAliases(docs, requestedFields, schemaFields, appId) {
|
|
9647
9716
|
var aliases = {};
|
|
9648
9717
|
if (!Array.isArray(docs) || !requestedFields.length) {
|
|
9649
9718
|
return aliases;
|
|
@@ -9699,7 +9768,7 @@ function resolveFieldAliases(docs, requestedFields, schemaFields) {
|
|
|
9699
9768
|
score = 70;
|
|
9700
9769
|
}
|
|
9701
9770
|
else {
|
|
9702
|
-
var requestedTokens = expandFieldTokens(requestedBaseTokens);
|
|
9771
|
+
var requestedTokens = expandFieldTokens(requestedBaseTokens, appId);
|
|
9703
9772
|
var overlap = requestedTokens.filter(function (token) { return candidateTokens.includes(token); }).length;
|
|
9704
9773
|
var baseOverlap = requestedBaseTokens.filter(function (token) { return candidateTokens.includes(token); }).length;
|
|
9705
9774
|
if (overlap > 0) {
|
|
@@ -10339,7 +10408,7 @@ function resolveAssistantNumericValue(value) {
|
|
|
10339
10408
|
function isAssistantPercentColumn(column) {
|
|
10340
10409
|
return /(percent|pct|percentage|ratio|rate)\b/.test(column);
|
|
10341
10410
|
}
|
|
10342
|
-
var ASSISTANT_NON_CURRENCY_COLUMN_PATTERN = /\b(
|
|
10411
|
+
var ASSISTANT_NON_CURRENCY_COLUMN_PATTERN = /\b(count|qty|quantity|index|rank|sequence|seq|id|code|ticket|number)\b/;
|
|
10343
10412
|
var ASSISTANT_CURRENCY_HINT_PATTERN = /\b(amount|price|cost|balance|fee|revenue|tax|billing|charge|payment|profit|margin|due)\b/;
|
|
10344
10413
|
var ASSISTANT_MONEY_TOTAL_PATTERN = /\b(sub\s*total|subtotal|grand\s*total|paid\s*total)\b/;
|
|
10345
10414
|
var ASSISTANT_TOTAL_WITH_MONEY_HINT_PATTERN = /\btotal\b.*\b(amount|revenue|sales|tax|price|cost|balance|paid|due|charge|billing|profit|margin)\b/;
|
|
@@ -12774,7 +12843,11 @@ function normalizeAssistantAggregateOptions(options) {
|
|
|
12774
12843
|
aggregateOptions: aggregateOptions,
|
|
12775
12844
|
limit: limit,
|
|
12776
12845
|
maxLimit: maxLimit,
|
|
12777
|
-
defaultLimit: defaultLimit
|
|
12846
|
+
defaultLimit: defaultLimit,
|
|
12847
|
+
disableNoDataFallbacks: normalized.disableNoDataFallbacks === true
|
|
12848
|
+
|| normalized.disable_no_data_fallbacks === true
|
|
12849
|
+
|| normalized.disableFallbacks === true
|
|
12850
|
+
|| normalized.disable_fallbacks === true
|
|
12778
12851
|
};
|
|
12779
12852
|
}
|
|
12780
12853
|
function findAggregateLimit(pipeline) {
|
|
@@ -15173,7 +15246,7 @@ function tokenizeCollectionText(value) {
|
|
|
15173
15246
|
}
|
|
15174
15247
|
function computeCollectionTokenWeights(tokens) {
|
|
15175
15248
|
var unique = Array.from(new Set(tokens));
|
|
15176
|
-
var hasDomain = unique.some(function (token) { return
|
|
15249
|
+
var hasDomain = unique.some(function (token) { return !AI_ASSISTANT_COLLECTION_GENERIC_TOKENS.has(token); });
|
|
15177
15250
|
var weights = {};
|
|
15178
15251
|
unique.forEach(function (token) {
|
|
15179
15252
|
if (hasDomain && AI_ASSISTANT_COLLECTION_GENERIC_TOKENS.has(token)) {
|
|
@@ -15797,8 +15870,11 @@ function createAssistantEmptyHeuristicProfile() {
|
|
|
15797
15870
|
return {
|
|
15798
15871
|
aliases: {},
|
|
15799
15872
|
aliasOptions: {},
|
|
15873
|
+
fieldSynonyms: {},
|
|
15800
15874
|
collectionTermHints: [],
|
|
15801
15875
|
dataIntents: [],
|
|
15876
|
+
routeIntents: [],
|
|
15877
|
+
collectionPreserveRules: [],
|
|
15802
15878
|
enabledDeterministicHeuristics: new Set(),
|
|
15803
15879
|
disabledDeterministicHeuristics: new Set()
|
|
15804
15880
|
};
|
|
@@ -15811,6 +15887,10 @@ function cloneAssistantHeuristicProfile(profile) {
|
|
|
15811
15887
|
acc[key] = mergeAssistantHintValues(((profile === null || profile === void 0 ? void 0 : profile.aliasOptions) || {})[key] || []);
|
|
15812
15888
|
return acc;
|
|
15813
15889
|
}, {}),
|
|
15890
|
+
fieldSynonyms: Object.keys((profile === null || profile === void 0 ? void 0 : profile.fieldSynonyms) || {}).reduce(function (acc, key) {
|
|
15891
|
+
acc[key] = mergeAssistantHintValues(((profile === null || profile === void 0 ? void 0 : profile.fieldSynonyms) || {})[key] || []);
|
|
15892
|
+
return acc;
|
|
15893
|
+
}, {}),
|
|
15814
15894
|
collectionTermHints: Array.isArray(profile === null || profile === void 0 ? void 0 : profile.collectionTermHints)
|
|
15815
15895
|
? profile.collectionTermHints.map(function (entry) { return ({
|
|
15816
15896
|
terms: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.terms) || []).map(function (term) { return term.toLowerCase(); }),
|
|
@@ -15829,9 +15909,39 @@ function cloneAssistantHeuristicProfile(profile) {
|
|
|
15829
15909
|
metricField: normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.metricField) || undefined,
|
|
15830
15910
|
fallbackCollections: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.fallbackCollections) || []),
|
|
15831
15911
|
progress: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.progress) || []),
|
|
15832
|
-
|
|
15912
|
+
acknowledgement: normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.acknowledgement) || undefined,
|
|
15913
|
+
assumptions: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.assumptions) || []),
|
|
15914
|
+
pipeline: Array.isArray(entry === null || entry === void 0 ? void 0 : entry.pipeline) ? (0, common_1.deepCopy)(entry.pipeline) : undefined,
|
|
15915
|
+
options: (entry === null || entry === void 0 ? void 0 : entry.options) && typeof entry.options === 'object' && !Array.isArray(entry.options)
|
|
15916
|
+
? (0, common_1.deepCopy)(entry.options)
|
|
15917
|
+
: undefined
|
|
15833
15918
|
}); }).filter(function (entry) { return !!entry.id && !!entry.collection; })
|
|
15834
15919
|
: [],
|
|
15920
|
+
routeIntents: Array.isArray(profile === null || profile === void 0 ? void 0 : profile.routeIntents)
|
|
15921
|
+
? profile.routeIntents.map(function (entry) { return ({
|
|
15922
|
+
id: normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.id),
|
|
15923
|
+
terms: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.terms) || []).map(function (term) { return term.toLowerCase(); }),
|
|
15924
|
+
excludeTerms: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.excludeTerms) || []).map(function (term) { return term.toLowerCase(); }),
|
|
15925
|
+
routes: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.routes) || []).map(function (route) { return normalizeRouteKey(route); }).filter(Boolean),
|
|
15926
|
+
response: normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.response) || undefined
|
|
15927
|
+
}); }).filter(function (entry) { return !!entry.id && !!entry.routes.length; })
|
|
15928
|
+
: [],
|
|
15929
|
+
collectionPreserveRules: Array.isArray(profile === null || profile === void 0 ? void 0 : profile.collectionPreserveRules)
|
|
15930
|
+
? profile.collectionPreserveRules.map(function (entry) { return ({
|
|
15931
|
+
id: normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.id) || undefined,
|
|
15932
|
+
routePreferredCollections: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.routePreferredCollections) || [])
|
|
15933
|
+
.map(function (collection) { return normalizeAssistantCollectionOverrideName(collection); })
|
|
15934
|
+
.filter(Boolean),
|
|
15935
|
+
routePatterns: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.routePatterns) || [])
|
|
15936
|
+
.map(function (route) { return normalizeRouteKey(route); })
|
|
15937
|
+
.filter(Boolean),
|
|
15938
|
+
requestedCollections: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.requestedCollections) || [])
|
|
15939
|
+
.map(function (collection) { return normalizeAssistantCollectionOverrideName(collection); })
|
|
15940
|
+
.filter(Boolean),
|
|
15941
|
+
contextTerms: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.contextTerms) || []).map(function (term) { return term.toLowerCase(); }),
|
|
15942
|
+
terms: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.terms) || []).map(function (term) { return term.toLowerCase(); })
|
|
15943
|
+
}); }).filter(function (entry) { return !!entry.routePreferredCollections.length && !!entry.routePatterns.length && !!entry.requestedCollections.length; })
|
|
15944
|
+
: [],
|
|
15835
15945
|
enabledDeterministicHeuristics: new Set(Array.from((profile === null || profile === void 0 ? void 0 : profile.enabledDeterministicHeuristics) || [])),
|
|
15836
15946
|
disabledDeterministicHeuristics: new Set(Array.from((profile === null || profile === void 0 ? void 0 : profile.disabledDeterministicHeuristics) || [])),
|
|
15837
15947
|
displayDateFormat: profile === null || profile === void 0 ? void 0 : profile.displayDateFormat
|
|
@@ -15858,8 +15968,18 @@ function mergeAssistantHeuristicProfiles(base, override) {
|
|
|
15858
15968
|
}
|
|
15859
15969
|
merged.aliasOptions[normalizedKey] = values;
|
|
15860
15970
|
});
|
|
15971
|
+
Object.keys(override.fieldSynonyms || {}).forEach(function (key) {
|
|
15972
|
+
var normalizedKey = normalizeCollectionKey(key);
|
|
15973
|
+
var values = mergeAssistantHintValues((override.fieldSynonyms || {})[key] || []);
|
|
15974
|
+
if (!normalizedKey || !values.length) {
|
|
15975
|
+
return;
|
|
15976
|
+
}
|
|
15977
|
+
merged.fieldSynonyms[normalizedKey] = mergeAssistantHintValues(merged.fieldSynonyms[normalizedKey] || [], values);
|
|
15978
|
+
});
|
|
15861
15979
|
merged.collectionTermHints = __spreadArray(__spreadArray([], __read(merged.collectionTermHints), false), __read((Array.isArray(override.collectionTermHints) ? override.collectionTermHints : [])), false);
|
|
15862
15980
|
merged.dataIntents = __spreadArray(__spreadArray([], __read(merged.dataIntents), false), __read((Array.isArray(override.dataIntents) ? override.dataIntents : [])), false);
|
|
15981
|
+
merged.routeIntents = __spreadArray(__spreadArray([], __read(merged.routeIntents), false), __read((Array.isArray(override.routeIntents) ? override.routeIntents : [])), false);
|
|
15982
|
+
merged.collectionPreserveRules = __spreadArray(__spreadArray([], __read(merged.collectionPreserveRules), false), __read((Array.isArray(override.collectionPreserveRules) ? override.collectionPreserveRules : [])), false);
|
|
15863
15983
|
Array.from(override.enabledDeterministicHeuristics || []).forEach(function (value) { return merged.enabledDeterministicHeuristics.add(value); });
|
|
15864
15984
|
Array.from(override.disabledDeterministicHeuristics || []).forEach(function (value) { return merged.disabledDeterministicHeuristics.add(value); });
|
|
15865
15985
|
if (override.displayDateFormat) {
|
|
@@ -15966,11 +16086,87 @@ function normalizeAssistantAppDataIntents(value) {
|
|
|
15966
16086
|
metricField: normalizeOptionalString(entry.metric_field || entry.metricField) || undefined,
|
|
15967
16087
|
fallbackCollections: normalizeAssistantHeuristicStringList(entry.fallback_collections || entry.fallbackCollections || []),
|
|
15968
16088
|
progress: mergeAssistantHintValues(Array.isArray(entry.progress) ? entry.progress : []),
|
|
15969
|
-
|
|
16089
|
+
acknowledgement: normalizeOptionalString(entry.acknowledgement
|
|
16090
|
+
|| entry.acknowledgement_text
|
|
16091
|
+
|| entry.acknowledgementText
|
|
16092
|
+
|| entry.acknowledgement_template
|
|
16093
|
+
|| entry.acknowledgementTemplate) || undefined,
|
|
16094
|
+
assumptions: mergeAssistantHintValues(Array.isArray(entry.assumptions) ? entry.assumptions : []),
|
|
16095
|
+
pipeline: Array.isArray(entry.pipeline) ? (0, common_1.deepCopy)(entry.pipeline) : undefined,
|
|
16096
|
+
options: entry.options && typeof entry.options === 'object' && !Array.isArray(entry.options)
|
|
16097
|
+
? (0, common_1.deepCopy)(entry.options)
|
|
16098
|
+
: undefined
|
|
15970
16099
|
});
|
|
15971
16100
|
});
|
|
15972
16101
|
return intents;
|
|
15973
16102
|
}
|
|
16103
|
+
function normalizeAssistantAppRouteIntents(value) {
|
|
16104
|
+
var entries = Array.isArray(value) ? value : [];
|
|
16105
|
+
var intents = [];
|
|
16106
|
+
entries.forEach(function (entry) {
|
|
16107
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
16108
|
+
return;
|
|
16109
|
+
}
|
|
16110
|
+
var id = normalizeOptionalString(entry.id || entry.intent_id || entry.intentId);
|
|
16111
|
+
var terms = normalizeAssistantHeuristicStringList(entry.terms || entry.trigger_terms || entry.triggerTerms || entry.phrases || []).map(function (term) { return term.toLowerCase(); });
|
|
16112
|
+
var routes = normalizeAssistantHeuristicStringList(entry.routes || entry.preferred_routes || entry.preferredRoutes || entry.targets || []).map(function (route) { return normalizeRouteKey(route); }).filter(Boolean);
|
|
16113
|
+
if (!id || !terms.length || !routes.length) {
|
|
16114
|
+
return;
|
|
16115
|
+
}
|
|
16116
|
+
intents.push({
|
|
16117
|
+
id: id,
|
|
16118
|
+
terms: terms,
|
|
16119
|
+
excludeTerms: normalizeAssistantHeuristicStringList(entry.exclude_terms || entry.excludeTerms || []).map(function (term) { return term.toLowerCase(); }),
|
|
16120
|
+
routes: routes,
|
|
16121
|
+
response: normalizeOptionalString(entry.response || entry.summary) || undefined
|
|
16122
|
+
});
|
|
16123
|
+
});
|
|
16124
|
+
return intents;
|
|
16125
|
+
}
|
|
16126
|
+
function normalizeAssistantAppCollectionPreserveRules(value) {
|
|
16127
|
+
var entries = Array.isArray(value) ? value : [];
|
|
16128
|
+
var rules = [];
|
|
16129
|
+
entries.forEach(function (entry) {
|
|
16130
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
16131
|
+
return;
|
|
16132
|
+
}
|
|
16133
|
+
var routePreferredCollections = normalizeAssistantHeuristicStringList(entry.route_preferred_collections
|
|
16134
|
+
|| entry.routePreferredCollections
|
|
16135
|
+
|| entry.route_collections
|
|
16136
|
+
|| entry.routeCollections
|
|
16137
|
+
|| entry.route_collection
|
|
16138
|
+
|| entry.routeCollection).map(function (collection) { return normalizeAssistantCollectionOverrideName(collection); }).filter(Boolean);
|
|
16139
|
+
var routePatterns = normalizeAssistantHeuristicStringList(entry.permission_routes
|
|
16140
|
+
|| entry.permissionRoutes
|
|
16141
|
+
|| entry.route_patterns
|
|
16142
|
+
|| entry.routePatterns
|
|
16143
|
+
|| entry.routes).map(function (route) { return normalizeRouteKey(route); }).filter(Boolean);
|
|
16144
|
+
var requestedCollections = normalizeAssistantHeuristicStringList(entry.requested_collections
|
|
16145
|
+
|| entry.requestedCollections
|
|
16146
|
+
|| entry.collections
|
|
16147
|
+
|| entry.collection).map(function (collection) { return normalizeAssistantCollectionOverrideName(collection); }).filter(Boolean);
|
|
16148
|
+
var terms = normalizeAssistantHeuristicStringList(entry.terms
|
|
16149
|
+
|| entry.trigger_terms
|
|
16150
|
+
|| entry.triggerTerms
|
|
16151
|
+
|| entry.phrases).map(function (term) { return term.toLowerCase(); });
|
|
16152
|
+
var contextTerms = normalizeAssistantHeuristicStringList(entry.context_terms
|
|
16153
|
+
|| entry.contextTerms
|
|
16154
|
+
|| entry.required_terms
|
|
16155
|
+
|| entry.requiredTerms).map(function (term) { return term.toLowerCase(); });
|
|
16156
|
+
if (!routePreferredCollections.length || !routePatterns.length || !requestedCollections.length) {
|
|
16157
|
+
return;
|
|
16158
|
+
}
|
|
16159
|
+
rules.push({
|
|
16160
|
+
id: normalizeOptionalString(entry.id || entry.rule_id || entry.ruleId) || undefined,
|
|
16161
|
+
routePreferredCollections: routePreferredCollections,
|
|
16162
|
+
routePatterns: routePatterns,
|
|
16163
|
+
requestedCollections: requestedCollections,
|
|
16164
|
+
contextTerms: contextTerms,
|
|
16165
|
+
terms: terms
|
|
16166
|
+
});
|
|
16167
|
+
});
|
|
16168
|
+
return rules;
|
|
16169
|
+
}
|
|
15974
16170
|
function normalizeAssistantAppHeuristicProfile(value) {
|
|
15975
16171
|
var profile = createAssistantEmptyHeuristicProfile();
|
|
15976
16172
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
@@ -15989,6 +16185,10 @@ function normalizeAssistantAppHeuristicProfile(value) {
|
|
|
15989
16185
|
|| value.collectionAliasOptions
|
|
15990
16186
|
|| value.alias_options
|
|
15991
16187
|
|| value.aliasOptions);
|
|
16188
|
+
profile.fieldSynonyms = normalizeAssistantAliasOptionsMap(value.field_synonyms
|
|
16189
|
+
|| value.fieldSynonyms
|
|
16190
|
+
|| value.field_token_synonyms
|
|
16191
|
+
|| value.fieldTokenSynonyms);
|
|
15992
16192
|
profile.collectionTermHints = normalizeAssistantCollectionTermHints(value.collection_term_hints
|
|
15993
16193
|
|| value.collectionTermHints
|
|
15994
16194
|
|| value.term_hints
|
|
@@ -15996,6 +16196,14 @@ function normalizeAssistantAppHeuristicProfile(value) {
|
|
|
15996
16196
|
profile.dataIntents = normalizeAssistantAppDataIntents(value.data_intents
|
|
15997
16197
|
|| value.dataIntents
|
|
15998
16198
|
|| value.intents);
|
|
16199
|
+
profile.routeIntents = normalizeAssistantAppRouteIntents(value.route_intents
|
|
16200
|
+
|| value.routeIntents
|
|
16201
|
+
|| value.navigation_intents
|
|
16202
|
+
|| value.navigationIntents);
|
|
16203
|
+
profile.collectionPreserveRules = normalizeAssistantAppCollectionPreserveRules(value.collection_override_preserves
|
|
16204
|
+
|| value.collectionOverridePreserves
|
|
16205
|
+
|| value.collection_preserve_rules
|
|
16206
|
+
|| value.collectionPreserveRules);
|
|
15999
16207
|
profile.displayDateFormat = normalizeAssistantDisplayDateFormat(value.display_date_format
|
|
16000
16208
|
|| value.displayDateFormat
|
|
16001
16209
|
|| value.date_display_format
|
|
@@ -16043,6 +16251,7 @@ function normalizeAssistantAppHeuristicRegistry(value) {
|
|
|
16043
16251
|
|| Object.keys(standaloneProfile.aliasOptions).length
|
|
16044
16252
|
|| standaloneProfile.collectionTermHints.length
|
|
16045
16253
|
|| standaloneProfile.dataIntents.length
|
|
16254
|
+
|| standaloneProfile.routeIntents.length
|
|
16046
16255
|
|| standaloneProfile.enabledDeterministicHeuristics.size
|
|
16047
16256
|
|| standaloneProfile.disabledDeterministicHeuristics.size
|
|
16048
16257
|
|| normalizeOptionalString(standaloneProfile.appId)) {
|
|
@@ -16456,6 +16665,9 @@ function resolveCollectionOverrideWithContext(params) {
|
|
|
16456
16665
|
? params.collectionHints.map(function (value) { return normalizeOptionalString(value); }).filter(Boolean)
|
|
16457
16666
|
: [];
|
|
16458
16667
|
var permissionView = normalizeOptionalString(params.permissionView);
|
|
16668
|
+
var collectionPreserveRules = Array.isArray(params.collectionPreserveRules)
|
|
16669
|
+
? params.collectionPreserveRules
|
|
16670
|
+
: resolveAssistantAppHeuristicProfile(params.appId).collectionPreserveRules;
|
|
16459
16671
|
var routeHintCollections = permissionView
|
|
16460
16672
|
? resolveCollectionHintsFromRoute(permissionView, collectionNames)
|
|
16461
16673
|
: [];
|
|
@@ -16478,7 +16690,13 @@ function resolveCollectionOverrideWithContext(params) {
|
|
|
16478
16690
|
&& !isAssistantCollectionInHintFamilies(requested, [routePreferred])) {
|
|
16479
16691
|
var routePreferredName = normalizeAssistantCollectionOverrideName(routePreferred);
|
|
16480
16692
|
var requestedIsWorkOrder = isAssistantWorkOrderCollectionOverrideCandidate(requested);
|
|
16481
|
-
if (
|
|
16693
|
+
if (shouldPreserveAssistantCollectionForRouteFromRules({
|
|
16694
|
+
message: params.message,
|
|
16695
|
+
permissionView: permissionView,
|
|
16696
|
+
routePreferredName: routePreferredName,
|
|
16697
|
+
requestedCollection: requested,
|
|
16698
|
+
rules: collectionPreserveRules
|
|
16699
|
+
})) {
|
|
16482
16700
|
return null;
|
|
16483
16701
|
}
|
|
16484
16702
|
if (!(routePreferredName === 'orders' && requestedIsWorkOrder && hasAssistantWorkOrderAliasTerms(params.message))) {
|
|
@@ -16580,30 +16798,76 @@ function resolveCollectionOverrideWithContext(params) {
|
|
|
16580
16798
|
function resolveCollectionOverrideWithContextForTesting(params) {
|
|
16581
16799
|
return resolveCollectionOverrideWithContext(params);
|
|
16582
16800
|
}
|
|
16583
|
-
function
|
|
16584
|
-
var route =
|
|
16585
|
-
var
|
|
16586
|
-
if (!route ||
|
|
16801
|
+
function doesAssistantPreserveRoutePatternMatch(permissionView, pattern) {
|
|
16802
|
+
var route = normalizeRouteKey(permissionView);
|
|
16803
|
+
var routePattern = normalizeRouteKey(pattern);
|
|
16804
|
+
if (!route || !routePattern) {
|
|
16587
16805
|
return false;
|
|
16588
16806
|
}
|
|
16589
|
-
|
|
16807
|
+
return route === routePattern || route.startsWith("".concat(routePattern, "/"));
|
|
16808
|
+
}
|
|
16809
|
+
function doesAssistantPreserveTermMatch(text, term) {
|
|
16810
|
+
var normalizedText = normalizeOptionalString(text).toLowerCase();
|
|
16811
|
+
var normalizedTerm = normalizeOptionalString(term).toLowerCase();
|
|
16812
|
+
if (!normalizedText || !normalizedTerm) {
|
|
16590
16813
|
return false;
|
|
16591
16814
|
}
|
|
16592
|
-
var
|
|
16593
|
-
if (
|
|
16815
|
+
var compactTerm = normalizedTerm.replace(/\s+/g, ' ');
|
|
16816
|
+
if (compactTerm.length <= 3 && /^[a-z0-9]+$/.test(compactTerm)) {
|
|
16817
|
+
return new RegExp("\\b".concat(escapeRegexValue(compactTerm), "\\b"), 'i').test(normalizedText);
|
|
16818
|
+
}
|
|
16819
|
+
return normalizedText.includes(compactTerm);
|
|
16820
|
+
}
|
|
16821
|
+
function doesAssistantPreserveAnyTermMatch(text, terms) {
|
|
16822
|
+
return (Array.isArray(terms) ? terms : []).some(function (term) { return doesAssistantPreserveTermMatch(text, term); });
|
|
16823
|
+
}
|
|
16824
|
+
function shouldPreserveAssistantCollectionForRouteFromRules(params) {
|
|
16825
|
+
var e_32, _a;
|
|
16826
|
+
var _b, _c, _d, _e, _f, _g, _h;
|
|
16827
|
+
var routePreferred = normalizeAssistantCollectionOverrideName(params.routePreferredName);
|
|
16828
|
+
var requested = normalizeAssistantCollectionOverrideName(params.requestedCollection);
|
|
16829
|
+
var text = normalizeOptionalString(params.message).toLowerCase();
|
|
16830
|
+
if (!routePreferred || !requested || !text) {
|
|
16594
16831
|
return false;
|
|
16595
16832
|
}
|
|
16596
|
-
|
|
16597
|
-
|
|
16833
|
+
try {
|
|
16834
|
+
for (var _j = __values(Array.isArray(params.rules) ? params.rules : []), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
16835
|
+
var rule = _k.value;
|
|
16836
|
+
if (!((_b = rule === null || rule === void 0 ? void 0 : rule.routePreferredCollections) === null || _b === void 0 ? void 0 : _b.includes(routePreferred))) {
|
|
16837
|
+
continue;
|
|
16838
|
+
}
|
|
16839
|
+
if (!((_c = rule.requestedCollections) === null || _c === void 0 ? void 0 : _c.includes(requested))) {
|
|
16840
|
+
continue;
|
|
16841
|
+
}
|
|
16842
|
+
if (!((_d = rule.routePatterns) === null || _d === void 0 ? void 0 : _d.some(function (pattern) { return doesAssistantPreserveRoutePatternMatch(params.permissionView, pattern); }))) {
|
|
16843
|
+
continue;
|
|
16844
|
+
}
|
|
16845
|
+
if (((_e = rule.contextTerms) === null || _e === void 0 ? void 0 : _e.length) && !doesAssistantPreserveAnyTermMatch(text, rule.contextTerms)) {
|
|
16846
|
+
continue;
|
|
16847
|
+
}
|
|
16848
|
+
if (((_f = rule.terms) === null || _f === void 0 ? void 0 : _f.length) && !doesAssistantPreserveAnyTermMatch(text, rule.terms)) {
|
|
16849
|
+
continue;
|
|
16850
|
+
}
|
|
16851
|
+
if (!((_g = rule.contextTerms) === null || _g === void 0 ? void 0 : _g.length) && !((_h = rule.terms) === null || _h === void 0 ? void 0 : _h.length)) {
|
|
16852
|
+
continue;
|
|
16853
|
+
}
|
|
16854
|
+
return true;
|
|
16855
|
+
}
|
|
16598
16856
|
}
|
|
16599
|
-
|
|
16600
|
-
|
|
16857
|
+
catch (e_32_1) { e_32 = { error: e_32_1 }; }
|
|
16858
|
+
finally {
|
|
16859
|
+
try {
|
|
16860
|
+
if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
|
|
16861
|
+
}
|
|
16862
|
+
finally { if (e_32) throw e_32.error; }
|
|
16601
16863
|
}
|
|
16602
|
-
return
|
|
16864
|
+
return false;
|
|
16603
16865
|
}
|
|
16604
16866
|
function isAssistantWorkOrderCollectionOverrideCandidate(value) {
|
|
16605
16867
|
var normalized = normalizeAssistantCollectionOverrideName(value);
|
|
16606
|
-
return normalized
|
|
16868
|
+
return normalized.startsWith('work-order-')
|
|
16869
|
+
|| normalized.endsWith('-work-orders')
|
|
16870
|
+
|| normalized.includes('-work-order-')
|
|
16607
16871
|
|| normalized === 'work-orders'
|
|
16608
16872
|
|| normalized === 'maintenance-orders'
|
|
16609
16873
|
|| normalized === 'repair-orders';
|
|
@@ -17486,7 +17750,7 @@ function resolveAssistantNestedPrefixCollectionCandidates(params) {
|
|
|
17486
17750
|
function resolveAssistantNestedAggregateFallbacks(params) {
|
|
17487
17751
|
return __awaiter(this, void 0, void 0, function () {
|
|
17488
17752
|
var prefixes, collectionNames, fallbacks, seen, prefixes_1, prefixes_1_1, prefix, rewrite, candidates, candidates_4, candidates_4_1, candidate, normalizedPipeline, key;
|
|
17489
|
-
var
|
|
17753
|
+
var e_33, _a, e_34, _b;
|
|
17490
17754
|
return __generator(this, function (_c) {
|
|
17491
17755
|
switch (_c.label) {
|
|
17492
17756
|
case 0:
|
|
@@ -17516,7 +17780,7 @@ function resolveAssistantNestedAggregateFallbacks(params) {
|
|
|
17516
17780
|
triedCollections: params.triedCollections
|
|
17517
17781
|
});
|
|
17518
17782
|
try {
|
|
17519
|
-
for (candidates_4 = (
|
|
17783
|
+
for (candidates_4 = (e_34 = void 0, __values(candidates)), candidates_4_1 = candidates_4.next(); !candidates_4_1.done; candidates_4_1 = candidates_4.next()) {
|
|
17520
17784
|
candidate = candidates_4_1.value;
|
|
17521
17785
|
normalizedPipeline = normalizeAssistantAggregatePipeline(rewrite.pipeline, candidate);
|
|
17522
17786
|
if (!normalizedPipeline.length || containsForbiddenMongoOperators(normalizedPipeline)) {
|
|
@@ -17538,21 +17802,21 @@ function resolveAssistantNestedAggregateFallbacks(params) {
|
|
|
17538
17802
|
}
|
|
17539
17803
|
}
|
|
17540
17804
|
}
|
|
17541
|
-
catch (
|
|
17805
|
+
catch (e_34_1) { e_34 = { error: e_34_1 }; }
|
|
17542
17806
|
finally {
|
|
17543
17807
|
try {
|
|
17544
17808
|
if (candidates_4_1 && !candidates_4_1.done && (_b = candidates_4.return)) _b.call(candidates_4);
|
|
17545
17809
|
}
|
|
17546
|
-
finally { if (
|
|
17810
|
+
finally { if (e_34) throw e_34.error; }
|
|
17547
17811
|
}
|
|
17548
17812
|
}
|
|
17549
17813
|
}
|
|
17550
|
-
catch (
|
|
17814
|
+
catch (e_33_1) { e_33 = { error: e_33_1 }; }
|
|
17551
17815
|
finally {
|
|
17552
17816
|
try {
|
|
17553
17817
|
if (prefixes_1_1 && !prefixes_1_1.done && (_a = prefixes_1.return)) _a.call(prefixes_1);
|
|
17554
17818
|
}
|
|
17555
|
-
finally { if (
|
|
17819
|
+
finally { if (e_33) throw e_33.error; }
|
|
17556
17820
|
}
|
|
17557
17821
|
return [2 /*return*/, fallbacks];
|
|
17558
17822
|
}
|
|
@@ -17684,8 +17948,8 @@ function resolveAssistantBridgeCollectionHintCandidates(requestedCollection, req
|
|
|
17684
17948
|
}
|
|
17685
17949
|
function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
17686
17950
|
return __awaiter(this, arguments, void 0, function (collection, db, dbName, options) {
|
|
17687
|
-
var normalized, resolutionPath, pushResolutionStep, finalizeResolution, requestHints, appId, requestedTokens, requestedTokenWeights, aliasCandidates, hintCandidates, alias, manager, hasManager, configuredCollectionNames, isConfiguredCollection, candidates, pushCandidate, base, reportCandidate, candidates_5, candidates_5_1, candidate, model, candidates_6, candidates_6_1, candidate, primaryCollectionHint, resolverTargets, resolverErrorLogged, resolverTargets_1, resolverTargets_1_1, resolverTarget, resolved, resolvedName, resolvedScore, resolvedModel, _a,
|
|
17688
|
-
var
|
|
17951
|
+
var normalized, resolutionPath, pushResolutionStep, finalizeResolution, requestHints, appId, requestedTokens, requestedTokenWeights, aliasCandidates, hintCandidates, alias, manager, hasManager, configuredCollectionNames, isConfiguredCollection, candidates, pushCandidate, base, reportCandidate, candidates_5, candidates_5_1, candidate, model, candidates_6, candidates_6_1, candidate, primaryCollectionHint, resolverTargets, resolverErrorLogged, resolverTargets_1, resolverTargets_1_1, resolverTarget, resolved, resolvedName, resolvedScore, resolvedModel, _a, e_35_1, candidates_7, candidates_7_1, candidate, e_36_1, candidates_8, candidates_8_1, candidate;
|
|
17952
|
+
var e_37, _b, e_38, _c, e_35, _d, e_36, _e, e_39, _f;
|
|
17689
17953
|
var _g, _h;
|
|
17690
17954
|
if (dbName === void 0) { dbName = ''; }
|
|
17691
17955
|
return __generator(this, function (_j) {
|
|
@@ -17759,12 +18023,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17759
18023
|
}
|
|
17760
18024
|
}
|
|
17761
18025
|
}
|
|
17762
|
-
catch (
|
|
18026
|
+
catch (e_37_1) { e_37 = { error: e_37_1 }; }
|
|
17763
18027
|
finally {
|
|
17764
18028
|
try {
|
|
17765
18029
|
if (candidates_5_1 && !candidates_5_1.done && (_b = candidates_5.return)) _b.call(candidates_5);
|
|
17766
18030
|
}
|
|
17767
|
-
finally { if (
|
|
18031
|
+
finally { if (e_37) throw e_37.error; }
|
|
17768
18032
|
}
|
|
17769
18033
|
}
|
|
17770
18034
|
if (configuredCollectionNames.length) {
|
|
@@ -17779,12 +18043,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17779
18043
|
}
|
|
17780
18044
|
}
|
|
17781
18045
|
}
|
|
17782
|
-
catch (
|
|
18046
|
+
catch (e_38_1) { e_38 = { error: e_38_1 }; }
|
|
17783
18047
|
finally {
|
|
17784
18048
|
try {
|
|
17785
18049
|
if (candidates_6_1 && !candidates_6_1.done && (_c = candidates_6.return)) _c.call(candidates_6);
|
|
17786
18050
|
}
|
|
17787
|
-
finally { if (
|
|
18051
|
+
finally { if (e_38) throw e_38.error; }
|
|
17788
18052
|
}
|
|
17789
18053
|
}
|
|
17790
18054
|
primaryCollectionHint = normalizeOptionalString((_h = requestHints === null || requestHints === void 0 ? void 0 : requestHints.collectionHints) === null || _h === void 0 ? void 0 : _h[0]);
|
|
@@ -17845,14 +18109,14 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17845
18109
|
return [3 /*break*/, 2];
|
|
17846
18110
|
case 7: return [3 /*break*/, 10];
|
|
17847
18111
|
case 8:
|
|
17848
|
-
|
|
17849
|
-
|
|
18112
|
+
e_35_1 = _j.sent();
|
|
18113
|
+
e_35 = { error: e_35_1 };
|
|
17850
18114
|
return [3 /*break*/, 10];
|
|
17851
18115
|
case 9:
|
|
17852
18116
|
try {
|
|
17853
18117
|
if (resolverTargets_1_1 && !resolverTargets_1_1.done && (_d = resolverTargets_1.return)) _d.call(resolverTargets_1);
|
|
17854
18118
|
}
|
|
17855
|
-
finally { if (
|
|
18119
|
+
finally { if (e_35) throw e_35.error; }
|
|
17856
18120
|
return [7 /*endfinally*/];
|
|
17857
18121
|
case 10:
|
|
17858
18122
|
if (!db) return [3 /*break*/, 18];
|
|
@@ -17878,14 +18142,14 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17878
18142
|
return [3 /*break*/, 12];
|
|
17879
18143
|
case 15: return [3 /*break*/, 18];
|
|
17880
18144
|
case 16:
|
|
17881
|
-
|
|
17882
|
-
|
|
18145
|
+
e_36_1 = _j.sent();
|
|
18146
|
+
e_36 = { error: e_36_1 };
|
|
17883
18147
|
return [3 /*break*/, 18];
|
|
17884
18148
|
case 17:
|
|
17885
18149
|
try {
|
|
17886
18150
|
if (candidates_7_1 && !candidates_7_1.done && (_e = candidates_7.return)) _e.call(candidates_7);
|
|
17887
18151
|
}
|
|
17888
|
-
finally { if (
|
|
18152
|
+
finally { if (e_36) throw e_36.error; }
|
|
17889
18153
|
return [7 /*endfinally*/];
|
|
17890
18154
|
case 18:
|
|
17891
18155
|
try {
|
|
@@ -17896,12 +18160,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17896
18160
|
}
|
|
17897
18161
|
}
|
|
17898
18162
|
}
|
|
17899
|
-
catch (
|
|
18163
|
+
catch (e_39_1) { e_39 = { error: e_39_1 }; }
|
|
17900
18164
|
finally {
|
|
17901
18165
|
try {
|
|
17902
18166
|
if (candidates_8_1 && !candidates_8_1.done && (_f = candidates_8.return)) _f.call(candidates_8);
|
|
17903
18167
|
}
|
|
17904
|
-
finally { if (
|
|
18168
|
+
finally { if (e_39) throw e_39.error; }
|
|
17905
18169
|
}
|
|
17906
18170
|
throw new Error('AI assistant report builder bridge: No queryable collection could be resolved.');
|
|
17907
18171
|
}
|
|
@@ -17909,7 +18173,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17909
18173
|
});
|
|
17910
18174
|
}
|
|
17911
18175
|
function findQueryDateField(query) {
|
|
17912
|
-
var
|
|
18176
|
+
var e_40, _a, e_41, _b;
|
|
17913
18177
|
if (!query || typeof query !== 'object') {
|
|
17914
18178
|
return null;
|
|
17915
18179
|
}
|
|
@@ -17923,12 +18187,12 @@ function findQueryDateField(query) {
|
|
|
17923
18187
|
}
|
|
17924
18188
|
}
|
|
17925
18189
|
}
|
|
17926
|
-
catch (
|
|
18190
|
+
catch (e_40_1) { e_40 = { error: e_40_1 }; }
|
|
17927
18191
|
finally {
|
|
17928
18192
|
try {
|
|
17929
18193
|
if (query_1_1 && !query_1_1.done && (_a = query_1.return)) _a.call(query_1);
|
|
17930
18194
|
}
|
|
17931
|
-
finally { if (
|
|
18195
|
+
finally { if (e_40) throw e_40.error; }
|
|
17932
18196
|
}
|
|
17933
18197
|
return null;
|
|
17934
18198
|
}
|
|
@@ -17947,12 +18211,12 @@ function findQueryDateField(query) {
|
|
|
17947
18211
|
}
|
|
17948
18212
|
}
|
|
17949
18213
|
}
|
|
17950
|
-
catch (
|
|
18214
|
+
catch (e_41_1) { e_41 = { error: e_41_1 }; }
|
|
17951
18215
|
finally {
|
|
17952
18216
|
try {
|
|
17953
18217
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
17954
18218
|
}
|
|
17955
|
-
finally { if (
|
|
18219
|
+
finally { if (e_41) throw e_41.error; }
|
|
17956
18220
|
}
|
|
17957
18221
|
return null;
|
|
17958
18222
|
}
|
|
@@ -18240,7 +18504,7 @@ function resolveQueryDateFieldFallback(query) {
|
|
|
18240
18504
|
return { from: dateField, to: fallback };
|
|
18241
18505
|
}
|
|
18242
18506
|
function containsForbiddenMongoOperators(value) {
|
|
18243
|
-
var
|
|
18507
|
+
var e_42, _a;
|
|
18244
18508
|
if (!value || typeof value !== 'object') {
|
|
18245
18509
|
return false;
|
|
18246
18510
|
}
|
|
@@ -18259,12 +18523,12 @@ function containsForbiddenMongoOperators(value) {
|
|
|
18259
18523
|
}
|
|
18260
18524
|
}
|
|
18261
18525
|
}
|
|
18262
|
-
catch (
|
|
18526
|
+
catch (e_42_1) { e_42 = { error: e_42_1 }; }
|
|
18263
18527
|
finally {
|
|
18264
18528
|
try {
|
|
18265
18529
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
18266
18530
|
}
|
|
18267
|
-
finally { if (
|
|
18531
|
+
finally { if (e_42) throw e_42.error; }
|
|
18268
18532
|
}
|
|
18269
18533
|
return false;
|
|
18270
18534
|
}
|
|
@@ -18449,7 +18713,7 @@ function splitAssistantPermissionTokenSets(value) {
|
|
|
18449
18713
|
};
|
|
18450
18714
|
}
|
|
18451
18715
|
function isAssistantTokenSetSubset(subset, superset) {
|
|
18452
|
-
var
|
|
18716
|
+
var e_43, _a;
|
|
18453
18717
|
if (!subset.size) {
|
|
18454
18718
|
return false;
|
|
18455
18719
|
}
|
|
@@ -18461,12 +18725,12 @@ function isAssistantTokenSetSubset(subset, superset) {
|
|
|
18461
18725
|
}
|
|
18462
18726
|
}
|
|
18463
18727
|
}
|
|
18464
|
-
catch (
|
|
18728
|
+
catch (e_43_1) { e_43 = { error: e_43_1 }; }
|
|
18465
18729
|
finally {
|
|
18466
18730
|
try {
|
|
18467
18731
|
if (subset_1_1 && !subset_1_1.done && (_a = subset_1.return)) _a.call(subset_1);
|
|
18468
18732
|
}
|
|
18469
|
-
finally { if (
|
|
18733
|
+
finally { if (e_43) throw e_43.error; }
|
|
18470
18734
|
}
|
|
18471
18735
|
return true;
|
|
18472
18736
|
}
|
|
@@ -18712,13 +18976,46 @@ function resolveAssistantMongoDefaultMaxTimeMs(config) {
|
|
|
18712
18976
|
}
|
|
18713
18977
|
function resolveAssistantSystemPrompt(config, runtimeContext) {
|
|
18714
18978
|
var override = normalizeOptionalString((config === null || config === void 0 ? void 0 : config.system_prompt) || (config === null || config === void 0 ? void 0 : config.systemPrompt));
|
|
18979
|
+
var additions = resolveAssistantSystemPromptAdditions(config);
|
|
18715
18980
|
if (override) {
|
|
18716
|
-
return override;
|
|
18981
|
+
return additions.length ? __spreadArray([override], __read(additions), false).join('\n') : override;
|
|
18982
|
+
}
|
|
18983
|
+
var basePrompt = !runtimeContext
|
|
18984
|
+
? AI_ASSISTANT_SYSTEM_PROMPT
|
|
18985
|
+
: buildAssistantSystemPromptText(buildAssistantPlatformIntelligencePrompt(runtimeContext));
|
|
18986
|
+
if (additions.length) {
|
|
18987
|
+
return __spreadArray([basePrompt], __read(additions), false).join('\n');
|
|
18717
18988
|
}
|
|
18718
18989
|
if (!runtimeContext) {
|
|
18719
|
-
return
|
|
18990
|
+
return basePrompt;
|
|
18720
18991
|
}
|
|
18721
|
-
return
|
|
18992
|
+
return basePrompt;
|
|
18993
|
+
}
|
|
18994
|
+
function resolveAssistantSystemPromptAdditions(config) {
|
|
18995
|
+
var values = [];
|
|
18996
|
+
var push = function (value) {
|
|
18997
|
+
var normalized = normalizeOptionalString(value);
|
|
18998
|
+
if (!normalized || values.includes(normalized)) {
|
|
18999
|
+
return;
|
|
19000
|
+
}
|
|
19001
|
+
values.push(normalized);
|
|
19002
|
+
};
|
|
19003
|
+
[
|
|
19004
|
+
config === null || config === void 0 ? void 0 : config.system_prompt_additions,
|
|
19005
|
+
config === null || config === void 0 ? void 0 : config.systemPromptAdditions,
|
|
19006
|
+
config === null || config === void 0 ? void 0 : config.app_instructions,
|
|
19007
|
+
config === null || config === void 0 ? void 0 : config.appInstructions,
|
|
19008
|
+
config === null || config === void 0 ? void 0 : config.assistant_instructions,
|
|
19009
|
+
config === null || config === void 0 ? void 0 : config.assistantInstructions
|
|
19010
|
+
].forEach(function (raw) {
|
|
19011
|
+
if (Array.isArray(raw)) {
|
|
19012
|
+
raw.forEach(push);
|
|
19013
|
+
}
|
|
19014
|
+
else {
|
|
19015
|
+
push(raw);
|
|
19016
|
+
}
|
|
19017
|
+
});
|
|
19018
|
+
return values;
|
|
18722
19019
|
}
|
|
18723
19020
|
function normalizeAssistantRuntimeControl(value) {
|
|
18724
19021
|
if (!value || typeof value !== 'object') {
|
|
@@ -18968,8 +19265,8 @@ function applyCodexStreamStatusHandler(runOptions, streamStatusHandler) {
|
|
|
18968
19265
|
}
|
|
18969
19266
|
function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
18970
19267
|
return __awaiter(this, void 0, void 0, function () {
|
|
18971
|
-
var _a, _b, _c, _d, message, payload, status_1,
|
|
18972
|
-
var _e,
|
|
19268
|
+
var _a, _b, _c, _d, message, payload, status_1, e_44_1;
|
|
19269
|
+
var _e, e_44, _f, _g;
|
|
18973
19270
|
return __generator(this, function (_h) {
|
|
18974
19271
|
switch (_h.label) {
|
|
18975
19272
|
case 0:
|
|
@@ -18996,8 +19293,8 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
18996
19293
|
return [3 /*break*/, 1];
|
|
18997
19294
|
case 4: return [3 /*break*/, 11];
|
|
18998
19295
|
case 5:
|
|
18999
|
-
|
|
19000
|
-
|
|
19296
|
+
e_44_1 = _h.sent();
|
|
19297
|
+
e_44 = { error: e_44_1 };
|
|
19001
19298
|
return [3 /*break*/, 11];
|
|
19002
19299
|
case 6:
|
|
19003
19300
|
_h.trys.push([6, , 9, 10]);
|
|
@@ -19008,7 +19305,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
19008
19305
|
_h.label = 8;
|
|
19009
19306
|
case 8: return [3 /*break*/, 10];
|
|
19010
19307
|
case 9:
|
|
19011
|
-
if (
|
|
19308
|
+
if (e_44) throw e_44.error;
|
|
19012
19309
|
return [7 /*endfinally*/];
|
|
19013
19310
|
case 10: return [7 /*endfinally*/];
|
|
19014
19311
|
case 11: throw new CodexWorkerBootstrapError('AI worker exited before completing.');
|
|
@@ -19018,7 +19315,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
19018
19315
|
}
|
|
19019
19316
|
function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler) {
|
|
19020
19317
|
return __awaiter(this, void 0, void 0, function () {
|
|
19021
|
-
var streamedOptions, normalizedThreadKey, shouldForceInProcessThreadReuse, codexClient, codexClient, workerPath, codexClient,
|
|
19318
|
+
var streamedOptions, normalizedThreadKey, shouldForceInProcessThreadReuse, codexClient, codexClient, workerPath, codexClient, error_15, codexClient;
|
|
19022
19319
|
return __generator(this, function (_a) {
|
|
19023
19320
|
switch (_a.label) {
|
|
19024
19321
|
case 0:
|
|
@@ -19046,11 +19343,11 @@ function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler)
|
|
|
19046
19343
|
return [4 /*yield*/, runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config, streamStatusHandler)];
|
|
19047
19344
|
case 8: return [2 /*return*/, _a.sent()];
|
|
19048
19345
|
case 9:
|
|
19049
|
-
|
|
19050
|
-
if (!(
|
|
19051
|
-
throw
|
|
19346
|
+
error_15 = _a.sent();
|
|
19347
|
+
if (!(error_15 instanceof CodexWorkerBootstrapError)) {
|
|
19348
|
+
throw error_15;
|
|
19052
19349
|
}
|
|
19053
|
-
console.error('AI worker bootstrap failed, falling back to in-process run.',
|
|
19350
|
+
console.error('AI worker bootstrap failed, falling back to in-process run.', error_15);
|
|
19054
19351
|
codexClient = getAssistantCodexClient(config);
|
|
19055
19352
|
return [4 /*yield*/, codexClient.run(prompt, streamedOptions)];
|
|
19056
19353
|
case 10: return [2 /*return*/, _a.sent()];
|
|
@@ -19088,7 +19385,7 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
19088
19385
|
timeoutMs = ((sanitizedOptions === null || sanitizedOptions === void 0 ? void 0 : sanitizedOptions.timeoutMs) || resolveCodexTimeoutMs()) + 15000;
|
|
19089
19386
|
timeoutController = new AbortController();
|
|
19090
19387
|
timeoutPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
19091
|
-
var
|
|
19388
|
+
var error_16;
|
|
19092
19389
|
return __generator(this, function (_a) {
|
|
19093
19390
|
switch (_a.label) {
|
|
19094
19391
|
case 0:
|
|
@@ -19098,11 +19395,11 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
19098
19395
|
_a.sent();
|
|
19099
19396
|
return [2 /*return*/, { type: 'timeout' }];
|
|
19100
19397
|
case 2:
|
|
19101
|
-
|
|
19102
|
-
if ((
|
|
19398
|
+
error_16 = _a.sent();
|
|
19399
|
+
if ((error_16 === null || error_16 === void 0 ? void 0 : error_16.name) === 'AbortError') {
|
|
19103
19400
|
return [2 /*return*/, { type: 'aborted' }];
|
|
19104
19401
|
}
|
|
19105
|
-
throw
|
|
19402
|
+
throw error_16;
|
|
19106
19403
|
case 3: return [2 /*return*/];
|
|
19107
19404
|
}
|
|
19108
19405
|
});
|
|
@@ -19352,8 +19649,8 @@ function buildAssistantWorkspaceRootCandidates(params) {
|
|
|
19352
19649
|
}
|
|
19353
19650
|
function resolveAssistantWorkspaceRoot() {
|
|
19354
19651
|
return __awaiter(this, void 0, void 0, function () {
|
|
19355
|
-
var candidates, firstExisting, firstNestedGitRoot, candidates_9, candidates_9_1, candidate, _a, gitRoot, nestedGitRoots,
|
|
19356
|
-
var
|
|
19652
|
+
var candidates, firstExisting, firstNestedGitRoot, candidates_9, candidates_9_1, candidate, _a, gitRoot, nestedGitRoots, e_45_1;
|
|
19653
|
+
var e_45, _b;
|
|
19357
19654
|
return __generator(this, function (_c) {
|
|
19358
19655
|
switch (_c.label) {
|
|
19359
19656
|
case 0:
|
|
@@ -19400,14 +19697,14 @@ function resolveAssistantWorkspaceRoot() {
|
|
|
19400
19697
|
return [3 /*break*/, 2];
|
|
19401
19698
|
case 8: return [3 /*break*/, 11];
|
|
19402
19699
|
case 9:
|
|
19403
|
-
|
|
19404
|
-
|
|
19700
|
+
e_45_1 = _c.sent();
|
|
19701
|
+
e_45 = { error: e_45_1 };
|
|
19405
19702
|
return [3 /*break*/, 11];
|
|
19406
19703
|
case 10:
|
|
19407
19704
|
try {
|
|
19408
19705
|
if (candidates_9_1 && !candidates_9_1.done && (_b = candidates_9.return)) _b.call(candidates_9);
|
|
19409
19706
|
}
|
|
19410
|
-
finally { if (
|
|
19707
|
+
finally { if (e_45) throw e_45.error; }
|
|
19411
19708
|
return [7 /*endfinally*/];
|
|
19412
19709
|
case 11:
|
|
19413
19710
|
if (firstNestedGitRoot) {
|
|
@@ -19476,9 +19773,11 @@ var AI_ASSISTANT_ROUTE_LOOKUP_PATTERNS = [
|
|
|
19476
19773
|
/\broutes?\s+(?:path|screen|page)\b/,
|
|
19477
19774
|
/\bwhat(?:['’]s| is)\s+the\s+route\b/,
|
|
19478
19775
|
/\bwhere\b.*\b(route|screen|page)\b/,
|
|
19479
|
-
/\bwhere\b.*\b(list|detail|dashboard|menu)\b/,
|
|
19480
|
-
/\
|
|
19481
|
-
/\bwhere
|
|
19776
|
+
/\bwhere\b.*\b(list|listed|listing|detail|dashboard|menu)\b/,
|
|
19777
|
+
/\bshow\s+me\b.*\b(list|listing|page|screen|route|menu)\b/,
|
|
19778
|
+
/\bwhere do i\s+(?:go|find|open|set|change|update|configure)\b/,
|
|
19779
|
+
/\bwhere can i\s+(?:go|find|open|set|change|update|configure)\b/,
|
|
19780
|
+
/\bhow (?:do|can) i\s+(?:set|change|update|configure|personalize)\b/,
|
|
19482
19781
|
/\bpath\b/,
|
|
19483
19782
|
/\bscreen\b/,
|
|
19484
19783
|
/\bpage\b/,
|
|
@@ -19813,7 +20112,7 @@ var AI_ASSISTANT_BREAKDOWN_DIMENSION_STOPWORDS = new Set([
|
|
|
19813
20112
|
'by'
|
|
19814
20113
|
]);
|
|
19815
20114
|
function normalizeAssistantBreakdownDimension(value) {
|
|
19816
|
-
var
|
|
20115
|
+
var e_46, _a;
|
|
19817
20116
|
var normalized = normalizeOptionalString(value)
|
|
19818
20117
|
.toLowerCase()
|
|
19819
20118
|
.replace(/[^a-z0-9_\s-]+/g, ' ')
|
|
@@ -19845,12 +20144,12 @@ function normalizeAssistantBreakdownDimension(value) {
|
|
|
19845
20144
|
}
|
|
19846
20145
|
}
|
|
19847
20146
|
}
|
|
19848
|
-
catch (
|
|
20147
|
+
catch (e_46_1) { e_46 = { error: e_46_1 }; }
|
|
19849
20148
|
finally {
|
|
19850
20149
|
try {
|
|
19851
20150
|
if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
|
|
19852
20151
|
}
|
|
19853
|
-
finally { if (
|
|
20152
|
+
finally { if (e_46) throw e_46.error; }
|
|
19854
20153
|
}
|
|
19855
20154
|
if (!kept.length) {
|
|
19856
20155
|
return '';
|
|
@@ -20055,7 +20354,7 @@ function resolveAssistantPlannerEnabled(config) {
|
|
|
20055
20354
|
return raw === undefined ? false : raw === true;
|
|
20056
20355
|
}
|
|
20057
20356
|
function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
|
|
20058
|
-
var
|
|
20357
|
+
var e_47, _a;
|
|
20059
20358
|
var _b;
|
|
20060
20359
|
if (isSuperAdmin === void 0) { isSuperAdmin = false; }
|
|
20061
20360
|
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
@@ -20069,12 +20368,12 @@ function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
|
|
|
20069
20368
|
}
|
|
20070
20369
|
}
|
|
20071
20370
|
}
|
|
20072
|
-
catch (
|
|
20371
|
+
catch (e_47_1) { e_47 = { error: e_47_1 }; }
|
|
20073
20372
|
finally {
|
|
20074
20373
|
try {
|
|
20075
20374
|
if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
|
|
20076
20375
|
}
|
|
20077
|
-
finally { if (
|
|
20376
|
+
finally { if (e_47) throw e_47.error; }
|
|
20078
20377
|
}
|
|
20079
20378
|
var normalizedRoutes = Array.from(unique);
|
|
20080
20379
|
var allowedRoutes = collectAssistantAllowedRoutesForUser(user, normalizedRoutes, isSuperAdmin);
|
|
@@ -20315,22 +20614,14 @@ function buildAssistantFieldHints(message, collectionNames, options) {
|
|
|
20315
20614
|
return [];
|
|
20316
20615
|
}
|
|
20317
20616
|
var baseTokens = tokenizeFieldKey(normalizedMessage);
|
|
20318
|
-
var expandedTokens = expandFieldTokens(baseTokens);
|
|
20617
|
+
var expandedTokens = expandFieldTokens(baseTokens, options === null || options === void 0 ? void 0 : options.appId);
|
|
20319
20618
|
var tokenSet = new Set(expandedTokens);
|
|
20320
20619
|
[
|
|
20321
20620
|
'date',
|
|
20322
20621
|
'status',
|
|
20323
20622
|
'total',
|
|
20324
20623
|
'amount',
|
|
20325
|
-
'
|
|
20326
|
-
'balance',
|
|
20327
|
-
'grand',
|
|
20328
|
-
'subtotal',
|
|
20329
|
-
'invoice',
|
|
20330
|
-
'revenue',
|
|
20331
|
-
'sales',
|
|
20332
|
-
'billing',
|
|
20333
|
-
'payment'
|
|
20624
|
+
'balance'
|
|
20334
20625
|
].forEach(function (token) { return tokenSet.add(token); });
|
|
20335
20626
|
var hints = [];
|
|
20336
20627
|
var candidates = collectionNames.filter(Boolean).slice(0, maxCollections);
|
|
@@ -20441,6 +20732,10 @@ function buildAssistantSchemaHints(collectionNames, options) {
|
|
|
20441
20732
|
});
|
|
20442
20733
|
return hints;
|
|
20443
20734
|
}
|
|
20735
|
+
var AI_ASSISTANT_CORE_PUBLIC_ROUTES = [
|
|
20736
|
+
'/home',
|
|
20737
|
+
'/user-settings/settings'
|
|
20738
|
+
];
|
|
20444
20739
|
var cachedClientRouteIndex = null;
|
|
20445
20740
|
function normalizeRouteKey(value) {
|
|
20446
20741
|
var trimmed = normalizeOptionalString(value);
|
|
@@ -20454,9 +20749,9 @@ function normalizeRouteMatchKey(value) {
|
|
|
20454
20749
|
return normalizeRouteKey(value).toLowerCase();
|
|
20455
20750
|
}
|
|
20456
20751
|
function buildClientRouteIndex() {
|
|
20457
|
-
var
|
|
20752
|
+
var e_48, _a;
|
|
20458
20753
|
var _b;
|
|
20459
|
-
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
20754
|
+
var routes = mergeAssistantHintValues(((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [], AI_ASSISTANT_CORE_PUBLIC_ROUTES);
|
|
20460
20755
|
var set = new Set();
|
|
20461
20756
|
var map = new Map();
|
|
20462
20757
|
try {
|
|
@@ -20473,18 +20768,18 @@ function buildClientRouteIndex() {
|
|
|
20473
20768
|
}
|
|
20474
20769
|
}
|
|
20475
20770
|
}
|
|
20476
|
-
catch (
|
|
20771
|
+
catch (e_48_1) { e_48 = { error: e_48_1 }; }
|
|
20477
20772
|
finally {
|
|
20478
20773
|
try {
|
|
20479
20774
|
if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
|
|
20480
20775
|
}
|
|
20481
|
-
finally { if (
|
|
20776
|
+
finally { if (e_48) throw e_48.error; }
|
|
20482
20777
|
}
|
|
20483
20778
|
return { set: set, map: map, size: routes.length };
|
|
20484
20779
|
}
|
|
20485
20780
|
function getClientRouteIndex() {
|
|
20486
20781
|
var _a;
|
|
20487
|
-
var routes = ((_a = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _a === void 0 ? void 0 : _a.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
20782
|
+
var routes = mergeAssistantHintValues(((_a = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _a === void 0 ? void 0 : _a.call(resolveio_server_app_1.ResolveIOServer)) || [], AI_ASSISTANT_CORE_PUBLIC_ROUTES);
|
|
20488
20783
|
if (cachedClientRouteIndex && cachedClientRouteIndex.size === routes.length) {
|
|
20489
20784
|
return cachedClientRouteIndex;
|
|
20490
20785
|
}
|
|
@@ -20645,6 +20940,7 @@ function collectAssistantAllowedRoutesForUser(user, allRoutes, isSuperAdmin) {
|
|
|
20645
20940
|
allowed.push(normalized);
|
|
20646
20941
|
};
|
|
20647
20942
|
var allRouteEntries = normalizedRoutes.map(function (route) { return ({ route: route }); });
|
|
20943
|
+
AI_ASSISTANT_CORE_PUBLIC_ROUTES.forEach(push);
|
|
20648
20944
|
views.forEach(function (view) {
|
|
20649
20945
|
var canonical = normalizedRoutes.find(function (route) { return normalizeRouteMatchKey(route) === normalizeRouteMatchKey(view); });
|
|
20650
20946
|
if (canonical) {
|
|
@@ -20668,6 +20964,79 @@ function resolveAssistantAllowedRoutesForUser(user, isSuperAdmin) {
|
|
|
20668
20964
|
var allRoutes = Array.from(index.map.values());
|
|
20669
20965
|
return collectAssistantAllowedRoutesForUser(user, allRoutes, isSuperAdmin);
|
|
20670
20966
|
}
|
|
20967
|
+
function scoreAssistantAppRouteIntent(messageText, intent) {
|
|
20968
|
+
var _a, _b;
|
|
20969
|
+
var text = normalizeOptionalString(messageText).toLowerCase();
|
|
20970
|
+
if (!text || !((_a = intent === null || intent === void 0 ? void 0 : intent.terms) === null || _a === void 0 ? void 0 : _a.length) || !((_b = intent === null || intent === void 0 ? void 0 : intent.routes) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
20971
|
+
return 0;
|
|
20972
|
+
}
|
|
20973
|
+
var excluded = (intent.excludeTerms || []).some(function (term) { return containsAssistantHeuristicTerm(text, term); });
|
|
20974
|
+
if (excluded) {
|
|
20975
|
+
return 0;
|
|
20976
|
+
}
|
|
20977
|
+
var score = 0;
|
|
20978
|
+
(intent.terms || []).forEach(function (term) {
|
|
20979
|
+
var normalizedTerm = normalizeOptionalString(term).toLowerCase();
|
|
20980
|
+
if (!normalizedTerm) {
|
|
20981
|
+
return;
|
|
20982
|
+
}
|
|
20983
|
+
if (containsAssistantHeuristicTerm(text, normalizedTerm)) {
|
|
20984
|
+
score += normalizedTerm.includes(' ') ? 26 : 14;
|
|
20985
|
+
return;
|
|
20986
|
+
}
|
|
20987
|
+
var key = normalizeCollectionKey(normalizedTerm);
|
|
20988
|
+
if (key && normalizeCollectionKey(text).includes(key) && key.length >= 5) {
|
|
20989
|
+
score += 10;
|
|
20990
|
+
}
|
|
20991
|
+
});
|
|
20992
|
+
return score;
|
|
20993
|
+
}
|
|
20994
|
+
function resolveAssistantAppRouteIntentMatch(params) {
|
|
20995
|
+
var allowedRoutes = mergeAssistantHintValues(params.allowedRoutes || []);
|
|
20996
|
+
if (!allowedRoutes.length) {
|
|
20997
|
+
return null;
|
|
20998
|
+
}
|
|
20999
|
+
var profile = resolveAssistantAppHeuristicProfile(params.appId);
|
|
21000
|
+
var routeIntents = Array.isArray(profile.routeIntents) ? profile.routeIntents : [];
|
|
21001
|
+
if (!routeIntents.length) {
|
|
21002
|
+
return null;
|
|
21003
|
+
}
|
|
21004
|
+
var selected = null;
|
|
21005
|
+
routeIntents.forEach(function (intent) {
|
|
21006
|
+
var score = scoreAssistantAppRouteIntent(params.message, intent);
|
|
21007
|
+
if (score < 14) {
|
|
21008
|
+
return;
|
|
21009
|
+
}
|
|
21010
|
+
var resolvedRoutes = mergeAssistantHintValues((intent.routes || [])
|
|
21011
|
+
.map(function (route) { return resolveAssistantBestAllowedRoute(route, allowedRoutes); })
|
|
21012
|
+
.filter(function (route) { return !!route; }));
|
|
21013
|
+
if (!resolvedRoutes.length) {
|
|
21014
|
+
return;
|
|
21015
|
+
}
|
|
21016
|
+
if (!selected || score > selected.score) {
|
|
21017
|
+
selected = {
|
|
21018
|
+
routes: resolvedRoutes.slice(0, 3),
|
|
21019
|
+
response: normalizeOptionalString(intent.response) || undefined,
|
|
21020
|
+
score: score
|
|
21021
|
+
};
|
|
21022
|
+
}
|
|
21023
|
+
});
|
|
21024
|
+
return selected ? {
|
|
21025
|
+
routes: selected.routes,
|
|
21026
|
+
response: selected.response
|
|
21027
|
+
} : null;
|
|
21028
|
+
}
|
|
21029
|
+
function formatAssistantNavigationRouteResponse(routes, singleIntro, multiIntro) {
|
|
21030
|
+
var normalizedRoutes = mergeAssistantHintValues(routes || []);
|
|
21031
|
+
var lines = [normalizedRoutes.length === 1 ? singleIntro : multiIntro];
|
|
21032
|
+
normalizedRoutes.forEach(function (route, index) {
|
|
21033
|
+
if (normalizedRoutes.length > 1) {
|
|
21034
|
+
lines.push("".concat(index + 1, ". ").concat(formatAssistantRouteLabel(route)));
|
|
21035
|
+
}
|
|
21036
|
+
lines.push(route);
|
|
21037
|
+
});
|
|
21038
|
+
return lines.join('\n');
|
|
21039
|
+
}
|
|
20671
21040
|
function rankAssistantNavigationRoutes(message, routes, limit) {
|
|
20672
21041
|
if (limit === void 0) { limit = 3; }
|
|
20673
21042
|
var normalizedMessage = normalizeOptionalString(message).toLowerCase();
|
|
@@ -20680,6 +21049,7 @@ function rankAssistantNavigationRoutes(message, routes, limit) {
|
|
|
20680
21049
|
}
|
|
20681
21050
|
var explicitRoutes = extractAssistantRouteMentions(normalizedMessage);
|
|
20682
21051
|
var queryTokens = tokenizeAssistantRouteQuery(normalizedMessage);
|
|
21052
|
+
var listIntent = /\b(list|listing|listings|directory|index|table|grid)\b/.test(normalizedMessage);
|
|
20683
21053
|
var scored = dedupedRoutes
|
|
20684
21054
|
.map(function (route) {
|
|
20685
21055
|
var routeKey = route.toLowerCase();
|
|
@@ -20702,8 +21072,11 @@ function rankAssistantNavigationRoutes(message, routes, limit) {
|
|
|
20702
21072
|
score += 7;
|
|
20703
21073
|
}
|
|
20704
21074
|
});
|
|
20705
|
-
if (
|
|
20706
|
-
score +=
|
|
21075
|
+
if (listIntent && routeTokens.includes('list')) {
|
|
21076
|
+
score += 20;
|
|
21077
|
+
}
|
|
21078
|
+
if (listIntent && routeTokens.some(function (token) { return token === 'new' || token === 'edit' || token === 'detail' || token === 'delete'; })) {
|
|
21079
|
+
score -= 8;
|
|
20707
21080
|
}
|
|
20708
21081
|
if (/\bdetail\b/.test(normalizedMessage) && routeTokens.includes('detail')) {
|
|
20709
21082
|
score += 8;
|
|
@@ -20731,6 +21104,19 @@ function rankAssistantNavigationRoutes(message, routes, limit) {
|
|
|
20731
21104
|
});
|
|
20732
21105
|
return scored.slice(0, limit).map(function (entry) { return entry.route; });
|
|
20733
21106
|
}
|
|
21107
|
+
function isAssistantContextDependentRouteLookup(message) {
|
|
21108
|
+
var text = normalizeOptionalString(message).toLowerCase();
|
|
21109
|
+
if (!text) {
|
|
21110
|
+
return false;
|
|
21111
|
+
}
|
|
21112
|
+
if (extractAssistantRouteMentions(text).length) {
|
|
21113
|
+
return false;
|
|
21114
|
+
}
|
|
21115
|
+
var hasContextReference = /\b(this|that|these|those|it|same)\b/.test(text);
|
|
21116
|
+
var hasReferencedSubject = /\b(info|information|data|result|results|records?|items?|dashboard|page|screen|view)\b/.test(text);
|
|
21117
|
+
var asksForNavigation = /\b(where|which|what|dashboard|page|screen|route|path|link|menu)\b/.test(text);
|
|
21118
|
+
return hasContextReference && hasReferencedSubject && asksForNavigation;
|
|
21119
|
+
}
|
|
20734
21120
|
function shouldUseAssistantNavigationFastPath(message, hasAttachments) {
|
|
20735
21121
|
if (hasAttachments === void 0) { hasAttachments = false; }
|
|
20736
21122
|
if (hasAttachments) {
|
|
@@ -20749,9 +21135,13 @@ function shouldUseAssistantNavigationFastPath(message, hasAttachments) {
|
|
|
20749
21135
|
if (!isAssistantRouteLookupQuestion(text)) {
|
|
20750
21136
|
return false;
|
|
20751
21137
|
}
|
|
21138
|
+
if (isAssistantContextDependentRouteLookup(text)) {
|
|
21139
|
+
return false;
|
|
21140
|
+
}
|
|
20752
21141
|
return !isAssistantStrongDataQuestion(text);
|
|
20753
21142
|
}
|
|
20754
21143
|
function evaluateAssistantNavigationFastPathWithRoutes(params) {
|
|
21144
|
+
var _a;
|
|
20755
21145
|
if (!shouldUseAssistantNavigationFastPath(params.message, params.hasAttachments)) {
|
|
20756
21146
|
return null;
|
|
20757
21147
|
}
|
|
@@ -20796,6 +21186,22 @@ function evaluateAssistantNavigationFastPathWithRoutes(params) {
|
|
|
20796
21186
|
reason: 'permission_denied'
|
|
20797
21187
|
};
|
|
20798
21188
|
}
|
|
21189
|
+
var appRouteIntent = resolveAssistantAppRouteIntentMatch({
|
|
21190
|
+
message: params.message,
|
|
21191
|
+
allowedRoutes: allowedRoutes,
|
|
21192
|
+
appId: params.appId
|
|
21193
|
+
});
|
|
21194
|
+
if ((_a = appRouteIntent === null || appRouteIntent === void 0 ? void 0 : appRouteIntent.routes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
21195
|
+
var routeText = formatAssistantNavigationRouteResponse(appRouteIntent.routes, 'Use this in-app route:', 'Use one of these in-app routes:');
|
|
21196
|
+
var response = appRouteIntent.response
|
|
21197
|
+
? "".concat(appRouteIntent.response, "\n").concat(routeText)
|
|
21198
|
+
: routeText;
|
|
21199
|
+
return {
|
|
21200
|
+
response: response,
|
|
21201
|
+
routes: appRouteIntent.routes,
|
|
21202
|
+
reason: 'app_route_intent'
|
|
21203
|
+
};
|
|
21204
|
+
}
|
|
20799
21205
|
var ranked = rankAssistantNavigationRoutes(params.message, allowedRoutes, 3);
|
|
20800
21206
|
if (!ranked.length) {
|
|
20801
21207
|
var contextRoute = normalizeRouteKey(params.contextRoute || '');
|
|
@@ -20828,7 +21234,8 @@ function resolveAssistantNavigationFastPathResponse(params) {
|
|
|
20828
21234
|
message: params.message,
|
|
20829
21235
|
hasAttachments: params.hasAttachments,
|
|
20830
21236
|
allowedRoutes: allowedRoutes,
|
|
20831
|
-
contextRoute: params.contextRoute
|
|
21237
|
+
contextRoute: params.contextRoute,
|
|
21238
|
+
appId: params.appId
|
|
20832
21239
|
});
|
|
20833
21240
|
}
|
|
20834
21241
|
var AI_ASSISTANT_CHANGE_HISTORY_PATTERNS = [
|
|
@@ -21257,8 +21664,8 @@ function shouldSkipAssistantGitDiscoveryDirectory(name) {
|
|
|
21257
21664
|
}
|
|
21258
21665
|
function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
21259
21666
|
return __awaiter(this, void 0, void 0, function () {
|
|
21260
|
-
var roots, seen, push, _a, configuredRoots, configuredRoots_1, configuredRoots_1_1, configuredRoot, _b,
|
|
21261
|
-
var
|
|
21667
|
+
var roots, seen, push, _a, configuredRoots, configuredRoots_1, configuredRoots_1_1, configuredRoot, _b, e_49_1, queue, queued, enqueue, next, entries, _c, entries_1, entries_1_1, entry, childName, candidate, gitPath, _d, e_50_1;
|
|
21668
|
+
var e_49, _e, e_50, _f;
|
|
21262
21669
|
var _g;
|
|
21263
21670
|
return __generator(this, function (_h) {
|
|
21264
21671
|
switch (_h.label) {
|
|
@@ -21303,14 +21710,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
21303
21710
|
return [3 /*break*/, 3];
|
|
21304
21711
|
case 6: return [3 /*break*/, 9];
|
|
21305
21712
|
case 7:
|
|
21306
|
-
|
|
21307
|
-
|
|
21713
|
+
e_49_1 = _h.sent();
|
|
21714
|
+
e_49 = { error: e_49_1 };
|
|
21308
21715
|
return [3 /*break*/, 9];
|
|
21309
21716
|
case 8:
|
|
21310
21717
|
try {
|
|
21311
21718
|
if (configuredRoots_1_1 && !configuredRoots_1_1.done && (_e = configuredRoots_1.return)) _e.call(configuredRoots_1);
|
|
21312
21719
|
}
|
|
21313
|
-
finally { if (
|
|
21720
|
+
finally { if (e_49) throw e_49.error; }
|
|
21314
21721
|
return [7 /*endfinally*/];
|
|
21315
21722
|
case 9:
|
|
21316
21723
|
queue = [];
|
|
@@ -21350,7 +21757,7 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
21350
21757
|
return [3 /*break*/, 14];
|
|
21351
21758
|
case 14:
|
|
21352
21759
|
_h.trys.push([14, 21, 22, 23]);
|
|
21353
|
-
entries_1 = (
|
|
21760
|
+
entries_1 = (e_50 = void 0, __values(entries)), entries_1_1 = entries_1.next();
|
|
21354
21761
|
_h.label = 15;
|
|
21355
21762
|
case 15:
|
|
21356
21763
|
if (!!entries_1_1.done) return [3 /*break*/, 20];
|
|
@@ -21389,14 +21796,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
21389
21796
|
return [3 /*break*/, 15];
|
|
21390
21797
|
case 20: return [3 /*break*/, 23];
|
|
21391
21798
|
case 21:
|
|
21392
|
-
|
|
21393
|
-
|
|
21799
|
+
e_50_1 = _h.sent();
|
|
21800
|
+
e_50 = { error: e_50_1 };
|
|
21394
21801
|
return [3 /*break*/, 23];
|
|
21395
21802
|
case 22:
|
|
21396
21803
|
try {
|
|
21397
21804
|
if (entries_1_1 && !entries_1_1.done && (_f = entries_1.return)) _f.call(entries_1);
|
|
21398
21805
|
}
|
|
21399
|
-
finally { if (
|
|
21806
|
+
finally { if (e_50) throw e_50.error; }
|
|
21400
21807
|
return [7 /*endfinally*/];
|
|
21401
21808
|
case 23: return [3 /*break*/, 10];
|
|
21402
21809
|
case 24: return [2 /*return*/, roots];
|
|
@@ -21736,8 +22143,8 @@ function syncAssistantGitMirror(repoUrl) {
|
|
|
21736
22143
|
}
|
|
21737
22144
|
function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
21738
22145
|
return __awaiter(this, void 0, void 0, function () {
|
|
21739
|
-
var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot,
|
|
21740
|
-
var
|
|
22146
|
+
var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot, e_51_1;
|
|
22147
|
+
var e_51, _a;
|
|
21741
22148
|
return __generator(this, function (_b) {
|
|
21742
22149
|
switch (_b.label) {
|
|
21743
22150
|
case 0: return [4 /*yield*/, resolveAssistantWorkspaceGitRoots(workspaceRoot)];
|
|
@@ -21771,14 +22178,14 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
|
21771
22178
|
return [3 /*break*/, 3];
|
|
21772
22179
|
case 6: return [3 /*break*/, 9];
|
|
21773
22180
|
case 7:
|
|
21774
|
-
|
|
21775
|
-
|
|
22181
|
+
e_51_1 = _b.sent();
|
|
22182
|
+
e_51 = { error: e_51_1 };
|
|
21776
22183
|
return [3 /*break*/, 9];
|
|
21777
22184
|
case 8:
|
|
21778
22185
|
try {
|
|
21779
22186
|
if (repoUrls_1_1 && !repoUrls_1_1.done && (_a = repoUrls_1.return)) _a.call(repoUrls_1);
|
|
21780
22187
|
}
|
|
21781
|
-
finally { if (
|
|
22188
|
+
finally { if (e_51) throw e_51.error; }
|
|
21782
22189
|
return [7 /*endfinally*/];
|
|
21783
22190
|
case 9: return [2 /*return*/, mirroredRoots];
|
|
21784
22191
|
}
|
|
@@ -21787,8 +22194,8 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
|
21787
22194
|
}
|
|
21788
22195
|
function resolveAssistantChangeHistoryFastPathResponse(params) {
|
|
21789
22196
|
return __awaiter(this, void 0, void 0, function () {
|
|
21790
|
-
var workspaceRoot, _a, gitRoots, featureKeywords, sawExecutionError, bestFallback, gitRoots_1, gitRoots_1_1, gitRoot, _b, branch, _c, _d, limit, historyDepth, rawHistory, commits, summary, hasKeywordMatches, _e,
|
|
21791
|
-
var
|
|
22197
|
+
var workspaceRoot, _a, gitRoots, featureKeywords, sawExecutionError, bestFallback, gitRoots_1, gitRoots_1_1, gitRoot, _b, branch, _c, _d, limit, historyDepth, rawHistory, commits, summary, hasKeywordMatches, _e, e_52_1;
|
|
22198
|
+
var e_52, _f;
|
|
21792
22199
|
return __generator(this, function (_g) {
|
|
21793
22200
|
switch (_g.label) {
|
|
21794
22201
|
case 0:
|
|
@@ -21910,14 +22317,14 @@ function resolveAssistantChangeHistoryFastPathResponse(params) {
|
|
|
21910
22317
|
return [3 /*break*/, 7];
|
|
21911
22318
|
case 20: return [3 /*break*/, 23];
|
|
21912
22319
|
case 21:
|
|
21913
|
-
|
|
21914
|
-
|
|
22320
|
+
e_52_1 = _g.sent();
|
|
22321
|
+
e_52 = { error: e_52_1 };
|
|
21915
22322
|
return [3 /*break*/, 23];
|
|
21916
22323
|
case 22:
|
|
21917
22324
|
try {
|
|
21918
22325
|
if (gitRoots_1_1 && !gitRoots_1_1.done && (_f = gitRoots_1.return)) _f.call(gitRoots_1);
|
|
21919
22326
|
}
|
|
21920
|
-
finally { if (
|
|
22327
|
+
finally { if (e_52) throw e_52.error; }
|
|
21921
22328
|
return [7 /*endfinally*/];
|
|
21922
22329
|
case 23:
|
|
21923
22330
|
if (bestFallback) {
|
|
@@ -22098,7 +22505,7 @@ function sanitizeAssistantResponse(value) {
|
|
|
22098
22505
|
return normalizeAssistantRoutes(normalizedCurrency);
|
|
22099
22506
|
}
|
|
22100
22507
|
function evaluateAssistantGuardrails(message) {
|
|
22101
|
-
var
|
|
22508
|
+
var e_53, _a;
|
|
22102
22509
|
var normalized = String(message || '').toLowerCase();
|
|
22103
22510
|
var identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(normalized);
|
|
22104
22511
|
if (identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked) {
|
|
@@ -22143,12 +22550,12 @@ function evaluateAssistantGuardrails(message) {
|
|
|
22143
22550
|
}
|
|
22144
22551
|
}
|
|
22145
22552
|
}
|
|
22146
|
-
catch (
|
|
22553
|
+
catch (e_53_1) { e_53 = { error: e_53_1 }; }
|
|
22147
22554
|
finally {
|
|
22148
22555
|
try {
|
|
22149
22556
|
if (patterns_2_1 && !patterns_2_1.done && (_a = patterns_2.return)) _a.call(patterns_2);
|
|
22150
22557
|
}
|
|
22151
|
-
finally { if (
|
|
22558
|
+
finally { if (e_53) throw e_53.error; }
|
|
22152
22559
|
}
|
|
22153
22560
|
return null;
|
|
22154
22561
|
}
|
|
@@ -22253,7 +22660,7 @@ function tokenizeArithmeticExpression(expression) {
|
|
|
22253
22660
|
return tokens;
|
|
22254
22661
|
}
|
|
22255
22662
|
function evaluateArithmeticExpression(expression) {
|
|
22256
|
-
var
|
|
22663
|
+
var e_54, _a, e_55, _b;
|
|
22257
22664
|
var tokens = tokenizeArithmeticExpression(expression);
|
|
22258
22665
|
if (!tokens || !tokens.length) {
|
|
22259
22666
|
return null;
|
|
@@ -22310,12 +22717,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
22310
22717
|
prevToken = token;
|
|
22311
22718
|
}
|
|
22312
22719
|
}
|
|
22313
|
-
catch (
|
|
22720
|
+
catch (e_54_1) { e_54 = { error: e_54_1 }; }
|
|
22314
22721
|
finally {
|
|
22315
22722
|
try {
|
|
22316
22723
|
if (tokens_2_1 && !tokens_2_1.done && (_a = tokens_2.return)) _a.call(tokens_2);
|
|
22317
22724
|
}
|
|
22318
|
-
finally { if (
|
|
22725
|
+
finally { if (e_54) throw e_54.error; }
|
|
22319
22726
|
}
|
|
22320
22727
|
while (ops.length) {
|
|
22321
22728
|
var op = ops.pop();
|
|
@@ -22355,12 +22762,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
22355
22762
|
stack.push(Number(token));
|
|
22356
22763
|
}
|
|
22357
22764
|
}
|
|
22358
|
-
catch (
|
|
22765
|
+
catch (e_55_1) { e_55 = { error: e_55_1 }; }
|
|
22359
22766
|
finally {
|
|
22360
22767
|
try {
|
|
22361
22768
|
if (output_1_1 && !output_1_1.done && (_b = output_1.return)) _b.call(output_1);
|
|
22362
22769
|
}
|
|
22363
|
-
finally { if (
|
|
22770
|
+
finally { if (e_55) throw e_55.error; }
|
|
22364
22771
|
}
|
|
22365
22772
|
if (stack.length !== 1 || Number.isNaN(stack[0])) {
|
|
22366
22773
|
return null;
|
|
@@ -22544,8 +22951,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
|
|
|
22544
22951
|
}
|
|
22545
22952
|
function readAttachmentContents(attachments) {
|
|
22546
22953
|
return __awaiter(this, void 0, void 0, function () {
|
|
22547
|
-
var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a,
|
|
22548
|
-
var
|
|
22954
|
+
var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_56_1;
|
|
22955
|
+
var e_56, _b;
|
|
22549
22956
|
return __generator(this, function (_c) {
|
|
22550
22957
|
switch (_c.label) {
|
|
22551
22958
|
case 0:
|
|
@@ -22624,14 +23031,14 @@ function readAttachmentContents(attachments) {
|
|
|
22624
23031
|
return [3 /*break*/, 2];
|
|
22625
23032
|
case 10: return [3 /*break*/, 13];
|
|
22626
23033
|
case 11:
|
|
22627
|
-
|
|
22628
|
-
|
|
23034
|
+
e_56_1 = _c.sent();
|
|
23035
|
+
e_56 = { error: e_56_1 };
|
|
22629
23036
|
return [3 /*break*/, 13];
|
|
22630
23037
|
case 12:
|
|
22631
23038
|
try {
|
|
22632
23039
|
if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
|
|
22633
23040
|
}
|
|
22634
|
-
finally { if (
|
|
23041
|
+
finally { if (e_56) throw e_56.error; }
|
|
22635
23042
|
return [7 /*endfinally*/];
|
|
22636
23043
|
case 13: return [2 /*return*/, {
|
|
22637
23044
|
promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
|
|
@@ -22710,6 +23117,7 @@ function sanitizeConfig(source) {
|
|
|
22710
23117
|
.map(function (entry) { return normalizeOptionalString(entry); })
|
|
22711
23118
|
.filter(Boolean),
|
|
22712
23119
|
system_prompt: normalizeOptionalString(source === null || source === void 0 ? void 0 : source.system_prompt),
|
|
23120
|
+
system_prompt_additions: resolveAssistantSystemPromptAdditions(source),
|
|
22713
23121
|
user_prompt_template: normalizeOptionalString(source === null || source === void 0 ? void 0 : source.user_prompt_template),
|
|
22714
23122
|
response_format: normalizeOptionalString(source === null || source === void 0 ? void 0 : source.response_format),
|
|
22715
23123
|
temperature: normalizeOptionalNumber(source === null || source === void 0 ? void 0 : source.temperature),
|
|
@@ -22841,7 +23249,7 @@ function resolveAssistantDatabaseNameForSystemCollections() {
|
|
|
22841
23249
|
}
|
|
22842
23250
|
function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
22843
23251
|
return __awaiter(this, void 0, void 0, function () {
|
|
22844
|
-
var safeSetPayload, fallbackId, debugEnabled, result,
|
|
23252
|
+
var safeSetPayload, fallbackId, debugEnabled, result, error_17, dbName, messagesCollection, result, _a, retryResult;
|
|
22845
23253
|
var _b, _c, _d, _e, _f, _g;
|
|
22846
23254
|
return __generator(this, function (_h) {
|
|
22847
23255
|
switch (_h.label) {
|
|
@@ -22880,14 +23288,14 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
22880
23288
|
}
|
|
22881
23289
|
return [2 /*return*/];
|
|
22882
23290
|
case 5:
|
|
22883
|
-
|
|
22884
|
-
if (!isAssistantTransactionCommittedError(
|
|
22885
|
-
throw
|
|
23291
|
+
error_17 = _h.sent();
|
|
23292
|
+
if (!isAssistantTransactionCommittedError(error_17)) {
|
|
23293
|
+
throw error_17;
|
|
22886
23294
|
}
|
|
22887
23295
|
if (debugEnabled) {
|
|
22888
23296
|
console.log(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update fallback triggered', {
|
|
22889
23297
|
messageId: fallbackId || messageId,
|
|
22890
|
-
reason: normalizeOptionalString(
|
|
23298
|
+
reason: normalizeOptionalString(error_17 === null || error_17 === void 0 ? void 0 : error_17.message) || 'transaction_committed'
|
|
22891
23299
|
});
|
|
22892
23300
|
}
|
|
22893
23301
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
@@ -22963,7 +23371,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
22963
23371
|
}
|
|
22964
23372
|
function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
22965
23373
|
return __awaiter(this, void 0, void 0, function () {
|
|
22966
|
-
var update, result,
|
|
23374
|
+
var update, result, error_18, dbName, conversationsCollection, fallbackResult;
|
|
22967
23375
|
return __generator(this, function (_a) {
|
|
22968
23376
|
switch (_a.label) {
|
|
22969
23377
|
case 0:
|
|
@@ -22988,9 +23396,9 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
22988
23396
|
}
|
|
22989
23397
|
return [2 /*return*/];
|
|
22990
23398
|
case 3:
|
|
22991
|
-
|
|
22992
|
-
if (!isAssistantTransactionCommittedError(
|
|
22993
|
-
throw
|
|
23399
|
+
error_18 = _a.sent();
|
|
23400
|
+
if (!isAssistantTransactionCommittedError(error_18)) {
|
|
23401
|
+
throw error_18;
|
|
22994
23402
|
}
|
|
22995
23403
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
22996
23404
|
conversationsCollection = resolveio_server_app_1.ResolveIOServer.getMongoConnection()
|
|
@@ -23055,7 +23463,7 @@ function sanitizeAssistantMessageSetPayload(setPayload) {
|
|
|
23055
23463
|
return next;
|
|
23056
23464
|
}
|
|
23057
23465
|
function sanitizeMongoSafeObject(value) {
|
|
23058
|
-
var
|
|
23466
|
+
var e_57, _a;
|
|
23059
23467
|
if (value === null || value === undefined) {
|
|
23060
23468
|
return value;
|
|
23061
23469
|
}
|
|
@@ -23079,17 +23487,17 @@ function sanitizeMongoSafeObject(value) {
|
|
|
23079
23487
|
out[key] = sanitizeMongoSafeObject(rawValue);
|
|
23080
23488
|
}
|
|
23081
23489
|
}
|
|
23082
|
-
catch (
|
|
23490
|
+
catch (e_57_1) { e_57 = { error: e_57_1 }; }
|
|
23083
23491
|
finally {
|
|
23084
23492
|
try {
|
|
23085
23493
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
23086
23494
|
}
|
|
23087
|
-
finally { if (
|
|
23495
|
+
finally { if (e_57) throw e_57.error; }
|
|
23088
23496
|
}
|
|
23089
23497
|
return out;
|
|
23090
23498
|
}
|
|
23091
23499
|
function restoreMongoSafeObject(value) {
|
|
23092
|
-
var
|
|
23500
|
+
var e_58, _a;
|
|
23093
23501
|
if (value === null || value === undefined) {
|
|
23094
23502
|
return value;
|
|
23095
23503
|
}
|
|
@@ -23113,12 +23521,12 @@ function restoreMongoSafeObject(value) {
|
|
|
23113
23521
|
out[key] = restoreMongoSafeObject(rawValue);
|
|
23114
23522
|
}
|
|
23115
23523
|
}
|
|
23116
|
-
catch (
|
|
23524
|
+
catch (e_58_1) { e_58 = { error: e_58_1 }; }
|
|
23117
23525
|
finally {
|
|
23118
23526
|
try {
|
|
23119
23527
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
23120
23528
|
}
|
|
23121
|
-
finally { if (
|
|
23529
|
+
finally { if (e_58) throw e_58.error; }
|
|
23122
23530
|
}
|
|
23123
23531
|
return out;
|
|
23124
23532
|
}
|
|
@@ -23262,7 +23670,7 @@ function buildAssistantAIRunId(prefix, parts) {
|
|
|
23262
23670
|
}
|
|
23263
23671
|
function recordAssistantAnswerAIRun(input) {
|
|
23264
23672
|
return __awaiter(this, void 0, void 0, function () {
|
|
23265
|
-
var messages, run,
|
|
23673
|
+
var messages, run, error_19;
|
|
23266
23674
|
return __generator(this, function (_a) {
|
|
23267
23675
|
switch (_a.label) {
|
|
23268
23676
|
case 0:
|
|
@@ -23287,8 +23695,8 @@ function recordAssistantAnswerAIRun(input) {
|
|
|
23287
23695
|
_a.sent();
|
|
23288
23696
|
return [3 /*break*/, 3];
|
|
23289
23697
|
case 2:
|
|
23290
|
-
|
|
23291
|
-
console.error(new Date(), 'Failed to record AI assistant AIRun evidence',
|
|
23698
|
+
error_19 = _a.sent();
|
|
23699
|
+
console.error(new Date(), 'Failed to record AI assistant AIRun evidence', error_19);
|
|
23292
23700
|
return [3 /*break*/, 3];
|
|
23293
23701
|
case 3: return [2 /*return*/];
|
|
23294
23702
|
}
|
|
@@ -23296,7 +23704,7 @@ function recordAssistantAnswerAIRun(input) {
|
|
|
23296
23704
|
});
|
|
23297
23705
|
}
|
|
23298
23706
|
function evaluateGuardrails(message) {
|
|
23299
|
-
var
|
|
23707
|
+
var e_59, _a;
|
|
23300
23708
|
var normalized = String(message || '').toLowerCase();
|
|
23301
23709
|
var identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(normalized);
|
|
23302
23710
|
if (identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked) {
|
|
@@ -23322,12 +23730,12 @@ function evaluateGuardrails(message) {
|
|
|
23322
23730
|
}
|
|
23323
23731
|
}
|
|
23324
23732
|
}
|
|
23325
|
-
catch (
|
|
23733
|
+
catch (e_59_1) { e_59 = { error: e_59_1 }; }
|
|
23326
23734
|
finally {
|
|
23327
23735
|
try {
|
|
23328
23736
|
if (patterns_3_1 && !patterns_3_1.done && (_a = patterns_3.return)) _a.call(patterns_3);
|
|
23329
23737
|
}
|
|
23330
|
-
finally { if (
|
|
23738
|
+
finally { if (e_59) throw e_59.error; }
|
|
23331
23739
|
}
|
|
23332
23740
|
return null;
|
|
23333
23741
|
}
|