a2a-source-edit: write agent.py
This commit is contained in:
15
agent.py
15
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:
|
||||
# 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, data)
|
||||
else:
|
||||
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.
|
||||
if hasattr(ctx.workspace, "write_bytes"):
|
||||
ctx.workspace.write_bytes(clean, text.encode("utf-8"))
|
||||
else:
|
||||
await view.write(clean, text.encode("utf-8"))
|
||||
_ = 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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user