a2a-source-edit: write agent.py

This commit is contained in:
a2a-cloud
2026-07-13 02:48:17 +00:00
parent 8f6af81ce2
commit ef60c6eaac

View File

@@ -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)