From 7102a63c82c7d916acaaaaff2eee653de3c1bd69 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 24 Apr 2026 18:06:19 +0900 Subject: [PATCH] refac --- backend/open_webui/tools/builtin.py | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/backend/open_webui/tools/builtin.py b/backend/open_webui/tools/builtin.py index 33d6bfa91e..18b888bbd7 100644 --- a/backend/open_webui/tools/builtin.py +++ b/backend/open_webui/tools/builtin.py @@ -2895,6 +2895,9 @@ def _ns_to_dt(ns: int, tz) -> str: def _event_to_dict(event, tz) -> dict: """Convert a calendar event model to a human-friendly dict with local timestamps.""" + alert_minutes = None + if event.meta and 'alert_minutes' in event.meta: + alert_minutes = event.meta['alert_minutes'] return { 'id': event.id, 'calendar_id': event.calendar_id, @@ -2904,6 +2907,7 @@ def _event_to_dict(event, tz) -> dict: 'end': _ns_to_dt(event.end_at, tz) if event.end_at else None, 'all_day': event.all_day, 'location': event.location or '', + 'reminder_minutes': alert_minutes if alert_minutes is not None else 10, 'color': event.color, 'is_cancelled': event.is_cancelled, } @@ -3010,6 +3014,7 @@ async def create_calendar_event( calendar_id: Optional[str] = None, all_day: bool = False, location: Optional[str] = None, + reminder_minutes: Optional[int] = None, __request__: Request = None, __user__: dict = None, ) -> str: @@ -3024,6 +3029,7 @@ async def create_calendar_event( :param calendar_id: Target calendar ID (optional, uses default calendar if omitted) :param all_day: Whether this is an all-day event (default: false) :param location: Event location (optional) + :param reminder_minutes: Minutes before the event to send a reminder notification (optional, default: 10). Use 0 for "at time of event", -1 for no reminder. Accepts any positive integer for custom timing (e.g. 120 for 2 hours before). :return: JSON with the created event details including id """ if __request__ is None: @@ -3086,6 +3092,18 @@ async def create_calendar_event( # Default to 1 hour duration end_ns = start_ns + 3_600_000_000_000 + # Build meta with reminder setting + meta = {} + if reminder_minutes is not None: + if isinstance(reminder_minutes, str): + try: + reminder_minutes = int(reminder_minutes) + except ValueError: + reminder_minutes = 10 + meta['alert_minutes'] = reminder_minutes + else: + meta['alert_minutes'] = 10 + form = CalendarEventForm( calendar_id=calendar_id, title=title, @@ -3094,6 +3112,7 @@ async def create_calendar_event( end_at=end_ns, all_day=all_day, location=location, + meta=meta, ) event = await CalendarEvents.insert_new_event(user_id, form) @@ -3121,6 +3140,7 @@ async def update_calendar_event( all_day: Optional[bool] = None, location: Optional[str] = None, is_cancelled: Optional[bool] = None, + reminder_minutes: Optional[int] = None, __request__: Request = None, __user__: dict = None, ) -> str: @@ -3136,6 +3156,7 @@ async def update_calendar_event( :param all_day: Whether this is an all-day event (optional) :param location: New event location (optional) :param is_cancelled: Set to true to cancel the event (optional) + :param reminder_minutes: Minutes before the event to send a reminder notification (optional). Use 0 for "at time of event", -1 for no reminder. Accepts any positive integer for custom timing (e.g. 120 for 2 hours before). :return: JSON with the updated event details """ if __request__ is None: @@ -3190,6 +3211,17 @@ async def update_calendar_event( except (ValueError, TypeError) as e: return json.dumps({'error': f'Invalid end datetime: {e}'}) + # Build meta update with reminder setting if provided + meta = None + if reminder_minutes is not None: + if isinstance(reminder_minutes, str): + try: + reminder_minutes = int(reminder_minutes) + except ValueError: + reminder_minutes = None + if reminder_minutes is not None: + meta = {'alert_minutes': reminder_minutes} + form = CalendarEventUpdateForm( title=title, description=description, @@ -3198,6 +3230,7 @@ async def update_calendar_event( all_day=all_day, location=location, is_cancelled=is_cancelled, + meta=meta, ) updated = await CalendarEvents.update_event_by_id(event_id, form)