Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Count a planner copy as localized only when it names its language

Emre Sokulluea15dbc03918
diff --git a/src/chrome/src/agent/planner.js b/src/chrome/src/agent/planner.js
index 94286872e..9ddf78ebf 100644
--- a/src/chrome/src/agent/planner.js
+++ b/src/chrome/src/agent/planner.js
@@ -1197,10 +1197,12 @@ export function normalizePlan(obj, opts = {}) {
: [];
const requestedLocale = normalizePlannerLocale(opts.locale || localizedInput.locale);
const englishLocale = requestedLocale === 'en' || requestedLocale.startsWith('en-');
- // The copy is in the requested language and covers the summary, every step
- // and every risk.
+ // The copy names the requested language and covers the summary, every step
+ // and every risk. A copy without a locale tag proves no language (output
+ // without schema enforcement can leave it out).
const localizedCopyComplete = Boolean(localizedSummary)
- && (!localizedInput.locale || localeLanguage(localizedInput.locale) === localeLanguage(requestedLocale))
+ && localeLanguage(localizedInput.locale) !== ''
+ && localeLanguage(localizedInput.locale) === localeLanguage(requestedLocale)
&& steps.every(step => localizedStepsById.get(step.id)?.action)
&& riskEntries.every(entry => sanitizeText(providedLocalizedRisks[entry.sourceIndex], 200));
if (opts.requireIntent) {
diff --git a/src/firefox/src/agent/planner.js b/src/firefox/src/agent/planner.js
index 94286872e..9ddf78ebf 100644
--- a/src/firefox/src/agent/planner.js
+++ b/src/firefox/src/agent/planner.js
@@ -1197,10 +1197,12 @@ export function normalizePlan(obj, opts = {}) {
: [];
const requestedLocale = normalizePlannerLocale(opts.locale || localizedInput.locale);
const englishLocale = requestedLocale === 'en' || requestedLocale.startsWith('en-');
- // The copy is in the requested language and covers the summary, every step
- // and every risk.
+ // The copy names the requested language and covers the summary, every step
+ // and every risk. A copy without a locale tag proves no language (output
+ // without schema enforcement can leave it out).
const localizedCopyComplete = Boolean(localizedSummary)
- && (!localizedInput.locale || localeLanguage(localizedInput.locale) === localeLanguage(requestedLocale))
+ && localeLanguage(localizedInput.locale) !== ''
+ && localeLanguage(localizedInput.locale) === localeLanguage(requestedLocale)
&& steps.every(step => localizedStepsById.get(step.id)?.action)
&& riskEntries.every(entry => sanitizeText(providedLocalizedRisks[entry.sourceIndex], 200));
if (opts.requireIntent) {
diff --git a/test/plan-when-needed.mjs b/test/plan-when-needed.mjs
index 0345abb8c..6905dc9b4 100644
--- a/test/plan-when-needed.mjs
+++ b/test/plan-when-needed.mjs
@@ -311,6 +311,7 @@ for (const build of BUILDS) {
assert.equal('missing' in parse(englishPlan({ risks: ['The form is submitted.'], localized: { ...copy, risks: ['Form gönderilir.'] } }), { locale: 'tr' }).localized, false);
// A copy in another language is no copy in the user's.
assert.equal(parse(englishPlan({ localized: { ...copy, locale: 'en' } }), { locale: 'tr' }).localized.missing, true);
+ assert.equal(parse(englishPlan({ localized: { ...copy, locale: undefined } }), { locale: 'tr' }).localized.missing, true, 'a copy that names no language proves none');
assert.equal('missing' in parse(englishPlan({ localized: { ...copy, locale: 'tr-TR' } }), { locale: 'tr' }).localized, false);
});