import json from typing import Any from sqlalchemy.orm import Session from app.pomodoro.service import PomodoroService TOOL_DEFINITIONS: list[dict[str, Any]] = [ { "type": "function", "function": { "name": "get_pomodoro_status", "description": "ОБЯЗАТЕЛЬНО вызывай перед любым ответом о таймере. Статус, фаза и прогресс цикла.", "parameters": {"type": "object", "properties": {}, "required": []}, }, }, { "type": "function", "function": { "name": "start_pomodoro", "description": "Запустить фазу работы в цикле помидоро (25 мин по умолчанию).", "parameters": { "type": "object", "properties": { "duration_min": {"type": "integer", "description": "Минуты работы"}, "task_note": {"type": "string", "description": "Над чем работаем"}, }, "required": [], }, }, }, { "type": "function", "function": { "name": "start_short_break", "description": "Запустить короткий перерыв между работами.", "parameters": { "type": "object", "properties": { "duration_min": {"type": "integer", "description": "Минуты перерыва"}, }, "required": [], }, }, }, { "type": "function", "function": { "name": "start_long_break", "description": "Запустить длинный перерыв после завершения цикла работ.", "parameters": { "type": "object", "properties": { "duration_min": {"type": "integer", "description": "Минуты перерыва"}, }, "required": [], }, }, }, { "type": "function", "function": { "name": "stop_pomodoro", "description": "Остановить текущую фазу таймера.", "parameters": { "type": "object", "properties": { "result": {"type": "string", "description": "Отчёт о сделанном"}, "completed": { "type": "boolean", "description": "True если фаза полностью завершена", }, }, "required": [], }, }, }, { "type": "function", "function": { "name": "skip_pomodoro_phase", "description": "Досрочно завершить текущую фазу и перейти к следующей в цикле.", "parameters": {"type": "object", "properties": {}, "required": []}, }, }, { "type": "function", "function": { "name": "reset_pomodoro_cycle", "description": "Сбросить цикл помидоро: обнулить счётчик работ и остановить таймер.", "parameters": { "type": "object", "properties": { "clear_task": { "type": "boolean", "description": "Также очистить текущую задачу", }, }, "required": [], }, }, }, { "type": "function", "function": { "name": "get_pomodoro_history", "description": "ОБЯЗАТЕЛЬНО при вопросах о задачах, истории работы или что пользователь делал.", "parameters": { "type": "object", "properties": { "limit": {"type": "integer", "description": "Сколько сессий вернуть"}, }, "required": [], }, }, }, ] def execute_tool(db: Session, name: str, arguments: dict[str, Any]) -> str: service = PomodoroService(db) try: if name == "get_pomodoro_status": result = service.get_status() elif name == "start_pomodoro": result = service.start_work( duration_min=arguments.get("duration_min"), task_note=arguments.get("task_note", ""), ) elif name == "start_short_break": result = service.start_short_break( duration_min=arguments.get("duration_min"), ) elif name == "start_long_break": result = service.start_long_break( duration_min=arguments.get("duration_min"), ) elif name == "stop_pomodoro": result = service.stop( result=arguments.get("result", ""), completed=arguments.get("completed", False), ) elif name == "skip_pomodoro_phase": result = service.skip_phase() elif name == "reset_pomodoro_cycle": result = service.reset_cycle( clear_task=arguments.get("clear_task", False), ) elif name == "get_pomodoro_history": result = service.history(limit=arguments.get("limit", 10)) else: return json.dumps({"error": f"Unknown tool: {name}"}, ensure_ascii=False) return json.dumps(result, ensure_ascii=False) except ValueError as exc: return json.dumps({"error": str(exc)}, ensure_ascii=False)