@resolveio/server-lib 22.2.14 → 22.2.15
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/managers/mongo.manager.d.ts +3 -0
- package/managers/mongo.manager.js +756 -653
- package/managers/mongo.manager.js.map +1 -1
- package/methods/ai-terminal.d.ts +71 -0
- package/methods/ai-terminal.js +747 -215
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +2 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -109,6 +109,7 @@ exports.loadAiTerminalMethods = loadAiTerminalMethods;
|
|
|
109
109
|
exports.executeAiAssistantMongoRead = executeAiAssistantMongoRead;
|
|
110
110
|
exports.executeAiAssistantMongoAggregate = executeAiAssistantMongoAggregate;
|
|
111
111
|
exports.extractAssistantMongoDirective = extractAssistantMongoDirective;
|
|
112
|
+
exports.buildAssistantToolRequest = buildAssistantToolRequest;
|
|
112
113
|
exports.buildAssistantInvoiceCustomerLabelExpr = buildAssistantInvoiceCustomerLabelExpr;
|
|
113
114
|
exports.buildAssistantDatedPivotDisplay = buildAssistantDatedPivotDisplay;
|
|
114
115
|
exports.deriveAssistantCommandExecutionStatus = deriveAssistantCommandExecutionStatus;
|
|
@@ -131,6 +132,7 @@ exports.resolveAssistantCrossCollectionFallbackCandidates = resolveAssistantCros
|
|
|
131
132
|
exports.resolveAssistantAvailableCrossCollectionFallbacksFromNames = resolveAssistantAvailableCrossCollectionFallbacksFromNames;
|
|
132
133
|
exports.evaluateAssistantFallbackDocumentsQuality = evaluateAssistantFallbackDocumentsQuality;
|
|
133
134
|
exports.shouldAcceptAssistantFallbackDocuments = shouldAcceptAssistantFallbackDocuments;
|
|
135
|
+
exports.resolveAssistantReportBuilderBridgeCollection = resolveAssistantReportBuilderBridgeCollection;
|
|
134
136
|
exports.collectUserViewPermissions = collectUserViewPermissions;
|
|
135
137
|
exports.userHasInvoiceAccess = userHasInvoiceAccess;
|
|
136
138
|
exports.resolveAssistantUserAccessTier = resolveAssistantUserAccessTier;
|
|
@@ -139,6 +141,7 @@ exports.buildAssistantWorkspaceRootCandidates = buildAssistantWorkspaceRootCandi
|
|
|
139
141
|
exports.classifyAssistantRequestType = classifyAssistantRequestType;
|
|
140
142
|
exports.shouldRunAssistantPlanner = shouldRunAssistantPlanner;
|
|
141
143
|
exports.shouldEnforceAssistantDatedDirective = shouldEnforceAssistantDatedDirective;
|
|
144
|
+
exports.buildAssistantSchemaHints = buildAssistantSchemaHints;
|
|
142
145
|
exports.collectAssistantAllowedRoutesForUser = collectAssistantAllowedRoutesForUser;
|
|
143
146
|
exports.rankAssistantNavigationRoutes = rankAssistantNavigationRoutes;
|
|
144
147
|
exports.shouldUseAssistantNavigationFastPath = shouldUseAssistantNavigationFastPath;
|
|
@@ -176,7 +179,7 @@ var DEFAULT_AI_ASSISTANT_MONGO_MAX_TIME_MS = 12000;
|
|
|
176
179
|
var AI_ASSISTANT_MONGO_DEFAULT_LIMIT = 20;
|
|
177
180
|
var AI_ASSISTANT_MONGO_MAX_LIMIT = 200;
|
|
178
181
|
var AI_ASSISTANT_MONGO_EXPORT_MAX_LIMIT = 5000;
|
|
179
|
-
var AI_ASSISTANT_TOOL_MAX_STEPS =
|
|
182
|
+
var AI_ASSISTANT_TOOL_MAX_STEPS = 2;
|
|
180
183
|
var AI_ASSISTANT_DISPLAY_MAX_COLUMNS = 12;
|
|
181
184
|
var AI_ASSISTANT_DISPLAY_PREVIEW_MAX_ROWS = 20;
|
|
182
185
|
var AI_ASSISTANT_DISPLAY_STRING_LIMIT = 160;
|
|
@@ -193,6 +196,9 @@ var AI_ASSISTANT_ID_LOOKUP_CANDIDATE_LIMIT = 4;
|
|
|
193
196
|
var AI_ASSISTANT_NAME_MATCH_FALLBACK_MAX_FIELDS = 12;
|
|
194
197
|
var AI_ASSISTANT_CONTEXT_MAX_COLLECTIONS = 3;
|
|
195
198
|
var AI_ASSISTANT_CONTEXT_MAX_FIELDS_PER_COLLECTION = 24;
|
|
199
|
+
var AI_ASSISTANT_CONTEXT_MAX_SCHEMA_COLLECTIONS = 5;
|
|
200
|
+
var AI_ASSISTANT_CONTEXT_MAX_SCHEMA_FIELDS_PER_COLLECTION = 18;
|
|
201
|
+
var AI_ASSISTANT_CONTEXT_MAX_LOOKUPS_PER_COLLECTION = 8;
|
|
196
202
|
var AI_ASSISTANT_PLANNER_MAX_ROUTES = 200;
|
|
197
203
|
var AI_ASSISTANT_PLANNER_DEBUG_MAX_CHARS = 2000;
|
|
198
204
|
var AI_ASSISTANT_LOCALE = 'en-US';
|
|
@@ -503,6 +509,7 @@ var AI_ASSISTANT_REPORT_BUILDER_EXPERT_PLAYBOOK = [
|
|
|
503
509
|
'2) Resolve the target dataset safely.',
|
|
504
510
|
'- Map user wording to internal collection names using routes, collection hints, field hints, and synonym expansion.',
|
|
505
511
|
'- Prefer report-* collections when permissionView is under /report-builder.',
|
|
512
|
+
'- If a report-* collection is unavailable, keep using REPORT_BUILDER_* with the best-matched family collection; the bridge can fall back to direct collection reads safely.',
|
|
506
513
|
'- Never use *.versions unless user explicitly requests bug-history/version investigation.',
|
|
507
514
|
'- Never invent collection names or fields.',
|
|
508
515
|
'',
|
|
@@ -563,6 +570,7 @@ var AI_ASSISTANT_SYSTEM_PROMPT = [
|
|
|
563
570
|
'- Never use *.versions collections for normal requests. Only use a .versions collection when explicitly investigating a bug by checking the last ~5 updates.',
|
|
564
571
|
'- Planning stage: regex/keyword scan the codebase for collectionName/model definitions, methods, publications, and Angular routes/modules to map user wording to internal names.',
|
|
565
572
|
'- If permissionView starts with /report-builder, prefer the report-* collection when both report and base collections exist.',
|
|
573
|
+
'- If a report-* collection is unavailable, keep using REPORT_BUILDER_READ/REPORT_BUILDER_AGG with the best-matched collection family; the bridge can safely fall back to direct collection access.',
|
|
566
574
|
'- Map user wording to internal collections/fields yourself. Do not ask for property names unless required to run a query.',
|
|
567
575
|
'- Use term hints from context (synonym expansions) when mapping user language to collections.',
|
|
568
576
|
'- Do not guess or invent collections/fields. If unsure, verify in the codebase or run a small REPORT_BUILDER_READ probe (limit 1-5) to learn the shape.',
|
|
@@ -790,6 +798,7 @@ var AI_ASSISTANT_PLANNER_USER_PROMPT_TEMPLATE = [
|
|
|
790
798
|
'',
|
|
791
799
|
'Collection hints (may be empty): {{collection_hints_json_array}}',
|
|
792
800
|
'Field hints (may be empty): {{field_hints_json_array}}',
|
|
801
|
+
'Schema hints (may be empty): {{schema_hints_json_array}}',
|
|
793
802
|
'Method hints (may be empty): {{method_hints_json_array}}',
|
|
794
803
|
'Publication hints (may be empty): {{publication_hints_json_array}}',
|
|
795
804
|
'',
|
|
@@ -1815,13 +1824,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1815
1824
|
insertResult = _d.sent();
|
|
1816
1825
|
assistantMessageId = (insertResult === null || insertResult === void 0 ? void 0 : insertResult._id) || (insertResult === null || insertResult === void 0 ? void 0 : insertResult.insertedId);
|
|
1817
1826
|
enqueueAssistantCodexRun(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1818
|
-
var runStart, fastModeEnabled, plannerEnabled, runBudgetMs, assistantMongoMaxTimeMs, assistantSystemPrompt, runDeadlineMs, steps, recordStep, progressTracker, streamProgress, remainingRunBudgetMs, hasRunBudget, applyCodexStageBudget, assistantContent, toolResult, assistantDebug, directiveSource, requestClassification, dataQuestion, lastDirective, heuristicDirectivePrecomputed, usedDeterministicHeuristicFastPath, requestedTimeGrain, requestedBreakdownDimensions, enforceDatedDirective, enforceGroupedDirective, datedDirectiveRetryUsed, datedDirectiveResolved, toolResponseDebug, toolError, termHints, collectionHints, fieldHints, 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, rankedCollectionHints, rankedCollections, hintCollections, assistantContext, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerBudgetAvailable, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, _c, initialStart, extractedDirective, error_2, directivePrompt, forcedStart, forcedDirective, _d, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, _e, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, _f, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, _g, heuristicDirective, requestedCollection, allowCollectionOverride, cleanedResponseText, deniedModuleByIntent, permissionLabel, effectiveDirective, toolRequest, toolStart, toolResponse,
|
|
1819
|
-
var
|
|
1820
|
-
return __generator(this, function (
|
|
1821
|
-
switch (
|
|
1827
|
+
var runStart, fastModeEnabled, alwaysAllowProbeEnabled, plannerEnabled, runBudgetMs, assistantMongoMaxTimeMs, assistantSystemPrompt, runDeadlineMs, steps, recordStep, progressTracker, streamProgress, remainingRunBudgetMs, hasRunBudget, applyCodexStageBudget, assistantContent, toolResult, assistantDebug, directiveSource, requestClassification, dataQuestion, 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, 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, _c, initialStart, extractedDirective, error_2, directivePrompt, forcedStart, forcedDirective, _d, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, _e, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, _f, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, _g, heuristicDirective, requestedCollection, allowCollectionOverride, cleanedResponseText, deniedModuleByIntent, permissionLabel, effectiveDirective, rankedCollections_1, directiveHintsBase_1, buildToolRequestForDirective, executionDirective, probeFieldHints, probeEnabled, probeBudgetAllowed, probeDirective, probeRequest, probeStart, probeResponse, _h, probeDurationMs, probeRowCount, probeRewrite, probeError_1, probeDurationMs, probeErrorMessage, toolRequest, requestedToolCollection, toolStart, toolResponse, _j, toolDurationMs, toolPayload, resolvedToolCollection, zeroRowResult, skipFollowupCodex, followupPrompt, followupStart, followupText, _k, error_3, errorMessage, existingFinal, error_4, runBudgetExceeded, includeToolExecutionTelemetry, toolExecutionTelemetry, finishedAt, finalNow, finishedAt, codexMs, draftingMs, finalMetadata, finalUsage, usageClientId, usageError_1, finalAssistantDoc, setPayload, finalizeError_1, failedAt, fallbackContent, failureMetadata, persistError_1, _l;
|
|
1828
|
+
var _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21;
|
|
1829
|
+
return __generator(this, function (_22) {
|
|
1830
|
+
switch (_22.label) {
|
|
1822
1831
|
case 0:
|
|
1823
1832
|
runStart = Date.now();
|
|
1824
1833
|
fastModeEnabled = resolveAssistantFastModeEnabled(input.config);
|
|
1834
|
+
alwaysAllowProbeEnabled = resolveAssistantAlwaysAllowProbeEnabled(input.config);
|
|
1825
1835
|
plannerEnabled = resolveAssistantPlannerEnabled(input.config);
|
|
1826
1836
|
runBudgetMs = resolveAssistantRunBudgetMs(input.config);
|
|
1827
1837
|
assistantMongoMaxTimeMs = resolveAssistantMongoDefaultMaxTimeMs(input.config);
|
|
@@ -1834,6 +1844,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1834
1844
|
id_conversation: (conversation === null || conversation === void 0 ? void 0 : conversation._id) || null,
|
|
1835
1845
|
id_message: assistantMessageId ? String(assistantMessageId) : null,
|
|
1836
1846
|
fastModeEnabled: fastModeEnabled,
|
|
1847
|
+
alwaysAllowProbeEnabled: alwaysAllowProbeEnabled,
|
|
1837
1848
|
runBudgetMs: runDeadlineMs ? runBudgetMs : null,
|
|
1838
1849
|
isWorkerInstance: process.env.IS_WORKER_INSTANCE || null,
|
|
1839
1850
|
workerIndex: process.env.WORKER_INDEX || null,
|
|
@@ -1898,9 +1909,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1898
1909
|
datedDirectiveResolved = false;
|
|
1899
1910
|
toolResponseDebug = null;
|
|
1900
1911
|
toolError = null;
|
|
1912
|
+
toolTelemetry = {
|
|
1913
|
+
mode: AI_ASSISTANT_TOOL_MAX_STEPS > 1 ? 'probe_then_final' : 'single_step',
|
|
1914
|
+
alwaysAllowProbe: alwaysAllowProbeEnabled
|
|
1915
|
+
};
|
|
1901
1916
|
termHints = [];
|
|
1902
1917
|
collectionHints = [];
|
|
1903
1918
|
fieldHints = [];
|
|
1919
|
+
schemaHints = [];
|
|
1904
1920
|
methodHints = [];
|
|
1905
1921
|
publicationHints = [];
|
|
1906
1922
|
collectionTokenization = null;
|
|
@@ -1935,8 +1951,8 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1935
1951
|
codexUsage.output_tokens += outputTokens;
|
|
1936
1952
|
codexUsage.total_tokens += inputTokens + outputTokens;
|
|
1937
1953
|
};
|
|
1938
|
-
contextRoute = normalizeOptionalString((
|
|
1939
|
-
contextMode = normalizeOptionalString((
|
|
1954
|
+
contextRoute = normalizeOptionalString((_m = input === null || input === void 0 ? void 0 : input.context) === null || _m === void 0 ? void 0 : _m.route);
|
|
1955
|
+
contextMode = normalizeOptionalString((_o = input === null || input === void 0 ? void 0 : input.context) === null || _o === void 0 ? void 0 : _o.mode);
|
|
1940
1956
|
recordStep('Queued', { requestId: requestId || undefined });
|
|
1941
1957
|
if (changeHistoryFastPathBypassedReason) {
|
|
1942
1958
|
recordStep('Planning: change-history fast path unavailable', {
|
|
@@ -1948,9 +1964,9 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1948
1964
|
source: requestClassification.source,
|
|
1949
1965
|
dataQuestion: dataQuestion
|
|
1950
1966
|
});
|
|
1951
|
-
|
|
1967
|
+
_22.label = 1;
|
|
1952
1968
|
case 1:
|
|
1953
|
-
|
|
1969
|
+
_22.trys.push([1, 68, 69, 70]);
|
|
1954
1970
|
hintSeed = [message, contextRoute].filter(Boolean).join(' ');
|
|
1955
1971
|
termExpansion = expandAssistantTermSynonyms(hintSeed);
|
|
1956
1972
|
hintText = termExpansion.expanded || hintSeed;
|
|
@@ -1971,19 +1987,19 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1971
1987
|
recordStep('Planning: term expansion', {
|
|
1972
1988
|
termMatches: termExpansion.matches.length ? termExpansion.matches : undefined
|
|
1973
1989
|
});
|
|
1974
|
-
|
|
1990
|
+
_22.label = 2;
|
|
1975
1991
|
case 2:
|
|
1976
|
-
|
|
1992
|
+
_22.trys.push([2, 5, , 6]);
|
|
1977
1993
|
dbName = resolveAssistantDatabaseName(undefined, input.mongo);
|
|
1978
1994
|
db = resolveio_server_app_1.ResolveIOServer.getMongoConnection().db(dbName);
|
|
1979
1995
|
return [4 /*yield*/, listAssistantCollections(db, dbName)];
|
|
1980
1996
|
case 3:
|
|
1981
|
-
collectionNames =
|
|
1997
|
+
collectionNames = _22.sent();
|
|
1982
1998
|
collectionHints = resolveCollectionHintsFromTokens(expandedTokens, collectionNames, 5);
|
|
1983
1999
|
collectionRanking = buildCollectionRankingDebugFromTokens(expandedTokens, collectionNames, 8);
|
|
1984
2000
|
return [4 /*yield*/, resolveAssistantSurfaceHints(hintSeed, contextRoute, collectionNames)];
|
|
1985
2001
|
case 4:
|
|
1986
|
-
surfaceHints =
|
|
2002
|
+
surfaceHints = _22.sent();
|
|
1987
2003
|
methodHints = surfaceHints.methodHints;
|
|
1988
2004
|
publicationHints = surfaceHints.publicationHints;
|
|
1989
2005
|
if (surfaceHints.collectionHints.length) {
|
|
@@ -1991,7 +2007,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1991
2007
|
}
|
|
1992
2008
|
return [3 /*break*/, 6];
|
|
1993
2009
|
case 5:
|
|
1994
|
-
_a =
|
|
2010
|
+
_a = _22.sent();
|
|
1995
2011
|
collectionHints = [];
|
|
1996
2012
|
collectionRanking = collectionRanking || ((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens)
|
|
1997
2013
|
? buildCollectionRankingDebugFromTokens(collectionTokenization.expandedTokens || [], [], 0)
|
|
@@ -2023,13 +2039,18 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2023
2039
|
: [];
|
|
2024
2040
|
hintCollections = mergeAssistantHintValues(collectionHints, rankedCollections)
|
|
2025
2041
|
.slice(0, AI_ASSISTANT_CONTEXT_MAX_COLLECTIONS);
|
|
2042
|
+
schemaHintCollections = mergeAssistantHintValues(hintCollections, rankedCollections, collectionHints).slice(0, AI_ASSISTANT_CONTEXT_MAX_SCHEMA_COLLECTIONS);
|
|
2026
2043
|
fieldHints = buildAssistantFieldHints(message, hintCollections);
|
|
2044
|
+
schemaHints = buildAssistantSchemaHints(schemaHintCollections, {
|
|
2045
|
+
maxCollections: AI_ASSISTANT_CONTEXT_MAX_SCHEMA_COLLECTIONS
|
|
2046
|
+
});
|
|
2027
2047
|
recordStep('Planning: collection hints', {
|
|
2028
2048
|
contextRoute: contextRoute || undefined,
|
|
2029
2049
|
contextMode: contextMode || undefined,
|
|
2030
2050
|
collectionHints: collectionHints.length ? collectionHints : undefined,
|
|
2031
2051
|
termHints: termHints.length ? termHints : undefined,
|
|
2032
2052
|
fieldHints: fieldHints.length ? fieldHints : undefined,
|
|
2053
|
+
schemaHints: schemaHints.length ? schemaHints : undefined,
|
|
2033
2054
|
methodHints: methodHints.length ? methodHints : undefined,
|
|
2034
2055
|
publicationHints: publicationHints.length ? publicationHints : undefined
|
|
2035
2056
|
});
|
|
@@ -2040,6 +2061,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2040
2061
|
collectionHints: collectionHints,
|
|
2041
2062
|
termHints: termHints,
|
|
2042
2063
|
fieldHints: fieldHints,
|
|
2064
|
+
schemaHints: schemaHints,
|
|
2043
2065
|
methodHints: methodHints,
|
|
2044
2066
|
publicationHints: publicationHints,
|
|
2045
2067
|
recentToolError: recentToolError,
|
|
@@ -2054,14 +2076,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2054
2076
|
if (hasDeterministicHeuristicFastPath) {
|
|
2055
2077
|
recordStep('Planning: heuristic directive fast path', {
|
|
2056
2078
|
type: heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.type,
|
|
2057
|
-
collection: normalizeOptionalString((
|
|
2079
|
+
collection: normalizeOptionalString((_p = heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.payload) === null || _p === void 0 ? void 0 : _p.collection) || undefined,
|
|
2058
2080
|
heuristic: normalizeOptionalString(heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.rawLine) || undefined
|
|
2059
2081
|
});
|
|
2060
2082
|
}
|
|
2061
2083
|
prompt_1 = buildAssistantCodexPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, assistantSystemPrompt);
|
|
2062
2084
|
return [4 /*yield*/, resolveAssistantWorkspaceRoot()];
|
|
2063
2085
|
case 7:
|
|
2064
|
-
workspaceRoot =
|
|
2086
|
+
workspaceRoot = _22.sent();
|
|
2065
2087
|
codexConfig = resolveCodexSettings({
|
|
2066
2088
|
model: codexModel,
|
|
2067
2089
|
fallbackModels: codexFallbackModels
|
|
@@ -2105,24 +2127,25 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2105
2127
|
user: user,
|
|
2106
2128
|
collectionHints: collectionHints,
|
|
2107
2129
|
fieldHints: fieldHints,
|
|
2130
|
+
schemaHints: schemaHints,
|
|
2108
2131
|
methodHints: methodHints,
|
|
2109
2132
|
publicationHints: publicationHints,
|
|
2110
2133
|
inputClientId: input.id_client
|
|
2111
2134
|
});
|
|
2112
|
-
|
|
2135
|
+
_22.label = 8;
|
|
2113
2136
|
case 8:
|
|
2114
|
-
|
|
2137
|
+
_22.trys.push([8, 10, , 11]);
|
|
2115
2138
|
plannerStart = Date.now();
|
|
2116
2139
|
return [4 /*yield*/, runCodexInWorkerThread(plannerPrompt, applyCodexStageBudget(plannerRunOptions), codexConfig, streamProgress)];
|
|
2117
2140
|
case 9:
|
|
2118
|
-
plannerRaw =
|
|
2141
|
+
plannerRaw = _22.sent();
|
|
2119
2142
|
accumulateCodexUsage(plannerPrompt, plannerRaw);
|
|
2120
2143
|
timingBreakdown.plannerMs = Date.now() - plannerStart;
|
|
2121
2144
|
plannerOutput = parseJsonObject(plannerRaw);
|
|
2122
2145
|
recordStep('Planning: planner result', { parsed: !!plannerOutput });
|
|
2123
2146
|
return [3 /*break*/, 11];
|
|
2124
2147
|
case 10:
|
|
2125
|
-
_b =
|
|
2148
|
+
_b = _22.sent();
|
|
2126
2149
|
recordStep('Planning: planner result', { parsed: false });
|
|
2127
2150
|
return [3 /*break*/, 11];
|
|
2128
2151
|
case 11: return [3 /*break*/, 13];
|
|
@@ -2142,7 +2165,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2142
2165
|
}
|
|
2143
2166
|
recordStep('Planning: planner skipped', { reason: plannerSkipReason });
|
|
2144
2167
|
}
|
|
2145
|
-
|
|
2168
|
+
_22.label = 13;
|
|
2146
2169
|
case 13:
|
|
2147
2170
|
requestClassification = classifyAssistantRequestType(message, plannerOutput || undefined);
|
|
2148
2171
|
dataQuestion = requestClassification.dataQuestion;
|
|
@@ -2184,12 +2207,12 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2184
2207
|
directiveSource = 'forced';
|
|
2185
2208
|
lastDirective = heuristicDirectiveFastPath;
|
|
2186
2209
|
usedDeterministicHeuristicFastPath = true;
|
|
2187
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2210
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_q = directive.payload) === null || _q === void 0 ? void 0 : _q.collection) || '');
|
|
2188
2211
|
recordStep('Directive resolved', {
|
|
2189
2212
|
source: directiveSource,
|
|
2190
2213
|
type: directive.type,
|
|
2191
|
-
collection: normalizeOptionalString((
|
|
2192
|
-
permissionView: normalizeOptionalString((
|
|
2214
|
+
collection: normalizeOptionalString((_r = directive.payload) === null || _r === void 0 ? void 0 : _r.collection) || undefined,
|
|
2215
|
+
permissionView: normalizeOptionalString((_s = directive.payload) === null || _s === void 0 ? void 0 : _s.permissionView) || undefined,
|
|
2193
2216
|
reportStyle: 'heuristic_fast_path',
|
|
2194
2217
|
timeGrain: requestedTimeGrain || undefined
|
|
2195
2218
|
});
|
|
@@ -2198,13 +2221,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2198
2221
|
recordStep('Directive: determine tool', { type: 'data-question' });
|
|
2199
2222
|
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode, assistantSystemPrompt);
|
|
2200
2223
|
if (!hasRunBudget('Directive: determine tool')) return [3 /*break*/, 17];
|
|
2201
|
-
|
|
2224
|
+
_22.label = 14;
|
|
2202
2225
|
case 14:
|
|
2203
|
-
|
|
2226
|
+
_22.trys.push([14, 16, , 17]);
|
|
2204
2227
|
directiveStart = Date.now();
|
|
2205
2228
|
return [4 /*yield*/, runCodexInWorkerThread(directivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2206
2229
|
case 15:
|
|
2207
|
-
directiveText =
|
|
2230
|
+
directiveText = _22.sent();
|
|
2208
2231
|
accumulateCodexUsage(directivePrompt, directiveText);
|
|
2209
2232
|
timingBreakdown.directiveMs = Date.now() - directiveStart;
|
|
2210
2233
|
forcedDirective = extractAssistantMongoDirective(directiveText);
|
|
@@ -2212,29 +2235,29 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2212
2235
|
directive = forcedDirective;
|
|
2213
2236
|
directiveSource = 'model';
|
|
2214
2237
|
lastDirective = forcedDirective;
|
|
2215
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2238
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_t = directive.payload) === null || _t === void 0 ? void 0 : _t.collection) || '');
|
|
2216
2239
|
recordStep('Directive resolved', {
|
|
2217
2240
|
source: directiveSource,
|
|
2218
2241
|
type: directive.type,
|
|
2219
|
-
collection: normalizeOptionalString((
|
|
2220
|
-
permissionView: normalizeOptionalString((
|
|
2242
|
+
collection: normalizeOptionalString((_u = directive.payload) === null || _u === void 0 ? void 0 : _u.collection) || undefined,
|
|
2243
|
+
permissionView: normalizeOptionalString((_v = directive.payload) === null || _v === void 0 ? void 0 : _v.permissionView) || undefined
|
|
2221
2244
|
});
|
|
2222
2245
|
}
|
|
2223
2246
|
return [3 /*break*/, 17];
|
|
2224
2247
|
case 16:
|
|
2225
|
-
_c =
|
|
2248
|
+
_c = _22.sent();
|
|
2226
2249
|
return [3 /*break*/, 17];
|
|
2227
2250
|
case 17:
|
|
2228
2251
|
if (!(!directive && !dataQuestion)) return [3 /*break*/, 21];
|
|
2229
2252
|
recordStep('Response: draft initial answer', { mode: 'full' });
|
|
2230
2253
|
if (!hasRunBudget('Response: initial draft')) return [3 /*break*/, 21];
|
|
2231
|
-
|
|
2254
|
+
_22.label = 18;
|
|
2232
2255
|
case 18:
|
|
2233
|
-
|
|
2256
|
+
_22.trys.push([18, 20, , 21]);
|
|
2234
2257
|
initialStart = Date.now();
|
|
2235
2258
|
return [4 /*yield*/, runCodexInWorkerThread(prompt_1, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2236
2259
|
case 19:
|
|
2237
|
-
responseText =
|
|
2260
|
+
responseText = _22.sent();
|
|
2238
2261
|
accumulateCodexUsage(prompt_1, responseText);
|
|
2239
2262
|
timingBreakdown.initialResponseMs = Date.now() - initialStart;
|
|
2240
2263
|
extractedDirective = extractAssistantMongoDirective(responseText);
|
|
@@ -2242,17 +2265,17 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2242
2265
|
if (directive) {
|
|
2243
2266
|
directiveSource = 'model';
|
|
2244
2267
|
lastDirective = directive;
|
|
2245
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2268
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_w = directive.payload) === null || _w === void 0 ? void 0 : _w.collection) || '');
|
|
2246
2269
|
recordStep('Directive resolved', {
|
|
2247
2270
|
source: directiveSource,
|
|
2248
2271
|
type: directive.type,
|
|
2249
|
-
collection: normalizeOptionalString((
|
|
2250
|
-
permissionView: normalizeOptionalString((
|
|
2272
|
+
collection: normalizeOptionalString((_x = directive.payload) === null || _x === void 0 ? void 0 : _x.collection) || undefined,
|
|
2273
|
+
permissionView: normalizeOptionalString((_y = directive.payload) === null || _y === void 0 ? void 0 : _y.permissionView) || undefined
|
|
2251
2274
|
});
|
|
2252
2275
|
}
|
|
2253
2276
|
return [3 /*break*/, 21];
|
|
2254
2277
|
case 20:
|
|
2255
|
-
error_2 =
|
|
2278
|
+
error_2 = _22.sent();
|
|
2256
2279
|
recordStep('Response: initial draft failed', {
|
|
2257
2280
|
message: normalizeOptionalString(error_2 === null || error_2 === void 0 ? void 0 : error_2.message) || 'Unknown error'
|
|
2258
2281
|
});
|
|
@@ -2262,13 +2285,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2262
2285
|
recordStep('Directive: forced retry', { mode: 'directive-only' });
|
|
2263
2286
|
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode, assistantSystemPrompt);
|
|
2264
2287
|
if (!hasRunBudget('Directive: forced retry')) return [3 /*break*/, 25];
|
|
2265
|
-
|
|
2288
|
+
_22.label = 22;
|
|
2266
2289
|
case 22:
|
|
2267
|
-
|
|
2290
|
+
_22.trys.push([22, 24, , 25]);
|
|
2268
2291
|
forcedStart = Date.now();
|
|
2269
2292
|
return [4 /*yield*/, runCodexInWorkerThread(directivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2270
2293
|
case 23:
|
|
2271
|
-
directiveText =
|
|
2294
|
+
directiveText = _22.sent();
|
|
2272
2295
|
accumulateCodexUsage(directivePrompt, directiveText);
|
|
2273
2296
|
timingBreakdown.forcedDirectiveMs = Date.now() - forcedStart;
|
|
2274
2297
|
forcedDirective = extractAssistantMongoDirective(directiveText);
|
|
@@ -2276,17 +2299,17 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2276
2299
|
directive = forcedDirective;
|
|
2277
2300
|
directiveSource = 'forced';
|
|
2278
2301
|
lastDirective = forcedDirective;
|
|
2279
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2302
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_z = directive.payload) === null || _z === void 0 ? void 0 : _z.collection) || '');
|
|
2280
2303
|
recordStep('Directive resolved', {
|
|
2281
2304
|
source: directiveSource,
|
|
2282
2305
|
type: directive.type,
|
|
2283
|
-
collection: normalizeOptionalString((
|
|
2284
|
-
permissionView: normalizeOptionalString((
|
|
2306
|
+
collection: normalizeOptionalString((_0 = directive.payload) === null || _0 === void 0 ? void 0 : _0.collection) || undefined,
|
|
2307
|
+
permissionView: normalizeOptionalString((_1 = directive.payload) === null || _1 === void 0 ? void 0 : _1.permissionView) || undefined
|
|
2285
2308
|
});
|
|
2286
2309
|
}
|
|
2287
2310
|
return [3 /*break*/, 25];
|
|
2288
2311
|
case 24:
|
|
2289
|
-
_d =
|
|
2312
|
+
_d = _22.sent();
|
|
2290
2313
|
return [3 /*break*/, 25];
|
|
2291
2314
|
case 25:
|
|
2292
2315
|
if (!(directive
|
|
@@ -2305,13 +2328,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2305
2328
|
strict: true
|
|
2306
2329
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2307
2330
|
if (!hasRunBudget('Directive: dated retry')) return [3 /*break*/, 29];
|
|
2308
|
-
|
|
2331
|
+
_22.label = 26;
|
|
2309
2332
|
case 26:
|
|
2310
|
-
|
|
2333
|
+
_22.trys.push([26, 28, , 29]);
|
|
2311
2334
|
strictStart = Date.now();
|
|
2312
2335
|
return [4 /*yield*/, runCodexInWorkerThread(strictDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2313
2336
|
case 27:
|
|
2314
|
-
strictDirectiveText =
|
|
2337
|
+
strictDirectiveText = _22.sent();
|
|
2315
2338
|
accumulateCodexUsage(strictDirectivePrompt, strictDirectiveText);
|
|
2316
2339
|
timingBreakdown.forcedDirectiveMs += Date.now() - strictStart;
|
|
2317
2340
|
strictDirective = extractAssistantMongoDirective(strictDirectiveText);
|
|
@@ -2322,19 +2345,19 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2322
2345
|
directiveSource = 'forced';
|
|
2323
2346
|
lastDirective = strictDirective;
|
|
2324
2347
|
datedDirectiveRetryUsed = true;
|
|
2325
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2348
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_2 = directive.payload) === null || _2 === void 0 ? void 0 : _2.collection) || '');
|
|
2326
2349
|
recordStep('Directive resolved', {
|
|
2327
2350
|
source: directiveSource,
|
|
2328
2351
|
type: directive.type,
|
|
2329
|
-
collection: normalizeOptionalString((
|
|
2330
|
-
permissionView: normalizeOptionalString((
|
|
2352
|
+
collection: normalizeOptionalString((_3 = directive.payload) === null || _3 === void 0 ? void 0 : _3.collection) || undefined,
|
|
2353
|
+
permissionView: normalizeOptionalString((_4 = directive.payload) === null || _4 === void 0 ? void 0 : _4.permissionView) || undefined,
|
|
2331
2354
|
reportStyle: strictDirectiveIsDated ? 'dated' : 'aggregate_fallback',
|
|
2332
2355
|
timeGrain: requestedTimeGrain || undefined
|
|
2333
2356
|
});
|
|
2334
2357
|
}
|
|
2335
2358
|
return [3 /*break*/, 29];
|
|
2336
2359
|
case 28:
|
|
2337
|
-
_e =
|
|
2360
|
+
_e = _22.sent();
|
|
2338
2361
|
return [3 /*break*/, 29];
|
|
2339
2362
|
case 29:
|
|
2340
2363
|
if (!(directive
|
|
@@ -2353,13 +2376,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2353
2376
|
strict: true
|
|
2354
2377
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2355
2378
|
if (!hasRunBudget('Directive: dated guard retry')) return [3 /*break*/, 33];
|
|
2356
|
-
|
|
2379
|
+
_22.label = 30;
|
|
2357
2380
|
case 30:
|
|
2358
|
-
|
|
2381
|
+
_22.trys.push([30, 32, , 33]);
|
|
2359
2382
|
guardStart = Date.now();
|
|
2360
2383
|
return [4 /*yield*/, runCodexInWorkerThread(guardDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2361
2384
|
case 31:
|
|
2362
|
-
guardDirectiveText =
|
|
2385
|
+
guardDirectiveText = _22.sent();
|
|
2363
2386
|
accumulateCodexUsage(guardDirectivePrompt, guardDirectiveText);
|
|
2364
2387
|
timingBreakdown.forcedDirectiveMs += Date.now() - guardStart;
|
|
2365
2388
|
guardDirective = extractAssistantMongoDirective(guardDirectiveText);
|
|
@@ -2368,19 +2391,19 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2368
2391
|
directiveSource = 'forced';
|
|
2369
2392
|
lastDirective = guardDirective;
|
|
2370
2393
|
datedDirectiveRetryUsed = true;
|
|
2371
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2394
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_5 = directive.payload) === null || _5 === void 0 ? void 0 : _5.collection) || '');
|
|
2372
2395
|
recordStep('Directive resolved', {
|
|
2373
2396
|
source: directiveSource,
|
|
2374
2397
|
type: directive.type,
|
|
2375
|
-
collection: normalizeOptionalString((
|
|
2376
|
-
permissionView: normalizeOptionalString((
|
|
2398
|
+
collection: normalizeOptionalString((_6 = directive.payload) === null || _6 === void 0 ? void 0 : _6.collection) || undefined,
|
|
2399
|
+
permissionView: normalizeOptionalString((_7 = directive.payload) === null || _7 === void 0 ? void 0 : _7.permissionView) || undefined,
|
|
2377
2400
|
reportStyle: isAssistantDirectiveDated(guardDirective) ? 'dated' : 'aggregate_fallback',
|
|
2378
2401
|
timeGrain: requestedTimeGrain || undefined
|
|
2379
2402
|
});
|
|
2380
2403
|
}
|
|
2381
2404
|
return [3 /*break*/, 33];
|
|
2382
2405
|
case 32:
|
|
2383
|
-
_f =
|
|
2406
|
+
_f = _22.sent();
|
|
2384
2407
|
return [3 /*break*/, 33];
|
|
2385
2408
|
case 33:
|
|
2386
2409
|
if (!(directive
|
|
@@ -2399,13 +2422,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2399
2422
|
strict: true
|
|
2400
2423
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2401
2424
|
if (!hasRunBudget('Directive: grouped guard retry')) return [3 /*break*/, 37];
|
|
2402
|
-
|
|
2425
|
+
_22.label = 34;
|
|
2403
2426
|
case 34:
|
|
2404
|
-
|
|
2427
|
+
_22.trys.push([34, 36, , 37]);
|
|
2405
2428
|
groupedStart = Date.now();
|
|
2406
2429
|
return [4 /*yield*/, runCodexInWorkerThread(groupedDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2407
2430
|
case 35:
|
|
2408
|
-
groupedDirectiveText =
|
|
2431
|
+
groupedDirectiveText = _22.sent();
|
|
2409
2432
|
accumulateCodexUsage(groupedDirectivePrompt, groupedDirectiveText);
|
|
2410
2433
|
timingBreakdown.forcedDirectiveMs += Date.now() - groupedStart;
|
|
2411
2434
|
groupedDirective = extractAssistantMongoDirective(groupedDirectiveText);
|
|
@@ -2414,12 +2437,12 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2414
2437
|
directiveSource = 'forced';
|
|
2415
2438
|
lastDirective = groupedDirective;
|
|
2416
2439
|
datedDirectiveRetryUsed = true;
|
|
2417
|
-
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((
|
|
2440
|
+
collectionSelection = buildCollectionSelectionDetail((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens) || [], normalizeOptionalString((_8 = directive.payload) === null || _8 === void 0 ? void 0 : _8.collection) || '');
|
|
2418
2441
|
recordStep('Directive resolved', {
|
|
2419
2442
|
source: directiveSource,
|
|
2420
2443
|
type: directive.type,
|
|
2421
|
-
collection: normalizeOptionalString((
|
|
2422
|
-
permissionView: normalizeOptionalString((
|
|
2444
|
+
collection: normalizeOptionalString((_9 = directive.payload) === null || _9 === void 0 ? void 0 : _9.collection) || undefined,
|
|
2445
|
+
permissionView: normalizeOptionalString((_10 = directive.payload) === null || _10 === void 0 ? void 0 : _10.permissionView) || undefined,
|
|
2423
2446
|
reportStyle: isAssistantDirectiveDated(groupedDirective)
|
|
2424
2447
|
? 'dated'
|
|
2425
2448
|
: 'grouped',
|
|
@@ -2429,7 +2452,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2429
2452
|
}
|
|
2430
2453
|
return [3 /*break*/, 37];
|
|
2431
2454
|
case 36:
|
|
2432
|
-
_g =
|
|
2455
|
+
_g = _22.sent();
|
|
2433
2456
|
return [3 /*break*/, 37];
|
|
2434
2457
|
case 37:
|
|
2435
2458
|
if (!directive && dataQuestion) {
|
|
@@ -2441,21 +2464,21 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2441
2464
|
recordStep('Directive resolved', {
|
|
2442
2465
|
source: directiveSource,
|
|
2443
2466
|
type: directive.type,
|
|
2444
|
-
collection: normalizeOptionalString((
|
|
2445
|
-
permissionView: normalizeOptionalString((
|
|
2467
|
+
collection: normalizeOptionalString((_11 = directive.payload) === null || _11 === void 0 ? void 0 : _11.collection) || undefined,
|
|
2468
|
+
permissionView: normalizeOptionalString((_12 = directive.payload) === null || _12 === void 0 ? void 0 : _12.permissionView) || undefined,
|
|
2446
2469
|
reportStyle: 'heuristic_fallback'
|
|
2447
2470
|
});
|
|
2448
2471
|
}
|
|
2449
2472
|
}
|
|
2450
2473
|
if (directive) {
|
|
2451
|
-
requestedCollection = normalizeOptionalString((
|
|
2474
|
+
requestedCollection = normalizeOptionalString((_13 = directive.payload) === null || _13 === void 0 ? void 0 : _13.collection);
|
|
2452
2475
|
allowCollectionOverride = !isAssistantDeterministicHeuristicDirective(directive);
|
|
2453
2476
|
collectionOverride = allowCollectionOverride
|
|
2454
2477
|
? resolveCollectionOverrideWithContext({
|
|
2455
2478
|
message: message,
|
|
2456
2479
|
collectionRanking: collectionRanking,
|
|
2457
2480
|
requestedCollection: requestedCollection,
|
|
2458
|
-
permissionView: normalizeOptionalString((
|
|
2481
|
+
permissionView: normalizeOptionalString((_14 = directive.payload) === null || _14 === void 0 ? void 0 : _14.permissionView) || contextRoute,
|
|
2459
2482
|
collectionNames: collectionNames
|
|
2460
2483
|
})
|
|
2461
2484
|
: null;
|
|
@@ -2486,48 +2509,204 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2486
2509
|
});
|
|
2487
2510
|
assistantContent = "I couldn't run that request because this account does not have ".concat(permissionLabel, " permission.");
|
|
2488
2511
|
toolError = new Error('AI assistant report builder bridge: Access denied.');
|
|
2489
|
-
|
|
2512
|
+
toolTelemetry.permissionDenied = true;
|
|
2513
|
+
toolTelemetry.final = {
|
|
2514
|
+
attempted: false,
|
|
2515
|
+
skippedReason: 'permission_denied',
|
|
2516
|
+
error: 'permission_denied'
|
|
2517
|
+
};
|
|
2518
|
+
toolTelemetry.outcome = {
|
|
2519
|
+
error: 'permission_denied'
|
|
2520
|
+
};
|
|
2521
|
+
return [3 /*break*/, 67];
|
|
2490
2522
|
case 38:
|
|
2491
|
-
if (!((directive === null || directive === void 0 ? void 0 : directive.payload) && AI_ASSISTANT_TOOL_MAX_STEPS > 0)) return [3 /*break*/,
|
|
2523
|
+
if (!((directive === null || directive === void 0 ? void 0 : directive.payload) && AI_ASSISTANT_TOOL_MAX_STEPS > 0)) return [3 /*break*/, 66];
|
|
2492
2524
|
effectiveDirective = collectionOverride
|
|
2493
2525
|
? __assign(__assign({}, directive), { payload: __assign(__assign({}, (directive.payload || {})), { collection: collectionOverride.to }) }) : directive;
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2526
|
+
rankedCollections_1 = Array.isArray(collectionRanking === null || collectionRanking === void 0 ? void 0 : collectionRanking.ranked)
|
|
2527
|
+
? collectionRanking.ranked
|
|
2528
|
+
.map(function (entry) { return normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.name); })
|
|
2529
|
+
.filter(Boolean)
|
|
2530
|
+
: [];
|
|
2531
|
+
directiveHintsBase_1 = {
|
|
2532
|
+
collectionHints: collectionHints,
|
|
2533
|
+
rankedCollections: rankedCollections_1,
|
|
2534
|
+
fieldHints: fieldHints,
|
|
2535
|
+
schemaHints: schemaHints
|
|
2536
|
+
};
|
|
2537
|
+
buildToolRequestForDirective = function (value, additionalFieldHints) {
|
|
2538
|
+
if (additionalFieldHints === void 0) { additionalFieldHints = []; }
|
|
2539
|
+
var request = buildAssistantToolRequest(value, input, __assign(__assign({}, directiveHintsBase_1), { fieldHints: mergeAssistantHintValues(directiveHintsBase_1.fieldHints || [], additionalFieldHints) }));
|
|
2540
|
+
request.__assistantRuntime = {
|
|
2541
|
+
fastMode: alwaysAllowProbeEnabled ? false : fastModeEnabled,
|
|
2542
|
+
deadlineMs: runDeadlineMs || undefined,
|
|
2543
|
+
maxTimeMS: assistantMongoMaxTimeMs
|
|
2544
|
+
};
|
|
2545
|
+
return request;
|
|
2499
2546
|
};
|
|
2500
2547
|
progressTracker.push('Grabbing Data');
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
permissionView: normalizeOptionalString(toolRequest === null || toolRequest === void 0 ? void 0 : toolRequest.permissionView) || undefined
|
|
2505
|
-
});
|
|
2506
|
-
_14.label = 39;
|
|
2548
|
+
executionDirective = effectiveDirective;
|
|
2549
|
+
probeFieldHints = [];
|
|
2550
|
+
_22.label = 39;
|
|
2507
2551
|
case 39:
|
|
2508
|
-
|
|
2509
|
-
if (
|
|
2552
|
+
_22.trys.push([39, 64, , 65]);
|
|
2553
|
+
if (!(!alwaysAllowProbeEnabled && !hasRunBudget('Grabbing Data', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS))) return [3 /*break*/, 40];
|
|
2510
2554
|
assistantContent = buildAssistantRunBudgetExceededMessage();
|
|
2511
|
-
|
|
2555
|
+
toolTelemetry.final = {
|
|
2556
|
+
attempted: false,
|
|
2557
|
+
skippedReason: 'run_budget_exhausted_before_probe',
|
|
2558
|
+
error: 'run_budget_exhausted'
|
|
2559
|
+
};
|
|
2560
|
+
toolTelemetry.outcome = {
|
|
2561
|
+
error: 'run_budget_exhausted'
|
|
2562
|
+
};
|
|
2563
|
+
return [3 /*break*/, 63];
|
|
2512
2564
|
case 40:
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2565
|
+
probeEnabled = AI_ASSISTANT_TOOL_MAX_STEPS > 1;
|
|
2566
|
+
probeBudgetAllowed = alwaysAllowProbeEnabled
|
|
2567
|
+
|| hasRunBudget('Grabbing Data: probe', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS);
|
|
2568
|
+
if (!(probeEnabled && probeBudgetAllowed)) return [3 /*break*/, 50];
|
|
2569
|
+
probeDirective = buildAssistantProbeDirective(executionDirective);
|
|
2570
|
+
if (!(probeDirective === null || probeDirective === void 0 ? void 0 : probeDirective.payload)) return [3 /*break*/, 48];
|
|
2571
|
+
probeRequest = buildToolRequestForDirective(probeDirective);
|
|
2572
|
+
recordStep('Grabbing Data: probe start', {
|
|
2573
|
+
type: probeDirective.type,
|
|
2574
|
+
collection: normalizeOptionalString(probeRequest === null || probeRequest === void 0 ? void 0 : probeRequest.collection) || undefined,
|
|
2575
|
+
permissionView: normalizeOptionalString(probeRequest === null || probeRequest === void 0 ? void 0 : probeRequest.permissionView) || undefined
|
|
2576
|
+
});
|
|
2577
|
+
toolTelemetry.probe = {
|
|
2578
|
+
attempted: true
|
|
2579
|
+
};
|
|
2580
|
+
probeStart = Date.now();
|
|
2581
|
+
_22.label = 41;
|
|
2516
2582
|
case 41:
|
|
2517
|
-
|
|
2518
|
-
return [3 /*break*/,
|
|
2519
|
-
|
|
2520
|
-
case
|
|
2521
|
-
_h =
|
|
2522
|
-
|
|
2583
|
+
_22.trys.push([41, 46, , 47]);
|
|
2584
|
+
if (!(probeDirective.type === 'aggregate')) return [3 /*break*/, 43];
|
|
2585
|
+
return [4 /*yield*/, executeAiAssistantReportBuilderAggregate(probeRequest, context)];
|
|
2586
|
+
case 42:
|
|
2587
|
+
_h = _22.sent();
|
|
2588
|
+
return [3 /*break*/, 45];
|
|
2589
|
+
case 43: return [4 /*yield*/, executeAiAssistantReportBuilderRead(probeRequest, context)];
|
|
2523
2590
|
case 44:
|
|
2524
|
-
|
|
2525
|
-
|
|
2591
|
+
_h = _22.sent();
|
|
2592
|
+
_22.label = 45;
|
|
2593
|
+
case 45:
|
|
2594
|
+
probeResponse = _h;
|
|
2595
|
+
probeDurationMs = Date.now() - probeStart;
|
|
2596
|
+
timingBreakdown.toolMs += probeDurationMs;
|
|
2597
|
+
probeRowCount = Array.isArray(probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.documents)
|
|
2598
|
+
? probeResponse.documents.length
|
|
2599
|
+
: 0;
|
|
2600
|
+
probeRewrite = rewriteAssistantDirectiveWithProbe(executionDirective, probeResponse);
|
|
2601
|
+
executionDirective = probeRewrite.directive;
|
|
2602
|
+
probeFieldHints = probeRewrite.fieldHints;
|
|
2603
|
+
toolTelemetry.probe = {
|
|
2604
|
+
attempted: true,
|
|
2605
|
+
succeeded: true,
|
|
2606
|
+
rowCount: probeRowCount,
|
|
2607
|
+
durationMs: probeDurationMs,
|
|
2608
|
+
rewritesApplied: probeRewrite.notes.length > 0 || probeFieldHints.length > 0,
|
|
2609
|
+
rewriteNotes: probeRewrite.notes.length ? probeRewrite.notes : undefined,
|
|
2610
|
+
fieldHintsAdded: probeFieldHints.length
|
|
2611
|
+
};
|
|
2612
|
+
recordStep('Grabbing Data: probe complete', {
|
|
2613
|
+
rowCount: probeRowCount,
|
|
2614
|
+
collection: normalizeOptionalString(((_15 = probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.debug) === null || _15 === void 0 ? void 0 : _15.collectionResolved) || ((_16 = probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.debug) === null || _16 === void 0 ? void 0 : _16.collection)) || undefined
|
|
2615
|
+
});
|
|
2616
|
+
if (probeRewrite.notes.length || probeFieldHints.length) {
|
|
2617
|
+
recordStep('Grabbing Data: probe rewrite', {
|
|
2618
|
+
notes: probeRewrite.notes.length ? probeRewrite.notes : undefined,
|
|
2619
|
+
fieldHints: probeFieldHints.length ? probeFieldHints.slice(0, 6) : undefined
|
|
2620
|
+
});
|
|
2621
|
+
}
|
|
2622
|
+
return [3 /*break*/, 47];
|
|
2623
|
+
case 46:
|
|
2624
|
+
probeError_1 = _22.sent();
|
|
2625
|
+
probeDurationMs = Date.now() - probeStart;
|
|
2626
|
+
probeErrorMessage = normalizeOptionalString(probeError_1 === null || probeError_1 === void 0 ? void 0 : probeError_1.message) || 'Unknown error';
|
|
2627
|
+
toolTelemetry.probe = {
|
|
2628
|
+
attempted: true,
|
|
2629
|
+
failed: true,
|
|
2630
|
+
durationMs: probeDurationMs,
|
|
2631
|
+
error: probeErrorMessage
|
|
2632
|
+
};
|
|
2633
|
+
recordStep('Grabbing Data: probe failed', {
|
|
2634
|
+
message: probeErrorMessage
|
|
2635
|
+
});
|
|
2636
|
+
return [3 /*break*/, 47];
|
|
2637
|
+
case 47: return [3 /*break*/, 49];
|
|
2638
|
+
case 48:
|
|
2639
|
+
toolTelemetry.probe = {
|
|
2640
|
+
attempted: false,
|
|
2641
|
+
skippedReason: 'probe_directive_missing_payload'
|
|
2642
|
+
};
|
|
2643
|
+
_22.label = 49;
|
|
2644
|
+
case 49: return [3 /*break*/, 51];
|
|
2645
|
+
case 50:
|
|
2646
|
+
if (probeEnabled) {
|
|
2647
|
+
toolTelemetry.probe = {
|
|
2648
|
+
attempted: false,
|
|
2649
|
+
skippedReason: 'run_budget_exhausted'
|
|
2650
|
+
};
|
|
2651
|
+
}
|
|
2652
|
+
_22.label = 51;
|
|
2653
|
+
case 51:
|
|
2654
|
+
if (!(!alwaysAllowProbeEnabled && !hasRunBudget('Grabbing Data: final', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS))) return [3 /*break*/, 52];
|
|
2655
|
+
assistantContent = buildAssistantRunBudgetExceededMessage();
|
|
2656
|
+
toolTelemetry.final = {
|
|
2657
|
+
attempted: false,
|
|
2658
|
+
skippedReason: 'run_budget_exhausted_before_final',
|
|
2659
|
+
error: 'run_budget_exhausted'
|
|
2660
|
+
};
|
|
2661
|
+
toolTelemetry.outcome = {
|
|
2662
|
+
error: 'run_budget_exhausted'
|
|
2663
|
+
};
|
|
2664
|
+
return [3 /*break*/, 63];
|
|
2665
|
+
case 52:
|
|
2666
|
+
toolRequest = buildToolRequestForDirective(executionDirective, probeFieldHints);
|
|
2667
|
+
requestedToolCollection = normalizeOptionalString(toolRequest === null || toolRequest === void 0 ? void 0 : toolRequest.collection);
|
|
2668
|
+
recordStep('Grabbing Data: start', {
|
|
2669
|
+
type: executionDirective.type,
|
|
2670
|
+
collection: requestedToolCollection || undefined,
|
|
2671
|
+
permissionView: normalizeOptionalString(toolRequest === null || toolRequest === void 0 ? void 0 : toolRequest.permissionView) || undefined
|
|
2672
|
+
});
|
|
2673
|
+
toolTelemetry.final = {
|
|
2674
|
+
attempted: true,
|
|
2675
|
+
toolType: executionDirective.type,
|
|
2676
|
+
collection: requestedToolCollection || undefined
|
|
2677
|
+
};
|
|
2678
|
+
toolStart = Date.now();
|
|
2679
|
+
if (!(executionDirective.type === 'aggregate')) return [3 /*break*/, 54];
|
|
2680
|
+
return [4 /*yield*/, executeAiAssistantReportBuilderAggregate(toolRequest, context)];
|
|
2681
|
+
case 53:
|
|
2682
|
+
_j = _22.sent();
|
|
2683
|
+
return [3 /*break*/, 56];
|
|
2684
|
+
case 54: return [4 /*yield*/, executeAiAssistantReportBuilderRead(toolRequest, context)];
|
|
2685
|
+
case 55:
|
|
2686
|
+
_j = _22.sent();
|
|
2687
|
+
_22.label = 56;
|
|
2688
|
+
case 56:
|
|
2689
|
+
toolResponse = _j;
|
|
2690
|
+
toolDurationMs = Date.now() - toolStart;
|
|
2691
|
+
timingBreakdown.toolMs += toolDurationMs;
|
|
2526
2692
|
toolResponseDebug = (toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) && typeof toolResponse.debug === 'object'
|
|
2527
2693
|
? toolResponse.debug
|
|
2528
2694
|
: null;
|
|
2529
|
-
toolPayload = buildAssistantToolResultPayload(
|
|
2695
|
+
toolPayload = buildAssistantToolResultPayload(executionDirective, toolResponse, message);
|
|
2530
2696
|
toolResult = toolPayload.result;
|
|
2697
|
+
resolvedToolCollection = normalizeOptionalString(toolPayload.result.output.collection
|
|
2698
|
+
|| ((_17 = toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) === null || _17 === void 0 ? void 0 : _17.collectionResolved)
|
|
2699
|
+
|| ((_18 = toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) === null || _18 === void 0 ? void 0 : _18.collection)
|
|
2700
|
+
|| requestedToolCollection);
|
|
2701
|
+
toolTelemetry.final = {
|
|
2702
|
+
attempted: true,
|
|
2703
|
+
succeeded: true,
|
|
2704
|
+
rowCount: toolPayload.result.output.rowCount,
|
|
2705
|
+
total: toolPayload.result.output.total,
|
|
2706
|
+
durationMs: toolDurationMs,
|
|
2707
|
+
toolType: executionDirective.type,
|
|
2708
|
+
collection: resolvedToolCollection || undefined
|
|
2709
|
+
};
|
|
2531
2710
|
recordStep('Grabbing Data: complete', {
|
|
2532
2711
|
rowCount: toolPayload.result.output.rowCount,
|
|
2533
2712
|
total: toolPayload.result.output.total,
|
|
@@ -2535,65 +2714,72 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2535
2714
|
});
|
|
2536
2715
|
progressTracker.push('Drafting response');
|
|
2537
2716
|
zeroRowResult = toolPayload.result.output.rowCount <= 0;
|
|
2717
|
+
toolTelemetry.outcome = zeroRowResult ? { zeroRows: true } : undefined;
|
|
2538
2718
|
skipFollowupCodex = usedDeterministicHeuristicFastPath
|
|
2539
|
-
|| isAssistantDeterministicHeuristicDirective(
|
|
2719
|
+
|| isAssistantDeterministicHeuristicDirective(executionDirective)
|
|
2540
2720
|
|| zeroRowResult;
|
|
2541
|
-
if (!skipFollowupCodex) return [3 /*break*/,
|
|
2721
|
+
if (!skipFollowupCodex) return [3 /*break*/, 57];
|
|
2542
2722
|
recordStep('Drafting response: deterministic summary', {
|
|
2543
2723
|
reason: zeroRowResult
|
|
2544
2724
|
? 'zero_rows'
|
|
2545
|
-
: (normalizeOptionalString(
|
|
2725
|
+
: (normalizeOptionalString(executionDirective.rawLine) || 'deterministic_heuristic')
|
|
2546
2726
|
});
|
|
2547
2727
|
assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
|
|
2548
2728
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2549
|
-
return [3 /*break*/,
|
|
2550
|
-
case
|
|
2729
|
+
return [3 /*break*/, 63];
|
|
2730
|
+
case 57:
|
|
2551
2731
|
recordStep('Drafting response');
|
|
2552
2732
|
followupPrompt = buildAssistantCodexToolFollowupPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, toolPayload.prompt, assistantSystemPrompt);
|
|
2553
|
-
if (!hasRunBudget('Drafting response: followup')) return [3 /*break*/,
|
|
2554
|
-
|
|
2555
|
-
case
|
|
2556
|
-
|
|
2733
|
+
if (!hasRunBudget('Drafting response: followup')) return [3 /*break*/, 62];
|
|
2734
|
+
_22.label = 58;
|
|
2735
|
+
case 58:
|
|
2736
|
+
_22.trys.push([58, 60, , 61]);
|
|
2557
2737
|
followupStart = Date.now();
|
|
2558
2738
|
return [4 /*yield*/, runCodexInWorkerThread(followupPrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2559
|
-
case
|
|
2560
|
-
followupText =
|
|
2739
|
+
case 59:
|
|
2740
|
+
followupText = _22.sent();
|
|
2561
2741
|
accumulateCodexUsage(followupPrompt, followupText);
|
|
2562
2742
|
timingBreakdown.followupMs = Date.now() - followupStart;
|
|
2563
2743
|
assistantContent = sanitizeAssistantResponse(followupText);
|
|
2564
2744
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2565
|
-
return [3 /*break*/,
|
|
2566
|
-
case
|
|
2567
|
-
|
|
2745
|
+
return [3 /*break*/, 61];
|
|
2746
|
+
case 60:
|
|
2747
|
+
_k = _22.sent();
|
|
2568
2748
|
assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
|
|
2569
2749
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2570
|
-
return [3 /*break*/,
|
|
2571
|
-
case
|
|
2572
|
-
case
|
|
2750
|
+
return [3 /*break*/, 61];
|
|
2751
|
+
case 61: return [3 /*break*/, 63];
|
|
2752
|
+
case 62:
|
|
2573
2753
|
assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
|
|
2574
2754
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2575
|
-
|
|
2576
|
-
case
|
|
2577
|
-
case
|
|
2578
|
-
error_3 =
|
|
2755
|
+
_22.label = 63;
|
|
2756
|
+
case 63: return [3 /*break*/, 65];
|
|
2757
|
+
case 64:
|
|
2758
|
+
error_3 = _22.sent();
|
|
2579
2759
|
assistantContent = buildAssistantToolErrorMessage(error_3);
|
|
2580
2760
|
toolError = error_3;
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2761
|
+
errorMessage = normalizeOptionalString(error_3 === null || error_3 === void 0 ? void 0 : error_3.message) || 'Unknown error';
|
|
2762
|
+
existingFinal = toolTelemetry.final && typeof toolTelemetry.final === 'object'
|
|
2763
|
+
? toolTelemetry.final
|
|
2764
|
+
: { attempted: false };
|
|
2765
|
+
toolTelemetry.final = __assign(__assign({}, existingFinal), { attempted: existingFinal.attempted === true, failed: true, error: errorMessage });
|
|
2766
|
+
toolTelemetry.outcome = __assign(__assign({}, (toolTelemetry.outcome || {})), { error: errorMessage });
|
|
2767
|
+
return [3 /*break*/, 65];
|
|
2768
|
+
case 65: return [3 /*break*/, 67];
|
|
2769
|
+
case 66:
|
|
2584
2770
|
progressTracker.push('Drafting response');
|
|
2585
2771
|
recordStep('Drafting response');
|
|
2586
|
-
|
|
2587
|
-
case
|
|
2588
|
-
case
|
|
2589
|
-
error_4 =
|
|
2772
|
+
_22.label = 67;
|
|
2773
|
+
case 67: return [3 /*break*/, 70];
|
|
2774
|
+
case 68:
|
|
2775
|
+
error_4 = _22.sent();
|
|
2590
2776
|
assistantContent = buildAssistantCodexErrorMessage(error_4);
|
|
2591
2777
|
recordStep('Error', { message: normalizeOptionalString(error_4 === null || error_4 === void 0 ? void 0 : error_4.message) || 'Unknown error' });
|
|
2592
|
-
return [3 /*break*/,
|
|
2593
|
-
case
|
|
2778
|
+
return [3 /*break*/, 70];
|
|
2779
|
+
case 69:
|
|
2594
2780
|
progressTracker.stop();
|
|
2595
2781
|
return [7 /*endfinally*/];
|
|
2596
|
-
case
|
|
2782
|
+
case 70:
|
|
2597
2783
|
runBudgetExceeded = runDeadlineMs ? Date.now() > runDeadlineMs : false;
|
|
2598
2784
|
if (!assistantContent) {
|
|
2599
2785
|
assistantContent = runBudgetExceeded
|
|
@@ -2604,6 +2790,20 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2604
2790
|
assistantContent = applyAssistantDatedReportWindow(assistantContent, toolResult);
|
|
2605
2791
|
assistantContent = applyAssistantLotNumberResponseGuard(assistantContent, message, toolResult);
|
|
2606
2792
|
assistantContent = normalizeAssistantCurrencyText(assistantContent);
|
|
2793
|
+
if (toolError && !normalizeOptionalString((_19 = toolTelemetry === null || toolTelemetry === void 0 ? void 0 : toolTelemetry.outcome) === null || _19 === void 0 ? void 0 : _19.error)) {
|
|
2794
|
+
toolTelemetry.outcome = __assign(__assign({}, (toolTelemetry.outcome || {})), { error: normalizeOptionalString(toolError === null || toolError === void 0 ? void 0 : toolError.message) || 'tool_error' });
|
|
2795
|
+
}
|
|
2796
|
+
if (((_20 = toolResult === null || toolResult === void 0 ? void 0 : toolResult.output) === null || _20 === void 0 ? void 0 : _20.rowCount) === 0 && !((_21 = toolTelemetry === null || toolTelemetry === void 0 ? void 0 : toolTelemetry.outcome) === null || _21 === void 0 ? void 0 : _21.zeroRows)) {
|
|
2797
|
+
toolTelemetry.outcome = __assign(__assign({}, (toolTelemetry.outcome || {})), { zeroRows: true });
|
|
2798
|
+
}
|
|
2799
|
+
includeToolExecutionTelemetry = dataQuestion
|
|
2800
|
+
|| toolTelemetry.permissionDenied === true
|
|
2801
|
+
|| !!toolTelemetry.probe
|
|
2802
|
+
|| !!toolTelemetry.final
|
|
2803
|
+
|| !!toolTelemetry.outcome;
|
|
2804
|
+
toolExecutionTelemetry = includeToolExecutionTelemetry
|
|
2805
|
+
? buildAssistantToolExecutionTelemetrySnapshot(toolTelemetry)
|
|
2806
|
+
: null;
|
|
2607
2807
|
if (aiWorkerDebug) {
|
|
2608
2808
|
finishedAt = Date.now();
|
|
2609
2809
|
console.log(new Date(), '[AI Worker Debug] codex run complete', {
|
|
@@ -2616,15 +2816,16 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2616
2816
|
timingBreakdown: timingBreakdown,
|
|
2617
2817
|
runBudgetMs: runDeadlineMs ? runBudgetMs : null,
|
|
2618
2818
|
runBudgetRemainingMs: remainingRunBudgetMs(),
|
|
2819
|
+
toolExecution: toolExecutionTelemetry || undefined,
|
|
2619
2820
|
isWorkerInstance: process.env.IS_WORKER_INSTANCE || null,
|
|
2620
2821
|
workerIndex: process.env.WORKER_INDEX || null,
|
|
2621
2822
|
workerInstance: process.env.NODE_APP_INSTANCE || null
|
|
2622
2823
|
});
|
|
2623
2824
|
}
|
|
2624
2825
|
finalNow = new Date();
|
|
2625
|
-
|
|
2626
|
-
case
|
|
2627
|
-
|
|
2826
|
+
_22.label = 71;
|
|
2827
|
+
case 71:
|
|
2828
|
+
_22.trys.push([71, 82, , 93]);
|
|
2628
2829
|
if (canViewDebug) {
|
|
2629
2830
|
finishedAt = Date.now();
|
|
2630
2831
|
codexMs = timingBreakdown.directiveMs
|
|
@@ -2649,6 +2850,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2649
2850
|
toolResult: toolResult,
|
|
2650
2851
|
toolResponseDebug: toolResponseDebug,
|
|
2651
2852
|
toolError: toolError,
|
|
2853
|
+
toolExecution: toolExecutionTelemetry || undefined,
|
|
2652
2854
|
collectionOverride: collectionOverride,
|
|
2653
2855
|
trace: {
|
|
2654
2856
|
steps: steps,
|
|
@@ -2658,6 +2860,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2658
2860
|
termHints: termHints.length ? termHints : undefined,
|
|
2659
2861
|
collectionHints: collectionHints.length ? collectionHints : undefined,
|
|
2660
2862
|
fieldHints: fieldHints.length ? fieldHints : undefined,
|
|
2863
|
+
schemaHints: schemaHints.length ? schemaHints : undefined,
|
|
2661
2864
|
methodHints: methodHints.length ? methodHints : undefined,
|
|
2662
2865
|
publicationHints: publicationHints.length ? publicationHints : undefined,
|
|
2663
2866
|
collectionTokenization: collectionTokenization || undefined,
|
|
@@ -2692,27 +2895,27 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2692
2895
|
}
|
|
2693
2896
|
});
|
|
2694
2897
|
}
|
|
2695
|
-
finalMetadata = __assign(__assign(__assign(__assign(__assign(__assign(__assign({ model: codexModel }, (codexFallbackModels.length ? { model_fallbacks: codexFallbackModels } : {})), (requestId ? { request_id: requestId } : {})), { pending: false }), (fastModeEnabled ? {
|
|
2898
|
+
finalMetadata = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({ model: codexModel }, (codexFallbackModels.length ? { model_fallbacks: codexFallbackModels } : {})), (requestId ? { request_id: requestId } : {})), { pending: false }), (fastModeEnabled ? {
|
|
2696
2899
|
fast_mode: true,
|
|
2697
2900
|
run_budget_ms: runBudgetMs,
|
|
2698
2901
|
run_budget_exhausted: runBudgetExceeded
|
|
2699
2902
|
} : {})), (changeHistoryFastPathBypassedReason ? {
|
|
2700
2903
|
fast_path_change_history_bypassed_reason: changeHistoryFastPathBypassedReason
|
|
2701
|
-
} : {})), (toolResult ? { tool_result: toolResult } : {})), (assistantDebug ? { debug: assistantDebug } : {}));
|
|
2904
|
+
} : {})), (toolResult ? { tool_result: toolResult } : {})), (toolExecutionTelemetry ? { tool_execution: toolExecutionTelemetry } : {})), (assistantDebug ? { debug: assistantDebug } : {}));
|
|
2702
2905
|
finalUsage = codexUsage.total_tokens > 0 ? {
|
|
2703
2906
|
model: codexModel || 'unknown',
|
|
2704
2907
|
input_tokens: codexUsage.input_tokens,
|
|
2705
2908
|
output_tokens: codexUsage.output_tokens,
|
|
2706
2909
|
total_tokens: codexUsage.total_tokens
|
|
2707
2910
|
} : null;
|
|
2708
|
-
if (!finalUsage) return [3 /*break*/,
|
|
2911
|
+
if (!finalUsage) return [3 /*break*/, 76];
|
|
2709
2912
|
return [4 /*yield*/, resolveClientId(conversation, input.id_client, context === null || context === void 0 ? void 0 : context.id_user)];
|
|
2710
|
-
case
|
|
2711
|
-
usageClientId =
|
|
2712
|
-
if (!usageClientId) return [3 /*break*/,
|
|
2713
|
-
|
|
2714
|
-
case
|
|
2715
|
-
|
|
2913
|
+
case 72:
|
|
2914
|
+
usageClientId = _22.sent();
|
|
2915
|
+
if (!usageClientId) return [3 /*break*/, 76];
|
|
2916
|
+
_22.label = 73;
|
|
2917
|
+
case 73:
|
|
2918
|
+
_22.trys.push([73, 75, , 76]);
|
|
2716
2919
|
return [4 /*yield*/, (0, openai_usage_ledger_manager_1.recordOpenAIUsage)({
|
|
2717
2920
|
id_client: usageClientId,
|
|
2718
2921
|
model: finalUsage.model,
|
|
@@ -2723,16 +2926,16 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2723
2926
|
id_request: requestId || undefined,
|
|
2724
2927
|
id_conversation: conversation._id
|
|
2725
2928
|
})];
|
|
2726
|
-
case
|
|
2727
|
-
|
|
2728
|
-
return [3 /*break*/,
|
|
2729
|
-
case
|
|
2730
|
-
usageError_1 =
|
|
2929
|
+
case 74:
|
|
2930
|
+
_22.sent();
|
|
2931
|
+
return [3 /*break*/, 76];
|
|
2932
|
+
case 75:
|
|
2933
|
+
usageError_1 = _22.sent();
|
|
2731
2934
|
console.error(new Date(), 'Failed to record AI usage', usageError_1);
|
|
2732
|
-
return [3 /*break*/,
|
|
2733
|
-
case
|
|
2935
|
+
return [3 /*break*/, 76];
|
|
2936
|
+
case 76:
|
|
2734
2937
|
finalAssistantDoc = __assign(__assign(__assign(__assign({}, assistantDoc), { _id: assistantMessageId, content: assistantContent, metadata: finalMetadata }), (finalUsage ? { usage: finalUsage } : {})), { updatedAt: finalNow });
|
|
2735
|
-
if (!assistantMessageId) return [3 /*break*/,
|
|
2938
|
+
if (!assistantMessageId) return [3 /*break*/, 78];
|
|
2736
2939
|
setPayload = {
|
|
2737
2940
|
content: assistantContent,
|
|
2738
2941
|
metadata: finalMetadata,
|
|
@@ -2742,59 +2945,59 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2742
2945
|
setPayload.usage = finalUsage;
|
|
2743
2946
|
}
|
|
2744
2947
|
return [4 /*yield*/, updateAssistantMessageWithFallback(assistantMessageId, setPayload)];
|
|
2745
|
-
case
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
case
|
|
2749
|
-
case
|
|
2750
|
-
|
|
2751
|
-
if (!(input.delete_files_after_run !== false)) return [3 /*break*/,
|
|
2948
|
+
case 77:
|
|
2949
|
+
_22.sent();
|
|
2950
|
+
_22.label = 78;
|
|
2951
|
+
case 78: return [4 /*yield*/, touchConversation(conversation._id, finalNow, assistantMessageId ? String(assistantMessageId) : undefined)];
|
|
2952
|
+
case 79:
|
|
2953
|
+
_22.sent();
|
|
2954
|
+
if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 81];
|
|
2752
2955
|
return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
|
|
2753
|
-
case
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
case
|
|
2757
|
-
case
|
|
2758
|
-
finalizeError_1 =
|
|
2956
|
+
case 80:
|
|
2957
|
+
_22.sent();
|
|
2958
|
+
_22.label = 81;
|
|
2959
|
+
case 81: return [2 /*return*/, finalAssistantDoc];
|
|
2960
|
+
case 82:
|
|
2961
|
+
finalizeError_1 = _22.sent();
|
|
2759
2962
|
failedAt = new Date();
|
|
2760
2963
|
fallbackContent = assistantContent || buildAssistantCodexErrorMessage(finalizeError_1);
|
|
2761
|
-
failureMetadata = __assign(__assign(__assign({ model: codexModel }, (codexFallbackModels.length ? { model_fallbacks: codexFallbackModels } : {})), (requestId ? { request_id: requestId } : {})), { pending: false, failed: true, error_message: normalizeOptionalString(finalizeError_1 === null || finalizeError_1 === void 0 ? void 0 : finalizeError_1.message) || 'Unknown error' });
|
|
2762
|
-
|
|
2763
|
-
case
|
|
2764
|
-
|
|
2765
|
-
if (!assistantMessageId) return [3 /*break*/,
|
|
2964
|
+
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' });
|
|
2965
|
+
_22.label = 83;
|
|
2966
|
+
case 83:
|
|
2967
|
+
_22.trys.push([83, 87, , 88]);
|
|
2968
|
+
if (!assistantMessageId) return [3 /*break*/, 85];
|
|
2766
2969
|
return [4 /*yield*/, updateAssistantMessageWithFallback(assistantMessageId, {
|
|
2767
2970
|
content: fallbackContent,
|
|
2768
2971
|
metadata: failureMetadata,
|
|
2769
2972
|
updatedAt: failedAt
|
|
2770
2973
|
})];
|
|
2771
|
-
case
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
case
|
|
2775
|
-
case
|
|
2776
|
-
|
|
2777
|
-
return [3 /*break*/,
|
|
2778
|
-
case
|
|
2779
|
-
persistError_1 =
|
|
2974
|
+
case 84:
|
|
2975
|
+
_22.sent();
|
|
2976
|
+
_22.label = 85;
|
|
2977
|
+
case 85: return [4 /*yield*/, touchConversation(conversation._id, failedAt, assistantMessageId ? String(assistantMessageId) : undefined)];
|
|
2978
|
+
case 86:
|
|
2979
|
+
_22.sent();
|
|
2980
|
+
return [3 /*break*/, 88];
|
|
2981
|
+
case 87:
|
|
2982
|
+
persistError_1 = _22.sent();
|
|
2780
2983
|
console.error(new Date(), 'AI assistant finalize fallback update failed', persistError_1);
|
|
2781
|
-
return [3 /*break*/,
|
|
2782
|
-
case
|
|
2783
|
-
if (!(input.delete_files_after_run !== false)) return [3 /*break*/,
|
|
2784
|
-
|
|
2785
|
-
case
|
|
2786
|
-
|
|
2984
|
+
return [3 /*break*/, 88];
|
|
2985
|
+
case 88:
|
|
2986
|
+
if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 92];
|
|
2987
|
+
_22.label = 89;
|
|
2988
|
+
case 89:
|
|
2989
|
+
_22.trys.push([89, 91, , 92]);
|
|
2787
2990
|
return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
|
|
2788
|
-
case
|
|
2789
|
-
|
|
2790
|
-
return [3 /*break*/,
|
|
2791
|
-
case
|
|
2792
|
-
|
|
2793
|
-
return [3 /*break*/,
|
|
2794
|
-
case
|
|
2991
|
+
case 90:
|
|
2992
|
+
_22.sent();
|
|
2993
|
+
return [3 /*break*/, 92];
|
|
2994
|
+
case 91:
|
|
2995
|
+
_l = _22.sent();
|
|
2996
|
+
return [3 /*break*/, 92];
|
|
2997
|
+
case 92:
|
|
2795
2998
|
console.error(new Date(), 'AI assistant run finalize failed:', finalizeError_1);
|
|
2796
2999
|
return [2 /*return*/, __assign(__assign({}, assistantDoc), { _id: assistantMessageId, content: fallbackContent, metadata: failureMetadata, updatedAt: failedAt })];
|
|
2797
|
-
case
|
|
3000
|
+
case 93: return [2 /*return*/];
|
|
2798
3001
|
}
|
|
2799
3002
|
});
|
|
2800
3003
|
}); });
|
|
@@ -3037,7 +3240,7 @@ function executeAiAssistantReportIssue(payload, context) {
|
|
|
3037
3240
|
}
|
|
3038
3241
|
function executeAiAssistantMongoRead(payload, context) {
|
|
3039
3242
|
return __awaiter(this, void 0, void 0, function () {
|
|
3040
|
-
var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasReadRuntimeBudget, resolveReadMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, buildFindOptions, buildCountOptions, runFindWithRepair, initialRead, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackRead, fallbackDocs, expanded, fallbackRead, fallbackDocs, nameFallback, fallbackRead, fallbackDocs, _c, chemicalLookup, fallbackRead, fallbackDocs, queryFields, _d, aliases, rewrittenQuery, fallbackRead, fallbackDocs, _e, activeFallback, fallbackRead, fallbackDocs, _f, idLookup, fallbackRead, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, existingFallbacks, rejectedQuality, error_5, existingErrors, e_1_1, nameFields, dateFields, diagnostics, countOptions, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, total, sanitizedDocuments, requestedFields, missingFields, _o, projectionAliases, expandedProjection, refreshedDocs, includeIds, fieldAliases, displayDocs, idLookupDisplay, priorityFields, displayMaxRows, display;
|
|
3243
|
+
var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, requestHints, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasReadRuntimeBudget, resolveReadMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, buildFindOptions, buildCountOptions, runFindWithRepair, initialRead, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackRead, fallbackDocs, expanded, fallbackRead, fallbackDocs, nameFallback, fallbackRead, fallbackDocs, _c, chemicalLookup, fallbackRead, fallbackDocs, queryFields, _d, aliases, rewrittenQuery, fallbackRead, fallbackDocs, _e, activeFallback, fallbackRead, fallbackDocs, _f, idLookup, fallbackRead, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, existingFallbacks, rejectedQuality, error_5, existingErrors, e_1_1, nameFields, dateFields, diagnostics, countOptions, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, total, sanitizedDocuments, requestedFields, missingFields, _o, projectionAliases, expandedProjection, refreshedDocs, includeIds, fieldAliases, displayDocs, idLookupDisplay, priorityFields, displayMaxRows, display;
|
|
3041
3244
|
var e_1, _p;
|
|
3042
3245
|
var _this = this;
|
|
3043
3246
|
var _q, _r;
|
|
@@ -3080,6 +3283,7 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3080
3283
|
throw new Error('AI assistant report builder bridge: Access denied.');
|
|
3081
3284
|
}
|
|
3082
3285
|
customerId = normalizeOptionalString((_q = user === null || user === void 0 ? void 0 : user.other) === null || _q === void 0 ? void 0 : _q.id_customer);
|
|
3286
|
+
requestHints = normalizeAssistantDirectiveHints(input.__assistantHints);
|
|
3083
3287
|
fallbackMeta = {};
|
|
3084
3288
|
runtimeControl = normalizeAssistantRuntimeControl(input.__assistantRuntime);
|
|
3085
3289
|
runtimeFastMode = (runtimeControl === null || runtimeControl === void 0 ? void 0 : runtimeControl.fastMode) === undefined
|
|
@@ -3105,6 +3309,8 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3105
3309
|
fallbackMeta.reportBuilderBridge = {
|
|
3106
3310
|
from: bridgeCollection.fallbackFrom,
|
|
3107
3311
|
to: collection,
|
|
3312
|
+
mode: bridgeCollection.mode,
|
|
3313
|
+
resolutionPath: bridgeCollection.resolutionPath,
|
|
3108
3314
|
used: true
|
|
3109
3315
|
};
|
|
3110
3316
|
fallbackMeta.permissionFallback = {
|
|
@@ -3734,20 +3940,11 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3734
3940
|
fallbackMeta.fieldAliases = fieldAliases;
|
|
3735
3941
|
}
|
|
3736
3942
|
return [2 /*return*/, __assign({ documents: sanitizedDocuments, total: total, display: display }, (canViewDebug ? {
|
|
3737
|
-
debug: {
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
collectionCandidates: collectionResolution.candidates,
|
|
3743
|
-
collectionScore: collectionResolution.score,
|
|
3744
|
-
bridge: 'report-builder',
|
|
3745
|
-
database: dbName,
|
|
3746
|
-
query: executedQuery,
|
|
3747
|
-
options: normalized.findOptions,
|
|
3748
|
-
includeTotal: normalized.includeTotal,
|
|
3749
|
-
fallbacks: fallbackMeta
|
|
3750
|
-
}
|
|
3943
|
+
debug: __assign(__assign({ collection: collection, collectionRequested: rawCollection, collectionResolved: collection, collectionMatched: collectionResolution.matched, collectionCandidates: collectionResolution.candidates, collectionScore: collectionResolution.score, bridge: bridgeCollection.mode === 'report-builder' ? 'report-builder' : 'direct-mongo', bridgeResolution: {
|
|
3944
|
+
mode: bridgeCollection.mode,
|
|
3945
|
+
fallbackFrom: bridgeCollection.fallbackFrom || undefined,
|
|
3946
|
+
path: bridgeCollection.resolutionPath
|
|
3947
|
+
}, database: dbName, query: executedQuery, options: normalized.findOptions, includeTotal: normalized.includeTotal }, (requestHints ? { requestHints: requestHints } : {})), { fallbacks: fallbackMeta })
|
|
3751
3948
|
} : {}))];
|
|
3752
3949
|
}
|
|
3753
3950
|
});
|
|
@@ -3755,7 +3952,7 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3755
3952
|
}
|
|
3756
3953
|
function executeAiAssistantMongoAggregate(payload, context) {
|
|
3757
3954
|
return __awaiter(this, void 0, void 0, function () {
|
|
3758
|
-
var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasAggregateRuntimeBudget, resolveAggregateMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, executedPipeline, dateField, buildAggregateOptions, buildAggregateCountOptions, runAggregateWithRepair, initialAggregate, documents, probeDocs, fallback, fallbackPipeline, fallbackAggregate, fallbackDocs, createdFallback, createdPipeline, createdAggregate, createdDocs, expanded, expandedAggregate, expandedDocs, completionFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, unwindFallback, shouldUnwind, _c, _d, fallbackPipeline, fallbackAggregate, fallbackDocs, nameFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, _e, _loop_1, i, state_1, matchFields_1, _f, aliases, rewrittenPipeline, fallbackAggregate, fallbackDocs, _loop_2, i, state_2, nestedFallbacks, nestedFallbacks_1, nestedFallbacks_1_1, nestedFallback, fallbackPayload, fallbackResult, existingFallbacks, error_7, errorMessage, existingErrors, e_2_1, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, fallbackAcceptanceOptions, crossCollectionCandidates, crossCollectionCandidates_2, crossCollectionCandidates_2_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, fallbackQuality, existingFallbacks, rejectedQuality, error_8, existingErrors, e_3_1, matchStages, diagnostics, combinedMatch, nameFields, dateFields, countOptions, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, verification, _o, sanitizedDocuments, includeIds, displayDocs, idLookupDisplay, display;
|
|
3955
|
+
var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, requestHints, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasAggregateRuntimeBudget, resolveAggregateMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, executedPipeline, dateField, buildAggregateOptions, buildAggregateCountOptions, runAggregateWithRepair, initialAggregate, documents, probeDocs, fallback, fallbackPipeline, fallbackAggregate, fallbackDocs, createdFallback, createdPipeline, createdAggregate, createdDocs, expanded, expandedAggregate, expandedDocs, completionFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, unwindFallback, shouldUnwind, _c, _d, fallbackPipeline, fallbackAggregate, fallbackDocs, nameFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, _e, _loop_1, i, state_1, matchFields_1, _f, aliases, rewrittenPipeline, fallbackAggregate, fallbackDocs, _loop_2, i, state_2, nestedFallbacks, nestedFallbacks_1, nestedFallbacks_1_1, nestedFallback, fallbackPayload, fallbackResult, existingFallbacks, error_7, errorMessage, existingErrors, e_2_1, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, fallbackAcceptanceOptions, crossCollectionCandidates, crossCollectionCandidates_2, crossCollectionCandidates_2_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, fallbackQuality, existingFallbacks, rejectedQuality, error_8, existingErrors, e_3_1, matchStages, diagnostics, combinedMatch, nameFields, dateFields, countOptions, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, verification, _o, sanitizedDocuments, includeIds, displayDocs, idLookupDisplay, display;
|
|
3759
3956
|
var e_2, _p, e_3, _q;
|
|
3760
3957
|
var _this = this;
|
|
3761
3958
|
var _r, _s;
|
|
@@ -3798,6 +3995,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3798
3995
|
throw new Error('AI assistant report builder bridge: Access denied.');
|
|
3799
3996
|
}
|
|
3800
3997
|
customerId = normalizeOptionalString((_r = user === null || user === void 0 ? void 0 : user.other) === null || _r === void 0 ? void 0 : _r.id_customer);
|
|
3998
|
+
requestHints = normalizeAssistantDirectiveHints(input.__assistantHints);
|
|
3801
3999
|
fallbackMeta = {};
|
|
3802
4000
|
runtimeControl = normalizeAssistantRuntimeControl(input.__assistantRuntime);
|
|
3803
4001
|
runtimeFastMode = (runtimeControl === null || runtimeControl === void 0 ? void 0 : runtimeControl.fastMode) === undefined
|
|
@@ -3824,6 +4022,8 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3824
4022
|
fallbackMeta.reportBuilderBridge = {
|
|
3825
4023
|
from: bridgeCollection.fallbackFrom,
|
|
3826
4024
|
to: collection,
|
|
4025
|
+
mode: bridgeCollection.mode,
|
|
4026
|
+
resolutionPath: bridgeCollection.resolutionPath,
|
|
3827
4027
|
used: true
|
|
3828
4028
|
};
|
|
3829
4029
|
fallbackMeta.permissionFallback = {
|
|
@@ -4693,7 +4893,11 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4693
4893
|
includeGroupFromId: false
|
|
4694
4894
|
});
|
|
4695
4895
|
return [2 /*return*/, __assign(__assign({ documents: sanitizedDocuments, display: display }, (verification ? { verification: verification } : {})), (canViewDebug ? {
|
|
4696
|
-
debug: __assign(__assign({ collection: collection, collectionRequested: rawCollection, collectionResolved: collection, collectionMatched: collectionResolution.matched, collectionCandidates: collectionResolution.candidates, collectionScore: collectionResolution.score, bridge: 'report-builder'
|
|
4896
|
+
debug: __assign(__assign(__assign({ collection: collection, collectionRequested: rawCollection, collectionResolved: collection, collectionMatched: collectionResolution.matched, collectionCandidates: collectionResolution.candidates, collectionScore: collectionResolution.score, bridge: bridgeCollection.mode === 'report-builder' ? 'report-builder' : 'direct-mongo', bridgeResolution: {
|
|
4897
|
+
mode: bridgeCollection.mode,
|
|
4898
|
+
fallbackFrom: bridgeCollection.fallbackFrom || undefined,
|
|
4899
|
+
path: bridgeCollection.resolutionPath
|
|
4900
|
+
}, database: dbName, query: scopedQuery, options: normalizedOptions.aggregateOptions, originalPipeline: limitedPipeline, executedPipeline: executedPipeline }, (requestHints ? { requestHints: requestHints } : {})), (verification ? { verification: verification } : {})), { fallbacks: fallbackMeta })
|
|
4697
4901
|
} : {}))];
|
|
4698
4902
|
}
|
|
4699
4903
|
});
|
|
@@ -5349,7 +5553,38 @@ function isAssistantExecutableDirective(directive) {
|
|
|
5349
5553
|
}
|
|
5350
5554
|
return true;
|
|
5351
5555
|
}
|
|
5352
|
-
function
|
|
5556
|
+
function normalizeAssistantDirectiveHints(hints) {
|
|
5557
|
+
if (!hints || typeof hints !== 'object') {
|
|
5558
|
+
return undefined;
|
|
5559
|
+
}
|
|
5560
|
+
var normalize = function (values, max) {
|
|
5561
|
+
if (!Array.isArray(values) || !max) {
|
|
5562
|
+
return [];
|
|
5563
|
+
}
|
|
5564
|
+
return mergeAssistantHintValues(values
|
|
5565
|
+
.map(function (value) { return normalizeOptionalString(value); })
|
|
5566
|
+
.filter(Boolean)).slice(0, max);
|
|
5567
|
+
};
|
|
5568
|
+
var normalized = {};
|
|
5569
|
+
var collectionHints = normalize(hints.collectionHints, 8);
|
|
5570
|
+
var rankedCollections = normalize(hints.rankedCollections, 8);
|
|
5571
|
+
var fieldHints = normalize(hints.fieldHints, 12);
|
|
5572
|
+
var schemaHints = normalize(hints.schemaHints, 8);
|
|
5573
|
+
if (collectionHints.length) {
|
|
5574
|
+
normalized.collectionHints = collectionHints;
|
|
5575
|
+
}
|
|
5576
|
+
if (rankedCollections.length) {
|
|
5577
|
+
normalized.rankedCollections = rankedCollections;
|
|
5578
|
+
}
|
|
5579
|
+
if (fieldHints.length) {
|
|
5580
|
+
normalized.fieldHints = fieldHints;
|
|
5581
|
+
}
|
|
5582
|
+
if (schemaHints.length) {
|
|
5583
|
+
normalized.schemaHints = schemaHints;
|
|
5584
|
+
}
|
|
5585
|
+
return Object.keys(normalized).length ? normalized : undefined;
|
|
5586
|
+
}
|
|
5587
|
+
function buildAssistantToolRequest(directive, payload, hints) {
|
|
5353
5588
|
var base = directive.payload && typeof directive.payload === 'object' ? directive.payload : {};
|
|
5354
5589
|
var request = __assign({}, base);
|
|
5355
5590
|
if (!request.permissionView) {
|
|
@@ -5365,6 +5600,10 @@ function buildAssistantToolRequest(directive, payload) {
|
|
|
5365
5600
|
if (!request.mongo && (payload === null || payload === void 0 ? void 0 : payload.mongo)) {
|
|
5366
5601
|
request.mongo = payload.mongo;
|
|
5367
5602
|
}
|
|
5603
|
+
var normalizedHints = normalizeAssistantDirectiveHints(hints);
|
|
5604
|
+
if (normalizedHints) {
|
|
5605
|
+
request.__assistantHints = normalizedHints;
|
|
5606
|
+
}
|
|
5368
5607
|
if (directive.type === 'aggregate' && !request.__assistantMessage) {
|
|
5369
5608
|
var message = normalizeOptionalString(payload === null || payload === void 0 ? void 0 : payload.message);
|
|
5370
5609
|
if (message) {
|
|
@@ -5373,6 +5612,180 @@ function buildAssistantToolRequest(directive, payload) {
|
|
|
5373
5612
|
}
|
|
5374
5613
|
return request;
|
|
5375
5614
|
}
|
|
5615
|
+
function buildAssistantProbeDirective(directive) {
|
|
5616
|
+
if (!(directive === null || directive === void 0 ? void 0 : directive.payload) || typeof directive.payload !== 'object') {
|
|
5617
|
+
return null;
|
|
5618
|
+
}
|
|
5619
|
+
var payload = (0, common_1.deepCopy)(directive.payload);
|
|
5620
|
+
if (directive.type === 'read') {
|
|
5621
|
+
var options = payload.options && typeof payload.options === 'object'
|
|
5622
|
+
? __assign({}, payload.options) : {};
|
|
5623
|
+
var requestedLimit = normalizeOptionalNumber(options.limit);
|
|
5624
|
+
options.limit = Math.max(1, Math.min(requestedLimit || AI_ASSISTANT_PROBE_LIMIT, AI_ASSISTANT_PROBE_LIMIT));
|
|
5625
|
+
delete options.includeTotal;
|
|
5626
|
+
delete options.export;
|
|
5627
|
+
payload.options = options;
|
|
5628
|
+
payload.query = {};
|
|
5629
|
+
}
|
|
5630
|
+
else if (directive.type === 'aggregate') {
|
|
5631
|
+
var options = payload.options && typeof payload.options === 'object'
|
|
5632
|
+
? __assign({}, payload.options) : {};
|
|
5633
|
+
var requestedLimit = normalizeOptionalNumber(options.limit);
|
|
5634
|
+
options.limit = Math.max(1, Math.min(requestedLimit || AI_ASSISTANT_PROBE_LIMIT, AI_ASSISTANT_PROBE_LIMIT));
|
|
5635
|
+
delete options.export;
|
|
5636
|
+
payload.options = options;
|
|
5637
|
+
}
|
|
5638
|
+
else {
|
|
5639
|
+
return null;
|
|
5640
|
+
}
|
|
5641
|
+
return __assign(__assign({}, directive), { payload: payload, rawLine: "".concat(normalizeOptionalString(directive.rawLine) || 'DIRECTIVE', " [probe]") });
|
|
5642
|
+
}
|
|
5643
|
+
function resolveAssistantProbeFieldHints(docs) {
|
|
5644
|
+
var rows = Array.isArray(docs) ? docs.slice(0, 3) : [];
|
|
5645
|
+
if (!rows.length) {
|
|
5646
|
+
return [];
|
|
5647
|
+
}
|
|
5648
|
+
var fields = [];
|
|
5649
|
+
var seen = new Set();
|
|
5650
|
+
var pushField = function (value) {
|
|
5651
|
+
var normalized = normalizeLookupPath(value) || normalizeOptionalString(value);
|
|
5652
|
+
if (!normalized || seen.has(normalized) || shouldRedactField(normalized)) {
|
|
5653
|
+
return;
|
|
5654
|
+
}
|
|
5655
|
+
seen.add(normalized);
|
|
5656
|
+
fields.push(normalized);
|
|
5657
|
+
};
|
|
5658
|
+
rows.forEach(function (doc) {
|
|
5659
|
+
if (!doc || typeof doc !== 'object' || Array.isArray(doc)) {
|
|
5660
|
+
return;
|
|
5661
|
+
}
|
|
5662
|
+
Object.keys(doc).forEach(function (key) {
|
|
5663
|
+
pushField(key);
|
|
5664
|
+
var nested = doc[key];
|
|
5665
|
+
if (!nested || typeof nested !== 'object' || Array.isArray(nested) || nested instanceof Date) {
|
|
5666
|
+
return;
|
|
5667
|
+
}
|
|
5668
|
+
Object.keys(nested).forEach(function (nestedKey) {
|
|
5669
|
+
pushField("".concat(key, ".").concat(nestedKey));
|
|
5670
|
+
});
|
|
5671
|
+
});
|
|
5672
|
+
});
|
|
5673
|
+
return fields.slice(0, 12);
|
|
5674
|
+
}
|
|
5675
|
+
function applyAssistantSortFieldAliases(sort, aliases) {
|
|
5676
|
+
if (!sort || typeof sort !== 'object' || !Object.keys(aliases || {}).length) {
|
|
5677
|
+
return sort;
|
|
5678
|
+
}
|
|
5679
|
+
var next = {};
|
|
5680
|
+
Object.keys(sort).forEach(function (key) {
|
|
5681
|
+
var mappedKey = normalizeOptionalString(aliases[key]) || key;
|
|
5682
|
+
if (Object.prototype.hasOwnProperty.call(next, mappedKey)) {
|
|
5683
|
+
return;
|
|
5684
|
+
}
|
|
5685
|
+
next[mappedKey] = sort[key];
|
|
5686
|
+
});
|
|
5687
|
+
return next;
|
|
5688
|
+
}
|
|
5689
|
+
function rewriteAssistantDirectiveWithProbe(directive, probeResponse) {
|
|
5690
|
+
var _a, _b;
|
|
5691
|
+
if (!(directive === null || directive === void 0 ? void 0 : directive.payload) || typeof directive.payload !== 'object') {
|
|
5692
|
+
return {
|
|
5693
|
+
directive: directive,
|
|
5694
|
+
notes: [],
|
|
5695
|
+
fieldHints: []
|
|
5696
|
+
};
|
|
5697
|
+
}
|
|
5698
|
+
var payload = (0, common_1.deepCopy)(directive.payload);
|
|
5699
|
+
var notes = [];
|
|
5700
|
+
var resolvedCollection = normalizeOptionalString(((_a = probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.debug) === null || _a === void 0 ? void 0 : _a.collectionResolved)
|
|
5701
|
+
|| ((_b = probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.debug) === null || _b === void 0 ? void 0 : _b.collection));
|
|
5702
|
+
if (resolvedCollection && resolvedCollection !== normalizeOptionalString(payload.collection)) {
|
|
5703
|
+
payload.collection = resolvedCollection;
|
|
5704
|
+
notes.push("collection:".concat(resolvedCollection));
|
|
5705
|
+
}
|
|
5706
|
+
var probeDocs = Array.isArray(probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.documents) ? probeResponse.documents : [];
|
|
5707
|
+
var probeFieldHints = resolveAssistantProbeFieldHints(probeDocs);
|
|
5708
|
+
if (directive.type !== 'read' || !probeDocs.length) {
|
|
5709
|
+
return {
|
|
5710
|
+
directive: __assign(__assign({}, directive), { payload: payload }),
|
|
5711
|
+
notes: notes,
|
|
5712
|
+
fieldHints: probeFieldHints
|
|
5713
|
+
};
|
|
5714
|
+
}
|
|
5715
|
+
var schemaFields = getCollectionSchemaFieldNames(normalizeOptionalString(payload.collection) || resolvedCollection);
|
|
5716
|
+
var options = payload.options && typeof payload.options === 'object'
|
|
5717
|
+
? __assign({}, payload.options) : {};
|
|
5718
|
+
if (payload.query && typeof payload.query === 'object') {
|
|
5719
|
+
var queryFields = extractQueryFieldPaths(payload.query).filter(function (field) { return !isAssistantIdField(field); });
|
|
5720
|
+
if (queryFields.length) {
|
|
5721
|
+
var queryAliases = resolveFieldAliases(probeDocs, queryFields, schemaFields);
|
|
5722
|
+
if (Object.keys(queryAliases).length) {
|
|
5723
|
+
Object.entries(queryAliases).forEach(function (_a) {
|
|
5724
|
+
var _b = __read(_a, 2), from = _b[0], to = _b[1];
|
|
5725
|
+
payload.query = replaceFieldPathDeep(payload.query, from, to);
|
|
5726
|
+
});
|
|
5727
|
+
notes.push("query_aliases:".concat(Object.keys(queryAliases).length));
|
|
5728
|
+
options.sort = applyAssistantSortFieldAliases(options.sort, queryAliases) || options.sort;
|
|
5729
|
+
}
|
|
5730
|
+
}
|
|
5731
|
+
}
|
|
5732
|
+
if (options.projection && typeof options.projection === 'object') {
|
|
5733
|
+
var projectionFields = resolveProjectionRequestedFields(options.projection);
|
|
5734
|
+
if (projectionFields.length) {
|
|
5735
|
+
var projectionAliases = resolveFieldAliases(probeDocs, projectionFields, schemaFields);
|
|
5736
|
+
if (Object.keys(projectionAliases).length) {
|
|
5737
|
+
var expandedProjection = expandProjectionWithAliases(options.projection, projectionAliases);
|
|
5738
|
+
if (expandedProjection && expandedProjection !== options.projection) {
|
|
5739
|
+
options.projection = expandedProjection;
|
|
5740
|
+
notes.push("projection_aliases:".concat(Object.keys(projectionAliases).length));
|
|
5741
|
+
}
|
|
5742
|
+
}
|
|
5743
|
+
}
|
|
5744
|
+
}
|
|
5745
|
+
payload.options = options;
|
|
5746
|
+
return {
|
|
5747
|
+
directive: __assign(__assign({}, directive), { payload: payload }),
|
|
5748
|
+
notes: notes,
|
|
5749
|
+
fieldHints: probeFieldHints
|
|
5750
|
+
};
|
|
5751
|
+
}
|
|
5752
|
+
function buildAssistantToolExecutionTelemetrySnapshot(telemetry) {
|
|
5753
|
+
var probe = (telemetry === null || telemetry === void 0 ? void 0 : telemetry.probe) || null;
|
|
5754
|
+
var final = (telemetry === null || telemetry === void 0 ? void 0 : telemetry.final) || null;
|
|
5755
|
+
return {
|
|
5756
|
+
mode: (telemetry === null || telemetry === void 0 ? void 0 : telemetry.mode) || 'single_step',
|
|
5757
|
+
always_allow_probe: (telemetry === null || telemetry === void 0 ? void 0 : telemetry.alwaysAllowProbe) === true,
|
|
5758
|
+
permission_denied: (telemetry === null || telemetry === void 0 ? void 0 : telemetry.permissionDenied) === true ? true : undefined,
|
|
5759
|
+
probe: probe ? {
|
|
5760
|
+
attempted: probe.attempted === true,
|
|
5761
|
+
succeeded: probe.succeeded === true ? true : undefined,
|
|
5762
|
+
failed: probe.failed === true ? true : undefined,
|
|
5763
|
+
skipped_reason: normalizeOptionalString(probe.skippedReason) || undefined,
|
|
5764
|
+
row_count: typeof probe.rowCount === 'number' ? probe.rowCount : undefined,
|
|
5765
|
+
duration_ms: typeof probe.durationMs === 'number' ? probe.durationMs : undefined,
|
|
5766
|
+
rewrites_applied: probe.rewritesApplied === true ? true : undefined,
|
|
5767
|
+
rewrite_notes: Array.isArray(probe.rewriteNotes) && probe.rewriteNotes.length ? probe.rewriteNotes : undefined,
|
|
5768
|
+
field_hints_added: typeof probe.fieldHintsAdded === 'number' ? probe.fieldHintsAdded : undefined,
|
|
5769
|
+
error: normalizeOptionalString(probe.error) || undefined
|
|
5770
|
+
} : undefined,
|
|
5771
|
+
final: final ? {
|
|
5772
|
+
attempted: final.attempted === true,
|
|
5773
|
+
succeeded: final.succeeded === true ? true : undefined,
|
|
5774
|
+
failed: final.failed === true ? true : undefined,
|
|
5775
|
+
skipped_reason: normalizeOptionalString(final.skippedReason) || undefined,
|
|
5776
|
+
row_count: typeof final.rowCount === 'number' ? final.rowCount : undefined,
|
|
5777
|
+
total: typeof final.total === 'number' ? final.total : undefined,
|
|
5778
|
+
duration_ms: typeof final.durationMs === 'number' ? final.durationMs : undefined,
|
|
5779
|
+
tool_type: normalizeOptionalString(final.toolType) || undefined,
|
|
5780
|
+
collection: normalizeOptionalString(final.collection) || undefined,
|
|
5781
|
+
error: normalizeOptionalString(final.error) || undefined
|
|
5782
|
+
} : undefined,
|
|
5783
|
+
outcome: (telemetry === null || telemetry === void 0 ? void 0 : telemetry.outcome) ? {
|
|
5784
|
+
zero_rows: telemetry.outcome.zeroRows === true ? true : undefined,
|
|
5785
|
+
error: normalizeOptionalString(telemetry.outcome.error) || undefined
|
|
5786
|
+
} : undefined
|
|
5787
|
+
};
|
|
5788
|
+
}
|
|
5376
5789
|
function buildAssistantTrimmedStringExpr(value) {
|
|
5377
5790
|
return {
|
|
5378
5791
|
$trim: {
|
|
@@ -7815,7 +8228,22 @@ function buildAssistantDebugPayload(params) {
|
|
|
7815
8228
|
if ((_v = fallbackInfo === null || fallbackInfo === void 0 ? void 0 : fallbackInfo.reportBuilderBridge) === null || _v === void 0 ? void 0 : _v.used) {
|
|
7816
8229
|
var from = fallbackInfo.reportBuilderBridge.from || 'unknown';
|
|
7817
8230
|
var to = fallbackInfo.reportBuilderBridge.to || 'unknown';
|
|
7818
|
-
|
|
8231
|
+
var mode = normalizeOptionalString(fallbackInfo.reportBuilderBridge.mode);
|
|
8232
|
+
if (mode === 'direct-mongo') {
|
|
8233
|
+
notes.push("Report builder bridge direct fallback: ".concat(from, " -> ").concat(to, "."));
|
|
8234
|
+
}
|
|
8235
|
+
else {
|
|
8236
|
+
notes.push("Report builder bridge collection: ".concat(from, " -> ").concat(to, "."));
|
|
8237
|
+
}
|
|
8238
|
+
var path_1 = Array.isArray(fallbackInfo.reportBuilderBridge.resolutionPath)
|
|
8239
|
+
? fallbackInfo.reportBuilderBridge.resolutionPath
|
|
8240
|
+
.map(function (entry) { return normalizeOptionalString(entry); })
|
|
8241
|
+
.filter(Boolean)
|
|
8242
|
+
.join(' -> ')
|
|
8243
|
+
: '';
|
|
8244
|
+
if (path_1) {
|
|
8245
|
+
notes.push("Bridge resolution path: ".concat(path_1, "."));
|
|
8246
|
+
}
|
|
7819
8247
|
}
|
|
7820
8248
|
if ((_w = fallbackInfo === null || fallbackInfo === void 0 ? void 0 : fallbackInfo.reportFallback) === null || _w === void 0 ? void 0 : _w.used) {
|
|
7821
8249
|
var from = fallbackInfo.reportFallback.from || 'report';
|
|
@@ -7903,6 +8331,7 @@ function buildAssistantDebugPayload(params) {
|
|
|
7903
8331
|
pipeline: ((_6 = params.toolResponseDebug) === null || _6 === void 0 ? void 0 : _6.executedPipeline) || ((_7 = params.toolResponseDebug) === null || _7 === void 0 ? void 0 : _7.originalPipeline) || undefined,
|
|
7904
8332
|
options: ((_8 = params.toolResponseDebug) === null || _8 === void 0 ? void 0 : _8.options) || undefined,
|
|
7905
8333
|
fallbacks: ((_9 = params.toolResponseDebug) === null || _9 === void 0 ? void 0 : _9.fallbacks) || undefined,
|
|
8334
|
+
toolExecution: params.toolExecution || undefined,
|
|
7906
8335
|
notes: notes
|
|
7907
8336
|
};
|
|
7908
8337
|
if (params.trace && typeof params.trace === 'object') {
|
|
@@ -16139,7 +16568,7 @@ function doesAssistantCollectionExistInDb(db, collection) {
|
|
|
16139
16568
|
}
|
|
16140
16569
|
function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
16141
16570
|
return __awaiter(this, arguments, void 0, function (collection, db, dbName) {
|
|
16142
|
-
var normalized, aliasCandidates, alias, manager, hasManager, candidates, pushCandidate, base, reportCandidate, candidates_5, candidates_5_1, candidate, model, resolved, resolvedName, resolvedModel, _a, candidates_6, candidates_6_1, candidate, e_37_1, candidates_7, candidates_7_1, candidate;
|
|
16571
|
+
var normalized, resolutionPath, pushResolutionStep, finalizeResolution, aliasCandidates, alias, manager, hasManager, candidates, pushCandidate, base, reportCandidate, candidates_5, candidates_5_1, candidate, model, resolved, resolvedName, resolvedModel, _a, candidates_6, candidates_6_1, candidate, e_37_1, candidates_7, candidates_7_1, candidate;
|
|
16143
16572
|
var e_38, _b, e_37, _c, e_39, _d;
|
|
16144
16573
|
var _e;
|
|
16145
16574
|
if (dbName === void 0) { dbName = ''; }
|
|
@@ -16150,7 +16579,23 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
16150
16579
|
if (!normalized) {
|
|
16151
16580
|
throw new Error('AI assistant report builder bridge: Collection is required.');
|
|
16152
16581
|
}
|
|
16582
|
+
resolutionPath = [];
|
|
16583
|
+
pushResolutionStep = function (value) {
|
|
16584
|
+
var step = normalizeOptionalString(value);
|
|
16585
|
+
if (!step || resolutionPath.includes(step)) {
|
|
16586
|
+
return;
|
|
16587
|
+
}
|
|
16588
|
+
resolutionPath.push(step);
|
|
16589
|
+
};
|
|
16590
|
+
finalizeResolution = function (resolvedCollection, mode, reason) {
|
|
16591
|
+
pushResolutionStep(reason);
|
|
16592
|
+
return __assign(__assign({ collection: resolvedCollection }, (resolvedCollection !== normalized ? { fallbackFrom: normalized } : {})), { mode: mode, resolutionPath: resolutionPath.slice(0, 10) });
|
|
16593
|
+
};
|
|
16594
|
+
pushResolutionStep("requested:".concat(normalized));
|
|
16153
16595
|
aliasCandidates = resolveAssistantBridgeCollectionAliasCandidates(normalized);
|
|
16596
|
+
if (aliasCandidates.length) {
|
|
16597
|
+
pushResolutionStep("aliases:".concat(aliasCandidates.join(',')));
|
|
16598
|
+
}
|
|
16154
16599
|
alias = aliasCandidates[0] || '';
|
|
16155
16600
|
manager = (_e = resolveio_server_app_1.ResolveIOServer.getMongoManager) === null || _e === void 0 ? void 0 : _e.call(resolveio_server_app_1.ResolveIOServer);
|
|
16156
16601
|
hasManager = !!(manager && typeof manager.collection === 'function');
|
|
@@ -16178,7 +16623,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
16178
16623
|
candidate = candidates_5_1.value;
|
|
16179
16624
|
model = manager.collection(candidate);
|
|
16180
16625
|
if (model === null || model === void 0 ? void 0 : model.useRB) {
|
|
16181
|
-
return [2 /*return*/,
|
|
16626
|
+
return [2 /*return*/, finalizeResolution(candidate, 'report-builder', "manager.useRB:".concat(candidate))];
|
|
16182
16627
|
}
|
|
16183
16628
|
}
|
|
16184
16629
|
}
|
|
@@ -16200,14 +16645,19 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
16200
16645
|
resolvedName = normalizeOptionalString(resolved === null || resolved === void 0 ? void 0 : resolved.name);
|
|
16201
16646
|
if (resolvedName) {
|
|
16202
16647
|
pushCandidate(resolvedName);
|
|
16648
|
+
pushResolutionStep("resolver:".concat(resolvedName));
|
|
16203
16649
|
resolvedModel = hasManager ? manager.collection(resolvedName) : null;
|
|
16204
|
-
if (
|
|
16205
|
-
return [2 /*return*/,
|
|
16650
|
+
if (resolvedModel === null || resolvedModel === void 0 ? void 0 : resolvedModel.useRB) {
|
|
16651
|
+
return [2 /*return*/, finalizeResolution(resolvedName, 'report-builder', "resolver.useRB:".concat(resolvedName))];
|
|
16652
|
+
}
|
|
16653
|
+
if (isAssistantDirectCollectionFallbackAllowed(resolvedName)) {
|
|
16654
|
+
return [2 /*return*/, finalizeResolution(resolvedName, 'direct-mongo', "allowlist:".concat(resolvedName))];
|
|
16206
16655
|
}
|
|
16207
16656
|
}
|
|
16208
16657
|
return [3 /*break*/, 4];
|
|
16209
16658
|
case 3:
|
|
16210
16659
|
_a = _f.sent();
|
|
16660
|
+
pushResolutionStep('resolver:error');
|
|
16211
16661
|
return [3 /*break*/, 4];
|
|
16212
16662
|
case 4:
|
|
16213
16663
|
if (!db) return [3 /*break*/, 12];
|
|
@@ -16225,7 +16675,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
16225
16675
|
return [4 /*yield*/, doesAssistantCollectionExistInDb(db, candidate)];
|
|
16226
16676
|
case 7:
|
|
16227
16677
|
if (_f.sent()) {
|
|
16228
|
-
return [2 /*return*/,
|
|
16678
|
+
return [2 /*return*/, finalizeResolution(candidate, 'direct-mongo', "db.exists:".concat(candidate))];
|
|
16229
16679
|
}
|
|
16230
16680
|
_f.label = 8;
|
|
16231
16681
|
case 8:
|
|
@@ -16247,7 +16697,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
16247
16697
|
for (candidates_7 = __values(candidates), candidates_7_1 = candidates_7.next(); !candidates_7_1.done; candidates_7_1 = candidates_7.next()) {
|
|
16248
16698
|
candidate = candidates_7_1.value;
|
|
16249
16699
|
if (isAssistantDirectCollectionFallbackAllowed(candidate)) {
|
|
16250
|
-
return [2 /*return*/,
|
|
16700
|
+
return [2 /*return*/, finalizeResolution(candidate, 'direct-mongo', "allowlist:".concat(candidate))];
|
|
16251
16701
|
}
|
|
16252
16702
|
}
|
|
16253
16703
|
}
|
|
@@ -16987,6 +17437,17 @@ function resolveAssistantFastModeEnabled(config) {
|
|
|
16987
17437
|
|| process.env.AI_ASSISTANT_FAST_MODE_ENABLED);
|
|
16988
17438
|
return raw === undefined ? false : raw === true;
|
|
16989
17439
|
}
|
|
17440
|
+
function resolveAssistantAlwaysAllowProbeEnabled(config) {
|
|
17441
|
+
var override = normalizeOptionalBoolean((config === null || config === void 0 ? void 0 : config.always_allow_probe)
|
|
17442
|
+
|| (config === null || config === void 0 ? void 0 : config.alwaysAllowProbe));
|
|
17443
|
+
if (typeof override === 'boolean') {
|
|
17444
|
+
return override;
|
|
17445
|
+
}
|
|
17446
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
17447
|
+
var raw = normalizeOptionalBoolean(serverConfig['AI_ASSISTANT_ALWAYS_ALLOW_PROBE']
|
|
17448
|
+
|| process.env.AI_ASSISTANT_ALWAYS_ALLOW_PROBE);
|
|
17449
|
+
return raw === undefined ? false : raw === true;
|
|
17450
|
+
}
|
|
16990
17451
|
function resolveAssistantRunBudgetMs(config) {
|
|
16991
17452
|
var override = normalizeOptionalNumber((config === null || config === void 0 ? void 0 : config.run_budget_ms)
|
|
16992
17453
|
|| (config === null || config === void 0 ? void 0 : config.runBudgetMs));
|
|
@@ -18413,6 +18874,7 @@ function buildAssistantPlannerPrompt(params) {
|
|
|
18413
18874
|
user_json: JSON.stringify(userSnapshot || {}),
|
|
18414
18875
|
collection_hints_json_array: JSON.stringify(params.collectionHints || []),
|
|
18415
18876
|
field_hints_json_array: JSON.stringify(params.fieldHints || []),
|
|
18877
|
+
schema_hints_json_array: JSON.stringify(params.schemaHints || []),
|
|
18416
18878
|
method_hints_json_array: JSON.stringify(params.methodHints || []),
|
|
18417
18879
|
publication_hints_json_array: JSON.stringify(params.publicationHints || [])
|
|
18418
18880
|
};
|
|
@@ -18465,6 +18927,14 @@ function buildAssistantContext(input, userContext) {
|
|
|
18465
18927
|
lines.push(hint);
|
|
18466
18928
|
});
|
|
18467
18929
|
}
|
|
18930
|
+
var schemaHints = Array.isArray(userContext === null || userContext === void 0 ? void 0 : userContext.schemaHints)
|
|
18931
|
+
? userContext.schemaHints.filter(Boolean)
|
|
18932
|
+
: [];
|
|
18933
|
+
if (schemaHints.length) {
|
|
18934
|
+
schemaHints.forEach(function (hint) {
|
|
18935
|
+
lines.push(hint);
|
|
18936
|
+
});
|
|
18937
|
+
}
|
|
18468
18938
|
var methodHints = Array.isArray(userContext === null || userContext === void 0 ? void 0 : userContext.methodHints)
|
|
18469
18939
|
? userContext.methodHints.filter(Boolean)
|
|
18470
18940
|
: [];
|
|
@@ -18582,6 +19052,68 @@ function buildAssistantFieldHints(message, collectionNames, options) {
|
|
|
18582
19052
|
});
|
|
18583
19053
|
return hints;
|
|
18584
19054
|
}
|
|
19055
|
+
function formatAssistantLookupMappingHint(mapping) {
|
|
19056
|
+
var localKey = normalizeLookupPath((mapping === null || mapping === void 0 ? void 0 : mapping.localKey) || '')
|
|
19057
|
+
|| normalizeOptionalString(mapping === null || mapping === void 0 ? void 0 : mapping.localKey);
|
|
19058
|
+
var lookupCollection = normalizeOptionalString(mapping === null || mapping === void 0 ? void 0 : mapping.lookupCollection);
|
|
19059
|
+
var lookupKey = normalizeLookupPath((mapping === null || mapping === void 0 ? void 0 : mapping.lookupKey) || '')
|
|
19060
|
+
|| normalizeOptionalString(mapping === null || mapping === void 0 ? void 0 : mapping.lookupKey)
|
|
19061
|
+
|| '_id';
|
|
19062
|
+
if (!localKey || !lookupCollection || !lookupKey) {
|
|
19063
|
+
return '';
|
|
19064
|
+
}
|
|
19065
|
+
if (shouldRedactField(localKey) || shouldRedactField(lookupKey)) {
|
|
19066
|
+
return '';
|
|
19067
|
+
}
|
|
19068
|
+
return "".concat(localKey, "->").concat(lookupCollection, ".").concat(lookupKey);
|
|
19069
|
+
}
|
|
19070
|
+
function buildAssistantSchemaHints(collectionNames, options) {
|
|
19071
|
+
if (!Array.isArray(collectionNames) || !collectionNames.length) {
|
|
19072
|
+
return [];
|
|
19073
|
+
}
|
|
19074
|
+
var maxCollections = typeof (options === null || options === void 0 ? void 0 : options.maxCollections) === 'number'
|
|
19075
|
+
? Math.max(options.maxCollections, 0)
|
|
19076
|
+
: AI_ASSISTANT_CONTEXT_MAX_COLLECTIONS;
|
|
19077
|
+
var maxFields = typeof (options === null || options === void 0 ? void 0 : options.maxFields) === 'number'
|
|
19078
|
+
? Math.max(options.maxFields, 0)
|
|
19079
|
+
: AI_ASSISTANT_CONTEXT_MAX_SCHEMA_FIELDS_PER_COLLECTION;
|
|
19080
|
+
var maxLookups = typeof (options === null || options === void 0 ? void 0 : options.maxLookups) === 'number'
|
|
19081
|
+
? Math.max(options.maxLookups, 0)
|
|
19082
|
+
: AI_ASSISTANT_CONTEXT_MAX_LOOKUPS_PER_COLLECTION;
|
|
19083
|
+
if (!maxCollections || (!maxFields && !maxLookups)) {
|
|
19084
|
+
return [];
|
|
19085
|
+
}
|
|
19086
|
+
var hints = [];
|
|
19087
|
+
var candidates = collectionNames.filter(Boolean).slice(0, maxCollections);
|
|
19088
|
+
candidates.forEach(function (collection) {
|
|
19089
|
+
var metadata = getAssistantCollectionMetadata(collection);
|
|
19090
|
+
var fields = Array.isArray(metadata === null || metadata === void 0 ? void 0 : metadata.fields) ? metadata.fields : [];
|
|
19091
|
+
var lookups = Array.isArray(metadata === null || metadata === void 0 ? void 0 : metadata.lookups) ? metadata.lookups : [];
|
|
19092
|
+
var schemaFields = maxFields
|
|
19093
|
+
? fields
|
|
19094
|
+
.map(function (field) { return normalizeLookupPath(field) || normalizeOptionalString(field); })
|
|
19095
|
+
.filter(function (field) { return !!field && !shouldRedactField(field); })
|
|
19096
|
+
.slice(0, maxFields)
|
|
19097
|
+
: [];
|
|
19098
|
+
var lookupMappings = maxLookups
|
|
19099
|
+
? mergeAssistantHintValues(lookups
|
|
19100
|
+
.map(function (mapping) { return formatAssistantLookupMappingHint(mapping); })
|
|
19101
|
+
.filter(Boolean)).slice(0, maxLookups)
|
|
19102
|
+
: [];
|
|
19103
|
+
if (!schemaFields.length && !lookupMappings.length) {
|
|
19104
|
+
return;
|
|
19105
|
+
}
|
|
19106
|
+
var sections = [];
|
|
19107
|
+
if (schemaFields.length) {
|
|
19108
|
+
sections.push("fields: ".concat(schemaFields.join(', ')));
|
|
19109
|
+
}
|
|
19110
|
+
if (lookupMappings.length) {
|
|
19111
|
+
sections.push("report-builder lookups: ".concat(lookupMappings.join(', ')));
|
|
19112
|
+
}
|
|
19113
|
+
hints.push("Schema hints (".concat(collection, "): ").concat(sections.join(' | ')));
|
|
19114
|
+
});
|
|
19115
|
+
return hints;
|
|
19116
|
+
}
|
|
18585
19117
|
var cachedClientRouteIndex = null;
|
|
18586
19118
|
function normalizeRouteKey(value) {
|
|
18587
19119
|
var trimmed = normalizeOptionalString(value);
|