refactor: introduce transport-neutral connection runtime

This commit is contained in:
caixypromise
2026-07-27 02:05:26 +08:00
parent f5ed1aaec8
commit 0c582ed3b6
56 changed files with 9931 additions and 237 deletions
@@ -350,4 +350,16 @@ async def send_display_message(conn: "ConnectionHandler", text):
"text": text,
"session_id": conn.session_id
}
await conn.websocket.send(json.dumps(message))
transport = getattr(conn, "transport", None)
if transport is not None:
send_json = getattr(transport, "send_json", None)
if callable(send_json):
await send_json(message)
else:
await transport.send(json.dumps(message))
return
websocket = getattr(conn, "websocket", None)
if websocket is None:
raise AttributeError("无法找到可用的传输层接口")
await websocket.send(json.dumps(message))