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: attach duplicate-named text files like LICENSE(1), and say why a file can't be attached (#14977)
Michael Hanbf172053ac80
diff --git a/studio/frontend/src/features/chat/runtime-provider.tsx b/studio/frontend/src/features/chat/runtime-provider.tsxindex a64f0f2067a..d73273fe25e 100644--- a/studio/frontend/src/features/chat/runtime-provider.tsx+++ b/studio/frontend/src/features/chat/runtime-provider.tsx@@ -95,6 +95,7 @@ import {isBinaryOfficeTemplate,isCompiledFortranModule,isBinaryVobSubSubtitle,+ isTextAttachmentName,readTextAttachmentOnce,UndecodableTextError,} from "./text-attachment-accept";@@ -301,6 +302,21 @@ const pendingRunStartReadyByMessageId = new Map<>();const pendingRunStartThreadIdsByMessageId = new Map<string, string[]>();+function matchesAccept(file: { name: string; type: string }, accept: string): boolean {+ if (accept === "*") return true;+ const extension = `.${file.name.split(".").pop()?.toLowerCase() ?? ""}`;+ const mime = file.type.toLowerCase();+ return accept.split(",").some((entry) => {+ const token = entry.trim().toLowerCase();+ if (token.startsWith(".")) return token === extension;+ if (token.endsWith("/*")) return mime.startsWith(token.slice(0, -1));+ return token === mime;+ });+}++const UNSUPPORTED_ATTACHMENT_HINT =+ "Attach images, audio, video, PDFs, Office and OpenDocument files, e-books, email, or text and code files.";+class PreStreamAwareAttachmentAdapter implements AttachmentAdapter {private readonly delegate: AttachmentAdapter;private readonly getThreadIds: () => Array<string | null | undefined>;@@ -313,11 +329,23 @@ class PreStreamAwareAttachmentAdapter implements AttachmentAdapter {this.getThreadIds = getThreadIds;}- get accept(): string {- return this.delegate.accept;- }+ // "*": the runtime's own check refuses silently, so add() toasts instead.+ readonly accept = "*";add(state: { file: File }) {+ let file = state.file;+ if (!matchesAccept(file, this.delegate.accept) && isTextAttachmentName(file.name)) {+ file = new File([file], file.name, {+ type: "text/plain",+ lastModified: file.lastModified,+ });+ }+ if (!matchesAccept(file, this.delegate.accept)) {+ const reason = `${file.name} can't be attached`;+ toast.error(reason, { description: UNSUPPORTED_ATTACHMENT_HINT });+ throw new Error(reason);+ }+ if (file !== state.file) state = { ...state, file };// A composite picks its adapter synchronously from the name and MIME type, and both say "video"// for an audio-only 3GP recording or a TypeScript .ts, so settle that from the file's own bytes// first, as the native readers do. Every other file goes straight through.diff --git a/studio/frontend/src/features/chat/text-attachment-accept.ts b/studio/frontend/src/features/chat/text-attachment-accept.tsindex e90afbfe883..a727915da53 100644--- a/studio/frontend/src/features/chat/text-attachment-accept.ts+++ b/studio/frontend/src/features/chat/text-attachment-accept.ts@@ -369,12 +369,15 @@ export const TEXT_ATTACHMENT_BASENAMES = [".htaccess",] as const;const PATH_SEPARATOR_RE = /[\\/]/;+// "LICENSE(1)", "README copy 2"; mirrored in native_path_policy.rs.+const DUPLICATE_SUFFIX_RE = /(?:\s*\(\d+\)|\s+(?:-\s+)?copy(?:\s+\d+)?)+$/i;/** Whether a path or filename belongs to the inline UTF-8 text adapter. */export function isTextAttachmentName(path: string): boolean {const segments = path.split(PATH_SEPARATOR_RE);const name = (segments[segments.length - 1] || path).toLowerCase();- if ((TEXT_ATTACHMENT_BASENAMES as readonly string[]).includes(name)) {+ const base = name.replace(DUPLICATE_SUFFIX_RE, "") || name;+ if ((TEXT_ATTACHMENT_BASENAMES as readonly string[]).includes(base)) {return true;}const dot = name.lastIndexOf(".");diff --git a/studio/frontend/src/features/native-intents/drop-paths.ts b/studio/frontend/src/features/native-intents/drop-paths.tsindex 442fda71301..bf6417919c5 100644--- a/studio/frontend/src/features/native-intents/drop-paths.ts+++ b/studio/frontend/src/features/native-intents/drop-paths.ts@@ -11,14 +11,10 @@ import {isServerDocumentAttachmentName,isToolOnlyAttachmentName,} from "../chat/open-document-accept.ts";-import {- TEXT_ATTACHMENT_BASENAMES,- TEXT_ATTACHMENT_EXTENSIONS,-} from "../chat/text-attachment-accept.ts";+import { isTextAttachmentName } from "../chat/text-attachment-accept.ts";import { MAX_AUDIO_FILES } from "../../lib/audio-utils.ts";const DOC_EXTS = [".pdf", ".html", ".htm", ".docx", ".xlsx", ".xlsm", ".pptx"];-const TEXT_EXTS = TEXT_ATTACHMENT_EXTENSIONS.map((ext) => ext.toLowerCase());export function isComposerAttachmentName(path: string): boolean {return (@@ -27,20 +23,10 @@ export function isComposerAttachmentName(path: string): boolean {isRtfAttachmentName(path) ||isServerDocumentAttachmentName(path) ||isToolOnlyAttachmentName(path) ||- isTextDropName(path)+ isTextAttachmentName(path));}-function isTextDropName(path: string): boolean {- const name = nativeFileName(path).toLowerCase();- if ((TEXT_ATTACHMENT_BASENAMES as readonly string[]).includes(name)) {- return true;- }- // Other dotfiles, ".env" among them, have no extension and remain unsupported.- const dot = name.lastIndexOf(".");- return dot > 0 && TEXT_EXTS.includes(name.slice(dot));-}-export const CHAT_IMAGE_DROP_ACCEPT = CHAT_IMAGE_EXTENSIONS;const IMAGE_EXTS = CHAT_IMAGE_DROP_ACCEPT.split(",").map((ext) =>diff --git a/studio/frontend/tests/native-drop-paths.test.ts b/studio/frontend/tests/native-drop-paths.test.tsindex 711e43329b3..9e37fd62600 100644--- a/studio/frontend/tests/native-drop-paths.test.ts+++ b/studio/frontend/tests/native-drop-paths.test.ts@@ -1023,8 +1023,19 @@ test("every basename the picker claims is one the drop paths accept", () => {assert.equal(isTextAttachmentName(name), true, `${name} is droppable`);assert.equal(classifyDropPaths([`/repo/${name}`]).kind, "docs", name);}+ for (const name of [+ "LICENSE(1)",+ "LICENSE (2)",+ "README copy",+ "README copy 2",+ "Makefile - Copy (3)",+ ".gitignore (1)",+ ]) {+ assert.equal(isTextAttachmentName(name), true, `${name} is droppable`);+ assert.equal(classifyDropPaths([`/repo/${name}`]).kind, "docs", name);+ }// Unlisted names stay out of both, rather than being widened; .env usually holds secrets.- for (const name of ["notes", ".env", ".DS_Store"]) {+ for (const name of ["notes", ".env", ".DS_Store", "notes(1)", ".env (1)", "copy", "(1)", "notes.txt(1)"]) {assert.equal(isTextAttachmentName(name), false, name);assert.equal(classifyDropPaths([`/repo/${name}`]).kind, "unsupported", name);}diff --git a/studio/src-tauri/src/native_path_policy.rs b/studio/src-tauri/src/native_path_policy.rsindex 9d87b90a87e..11891505487 100644--- a/studio/src-tauri/src/native_path_policy.rs+++ b/studio/src-tauri/src/native_path_policy.rs@@ -509,7 +509,35 @@ pub fn is_text_attachment_name(path: &Path) -> bool {path.file_name().and_then(|value| value.to_str()).map(|value| value.to_ascii_lowercase())- .is_some_and(|name| TEXT_ATTACHMENT_NAMES.contains(&name.as_str()))+ .is_some_and(|name| TEXT_ATTACHMENT_NAMES.contains(&without_duplicate_suffix(&name)))+}++fn without_duplicate_suffix(name: &str) -> &str {+ let mut rest = name;+ while let Some(shorter) = strip_counter_suffix(rest).or_else(|| strip_copy_suffix(rest)) {+ if shorter.is_empty() {+ break;+ }+ rest = shorter;+ }+ rest+}++fn strip_counter_suffix(name: &str) -> Option<&str> {+ let inner = name.strip_suffix(')')?;+ let open = inner.rfind('(')?;+ let digits = &inner[open + 1..];+ (!digits.is_empty() && digits.bytes().all(|b| b.is_ascii_digit()))+ .then(|| inner[..open].trim_end())+}++fn strip_copy_suffix(name: &str) -> Option<&str> {+ let unnumbered = match name.rsplit_once(' ') {+ Some((head, tail)) if !tail.is_empty() && tail.bytes().all(|b| b.is_ascii_digit()) => head,+ _ => name,+ };+ let base = unnumbered.strip_suffix(" copy")?;+ Some(base.strip_suffix(" -").unwrap_or(base).trim_end())}pub fn is_binary_property_list(path: &Path, bytes: &[u8]) -> bool {@@ -1357,6 +1385,23 @@ mod tests {))}+ #[test]+ fn duplicate_download_names_stay_text_attachments() {+ for name in [+ "LICENSE(1)",+ "LICENSE (2)",+ "README copy",+ "README copy 2",+ "Makefile - Copy (3)",+ ".gitignore (1)",+ ] {+ assert!(is_text_attachment_name(Path::new(name)), "{name}");+ }+ for name in ["notes(1)", ".env (1)", "copy", "(1)", "LICENSE(x)", "notes.txt(1)"] {+ assert!(!is_text_attachment_name(Path::new(name)), "{name}");+ }+ }+#[test]fn gguf_model_allows_validate_load_reveal() {let path = temp_path("model").with_extension("gguf");