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
Compare opaque continuation fields exactly and count an explicit empty ref_id as a read
Claude31afdc5003df
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 0f580e326..ec42440af 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -11314,7 +11314,7 @@ export class Agent extends LoopDetector {const allowed = ['filter', 'maxDepth', 'maxChars', 'ref_id', 'page', 'tree_revision'];// Two values agree when they are the same once scalar types and the// case of a filter are normalized, as the call is repaired below.- const normalized = (value, key) => { const scalar = decimal(value); return typeof scalar === 'string' ? (key === 'filter' ? scalar.trim().toLowerCase() : scalar.trim()) : scalar; };+ const normalized = (value, key) => { const scalar = decimal(value); return typeof scalar === 'string' && key === 'filter' ? scalar.trim().toLowerCase() : scalar; };const agrees = (key, value) => !Object.hasOwn(next, key) || Object.is(normalized(next[key], key), normalized(value, key));// Only a truncated result returns a continuation, and it is always for// page 2 or later with a tree revision. One for page 1 without a@@ -11332,7 +11332,7 @@ export class Agent extends LoopDetector {// an anchored one is a placeholder only where the call disagrees with it// (a restart nested alone, or beside fields that agree, is the read).&& (String(continuation.ref_id ?? '').trim() === ''- ? allowed.some(key => key !== 'tree_revision' && String(next[key] ?? '').trim() !== '')+ ? allowed.some(key => key !== 'tree_revision' && (key === 'ref_id' ? Object.hasOwn(next, key) : String(next[key] ?? '').trim() !== '')): Object.entries(continuation).some(([key, value]) => String(next[key] ?? '').trim() !== '' && !agrees(key, value)));if (restart) {delete next.continuationArgs;diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 1cc554e24..f45ccdc0c 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -10992,7 +10992,7 @@ export class Agent extends LoopDetector {const allowed = ['filter', 'maxDepth', 'maxChars', 'ref_id', 'page', 'tree_revision'];// Two values agree when they are the same once scalar types and the// case of a filter are normalized, as the call is repaired below.- const normalized = (value, key) => { const scalar = decimal(value); return typeof scalar === 'string' ? (key === 'filter' ? scalar.trim().toLowerCase() : scalar.trim()) : scalar; };+ const normalized = (value, key) => { const scalar = decimal(value); return typeof scalar === 'string' && key === 'filter' ? scalar.trim().toLowerCase() : scalar; };const agrees = (key, value) => !Object.hasOwn(next, key) || Object.is(normalized(next[key], key), normalized(value, key));// Only a truncated result returns a continuation, and it is always for// page 2 or later with a tree revision. One for page 1 without a@@ -11010,7 +11010,7 @@ export class Agent extends LoopDetector {// an anchored one is a placeholder only where the call disagrees with it// (a restart nested alone, or beside fields that agree, is the read).&& (String(continuation.ref_id ?? '').trim() === ''- ? allowed.some(key => key !== 'tree_revision' && String(next[key] ?? '').trim() !== '')+ ? allowed.some(key => key !== 'tree_revision' && (key === 'ref_id' ? Object.hasOwn(next, key) : String(next[key] ?? '').trim() !== '')): Object.entries(continuation).some(([key, value]) => String(next[key] ?? '').trim() !== '' && !agrees(key, value)));if (restart) {delete next.continuationArgs;diff --git a/test/read-continuation-schema.mjs b/test/read-continuation-schema.mjsindex 2479a42d7..672c3545f 100644--- a/test/read-continuation-schema.mjs+++ b/test/read-continuation-schema.mjs@@ -248,6 +248,15 @@ for (const browser of ['chrome', 'firefox']) {assert.equal(altered.result?.errorCode, 'invalid_tool_arguments');const same = agent._repairToolCallArgs('get_accessibility_tree', { tree_revision: page2.tree_revision, continuationArgs: page2 });assert.equal(same.result, undefined);+ const padded = agent._repairToolCallArgs('get_accessibility_tree', { tree_revision: ` ${page2.tree_revision} `, continuationArgs: page2 });+ assert.equal(padded.result?.errorCode, 'invalid_tool_arguments', 'An opaque revision is not trimmed');+ });++ test(`${browser}: an explicit empty ref_id beside an unanchored page-1 object is a top-level read`, () => {+ const agent = new Agent({ getActive: () => null });+ const repaired = agent._repairToolCallArgs('get_accessibility_tree', { ref_id: '', continuationArgs: { filter: 'interactive', page: 1 } });+ assert.equal(repaired.result, undefined);+ assert.deepEqual(repaired.args, { ref_id: '' });});test(`${browser}: an unanchored or loosely written page-1 object beside a read is a placeholder`, () => {