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 chat's files in the Library after it moves into a project (#14044)
Nilaycaffebd4fd1b
diff --git a/studio/backend/core/library.py b/studio/backend/core/library.pyindex ae7c013d426..fd2bc706f43 100644--- a/studio/backend/core/library.py+++ b/studio/backend/core/library.py@@ -814,14 +814,13 @@ def _sandbox_sessions() -> list[_SandboxSession]:conn = get_connection()try:- threads = conn.execute(- "SELECT id, title, pair_id FROM chat_threads WHERE project_id IS NULL"- ).fetchall()+ threads = conn.execute("SELECT id, title, pair_id FROM chat_threads").fetchall()projects = conn.execute("SELECT id, name, root_path FROM chat_projects WHERE COALESCE(working_folder, '') = ''").fetchall()finally:conn.close()+ thread_ids = {row["id"] for row in threads}return [_SandboxSession(row["id"], row["id"], row["title"], pair_id = row["pair_id"])for row in threads@@ -830,7 +829,9 @@ def _sandbox_sessions() -> list[_SandboxSession]:f"{_PROJECT_SESSION_PREFIX}{row['id']}", None, row["name"], project_id = row["id"])for row in projects- if _studio_project_root(row["root_path"])+ # A chat with this id owns the directory (_get_project_workdir): listing both walks it twice.+ if f"{_PROJECT_SESSION_PREFIX}{row['id']}" not in thread_ids+ and _studio_project_root(row["root_path"])]@@ -853,9 +854,7 @@ def _sandbox_session_eligible(session_id: str) -> bool:conn = get_connection()try:- if conn.execute(- "SELECT 1 FROM chat_threads WHERE id = ? AND project_id IS NULL", (session_id,)- ).fetchone():+ if conn.execute("SELECT 1 FROM chat_threads WHERE id = ?", (session_id,)).fetchone():return Trueif not session_id.startswith(_PROJECT_SESSION_PREFIX):return Falsediff --git a/studio/backend/tests/test_library_routes.py b/studio/backend/tests/test_library_routes.pyindex c3c1ec5a186..5215cb0602c 100644--- a/studio/backend/tests/test_library_routes.py+++ b/studio/backend/tests/test_library_routes.py@@ -584,6 +584,28 @@ def test_a_sandbox_file_of_a_chat_whose_id_has_a_colon_is_reachable(client, signassert _items(client)[0] == {}+def test_a_chats_files_stay_listed_after_it_is_moved_into_a_project(+ client, signed_in, monkeypatch, tmp_path+):+ from storage import studio_db++ monkeypatch.setenv("UNSLOTH_STUDIO_PROJECTS_HOME", str(tmp_path / "Projects home"))+ monkeypatch.setattr(library, "_SOURCES", (library._sandbox_items,))+ _sandbox_chat("a.txt", b"mine")+ folder = _folder(client, "Charts", None)+ _patch(client, id = _SANDBOX_A, name = "Chart", favorite = True, folderId = folder)+ studio_db.upsert_chat_project(+ {"id": "p-lib", "name": "Research", "createdAt": 1, "updatedAt": 1}+ )+ studio_db.update_chat_thread("t-lib", {"projectId": "p-lib"})+ library.invalidate_listing()+ item = _items(client)[0][_SANDBOX_A]+ assert (item["name"], item["favorite"], item["folderId"]) == ("Chart", True, folder)+ assert item["threadId"] == "t-lib"+ assert _download(client, _SANDBOX_A).content == b"mine"+ assert _delete(client, _SANDBOX_A) == 200++def test_a_sandbox_file_written_twice_in_a_second_is_a_new_version(client, signed_in, monkeypatch):monkeypatch.setattr(library, "_SOURCES", (library._sandbox_items,))_directory, path = _sandbox_chat("frame.png", b"one")@@ -2834,3 +2856,24 @@ def test_a_stream_link_reads_only_its_own_accounts_item(client, two_accounts):assert response.status_code == 404 and b"bob" not in response.contentassert _stream(theirs_id, sign(alice, mine_id)).status_code == 401assert _stream(mine_id, sign(OWNER, mine_id)).status_code == 404++[email protected]("in_project", [False, True])+def test_a_chat_named_like_its_project_session_is_listed_once(+ client, signed_in, monkeypatch, tmp_path, in_project+):+ from storage import studio_db++ monkeypatch.setenv("UNSLOTH_STUDIO_PROJECTS_HOME", str(tmp_path / "Projects home"))+ monkeypatch.setattr(library, "_SOURCES", (library._sandbox_items,))+ studio_db.upsert_chat_project(+ {"id": "p-lib", "name": "Research", "createdAt": 1, "updatedAt": 1}+ )+ _sandbox_chat("a.txt", b"mine", thread = "project-p-lib")+ if in_project:+ studio_db.update_chat_thread("project-p-lib", {"projectId": "p-lib"})+ library.invalidate_listing()+ body = client.get("/api/library").json()["items"]+ ids = [item["id"] for item in body]+ assert ids.count("sandbox:project-p-lib:a.txt") == 1+ assert body[ids.index("sandbox:project-p-lib:a.txt")]["threadId"] == "project-p-lib"