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
Normalize the page before classifying a placeholder and drop an unanchored one beside a read
Claude473284ed9e89
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 748685900..0630d4034 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -11325,13 +11325,15 @@ export class Agent extends LoopDetector {const restart = continuation && typeof continuation === 'object' && !Array.isArray(continuation)&& Object.keys(continuation).length > 0 && Object.keys(continuation).every(key => allowed.includes(key))&& !String(continuation.tree_revision ?? '').trim() && !String(next.tree_revision ?? '').trim()- && [undefined, null, '', 1, '1'].includes(continuation.page)- // It is a placeholder only beside a read of the call's own that it- // disagrees with. A restart nested alone, or beside top-level fields- // that agree with it (a partial copy), is the restart the tool- // returned (page 1 of an anchored subtree after its revision changed),- // and it is the read.- && Object.entries(continuation).some(([key, value]) => String(next[key] ?? '').trim() !== '' && !agrees(key, value));+ && [undefined, null, '', 1].includes(normalized(continuation.page))+ // It is a placeholder only beside a read of the call's own. A restart+ // the tool returns is always anchored (it names a ref_id), so one that+ // names none cannot be genuine and is dropped beside any top-level read;+ // 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() !== '')+ : Object.entries(continuation).some(([key, value]) => String(next[key] ?? '').trim() !== '' && !agrees(key, value)));if (restart) {delete next.continuationArgs;repaired = true;diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 2b248dbdc..3a06438c9 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -11003,13 +11003,15 @@ export class Agent extends LoopDetector {const restart = continuation && typeof continuation === 'object' && !Array.isArray(continuation)&& Object.keys(continuation).length > 0 && Object.keys(continuation).every(key => allowed.includes(key))&& !String(continuation.tree_revision ?? '').trim() && !String(next.tree_revision ?? '').trim()- && [undefined, null, '', 1, '1'].includes(continuation.page)- // It is a placeholder only beside a read of the call's own that it- // disagrees with. A restart nested alone, or beside top-level fields- // that agree with it (a partial copy), is the restart the tool- // returned (page 1 of an anchored subtree after its revision changed),- // and it is the read.- && Object.entries(continuation).some(([key, value]) => String(next[key] ?? '').trim() !== '' && !agrees(key, value));+ && [undefined, null, '', 1].includes(normalized(continuation.page))+ // It is a placeholder only beside a read of the call's own. A restart+ // the tool returns is always anchored (it names a ref_id), so one that+ // names none cannot be genuine and is dropped beside any top-level read;+ // 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() !== '')+ : Object.entries(continuation).some(([key, value]) => String(next[key] ?? '').trim() !== '' && !agrees(key, value)));if (restart) {delete next.continuationArgs;repaired = true;diff --git a/test/read-continuation-schema.mjs b/test/read-continuation-schema.mjsindex 14ed9197a..dfb66d035 100644--- a/test/read-continuation-schema.mjs+++ b/test/read-continuation-schema.mjs@@ -241,6 +241,20 @@ for (const browser of ['chrome', 'firefox']) {}});+ test(`${browser}: an unanchored or loosely written page-1 object beside a read is a placeholder`, () => {+ const agent = new Agent({ getActive: () => null });+ // No ref_id: the tool never returns such a restart, so the top-level read stands.+ const partial = agent._repairToolCallArgs('get_accessibility_tree', { filter: 'all', continuationArgs: { maxDepth: 1, page: 1 } });+ assert.equal(partial.result, undefined);+ assert.deepEqual(partial.args, { filter: 'all' });+ for (const page of [' 1 ', '1.0', '01'.slice(1)]) {+ const loose = agent._repairToolCallArgs('get_accessibility_tree', { filter: 'all', maxDepth: 8,+ continuationArgs: { filter: 'visible', maxDepth: 15, page } });+ assert.equal(loose.result, undefined, JSON.stringify(page));+ assert.equal(loose.args.maxDepth, 8, JSON.stringify(page));+ }+ });+test(`${browser}: oversized declared prose windows are bounded without losing the requested document position`, () => {const agent = new Agent({ getActive: () => null });const schema = getToolsForMode('act', { tier: 'full' })