Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: add Always allow to browser agent prompts (#13777)

Nilay7ae1a5386f39
diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.ts
index aa181879c6d..5331216589e 100644
--- a/studio/frontend/scripts/check-bundle-budget.ts
+++ b/studio/frontend/scripts/check-bundle-budget.ts
@@ -124,8 +124,11 @@ export const BUDGET = {
// native view, and the off-screen question strings) adds 5,278 B raw / 1,928 B transfer (6,765,003 ->
// 6,770,281 B raw, 2,033,563 -> 2,035,491 B transfer against a8585676d4, one machine and build, Node 24,
// chunk count unchanged at 95), raised by that.
+ // Always allow on browser agent prompts (#13777) adds 91 B raw / 42 B transfer to the eager chat chunk
+ // (6,770,922 -> 6,771,013 B raw, 2,035,640 -> 2,035,682 B transfer against cd947468f1, one machine and build,
+ // Node 24, chunk count unchanged at 95), which put main 71 B raw over. Raised by that growth.
transferBytes: 2_035_705,
- rawBytes: 6_770_942,
+ rawBytes: 6_771_033,
};
// The chunk count is reported but not budgeted. Splitting a page out of the entry raises it while lowering the
diff --git a/studio/frontend/src/features/browser/agent/agent-bar.tsx b/studio/frontend/src/features/browser/agent/agent-bar.tsx
index a1a45cb9795..c01ce788cd9 100644
--- a/studio/frontend/src/features/browser/agent/agent-bar.tsx
+++ b/studio/frontend/src/features/browser/agent/agent-bar.tsx
@@ -22,10 +22,10 @@ export function AgentBar({ activeTabId }: { activeTabId: string | null }) {
<div
role={question ? "alertdialog" : "status"}
aria-live="polite"
- className="flex shrink-0 items-center gap-2 border-t border-border/70 bg-primary/5 px-3 py-1.5 text-ui-12"
+ className="flex shrink-0 flex-wrap items-center gap-2 border-t border-border/70 bg-primary/5 px-3 py-1.5 text-ui-12"
>
{question ? null : <Spinner className="size-3.5 text-primary" />}
- <div className="min-w-0 flex-1">
+ <div className="min-w-0 flex-[1_1_12rem]">
<p className="truncate font-medium text-foreground">
{question ? t(`browser.agent.ask.${question.ask}`, { host: question.host, name: question.name }) : t("browser.agent.working")}
</p>
@@ -37,24 +37,31 @@ export function AgentBar({ activeTabId }: { activeTabId: string | null }) {
</p>
) : null}
</div>
- {question ? (
- <>
- <Button type="button" size="xs" variant="ghost" onClick={() => answerQuestion(question.id, false)}>
- {t("browser.agent.deny")}
- </Button>
- <Button
- type="button"
- size="xs"
- disabled={script && readId !== question.id}
- onClick={() => answerQuestion(question.id, true)}
- >
- {t("browser.agent.allow")}
- </Button>
- </>
- ) : null}
- <Button type="button" size="xs" variant="outline" onClick={() => stopBrowserAgent(chat)}>
- {t("browser.agent.stop")}
- </Button>
+ <div className="ml-auto flex flex-wrap items-center justify-end gap-2">
+ {question ? (
+ <>
+ <Button type="button" size="xs" variant="ghost" onClick={() => answerQuestion(question.id, false)}>
+ {t("browser.agent.deny")}
+ </Button>
+ {question.always ? (
+ <Button type="button" size="xs" variant="outline" onClick={() => answerQuestion(question.id, true, true)}>
+ {t("browser.agentSettings.alwaysAllow")}
+ </Button>
+ ) : null}
+ <Button
+ type="button"
+ size="xs"
+ disabled={script && readId !== question.id}
+ onClick={() => answerQuestion(question.id, true)}
+ >
+ {t("browser.agent.allow")}
+ </Button>
+ </>
+ ) : null}
+ <Button type="button" size="xs" variant="outline" onClick={() => stopBrowserAgent(chat)}>
+ {t("browser.agent.stop")}
+ </Button>
+ </div>
</div>
);
}
diff --git a/studio/frontend/src/features/browser/agent/agent-store.ts b/studio/frontend/src/features/browser/agent/agent-store.ts
index 6688db63b55..5738bc7c899 100644
--- a/studio/frontend/src/features/browser/agent/agent-store.ts
+++ b/studio/frontend/src/features/browser/agent/agent-store.ts
@@ -16,7 +16,10 @@ import {
ruleFor,
} from "./permissions";
-export type AgentPrompt = Question & { id: number };
+/** `always`: the bar offers Always allow, as the answer can be kept for this chat. */
+export type AgentPrompt = Question & { id: number; always: boolean };
+/** `always`: allowed, and not asked again for this kind of action on this site in this chat. */
+export type Answer = false | "once" | "always";
/** One chat's use of the browser tools; chats run theirs side by side, each in its own tab. */
export type AgentChat = {
@@ -132,18 +135,18 @@ export function adoptAgentChat(from: string, to: string): void {
});
}
-const answers = new Map<number, (allow: boolean) => void>();
+const answers = new Map<number, (answer: Answer) => void>();
let nextQuestion = 1;
/** Ask the user in `chat`'s agent bar; false when they decline or the run ends first. */
-export function askUser(chat: string, question: Question, signal?: AbortSignal): Promise<boolean> {
+export function askUser(chat: string, question: Question, signal?: AbortSignal, always = false): Promise<Answer> {
return new Promise((resolve) => {
const id = nextQuestion++;
- const finish = (allow: boolean) => {
+ const finish = (answer: Answer) => {
answers.delete(id);
signal?.removeEventListener("abort", onAbort);
if (agentChat(chat).question?.id === id) patchAgentChat(chat, { question: null });
- resolve(allow);
+ resolve(answer);
};
const onAbort = () => finish(false);
if (signal?.aborted) {
@@ -155,12 +158,12 @@ export function askUser(chat: string, question: Question, signal?: AbortSignal):
const current = agentChat(chat).question;
if (current) answers.get(current.id)?.(false);
answers.set(id, finish);
- patchAgentChat(chat, { question: { ...question, id } });
+ patchAgentChat(chat, { question: { ...question, id, always } });
});
}
-export function answerQuestion(id: number, allow: boolean): void {
- answers.get(id)?.(allow);
+export function answerQuestion(id: number, allow: boolean, always = false): void {
+ answers.get(id)?.(allow && (always ? "always" : "once"));
}
const DOWNLOAD_STRICTNESS: Record<DownloadsRule, number> = { allow: 0, ask: 1, block: 2 };
diff --git a/studio/frontend/src/features/browser/agent/executor.ts b/studio/frontend/src/features/browser/agent/executor.ts
index 24e74a29ad0..a8991976328 100644
--- a/studio/frontend/src/features/browser/agent/executor.ts
+++ b/studio/frontend/src/features/browser/agent/executor.ts
@@ -16,7 +16,7 @@ import { callNative, useNativeBrowser } from "../native-support";
import { requestFrameAgent } from "../page-frame";
import { browserPanelAvailable } from "../panel-availability";
import { type BrowserTab, chatKeyOfThread, currentEntry, onChatAdopted, useBrowserStore } from "../store";
-import { adoptAgentChat, agentChat, askUser, liveChat, onBrowserAgentRunEnd, patchAgentChat, setActiveAction, useBrowserAgentStore } from "./agent-store";
+import { type Answer, adoptAgentChat, agentChat, askUser, liveChat, onBrowserAgentRunEnd, patchAgentChat, setActiveAction, useBrowserAgentStore } from "./agent-store";
import { type Gate, type Question, type SitePolicy, gateElement, gateNavigation, hostOfUrl, navigationBlocks } from "./gate";
import { type SiteRule, ruleFor } from "./permissions";
import { type AgentAnswer, type ElementInfo, pageAgentSource } from "./page-agent";
@@ -128,6 +128,7 @@ type Session = {
// A chat never saw another's screenshots: its x and y are CSS pixels until it takes one.
pointScale: Map<string, ShotView & { scaleX: number; scaleY: number }>;
queue: Promise<void>;
+ alwaysAllowed: Set<string>;
};
const sessions = new Map<string, Session>();
@@ -146,6 +147,7 @@ function sessionFor(chat: string): Session {
at: -1,
pointScale: new Map(),
queue: Promise.resolve(),
+ alwaysAllowed: new Set(),
};
sessions.set(chat, session);
for (const old of sessions.keys()) {
@@ -459,11 +461,11 @@ async function untilFilled(tab: BrowserTab, since: number, signal?: AbortSignal)
return (await waitOnPage(tab.id, (now) => currentEntry(now) !== entry, since, FILL_QUIET_MAX_MS, signal, FILL_IDLE_QUIET_MS)) === "loading";
}
-async function pass(gate: Gate, context: Run): Promise<string | null> {
+async function pass(gate: Gate, context: Run, remember = true): Promise<string | null> {
if (gate.kind === "allow") return null;
if (gate.kind === "block") return `Not done: ${gate.reason}.`;
const { ask, host, name, detail } = gate;
- const allowed = await askInPanel({ ask, host, name, detail }, context);
+ const allowed = await askInPanel({ ask, host, name, detail }, context, remember);
// Not gate.prompt: it quotes the page's label, and errors reach the model outside the fence.
return allowed ? null : `The user declined ${DECLINED[ask]} on ${host || "this page"}. Do something else, or ask them.`;
}
@@ -491,14 +493,24 @@ function notifyOffScreenQuestion(chat: string): void {
}
/** Questions show in the chat's agent bar: the panel opens for one in the chat on screen, and one
- * from a chat off screen waits there, with a toast to go answer it. */
-function askInPanel(question: Question, context: Run): Promise<boolean> {
+ * from a chat off screen waits there, with a toast to go answer it. A script is asked every time. */
+async function askInPanel(question: Question, context: Run, remember = true): Promise<Answer> {
+ // As askUser does: a stopped action isn't answered, even by Always allow.
+ if (context.signal?.aborted) return false;
+ // A click is asked about by its label, so Always allow covers that button, not every risky one.
+ const key = [question.ask, question.host, question.ask === "click" ? question.name : ""].join("\n");
+ // A "__default" first turn resolves to whichever chat is on screen, which may not be its own.
+ const keep = remember && question.ask !== "script" && Boolean(context.chat || (context.scope && context.scope !== "__default"));
+ const granted = context.session.alwaysAllowed;
+ if (keep && granted.has(key)) return "always";
const tabId = agentChat(context.session.chat).tabId;
const store = useBrowserStore.getState();
if (tabId) store.revealIn(context.session.chat, tabId);
else if (chatOnScreen(context) && !store.open) store.openPanel();
if (!chatOnScreen(context)) notifyOffScreenQuestion(context.session.chat);
- return askUser(context.session.chat, question, context.signal);
+ const answer = await askUser(context.session.chat, question, context.signal, keep);
+ if (answer === "always" && keep) granted.add(key);
+ return answer;
}
async function observe(tab: BrowserTab, context: Run, note?: string, op: Record<string, unknown> = { op: "snapshot" }): Promise<Result> {
@@ -651,7 +663,8 @@ async function perform(action: BrowserAction, context: Run): Promise<Result> {
} else if (nativeMove) {
// History from before this chat, or from the user browsing in the tab: where it leads is unknown.
const where = action.op === "back" ? "the previous page" : "the next page";
- const refused = await pass({ kind: "ask", ask: "open", host: where, name: "", detail: "", prompt: `Open ${where}?` }, context);
+ // Not kept by Always allow: `where` names no site, so it would answer for wherever a later move leads.
+ const refused = await pass({ kind: "ask", ask: "open", host: where, name: "", detail: "", prompt: `Open ${where}?` }, context, false);
if (refused) return { ok: false, error: refused };
}
const since = Date.now();
diff --git a/studio/frontend/tests/browser-agent-always-allow.test.ts b/studio/frontend/tests/browser-agent-always-allow.test.ts
new file mode 100644
index 00000000000..65a2cb1f56c
--- /dev/null
+++ b/studio/frontend/tests/browser-agent-always-allow.test.ts
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import { register } from "node:module";
+import { test } from "node:test";
+
+register("./helpers/browser-executor-resolver.mjs", import.meta.url);
+const { runBrowserAction } = await import("../src/features/browser/agent/executor.ts");
+const { answerQuestion, stopBrowserAgent, useBrowserAgentStore } = await import("../src/features/browser/agent/agent-store.ts");
+const { chatKeyOfThread, useBrowserStore } = await import("../src/features/browser/store.ts");
+
+const globals = globalThis as Record<string, unknown>;
+// The stub page loads at once, as tab-view marks a real tab loaded; else each action waits out LOAD_TIMEOUT_MS.
+useBrowserStore.subscribe(({ tabs }) => {
+ for (const tab of tabs) if (tab.loading) queueMicrotask(() => useBrowserStore.getState().updateTab(tab.id, { loading: false }));
+});
+globals.__authFetch = async () => new Response(null, { status: 200 });
+const policy = { allowedDomains: [], blockedDomains: [] };
+const buy = { role: "button", name: "Buy now", tag: "button", href: "", formMethod: "", formAction: "", formHasPassword: false, submits: false };
+const sent: string[] = [];
+let info: Record<string, unknown> = buy;
+let onClick: (() => void) | null = null;
+globals.__frameAgent = async (_tabId: string, op: Record<string, unknown>) => {
+ sent.push(String(op.op));
+ if (op.op === "status") return { installed: true, result: { ok: true, quietMs: 1000, doc: "r1" } };
+ if (op.op === "describe") {
+ onClick?.();
+ return { installed: true, result: { ok: true, info, hit: "r5", sig: "s" } };
+ }
+ return { installed: true, result: { ok: true, text: "page", links: [] } };
+};
+
+type Run = { runKey: string; scope: string; userText: string };
+const chatOf = (scope: string) => chatKeyOfThread(scope);
+const show = (scope: string) => useBrowserStore.getState().showChat(chatKeyOfThread(scope));
+const pending = () => Object.values(useBrowserAgentStore.getState().chats).find((chat) => chat.question)?.question ?? null;
+const navigate = (id: string, run: Run, url = "https://shop.example.com/") =>
+ runBrowserAction({ id, sessionId: "s", op: "navigate", url, direction: "down", policy }, run);
+const click = (id: string, run: Run) => runBrowserAction({ id, sessionId: "s", op: "click", x: 40, y: 20, direction: "down", policy }, run);
+const run = (scope: string): Run => ({ runKey: `run-${scope}`, scope, userText: "open https://shop.example.com/" });
+
+/** What the action asks, answered by `reply`, and whether the bar offered Always allow; null when it doesn't ask. */
+async function askedBy(action: Promise<void>, reply: (id: number) => void) {
+ let finished = false;
+ const done = action.then(() => {
+ finished = true;
+ });
+ let asked = pending();
+ while (!finished && !asked) {
+ await new Promise((resolve) => setTimeout(resolve, 10));
+ asked = pending();
+ }
+ if (asked) reply(asked.id);
+ await done;
+ return asked ? `${asked.ask}${asked.always ? "+always" : ""}` : null;
+}
+
+test("Always allow stops asking about that action on that site, in that chat only", async () => {
+ info = buy;
+ const a = run("chat-a");
+ show("chat-a");
+ await navigate("a0", a);
+ assert.equal(await askedBy(click("a1", a), (id) => answerQuestion(id, true, true)), "click+always");
+ const clicks = sent.filter((op) => op === "click").length;
+ assert.equal(await askedBy(click("a2", a), (id) => answerQuestion(id, false)), null, "asked again after Always allow");
+ assert.equal(sent.filter((op) => op === "click").length, clicks + 1);
+
+ const b = run("chat-b");
+ show("chat-b");
+ await navigate("b0", b);
+ assert.equal(await askedBy(click("b1", b), (id) => answerQuestion(id, false)), "click+always", "another chat inherited Always allow");
+
+ show("chat-a");
+ assert.equal(await askedBy(click("a3", a), (id) => answerQuestion(id, false)), null, "Always allow lost on coming back to the chat");
+});
+
+test("Always allow on a click covers only the button it named", async () => {
+ const c = run("chat-c");
+ show("chat-c");
+ info = buy;
+ await navigate("c0", c);
+ assert.equal(await askedBy(click("c1", c), (id) => answerQuestion(id, true, true)), "click+always");
+ info = { ...buy, name: "Delete account" };
+ assert.equal(await askedBy(click("c2", c), (id) => answerQuestion(id, true)), "click+always");
+ info = buy;
+ assert.equal(await askedBy(click("c3", c), (id) => answerQuestion(id, true)), null);
+});
+
+test("Always allow isn't offered or kept for a new chat's first turn before it has an id", async () => {
+ info = buy;
+ const first = run("__default");
+ useBrowserStore.getState().showChat("new:e");
+ await navigate("e0", first);
+ assert.equal(await askedBy(click("e1", first), (id) => answerQuestion(id, true, true)), "click");
+ assert.equal(await askedBy(click("e2", first), (id) => answerQuestion(id, true)), "click");
+});
+
+test("Always allow isn't offered or kept for a native Back whose destination is unknown", async () => {
+ const g = run("chat-g");
+ show("chat-g");
+ await navigate("g0", g);
+ const tabId = useBrowserAgentStore.getState().chats[chatOf("chat-g")]?.tabId ?? "";
+ globals.__native = true;
+ globals.__callNative = async (command: string, args: { command: { op: Record<string, unknown> } }) =>
+ command === "browser_view_agent" ? (globals.__frameAgent as (t: string, op: Record<string, unknown>) => unknown)(tabId, args.command.op) : null;
+ try {
+ // History from before this chat: the view can go back, but not to where.
+ const back = (id: string) => {
+ useBrowserStore.getState().updateTab(tabId, { nativeHistory: { back: true, forward: false } });
+ return runBrowserAction({ id, sessionId: "s", op: "back", direction: "down", policy }, g);
+ };
+ assert.equal(await askedBy(back("g1"), (id) => answerQuestion(id, true, true)), "open");
+ // The user browsed on in the view, so where Back leads is unknown again.
+ useBrowserStore.getState().updateTab(tabId, { displayUrl: "https://shop.example.com/elsewhere" });
+ assert.equal(await askedBy(back("g2"), (id) => answerQuestion(id, false)), "open", "an unnamed Back reused Always allow");
+ } finally {
+ globals.__native = false;
+ delete globals.__callNative;
+ }
+});
+
+test("Always allow doesn't answer for an action that was stopped", async () => {
+ info = buy;
+ const d = run("chat-d");
+ show("chat-d");
+ await navigate("d0", d);
+ assert.equal(await askedBy(click("d1", d), (id) => answerQuestion(id, true, true)), "click+always");
+ const clicks = sent.filter((op) => op === "click").length;
+ // Stop lands while the next click on that button is being read, before it is asked about.
+ onClick = () => stopBrowserAgent(chatOf("chat-d"));
+ try {
+ await click("d2", d);
+ } finally {
+ onClick = null;
+ }
+ assert.equal(sent.filter((op) => op === "click").length, clicks, "a stopped click ran on Always allow");
+});