agentic_huge_data_base / wiki
页面 Open WebUI · 20.2 日历工作区·DeepWiki 中文全文译文

20.2 · 日历工作区(Calendar Workspace)

多模型对话工作台与知识应用入口 · 本章是 Open WebUI DeepWiki 中文译文的独立章节页,保留原始链接、源码锚点、模块标签和章节层级。

项目Open WebUI 章节20.2 状态全文译文 模块界面与交互、系统架构、接口与服务契约、频道、笔记与协作
源码线索
  • backend/open_webui/migrations/versions/56359461a091_add_calendar_tables.py
  • backend/open_webui/models/calendar.py
  • backend/open_webui/routers/calendar.py
  • backend/open_webui/utils/calendar.py
  • src/lib/apis/calendar/index.ts
  • src/lib/components/calendar/CalendarEventChip.svelte
  • src/lib/components/calendar/CalendarEventModal.svelte
  • src/lib/components/calendar/CalendarSidebar.svelte
  • src/lib/components/calendar/CalendarView.svelte
  • CalendarEventModal.svelte
模块标签
  • 界面与交互
  • 系统架构
  • 接口与服务契约
  • 频道、笔记与协作
  • 工具、记忆与模型调用

中文译文

Calendar 工作区(中文译文)

原始 DeepWiki 页面:https://deepwiki.com/open-webui/open-webui/20.2-calendar-workspace
翻译时间:2026-06-09T16:12:47.348Z
翻译模型:deepseek-chat
原文字符数:9363
项目:Open WebUI (open-webui)

---

日历工作区

相关源文件

以下文件被用作生成此 wiki 页面的上下文:

  • backend/open_webui/migrations/versions/56359461a091_add_calendar_tables.py
  • backend/open_webui/models/calendar.py
  • backend/open_webui/routers/calendar.py
  • backend/open_webui/utils/calendar.py
  • src/lib/apis/calendar/index.ts
  • src/lib/components/calendar/CalendarEventChip.svelte
  • src/lib/components/calendar/CalendarEventModal.svelte
  • src/lib/components/calendar/CalendarSidebar.svelte
  • src/lib/components/calendar/CalendarView.svelte
  • src/routes/(app)/calendar/+page.svelte/calendar/+page.svelte)

日历工作区是 v0.9.0 中引入的一项功能,提供了一个集中式界面来管理基于时间的事件、重复日程和 AI 驱动的自动化。它直接与 Open WebUI 自动化引擎集成,允许用户将计划中的 AI 任务与手动日历条目一起可视化。

系统架构与数据流

日历系统遵循标准的三层架构:基于 SvelteKit 的前端用于可视化,FastAPI 后端用于业务逻辑和权限执行,以及 SQLAlchemy 管理的关系数据库用于持久化。

数据流:事件检索

下图说明了获取事件的过程,突出了物理数据库记录与虚拟自动化实例的合并。

事件解析管道

sequenceDiagram
    participant UI as "CalendarView.svelte"
    participant API as "calendar.py (Router)"
    participant DB as "CalendarEvent (SQLAlchemy)"
    participant AUTO as "Automations (Model)"
    participant RR as "expand_recurring_event (Utils)"

    UI->>API: GET /calendars/events?start={ISO}&end={ISO}
    API->>DB: get_events_by_range(user_id, start_ns, end_ns)
    DB-->>API: List[CalendarEvent]

    API->>RR: expand_recurring_event(event_dict, start_ns, end_ns)
    RR-->>API: List[CalendarEventUserResponse]

    alt 自动化已启用
        API->>AUTO: get_active_by_user(user_id)
        AUTO-->>API: List[Automation]
        API->>RR: expand_recurring_event(auto_dict, ...)
        RR-->>API: List[VirtualAutomationEvents]
    end

    API-->>UI: 合并后的 JSON (items, total)

来源:backend/open_webui/routers/calendar.py:123-210src/routes/(app)/calendar/+page.svelte:92-99backend/open_webui/utils/calendar.py:17-74

数据模型与模式

日历系统使用三个主要表来管理日历、事件和参与情况。

数据库实体
描述关键字段
calendar事件的容器;支持通过访问授权进行共享。iduser_idnamecoloris_default
calendar_event单个或重复的时间段。idcalendar_idstart_atend_atrrulemeta
calendar_event_attendee跟踪用户对特定事件的 RSVP 状态。event_iduser_idstatus (pending/accepted/etc)

来源:backend/open_webui/models/calendar.py:37-97backend/open_webui/migrations/versions/56359461a091_add_calendar_tables.py:23-73

代码实体映射

此图将逻辑概念映射到 Python 和 TypeScript 代码库中的具体实现。

后端模型架构

