Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Show the English plan when a partial copy cannot be completed
Emre Sokullu0da2be0666be
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 51ccdcae0..d07574358 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -144,6 +144,7 @@ import {PLAN_LOCALIZATION_RESPONSE_JSON_SCHEMA,buildAskModeHandoffMessages,buildPlanLocalizationMessages,+ canonicalPlanDisplay,localizePlanFromContent,parsePlanFromContent,parseReadScopeFromContent,@@ -26329,9 +26330,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// other than English, when the planner left out its localized copy: one// small request translates the display fields. Execution keeps the English// plan, and if the translation fails or is incomplete the user sees the- // English text.+ // English plan, never what was left of a partial copy.async _localizedPlanForDisplay(tabId, plan, provider, costState, runId = null, runtimeMode = 'act') {- if (plan?.localized?.missing !== true || !provider?.chat) return plan;+ if (plan?.localized?.missing !== true) return plan;+ if (!provider?.chat) return canonicalPlanDisplay(plan);const messages = buildPlanLocalizationMessages(plan);const chatOptions = { ...this._plannerChatOptions(provider, false, false, 'localize'), temperature: 0 };await this._tracePlannerAttemptRequest(runId, 0, provider, messages, 'planner_localize', 1, runtimeMode, chatOptions);@@ -26340,11 +26342,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst result = await this._chatWithCostAllowance(provider, messages, chatOptions, costState,{ tabId, generationName: 'planner_localize' });await this._tracePlannerAttemptResponse(runId, 0, provider, result, 'planner_localize', 1, startedAt, chatOptions);- return localizePlanFromContent(plan, result?.content) || plan;+ return localizePlanFromContent(plan, result?.content) || canonicalPlanDisplay(plan);} catch (error) {if (this._isCostAllowanceError(error) || this._checkAbort(tabId)) throw error;await this._tracePlannerAttemptFailure(runId, 'planner_localize', 1, error);- return plan;+ return canonicalPlanDisplay(plan);}}diff --git a/src/chrome/src/agent/planner.js b/src/chrome/src/agent/planner.jsindex 9ddf78ebf..5e087cf0a 100644--- a/src/chrome/src/agent/planner.js+++ b/src/chrome/src/agent/planner.js@@ -1502,6 +1502,23 @@ export function buildPlanLocalizationMessages(plan) {];}+// The plan with its display fields in canonical English: what the user reads+// when no complete copy in their language is available, so a partial copy+// never shows two languages.+export function canonicalPlanDisplay(plan) {+ if (!plan) return plan;+ return {+ ...plan,+ localized: {+ locale: plan.localized?.locale || 'en',+ summary: plan.summary,+ steps: (plan.steps || []).map(({ id, action }) => ({ id, action })),+ risks: [...(plan.risks || [])],+ missing: true,+ },+ };+}+// The plan with the translation in `content` as its localized copy, or null// unless `content` is in the requested language and translates the summary,// every step (matched by id) and every risk: the user reads the plan in onediff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 5a6d26312..8be7e3a1d 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -136,6 +136,7 @@ import {PLAN_LOCALIZATION_RESPONSE_JSON_SCHEMA,buildAskModeHandoffMessages,buildPlanLocalizationMessages,+ canonicalPlanDisplay,localizePlanFromContent,parsePlanFromContent,parseReadScopeFromContent,@@ -23385,9 +23386,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// other than English, when the planner left out its localized copy: one// small request translates the display fields. Execution keeps the English// plan, and if the translation fails or is incomplete the user sees the- // English text.+ // English plan, never what was left of a partial copy.async _localizedPlanForDisplay(tabId, plan, provider, costState, runId = null, runtimeMode = 'act') {- if (plan?.localized?.missing !== true || !provider?.chat) return plan;+ if (plan?.localized?.missing !== true) return plan;+ if (!provider?.chat) return canonicalPlanDisplay(plan);const messages = buildPlanLocalizationMessages(plan);const chatOptions = { ...this._plannerChatOptions(provider, false, false, 'localize'), temperature: 0 };await this._tracePlannerAttemptRequest(runId, 0, provider, messages, 'planner_localize', 1, runtimeMode, chatOptions);@@ -23396,11 +23398,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst result = await this._chatWithCostAllowance(provider, messages, chatOptions, costState,{ tabId, generationName: 'planner_localize' });await this._tracePlannerAttemptResponse(runId, 0, provider, result, 'planner_localize', 1, startedAt, chatOptions);- return localizePlanFromContent(plan, result?.content) || plan;+ return localizePlanFromContent(plan, result?.content) || canonicalPlanDisplay(plan);} catch (error) {if (this._isCostAllowanceError(error) || this._checkAbort(tabId)) throw error;await this._tracePlannerAttemptFailure(runId, 'planner_localize', 1, error);- return plan;+ return canonicalPlanDisplay(plan);}}diff --git a/src/firefox/src/agent/planner.js b/src/firefox/src/agent/planner.jsindex 9ddf78ebf..5e087cf0a 100644--- a/src/firefox/src/agent/planner.js+++ b/src/firefox/src/agent/planner.js@@ -1502,6 +1502,23 @@ export function buildPlanLocalizationMessages(plan) {];}+// The plan with its display fields in canonical English: what the user reads+// when no complete copy in their language is available, so a partial copy+// never shows two languages.+export function canonicalPlanDisplay(plan) {+ if (!plan) return plan;+ return {+ ...plan,+ localized: {+ locale: plan.localized?.locale || 'en',+ summary: plan.summary,+ steps: (plan.steps || []).map(({ id, action }) => ({ id, action })),+ risks: [...(plan.risks || [])],+ missing: true,+ },+ };+}+// The plan with the translation in `content` as its localized copy, or null// unless `content` is in the requested language and translates the summary,// every step (matched by id) and every risk: the user reads the plan in onediff --git a/test/plan-when-needed.mjs b/test/plan-when-needed.mjsindex 6905dc9b4..ce2b5f3f8 100644--- a/test/plan-when-needed.mjs+++ b/test/plan-when-needed.mjs@@ -399,12 +399,18 @@ for (const build of BUILDS) {test(`${build}: a failed or incomplete translation shows the English plan instead`, async () => {const incomplete = JSON.stringify({ locale: 'tr', summary: 'Adresi bültene abone et.', steps: [{ id: '1', action: 'E-posta alanını doldur.' }], risks: [] });- for (const translation of [new Error('provider unavailable'), 'not json', incomplete]) {- const f = displayFixture({ translation });- const gate = await f.gate();- assert.equal(gate.proceed, true);- assert.deepEqual(f.calls, ['planner', 'planner_localize']);- assert.equal(f.reviewed[0].shown.localized.summary, englishPlan().summary);+ // The planner's own partial copy is not shown either: one language, never a mix.+ const partialCopy = englishPlan({ confidence: 0.5, localized: { locale: 'tr', summary: 'Bültene abone ol.', steps: [{ id: '1', action: 'Doldur.' }], risks: [] } });+ for (const plan of [englishPlan({ confidence: 0.5 }), partialCopy]) {+ for (const translation of [new Error('provider unavailable'), 'not json', incomplete]) {+ const f = displayFixture({ plan, translation });+ const gate = await f.gate();+ assert.equal(gate.proceed, true);+ assert.deepEqual(f.calls, ['planner', 'planner_localize']);+ const shown = f.reviewed[0].shown;+ assert.equal(shown.localized.summary, englishPlan().summary);+ assert.deepEqual(shown.localized.steps.map(step => step.action), englishPlan().steps.map(step => step.action));+ }}});