@resolveio/server-lib 22.3.203 → 22.3.205
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 +887 -350
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +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) {
|
|
@@ -6944,22 +7045,37 @@ function resolveAssistantDataIntentDateWindow(message) {
|
|
|
6944
7045
|
var year_1 = Number(boundedEndMatch[3]) || now.getUTCFullYear();
|
|
6945
7046
|
var start = /\b(?:this|current)\s+month\b/.test(text)
|
|
6946
7047
|
? new Date(Date.UTC(year_1, endMonth, 1, 0, 0, 0, 0)).toISOString()
|
|
6947
|
-
:
|
|
7048
|
+
: /\b(?:this|current)\s+year\b|\bytd\b|\byear\s+to\s+date\b/.test(text)
|
|
7049
|
+
? new Date(Date.UTC(year_1, 0, 1, 0, 0, 0, 0)).toISOString()
|
|
7050
|
+
: undefined;
|
|
6948
7051
|
return {
|
|
6949
7052
|
start: start,
|
|
6950
7053
|
end: new Date(Date.UTC(year_1, endMonth, endDay, 23, 59, 59, 999)).toISOString(),
|
|
6951
7054
|
year: year_1
|
|
6952
7055
|
};
|
|
6953
7056
|
}
|
|
7057
|
+
var boundedEndMonthMatch = text.match(/\b(?:until|through|thru|to)\s+(january|jan|february|feb|march|mar|april|apr|may|june|jun|july|jul|august|aug|september|sep|october|oct|november|nov|december|dec)(?:,?\s+([0-9]{4}))?\b/);
|
|
7058
|
+
if (boundedEndMonthMatch) {
|
|
7059
|
+
var endMonth = monthNames[boundedEndMonthMatch[1]];
|
|
7060
|
+
var year_2 = Number(boundedEndMonthMatch[2]) || now.getUTCFullYear();
|
|
7061
|
+
var start = /\b(?:this|current)\s+year\b|\bytd\b|\byear\s+to\s+date\b/.test(text)
|
|
7062
|
+
? new Date(Date.UTC(year_2, 0, 1, 0, 0, 0, 0)).toISOString()
|
|
7063
|
+
: undefined;
|
|
7064
|
+
return {
|
|
7065
|
+
start: start,
|
|
7066
|
+
end: new Date(Date.UTC(year_2, endMonth + 1, 0, 23, 59, 59, 999)).toISOString(),
|
|
7067
|
+
year: year_2
|
|
7068
|
+
};
|
|
7069
|
+
}
|
|
6954
7070
|
var monthMatch = text.match(/\b(january|jan|february|feb|march|mar|april|apr|may|june|jun|july|jul|august|aug|september|sep|october|oct|november|nov|december|dec)\s+([0-9]{4})\b/);
|
|
6955
7071
|
if (monthMatch) {
|
|
6956
7072
|
var month = monthNames[monthMatch[1]];
|
|
6957
|
-
var
|
|
6958
|
-
if (Number.isFinite(
|
|
7073
|
+
var year_3 = Number(monthMatch[2]);
|
|
7074
|
+
if (Number.isFinite(year_3) && month >= 0) {
|
|
6959
7075
|
return {
|
|
6960
|
-
start: new Date(Date.UTC(
|
|
6961
|
-
end: new Date(Date.UTC(
|
|
6962
|
-
year:
|
|
7076
|
+
start: new Date(Date.UTC(year_3, month, 1, 0, 0, 0, 0)).toISOString(),
|
|
7077
|
+
end: new Date(Date.UTC(year_3, month + 1, 0, 23, 59, 59, 999)).toISOString(),
|
|
7078
|
+
year: year_3
|
|
6963
7079
|
};
|
|
6964
7080
|
}
|
|
6965
7081
|
}
|
|
@@ -7354,8 +7470,419 @@ function buildAssistantDataRequestMeasures(intent, pipeline) {
|
|
|
7354
7470
|
}
|
|
7355
7471
|
return measures;
|
|
7356
7472
|
}
|
|
7357
|
-
function
|
|
7358
|
-
|
|
7473
|
+
function clampAssistantConfidence(value, fallback) {
|
|
7474
|
+
if (fallback === void 0) { fallback = 0.75; }
|
|
7475
|
+
var parsed = Number(value);
|
|
7476
|
+
if (!Number.isFinite(parsed)) {
|
|
7477
|
+
return fallback;
|
|
7478
|
+
}
|
|
7479
|
+
return Math.max(0, Math.min(parsed, 1));
|
|
7480
|
+
}
|
|
7481
|
+
function normalizeAssistantContractStringList(value, max) {
|
|
7482
|
+
if (max === void 0) { max = 12; }
|
|
7483
|
+
var source = Array.isArray(value) ? value : (normalizeOptionalString(value) ? [value] : []);
|
|
7484
|
+
var values = [];
|
|
7485
|
+
source.forEach(function (entry) {
|
|
7486
|
+
var normalized = normalizeOptionalString(entry);
|
|
7487
|
+
if (!normalized || values.includes(normalized)) {
|
|
7488
|
+
return;
|
|
7489
|
+
}
|
|
7490
|
+
values.push(normalized.slice(0, 160));
|
|
7491
|
+
});
|
|
7492
|
+
return values.slice(0, max);
|
|
7493
|
+
}
|
|
7494
|
+
function normalizeAssistantContractFilters(value) {
|
|
7495
|
+
if (!Array.isArray(value)) {
|
|
7496
|
+
return [];
|
|
7497
|
+
}
|
|
7498
|
+
return value
|
|
7499
|
+
.filter(function (entry) { return !!entry && typeof entry === 'object' && !Array.isArray(entry); })
|
|
7500
|
+
.map(function (entry) { return Object.keys(entry).reduce(function (acc, key) {
|
|
7501
|
+
var normalizedKey = normalizeOptionalString(key);
|
|
7502
|
+
if (!normalizedKey || shouldRedactField(normalizedKey)) {
|
|
7503
|
+
return acc;
|
|
7504
|
+
}
|
|
7505
|
+
var rawValue = entry[key];
|
|
7506
|
+
if (rawValue === undefined || rawValue === null) {
|
|
7507
|
+
return acc;
|
|
7508
|
+
}
|
|
7509
|
+
if (typeof rawValue === 'object') {
|
|
7510
|
+
try {
|
|
7511
|
+
acc[normalizedKey] = JSON.parse(JSON.stringify(rawValue));
|
|
7512
|
+
}
|
|
7513
|
+
catch (_a) {
|
|
7514
|
+
acc[normalizedKey] = normalizeOptionalString(rawValue).slice(0, 240);
|
|
7515
|
+
}
|
|
7516
|
+
return acc;
|
|
7517
|
+
}
|
|
7518
|
+
acc[normalizedKey] = normalizeOptionalString(rawValue).slice(0, 240);
|
|
7519
|
+
return acc;
|
|
7520
|
+
}, {}); })
|
|
7521
|
+
.filter(function (entry) { return Object.keys(entry).length > 0; })
|
|
7522
|
+
.slice(0, 12);
|
|
7523
|
+
}
|
|
7524
|
+
function normalizeAssistantContractDateRange(value) {
|
|
7525
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
7526
|
+
return null;
|
|
7527
|
+
}
|
|
7528
|
+
var start = normalizeOptionalString(value.start || value.start_date || value.startDate);
|
|
7529
|
+
var end = normalizeOptionalString(value.end || value.end_date || value.endDate);
|
|
7530
|
+
var year = normalizeOptionalNumber(value.year);
|
|
7531
|
+
var result = {};
|
|
7532
|
+
if (start) {
|
|
7533
|
+
result.start = start;
|
|
7534
|
+
}
|
|
7535
|
+
if (end) {
|
|
7536
|
+
result.end = end;
|
|
7537
|
+
}
|
|
7538
|
+
if (year && year >= 1900 && year <= 3000) {
|
|
7539
|
+
result.year = (0, common_1.round)(year);
|
|
7540
|
+
}
|
|
7541
|
+
return Object.keys(result).length ? result : null;
|
|
7542
|
+
}
|
|
7543
|
+
function extractAssistantDataRequestClassifierRoot(value) {
|
|
7544
|
+
if (!value || typeof value !== 'object') {
|
|
7545
|
+
return value;
|
|
7546
|
+
}
|
|
7547
|
+
return value.request
|
|
7548
|
+
|| value.contract
|
|
7549
|
+
|| value.data_request
|
|
7550
|
+
|| value.dataRequest
|
|
7551
|
+
|| value;
|
|
7552
|
+
}
|
|
7553
|
+
function normalizeAssistantDataRequestBreakdownContract(value) {
|
|
7554
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
7555
|
+
var text_1 = cleanAssistantRequestedDimensionText(normalizeOptionalString(value));
|
|
7556
|
+
return text_1 ? { type: 'unknown', requested_text: text_1 } : null;
|
|
7557
|
+
}
|
|
7558
|
+
var rawType = normalizeOptionalString(value.type || value.kind).toLowerCase();
|
|
7559
|
+
var requestedText = cleanAssistantRequestedDimensionText(value.requested_text
|
|
7560
|
+
|| value.requestedText
|
|
7561
|
+
|| value.text
|
|
7562
|
+
|| value.label
|
|
7563
|
+
|| value.dimension
|
|
7564
|
+
|| value.field
|
|
7565
|
+
|| value.granularity);
|
|
7566
|
+
var dimension = cleanAssistantRequestedDimensionText(value.dimension
|
|
7567
|
+
|| value.dimension_id
|
|
7568
|
+
|| value.dimensionId
|
|
7569
|
+
|| '');
|
|
7570
|
+
var granularity = cleanAssistantRequestedDimensionText(value.granularity
|
|
7571
|
+
|| value.time_grain
|
|
7572
|
+
|| value.timeGrain
|
|
7573
|
+
|| '');
|
|
7574
|
+
var fieldHint = normalizeOptionalString(value.field_hint || value.fieldHint || value.date_field || value.dateField);
|
|
7575
|
+
var fieldHints = normalizeAssistantContractStringList(value.field_hints || value.fieldHints || value.fields, 8);
|
|
7576
|
+
var inferredGranularity = granularity || resolveAssistantTimeBreakdownGranularity(requestedText || dimension);
|
|
7577
|
+
var type = rawType === 'time' || inferredGranularity
|
|
7578
|
+
? 'time'
|
|
7579
|
+
: rawType === 'entity'
|
|
7580
|
+
? 'entity'
|
|
7581
|
+
: rawType === 'unknown'
|
|
7582
|
+
? 'unknown'
|
|
7583
|
+
: 'unknown';
|
|
7584
|
+
var text = requestedText || dimension || granularity;
|
|
7585
|
+
if (!text) {
|
|
7586
|
+
return null;
|
|
7587
|
+
}
|
|
7588
|
+
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 } : {}));
|
|
7589
|
+
}
|
|
7590
|
+
function normalizeAssistantDataRequestContract(value, intent, dateWindow, source) {
|
|
7591
|
+
if (source === void 0) { source = 'mini_model_classifier'; }
|
|
7592
|
+
var root = extractAssistantDataRequestClassifierRoot(value);
|
|
7593
|
+
if (!root || typeof root !== 'object' || Array.isArray(root)) {
|
|
7594
|
+
return null;
|
|
7595
|
+
}
|
|
7596
|
+
var breakdownSource = root.requested_breakdowns
|
|
7597
|
+
|| root.requestedBreakdowns
|
|
7598
|
+
|| root.breakdowns
|
|
7599
|
+
|| root.groupings
|
|
7600
|
+
|| root.group_by
|
|
7601
|
+
|| root.groupBy
|
|
7602
|
+
|| [];
|
|
7603
|
+
var requestedBreakdowns = (Array.isArray(breakdownSource) ? breakdownSource : [breakdownSource])
|
|
7604
|
+
.map(function (entry) { return normalizeAssistantDataRequestBreakdownContract(entry); })
|
|
7605
|
+
.filter(function (entry) { return !!entry; });
|
|
7606
|
+
var dateRange = normalizeAssistantContractDateRange(root.date_range || root.dateRange)
|
|
7607
|
+
|| (dateWindow.start || dateWindow.end ? __assign({}, dateWindow) : null);
|
|
7608
|
+
var intentId = normalizeOptionalString(root.intent_id || root.intentId || intent.id);
|
|
7609
|
+
var collection = normalizeOptionalString(root.collection || intent.collection);
|
|
7610
|
+
return {
|
|
7611
|
+
intent_type: 'data_summary',
|
|
7612
|
+
intent_id: intentId || undefined,
|
|
7613
|
+
domain: normalizeOptionalString(root.domain || intent.id || intent.collection),
|
|
7614
|
+
collection: collection || undefined,
|
|
7615
|
+
operation: 'aggregate',
|
|
7616
|
+
requested_breakdowns: requestedBreakdowns,
|
|
7617
|
+
date_range: dateRange,
|
|
7618
|
+
measures: normalizeAssistantContractStringList(root.measures || root.metrics || root.measure, 16),
|
|
7619
|
+
filters: normalizeAssistantContractFilters(root.filters || root.where),
|
|
7620
|
+
output_format: 'collapse_table',
|
|
7621
|
+
ambiguities: normalizeAssistantContractStringList(root.ambiguities || root.questions || root.uncertainties, 8),
|
|
7622
|
+
confidence: clampAssistantConfidence(root.confidence, requestedBreakdowns.length ? 0.82 : 0.65),
|
|
7623
|
+
source: source
|
|
7624
|
+
};
|
|
7625
|
+
}
|
|
7626
|
+
function buildAssistantRequestedBreakdownCandidates(message, classifierContract) {
|
|
7627
|
+
var candidates = [];
|
|
7628
|
+
var seen = new Set();
|
|
7629
|
+
var add = function (text, breakdown) {
|
|
7630
|
+
var normalized = cleanAssistantRequestedDimensionText(text);
|
|
7631
|
+
if (!normalized) {
|
|
7632
|
+
return;
|
|
7633
|
+
}
|
|
7634
|
+
var key = [
|
|
7635
|
+
(breakdown === null || breakdown === void 0 ? void 0 : breakdown.type) || '',
|
|
7636
|
+
(breakdown === null || breakdown === void 0 ? void 0 : breakdown.granularity) || '',
|
|
7637
|
+
(breakdown === null || breakdown === void 0 ? void 0 : breakdown.dimension) || '',
|
|
7638
|
+
normalized
|
|
7639
|
+
].join(':');
|
|
7640
|
+
if (seen.has(key)) {
|
|
7641
|
+
return;
|
|
7642
|
+
}
|
|
7643
|
+
seen.add(key);
|
|
7644
|
+
candidates.push({ text: normalized, breakdown: breakdown });
|
|
7645
|
+
};
|
|
7646
|
+
((classifierContract === null || classifierContract === void 0 ? void 0 : classifierContract.requested_breakdowns) || []).forEach(function (breakdown) {
|
|
7647
|
+
add(breakdown.granularity
|
|
7648
|
+
|| breakdown.dimension
|
|
7649
|
+
|| breakdown.requested_text, breakdown);
|
|
7650
|
+
});
|
|
7651
|
+
extractAssistantRequestedBreakdownDimensionTexts(message).forEach(function (text) { return add(text); });
|
|
7652
|
+
return candidates;
|
|
7653
|
+
}
|
|
7654
|
+
function buildAssistantDataRequestClassifierCandidatePayload(candidate) {
|
|
7655
|
+
var intent = candidate.intent;
|
|
7656
|
+
return {
|
|
7657
|
+
intent_id: intent.id,
|
|
7658
|
+
collection: intent.collection,
|
|
7659
|
+
permission_view: intent.permissionView || undefined,
|
|
7660
|
+
score: candidate.score,
|
|
7661
|
+
trigger_terms: (intent.terms || []).slice(0, 16),
|
|
7662
|
+
date_field: intent.dateField || undefined,
|
|
7663
|
+
quantity_field: intent.quantityField || undefined,
|
|
7664
|
+
metric_field: intent.metricField || undefined,
|
|
7665
|
+
dimensions: (intent.dimensions || []).map(function (dimension) { return ({
|
|
7666
|
+
id: dimension.id,
|
|
7667
|
+
type: dimension.type || 'entity',
|
|
7668
|
+
granularity: dimension.granularity || undefined,
|
|
7669
|
+
terms: (dimension.terms || []).slice(0, 12),
|
|
7670
|
+
field_hints: extractAssistantDataIntentExpressionFieldHints(dimension.groupId).slice(0, 8)
|
|
7671
|
+
}); })
|
|
7672
|
+
};
|
|
7673
|
+
}
|
|
7674
|
+
function buildAssistantDataRequestClassifierMessages(params) {
|
|
7675
|
+
var systemPrompt = [
|
|
7676
|
+
'Classify one business app data request into strict JSON.',
|
|
7677
|
+
'Use only the supplied app-owned intent candidates and configured dimensions.',
|
|
7678
|
+
'Do not create MongoDB pipelines, queries, field paths, or collections.',
|
|
7679
|
+
'Preserve every explicit grouping phrase: "by month by chemical" must produce two requested_breakdowns, one for month and one for chemical.',
|
|
7680
|
+
'Interpret "by", "per", "break down by", and "group by" as requested_breakdowns.',
|
|
7681
|
+
'Interpret date phrases like "this month", "last month", "until June 12", "through May", "past 30 days", and "last 6 months" as date_range or filters when clear.',
|
|
7682
|
+
'For time breakdowns, set type="time" and granularity to one of year, quarter, month, week, day, date.',
|
|
7683
|
+
'For configured dimensions, set type="entity" and dimension to the candidate dimension id.',
|
|
7684
|
+
'If unsure, include an ambiguity instead of guessing.',
|
|
7685
|
+
'Always set output_format to "collapse_table".',
|
|
7686
|
+
'Return JSON only with keys: intent_id, domain, collection, operation, requested_breakdowns, date_range, measures, filters, output_format, ambiguities, confidence.'
|
|
7687
|
+
].join('\n');
|
|
7688
|
+
var userPayload = {
|
|
7689
|
+
message: params.message,
|
|
7690
|
+
app_id: normalizeOptionalString(params.appId) || undefined,
|
|
7691
|
+
candidates: params.candidates.map(buildAssistantDataRequestClassifierCandidatePayload)
|
|
7692
|
+
};
|
|
7693
|
+
return [
|
|
7694
|
+
{ role: 'system', content: systemPrompt },
|
|
7695
|
+
{ role: 'user', content: JSON.stringify(userPayload) }
|
|
7696
|
+
];
|
|
7697
|
+
}
|
|
7698
|
+
function resolveAssistantDataRequestClassifierEnabled(config) {
|
|
7699
|
+
var override = normalizeOptionalBoolean((config === null || config === void 0 ? void 0 : config.data_request_classifier_enabled)
|
|
7700
|
+
|| (config === null || config === void 0 ? void 0 : config.dataRequestClassifierEnabled));
|
|
7701
|
+
if (typeof override === 'boolean') {
|
|
7702
|
+
return override;
|
|
7703
|
+
}
|
|
7704
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
7705
|
+
var raw = normalizeOptionalBoolean(serverConfig['AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_ENABLED']
|
|
7706
|
+
|| process.env.AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_ENABLED
|
|
7707
|
+
|| serverConfig['AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_ENABLED']
|
|
7708
|
+
|| process.env.AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_ENABLED);
|
|
7709
|
+
return raw === undefined ? true : raw === true;
|
|
7710
|
+
}
|
|
7711
|
+
function resolveAssistantDataRequestClassifierModel(config) {
|
|
7712
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
7713
|
+
return normalizeOptionalString((config === null || config === void 0 ? void 0 : config.data_request_classifier_model)
|
|
7714
|
+
|| (config === null || config === void 0 ? void 0 : config.dataRequestClassifierModel)
|
|
7715
|
+
|| serverConfig['AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_MODEL']
|
|
7716
|
+
|| process.env.AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_MODEL
|
|
7717
|
+
|| serverConfig['AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_MODEL']
|
|
7718
|
+
|| process.env.AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_MODEL
|
|
7719
|
+
|| serverConfig['AI_ASSISTANT_INTENT_MODEL']
|
|
7720
|
+
|| process.env.AI_ASSISTANT_INTENT_MODEL
|
|
7721
|
+
|| 'gpt-5.4-mini');
|
|
7722
|
+
}
|
|
7723
|
+
function resolveAssistantDataRequestClassifierTimeoutMs(config) {
|
|
7724
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
7725
|
+
var raw = normalizeOptionalNumber((config === null || config === void 0 ? void 0 : config.data_request_classifier_timeout_ms)
|
|
7726
|
+
|| (config === null || config === void 0 ? void 0 : config.dataRequestClassifierTimeoutMs)
|
|
7727
|
+
|| serverConfig['AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_TIMEOUT_MS']
|
|
7728
|
+
|| process.env.AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_TIMEOUT_MS
|
|
7729
|
+
|| serverConfig['AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_TIMEOUT_MS']
|
|
7730
|
+
|| process.env.AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_TIMEOUT_MS);
|
|
7731
|
+
if (raw && raw > 0) {
|
|
7732
|
+
return Math.max(250, Math.min((0, common_1.round)(raw), 5000));
|
|
7733
|
+
}
|
|
7734
|
+
return 1800;
|
|
7735
|
+
}
|
|
7736
|
+
function resolveAssistantDataRequestClassifierMaxTokens() {
|
|
7737
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
7738
|
+
var raw = normalizeOptionalNumber(serverConfig['AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_MAX_TOKENS']
|
|
7739
|
+
|| process.env.AI_ASSISTANT_DATA_REQUEST_CLASSIFIER_MAX_TOKENS
|
|
7740
|
+
|| serverConfig['AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_MAX_TOKENS']
|
|
7741
|
+
|| process.env.AI_ASSISTANT_DATA_CONTRACT_CLASSIFIER_MAX_TOKENS);
|
|
7742
|
+
if (raw && raw > 0) {
|
|
7743
|
+
return Math.max(128, Math.min((0, common_1.round)(raw), 1200));
|
|
7744
|
+
}
|
|
7745
|
+
return 650;
|
|
7746
|
+
}
|
|
7747
|
+
function resolveAssistantDataRequestClassifierIntent(raw, candidates) {
|
|
7748
|
+
var _a, _b;
|
|
7749
|
+
var root = extractAssistantDataRequestClassifierRoot(raw);
|
|
7750
|
+
var rawKeys = [
|
|
7751
|
+
root === null || root === void 0 ? void 0 : root.intent_id,
|
|
7752
|
+
root === null || root === void 0 ? void 0 : root.intentId,
|
|
7753
|
+
root === null || root === void 0 ? void 0 : root.domain,
|
|
7754
|
+
root === null || root === void 0 ? void 0 : root.collection
|
|
7755
|
+
].map(function (value) { return normalizeCollectionKey(normalizeOptionalString(value)); }).filter(Boolean);
|
|
7756
|
+
if (!rawKeys.length) {
|
|
7757
|
+
return ((_a = candidates[0]) === null || _a === void 0 ? void 0 : _a.intent) || null;
|
|
7758
|
+
}
|
|
7759
|
+
var selected = candidates.find(function (candidate) {
|
|
7760
|
+
var intentKeys = [
|
|
7761
|
+
candidate.intent.id,
|
|
7762
|
+
candidate.intent.collection
|
|
7763
|
+
].map(function (value) { return normalizeCollectionKey(normalizeOptionalString(value)); }).filter(Boolean);
|
|
7764
|
+
return rawKeys.some(function (key) { return intentKeys.includes(key); });
|
|
7765
|
+
});
|
|
7766
|
+
return (selected === null || selected === void 0 ? void 0 : selected.intent) || ((_b = candidates[0]) === null || _b === void 0 ? void 0 : _b.intent) || null;
|
|
7767
|
+
}
|
|
7768
|
+
function classifyAssistantAppDataRequest(params) {
|
|
7769
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7770
|
+
var candidates, serverConfig, apiKey, model, timeoutMs, messages, start, client, response, parsed, intent, contract, understanding, error_15;
|
|
7771
|
+
var _a, _b, _c;
|
|
7772
|
+
return __generator(this, function (_d) {
|
|
7773
|
+
switch (_d.label) {
|
|
7774
|
+
case 0:
|
|
7775
|
+
if (!resolveAssistantDataRequestClassifierEnabled(params.config)) {
|
|
7776
|
+
return [2 /*return*/, {
|
|
7777
|
+
debug: {
|
|
7778
|
+
enabled: false,
|
|
7779
|
+
reason: 'disabled'
|
|
7780
|
+
}
|
|
7781
|
+
}];
|
|
7782
|
+
}
|
|
7783
|
+
candidates = rankAssistantAppDataIntentCandidates(params.message, params.collectionNames, params.appId, { includeUnscored: true, limit: 6 });
|
|
7784
|
+
if (!candidates.length) {
|
|
7785
|
+
return [2 /*return*/, {
|
|
7786
|
+
debug: {
|
|
7787
|
+
enabled: true,
|
|
7788
|
+
attempted: false,
|
|
7789
|
+
reason: 'no_app_data_intent_candidates'
|
|
7790
|
+
}
|
|
7791
|
+
}];
|
|
7792
|
+
}
|
|
7793
|
+
serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
7794
|
+
apiKey = normalizeOptionalString(serverConfig['OPENAI_API_KEY'] || process.env.OPENAI_API_KEY);
|
|
7795
|
+
if (!apiKey) {
|
|
7796
|
+
return [2 /*return*/, {
|
|
7797
|
+
debug: {
|
|
7798
|
+
enabled: true,
|
|
7799
|
+
attempted: false,
|
|
7800
|
+
reason: 'missing_openai_api_key',
|
|
7801
|
+
candidates: candidates.map(function (candidate) { return ({ intentId: candidate.intent.id, score: candidate.score }); })
|
|
7802
|
+
}
|
|
7803
|
+
}];
|
|
7804
|
+
}
|
|
7805
|
+
model = resolveAssistantDataRequestClassifierModel(params.config);
|
|
7806
|
+
timeoutMs = resolveAssistantDataRequestClassifierTimeoutMs(params.config);
|
|
7807
|
+
messages = buildAssistantDataRequestClassifierMessages({
|
|
7808
|
+
message: params.message,
|
|
7809
|
+
appId: params.appId,
|
|
7810
|
+
candidates: candidates
|
|
7811
|
+
});
|
|
7812
|
+
start = Date.now();
|
|
7813
|
+
_d.label = 1;
|
|
7814
|
+
case 1:
|
|
7815
|
+
_d.trys.push([1, 3, , 4]);
|
|
7816
|
+
client = new openai_client_1.OpenAIClient({
|
|
7817
|
+
apiKey: apiKey,
|
|
7818
|
+
baseUrl: normalizeOptionalString(serverConfig['OPENAI_BASE_URL'] || process.env.OPENAI_BASE_URL) || undefined,
|
|
7819
|
+
model: model,
|
|
7820
|
+
temperature: 0,
|
|
7821
|
+
maxRetries: 0,
|
|
7822
|
+
maxTokens: resolveAssistantDataRequestClassifierMaxTokens(),
|
|
7823
|
+
responseFormat: 'json_object'
|
|
7824
|
+
});
|
|
7825
|
+
return [4 /*yield*/, client.chat(messages, {
|
|
7826
|
+
timeoutMs: timeoutMs,
|
|
7827
|
+
responseFormat: 'json_object'
|
|
7828
|
+
})];
|
|
7829
|
+
case 2:
|
|
7830
|
+
response = _d.sent();
|
|
7831
|
+
parsed = parseJsonObject(response.content);
|
|
7832
|
+
intent = resolveAssistantDataRequestClassifierIntent(parsed, candidates);
|
|
7833
|
+
contract = intent
|
|
7834
|
+
? normalizeAssistantDataRequestContract(parsed, intent, params.dateWindow, 'mini_model_classifier')
|
|
7835
|
+
: null;
|
|
7836
|
+
understanding = intent && contract
|
|
7837
|
+
? buildAssistantDataRequestUnderstanding(params.message, intent, params.dateWindow, contract)
|
|
7838
|
+
: null;
|
|
7839
|
+
return [2 /*return*/, {
|
|
7840
|
+
intent: intent,
|
|
7841
|
+
understanding: understanding,
|
|
7842
|
+
debug: {
|
|
7843
|
+
enabled: true,
|
|
7844
|
+
attempted: true,
|
|
7845
|
+
succeeded: !!understanding,
|
|
7846
|
+
model: response.model || model,
|
|
7847
|
+
durationMs: Date.now() - start,
|
|
7848
|
+
intentId: (intent === null || intent === void 0 ? void 0 : intent.id) || undefined,
|
|
7849
|
+
requestedBreakdowns: ((_a = understanding === null || understanding === void 0 ? void 0 : understanding.contract) === null || _a === void 0 ? void 0 : _a.requested_breakdowns) || undefined,
|
|
7850
|
+
ambiguities: ((_b = understanding === null || understanding === void 0 ? void 0 : understanding.contract) === null || _b === void 0 ? void 0 : _b.ambiguities) || undefined,
|
|
7851
|
+
confidence: (_c = understanding === null || understanding === void 0 ? void 0 : understanding.contract) === null || _c === void 0 ? void 0 : _c.confidence,
|
|
7852
|
+
candidates: candidates.map(function (candidate) { return ({ intentId: candidate.intent.id, score: candidate.score }); }),
|
|
7853
|
+
parseSucceeded: !!parsed
|
|
7854
|
+
},
|
|
7855
|
+
usage: response.usage ? {
|
|
7856
|
+
model: response.model || model,
|
|
7857
|
+
inputTokens: response.usage.inputTokens,
|
|
7858
|
+
outputTokens: response.usage.outputTokens,
|
|
7859
|
+
totalTokens: response.usage.totalTokens,
|
|
7860
|
+
requestId: response.requestId
|
|
7861
|
+
} : undefined
|
|
7862
|
+
}];
|
|
7863
|
+
case 3:
|
|
7864
|
+
error_15 = _d.sent();
|
|
7865
|
+
return [2 /*return*/, {
|
|
7866
|
+
debug: {
|
|
7867
|
+
enabled: true,
|
|
7868
|
+
attempted: true,
|
|
7869
|
+
succeeded: false,
|
|
7870
|
+
model: model,
|
|
7871
|
+
durationMs: Date.now() - start,
|
|
7872
|
+
error: normalizeOptionalString(error_15 === null || error_15 === void 0 ? void 0 : error_15.message) || 'classifier_failed',
|
|
7873
|
+
candidates: candidates.map(function (candidate) { return ({ intentId: candidate.intent.id, score: candidate.score }); })
|
|
7874
|
+
}
|
|
7875
|
+
}];
|
|
7876
|
+
case 4: return [2 /*return*/];
|
|
7877
|
+
}
|
|
7878
|
+
});
|
|
7879
|
+
});
|
|
7880
|
+
}
|
|
7881
|
+
function buildAssistantDataRequestUnderstanding(message, intent, dateWindow, classifierContract) {
|
|
7882
|
+
var normalizedClassifierContract = classifierContract
|
|
7883
|
+
? normalizeAssistantDataRequestContract(classifierContract, intent, dateWindow, classifierContract.source || 'mini_model_classifier')
|
|
7884
|
+
: null;
|
|
7885
|
+
var requestedBreakdownCandidates = buildAssistantRequestedBreakdownCandidates(message, normalizedClassifierContract);
|
|
7359
7886
|
var dimensions = [];
|
|
7360
7887
|
var requestedBreakdowns = [];
|
|
7361
7888
|
var ambiguities = [];
|
|
@@ -7365,11 +7892,19 @@ function buildAssistantDataRequestUnderstanding(message, intent, dateWindow) {
|
|
|
7365
7892
|
if (!id || seenDimensionIds.has(id)) {
|
|
7366
7893
|
return;
|
|
7367
7894
|
}
|
|
7895
|
+
if ((dimension.type || '') === 'time' && dimensions.some(function (entry) { return (entry.type || '') === 'time'; })) {
|
|
7896
|
+
return;
|
|
7897
|
+
}
|
|
7368
7898
|
seenDimensionIds.add(id);
|
|
7369
7899
|
dimensions.push(dimension);
|
|
7370
7900
|
};
|
|
7371
|
-
|
|
7372
|
-
var
|
|
7901
|
+
requestedBreakdownCandidates.forEach(function (candidate) {
|
|
7902
|
+
var _a;
|
|
7903
|
+
var requestedDimensionText = candidate.text;
|
|
7904
|
+
var requestedGranularity = ((_a = candidate.breakdown) === null || _a === void 0 ? void 0 : _a.granularity) || resolveAssistantTimeBreakdownGranularity(requestedDimensionText);
|
|
7905
|
+
var timeDimension = requestedGranularity
|
|
7906
|
+
? buildAssistantDataIntentTimeDimension(requestedGranularity, intent)
|
|
7907
|
+
: null;
|
|
7373
7908
|
if (timeDimension) {
|
|
7374
7909
|
addDimension(timeDimension);
|
|
7375
7910
|
requestedBreakdowns.push({
|
|
@@ -7381,18 +7916,21 @@ function buildAssistantDataRequestUnderstanding(message, intent, dateWindow) {
|
|
|
7381
7916
|
});
|
|
7382
7917
|
return;
|
|
7383
7918
|
}
|
|
7384
|
-
if (
|
|
7919
|
+
if (requestedGranularity && !intent.dateField) {
|
|
7385
7920
|
ambiguities.push("Requested ".concat(requestedDimensionText, " breakdown, but this app data intent has no date field."));
|
|
7386
7921
|
requestedBreakdowns.push({
|
|
7387
7922
|
type: 'unknown',
|
|
7388
7923
|
requested_text: requestedDimensionText,
|
|
7389
|
-
granularity:
|
|
7924
|
+
granularity: requestedGranularity
|
|
7390
7925
|
});
|
|
7391
7926
|
return;
|
|
7392
7927
|
}
|
|
7393
7928
|
var selected = null;
|
|
7394
7929
|
(intent.dimensions || []).forEach(function (dimension) {
|
|
7395
|
-
var
|
|
7930
|
+
var _a;
|
|
7931
|
+
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)
|
|
7932
|
+
? 10
|
|
7933
|
+
: 0);
|
|
7396
7934
|
if (score <= 0) {
|
|
7397
7935
|
return;
|
|
7398
7936
|
}
|
|
@@ -7418,24 +7956,26 @@ function buildAssistantDataRequestUnderstanding(message, intent, dateWindow) {
|
|
|
7418
7956
|
});
|
|
7419
7957
|
});
|
|
7420
7958
|
var confidence = requestedBreakdowns.length && !ambiguities.length
|
|
7421
|
-
? 0.9
|
|
7959
|
+
? clampAssistantConfidence(normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.confidence, 0.9)
|
|
7422
7960
|
: requestedBreakdowns.length
|
|
7423
|
-
? 0.65
|
|
7424
|
-
: 0.75;
|
|
7961
|
+
? clampAssistantConfidence(normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.confidence, 0.65)
|
|
7962
|
+
: clampAssistantConfidence(normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.confidence, 0.75);
|
|
7425
7963
|
return {
|
|
7426
7964
|
dimensions: dimensions,
|
|
7427
7965
|
contract: {
|
|
7428
7966
|
intent_type: 'data_summary',
|
|
7967
|
+
intent_id: (normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.intent_id) || intent.id,
|
|
7429
7968
|
domain: intent.id || intent.collection,
|
|
7969
|
+
collection: intent.collection,
|
|
7430
7970
|
operation: 'aggregate',
|
|
7431
7971
|
requested_breakdowns: requestedBreakdowns,
|
|
7432
|
-
date_range: dateWindow.start || dateWindow.end ? __assign({}, dateWindow) : null,
|
|
7433
|
-
measures: [],
|
|
7434
|
-
filters: [],
|
|
7972
|
+
date_range: (normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.date_range) || (dateWindow.start || dateWindow.end ? __assign({}, dateWindow) : null),
|
|
7973
|
+
measures: (normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.measures) || [],
|
|
7974
|
+
filters: (normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.filters) || [],
|
|
7435
7975
|
output_format: 'collapse_table',
|
|
7436
|
-
ambiguities: ambiguities,
|
|
7976
|
+
ambiguities: mergeAssistantHintValues((normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.ambiguities) || [], ambiguities),
|
|
7437
7977
|
confidence: confidence,
|
|
7438
|
-
source: 'fast_app_data_request_contract'
|
|
7978
|
+
source: (normalizedClassifierContract === null || normalizedClassifierContract === void 0 ? void 0 : normalizedClassifierContract.source) || 'fast_app_data_request_contract'
|
|
7439
7979
|
}
|
|
7440
7980
|
};
|
|
7441
7981
|
}
|
|
@@ -7519,15 +8059,16 @@ function applyAssistantDataIntentDimensionsToPipeline(pipeline, dimensions) {
|
|
|
7519
8059
|
}
|
|
7520
8060
|
return next;
|
|
7521
8061
|
}
|
|
7522
|
-
function buildAssistantAppDataIntentDirective(message, collectionNames, appId) {
|
|
8062
|
+
function buildAssistantAppDataIntentDirective(message, collectionNames, appId, options) {
|
|
7523
8063
|
if (collectionNames === void 0) { collectionNames = []; }
|
|
7524
|
-
var intent = selectAssistantAppDataIntent(message, collectionNames, appId);
|
|
8064
|
+
var intent = (options === null || options === void 0 ? void 0 : options.appDataIntent) || selectAssistantAppDataIntent(message, collectionNames, appId);
|
|
7525
8065
|
if (!intent) {
|
|
7526
8066
|
return null;
|
|
7527
8067
|
}
|
|
7528
8068
|
var customerText = extractAssistantDataIntentCustomerText(message);
|
|
7529
8069
|
var dateWindow = resolveAssistantDataIntentDateWindow(message);
|
|
7530
|
-
var requestUnderstanding =
|
|
8070
|
+
var requestUnderstanding = (options === null || options === void 0 ? void 0 : options.appDataRequestUnderstanding)
|
|
8071
|
+
|| buildAssistantDataRequestUnderstanding(message, intent, dateWindow, (options === null || options === void 0 ? void 0 : options.appDataRequestContract) || null);
|
|
7531
8072
|
var templatedDimensions = requestUnderstanding.dimensions
|
|
7532
8073
|
.map(function (dimension) { return applyAssistantDataIntentDimensionTemplate(dimension, { customerText: customerText, dateWindow: dateWindow }); })
|
|
7533
8074
|
.filter(function (dimension) { return !!(dimension === null || dimension === void 0 ? void 0 : dimension.groupId); });
|
|
@@ -7537,27 +8078,15 @@ function buildAssistantAppDataIntentDirective(message, collectionNames, appId) {
|
|
|
7537
8078
|
.replace(/\{\{customer\}\}/g, customerText || 'the requested customer')
|
|
7538
8079
|
.replace(/\{\{year\}\}/g, dateWindow.year ? String(dateWindow.year) : 'the requested date range');
|
|
7539
8080
|
});
|
|
7540
|
-
var metadata = {
|
|
7541
|
-
intentId: intent.id,
|
|
7542
|
-
recipeUsed: intent.id,
|
|
7543
|
-
acknowledgementText: acknowledgementText,
|
|
7544
|
-
progress: progress,
|
|
7545
|
-
assumptions: intent.assumptions,
|
|
7546
|
-
fallbackCollections: intent.fallbackCollections,
|
|
7547
|
-
customerText: customerText,
|
|
7548
|
-
dateWindow: dateWindow,
|
|
7549
|
-
requestedDimension: templatedDimensions[0] ? {
|
|
8081
|
+
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] ? {
|
|
7550
8082
|
id: templatedDimensions[0].id,
|
|
7551
8083
|
terms: templatedDimensions[0].terms
|
|
7552
|
-
} : null,
|
|
7553
|
-
requestedDimensions: templatedDimensions.map(function (dimension) { return ({
|
|
8084
|
+
} : null, requestedDimensions: templatedDimensions.map(function (dimension) { return ({
|
|
7554
8085
|
id: dimension.id,
|
|
7555
8086
|
type: dimension.type || 'entity',
|
|
7556
8087
|
granularity: dimension.granularity || undefined,
|
|
7557
8088
|
terms: dimension.terms
|
|
7558
|
-
}); }),
|
|
7559
|
-
requestContract: requestUnderstanding.contract
|
|
7560
|
-
};
|
|
8089
|
+
}); }), requestContract: requestUnderstanding.contract }, ((options === null || options === void 0 ? void 0 : options.appDataRequestClassifier) ? { requestClassifier: options.appDataRequestClassifier } : {}));
|
|
7561
8090
|
var basePayload = function (pipeline) { return ({
|
|
7562
8091
|
collection: intent.collection,
|
|
7563
8092
|
permissionView: intent.permissionView || resolveDefaultAssistantPermissionView(intent.collection),
|
|
@@ -7576,13 +8105,13 @@ function isAssistantDeterministicHeuristicDirective(directive) {
|
|
|
7576
8105
|
return isAssistantSchemaHoursHeuristicDirective(directive)
|
|
7577
8106
|
|| isAssistantAppDataIntentHeuristicDirective(directive);
|
|
7578
8107
|
}
|
|
7579
|
-
function buildAssistantHeuristicDirective(message, collectionHints, collectionNames, appId) {
|
|
8108
|
+
function buildAssistantHeuristicDirective(message, collectionHints, collectionNames, appId, options) {
|
|
7580
8109
|
if (collectionNames === void 0) { collectionNames = []; }
|
|
7581
8110
|
if (!normalizeOptionalString(message)) {
|
|
7582
8111
|
return null;
|
|
7583
8112
|
}
|
|
7584
8113
|
var appDataIntentDirective = resolveAssistantDeterministicHeuristicEnabled(AI_ASSISTANT_HEURISTIC_ID_APP_DATA_INTENT, appId)
|
|
7585
|
-
? buildAssistantAppDataIntentDirective(message, collectionNames, appId)
|
|
8114
|
+
? buildAssistantAppDataIntentDirective(message, collectionNames, appId, options)
|
|
7586
8115
|
: null;
|
|
7587
8116
|
if (appDataIntentDirective) {
|
|
7588
8117
|
return appDataIntentDirective;
|
|
@@ -7595,9 +8124,17 @@ function buildAssistantHeuristicDirective(message, collectionHints, collectionNa
|
|
|
7595
8124
|
}
|
|
7596
8125
|
return null;
|
|
7597
8126
|
}
|
|
7598
|
-
function resolveAssistantHeuristicDirectiveForTesting(message, collectionHints, collectionNames, appId) {
|
|
8127
|
+
function resolveAssistantHeuristicDirectiveForTesting(message, collectionHints, collectionNames, appId, options) {
|
|
7599
8128
|
if (collectionNames === void 0) { collectionNames = []; }
|
|
7600
|
-
return buildAssistantHeuristicDirective(message, collectionHints, collectionNames, appId);
|
|
8129
|
+
return buildAssistantHeuristicDirective(message, collectionHints, collectionNames, appId, options);
|
|
8130
|
+
}
|
|
8131
|
+
function buildAssistantDataRequestClassifierMessagesForTesting(params) {
|
|
8132
|
+
var candidates = rankAssistantAppDataIntentCandidates(params.message, params.collectionNames || [], params.appId, { includeUnscored: true, limit: 6 });
|
|
8133
|
+
return buildAssistantDataRequestClassifierMessages({
|
|
8134
|
+
message: params.message,
|
|
8135
|
+
appId: params.appId,
|
|
8136
|
+
candidates: candidates
|
|
8137
|
+
});
|
|
7601
8138
|
}
|
|
7602
8139
|
function resolveDefaultAssistantPermissionView(collection) {
|
|
7603
8140
|
var normalizedCollection = normalizeOptionalString(collection).toLowerCase();
|
|
@@ -19784,7 +20321,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
19784
20321
|
}
|
|
19785
20322
|
function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler) {
|
|
19786
20323
|
return __awaiter(this, void 0, void 0, function () {
|
|
19787
|
-
var streamedOptions, normalizedThreadKey, shouldForceInProcessThreadReuse, codexClient, codexClient, workerPath, codexClient,
|
|
20324
|
+
var streamedOptions, normalizedThreadKey, shouldForceInProcessThreadReuse, codexClient, codexClient, workerPath, codexClient, error_16, codexClient;
|
|
19788
20325
|
return __generator(this, function (_a) {
|
|
19789
20326
|
switch (_a.label) {
|
|
19790
20327
|
case 0:
|
|
@@ -19812,11 +20349,11 @@ function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler)
|
|
|
19812
20349
|
return [4 /*yield*/, runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config, streamStatusHandler)];
|
|
19813
20350
|
case 8: return [2 /*return*/, _a.sent()];
|
|
19814
20351
|
case 9:
|
|
19815
|
-
|
|
19816
|
-
if (!(
|
|
19817
|
-
throw
|
|
20352
|
+
error_16 = _a.sent();
|
|
20353
|
+
if (!(error_16 instanceof CodexWorkerBootstrapError)) {
|
|
20354
|
+
throw error_16;
|
|
19818
20355
|
}
|
|
19819
|
-
console.error('AI worker bootstrap failed, falling back to in-process run.',
|
|
20356
|
+
console.error('AI worker bootstrap failed, falling back to in-process run.', error_16);
|
|
19820
20357
|
codexClient = getAssistantCodexClient(config);
|
|
19821
20358
|
return [4 /*yield*/, codexClient.run(prompt, streamedOptions)];
|
|
19822
20359
|
case 10: return [2 /*return*/, _a.sent()];
|
|
@@ -19854,7 +20391,7 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
19854
20391
|
timeoutMs = ((sanitizedOptions === null || sanitizedOptions === void 0 ? void 0 : sanitizedOptions.timeoutMs) || resolveCodexTimeoutMs()) + 15000;
|
|
19855
20392
|
timeoutController = new AbortController();
|
|
19856
20393
|
timeoutPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
19857
|
-
var
|
|
20394
|
+
var error_17;
|
|
19858
20395
|
return __generator(this, function (_a) {
|
|
19859
20396
|
switch (_a.label) {
|
|
19860
20397
|
case 0:
|
|
@@ -19864,11 +20401,11 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
19864
20401
|
_a.sent();
|
|
19865
20402
|
return [2 /*return*/, { type: 'timeout' }];
|
|
19866
20403
|
case 2:
|
|
19867
|
-
|
|
19868
|
-
if ((
|
|
20404
|
+
error_17 = _a.sent();
|
|
20405
|
+
if ((error_17 === null || error_17 === void 0 ? void 0 : error_17.name) === 'AbortError') {
|
|
19869
20406
|
return [2 /*return*/, { type: 'aborted' }];
|
|
19870
20407
|
}
|
|
19871
|
-
throw
|
|
20408
|
+
throw error_17;
|
|
19872
20409
|
case 3: return [2 /*return*/];
|
|
19873
20410
|
}
|
|
19874
20411
|
});
|
|
@@ -23718,7 +24255,7 @@ function resolveAssistantDatabaseNameForSystemCollections() {
|
|
|
23718
24255
|
}
|
|
23719
24256
|
function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
23720
24257
|
return __awaiter(this, void 0, void 0, function () {
|
|
23721
|
-
var safeSetPayload, fallbackId, debugEnabled, result,
|
|
24258
|
+
var safeSetPayload, fallbackId, debugEnabled, result, error_18, dbName, messagesCollection, result, _a, retryResult;
|
|
23722
24259
|
var _b, _c, _d, _e, _f, _g;
|
|
23723
24260
|
return __generator(this, function (_h) {
|
|
23724
24261
|
switch (_h.label) {
|
|
@@ -23757,14 +24294,14 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
23757
24294
|
}
|
|
23758
24295
|
return [2 /*return*/];
|
|
23759
24296
|
case 5:
|
|
23760
|
-
|
|
23761
|
-
if (!isAssistantTransactionCommittedError(
|
|
23762
|
-
throw
|
|
24297
|
+
error_18 = _h.sent();
|
|
24298
|
+
if (!isAssistantTransactionCommittedError(error_18)) {
|
|
24299
|
+
throw error_18;
|
|
23763
24300
|
}
|
|
23764
24301
|
if (debugEnabled) {
|
|
23765
24302
|
console.log(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update fallback triggered', {
|
|
23766
24303
|
messageId: fallbackId || messageId,
|
|
23767
|
-
reason: normalizeOptionalString(
|
|
24304
|
+
reason: normalizeOptionalString(error_18 === null || error_18 === void 0 ? void 0 : error_18.message) || 'transaction_committed'
|
|
23768
24305
|
});
|
|
23769
24306
|
}
|
|
23770
24307
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
@@ -23840,7 +24377,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
23840
24377
|
}
|
|
23841
24378
|
function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
23842
24379
|
return __awaiter(this, void 0, void 0, function () {
|
|
23843
|
-
var update, result,
|
|
24380
|
+
var update, result, error_19, dbName, conversationsCollection, fallbackResult;
|
|
23844
24381
|
return __generator(this, function (_a) {
|
|
23845
24382
|
switch (_a.label) {
|
|
23846
24383
|
case 0:
|
|
@@ -23865,9 +24402,9 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
23865
24402
|
}
|
|
23866
24403
|
return [2 /*return*/];
|
|
23867
24404
|
case 3:
|
|
23868
|
-
|
|
23869
|
-
if (!isAssistantTransactionCommittedError(
|
|
23870
|
-
throw
|
|
24405
|
+
error_19 = _a.sent();
|
|
24406
|
+
if (!isAssistantTransactionCommittedError(error_19)) {
|
|
24407
|
+
throw error_19;
|
|
23871
24408
|
}
|
|
23872
24409
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
23873
24410
|
conversationsCollection = resolveio_server_app_1.ResolveIOServer.getMongoConnection()
|
|
@@ -24139,7 +24676,7 @@ function buildAssistantAIRunId(prefix, parts) {
|
|
|
24139
24676
|
}
|
|
24140
24677
|
function recordAssistantAnswerAIRun(input) {
|
|
24141
24678
|
return __awaiter(this, void 0, void 0, function () {
|
|
24142
|
-
var messages, run,
|
|
24679
|
+
var messages, run, error_20;
|
|
24143
24680
|
return __generator(this, function (_a) {
|
|
24144
24681
|
switch (_a.label) {
|
|
24145
24682
|
case 0:
|
|
@@ -24164,8 +24701,8 @@ function recordAssistantAnswerAIRun(input) {
|
|
|
24164
24701
|
_a.sent();
|
|
24165
24702
|
return [3 /*break*/, 3];
|
|
24166
24703
|
case 2:
|
|
24167
|
-
|
|
24168
|
-
console.error(new Date(), 'Failed to record AI assistant AIRun evidence',
|
|
24704
|
+
error_20 = _a.sent();
|
|
24705
|
+
console.error(new Date(), 'Failed to record AI assistant AIRun evidence', error_20);
|
|
24169
24706
|
return [3 /*break*/, 3];
|
|
24170
24707
|
case 3: return [2 /*return*/];
|
|
24171
24708
|
}
|