a2a-source-edit: write agent.py
This commit is contained in:
6
agent.py
6
agent.py
@@ -702,12 +702,16 @@ async def _write_workspace_text(ctx: RunContext[NoAuth], path: str, text: str, m
|
|||||||
if len(data) > MAX_TEXT_BYTES * 4:
|
if len(data) > MAX_TEXT_BYTES * 4:
|
||||||
raise ValueError("artifact exceeds bounded text size")
|
raise ValueError("artifact exceeds bounded text size")
|
||||||
ws = ctx.workspace
|
ws = ctx.workspace
|
||||||
|
if hasattr(ws, "is_writable_output") and ws.is_writable_output(clean): # type: ignore[attr-defined]
|
||||||
if hasattr(ws, "write_bytes"):
|
if hasattr(ws, "write_bytes"):
|
||||||
ws.write_bytes(clean, data) # type: ignore[attr-defined]
|
ws.write_bytes(clean, data) # type: ignore[attr-defined]
|
||||||
else:
|
else:
|
||||||
view = await ws.open_view(purpose=f"write {clean}", hints=[clean], max_files=1, mode=WorkspaceMode.READ_WRITE_OVERLAY, reason="Persist integration engineering output under outputs/integrations")
|
view = await ws.open_view(purpose=f"write {clean}", hints=[clean], max_files=1, mode=WorkspaceMode.READ_WRITE_OVERLAY, reason="Persist integration engineering output under outputs/integrations")
|
||||||
await view.write(clean, data)
|
await view.write(clean, data)
|
||||||
ref = await ctx.write_artifact(clean.split("/")[-1], data, mime_type)
|
else:
|
||||||
|
raise PermissionError("workspace grant does not allow writes under outputs/integrations")
|
||||||
|
artifact_name = clean.replace("/", "__")
|
||||||
|
ref = await ctx.write_artifact(artifact_name, data, mime_type)
|
||||||
await ctx.emit_artifact(ref)
|
await ctx.emit_artifact(ref)
|
||||||
return ArtifactRecord(path=clean, sha256=hashlib.sha256(data).hexdigest(), size_bytes=len(data), mime_type=mime_type)
|
return ArtifactRecord(path=clean, sha256=hashlib.sha256(data).hexdigest(), size_bytes=len(data), mime_type=mime_type)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user