MCPcopy Index your code
hub / github.com/AstrBotDevs/AstrBot / handle_result

Function handle_result

astrbot/core/tools/computer_tools/python.py:46–74  ·  view source on GitHub ↗
(result: dict, event: AstrMessageEvent)

Source from the content-addressed store, hash-verified

44
45
46async 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)

Callers 2

callMethod · 0.85
callMethod · 0.85

Calls 6

MessageChainClass · 0.90
base64_imageMethod · 0.80
getMethod · 0.45
appendMethod · 0.45
get_platform_nameMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected