feat: unify card runtime and event-driven web ui
This commit is contained in:
parent
0edf8c3fef
commit
4dfb7ca3cc
105 changed files with 17382 additions and 8505 deletions
|
|
@ -127,7 +127,13 @@ class NanobotApiProcess:
|
|||
self._read_task = asyncio.create_task(self._read_loop(), name="nanobot-api-reader")
|
||||
await self._bus.publish(WisperEvent(role="system", text="Connected to nanobot."))
|
||||
|
||||
async def send(self, text: str, metadata: dict[str, Any] | None = None) -> None:
|
||||
async def send(
|
||||
self,
|
||||
text: str,
|
||||
metadata: dict[str, Any] | None = None,
|
||||
*,
|
||||
chat_id: str = "web",
|
||||
) -> None:
|
||||
if not self.running or self._writer is None:
|
||||
await self._bus.publish(WisperEvent(role="system", text="Not connected to nanobot."))
|
||||
raise RuntimeError("Not connected to nanobot.")
|
||||
|
|
@ -136,7 +142,7 @@ class NanobotApiProcess:
|
|||
"message.send",
|
||||
{
|
||||
"content": text,
|
||||
"chat_id": "web",
|
||||
"chat_id": chat_id,
|
||||
"metadata": dict(metadata or {}),
|
||||
},
|
||||
)
|
||||
|
|
@ -161,7 +167,7 @@ class NanobotApiProcess:
|
|||
await self._cleanup()
|
||||
raise RuntimeError(f"Send failed: {exc}") from exc
|
||||
|
||||
async def send_command(self, command: str) -> None:
|
||||
async def send_command(self, command: str, *, chat_id: str = "web") -> None:
|
||||
if not self.running or self._writer is None:
|
||||
await self._bus.publish(WisperEvent(role="system", text="Not connected to nanobot."))
|
||||
raise RuntimeError("Not connected to nanobot.")
|
||||
|
|
@ -170,7 +176,7 @@ class NanobotApiProcess:
|
|||
"command.execute",
|
||||
{
|
||||
"command": command,
|
||||
"chat_id": "web",
|
||||
"chat_id": chat_id,
|
||||
},
|
||||
)
|
||||
except OSError as exc:
|
||||
|
|
@ -377,24 +383,30 @@ class SuperTonicGateway:
|
|||
raise RuntimeError("Not connected to nanobot.")
|
||||
return self._process
|
||||
|
||||
async def send_user_message(self, text: str, metadata: dict[str, Any] | None = None) -> None:
|
||||
async def send_user_message(
|
||||
self,
|
||||
text: str,
|
||||
metadata: dict[str, Any] | None = None,
|
||||
*,
|
||||
chat_id: str = "web",
|
||||
) -> None:
|
||||
message = text.strip()
|
||||
if not message:
|
||||
return
|
||||
await self.bus.publish(WisperEvent(role="user", text=message))
|
||||
async with self._lock:
|
||||
process = await self._ensure_connected_process()
|
||||
await process.send(message, metadata=metadata)
|
||||
await process.send(message, metadata=metadata, chat_id=chat_id)
|
||||
|
||||
async def send_card_response(self, card_id: str, value: str) -> None:
|
||||
async with self._lock:
|
||||
process = await self._ensure_connected_process()
|
||||
await process.send_card_response(card_id, value)
|
||||
|
||||
async def send_command(self, command: str) -> None:
|
||||
async def send_command(self, command: str, *, chat_id: str = "web") -> None:
|
||||
async with self._lock:
|
||||
process = await self._ensure_connected_process()
|
||||
await process.send_command(command)
|
||||
await process.send_command(command, chat_id=chat_id)
|
||||
|
||||
async def disconnect_nanobot(self) -> None:
|
||||
async with self._lock:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue