@resolveio/server-lib 22.3.199 → 22.3.200
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 +975 -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,101 @@ 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 (/\bthis\s+week\b/.test(text)) {
|
|
6983
|
+
var start = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 0, 0, 0, 0));
|
|
6984
|
+
var day = start.getUTCDay();
|
|
6985
|
+
var offset = day === 0 ? 6 : day - 1;
|
|
6986
|
+
start.setUTCDate(start.getUTCDate() - offset);
|
|
6987
|
+
return {
|
|
6988
|
+
start: start.toISOString(),
|
|
6989
|
+
end: new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 23, 59, 59, 999)).toISOString(),
|
|
6990
|
+
year: now.getUTCFullYear()
|
|
6991
|
+
};
|
|
6992
|
+
}
|
|
6962
6993
|
if (!/\b(this\s+year|ytd|year\s+to\s+date|current\s+year)\b/.test(text)) {
|
|
6963
6994
|
return {};
|
|
6964
6995
|
}
|
|
6965
|
-
var now = new Date();
|
|
6966
6996
|
var year = now.getUTCFullYear();
|
|
6967
6997
|
return {
|
|
6968
6998
|
start: new Date(Date.UTC(year, 0, 1, 0, 0, 0, 0)).toISOString(),
|
|
@@ -6970,19 +7000,21 @@ function resolveAssistantDataIntentDateWindow(message) {
|
|
|
6970
7000
|
year: year
|
|
6971
7001
|
};
|
|
6972
7002
|
}
|
|
7003
|
+
function applyAssistantDataIntentTextTemplate(value, params) {
|
|
7004
|
+
return String(value || '')
|
|
7005
|
+
.replace(/\{\{customer\}\}/g, params.customerText)
|
|
7006
|
+
.replace(/\{\{year\}\}/g, params.dateWindow.year ? String(params.dateWindow.year) : '')
|
|
7007
|
+
.replace(/\{\{date_start\}\}/g, params.dateWindow.start || '')
|
|
7008
|
+
.replace(/\{\{date_end\}\}/g, params.dateWindow.end || '');
|
|
7009
|
+
}
|
|
6973
7010
|
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.");
|
|
7011
|
+
var template = normalizeOptionalString(intent.acknowledgement);
|
|
7012
|
+
if (template) {
|
|
7013
|
+
return applyAssistantDataIntentTextTemplate(template, { customerText: customerText, dateWindow: dateWindow }).trim();
|
|
6984
7014
|
}
|
|
6985
|
-
|
|
7015
|
+
var yearText = dateWindow.year ? " for ".concat(dateWindow.year) : '';
|
|
7016
|
+
var target = customerText ? " for ".concat(customerText) : '';
|
|
7017
|
+
return "I understand the data you want".concat(target).concat(yearText, ". Let me pull the matching records for you.");
|
|
6986
7018
|
}
|
|
6987
7019
|
function buildAssistantDataIntentMatchStage(customerText, dateField, dateWindow, customerPaths) {
|
|
6988
7020
|
var _a;
|
|
@@ -7010,6 +7042,98 @@ function buildAssistantDataIntentMatchStage(customerText, dateField, dateWindow,
|
|
|
7010
7042
|
}
|
|
7011
7043
|
return and.length ? { $match: { $and: and } } : { $match: {} };
|
|
7012
7044
|
}
|
|
7045
|
+
function applyAssistantDataIntentPipelineTemplate(value, params) {
|
|
7046
|
+
if (Array.isArray(value)) {
|
|
7047
|
+
return value.map(function (entry) { return applyAssistantDataIntentPipelineTemplate(entry, params); });
|
|
7048
|
+
}
|
|
7049
|
+
if (value && typeof value === 'object') {
|
|
7050
|
+
return Object.keys(value).reduce(function (acc, key) {
|
|
7051
|
+
acc[key] = applyAssistantDataIntentPipelineTemplate(value[key], params);
|
|
7052
|
+
return acc;
|
|
7053
|
+
}, {});
|
|
7054
|
+
}
|
|
7055
|
+
if (typeof value !== 'string') {
|
|
7056
|
+
return value;
|
|
7057
|
+
}
|
|
7058
|
+
if (value === '{{date_start}}') {
|
|
7059
|
+
return params.dateWindow.start ? new Date(params.dateWindow.start) : undefined;
|
|
7060
|
+
}
|
|
7061
|
+
if (value === '{{date_end}}') {
|
|
7062
|
+
return params.dateWindow.end ? new Date(params.dateWindow.end) : undefined;
|
|
7063
|
+
}
|
|
7064
|
+
if (value === '{{year}}') {
|
|
7065
|
+
return params.dateWindow.year || '';
|
|
7066
|
+
}
|
|
7067
|
+
if (value === '{{customer}}') {
|
|
7068
|
+
return params.customerText;
|
|
7069
|
+
}
|
|
7070
|
+
return applyAssistantDataIntentTextTemplate(value, params);
|
|
7071
|
+
}
|
|
7072
|
+
function isAssistantEmptyPipelineObject(value) {
|
|
7073
|
+
return !!value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length;
|
|
7074
|
+
}
|
|
7075
|
+
function removeUndefinedAssistantPipelineValues(value, parentKey) {
|
|
7076
|
+
if (parentKey === void 0) { parentKey = ''; }
|
|
7077
|
+
if (Array.isArray(value)) {
|
|
7078
|
+
return value
|
|
7079
|
+
.map(function (entry) { return removeUndefinedAssistantPipelineValues(entry, parentKey); })
|
|
7080
|
+
.filter(function (entry) { return entry !== undefined; });
|
|
7081
|
+
}
|
|
7082
|
+
if (value && typeof value === 'object') {
|
|
7083
|
+
var cleaned = Object.keys(value).reduce(function (acc, key) {
|
|
7084
|
+
var nextValue = removeUndefinedAssistantPipelineValues(value[key], key);
|
|
7085
|
+
if (nextValue !== undefined) {
|
|
7086
|
+
acc[key] = nextValue;
|
|
7087
|
+
}
|
|
7088
|
+
return acc;
|
|
7089
|
+
}, {});
|
|
7090
|
+
if (isAssistantEmptyPipelineObject(cleaned) && parentKey && !parentKey.startsWith('$')) {
|
|
7091
|
+
return undefined;
|
|
7092
|
+
}
|
|
7093
|
+
return cleaned;
|
|
7094
|
+
}
|
|
7095
|
+
return value;
|
|
7096
|
+
}
|
|
7097
|
+
function buildAssistantConfiguredDataIntentPipeline(intent, customerText, dateWindow) {
|
|
7098
|
+
if (!Array.isArray(intent.pipeline) || !intent.pipeline.length) {
|
|
7099
|
+
return [];
|
|
7100
|
+
}
|
|
7101
|
+
return removeUndefinedAssistantPipelineValues(applyAssistantDataIntentPipelineTemplate(intent.pipeline, {
|
|
7102
|
+
customerText: customerText,
|
|
7103
|
+
dateWindow: dateWindow
|
|
7104
|
+
}));
|
|
7105
|
+
}
|
|
7106
|
+
function buildAssistantGenericDataIntentPipeline(intent, customerText, dateWindow) {
|
|
7107
|
+
var _a;
|
|
7108
|
+
var pipeline = [
|
|
7109
|
+
buildAssistantDataIntentMatchStage(customerText, intent.dateField, dateWindow, ['customer', 'job.customer', 'jca.customer'])
|
|
7110
|
+
];
|
|
7111
|
+
var quantityField = normalizeOptionalString(intent.quantityField || intent.metricField);
|
|
7112
|
+
if (!quantityField) {
|
|
7113
|
+
pipeline.push({ $limit: 20 });
|
|
7114
|
+
return pipeline;
|
|
7115
|
+
}
|
|
7116
|
+
var firstPath = quantityField.split('.')[0];
|
|
7117
|
+
if (firstPath && quantityField.includes('.')) {
|
|
7118
|
+
pipeline.push({ $unwind: "$".concat(firstPath) });
|
|
7119
|
+
pipeline.push({ $match: (_a = {}, _a[quantityField] = { $gt: 0 }, _a) });
|
|
7120
|
+
}
|
|
7121
|
+
pipeline.push({
|
|
7122
|
+
$group: {
|
|
7123
|
+
_id: null,
|
|
7124
|
+
total_quantity: { $sum: "$".concat(quantityField) },
|
|
7125
|
+
row_count: { $sum: 1 }
|
|
7126
|
+
}
|
|
7127
|
+
});
|
|
7128
|
+
pipeline.push({
|
|
7129
|
+
$project: {
|
|
7130
|
+
_id: 0,
|
|
7131
|
+
total_quantity: 1,
|
|
7132
|
+
row_count: 1
|
|
7133
|
+
}
|
|
7134
|
+
});
|
|
7135
|
+
return pipeline;
|
|
7136
|
+
}
|
|
7013
7137
|
function buildAssistantAppDataIntentDirective(message, collectionNames, appId) {
|
|
7014
7138
|
if (collectionNames === void 0) { collectionNames = []; }
|
|
7015
7139
|
var intent = selectAssistantAppDataIntent(message, collectionNames, appId);
|
|
@@ -7030,113 +7154,21 @@ function buildAssistantAppDataIntentDirective(message, collectionNames, appId) {
|
|
|
7030
7154
|
acknowledgementText: acknowledgementText,
|
|
7031
7155
|
progress: progress,
|
|
7032
7156
|
assumptions: intent.assumptions,
|
|
7033
|
-
fallbackCollections: intent.fallbackCollections
|
|
7157
|
+
fallbackCollections: intent.fallbackCollections,
|
|
7158
|
+
customerText: customerText,
|
|
7159
|
+
dateWindow: dateWindow
|
|
7034
7160
|
};
|
|
7035
7161
|
var basePayload = function (pipeline) { return ({
|
|
7036
7162
|
collection: intent.collection,
|
|
7037
7163
|
permissionView: intent.permissionView || resolveDefaultAssistantPermissionView(intent.collection),
|
|
7038
7164
|
pipeline: pipeline,
|
|
7039
|
-
options: {
|
|
7040
|
-
allowDiskUse: true,
|
|
7041
|
-
limit: 20
|
|
7042
|
-
}
|
|
7165
|
+
options: __assign(__assign({ disableNoDataFallbacks: true }, (intent.options || {})), { allowDiskUse: true, limit: 20 })
|
|
7043
7166
|
}); };
|
|
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;
|
|
7167
|
+
var configuredPipeline = buildAssistantConfiguredDataIntentPipeline(intent, customerText, dateWindow);
|
|
7168
|
+
var pipeline = configuredPipeline.length
|
|
7169
|
+
? configuredPipeline
|
|
7170
|
+
: buildAssistantGenericDataIntentPipeline(intent, customerText, dateWindow);
|
|
7171
|
+
return { type: 'aggregate', payload: basePayload(pipeline), cleaned: '', rawLine: "HEURISTIC_AGG(app-data-intent:".concat(intent.id, ")"), metadata: metadata };
|
|
7140
7172
|
}
|
|
7141
7173
|
function isAssistantDeterministicHeuristicDirective(directive) {
|
|
7142
7174
|
return isAssistantSchemaHoursHeuristicDirective(directive)
|
|
@@ -7841,7 +7873,7 @@ function buildAssistantToolResultPayload(directive, toolResponse, requestMessage
|
|
|
7841
7873
|
? toolResponse.verification
|
|
7842
7874
|
: undefined;
|
|
7843
7875
|
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 } : {}));
|
|
7876
|
+
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
7877
|
var result = {
|
|
7846
7878
|
type: directive.type === 'aggregate' ? 'mongo_agg' : 'mongo_read',
|
|
7847
7879
|
input: directivePayload,
|
|
@@ -8033,21 +8065,46 @@ function buildAssistantDisplayLeadSummary(display) {
|
|
|
8033
8065
|
? "First row: ".concat(details.join(', '), ".")
|
|
8034
8066
|
: "Result: ".concat(details.join(', '), ".");
|
|
8035
8067
|
}
|
|
8068
|
+
function formatAssistantEvidenceDate(value) {
|
|
8069
|
+
var normalized = normalizeOptionalString(value);
|
|
8070
|
+
if (!normalized) {
|
|
8071
|
+
return '';
|
|
8072
|
+
}
|
|
8073
|
+
var date = new Date(normalized);
|
|
8074
|
+
if (!Number.isNaN(date.getTime())) {
|
|
8075
|
+
return date.toISOString().slice(0, 10);
|
|
8076
|
+
}
|
|
8077
|
+
return normalized.slice(0, 10);
|
|
8078
|
+
}
|
|
8036
8079
|
function buildAssistantToolFallbackResponse(result) {
|
|
8037
8080
|
var _a, _b;
|
|
8038
8081
|
var rowCount = Math.max(0, Number(result.output.rowCount || 0));
|
|
8039
8082
|
var source = normalizeOptionalString(result.output.collection);
|
|
8040
8083
|
var debug = result.output.debug && typeof result.output.debug === 'object' ? result.output.debug : {};
|
|
8041
8084
|
var intentId = normalizeOptionalString(debug.intentId);
|
|
8085
|
+
var customerText = normalizeOptionalString(debug.customerText);
|
|
8086
|
+
var dateWindow = debug.dateWindow && typeof debug.dateWindow === 'object'
|
|
8087
|
+
? debug.dateWindow
|
|
8088
|
+
: {};
|
|
8089
|
+
var dateStart = formatAssistantEvidenceDate(dateWindow.start);
|
|
8090
|
+
var dateEnd = formatAssistantEvidenceDate(dateWindow.end);
|
|
8091
|
+
var targetText = customerText ? " for ".concat(customerText) : '';
|
|
8092
|
+
var dateText = dateStart || dateEnd ? " from ".concat(dateStart || 'the beginning', " through ").concat(dateEnd || 'the end') : '';
|
|
8042
8093
|
var lines = rowCount > 0
|
|
8043
|
-
? ["I found ".concat(rowCount === 1 ? '1 matching row' : "".concat(rowCount, " matching rows")).concat(source ? " from ".concat(source) : '', ".")]
|
|
8094
|
+
? ["I found ".concat(rowCount === 1 ? '1 matching row' : "".concat(rowCount, " matching rows")).concat(source ? " from ".concat(source) : '').concat(targetText).concat(dateText, ".")]
|
|
8044
8095
|
: [intentId
|
|
8045
|
-
? "I checked the ".concat(source || 'selected', " data
|
|
8096
|
+
? "I checked the ".concat(source || 'selected', " data").concat(targetText).concat(dateText, ", but I did not find matching rows for those filters.")
|
|
8046
8097
|
: "I checked the data".concat(source ? " in ".concat(source) : '', ", but no matching rows were returned.")];
|
|
8047
8098
|
if (source) {
|
|
8048
8099
|
lines.push("- Source: ".concat(source));
|
|
8049
8100
|
}
|
|
8050
8101
|
lines.push("- Rows returned: ".concat(rowCount));
|
|
8102
|
+
if (customerText) {
|
|
8103
|
+
lines.push("- Filter: ".concat(customerText));
|
|
8104
|
+
}
|
|
8105
|
+
if (dateStart || dateEnd) {
|
|
8106
|
+
lines.push("- Date window: ".concat(dateStart || 'open', " to ").concat(dateEnd || 'open'));
|
|
8107
|
+
}
|
|
8051
8108
|
if (typeof result.output.total === 'number') {
|
|
8052
8109
|
lines.push("- Total: ".concat(result.output.total));
|
|
8053
8110
|
}
|
|
@@ -8058,14 +8115,6 @@ function buildAssistantToolFallbackResponse(result) {
|
|
|
8058
8115
|
if (assumptions.length) {
|
|
8059
8116
|
lines.push("- Assumptions: ".concat(assumptions.slice(0, 3).join('; ')));
|
|
8060
8117
|
}
|
|
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
8118
|
}
|
|
8070
8119
|
var leadSummary = buildAssistantDisplayLeadSummary(result.output.display);
|
|
8071
8120
|
if (leadSummary) {
|
|
@@ -8581,10 +8630,10 @@ function deriveAssistantStreamStatus(event) {
|
|
|
8581
8630
|
return null;
|
|
8582
8631
|
}
|
|
8583
8632
|
if (event.type === 'thread.started' || event.type === 'turn.started') {
|
|
8584
|
-
return
|
|
8633
|
+
return AI_ASSISTANT_PROGRESS_CONTEXT;
|
|
8585
8634
|
}
|
|
8586
8635
|
if (event.type === 'turn.completed') {
|
|
8587
|
-
return
|
|
8636
|
+
return AI_ASSISTANT_PROGRESS_DRAFT;
|
|
8588
8637
|
}
|
|
8589
8638
|
if (event.type === 'item.started' || event.type === 'item.updated' || event.type === 'item.completed') {
|
|
8590
8639
|
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 +8641,7 @@ function deriveAssistantStreamStatus(event) {
|
|
|
8592
8641
|
return null;
|
|
8593
8642
|
}
|
|
8594
8643
|
if (itemType === 'mcp_tool_call') {
|
|
8595
|
-
return
|
|
8644
|
+
return AI_ASSISTANT_PROGRESS_NAVIGATION;
|
|
8596
8645
|
}
|
|
8597
8646
|
if (itemType === 'command_execution') {
|
|
8598
8647
|
return deriveAssistantCommandExecutionStatus((_b = event === null || event === void 0 ? void 0 : event.item) === null || _b === void 0 ? void 0 : _b.command);
|
|
@@ -8601,13 +8650,13 @@ function deriveAssistantStreamStatus(event) {
|
|
|
8601
8650
|
return 'Searching references';
|
|
8602
8651
|
}
|
|
8603
8652
|
if (itemType === 'file_change') {
|
|
8604
|
-
return
|
|
8653
|
+
return AI_ASSISTANT_PROGRESS_DRAFT;
|
|
8605
8654
|
}
|
|
8606
8655
|
if (itemType === 'agent_message') {
|
|
8607
|
-
return
|
|
8656
|
+
return AI_ASSISTANT_PROGRESS_DRAFT;
|
|
8608
8657
|
}
|
|
8609
8658
|
if (itemType === 'reasoning') {
|
|
8610
|
-
return
|
|
8659
|
+
return AI_ASSISTANT_PROGRESS_CONTEXT;
|
|
8611
8660
|
}
|
|
8612
8661
|
}
|
|
8613
8662
|
return null;
|
|
@@ -8620,13 +8669,13 @@ function normalizeAssistantStreamProgressStatus(status, dataMode) {
|
|
|
8620
8669
|
}
|
|
8621
8670
|
var normalized = trimmed.toLowerCase();
|
|
8622
8671
|
if (normalized === 'planning') {
|
|
8623
|
-
return
|
|
8672
|
+
return AI_ASSISTANT_PROGRESS_CONTEXT;
|
|
8624
8673
|
}
|
|
8625
8674
|
if (normalized === 'drafting response') {
|
|
8626
|
-
return
|
|
8675
|
+
return AI_ASSISTANT_PROGRESS_DRAFT;
|
|
8627
8676
|
}
|
|
8628
8677
|
if (normalized === 'searching files' || normalized === 'finding files' || normalized === 'opening files' || normalized === 'scanning files') {
|
|
8629
|
-
return
|
|
8678
|
+
return AI_ASSISTANT_PROGRESS_DATA_RUNNING;
|
|
8630
8679
|
}
|
|
8631
8680
|
return trimmed;
|
|
8632
8681
|
}
|
|
@@ -8896,24 +8945,34 @@ function isUnsafeFieldAlias(requestedTokens, candidateTokens) {
|
|
|
8896
8945
|
}
|
|
8897
8946
|
return false;
|
|
8898
8947
|
}
|
|
8899
|
-
function
|
|
8948
|
+
function resolveAssistantFieldTokenSynonyms(token, appId) {
|
|
8949
|
+
var key = normalizeCollectionKey(token);
|
|
8950
|
+
if (!key) {
|
|
8951
|
+
return [];
|
|
8952
|
+
}
|
|
8953
|
+
var base = AI_ASSISTANT_BASE_FIELD_TOKEN_SYNONYMS[key] || [];
|
|
8954
|
+
var profile = resolveAssistantAppHeuristicProfile(appId);
|
|
8955
|
+
var appSynonyms = profile.fieldSynonyms[key] || [];
|
|
8956
|
+
return mergeAssistantHintValues(base, appSynonyms);
|
|
8957
|
+
}
|
|
8958
|
+
function expandFieldTokens(tokens, appId) {
|
|
8900
8959
|
var expanded = new Set();
|
|
8901
8960
|
tokens.forEach(function (token) {
|
|
8902
8961
|
if (!token) {
|
|
8903
8962
|
return;
|
|
8904
8963
|
}
|
|
8905
8964
|
expanded.add(token);
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
}
|
|
8912
|
-
});
|
|
8913
|
-
}
|
|
8965
|
+
resolveAssistantFieldTokenSynonyms(token, appId).forEach(function (synonym) {
|
|
8966
|
+
if (synonym) {
|
|
8967
|
+
expanded.add(synonym);
|
|
8968
|
+
}
|
|
8969
|
+
});
|
|
8914
8970
|
});
|
|
8915
8971
|
return Array.from(expanded);
|
|
8916
8972
|
}
|
|
8973
|
+
function expandAssistantFieldTokensForTesting(tokens, appId) {
|
|
8974
|
+
return expandFieldTokens(tokens, appId);
|
|
8975
|
+
}
|
|
8917
8976
|
function getValueAtPath(obj, path) {
|
|
8918
8977
|
if (!obj || typeof obj !== 'object') {
|
|
8919
8978
|
return undefined;
|
|
@@ -9643,7 +9702,7 @@ function collectFieldCandidates(docs) {
|
|
|
9643
9702
|
});
|
|
9644
9703
|
return candidates;
|
|
9645
9704
|
}
|
|
9646
|
-
function resolveFieldAliases(docs, requestedFields, schemaFields) {
|
|
9705
|
+
function resolveFieldAliases(docs, requestedFields, schemaFields, appId) {
|
|
9647
9706
|
var aliases = {};
|
|
9648
9707
|
if (!Array.isArray(docs) || !requestedFields.length) {
|
|
9649
9708
|
return aliases;
|
|
@@ -9699,7 +9758,7 @@ function resolveFieldAliases(docs, requestedFields, schemaFields) {
|
|
|
9699
9758
|
score = 70;
|
|
9700
9759
|
}
|
|
9701
9760
|
else {
|
|
9702
|
-
var requestedTokens = expandFieldTokens(requestedBaseTokens);
|
|
9761
|
+
var requestedTokens = expandFieldTokens(requestedBaseTokens, appId);
|
|
9703
9762
|
var overlap = requestedTokens.filter(function (token) { return candidateTokens.includes(token); }).length;
|
|
9704
9763
|
var baseOverlap = requestedBaseTokens.filter(function (token) { return candidateTokens.includes(token); }).length;
|
|
9705
9764
|
if (overlap > 0) {
|
|
@@ -10339,7 +10398,7 @@ function resolveAssistantNumericValue(value) {
|
|
|
10339
10398
|
function isAssistantPercentColumn(column) {
|
|
10340
10399
|
return /(percent|pct|percentage|ratio|rate)\b/.test(column);
|
|
10341
10400
|
}
|
|
10342
|
-
var ASSISTANT_NON_CURRENCY_COLUMN_PATTERN = /\b(
|
|
10401
|
+
var ASSISTANT_NON_CURRENCY_COLUMN_PATTERN = /\b(count|qty|quantity|index|rank|sequence|seq|id|code|ticket|number)\b/;
|
|
10343
10402
|
var ASSISTANT_CURRENCY_HINT_PATTERN = /\b(amount|price|cost|balance|fee|revenue|tax|billing|charge|payment|profit|margin|due)\b/;
|
|
10344
10403
|
var ASSISTANT_MONEY_TOTAL_PATTERN = /\b(sub\s*total|subtotal|grand\s*total|paid\s*total)\b/;
|
|
10345
10404
|
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 +12833,11 @@ function normalizeAssistantAggregateOptions(options) {
|
|
|
12774
12833
|
aggregateOptions: aggregateOptions,
|
|
12775
12834
|
limit: limit,
|
|
12776
12835
|
maxLimit: maxLimit,
|
|
12777
|
-
defaultLimit: defaultLimit
|
|
12836
|
+
defaultLimit: defaultLimit,
|
|
12837
|
+
disableNoDataFallbacks: normalized.disableNoDataFallbacks === true
|
|
12838
|
+
|| normalized.disable_no_data_fallbacks === true
|
|
12839
|
+
|| normalized.disableFallbacks === true
|
|
12840
|
+
|| normalized.disable_fallbacks === true
|
|
12778
12841
|
};
|
|
12779
12842
|
}
|
|
12780
12843
|
function findAggregateLimit(pipeline) {
|
|
@@ -15173,7 +15236,7 @@ function tokenizeCollectionText(value) {
|
|
|
15173
15236
|
}
|
|
15174
15237
|
function computeCollectionTokenWeights(tokens) {
|
|
15175
15238
|
var unique = Array.from(new Set(tokens));
|
|
15176
|
-
var hasDomain = unique.some(function (token) { return
|
|
15239
|
+
var hasDomain = unique.some(function (token) { return !AI_ASSISTANT_COLLECTION_GENERIC_TOKENS.has(token); });
|
|
15177
15240
|
var weights = {};
|
|
15178
15241
|
unique.forEach(function (token) {
|
|
15179
15242
|
if (hasDomain && AI_ASSISTANT_COLLECTION_GENERIC_TOKENS.has(token)) {
|
|
@@ -15797,8 +15860,11 @@ function createAssistantEmptyHeuristicProfile() {
|
|
|
15797
15860
|
return {
|
|
15798
15861
|
aliases: {},
|
|
15799
15862
|
aliasOptions: {},
|
|
15863
|
+
fieldSynonyms: {},
|
|
15800
15864
|
collectionTermHints: [],
|
|
15801
15865
|
dataIntents: [],
|
|
15866
|
+
routeIntents: [],
|
|
15867
|
+
collectionPreserveRules: [],
|
|
15802
15868
|
enabledDeterministicHeuristics: new Set(),
|
|
15803
15869
|
disabledDeterministicHeuristics: new Set()
|
|
15804
15870
|
};
|
|
@@ -15811,6 +15877,10 @@ function cloneAssistantHeuristicProfile(profile) {
|
|
|
15811
15877
|
acc[key] = mergeAssistantHintValues(((profile === null || profile === void 0 ? void 0 : profile.aliasOptions) || {})[key] || []);
|
|
15812
15878
|
return acc;
|
|
15813
15879
|
}, {}),
|
|
15880
|
+
fieldSynonyms: Object.keys((profile === null || profile === void 0 ? void 0 : profile.fieldSynonyms) || {}).reduce(function (acc, key) {
|
|
15881
|
+
acc[key] = mergeAssistantHintValues(((profile === null || profile === void 0 ? void 0 : profile.fieldSynonyms) || {})[key] || []);
|
|
15882
|
+
return acc;
|
|
15883
|
+
}, {}),
|
|
15814
15884
|
collectionTermHints: Array.isArray(profile === null || profile === void 0 ? void 0 : profile.collectionTermHints)
|
|
15815
15885
|
? profile.collectionTermHints.map(function (entry) { return ({
|
|
15816
15886
|
terms: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.terms) || []).map(function (term) { return term.toLowerCase(); }),
|
|
@@ -15829,9 +15899,39 @@ function cloneAssistantHeuristicProfile(profile) {
|
|
|
15829
15899
|
metricField: normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.metricField) || undefined,
|
|
15830
15900
|
fallbackCollections: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.fallbackCollections) || []),
|
|
15831
15901
|
progress: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.progress) || []),
|
|
15832
|
-
|
|
15902
|
+
acknowledgement: normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.acknowledgement) || undefined,
|
|
15903
|
+
assumptions: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.assumptions) || []),
|
|
15904
|
+
pipeline: Array.isArray(entry === null || entry === void 0 ? void 0 : entry.pipeline) ? (0, common_1.deepCopy)(entry.pipeline) : undefined,
|
|
15905
|
+
options: (entry === null || entry === void 0 ? void 0 : entry.options) && typeof entry.options === 'object' && !Array.isArray(entry.options)
|
|
15906
|
+
? (0, common_1.deepCopy)(entry.options)
|
|
15907
|
+
: undefined
|
|
15833
15908
|
}); }).filter(function (entry) { return !!entry.id && !!entry.collection; })
|
|
15834
15909
|
: [],
|
|
15910
|
+
routeIntents: Array.isArray(profile === null || profile === void 0 ? void 0 : profile.routeIntents)
|
|
15911
|
+
? profile.routeIntents.map(function (entry) { return ({
|
|
15912
|
+
id: normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.id),
|
|
15913
|
+
terms: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.terms) || []).map(function (term) { return term.toLowerCase(); }),
|
|
15914
|
+
excludeTerms: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.excludeTerms) || []).map(function (term) { return term.toLowerCase(); }),
|
|
15915
|
+
routes: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.routes) || []).map(function (route) { return normalizeRouteKey(route); }).filter(Boolean),
|
|
15916
|
+
response: normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.response) || undefined
|
|
15917
|
+
}); }).filter(function (entry) { return !!entry.id && !!entry.routes.length; })
|
|
15918
|
+
: [],
|
|
15919
|
+
collectionPreserveRules: Array.isArray(profile === null || profile === void 0 ? void 0 : profile.collectionPreserveRules)
|
|
15920
|
+
? profile.collectionPreserveRules.map(function (entry) { return ({
|
|
15921
|
+
id: normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.id) || undefined,
|
|
15922
|
+
routePreferredCollections: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.routePreferredCollections) || [])
|
|
15923
|
+
.map(function (collection) { return normalizeAssistantCollectionOverrideName(collection); })
|
|
15924
|
+
.filter(Boolean),
|
|
15925
|
+
routePatterns: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.routePatterns) || [])
|
|
15926
|
+
.map(function (route) { return normalizeRouteKey(route); })
|
|
15927
|
+
.filter(Boolean),
|
|
15928
|
+
requestedCollections: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.requestedCollections) || [])
|
|
15929
|
+
.map(function (collection) { return normalizeAssistantCollectionOverrideName(collection); })
|
|
15930
|
+
.filter(Boolean),
|
|
15931
|
+
contextTerms: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.contextTerms) || []).map(function (term) { return term.toLowerCase(); }),
|
|
15932
|
+
terms: mergeAssistantHintValues((entry === null || entry === void 0 ? void 0 : entry.terms) || []).map(function (term) { return term.toLowerCase(); })
|
|
15933
|
+
}); }).filter(function (entry) { return !!entry.routePreferredCollections.length && !!entry.routePatterns.length && !!entry.requestedCollections.length; })
|
|
15934
|
+
: [],
|
|
15835
15935
|
enabledDeterministicHeuristics: new Set(Array.from((profile === null || profile === void 0 ? void 0 : profile.enabledDeterministicHeuristics) || [])),
|
|
15836
15936
|
disabledDeterministicHeuristics: new Set(Array.from((profile === null || profile === void 0 ? void 0 : profile.disabledDeterministicHeuristics) || [])),
|
|
15837
15937
|
displayDateFormat: profile === null || profile === void 0 ? void 0 : profile.displayDateFormat
|
|
@@ -15858,8 +15958,18 @@ function mergeAssistantHeuristicProfiles(base, override) {
|
|
|
15858
15958
|
}
|
|
15859
15959
|
merged.aliasOptions[normalizedKey] = values;
|
|
15860
15960
|
});
|
|
15961
|
+
Object.keys(override.fieldSynonyms || {}).forEach(function (key) {
|
|
15962
|
+
var normalizedKey = normalizeCollectionKey(key);
|
|
15963
|
+
var values = mergeAssistantHintValues((override.fieldSynonyms || {})[key] || []);
|
|
15964
|
+
if (!normalizedKey || !values.length) {
|
|
15965
|
+
return;
|
|
15966
|
+
}
|
|
15967
|
+
merged.fieldSynonyms[normalizedKey] = mergeAssistantHintValues(merged.fieldSynonyms[normalizedKey] || [], values);
|
|
15968
|
+
});
|
|
15861
15969
|
merged.collectionTermHints = __spreadArray(__spreadArray([], __read(merged.collectionTermHints), false), __read((Array.isArray(override.collectionTermHints) ? override.collectionTermHints : [])), false);
|
|
15862
15970
|
merged.dataIntents = __spreadArray(__spreadArray([], __read(merged.dataIntents), false), __read((Array.isArray(override.dataIntents) ? override.dataIntents : [])), false);
|
|
15971
|
+
merged.routeIntents = __spreadArray(__spreadArray([], __read(merged.routeIntents), false), __read((Array.isArray(override.routeIntents) ? override.routeIntents : [])), false);
|
|
15972
|
+
merged.collectionPreserveRules = __spreadArray(__spreadArray([], __read(merged.collectionPreserveRules), false), __read((Array.isArray(override.collectionPreserveRules) ? override.collectionPreserveRules : [])), false);
|
|
15863
15973
|
Array.from(override.enabledDeterministicHeuristics || []).forEach(function (value) { return merged.enabledDeterministicHeuristics.add(value); });
|
|
15864
15974
|
Array.from(override.disabledDeterministicHeuristics || []).forEach(function (value) { return merged.disabledDeterministicHeuristics.add(value); });
|
|
15865
15975
|
if (override.displayDateFormat) {
|
|
@@ -15966,11 +16076,87 @@ function normalizeAssistantAppDataIntents(value) {
|
|
|
15966
16076
|
metricField: normalizeOptionalString(entry.metric_field || entry.metricField) || undefined,
|
|
15967
16077
|
fallbackCollections: normalizeAssistantHeuristicStringList(entry.fallback_collections || entry.fallbackCollections || []),
|
|
15968
16078
|
progress: mergeAssistantHintValues(Array.isArray(entry.progress) ? entry.progress : []),
|
|
15969
|
-
|
|
16079
|
+
acknowledgement: normalizeOptionalString(entry.acknowledgement
|
|
16080
|
+
|| entry.acknowledgement_text
|
|
16081
|
+
|| entry.acknowledgementText
|
|
16082
|
+
|| entry.acknowledgement_template
|
|
16083
|
+
|| entry.acknowledgementTemplate) || undefined,
|
|
16084
|
+
assumptions: mergeAssistantHintValues(Array.isArray(entry.assumptions) ? entry.assumptions : []),
|
|
16085
|
+
pipeline: Array.isArray(entry.pipeline) ? (0, common_1.deepCopy)(entry.pipeline) : undefined,
|
|
16086
|
+
options: entry.options && typeof entry.options === 'object' && !Array.isArray(entry.options)
|
|
16087
|
+
? (0, common_1.deepCopy)(entry.options)
|
|
16088
|
+
: undefined
|
|
15970
16089
|
});
|
|
15971
16090
|
});
|
|
15972
16091
|
return intents;
|
|
15973
16092
|
}
|
|
16093
|
+
function normalizeAssistantAppRouteIntents(value) {
|
|
16094
|
+
var entries = Array.isArray(value) ? value : [];
|
|
16095
|
+
var intents = [];
|
|
16096
|
+
entries.forEach(function (entry) {
|
|
16097
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
16098
|
+
return;
|
|
16099
|
+
}
|
|
16100
|
+
var id = normalizeOptionalString(entry.id || entry.intent_id || entry.intentId);
|
|
16101
|
+
var terms = normalizeAssistantHeuristicStringList(entry.terms || entry.trigger_terms || entry.triggerTerms || entry.phrases || []).map(function (term) { return term.toLowerCase(); });
|
|
16102
|
+
var routes = normalizeAssistantHeuristicStringList(entry.routes || entry.preferred_routes || entry.preferredRoutes || entry.targets || []).map(function (route) { return normalizeRouteKey(route); }).filter(Boolean);
|
|
16103
|
+
if (!id || !terms.length || !routes.length) {
|
|
16104
|
+
return;
|
|
16105
|
+
}
|
|
16106
|
+
intents.push({
|
|
16107
|
+
id: id,
|
|
16108
|
+
terms: terms,
|
|
16109
|
+
excludeTerms: normalizeAssistantHeuristicStringList(entry.exclude_terms || entry.excludeTerms || []).map(function (term) { return term.toLowerCase(); }),
|
|
16110
|
+
routes: routes,
|
|
16111
|
+
response: normalizeOptionalString(entry.response || entry.summary) || undefined
|
|
16112
|
+
});
|
|
16113
|
+
});
|
|
16114
|
+
return intents;
|
|
16115
|
+
}
|
|
16116
|
+
function normalizeAssistantAppCollectionPreserveRules(value) {
|
|
16117
|
+
var entries = Array.isArray(value) ? value : [];
|
|
16118
|
+
var rules = [];
|
|
16119
|
+
entries.forEach(function (entry) {
|
|
16120
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
16121
|
+
return;
|
|
16122
|
+
}
|
|
16123
|
+
var routePreferredCollections = normalizeAssistantHeuristicStringList(entry.route_preferred_collections
|
|
16124
|
+
|| entry.routePreferredCollections
|
|
16125
|
+
|| entry.route_collections
|
|
16126
|
+
|| entry.routeCollections
|
|
16127
|
+
|| entry.route_collection
|
|
16128
|
+
|| entry.routeCollection).map(function (collection) { return normalizeAssistantCollectionOverrideName(collection); }).filter(Boolean);
|
|
16129
|
+
var routePatterns = normalizeAssistantHeuristicStringList(entry.permission_routes
|
|
16130
|
+
|| entry.permissionRoutes
|
|
16131
|
+
|| entry.route_patterns
|
|
16132
|
+
|| entry.routePatterns
|
|
16133
|
+
|| entry.routes).map(function (route) { return normalizeRouteKey(route); }).filter(Boolean);
|
|
16134
|
+
var requestedCollections = normalizeAssistantHeuristicStringList(entry.requested_collections
|
|
16135
|
+
|| entry.requestedCollections
|
|
16136
|
+
|| entry.collections
|
|
16137
|
+
|| entry.collection).map(function (collection) { return normalizeAssistantCollectionOverrideName(collection); }).filter(Boolean);
|
|
16138
|
+
var terms = normalizeAssistantHeuristicStringList(entry.terms
|
|
16139
|
+
|| entry.trigger_terms
|
|
16140
|
+
|| entry.triggerTerms
|
|
16141
|
+
|| entry.phrases).map(function (term) { return term.toLowerCase(); });
|
|
16142
|
+
var contextTerms = normalizeAssistantHeuristicStringList(entry.context_terms
|
|
16143
|
+
|| entry.contextTerms
|
|
16144
|
+
|| entry.required_terms
|
|
16145
|
+
|| entry.requiredTerms).map(function (term) { return term.toLowerCase(); });
|
|
16146
|
+
if (!routePreferredCollections.length || !routePatterns.length || !requestedCollections.length) {
|
|
16147
|
+
return;
|
|
16148
|
+
}
|
|
16149
|
+
rules.push({
|
|
16150
|
+
id: normalizeOptionalString(entry.id || entry.rule_id || entry.ruleId) || undefined,
|
|
16151
|
+
routePreferredCollections: routePreferredCollections,
|
|
16152
|
+
routePatterns: routePatterns,
|
|
16153
|
+
requestedCollections: requestedCollections,
|
|
16154
|
+
contextTerms: contextTerms,
|
|
16155
|
+
terms: terms
|
|
16156
|
+
});
|
|
16157
|
+
});
|
|
16158
|
+
return rules;
|
|
16159
|
+
}
|
|
15974
16160
|
function normalizeAssistantAppHeuristicProfile(value) {
|
|
15975
16161
|
var profile = createAssistantEmptyHeuristicProfile();
|
|
15976
16162
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
@@ -15989,6 +16175,10 @@ function normalizeAssistantAppHeuristicProfile(value) {
|
|
|
15989
16175
|
|| value.collectionAliasOptions
|
|
15990
16176
|
|| value.alias_options
|
|
15991
16177
|
|| value.aliasOptions);
|
|
16178
|
+
profile.fieldSynonyms = normalizeAssistantAliasOptionsMap(value.field_synonyms
|
|
16179
|
+
|| value.fieldSynonyms
|
|
16180
|
+
|| value.field_token_synonyms
|
|
16181
|
+
|| value.fieldTokenSynonyms);
|
|
15992
16182
|
profile.collectionTermHints = normalizeAssistantCollectionTermHints(value.collection_term_hints
|
|
15993
16183
|
|| value.collectionTermHints
|
|
15994
16184
|
|| value.term_hints
|
|
@@ -15996,6 +16186,14 @@ function normalizeAssistantAppHeuristicProfile(value) {
|
|
|
15996
16186
|
profile.dataIntents = normalizeAssistantAppDataIntents(value.data_intents
|
|
15997
16187
|
|| value.dataIntents
|
|
15998
16188
|
|| value.intents);
|
|
16189
|
+
profile.routeIntents = normalizeAssistantAppRouteIntents(value.route_intents
|
|
16190
|
+
|| value.routeIntents
|
|
16191
|
+
|| value.navigation_intents
|
|
16192
|
+
|| value.navigationIntents);
|
|
16193
|
+
profile.collectionPreserveRules = normalizeAssistantAppCollectionPreserveRules(value.collection_override_preserves
|
|
16194
|
+
|| value.collectionOverridePreserves
|
|
16195
|
+
|| value.collection_preserve_rules
|
|
16196
|
+
|| value.collectionPreserveRules);
|
|
15999
16197
|
profile.displayDateFormat = normalizeAssistantDisplayDateFormat(value.display_date_format
|
|
16000
16198
|
|| value.displayDateFormat
|
|
16001
16199
|
|| value.date_display_format
|
|
@@ -16043,6 +16241,7 @@ function normalizeAssistantAppHeuristicRegistry(value) {
|
|
|
16043
16241
|
|| Object.keys(standaloneProfile.aliasOptions).length
|
|
16044
16242
|
|| standaloneProfile.collectionTermHints.length
|
|
16045
16243
|
|| standaloneProfile.dataIntents.length
|
|
16244
|
+
|| standaloneProfile.routeIntents.length
|
|
16046
16245
|
|| standaloneProfile.enabledDeterministicHeuristics.size
|
|
16047
16246
|
|| standaloneProfile.disabledDeterministicHeuristics.size
|
|
16048
16247
|
|| normalizeOptionalString(standaloneProfile.appId)) {
|
|
@@ -16456,6 +16655,9 @@ function resolveCollectionOverrideWithContext(params) {
|
|
|
16456
16655
|
? params.collectionHints.map(function (value) { return normalizeOptionalString(value); }).filter(Boolean)
|
|
16457
16656
|
: [];
|
|
16458
16657
|
var permissionView = normalizeOptionalString(params.permissionView);
|
|
16658
|
+
var collectionPreserveRules = Array.isArray(params.collectionPreserveRules)
|
|
16659
|
+
? params.collectionPreserveRules
|
|
16660
|
+
: resolveAssistantAppHeuristicProfile(params.appId).collectionPreserveRules;
|
|
16459
16661
|
var routeHintCollections = permissionView
|
|
16460
16662
|
? resolveCollectionHintsFromRoute(permissionView, collectionNames)
|
|
16461
16663
|
: [];
|
|
@@ -16478,7 +16680,13 @@ function resolveCollectionOverrideWithContext(params) {
|
|
|
16478
16680
|
&& !isAssistantCollectionInHintFamilies(requested, [routePreferred])) {
|
|
16479
16681
|
var routePreferredName = normalizeAssistantCollectionOverrideName(routePreferred);
|
|
16480
16682
|
var requestedIsWorkOrder = isAssistantWorkOrderCollectionOverrideCandidate(requested);
|
|
16481
|
-
if (
|
|
16683
|
+
if (shouldPreserveAssistantCollectionForRouteFromRules({
|
|
16684
|
+
message: params.message,
|
|
16685
|
+
permissionView: permissionView,
|
|
16686
|
+
routePreferredName: routePreferredName,
|
|
16687
|
+
requestedCollection: requested,
|
|
16688
|
+
rules: collectionPreserveRules
|
|
16689
|
+
})) {
|
|
16482
16690
|
return null;
|
|
16483
16691
|
}
|
|
16484
16692
|
if (!(routePreferredName === 'orders' && requestedIsWorkOrder && hasAssistantWorkOrderAliasTerms(params.message))) {
|
|
@@ -16580,30 +16788,76 @@ function resolveCollectionOverrideWithContext(params) {
|
|
|
16580
16788
|
function resolveCollectionOverrideWithContextForTesting(params) {
|
|
16581
16789
|
return resolveCollectionOverrideWithContext(params);
|
|
16582
16790
|
}
|
|
16583
|
-
function
|
|
16584
|
-
var route =
|
|
16585
|
-
var
|
|
16586
|
-
if (!route ||
|
|
16791
|
+
function doesAssistantPreserveRoutePatternMatch(permissionView, pattern) {
|
|
16792
|
+
var route = normalizeRouteKey(permissionView);
|
|
16793
|
+
var routePattern = normalizeRouteKey(pattern);
|
|
16794
|
+
if (!route || !routePattern) {
|
|
16587
16795
|
return false;
|
|
16588
16796
|
}
|
|
16589
|
-
|
|
16797
|
+
return route === routePattern || route.startsWith("".concat(routePattern, "/"));
|
|
16798
|
+
}
|
|
16799
|
+
function doesAssistantPreserveTermMatch(text, term) {
|
|
16800
|
+
var normalizedText = normalizeOptionalString(text).toLowerCase();
|
|
16801
|
+
var normalizedTerm = normalizeOptionalString(term).toLowerCase();
|
|
16802
|
+
if (!normalizedText || !normalizedTerm) {
|
|
16590
16803
|
return false;
|
|
16591
16804
|
}
|
|
16592
|
-
var
|
|
16593
|
-
if (
|
|
16805
|
+
var compactTerm = normalizedTerm.replace(/\s+/g, ' ');
|
|
16806
|
+
if (compactTerm.length <= 3 && /^[a-z0-9]+$/.test(compactTerm)) {
|
|
16807
|
+
return new RegExp("\\b".concat(escapeRegexValue(compactTerm), "\\b"), 'i').test(normalizedText);
|
|
16808
|
+
}
|
|
16809
|
+
return normalizedText.includes(compactTerm);
|
|
16810
|
+
}
|
|
16811
|
+
function doesAssistantPreserveAnyTermMatch(text, terms) {
|
|
16812
|
+
return (Array.isArray(terms) ? terms : []).some(function (term) { return doesAssistantPreserveTermMatch(text, term); });
|
|
16813
|
+
}
|
|
16814
|
+
function shouldPreserveAssistantCollectionForRouteFromRules(params) {
|
|
16815
|
+
var e_32, _a;
|
|
16816
|
+
var _b, _c, _d, _e, _f, _g, _h;
|
|
16817
|
+
var routePreferred = normalizeAssistantCollectionOverrideName(params.routePreferredName);
|
|
16818
|
+
var requested = normalizeAssistantCollectionOverrideName(params.requestedCollection);
|
|
16819
|
+
var text = normalizeOptionalString(params.message).toLowerCase();
|
|
16820
|
+
if (!routePreferred || !requested || !text) {
|
|
16594
16821
|
return false;
|
|
16595
16822
|
}
|
|
16596
|
-
|
|
16597
|
-
|
|
16823
|
+
try {
|
|
16824
|
+
for (var _j = __values(Array.isArray(params.rules) ? params.rules : []), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
16825
|
+
var rule = _k.value;
|
|
16826
|
+
if (!((_b = rule === null || rule === void 0 ? void 0 : rule.routePreferredCollections) === null || _b === void 0 ? void 0 : _b.includes(routePreferred))) {
|
|
16827
|
+
continue;
|
|
16828
|
+
}
|
|
16829
|
+
if (!((_c = rule.requestedCollections) === null || _c === void 0 ? void 0 : _c.includes(requested))) {
|
|
16830
|
+
continue;
|
|
16831
|
+
}
|
|
16832
|
+
if (!((_d = rule.routePatterns) === null || _d === void 0 ? void 0 : _d.some(function (pattern) { return doesAssistantPreserveRoutePatternMatch(params.permissionView, pattern); }))) {
|
|
16833
|
+
continue;
|
|
16834
|
+
}
|
|
16835
|
+
if (((_e = rule.contextTerms) === null || _e === void 0 ? void 0 : _e.length) && !doesAssistantPreserveAnyTermMatch(text, rule.contextTerms)) {
|
|
16836
|
+
continue;
|
|
16837
|
+
}
|
|
16838
|
+
if (((_f = rule.terms) === null || _f === void 0 ? void 0 : _f.length) && !doesAssistantPreserveAnyTermMatch(text, rule.terms)) {
|
|
16839
|
+
continue;
|
|
16840
|
+
}
|
|
16841
|
+
if (!((_g = rule.contextTerms) === null || _g === void 0 ? void 0 : _g.length) && !((_h = rule.terms) === null || _h === void 0 ? void 0 : _h.length)) {
|
|
16842
|
+
continue;
|
|
16843
|
+
}
|
|
16844
|
+
return true;
|
|
16845
|
+
}
|
|
16598
16846
|
}
|
|
16599
|
-
|
|
16600
|
-
|
|
16847
|
+
catch (e_32_1) { e_32 = { error: e_32_1 }; }
|
|
16848
|
+
finally {
|
|
16849
|
+
try {
|
|
16850
|
+
if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
|
|
16851
|
+
}
|
|
16852
|
+
finally { if (e_32) throw e_32.error; }
|
|
16601
16853
|
}
|
|
16602
|
-
return
|
|
16854
|
+
return false;
|
|
16603
16855
|
}
|
|
16604
16856
|
function isAssistantWorkOrderCollectionOverrideCandidate(value) {
|
|
16605
16857
|
var normalized = normalizeAssistantCollectionOverrideName(value);
|
|
16606
|
-
return normalized
|
|
16858
|
+
return normalized.startsWith('work-order-')
|
|
16859
|
+
|| normalized.endsWith('-work-orders')
|
|
16860
|
+
|| normalized.includes('-work-order-')
|
|
16607
16861
|
|| normalized === 'work-orders'
|
|
16608
16862
|
|| normalized === 'maintenance-orders'
|
|
16609
16863
|
|| normalized === 'repair-orders';
|
|
@@ -17486,7 +17740,7 @@ function resolveAssistantNestedPrefixCollectionCandidates(params) {
|
|
|
17486
17740
|
function resolveAssistantNestedAggregateFallbacks(params) {
|
|
17487
17741
|
return __awaiter(this, void 0, void 0, function () {
|
|
17488
17742
|
var prefixes, collectionNames, fallbacks, seen, prefixes_1, prefixes_1_1, prefix, rewrite, candidates, candidates_4, candidates_4_1, candidate, normalizedPipeline, key;
|
|
17489
|
-
var
|
|
17743
|
+
var e_33, _a, e_34, _b;
|
|
17490
17744
|
return __generator(this, function (_c) {
|
|
17491
17745
|
switch (_c.label) {
|
|
17492
17746
|
case 0:
|
|
@@ -17516,7 +17770,7 @@ function resolveAssistantNestedAggregateFallbacks(params) {
|
|
|
17516
17770
|
triedCollections: params.triedCollections
|
|
17517
17771
|
});
|
|
17518
17772
|
try {
|
|
17519
|
-
for (candidates_4 = (
|
|
17773
|
+
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
17774
|
candidate = candidates_4_1.value;
|
|
17521
17775
|
normalizedPipeline = normalizeAssistantAggregatePipeline(rewrite.pipeline, candidate);
|
|
17522
17776
|
if (!normalizedPipeline.length || containsForbiddenMongoOperators(normalizedPipeline)) {
|
|
@@ -17538,21 +17792,21 @@ function resolveAssistantNestedAggregateFallbacks(params) {
|
|
|
17538
17792
|
}
|
|
17539
17793
|
}
|
|
17540
17794
|
}
|
|
17541
|
-
catch (
|
|
17795
|
+
catch (e_34_1) { e_34 = { error: e_34_1 }; }
|
|
17542
17796
|
finally {
|
|
17543
17797
|
try {
|
|
17544
17798
|
if (candidates_4_1 && !candidates_4_1.done && (_b = candidates_4.return)) _b.call(candidates_4);
|
|
17545
17799
|
}
|
|
17546
|
-
finally { if (
|
|
17800
|
+
finally { if (e_34) throw e_34.error; }
|
|
17547
17801
|
}
|
|
17548
17802
|
}
|
|
17549
17803
|
}
|
|
17550
|
-
catch (
|
|
17804
|
+
catch (e_33_1) { e_33 = { error: e_33_1 }; }
|
|
17551
17805
|
finally {
|
|
17552
17806
|
try {
|
|
17553
17807
|
if (prefixes_1_1 && !prefixes_1_1.done && (_a = prefixes_1.return)) _a.call(prefixes_1);
|
|
17554
17808
|
}
|
|
17555
|
-
finally { if (
|
|
17809
|
+
finally { if (e_33) throw e_33.error; }
|
|
17556
17810
|
}
|
|
17557
17811
|
return [2 /*return*/, fallbacks];
|
|
17558
17812
|
}
|
|
@@ -17684,8 +17938,8 @@ function resolveAssistantBridgeCollectionHintCandidates(requestedCollection, req
|
|
|
17684
17938
|
}
|
|
17685
17939
|
function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
17686
17940
|
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
|
|
17941
|
+
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;
|
|
17942
|
+
var e_37, _b, e_38, _c, e_35, _d, e_36, _e, e_39, _f;
|
|
17689
17943
|
var _g, _h;
|
|
17690
17944
|
if (dbName === void 0) { dbName = ''; }
|
|
17691
17945
|
return __generator(this, function (_j) {
|
|
@@ -17759,12 +18013,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17759
18013
|
}
|
|
17760
18014
|
}
|
|
17761
18015
|
}
|
|
17762
|
-
catch (
|
|
18016
|
+
catch (e_37_1) { e_37 = { error: e_37_1 }; }
|
|
17763
18017
|
finally {
|
|
17764
18018
|
try {
|
|
17765
18019
|
if (candidates_5_1 && !candidates_5_1.done && (_b = candidates_5.return)) _b.call(candidates_5);
|
|
17766
18020
|
}
|
|
17767
|
-
finally { if (
|
|
18021
|
+
finally { if (e_37) throw e_37.error; }
|
|
17768
18022
|
}
|
|
17769
18023
|
}
|
|
17770
18024
|
if (configuredCollectionNames.length) {
|
|
@@ -17779,12 +18033,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17779
18033
|
}
|
|
17780
18034
|
}
|
|
17781
18035
|
}
|
|
17782
|
-
catch (
|
|
18036
|
+
catch (e_38_1) { e_38 = { error: e_38_1 }; }
|
|
17783
18037
|
finally {
|
|
17784
18038
|
try {
|
|
17785
18039
|
if (candidates_6_1 && !candidates_6_1.done && (_c = candidates_6.return)) _c.call(candidates_6);
|
|
17786
18040
|
}
|
|
17787
|
-
finally { if (
|
|
18041
|
+
finally { if (e_38) throw e_38.error; }
|
|
17788
18042
|
}
|
|
17789
18043
|
}
|
|
17790
18044
|
primaryCollectionHint = normalizeOptionalString((_h = requestHints === null || requestHints === void 0 ? void 0 : requestHints.collectionHints) === null || _h === void 0 ? void 0 : _h[0]);
|
|
@@ -17845,14 +18099,14 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17845
18099
|
return [3 /*break*/, 2];
|
|
17846
18100
|
case 7: return [3 /*break*/, 10];
|
|
17847
18101
|
case 8:
|
|
17848
|
-
|
|
17849
|
-
|
|
18102
|
+
e_35_1 = _j.sent();
|
|
18103
|
+
e_35 = { error: e_35_1 };
|
|
17850
18104
|
return [3 /*break*/, 10];
|
|
17851
18105
|
case 9:
|
|
17852
18106
|
try {
|
|
17853
18107
|
if (resolverTargets_1_1 && !resolverTargets_1_1.done && (_d = resolverTargets_1.return)) _d.call(resolverTargets_1);
|
|
17854
18108
|
}
|
|
17855
|
-
finally { if (
|
|
18109
|
+
finally { if (e_35) throw e_35.error; }
|
|
17856
18110
|
return [7 /*endfinally*/];
|
|
17857
18111
|
case 10:
|
|
17858
18112
|
if (!db) return [3 /*break*/, 18];
|
|
@@ -17878,14 +18132,14 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17878
18132
|
return [3 /*break*/, 12];
|
|
17879
18133
|
case 15: return [3 /*break*/, 18];
|
|
17880
18134
|
case 16:
|
|
17881
|
-
|
|
17882
|
-
|
|
18135
|
+
e_36_1 = _j.sent();
|
|
18136
|
+
e_36 = { error: e_36_1 };
|
|
17883
18137
|
return [3 /*break*/, 18];
|
|
17884
18138
|
case 17:
|
|
17885
18139
|
try {
|
|
17886
18140
|
if (candidates_7_1 && !candidates_7_1.done && (_e = candidates_7.return)) _e.call(candidates_7);
|
|
17887
18141
|
}
|
|
17888
|
-
finally { if (
|
|
18142
|
+
finally { if (e_36) throw e_36.error; }
|
|
17889
18143
|
return [7 /*endfinally*/];
|
|
17890
18144
|
case 18:
|
|
17891
18145
|
try {
|
|
@@ -17896,12 +18150,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17896
18150
|
}
|
|
17897
18151
|
}
|
|
17898
18152
|
}
|
|
17899
|
-
catch (
|
|
18153
|
+
catch (e_39_1) { e_39 = { error: e_39_1 }; }
|
|
17900
18154
|
finally {
|
|
17901
18155
|
try {
|
|
17902
18156
|
if (candidates_8_1 && !candidates_8_1.done && (_f = candidates_8.return)) _f.call(candidates_8);
|
|
17903
18157
|
}
|
|
17904
|
-
finally { if (
|
|
18158
|
+
finally { if (e_39) throw e_39.error; }
|
|
17905
18159
|
}
|
|
17906
18160
|
throw new Error('AI assistant report builder bridge: No queryable collection could be resolved.');
|
|
17907
18161
|
}
|
|
@@ -17909,7 +18163,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
17909
18163
|
});
|
|
17910
18164
|
}
|
|
17911
18165
|
function findQueryDateField(query) {
|
|
17912
|
-
var
|
|
18166
|
+
var e_40, _a, e_41, _b;
|
|
17913
18167
|
if (!query || typeof query !== 'object') {
|
|
17914
18168
|
return null;
|
|
17915
18169
|
}
|
|
@@ -17923,12 +18177,12 @@ function findQueryDateField(query) {
|
|
|
17923
18177
|
}
|
|
17924
18178
|
}
|
|
17925
18179
|
}
|
|
17926
|
-
catch (
|
|
18180
|
+
catch (e_40_1) { e_40 = { error: e_40_1 }; }
|
|
17927
18181
|
finally {
|
|
17928
18182
|
try {
|
|
17929
18183
|
if (query_1_1 && !query_1_1.done && (_a = query_1.return)) _a.call(query_1);
|
|
17930
18184
|
}
|
|
17931
|
-
finally { if (
|
|
18185
|
+
finally { if (e_40) throw e_40.error; }
|
|
17932
18186
|
}
|
|
17933
18187
|
return null;
|
|
17934
18188
|
}
|
|
@@ -17947,12 +18201,12 @@ function findQueryDateField(query) {
|
|
|
17947
18201
|
}
|
|
17948
18202
|
}
|
|
17949
18203
|
}
|
|
17950
|
-
catch (
|
|
18204
|
+
catch (e_41_1) { e_41 = { error: e_41_1 }; }
|
|
17951
18205
|
finally {
|
|
17952
18206
|
try {
|
|
17953
18207
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
17954
18208
|
}
|
|
17955
|
-
finally { if (
|
|
18209
|
+
finally { if (e_41) throw e_41.error; }
|
|
17956
18210
|
}
|
|
17957
18211
|
return null;
|
|
17958
18212
|
}
|
|
@@ -18240,7 +18494,7 @@ function resolveQueryDateFieldFallback(query) {
|
|
|
18240
18494
|
return { from: dateField, to: fallback };
|
|
18241
18495
|
}
|
|
18242
18496
|
function containsForbiddenMongoOperators(value) {
|
|
18243
|
-
var
|
|
18497
|
+
var e_42, _a;
|
|
18244
18498
|
if (!value || typeof value !== 'object') {
|
|
18245
18499
|
return false;
|
|
18246
18500
|
}
|
|
@@ -18259,12 +18513,12 @@ function containsForbiddenMongoOperators(value) {
|
|
|
18259
18513
|
}
|
|
18260
18514
|
}
|
|
18261
18515
|
}
|
|
18262
|
-
catch (
|
|
18516
|
+
catch (e_42_1) { e_42 = { error: e_42_1 }; }
|
|
18263
18517
|
finally {
|
|
18264
18518
|
try {
|
|
18265
18519
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
18266
18520
|
}
|
|
18267
|
-
finally { if (
|
|
18521
|
+
finally { if (e_42) throw e_42.error; }
|
|
18268
18522
|
}
|
|
18269
18523
|
return false;
|
|
18270
18524
|
}
|
|
@@ -18449,7 +18703,7 @@ function splitAssistantPermissionTokenSets(value) {
|
|
|
18449
18703
|
};
|
|
18450
18704
|
}
|
|
18451
18705
|
function isAssistantTokenSetSubset(subset, superset) {
|
|
18452
|
-
var
|
|
18706
|
+
var e_43, _a;
|
|
18453
18707
|
if (!subset.size) {
|
|
18454
18708
|
return false;
|
|
18455
18709
|
}
|
|
@@ -18461,12 +18715,12 @@ function isAssistantTokenSetSubset(subset, superset) {
|
|
|
18461
18715
|
}
|
|
18462
18716
|
}
|
|
18463
18717
|
}
|
|
18464
|
-
catch (
|
|
18718
|
+
catch (e_43_1) { e_43 = { error: e_43_1 }; }
|
|
18465
18719
|
finally {
|
|
18466
18720
|
try {
|
|
18467
18721
|
if (subset_1_1 && !subset_1_1.done && (_a = subset_1.return)) _a.call(subset_1);
|
|
18468
18722
|
}
|
|
18469
|
-
finally { if (
|
|
18723
|
+
finally { if (e_43) throw e_43.error; }
|
|
18470
18724
|
}
|
|
18471
18725
|
return true;
|
|
18472
18726
|
}
|
|
@@ -18712,13 +18966,46 @@ function resolveAssistantMongoDefaultMaxTimeMs(config) {
|
|
|
18712
18966
|
}
|
|
18713
18967
|
function resolveAssistantSystemPrompt(config, runtimeContext) {
|
|
18714
18968
|
var override = normalizeOptionalString((config === null || config === void 0 ? void 0 : config.system_prompt) || (config === null || config === void 0 ? void 0 : config.systemPrompt));
|
|
18969
|
+
var additions = resolveAssistantSystemPromptAdditions(config);
|
|
18715
18970
|
if (override) {
|
|
18716
|
-
return override;
|
|
18971
|
+
return additions.length ? __spreadArray([override], __read(additions), false).join('\n') : override;
|
|
18972
|
+
}
|
|
18973
|
+
var basePrompt = !runtimeContext
|
|
18974
|
+
? AI_ASSISTANT_SYSTEM_PROMPT
|
|
18975
|
+
: buildAssistantSystemPromptText(buildAssistantPlatformIntelligencePrompt(runtimeContext));
|
|
18976
|
+
if (additions.length) {
|
|
18977
|
+
return __spreadArray([basePrompt], __read(additions), false).join('\n');
|
|
18717
18978
|
}
|
|
18718
18979
|
if (!runtimeContext) {
|
|
18719
|
-
return
|
|
18980
|
+
return basePrompt;
|
|
18720
18981
|
}
|
|
18721
|
-
return
|
|
18982
|
+
return basePrompt;
|
|
18983
|
+
}
|
|
18984
|
+
function resolveAssistantSystemPromptAdditions(config) {
|
|
18985
|
+
var values = [];
|
|
18986
|
+
var push = function (value) {
|
|
18987
|
+
var normalized = normalizeOptionalString(value);
|
|
18988
|
+
if (!normalized || values.includes(normalized)) {
|
|
18989
|
+
return;
|
|
18990
|
+
}
|
|
18991
|
+
values.push(normalized);
|
|
18992
|
+
};
|
|
18993
|
+
[
|
|
18994
|
+
config === null || config === void 0 ? void 0 : config.system_prompt_additions,
|
|
18995
|
+
config === null || config === void 0 ? void 0 : config.systemPromptAdditions,
|
|
18996
|
+
config === null || config === void 0 ? void 0 : config.app_instructions,
|
|
18997
|
+
config === null || config === void 0 ? void 0 : config.appInstructions,
|
|
18998
|
+
config === null || config === void 0 ? void 0 : config.assistant_instructions,
|
|
18999
|
+
config === null || config === void 0 ? void 0 : config.assistantInstructions
|
|
19000
|
+
].forEach(function (raw) {
|
|
19001
|
+
if (Array.isArray(raw)) {
|
|
19002
|
+
raw.forEach(push);
|
|
19003
|
+
}
|
|
19004
|
+
else {
|
|
19005
|
+
push(raw);
|
|
19006
|
+
}
|
|
19007
|
+
});
|
|
19008
|
+
return values;
|
|
18722
19009
|
}
|
|
18723
19010
|
function normalizeAssistantRuntimeControl(value) {
|
|
18724
19011
|
if (!value || typeof value !== 'object') {
|
|
@@ -18968,8 +19255,8 @@ function applyCodexStreamStatusHandler(runOptions, streamStatusHandler) {
|
|
|
18968
19255
|
}
|
|
18969
19256
|
function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
18970
19257
|
return __awaiter(this, void 0, void 0, function () {
|
|
18971
|
-
var _a, _b, _c, _d, message, payload, status_1,
|
|
18972
|
-
var _e,
|
|
19258
|
+
var _a, _b, _c, _d, message, payload, status_1, e_44_1;
|
|
19259
|
+
var _e, e_44, _f, _g;
|
|
18973
19260
|
return __generator(this, function (_h) {
|
|
18974
19261
|
switch (_h.label) {
|
|
18975
19262
|
case 0:
|
|
@@ -18996,8 +19283,8 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
18996
19283
|
return [3 /*break*/, 1];
|
|
18997
19284
|
case 4: return [3 /*break*/, 11];
|
|
18998
19285
|
case 5:
|
|
18999
|
-
|
|
19000
|
-
|
|
19286
|
+
e_44_1 = _h.sent();
|
|
19287
|
+
e_44 = { error: e_44_1 };
|
|
19001
19288
|
return [3 /*break*/, 11];
|
|
19002
19289
|
case 6:
|
|
19003
19290
|
_h.trys.push([6, , 9, 10]);
|
|
@@ -19008,7 +19295,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
19008
19295
|
_h.label = 8;
|
|
19009
19296
|
case 8: return [3 /*break*/, 10];
|
|
19010
19297
|
case 9:
|
|
19011
|
-
if (
|
|
19298
|
+
if (e_44) throw e_44.error;
|
|
19012
19299
|
return [7 /*endfinally*/];
|
|
19013
19300
|
case 10: return [7 /*endfinally*/];
|
|
19014
19301
|
case 11: throw new CodexWorkerBootstrapError('AI worker exited before completing.');
|
|
@@ -19018,7 +19305,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
19018
19305
|
}
|
|
19019
19306
|
function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler) {
|
|
19020
19307
|
return __awaiter(this, void 0, void 0, function () {
|
|
19021
|
-
var streamedOptions, normalizedThreadKey, shouldForceInProcessThreadReuse, codexClient, codexClient, workerPath, codexClient,
|
|
19308
|
+
var streamedOptions, normalizedThreadKey, shouldForceInProcessThreadReuse, codexClient, codexClient, workerPath, codexClient, error_15, codexClient;
|
|
19022
19309
|
return __generator(this, function (_a) {
|
|
19023
19310
|
switch (_a.label) {
|
|
19024
19311
|
case 0:
|
|
@@ -19046,11 +19333,11 @@ function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler)
|
|
|
19046
19333
|
return [4 /*yield*/, runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config, streamStatusHandler)];
|
|
19047
19334
|
case 8: return [2 /*return*/, _a.sent()];
|
|
19048
19335
|
case 9:
|
|
19049
|
-
|
|
19050
|
-
if (!(
|
|
19051
|
-
throw
|
|
19336
|
+
error_15 = _a.sent();
|
|
19337
|
+
if (!(error_15 instanceof CodexWorkerBootstrapError)) {
|
|
19338
|
+
throw error_15;
|
|
19052
19339
|
}
|
|
19053
|
-
console.error('AI worker bootstrap failed, falling back to in-process run.',
|
|
19340
|
+
console.error('AI worker bootstrap failed, falling back to in-process run.', error_15);
|
|
19054
19341
|
codexClient = getAssistantCodexClient(config);
|
|
19055
19342
|
return [4 /*yield*/, codexClient.run(prompt, streamedOptions)];
|
|
19056
19343
|
case 10: return [2 /*return*/, _a.sent()];
|
|
@@ -19088,7 +19375,7 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
19088
19375
|
timeoutMs = ((sanitizedOptions === null || sanitizedOptions === void 0 ? void 0 : sanitizedOptions.timeoutMs) || resolveCodexTimeoutMs()) + 15000;
|
|
19089
19376
|
timeoutController = new AbortController();
|
|
19090
19377
|
timeoutPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
19091
|
-
var
|
|
19378
|
+
var error_16;
|
|
19092
19379
|
return __generator(this, function (_a) {
|
|
19093
19380
|
switch (_a.label) {
|
|
19094
19381
|
case 0:
|
|
@@ -19098,11 +19385,11 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
19098
19385
|
_a.sent();
|
|
19099
19386
|
return [2 /*return*/, { type: 'timeout' }];
|
|
19100
19387
|
case 2:
|
|
19101
|
-
|
|
19102
|
-
if ((
|
|
19388
|
+
error_16 = _a.sent();
|
|
19389
|
+
if ((error_16 === null || error_16 === void 0 ? void 0 : error_16.name) === 'AbortError') {
|
|
19103
19390
|
return [2 /*return*/, { type: 'aborted' }];
|
|
19104
19391
|
}
|
|
19105
|
-
throw
|
|
19392
|
+
throw error_16;
|
|
19106
19393
|
case 3: return [2 /*return*/];
|
|
19107
19394
|
}
|
|
19108
19395
|
});
|
|
@@ -19352,8 +19639,8 @@ function buildAssistantWorkspaceRootCandidates(params) {
|
|
|
19352
19639
|
}
|
|
19353
19640
|
function resolveAssistantWorkspaceRoot() {
|
|
19354
19641
|
return __awaiter(this, void 0, void 0, function () {
|
|
19355
|
-
var candidates, firstExisting, firstNestedGitRoot, candidates_9, candidates_9_1, candidate, _a, gitRoot, nestedGitRoots,
|
|
19356
|
-
var
|
|
19642
|
+
var candidates, firstExisting, firstNestedGitRoot, candidates_9, candidates_9_1, candidate, _a, gitRoot, nestedGitRoots, e_45_1;
|
|
19643
|
+
var e_45, _b;
|
|
19357
19644
|
return __generator(this, function (_c) {
|
|
19358
19645
|
switch (_c.label) {
|
|
19359
19646
|
case 0:
|
|
@@ -19400,14 +19687,14 @@ function resolveAssistantWorkspaceRoot() {
|
|
|
19400
19687
|
return [3 /*break*/, 2];
|
|
19401
19688
|
case 8: return [3 /*break*/, 11];
|
|
19402
19689
|
case 9:
|
|
19403
|
-
|
|
19404
|
-
|
|
19690
|
+
e_45_1 = _c.sent();
|
|
19691
|
+
e_45 = { error: e_45_1 };
|
|
19405
19692
|
return [3 /*break*/, 11];
|
|
19406
19693
|
case 10:
|
|
19407
19694
|
try {
|
|
19408
19695
|
if (candidates_9_1 && !candidates_9_1.done && (_b = candidates_9.return)) _b.call(candidates_9);
|
|
19409
19696
|
}
|
|
19410
|
-
finally { if (
|
|
19697
|
+
finally { if (e_45) throw e_45.error; }
|
|
19411
19698
|
return [7 /*endfinally*/];
|
|
19412
19699
|
case 11:
|
|
19413
19700
|
if (firstNestedGitRoot) {
|
|
@@ -19476,9 +19763,11 @@ var AI_ASSISTANT_ROUTE_LOOKUP_PATTERNS = [
|
|
|
19476
19763
|
/\broutes?\s+(?:path|screen|page)\b/,
|
|
19477
19764
|
/\bwhat(?:['’]s| is)\s+the\s+route\b/,
|
|
19478
19765
|
/\bwhere\b.*\b(route|screen|page)\b/,
|
|
19479
|
-
/\bwhere\b.*\b(list|detail|dashboard|menu)\b/,
|
|
19480
|
-
/\
|
|
19481
|
-
/\bwhere
|
|
19766
|
+
/\bwhere\b.*\b(list|listed|listing|detail|dashboard|menu)\b/,
|
|
19767
|
+
/\bshow\s+me\b.*\b(list|listing|page|screen|route|menu)\b/,
|
|
19768
|
+
/\bwhere do i\s+(?:go|find|open|set|change|update|configure)\b/,
|
|
19769
|
+
/\bwhere can i\s+(?:go|find|open|set|change|update|configure)\b/,
|
|
19770
|
+
/\bhow (?:do|can) i\s+(?:set|change|update|configure|personalize)\b/,
|
|
19482
19771
|
/\bpath\b/,
|
|
19483
19772
|
/\bscreen\b/,
|
|
19484
19773
|
/\bpage\b/,
|
|
@@ -19813,7 +20102,7 @@ var AI_ASSISTANT_BREAKDOWN_DIMENSION_STOPWORDS = new Set([
|
|
|
19813
20102
|
'by'
|
|
19814
20103
|
]);
|
|
19815
20104
|
function normalizeAssistantBreakdownDimension(value) {
|
|
19816
|
-
var
|
|
20105
|
+
var e_46, _a;
|
|
19817
20106
|
var normalized = normalizeOptionalString(value)
|
|
19818
20107
|
.toLowerCase()
|
|
19819
20108
|
.replace(/[^a-z0-9_\s-]+/g, ' ')
|
|
@@ -19845,12 +20134,12 @@ function normalizeAssistantBreakdownDimension(value) {
|
|
|
19845
20134
|
}
|
|
19846
20135
|
}
|
|
19847
20136
|
}
|
|
19848
|
-
catch (
|
|
20137
|
+
catch (e_46_1) { e_46 = { error: e_46_1 }; }
|
|
19849
20138
|
finally {
|
|
19850
20139
|
try {
|
|
19851
20140
|
if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
|
|
19852
20141
|
}
|
|
19853
|
-
finally { if (
|
|
20142
|
+
finally { if (e_46) throw e_46.error; }
|
|
19854
20143
|
}
|
|
19855
20144
|
if (!kept.length) {
|
|
19856
20145
|
return '';
|
|
@@ -20055,7 +20344,7 @@ function resolveAssistantPlannerEnabled(config) {
|
|
|
20055
20344
|
return raw === undefined ? false : raw === true;
|
|
20056
20345
|
}
|
|
20057
20346
|
function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
|
|
20058
|
-
var
|
|
20347
|
+
var e_47, _a;
|
|
20059
20348
|
var _b;
|
|
20060
20349
|
if (isSuperAdmin === void 0) { isSuperAdmin = false; }
|
|
20061
20350
|
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
@@ -20069,12 +20358,12 @@ function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
|
|
|
20069
20358
|
}
|
|
20070
20359
|
}
|
|
20071
20360
|
}
|
|
20072
|
-
catch (
|
|
20361
|
+
catch (e_47_1) { e_47 = { error: e_47_1 }; }
|
|
20073
20362
|
finally {
|
|
20074
20363
|
try {
|
|
20075
20364
|
if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
|
|
20076
20365
|
}
|
|
20077
|
-
finally { if (
|
|
20366
|
+
finally { if (e_47) throw e_47.error; }
|
|
20078
20367
|
}
|
|
20079
20368
|
var normalizedRoutes = Array.from(unique);
|
|
20080
20369
|
var allowedRoutes = collectAssistantAllowedRoutesForUser(user, normalizedRoutes, isSuperAdmin);
|
|
@@ -20315,22 +20604,14 @@ function buildAssistantFieldHints(message, collectionNames, options) {
|
|
|
20315
20604
|
return [];
|
|
20316
20605
|
}
|
|
20317
20606
|
var baseTokens = tokenizeFieldKey(normalizedMessage);
|
|
20318
|
-
var expandedTokens = expandFieldTokens(baseTokens);
|
|
20607
|
+
var expandedTokens = expandFieldTokens(baseTokens, options === null || options === void 0 ? void 0 : options.appId);
|
|
20319
20608
|
var tokenSet = new Set(expandedTokens);
|
|
20320
20609
|
[
|
|
20321
20610
|
'date',
|
|
20322
20611
|
'status',
|
|
20323
20612
|
'total',
|
|
20324
20613
|
'amount',
|
|
20325
|
-
'
|
|
20326
|
-
'balance',
|
|
20327
|
-
'grand',
|
|
20328
|
-
'subtotal',
|
|
20329
|
-
'invoice',
|
|
20330
|
-
'revenue',
|
|
20331
|
-
'sales',
|
|
20332
|
-
'billing',
|
|
20333
|
-
'payment'
|
|
20614
|
+
'balance'
|
|
20334
20615
|
].forEach(function (token) { return tokenSet.add(token); });
|
|
20335
20616
|
var hints = [];
|
|
20336
20617
|
var candidates = collectionNames.filter(Boolean).slice(0, maxCollections);
|
|
@@ -20441,6 +20722,10 @@ function buildAssistantSchemaHints(collectionNames, options) {
|
|
|
20441
20722
|
});
|
|
20442
20723
|
return hints;
|
|
20443
20724
|
}
|
|
20725
|
+
var AI_ASSISTANT_CORE_PUBLIC_ROUTES = [
|
|
20726
|
+
'/home',
|
|
20727
|
+
'/user-settings/settings'
|
|
20728
|
+
];
|
|
20444
20729
|
var cachedClientRouteIndex = null;
|
|
20445
20730
|
function normalizeRouteKey(value) {
|
|
20446
20731
|
var trimmed = normalizeOptionalString(value);
|
|
@@ -20454,9 +20739,9 @@ function normalizeRouteMatchKey(value) {
|
|
|
20454
20739
|
return normalizeRouteKey(value).toLowerCase();
|
|
20455
20740
|
}
|
|
20456
20741
|
function buildClientRouteIndex() {
|
|
20457
|
-
var
|
|
20742
|
+
var e_48, _a;
|
|
20458
20743
|
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)) || [];
|
|
20744
|
+
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
20745
|
var set = new Set();
|
|
20461
20746
|
var map = new Map();
|
|
20462
20747
|
try {
|
|
@@ -20473,18 +20758,18 @@ function buildClientRouteIndex() {
|
|
|
20473
20758
|
}
|
|
20474
20759
|
}
|
|
20475
20760
|
}
|
|
20476
|
-
catch (
|
|
20761
|
+
catch (e_48_1) { e_48 = { error: e_48_1 }; }
|
|
20477
20762
|
finally {
|
|
20478
20763
|
try {
|
|
20479
20764
|
if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
|
|
20480
20765
|
}
|
|
20481
|
-
finally { if (
|
|
20766
|
+
finally { if (e_48) throw e_48.error; }
|
|
20482
20767
|
}
|
|
20483
20768
|
return { set: set, map: map, size: routes.length };
|
|
20484
20769
|
}
|
|
20485
20770
|
function getClientRouteIndex() {
|
|
20486
20771
|
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)) || [];
|
|
20772
|
+
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
20773
|
if (cachedClientRouteIndex && cachedClientRouteIndex.size === routes.length) {
|
|
20489
20774
|
return cachedClientRouteIndex;
|
|
20490
20775
|
}
|
|
@@ -20645,6 +20930,7 @@ function collectAssistantAllowedRoutesForUser(user, allRoutes, isSuperAdmin) {
|
|
|
20645
20930
|
allowed.push(normalized);
|
|
20646
20931
|
};
|
|
20647
20932
|
var allRouteEntries = normalizedRoutes.map(function (route) { return ({ route: route }); });
|
|
20933
|
+
AI_ASSISTANT_CORE_PUBLIC_ROUTES.forEach(push);
|
|
20648
20934
|
views.forEach(function (view) {
|
|
20649
20935
|
var canonical = normalizedRoutes.find(function (route) { return normalizeRouteMatchKey(route) === normalizeRouteMatchKey(view); });
|
|
20650
20936
|
if (canonical) {
|
|
@@ -20668,6 +20954,79 @@ function resolveAssistantAllowedRoutesForUser(user, isSuperAdmin) {
|
|
|
20668
20954
|
var allRoutes = Array.from(index.map.values());
|
|
20669
20955
|
return collectAssistantAllowedRoutesForUser(user, allRoutes, isSuperAdmin);
|
|
20670
20956
|
}
|
|
20957
|
+
function scoreAssistantAppRouteIntent(messageText, intent) {
|
|
20958
|
+
var _a, _b;
|
|
20959
|
+
var text = normalizeOptionalString(messageText).toLowerCase();
|
|
20960
|
+
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)) {
|
|
20961
|
+
return 0;
|
|
20962
|
+
}
|
|
20963
|
+
var excluded = (intent.excludeTerms || []).some(function (term) { return containsAssistantHeuristicTerm(text, term); });
|
|
20964
|
+
if (excluded) {
|
|
20965
|
+
return 0;
|
|
20966
|
+
}
|
|
20967
|
+
var score = 0;
|
|
20968
|
+
(intent.terms || []).forEach(function (term) {
|
|
20969
|
+
var normalizedTerm = normalizeOptionalString(term).toLowerCase();
|
|
20970
|
+
if (!normalizedTerm) {
|
|
20971
|
+
return;
|
|
20972
|
+
}
|
|
20973
|
+
if (containsAssistantHeuristicTerm(text, normalizedTerm)) {
|
|
20974
|
+
score += normalizedTerm.includes(' ') ? 26 : 14;
|
|
20975
|
+
return;
|
|
20976
|
+
}
|
|
20977
|
+
var key = normalizeCollectionKey(normalizedTerm);
|
|
20978
|
+
if (key && normalizeCollectionKey(text).includes(key) && key.length >= 5) {
|
|
20979
|
+
score += 10;
|
|
20980
|
+
}
|
|
20981
|
+
});
|
|
20982
|
+
return score;
|
|
20983
|
+
}
|
|
20984
|
+
function resolveAssistantAppRouteIntentMatch(params) {
|
|
20985
|
+
var allowedRoutes = mergeAssistantHintValues(params.allowedRoutes || []);
|
|
20986
|
+
if (!allowedRoutes.length) {
|
|
20987
|
+
return null;
|
|
20988
|
+
}
|
|
20989
|
+
var profile = resolveAssistantAppHeuristicProfile(params.appId);
|
|
20990
|
+
var routeIntents = Array.isArray(profile.routeIntents) ? profile.routeIntents : [];
|
|
20991
|
+
if (!routeIntents.length) {
|
|
20992
|
+
return null;
|
|
20993
|
+
}
|
|
20994
|
+
var selected = null;
|
|
20995
|
+
routeIntents.forEach(function (intent) {
|
|
20996
|
+
var score = scoreAssistantAppRouteIntent(params.message, intent);
|
|
20997
|
+
if (score < 14) {
|
|
20998
|
+
return;
|
|
20999
|
+
}
|
|
21000
|
+
var resolvedRoutes = mergeAssistantHintValues((intent.routes || [])
|
|
21001
|
+
.map(function (route) { return resolveAssistantBestAllowedRoute(route, allowedRoutes); })
|
|
21002
|
+
.filter(function (route) { return !!route; }));
|
|
21003
|
+
if (!resolvedRoutes.length) {
|
|
21004
|
+
return;
|
|
21005
|
+
}
|
|
21006
|
+
if (!selected || score > selected.score) {
|
|
21007
|
+
selected = {
|
|
21008
|
+
routes: resolvedRoutes.slice(0, 3),
|
|
21009
|
+
response: normalizeOptionalString(intent.response) || undefined,
|
|
21010
|
+
score: score
|
|
21011
|
+
};
|
|
21012
|
+
}
|
|
21013
|
+
});
|
|
21014
|
+
return selected ? {
|
|
21015
|
+
routes: selected.routes,
|
|
21016
|
+
response: selected.response
|
|
21017
|
+
} : null;
|
|
21018
|
+
}
|
|
21019
|
+
function formatAssistantNavigationRouteResponse(routes, singleIntro, multiIntro) {
|
|
21020
|
+
var normalizedRoutes = mergeAssistantHintValues(routes || []);
|
|
21021
|
+
var lines = [normalizedRoutes.length === 1 ? singleIntro : multiIntro];
|
|
21022
|
+
normalizedRoutes.forEach(function (route, index) {
|
|
21023
|
+
if (normalizedRoutes.length > 1) {
|
|
21024
|
+
lines.push("".concat(index + 1, ". ").concat(formatAssistantRouteLabel(route)));
|
|
21025
|
+
}
|
|
21026
|
+
lines.push(route);
|
|
21027
|
+
});
|
|
21028
|
+
return lines.join('\n');
|
|
21029
|
+
}
|
|
20671
21030
|
function rankAssistantNavigationRoutes(message, routes, limit) {
|
|
20672
21031
|
if (limit === void 0) { limit = 3; }
|
|
20673
21032
|
var normalizedMessage = normalizeOptionalString(message).toLowerCase();
|
|
@@ -20680,6 +21039,7 @@ function rankAssistantNavigationRoutes(message, routes, limit) {
|
|
|
20680
21039
|
}
|
|
20681
21040
|
var explicitRoutes = extractAssistantRouteMentions(normalizedMessage);
|
|
20682
21041
|
var queryTokens = tokenizeAssistantRouteQuery(normalizedMessage);
|
|
21042
|
+
var listIntent = /\b(list|listing|listings|directory|index|table|grid)\b/.test(normalizedMessage);
|
|
20683
21043
|
var scored = dedupedRoutes
|
|
20684
21044
|
.map(function (route) {
|
|
20685
21045
|
var routeKey = route.toLowerCase();
|
|
@@ -20702,8 +21062,11 @@ function rankAssistantNavigationRoutes(message, routes, limit) {
|
|
|
20702
21062
|
score += 7;
|
|
20703
21063
|
}
|
|
20704
21064
|
});
|
|
20705
|
-
if (
|
|
20706
|
-
score +=
|
|
21065
|
+
if (listIntent && routeTokens.includes('list')) {
|
|
21066
|
+
score += 20;
|
|
21067
|
+
}
|
|
21068
|
+
if (listIntent && routeTokens.some(function (token) { return token === 'new' || token === 'edit' || token === 'detail' || token === 'delete'; })) {
|
|
21069
|
+
score -= 8;
|
|
20707
21070
|
}
|
|
20708
21071
|
if (/\bdetail\b/.test(normalizedMessage) && routeTokens.includes('detail')) {
|
|
20709
21072
|
score += 8;
|
|
@@ -20731,6 +21094,19 @@ function rankAssistantNavigationRoutes(message, routes, limit) {
|
|
|
20731
21094
|
});
|
|
20732
21095
|
return scored.slice(0, limit).map(function (entry) { return entry.route; });
|
|
20733
21096
|
}
|
|
21097
|
+
function isAssistantContextDependentRouteLookup(message) {
|
|
21098
|
+
var text = normalizeOptionalString(message).toLowerCase();
|
|
21099
|
+
if (!text) {
|
|
21100
|
+
return false;
|
|
21101
|
+
}
|
|
21102
|
+
if (extractAssistantRouteMentions(text).length) {
|
|
21103
|
+
return false;
|
|
21104
|
+
}
|
|
21105
|
+
var hasContextReference = /\b(this|that|these|those|it|same)\b/.test(text);
|
|
21106
|
+
var hasReferencedSubject = /\b(info|information|data|result|results|records?|items?|dashboard|page|screen|view)\b/.test(text);
|
|
21107
|
+
var asksForNavigation = /\b(where|which|what|dashboard|page|screen|route|path|link|menu)\b/.test(text);
|
|
21108
|
+
return hasContextReference && hasReferencedSubject && asksForNavigation;
|
|
21109
|
+
}
|
|
20734
21110
|
function shouldUseAssistantNavigationFastPath(message, hasAttachments) {
|
|
20735
21111
|
if (hasAttachments === void 0) { hasAttachments = false; }
|
|
20736
21112
|
if (hasAttachments) {
|
|
@@ -20749,9 +21125,13 @@ function shouldUseAssistantNavigationFastPath(message, hasAttachments) {
|
|
|
20749
21125
|
if (!isAssistantRouteLookupQuestion(text)) {
|
|
20750
21126
|
return false;
|
|
20751
21127
|
}
|
|
21128
|
+
if (isAssistantContextDependentRouteLookup(text)) {
|
|
21129
|
+
return false;
|
|
21130
|
+
}
|
|
20752
21131
|
return !isAssistantStrongDataQuestion(text);
|
|
20753
21132
|
}
|
|
20754
21133
|
function evaluateAssistantNavigationFastPathWithRoutes(params) {
|
|
21134
|
+
var _a;
|
|
20755
21135
|
if (!shouldUseAssistantNavigationFastPath(params.message, params.hasAttachments)) {
|
|
20756
21136
|
return null;
|
|
20757
21137
|
}
|
|
@@ -20796,6 +21176,22 @@ function evaluateAssistantNavigationFastPathWithRoutes(params) {
|
|
|
20796
21176
|
reason: 'permission_denied'
|
|
20797
21177
|
};
|
|
20798
21178
|
}
|
|
21179
|
+
var appRouteIntent = resolveAssistantAppRouteIntentMatch({
|
|
21180
|
+
message: params.message,
|
|
21181
|
+
allowedRoutes: allowedRoutes,
|
|
21182
|
+
appId: params.appId
|
|
21183
|
+
});
|
|
21184
|
+
if ((_a = appRouteIntent === null || appRouteIntent === void 0 ? void 0 : appRouteIntent.routes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
21185
|
+
var routeText = formatAssistantNavigationRouteResponse(appRouteIntent.routes, 'Use this in-app route:', 'Use one of these in-app routes:');
|
|
21186
|
+
var response = appRouteIntent.response
|
|
21187
|
+
? "".concat(appRouteIntent.response, "\n").concat(routeText)
|
|
21188
|
+
: routeText;
|
|
21189
|
+
return {
|
|
21190
|
+
response: response,
|
|
21191
|
+
routes: appRouteIntent.routes,
|
|
21192
|
+
reason: 'app_route_intent'
|
|
21193
|
+
};
|
|
21194
|
+
}
|
|
20799
21195
|
var ranked = rankAssistantNavigationRoutes(params.message, allowedRoutes, 3);
|
|
20800
21196
|
if (!ranked.length) {
|
|
20801
21197
|
var contextRoute = normalizeRouteKey(params.contextRoute || '');
|
|
@@ -20828,7 +21224,8 @@ function resolveAssistantNavigationFastPathResponse(params) {
|
|
|
20828
21224
|
message: params.message,
|
|
20829
21225
|
hasAttachments: params.hasAttachments,
|
|
20830
21226
|
allowedRoutes: allowedRoutes,
|
|
20831
|
-
contextRoute: params.contextRoute
|
|
21227
|
+
contextRoute: params.contextRoute,
|
|
21228
|
+
appId: params.appId
|
|
20832
21229
|
});
|
|
20833
21230
|
}
|
|
20834
21231
|
var AI_ASSISTANT_CHANGE_HISTORY_PATTERNS = [
|
|
@@ -21257,8 +21654,8 @@ function shouldSkipAssistantGitDiscoveryDirectory(name) {
|
|
|
21257
21654
|
}
|
|
21258
21655
|
function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
21259
21656
|
return __awaiter(this, void 0, void 0, function () {
|
|
21260
|
-
var roots, seen, push, _a, configuredRoots, configuredRoots_1, configuredRoots_1_1, configuredRoot, _b,
|
|
21261
|
-
var
|
|
21657
|
+
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;
|
|
21658
|
+
var e_49, _e, e_50, _f;
|
|
21262
21659
|
var _g;
|
|
21263
21660
|
return __generator(this, function (_h) {
|
|
21264
21661
|
switch (_h.label) {
|
|
@@ -21303,14 +21700,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
21303
21700
|
return [3 /*break*/, 3];
|
|
21304
21701
|
case 6: return [3 /*break*/, 9];
|
|
21305
21702
|
case 7:
|
|
21306
|
-
|
|
21307
|
-
|
|
21703
|
+
e_49_1 = _h.sent();
|
|
21704
|
+
e_49 = { error: e_49_1 };
|
|
21308
21705
|
return [3 /*break*/, 9];
|
|
21309
21706
|
case 8:
|
|
21310
21707
|
try {
|
|
21311
21708
|
if (configuredRoots_1_1 && !configuredRoots_1_1.done && (_e = configuredRoots_1.return)) _e.call(configuredRoots_1);
|
|
21312
21709
|
}
|
|
21313
|
-
finally { if (
|
|
21710
|
+
finally { if (e_49) throw e_49.error; }
|
|
21314
21711
|
return [7 /*endfinally*/];
|
|
21315
21712
|
case 9:
|
|
21316
21713
|
queue = [];
|
|
@@ -21350,7 +21747,7 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
21350
21747
|
return [3 /*break*/, 14];
|
|
21351
21748
|
case 14:
|
|
21352
21749
|
_h.trys.push([14, 21, 22, 23]);
|
|
21353
|
-
entries_1 = (
|
|
21750
|
+
entries_1 = (e_50 = void 0, __values(entries)), entries_1_1 = entries_1.next();
|
|
21354
21751
|
_h.label = 15;
|
|
21355
21752
|
case 15:
|
|
21356
21753
|
if (!!entries_1_1.done) return [3 /*break*/, 20];
|
|
@@ -21389,14 +21786,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
21389
21786
|
return [3 /*break*/, 15];
|
|
21390
21787
|
case 20: return [3 /*break*/, 23];
|
|
21391
21788
|
case 21:
|
|
21392
|
-
|
|
21393
|
-
|
|
21789
|
+
e_50_1 = _h.sent();
|
|
21790
|
+
e_50 = { error: e_50_1 };
|
|
21394
21791
|
return [3 /*break*/, 23];
|
|
21395
21792
|
case 22:
|
|
21396
21793
|
try {
|
|
21397
21794
|
if (entries_1_1 && !entries_1_1.done && (_f = entries_1.return)) _f.call(entries_1);
|
|
21398
21795
|
}
|
|
21399
|
-
finally { if (
|
|
21796
|
+
finally { if (e_50) throw e_50.error; }
|
|
21400
21797
|
return [7 /*endfinally*/];
|
|
21401
21798
|
case 23: return [3 /*break*/, 10];
|
|
21402
21799
|
case 24: return [2 /*return*/, roots];
|
|
@@ -21736,8 +22133,8 @@ function syncAssistantGitMirror(repoUrl) {
|
|
|
21736
22133
|
}
|
|
21737
22134
|
function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
21738
22135
|
return __awaiter(this, void 0, void 0, function () {
|
|
21739
|
-
var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot,
|
|
21740
|
-
var
|
|
22136
|
+
var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot, e_51_1;
|
|
22137
|
+
var e_51, _a;
|
|
21741
22138
|
return __generator(this, function (_b) {
|
|
21742
22139
|
switch (_b.label) {
|
|
21743
22140
|
case 0: return [4 /*yield*/, resolveAssistantWorkspaceGitRoots(workspaceRoot)];
|
|
@@ -21771,14 +22168,14 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
|
21771
22168
|
return [3 /*break*/, 3];
|
|
21772
22169
|
case 6: return [3 /*break*/, 9];
|
|
21773
22170
|
case 7:
|
|
21774
|
-
|
|
21775
|
-
|
|
22171
|
+
e_51_1 = _b.sent();
|
|
22172
|
+
e_51 = { error: e_51_1 };
|
|
21776
22173
|
return [3 /*break*/, 9];
|
|
21777
22174
|
case 8:
|
|
21778
22175
|
try {
|
|
21779
22176
|
if (repoUrls_1_1 && !repoUrls_1_1.done && (_a = repoUrls_1.return)) _a.call(repoUrls_1);
|
|
21780
22177
|
}
|
|
21781
|
-
finally { if (
|
|
22178
|
+
finally { if (e_51) throw e_51.error; }
|
|
21782
22179
|
return [7 /*endfinally*/];
|
|
21783
22180
|
case 9: return [2 /*return*/, mirroredRoots];
|
|
21784
22181
|
}
|
|
@@ -21787,8 +22184,8 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
|
21787
22184
|
}
|
|
21788
22185
|
function resolveAssistantChangeHistoryFastPathResponse(params) {
|
|
21789
22186
|
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
|
|
22187
|
+
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;
|
|
22188
|
+
var e_52, _f;
|
|
21792
22189
|
return __generator(this, function (_g) {
|
|
21793
22190
|
switch (_g.label) {
|
|
21794
22191
|
case 0:
|
|
@@ -21910,14 +22307,14 @@ function resolveAssistantChangeHistoryFastPathResponse(params) {
|
|
|
21910
22307
|
return [3 /*break*/, 7];
|
|
21911
22308
|
case 20: return [3 /*break*/, 23];
|
|
21912
22309
|
case 21:
|
|
21913
|
-
|
|
21914
|
-
|
|
22310
|
+
e_52_1 = _g.sent();
|
|
22311
|
+
e_52 = { error: e_52_1 };
|
|
21915
22312
|
return [3 /*break*/, 23];
|
|
21916
22313
|
case 22:
|
|
21917
22314
|
try {
|
|
21918
22315
|
if (gitRoots_1_1 && !gitRoots_1_1.done && (_f = gitRoots_1.return)) _f.call(gitRoots_1);
|
|
21919
22316
|
}
|
|
21920
|
-
finally { if (
|
|
22317
|
+
finally { if (e_52) throw e_52.error; }
|
|
21921
22318
|
return [7 /*endfinally*/];
|
|
21922
22319
|
case 23:
|
|
21923
22320
|
if (bestFallback) {
|
|
@@ -22098,7 +22495,7 @@ function sanitizeAssistantResponse(value) {
|
|
|
22098
22495
|
return normalizeAssistantRoutes(normalizedCurrency);
|
|
22099
22496
|
}
|
|
22100
22497
|
function evaluateAssistantGuardrails(message) {
|
|
22101
|
-
var
|
|
22498
|
+
var e_53, _a;
|
|
22102
22499
|
var normalized = String(message || '').toLowerCase();
|
|
22103
22500
|
var identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(normalized);
|
|
22104
22501
|
if (identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked) {
|
|
@@ -22143,12 +22540,12 @@ function evaluateAssistantGuardrails(message) {
|
|
|
22143
22540
|
}
|
|
22144
22541
|
}
|
|
22145
22542
|
}
|
|
22146
|
-
catch (
|
|
22543
|
+
catch (e_53_1) { e_53 = { error: e_53_1 }; }
|
|
22147
22544
|
finally {
|
|
22148
22545
|
try {
|
|
22149
22546
|
if (patterns_2_1 && !patterns_2_1.done && (_a = patterns_2.return)) _a.call(patterns_2);
|
|
22150
22547
|
}
|
|
22151
|
-
finally { if (
|
|
22548
|
+
finally { if (e_53) throw e_53.error; }
|
|
22152
22549
|
}
|
|
22153
22550
|
return null;
|
|
22154
22551
|
}
|
|
@@ -22253,7 +22650,7 @@ function tokenizeArithmeticExpression(expression) {
|
|
|
22253
22650
|
return tokens;
|
|
22254
22651
|
}
|
|
22255
22652
|
function evaluateArithmeticExpression(expression) {
|
|
22256
|
-
var
|
|
22653
|
+
var e_54, _a, e_55, _b;
|
|
22257
22654
|
var tokens = tokenizeArithmeticExpression(expression);
|
|
22258
22655
|
if (!tokens || !tokens.length) {
|
|
22259
22656
|
return null;
|
|
@@ -22310,12 +22707,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
22310
22707
|
prevToken = token;
|
|
22311
22708
|
}
|
|
22312
22709
|
}
|
|
22313
|
-
catch (
|
|
22710
|
+
catch (e_54_1) { e_54 = { error: e_54_1 }; }
|
|
22314
22711
|
finally {
|
|
22315
22712
|
try {
|
|
22316
22713
|
if (tokens_2_1 && !tokens_2_1.done && (_a = tokens_2.return)) _a.call(tokens_2);
|
|
22317
22714
|
}
|
|
22318
|
-
finally { if (
|
|
22715
|
+
finally { if (e_54) throw e_54.error; }
|
|
22319
22716
|
}
|
|
22320
22717
|
while (ops.length) {
|
|
22321
22718
|
var op = ops.pop();
|
|
@@ -22355,12 +22752,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
22355
22752
|
stack.push(Number(token));
|
|
22356
22753
|
}
|
|
22357
22754
|
}
|
|
22358
|
-
catch (
|
|
22755
|
+
catch (e_55_1) { e_55 = { error: e_55_1 }; }
|
|
22359
22756
|
finally {
|
|
22360
22757
|
try {
|
|
22361
22758
|
if (output_1_1 && !output_1_1.done && (_b = output_1.return)) _b.call(output_1);
|
|
22362
22759
|
}
|
|
22363
|
-
finally { if (
|
|
22760
|
+
finally { if (e_55) throw e_55.error; }
|
|
22364
22761
|
}
|
|
22365
22762
|
if (stack.length !== 1 || Number.isNaN(stack[0])) {
|
|
22366
22763
|
return null;
|
|
@@ -22544,8 +22941,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
|
|
|
22544
22941
|
}
|
|
22545
22942
|
function readAttachmentContents(attachments) {
|
|
22546
22943
|
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
|
|
22944
|
+
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;
|
|
22945
|
+
var e_56, _b;
|
|
22549
22946
|
return __generator(this, function (_c) {
|
|
22550
22947
|
switch (_c.label) {
|
|
22551
22948
|
case 0:
|
|
@@ -22624,14 +23021,14 @@ function readAttachmentContents(attachments) {
|
|
|
22624
23021
|
return [3 /*break*/, 2];
|
|
22625
23022
|
case 10: return [3 /*break*/, 13];
|
|
22626
23023
|
case 11:
|
|
22627
|
-
|
|
22628
|
-
|
|
23024
|
+
e_56_1 = _c.sent();
|
|
23025
|
+
e_56 = { error: e_56_1 };
|
|
22629
23026
|
return [3 /*break*/, 13];
|
|
22630
23027
|
case 12:
|
|
22631
23028
|
try {
|
|
22632
23029
|
if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
|
|
22633
23030
|
}
|
|
22634
|
-
finally { if (
|
|
23031
|
+
finally { if (e_56) throw e_56.error; }
|
|
22635
23032
|
return [7 /*endfinally*/];
|
|
22636
23033
|
case 13: return [2 /*return*/, {
|
|
22637
23034
|
promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
|
|
@@ -22710,6 +23107,7 @@ function sanitizeConfig(source) {
|
|
|
22710
23107
|
.map(function (entry) { return normalizeOptionalString(entry); })
|
|
22711
23108
|
.filter(Boolean),
|
|
22712
23109
|
system_prompt: normalizeOptionalString(source === null || source === void 0 ? void 0 : source.system_prompt),
|
|
23110
|
+
system_prompt_additions: resolveAssistantSystemPromptAdditions(source),
|
|
22713
23111
|
user_prompt_template: normalizeOptionalString(source === null || source === void 0 ? void 0 : source.user_prompt_template),
|
|
22714
23112
|
response_format: normalizeOptionalString(source === null || source === void 0 ? void 0 : source.response_format),
|
|
22715
23113
|
temperature: normalizeOptionalNumber(source === null || source === void 0 ? void 0 : source.temperature),
|
|
@@ -22841,7 +23239,7 @@ function resolveAssistantDatabaseNameForSystemCollections() {
|
|
|
22841
23239
|
}
|
|
22842
23240
|
function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
22843
23241
|
return __awaiter(this, void 0, void 0, function () {
|
|
22844
|
-
var safeSetPayload, fallbackId, debugEnabled, result,
|
|
23242
|
+
var safeSetPayload, fallbackId, debugEnabled, result, error_17, dbName, messagesCollection, result, _a, retryResult;
|
|
22845
23243
|
var _b, _c, _d, _e, _f, _g;
|
|
22846
23244
|
return __generator(this, function (_h) {
|
|
22847
23245
|
switch (_h.label) {
|
|
@@ -22880,14 +23278,14 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
22880
23278
|
}
|
|
22881
23279
|
return [2 /*return*/];
|
|
22882
23280
|
case 5:
|
|
22883
|
-
|
|
22884
|
-
if (!isAssistantTransactionCommittedError(
|
|
22885
|
-
throw
|
|
23281
|
+
error_17 = _h.sent();
|
|
23282
|
+
if (!isAssistantTransactionCommittedError(error_17)) {
|
|
23283
|
+
throw error_17;
|
|
22886
23284
|
}
|
|
22887
23285
|
if (debugEnabled) {
|
|
22888
23286
|
console.log(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update fallback triggered', {
|
|
22889
23287
|
messageId: fallbackId || messageId,
|
|
22890
|
-
reason: normalizeOptionalString(
|
|
23288
|
+
reason: normalizeOptionalString(error_17 === null || error_17 === void 0 ? void 0 : error_17.message) || 'transaction_committed'
|
|
22891
23289
|
});
|
|
22892
23290
|
}
|
|
22893
23291
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
@@ -22963,7 +23361,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
22963
23361
|
}
|
|
22964
23362
|
function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
22965
23363
|
return __awaiter(this, void 0, void 0, function () {
|
|
22966
|
-
var update, result,
|
|
23364
|
+
var update, result, error_18, dbName, conversationsCollection, fallbackResult;
|
|
22967
23365
|
return __generator(this, function (_a) {
|
|
22968
23366
|
switch (_a.label) {
|
|
22969
23367
|
case 0:
|
|
@@ -22988,9 +23386,9 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
22988
23386
|
}
|
|
22989
23387
|
return [2 /*return*/];
|
|
22990
23388
|
case 3:
|
|
22991
|
-
|
|
22992
|
-
if (!isAssistantTransactionCommittedError(
|
|
22993
|
-
throw
|
|
23389
|
+
error_18 = _a.sent();
|
|
23390
|
+
if (!isAssistantTransactionCommittedError(error_18)) {
|
|
23391
|
+
throw error_18;
|
|
22994
23392
|
}
|
|
22995
23393
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
22996
23394
|
conversationsCollection = resolveio_server_app_1.ResolveIOServer.getMongoConnection()
|
|
@@ -23055,7 +23453,7 @@ function sanitizeAssistantMessageSetPayload(setPayload) {
|
|
|
23055
23453
|
return next;
|
|
23056
23454
|
}
|
|
23057
23455
|
function sanitizeMongoSafeObject(value) {
|
|
23058
|
-
var
|
|
23456
|
+
var e_57, _a;
|
|
23059
23457
|
if (value === null || value === undefined) {
|
|
23060
23458
|
return value;
|
|
23061
23459
|
}
|
|
@@ -23079,17 +23477,17 @@ function sanitizeMongoSafeObject(value) {
|
|
|
23079
23477
|
out[key] = sanitizeMongoSafeObject(rawValue);
|
|
23080
23478
|
}
|
|
23081
23479
|
}
|
|
23082
|
-
catch (
|
|
23480
|
+
catch (e_57_1) { e_57 = { error: e_57_1 }; }
|
|
23083
23481
|
finally {
|
|
23084
23482
|
try {
|
|
23085
23483
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
23086
23484
|
}
|
|
23087
|
-
finally { if (
|
|
23485
|
+
finally { if (e_57) throw e_57.error; }
|
|
23088
23486
|
}
|
|
23089
23487
|
return out;
|
|
23090
23488
|
}
|
|
23091
23489
|
function restoreMongoSafeObject(value) {
|
|
23092
|
-
var
|
|
23490
|
+
var e_58, _a;
|
|
23093
23491
|
if (value === null || value === undefined) {
|
|
23094
23492
|
return value;
|
|
23095
23493
|
}
|
|
@@ -23113,12 +23511,12 @@ function restoreMongoSafeObject(value) {
|
|
|
23113
23511
|
out[key] = restoreMongoSafeObject(rawValue);
|
|
23114
23512
|
}
|
|
23115
23513
|
}
|
|
23116
|
-
catch (
|
|
23514
|
+
catch (e_58_1) { e_58 = { error: e_58_1 }; }
|
|
23117
23515
|
finally {
|
|
23118
23516
|
try {
|
|
23119
23517
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
23120
23518
|
}
|
|
23121
|
-
finally { if (
|
|
23519
|
+
finally { if (e_58) throw e_58.error; }
|
|
23122
23520
|
}
|
|
23123
23521
|
return out;
|
|
23124
23522
|
}
|
|
@@ -23262,7 +23660,7 @@ function buildAssistantAIRunId(prefix, parts) {
|
|
|
23262
23660
|
}
|
|
23263
23661
|
function recordAssistantAnswerAIRun(input) {
|
|
23264
23662
|
return __awaiter(this, void 0, void 0, function () {
|
|
23265
|
-
var messages, run,
|
|
23663
|
+
var messages, run, error_19;
|
|
23266
23664
|
return __generator(this, function (_a) {
|
|
23267
23665
|
switch (_a.label) {
|
|
23268
23666
|
case 0:
|
|
@@ -23287,8 +23685,8 @@ function recordAssistantAnswerAIRun(input) {
|
|
|
23287
23685
|
_a.sent();
|
|
23288
23686
|
return [3 /*break*/, 3];
|
|
23289
23687
|
case 2:
|
|
23290
|
-
|
|
23291
|
-
console.error(new Date(), 'Failed to record AI assistant AIRun evidence',
|
|
23688
|
+
error_19 = _a.sent();
|
|
23689
|
+
console.error(new Date(), 'Failed to record AI assistant AIRun evidence', error_19);
|
|
23292
23690
|
return [3 /*break*/, 3];
|
|
23293
23691
|
case 3: return [2 /*return*/];
|
|
23294
23692
|
}
|
|
@@ -23296,7 +23694,7 @@ function recordAssistantAnswerAIRun(input) {
|
|
|
23296
23694
|
});
|
|
23297
23695
|
}
|
|
23298
23696
|
function evaluateGuardrails(message) {
|
|
23299
|
-
var
|
|
23697
|
+
var e_59, _a;
|
|
23300
23698
|
var normalized = String(message || '').toLowerCase();
|
|
23301
23699
|
var identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(normalized);
|
|
23302
23700
|
if (identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked) {
|
|
@@ -23322,12 +23720,12 @@ function evaluateGuardrails(message) {
|
|
|
23322
23720
|
}
|
|
23323
23721
|
}
|
|
23324
23722
|
}
|
|
23325
|
-
catch (
|
|
23723
|
+
catch (e_59_1) { e_59 = { error: e_59_1 }; }
|
|
23326
23724
|
finally {
|
|
23327
23725
|
try {
|
|
23328
23726
|
if (patterns_3_1 && !patterns_3_1.done && (_a = patterns_3.return)) _a.call(patterns_3);
|
|
23329
23727
|
}
|
|
23330
|
-
finally { if (
|
|
23728
|
+
finally { if (e_59) throw e_59.error; }
|
|
23331
23729
|
}
|
|
23332
23730
|
return null;
|
|
23333
23731
|
}
|