Skip to content

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

Settings: keep the model and key fields locked for D1 as well as the chat model

Claude5b0a0e461e36
diff --git a/src/chrome/src/ui/settings.js b/src/chrome/src/ui/settings.js
index 3200871ea..407d84930 100644
--- a/src/chrome/src/ui/settings.js
+++ b/src/chrome/src/ui/settings.js
@@ -241,15 +241,20 @@ const decisionKeyDrafts = new Map();
let previousDecisionProvider = 'openrouter';
// Decision providers that run locally and need no API key.
const LOCAL_DECISION_PROVIDERS = ['local', 'webgpu_d1', 'webgpu_chat'];
+// In-browser decision providers with a fixed model and no API key.
+const FIXED_WEBGPU_DECISION_PROVIDERS = ['webgpu_d1', 'webgpu_chat'];
// The in-browser chat model's decision mode has a fixed model and a note.
+// Runs after d1-settings.js on load and on every provider change, so it
+// owns the locked state for both fixed providers.
function syncWebgpuDecisionProvider() {
const selected = decisionProviderInput?.value === 'webgpu_chat';
+ const fixed = FIXED_WEBGPU_DECISION_PROVIDERS.includes(decisionProviderInput?.value);
const note = document.getElementById('webgpu-decision-note');
if (note) note.hidden = !selected;
if (selected) decisionModelInput.value = WEBGPU_CHAT_DECISION_MODEL;
- // Restore both controls when another provider is chosen.
- if (decisionModelInput) decisionModelInput.readOnly = selected;
- if (systemOneApiKeyInput) systemOneApiKeyInput.disabled = selected;
+ // Lock both controls for D1 and the chat model; restore them otherwise.
+ if (decisionModelInput) decisionModelInput.readOnly = fixed;
+ if (systemOneApiKeyInput) systemOneApiKeyInput.disabled = fixed;
}
const systemOneApiKeyInput = document.getElementById('system-one-api-key');
@@ -1644,6 +1649,7 @@ if (btnClearSystemOne) {
updateSystemOneThresholdLabels();
await sendToBackground('d1_control', { command: 'reset' }).catch(() => {});
await refreshD1Settings();
+ syncWebgpuDecisionProvider();
showSystemOneResult('ok', t('st.captcha.cleared'));
});
}
diff --git a/test/webgpu-decisions.mjs b/test/webgpu-decisions.mjs
index 6c054894c..2dbddf616 100644
--- a/test/webgpu-decisions.mjs
+++ b/test/webgpu-decisions.mjs
@@ -304,10 +304,19 @@ test('in-browser decisions get their own timeout unless a caller sets a shorter
}
});
-test('Settings restores the model and key fields after leaving the chat-model provider', async () => {
+test('Settings locks the model and key fields for both fixed in-browser providers and restores them otherwise', async () => {
const settings = await readFile(new URL('../src/chrome/src/ui/settings.js', import.meta.url), 'utf8');
const sync = settings.slice(settings.indexOf('function syncWebgpuDecisionProvider'), settings.indexOf('const systemOneApiKeyInput'));
- assert.match(sync, /decisionModelInput\.readOnly = selected;/);
- assert.match(sync, /systemOneApiKeyInput\.disabled = selected;/);
+ assert.match(settings, /const FIXED_WEBGPU_DECISION_PROVIDERS = \['webgpu_d1', 'webgpu_chat'\];/);
+ assert.match(sync, /const fixed = FIXED_WEBGPU_DECISION_PROVIDERS\.includes\(decisionProviderInput\?\.value\);/);
+ assert.match(sync, /decisionModelInput\.readOnly = fixed;/);
+ assert.match(sync, /systemOneApiKeyInput\.disabled = fixed;/);
assert.doesNotMatch(sync, /= true;/, 'nothing is locked only one way');
+ // d1-settings.js also sets these fields for D1 only; the sync must run after it.
+ const awaited = [...settings.matchAll(/await refreshD1Settings\(\);\n\s*(\S+)/g)].map(match => match[1]);
+ assert.deepEqual(awaited, ['syncWebgpuDecisionProvider();', 'syncWebgpuDecisionProvider();'], 'load and Clear re-sync after D1');
+ const change = settings.slice(settings.indexOf("decisionProviderInput?.addEventListener('change'"));
+ assert.match(change.slice(0, change.indexOf('});')), /syncWebgpuDecisionProvider\(\);/);
+ assert.ok(settings.indexOf('initD1Settings(sendToBackground)') < settings.indexOf("decisionProviderInput?.addEventListener('change'"),
+ "D1's change listener is registered first, so this one runs last");
});