@resolveio/server-lib 22.2.12 → 22.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/methods/ai-terminal.js +94 -43
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +1 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -171,8 +171,8 @@ var DEFAULT_MAX_TOTAL_ATTACHMENT_CHARS = 40000;
|
|
|
171
171
|
var DEFAULT_CODEX_MODEL = 'gpt-5.3-codex';
|
|
172
172
|
var DEFAULT_CODEX_FALLBACK_MODEL = 'gpt-5.2-codex';
|
|
173
173
|
var DEFAULT_CODEX_TIMEOUT_MS = 180000;
|
|
174
|
-
var DEFAULT_AI_ASSISTANT_RUN_BUDGET_MS =
|
|
175
|
-
var DEFAULT_AI_ASSISTANT_MONGO_MAX_TIME_MS =
|
|
174
|
+
var DEFAULT_AI_ASSISTANT_RUN_BUDGET_MS = 120000;
|
|
175
|
+
var DEFAULT_AI_ASSISTANT_MONGO_MAX_TIME_MS = 12000;
|
|
176
176
|
var AI_ASSISTANT_MONGO_DEFAULT_LIMIT = 20;
|
|
177
177
|
var AI_ASSISTANT_MONGO_MAX_LIMIT = 200;
|
|
178
178
|
var AI_ASSISTANT_MONGO_EXPORT_MAX_LIMIT = 5000;
|
|
@@ -1603,7 +1603,7 @@ function executeAiFormPatch(payload, context) {
|
|
|
1603
1603
|
}
|
|
1604
1604
|
function executeAiAssistantCodexRun(payload, context) {
|
|
1605
1605
|
return __awaiter(this, void 0, void 0, function () {
|
|
1606
|
-
var input, message, aiWorkerDebug, requestId, codexModel, codexFallbackModels, guardrail, conversation_3, now_3, userMsg, assistantMsg,
|
|
1606
|
+
var input, message, aiWorkerDebug, requestId, codexModel, codexFallbackModels, user, isSuperAdmin, guardrailsEnabled, 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
1607
|
var _this = this;
|
|
1608
1608
|
var _a, _b, _c;
|
|
1609
1609
|
return __generator(this, function (_d) {
|
|
@@ -1621,10 +1621,19 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1621
1621
|
requestId = normalizeOptionalString(input.request_id);
|
|
1622
1622
|
codexModel = resolveCodexModel(input.config);
|
|
1623
1623
|
codexFallbackModels = resolveCodexFallbackModels(input.config, codexModel);
|
|
1624
|
+
return [4 /*yield*/, user_collection_1.Users.findById(context === null || context === void 0 ? void 0 : context.id_user)];
|
|
1625
|
+
case 1:
|
|
1626
|
+
user = _d.sent();
|
|
1627
|
+
if (!user) {
|
|
1628
|
+
throw new Error('Unauthorized.');
|
|
1629
|
+
}
|
|
1630
|
+
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];
|
|
1624
1633
|
guardrail = evaluateAssistantGuardrails(message);
|
|
1625
|
-
if (!(guardrail === null || guardrail === void 0 ? void 0 : guardrail.blocked)) return [3 /*break*/,
|
|
1634
|
+
if (!(guardrail === null || guardrail === void 0 ? void 0 : guardrail.blocked)) return [3 /*break*/, 6];
|
|
1626
1635
|
return [4 /*yield*/, ensureConversation(input, 'codex', context === null || context === void 0 ? void 0 : context.id_user)];
|
|
1627
|
-
case
|
|
1636
|
+
case 2:
|
|
1628
1637
|
conversation_3 = _d.sent();
|
|
1629
1638
|
now_3 = new Date();
|
|
1630
1639
|
userMsg = {
|
|
@@ -1644,23 +1653,20 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1644
1653
|
updatedAt: now_3
|
|
1645
1654
|
};
|
|
1646
1655
|
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.insertOne(userMsg)];
|
|
1647
|
-
case
|
|
1656
|
+
case 3:
|
|
1648
1657
|
_d.sent();
|
|
1649
1658
|
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.insertOne(assistantMsg)];
|
|
1650
|
-
case
|
|
1659
|
+
case 4:
|
|
1651
1660
|
_d.sent();
|
|
1652
1661
|
return [4 /*yield*/, touchConversation(conversation_3._id, now_3)];
|
|
1653
|
-
case
|
|
1662
|
+
case 5:
|
|
1654
1663
|
_d.sent();
|
|
1655
1664
|
return [2 /*return*/, {
|
|
1656
1665
|
conversation: conversation_3,
|
|
1657
1666
|
message: assistantMsg,
|
|
1658
1667
|
guardrails: { blocked: true, reason: guardrail.reason }
|
|
1659
1668
|
}];
|
|
1660
|
-
case 5: return [4 /*yield*/, user_collection_1.Users.findById(context === null || context === void 0 ? void 0 : context.id_user)];
|
|
1661
1669
|
case 6:
|
|
1662
|
-
user = _d.sent();
|
|
1663
|
-
isSuperAdmin = !!((_a = user === null || user === void 0 ? void 0 : user.roles) === null || _a === void 0 ? void 0 : _a.super_admin);
|
|
1664
1670
|
canViewDebug = isAssistantDebugUser(user);
|
|
1665
1671
|
if (shouldLogAssistantFinalizeDebug()) {
|
|
1666
1672
|
console.log(new Date(), '[AI-Dashboard][AI-Assistant] debug-visibility', {
|
|
@@ -1811,14 +1817,17 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1811
1817
|
insertResult = _d.sent();
|
|
1812
1818
|
assistantMessageId = (insertResult === null || insertResult === void 0 ? void 0 : insertResult._id) || (insertResult === null || insertResult === void 0 ? void 0 : insertResult.insertedId);
|
|
1813
1819
|
enqueueAssistantCodexRun(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1814
|
-
var runStart, fastModeEnabled, runBudgetMs, 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,
|
|
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, _h, toolPayload, zeroRowResult, skipFollowupCodex, followupPrompt, followupStart, followupText, _j, error_3, error_4, runBudgetExceeded, finishedAt, finalNow, finishedAt, codexMs, draftingMs, finalMetadata, finalUsage, usageClientId, usageError_1, finalAssistantDoc, setPayload, finalizeError_1, failedAt, fallbackContent, failureMetadata, persistError_1, _k;
|
|
1815
1821
|
var _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13;
|
|
1816
1822
|
return __generator(this, function (_14) {
|
|
1817
1823
|
switch (_14.label) {
|
|
1818
1824
|
case 0:
|
|
1819
1825
|
runStart = Date.now();
|
|
1820
|
-
fastModeEnabled = resolveAssistantFastModeEnabled();
|
|
1821
|
-
|
|
1826
|
+
fastModeEnabled = resolveAssistantFastModeEnabled(input.config);
|
|
1827
|
+
plannerEnabled = resolveAssistantPlannerEnabled(input.config);
|
|
1828
|
+
runBudgetMs = resolveAssistantRunBudgetMs(input.config);
|
|
1829
|
+
assistantMongoMaxTimeMs = resolveAssistantMongoDefaultMaxTimeMs(input.config);
|
|
1830
|
+
assistantSystemPrompt = resolveAssistantSystemPrompt(input.config);
|
|
1822
1831
|
runDeadlineMs = fastModeEnabled ? runStart + runBudgetMs : null;
|
|
1823
1832
|
if (aiWorkerDebug) {
|
|
1824
1833
|
console.log(new Date(), '[AI Worker Debug] codex run start', {
|
|
@@ -1901,7 +1910,6 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1901
1910
|
collectionSelection = null;
|
|
1902
1911
|
collectionOverride = null;
|
|
1903
1912
|
collectionNames = [];
|
|
1904
|
-
plannerEnabled = resolveAssistantPlannerEnabled();
|
|
1905
1913
|
plannerUsed = false;
|
|
1906
1914
|
plannerSkipReason = '';
|
|
1907
1915
|
plannerOutput = null;
|
|
@@ -2052,7 +2060,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2052
2060
|
heuristic: normalizeOptionalString(heuristicDirectivePrecomputed === null || heuristicDirectivePrecomputed === void 0 ? void 0 : heuristicDirectivePrecomputed.rawLine) || undefined
|
|
2053
2061
|
});
|
|
2054
2062
|
}
|
|
2055
|
-
prompt_1 = buildAssistantCodexPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext);
|
|
2063
|
+
prompt_1 = buildAssistantCodexPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, assistantSystemPrompt);
|
|
2056
2064
|
return [4 /*yield*/, resolveAssistantWorkspaceRoot()];
|
|
2057
2065
|
case 7:
|
|
2058
2066
|
workspaceRoot = _14.sent();
|
|
@@ -2190,7 +2198,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2190
2198
|
}
|
|
2191
2199
|
if (!(dataQuestion && !directive)) return [3 /*break*/, 17];
|
|
2192
2200
|
recordStep('Directive: determine tool', { type: 'data-question' });
|
|
2193
|
-
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode);
|
|
2201
|
+
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode, assistantSystemPrompt);
|
|
2194
2202
|
if (!hasRunBudget('Directive: determine tool')) return [3 /*break*/, 17];
|
|
2195
2203
|
_14.label = 14;
|
|
2196
2204
|
case 14:
|
|
@@ -2254,7 +2262,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2254
2262
|
case 21:
|
|
2255
2263
|
if (!(!directive && dataQuestion)) return [3 /*break*/, 25];
|
|
2256
2264
|
recordStep('Directive: forced retry', { mode: 'directive-only' });
|
|
2257
|
-
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode);
|
|
2265
|
+
directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode, assistantSystemPrompt);
|
|
2258
2266
|
if (!hasRunBudget('Directive: forced retry')) return [3 /*break*/, 25];
|
|
2259
2267
|
_14.label = 22;
|
|
2260
2268
|
case 22:
|
|
@@ -2297,7 +2305,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2297
2305
|
requestedTimeGrain: requestedTimeGrain,
|
|
2298
2306
|
requestedBreakdowns: requestedBreakdownDimensions,
|
|
2299
2307
|
strict: true
|
|
2300
|
-
}), 'aggregate_only');
|
|
2308
|
+
}), 'aggregate_only', assistantSystemPrompt);
|
|
2301
2309
|
if (!hasRunBudget('Directive: dated retry')) return [3 /*break*/, 29];
|
|
2302
2310
|
_14.label = 26;
|
|
2303
2311
|
case 26:
|
|
@@ -2345,7 +2353,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2345
2353
|
requestedTimeGrain: requestedTimeGrain,
|
|
2346
2354
|
requestedBreakdowns: requestedBreakdownDimensions,
|
|
2347
2355
|
strict: true
|
|
2348
|
-
}), 'aggregate_only');
|
|
2356
|
+
}), 'aggregate_only', assistantSystemPrompt);
|
|
2349
2357
|
if (!hasRunBudget('Directive: dated guard retry')) return [3 /*break*/, 33];
|
|
2350
2358
|
_14.label = 30;
|
|
2351
2359
|
case 30:
|
|
@@ -2391,7 +2399,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2391
2399
|
requestedTimeGrain: requestedTimeGrain,
|
|
2392
2400
|
requestedBreakdowns: requestedBreakdownDimensions,
|
|
2393
2401
|
strict: true
|
|
2394
|
-
}), 'aggregate_only');
|
|
2402
|
+
}), 'aggregate_only', assistantSystemPrompt);
|
|
2395
2403
|
if (!hasRunBudget('Directive: grouped guard retry')) return [3 /*break*/, 37];
|
|
2396
2404
|
_14.label = 34;
|
|
2397
2405
|
case 34:
|
|
@@ -2489,7 +2497,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2489
2497
|
toolRequest.__assistantRuntime = {
|
|
2490
2498
|
fastMode: fastModeEnabled,
|
|
2491
2499
|
deadlineMs: runDeadlineMs || undefined,
|
|
2492
|
-
maxTimeMS:
|
|
2500
|
+
maxTimeMS: assistantMongoMaxTimeMs
|
|
2493
2501
|
};
|
|
2494
2502
|
progressTracker.push('Grabbing Data');
|
|
2495
2503
|
recordStep('Grabbing Data: start', {
|
|
@@ -2543,7 +2551,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2543
2551
|
return [3 /*break*/, 51];
|
|
2544
2552
|
case 45:
|
|
2545
2553
|
recordStep('Drafting response');
|
|
2546
|
-
followupPrompt = buildAssistantCodexToolFollowupPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, toolPayload.prompt);
|
|
2554
|
+
followupPrompt = buildAssistantCodexToolFollowupPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, toolPayload.prompt, assistantSystemPrompt);
|
|
2547
2555
|
if (!hasRunBudget('Drafting response: followup')) return [3 /*break*/, 50];
|
|
2548
2556
|
_14.label = 46;
|
|
2549
2557
|
case 46:
|
|
@@ -7464,14 +7472,15 @@ function buildAssistantToolResultPrompt(result, displayPreview) {
|
|
|
7464
7472
|
}
|
|
7465
7473
|
return lines.join('\n');
|
|
7466
7474
|
}
|
|
7467
|
-
function buildAssistantCodexToolFollowupPrompt(message, attachmentText, historyText, contextText, toolResultText) {
|
|
7475
|
+
function buildAssistantCodexToolFollowupPrompt(message, attachmentText, historyText, contextText, toolResultText, systemPromptText) {
|
|
7476
|
+
if (systemPromptText === void 0) { systemPromptText = AI_ASSISTANT_SYSTEM_PROMPT; }
|
|
7468
7477
|
var trimmedContext = normalizeOptionalString(contextText);
|
|
7469
7478
|
var contextBlock = trimmedContext ? "\n\nContext:\n".concat(trimmedContext) : '';
|
|
7470
7479
|
var trimmedHistory = normalizeOptionalString(historyText);
|
|
7471
7480
|
var historyBlock = trimmedHistory ? "\n\nConversation so far:\n".concat(trimmedHistory) : '';
|
|
7472
7481
|
var toolBlock = toolResultText ? "\n\nTool Result:\n".concat(toolResultText) : '';
|
|
7473
7482
|
var instruction = '\n\nInstruction:\nNow answer the user. Do NOT output another REPORT_BUILDER_* directive. Output plain Markdown. Summarize first, then include a Markdown table. If the Tool Result includes verification warnings that materially affect interpretation (partial periods, mixed metric/date basis, failed cross-check), mention them briefly and call out the metric/date basis used. Include explicit UTC date boundaries and never show placeholders like $$NOW.';
|
|
7474
|
-
return "System:\n".concat(
|
|
7483
|
+
return "System:\n".concat(systemPromptText).concat(contextBlock).concat(historyBlock, "\n\nUser:\n").concat(message).concat(attachmentText || '').concat(toolBlock).concat(instruction).trim();
|
|
7475
7484
|
}
|
|
7476
7485
|
function buildAssistantToolFallbackResponse(result) {
|
|
7477
7486
|
var _a, _b;
|
|
@@ -16969,30 +16978,65 @@ function resolveCodexTimeoutMs() {
|
|
|
16969
16978
|
}
|
|
16970
16979
|
return DEFAULT_CODEX_TIMEOUT_MS;
|
|
16971
16980
|
}
|
|
16972
|
-
function resolveAssistantFastModeEnabled() {
|
|
16973
|
-
var
|
|
16974
|
-
|
|
16981
|
+
function resolveAssistantFastModeEnabled(config) {
|
|
16982
|
+
var override = normalizeOptionalBoolean((config === null || config === void 0 ? void 0 : config.fast_mode)
|
|
16983
|
+
|| (config === null || config === void 0 ? void 0 : config.fastMode));
|
|
16984
|
+
if (typeof override === 'boolean') {
|
|
16985
|
+
return override;
|
|
16986
|
+
}
|
|
16987
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
16988
|
+
var raw = normalizeOptionalBoolean(serverConfig['AI_ASSISTANT_FAST_MODE_ENABLED']
|
|
16975
16989
|
|| process.env.AI_ASSISTANT_FAST_MODE_ENABLED);
|
|
16976
|
-
return raw === undefined ?
|
|
16990
|
+
return raw === undefined ? false : raw === true;
|
|
16977
16991
|
}
|
|
16978
|
-
function resolveAssistantRunBudgetMs() {
|
|
16979
|
-
var
|
|
16980
|
-
|
|
16992
|
+
function resolveAssistantRunBudgetMs(config) {
|
|
16993
|
+
var override = normalizeOptionalNumber((config === null || config === void 0 ? void 0 : config.run_budget_ms)
|
|
16994
|
+
|| (config === null || config === void 0 ? void 0 : config.runBudgetMs));
|
|
16995
|
+
if (override && override > 0) {
|
|
16996
|
+
return Math.max((0, common_1.round)(override), 5000);
|
|
16997
|
+
}
|
|
16998
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
16999
|
+
var raw = normalizeOptionalNumber(serverConfig['AI_ASSISTANT_RUN_BUDGET_MS']
|
|
16981
17000
|
|| process.env.AI_ASSISTANT_RUN_BUDGET_MS);
|
|
16982
17001
|
if (raw && raw > 0) {
|
|
16983
17002
|
return Math.max((0, common_1.round)(raw), 5000);
|
|
16984
17003
|
}
|
|
16985
17004
|
return DEFAULT_AI_ASSISTANT_RUN_BUDGET_MS;
|
|
16986
17005
|
}
|
|
16987
|
-
function resolveAssistantMongoDefaultMaxTimeMs() {
|
|
16988
|
-
var
|
|
16989
|
-
|
|
17006
|
+
function resolveAssistantMongoDefaultMaxTimeMs(config) {
|
|
17007
|
+
var override = normalizeOptionalNumber((config === null || config === void 0 ? void 0 : config.mongo_max_time_ms)
|
|
17008
|
+
|| (config === null || config === void 0 ? void 0 : config.mongoMaxTimeMs));
|
|
17009
|
+
if (override && override > 0) {
|
|
17010
|
+
return Math.max((0, common_1.round)(override), 250);
|
|
17011
|
+
}
|
|
17012
|
+
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
17013
|
+
var raw = normalizeOptionalNumber(serverConfig['AI_ASSISTANT_MONGO_MAX_TIME_MS']
|
|
16990
17014
|
|| process.env.AI_ASSISTANT_MONGO_MAX_TIME_MS);
|
|
16991
17015
|
if (raw && raw > 0) {
|
|
16992
17016
|
return Math.max((0, common_1.round)(raw), 250);
|
|
16993
17017
|
}
|
|
16994
17018
|
return DEFAULT_AI_ASSISTANT_MONGO_MAX_TIME_MS;
|
|
16995
17019
|
}
|
|
17020
|
+
function resolveAssistantSystemPrompt(config) {
|
|
17021
|
+
var override = normalizeOptionalString((config === null || config === void 0 ? void 0 : config.system_prompt) || (config === null || config === void 0 ? void 0 : config.systemPrompt));
|
|
17022
|
+
return override || AI_ASSISTANT_SYSTEM_PROMPT;
|
|
17023
|
+
}
|
|
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
|
+
}
|
|
16996
17040
|
function normalizeAssistantRuntimeControl(value) {
|
|
16997
17041
|
if (!value || typeof value !== 'object') {
|
|
16998
17042
|
return null;
|
|
@@ -18276,8 +18320,9 @@ function buildAssistantDirectiveStyleHint(params) {
|
|
|
18276
18320
|
params.strict ? '- STRICT: if unsure, still prefer REPORT_BUILDER_AGG.' : ''
|
|
18277
18321
|
].filter(Boolean).join('\n');
|
|
18278
18322
|
}
|
|
18279
|
-
function buildAssistantCodexDirectivePrompt(message, attachmentText, historyText, contextText, directiveStyleHintText, mode) {
|
|
18323
|
+
function buildAssistantCodexDirectivePrompt(message, attachmentText, historyText, contextText, directiveStyleHintText, mode, systemPromptText) {
|
|
18280
18324
|
if (mode === void 0) { mode = 'any'; }
|
|
18325
|
+
if (systemPromptText === void 0) { systemPromptText = AI_ASSISTANT_SYSTEM_PROMPT; }
|
|
18281
18326
|
var trimmedContext = normalizeOptionalString(contextText);
|
|
18282
18327
|
var contextBlock = trimmedContext ? "\n\nContext:\n".concat(trimmedContext) : '';
|
|
18283
18328
|
var trimmedHistory = normalizeOptionalString(historyText);
|
|
@@ -18287,21 +18332,27 @@ function buildAssistantCodexDirectivePrompt(message, attachmentText, historyText
|
|
|
18287
18332
|
var instruction = mode === 'aggregate_only'
|
|
18288
18333
|
? '\n\nInstruction:\nReturn ONLY a single REPORT_BUILDER_AGG directive line. Do not include any other text.'
|
|
18289
18334
|
: '\n\nInstruction:\nReturn ONLY a single REPORT_BUILDER_READ or REPORT_BUILDER_AGG directive line. Do not include any other text.';
|
|
18290
|
-
return "System:\n".concat(
|
|
18335
|
+
return "System:\n".concat(systemPromptText).concat(contextBlock).concat(historyBlock).concat(styleHintBlock, "\n\nUser:\n").concat(message).concat(attachmentText || '').concat(instruction).trim();
|
|
18291
18336
|
}
|
|
18292
|
-
function buildAssistantCodexPrompt(message, attachmentText, historyText, contextText) {
|
|
18337
|
+
function buildAssistantCodexPrompt(message, attachmentText, historyText, contextText, systemPromptText) {
|
|
18338
|
+
if (systemPromptText === void 0) { systemPromptText = AI_ASSISTANT_SYSTEM_PROMPT; }
|
|
18293
18339
|
var trimmedContext = normalizeOptionalString(contextText);
|
|
18294
18340
|
var contextBlock = trimmedContext ? "\n\nContext:\n".concat(trimmedContext) : '';
|
|
18295
18341
|
var trimmedHistory = normalizeOptionalString(historyText);
|
|
18296
18342
|
var historyBlock = trimmedHistory ? "\n\nConversation so far:\n".concat(trimmedHistory) : '';
|
|
18297
|
-
return "System:\n".concat(
|
|
18343
|
+
return "System:\n".concat(systemPromptText).concat(contextBlock).concat(historyBlock, "\n\nUser:\n").concat(message).concat(attachmentText || '').trim();
|
|
18298
18344
|
}
|
|
18299
|
-
function resolveAssistantPlannerEnabled() {
|
|
18345
|
+
function resolveAssistantPlannerEnabled(config) {
|
|
18300
18346
|
var _a;
|
|
18301
|
-
var
|
|
18302
|
-
|
|
18347
|
+
var override = normalizeOptionalBoolean((config === null || config === void 0 ? void 0 : config.planner_enabled)
|
|
18348
|
+
|| (config === null || config === void 0 ? void 0 : config.plannerEnabled));
|
|
18349
|
+
if (typeof override === 'boolean') {
|
|
18350
|
+
return override;
|
|
18351
|
+
}
|
|
18352
|
+
var serverConfig = ((_a = resolveio_server_app_1.ResolveIOServer.getServerConfig) === null || _a === void 0 ? void 0 : _a.call(resolveio_server_app_1.ResolveIOServer)) || {};
|
|
18353
|
+
var raw = normalizeOptionalBoolean(serverConfig['AI_ASSISTANT_CODEX_PLANNER_ENABLED']
|
|
18303
18354
|
|| process.env.AI_ASSISTANT_CODEX_PLANNER_ENABLED);
|
|
18304
|
-
return raw === undefined ?
|
|
18355
|
+
return raw === undefined ? false : raw === true;
|
|
18305
18356
|
}
|
|
18306
18357
|
function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
|
|
18307
18358
|
var e_47, _a;
|