Files
Home_assistant/backend/app/tools/pomodoro.py
T
2026-06-16 09:19:32 +03:00

158 lines
5.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from typing import Any
from app.pomodoro.service import PomodoroService
from app.tools._dispatch import NOT_HANDLED, ToolContext
TOOL_NAMES = frozenset({
"get_pomodoro_status",
"start_pomodoro",
"start_short_break",
"start_long_break",
"stop_pomodoro",
"skip_pomodoro_phase",
"reset_pomodoro_cycle",
"get_pomodoro_history",
})
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": "История помидоро-сессий (таймер), не Taiga-задачи.",
"parameters": {
"type": "object",
"properties": {
"limit": {"type": "integer", "description": "Сколько сессий вернуть"},
},
"required": [],
},
},
},
]
async def execute(name: str, arguments: dict[str, Any], ctx: ToolContext) -> Any:
if name not in TOOL_NAMES:
return NOT_HANDLED
pomodoro = PomodoroService(ctx.db, ctx.user_id)
if name == "get_pomodoro_status":
return pomodoro.get_status()
if name == "start_pomodoro":
return pomodoro.start_work(
duration_min=arguments.get("duration_min"),
task_note=arguments.get("task_note", ""),
)
if name == "start_short_break":
return pomodoro.start_short_break(duration_min=arguments.get("duration_min"))
if name == "start_long_break":
return pomodoro.start_long_break(duration_min=arguments.get("duration_min"))
if name == "stop_pomodoro":
return pomodoro.stop(
result=arguments.get("result", ""),
completed=arguments.get("completed", False),
)
if name == "skip_pomodoro_phase":
return pomodoro.skip_phase()
if name == "reset_pomodoro_cycle":
return pomodoro.reset_cycle(clear_task=arguments.get("clear_task", False))
if name == "get_pomodoro_history":
return pomodoro.history(limit=arguments.get("limit", 10))
return NOT_HANDLED