feat: update openclaw workspace integration

This commit is contained in:
2026-03-27 22:27:16 +08:00
parent 5c08c1865c
commit 4aa69650e8
26 changed files with 2103 additions and 310 deletions

View File

@@ -517,11 +517,13 @@ class OpenClawWebSocketClient:
params["agentId"] = agent_id
if label:
params["label"] = label
if channel:
params["channel"] = channel
result = await self._send_request("sessions.resolve", params)
sessions = result.get("sessions", [])
if sessions:
return sessions[0].get("key")
key = result.get("key")
if isinstance(key, str) and key.strip():
return key.strip()
return None
async def send_message(
@@ -549,12 +551,30 @@ class OpenClawWebSocketClient:
if thinking:
params["thinking"] = thinking
# Use shorter timeout for send since it waits for agent response
result = await self._send_request(
"sessions.send",
params,
)
return result
previous_timeout_ms = self.timeout_ms
if timeout_ms is not None:
self.timeout_ms = timeout_ms
try:
return await self._send_request("sessions.send", params)
finally:
self.timeout_ms = previous_timeout_ms
async def unsubscribe(self, session_key: str) -> dict[str, Any]:
"""Unsubscribe from messages for a session."""
return await self._send_request("sessions.messages.unsubscribe", {"key": session_key})
async def get_session_history(
self,
session_key: str,
limit: int = 20,
) -> dict[str, Any]:
"""Best-effort session history read.
OpenClaw's public Gateway surface is subscription-first for live message flow.
History is not consistently exposed over the same WS methods across builds, so
callers should still keep a CLI or REST fallback available.
"""
return await self._send_request("sessions.preview", {"keys": [session_key], "limit": limit})
async def subscribe(self, session_key: str) -> AsyncMessageIterator:
"""Subscribe to messages from a session.
@@ -670,6 +690,11 @@ class AsyncMessageIterator:
async def __anext__(self) -> MessageEvent:
return await self._queue.get()
async def aclose(self) -> None:
if self._handler_added:
self._client.remove_event_handler(self._on_event)
self._handler_added = False
# -----------------------------------------------------------------------------
# Synchronous convenience functions