fix(webui): keep settings restarts out of chat history
This commit is contained in:
1 parent
1e5ab8e95c
commit
77660ea8e5
5 files changed
+181
-5
No files matched your search
@@ -47,7 +47,11 @@ from nanobot.webui.file_preview import (
|
||||
from nanobot.webui.forking import handle_webui_fork_chat
|
||||
from nanobot.webui.gateway_services import GatewayServices
|
||||
from nanobot.webui.mcp_presets_api import normalize_mcp_preset_mentions
|
||||
from nanobot.webui.metadata import WEBSOCKET_TURN_OWNER_METADATA_KEY
|
||||
from nanobot.webui.metadata import (
|
||||
WEBSOCKET_TURN_OWNER_METADATA_KEY,
|
||||
WEBUI_RESTART_CONTROL_METADATA_KEY,
|
||||
WEBUI_SYSTEM_COMMAND_TURN_PREFIX,
|
||||
)
|
||||
from nanobot.webui.session_access import (
|
||||
SessionMention,
|
||||
WebuiSessionAccess,
|
||||
@@ -649,6 +653,17 @@ class WebUICommandRouter:
|
||||
metadata["webui"] = True
|
||||
metadata.update(self._transcripts.client_turn_metadata(envelope.get("turn_id")))
|
||||
trusted_webui = metadata.get("webui") is True and connection in self._webui_connections
|
||||
# The settings Restart button uses the existing silent command protocol.
|
||||
# Its routing chat ID is not a new conversation or a workspace update.
|
||||
restart_control = (
|
||||
trusted_webui
|
||||
and turn_id is not None
|
||||
and turn_id.startswith(WEBUI_SYSTEM_COMMAND_TURN_PREFIX)
|
||||
and content.strip().lower() == "/restart"
|
||||
and not media_paths
|
||||
)
|
||||
if restart_control:
|
||||
metadata[WEBUI_RESTART_CONTROL_METADATA_KEY] = True
|
||||
is_user_shell = (
|
||||
trusted_webui
|
||||
and envelope.get("user_shell") is True
|
||||
@@ -701,7 +716,7 @@ class WebUICommandRouter:
|
||||
|
||||
accepted = False
|
||||
try:
|
||||
if is_webui and (
|
||||
if is_webui and not restart_control and (
|
||||
temporary_policy is None or temporary_policy.persist_transcript
|
||||
):
|
||||
self._transcripts.append_user_message(
|
||||
@@ -746,7 +761,8 @@ class WebUICommandRouter:
|
||||
else False
|
||||
),
|
||||
)
|
||||
self._workspaces.persist_scope(chat_id, scope)
|
||||
if not restart_control:
|
||||
self._workspaces.persist_scope(chat_id, scope)
|
||||
accepted = True
|
||||
if turn_id:
|
||||
self._accepted_messages[(chat_id, turn_id)] = time.monotonic() + 600
|
||||
@@ -756,7 +772,7 @@ class WebUICommandRouter:
|
||||
if not accepted and queued_owner is not None:
|
||||
clear_websocket_turn_if_current(chat_id, queued_owner)
|
||||
|
||||
if is_webui:
|
||||
if is_webui and not restart_control:
|
||||
await self.broadcast_user_message(
|
||||
connection,
|
||||
chat_id,
|
||||
|
||||
@@ -2,5 +2,7 @@
|
||||
|
||||
WEBUI_TURN_METADATA_KEY = "webui_turn_id"
|
||||
WEBUI_SYSTEM_COMMAND_TURN_PREFIX = "webui-system:"
|
||||
# Set by authenticated WebUI ingress, never copied from an envelope's metadata.
|
||||
WEBUI_RESTART_CONTROL_METADATA_KEY = "_webui_restart_control"
|
||||
WEBSOCKET_TURN_OWNER_METADATA_KEY = "_websocket_turn_owner"
|
||||
WEBUI_MESSAGE_SOURCE_METADATA_KEY = "_webui_message_source"
|
||||
Reference in new issue
Block a user