Files
chat/chat/services/reset.py
T
2026-04-26 14:07:56 -04:00

24 lines
846 B
Python

from __future__ import annotations
from sqlite3 import Connection
from chat.eventlog.log import append_and_apply
from chat.state.entities import get_bot
def reset_bot(conn: Connection, bot_id: str, *, confirm_name: str) -> None:
"""Reset a bot's runtime state via a ``bot_reset`` event.
Validates that ``confirm_name`` matches the bot's stored ``name``
exactly (case-sensitive, no trim). Raises:
- ``ValueError("bot {bot_id} not found")`` when the bot is missing.
- ``ValueError("confirm_name does not match bot name")`` on mismatch.
"""
bot = get_bot(conn, bot_id)
if bot is None:
raise ValueError(f"bot {bot_id} not found")
if confirm_name != bot["name"]:
raise ValueError("confirm_name does not match bot name")
append_and_apply(conn, kind="bot_reset", payload={"bot_id": bot_id})