Agent Zero AI framework
Fix Office artifact creation and canvas closing
Alessandrobaac20f7a474
diff --git a/plugins/_office/tools/document_artifact.py b/plugins/_office/tools/document_artifact.pyindex 0718a111f..09470874d 100644--- a/plugins/_office/tools/document_artifact.py+++ b/plugins/_office/tools/document_artifact.py@@ -28,9 +28,10 @@ class DocumentArtifact(Tool):chart: Any = None,slides: Any = None,max_chars: int | str = 12000,+ method: str = "",**kwargs: Any,) -> Response:- action = str(action or self.method or "status").strip().lower().replace("-", "_")+ action = str(action or method or self.method or "status").strip().lower().replace("-", "_")try:if action == "create":doc = document_store.create_document(diff --git a/tests/test_office_canvas_setup.py b/tests/test_office_canvas_setup.pyindex b6475afc0..7625f615a 100644--- a/tests/test_office_canvas_setup.py+++ b/tests/test_office_canvas_setup.py@@ -300,6 +300,11 @@ def test_right_canvas_requires_explicit_open_and_is_absent_on_mobile():assert "if (this.isMobileMode)" in canvas_storeassert "shouldRender()" in canvas_storeassert "$store.rightCanvas.shouldRender()" in canvas_html+ assert 'title="Open as window"' in canvas_html+ assert 'title="Close canvas"' in canvas_html+ assert 'aria-label="Close canvas"' in canvas_html+ assert "@click=\"$store.rightCanvas.close()\"" in canvas_html+ assert canvas_html.index('title="Open as window"') < canvas_html.index('title="Close canvas"')assert "body.right-canvas-mobile-mode .right-canvas" in canvas_cssassert "display: none !important" in canvas_cssassert "autoOpenOfficeCanvas" not in handlerdiff --git a/tests/test_office_document_store.py b/tests/test_office_document_store.pyindex 65c62a57a..9a238120b 100644--- a/tests/test_office_document_store.py+++ b/tests/test_office_document_store.py@@ -1,5 +1,6 @@from __future__ import annotations+import asyncioimport importlib.utilimport jsonimport os@@ -127,6 +128,62 @@ def test_xlsx_and_pptx_creation_and_direct_edits_still_work(office_state):assert deck_read["slides"][1]["title"] == "Next"+def test_document_artifact_accepts_method_alias_for_xlsx_create(office_state, monkeypatch):+ tool_module = types.ModuleType("helpers.tool")++ class Response:+ def __init__(self, message, break_loop, additional=None):+ self.message = message+ self.break_loop = break_loop+ self.additional = additional++ class Tool:+ def __init__(self, agent, name, method, args, message, loop_data, **kwargs):+ self.agent = agent+ self.name = name+ self.method = method+ self.args = args+ self.message = message+ self.loop_data = loop_data++ tool_module.Response = Response+ tool_module.Tool = Tool+ monkeypatch.setitem(sys.modules, "helpers.tool", tool_module)+ spec = importlib.util.spec_from_file_location(+ "test_document_artifact_tool",+ PROJECT_ROOT / "plugins" / "_office" / "tools" / "document_artifact.py",+ )+ document_artifact_module = importlib.util.module_from_spec(spec)+ assert spec and spec.loader+ spec.loader.exec_module(document_artifact_module)+ DocumentArtifact = document_artifact_module.DocumentArtifact++ tool = DocumentArtifact(+ agent=None,+ name="document_artifact",+ method=None,+ args={},+ message="",+ loop_data=None,+ )++ response = asyncio.run(+ tool.execute(+ method="create",+ kind="document",+ title="New Excel Workbook",+ format="xlsx",+ content="Sheet1\n",+ )+ )+ payload = json.loads(response.message)++ assert payload["action"] == "create"+ assert payload["document"]["extension"] == "xlsx"+ assert Path(payload["document"]["path"]).name == "New Excel Workbook.xlsx"+ assert Path(document_store._path_from_a0(payload["document"]["path"])).exists()++def test_odt_is_not_advertised_and_returns_clear_unsupported_response(office_state):prompt = (PROJECT_ROOT / "plugins" / "_office" / "prompts" / "agent.system.tool.document_artifact.md").read_text(encoding="utf-8",diff --git a/webui/components/canvas/right-canvas.html b/webui/components/canvas/right-canvas.htmlindex d105dc5a5..3cba11a98 100644--- a/webui/components/canvas/right-canvas.html+++ b/webui/components/canvas/right-canvas.html@@ -98,6 +98,15 @@><span class="material-symbols-outlined">open_in_new</span></button>+ <button+ type="button"+ class="right-canvas-icon-button right-canvas-close-button"+ title="Close canvas"+ aria-label="Close canvas"+ @click="$store.rightCanvas.close()"+ >+ <span class="material-symbols-outlined">close</span>+ </button><x-extension id="right-canvas-toolbar-end"></x-extension></div></header>