@resolveio/server-lib 22.2.13 → 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 +748 -234
- 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
|
'',
|
|
@@ -1603,7 +1612,7 @@ function executeAiFormPatch(payload, context) {
|
|
|
1603
1612
|
}
|
|
1604
1613
|
function executeAiAssistantCodexRun(payload, context) {
|
|
1605
1614
|
return __awaiter(this, void 0, void 0, function () {
|
|
1606
|
-
var input, message, aiWorkerDebug, requestId, codexModel, codexFallbackModels, user, isSuperAdmin,
|
|
1615
|
+
var input, message, aiWorkerDebug, requestId, codexModel, codexFallbackModels, user, isSuperAdmin, guardrail, conversation_3, now_3, userMsg, assistantMsg, canViewDebug, hasInvoiceAccess, customerId, conversation, now, attachments, navigationFastPath, userMsg, assistantMsg, assistantInsert, assistantMessageId_1, changeHistoryFastPath, changeHistoryFastPathBypassedReason, userMsg, assistantMsg, assistantInsert, assistantMessageId_2, attachmentData, historyLines, recentToolError, userDoc, initialProgress, assistantDoc, insertResult, assistantMessageId;
|
|
1607
1616
|
var _this = this;
|
|
1608
1617
|
var _a, _b, _c;
|
|
1609
1618
|
return __generator(this, function (_d) {
|
|
@@ -1628,8 +1637,6 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1628
1637
|
throw new Error('Unauthorized.');
|
|
1629
1638
|
}
|
|
1630
1639
|
isSuperAdmin = !!((_a = user === null || user === void 0 ? void 0 : user.roles) === null || _a === void 0 ? void 0 : _a.super_admin);
|
|
1631
|
-
guardrailsEnabled = resolveAssistantGuardrailsEnabled(input, isSuperAdmin);
|
|
1632
|
-
if (!guardrailsEnabled) return [3 /*break*/, 6];
|
|
1633
1640
|
guardrail = evaluateAssistantGuardrails(message);
|
|
1634
1641
|
if (!(guardrail === null || guardrail === void 0 ? void 0 : guardrail.blocked)) return [3 /*break*/, 6];
|
|
1635
1642
|
return [4 /*yield*/, ensureConversation(input, 'codex', context === null || context === void 0 ? void 0 : context.id_user)];
|
|
@@ -1817,13 +1824,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1817
1824
|
insertResult = _d.sent();
|
|
1818
1825
|
assistantMessageId = (insertResult === null || insertResult === void 0 ? void 0 : insertResult._id) || (insertResult === null || insertResult === void 0 ? void 0 : insertResult.insertedId);
|
|
1819
1826
|
enqueueAssistantCodexRun(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1820
|
-
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,
|
|
1821
|
-
var
|
|
1822
|
-
return __generator(this, function (
|
|
1823
|
-
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) {
|
|
1824
1831
|
case 0:
|
|
1825
1832
|
runStart = Date.now();
|
|
1826
1833
|
fastModeEnabled = resolveAssistantFastModeEnabled(input.config);
|
|
1834
|
+
alwaysAllowProbeEnabled = resolveAssistantAlwaysAllowProbeEnabled(input.config);
|
|
1827
1835
|
plannerEnabled = resolveAssistantPlannerEnabled(input.config);
|
|
1828
1836
|
runBudgetMs = resolveAssistantRunBudgetMs(input.config);
|
|
1829
1837
|
assistantMongoMaxTimeMs = resolveAssistantMongoDefaultMaxTimeMs(input.config);
|
|
@@ -1836,6 +1844,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1836
1844
|
id_conversation: (conversation === null || conversation === void 0 ? void 0 : conversation._id) || null,
|
|
1837
1845
|
id_message: assistantMessageId ? String(assistantMessageId) : null,
|
|
1838
1846
|
fastModeEnabled: fastModeEnabled,
|
|
1847
|
+
alwaysAllowProbeEnabled: alwaysAllowProbeEnabled,
|
|
1839
1848
|
runBudgetMs: runDeadlineMs ? runBudgetMs : null,
|
|
1840
1849
|
isWorkerInstance: process.env.IS_WORKER_INSTANCE || null,
|
|
1841
1850
|
workerIndex: process.env.WORKER_INDEX || null,
|
|
@@ -1900,9 +1909,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1900
1909
|
datedDirectiveResolved = false;
|
|
1901
1910
|
toolResponseDebug = null;
|
|
1902
1911
|
toolError = null;
|
|
1912
|
+
toolTelemetry = {
|
|
1913
|
+
mode: AI_ASSISTANT_TOOL_MAX_STEPS > 1 ? 'probe_then_final' : 'single_step',
|
|
1914
|
+
alwaysAllowProbe: alwaysAllowProbeEnabled
|
|
1915
|
+
};
|
|
1903
1916
|
termHints = [];
|
|
1904
1917
|
collectionHints = [];
|
|
1905
1918
|
fieldHints = [];
|
|
1919
|
+
schemaHints = [];
|
|
1906
1920
|
methodHints = [];
|
|
1907
1921
|
publicationHints = [];
|
|
1908
1922
|
collectionTokenization = null;
|
|
@@ -1937,8 +1951,8 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1937
1951
|
codexUsage.output_tokens += outputTokens;
|
|
1938
1952
|
codexUsage.total_tokens += inputTokens + outputTokens;
|
|
1939
1953
|
};
|
|
1940
|
-
contextRoute = normalizeOptionalString((
|
|
1941
|
-
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);
|
|
1942
1956
|
recordStep('Queued', { requestId: requestId || undefined });
|
|
1943
1957
|
if (changeHistoryFastPathBypassedReason) {
|
|
1944
1958
|
recordStep('Planning: change-history fast path unavailable', {
|
|
@@ -1950,9 +1964,9 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1950
1964
|
source: requestClassification.source,
|
|
1951
1965
|
dataQuestion: dataQuestion
|
|
1952
1966
|
});
|
|
1953
|
-
|
|
1967
|
+
_22.label = 1;
|
|
1954
1968
|
case 1:
|
|
1955
|
-
|
|
1969
|
+
_22.trys.push([1, 68, 69, 70]);
|
|
1956
1970
|
hintSeed = [message, contextRoute].filter(Boolean).join(' ');
|
|
1957
1971
|
termExpansion = expandAssistantTermSynonyms(hintSeed);
|
|
1958
1972
|
hintText = termExpansion.expanded || hintSeed;
|
|
@@ -1973,19 +1987,19 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1973
1987
|
recordStep('Planning: term expansion', {
|
|
1974
1988
|
termMatches: termExpansion.matches.length ? termExpansion.matches : undefined
|
|
1975
1989
|
});
|
|
1976
|
-
|
|
1990
|
+
_22.label = 2;
|
|
1977
1991
|
case 2:
|
|
1978
|
-
|
|
1992
|
+
_22.trys.push([2, 5, , 6]);
|
|
1979
1993
|
dbName = resolveAssistantDatabaseName(undefined, input.mongo);
|
|
1980
1994
|
db = resolveio_server_app_1.ResolveIOServer.getMongoConnection().db(dbName);
|
|
1981
1995
|
return [4 /*yield*/, listAssistantCollections(db, dbName)];
|
|
1982
1996
|
case 3:
|
|
1983
|
-
collectionNames =
|
|
1997
|
+
collectionNames = _22.sent();
|
|
1984
1998
|
collectionHints = resolveCollectionHintsFromTokens(expandedTokens, collectionNames, 5);
|
|
1985
1999
|
collectionRanking = buildCollectionRankingDebugFromTokens(expandedTokens, collectionNames, 8);
|
|
1986
2000
|
return [4 /*yield*/, resolveAssistantSurfaceHints(hintSeed, contextRoute, collectionNames)];
|
|
1987
2001
|
case 4:
|
|
1988
|
-
surfaceHints =
|
|
2002
|
+
surfaceHints = _22.sent();
|
|
1989
2003
|
methodHints = surfaceHints.methodHints;
|
|
1990
2004
|
publicationHints = surfaceHints.publicationHints;
|
|
1991
2005
|
if (surfaceHints.collectionHints.length) {
|
|
@@ -1993,7 +2007,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1993
2007
|
}
|
|
1994
2008
|
return [3 /*break*/, 6];
|
|
1995
2009
|
case 5:
|
|
1996
|
-
_a =
|
|
2010
|
+
_a = _22.sent();
|
|
1997
2011
|
collectionHints = [];
|
|
1998
2012
|
collectionRanking = collectionRanking || ((collectionTokenization === null || collectionTokenization === void 0 ? void 0 : collectionTokenization.expandedTokens)
|
|
1999
2013
|
? buildCollectionRankingDebugFromTokens(collectionTokenization.expandedTokens || [], [], 0)
|
|
@@ -2025,13 +2039,18 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2025
2039
|
: [];
|
|
2026
2040
|
hintCollections = mergeAssistantHintValues(collectionHints, rankedCollections)
|
|
2027
2041
|
.slice(0, AI_ASSISTANT_CONTEXT_MAX_COLLECTIONS);
|
|
2042
|
+
schemaHintCollections = mergeAssistantHintValues(hintCollections, rankedCollections, collectionHints).slice(0, AI_ASSISTANT_CONTEXT_MAX_SCHEMA_COLLECTIONS);
|
|
2028
2043
|
fieldHints = buildAssistantFieldHints(message, hintCollections);
|
|
2044
|
+
schemaHints = buildAssistantSchemaHints(schemaHintCollections, {
|
|
2045
|
+
maxCollections: AI_ASSISTANT_CONTEXT_MAX_SCHEMA_COLLECTIONS
|
|
2046
|
+
});
|
|
2029
2047
|
recordStep('Planning: collection hints', {
|
|
2030
2048
|
contextRoute: contextRoute || undefined,
|
|
2031
2049
|
contextMode: contextMode || undefined,
|
|
2032
2050
|
collectionHints: collectionHints.length ? collectionHints : undefined,
|
|
2033
2051
|
termHints: termHints.length ? termHints : undefined,
|
|
2034
2052
|
fieldHints: fieldHints.length ? fieldHints : undefined,
|
|
2053
|
+
schemaHints: schemaHints.length ? schemaHints : undefined,
|
|
2035
2054
|
methodHints: methodHints.length ? methodHints : undefined,
|
|
2036
2055
|
publicationHints: publicationHints.length ? publicationHints : undefined
|
|
2037
2056
|
});
|
|
@@ -2042,6 +2061,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2042
2061
|
collectionHints: collectionHints,
|
|
2043
2062
|
termHints: termHints,
|
|
2044
2063
|
fieldHints: fieldHints,
|
|
2064
|
+
schemaHints: schemaHints,
|
|
2045
2065
|
methodHints: methodHints,
|
|
2046
2066
|
publicationHints: publicationHints,
|
|
2047
2067
|
recentToolError: recentToolError,
|
|
@@ -2056,14 +2076,14 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2056
2076
|
if (hasDeterministicHeuristicFastPath) {
|
|
2057
2077
|
recordStep('Planning: heuristic directive fast path', {
|
|
2058
2078
|
type: heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.type,
|
|
2059
|
-
collection: normalizeOptionalString((
|
|
2079
|
+
collection: normalizeOptionalString((_p = heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.payload) === null || _p === void 0 ? void 0 : _p.collection) || undefined,
|
|
2060
2080
|
heuristic: normalizeOptionalString(heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.rawLine) || undefined
|
|
2061
2081
|
});
|
|
2062
2082
|
}
|
|
2063
2083
|
prompt_1 = buildAssistantCodexPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, assistantSystemPrompt);
|
|
2064
2084
|
return [4 /*yield*/, resolveAssistantWorkspaceRoot()];
|
|
2065
2085
|
case 7:
|
|
2066
|
-
workspaceRoot =
|
|
2086
|
+
workspaceRoot = _22.sent();
|
|
2067
2087
|
codexConfig = resolveCodexSettings({
|
|
2068
2088
|
model: codexModel,
|
|
2069
2089
|
fallbackModels: codexFallbackModels
|
|
@@ -2107,24 +2127,25 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2107
2127
|
user: user,
|
|
2108
2128
|
collectionHints: collectionHints,
|
|
2109
2129
|
fieldHints: fieldHints,
|
|
2130
|
+
schemaHints: schemaHints,
|
|
2110
2131
|
methodHints: methodHints,
|
|
2111
2132
|
publicationHints: publicationHints,
|
|
2112
2133
|
inputClientId: input.id_client
|
|
2113
2134
|
});
|
|
2114
|
-
|
|
2135
|
+
_22.label = 8;
|
|
2115
2136
|
case 8:
|
|
2116
|
-
|
|
2137
|
+
_22.trys.push([8, 10, , 11]);
|
|
2117
2138
|
plannerStart = Date.now();
|
|
2118
2139
|
return [4 /*yield*/, runCodexInWorkerThread(plannerPrompt, applyCodexStageBudget(plannerRunOptions), codexConfig, streamProgress)];
|
|
2119
2140
|
case 9:
|
|
2120
|
-
plannerRaw =
|
|
2141
|
+
plannerRaw = _22.sent();
|
|
2121
2142
|
accumulateCodexUsage(plannerPrompt, plannerRaw);
|
|
2122
2143
|
timingBreakdown.plannerMs = Date.now() - plannerStart;
|
|
2123
2144
|
plannerOutput = parseJsonObject(plannerRaw);
|
|
2124
2145
|
recordStep('Planning: planner result', { parsed: !!plannerOutput });
|
|
2125
2146
|
return [3 /*break*/, 11];
|
|
2126
2147
|
case 10:
|
|
2127
|
-
_b =
|
|
2148
|
+
_b = _22.sent();
|
|
2128
2149
|
recordStep('Planning: planner result', { parsed: false });
|
|
2129
2150
|
return [3 /*break*/, 11];
|
|
2130
2151
|
case 11: return [3 /*break*/, 13];
|
|
@@ -2144,7 +2165,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2144
2165
|
}
|
|
2145
2166
|
recordStep('Planning: planner skipped', { reason: plannerSkipReason });
|
|
2146
2167
|
}
|
|
2147
|
-
|
|
2168
|
+
_22.label = 13;
|
|
2148
2169
|
case 13:
|
|
2149
2170
|
requestClassification = classifyAssistantRequestType(message, plannerOutput || undefined);
|
|
2150
2171
|
dataQuestion = requestClassification.dataQuestion;
|
|
@@ -2186,12 +2207,12 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2186
2207
|
directiveSource = 'forced';
|
|
2187
2208
|
lastDirective = heuristicDirectiveFastPath;
|
|
2188
2209
|
usedDeterministicHeuristicFastPath = true;
|
|
2189
|
-
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) || '');
|
|
2190
2211
|
recordStep('Directive resolved', {
|
|
2191
2212
|
source: directiveSource,
|
|
2192
2213
|
type: directive.type,
|
|
2193
|
-
collection: normalizeOptionalString((
|
|
2194
|
-
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,
|
|
2195
2216
|
reportStyle: 'heuristic_fast_path',
|
|
2196
2217
|
timeGrain: requestedTimeGrain || undefined
|
|
2197
2218
|
});
|
|
@@ -2200,13 +2221,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2200
2221
|
recordStep('Directive: determine tool', { type: 'data-question' });
|
|
2201
2222
|
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode, assistantSystemPrompt);
|
|
2202
2223
|
if (!hasRunBudget('Directive: determine tool')) return [3 /*break*/, 17];
|
|
2203
|
-
|
|
2224
|
+
_22.label = 14;
|
|
2204
2225
|
case 14:
|
|
2205
|
-
|
|
2226
|
+
_22.trys.push([14, 16, , 17]);
|
|
2206
2227
|
directiveStart = Date.now();
|
|
2207
2228
|
return [4 /*yield*/, runCodexInWorkerThread(directivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2208
2229
|
case 15:
|
|
2209
|
-
directiveText =
|
|
2230
|
+
directiveText = _22.sent();
|
|
2210
2231
|
accumulateCodexUsage(directivePrompt, directiveText);
|
|
2211
2232
|
timingBreakdown.directiveMs = Date.now() - directiveStart;
|
|
2212
2233
|
forcedDirective = extractAssistantMongoDirective(directiveText);
|
|
@@ -2214,29 +2235,29 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2214
2235
|
directive = forcedDirective;
|
|
2215
2236
|
directiveSource = 'model';
|
|
2216
2237
|
lastDirective = forcedDirective;
|
|
2217
|
-
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) || '');
|
|
2218
2239
|
recordStep('Directive resolved', {
|
|
2219
2240
|
source: directiveSource,
|
|
2220
2241
|
type: directive.type,
|
|
2221
|
-
collection: normalizeOptionalString((
|
|
2222
|
-
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
|
|
2223
2244
|
});
|
|
2224
2245
|
}
|
|
2225
2246
|
return [3 /*break*/, 17];
|
|
2226
2247
|
case 16:
|
|
2227
|
-
_c =
|
|
2248
|
+
_c = _22.sent();
|
|
2228
2249
|
return [3 /*break*/, 17];
|
|
2229
2250
|
case 17:
|
|
2230
2251
|
if (!(!directive && !dataQuestion)) return [3 /*break*/, 21];
|
|
2231
2252
|
recordStep('Response: draft initial answer', { mode: 'full' });
|
|
2232
2253
|
if (!hasRunBudget('Response: initial draft')) return [3 /*break*/, 21];
|
|
2233
|
-
|
|
2254
|
+
_22.label = 18;
|
|
2234
2255
|
case 18:
|
|
2235
|
-
|
|
2256
|
+
_22.trys.push([18, 20, , 21]);
|
|
2236
2257
|
initialStart = Date.now();
|
|
2237
2258
|
return [4 /*yield*/, runCodexInWorkerThread(prompt_1, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2238
2259
|
case 19:
|
|
2239
|
-
responseText =
|
|
2260
|
+
responseText = _22.sent();
|
|
2240
2261
|
accumulateCodexUsage(prompt_1, responseText);
|
|
2241
2262
|
timingBreakdown.initialResponseMs = Date.now() - initialStart;
|
|
2242
2263
|
extractedDirective = extractAssistantMongoDirective(responseText);
|
|
@@ -2244,17 +2265,17 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2244
2265
|
if (directive) {
|
|
2245
2266
|
directiveSource = 'model';
|
|
2246
2267
|
lastDirective = directive;
|
|
2247
|
-
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) || '');
|
|
2248
2269
|
recordStep('Directive resolved', {
|
|
2249
2270
|
source: directiveSource,
|
|
2250
2271
|
type: directive.type,
|
|
2251
|
-
collection: normalizeOptionalString((
|
|
2252
|
-
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
|
|
2253
2274
|
});
|
|
2254
2275
|
}
|
|
2255
2276
|
return [3 /*break*/, 21];
|
|
2256
2277
|
case 20:
|
|
2257
|
-
error_2 =
|
|
2278
|
+
error_2 = _22.sent();
|
|
2258
2279
|
recordStep('Response: initial draft failed', {
|
|
2259
2280
|
message: normalizeOptionalString(error_2 === null || error_2 === void 0 ? void 0 : error_2.message) || 'Unknown error'
|
|
2260
2281
|
});
|
|
@@ -2264,13 +2285,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2264
2285
|
recordStep('Directive: forced retry', { mode: 'directive-only' });
|
|
2265
2286
|
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode, assistantSystemPrompt);
|
|
2266
2287
|
if (!hasRunBudget('Directive: forced retry')) return [3 /*break*/, 25];
|
|
2267
|
-
|
|
2288
|
+
_22.label = 22;
|
|
2268
2289
|
case 22:
|
|
2269
|
-
|
|
2290
|
+
_22.trys.push([22, 24, , 25]);
|
|
2270
2291
|
forcedStart = Date.now();
|
|
2271
2292
|
return [4 /*yield*/, runCodexInWorkerThread(directivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2272
2293
|
case 23:
|
|
2273
|
-
directiveText =
|
|
2294
|
+
directiveText = _22.sent();
|
|
2274
2295
|
accumulateCodexUsage(directivePrompt, directiveText);
|
|
2275
2296
|
timingBreakdown.forcedDirectiveMs = Date.now() - forcedStart;
|
|
2276
2297
|
forcedDirective = extractAssistantMongoDirective(directiveText);
|
|
@@ -2278,17 +2299,17 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2278
2299
|
directive = forcedDirective;
|
|
2279
2300
|
directiveSource = 'forced';
|
|
2280
2301
|
lastDirective = forcedDirective;
|
|
2281
|
-
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) || '');
|
|
2282
2303
|
recordStep('Directive resolved', {
|
|
2283
2304
|
source: directiveSource,
|
|
2284
2305
|
type: directive.type,
|
|
2285
|
-
collection: normalizeOptionalString((
|
|
2286
|
-
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
|
|
2287
2308
|
});
|
|
2288
2309
|
}
|
|
2289
2310
|
return [3 /*break*/, 25];
|
|
2290
2311
|
case 24:
|
|
2291
|
-
_d =
|
|
2312
|
+
_d = _22.sent();
|
|
2292
2313
|
return [3 /*break*/, 25];
|
|
2293
2314
|
case 25:
|
|
2294
2315
|
if (!(directive
|
|
@@ -2307,13 +2328,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2307
2328
|
strict: true
|
|
2308
2329
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2309
2330
|
if (!hasRunBudget('Directive: dated retry')) return [3 /*break*/, 29];
|
|
2310
|
-
|
|
2331
|
+
_22.label = 26;
|
|
2311
2332
|
case 26:
|
|
2312
|
-
|
|
2333
|
+
_22.trys.push([26, 28, , 29]);
|
|
2313
2334
|
strictStart = Date.now();
|
|
2314
2335
|
return [4 /*yield*/, runCodexInWorkerThread(strictDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2315
2336
|
case 27:
|
|
2316
|
-
strictDirectiveText =
|
|
2337
|
+
strictDirectiveText = _22.sent();
|
|
2317
2338
|
accumulateCodexUsage(strictDirectivePrompt, strictDirectiveText);
|
|
2318
2339
|
timingBreakdown.forcedDirectiveMs += Date.now() - strictStart;
|
|
2319
2340
|
strictDirective = extractAssistantMongoDirective(strictDirectiveText);
|
|
@@ -2324,19 +2345,19 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2324
2345
|
directiveSource = 'forced';
|
|
2325
2346
|
lastDirective = strictDirective;
|
|
2326
2347
|
datedDirectiveRetryUsed = true;
|
|
2327
|
-
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) || '');
|
|
2328
2349
|
recordStep('Directive resolved', {
|
|
2329
2350
|
source: directiveSource,
|
|
2330
2351
|
type: directive.type,
|
|
2331
|
-
collection: normalizeOptionalString((
|
|
2332
|
-
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,
|
|
2333
2354
|
reportStyle: strictDirectiveIsDated ? 'dated' : 'aggregate_fallback',
|
|
2334
2355
|
timeGrain: requestedTimeGrain || undefined
|
|
2335
2356
|
});
|
|
2336
2357
|
}
|
|
2337
2358
|
return [3 /*break*/, 29];
|
|
2338
2359
|
case 28:
|
|
2339
|
-
_e =
|
|
2360
|
+
_e = _22.sent();
|
|
2340
2361
|
return [3 /*break*/, 29];
|
|
2341
2362
|
case 29:
|
|
2342
2363
|
if (!(directive
|
|
@@ -2355,13 +2376,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2355
2376
|
strict: true
|
|
2356
2377
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2357
2378
|
if (!hasRunBudget('Directive: dated guard retry')) return [3 /*break*/, 33];
|
|
2358
|
-
|
|
2379
|
+
_22.label = 30;
|
|
2359
2380
|
case 30:
|
|
2360
|
-
|
|
2381
|
+
_22.trys.push([30, 32, , 33]);
|
|
2361
2382
|
guardStart = Date.now();
|
|
2362
2383
|
return [4 /*yield*/, runCodexInWorkerThread(guardDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2363
2384
|
case 31:
|
|
2364
|
-
guardDirectiveText =
|
|
2385
|
+
guardDirectiveText = _22.sent();
|
|
2365
2386
|
accumulateCodexUsage(guardDirectivePrompt, guardDirectiveText);
|
|
2366
2387
|
timingBreakdown.forcedDirectiveMs += Date.now() - guardStart;
|
|
2367
2388
|
guardDirective = extractAssistantMongoDirective(guardDirectiveText);
|
|
@@ -2370,19 +2391,19 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2370
2391
|
directiveSource = 'forced';
|
|
2371
2392
|
lastDirective = guardDirective;
|
|
2372
2393
|
datedDirectiveRetryUsed = true;
|
|
2373
|
-
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) || '');
|
|
2374
2395
|
recordStep('Directive resolved', {
|
|
2375
2396
|
source: directiveSource,
|
|
2376
2397
|
type: directive.type,
|
|
2377
|
-
collection: normalizeOptionalString((
|
|
2378
|
-
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,
|
|
2379
2400
|
reportStyle: isAssistantDirectiveDated(guardDirective) ? 'dated' : 'aggregate_fallback',
|
|
2380
2401
|
timeGrain: requestedTimeGrain || undefined
|
|
2381
2402
|
});
|
|
2382
2403
|
}
|
|
2383
2404
|
return [3 /*break*/, 33];
|
|
2384
2405
|
case 32:
|
|
2385
|
-
_f =
|
|
2406
|
+
_f = _22.sent();
|
|
2386
2407
|
return [3 /*break*/, 33];
|
|
2387
2408
|
case 33:
|
|
2388
2409
|
if (!(directive
|
|
@@ -2401,13 +2422,13 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2401
2422
|
strict: true
|
|
2402
2423
|
}), 'aggregate_only', assistantSystemPrompt);
|
|
2403
2424
|
if (!hasRunBudget('Directive: grouped guard retry')) return [3 /*break*/, 37];
|
|
2404
|
-
|
|
2425
|
+
_22.label = 34;
|
|
2405
2426
|
case 34:
|
|
2406
|
-
|
|
2427
|
+
_22.trys.push([34, 36, , 37]);
|
|
2407
2428
|
groupedStart = Date.now();
|
|
2408
2429
|
return [4 /*yield*/, runCodexInWorkerThread(groupedDirectivePrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2409
2430
|
case 35:
|
|
2410
|
-
groupedDirectiveText =
|
|
2431
|
+
groupedDirectiveText = _22.sent();
|
|
2411
2432
|
accumulateCodexUsage(groupedDirectivePrompt, groupedDirectiveText);
|
|
2412
2433
|
timingBreakdown.forcedDirectiveMs += Date.now() - groupedStart;
|
|
2413
2434
|
groupedDirective = extractAssistantMongoDirective(groupedDirectiveText);
|
|
@@ -2416,12 +2437,12 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2416
2437
|
directiveSource = 'forced';
|
|
2417
2438
|
lastDirective = groupedDirective;
|
|
2418
2439
|
datedDirectiveRetryUsed = true;
|
|
2419
|
-
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) || '');
|
|
2420
2441
|
recordStep('Directive resolved', {
|
|
2421
2442
|
source: directiveSource,
|
|
2422
2443
|
type: directive.type,
|
|
2423
|
-
collection: normalizeOptionalString((
|
|
2424
|
-
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,
|
|
2425
2446
|
reportStyle: isAssistantDirectiveDated(groupedDirective)
|
|
2426
2447
|
? 'dated'
|
|
2427
2448
|
: 'grouped',
|
|
@@ -2431,7 +2452,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2431
2452
|
}
|
|
2432
2453
|
return [3 /*break*/, 37];
|
|
2433
2454
|
case 36:
|
|
2434
|
-
_g =
|
|
2455
|
+
_g = _22.sent();
|
|
2435
2456
|
return [3 /*break*/, 37];
|
|
2436
2457
|
case 37:
|
|
2437
2458
|
if (!directive && dataQuestion) {
|
|
@@ -2443,21 +2464,21 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2443
2464
|
recordStep('Directive resolved', {
|
|
2444
2465
|
source: directiveSource,
|
|
2445
2466
|
type: directive.type,
|
|
2446
|
-
collection: normalizeOptionalString((
|
|
2447
|
-
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,
|
|
2448
2469
|
reportStyle: 'heuristic_fallback'
|
|
2449
2470
|
});
|
|
2450
2471
|
}
|
|
2451
2472
|
}
|
|
2452
2473
|
if (directive) {
|
|
2453
|
-
requestedCollection = normalizeOptionalString((
|
|
2474
|
+
requestedCollection = normalizeOptionalString((_13 = directive.payload) === null || _13 === void 0 ? void 0 : _13.collection);
|
|
2454
2475
|
allowCollectionOverride = !isAssistantDeterministicHeuristicDirective(directive);
|
|
2455
2476
|
collectionOverride = allowCollectionOverride
|
|
2456
2477
|
? resolveCollectionOverrideWithContext({
|
|
2457
2478
|
message: message,
|
|
2458
2479
|
collectionRanking: collectionRanking,
|
|
2459
2480
|
requestedCollection: requestedCollection,
|
|
2460
|
-
permissionView: normalizeOptionalString((
|
|
2481
|
+
permissionView: normalizeOptionalString((_14 = directive.payload) === null || _14 === void 0 ? void 0 : _14.permissionView) || contextRoute,
|
|
2461
2482
|
collectionNames: collectionNames
|
|
2462
2483
|
})
|
|
2463
2484
|
: null;
|
|
@@ -2488,48 +2509,204 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2488
2509
|
});
|
|
2489
2510
|
assistantContent = "I couldn't run that request because this account does not have ".concat(permissionLabel, " permission.");
|
|
2490
2511
|
toolError = new Error('AI assistant report builder bridge: Access denied.');
|
|
2491
|
-
|
|
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];
|
|
2492
2522
|
case 38:
|
|
2493
|
-
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];
|
|
2494
2524
|
effectiveDirective = collectionOverride
|
|
2495
2525
|
? __assign(__assign({}, directive), { payload: __assign(__assign({}, (directive.payload || {})), { collection: collectionOverride.to }) }) : directive;
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
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;
|
|
2501
2546
|
};
|
|
2502
2547
|
progressTracker.push('Grabbing Data');
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
permissionView: normalizeOptionalString(toolRequest === null || toolRequest === void 0 ? void 0 : toolRequest.permissionView) || undefined
|
|
2507
|
-
});
|
|
2508
|
-
_14.label = 39;
|
|
2548
|
+
executionDirective = effectiveDirective;
|
|
2549
|
+
probeFieldHints = [];
|
|
2550
|
+
_22.label = 39;
|
|
2509
2551
|
case 39:
|
|
2510
|
-
|
|
2511
|
-
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];
|
|
2512
2554
|
assistantContent = buildAssistantRunBudgetExceededMessage();
|
|
2513
|
-
|
|
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];
|
|
2514
2564
|
case 40:
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
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;
|
|
2518
2582
|
case 41:
|
|
2519
|
-
|
|
2520
|
-
return [3 /*break*/,
|
|
2521
|
-
|
|
2522
|
-
case
|
|
2523
|
-
_h =
|
|
2524
|
-
|
|
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)];
|
|
2525
2590
|
case 44:
|
|
2526
|
-
|
|
2527
|
-
|
|
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;
|
|
2528
2692
|
toolResponseDebug = (toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) && typeof toolResponse.debug === 'object'
|
|
2529
2693
|
? toolResponse.debug
|
|
2530
2694
|
: null;
|
|
2531
|
-
toolPayload = buildAssistantToolResultPayload(
|
|
2695
|
+
toolPayload = buildAssistantToolResultPayload(executionDirective, toolResponse, message);
|
|
2532
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
|
+
};
|
|
2533
2710
|
recordStep('Grabbing Data: complete', {
|
|
2534
2711
|
rowCount: toolPayload.result.output.rowCount,
|
|
2535
2712
|
total: toolPayload.result.output.total,
|
|
@@ -2537,65 +2714,72 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2537
2714
|
});
|
|
2538
2715
|
progressTracker.push('Drafting response');
|
|
2539
2716
|
zeroRowResult = toolPayload.result.output.rowCount <= 0;
|
|
2717
|
+
toolTelemetry.outcome = zeroRowResult ? { zeroRows: true } : undefined;
|
|
2540
2718
|
skipFollowupCodex = usedDeterministicHeuristicFastPath
|
|
2541
|
-
|| isAssistantDeterministicHeuristicDirective(
|
|
2719
|
+
|| isAssistantDeterministicHeuristicDirective(executionDirective)
|
|
2542
2720
|
|| zeroRowResult;
|
|
2543
|
-
if (!skipFollowupCodex) return [3 /*break*/,
|
|
2721
|
+
if (!skipFollowupCodex) return [3 /*break*/, 57];
|
|
2544
2722
|
recordStep('Drafting response: deterministic summary', {
|
|
2545
2723
|
reason: zeroRowResult
|
|
2546
2724
|
? 'zero_rows'
|
|
2547
|
-
: (normalizeOptionalString(
|
|
2725
|
+
: (normalizeOptionalString(executionDirective.rawLine) || 'deterministic_heuristic')
|
|
2548
2726
|
});
|
|
2549
2727
|
assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
|
|
2550
2728
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2551
|
-
return [3 /*break*/,
|
|
2552
|
-
case
|
|
2729
|
+
return [3 /*break*/, 63];
|
|
2730
|
+
case 57:
|
|
2553
2731
|
recordStep('Drafting response');
|
|
2554
2732
|
followupPrompt = buildAssistantCodexToolFollowupPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, toolPayload.prompt, assistantSystemPrompt);
|
|
2555
|
-
if (!hasRunBudget('Drafting response: followup')) return [3 /*break*/,
|
|
2556
|
-
|
|
2557
|
-
case
|
|
2558
|
-
|
|
2733
|
+
if (!hasRunBudget('Drafting response: followup')) return [3 /*break*/, 62];
|
|
2734
|
+
_22.label = 58;
|
|
2735
|
+
case 58:
|
|
2736
|
+
_22.trys.push([58, 60, , 61]);
|
|
2559
2737
|
followupStart = Date.now();
|
|
2560
2738
|
return [4 /*yield*/, runCodexInWorkerThread(followupPrompt, applyCodexStageBudget(runOptions), codexConfig, streamProgress)];
|
|
2561
|
-
case
|
|
2562
|
-
followupText =
|
|
2739
|
+
case 59:
|
|
2740
|
+
followupText = _22.sent();
|
|
2563
2741
|
accumulateCodexUsage(followupPrompt, followupText);
|
|
2564
2742
|
timingBreakdown.followupMs = Date.now() - followupStart;
|
|
2565
2743
|
assistantContent = sanitizeAssistantResponse(followupText);
|
|
2566
2744
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2567
|
-
return [3 /*break*/,
|
|
2568
|
-
case
|
|
2569
|
-
|
|
2745
|
+
return [3 /*break*/, 61];
|
|
2746
|
+
case 60:
|
|
2747
|
+
_k = _22.sent();
|
|
2570
2748
|
assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
|
|
2571
2749
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2572
|
-
return [3 /*break*/,
|
|
2573
|
-
case
|
|
2574
|
-
case
|
|
2750
|
+
return [3 /*break*/, 61];
|
|
2751
|
+
case 61: return [3 /*break*/, 63];
|
|
2752
|
+
case 62:
|
|
2575
2753
|
assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
|
|
2576
2754
|
assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
|
|
2577
|
-
|
|
2578
|
-
case
|
|
2579
|
-
case
|
|
2580
|
-
error_3 =
|
|
2755
|
+
_22.label = 63;
|
|
2756
|
+
case 63: return [3 /*break*/, 65];
|
|
2757
|
+
case 64:
|
|
2758
|
+
error_3 = _22.sent();
|
|
2581
2759
|
assistantContent = buildAssistantToolErrorMessage(error_3);
|
|
2582
2760
|
toolError = error_3;
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
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:
|
|
2586
2770
|
progressTracker.push('Drafting response');
|
|
2587
2771
|
recordStep('Drafting response');
|
|
2588
|
-
|
|
2589
|
-
case
|
|
2590
|
-
case
|
|
2591
|
-
error_4 =
|
|
2772
|
+
_22.label = 67;
|
|
2773
|
+
case 67: return [3 /*break*/, 70];
|
|
2774
|
+
case 68:
|
|
2775
|
+
error_4 = _22.sent();
|
|
2592
2776
|
assistantContent = buildAssistantCodexErrorMessage(error_4);
|
|
2593
2777
|
recordStep('Error', { message: normalizeOptionalString(error_4 === null || error_4 === void 0 ? void 0 : error_4.message) || 'Unknown error' });
|
|
2594
|
-
return [3 /*break*/,
|
|
2595
|
-
case
|
|
2778
|
+
return [3 /*break*/, 70];
|
|
2779
|
+
case 69:
|
|
2596
2780
|
progressTracker.stop();
|
|
2597
2781
|
return [7 /*endfinally*/];
|
|
2598
|
-
case
|
|
2782
|
+
case 70:
|
|
2599
2783
|
runBudgetExceeded = runDeadlineMs ? Date.now() > runDeadlineMs : false;
|
|
2600
2784
|
if (!assistantContent) {
|
|
2601
2785
|
assistantContent = runBudgetExceeded
|
|
@@ -2606,6 +2790,20 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2606
2790
|
assistantContent = applyAssistantDatedReportWindow(assistantContent, toolResult);
|
|
2607
2791
|
assistantContent = applyAssistantLotNumberResponseGuard(assistantContent, message, toolResult);
|
|
2608
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;
|
|
2609
2807
|
if (aiWorkerDebug) {
|
|
2610
2808
|
finishedAt = Date.now();
|
|
2611
2809
|
console.log(new Date(), '[AI Worker Debug] codex run complete', {
|
|
@@ -2618,15 +2816,16 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2618
2816
|
timingBreakdown: timingBreakdown,
|
|
2619
2817
|
runBudgetMs: runDeadlineMs ? runBudgetMs : null,
|
|
2620
2818
|
runBudgetRemainingMs: remainingRunBudgetMs(),
|
|
2819
|
+
toolExecution: toolExecutionTelemetry || undefined,
|
|
2621
2820
|
isWorkerInstance: process.env.IS_WORKER_INSTANCE || null,
|
|
2622
2821
|
workerIndex: process.env.WORKER_INDEX || null,
|
|
2623
2822
|
workerInstance: process.env.NODE_APP_INSTANCE || null
|
|
2624
2823
|
});
|
|
2625
2824
|
}
|
|
2626
2825
|
finalNow = new Date();
|
|
2627
|
-
|
|
2628
|
-
case
|
|
2629
|
-
|
|
2826
|
+
_22.label = 71;
|
|
2827
|
+
case 71:
|
|
2828
|
+
_22.trys.push([71, 82, , 93]);
|
|
2630
2829
|
if (canViewDebug) {
|
|
2631
2830
|
finishedAt = Date.now();
|
|
2632
2831
|
codexMs = timingBreakdown.directiveMs
|
|
@@ -2651,6 +2850,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2651
2850
|
toolResult: toolResult,
|
|
2652
2851
|
toolResponseDebug: toolResponseDebug,
|
|
2653
2852
|
toolError: toolError,
|
|
2853
|
+
toolExecution: toolExecutionTelemetry || undefined,
|
|
2654
2854
|
collectionOverride: collectionOverride,
|
|
2655
2855
|
trace: {
|
|
2656
2856
|
steps: steps,
|
|
@@ -2660,6 +2860,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2660
2860
|
termHints: termHints.length ? termHints : undefined,
|
|
2661
2861
|
collectionHints: collectionHints.length ? collectionHints : undefined,
|
|
2662
2862
|
fieldHints: fieldHints.length ? fieldHints : undefined,
|
|
2863
|
+
schemaHints: schemaHints.length ? schemaHints : undefined,
|
|
2663
2864
|
methodHints: methodHints.length ? methodHints : undefined,
|
|
2664
2865
|
publicationHints: publicationHints.length ? publicationHints : undefined,
|
|
2665
2866
|
collectionTokenization: collectionTokenization || undefined,
|
|
@@ -2694,27 +2895,27 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2694
2895
|
}
|
|
2695
2896
|
});
|
|
2696
2897
|
}
|
|
2697
|
-
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 ? {
|
|
2698
2899
|
fast_mode: true,
|
|
2699
2900
|
run_budget_ms: runBudgetMs,
|
|
2700
2901
|
run_budget_exhausted: runBudgetExceeded
|
|
2701
2902
|
} : {})), (changeHistoryFastPathBypassedReason ? {
|
|
2702
2903
|
fast_path_change_history_bypassed_reason: changeHistoryFastPathBypassedReason
|
|
2703
|
-
} : {})), (toolResult ? { tool_result: toolResult } : {})), (assistantDebug ? { debug: assistantDebug } : {}));
|
|
2904
|
+
} : {})), (toolResult ? { tool_result: toolResult } : {})), (toolExecutionTelemetry ? { tool_execution: toolExecutionTelemetry } : {})), (assistantDebug ? { debug: assistantDebug } : {}));
|
|
2704
2905
|
finalUsage = codexUsage.total_tokens > 0 ? {
|
|
2705
2906
|
model: codexModel || 'unknown',
|
|
2706
2907
|
input_tokens: codexUsage.input_tokens,
|
|
2707
2908
|
output_tokens: codexUsage.output_tokens,
|
|
2708
2909
|
total_tokens: codexUsage.total_tokens
|
|
2709
2910
|
} : null;
|
|
2710
|
-
if (!finalUsage) return [3 /*break*/,
|
|
2911
|
+
if (!finalUsage) return [3 /*break*/, 76];
|
|
2711
2912
|
return [4 /*yield*/, resolveClientId(conversation, input.id_client, context === null || context === void 0 ? void 0 : context.id_user)];
|
|
2712
|
-
case
|
|
2713
|
-
usageClientId =
|
|
2714
|
-
if (!usageClientId) return [3 /*break*/,
|
|
2715
|
-
|
|
2716
|
-
case
|
|
2717
|
-
|
|
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]);
|
|
2718
2919
|
return [4 /*yield*/, (0, openai_usage_ledger_manager_1.recordOpenAIUsage)({
|
|
2719
2920
|
id_client: usageClientId,
|
|
2720
2921
|
model: finalUsage.model,
|
|
@@ -2725,16 +2926,16 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2725
2926
|
id_request: requestId || undefined,
|
|
2726
2927
|
id_conversation: conversation._id
|
|
2727
2928
|
})];
|
|
2728
|
-
case
|
|
2729
|
-
|
|
2730
|
-
return [3 /*break*/,
|
|
2731
|
-
case
|
|
2732
|
-
usageError_1 =
|
|
2929
|
+
case 74:
|
|
2930
|
+
_22.sent();
|
|
2931
|
+
return [3 /*break*/, 76];
|
|
2932
|
+
case 75:
|
|
2933
|
+
usageError_1 = _22.sent();
|
|
2733
2934
|
console.error(new Date(), 'Failed to record AI usage', usageError_1);
|
|
2734
|
-
return [3 /*break*/,
|
|
2735
|
-
case
|
|
2935
|
+
return [3 /*break*/, 76];
|
|
2936
|
+
case 76:
|
|
2736
2937
|
finalAssistantDoc = __assign(__assign(__assign(__assign({}, assistantDoc), { _id: assistantMessageId, content: assistantContent, metadata: finalMetadata }), (finalUsage ? { usage: finalUsage } : {})), { updatedAt: finalNow });
|
|
2737
|
-
if (!assistantMessageId) return [3 /*break*/,
|
|
2938
|
+
if (!assistantMessageId) return [3 /*break*/, 78];
|
|
2738
2939
|
setPayload = {
|
|
2739
2940
|
content: assistantContent,
|
|
2740
2941
|
metadata: finalMetadata,
|
|
@@ -2744,59 +2945,59 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2744
2945
|
setPayload.usage = finalUsage;
|
|
2745
2946
|
}
|
|
2746
2947
|
return [4 /*yield*/, updateAssistantMessageWithFallback(assistantMessageId, setPayload)];
|
|
2747
|
-
case
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
case
|
|
2751
|
-
case
|
|
2752
|
-
|
|
2753
|
-
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];
|
|
2754
2955
|
return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
|
|
2755
|
-
case
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
case
|
|
2759
|
-
case
|
|
2760
|
-
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();
|
|
2761
2962
|
failedAt = new Date();
|
|
2762
2963
|
fallbackContent = assistantContent || buildAssistantCodexErrorMessage(finalizeError_1);
|
|
2763
|
-
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' });
|
|
2764
|
-
|
|
2765
|
-
case
|
|
2766
|
-
|
|
2767
|
-
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];
|
|
2768
2969
|
return [4 /*yield*/, updateAssistantMessageWithFallback(assistantMessageId, {
|
|
2769
2970
|
content: fallbackContent,
|
|
2770
2971
|
metadata: failureMetadata,
|
|
2771
2972
|
updatedAt: failedAt
|
|
2772
2973
|
})];
|
|
2773
|
-
case
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
case
|
|
2777
|
-
case
|
|
2778
|
-
|
|
2779
|
-
return [3 /*break*/,
|
|
2780
|
-
case
|
|
2781
|
-
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();
|
|
2782
2983
|
console.error(new Date(), 'AI assistant finalize fallback update failed', persistError_1);
|
|
2783
|
-
return [3 /*break*/,
|
|
2784
|
-
case
|
|
2785
|
-
if (!(input.delete_files_after_run !== false)) return [3 /*break*/,
|
|
2786
|
-
|
|
2787
|
-
case
|
|
2788
|
-
|
|
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]);
|
|
2789
2990
|
return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
|
|
2790
|
-
case
|
|
2791
|
-
|
|
2792
|
-
return [3 /*break*/,
|
|
2793
|
-
case
|
|
2794
|
-
|
|
2795
|
-
return [3 /*break*/,
|
|
2796
|
-
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:
|
|
2797
2998
|
console.error(new Date(), 'AI assistant run finalize failed:', finalizeError_1);
|
|
2798
2999
|
return [2 /*return*/, __assign(__assign({}, assistantDoc), { _id: assistantMessageId, content: fallbackContent, metadata: failureMetadata, updatedAt: failedAt })];
|
|
2799
|
-
case
|
|
3000
|
+
case 93: return [2 /*return*/];
|
|
2800
3001
|
}
|
|
2801
3002
|
});
|
|
2802
3003
|
}); });
|
|
@@ -3039,7 +3240,7 @@ function executeAiAssistantReportIssue(payload, context) {
|
|
|
3039
3240
|
}
|
|
3040
3241
|
function executeAiAssistantMongoRead(payload, context) {
|
|
3041
3242
|
return __awaiter(this, void 0, void 0, function () {
|
|
3042
|
-
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;
|
|
3043
3244
|
var e_1, _p;
|
|
3044
3245
|
var _this = this;
|
|
3045
3246
|
var _q, _r;
|
|
@@ -3082,6 +3283,7 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3082
3283
|
throw new Error('AI assistant report builder bridge: Access denied.');
|
|
3083
3284
|
}
|
|
3084
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);
|
|
3085
3287
|
fallbackMeta = {};
|
|
3086
3288
|
runtimeControl = normalizeAssistantRuntimeControl(input.__assistantRuntime);
|
|
3087
3289
|
runtimeFastMode = (runtimeControl === null || runtimeControl === void 0 ? void 0 : runtimeControl.fastMode) === undefined
|
|
@@ -3107,6 +3309,8 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3107
3309
|
fallbackMeta.reportBuilderBridge = {
|
|
3108
3310
|
from: bridgeCollection.fallbackFrom,
|
|
3109
3311
|
to: collection,
|
|
3312
|
+
mode: bridgeCollection.mode,
|
|
3313
|
+
resolutionPath: bridgeCollection.resolutionPath,
|
|
3110
3314
|
used: true
|
|
3111
3315
|
};
|
|
3112
3316
|
fallbackMeta.permissionFallback = {
|
|
@@ -3736,20 +3940,11 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3736
3940
|
fallbackMeta.fieldAliases = fieldAliases;
|
|
3737
3941
|
}
|
|
3738
3942
|
return [2 /*return*/, __assign({ documents: sanitizedDocuments, total: total, display: display }, (canViewDebug ? {
|
|
3739
|
-
debug: {
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
collectionCandidates: collectionResolution.candidates,
|
|
3745
|
-
collectionScore: collectionResolution.score,
|
|
3746
|
-
bridge: 'report-builder',
|
|
3747
|
-
database: dbName,
|
|
3748
|
-
query: executedQuery,
|
|
3749
|
-
options: normalized.findOptions,
|
|
3750
|
-
includeTotal: normalized.includeTotal,
|
|
3751
|
-
fallbacks: fallbackMeta
|
|
3752
|
-
}
|
|
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 })
|
|
3753
3948
|
} : {}))];
|
|
3754
3949
|
}
|
|
3755
3950
|
});
|
|
@@ -3757,7 +3952,7 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3757
3952
|
}
|
|
3758
3953
|
function executeAiAssistantMongoAggregate(payload, context) {
|
|
3759
3954
|
return __awaiter(this, void 0, void 0, function () {
|
|
3760
|
-
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;
|
|
3761
3956
|
var e_2, _p, e_3, _q;
|
|
3762
3957
|
var _this = this;
|
|
3763
3958
|
var _r, _s;
|
|
@@ -3800,6 +3995,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3800
3995
|
throw new Error('AI assistant report builder bridge: Access denied.');
|
|
3801
3996
|
}
|
|
3802
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);
|
|
3803
3999
|
fallbackMeta = {};
|
|
3804
4000
|
runtimeControl = normalizeAssistantRuntimeControl(input.__assistantRuntime);
|
|
3805
4001
|
runtimeFastMode = (runtimeControl === null || runtimeControl === void 0 ? void 0 : runtimeControl.fastMode) === undefined
|
|
@@ -3826,6 +4022,8 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3826
4022
|
fallbackMeta.reportBuilderBridge = {
|
|
3827
4023
|
from: bridgeCollection.fallbackFrom,
|
|
3828
4024
|
to: collection,
|
|
4025
|
+
mode: bridgeCollection.mode,
|
|
4026
|
+
resolutionPath: bridgeCollection.resolutionPath,
|
|
3829
4027
|
used: true
|
|
3830
4028
|
};
|
|
3831
4029
|
fallbackMeta.permissionFallback = {
|
|
@@ -4695,7 +4893,11 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4695
4893
|
includeGroupFromId: false
|
|
4696
4894
|
});
|
|
4697
4895
|
return [2 /*return*/, __assign(__assign({ documents: sanitizedDocuments, display: display }, (verification ? { verification: verification } : {})), (canViewDebug ? {
|
|
4698
|
-
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 })
|
|
4699
4901
|
} : {}))];
|
|
4700
4902
|
}
|
|
4701
4903
|
});
|
|
@@ -5351,7 +5553,38 @@ function isAssistantExecutableDirective(directive) {
|
|
|
5351
5553
|
}
|
|
5352
5554
|
return true;
|
|
5353
5555
|
}
|
|
5354
|
-
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) {
|
|
5355
5588
|
var base = directive.payload && typeof directive.payload === 'object' ? directive.payload : {};
|
|
5356
5589
|
var request = __assign({}, base);
|
|
5357
5590
|
if (!request.permissionView) {
|
|
@@ -5367,6 +5600,10 @@ function buildAssistantToolRequest(directive, payload) {
|
|
|
5367
5600
|
if (!request.mongo && (payload === null || payload === void 0 ? void 0 : payload.mongo)) {
|
|
5368
5601
|
request.mongo = payload.mongo;
|
|
5369
5602
|
}
|
|
5603
|
+
var normalizedHints = normalizeAssistantDirectiveHints(hints);
|
|
5604
|
+
if (normalizedHints) {
|
|
5605
|
+
request.__assistantHints = normalizedHints;
|
|
5606
|
+
}
|
|
5370
5607
|
if (directive.type === 'aggregate' && !request.__assistantMessage) {
|
|
5371
5608
|
var message = normalizeOptionalString(payload === null || payload === void 0 ? void 0 : payload.message);
|
|
5372
5609
|
if (message) {
|
|
@@ -5375,6 +5612,180 @@ function buildAssistantToolRequest(directive, payload) {
|
|
|
5375
5612
|
}
|
|
5376
5613
|
return request;
|
|
5377
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
|
+
}
|
|
5378
5789
|
function buildAssistantTrimmedStringExpr(value) {
|
|
5379
5790
|
return {
|
|
5380
5791
|
$trim: {
|
|
@@ -7817,7 +8228,22 @@ function buildAssistantDebugPayload(params) {
|
|
|
7817
8228
|
if ((_v = fallbackInfo === null || fallbackInfo === void 0 ? void 0 : fallbackInfo.reportBuilderBridge) === null || _v === void 0 ? void 0 : _v.used) {
|
|
7818
8229
|
var from = fallbackInfo.reportBuilderBridge.from || 'unknown';
|
|
7819
8230
|
var to = fallbackInfo.reportBuilderBridge.to || 'unknown';
|
|
7820
|
-
|
|
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
|
+
}
|
|
7821
8247
|
}
|
|
7822
8248
|
if ((_w = fallbackInfo === null || fallbackInfo === void 0 ? void 0 : fallbackInfo.reportFallback) === null || _w === void 0 ? void 0 : _w.used) {
|
|
7823
8249
|
var from = fallbackInfo.reportFallback.from || 'report';
|
|
@@ -7905,6 +8331,7 @@ function buildAssistantDebugPayload(params) {
|
|
|
7905
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,
|
|
7906
8332
|
options: ((_8 = params.toolResponseDebug) === null || _8 === void 0 ? void 0 : _8.options) || undefined,
|
|
7907
8333
|
fallbacks: ((_9 = params.toolResponseDebug) === null || _9 === void 0 ? void 0 : _9.fallbacks) || undefined,
|
|
8334
|
+
toolExecution: params.toolExecution || undefined,
|
|
7908
8335
|
notes: notes
|
|
7909
8336
|
};
|
|
7910
8337
|
if (params.trace && typeof params.trace === 'object') {
|
|
@@ -16141,7 +16568,7 @@ function doesAssistantCollectionExistInDb(db, collection) {
|
|
|
16141
16568
|
}
|
|
16142
16569
|
function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
16143
16570
|
return __awaiter(this, arguments, void 0, function (collection, db, dbName) {
|
|
16144
|
-
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;
|
|
16145
16572
|
var e_38, _b, e_37, _c, e_39, _d;
|
|
16146
16573
|
var _e;
|
|
16147
16574
|
if (dbName === void 0) { dbName = ''; }
|
|
@@ -16152,7 +16579,23 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
16152
16579
|
if (!normalized) {
|
|
16153
16580
|
throw new Error('AI assistant report builder bridge: Collection is required.');
|
|
16154
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));
|
|
16155
16595
|
aliasCandidates = resolveAssistantBridgeCollectionAliasCandidates(normalized);
|
|
16596
|
+
if (aliasCandidates.length) {
|
|
16597
|
+
pushResolutionStep("aliases:".concat(aliasCandidates.join(',')));
|
|
16598
|
+
}
|
|
16156
16599
|
alias = aliasCandidates[0] || '';
|
|
16157
16600
|
manager = (_e = resolveio_server_app_1.ResolveIOServer.getMongoManager) === null || _e === void 0 ? void 0 : _e.call(resolveio_server_app_1.ResolveIOServer);
|
|
16158
16601
|
hasManager = !!(manager && typeof manager.collection === 'function');
|
|
@@ -16180,7 +16623,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
16180
16623
|
candidate = candidates_5_1.value;
|
|
16181
16624
|
model = manager.collection(candidate);
|
|
16182
16625
|
if (model === null || model === void 0 ? void 0 : model.useRB) {
|
|
16183
|
-
return [2 /*return*/,
|
|
16626
|
+
return [2 /*return*/, finalizeResolution(candidate, 'report-builder', "manager.useRB:".concat(candidate))];
|
|
16184
16627
|
}
|
|
16185
16628
|
}
|
|
16186
16629
|
}
|
|
@@ -16202,14 +16645,19 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
16202
16645
|
resolvedName = normalizeOptionalString(resolved === null || resolved === void 0 ? void 0 : resolved.name);
|
|
16203
16646
|
if (resolvedName) {
|
|
16204
16647
|
pushCandidate(resolvedName);
|
|
16648
|
+
pushResolutionStep("resolver:".concat(resolvedName));
|
|
16205
16649
|
resolvedModel = hasManager ? manager.collection(resolvedName) : null;
|
|
16206
|
-
if (
|
|
16207
|
-
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))];
|
|
16208
16655
|
}
|
|
16209
16656
|
}
|
|
16210
16657
|
return [3 /*break*/, 4];
|
|
16211
16658
|
case 3:
|
|
16212
16659
|
_a = _f.sent();
|
|
16660
|
+
pushResolutionStep('resolver:error');
|
|
16213
16661
|
return [3 /*break*/, 4];
|
|
16214
16662
|
case 4:
|
|
16215
16663
|
if (!db) return [3 /*break*/, 12];
|
|
@@ -16227,7 +16675,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
16227
16675
|
return [4 /*yield*/, doesAssistantCollectionExistInDb(db, candidate)];
|
|
16228
16676
|
case 7:
|
|
16229
16677
|
if (_f.sent()) {
|
|
16230
|
-
return [2 /*return*/,
|
|
16678
|
+
return [2 /*return*/, finalizeResolution(candidate, 'direct-mongo', "db.exists:".concat(candidate))];
|
|
16231
16679
|
}
|
|
16232
16680
|
_f.label = 8;
|
|
16233
16681
|
case 8:
|
|
@@ -16249,7 +16697,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
16249
16697
|
for (candidates_7 = __values(candidates), candidates_7_1 = candidates_7.next(); !candidates_7_1.done; candidates_7_1 = candidates_7.next()) {
|
|
16250
16698
|
candidate = candidates_7_1.value;
|
|
16251
16699
|
if (isAssistantDirectCollectionFallbackAllowed(candidate)) {
|
|
16252
|
-
return [2 /*return*/,
|
|
16700
|
+
return [2 /*return*/, finalizeResolution(candidate, 'direct-mongo', "allowlist:".concat(candidate))];
|
|
16253
16701
|
}
|
|
16254
16702
|
}
|
|
16255
16703
|
}
|
|
@@ -16989,6 +17437,17 @@ function resolveAssistantFastModeEnabled(config) {
|
|
|
16989
17437
|
|| process.env.AI_ASSISTANT_FAST_MODE_ENABLED);
|
|
16990
17438
|
return raw === undefined ? false : raw === true;
|
|
16991
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
|
+
}
|
|
16992
17451
|
function resolveAssistantRunBudgetMs(config) {
|
|
16993
17452
|
var override = normalizeOptionalNumber((config === null || config === void 0 ? void 0 : config.run_budget_ms)
|
|
16994
17453
|
|| (config === null || config === void 0 ? void 0 : config.runBudgetMs));
|
|
@@ -17021,22 +17480,6 @@ function resolveAssistantSystemPrompt(config) {
|
|
|
17021
17480
|
var override = normalizeOptionalString((config === null || config === void 0 ? void 0 : config.system_prompt) || (config === null || config === void 0 ? void 0 : config.systemPrompt));
|
|
17022
17481
|
return override || AI_ASSISTANT_SYSTEM_PROMPT;
|
|
17023
17482
|
}
|
|
17024
|
-
function resolveAssistantGuardrailsEnabled(input, isSuperAdmin) {
|
|
17025
|
-
var _a;
|
|
17026
|
-
if (isSuperAdmin === void 0) { isSuperAdmin = false; }
|
|
17027
|
-
if (isSuperAdmin) {
|
|
17028
|
-
return false;
|
|
17029
|
-
}
|
|
17030
|
-
var topLevel = input === null || input === void 0 ? void 0 : input.guardrails;
|
|
17031
|
-
if (topLevel === false) {
|
|
17032
|
-
return false;
|
|
17033
|
-
}
|
|
17034
|
-
var configGuardrails = normalizeOptionalBoolean((_a = input === null || input === void 0 ? void 0 : input.config) === null || _a === void 0 ? void 0 : _a.guardrails);
|
|
17035
|
-
if (configGuardrails === false) {
|
|
17036
|
-
return false;
|
|
17037
|
-
}
|
|
17038
|
-
return true;
|
|
17039
|
-
}
|
|
17040
17483
|
function normalizeAssistantRuntimeControl(value) {
|
|
17041
17484
|
if (!value || typeof value !== 'object') {
|
|
17042
17485
|
return null;
|
|
@@ -18431,6 +18874,7 @@ function buildAssistantPlannerPrompt(params) {
|
|
|
18431
18874
|
user_json: JSON.stringify(userSnapshot || {}),
|
|
18432
18875
|
collection_hints_json_array: JSON.stringify(params.collectionHints || []),
|
|
18433
18876
|
field_hints_json_array: JSON.stringify(params.fieldHints || []),
|
|
18877
|
+
schema_hints_json_array: JSON.stringify(params.schemaHints || []),
|
|
18434
18878
|
method_hints_json_array: JSON.stringify(params.methodHints || []),
|
|
18435
18879
|
publication_hints_json_array: JSON.stringify(params.publicationHints || [])
|
|
18436
18880
|
};
|
|
@@ -18483,6 +18927,14 @@ function buildAssistantContext(input, userContext) {
|
|
|
18483
18927
|
lines.push(hint);
|
|
18484
18928
|
});
|
|
18485
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
|
+
}
|
|
18486
18938
|
var methodHints = Array.isArray(userContext === null || userContext === void 0 ? void 0 : userContext.methodHints)
|
|
18487
18939
|
? userContext.methodHints.filter(Boolean)
|
|
18488
18940
|
: [];
|
|
@@ -18600,6 +19052,68 @@ function buildAssistantFieldHints(message, collectionNames, options) {
|
|
|
18600
19052
|
});
|
|
18601
19053
|
return hints;
|
|
18602
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
|
+
}
|
|
18603
19117
|
var cachedClientRouteIndex = null;
|
|
18604
19118
|
function normalizeRouteKey(value) {
|
|
18605
19119
|
var trimmed = normalizeOptionalString(value);
|