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
Keep the authored-text normalizer private to agent.js
Barack Sokullu306651574a5b
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 18660a632..6d5e63912 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -73,7 +73,7 @@ import {shouldInvalidateFormInventoryAfterAction,workflowRequiredRowsAreProcessed,} from './adapter-workflow-evidence.js';-import { messageTargetMatchesObservedIdentities, messageRecipientUploadSourceKey, normalizeMessageTarget, normalizeRecipientAnswer, normalizeRecipientIdentity } from './message-recipient-guard.js';+import { messageTargetMatchesObservedIdentities, messageRecipientUploadSourceKey, normalizeMessageTarget, normalizeRecipientIdentity } from './message-recipient-guard.js';import { advanceChatSession, chatRunEndedNotice, createOwnedNativeChatReadRepair, createChatSession, decideChatSend, markChatSendPending, normalizeChatSession, normalizeChatSnapshot, normalizeNativeOpaqueBaseline, serializeChatSession } from './chat-workflow.js';import {fetchUrl,@@ -864,6 +864,22 @@ function collectVisibleInteractiveElements(maxEl) {return out;}+// The user's own task text, normalized like a recipient identity (NFKC,+// lowercase, collapsed whitespace) so an identity can be found inside it.+function normalizeAuthoredRecipientText(value) {+ const text = String(value ?? '')+ .replace(/[\u0000-\u001f\u007f]/g, ' ')+ .replace(/[\u200b-\u200d\ufeff]/g, '')+ .replace(/\s+/g, ' ')+ .trim();+ if (!text) return '';+ try {+ return text.normalize('NFKC').toLocaleLowerCase();+ } catch {+ return text.toLowerCase();+ }+}+export class Agent extends LoopDetector {constructor(providerManager) {super();@@ -24797,7 +24813,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// Semantic intent is necessary but cannot invent a named destination.// The fresh authenticated task must itself contain each exact identity;// a page title, OCR, prior turn or address suffix cannot provide it.- const authored = normalizeRecipientAnswer(this._plannerUserAuthoredText(enriched)).slice(0, 100000);+ const authored = normalizeAuthoredRecipientText(this._plannerUserAuthoredText(enriched)).slice(0, 100000);const tokenChar = /[\p{L}\p{N}@._%+-]/u;const present = plan.messaging.recipients.every(recipient => {const identity = normalizeRecipientIdentity(recipient.identity);diff --git a/src/chrome/src/agent/message-recipient-guard.js b/src/chrome/src/agent/message-recipient-guard.jsindex a388f6a24..740612820 100644--- a/src/chrome/src/agent/message-recipient-guard.js+++ b/src/chrome/src/agent/message-recipient-guard.js@@ -81,22 +81,6 @@ export function normalizeRecipientIdentity(value) {}}-// Free text (a user's task or answer) normalized the same way as identities,-// so an identity can be found inside it with indexOf.-export function normalizeRecipientAnswer(value) {- const text = String(value ?? '')- .replace(/[\u0000-\u001f\u007f]/g, ' ')- .replace(/[\u200b-\u200d\ufeff]/g, '')- .replace(/\s+/g, ' ')- .trim();- if (!text) return '';- try {- return text.normalize('NFKC').toLocaleLowerCase();- } catch {- return text.toLowerCase();- }-}-export function recipientMatchesObservedIdentity(recipient, observedIdentity) {const expected = normalizeRecipientIdentity(recipient);const observed = normalizeRecipientIdentity(observedIdentity);diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex d07a237e1..b048e117f 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -71,7 +71,7 @@ import {shouldInvalidateFormInventoryAfterAction,workflowRequiredRowsAreProcessed,} from './adapter-workflow-evidence.js';-import { messageTargetMatchesObservedIdentities, messageRecipientUploadSourceKey, normalizeMessageTarget, normalizeRecipientAnswer, normalizeRecipientIdentity } from './message-recipient-guard.js';+import { messageTargetMatchesObservedIdentities, messageRecipientUploadSourceKey, normalizeMessageTarget, normalizeRecipientIdentity } from './message-recipient-guard.js';import { advanceChatSession, chatRunEndedNotice, createOwnedNativeChatReadRepair, createChatSession, decideChatSend, markChatSendPending, normalizeChatSession, normalizeChatSnapshot, normalizeNativeOpaqueBaseline, serializeChatSession } from './chat-workflow.js';import {fetchUrl,@@ -589,6 +589,22 @@ function unavailableHtmlFormVerification(scope, matchingFrameCount = 1) {const OWNED_NATIVE_CHAT_READ_REPAIR = Symbol('owned-native-chat-read-repair');+// The user's own task text, normalized like a recipient identity (NFKC,+// lowercase, collapsed whitespace) so an identity can be found inside it.+function normalizeAuthoredRecipientText(value) {+ const text = String(value ?? '')+ .replace(/[\u0000-\u001f\u007f]/g, ' ')+ .replace(/[\u200b-\u200d\ufeff]/g, '')+ .replace(/\s+/g, ' ')+ .trim();+ if (!text) return '';+ try {+ return text.normalize('NFKC').toLocaleLowerCase();+ } catch {+ return text.toLowerCase();+ }+}+export class Agent extends LoopDetector {constructor(providerManager) {super();@@ -22167,7 +22183,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// Semantic intent is necessary but cannot invent a named destination.// The fresh authenticated task must itself contain each exact identity;// a page title, OCR, prior turn or address suffix cannot provide it.- const authored = normalizeRecipientAnswer(this._plannerUserAuthoredText(enriched)).slice(0, 100000);+ const authored = normalizeAuthoredRecipientText(this._plannerUserAuthoredText(enriched)).slice(0, 100000);const tokenChar = /[\p{L}\p{N}@._%+-]/u;const present = plan.messaging.recipients.every(recipient => {const identity = normalizeRecipientIdentity(recipient.identity);diff --git a/src/firefox/src/agent/message-recipient-guard.js b/src/firefox/src/agent/message-recipient-guard.jsindex a388f6a24..740612820 100644--- a/src/firefox/src/agent/message-recipient-guard.js+++ b/src/firefox/src/agent/message-recipient-guard.js@@ -81,22 +81,6 @@ export function normalizeRecipientIdentity(value) {}}-// Free text (a user's task or answer) normalized the same way as identities,-// so an identity can be found inside it with indexOf.-export function normalizeRecipientAnswer(value) {- const text = String(value ?? '')- .replace(/[\u0000-\u001f\u007f]/g, ' ')- .replace(/[\u200b-\u200d\ufeff]/g, '')- .replace(/\s+/g, ' ')- .trim();- if (!text) return '';- try {- return text.normalize('NFKC').toLocaleLowerCase();- } catch {- return text.toLowerCase();- }-}-export function recipientMatchesObservedIdentity(recipient, observedIdentity) {const expected = normalizeRecipientIdentity(recipient);const observed = normalizeRecipientIdentity(observedIdentity);