From ef60c6eaac7de488a2e493a6b38a6e376f5bc3e1 Mon Sep 17 00:00:00 2001 From: a2a-cloud Date: Mon, 13 Jul 2026 02:48:17 +0000 Subject: [PATCH] a2a-source-edit: write agent.py --- agent.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/agent.py b/agent.py index 0604fcd..63c9f98 100644 --- a/agent.py +++ b/agent.py @@ -367,17 +367,20 @@ async def workspace_write_json(ctx: RunContext[NoAuth], path: str, data: BaseMod async def workspace_write_text(ctx: RunContext[NoAuth], path: str, text: str, mime: str = "text/plain") -> None: clean = validate_incident_path(path, _incident_id_from_path(path) or "unknown") + data = text.encode("utf-8") try: - grant = await ctx.workspace.request_access(files=[clean], mode=WorkspaceMode.READ_WRITE_OVERLAY, reason="write incident artifact", purpose="incident artifact write") - view = await ctx.workspace.open_view(purpose="write incident artifact", hints=[clean], max_files=1, mode=WorkspaceMode.READ_WRITE_OVERLAY, reason="write incident artifact") - # open_view search may not include a new output path, so use request grant path directly when available. + # Runtime workspace clients expose write_bytes for grant-scoped output + # writes. Use it directly so new incident artifacts under the approved + # outputs/incidents/ prefix are durable even before they appear in search. if hasattr(ctx.workspace, "write_bytes"): - ctx.workspace.write_bytes(clean, text.encode("utf-8")) + ctx.workspace.write_bytes(clean, data) else: - await view.write(clean, text.encode("utf-8")) - _ = grant + grant = await ctx.workspace.request_access(files=[clean], mode=WorkspaceMode.READ_WRITE_OVERLAY, reason="write incident artifact", purpose="incident artifact write") + view = await ctx.workspace.open_view(purpose="write incident artifact", hints=[clean], max_files=1, mode=WorkspaceMode.READ_WRITE_OVERLAY, reason="write incident artifact") + _ = grant + await view.write(clean, data) except Exception: - ref = await ctx.write_artifact(clean.split("/")[-1], text.encode("utf-8"), mime) + ref = await ctx.write_artifact(clean.split("/")[-1], data, mime) await ctx.emit_artifact(ref)