Agent Zero AI framework
feat(chats): allow explicit project selection on creation
Alessandro3a18d678aded
diff --git a/api/chat_create.py b/api/chat_create.pyindex 0ad9c7fc2..22b1b6340 100644--- a/api/chat_create.py+++ b/api/chat_create.py@@ -7,6 +7,17 @@ from agent import AgentContextclass CreateChat(ApiHandler):async def process(self, input: Input, request: Request) -> Output:+ # An explicit project choice takes precedence over chat inheritance.+ project_name = input.get("project_name")+ if "project_name" in input:+ if not isinstance(project_name, str):+ return Response("project_name must be a string", 400)+ if project_name:+ try:+ projects.validate_project_name(project_name)+ projects.load_basic_project_data(project_name)+ except (ValueError, FileNotFoundError):+ return Response("Project not found", 400)current_ctxid = input.get("current_context", "") # current context idnew_ctxid = input.get("new_context", guids.generate_id()) # given or new guid@@ -17,7 +28,12 @@ class CreateChat(ApiHandler):new_context = self.use_context(new_ctxid)# copy selected data from current to new context- if current_context and settings.get_settings().get("chat_inherit_project", True):+ if "project_name" in input:+ if project_name:+ projects.activate_project(new_context.id, project_name, mark_dirty=False)+ else:+ projects.deactivate_project(new_context.id, mark_dirty=False)+ elif current_context and settings.get_settings().get("chat_inherit_project", True):current_data_1 = current_context.get_data(projects.CONTEXT_DATA_KEY_PROJECT)if current_data_1:new_context.set_data(projects.CONTEXT_DATA_KEY_PROJECT, current_data_1)diff --git a/api/chat_create.py.dox.md b/api/chat_create.py.dox.mdindex 49f67a70a..d37295371 100644--- a/api/chat_create.py.dox.md+++ b/api/chat_create.py.dox.md@@ -22,6 +22,7 @@- `CreateChat` defines `process(...)`.- A newly created chat reconciles its profile after project inheritance, so itnever keeps a profile unavailable in the inherited scope.+- Optional `project_name` explicitly selects a project, with `""` meaning no project. Validate it before creating a context; an explicit choice overrides inheritance even when inheritance is disabled. Omitting it retains the existing behavior.- Observed side-effect areas: filesystem writes, model calls, plugin state, settings/state persistence.- Imported dependency areas include: `agent`, `helpers`, `helpers.api`.@@ -40,6 +41,7 @@- Run endpoint-specific or API/WebSocket tests for changed behavior; smoke-test browser callers when no focused test exists.- Related tests observed by source search:+ - `tests/test_chat_create.py`- `tests/test_browser_agent_regressions.py`## Child DOX Indexdiff --git a/tests/test_chat_create.py b/tests/test_chat_create.pynew file mode 100644index 000000000..2b1ce9076--- /dev/null+++ b/tests/test_chat_create.py@@ -0,0 +1,32 @@+import asyncio+from types import SimpleNamespace+++def test_explicit_new_chat_project_overrides_inheritance_and_validates_first(monkeypatch):+ from api import chat_create+ from helpers import state_monitor_integration++ current = SimpleNamespace(get_data=lambda key: "old" if key == "project" else None,+ get_output_data=lambda key: {"name": "old"})+ new = SimpleNamespace(id="new", set_data=lambda *args: None, set_output_data=lambda *args: None)+ monkeypatch.setattr(chat_create.AgentContext, "get", lambda id: current)+ monkeypatch.setattr(chat_create.settings, "get_settings", lambda: {"chat_inherit_project": True})+ monkeypatch.setattr(chat_create.projects, "load_basic_project_data", lambda name: {})+ monkeypatch.setattr(chat_create.projects, "get_context_project_name", lambda context: None)+ monkeypatch.setattr(chat_create.projects, "reconcile_agent_profile", lambda *args: None)+ monkeypatch.setattr(state_monitor_integration, "mark_dirty_all", lambda **kwargs: None)+ created, assigned = [], []+ handler = chat_create.CreateChat(None, None)+ monkeypatch.setattr(handler, "use_context", lambda id: created.append(id) or new)+ monkeypatch.setattr(chat_create.projects, "activate_project", lambda id, name, **kwargs: assigned.append(name))+ monkeypatch.setattr(chat_create.projects, "deactivate_project", lambda id, **kwargs: assigned.append(""))++ for name in ("project-b", ""):+ result = asyncio.run(handler.process({"current_context": "old", "project_name": name}, None))+ assert result["ctxid"] == "new"+ assert assigned == ["project-b", ""]+ created.clear()+ for name in ("../escape", None, {}):+ result = asyncio.run(handler.process({"project_name": name}, None))+ assert result.status_code == 400+ assert created == []diff --git a/webui/components/sidebar/AGENTS.md b/webui/components/sidebar/AGENTS.mdindex c09c961ef..b02426040 100644--- a/webui/components/sidebar/AGENTS.md+++ b/webui/components/sidebar/AGENTS.md@@ -27,6 +27,7 @@- `chats.saveChat(ctxid)` exports an explicit context without changing selection; omitted IDs retain current-chat behavior.- Cancelling the Load Chat file chooser resolves without calling `chat_load` or showing a success/error notification.- `sidebar-row-actions-menu` owns plugin-contributed row-menu actions; list-order plugins register stable sort and divider callbacks through the sidebar store instead of patching chat/task stores or injecting row DOM.+- `chats.newChat(projectName)` passes an explicit project choice to `chat_create`; omitted project names retain inheritance behavior, and an empty name explicitly creates a chat without a project.- Bottom version information shows its commit timestamp in UTC without a timezone suffix and remains on one line.- Avoid text or controls overflowing fixed sidebar widths.- Instance-level interface visibility preferences own independent mobile and desktop states for the chat-top controls and right canvas rail; mobile uses the shared 768px breakpoint.diff --git a/webui/components/sidebar/chats/chats-store.js b/webui/components/sidebar/chats/chats-store.jsindex 51c761963..4d5301c77 100644--- a/webui/components/sidebar/chats/chats-store.js+++ b/webui/components/sidebar/chats/chats-store.js@@ -259,12 +259,13 @@ const model = {},// Create new chat- async newChat() {+ async newChat(projectName = undefined) {try {// first create a new chat on the backendconst response = await sendJsonData("/chat_create", {- current_context: this.selected+ current_context: this.selected,+ ...(projectName !== undefined ? { project_name: projectName } : {}),});if (response.ok) {