import uuid from sqlalchemy.ext.asyncio import AsyncSession from app.models.game import Game TOOL_SCHEMA = { "name": "end_game", "description": ( "Call when the story reaches a real conclusion — the party wins, loses, or a one-shot's " "plot is resolved. Marks the game as ended so players see a clear ending. Do not call this " "just because a scene ends; only for a genuine story conclusion." ), "parameters": { "type": "object", "properties": { "reason": { "type": "string", "description": ( "A short narrative summary of how/why the story ended (victory, defeat, or " "resolution), shown to the players, e.g. 'Das Dorf ist gerettet, die Kerze brennt wieder.'" ), }, }, "required": ["reason"], }, } async def end(session: AsyncSession, game_id: uuid.UUID, tool_input: dict) -> dict: game = await session.get(Game, game_id) if game is None: raise ValueError(f"Game {game_id} not found") if game.status != "ended": game.status = "ended" game.ended_reason = tool_input["reason"] await session.commit() return {"status": "ended", "reason": game.ended_reason}