mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 17:54:04 +00:00
Add a bounded `chat.message.get` gateway method so Control UI can fetch one display-normalized transcript message by id when an assistant history preview was truncated. Keep `chat.history` lightweight, reject oversized/hidden/missing rows with explicit unavailable reasons, and wire the WebChat side reader to request full content only for visible truncated assistant messages. Also refresh the generated Swift gateway protocol models and document the new assistant-message side-reader behavior. Closes #84651. Related #53242. Co-authored-by: NianJiuZst <3235467914@qq.com>
8.0 KiB
8.0 KiB
summary, read_when, title
| summary | read_when | title | |
|---|---|---|---|
| Loopback WebChat static host and Gateway WS usage for chat UI |
|
WebChat |
Status: the macOS/iOS SwiftUI chat UI talks directly to the Gateway WebSocket.
What it is
- A native chat UI for the gateway (no embedded browser and no local static server).
- Uses the same sessions and routing rules as other channels.
- Deterministic routing: replies always go back to WebChat.
Quick start
- Start the gateway.
- Open the WebChat UI (macOS/iOS app) or the Control UI chat tab.
- Ensure a valid gateway auth path is configured (shared-secret by default, even on loopback).
How it works (behavior)
- The UI connects to the Gateway WebSocket and uses
chat.history,chat.send, andchat.inject. chat.historyis bounded for stability: Gateway may truncate long text fields, omit heavy metadata, and replace oversized entries with[chat.history omitted: message too large].- When a visible assistant message was truncated in
chat.history, Control UI can open a side reader and fetch the full display-normalized entry on demand throughchat.message.getwithout increasing the default history payload. chat.historyfollows the active transcript branch for modern append-only session files, so abandoned rewrite branches and superseded prompt copies are not rendered in WebChat.- Compaction entries render as an explicit compacted-history divider. The divider explains that the compacted transcript is preserved as a checkpoint and links to the Sessions checkpoint controls, where operators can branch or restore from that compacted view when their permissions allow it.
- Control UI remembers the backing Gateway
sessionIdreturned bychat.historyand includes it on follow-upchat.sendcalls, so reconnects and page refreshes continue the same stored conversation unless the user starts or resets a session. - Control UI coalesces duplicate in-flight submits for the same session, message, and attachments before generating a new
chat.sendrun id; the Gateway still dedupes repeated requests that reuse the same idempotency key. - Workspace startup files and pending
BOOTSTRAP.mdinstructions are supplied through the agent system prompt's Project Context, not copied into the WebChat user message. Bootstrap truncation only adds a concise system-prompt recovery notice; detailed counts and config knobs stay on diagnostic surfaces. chat.historyis also display-normalized: runtime-only OpenClaw context, inbound envelope wrappers, inline delivery directive tags such as[[reply_to_*]]and[[audio_as_voice]], plain-text tool-call XML payloads (including<tool_call>...</tool_call>,<function_call>...</function_call>,<tool_calls>...</tool_calls>,<function_calls>...</function_calls>, and truncated tool-call blocks), and leaked ASCII/full-width model control tokens are stripped from visible text, and assistant entries whose whole visible text is only the exact silent tokenNO_REPLY/no_replyare omitted.- Reasoning-flagged reply payloads (
isReasoning: true) are excluded from WebChat assistant content, transcript replay text, and audio content blocks, so thinking-only payloads do not surface as visible assistant messages or playable audio. chat.injectappends an assistant note directly to the transcript and broadcasts it to the UI (no agent run).- Aborted runs can keep partial assistant output visible in the UI.
- Gateway persists aborted partial assistant text into transcript history when buffered output exists, and marks those entries with abort metadata.
- History is always fetched from the gateway (no local file watching).
- If the gateway is unreachable, WebChat is read-only.
Transcript and delivery model
WebChat has two separate data paths:
- The session JSONL file is the durable model/runtime transcript. For normal agent runs, the embedded OpenClaw runtime persists model-visible
user,assistant, andtoolResultmessages through its session manager. WebChat does not write arbitrary delivery, status, or helper text into that transcript. - Gateway
ReplyPayloadevents are the live delivery projection. They can be normalized for WebChat/channel display, block streaming, directive tags, media embedding, TTS/audio flags, and UI fallback behavior. They are not themselves the canonical session log. - Harnesses that require visible replies through
tools.messagestill use WebChat as a current-run internal source reply sink. A targetlessmessage.sendfrom that active WebChat run is projected into the same chat and mirrored to the session transcript; WebChat does not become a reusable outbound channel and never inheritslastChannel. - WebChat injects assistant transcript entries only when the Gateway owns a displayed message outside a normal embedded agent turn:
chat.inject, non-agent command replies, aborted partial output, and WebChat-managed media transcript supplements. chat.historyreads the stored session transcript and applies WebChat display projection. If live assistant text appears during a run but disappears after history reload, first check whether the raw JSONL contains the assistant text, then whetherchat.historyprojection stripped it, then whether the Control UI optimistic-tail merge replaced local delivery state with the persisted snapshot.chat.message.getuses the same transcript branch and display projection rules aschat.history, including active-agent scoping, but targets one transcript entry bymessageIdand returns an honest unavailable reason when the full content can no longer be returned.
Normal agent-run final answers should be durable because the embedded runtime writes the assistant message_end. Any fallback that mirrors a delivered final payload into the transcript must first avoid duplicating an assistant turn that the embedded runtime already wrote.
Control UI agents tools panel
- The Control UI
/agentsTools panel has two separate views:- Available Right Now uses
tools.effective(sessionKey=...)and shows a server-derived read-only projection of the current session inventory, including core, plugin, channel-owned, and already-discovered MCP server tools. - Tool Configuration uses
tools.catalogand stays focused on profiles, overrides, and catalog semantics.
- Available Right Now uses
- Runtime availability is session-scoped. Switching sessions on the same agent can change the Available Right Now list. If configured MCP servers have not been connected or were changed since the last discovery, the panel shows a notice instead of silently starting MCP transports from the read path.
- The config editor does not imply runtime availability; effective access still follows policy
precedence (
allow/deny, per-agent and provider/channel overrides).
Remote use
- Remote mode tunnels the gateway WebSocket over SSH/Tailscale.
- You do not need to run a separate WebChat server.
Configuration reference (WebChat)
Full configuration: Configuration
WebChat options:
gateway.webchat.chatHistoryMaxChars: maximum character count for text fields inchat.historyresponses. When a transcript entry exceeds this limit, Gateway truncates long text fields and may replace oversized messages with a placeholder. Per-requestmaxCharscan also be sent by the client to override this default for a singlechat.historycall.
Related global options:
gateway.port,gateway.bind: WebSocket host/port.gateway.auth.mode,gateway.auth.token,gateway.auth.password: shared-secret WebSocket auth.gateway.auth.allowTailscale: browser Control UI chat tab can use Tailscale Serve identity headers when enabled.gateway.auth.mode: "trusted-proxy": reverse-proxy auth for browser clients behind an identity-aware non-loopback proxy source (see Trusted Proxy Auth).gateway.remote.url,gateway.remote.token,gateway.remote.password: remote gateway target.session.*: session storage and main key defaults.