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: remember download answers for a site or every site, programs included (#16658)
Michael Haneec7711a4261
diff --git a/studio/frontend/src/features/browser/download-approval-queue.ts b/studio/frontend/src/features/browser/download-approval-queue.tsindex fed64983f35..b4fcc10575e 100644--- a/studio/frontend/src/features/browser/download-approval-queue.ts+++ b/studio/frontend/src/features/browser/download-approval-queue.ts@@ -17,6 +17,8 @@ export type DownloadRequest = {label: string;name: string;dangerous: boolean;+ /** From the browser agent's tab: asked under its own rules, so another file's answer never settles it. */+ agent: boolean;resolve: (allow: boolean) => void;};@@ -50,41 +52,54 @@ export function approveDownload(toast.error(translate("browser.downloadPrompt.blocked", { host: label }, getLocale()));return Promise.resolve(false);}- // A file that runs code always asks: a site's Always allow, or asking turned off, doesn't cover it.- const allowed =- agentRule === "allow" ||- (agentRule !== "ask" && (remembered === "allow" || !useBrowserPrefsStore.getState().askBeforeDownloading));- if (!dangerous && allowed) {- return Promise.resolve(true);- }- return ask(origin, label, shown, dangerous);+ const prefs = useBrowserPrefsStore.getState();+ // A file that runs code asks unless the user allowed those in particular, never on the agent's say.+ const allowed = dangerous+ ? agentRule == null && (remembered === "allowAll" || !prefs.askBeforeProgramDownloads)+ : agentRule === "allow" ||+ (agentRule !== "ask" && (remembered === "allow" || remembered === "allowAll" || !prefs.askBeforeDownloading));+ if (allowed) return Promise.resolve(true);+ return ask(origin, label, shown, dangerous, agentRule != null);}-/** Picked from the context menu: no site answer applies, and only a file that runs code asks (with nothing to remember). */+/** Picked from the context menu: no site answer applies, and only a file that runs code asks, unless those were allowed everywhere. */export function approveChosenDownload(url: string, name: string): Promise<boolean> {const shown = safeDownloadName(name);- if (!isDangerousDownload(shown)) return Promise.resolve(true);+ if (!isDangerousDownload(shown) || !useBrowserPrefsStore.getState().askBeforeProgramDownloads) return Promise.resolve(true);return ask("", hostOf(url) || url.slice(0, 80), shown, true);}-function ask(origin: string, label: string, name: string, dangerous: boolean): Promise<boolean> {+function ask(origin: string, label: string, name: string, dangerous: boolean, agent = false): Promise<boolean> {return new Promise((resolve) =>useApprovalStore.setState((state) => ({- queue: [...state.queue, { origin, label, name, dangerous, resolve }],+ queue: [...state.queue, { origin, label, name, dangerous, agent, resolve }],})),);}-/** Ignored unless it's the download being asked about. Remembered, it also settles the site's other waiting downloads. */-export function answerDownload(request: DownloadRequest, allow: boolean, remember: boolean): void {+/** `true`: for this site. `"all"`: Download without asking anywhere; a Cancel isn't kept for every site. */+export type RememberDownload = boolean | "all";++/** Ignored unless it's the download being asked about. Remembered, it also settles the other waiting downloads it covers. */+export function answerDownload(request: DownloadRequest, allow: boolean, remember: RememberDownload): void {const { queue } = useApprovalStore.getState();if (queue[0] !== request) return;- const kept = remember && request.origin !== "";- if (kept) useDownloadSitesStore.getState().setSite(request.origin, allow ? "allow" : "block");- // A remembered Allow settles the site's other waiting files, except ones that run code: each of those asks.- const answered = kept- ? queue.filter((other) => other === request || (other.origin === request.origin && !(allow && other.dangerous)))- : [request];+ // Allowing a file that runs code is remembered for those too; allowing any other file isn't.+ const programs = allow && request.dangerous;+ const everywhere = remember === "all" && allow;+ const site = remember === true && request.origin !== "";+ if (site) useDownloadSitesStore.getState().setSite(request.origin, !allow ? "block" : programs ? "allowAll" : "allow");+ if (everywhere) {+ const prefs = useBrowserPrefsStore.getState();+ prefs.setAskBeforeDownloading(false);+ if (programs) prefs.setAskBeforeProgramDownloads(false);+ }+ const covered = (other: DownloadRequest) => !other.agent && !(allow && other.dangerous && !programs);+ const answered = everywhere+ ? queue.filter((other) => other === request || covered(other))+ : site+ ? queue.filter((other) => other === request || (other.origin === request.origin && covered(other)))+ : [request];useApprovalStore.setState({ queue: queue.filter((other) => !answered.includes(other)) });for (const other of answered) other.resolve(allow);}diff --git a/studio/frontend/src/features/browser/download-approval.tsx b/studio/frontend/src/features/browser/download-approval.tsxindex 1a8f3c55dea..a1a6e851b12 100644--- a/studio/frontend/src/features/browser/download-approval.tsx+++ b/studio/frontend/src/features/browser/download-approval.tsx@@ -11,22 +11,26 @@ import {AlertDialogHeader,AlertDialogTitle,} from "@/components/ui/alert-dialog";-import { Checkbox } from "@/components/ui/checkbox";+import { Label } from "@/components/ui/label";+import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";import { useT } from "@/i18n";import { useId, useState } from "react";-import { answerDownload, useApprovalStore } from "./download-approval-queue";+import { type RememberDownload, answerDownload, useApprovalStore } from "./download-approval-queue";++type Choice = "once" | "site" | "all";+const REMEMBER: Record<Choice, RememberDownload> = { once: false, site: true, all: "all" };export function DownloadApprovalDialog() {const t = useT();const request = useApprovalStore((state) => state.queue[0]);- const [remember, setRemember] = useState(false);- const checkboxId = useId();+ const [choice, setChoice] = useState<Choice>("once");+ const id = useId();// Escape or an outside click cancels this once only, so a stray click with the box ticked doesn't block the site for good.const answer = (allow: boolean, kept = true) => {if (!request || useApprovalStore.getState().queue[0] !== request) return;- setRemember(false);- answerDownload(request, allow, kept && remember);+ setChoice("once");+ answerDownload(request, allow, kept ? REMEMBER[choice] : false);};return (@@ -43,12 +47,25 @@ export function DownloadApprovalDialog() {</p>) : null}</AlertDialogHeader>- {/* Files that run code ask every time, so there's nothing to remember. */}- {request?.origin && !request.dangerous ? (- <label htmlFor={checkboxId} className="flex cursor-pointer items-center gap-2 text-sm text-foreground">- <Checkbox id={checkboxId} checked={remember} onCheckedChange={(checked) => setRemember(checked === true)} />- {t("browser.downloadPrompt.remember")}- </label>+ {request ? (+ <RadioGroup+ value={choice}+ onValueChange={(value) => setChoice(value as Choice)}+ aria-label={t("browser.downloadPrompt.remember")}+ className="gap-2"+ >+ {(["once", "site", "all"] as const)+ // Without a web origin (data:, an opaque blob) there's no site to remember.+ .filter((option) => option !== "site" || request.origin)+ .map((option) => (+ <div key={option} className="flex items-center gap-2">+ <RadioGroupItem id={`${id}-${option}`} value={option} />+ <Label htmlFor={`${id}-${option}`} className="cursor-pointer text-sm font-normal text-foreground">+ {t(`browser.downloadPrompt.${option}`, { host: request.label })}+ </Label>+ </div>+ ))}+ </RadioGroup>) : null}<AlertDialogFooter><AlertDialogCancel onClick={() => answer(false)}>{t("browser.downloadPrompt.cancel")}</AlertDialogCancel>diff --git a/studio/frontend/src/features/browser/download-sites-store.ts b/studio/frontend/src/features/browser/download-sites-store.tsindex de8c659dead..5545ab82970 100644--- a/studio/frontend/src/features/browser/download-sites-store.ts+++ b/studio/frontend/src/features/browser/download-sites-store.ts@@ -8,7 +8,8 @@ import { createJSONStorage, persist } from "zustand/middleware";import { accountDatabaseName } from "@/lib/account-transition";import { syncAcrossWindows } from "@/lib/sync-across-windows";-export type DownloadSiteDecision = "allow" | "block";+/** "allowAll": files that can run programs too, which "allow" still asks about. */+export type DownloadSiteDecision = "allow" | "allowAll" | "block";interface DownloadSitesState {sites: Record<string, DownloadSiteDecision>;diff --git a/studio/frontend/src/features/browser/prefs-store.ts b/studio/frontend/src/features/browser/prefs-store.tsindex 7f8517fb03a..2cc70a193ef 100644--- a/studio/frontend/src/features/browser/prefs-store.ts+++ b/studio/frontend/src/features/browser/prefs-store.ts@@ -35,6 +35,8 @@ interface BrowserPrefsState {saveDownloadHistory: boolean;askWhereToSave: boolean;askBeforeDownloading: boolean;+ /** Files that can run programs; asked about even with askBeforeDownloading off, unless this is off too. */+ askBeforeProgramDownloads: boolean;annotationScreenshots: AnnotationScreenshots;setOpenLinksInBrowser: (value: boolean) => void;setOpenFilesInBrowser: (value: boolean) => void;@@ -53,6 +55,7 @@ interface BrowserPrefsState {setSaveDownloadHistory: (value: boolean) => void;setAskWhereToSave: (value: boolean) => void;setAskBeforeDownloading: (value: boolean) => void;+ setAskBeforeProgramDownloads: (value: boolean) => void;setAnnotationScreenshots: (value: AnnotationScreenshots) => void;}@@ -75,6 +78,7 @@ export const useBrowserPrefsStore = create<BrowserPrefsState>()(saveDownloadHistory: true,askWhereToSave: false,askBeforeDownloading: true,+ askBeforeProgramDownloads: true,annotationScreenshots: "never",setOpenLinksInBrowser: (openLinksInBrowser) => set({ openLinksInBrowser }),setOpenFilesInBrowser: (openFilesInBrowser) => set({ openFilesInBrowser }),@@ -98,6 +102,7 @@ export const useBrowserPrefsStore = create<BrowserPrefsState>()(setSaveDownloadHistory: (saveDownloadHistory) => set({ saveDownloadHistory }),setAskWhereToSave: (askWhereToSave) => set({ askWhereToSave }),setAskBeforeDownloading: (askBeforeDownloading) => set({ askBeforeDownloading }),+ setAskBeforeProgramDownloads: (askBeforeProgramDownloads) => set({ askBeforeProgramDownloads }),setAnnotationScreenshots: (annotationScreenshots) => set({ annotationScreenshots }),}),{diff --git a/studio/frontend/src/features/settings/settings-search.ts b/studio/frontend/src/features/settings/settings-search.tsindex 33b55470906..c53ad252d24 100644--- a/studio/frontend/src/features/settings/settings-search.ts+++ b/studio/frontend/src/features/settings/settings-search.ts@@ -203,6 +203,7 @@ export const SETTINGS_SEARCH_INDEX: Record<SettingsTab, TranslationKey[]> = {"browser.downloadsTitle","browser.askWhereToSaveSetting","browser.askBeforeDownloadingSetting",+ "browser.askBeforeProgramDownloadsSetting","browser.downloadSitesSetting","browser.saveDownloadHistorySetting","browser.browsingDataTitle",diff --git a/studio/frontend/src/features/settings/tabs/browser-tab.tsx b/studio/frontend/src/features/settings/tabs/browser-tab.tsxindex 7b3918c574c..8b041df020a 100644--- a/studio/frontend/src/features/settings/tabs/browser-tab.tsx+++ b/studio/frontend/src/features/settings/tabs/browser-tab.tsx@@ -120,6 +120,7 @@ function DownloadSiteRows() {</SelectTrigger><SelectContent><SelectItem value="allow">{t("browser.downloadSiteAllow")}</SelectItem>+ <SelectItem value="allowAll">{t("browser.downloadSiteAllowAll")}</SelectItem><SelectItem value="block">{t("browser.downloadSiteBlock")}</SelectItem></SelectContent></Select>@@ -163,6 +164,7 @@ export function BrowserTab() {const saveDownloadHistory = useBrowserPrefsStore((state) => state.saveDownloadHistory);const askWhereToSave = useBrowserPrefsStore((state) => state.askWhereToSave);const askBeforeDownloading = useBrowserPrefsStore((state) => state.askBeforeDownloading);+ const askBeforeProgramDownloads = useBrowserPrefsStore((state) => state.askBeforeProgramDownloads);const annotationScreenshots = useBrowserPrefsStore((state) => state.annotationScreenshots);const {setOpenLinksInBrowser,@@ -181,6 +183,7 @@ export function BrowserTab() {setSaveDownloadHistory,setAskWhereToSave,setAskBeforeDownloading,+ setAskBeforeProgramDownloads,setAnnotationScreenshots,} = useBrowserPrefsStore.getState();const [clearOpen, setClearOpen] = useState(false);@@ -491,6 +494,16 @@ export function BrowserTab() {onCheckedChange={setAskBeforeDownloading}/></SettingsRow>+ <SettingsRow+ label={t("browser.askBeforeProgramDownloadsSetting")}+ description={t("browser.askBeforeProgramDownloadsSettingDescription")}+ >+ <Switch+ aria-label={t("browser.askBeforeProgramDownloadsSetting")}+ checked={askBeforeProgramDownloads}+ onCheckedChange={setAskBeforeProgramDownloads}+ />+ </SettingsRow><DownloadSiteRows /><SettingsRowlabel={t("browser.saveDownloadHistorySetting")}diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.tsindex e5a70521c35..f8049f1849f 100644--- a/studio/frontend/src/i18n/locales/en.ts+++ b/studio/frontend/src/i18n/locales/en.ts@@ -327,18 +327,24 @@ export const en = {downloadLocationReset: "Reset",askBeforeDownloadingSetting: "Ask before downloading",askBeforeDownloadingSettingDescription: "Confirm files from websites before they're saved.",+ askBeforeProgramDownloadsSetting: "Ask before downloading programs",+ askBeforeProgramDownloadsSettingDescription: "Confirm files that can run programs, such as .exe or .dmg, even when other downloads don't ask.",downloadSitesSetting: "Site download permissions",downloadSitesSettingDescription: "Sites you chose to always allow or block downloads from.",- downloadSitesNone: "Check Remember for next time when asked, and the site shows up here.",+ downloadSitesNone: "Choose Always for a site when asked, and it shows up here.",downloadSitesFor: "Downloads from {host}",downloadSitesRemove: "Forget {host}",downloadSiteAllow: "Always allow",+ downloadSiteAllowAll: "Allow programs too",downloadSiteBlock: "Always block",downloadPrompt: {title: "Download this file?",description: "{host} wants to save {name} to your computer.",dangerous: "Files like this can run programs on your computer. Only download it if you trust {host}.",- remember: "Remember for next time",+ remember: "Remember this choice",+ once: "Ask next time",+ site: "Always for {host}",+ all: "Always download, from every site",cancel: "Cancel",download: "Download",blocked: "Blocked a download from {host}.",diff --git a/studio/frontend/tests/browser-settings.test.ts b/studio/frontend/tests/browser-settings.test.tsindex d9f3203dd09..1d06aae2ca5 100644--- a/studio/frontend/tests/browser-settings.test.ts+++ b/studio/frontend/tests/browser-settings.test.ts@@ -999,11 +999,77 @@ test("a blocked site's blob: page can't download past the block", async () => {prefs.setAskBeforeDownloading(true);});-test("the download prompt offers Remember only for files a remembered answer can cover", async () => {- const { readFileSync } = await import("node:fs");- const source = readFileSync(new URL("../src/features/browser/download-approval.tsx", import.meta.url), "utf8");- // A file that runs code asks whatever was remembered (approveDownload), so its prompt has no checkbox.- assert.match(source, /\{request\?\.origin && !request\.dangerous \? \(\s*<label/);+test("a file that runs code can be remembered for its site, or for every site", async () => {+ const { approveDownload, answerDownload, useApprovalStore } = await import(+ "../src/features/browser/download-approval-queue.ts"+ );+ const { useDownloadSitesStore } = await import("../src/features/browser/download-sites-store.ts");+ const answer = (allow: boolean, remember: boolean | "all") => answerDownload(useApprovalStore.getState().queue[0], allow, remember);+ try {+ // Always for this site, on a program: that site's programs stop asking; other sites' still ask.+ const app = approveDownload("https://f.example/App.dmg", "App.dmg");+ answer(true, true);+ assert.equal(await app, true);+ assert.equal(useDownloadSitesStore.getState().sites["https://f.example"], "allowAll");+ assert.equal(await approveDownload("https://f.example/Other.pkg", "Other.pkg"), true);+ const elsewhere = approveDownload("https://g.example/App.dmg", "App.dmg");+ assert.equal(useApprovalStore.getState().queue.length, 1);+ // Cancel with every site chosen is this once: nothing is blocked or turned off.+ answer(false, "all");+ assert.equal(await elsewhere, false);+ assert.equal(useBrowserPrefsStore.getState().askBeforeDownloading, true);++ // Every site, on an ordinary file: ordinary files stop asking, programs still ask.+ const zip = approveDownload("https://h.example/a.zip", "a.zip");+ const exe = approveDownload("https://h.example/b.exe", "b.exe");+ const pdf = approveDownload("https://i.example/c.pdf", "c.pdf");+ answer(true, "all");+ assert.equal(await zip, true);+ assert.equal(await pdf, true);+ assert.deepEqual(useApprovalStore.getState().queue.map(({ name }) => name), ["b.exe"]);+ assert.equal(useBrowserPrefsStore.getState().askBeforeProgramDownloads, true);+ // Every site, on a program: programs stop asking too.+ answer(true, "all");+ assert.equal(await exe, true);+ assert.equal(useBrowserPrefsStore.getState().askBeforeProgramDownloads, false);+ assert.equal(await approveDownload("https://j.example/d.msi", "d.msi"), true);+ // A program saved from the context menu follows the every-site choice too.+ const { approveChosenDownload } = await import("../src/features/browser/download-approval-queue.ts");+ assert.equal(await approveChosenDownload("https://k.example/f.exe", "f.exe"), true);+ // The agent's downloads of programs still ask whatever the user chose.+ const agent = approveDownload("https://j.example/e.msi", "e.msi", undefined, "allow");+ assert.equal(useApprovalStore.getState().queue.length, 1);+ answer(false, false);+ assert.equal(await agent, false);+ } finally {+ useBrowserPrefsStore.getState().setAskBeforeDownloading(true);+ useBrowserPrefsStore.getState().setAskBeforeProgramDownloads(true);+ useDownloadSitesStore.getState().setSite("https://f.example", null);+ }+});++test("an answer remembered for other files never settles one the browser agent is waiting on", async () => {+ const { approveDownload, answerDownload, useApprovalStore } = await import(+ "../src/features/browser/download-approval-queue.ts"+ );+ const { useDownloadSitesStore } = await import("../src/features/browser/download-sites-store.ts");+ try {+ const mine = approveDownload("https://m.example/App.dmg", "App.dmg");+ const agents = approveDownload("https://m.example/Tool.dmg", "Tool.dmg", undefined, "allow");+ const agentZip = approveDownload("https://m.example/a.zip", "a.zip", undefined, "ask");+ answerDownload(useApprovalStore.getState().queue[0], true, "all");+ assert.equal(await mine, true);+ assert.deepEqual(useApprovalStore.getState().queue.map(({ name }) => name), ["Tool.dmg", "a.zip"]);+ answerDownload(useApprovalStore.getState().queue[0], true, true);+ assert.equal(await agents, true);+ assert.deepEqual(useApprovalStore.getState().queue.map(({ name }) => name), ["a.zip"]);+ answerDownload(useApprovalStore.getState().queue[0], false, false);+ assert.equal(await agentZip, false);+ } finally {+ useBrowserPrefsStore.getState().setAskBeforeDownloading(true);+ useBrowserPrefsStore.getState().setAskBeforeProgramDownloads(true);+ useDownloadSitesStore.getState().setSite("https://m.example", null);+ }});test("a finished download links to its history row, and an unrecorded one drops its forgotten native id", async () => {