(result: dict, event: AstrMessageEvent)
| 44 | |
| 45 | |
| 46 | async def handle_result(result: dict, event: AstrMessageEvent) -> ToolExecResult: |
| 47 | data = result.get("data", {}) |
| 48 | output = data.get("output", {}) |
| 49 | error = data.get("error", "") |
| 50 | images: list[dict] = output.get("images", []) |
| 51 | text: str = output.get("text", "") |
| 52 | |
| 53 | resp = mcp.types.CallToolResult(content=[]) |
| 54 | |
| 55 | if error: |
| 56 | resp.content.append(mcp.types.TextContent(type="text", text=f"error: {error}")) |
| 57 | |
| 58 | if images: |
| 59 | for img in images: |
| 60 | resp.content.append( |
| 61 | mcp.types.ImageContent( |
| 62 | type="image", data=img["image/png"], mimeType="image/png" |
| 63 | ) |
| 64 | ) |
| 65 | |
| 66 | if event.get_platform_name() == "webchat": |
| 67 | await event.send(message=MessageChain().base64_image(img["image/png"])) |
| 68 | if text: |
| 69 | resp.content.append(mcp.types.TextContent(type="text", text=text)) |
| 70 | |
| 71 | if not resp.content: |
| 72 | resp.content.append(mcp.types.TextContent(type="text", text="No output.")) |
| 73 | |
| 74 | return resp |
| 75 | |
| 76 | |
| 77 | @builtin_tool(config=_SANDBOX_PYTHON_TOOL_CONFIG) |
no test coverage detected