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
decision model bugfix
Codex release-state test20c15eaaa071
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 318a1bec2..192d68e1a 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -7281,17 +7281,18 @@ export class Agent extends LoopDetector {return image;}- async _jevSettings() {+ async _jevSettings(tabId, provider = this._activeProvider(tabId)) {const stored = await chrome.storage.local.get([...JEV_FAST_KEYS, ...DECISION_SETTINGS_KEYS]);- const decisionConfig = resolveDecisionConfig(stored);+ const compass = provider?.config?.providerName === 'webbrain-cloud' ? provider.config : null;+ const decisionConfig = resolveDecisionConfig(stored, compass);return decisionConfig.enabled && !this.strictSecretMode && (decisionConfig.local || globalThis.navigator?.onLine !== false) ? { ...stored, decisionConfig } : null;}async _jevClassify(tabId, instructions, criteria, state) {const context = this.systemOneContext(tabId);try {- const settings = await this._jevSettings();- if (!settings?.systemOneFastClassifications || this._jevSessions?.get(tabId)?.hardStopped || this._checkAbort(tabId) || !context.isCurrent()) return null;+ const settings = await this._jevSettings(tabId);+ if (settings?.systemOneEnabled !== true || !settings.systemOneFastClassifications || this._jevSessions?.get(tabId)?.hardStopped || this._checkAbort(tabId) || !context.isCurrent()) return null;// Classification receives plain text only; multimodal requests stay with the active provider.if (!state || Object.values(state).some(value => value != null && typeof value !== 'string')) return null;const text = JSON.stringify(state);@@ -7343,7 +7344,7 @@ export class Agent extends LoopDetector {const runSignal = signal || this._runAbortSignal(tabId);const context = this.systemOneContext(tabId);try {- const settings = await this._jevSettings();+ const settings = await this._jevSettings(tabId, provider);if (settings && !this._checkAbort(tabId)) {const verdict = await this.evaluateSystemOne(tabId, createSystemOneJudge({ timeoutMs: 2500, maxRetries: 0 }), {config: settings.decisionConfig, apiKey: settings.typesafeApiKey, signal: runSignal,@@ -7406,7 +7407,7 @@ export class Agent extends LoopDetector {let open = pending();if (open.length) {try {- const settings = await this._jevSettings();+ const settings = await this._jevSettings(tabId, provider);for (const chunk of settings ? semanticBatchChunks(open.map(index => data[index]), SEMANTIC_BATCH_LIMITS.decision) : []) {if (this._checkAbort(tabId)) break;const indexes = chunk.map(position => open[position]);@@ -7586,8 +7587,8 @@ export class Agent extends LoopDetector {if (!['act', 'dev'].includes(mode) || this._checkAbort(tabId)) return null;let session;try {- const settings = await this._jevSettings();- if (!settings?.systemOneFastBrowser || !context.isCurrent()) return null;+ const settings = await this._jevSettings(tabId, provider);+ if (settings?.systemOneEnabled !== true || !settings.systemOneFastBrowser || !context.isCurrent()) return null;let skipReason = '';if (recovery) skipReason = 'recovery_turn';else if (runOptions.cloudRun) skipReason = 'cloud_run';@@ -7674,7 +7675,14 @@ export class Agent extends LoopDetector {async evaluateSystemOne(tabId, client, args, context = this.systemOneContext(tabId)) {const costState = context.costState || this.currentCostState.get(tabId) || this._newCostRunState();+ const activeConfig = this._activeProvider(tabId)?.config;+ const compass = args.config?.provider === 'compass' && activeConfig?.providerName === 'webbrain-cloud' ? activeConfig : null;return client.evaluate({ ...args,+ ...(compass ? {+ headers: { 'X-WebBrain-Device-Id': compass.deviceGuid || '', 'X-WebBrain-Client': 'extension',+ 'X-WebBrain-Help-Improve': compass.helpImproveWebBrain === false ? '0' : '1', ...args.headers },+ metadata: { session_id: this.conversationIds.get(tabId), ...args.metadata },+ } : {}),beforeRequest: async () => {if (this.strictSecretMode || (!args.config?.local && globalThis.navigator?.onLine === false) || context.isCurrent?.() === false) throw new Error('Jev unavailable.');const message = await this._checkCostAllowance(args.config || SYSTEM_ONE_COST_PROVIDER, costState);diff --git a/src/chrome/src/agent/decision-config.js b/src/chrome/src/agent/decision-config.jsindex 04f90a399..0aa4c6ae3 100644--- a/src/chrome/src/agent/decision-config.js+++ b/src/chrome/src/agent/decision-config.js@@ -31,7 +31,7 @@ export function resolveDecisionConfig(stored = {}, compass = null) {if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new Error('Invalid decision endpoint.');const loopback = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);if (url.protocol === 'http:' && !loopback) throw new Error('Decision endpoints require HTTPS outside localhost.');- const apiKey = String(compass?.apiKey || (provider === 'typesafe' ? stored.typesafeApiKey : provider === 'local' ? stored.decisionLocalApiKey : stored.decisionApiKey) || '').trim();+ const apiKey = String((provider === 'compass' ? compass?.apiKey : provider === 'typesafe' ? stored.typesafeApiKey : provider === 'local' ? stored.decisionLocalApiKey : stored.decisionApiKey) || '').trim();const visionMode = compass ? 'auto' : (stored.decisionVisionMode || 'auto');const rate = (value, fallback) => Number.isFinite(value) && value >= 0 ? value : fallback;return {diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex a265e5fdf..b44e9272b 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -7095,17 +7095,18 @@ export class Agent extends LoopDetector {return image;}- async _jevSettings() {+ async _jevSettings(tabId, provider = this._activeProvider(tabId)) {const stored = await browser.storage.local.get([...JEV_FAST_KEYS, ...DECISION_SETTINGS_KEYS]);- const decisionConfig = resolveDecisionConfig(stored);+ const compass = provider?.config?.providerName === 'webbrain-cloud' ? provider.config : null;+ const decisionConfig = resolveDecisionConfig(stored, compass);return decisionConfig.enabled && !this.strictSecretMode && (decisionConfig.local || globalThis.navigator?.onLine !== false) ? { ...stored, decisionConfig } : null;}async _jevClassify(tabId, instructions, criteria, state) {const context = this.systemOneContext(tabId);try {- const settings = await this._jevSettings();- if (!settings?.systemOneFastClassifications || this._jevSessions?.get(tabId)?.hardStopped || this._checkAbort(tabId) || !context.isCurrent()) return null;+ const settings = await this._jevSettings(tabId);+ if (settings?.systemOneEnabled !== true || !settings.systemOneFastClassifications || this._jevSessions?.get(tabId)?.hardStopped || this._checkAbort(tabId) || !context.isCurrent()) return null;// Classification receives plain text only; multimodal requests stay with the active provider.if (!state || Object.values(state).some(value => value != null && typeof value !== 'string')) return null;const text = JSON.stringify(state);@@ -7157,7 +7158,7 @@ export class Agent extends LoopDetector {const runSignal = signal || this._runAbortSignal(tabId);const context = this.systemOneContext(tabId);try {- const settings = await this._jevSettings();+ const settings = await this._jevSettings(tabId, provider);if (settings && !this._checkAbort(tabId)) {const verdict = await this.evaluateSystemOne(tabId, createSystemOneJudge({ timeoutMs: 2500, maxRetries: 0 }), {config: settings.decisionConfig, apiKey: settings.typesafeApiKey, signal: runSignal,@@ -7220,7 +7221,7 @@ export class Agent extends LoopDetector {let open = pending();if (open.length) {try {- const settings = await this._jevSettings();+ const settings = await this._jevSettings(tabId, provider);for (const chunk of settings ? semanticBatchChunks(open.map(index => data[index]), SEMANTIC_BATCH_LIMITS.decision) : []) {if (this._checkAbort(tabId)) break;const indexes = chunk.map(position => open[position]);@@ -7400,8 +7401,8 @@ export class Agent extends LoopDetector {if (!['act', 'dev'].includes(mode) || this._checkAbort(tabId)) return null;let session;try {- const settings = await this._jevSettings();- if (!settings?.systemOneFastBrowser || !context.isCurrent()) return null;+ const settings = await this._jevSettings(tabId, provider);+ if (settings?.systemOneEnabled !== true || !settings.systemOneFastBrowser || !context.isCurrent()) return null;let skipReason = '';if (recovery) skipReason = 'recovery_turn';else if (runOptions.cloudRun) skipReason = 'cloud_run';@@ -7488,7 +7489,14 @@ export class Agent extends LoopDetector {async evaluateSystemOne(tabId, client, args, context = this.systemOneContext(tabId)) {const costState = context.costState || this.currentCostState.get(tabId) || this._newCostRunState();+ const activeConfig = this._activeProvider(tabId)?.config;+ const compass = args.config?.provider === 'compass' && activeConfig?.providerName === 'webbrain-cloud' ? activeConfig : null;return client.evaluate({ ...args,+ ...(compass ? {+ headers: { 'X-WebBrain-Device-Id': compass.deviceGuid || '', 'X-WebBrain-Client': 'extension',+ 'X-WebBrain-Help-Improve': compass.helpImproveWebBrain === false ? '0' : '1', ...args.headers },+ metadata: { session_id: this.conversationIds.get(tabId), ...args.metadata },+ } : {}),beforeRequest: async () => {if (this.strictSecretMode || (!args.config?.local && globalThis.navigator?.onLine === false) || context.isCurrent?.() === false) throw new Error('Jev unavailable.');const message = await this._checkCostAllowance(args.config || SYSTEM_ONE_COST_PROVIDER, costState);diff --git a/src/firefox/src/agent/decision-config.js b/src/firefox/src/agent/decision-config.jsindex 04f90a399..0aa4c6ae3 100644--- a/src/firefox/src/agent/decision-config.js+++ b/src/firefox/src/agent/decision-config.js@@ -31,7 +31,7 @@ export function resolveDecisionConfig(stored = {}, compass = null) {if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new Error('Invalid decision endpoint.');const loopback = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);if (url.protocol === 'http:' && !loopback) throw new Error('Decision endpoints require HTTPS outside localhost.');- const apiKey = String(compass?.apiKey || (provider === 'typesafe' ? stored.typesafeApiKey : provider === 'local' ? stored.decisionLocalApiKey : stored.decisionApiKey) || '').trim();+ const apiKey = String((provider === 'compass' ? compass?.apiKey : provider === 'typesafe' ? stored.typesafeApiKey : provider === 'local' ? stored.decisionLocalApiKey : stored.decisionApiKey) || '').trim();const visionMode = compass ? 'auto' : (stored.decisionVisionMode || 'auto');const rate = (value, fallback) => Number.isFinite(value) && value >= 0 ? value : fallback;return {diff --git a/test/completion-verifier.mjs b/test/completion-verifier.mjsindex 9102ea66d..2f1a1d16d 100644--- a/test/completion-verifier.mjs+++ b/test/completion-verifier.mjs@@ -44,6 +44,26 @@ for (const build of ['chrome', 'firefox']) {const compass = config.resolveDecisionConfig({ decisionProvider: 'local', systemOneDoneEnabled: false }, { baseUrl: 'https://api.webbrain.one/v1' });assert.equal(compass.provider, 'compass'); assert.equal(compass.enabled, true); assert.equal(compass.doneEnabled, true);});+ test(`${build}: Compass credentials never fall back to saved decision-provider keys`, async () => {+ const saved = { systemOneEnabled: false, decisionApiKey: 'saved-openrouter-key',+ typesafeApiKey: 'saved-typesafe-key', decisionLocalApiKey: 'saved-local-key' };+ for (const decisionProvider of ['openrouter', 'typesafe', 'local']) {+ for (const apiKey of [undefined, '', ' ', 'managed-compass-key']) {+ const selected = config.resolveDecisionConfig({ ...saved, decisionProvider }, { baseUrl: 'https://api.webbrain.one/v1', apiKey });+ assert.equal(selected.apiKey, (apiKey || '').trim());+ let request;+ const client = judge.createSystemOneJudge({ fetchImpl: async (url, options) => {+ request = { url, ...options };+ return { ok: true, json: async () => response() };+ } });+ await client.evaluate({ config: selected, apiKey: saved.typesafeApiKey, state: {}, questions: verifier.completionQuestions() });+ assert.equal(request.url, 'https://api.webbrain.one/v1/decisions');+ assert.equal(request.headers.Authorization, selected.apiKey ? `Bearer ${selected.apiKey}` : undefined);+ }+ const byo = config.resolveDecisionConfig({ ...saved, decisionProvider, systemOneEnabled: true });+ assert.equal(byo.apiKey, decisionProvider === 'typesafe' ? saved.typesafeApiKey : decisionProvider === 'local' ? saved.decisionLocalApiKey : saved.decisionApiKey);+ }+ });// The judge answers every question it is asked: the outcome, and the two// side questions about later outcomes and the candidate summary.const side = (choices, choice) => ({ type: 'choice', choice, confidence: .95,diff --git a/test/systemone-fast.mjs b/test/systemone-fast.mjsindex e061a1905..9ce1f806b 100644--- a/test/systemone-fast.mjs+++ b/test/systemone-fast.mjs@@ -8,12 +8,95 @@ for (const build of ['chrome', 'firefox']) {const mod = await import(`../src/${build}/src/agent/systemone-fast.js`);const { Agent } = await import(`../src/${build}/src/agent/agent.js`);const config = await import(`../src/${build}/src/config-transfer.js`);+ test(`${build}: Compass semantic checks use decisions with device, consent and session context`, async () => {+ const saved = { ...storage }, originalFetch = globalThis.fetch;+ for (const key of Object.keys(storage)) delete storage[key];+ Object.assign(storage, { systemOneEnabled: false, decisionProvider: 'openrouter',+ decisionApiKey: 'saved-openrouter-key', typesafeApiKey: 'saved-typesafe-key', decisionLocalApiKey: 'saved-local-key' });+ const provider = { model: 'webbrain-cloud 1.0', config: { providerName: 'webbrain-cloud',+ baseUrl: 'https://api.webbrain.one/v1', deviceGuid: 'decision-test-device', helpImproveWebBrain: false },+ chat: async () => { throw Error('Confident decisions must not call chat'); } };+ const agent = new Agent({ getActive: () => provider });+ agent.conversationIds.set(1, 'decision-test-session');+ agent._checkCostAllowance = async () => null;+ agent._recordCostUsage = async () => null;+ const requests = [];+ globalThis.fetch = async (url, options) => {+ const body = JSON.parse(options.body);+ requests.push({ url, ...options, body });+ const answers = Object.fromEntries(Object.entries(body.questions).map(([id, question]) => {+ const keys = Object.keys(question.criteria), selected = 'not_requested';+ return [id, { type: 'choice', choice: selected, confidence: .99,+ probabilities: Object.fromEntries(keys.map(key => [key, key === selected ? .99 : .01 / (keys.length - 1)])) }];+ }));+ return { ok: true, json: async () => ({ model: body.model, answers,+ usage: { input_tokens: 20, output_tokens: 0, cost: .000001 } }) };+ };+ try {+ const result = await agent._semanticDecision(1, 'deletion_request', { request: 'Read this post', page: { item: 'QA post' } });+ assert.equal(result.source, 'decision_model');+ assert.equal(result.choice, 'not_requested');+ const batch = await agent._semanticDecisions(1, 'deletion_request', { request: 'Read these posts', items: [{ item: 'Another QA post' }] });+ assert.equal(batch[0].source, 'decision_model');+ assert.equal(requests.length, 2);+ for (const request of requests) {+ assert.equal(request.url, 'https://api.webbrain.one/v1/decisions');+ assert.equal(request.body.model, 'perplexity/pplx-decider-v1-27b');+ assert.equal(request.headers['X-WebBrain-Device-Id'], 'decision-test-device');+ assert.equal(request.headers['X-WebBrain-Help-Improve'], '0');+ assert.equal(request.headers['X-WebBrain-Client'], 'extension');+ assert.equal(request.headers.Authorization, undefined, 'Saved BYO credentials must stay out of Compass requests');+ assert.equal(request.body.session_id, 'decision-test-session');+ }+ assert.equal((await agent._jevSettings(1, { config: {} })), null, 'Other providers keep their opt-in requirement');+ agent.strictSecretMode = true;+ assert.equal(await agent._jevSettings(1), null);+ } finally {+ globalThis.fetch = originalFetch;+ for (const key of Object.keys(storage)) delete storage[key];+ Object.assign(storage, saved);+ }+ });const snapshot = () => ({ documentToken: 'doc', pageUrl: 'http://jev.local/', structure: 'form', progress: 'initial', controls: [{ ref: 'ref_1', name: 'Name', role: 'textbox', kinds: ['fill'], value: '', signature: 'name' },{ ref: 'ref_2', name: 'Email', role: 'textbox', kinds: ['fill'], value: '', signature: 'email' },{ ref: 'ref_3', name: 'Send', role: 'button', kinds: ['click'], signature: 'send' },{ ref: 'ref_4', name: 'City', role: 'combobox', kinds: ['select'], signature: 'city', options: [{ value: '34', label: 'Istanbul' }] },] });+ test(`${build}: Compass master opt-out blocks optional fast calls and queued actions`, async () => {+ const saved = { ...storage };+ for (const key of Object.keys(storage)) delete storage[key];+ Object.assign(storage, { systemOneFastBrowser: true, systemOneFastClassifications: true });+ const provider = { model: 'webbrain-cloud 1.0', config: { providerName: 'webbrain-cloud', baseUrl: 'https://api.webbrain.one/v1' } };+ const agent = new Agent({ getActive: () => provider });+ const session = new mod.JevFastSession(); session.observe(snapshot()); agent._jevSessions = new Map([[1, session]]);+ let calls = 0;+ agent.evaluateSystemOne = async () => {+ calls++;+ return { answers: { classification: choice('yes'), operation: choice('click'), click_target: choice('ref_3') } };+ };+ const classify = () => agent._jevClassify(1, 'Classify this request', { yes: 'yes', no: 'no' }, { task: 'Read the page' });+ const turn = () => agent._maybeJevFastTurn(1, 'Click Send', [], 'act', new Set(['get_accessibility_tree', 'click_ax']), provider, {});+ try {+ storage.systemOneEnabled = true;+ assert.equal(await classify(), 'yes');+ assert.equal((await turn()).toolCalls[0].function.name, 'click_ax');+ assert.equal(calls, 2, 'Explicit opt-in still enables optional fast paths');+ session.pending = null;+ session.queue = [{ name: 'click_ax', args: { ref_id: 'ref_3' } }];+ for (const master of [false, undefined]) {+ if (master === undefined) delete storage.systemOneEnabled;+ else storage.systemOneEnabled = master;+ assert.equal(await classify(), null);+ assert.equal(await turn(), null);+ }+ assert.equal(calls, 2, 'Disabled or unset master switch must prevent all optional judge calls');+ assert.equal(session.queue.length, 1, 'The fast path must not consume a queued action after opt-out');+ } finally {+ for (const key of Object.keys(storage)) delete storage[key];+ Object.assign(storage, saved);+ }+ });test(`${build}: browser requests omit unsupported operations and one-option target questions`, () => {const google = {documentToken: 'google-home', pageUrl: 'https://www.google.com/', structure: 'search', progress: 'initial', controls: [