@resolveio/server-lib 22.3.202 → 22.3.204
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 +77 -1
- package/methods/ai-terminal.js +1131 -367
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +1 -1
- package/util/ai-runner-qa-tools.js +39 -10
- package/util/ai-runner-qa-tools.js.map +1 -1
- package/util/support-runner-v5.js +28 -2
- package/util/support-runner-v5.js.map +1 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -114,6 +114,7 @@ exports.shouldPreserveAssistantProbeCollectionForTesting = shouldPreserveAssista
|
|
|
114
114
|
exports.buildAssistantAnswerQualityFromExecution = buildAssistantAnswerQualityFromExecution;
|
|
115
115
|
exports.buildAssistantInvoiceCustomerLabelExpr = buildAssistantInvoiceCustomerLabelExpr;
|
|
116
116
|
exports.resolveAssistantHeuristicDirectiveForTesting = resolveAssistantHeuristicDirectiveForTesting;
|
|
117
|
+
exports.buildAssistantDataRequestClassifierMessagesForTesting = buildAssistantDataRequestClassifierMessagesForTesting;
|
|
117
118
|
exports.buildAssistantDatedPivotDisplay = buildAssistantDatedPivotDisplay;
|
|
118
119
|
exports.buildAssistantToolFallbackResponseForTesting = buildAssistantToolFallbackResponseForTesting;
|
|
119
120
|
exports.deriveAssistantCommandExecutionStatus = deriveAssistantCommandExecutionStatus;
|
|
@@ -183,6 +184,7 @@ var ai_terminal_issue_report_collection_1 = require("../collections/ai-terminal-
|
|
|
183
184
|
var common_1 = require("../util/common");
|
|
184
185
|
var tokenizer_1 = require("../util/tokenizer");
|
|
185
186
|
var codex_client_1 = require("../services/codex-client");
|
|
187
|
+
var openai_client_1 = require("../services/openai-client");
|
|
186
188
|
var openai_usage_ledger_manager_1 = require("../managers/openai-usage-ledger.manager");
|
|
187
189
|
var ai_run_evidence_manager_1 = require("../managers/ai-run-evidence.manager");
|
|
188
190
|
var assistant_core_heuristics_1 = require("../ai/assistant-core-heuristics");
|
|
@@ -1886,10 +1888,10 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1886
1888
|
insertResult = _d.sent();
|
|
1887
1889
|
assistantMessageId = (insertResult === null || insertResult === void 0 ? void 0 : insertResult._id) || (insertResult === null || insertResult === void 0 ? void 0 : insertResult.insertedId);
|
|
1888
1890
|
enqueueAssistantCodexRun(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
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,
|
|
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 (
|
|
1892
|
-
switch (
|
|
1891
|
+
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, appDataRequestClassifierDebug, appDataRequestClassifierIntent, appDataRequestClassifierUnderstanding, 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, scoredAppDataIntentCandidates, shouldAttemptAppDataClassifier, classifierResult, classifierUsageClientId, usageError_1, 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_2, finalAssistantDoc, setPayload, finalizeError_1, failedAt, fallbackContent, failureMetadata, persistError_1, _f;
|
|
1892
|
+
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, _19, _20;
|
|
1893
|
+
return __generator(this, function (_21) {
|
|
1894
|
+
switch (_21.label) {
|
|
1893
1895
|
case 0:
|
|
1894
1896
|
runStart = Date.now();
|
|
1895
1897
|
fastModeEnabled = resolveAssistantFastModeEnabled(input.config);
|
|
@@ -1994,6 +1996,9 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1994
1996
|
plannerSkipReason = '';
|
|
1995
1997
|
plannerOutput = null;
|
|
1996
1998
|
plannerRaw = '';
|
|
1999
|
+
appDataRequestClassifierDebug = null;
|
|
2000
|
+
appDataRequestClassifierIntent = null;
|
|
2001
|
+
appDataRequestClassifierUnderstanding = null;
|
|
1997
2002
|
timingBreakdown = {
|
|
1998
2003
|
plannerMs: 0,
|
|
1999
2004
|
directiveMs: 0,
|
|
@@ -2030,9 +2035,9 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2030
2035
|
source: requestClassification.source,
|
|
2031
2036
|
dataQuestion: dataQuestion
|
|
2032
2037
|
});
|
|
2033
|
-
|
|
2038
|
+
_21.label = 1;
|
|
2034
2039
|
case 1:
|
|
2035
|
-
|
|
2040
|
+
_21.trys.push([1, 76, 77, 78]);
|
|
2036
2041
|
hintSeed = [message, contextRoute].filter(Boolean).join(' ');
|
|
2037
2042
|
termExpansion = expandAssistantTermSynonyms(hintSeed);
|
|
2038
2043
|
hintText = termExpansion.expanded || hintSeed;
|
|
@@ -2053,19 +2058,19 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2053
2058
|
recordStep('Planning: term expansion', {
|
|
2054
2059
|
termMatches: termExpansion.matches.length ? termExpansion.matches : undefined
|
|
2055
2060
|
});
|
|
2056
|
-
|
|
2061
|
+
_21.label = 2;
|
|
2057
2062
|
case 2:
|
|
2058
|
-
|
|
2063
|
+
_21.trys.push([2, 5, , 6]);
|
|
2059
2064
|
dbName = resolveAssistantDatabaseName(undefined, input.mongo);
|
|
2060
2065
|
db = resolveio_server_app_1.ResolveIOServer.getMongoConnection().db(dbName);
|
|
2061
2066
|
return [4 /*yield*/, listAssistantCollections(db, dbName)];
|
|
2062
2067
|
case 3:
|
|
2063
|
-
collectionNames =
|
|
2068
|
+
collectionNames = _21.sent();
|
|
2064
2069
|
collectionHints = resolveCollectionHintsFromTokens(expandedTokens, collectionNames, 5);
|
|
2065
2070
|
collectionRanking = buildCollectionRankingDebugFromTokens(expandedTokens, collectionNames, 8);
|
|
2066
2071
|
return [4 /*yield*/, resolveAssistantSurfaceHints(hintSeed, contextRoute, collectionNames)];
|
|
2067
2072
|
case 4:
|
|
2068
|
-
surfaceHints =
|
|
2073
|
+
surfaceHints = _21.sent();
|
|
2069
2074
|
methodHints = surfaceHints.methodHints;
|
|
2070
2075
|
publicationHints = surfaceHints.publicationHints;
|
|
2071
2076
|
if (surfaceHints.collectionHints.length) {
|
|
@@ -2073,7 +2078,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2073
2078
|
}
|
|
2074
2079
|
return [3 /*break*/, 6];
|
|
2075
2080
|
case 5:
|
|
2076
|
-
_a =
|
|
2081
|
+
_a = _21.sent();
|
|
2077
2082
|
collectionHints = [];
|
|
2078
2083
|
collectionRanking = collectionRanking || ((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens)
|
|
2079
2084
|
? buildCollectionRankingDebugFromTokens(collectionTokenization.expandedTokens || [], [], 0)
|
|
@@ -2137,28 +2142,104 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2137
2142
|
recentToolError: recentToolError,
|
|
2138
2143
|
changeHistoryFastPathBypassedReason: changeHistoryFastPathBypassedReason
|
|
2139
2144
|
});
|
|
2140
|
-
|
|
2145
|
+
scoredAppDataIntentCandidates = rankAssistantAppDataIntentCandidates(message, collectionNames, input.id_app, { includeUnscored: false, limit: 3 });
|
|
2146
|
+
shouldAttemptAppDataClassifier = resolveAssistantDeterministicHeuristicEnabled(AI_ASSISTANT_HEURISTIC_ID_APP_DATA_INTENT, input.id_app) && (dataQuestion
|
|
2147
|
+
|| scoredAppDataIntentCandidates.length > 0
|
|
2148
|
+
|| isAssistantStrongDataQuestion(message));
|
|
2149
|
+
if (!(shouldAttemptAppDataClassifier && hasRunBudget('Planning: data request classifier', 500))) return [3 /*break*/, 13];
|
|
2150
|
+
return [4 /*yield*/, classifyAssistantAppDataRequest({
|
|
2151
|
+
message: message,
|
|
2152
|
+
appId: input.id_app,
|
|
2153
|
+
collectionNames: collectionNames,
|
|
2154
|
+
dateWindow: resolveAssistantDataIntentDateWindow(message),
|
|
2155
|
+
config: input.config
|
|
2156
|
+
})];
|
|
2157
|
+
case 7:
|
|
2158
|
+
classifierResult = _21.sent();
|
|
2159
|
+
if (!classifierResult) return [3 /*break*/, 12];
|
|
2160
|
+
appDataRequestClassifierDebug = classifierResult.debug || null;
|
|
2161
|
+
appDataRequestClassifierIntent = classifierResult.intent || null;
|
|
2162
|
+
appDataRequestClassifierUnderstanding = classifierResult.understanding || null;
|
|
2163
|
+
recordStep('Planning: data request classifier', {
|
|
2164
|
+
enabled: appDataRequestClassifierDebug === null || appDataRequestClassifierDebug === void 0 ? void 0 : appDataRequestClassifierDebug.enabled,
|
|
2165
|
+
attempted: appDataRequestClassifierDebug === null || appDataRequestClassifierDebug === void 0 ? void 0 : appDataRequestClassifierDebug.attempted,
|
|
2166
|
+
succeeded: appDataRequestClassifierDebug === null || appDataRequestClassifierDebug === void 0 ? void 0 : appDataRequestClassifierDebug.succeeded,
|
|
2167
|
+
model: appDataRequestClassifierDebug === null || appDataRequestClassifierDebug === void 0 ? void 0 : appDataRequestClassifierDebug.model,
|
|
2168
|
+
durationMs: appDataRequestClassifierDebug === null || appDataRequestClassifierDebug === void 0 ? void 0 : appDataRequestClassifierDebug.durationMs,
|
|
2169
|
+
intentId: (appDataRequestClassifierIntent === null || appDataRequestClassifierIntent === void 0 ? void 0 : appDataRequestClassifierIntent.id) || (appDataRequestClassifierDebug === null || appDataRequestClassifierDebug === void 0 ? void 0 : appDataRequestClassifierDebug.intentId),
|
|
2170
|
+
requestedBreakdowns: ((_j = appDataRequestClassifierUnderstanding === null || appDataRequestClassifierUnderstanding === void 0 ? void 0 : appDataRequestClassifierUnderstanding.contract) === null || _j === void 0 ? void 0 : _j.requested_breakdowns) || undefined,
|
|
2171
|
+
reason: appDataRequestClassifierDebug === null || appDataRequestClassifierDebug === void 0 ? void 0 : appDataRequestClassifierDebug.reason,
|
|
2172
|
+
error: appDataRequestClassifierDebug === null || appDataRequestClassifierDebug === void 0 ? void 0 : appDataRequestClassifierDebug.error
|
|
2173
|
+
});
|
|
2174
|
+
if (!((_k = classifierResult.usage) === null || _k === void 0 ? void 0 : _k.totalTokens)) return [3 /*break*/, 12];
|
|
2175
|
+
_21.label = 8;
|
|
2176
|
+
case 8:
|
|
2177
|
+
_21.trys.push([8, 11, , 12]);
|
|
2178
|
+
return [4 /*yield*/, resolveClientId(conversation, input.id_client, context === null || context === void 0 ? void 0 : context.id_user)];
|
|
2179
|
+
case 9:
|
|
2180
|
+
classifierUsageClientId = _21.sent();
|
|
2181
|
+
return [4 /*yield*/, (0, openai_usage_ledger_manager_1.recordOpenAIUsage)(buildAssistantAIRunUsageLedgerEntry({
|
|
2182
|
+
idClient: classifierUsageClientId || '',
|
|
2183
|
+
model: classifierResult.usage.model || (appDataRequestClassifierDebug === null || appDataRequestClassifierDebug === void 0 ? void 0 : appDataRequestClassifierDebug.model) || resolveAssistantDataRequestClassifierModel(input.config),
|
|
2184
|
+
inputTokens: classifierResult.usage.inputTokens || 0,
|
|
2185
|
+
outputTokens: classifierResult.usage.outputTokens || 0,
|
|
2186
|
+
totalTokens: classifierResult.usage.totalTokens || 0,
|
|
2187
|
+
category: 'ai-terminal-classifier',
|
|
2188
|
+
conversationId: conversation._id,
|
|
2189
|
+
requestId: requestId || classifierResult.usage.requestId || undefined,
|
|
2190
|
+
usagePhase: 'data_request_classifier',
|
|
2191
|
+
idApp: String((conversation === null || conversation === void 0 ? void 0 : conversation.id_app) || ''),
|
|
2192
|
+
metadata: {
|
|
2193
|
+
conversationId: conversation._id,
|
|
2194
|
+
requestId: requestId || '',
|
|
2195
|
+
classifierRequestId: classifierResult.usage.requestId || '',
|
|
2196
|
+
intentId: (appDataRequestClassifierIntent === null || appDataRequestClassifierIntent === void 0 ? void 0 : appDataRequestClassifierIntent.id) || ''
|
|
2197
|
+
}
|
|
2198
|
+
}))];
|
|
2199
|
+
case 10:
|
|
2200
|
+
_21.sent();
|
|
2201
|
+
return [3 /*break*/, 12];
|
|
2202
|
+
case 11:
|
|
2203
|
+
usageError_1 = _21.sent();
|
|
2204
|
+
console.error(new Date(), 'Failed to record AI data request classifier usage', usageError_1);
|
|
2205
|
+
return [3 /*break*/, 12];
|
|
2206
|
+
case 12: return [3 /*break*/, 14];
|
|
2207
|
+
case 13:
|
|
2208
|
+
if (shouldAttemptAppDataClassifier) {
|
|
2209
|
+
appDataRequestClassifierDebug = {
|
|
2210
|
+
enabled: resolveAssistantDataRequestClassifierEnabled(input.config),
|
|
2211
|
+
attempted: false,
|
|
2212
|
+
reason: 'run_budget_exhausted'
|
|
2213
|
+
};
|
|
2214
|
+
}
|
|
2215
|
+
_21.label = 14;
|
|
2216
|
+
case 14:
|
|
2217
|
+
heuristicDirectivePrecomputed = buildAssistantHeuristicDirective(message, collectionHints, collectionNames, input.id_app, {
|
|
2218
|
+
appDataIntent: appDataRequestClassifierIntent,
|
|
2219
|
+
appDataRequestUnderstanding: appDataRequestClassifierUnderstanding,
|
|
2220
|
+
appDataRequestClassifier: appDataRequestClassifierDebug
|
|
2221
|
+
});
|
|
2141
2222
|
hasDeterministicHeuristicFastPath = isAssistantExecutableDirective(heuristicDirectivePrecomputed)
|
|
2142
2223
|
&& isAssistantDeterministicHeuristicDirective(heuristicDirectivePrecomputed);
|
|
2143
2224
|
if (hasDeterministicHeuristicFastPath && !dataQuestion) {
|
|
2144
2225
|
requestClassification = __assign(__assign({}, requestClassification), { type: requestClassification.type === 'navigation' ? 'mixed' : 'data', dataQuestion: true, source: requestClassification.type === 'navigation' ? 'merged' : 'heuristic' });
|
|
2145
2226
|
dataQuestion = true;
|
|
2146
2227
|
recordStep('Planning: app data intent classified request', {
|
|
2147
|
-
collection: normalizeOptionalString((
|
|
2228
|
+
collection: normalizeOptionalString((_l = heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.payload) === null || _l === void 0 ? void 0 : _l.collection) || undefined,
|
|
2148
2229
|
heuristic: normalizeOptionalString(heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.rawLine) || undefined
|
|
2149
2230
|
});
|
|
2150
2231
|
}
|
|
2151
2232
|
if (hasDeterministicHeuristicFastPath) {
|
|
2152
2233
|
recordStep('Planning: heuristic directive fast path', {
|
|
2153
2234
|
type: heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.type,
|
|
2154
|
-
collection: normalizeOptionalString((
|
|
2235
|
+
collection: normalizeOptionalString((_m = heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.payload) === null || _m === void 0 ? void 0 : _m.collection) || undefined,
|
|
2155
2236
|
heuristic: normalizeOptionalString(heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.rawLine) || undefined
|
|
2156
2237
|
});
|
|
2157
2238
|
}
|
|
2158
2239
|
prompt_1 = buildAssistantCodexPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, assistantSystemPrompt);
|
|
2159
2240
|
return [4 /*yield*/, resolveAssistantWorkspaceRoot()];
|
|
2160
|
-
case
|
|
2161
|
-
workspaceRoot =
|
|
2241
|
+
case 15:
|
|
2242
|
+
workspaceRoot = _21.sent();
|
|
2162
2243
|
codexConfig = resolveCodexSettings({
|
|
2163
2244
|
model: codexModel,
|
|
2164
2245
|
fallbackModels: codexFallbackModels
|
|
@@ -2191,7 +2272,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2191
2272
|
hasDeterministicHeuristicFastPath: hasDeterministicHeuristicFastPath
|
|
2192
2273
|
});
|
|
2193
2274
|
plannerBudgetAvailable = !shouldRunPlanner || hasRunBudget('Planning: planner');
|
|
2194
|
-
if (!(shouldRunPlanner && plannerBudgetAvailable)) return [3 /*break*/,
|
|
2275
|
+
if (!(shouldRunPlanner && plannerBudgetAvailable)) return [3 /*break*/, 20];
|
|
2195
2276
|
plannerUsed = true;
|
|
2196
2277
|
recordStep('Planning: planner prompt');
|
|
2197
2278
|
plannerPrompt = buildAssistantPlannerPrompt({
|
|
@@ -2207,24 +2288,24 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2207
2288
|
publicationHints: publicationHints,
|
|
2208
2289
|
inputClientId: input.id_client
|
|
2209
2290
|
});
|
|
2210
|
-
|
|
2211
|
-
case
|
|
2212
|
-
|
|
2291
|
+
_21.label = 16;
|
|
2292
|
+
case 16:
|
|
2293
|
+
_21.trys.push([16, 18, , 19]);
|
|
2213
2294
|
plannerStart = Date.now();
|
|
2214
2295
|
return [4 /*yield*/, runCodexInWorkerThread(plannerPrompt, applyCodexStageBudget(plannerRunOptions), codexConfig, streamProgress)];
|
|
2215
|
-
case
|
|
2216
|
-
plannerRaw =
|
|
2296
|
+
case 17:
|
|
2297
|
+
plannerRaw = _21.sent();
|
|
2217
2298
|
accumulateCodexUsage(plannerPrompt, plannerRaw);
|
|
2218
2299
|
timingBreakdown.plannerMs = Date.now() - plannerStart;
|
|
2219
2300
|
plannerOutput = parseJsonObject(plannerRaw);
|
|
2220
2301
|
recordStep('Planning: planner result', { parsed: !!plannerOutput });
|
|
2221
|
-
return [3 /*break*/,
|
|
2222
|
-
case
|
|
2223
|
-
_b =
|
|
2302
|
+
return [3 /*break*/, 19];
|
|
2303
|
+
case 18:
|
|
2304
|
+
_b = _21.sent();
|
|
2224
2305
|
recordStep('Planning: planner result', { parsed: false });
|
|
2225
|
-
return [3 /*break*/,
|
|
2226
|
-
case
|
|
2227
|
-
case
|
|
2306
|
+
return [3 /*break*/, 19];
|
|
2307
|
+
case 19: return [3 /*break*/, 21];
|
|
2308
|
+
case 20:
|
|
2228
2309
|
if (plannerEnabled) {
|
|
2229
2310
|
if (hasDeterministicHeuristicFastPath) {
|
|
2230
2311
|
plannerSkipReason = 'heuristic_directive_fast_path';
|
|
@@ -2240,8 +2321,8 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2240
2321
|
}
|
|
2241
2322
|
recordStep('Planning: planner skipped', { reason: plannerSkipReason });
|
|
2242
2323
|
}
|
|
2243
|
-
|
|
2244
|
-
case
|
|
2324
|
+
_21.label = 21;
|
|
2325
|
+
case 21:
|
|
2245
2326
|
requestClassification = classifyAssistantRequestType(message, plannerOutput || undefined);
|
|
2246
2327
|
if (hasDeterministicHeuristicFastPath && !requestClassification.dataQuestion) {
|
|
2247
2328
|
requestClassification = __assign(__assign({}, requestClassification), { type: requestClassification.type === 'navigation' ? 'mixed' : 'data', dataQuestion: true, source: requestClassification.type === 'navigation' ? 'merged' : 'heuristic' });
|
|
@@ -2276,7 +2357,11 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2276
2357
|
directiveText = '';
|
|
2277
2358
|
directive = null;
|
|
2278
2359
|
heuristicDirectiveFastPath = dataQuestion
|
|
2279
|
-
? (heuristicDirectivePrecomputed || buildAssistantHeuristicDirective(message, collectionHints, collectionNames, input.id_app
|
|
2360
|
+
? (heuristicDirectivePrecomputed || buildAssistantHeuristicDirective(message, collectionHints, collectionNames, input.id_app, {
|
|
2361
|
+
appDataIntent: appDataRequestClassifierIntent,
|
|
2362
|
+
appDataRequestUnderstanding: appDataRequestClassifierUnderstanding,
|
|
2363
|
+
appDataRequestClassifier: appDataRequestClassifierDebug
|
|
2364
|
+
}))
|
|
2280
2365
|
: null;
|
|
2281
2366
|
if (dataQuestion
|
|
2282
2367
|
&& isAssistantExecutableDirective(heuristicDirectiveFastPath)
|
|
@@ -2285,27 +2370,27 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2285
2370
|
directiveSource = 'forced';
|
|
2286
2371
|
lastDirective = heuristicDirectiveFastPath;
|
|
2287
2372
|
usedDeterministicHeuristicFastPath = true;
|
|
2288
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2373
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_o = directive.payload) === null || _o === void 0 ? void 0 : _o.collection) || '');
|
|
2289
2374
|
recordStep('Directive resolved', {
|
|
2290
2375
|
source: directiveSource,
|
|
2291
2376
|
type: directive.type,
|
|
2292
|
-
collection: normalizeOptionalString((
|
|
2293
|
-
permissionView: normalizeOptionalString((
|
|
2377
|
+
collection: normalizeOptionalString((_p = directive.payload) === null || _p === void 0 ? void 0 : _p.collection) || undefined,
|
|
2378
|
+
permissionView: normalizeOptionalString((_q = directive.payload) === null || _q === void 0 ? void 0 : _q.permissionView) || undefined,
|
|
2294
2379
|
reportStyle: 'heuristic_fast_path',
|
|
2295
2380
|
timeGrain: requestedTimeGrain || undefined
|
|
2296
2381
|
});
|
|
2297
2382
|
}
|
|
2298
|
-
if (!(dataQuestion && !directive)) return [3 /*break*/,
|
|
2383
|
+
if (!(dataQuestion && !directive)) return [3 /*break*/, 25];
|
|
2299
2384
|
recordStep('Directive: determine tool', { type: 'data-question' });
|
|
2300
2385
|
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode, assistantSystemPrompt);
|
|
2301
|
-
if (!hasRunBudget('Directive: determine tool')) return [3 /*break*/,
|
|
2302
|
-
|
|
2303
|
-
case
|
|
2304
|
-
|
|
2386
|
+
if (!hasRunBudget('Directive: determine tool')) return [3 /*break*/, 25];
|
|
2387
|
+
_21.label = 22;
|
|
2388
|
+
case 22:
|
|
2389
|
+
_21.trys.push([22, 24, , 25]);
|
|
2305
2390
|
directiveStart = Date.now();
|
|
2306
2391
|
return [4 /*yield*/, runCodexInWorkerThread(directivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2307
|
-
case
|
|
2308
|
-
directiveText =
|
|
2392
|
+
case 23:
|
|
2393
|
+
directiveText = _21.sent();
|
|
2309
2394
|
accumulateCodexUsage(directivePrompt, directiveText);
|
|
2310
2395
|
timingBreakdown.directiveMs = Date.now() - directiveStart;
|
|
2311
2396
|
forcedDirective = extractAssistantMongoDirective(directiveText);
|
|
@@ -2313,32 +2398,32 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2313
2398
|
directive = forcedDirective;
|
|
2314
2399
|
directiveSource = 'model';
|
|
2315
2400
|
lastDirective = forcedDirective;
|
|
2316
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2401
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_r = directive.payload) === null || _r === void 0 ? void 0 : _r.collection) || '');
|
|
2317
2402
|
recordStep('Directive resolved', {
|
|
2318
2403
|
source: directiveSource,
|
|
2319
2404
|
type: directive.type,
|
|
2320
|
-
collection: normalizeOptionalString((
|
|
2321
|
-
permissionView: normalizeOptionalString((
|
|
2405
|
+
collection: normalizeOptionalString((_s = directive.payload) === null || _s === void 0 ? void 0 : _s.collection) || undefined,
|
|
2406
|
+
permissionView: normalizeOptionalString((_t = directive.payload) === null || _t === void 0 ? void 0 : _t.permissionView) || undefined
|
|
2322
2407
|
});
|
|
2323
2408
|
}
|
|
2324
|
-
return [3 /*break*/,
|
|
2325
|
-
case
|
|
2326
|
-
error_2 =
|
|
2409
|
+
return [3 /*break*/, 25];
|
|
2410
|
+
case 24:
|
|
2411
|
+
error_2 = _21.sent();
|
|
2327
2412
|
recordStep('Directive: determine tool failed', {
|
|
2328
2413
|
message: normalizeOptionalString(error_2 === null || error_2 === void 0 ? void 0 : error_2.message) || 'Unknown error'
|
|
2329
2414
|
});
|
|
2330
|
-
return [3 /*break*/,
|
|
2331
|
-
case
|
|
2332
|
-
if (!(!directive && !dataQuestion)) return [3 /*break*/,
|
|
2415
|
+
return [3 /*break*/, 25];
|
|
2416
|
+
case 25:
|
|
2417
|
+
if (!(!directive && !dataQuestion)) return [3 /*break*/, 29];
|
|
2333
2418
|
recordStep('Response: draft initial answer', { mode: 'full' });
|
|
2334
|
-
if (!hasRunBudget('Response: initial draft')) return [3 /*break*/,
|
|
2335
|
-
|
|
2336
|
-
case
|
|
2337
|
-
|
|
2419
|
+
if (!hasRunBudget('Response: initial draft')) return [3 /*break*/, 29];
|
|
2420
|
+
_21.label = 26;
|
|
2421
|
+
case 26:
|
|
2422
|
+
_21.trys.push([26, 28, , 29]);
|
|
2338
2423
|
initialStart = Date.now();
|
|
2339
2424
|
return [4 /*yield*/, runCodexInWorkerThread(prompt_1, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2340
|
-
case
|
|
2341
|
-
responseText =
|
|
2425
|
+
case 27:
|
|
2426
|
+
responseText = _21.sent();
|
|
2342
2427
|
accumulateCodexUsage(prompt_1, responseText);
|
|
2343
2428
|
timingBreakdown.initialResponseMs = Date.now() - initialStart;
|
|
2344
2429
|
extractedDirective = extractAssistantMongoDirective(responseText);
|
|
@@ -2346,33 +2431,33 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2346
2431
|
if (directive) {
|
|
2347
2432
|
directiveSource = 'model';
|
|
2348
2433
|
lastDirective = directive;
|
|
2349
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2434
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_u = directive.payload) === null || _u === void 0 ? void 0 : _u.collection) || '');
|
|
2350
2435
|
recordStep('Directive resolved', {
|
|
2351
2436
|
source: directiveSource,
|
|
2352
2437
|
type: directive.type,
|
|
2353
|
-
collection: normalizeOptionalString((
|
|
2354
|
-
permissionView: normalizeOptionalString((
|
|
2438
|
+
collection: normalizeOptionalString((_v = directive.payload) === null || _v === void 0 ? void 0 : _v.collection) || undefined,
|
|
2439
|
+
permissionView: normalizeOptionalString((_w = directive.payload) === null || _w === void 0 ? void 0 : _w.permissionView) || undefined
|
|
2355
2440
|
});
|
|
2356
2441
|
}
|
|
2357
|
-
return [3 /*break*/,
|
|
2358
|
-
case
|
|
2359
|
-
error_3 =
|
|
2442
|
+
return [3 /*break*/, 29];
|
|
2443
|
+
case 28:
|
|
2444
|
+
error_3 = _21.sent();
|
|
2360
2445
|
recordStep('Response: initial draft failed', {
|
|
2361
2446
|
message: normalizeOptionalString(error_3 === null || error_3 === void 0 ? void 0 : error_3.message) || 'Unknown error'
|
|
2362
2447
|
});
|
|
2363
|
-
return [3 /*break*/,
|
|
2364
|
-
case
|
|
2365
|
-
if (!(!directive && dataQuestion)) return [3 /*break*/,
|
|
2448
|
+
return [3 /*break*/, 29];
|
|
2449
|
+
case 29:
|
|
2450
|
+
if (!(!directive && dataQuestion)) return [3 /*break*/, 33];
|
|
2366
2451
|
recordStep('Directive: forced retry', { mode: 'directive-only' });
|
|
2367
2452
|
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode, assistantSystemPrompt);
|
|
2368
|
-
if (!hasRunBudget('Directive: forced retry')) return [3 /*break*/,
|
|
2369
|
-
|
|
2370
|
-
case
|
|
2371
|
-
|
|
2453
|
+
if (!hasRunBudget('Directive: forced retry')) return [3 /*break*/, 33];
|
|
2454
|
+
_21.label = 30;
|
|
2455
|
+
case 30:
|
|
2456
|
+
_21.trys.push([30, 32, , 33]);
|
|
2372
2457
|
forcedStart = Date.now();
|
|
2373
2458
|
return [4 /*yield*/, runCodexInWorkerThread(directivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2374
|
-
case
|
|
2375
|
-
directiveText =
|
|
2459
|
+
case 31:
|
|
2460
|
+
directiveText = _21.sent();
|
|
2376
2461
|
accumulateCodexUsage(directivePrompt, directiveText);
|
|
2377
2462
|
timingBreakdown.forcedDirectiveMs = Date.now() - forcedStart;
|
|
2378
2463
|
forcedDirective = extractAssistantMongoDirective(directiveText);
|
|
@@ -2380,26 +2465,26 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2380
2465
|
directive = forcedDirective;
|
|
2381
2466
|
directiveSource = 'forced';
|
|
2382
2467
|
lastDirective = forcedDirective;
|
|
2383
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2468
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_x = directive.payload) === null || _x === void 0 ? void 0 : _x.collection) || '');
|
|
2384
2469
|
recordStep('Directive resolved', {
|
|
2385
2470
|
source: directiveSource,
|
|
2386
2471
|
type: directive.type,
|
|
2387
|
-
collection: normalizeOptionalString((
|
|
2388
|
-
permissionView: normalizeOptionalString((
|
|
2472
|
+
collection: normalizeOptionalString((_y = directive.payload) === null || _y === void 0 ? void 0 : _y.collection) || undefined,
|
|
2473
|
+
permissionView: normalizeOptionalString((_z = directive.payload) === null || _z === void 0 ? void 0 : _z.permissionView) || undefined
|
|
2389
2474
|
});
|
|
2390
2475
|
}
|
|
2391
|
-
return [3 /*break*/,
|
|
2392
|
-
case
|
|
2393
|
-
error_4 =
|
|
2476
|
+
return [3 /*break*/, 33];
|
|
2477
|
+
case 32:
|
|
2478
|
+
error_4 = _21.sent();
|
|
2394
2479
|
recordStep('Directive: forced retry failed', {
|
|
2395
2480
|
message: normalizeOptionalString(error_4 === null || error_4 === void 0 ? void 0 : error_4.message) || 'Unknown error'
|
|
2396
2481
|
});
|
|
2397
|
-
return [3 /*break*/,
|
|
2398
|
-
case
|
|
2482
|
+
return [3 /*break*/, 33];
|
|
2483
|
+
case 33:
|
|
2399
2484
|
if (!(directive
|
|
2400
2485
|
&& enforceDatedDirective
|
|
2401
2486
|
&& !isAssistantDeterministicHeuristicDirective(directive)
|
|
2402
|
-
&& !isAssistantDirectiveDated(directive))) return [3 /*break*/,
|
|
2487
|
+
&& !isAssistantDirectiveDated(directive))) return [3 /*break*/, 37];
|
|
2403
2488
|
recordStep('Directive: dated retry', {
|
|
2404
2489
|
currentType: directive.type,
|
|
2405
2490
|
timeGrain: requestedTimeGrain || undefined
|
|
@@ -2411,14 +2496,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2411
2496
|
requestedBreakdowns: requestedBreakdownDimensions,
|
|
2412
2497
|
strict: true
|
|
2413
2498
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2414
|
-
if (!hasRunBudget('Directive: dated retry')) return [3 /*break*/,
|
|
2415
|
-
|
|
2416
|
-
case
|
|
2417
|
-
|
|
2499
|
+
if (!hasRunBudget('Directive: dated retry')) return [3 /*break*/, 37];
|
|
2500
|
+
_21.label = 34;
|
|
2501
|
+
case 34:
|
|
2502
|
+
_21.trys.push([34, 36, , 37]);
|
|
2418
2503
|
strictStart = Date.now();
|
|
2419
2504
|
return [4 /*yield*/, runCodexInWorkerThread(strictDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2420
|
-
case
|
|
2421
|
-
strictDirectiveText =
|
|
2505
|
+
case 35:
|
|
2506
|
+
strictDirectiveText = _21.sent();
|
|
2422
2507
|
accumulateCodexUsage(strictDirectivePrompt, strictDirectiveText);
|
|
2423
2508
|
timingBreakdown.forcedDirectiveMs += Date.now() - strictStart;
|
|
2424
2509
|
strictDirective = extractAssistantMongoDirective(strictDirectiveText);
|
|
@@ -2429,28 +2514,28 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2429
2514
|
directiveSource = 'forced';
|
|
2430
2515
|
lastDirective = strictDirective;
|
|
2431
2516
|
datedDirectiveRetryUsed = true;
|
|
2432
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2517
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_0 = directive.payload) === null || _0 === void 0 ? void 0 : _0.collection) || '');
|
|
2433
2518
|
recordStep('Directive resolved', {
|
|
2434
2519
|
source: directiveSource,
|
|
2435
2520
|
type: directive.type,
|
|
2436
|
-
collection: normalizeOptionalString((
|
|
2437
|
-
permissionView: normalizeOptionalString((
|
|
2521
|
+
collection: normalizeOptionalString((_1 = directive.payload) === null || _1 === void 0 ? void 0 : _1.collection) || undefined,
|
|
2522
|
+
permissionView: normalizeOptionalString((_2 = directive.payload) === null || _2 === void 0 ? void 0 : _2.permissionView) || undefined,
|
|
2438
2523
|
reportStyle: strictDirectiveIsDated ? 'dated' : 'aggregate_fallback',
|
|
2439
2524
|
timeGrain: requestedTimeGrain || undefined
|
|
2440
2525
|
});
|
|
2441
2526
|
}
|
|
2442
|
-
return [3 /*break*/,
|
|
2443
|
-
case
|
|
2444
|
-
error_5 =
|
|
2527
|
+
return [3 /*break*/, 37];
|
|
2528
|
+
case 36:
|
|
2529
|
+
error_5 = _21.sent();
|
|
2445
2530
|
recordStep('Directive: dated retry failed', {
|
|
2446
2531
|
message: normalizeOptionalString(error_5 === null || error_5 === void 0 ? void 0 : error_5.message) || 'Unknown error'
|
|
2447
2532
|
});
|
|
2448
|
-
return [3 /*break*/,
|
|
2449
|
-
case
|
|
2533
|
+
return [3 /*break*/, 37];
|
|
2534
|
+
case 37:
|
|
2450
2535
|
if (!(directive
|
|
2451
2536
|
&& enforceDatedDirective
|
|
2452
2537
|
&& !isAssistantDeterministicHeuristicDirective(directive)
|
|
2453
|
-
&& directive.type === 'read')) return [3 /*break*/,
|
|
2538
|
+
&& directive.type === 'read')) return [3 /*break*/, 41];
|
|
2454
2539
|
recordStep('Directive: dated guard retry', {
|
|
2455
2540
|
currentType: directive.type,
|
|
2456
2541
|
timeGrain: requestedTimeGrain || undefined
|
|
@@ -2462,14 +2547,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2462
2547
|
requestedBreakdowns: requestedBreakdownDimensions,
|
|
2463
2548
|
strict: true
|
|
2464
2549
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2465
|
-
if (!hasRunBudget('Directive: dated guard retry')) return [3 /*break*/,
|
|
2466
|
-
|
|
2467
|
-
case
|
|
2468
|
-
|
|
2550
|
+
if (!hasRunBudget('Directive: dated guard retry')) return [3 /*break*/, 41];
|
|
2551
|
+
_21.label = 38;
|
|
2552
|
+
case 38:
|
|
2553
|
+
_21.trys.push([38, 40, , 41]);
|
|
2469
2554
|
guardStart = Date.now();
|
|
2470
2555
|
return [4 /*yield*/, runCodexInWorkerThread(guardDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2471
|
-
case
|
|
2472
|
-
guardDirectiveText =
|
|
2556
|
+
case 39:
|
|
2557
|
+
guardDirectiveText = _21.sent();
|
|
2473
2558
|
accumulateCodexUsage(guardDirectivePrompt, guardDirectiveText);
|
|
2474
2559
|
timingBreakdown.forcedDirectiveMs += Date.now() - guardStart;
|
|
2475
2560
|
guardDirective = extractAssistantMongoDirective(guardDirectiveText);
|
|
@@ -2478,28 +2563,28 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2478
2563
|
directiveSource = 'forced';
|
|
2479
2564
|
lastDirective = guardDirective;
|
|
2480
2565
|
datedDirectiveRetryUsed = true;
|
|
2481
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2566
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_3 = directive.payload) === null || _3 === void 0 ? void 0 : _3.collection) || '');
|
|
2482
2567
|
recordStep('Directive resolved', {
|
|
2483
2568
|
source: directiveSource,
|
|
2484
2569
|
type: directive.type,
|
|
2485
|
-
collection: normalizeOptionalString((
|
|
2486
|
-
permissionView: normalizeOptionalString((
|
|
2570
|
+
collection: normalizeOptionalString((_4 = directive.payload) === null || _4 === void 0 ? void 0 : _4.collection) || undefined,
|
|
2571
|
+
permissionView: normalizeOptionalString((_5 = directive.payload) === null || _5 === void 0 ? void 0 : _5.permissionView) || undefined,
|
|
2487
2572
|
reportStyle: isAssistantDirectiveDated(guardDirective) ? 'dated' : 'aggregate_fallback',
|
|
2488
2573
|
timeGrain: requestedTimeGrain || undefined
|
|
2489
2574
|
});
|
|
2490
2575
|
}
|
|
2491
|
-
return [3 /*break*/,
|
|
2492
|
-
case
|
|
2493
|
-
error_6 =
|
|
2576
|
+
return [3 /*break*/, 41];
|
|
2577
|
+
case 40:
|
|
2578
|
+
error_6 = _21.sent();
|
|
2494
2579
|
recordStep('Directive: dated guard retry failed', {
|
|
2495
2580
|
message: normalizeOptionalString(error_6 === null || error_6 === void 0 ? void 0 : error_6.message) || 'Unknown error'
|
|
2496
2581
|
});
|
|
2497
|
-
return [3 /*break*/,
|
|
2498
|
-
case
|
|
2582
|
+
return [3 /*break*/, 41];
|
|
2583
|
+
case 41:
|
|
2499
2584
|
if (!(directive
|
|
2500
2585
|
&& enforceGroupedDirective
|
|
2501
2586
|
&& !isAssistantDeterministicHeuristicDirective(directive)
|
|
2502
|
-
&& !isAssistantDirectiveGrouped(directive))) return [3 /*break*/,
|
|
2587
|
+
&& !isAssistantDirectiveGrouped(directive))) return [3 /*break*/, 45];
|
|
2503
2588
|
recordStep('Directive: grouped guard retry', {
|
|
2504
2589
|
currentType: directive.type,
|
|
2505
2590
|
breakdownDimensions: requestedBreakdownDimensions.length ? requestedBreakdownDimensions : undefined
|
|
@@ -2511,14 +2596,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2511
2596
|
requestedBreakdowns: requestedBreakdownDimensions,
|
|
2512
2597
|
strict: true
|
|
2513
2598
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2514
|
-
if (!hasRunBudget('Directive: grouped guard retry')) return [3 /*break*/,
|
|
2515
|
-
|
|
2516
|
-
case
|
|
2517
|
-
|
|
2599
|
+
if (!hasRunBudget('Directive: grouped guard retry')) return [3 /*break*/, 45];
|
|
2600
|
+
_21.label = 42;
|
|
2601
|
+
case 42:
|
|
2602
|
+
_21.trys.push([42, 44, , 45]);
|
|
2518
2603
|
groupedStart = Date.now();
|
|
2519
2604
|
return [4 /*yield*/, runCodexInWorkerThread(groupedDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2520
|
-
case
|
|
2521
|
-
groupedDirectiveText =
|
|
2605
|
+
case 43:
|
|
2606
|
+
groupedDirectiveText = _21.sent();
|
|
2522
2607
|
accumulateCodexUsage(groupedDirectivePrompt, groupedDirectiveText);
|
|
2523
2608
|
timingBreakdown.forcedDirectiveMs += Date.now() - groupedStart;
|
|
2524
2609
|
groupedDirective = extractAssistantMongoDirective(groupedDirectiveText);
|
|
@@ -2527,12 +2612,12 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2527
2612
|
directiveSource = 'forced';
|
|
2528
2613
|
lastDirective = groupedDirective;
|
|
2529
2614
|
datedDirectiveRetryUsed = true;
|
|
2530
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2615
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_6 = directive.payload) === null || _6 === void 0 ? void 0 : _6.collection) || '');
|
|
2531
2616
|
recordStep('Directive resolved', {
|
|
2532
2617
|
source: directiveSource,
|
|
2533
2618
|
type: directive.type,
|
|
2534
|
-
collection: normalizeOptionalString((
|
|
2535
|
-
permissionView: normalizeOptionalString((
|
|
2619
|
+
collection: normalizeOptionalString((_7 = directive.payload) === null || _7 === void 0 ? void 0 : _7.collection) || undefined,
|
|
2620
|
+
permissionView: normalizeOptionalString((_8 = directive.payload) === null || _8 === void 0 ? void 0 : _8.permissionView) || undefined,
|
|
2536
2621
|
reportStyle: isAssistantDirectiveDated(groupedDirective)
|
|
2537
2622
|
? 'dated'
|
|
2538
2623
|
: 'grouped',
|
|
@@ -2540,16 +2625,20 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2540
2625
|
timeGrain: requestedTimeGrain || undefined
|
|
2541
2626
|
});
|
|
2542
2627
|
}
|
|
2543
|
-
return [3 /*break*/,
|
|
2544
|
-
case
|
|
2545
|
-
error_7 =
|
|
2628
|
+
return [3 /*break*/, 45];
|
|
2629
|
+
case 44:
|
|
2630
|
+
error_7 = _21.sent();
|
|
2546
2631
|
recordStep('Directive: grouped guard retry failed', {
|
|
2547
2632
|
message: normalizeOptionalString(error_7 === null || error_7 === void 0 ? void 0 : error_7.message) || 'Unknown error'
|
|
2548
2633
|
});
|
|
2549
|
-
return [3 /*break*/,
|
|
2550
|
-
case
|
|
2634
|
+
return [3 /*break*/, 45];
|
|
2635
|
+
case 45:
|
|
2551
2636
|
if (!directive && dataQuestion) {
|
|
2552
|
-
heuristicDirective = buildAssistantHeuristicDirective(message, collectionHints, collectionNames, input.id_app
|
|
2637
|
+
heuristicDirective = buildAssistantHeuristicDirective(message, collectionHints, collectionNames, input.id_app, {
|
|
2638
|
+
appDataIntent: appDataRequestClassifierIntent,
|
|
2639
|
+
appDataRequestUnderstanding: appDataRequestClassifierUnderstanding,
|
|
2640
|
+
appDataRequestClassifier: appDataRequestClassifierDebug
|
|
2641
|
+
});
|
|
2553
2642
|
if (isAssistantExecutableDirective(heuristicDirective)) {
|
|
2554
2643
|
directive = heuristicDirective;
|
|
2555
2644
|
directiveSource = 'forced';
|
|
@@ -2557,21 +2646,21 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2557
2646
|
recordStep('Directive resolved', {
|
|
2558
2647
|
source: directiveSource,
|
|
2559
2648
|
type: directive.type,
|
|
2560
|
-
collection: normalizeOptionalString((
|
|
2561
|
-
permissionView: normalizeOptionalString((
|
|
2649
|
+
collection: normalizeOptionalString((_9 = directive.payload) === null || _9 === void 0 ? void 0 : _9.collection) || undefined,
|
|
2650
|
+
permissionView: normalizeOptionalString((_10 = directive.payload) === null || _10 === void 0 ? void 0 : _10.permissionView) || undefined,
|
|
2562
2651
|
reportStyle: 'heuristic_fallback'
|
|
2563
2652
|
});
|
|
2564
2653
|
}
|
|
2565
2654
|
}
|
|
2566
2655
|
if (directive) {
|
|
2567
|
-
requestedCollection = normalizeOptionalString((
|
|
2656
|
+
requestedCollection = normalizeOptionalString((_11 = directive.payload) === null || _11 === void 0 ? void 0 : _11.collection);
|
|
2568
2657
|
allowCollectionOverride = !isAssistantDeterministicHeuristicDirective(directive);
|
|
2569
2658
|
collectionOverride = allowCollectionOverride
|
|
2570
2659
|
? resolveCollectionOverrideWithContext({
|
|
2571
2660
|
message: message,
|
|
2572
2661
|
collectionRanking: collectionRanking,
|
|
2573
2662
|
requestedCollection: requestedCollection,
|
|
2574
|
-
permissionView: normalizeOptionalString((
|
|
2663
|
+
permissionView: normalizeOptionalString((_12 = directive.payload) === null || _12 === void 0 ? void 0 : _12.permissionView) || contextRoute,
|
|
2575
2664
|
collectionNames: collectionNames,
|
|
2576
2665
|
collectionHints: collectionHints,
|
|
2577
2666
|
appId: input.id_app
|
|
@@ -2596,7 +2685,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2596
2685
|
isSuperAdmin: isSuperAdmin,
|
|
2597
2686
|
message: message
|
|
2598
2687
|
});
|
|
2599
|
-
if (!deniedModuleByIntent) return [3 /*break*/,
|
|
2688
|
+
if (!deniedModuleByIntent) return [3 /*break*/, 46];
|
|
2600
2689
|
permissionLabel = formatAssistantModulePermissionLabel(deniedModuleByIntent);
|
|
2601
2690
|
progressTracker.push(AI_ASSISTANT_PROGRESS_DATA_LOOKUP);
|
|
2602
2691
|
recordStep('Grabbing Data: denied', {
|
|
@@ -2613,9 +2702,9 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2613
2702
|
toolTelemetry.outcome = {
|
|
2614
2703
|
error: 'permission_denied'
|
|
2615
2704
|
};
|
|
2616
|
-
return [3 /*break*/,
|
|
2617
|
-
case
|
|
2618
|
-
if (!((directive === null || directive === void 0 ? void 0 : directive.payload) && AI_ASSISTANT_TOOL_MAX_STEPS > 0)) return [3 /*break*/,
|
|
2705
|
+
return [3 /*break*/, 75];
|
|
2706
|
+
case 46:
|
|
2707
|
+
if (!((directive === null || directive === void 0 ? void 0 : directive.payload) && AI_ASSISTANT_TOOL_MAX_STEPS > 0)) return [3 /*break*/, 74];
|
|
2619
2708
|
effectiveDirective = collectionOverride
|
|
2620
2709
|
? __assign(__assign({}, directive), { payload: __assign(__assign({}, (directive.payload || {})), { collection: collectionOverride.to }) }) : directive;
|
|
2621
2710
|
effectiveDirectiveMetadata = effectiveDirective.metadata && typeof effectiveDirective.metadata === 'object'
|
|
@@ -2667,10 +2756,10 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2667
2756
|
directiveProgressMessages.slice(0, 2).forEach(function (messageText) { return progressTracker.push(messageText); });
|
|
2668
2757
|
executionDirective = effectiveDirective;
|
|
2669
2758
|
probeFieldHints = [];
|
|
2670
|
-
|
|
2671
|
-
case
|
|
2672
|
-
|
|
2673
|
-
if (!(!alwaysAllowProbeEnabled && !hasRunBudget('Grabbing Data', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS))) return [3 /*break*/,
|
|
2759
|
+
_21.label = 47;
|
|
2760
|
+
case 47:
|
|
2761
|
+
_21.trys.push([47, 72, , 73]);
|
|
2762
|
+
if (!(!alwaysAllowProbeEnabled && !hasRunBudget('Grabbing Data', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS))) return [3 /*break*/, 48];
|
|
2674
2763
|
assistantContent = buildAssistantRunBudgetExceededMessage();
|
|
2675
2764
|
toolTelemetry.final = {
|
|
2676
2765
|
attempted: false,
|
|
@@ -2680,17 +2769,17 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2680
2769
|
toolTelemetry.outcome = {
|
|
2681
2770
|
error: 'run_budget_exhausted'
|
|
2682
2771
|
};
|
|
2683
|
-
return [3 /*break*/,
|
|
2684
|
-
case
|
|
2772
|
+
return [3 /*break*/, 71];
|
|
2773
|
+
case 48:
|
|
2685
2774
|
aggregateProbeDisabled = executionDirective.type === 'aggregate'
|
|
2686
2775
|
&& !alwaysAllowProbeEnabled
|
|
2687
2776
|
&& !isAssistantAppDataIntentHeuristicDirective(executionDirective);
|
|
2688
2777
|
probeEnabled = AI_ASSISTANT_TOOL_MAX_STEPS > 1 && !aggregateProbeDisabled;
|
|
2689
2778
|
probeBudgetAllowed = alwaysAllowProbeEnabled
|
|
2690
2779
|
|| hasRunBudget('Grabbing Data: probe', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS);
|
|
2691
|
-
if (!(probeEnabled && probeBudgetAllowed)) return [3 /*break*/,
|
|
2780
|
+
if (!(probeEnabled && probeBudgetAllowed)) return [3 /*break*/, 58];
|
|
2692
2781
|
probeDirective = buildAssistantProbeDirective(executionDirective);
|
|
2693
|
-
if (!(probeDirective === null || probeDirective === void 0 ? void 0 : probeDirective.payload)) return [3 /*break*/,
|
|
2782
|
+
if (!(probeDirective === null || probeDirective === void 0 ? void 0 : probeDirective.payload)) return [3 /*break*/, 56];
|
|
2694
2783
|
probeRequest = buildToolRequestForDirective(probeDirective);
|
|
2695
2784
|
recordStep('Grabbing Data: probe start', {
|
|
2696
2785
|
type: probeDirective.type,
|
|
@@ -2701,19 +2790,19 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2701
2790
|
attempted: true
|
|
2702
2791
|
};
|
|
2703
2792
|
probeStart = Date.now();
|
|
2704
|
-
|
|
2705
|
-
case
|
|
2706
|
-
|
|
2707
|
-
if (!(probeDirective.type === 'aggregate')) return [3 /*break*/,
|
|
2793
|
+
_21.label = 49;
|
|
2794
|
+
case 49:
|
|
2795
|
+
_21.trys.push([49, 54, , 55]);
|
|
2796
|
+
if (!(probeDirective.type === 'aggregate')) return [3 /*break*/, 51];
|
|
2708
2797
|
return [4 /*yield*/, executeAiAssistantReportBuilderAggregate(probeRequest, context)];
|
|
2709
|
-
case
|
|
2710
|
-
_c =
|
|
2711
|
-
return [3 /*break*/,
|
|
2712
|
-
case
|
|
2713
|
-
case
|
|
2714
|
-
_c =
|
|
2715
|
-
|
|
2716
|
-
case
|
|
2798
|
+
case 50:
|
|
2799
|
+
_c = _21.sent();
|
|
2800
|
+
return [3 /*break*/, 53];
|
|
2801
|
+
case 51: return [4 /*yield*/, executeAiAssistantReportBuilderRead(probeRequest, context)];
|
|
2802
|
+
case 52:
|
|
2803
|
+
_c = _21.sent();
|
|
2804
|
+
_21.label = 53;
|
|
2805
|
+
case 53:
|
|
2717
2806
|
probeResponse = _c;
|
|
2718
2807
|
probeDurationMs = Date.now() - probeStart;
|
|
2719
2808
|
timingBreakdown.toolMs += probeDurationMs;
|
|
@@ -2734,7 +2823,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2734
2823
|
};
|
|
2735
2824
|
recordStep('Grabbing Data: probe complete', {
|
|
2736
2825
|
rowCount: probeRowCount,
|
|
2737
|
-
collection: normalizeOptionalString(((
|
|
2826
|
+
collection: normalizeOptionalString(((_13 = probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.debug) === null || _13 === void 0 ? void 0 : _13.collectionResolved) || ((_14 = probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.debug) === null || _14 === void 0 ? void 0 : _14.collection)) || undefined
|
|
2738
2827
|
});
|
|
2739
2828
|
if (probeRewrite.notes.length || probeFieldHints.length) {
|
|
2740
2829
|
recordStep('Grabbing Data: probe rewrite', {
|
|
@@ -2742,9 +2831,9 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2742
2831
|
fieldHints: probeFieldHints.length ? probeFieldHints.slice(0, 6) : undefined
|
|
2743
2832
|
});
|
|
2744
2833
|
}
|
|
2745
|
-
return [3 /*break*/,
|
|
2746
|
-
case
|
|
2747
|
-
probeError_1 =
|
|
2834
|
+
return [3 /*break*/, 55];
|
|
2835
|
+
case 54:
|
|
2836
|
+
probeError_1 = _21.sent();
|
|
2748
2837
|
probeDurationMs = Date.now() - probeStart;
|
|
2749
2838
|
probeErrorMessage = normalizeOptionalString(probeError_1 === null || probeError_1 === void 0 ? void 0 : probeError_1.message) || 'Unknown error';
|
|
2750
2839
|
toolTelemetry.probe = {
|
|
@@ -2756,16 +2845,16 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2756
2845
|
recordStep('Grabbing Data: probe failed', {
|
|
2757
2846
|
message: probeErrorMessage
|
|
2758
2847
|
});
|
|
2759
|
-
return [3 /*break*/,
|
|
2760
|
-
case
|
|
2761
|
-
case
|
|
2848
|
+
return [3 /*break*/, 55];
|
|
2849
|
+
case 55: return [3 /*break*/, 57];
|
|
2850
|
+
case 56:
|
|
2762
2851
|
toolTelemetry.probe = {
|
|
2763
2852
|
attempted: false,
|
|
2764
2853
|
skippedReason: 'probe_directive_missing_payload'
|
|
2765
2854
|
};
|
|
2766
|
-
|
|
2767
|
-
case
|
|
2768
|
-
case
|
|
2855
|
+
_21.label = 57;
|
|
2856
|
+
case 57: return [3 /*break*/, 59];
|
|
2857
|
+
case 58:
|
|
2769
2858
|
if (probeEnabled) {
|
|
2770
2859
|
toolTelemetry.probe = {
|
|
2771
2860
|
attempted: false,
|
|
@@ -2778,9 +2867,9 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2778
2867
|
skippedReason: 'aggregate_probe_disabled'
|
|
2779
2868
|
};
|
|
2780
2869
|
}
|
|
2781
|
-
|
|
2782
|
-
case
|
|
2783
|
-
if (!(!alwaysAllowProbeEnabled && !hasRunBudget('Grabbing Data: final', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS))) return [3 /*break*/,
|
|
2870
|
+
_21.label = 59;
|
|
2871
|
+
case 59:
|
|
2872
|
+
if (!(!alwaysAllowProbeEnabled && !hasRunBudget('Grabbing Data: final', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS))) return [3 /*break*/, 60];
|
|
2784
2873
|
assistantContent = buildAssistantRunBudgetExceededMessage();
|
|
2785
2874
|
toolTelemetry.final = {
|
|
2786
2875
|
attempted: false,
|
|
@@ -2790,8 +2879,8 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2790
2879
|
toolTelemetry.outcome = {
|
|
2791
2880
|
error: 'run_budget_exhausted'
|
|
2792
2881
|
};
|
|
2793
|
-
return [3 /*break*/,
|
|
2794
|
-
case
|
|
2882
|
+
return [3 /*break*/, 71];
|
|
2883
|
+
case 60:
|
|
2795
2884
|
toolRequest = buildToolRequestForDirective(executionDirective, probeFieldHints);
|
|
2796
2885
|
requestedToolCollection = normalizeOptionalString(toolRequest === null || toolRequest === void 0 ? void 0 : toolRequest.collection);
|
|
2797
2886
|
recordStep('Grabbing Data: start', {
|
|
@@ -2805,16 +2894,16 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2805
2894
|
collection: requestedToolCollection || undefined
|
|
2806
2895
|
};
|
|
2807
2896
|
toolStart = Date.now();
|
|
2808
|
-
if (!(executionDirective.type === 'aggregate')) return [3 /*break*/,
|
|
2897
|
+
if (!(executionDirective.type === 'aggregate')) return [3 /*break*/, 62];
|
|
2809
2898
|
return [4 /*yield*/, executeAiAssistantReportBuilderAggregate(toolRequest, context)];
|
|
2810
|
-
case
|
|
2811
|
-
_d =
|
|
2812
|
-
return [3 /*break*/,
|
|
2813
|
-
case
|
|
2814
|
-
case
|
|
2815
|
-
_d =
|
|
2816
|
-
|
|
2817
|
-
case
|
|
2899
|
+
case 61:
|
|
2900
|
+
_d = _21.sent();
|
|
2901
|
+
return [3 /*break*/, 64];
|
|
2902
|
+
case 62: return [4 /*yield*/, executeAiAssistantReportBuilderRead(toolRequest, context)];
|
|
2903
|
+
case 63:
|
|
2904
|
+
_d = _21.sent();
|
|
2905
|
+
_21.label = 64;
|
|
2906
|
+
case 64:
|
|
2818
2907
|
toolResponse = _d;
|
|
2819
2908
|
toolDurationMs = Date.now() - toolStart;
|
|
2820
2909
|
timingBreakdown.toolMs += toolDurationMs;
|
|
@@ -2824,8 +2913,8 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2824
2913
|
toolPayload = buildAssistantToolResultPayload(executionDirective, toolResponse, message);
|
|
2825
2914
|
toolResult = toolPayload.result;
|
|
2826
2915
|
resolvedToolCollection = normalizeOptionalString(toolPayload.result.output.collection
|
|
2827
|
-
|| ((
|
|
2828
|
-
|| ((
|
|
2916
|
+
|| ((_15 = toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) === null || _15 === void 0 ? void 0 : _15.collectionResolved)
|
|
2917
|
+
|| ((_16 = toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) === null || _16 === void 0 ? void 0 : _16.collection)
|
|
2829
2918
|
|| requestedToolCollection);
|
|
2830
2919
|
toolTelemetry.final = {
|
|
2831
2920
|
attempted: true,
|
|
@@ -2849,7 +2938,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2849
2938
|
|| usedDeterministicHeuristicFastPath
|
|
2850
2939
|
|| isAssistantDeterministicHeuristicDirective(executionDirective)
|
|
2851
2940
|
|| zeroRowResult;
|
|
2852
|
-
if (!skipFollowupCodex) return [3 /*break*/,
|
|
2941
|
+
if (!skipFollowupCodex) return [3 /*break*/, 65];
|
|
2853
2942
|
recordStep('Drafting response: deterministic summary', {
|
|
2854
2943
|
reason: zeroRowResult
|
|
2855
2944
|
? 'zero_rows'
|
|
@@ -2859,36 +2948,36 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2859
2948
|
});
|
|
2860
2949
|
assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
|
|
2861
2950
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2862
|
-
return [3 /*break*/,
|
|
2863
|
-
case
|
|
2951
|
+
return [3 /*break*/, 71];
|
|
2952
|
+
case 65:
|
|
2864
2953
|
recordStep('Drafting response');
|
|
2865
2954
|
followupPrompt = buildAssistantCodexToolFollowupPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, toolPayload.prompt, assistantSystemPrompt);
|
|
2866
|
-
if (!hasRunBudget('Drafting response: followup')) return [3 /*break*/,
|
|
2867
|
-
|
|
2868
|
-
case
|
|
2869
|
-
|
|
2955
|
+
if (!hasRunBudget('Drafting response: followup')) return [3 /*break*/, 70];
|
|
2956
|
+
_21.label = 66;
|
|
2957
|
+
case 66:
|
|
2958
|
+
_21.trys.push([66, 68, , 69]);
|
|
2870
2959
|
followupStart = Date.now();
|
|
2871
2960
|
return [4 /*yield*/, runCodexInWorkerThread(followupPrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2872
|
-
case
|
|
2873
|
-
followupText =
|
|
2961
|
+
case 67:
|
|
2962
|
+
followupText = _21.sent();
|
|
2874
2963
|
accumulateCodexUsage(followupPrompt, followupText);
|
|
2875
2964
|
timingBreakdown.followupMs = Date.now() - followupStart;
|
|
2876
2965
|
assistantContent = sanitizeAssistantResponse(followupText);
|
|
2877
2966
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2878
|
-
return [3 /*break*/,
|
|
2879
|
-
case
|
|
2880
|
-
_e =
|
|
2967
|
+
return [3 /*break*/, 69];
|
|
2968
|
+
case 68:
|
|
2969
|
+
_e = _21.sent();
|
|
2881
2970
|
assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
|
|
2882
2971
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2883
|
-
return [3 /*break*/,
|
|
2884
|
-
case
|
|
2885
|
-
case
|
|
2972
|
+
return [3 /*break*/, 69];
|
|
2973
|
+
case 69: return [3 /*break*/, 71];
|
|
2974
|
+
case 70:
|
|
2886
2975
|
assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
|
|
2887
2976
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2888
|
-
|
|
2889
|
-
case
|
|
2890
|
-
case
|
|
2891
|
-
error_8 =
|
|
2977
|
+
_21.label = 71;
|
|
2978
|
+
case 71: return [3 /*break*/, 73];
|
|
2979
|
+
case 72:
|
|
2980
|
+
error_8 = _21.sent();
|
|
2892
2981
|
assistantContent = buildAssistantToolErrorMessage(error_8);
|
|
2893
2982
|
toolError = error_8;
|
|
2894
2983
|
errorMessage = normalizeOptionalString(error_8 === null || error_8 === void 0 ? void 0 : error_8.message) || 'Unknown error';
|
|
@@ -2897,22 +2986,22 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2897
2986
|
: { attempted: false };
|
|
2898
2987
|
toolTelemetry.final = __assign(__assign({}, existingFinal), { attempted: existingFinal.attempted === true, failed: true, error: errorMessage });
|
|
2899
2988
|
toolTelemetry.outcome = __assign(__assign({}, (toolTelemetry.outcome || {})), { error: errorMessage });
|
|
2900
|
-
return [3 /*break*/,
|
|
2901
|
-
case
|
|
2902
|
-
case
|
|
2989
|
+
return [3 /*break*/, 73];
|
|
2990
|
+
case 73: return [3 /*break*/, 75];
|
|
2991
|
+
case 74:
|
|
2903
2992
|
progressTracker.push(AI_ASSISTANT_PROGRESS_DRAFT);
|
|
2904
2993
|
recordStep('Drafting response');
|
|
2905
|
-
|
|
2906
|
-
case
|
|
2907
|
-
case
|
|
2908
|
-
error_9 =
|
|
2994
|
+
_21.label = 75;
|
|
2995
|
+
case 75: return [3 /*break*/, 78];
|
|
2996
|
+
case 76:
|
|
2997
|
+
error_9 = _21.sent();
|
|
2909
2998
|
assistantContent = buildAssistantCodexErrorMessage(error_9);
|
|
2910
2999
|
recordStep('Error', { message: normalizeOptionalString(error_9 === null || error_9 === void 0 ? void 0 : error_9.message) || 'Unknown error' });
|
|
2911
|
-
return [3 /*break*/,
|
|
2912
|
-
case
|
|
3000
|
+
return [3 /*break*/, 78];
|
|
3001
|
+
case 77:
|
|
2913
3002
|
progressTracker.stop();
|
|
2914
3003
|
return [7 /*endfinally*/];
|
|
2915
|
-
case
|
|
3004
|
+
case 78:
|
|
2916
3005
|
runBudgetExceeded = runDeadlineMs ? Date.now() > runDeadlineMs : false;
|
|
2917
3006
|
if (!assistantContent) {
|
|
2918
3007
|
assistantContent = runBudgetExceeded
|
|
@@ -2923,10 +3012,10 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2923
3012
|
assistantContent = applyAssistantDatedReportWindow(assistantContent, toolResult);
|
|
2924
3013
|
assistantContent = applyAssistantLotNumberResponseGuard(assistantContent, message, toolResult);
|
|
2925
3014
|
assistantContent = normalizeAssistantCurrencyText(assistantContent);
|
|
2926
|
-
if (toolError && !normalizeOptionalString((
|
|
3015
|
+
if (toolError && !normalizeOptionalString((_17 = toolTelemetry === null || toolTelemetry === void 0 ? void 0 : toolTelemetry.outcome) === null || _17 === void 0 ? void 0 : _17.error)) {
|
|
2927
3016
|
toolTelemetry.outcome = __assign(__assign({}, (toolTelemetry.outcome || {})), { error: normalizeOptionalString(toolError === null || toolError === void 0 ? void 0 : toolError.message) || 'tool_error' });
|
|
2928
3017
|
}
|
|
2929
|
-
if (((
|
|
3018
|
+
if (((_18 = toolResult === null || toolResult === void 0 ? void 0 : toolResult.output) === null || _18 === void 0 ? void 0 : _18.rowCount) === 0 && !((_19 = toolTelemetry === null || toolTelemetry === void 0 ? void 0 : toolTelemetry.outcome) === null || _19 === void 0 ? void 0 : _19.zeroRows)) {
|
|
2930
3019
|
toolTelemetry.outcome = __assign(__assign({}, (toolTelemetry.outcome || {})), { zeroRows: true });
|
|
2931
3020
|
}
|
|
2932
3021
|
includeToolExecutionTelemetry = dataQuestion
|
|
@@ -2956,9 +3045,9 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2956
3045
|
});
|
|
2957
3046
|
}
|
|
2958
3047
|
finalNow = new Date();
|
|
2959
|
-
|
|
2960
|
-
case
|
|
2961
|
-
|
|
3048
|
+
_21.label = 79;
|
|
3049
|
+
case 79:
|
|
3050
|
+
_21.trys.push([79, 91, , 102]);
|
|
2962
3051
|
if (canViewDebug) {
|
|
2963
3052
|
finishedAt = Date.now();
|
|
2964
3053
|
codexMs = timingBreakdown.directiveMs
|
|
@@ -3000,6 +3089,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3000
3089
|
collectionRanking: collectionRanking || undefined,
|
|
3001
3090
|
collectionSelection: collectionSelection || undefined,
|
|
3002
3091
|
collectionOverride: collectionOverride || undefined,
|
|
3092
|
+
dataRequestClassifier: appDataRequestClassifierDebug || undefined,
|
|
3003
3093
|
planner: plannerUsed ? {
|
|
3004
3094
|
enabled: true,
|
|
3005
3095
|
parsed: !!plannerOutput,
|
|
@@ -3058,13 +3148,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3058
3148
|
total_tokens: codexUsage.total_tokens
|
|
3059
3149
|
} : null;
|
|
3060
3150
|
finalUsageLedgerEntry = null;
|
|
3061
|
-
if (!finalUsage) return [3 /*break*/,
|
|
3151
|
+
if (!finalUsage) return [3 /*break*/, 84];
|
|
3062
3152
|
return [4 /*yield*/, resolveClientId(conversation, input.id_client, context === null || context === void 0 ? void 0 : context.id_user)];
|
|
3063
|
-
case
|
|
3064
|
-
usageClientId =
|
|
3065
|
-
|
|
3066
|
-
case
|
|
3067
|
-
|
|
3153
|
+
case 80:
|
|
3154
|
+
usageClientId = _21.sent();
|
|
3155
|
+
_21.label = 81;
|
|
3156
|
+
case 81:
|
|
3157
|
+
_21.trys.push([81, 83, , 84]);
|
|
3068
3158
|
finalUsageLedgerEntry = buildAssistantAIRunUsageLedgerEntry({
|
|
3069
3159
|
idClient: usageClientId || '',
|
|
3070
3160
|
model: finalUsage.model,
|
|
@@ -3084,16 +3174,16 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3084
3174
|
}
|
|
3085
3175
|
});
|
|
3086
3176
|
return [4 /*yield*/, (0, openai_usage_ledger_manager_1.recordOpenAIUsage)(finalUsageLedgerEntry)];
|
|
3087
|
-
case
|
|
3088
|
-
|
|
3089
|
-
return [3 /*break*/,
|
|
3090
|
-
case
|
|
3091
|
-
|
|
3092
|
-
console.error(new Date(), 'Failed to record AI usage',
|
|
3093
|
-
return [3 /*break*/,
|
|
3094
|
-
case
|
|
3177
|
+
case 82:
|
|
3178
|
+
_21.sent();
|
|
3179
|
+
return [3 /*break*/, 84];
|
|
3180
|
+
case 83:
|
|
3181
|
+
usageError_2 = _21.sent();
|
|
3182
|
+
console.error(new Date(), 'Failed to record AI usage', usageError_2);
|
|
3183
|
+
return [3 /*break*/, 84];
|
|
3184
|
+
case 84:
|
|
3095
3185
|
finalAssistantDoc = __assign(__assign(__assign(__assign({}, assistantDoc), { _id: assistantMessageId, content: assistantContent, metadata: finalMetadata }), (finalUsage ? { usage: finalUsage } : {})), { updatedAt: finalNow });
|
|
3096
|
-
if (!assistantMessageId) return [3 /*break*/,
|
|
3186
|
+
if (!assistantMessageId) return [3 /*break*/, 86];
|
|
3097
3187
|
setPayload = {
|
|
3098
3188
|
content: assistantContent,
|
|
3099
3189
|
metadata: finalMetadata,
|
|
@@ -3103,12 +3193,12 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3103
3193
|
setPayload.usage = finalUsage;
|
|
3104
3194
|
}
|
|
3105
3195
|
return [4 /*yield*/, updateAssistantMessageWithFallback(assistantMessageId, setPayload)];
|
|
3106
|
-
case
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
case
|
|
3110
|
-
case
|
|
3111
|
-
|
|
3196
|
+
case 85:
|
|
3197
|
+
_21.sent();
|
|
3198
|
+
_21.label = 86;
|
|
3199
|
+
case 86: return [4 /*yield*/, touchConversation(conversation._id, finalNow, assistantMessageId ? String(assistantMessageId) : undefined)];
|
|
3200
|
+
case 87:
|
|
3201
|
+
_21.sent();
|
|
3112
3202
|
return [4 /*yield*/, recordAssistantAnswerAIRun({
|
|
3113
3203
|
runId: buildAssistantAIRunId('codex_query', [conversation._id, assistantMessageId || requestId]),
|
|
3114
3204
|
requestId: requestId || undefined,
|
|
@@ -3117,7 +3207,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3117
3207
|
userMessage: __assign(__assign({}, userDoc), { _id: userMessageId ? String(userMessageId) : undefined }),
|
|
3118
3208
|
assistantMessage: finalAssistantDoc,
|
|
3119
3209
|
usageLedgerEntry: finalUsageLedgerEntry || undefined,
|
|
3120
|
-
correctnessChecks: ((
|
|
3210
|
+
correctnessChecks: ((_20 = toolTelemetry === null || toolTelemetry === void 0 ? void 0 : toolTelemetry.outcome) === null || _20 === void 0 ? void 0 : _20.error) ? [{
|
|
3121
3211
|
assertion: 'assistant_tool_execution',
|
|
3122
3212
|
status: 'fail',
|
|
3123
3213
|
observed: toolTelemetry.outcome.error,
|
|
@@ -3126,55 +3216,55 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
3126
3216
|
answerQuality: answerQualityEvidence,
|
|
3127
3217
|
now: finalNow
|
|
3128
3218
|
})];
|
|
3129
|
-
case
|
|
3130
|
-
|
|
3131
|
-
if (!(input.delete_files_after_run !== false)) return [3 /*break*/,
|
|
3219
|
+
case 88:
|
|
3220
|
+
_21.sent();
|
|
3221
|
+
if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 90];
|
|
3132
3222
|
return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
|
|
3133
|
-
case
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
case
|
|
3137
|
-
case
|
|
3138
|
-
finalizeError_1 =
|
|
3223
|
+
case 89:
|
|
3224
|
+
_21.sent();
|
|
3225
|
+
_21.label = 90;
|
|
3226
|
+
case 90: return [2 /*return*/, finalAssistantDoc];
|
|
3227
|
+
case 91:
|
|
3228
|
+
finalizeError_1 = _21.sent();
|
|
3139
3229
|
failedAt = new Date();
|
|
3140
3230
|
fallbackContent = assistantContent || buildAssistantCodexErrorMessage(finalizeError_1);
|
|
3141
3231
|
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' });
|
|
3142
|
-
|
|
3143
|
-
case
|
|
3144
|
-
|
|
3145
|
-
if (!assistantMessageId) return [3 /*break*/,
|
|
3232
|
+
_21.label = 92;
|
|
3233
|
+
case 92:
|
|
3234
|
+
_21.trys.push([92, 96, , 97]);
|
|
3235
|
+
if (!assistantMessageId) return [3 /*break*/, 94];
|
|
3146
3236
|
return [4 /*yield*/, updateAssistantMessageWithFallback(assistantMessageId, {
|
|
3147
3237
|
content: fallbackContent,
|
|
3148
3238
|
metadata: failureMetadata,
|
|
3149
3239
|
updatedAt: failedAt
|
|
3150
3240
|
})];
|
|
3151
|
-
case
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
case
|
|
3155
|
-
case
|
|
3156
|
-
|
|
3157
|
-
return [3 /*break*/,
|
|
3158
|
-
case
|
|
3159
|
-
persistError_1 =
|
|
3241
|
+
case 93:
|
|
3242
|
+
_21.sent();
|
|
3243
|
+
_21.label = 94;
|
|
3244
|
+
case 94: return [4 /*yield*/, touchConversation(conversation._id, failedAt, assistantMessageId ? String(assistantMessageId) : undefined)];
|
|
3245
|
+
case 95:
|
|
3246
|
+
_21.sent();
|
|
3247
|
+
return [3 /*break*/, 97];
|
|
3248
|
+
case 96:
|
|
3249
|
+
persistError_1 = _21.sent();
|
|
3160
3250
|
console.error(new Date(), 'AI assistant finalize fallback update failed', persistError_1);
|
|
3161
|
-
return [3 /*break*/,
|
|
3162
|
-
case
|
|
3163
|
-
if (!(input.delete_files_after_run !== false)) return [3 /*break*/,
|
|
3164
|
-
|
|
3165
|
-
case
|
|
3166
|
-
|
|
3251
|
+
return [3 /*break*/, 97];
|
|
3252
|
+
case 97:
|
|
3253
|
+
if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 101];
|
|
3254
|
+
_21.label = 98;
|
|
3255
|
+
case 98:
|
|
3256
|
+
_21.trys.push([98, 100, , 101]);
|
|
3167
3257
|
return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
|
|
3168
|
-
case
|
|
3169
|
-
|
|
3170
|
-
return [3 /*break*/,
|
|
3171
|
-
case
|
|
3172
|
-
_f =
|
|
3173
|
-
return [3 /*break*/,
|
|
3174
|
-
case
|
|
3258
|
+
case 99:
|
|
3259
|
+
_21.sent();
|
|
3260
|
+
return [3 /*break*/, 101];
|
|
3261
|
+
case 100:
|
|
3262
|
+
_f = _21.sent();
|
|
3263
|
+
return [3 /*break*/, 101];
|
|
3264
|
+
case 101:
|
|
3175
3265
|
console.error(new Date(), 'AI assistant run finalize failed:', finalizeError_1);
|
|
3176
3266
|
return [2 /*return*/, __assign(__assign({}, assistantDoc), { _id: assistantMessageId, content: fallbackContent, metadata: failureMetadata, updatedAt: failedAt })];
|
|
3177
|
-
case
|
|
3267
|
+
case 102: return [2 /*return*/];
|
|
3178
3268
|
}
|
|
3179
3269
|
});
|
|
3180
3270
|
}); });
|
|
@@ -6868,29 +6958,40 @@ function scoreAssistantAppDataIntent(messageText, intent) {
|
|
|
6868
6958
|
return score + (term.includes(' ') ? 4 : 1);
|
|
6869
6959
|
}, 0);
|
|
6870
6960
|
}
|
|
6871
|
-
function
|
|
6961
|
+
function rankAssistantAppDataIntentCandidates(message, collectionNames, appId, options) {
|
|
6872
6962
|
var text = normalizeOptionalString(message).toLowerCase();
|
|
6873
6963
|
if (!text) {
|
|
6874
|
-
return
|
|
6964
|
+
return [];
|
|
6875
6965
|
}
|
|
6876
6966
|
var availableNames = new Set((Array.isArray(collectionNames) ? collectionNames : []).map(function (value) { return normalizeOptionalString(value); }).filter(Boolean));
|
|
6877
6967
|
var profile = resolveAssistantAppHeuristicProfile(appId);
|
|
6878
|
-
var
|
|
6879
|
-
|
|
6968
|
+
var includeUnscored = (options === null || options === void 0 ? void 0 : options.includeUnscored) === true;
|
|
6969
|
+
var limit = Math.max(1, Math.min((0, common_1.round)((options === null || options === void 0 ? void 0 : options.limit) || 6), 12));
|
|
6970
|
+
return profile.dataIntents
|
|
6971
|
+
.filter(function (intent) {
|
|
6880
6972
|
if (!(intent === null || intent === void 0 ? void 0 : intent.id) || !intent.collection) {
|
|
6881
|
-
return;
|
|
6882
|
-
}
|
|
6883
|
-
if (availableNames.size && !availableNames.has(intent.collection)) {
|
|
6884
|
-
return;
|
|
6885
|
-
}
|
|
6886
|
-
var score = scoreAssistantAppDataIntent(text, intent);
|
|
6887
|
-
if (score <= 0) {
|
|
6888
|
-
return;
|
|
6973
|
+
return false;
|
|
6889
6974
|
}
|
|
6890
|
-
|
|
6891
|
-
|
|
6975
|
+
return !availableNames.size || availableNames.has(intent.collection);
|
|
6976
|
+
})
|
|
6977
|
+
.map(function (intent) { return ({
|
|
6978
|
+
intent: intent,
|
|
6979
|
+
score: scoreAssistantAppDataIntent(text, intent)
|
|
6980
|
+
}); })
|
|
6981
|
+
.filter(function (candidate) { return includeUnscored || candidate.score > 0; })
|
|
6982
|
+
.sort(function (a, b) {
|
|
6983
|
+
if (b.score !== a.score) {
|
|
6984
|
+
return b.score - a.score;
|
|
6892
6985
|
}
|
|
6893
|
-
|
|
6986
|
+
return a.intent.id.localeCompare(b.intent.id);
|
|
6987
|
+
})
|
|
6988
|
+
.slice(0, limit);
|
|
6989
|
+
}
|
|
6990
|
+
function selectAssistantAppDataIntent(message, collectionNames, appId) {
|
|
6991
|
+
var selected = rankAssistantAppDataIntentCandidates(message, collectionNames, appId, {
|
|
6992
|
+
includeUnscored: false,
|
|
6993
|
+
limit: 1
|
|
6994
|
+
})[0];
|
|
6894
6995
|
return selected ? selected.intent : null;
|
|
6895
6996
|
}
|
|
6896
6997
|
function extractAssistantDataIntentCustomerText(message) {
|
|
@@ -7167,24 +7268,31 @@ function cleanAssistantRequestedDimensionText(value) {
|
|
|
7167
7268
|
text = text.replace(/[^a-z0-9_ -]+/gi, ' ');
|
|
7168
7269
|
return normalizeOptionalString(text.replace(/\s+/g, ' ')).toLowerCase();
|
|
7169
7270
|
}
|
|
7170
|
-
function
|
|
7271
|
+
function extractAssistantRequestedBreakdownDimensionTexts(message) {
|
|
7171
7272
|
var e_5, _a;
|
|
7172
7273
|
var text = normalizeOptionalString(message).toLowerCase();
|
|
7173
7274
|
if (!text) {
|
|
7174
|
-
return
|
|
7275
|
+
return [];
|
|
7276
|
+
}
|
|
7277
|
+
var extracted = extractAssistantRequestedBreakdownDimensions(text)
|
|
7278
|
+
.map(function (value) { return cleanAssistantRequestedDimensionText(value); })
|
|
7279
|
+
.filter(Boolean);
|
|
7280
|
+
if (extracted.length) {
|
|
7281
|
+
return mergeAssistantHintValues(extracted);
|
|
7175
7282
|
}
|
|
7176
7283
|
var patterns = [
|
|
7177
7284
|
/\b(?:group(?:ed)?|break(?:\s*down)?|broken\s+down|split)\s+by\s+([a-z0-9][a-z0-9_ -]{0,50}?)(?=\s+(?:for|from|to|until|through|during|this|last|past|current|where|with|and|or)\b|[,.!?;]|$)/i,
|
|
7178
7285
|
/\bby\s+([a-z0-9][a-z0-9_ -]{0,50}?)(?=\s+(?:for|from|to|until|through|during|this|last|past|current|where|with|and|or)\b|[,.!?;]|$)/i,
|
|
7179
7286
|
/\bper\s+([a-z0-9][a-z0-9_ -]{0,50}?)(?=\s+(?:for|from|to|until|through|during|this|last|past|current|where|with|and|or)\b|[,.!?;]|$)/i
|
|
7180
7287
|
];
|
|
7288
|
+
var results = [];
|
|
7181
7289
|
try {
|
|
7182
7290
|
for (var patterns_2 = __values(patterns), patterns_2_1 = patterns_2.next(); !patterns_2_1.done; patterns_2_1 = patterns_2.next()) {
|
|
7183
7291
|
var pattern = patterns_2_1.value;
|
|
7184
7292
|
var match = text.match(pattern);
|
|
7185
7293
|
var dimensionText = cleanAssistantRequestedDimensionText((match === null || match === void 0 ? void 0 : match[1]) || '');
|
|
7186
7294
|
if (dimensionText) {
|
|
7187
|
-
|
|
7295
|
+
results.push(dimensionText);
|
|
7188
7296
|
}
|
|
7189
7297
|
}
|
|
7190
7298
|
}
|
|
@@ -7195,7 +7303,7 @@ function extractAssistantRequestedBreakdownDimensionText(message) {
|
|
|
7195
7303
|
}
|
|
7196
7304
|
finally { if (e_5) throw e_5.error; }
|
|
7197
7305
|
}
|
|
7198
|
-
return
|
|
7306
|
+
return mergeAssistantHintValues(results);
|
|
7199
7307
|
}
|
|
7200
7308
|
function scoreAssistantDataDimensionMatch(requestedDimensionText, dimension) {
|
|
7201
7309
|
var requested = cleanAssistantRequestedDimensionText(requestedDimensionText);
|
|
@@ -7224,22 +7332,637 @@ function scoreAssistantDataDimensionMatch(requestedDimensionText, dimension) {
|
|
|
7224
7332
|
});
|
|
7225
7333
|
return score;
|
|
7226
7334
|
}
|
|
7227
|
-
function
|
|
7228
|
-
var
|
|
7229
|
-
if (!
|
|
7335
|
+
function resolveAssistantTimeBreakdownGranularity(requestedDimensionText) {
|
|
7336
|
+
var requested = cleanAssistantRequestedDimensionText(requestedDimensionText);
|
|
7337
|
+
if (!requested) {
|
|
7338
|
+
return '';
|
|
7339
|
+
}
|
|
7340
|
+
if (/\b(quarter|quarters|quarterly|qtr|qtrs)\b/i.test(requested)) {
|
|
7341
|
+
return 'quarter';
|
|
7342
|
+
}
|
|
7343
|
+
if (/\b(month|months|monthly)\b/i.test(requested)) {
|
|
7344
|
+
return 'month';
|
|
7345
|
+
}
|
|
7346
|
+
if (/\b(week|weeks|weekly)\b/i.test(requested)) {
|
|
7347
|
+
return 'week';
|
|
7348
|
+
}
|
|
7349
|
+
if (/\b(day|days|daily|date)\b/i.test(requested)) {
|
|
7350
|
+
return requested === 'date' ? 'date' : 'day';
|
|
7351
|
+
}
|
|
7352
|
+
if (/\b(year|years|yearly|annual|annually)\b/i.test(requested)) {
|
|
7353
|
+
return 'year';
|
|
7354
|
+
}
|
|
7355
|
+
return '';
|
|
7356
|
+
}
|
|
7357
|
+
function buildAssistantTimeBreakdownGroupExpression(granularity, dateField) {
|
|
7358
|
+
var dateOperand = "$".concat(dateField);
|
|
7359
|
+
if (granularity === 'quarter') {
|
|
7360
|
+
return {
|
|
7361
|
+
$concat: [
|
|
7362
|
+
{ $toString: { $year: dateOperand } },
|
|
7363
|
+
'-Q',
|
|
7364
|
+
{ $toString: { $ceil: { $divide: [{ $month: dateOperand }, 3] } } }
|
|
7365
|
+
]
|
|
7366
|
+
};
|
|
7367
|
+
}
|
|
7368
|
+
var format = granularity === 'year'
|
|
7369
|
+
? '%Y'
|
|
7370
|
+
: granularity === 'week'
|
|
7371
|
+
? '%Y-W%U'
|
|
7372
|
+
: granularity === 'day' || granularity === 'date'
|
|
7373
|
+
? '%Y-%m-%d'
|
|
7374
|
+
: '%Y-%m';
|
|
7375
|
+
return {
|
|
7376
|
+
$dateToString: {
|
|
7377
|
+
format: format,
|
|
7378
|
+
date: dateOperand
|
|
7379
|
+
}
|
|
7380
|
+
};
|
|
7381
|
+
}
|
|
7382
|
+
function buildAssistantDataIntentTimeDimension(requestedDimensionText, intent) {
|
|
7383
|
+
var _a, _b, _c;
|
|
7384
|
+
var granularity = resolveAssistantTimeBreakdownGranularity(requestedDimensionText);
|
|
7385
|
+
var dateField = normalizeOptionalString(intent.dateField);
|
|
7386
|
+
if (!granularity || !dateField) {
|
|
7230
7387
|
return null;
|
|
7231
7388
|
}
|
|
7232
|
-
var
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7389
|
+
var id = granularity === 'date' ? 'date' : granularity;
|
|
7390
|
+
return {
|
|
7391
|
+
id: id,
|
|
7392
|
+
type: 'time',
|
|
7393
|
+
granularity: granularity,
|
|
7394
|
+
requestedText: requestedDimensionText,
|
|
7395
|
+
terms: [id, requestedDimensionText].filter(Boolean),
|
|
7396
|
+
groupId: (_a = {},
|
|
7397
|
+
_a[id] = buildAssistantTimeBreakdownGroupExpression(granularity, dateField),
|
|
7398
|
+
_a),
|
|
7399
|
+
project: (_b = {},
|
|
7400
|
+
_b[id] = "$_id.".concat(id),
|
|
7401
|
+
_b),
|
|
7402
|
+
sort: (_c = {},
|
|
7403
|
+
_c[id] = 1,
|
|
7404
|
+
_c)
|
|
7405
|
+
};
|
|
7406
|
+
}
|
|
7407
|
+
function extractAssistantDataIntentExpressionFieldHints(value, hints) {
|
|
7408
|
+
if (hints === void 0) { hints = new Set(); }
|
|
7409
|
+
if (typeof value === 'string') {
|
|
7410
|
+
if (value.startsWith('$') && !value.startsWith('$$') && !value.startsWith('$_id.')) {
|
|
7411
|
+
var path_1 = normalizeOptionalString(value.slice(1));
|
|
7412
|
+
if (path_1) {
|
|
7413
|
+
hints.add(path_1);
|
|
7414
|
+
}
|
|
7415
|
+
}
|
|
7416
|
+
return Array.from(hints);
|
|
7417
|
+
}
|
|
7418
|
+
if (Array.isArray(value)) {
|
|
7419
|
+
value.forEach(function (entry) { return extractAssistantDataIntentExpressionFieldHints(entry, hints); });
|
|
7420
|
+
return Array.from(hints);
|
|
7421
|
+
}
|
|
7422
|
+
if (value && typeof value === 'object') {
|
|
7423
|
+
Object.keys(value).forEach(function (key) { return extractAssistantDataIntentExpressionFieldHints(value[key], hints); });
|
|
7424
|
+
}
|
|
7425
|
+
return Array.from(hints);
|
|
7426
|
+
}
|
|
7427
|
+
function buildAssistantDataRequestMeasures(intent, pipeline) {
|
|
7428
|
+
var _a;
|
|
7429
|
+
var measures = [];
|
|
7430
|
+
var add = function (value) {
|
|
7431
|
+
var normalized = normalizeOptionalString(value);
|
|
7432
|
+
if (normalized && !measures.includes(normalized)) {
|
|
7433
|
+
measures.push(normalized);
|
|
7434
|
+
}
|
|
7435
|
+
};
|
|
7436
|
+
var groupIndex = findAggregateGroupIndex(pipeline || []);
|
|
7437
|
+
if (groupIndex > -1) {
|
|
7438
|
+
var groupStage = (_a = pipeline[groupIndex]) === null || _a === void 0 ? void 0 : _a.$group;
|
|
7439
|
+
if (groupStage && typeof groupStage === 'object') {
|
|
7440
|
+
Object.keys(groupStage).forEach(function (key) {
|
|
7441
|
+
if (key === '_id') {
|
|
7442
|
+
return;
|
|
7443
|
+
}
|
|
7444
|
+
if (/^(first|last|min|max)_/i.test(key) || /_ids?$/i.test(key) || key === 'blend_ids') {
|
|
7445
|
+
return;
|
|
7446
|
+
}
|
|
7447
|
+
add(key);
|
|
7448
|
+
});
|
|
7449
|
+
}
|
|
7450
|
+
}
|
|
7451
|
+
add(intent.quantityField ? intent.quantityField.split('.').pop() || intent.quantityField : '');
|
|
7452
|
+
add(intent.metricField ? intent.metricField.split('.').pop() || intent.metricField : '');
|
|
7453
|
+
if (!measures.length) {
|
|
7454
|
+
add('row_count');
|
|
7455
|
+
}
|
|
7456
|
+
return measures;
|
|
7457
|
+
}
|
|
7458
|
+
function clampAssistantConfidence(value, fallback) {
|
|
7459
|
+
if (fallback === void 0) { fallback = 0.75; }
|
|
7460
|
+
var parsed = Number(value);
|
|
7461
|
+
if (!Number.isFinite(parsed)) {
|
|
7462
|
+
return fallback;
|
|
7463
|
+
}
|
|
7464
|
+
return Math.max(0, Math.min(parsed, 1));
|
|
7465
|
+
}
|
|
7466
|
+
function normalizeAssistantContractStringList(value, max) {
|
|
7467
|
+
if (max === void 0) { max = 12; }
|
|
7468
|
+
var source = Array.isArray(value) ? value : (normalizeOptionalString(value) ? [value] : []);
|
|
7469
|
+
var values = [];
|
|
7470
|
+
source.forEach(function (entry) {
|
|
7471
|
+
var normalized = normalizeOptionalString(entry);
|
|
7472
|
+
if (!normalized || values.includes(normalized)) {
|
|
7236
7473
|
return;
|
|
7237
7474
|
}
|
|
7238
|
-
|
|
7239
|
-
|
|
7475
|
+
values.push(normalized.slice(0, 160));
|
|
7476
|
+
});
|
|
7477
|
+
return values.slice(0, max);
|
|
7478
|
+
}
|
|
7479
|
+
function normalizeAssistantContractFilters(value) {
|
|
7480
|
+
if (!Array.isArray(value)) {
|
|
7481
|
+
return [];
|
|
7482
|
+
}
|
|
7483
|
+
return value
|
|
7484
|
+
.filter(function (entry) { return !!entry && typeof entry === 'object' && !Array.isArray(entry); })
|
|
7485
|
+
.map(function (entry) { return Object.keys(entry).reduce(function (acc, key) {
|
|
7486
|
+
var normalizedKey = normalizeOptionalString(key);
|
|
7487
|
+
if (!normalizedKey || shouldRedactField(normalizedKey)) {
|
|
7488
|
+
return acc;
|
|
7489
|
+
}
|
|
7490
|
+
var rawValue = entry[key];
|
|
7491
|
+
if (rawValue === undefined || rawValue === null) {
|
|
7492
|
+
return acc;
|
|
7493
|
+
}
|
|
7494
|
+
if (typeof rawValue === 'object') {
|
|
7495
|
+
try {
|
|
7496
|
+
acc[normalizedKey] = JSON.parse(JSON.stringify(rawValue));
|
|
7497
|
+
}
|
|
7498
|
+
catch (_a) {
|
|
7499
|
+
acc[normalizedKey] = normalizeOptionalString(rawValue).slice(0, 240);
|
|
7500
|
+
}
|
|
7501
|
+
return acc;
|
|
7502
|
+
}
|
|
7503
|
+
acc[normalizedKey] = normalizeOptionalString(rawValue).slice(0, 240);
|
|
7504
|
+
return acc;
|
|
7505
|
+
}, {}); })
|
|
7506
|
+
.filter(function (entry) { return Object.keys(entry).length > 0; })
|
|
7507
|
+
.slice(0, 12);
|
|
7508
|
+
}
|
|
7509
|
+
function normalizeAssistantContractDateRange(value) {
|
|
7510
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
7511
|
+
return null;
|
|
7512
|
+
}
|
|
7513
|
+
var start = normalizeOptionalString(value.start || value.start_date || value.startDate);
|
|
7514
|
+
var end = normalizeOptionalString(value.end || value.end_date || value.endDate);
|
|
7515
|
+
var year = normalizeOptionalNumber(value.year);
|
|
7516
|
+
var result = {};
|
|
7517
|
+
if (start) {
|
|
7518
|
+
result.start = start;
|
|
7519
|
+
}
|
|
7520
|
+
if (end) {
|
|
7521
|
+
result.end = end;
|
|
7522
|
+
}
|
|
7523
|
+
if (year && year >= 1900 && year <= 3000) {
|
|
7524
|
+
result.year = (0, common_1.round)(year);
|
|
7525
|
+
}
|
|
7526
|
+
return Object.keys(result).length ? result : null;
|
|
7527
|
+
}
|
|
7528
|
+
function extractAssistantDataRequestClassifierRoot(value) {
|
|
7529
|
+
if (!value || typeof value !== 'object') {
|
|
7530
|
+
return value;
|
|
7531
|
+
}
|
|
7532
|
+
return value.request
|
|
7533
|
+
|| value.contract
|
|
7534
|
+
|| value.data_request
|
|
7535
|
+
|| value.dataRequest
|
|
7536
|
+
|| value;
|
|
7537
|
+
}
|
|
7538
|
+
function normalizeAssistantDataRequestBreakdownContract(value) {
|
|
7539
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
7540
|
+
var text_1 = cleanAssistantRequestedDimensionText(normalizeOptionalString(value));
|
|
7541
|
+
return text_1 ? { type: 'unknown', requested_text: text_1 } : null;
|
|
7542
|
+
}
|
|
7543
|
+
var rawType = normalizeOptionalString(value.type || value.kind).toLowerCase();
|
|
7544
|
+
var requestedText = cleanAssistantRequestedDimensionText(value.requested_text
|
|
7545
|
+
|| value.requestedText
|
|
7546
|
+
|| value.text
|
|
7547
|
+
|| value.label
|
|
7548
|
+
|| value.dimension
|
|
7549
|
+
|| value.field
|
|
7550
|
+
|| value.granularity);
|
|
7551
|
+
var dimension = cleanAssistantRequestedDimensionText(value.dimension
|
|
7552
|
+
|| value.dimension_id
|
|
7553
|
+
|| value.dimensionId
|
|
7554
|
+
|| '');
|
|
7555
|
+
var granularity = cleanAssistantRequestedDimensionText(value.granularity
|
|
7556
|
+
|| value.time_grain
|
|
7557
|
+
|| value.timeGrain
|
|
7558
|
+
|| '');
|
|
7559
|
+
var fieldHint = normalizeOptionalString(value.field_hint || value.fieldHint || value.date_field || value.dateField);
|
|
7560
|
+
var fieldHints = normalizeAssistantContractStringList(value.field_hints || value.fieldHints || value.fields, 8);
|
|
7561
|
+
var inferredGranularity = granularity || resolveAssistantTimeBreakdownGranularity(requestedText || dimension);
|
|
7562
|
+
var type = rawType === 'time' || inferredGranularity
|
|
7563
|
+
? 'time'
|
|
7564
|
+
: rawType === 'entity'
|
|
7565
|
+
? 'entity'
|
|
7566
|
+
: rawType === 'unknown'
|
|
7567
|
+
? 'unknown'
|
|
7568
|
+
: 'unknown';
|
|
7569
|
+
var text = requestedText || dimension || granularity;
|
|
7570
|
+
if (!text) {
|
|
7571
|
+
return null;
|
|
7572
|
+
}
|
|
7573
|
+
return __assign(__assign(__assign(__assign({ type: type, requested_text: text }, (dimension ? { dimension: dimension } : {})), (inferredGranularity ? { granularity: inferredGranularity } : {})), (fieldHint ? { field_hint: fieldHint } : {})), (fieldHints.length ? { field_hints: fieldHints } : {}));
|
|
7574
|
+
}
|
|
7575
|
+
function normalizeAssistantDataRequestContract(value, intent, dateWindow, source) {
|
|
7576
|
+
if (source === void 0) { source = 'mini_model_classifier'; }
|
|
7577
|
+
var root = extractAssistantDataRequestClassifierRoot(value);
|
|
7578
|
+
if (!root || typeof root !== 'object' || Array.isArray(root)) {
|
|
7579
|
+
return null;
|
|
7580
|
+
}
|
|
7581
|
+
var breakdownSource = root.requested_breakdowns
|
|
7582
|
+
|| root.requestedBreakdowns
|
|
7583
|
+
|| root.breakdowns
|
|
7584
|
+
|| root.groupings
|
|
7585
|
+
|| root.group_by
|
|
7586
|
+
|| root.groupBy
|
|
7587
|
+
|| [];
|
|
7588
|
+
var requestedBreakdowns = (Array.isArray(breakdownSource) ? breakdownSource : [breakdownSource])
|
|
7589
|
+
.map(function (entry) { return normalizeAssistantDataRequestBreakdownContract(entry); })
|
|
7590
|
+
.filter(function (entry) { return !!entry; });
|
|
7591
|
+
var dateRange = normalizeAssistantContractDateRange(root.date_range || root.dateRange)
|
|
7592
|
+
|| (dateWindow.start || dateWindow.end ? __assign({}, dateWindow) : null);
|
|
7593
|
+
var intentId = normalizeOptionalString(root.intent_id || root.intentId || intent.id);
|
|
7594
|
+
var collection = normalizeOptionalString(root.collection || intent.collection);
|
|
7595
|
+
return {
|
|
7596
|
+
intent_type: 'data_summary',
|
|
7597
|
+
intent_id: intentId || undefined,
|
|
7598
|
+
domain: normalizeOptionalString(root.domain || intent.id || intent.collection),
|
|
7599
|
+
collection: collection || undefined,
|
|
7600
|
+
operation: 'aggregate',
|
|
7601
|
+
requested_breakdowns: requestedBreakdowns,
|
|
7602
|
+
date_range: dateRange,
|
|
7603
|
+
measures: normalizeAssistantContractStringList(root.measures || root.metrics || root.measure, 16),
|
|
7604
|
+
filters: normalizeAssistantContractFilters(root.filters || root.where),
|
|
7605
|
+
output_format: 'collapse_table',
|
|
7606
|
+
ambiguities: normalizeAssistantContractStringList(root.ambiguities || root.questions || root.uncertainties, 8),
|
|
7607
|
+
confidence: clampAssistantConfidence(root.confidence, requestedBreakdowns.length ? 0.82 : 0.65),
|
|
7608
|
+
source: source
|
|
7609
|
+
};
|
|
7610
|
+
}
|
|
7611
|
+
function buildAssistantRequestedBreakdownCandidates(message, classifierContract) {
|
|
7612
|
+
var candidates = [];
|
|
7613
|
+
var seen = new Set();
|
|
7614
|
+
var add = function (text, breakdown) {
|
|
7615
|
+
var normalized = cleanAssistantRequestedDimensionText(text);
|
|
7616
|
+
if (!normalized) {
|
|
7617
|
+
return;
|
|
7618
|
+
}
|
|
7619
|
+
var key = [
|
|
7620
|
+
(breakdown === null || breakdown === void 0 ? void 0 : breakdown.type) || '',
|
|
7621
|
+
(breakdown === null || breakdown === void 0 ? void 0 : breakdown.granularity) || '',
|
|
7622
|
+
(breakdown === null || breakdown === void 0 ? void 0 : breakdown.dimension) || '',
|
|
7623
|
+
normalized
|
|
7624
|
+
].join(':');
|
|
7625
|
+
if (seen.has(key)) {
|
|
7626
|
+
return;
|
|
7240
7627
|
}
|
|
7628
|
+
seen.add(key);
|
|
7629
|
+
candidates.push({ text: normalized, breakdown: breakdown });
|
|
7630
|
+
};
|
|
7631
|
+
((classifierContract === null || classifierContract === void 0 ? void 0 : classifierContract.requested_breakdowns) || []).forEach(function (breakdown) {
|
|
7632
|
+
add(breakdown.granularity
|
|
7633
|
+
|| breakdown.dimension
|
|
7634
|
+
|| breakdown.requested_text, breakdown);
|
|
7241
7635
|
});
|
|
7242
|
-
|
|
7636
|
+
extractAssistantRequestedBreakdownDimensionTexts(message).forEach(function (text) { return add(text); });
|
|
7637
|
+
return candidates;
|
|
7638
|
+
}
|
|
7639
|
+
function buildAssistantDataRequestClassifierCandidatePayload(candidate) {
|
|
7640
|
+
var intent = candidate.intent;
|
|
7641
|
+
return {
|
|
7642
|
+
intent_id: intent.id,
|
|
7643
|
+
collection: intent.collection,
|
|
7644
|
+
permission_view: intent.permissionView || undefined,
|
|
7645
|
+
score: candidate.score,
|
|
7646
|
+
trigger_terms: (intent.terms || []).slice(0, 16),
|
|
7647
|
+
date_field: intent.dateField || undefined,
|
|
7648
|
+
quantity_field: intent.quantityField || undefined,
|
|
7649
|
+
metric_field: intent.metricField || undefined,
|
|
7650
|
+
dimensions: (intent.dimensions || []).map(function (dimension) { return ({
|
|
7651
|
+
id: dimension.id,
|
|
7652
|
+
type: dimension.type || 'entity',
|
|
7653
|
+
granularity: dimension.granularity || undefined,
|
|
7654
|
+
terms: (dimension.terms || []).slice(0, 12),
|
|
7655
|
+
field_hints: extractAssistantDataIntentExpressionFieldHints(dimension.groupId).slice(0, 8)
|
|
7656
|
+
}); })
|
|
7657
|
+
};
|
|
7658
|
+
}
|
|
7659
|
+
function buildAssistantDataRequestClassifierMessages(params) {
|
|
7660
|
+
var systemPrompt = [
|
|
7661
|
+
'Classify one business app data request into strict JSON.',
|
|
7662
|
+
'Use only the supplied app-owned intent candidates and configured dimensions.',
|
|
7663
|
+
'Do not create MongoDB pipelines, queries, field paths, or collections.',
|
|
7664
|
+
'Preserve every explicit grouping phrase: "by month by chemical" must produce two requested_breakdowns, one for month and one for chemical.',
|
|
7665
|
+
'Interpret "by", "per", "break down by", and "group by" as requested_breakdowns.',
|
|
7666
|
+
'Interpret date phrases like "this month", "last month", "until June 12", and "last 6 months" as date_range or filters when clear.',
|
|
7667
|
+
'For time breakdowns, set type="time" and granularity to one of year, quarter, month, week, day, date.',
|
|
7668
|
+
'For configured dimensions, set type="entity" and dimension to the candidate dimension id.',
|
|
7669
|
+
'If unsure, include an ambiguity instead of guessing.',
|
|
7670
|
+
'Always set output_format to "collapse_table".',
|
|
7671
|
+
'Return JSON only with keys: intent_id, domain, collection, operation, requested_breakdowns, date_range, measures, filters, output_format, ambiguities, confidence.'
|
|
7672
|
+
].join('\n');
|
|
7673
|
+
var userPayload = {
|
|
7674
|
+
message: params.message,
|
|
7675
|
+
app_id: normalizeOptionalString(params.appId) || undefined,
|
|
7676
|
+
candidates: params.candidates.map(buildAssistantDataRequestClassifierCandidatePayload)
|
|
7677
|
+
};
|
|
7678
|
+
return [
|
|
7679
|
+
{ role: 'system', content: systemPrompt },
|
|
7680
|
+
{ role: 'user', content: JSON.stringify(userPayload) }
|
|
7681
|
+
];
|
|
7682
|
+
}
|
|
7683
|
+
function resolveAssistantDataRequestClassifierEnabled(config) {
|
|
7684
|
+
var override = normalizeOptionalBoolean((config === null || config === void 0 ? void 0 : config.data_request_classifier_enabled)
|
|
7685
|
+
|| (config === null || config === void 0 ? void 0 : config.dataRequestClassifierEnabled));
|
|
7686
|
+
if (typeof override === 'boolean') {
|
|
7687
|
+
return override;
|
|
7688
|
+
}
|
|
7689
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
7690
|
+
var raw = normalizeOptionalBoolean(serverConfig['AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_ENABLED']
|
|
7691
|
+
|| process.env.AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_ENABLED
|
|
7692
|
+
|| serverConfig['AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_ENABLED']
|
|
7693
|
+
|| process.env.AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_ENABLED);
|
|
7694
|
+
return raw === undefined ? true : raw === true;
|
|
7695
|
+
}
|
|
7696
|
+
function resolveAssistantDataRequestClassifierModel(config) {
|
|
7697
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
7698
|
+
return normalizeOptionalString((config === null || config === void 0 ? void 0 : config.data_request_classifier_model)
|
|
7699
|
+
|| (config === null || config === void 0 ? void 0 : config.dataRequestClassifierModel)
|
|
7700
|
+
|| serverConfig['AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_MODEL']
|
|
7701
|
+
|| process.env.AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_MODEL
|
|
7702
|
+
|| serverConfig['AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_MODEL']
|
|
7703
|
+
|| process.env.AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_MODEL
|
|
7704
|
+
|| serverConfig['AI_ASSISTANT_INTENT_MODEL']
|
|
7705
|
+
|| process.env.AI_ASSISTANT_INTENT_MODEL
|
|
7706
|
+
|| 'gpt-5.4-mini');
|
|
7707
|
+
}
|
|
7708
|
+
function resolveAssistantDataRequestClassifierTimeoutMs(config) {
|
|
7709
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
7710
|
+
var raw = normalizeOptionalNumber((config === null || config === void 0 ? void 0 : config.data_request_classifier_timeout_ms)
|
|
7711
|
+
|| (config === null || config === void 0 ? void 0 : config.dataRequestClassifierTimeoutMs)
|
|
7712
|
+
|| serverConfig['AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_TIMEOUT_MS']
|
|
7713
|
+
|| process.env.AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_TIMEOUT_MS
|
|
7714
|
+
|| serverConfig['AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_TIMEOUT_MS']
|
|
7715
|
+
|| process.env.AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_TIMEOUT_MS);
|
|
7716
|
+
if (raw && raw > 0) {
|
|
7717
|
+
return Math.max(250, Math.min((0, common_1.round)(raw), 5000));
|
|
7718
|
+
}
|
|
7719
|
+
return 1800;
|
|
7720
|
+
}
|
|
7721
|
+
function resolveAssistantDataRequestClassifierMaxTokens() {
|
|
7722
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
7723
|
+
var raw = normalizeOptionalNumber(serverConfig['AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_MAX_TOKENS']
|
|
7724
|
+
|| process.env.AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_MAX_TOKENS
|
|
7725
|
+
|| serverConfig['AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_MAX_TOKENS']
|
|
7726
|
+
|| process.env.AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_MAX_TOKENS);
|
|
7727
|
+
if (raw && raw > 0) {
|
|
7728
|
+
return Math.max(128, Math.min((0, common_1.round)(raw), 1200));
|
|
7729
|
+
}
|
|
7730
|
+
return 650;
|
|
7731
|
+
}
|
|
7732
|
+
function resolveAssistantDataRequestClassifierIntent(raw, candidates) {
|
|
7733
|
+
var _a, _b;
|
|
7734
|
+
var root = extractAssistantDataRequestClassifierRoot(raw);
|
|
7735
|
+
var rawKeys = [
|
|
7736
|
+
root === null || root === void 0 ? void 0 : root.intent_id,
|
|
7737
|
+
root === null || root === void 0 ? void 0 : root.intentId,
|
|
7738
|
+
root === null || root === void 0 ? void 0 : root.domain,
|
|
7739
|
+
root === null || root === void 0 ? void 0 : root.collection
|
|
7740
|
+
].map(function (value) { return normalizeCollectionKey(normalizeOptionalString(value)); }).filter(Boolean);
|
|
7741
|
+
if (!rawKeys.length) {
|
|
7742
|
+
return ((_a = candidates[0]) === null || _a === void 0 ? void 0 : _a.intent) || null;
|
|
7743
|
+
}
|
|
7744
|
+
var selected = candidates.find(function (candidate) {
|
|
7745
|
+
var intentKeys = [
|
|
7746
|
+
candidate.intent.id,
|
|
7747
|
+
candidate.intent.collection
|
|
7748
|
+
].map(function (value) { return normalizeCollectionKey(normalizeOptionalString(value)); }).filter(Boolean);
|
|
7749
|
+
return rawKeys.some(function (key) { return intentKeys.includes(key); });
|
|
7750
|
+
});
|
|
7751
|
+
return (selected === null || selected === void 0 ? void 0 : selected.intent) || ((_b = candidates[0]) === null || _b === void 0 ? void 0 : _b.intent) || null;
|
|
7752
|
+
}
|
|
7753
|
+
function classifyAssistantAppDataRequest(params) {
|
|
7754
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7755
|
+
var candidates, serverConfig, apiKey, model, timeoutMs, messages, start, client, response, parsed, intent, contract, understanding, error_15;
|
|
7756
|
+
var _a, _b, _c;
|
|
7757
|
+
return __generator(this, function (_d) {
|
|
7758
|
+
switch (_d.label) {
|
|
7759
|
+
case 0:
|
|
7760
|
+
if (!resolveAssistantDataRequestClassifierEnabled(params.config)) {
|
|
7761
|
+
return [2 /*return*/, {
|
|
7762
|
+
debug: {
|
|
7763
|
+
enabled: false,
|
|
7764
|
+
reason: 'disabled'
|
|
7765
|
+
}
|
|
7766
|
+
}];
|
|
7767
|
+
}
|
|
7768
|
+
candidates = rankAssistantAppDataIntentCandidates(params.message, params.collectionNames, params.appId, { includeUnscored: true, limit: 6 });
|
|
7769
|
+
if (!candidates.length) {
|
|
7770
|
+
return [2 /*return*/, {
|
|
7771
|
+
debug: {
|
|
7772
|
+
enabled: true,
|
|
7773
|
+
attempted: false,
|
|
7774
|
+
reason: 'no_app_data_intent_candidates'
|
|
7775
|
+
}
|
|
7776
|
+
}];
|
|
7777
|
+
}
|
|
7778
|
+
serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
7779
|
+
apiKey = normalizeOptionalString(serverConfig['OPENAI_API_KEY'] || process.env.OPENAI_API_KEY);
|
|
7780
|
+
if (!apiKey) {
|
|
7781
|
+
return [2 /*return*/, {
|
|
7782
|
+
debug: {
|
|
7783
|
+
enabled: true,
|
|
7784
|
+
attempted: false,
|
|
7785
|
+
reason: 'missing_openai_api_key',
|
|
7786
|
+
candidates: candidates.map(function (candidate) { return ({ intentId: candidate.intent.id, score: candidate.score }); })
|
|
7787
|
+
}
|
|
7788
|
+
}];
|
|
7789
|
+
}
|
|
7790
|
+
model = resolveAssistantDataRequestClassifierModel(params.config);
|
|
7791
|
+
timeoutMs = resolveAssistantDataRequestClassifierTimeoutMs(params.config);
|
|
7792
|
+
messages = buildAssistantDataRequestClassifierMessages({
|
|
7793
|
+
message: params.message,
|
|
7794
|
+
appId: params.appId,
|
|
7795
|
+
candidates: candidates
|
|
7796
|
+
});
|
|
7797
|
+
start = Date.now();
|
|
7798
|
+
_d.label = 1;
|
|
7799
|
+
case 1:
|
|
7800
|
+
_d.trys.push([1, 3, , 4]);
|
|
7801
|
+
client = new openai_client_1.OpenAIClient({
|
|
7802
|
+
apiKey: apiKey,
|
|
7803
|
+
baseUrl: normalizeOptionalString(serverConfig['OPENAI_BASE_URL'] || process.env.OPENAI_BASE_URL) || undefined,
|
|
7804
|
+
model: model,
|
|
7805
|
+
temperature: 0,
|
|
7806
|
+
maxRetries: 0,
|
|
7807
|
+
maxTokens: resolveAssistantDataRequestClassifierMaxTokens(),
|
|
7808
|
+
responseFormat: 'json_object'
|
|
7809
|
+
});
|
|
7810
|
+
return [4 /*yield*/, client.chat(messages, {
|
|
7811
|
+
timeoutMs: timeoutMs,
|
|
7812
|
+
responseFormat: 'json_object'
|
|
7813
|
+
})];
|
|
7814
|
+
case 2:
|
|
7815
|
+
response = _d.sent();
|
|
7816
|
+
parsed = parseJsonObject(response.content);
|
|
7817
|
+
intent = resolveAssistantDataRequestClassifierIntent(parsed, candidates);
|
|
7818
|
+
contract = intent
|
|
7819
|
+
? normalizeAssistantDataRequestContract(parsed, intent, params.dateWindow, 'mini_model_classifier')
|
|
7820
|
+
: null;
|
|
7821
|
+
understanding = intent && contract
|
|
7822
|
+
? buildAssistantDataRequestUnderstanding(params.message, intent, params.dateWindow, contract)
|
|
7823
|
+
: null;
|
|
7824
|
+
return [2 /*return*/, {
|
|
7825
|
+
intent: intent,
|
|
7826
|
+
understanding: understanding,
|
|
7827
|
+
debug: {
|
|
7828
|
+
enabled: true,
|
|
7829
|
+
attempted: true,
|
|
7830
|
+
succeeded: !!understanding,
|
|
7831
|
+
model: response.model || model,
|
|
7832
|
+
durationMs: Date.now() - start,
|
|
7833
|
+
intentId: (intent === null || intent === void 0 ? void 0 : intent.id) || undefined,
|
|
7834
|
+
requestedBreakdowns: ((_a = understanding === null || understanding === void 0 ? void 0 : understanding.contract) === null || _a === void 0 ? void 0 : _a.requested_breakdowns) || undefined,
|
|
7835
|
+
ambiguities: ((_b = understanding === null || understanding === void 0 ? void 0 : understanding.contract) === null || _b === void 0 ? void 0 : _b.ambiguities) || undefined,
|
|
7836
|
+
confidence: (_c = understanding === null || understanding === void 0 ? void 0 : understanding.contract) === null || _c === void 0 ? void 0 : _c.confidence,
|
|
7837
|
+
candidates: candidates.map(function (candidate) { return ({ intentId: candidate.intent.id, score: candidate.score }); }),
|
|
7838
|
+
parseSucceeded: !!parsed
|
|
7839
|
+
},
|
|
7840
|
+
usage: response.usage ? {
|
|
7841
|
+
model: response.model || model,
|
|
7842
|
+
inputTokens: response.usage.inputTokens,
|
|
7843
|
+
outputTokens: response.usage.outputTokens,
|
|
7844
|
+
totalTokens: response.usage.totalTokens,
|
|
7845
|
+
requestId: response.requestId
|
|
7846
|
+
} : undefined
|
|
7847
|
+
}];
|
|
7848
|
+
case 3:
|
|
7849
|
+
error_15 = _d.sent();
|
|
7850
|
+
return [2 /*return*/, {
|
|
7851
|
+
debug: {
|
|
7852
|
+
enabled: true,
|
|
7853
|
+
attempted: true,
|
|
7854
|
+
succeeded: false,
|
|
7855
|
+
model: model,
|
|
7856
|
+
durationMs: Date.now() - start,
|
|
7857
|
+
error: normalizeOptionalString(error_15 === null || error_15 === void 0 ? void 0 : error_15.message) || 'classifier_failed',
|
|
7858
|
+
candidates: candidates.map(function (candidate) { return ({ intentId: candidate.intent.id, score: candidate.score }); })
|
|
7859
|
+
}
|
|
7860
|
+
}];
|
|
7861
|
+
case 4: return [2 /*return*/];
|
|
7862
|
+
}
|
|
7863
|
+
});
|
|
7864
|
+
});
|
|
7865
|
+
}
|
|
7866
|
+
function buildAssistantDataRequestUnderstanding(message, intent, dateWindow, classifierContract) {
|
|
7867
|
+
var normalizedClassifierContract = classifierContract
|
|
7868
|
+
? normalizeAssistantDataRequestContract(classifierContract, intent, dateWindow, classifierContract.source || 'mini_model_classifier')
|
|
7869
|
+
: null;
|
|
7870
|
+
var requestedBreakdownCandidates = buildAssistantRequestedBreakdownCandidates(message, normalizedClassifierContract);
|
|
7871
|
+
var dimensions = [];
|
|
7872
|
+
var requestedBreakdowns = [];
|
|
7873
|
+
var ambiguities = [];
|
|
7874
|
+
var seenDimensionIds = new Set();
|
|
7875
|
+
var addDimension = function (dimension) {
|
|
7876
|
+
var id = normalizeOptionalString(dimension.id);
|
|
7877
|
+
if (!id || seenDimensionIds.has(id)) {
|
|
7878
|
+
return;
|
|
7879
|
+
}
|
|
7880
|
+
if ((dimension.type || '') === 'time' && dimensions.some(function (entry) { return (entry.type || '') === 'time'; })) {
|
|
7881
|
+
return;
|
|
7882
|
+
}
|
|
7883
|
+
seenDimensionIds.add(id);
|
|
7884
|
+
dimensions.push(dimension);
|
|
7885
|
+
};
|
|
7886
|
+
requestedBreakdownCandidates.forEach(function (candidate) {
|
|
7887
|
+
var _a;
|
|
7888
|
+
var requestedDimensionText = candidate.text;
|
|
7889
|
+
var requestedGranularity = ((_a = candidate.breakdown) === null || _a === void 0 ? void 0 : _a.granularity) || resolveAssistantTimeBreakdownGranularity(requestedDimensionText);
|
|
7890
|
+
var timeDimension = requestedGranularity
|
|
7891
|
+
? buildAssistantDataIntentTimeDimension(requestedGranularity, intent)
|
|
7892
|
+
: null;
|
|
7893
|
+
if (timeDimension) {
|
|
7894
|
+
addDimension(timeDimension);
|
|
7895
|
+
requestedBreakdowns.push({
|
|
7896
|
+
type: 'time',
|
|
7897
|
+
requested_text: requestedDimensionText,
|
|
7898
|
+
dimension: timeDimension.id,
|
|
7899
|
+
granularity: timeDimension.granularity,
|
|
7900
|
+
field_hint: intent.dateField
|
|
7901
|
+
});
|
|
7902
|
+
return;
|
|
7903
|
+
}
|
|
7904
|
+
if (requestedGranularity && !intent.dateField) {
|
|
7905
|
+
ambiguities.push("Requested ".concat(requestedDimensionText, " breakdown, but this app data intent has no date field."));
|
|
7906
|
+
requestedBreakdowns.push({
|
|
7907
|
+
type: 'unknown',
|
|
7908
|
+
requested_text: requestedDimensionText,
|
|
7909
|
+
granularity: requestedGranularity
|
|
7910
|
+
});
|
|
7911
|
+
return;
|
|
7912
|
+
}
|
|
7913
|
+
var selected = null;
|
|
7914
|
+
(intent.dimensions || []).forEach(function (dimension) {
|
|
7915
|
+
var _a;
|
|
7916
|
+
var score = Math.max(scoreAssistantDataDimensionMatch(requestedDimensionText, dimension), ((_a = candidate.breakdown) === null || _a === void 0 ? void 0 : _a.dimension) && cleanAssistantRequestedDimensionText(candidate.breakdown.dimension) === cleanAssistantRequestedDimensionText(dimension.id)
|
|
7917
|
+
? 10
|
|
7918
|
+
: 0);
|
|
7919
|
+
if (score <= 0) {
|
|
7920
|
+
return;
|
|
7921
|
+
}
|
|
7922
|
+
if (!selected || score > selected.score) {
|
|
7923
|
+
selected = { dimension: dimension, score: score };
|
|
7924
|
+
}
|
|
7925
|
+
});
|
|
7926
|
+
if (selected) {
|
|
7927
|
+
var dimension = __assign(__assign({}, selected.dimension), { type: selected.dimension.type || 'entity', requestedText: requestedDimensionText });
|
|
7928
|
+
addDimension(dimension);
|
|
7929
|
+
requestedBreakdowns.push({
|
|
7930
|
+
type: 'entity',
|
|
7931
|
+
requested_text: requestedDimensionText,
|
|
7932
|
+
dimension: dimension.id,
|
|
7933
|
+
field_hints: extractAssistantDataIntentExpressionFieldHints(dimension.groupId)
|
|
7934
|
+
});
|
|
7935
|
+
return;
|
|
7936
|
+
}
|
|
7937
|
+
ambiguities.push("Requested ".concat(requestedDimensionText, " breakdown did not match a configured app dimension."));
|
|
7938
|
+
requestedBreakdowns.push({
|
|
7939
|
+
type: 'unknown',
|
|
7940
|
+
requested_text: requestedDimensionText
|
|
7941
|
+
});
|
|
7942
|
+
});
|
|
7943
|
+
var confidence = requestedBreakdowns.length && !ambiguities.length
|
|
7944
|
+
? clampAssistantConfidence(normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.confidence, 0.9)
|
|
7945
|
+
: requestedBreakdowns.length
|
|
7946
|
+
? clampAssistantConfidence(normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.confidence, 0.65)
|
|
7947
|
+
: clampAssistantConfidence(normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.confidence, 0.75);
|
|
7948
|
+
return {
|
|
7949
|
+
dimensions: dimensions,
|
|
7950
|
+
contract: {
|
|
7951
|
+
intent_type: 'data_summary',
|
|
7952
|
+
intent_id: (normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.intent_id) || intent.id,
|
|
7953
|
+
domain: intent.id || intent.collection,
|
|
7954
|
+
collection: intent.collection,
|
|
7955
|
+
operation: 'aggregate',
|
|
7956
|
+
requested_breakdowns: requestedBreakdowns,
|
|
7957
|
+
date_range: (normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.date_range) || (dateWindow.start || dateWindow.end ? __assign({}, dateWindow) : null),
|
|
7958
|
+
measures: (normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.measures) || [],
|
|
7959
|
+
filters: (normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.filters) || [],
|
|
7960
|
+
output_format: 'collapse_table',
|
|
7961
|
+
ambiguities: mergeAssistantHintValues((normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.ambiguities) || [], ambiguities),
|
|
7962
|
+
confidence: confidence,
|
|
7963
|
+
source: (normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.source) || 'fast_app_data_request_contract'
|
|
7964
|
+
}
|
|
7965
|
+
};
|
|
7243
7966
|
}
|
|
7244
7967
|
function extractAssistantDataIntentGroupKeys(groupId) {
|
|
7245
7968
|
if (!groupId || typeof groupId !== 'object' || Array.isArray(groupId)) {
|
|
@@ -7259,8 +7982,9 @@ function applyAssistantDataIntentDimensionTemplate(dimension, params) {
|
|
|
7259
7982
|
? removeUndefinedAssistantPipelineValues(applyAssistantDataIntentPipelineTemplate(dimension.preGroupStages, params))
|
|
7260
7983
|
: undefined });
|
|
7261
7984
|
}
|
|
7262
|
-
function
|
|
7263
|
-
|
|
7985
|
+
function applyAssistantDataIntentDimensionsToPipeline(pipeline, dimensions) {
|
|
7986
|
+
var selectedDimensions = (Array.isArray(dimensions) ? dimensions : []).filter(function (dimension) { return !!(dimension === null || dimension === void 0 ? void 0 : dimension.groupId); });
|
|
7987
|
+
if (!selectedDimensions.length || !Array.isArray(pipeline) || !pipeline.length) {
|
|
7264
7988
|
return pipeline;
|
|
7265
7989
|
}
|
|
7266
7990
|
var next = (0, common_1.deepCopy)(pipeline);
|
|
@@ -7268,17 +7992,25 @@ function applyAssistantDataIntentDimensionToPipeline(pipeline, dimension) {
|
|
|
7268
7992
|
if (groupIndex === -1) {
|
|
7269
7993
|
return next;
|
|
7270
7994
|
}
|
|
7271
|
-
|
|
7272
|
-
|
|
7273
|
-
|
|
7274
|
-
|
|
7995
|
+
selectedDimensions.forEach(function (dimension) {
|
|
7996
|
+
if (Array.isArray(dimension.preGroupStages) && dimension.preGroupStages.length) {
|
|
7997
|
+
next.splice.apply(next, __spreadArray([groupIndex, 0], __read((0, common_1.deepCopy)(dimension.preGroupStages)), false));
|
|
7998
|
+
groupIndex += dimension.preGroupStages.length;
|
|
7999
|
+
}
|
|
8000
|
+
});
|
|
7275
8001
|
var groupStage = next[groupIndex];
|
|
7276
8002
|
if (!(groupStage === null || groupStage === void 0 ? void 0 : groupStage.$group) || typeof groupStage.$group !== 'object') {
|
|
7277
8003
|
return next;
|
|
7278
8004
|
}
|
|
7279
8005
|
var oldGroupKeys = new Set(extractAssistantDataIntentGroupKeys(groupStage.$group._id));
|
|
7280
|
-
var
|
|
7281
|
-
|
|
8006
|
+
var combinedGroupId = {};
|
|
8007
|
+
selectedDimensions.forEach(function (dimension) {
|
|
8008
|
+
if (dimension.groupId && typeof dimension.groupId === 'object' && !Array.isArray(dimension.groupId)) {
|
|
8009
|
+
Object.assign(combinedGroupId, (0, common_1.deepCopy)(dimension.groupId));
|
|
8010
|
+
}
|
|
8011
|
+
});
|
|
8012
|
+
var newGroupKeys = new Set(extractAssistantDataIntentGroupKeys(combinedGroupId));
|
|
8013
|
+
groupStage.$group._id = combinedGroupId;
|
|
7282
8014
|
var projectIndex = next.findIndex(function (stage, index) { return index > groupIndex && !!(stage === null || stage === void 0 ? void 0 : stage.$project); });
|
|
7283
8015
|
if (projectIndex > -1 && next[projectIndex].$project && typeof next[projectIndex].$project === 'object') {
|
|
7284
8016
|
var project_1 = next[projectIndex].$project;
|
|
@@ -7287,48 +8019,59 @@ function applyAssistantDataIntentDimensionToPipeline(pipeline, dimension) {
|
|
|
7287
8019
|
delete project_1[key];
|
|
7288
8020
|
}
|
|
7289
8021
|
});
|
|
7290
|
-
|
|
7291
|
-
|
|
7292
|
-
|
|
8022
|
+
selectedDimensions.forEach(function (dimension) {
|
|
8023
|
+
if (dimension.project) {
|
|
8024
|
+
Object.assign(project_1, (0, common_1.deepCopy)(dimension.project));
|
|
8025
|
+
}
|
|
8026
|
+
});
|
|
7293
8027
|
}
|
|
7294
8028
|
var sortIndex = next.findIndex(function (stage, index) { return index > groupIndex && !!(stage === null || stage === void 0 ? void 0 : stage.$sort); });
|
|
7295
|
-
if (sortIndex > -1
|
|
7296
|
-
|
|
8029
|
+
if (sortIndex > -1) {
|
|
8030
|
+
var combinedSort_1 = {};
|
|
8031
|
+
selectedDimensions.forEach(function (dimension) {
|
|
8032
|
+
if (dimension.sort && typeof dimension.sort === 'object' && !Array.isArray(dimension.sort)) {
|
|
8033
|
+
Object.keys(dimension.sort).forEach(function (key) {
|
|
8034
|
+
var _a;
|
|
8035
|
+
if (!Object.prototype.hasOwnProperty.call(combinedSort_1, key)) {
|
|
8036
|
+
combinedSort_1[key] = (0, common_1.deepCopy)((_a = dimension.sort) === null || _a === void 0 ? void 0 : _a[key]);
|
|
8037
|
+
}
|
|
8038
|
+
});
|
|
8039
|
+
}
|
|
8040
|
+
});
|
|
8041
|
+
if (Object.keys(combinedSort_1).length) {
|
|
8042
|
+
next[sortIndex].$sort = combinedSort_1;
|
|
8043
|
+
}
|
|
7297
8044
|
}
|
|
7298
8045
|
return next;
|
|
7299
8046
|
}
|
|
7300
|
-
function buildAssistantAppDataIntentDirective(message, collectionNames, appId) {
|
|
8047
|
+
function buildAssistantAppDataIntentDirective(message, collectionNames, appId, options) {
|
|
7301
8048
|
if (collectionNames === void 0) { collectionNames = []; }
|
|
7302
|
-
var intent = selectAssistantAppDataIntent(message, collectionNames, appId);
|
|
8049
|
+
var intent = (options === null || options === void 0 ? void 0 : options.appDataIntent) || selectAssistantAppDataIntent(message, collectionNames, appId);
|
|
7303
8050
|
if (!intent) {
|
|
7304
8051
|
return null;
|
|
7305
8052
|
}
|
|
7306
8053
|
var customerText = extractAssistantDataIntentCustomerText(message);
|
|
7307
8054
|
var dateWindow = resolveAssistantDataIntentDateWindow(message);
|
|
7308
|
-
var
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
:
|
|
8055
|
+
var requestUnderstanding = (options === null || options === void 0 ? void 0 : options.appDataRequestUnderstanding)
|
|
8056
|
+
|| buildAssistantDataRequestUnderstanding(message, intent, dateWindow, (options === null || options === void 0 ? void 0 : options.appDataRequestContract) || null);
|
|
8057
|
+
var templatedDimensions = requestUnderstanding.dimensions
|
|
8058
|
+
.map(function (dimension) { return applyAssistantDataIntentDimensionTemplate(dimension, { customerText: customerText, dateWindow: dateWindow }); })
|
|
8059
|
+
.filter(function (dimension) { return !!(dimension === null || dimension === void 0 ? void 0 : dimension.groupId); });
|
|
7312
8060
|
var acknowledgementText = buildAssistantDataIntentAcknowledgement(intent, customerText, dateWindow);
|
|
7313
8061
|
var progress = intent.progress.map(function (entry) {
|
|
7314
8062
|
return entry
|
|
7315
8063
|
.replace(/\{\{customer\}\}/g, customerText || 'the requested customer')
|
|
7316
8064
|
.replace(/\{\{year\}\}/g, dateWindow.year ? String(dateWindow.year) : 'the requested date range');
|
|
7317
8065
|
});
|
|
7318
|
-
var metadata = {
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
requestedDimension: templatedDimension ? {
|
|
7328
|
-
id: templatedDimension.id,
|
|
7329
|
-
terms: templatedDimension.terms
|
|
7330
|
-
} : null
|
|
7331
|
-
};
|
|
8066
|
+
var metadata = __assign({ intentId: intent.id, recipeUsed: intent.id, acknowledgementText: acknowledgementText, progress: progress, assumptions: intent.assumptions, fallbackCollections: intent.fallbackCollections, customerText: customerText, dateWindow: dateWindow, requestedDimension: templatedDimensions[0] ? {
|
|
8067
|
+
id: templatedDimensions[0].id,
|
|
8068
|
+
terms: templatedDimensions[0].terms
|
|
8069
|
+
} : null, requestedDimensions: templatedDimensions.map(function (dimension) { return ({
|
|
8070
|
+
id: dimension.id,
|
|
8071
|
+
type: dimension.type || 'entity',
|
|
8072
|
+
granularity: dimension.granularity || undefined,
|
|
8073
|
+
terms: dimension.terms
|
|
8074
|
+
}); }), requestContract: requestUnderstanding.contract }, ((options === null || options === void 0 ? void 0 : options.appDataRequestClassifier) ? { requestClassifier: options.appDataRequestClassifier } : {}));
|
|
7332
8075
|
var basePayload = function (pipeline) { return ({
|
|
7333
8076
|
collection: intent.collection,
|
|
7334
8077
|
permissionView: intent.permissionView || resolveDefaultAssistantPermissionView(intent.collection),
|
|
@@ -7339,20 +8082,21 @@ function buildAssistantAppDataIntentDirective(message, collectionNames, appId) {
|
|
|
7339
8082
|
var pipeline = configuredPipeline.length
|
|
7340
8083
|
? configuredPipeline
|
|
7341
8084
|
: buildAssistantGenericDataIntentPipeline(intent, customerText, dateWindow);
|
|
7342
|
-
var finalPipeline =
|
|
8085
|
+
var finalPipeline = applyAssistantDataIntentDimensionsToPipeline(pipeline, templatedDimensions);
|
|
8086
|
+
metadata.requestContract = __assign(__assign({}, requestUnderstanding.contract), { measures: buildAssistantDataRequestMeasures(intent, finalPipeline) });
|
|
7343
8087
|
return { type: 'aggregate', payload: basePayload(finalPipeline), cleaned: '', rawLine: "HEURISTIC_AGG(app-data-intent:".concat(intent.id, ")"), metadata: metadata };
|
|
7344
8088
|
}
|
|
7345
8089
|
function isAssistantDeterministicHeuristicDirective(directive) {
|
|
7346
8090
|
return isAssistantSchemaHoursHeuristicDirective(directive)
|
|
7347
8091
|
|| isAssistantAppDataIntentHeuristicDirective(directive);
|
|
7348
8092
|
}
|
|
7349
|
-
function buildAssistantHeuristicDirective(message, collectionHints, collectionNames, appId) {
|
|
8093
|
+
function buildAssistantHeuristicDirective(message, collectionHints, collectionNames, appId, options) {
|
|
7350
8094
|
if (collectionNames === void 0) { collectionNames = []; }
|
|
7351
8095
|
if (!normalizeOptionalString(message)) {
|
|
7352
8096
|
return null;
|
|
7353
8097
|
}
|
|
7354
8098
|
var appDataIntentDirective = resolveAssistantDeterministicHeuristicEnabled(AI_ASSISTANT_HEURISTIC_ID_APP_DATA_INTENT, appId)
|
|
7355
|
-
? buildAssistantAppDataIntentDirective(message, collectionNames, appId)
|
|
8099
|
+
? buildAssistantAppDataIntentDirective(message, collectionNames, appId, options)
|
|
7356
8100
|
: null;
|
|
7357
8101
|
if (appDataIntentDirective) {
|
|
7358
8102
|
return appDataIntentDirective;
|
|
@@ -7365,9 +8109,17 @@ function buildAssistantHeuristicDirective(message, collectionHints, collectionNa
|
|
|
7365
8109
|
}
|
|
7366
8110
|
return null;
|
|
7367
8111
|
}
|
|
7368
|
-
function resolveAssistantHeuristicDirectiveForTesting(message, collectionHints, collectionNames, appId) {
|
|
8112
|
+
function resolveAssistantHeuristicDirectiveForTesting(message, collectionHints, collectionNames, appId, options) {
|
|
7369
8113
|
if (collectionNames === void 0) { collectionNames = []; }
|
|
7370
|
-
return buildAssistantHeuristicDirective(message, collectionHints, collectionNames, appId);
|
|
8114
|
+
return buildAssistantHeuristicDirective(message, collectionHints, collectionNames, appId, options);
|
|
8115
|
+
}
|
|
8116
|
+
function buildAssistantDataRequestClassifierMessagesForTesting(params) {
|
|
8117
|
+
var candidates = rankAssistantAppDataIntentCandidates(params.message, params.collectionNames || [], params.appId, { includeUnscored: true, limit: 6 });
|
|
8118
|
+
return buildAssistantDataRequestClassifierMessages({
|
|
8119
|
+
message: params.message,
|
|
8120
|
+
appId: params.appId,
|
|
8121
|
+
candidates: candidates
|
|
8122
|
+
});
|
|
7371
8123
|
}
|
|
7372
8124
|
function resolveDefaultAssistantPermissionView(collection) {
|
|
7373
8125
|
var normalizedCollection = normalizeOptionalString(collection).toLowerCase();
|
|
@@ -8045,7 +8797,7 @@ function buildAssistantToolResultPayload(directive, toolResponse, requestMessage
|
|
|
8045
8797
|
? toolResponse.verification
|
|
8046
8798
|
: undefined;
|
|
8047
8799
|
var directiveMetadata = directive.metadata && typeof directive.metadata === 'object' ? directive.metadata : {};
|
|
8048
|
-
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 } : {}));
|
|
8800
|
+
var mergedDebug = __assign(__assign(__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 } : {})), (directiveMetadata.requestContract && typeof directiveMetadata.requestContract === 'object' ? { requestContract: directiveMetadata.requestContract } : {})), (Array.isArray(directiveMetadata.requestedDimensions) && directiveMetadata.requestedDimensions.length ? { requestedDimensions: directiveMetadata.requestedDimensions } : {})), (Array.isArray(directiveMetadata.assumptions) && directiveMetadata.assumptions.length ? { assumptions: directiveMetadata.assumptions } : {}));
|
|
8049
8801
|
var result = {
|
|
8050
8802
|
type: directive.type === 'aggregate' ? 'mongo_agg' : 'mongo_read',
|
|
8051
8803
|
input: directivePayload,
|
|
@@ -8633,14 +9385,14 @@ function buildAssistantDebugPayload(params) {
|
|
|
8633
9385
|
else {
|
|
8634
9386
|
notes.push("Report builder bridge collection: ".concat(from, " -> ").concat(to, "."));
|
|
8635
9387
|
}
|
|
8636
|
-
var
|
|
9388
|
+
var path_2 = Array.isArray(fallbackInfo.reportBuilderBridge.resolutionPath)
|
|
8637
9389
|
? fallbackInfo.reportBuilderBridge.resolutionPath
|
|
8638
9390
|
.map(function (entry) { return normalizeOptionalString(entry); })
|
|
8639
9391
|
.filter(Boolean)
|
|
8640
9392
|
.join(' -> ')
|
|
8641
9393
|
: '';
|
|
8642
|
-
if (
|
|
8643
|
-
notes.push("Bridge resolution path: ".concat(
|
|
9394
|
+
if (path_2) {
|
|
9395
|
+
notes.push("Bridge resolution path: ".concat(path_2, "."));
|
|
8644
9396
|
}
|
|
8645
9397
|
}
|
|
8646
9398
|
if ((_w = fallbackInfo === null || fallbackInfo === void 0 ? void 0 : fallbackInfo.reportFallback) === null || _w === void 0 ? void 0 : _w.used) {
|
|
@@ -16076,6 +16828,9 @@ function cloneAssistantHeuristicProfile(profile) {
|
|
|
16076
16828
|
dimensions: Array.isArray(entry === null || entry === void 0 ? void 0 : entry.dimensions)
|
|
16077
16829
|
? entry.dimensions.map(function (dimension) { return ({
|
|
16078
16830
|
id: normalizeOptionalString(dimension === null || dimension === void 0 ? void 0 : dimension.id),
|
|
16831
|
+
type: normalizeAssistantAppDataDimensionType(dimension === null || dimension === void 0 ? void 0 : dimension.type),
|
|
16832
|
+
granularity: normalizeOptionalString(dimension === null || dimension === void 0 ? void 0 : dimension.granularity) || undefined,
|
|
16833
|
+
requestedText: normalizeOptionalString(dimension === null || dimension === void 0 ? void 0 : dimension.requestedText) || undefined,
|
|
16079
16834
|
terms: mergeAssistantHintValues((dimension === null || dimension === void 0 ? void 0 : dimension.terms) || []).map(function (term) { return term.toLowerCase(); }),
|
|
16080
16835
|
groupId: (0, common_1.deepCopy)(dimension === null || dimension === void 0 ? void 0 : dimension.groupId),
|
|
16081
16836
|
project: (dimension === null || dimension === void 0 ? void 0 : dimension.project) && typeof dimension.project === 'object' && !Array.isArray(dimension.project)
|
|
@@ -16180,6 +16935,13 @@ function normalizeAssistantDisplayDateFormat(value) {
|
|
|
16180
16935
|
}
|
|
16181
16936
|
return undefined;
|
|
16182
16937
|
}
|
|
16938
|
+
function normalizeAssistantAppDataDimensionType(value) {
|
|
16939
|
+
var normalized = normalizeOptionalString(value).toLowerCase();
|
|
16940
|
+
if (normalized === 'time' || normalized === 'entity') {
|
|
16941
|
+
return normalized;
|
|
16942
|
+
}
|
|
16943
|
+
return undefined;
|
|
16944
|
+
}
|
|
16183
16945
|
function normalizeAssistantHeuristicStringList(value) {
|
|
16184
16946
|
if (Array.isArray(value)) {
|
|
16185
16947
|
return mergeAssistantHintValues(value.map(function (entry) { return normalizeOptionalString(entry).toLowerCase(); }));
|
|
@@ -16268,6 +17030,8 @@ function normalizeAssistantAppDataDimensions(value) {
|
|
|
16268
17030
|
|| [id]).map(function (term) { return term.toLowerCase(); });
|
|
16269
17031
|
dimensions.push({
|
|
16270
17032
|
id: id,
|
|
17033
|
+
type: normalizeAssistantAppDataDimensionType(entry.type),
|
|
17034
|
+
granularity: normalizeOptionalString(entry.granularity) || undefined,
|
|
16271
17035
|
terms: terms.length ? terms : [id.toLowerCase()],
|
|
16272
17036
|
groupId: (0, common_1.deepCopy)(groupId),
|
|
16273
17037
|
project: entry.project && typeof entry.project === 'object' && !Array.isArray(entry.project)
|
|
@@ -19542,7 +20306,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
19542
20306
|
}
|
|
19543
20307
|
function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler) {
|
|
19544
20308
|
return __awaiter(this, void 0, void 0, function () {
|
|
19545
|
-
var streamedOptions, normalizedThreadKey, shouldForceInProcessThreadReuse, codexClient, codexClient, workerPath, codexClient,
|
|
20309
|
+
var streamedOptions, normalizedThreadKey, shouldForceInProcessThreadReuse, codexClient, codexClient, workerPath, codexClient, error_16, codexClient;
|
|
19546
20310
|
return __generator(this, function (_a) {
|
|
19547
20311
|
switch (_a.label) {
|
|
19548
20312
|
case 0:
|
|
@@ -19570,11 +20334,11 @@ function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler)
|
|
|
19570
20334
|
return [4 /*yield*/, runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config, streamStatusHandler)];
|
|
19571
20335
|
case 8: return [2 /*return*/, _a.sent()];
|
|
19572
20336
|
case 9:
|
|
19573
|
-
|
|
19574
|
-
if (!(
|
|
19575
|
-
throw
|
|
20337
|
+
error_16 = _a.sent();
|
|
20338
|
+
if (!(error_16 instanceof CodexWorkerBootstrapError)) {
|
|
20339
|
+
throw error_16;
|
|
19576
20340
|
}
|
|
19577
|
-
console.error('AI worker bootstrap failed, falling back to in-process run.',
|
|
20341
|
+
console.error('AI worker bootstrap failed, falling back to in-process run.', error_16);
|
|
19578
20342
|
codexClient = getAssistantCodexClient(config);
|
|
19579
20343
|
return [4 /*yield*/, codexClient.run(prompt, streamedOptions)];
|
|
19580
20344
|
case 10: return [2 /*return*/, _a.sent()];
|
|
@@ -19612,7 +20376,7 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
19612
20376
|
timeoutMs = ((sanitizedOptions === null || sanitizedOptions === void 0 ? void 0 : sanitizedOptions.timeoutMs) || resolveCodexTimeoutMs()) + 15000;
|
|
19613
20377
|
timeoutController = new AbortController();
|
|
19614
20378
|
timeoutPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
19615
|
-
var
|
|
20379
|
+
var error_17;
|
|
19616
20380
|
return __generator(this, function (_a) {
|
|
19617
20381
|
switch (_a.label) {
|
|
19618
20382
|
case 0:
|
|
@@ -19622,11 +20386,11 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
19622
20386
|
_a.sent();
|
|
19623
20387
|
return [2 /*return*/, { type: 'timeout' }];
|
|
19624
20388
|
case 2:
|
|
19625
|
-
|
|
19626
|
-
if ((
|
|
20389
|
+
error_17 = _a.sent();
|
|
20390
|
+
if ((error_17 === null || error_17 === void 0 ? void 0 : error_17.name) === 'AbortError') {
|
|
19627
20391
|
return [2 /*return*/, { type: 'aborted' }];
|
|
19628
20392
|
}
|
|
19629
|
-
throw
|
|
20393
|
+
throw error_17;
|
|
19630
20394
|
case 3: return [2 /*return*/];
|
|
19631
20395
|
}
|
|
19632
20396
|
});
|
|
@@ -20399,10 +21163,10 @@ function extractAssistantRequestedBreakdownDimensions(message) {
|
|
|
20399
21163
|
results.push(normalized);
|
|
20400
21164
|
};
|
|
20401
21165
|
var patterns = [
|
|
20402
|
-
/\bgroup(?:ed)?\s+by\s+([a-z0-9_-]+(?:\s+[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
|
|
20403
|
-
/\bbreak(?:\s+up|\s*down)?\b[\s\S]{0,80}?\bby\s+([a-z0-9_-]+(?:\s+[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
|
|
20404
|
-
/\b(?:by|per)\s+(?:each\s+)?([a-z0-9_-]+(?:\s+[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
|
|
20405
|
-
/\bfor\s+each\s+([a-z0-9_-]+(?:\s+[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi
|
|
21166
|
+
/\bgroup(?:ed)?\s+by\s+([a-z0-9_-]+(?:\s+(?!(?:by|per|for|of|in|with|and|or)\b)[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
|
|
21167
|
+
/\bbreak(?:\s+up|\s*down)?\b[\s\S]{0,80}?\bby\s+([a-z0-9_-]+(?:\s+(?!(?:by|per|for|of|in|with|and|or)\b)[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
|
|
21168
|
+
/\b(?:by|per)\s+(?:each\s+)?([a-z0-9_-]+(?:\s+(?!(?:by|per|for|of|in|with|and|or)\b)[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
|
|
21169
|
+
/\bfor\s+each\s+([a-z0-9_-]+(?:\s+(?!(?:by|per|for|of|in|with|and|or)\b)[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi
|
|
20406
21170
|
];
|
|
20407
21171
|
patterns.forEach(function (pattern) {
|
|
20408
21172
|
var match = pattern.exec(text);
|
|
@@ -23476,7 +24240,7 @@ function resolveAssistantDatabaseNameForSystemCollections() {
|
|
|
23476
24240
|
}
|
|
23477
24241
|
function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
23478
24242
|
return __awaiter(this, void 0, void 0, function () {
|
|
23479
|
-
var safeSetPayload, fallbackId, debugEnabled, result,
|
|
24243
|
+
var safeSetPayload, fallbackId, debugEnabled, result, error_18, dbName, messagesCollection, result, _a, retryResult;
|
|
23480
24244
|
var _b, _c, _d, _e, _f, _g;
|
|
23481
24245
|
return __generator(this, function (_h) {
|
|
23482
24246
|
switch (_h.label) {
|
|
@@ -23515,14 +24279,14 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
23515
24279
|
}
|
|
23516
24280
|
return [2 /*return*/];
|
|
23517
24281
|
case 5:
|
|
23518
|
-
|
|
23519
|
-
if (!isAssistantTransactionCommittedError(
|
|
23520
|
-
throw
|
|
24282
|
+
error_18 = _h.sent();
|
|
24283
|
+
if (!isAssistantTransactionCommittedError(error_18)) {
|
|
24284
|
+
throw error_18;
|
|
23521
24285
|
}
|
|
23522
24286
|
if (debugEnabled) {
|
|
23523
24287
|
console.log(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update fallback triggered', {
|
|
23524
24288
|
messageId: fallbackId || messageId,
|
|
23525
|
-
reason: normalizeOptionalString(
|
|
24289
|
+
reason: normalizeOptionalString(error_18 === null || error_18 === void 0 ? void 0 : error_18.message) || 'transaction_committed'
|
|
23526
24290
|
});
|
|
23527
24291
|
}
|
|
23528
24292
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
@@ -23598,7 +24362,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
23598
24362
|
}
|
|
23599
24363
|
function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
23600
24364
|
return __awaiter(this, void 0, void 0, function () {
|
|
23601
|
-
var update, result,
|
|
24365
|
+
var update, result, error_19, dbName, conversationsCollection, fallbackResult;
|
|
23602
24366
|
return __generator(this, function (_a) {
|
|
23603
24367
|
switch (_a.label) {
|
|
23604
24368
|
case 0:
|
|
@@ -23623,9 +24387,9 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
23623
24387
|
}
|
|
23624
24388
|
return [2 /*return*/];
|
|
23625
24389
|
case 3:
|
|
23626
|
-
|
|
23627
|
-
if (!isAssistantTransactionCommittedError(
|
|
23628
|
-
throw
|
|
24390
|
+
error_19 = _a.sent();
|
|
24391
|
+
if (!isAssistantTransactionCommittedError(error_19)) {
|
|
24392
|
+
throw error_19;
|
|
23629
24393
|
}
|
|
23630
24394
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
23631
24395
|
conversationsCollection = resolveio_server_app_1.ResolveIOServer.getMongoConnection()
|
|
@@ -23897,7 +24661,7 @@ function buildAssistantAIRunId(prefix, parts) {
|
|
|
23897
24661
|
}
|
|
23898
24662
|
function recordAssistantAnswerAIRun(input) {
|
|
23899
24663
|
return __awaiter(this, void 0, void 0, function () {
|
|
23900
|
-
var messages, run,
|
|
24664
|
+
var messages, run, error_20;
|
|
23901
24665
|
return __generator(this, function (_a) {
|
|
23902
24666
|
switch (_a.label) {
|
|
23903
24667
|
case 0:
|
|
@@ -23922,8 +24686,8 @@ function recordAssistantAnswerAIRun(input) {
|
|
|
23922
24686
|
_a.sent();
|
|
23923
24687
|
return [3 /*break*/, 3];
|
|
23924
24688
|
case 2:
|
|
23925
|
-
|
|
23926
|
-
console.error(new Date(), 'Failed to record AI assistant AIRun evidence',
|
|
24689
|
+
error_20 = _a.sent();
|
|
24690
|
+
console.error(new Date(), 'Failed to record AI assistant AIRun evidence', error_20);
|
|
23927
24691
|
return [3 /*break*/, 3];
|
|
23928
24692
|
case 3: return [2 /*return*/];
|
|
23929
24693
|
}
|