fix(planner): align recall timeout with global setting

This commit is contained in:
Hao19911125
2026-04-06 23:59:43 +08:00
parent ffdf0e4929
commit f7f408da4a
2 changed files with 20 additions and 3 deletions

View File

@@ -13,6 +13,13 @@ const _currentModuleUrl = import.meta.url;
let _bmeRuntime = null; let _bmeRuntime = null;
function getPlannerRecallTimeoutMs() {
const timeoutMs = Number(_bmeRuntime?.getPlannerRecallTimeoutMs?.());
return Number.isFinite(timeoutMs) && timeoutMs > 0
? timeoutMs
: VECTOR_RECALL_TIMEOUT_MS;
}
function getTrustedOrigin() { return window.location.origin; } function getTrustedOrigin() { return window.location.origin; }
function postToIframe(iframe, payload) { function postToIframe(iframe, payload) {
@@ -1135,7 +1142,9 @@ async function buildPlannerMessages(rawUserInput) {
let plannerRecall = null; let plannerRecall = null;
if (_bmeRuntime?.runPlannerRecallForEna) { if (_bmeRuntime?.runPlannerRecallForEna) {
const controller = new AbortController(); const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), VECTOR_RECALL_TIMEOUT_MS); const recallTimeoutMs = getPlannerRecallTimeoutMs();
const recallStartedAt = Date.now();
const timeoutId = setTimeout(() => controller.abort(), recallTimeoutMs);
try { try {
const recall = await _bmeRuntime.runPlannerRecallForEna({ const recall = await _bmeRuntime.runPlannerRecallForEna({
rawUserInput, rawUserInput,
@@ -1148,12 +1157,15 @@ async function buildPlannerMessages(rawUserInput) {
} }
} catch (e) { } catch (e) {
if (e?.name === 'AbortError') { if (e?.name === 'AbortError') {
console.warn(`[Ena] BME recall timed out (> ${Math.floor(VECTOR_RECALL_TIMEOUT_MS / 1000)}s)`); console.warn(`[Ena] BME recall timed out (> ${Math.floor(recallTimeoutMs / 1000)}s)`);
} else { } else {
console.warn('[Ena] BME planner recall failed:', e); console.warn('[Ena] BME planner recall failed:', e);
} }
} finally { } finally {
clearTimeout(timeoutId); clearTimeout(timeoutId);
debugLog(
`[Ena] Planner recall finished in ${Date.now() - recallStartedAt}ms (source=${memorySource}, timeout=${recallTimeoutMs}ms)`,
);
} }
} }
debugLog(`[Ena] Memory source: ${memorySource}`); debugLog(`[Ena] Memory source: ${memorySource}`);

View File

@@ -3237,6 +3237,10 @@ function getConfiguredTimeoutMs(settings = getSettings()) {
})(); })();
} }
function getPlannerRecallTimeoutMs() {
return getConfiguredTimeoutMs(getSettings());
}
function getEmbeddingConfig(mode = null) { function getEmbeddingConfig(mode = null) {
const settings = getSettings(); const settings = getSettings();
return getVectorConfigFromSettings( return getVectorConfigFromSettings(
@@ -10570,6 +10574,7 @@ async function onReembedDirect() {
await initEnaPlanner({ await initEnaPlanner({
getContext, getContext,
getExtensionPath: () => `scripts/extensions/third-party/${MODULE_NAME}`, getExtensionPath: () => `scripts/extensions/third-party/${MODULE_NAME}`,
getPlannerRecallTimeoutMs,
isTrivialUserInput, isTrivialUserInput,
preparePlannerRecallHandoff, preparePlannerRecallHandoff,
runPlannerRecallForEna, runPlannerRecallForEna,