classDiagram
    class "Calendar (SQLAlchemy)" {
        +String id
        +String user_id
        +JSON data
        +JSON meta
    }
    class "CalendarEvent (SQLAlchemy)" {
        +String title
        +BigInteger start_at
        +String rrule
        +Boolean all_day
    }
    class "CalendarEventAttendee (SQLAlchemy)" {
        +String status
    }
    class "CalendarTable (Internal)" {
        +insert_new_calendar()
        +get_calendars_by_user()
    }
    class "CalendarEventsTable (Internal)" {
        +get_events_by_range()
    }

    "Calendar (SQLAlchemy)" "1" --* "many" "CalendarEvent (SQLAlchemy)" : 包含
    "CalendarEvent (SQLAlchemy)" "1" --* "many" "CalendarEventAttendee (SQLAlchemy)" : 拥有
    "CalendarTable (Internal)" ..> "Calendar (SQLAlchemy)" : 管理
    "CalendarEventsTable (Internal)" ..> "CalendarEvent (SQLAlchemy)" : 管理

来源:backend/open_webui/models/calendar.py:37-97backend/open_webui/models/calendar.py:235-255

核心功能

1. 事件管理

用户可以通过 CalendarEventModal.svelte 组件创建、更新和删除事件。事件支持:

  • 时间选择:以纳秒精度存储为 BigInteger(ns),使用转换因子 NS = 1_000_000 将毫秒转换为纳秒 src/lib/components/calendar/CalendarEventModal.svelte:39-51
  • 重复日程:使用 iCalendar RRULE 字符串定义模式,由后端的 dateutil.rrule 展开 backend/open_webui/utils/calendar.py:29-41
  • 全天事件:布尔标志,调整 UI 渲染并将时间默认为 00:0023:59 src/lib/components/calendar/CalendarEventModal.svelte:99-100
2. 自动化集成

日历包含一个虚拟系统日历,标识为 SCHEDULED_TASKS_CALENDAR_ID__scheduled_tasks__backend/open_webui/routers/calendar.py:33

  • 虚拟事件:此日历中的事件不存储在 calendar_event 表中。相反,它们通过 expand_recurring_event 工具从活动的 Automations 动态生成 backend/open_webui/routers/calendar.py:182-200
  • 导航:在 UI 中点击自动化事件会通过 goto 将用户重定向到关联的聊天或自动化配置页面 src/routes/(app)/calendar/+page.svelte:138-144
3. 提醒与通知

事件元数据包含一个 alert_minutes 字段 src/lib/components/calendar/CalendarEventModal.svelte:35。系统支持:

  • 应用内 Toast:由前端在事件临近或成功执行 CRUD 操作时触发 src/routes/(app)/calendar/+page.svelte:119
  • RSVP 跟踪:用户可以使用 RSVPForm 中定义的状态响应邀请:accepteddeclinedtentativepending backend/open_webui/models/calendar.py:213

权限与访问控制

访问权限由全局配置和每个用户的权限共同控制:

  • 功能开关:由应用程序状态中的 ENABLE_CALENDAR 控制 backend/open_webui/routers/calendar.py:38
  • 用户权限:非管理员用户必须通过 has_permission 检查 features.calendar 权限 backend/open_webui/routers/calendar.py:43-45
  • 资源共享_check_calendar_access 函数使用 AccessGrants.has_access 验证共享日历的所有权或是否存在 AccessGrant backend/open_webui/routers/calendar.py:61-78

前端组件

UI 使用模块化组件结构构建:

组件文件路径职责
CalendarViewCalendarView.svelte月、周和日视图的主网格渲染 src/lib/components/calendar/CalendarView.svelte:144-204
CalendarSidebarCalendarSidebar.svelte迷你日历导航和日历可见性切换 src/lib/components/calendar/CalendarSidebar.svelte:105-233
CalendarEventModalCalendarEventModal.svelte用于创建/编辑事件详情和提醒的表单 src/lib/components/calendar/CalendarEventModal.svelte:159-228
CalendarEventChipCalendarEventChip.svelte在日历网格中渲染的紧凑事件摘要 src/lib/components/calendar/CalendarEventChip.svelte:12-32

前端组件层次结构

graph TD
    Page["+page.svelte (路由)"] --> Sidebar["CalendarSidebar.svelte"]
    Page --> View["CalendarView.svelte"]
    Page --> Modal["CalendarEventModal.svelte"]
    View --> Chip["CalendarEventChip.svelte"]
    Sidebar --> MiniCal["迷你日历网格"]
    Sidebar --> List["日历列表"]

来源:src/routes/(app)/calendar/+page.svelte:13-15src/lib/components/calendar/CalendarView.svelte:4src/lib/components/calendar/CalendarSidebar.svelte:4

API 端点

日历功能通过 /calendars 路由前缀暴露:

  • GET /:列出所有可用的日历 backend/open_webui/routers/calendar.py:86
  • POST /create:创建新日历 backend/open_webui/routers/calendar.py:111
  • GET /events:获取特定日期范围的事件 backend/open_webui/routers/calendar.py:123
  • POST /events/create:向日历添加新事件 backend/open_webui/routers/calendar.py:246
  • POST /events/{event_id}/rsvp:更新用户参与状态 backend/open_webui/routers/calendar.py:348

来源:backend/open_webui/routers/calendar.py:31-360src/lib/apis/calendar/index.ts:74-263