From 5b88700660dc30b9f9e38b3aaa05bfdfd1f8bba9 Mon Sep 17 00:00:00 2001 From: vegu-ai-tools <152010387+vegu-ai-tools@users.noreply.github.com> Date: Sun, 11 May 2025 22:28:57 +0300 Subject: [PATCH] missing files --- docs/user-guide/agents/editor/revisions.md | 17 ++++++ .../agents/editor/websocket_handler.py | 59 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 docs/user-guide/agents/editor/revisions.md create mode 100644 src/talemate/agents/editor/websocket_handler.py diff --git a/docs/user-guide/agents/editor/revisions.md b/docs/user-guide/agents/editor/revisions.md new file mode 100644 index 00000000..53e52bb7 --- /dev/null +++ b/docs/user-guide/agents/editor/revisions.md @@ -0,0 +1,17 @@ +Revisions were introduced in version `0.30.0` and allow the editor to detect and fix repetition and unwanted prose. + +Please see the [settings](/talemate/user-guide/agents/editor/settings/#revision) for more information on how to configure **:material-typewriter: Revisions**. + +Once automatic revisions are enabled, if the editor finds an issue in a message you will see the following status updates: + +![Editor revision status](/talemate/img/0.30.0/editor-revision-issue-identified.png) + +![Editor revision status](/talemate/img/0.30.0/editor-revision-rewriting.png) + +Once the revision is complete the editor agent will indicate that that it made some changes by showing the :material-message-text-outline: icon next to its name. + +![Editor revision status](/talemate/img/0.30.0/editor-has-messages.png) + +Click the :material-message-text-outline: icon to open the Agent Messages dialog to view the changes. + +![Editor revision messages](/talemate/img/0.30.0/editor-revision-history.png) \ No newline at end of file diff --git a/src/talemate/agents/editor/websocket_handler.py b/src/talemate/agents/editor/websocket_handler.py new file mode 100644 index 00000000..83716741 --- /dev/null +++ b/src/talemate/agents/editor/websocket_handler.py @@ -0,0 +1,59 @@ +import pydantic +import structlog +from typing import TYPE_CHECKING + +from talemate.instance import get_agent +from talemate.server.websocket_plugin import Plugin +from talemate.status import set_loading +from talemate.scene_message import CharacterMessage +from talemate.agents.editor.revision import RevisionContext + +if TYPE_CHECKING: + from talemate.tale_mate import Scene + +__all__ = [ + "EditorWebsocketHandler", +] + +log = structlog.get_logger("talemate.server.editor") + +class RevisionPayload(pydantic.BaseModel): + message_id: int + +class EditorWebsocketHandler(Plugin): + """ + Handles editor actions + """ + + router = "editor" + + @property + def editor(self): + return get_agent("editor") + + async def handle_request_revision(self, data: dict): + """ + Generate clickable actions for the user + """ + + editor = self.editor + scene:"Scene" = self.scene + + if not editor.revision_enabled: + raise Exception("Revision is not enabled") + + payload = RevisionPayload(**data) + message = scene.get_message(payload.message_id) + + character = None + + if isinstance(message, CharacterMessage): + character = scene.get_character(message.character_name) + + if not message: + raise Exception("Message not found") + + with RevisionContext(message.id): + revised = await editor.revision_revise(message.message, character=character) + + scene.edit_message(message.id, revised) \ No newline at end of file