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
Don't show the previous provider's result on a new selection
Emre Sokulluf252b4a7b738
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.jsindex 0542b7a42..df31c0014 100644--- a/src/chrome/src/ui/sidepanel.js+++ b/src/chrome/src/ui/sidepanel.js@@ -735,6 +735,8 @@ const statusDot = document.getElementById('status-dot');// says the live status again (syncProviderPickerButton) instead of a fixed// first value.let statusDotTitle = () => t('sp.status.disconnected');+// The provider whose state the dot shows (the selected one when it was set).+let statusDotProviderId = null;if (statusDot) statusDot.title = statusDotTitle();// Short labels for the closed picker button (menu rows keep the longer status text).const providerPickerLabelById = new Map();@@ -8362,9 +8364,12 @@ function syncProviderPickerButton() {providerPickerBtn.title = label;providerPickerBtn.setAttribute('aria-label', label);}- // The dot's title is the button's description: a language change renders the- // name again here, so it says the live status again too.- if (statusDot) statusDot.title = statusDotTitle();+ // The dot is part of the button. When the selection has moved to another+ // provider (here or from Settings), the last result belongs to the old one:+ // show this one as untested until its own check. Otherwise say the live+ // status again, which also follows a language change.+ if (statusDot && statusDotProviderId !== id) markSelectedProviderUntested();+ else if (statusDot) statusDot.title = statusDotTitle();if (providerPickerMenu) {providerPickerMenu.querySelectorAll('.provider-picker-option').forEach((btn) => {btn.setAttribute('aria-selected', btn.dataset.value === id ? 'true' : 'false');@@ -8766,6 +8771,7 @@ async function testConnection(options = {}) {function setStatusDot(state, title) {statusDot.className = state ? `status-dot ${state}` : 'status-dot';statusDotTitle = title;+ statusDotProviderId = providerSelect?.value ?? null;statusDot.title = title();}@@ -16352,6 +16358,9 @@ providerSelect.addEventListener('change', async () => {syncProviderPickerButton();const requestId = ++providerSelectionRequestId;providerTestRequestId += 1;+ // The button already names the new provider: while it is activated and+ // checked, its status says so rather than the previous provider's result.+ setStatusDot('connecting', () => t('sp.status.connecting'));try {await setActiveChatProvider(providerId);} catch (e) {diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.jsindex aa57289f0..394a3ad56 100644--- a/src/firefox/src/ui/sidepanel.js+++ b/src/firefox/src/ui/sidepanel.js@@ -610,6 +610,8 @@ const statusDot = document.getElementById('status-dot');// says the live status again (syncProviderPickerButton) instead of a fixed// first value.let statusDotTitle = () => t('sp.status.disconnected');+// The provider whose state the dot shows (the selected one when it was set).+let statusDotProviderId = null;if (statusDot) statusDot.title = statusDotTitle();// Short labels for the closed picker button (menu rows keep the longer status text).const providerPickerLabelById = new Map();@@ -8192,9 +8194,12 @@ function syncProviderPickerButton() {providerPickerBtn.title = label;providerPickerBtn.setAttribute('aria-label', label);}- // The dot's title is the button's description: a language change renders the- // name again here, so it says the live status again too.- if (statusDot) statusDot.title = statusDotTitle();+ // The dot is part of the button. When the selection has moved to another+ // provider (here or from Settings), the last result belongs to the old one:+ // show this one as untested until its own check. Otherwise say the live+ // status again, which also follows a language change.+ if (statusDot && statusDotProviderId !== id) markSelectedProviderUntested();+ else if (statusDot) statusDot.title = statusDotTitle();if (providerPickerMenu) {providerPickerMenu.querySelectorAll('.provider-picker-option').forEach((btn) => {btn.setAttribute('aria-selected', btn.dataset.value === id ? 'true' : 'false');@@ -8547,6 +8552,7 @@ async function testConnection(options = {}) {function setStatusDot(state, title) {statusDot.className = state ? `status-dot ${state}` : 'status-dot';statusDotTitle = title;+ statusDotProviderId = providerSelect?.value ?? null;statusDot.title = title();}@@ -15821,6 +15827,9 @@ providerSelect.addEventListener('change', async () => {syncProviderPickerButton();const requestId = ++providerSelectionRequestId;providerTestRequestId += 1;+ // The button already names the new provider: while it is activated and+ // checked, its status says so rather than the previous provider's result.+ setStatusDot('connecting', () => t('sp.status.connecting'));try {await sendToBackground('set_active_provider', { providerId });} catch (e) {diff --git a/test/model-picker-icon.mjs b/test/model-picker-icon.mjsindex 8e4161776..b3f82a9cb 100644--- a/test/model-picker-icon.mjs+++ b/test/model-picker-icon.mjs@@ -45,6 +45,8 @@ for (const build of ['chrome', 'firefox']) {providerPickerMenu: { querySelectorAll: () => options },statusDot: { title: '' },statusDotTitle: () => en['sp.status.connecting'],+ statusDotProviderId: 'openrouter',+ markSelectedProviderUntested() {},});vm.runInContext(extract(panel, 'syncProviderPickerButton'), context);context.syncProviderPickerButton();@@ -113,6 +115,7 @@ for (const build of ['chrome', 'firefox']) {providerPickerBtn: { title: '', setAttribute() {} },providerPickerMenu: null,statusDot: { className: 'status-dot offline', title: '' },+ statusDotProviderId: null,sendToBackground: async () => new Promise((resolve) => { answer = resolve; }),});vm.runInContext(['setStatusDot', 'testConnection', 'syncProviderPickerButton', 'markSelectedProviderFailed', 'markSelectedProviderUntested']@@ -139,6 +142,70 @@ for (const build of ['chrome', 'firefox']) {});}+for (const build of ['chrome', 'firefox']) {+ test(`${build}: picking another provider never shows the previous provider's result`, async () => {+ const en = (await import(`../src/${build}/src/ui/locales/en.js`)).default;+ const panel = read(build, 'src/ui/sidepanel.js');+ const pending = {};+ const options = { openrouter: 'OpenRouter — Active', local: 'Local proxy — Active' };+ const providerSelect = {+ value: 'openrouter',+ get selectedOptions() { return [{ textContent: options[this.value] }]; },+ };+ const wait = (name) => new Promise((resolve) => { pending[name] = resolve; });+ const context = vm.createContext({+ t: (key, params = {}) => String(en[key] || key).replace(/\{(\w+)\}/g, (_, k) => params[k] ?? ''),+ providerSelect,+ MORE_PROVIDERS_OPTION_VALUE: '__more_providers__',+ selectedProviderId: 'openrouter',+ providerSelectionRequestId: 0,+ providerTestRequestId: 0,+ providerPickerLabel: { textContent: '' },+ providerPickerLabelById: new Map([['openrouter', 'OpenRouter'], ['local', 'Local proxy']]),+ providerPickerModelById: new Map(),+ providerPickerBtn: { title: '', setAttribute() {} },+ providerPickerMenu: null,+ statusDot: { className: 'status-dot offline', title: '' },+ statusDotProviderId: null,+ setActiveChatProvider: () => wait('activate'),+ sendToBackground: (action) => wait(action === 'set_active_provider' ? 'activate' : 'test'),+ openProvidersSettingsPage: async () => {},+ });+ vm.runInContext(['setStatusDot', 'testConnection', 'syncProviderPickerButton', 'markSelectedProviderFailed', 'markSelectedProviderUntested']+ .map((name) => extract(panel, name)).join('\n'), context);+ const start = panel.indexOf("providerSelect.addEventListener('change', async () => {");+ const handler = vm.runInContext(`(${panel.slice(panel.indexOf('async () => {', start), panel.indexOf('\n});', start) + 2)})`, context);+ const dot = () => [context.statusDot.className, context.statusDot.title];++ // OpenRouter was checked and answered.+ const first = context.testConnection();+ pending.test({ ok: true, model: 'openai/gpt-6-luna' });+ await first;+ assert.deepEqual(dot(), ['status-dot online', 'Connected (openai/gpt-6-luna)']);++ // The user picks the local proxy: while it is activated, the button that+ // now names it says the check is under way, not OpenRouter's result.+ providerSelect.value = 'local';+ const change = handler();+ assert.deepEqual(dot(), ['status-dot connecting', 'Checking connection…']);+ pending.activate({ ok: true });+ await new Promise((resolve) => setImmediate(resolve));+ assert.deepEqual(dot(), ['status-dot connecting', 'Checking connection…'], 'then its own check runs');+ pending.test({ ok: false, error: 'connect ECONNREFUSED' });+ await change;+ assert.deepEqual(dot(), ['status-dot offline', 'Error: connect ECONNREFUSED']);++ // Settings switches back to OpenRouter: loadProviders() selects it and+ // syncs the button, with no check of its own, so the local proxy's+ // error is not shown for OpenRouter.+ providerSelect.value = 'openrouter';+ context.syncProviderPickerButton();+ assert.deepEqual(dot(), ['status-dot', 'OpenRouter — Active']);+ context.syncProviderPickerButton();+ assert.deepEqual(dot(), ['status-dot', 'OpenRouter — Active'], 'and stays so');+ });+}+test('every language names the active model', async () => {for (const build of ['chrome', 'firefox']) {for (const code of ['en', 'tr', 'es', 'fr', 'de', 'nl', 'pt', 'pl', 'ru', 'uk', 'zh', 'ja', 'ko', 'ar', 'he', 'fa', 'hi', 'bn', 'id', 'ms', 'tl', 'th', 'vi']) {diff --git a/test/run.js b/test/run.jsindex 7bcd70374..ba385a974 100644--- a/test/run.js+++ b/test/run.js@@ -50392,6 +50392,8 @@ test('sidepanel drops stale provider selection and connection checks', () => {? 'setActiveChatProvider(latestProviderId).catch(() => {});': "sendToBackground('set_active_provider', { providerId: latestProviderId }).catch(() => {});");const changeTestIdx = changeBody.indexOf('await testConnection({ providerId });');+ const changeCheckingIdx = changeBody.indexOf("setStatusDot('connecting', () => t('sp.status.connecting'));");+ assert.ok(invalidateIdx < changeCheckingIdx && changeCheckingIdx < activateIdx, `${label}: a provider change says it is checking before the activation request, not the previous provider's result`);assert.notEqual(changeCaptureIdx, -1, `${label}: provider change should capture the intended provider`);assert.notEqual(changeRequestIdx, -1, `${label}: provider change should increment a request sequence`);assert.notEqual(invalidateIdx, -1, `${label}: provider change should invalidate pending provider tests`);