feat: support updating notes and reminders
All checks were successful
quality / test (3.10) (push) Successful in 10m42s
quality / test (3.12) (push) Successful in 9m25s

This commit is contained in:
kandrusyak
2026-07-27 19:53:08 +03:00
parent d1c1ef68d3
commit 7dc5a1f7f2
4 changed files with 418 additions and 3 deletions

View File

@@ -127,6 +127,20 @@ def list_notes(arguments: dict[str, Any], context: ToolContext) -> ToolResult:
return {"ok": True, "items": rows}
def update_note(arguments: dict[str, Any], context: ToolContext) -> ToolResult:
note_id = parse_positive_int(str(arguments.get("id", "")))
if note_id is None:
return {"ok": False, "error": "valid id is required"}
text = coerce_required_text(arguments, "text")
if not text:
return {"ok": False, "error": "text is required"}
return {
"ok": context.storage.update_note(context.user_id, note_id, text),
"id": note_id,
"text": text,
}
def delete_note(arguments: dict[str, Any], context: ToolContext) -> ToolResult:
note_id = parse_positive_int(str(arguments.get("id", "")))
if note_id is None:
@@ -181,6 +195,47 @@ def list_reminders(
return {"ok": True, "items": rows}
def update_reminder(
arguments: dict[str, Any],
context: ToolContext,
) -> ToolResult:
reminder_id = parse_positive_int(str(arguments.get("id", "")))
if reminder_id is None:
return {"ok": False, "error": "valid id is required"}
when = coerce_required_text(arguments, "when")
text = coerce_required_text(arguments, "text")
if not when and not text:
return {"ok": False, "error": "when or text is required"}
remind_at_utc = None
if when:
parsed = parse_agent_reminder(when, text or "напоминание", context.tz)
if not parsed:
return {"ok": False, "error": "could not parse reminder time"}
if parsed.remind_at_utc <= utc_now():
return {
"ok": False,
"error": "reminder time must be in the future",
}
remind_at_utc = parsed.remind_at_utc
result: ToolResult = {
"ok": context.storage.update_reminder(
context.user_id,
reminder_id,
text=text or None,
remind_at_utc=remind_at_utc,
),
"id": reminder_id,
}
if text:
result["text"] = text
if remind_at_utc is not None:
result["remind_at"] = format_local_dt(remind_at_utc, context.tz)
return result
def cancel_reminder(
arguments: dict[str, Any],
context: ToolContext,
@@ -330,6 +385,16 @@ AGENT_TOOLS = (
list_notes,
allowed_arguments=frozenset({"limit"}),
),
AgentTool(
"update_note",
'{"id":1,"text":"..."}',
(
"заменить текст существующей заметки. При дополнении сохрани прежний "
"текст и добавь к нему новые данные."
),
update_note,
allowed_arguments=frozenset({"id", "text"}),
),
AgentTool(
"delete_note",
'{"id":1}',
@@ -356,6 +421,16 @@ AGENT_TOOLS = (
list_reminders,
allowed_arguments=frozenset({"limit"}),
),
AgentTool(
"update_reminder",
'{"id":1} (необязательно: "when" и/или "text"; хотя бы одно)',
(
"изменить время или полный текст активного напоминания без отмены. "
"when поддерживает те же форматы, что create_reminder."
),
update_reminder,
allowed_arguments=frozenset({"id", "when", "text"}),
),
AgentTool(
"cancel_reminder",
'{"id":1}',