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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: keep a temporary chat's browser agent pages out of history (#14956)
Daniel Han3bfc78697f40
diff --git a/studio/frontend/src/features/browser/agent/executor.ts b/studio/frontend/src/features/browser/agent/executor.tsindex af6a28242fb..289c5e40c58 100644--- a/studio/frontend/src/features/browser/agent/executor.ts+++ b/studio/frontend/src/features/browser/agent/executor.ts@@ -61,11 +61,13 @@ export type BrowserAction = {};/** `scope`: the chat the run belongs to; sites approved in one chat aren't approved in another.- * `chat`: its browser chat when that isn't the thread's own (a compare pane's pair). */+ * `chat`: its browser chat when that isn't the thread's own (a compare pane's pair).+ * `temporary`: the run's chat is temporary, so its pages stay out of history whatever chat is shown. */export type ActionContext = {runKey: string;scope?: string;chat?: string;+ temporary?: boolean;userText: string;fullAccess?: boolean;signal?: AbortSignal;@@ -627,12 +629,12 @@ async function open(url: string, context: Run): Promise<BrowserTab | null> {: agent && !onGrantedOrigin(agent) ? agent : undefined;if (existing) {if (agentChat(context.session.chat).tabId !== existing.id) moveRun(context, existing.id);- store.navigate(existing.id, { url }, { replace: false });+ store.navigate(existing.id, { url, temporary: context.temporary }, { replace: false });showTab(existing, context);return waitForLoad(existing.id, context.signal);}// In its own chat's tabs: a chat off screen gets a tab there, and the panel on screen stays put.- const tabId = store.openTabIn(context.session.chat, url);+ const tabId = store.openTabIn(context.session.chat, url, { temporary: context.temporary });if (!tabId) return null;// Off screen the view opens a beat later: loading until it reports in, so the wait below doesn't read the blank view.if (!chatOnScreen(context)) store.updateTab(tabId, { loading: true });@@ -988,7 +990,7 @@ async function perform(action: BrowserAction, context: Run): Promise<Result> {}const sent = Date.now();// Straight to the landing page that was gated: the store unwraps only one redirect hop.- useBrowserStore.getState().navigate(ready.id, { url: end, from: here }, { replace: false });+ useBrowserStore.getState().navigate(ready.id, { url: end, from: here, temporary: context.temporary }, { replace: false });const loaded = await waitForLoad(ready.id, signal);return loaded ? arrive(loaded, end, action, context, sent) : { ok: false, error: "the browser tab closed." };}diff --git a/studio/frontend/src/features/browser/native-view.ts b/studio/frontend/src/features/browser/native-view.tsindex d8515ca12b3..cd9ca362a56 100644--- a/studio/frontend/src/features/browser/native-view.ts+++ b/studio/frontend/src/features/browser/native-view.ts@@ -310,8 +310,11 @@ function onNativeEvent(event: NativeEvent): void {// A page at work in a chat off screen opens its popups there, not over this chat's tabs.function openPopup(tab: BrowserTab, url: string): void {const store = useBrowserStore.getState();- if (tab.chat !== store.chat) store.openTabIn(tab.chat, url, { from: shownUrl(tab), background: true });- else store.openUrl(url, { newTab: true, from: shownUrl(tab) });+ if (tab.chat !== store.chat) {+ // The opener's temporary flag, not the shown chat's: a temporary page's popups stay out of history.+ const temporary = pageTemporary(tab.id, currentEntry(tab));+ store.openTabIn(tab.chat, url, { from: shownUrl(tab), background: true, temporary });+ } else store.openUrl(url, { newTab: true, from: shownUrl(tab) });}function promptPopup(tab: BrowserTab, url: string): void {diff --git a/studio/frontend/src/features/browser/store.ts b/studio/frontend/src/features/browser/store.tsindex f2467fc1df2..605b98ac66f 100644--- a/studio/frontend/src/features/browser/store.ts+++ b/studio/frontend/src/features/browser/store.ts@@ -321,7 +321,7 @@ type BrowserState = {/** A new chat got its id on its first save: its tabs go with it. */adoptChat: (from: string, to: string) => void;/** A web tab for `chat`, in front only when that chat is on screen (`background`: behind its front tab); its id. */- openTabIn: (chat: string, url: string, options?: { from?: string; background?: boolean }) => string | null;+ openTabIn: (chat: string, url: string, options?: { from?: string; background?: boolean; temporary?: boolean }) => string | null;forgetChat: (chat: string) => void;/** `tabId` in front of `chat`'s open panel: now if it is on screen, else when it comes back. */revealIn: (chat: string, tabId: string) => void;@@ -572,7 +572,7 @@ export const useBrowserStore = create<BrowserState>((set, get) => {},openTabIn: (chat, url, options) => {if (!isWeb(url)) return null;- const tab = createTab(webEntry(unwrapRedirect(url), undefined, undefined, options?.from));+ const tab = createTab(webEntry(unwrapRedirect(url), undefined, undefined, options?.from, options?.temporary));openTab(tab, options?.background, undefined, chat);return tab.id;},diff --git a/studio/frontend/src/features/chat/api/chat-adapter.ts b/studio/frontend/src/features/chat/api/chat-adapter.tsindex 1d190e328fd..67081430355 100644--- a/studio/frontend/src/features/chat/api/chat-adapter.ts+++ b/studio/frontend/src/features/chat/api/chat-adapter.ts@@ -4443,6 +4443,12 @@ export function createOpenAIStreamAdapter(// Capture the thread ID once so it stays stable across chat switches during model load.const resolvedThreadId =(runThreadId ?? runtime.activeThreadId) || undefined;+ // Taken as it sends, from the run's own thread: its browser pages keep that chat's history rule+ // after a switch. The shown chat's toggle counts only for the thread on screen (marked as it initializes).+ const browserTemporary = resolvedThreadId+ ? isThreadIncognito(resolvedThreadId) ||+ (resolvedThreadId === runtime.activeThreadId && runtime.incognito)+ : runtime.incognito;if (resolvedThreadId) {rememberComposerProjectForRun(resolvedThreadId, composerProjectIdAtSend);}@@ -7375,6 +7381,7 @@ export function createOpenAIStreamAdapter(scope: liveThreadKey(serverCancel),userText,fullAccess: bypassPermissions,+ temporary: browserTemporary,signal: runSignal,});}diff --git a/studio/frontend/tests/browser-agent-chats.test.ts b/studio/frontend/tests/browser-agent-chats.test.tsindex 879874442f3..e41e5e0f336 100644--- a/studio/frontend/tests/browser-agent-chats.test.ts+++ b/studio/frontend/tests/browser-agent-chats.test.ts@@ -175,3 +175,65 @@ test("a new chat's run stays in it after a switch, and Stop in the saved chat enassert.equal(agentChat(chatKeyOfThread("bound")).question, null);});++test("a temporary chat's run keeps its pages out of history after a switch to a saved chat", async () => {+ globals.__native = true;+ const store = useBrowserStore.getState();+ // The saved chat on screen is not temporary: only the run itself says its pages are.+ store.showChat(chatKeyOfThread("saved-shown"));+ const run = (id: string, url: string) =>+ runBrowserAction(+ { id, sessionId: "s", op: "navigate", url, direction: "down", policy },+ { runKey: "run-hidden-temp", scope: "hidden-temp", temporary: true, userText: `open ${url}` },+ );+ // The first opens the run's tab in its own chat; the second moves that tab on.+ await run("t1", "https://private.example/");+ await run("t2", "https://private.example/next");+ assert.equal(resultOf("t1")?.ok, true, resultOf("t1")?.error);+ assert.equal(resultOf("t2")?.ok, true, resultOf("t2")?.error);+ const tab = useBrowserStore.getState().tabs.find((candidate) => candidate.id === agentChat(chatKeyOfThread("hidden-temp")).tabId);+ assert.deepEqual(+ tab?.history.map((entry) => (entry.kind === "web" ? [entry.url, entry.temporary] : null)),+ [+ ["https://private.example/", true],+ ["https://private.example/next", true],+ ],+ );+});++test("a saved chat's run keeps its pages in history while a temporary chat is on screen", async () => {+ globals.__native = true;+ const { useChatRuntimeStore } = await import("@/features/chat");+ const store = useBrowserStore.getState();+ store.showChat(chatKeyOfThread("temp-shown"));+ useChatRuntimeStore.getState().setIncognito(true);+ try {+ const run = (id: string, url: string) =>+ runBrowserAction(+ { id, sessionId: "s", op: "navigate", url, direction: "down", policy },+ { runKey: "run-hidden-saved", scope: "hidden-saved", temporary: false, userText: `open ${url}` },+ );+ await run("s1", "https://kept.example/");+ await run("s2", "https://kept.example/next");+ assert.equal(resultOf("s2")?.ok, true, resultOf("s2")?.error);+ const tab = useBrowserStore.getState().tabs.find((candidate) => candidate.id === agentChat(chatKeyOfThread("hidden-saved")).tabId);+ assert.deepEqual(+ tab?.history.map((entry) => (entry.kind === "web" ? [entry.url, entry.temporary] : null)),+ [+ ["https://kept.example/", undefined],+ ["https://kept.example/next", undefined],+ ],+ );+ } finally {+ useChatRuntimeStore.getState().setIncognito(false);+ }+});++test("a run's temporary flag comes from its own thread, not a chat shown later", async () => {+ const { readSrc } = await import("./helpers/kit.ts");+ const adapter = readSrc("features/chat/api/chat-adapter.ts");+ assert.match(+ adapter,+ /const browserTemporary = resolvedThreadId\s*\?\s*isThreadIncognito\(resolvedThreadId\) \|\|\s*\(resolvedThreadId === runtime\.activeThreadId && runtime\.incognito\)\s*:\s*runtime\.incognito;/,+ );+});diff --git a/studio/frontend/tests/browser-native-view-layered.test.ts b/studio/frontend/tests/browser-native-view-layered.test.tsindex 2a54d11a33c..2d31f50913a 100644--- a/studio/frontend/tests/browser-native-view-layered.test.ts+++ b/studio/frontend/tests/browser-native-view-layered.test.ts@@ -375,6 +375,22 @@ test("a background page's popup opens in its own chat, and a page that fails toreleaseBackground(tabId);});+test("a temporary page's popup in a chat off screen stays out of history", () => {+ const store = useBrowserStore.getState();+ store.closePanel();+ store.showChat("single:saved");+ const tabId = store.openTabIn("single:temporary", "https://worker.example/", { temporary: true }) ?? "";+ const listener = (globalThis as { nativeViewListener?: (event: { payload: unknown }) => void }).nativeViewListener;+ listener?.({ payload: { kind: "newTab", tabId, url: "https://popup-temp.example/" } });+ const popup = useBrowserStore.getState().tabs.find((tab) => {+ const entry = currentEntry(tab);+ return entry.kind === "web" && entry.url === "https://popup-temp.example/";+ });+ assert.equal(popup?.chat, "single:temporary");+ const entry = popup && currentEntry(popup);+ assert.equal(entry?.kind === "web" ? entry.temporary : undefined, true);+});+test("an address a local page can't go to itself is offered, not opened", async () => {const store = useBrowserStore.getState();store.closePanel();