agentic_huge_data_base / wiki
页面 Open WebUI · 20 自动化与日历·DeepWiki 中文全文译文

20 · 自动化与日历(Automations and Calendar)

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

项目Open WebUI 章节20 状态全文译文 模块界面与交互、接口与服务契约、系统架构、频道、笔记与协作
源码线索
  • backend/open_webui/migrations/versions/56359461a091_add_calendar_tables.py
  • backend/open_webui/migrations/versions/d4e5f6a7b8c9_add_automation_tables.py
  • backend/open_webui/models/automations.py
  • backend/open_webui/models/calendar.py
  • backend/open_webui/routers/automations.py
  • backend/open_webui/routers/calendar.py
  • backend/open_webui/utils/automations.py
  • backend/open_webui/utils/calendar.py
  • src/lib/apis/automations/index.ts
  • src/lib/apis/calendar/index.ts
模块标签
  • 界面与交互
  • 接口与服务契约
  • 系统架构
  • 频道、笔记与协作
  • 认证、权限与安全

中文译文

自动化与日历(中文译文)

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

---

自动化与日历

相关源文件

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

  • backend/open_webui/migrations/versions/56359461a091_add_calendar_tables.py
  • backend/open_webui/migrations/versions/d4e5f6a7b8c9_add_automation_tables.py
  • backend/open_webui/models/automations.py
  • backend/open_webui/models/calendar.py
  • backend/open_webui/routers/automations.py
  • backend/open_webui/routers/calendar.py
  • backend/open_webui/utils/automations.py
  • backend/open_webui/utils/calendar.py
  • src/lib/apis/automations/index.ts
  • src/lib/apis/calendar/index.ts
  • src/lib/components/AutomationModal.svelte
  • src/lib/components/automations/AutomationEditor.svelte
  • src/lib/components/automations/AutomationMenu.svelte
  • 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/lib/components/layout/Sidebar/UserMenu.svelte
  • src/lib/components/workspace/Models/TerminalSelector.svelte
  • src/routes/(app)/automations/+page.svelte/automations/+page.svelte)
  • [src/routes/(app)/automations/[id]/+page.svelte](src/routes/(app)/automations/[id]/+page.svelte)
  • src/routes/(app)/calendar/+page.svelte/calendar/+page.svelte)

自动化与日历系统于 v0.9.0 版本引入,为在 Open WebUI 中调度周期性 AI 任务和管理基于时间的事件提供了统一框架。它由一个执行自动化聊天补全的后台调度引擎和一个功能完备的日历工作区组成,后者用于事件管理和提醒通知。

系统架构

该系统依赖于一个统一的 scheduler_worker_loop,该循环作为 FastAPI 后端的后台进程运行。此工作线程负责执行到期的自动化任务以及分发日历提醒。

高层数据流

下图展示了前端如何与后端模型交互以调度和执行任务。

调度器与实体交互

graph TD
    subgraph "前端空间 (SvelteKit)"
        A["AutomationEditor.svelte"] -- "CRUD API" --> B["/automations"]
        C["CalendarView.svelte"] -- "事件 API" --> D["/calendar"]
    end

    subgraph "后端逻辑 (Python)"
        B --> E["open_webui.routers.automations"]
        D --> F["open_webui.routers.calendar"]

        G["scheduler_worker_loop"] -- "轮询" --> H[("数据库: automation")]
        G -- "轮询" --> I[("数据库: calendar_event")]

        G -- "触发" --> J["execute_automation()"]
        J -- "聊天请求" --> K["chat_completion()"]
        G -- "提醒" --> L["Socket.IO / Webhooks"]
    end

    subgraph "数据库实体"
        H --- M["AutomationTable"]
        I --- N["CalendarTable"]
    end

来源:backend/open_webui/utils/automations.py:162-199backend/open_webui/routers/automations.py:31-149backend/open_webui/routers/calendar.py:31-108

计划自动化

自动化引擎允许用户使用标准的 iCalendar RRULE 语法定义周期性 AI 任务。这些自动化充当"计划聊天",系统会按定义的时间间隔使用指定模型自动生成提示响应。

关键组件
  • 自动化记录:将提示词、模型 ID 和重复规则存储在 automation 表中 backend/open_webui/models/automations.py:20-35
  • 执行引擎:使用 _build_request 构建的模拟 ASGI Request 来调用内部的 chat_completion 管道,确保自动化遵循与手动聊天相同的过滤器和工具 backend/open_webui/utils/automations.py:206-250
  • 运行历史:每次执行都会记录在 automation_run 表中,跟踪状态(成功/错误)并链接到生成的 chat_id backend/open_webui/models/automations.py:38-51
  • 前端管理AutomationEditor.svelte 组件允许用户配置这些任务、查看运行历史并通过 runNowHandler 手动触发执行 src/lib/components/automations/AutomationEditor.svelte:122-133
管理员配置

管理员可以通过环境变量控制资源使用:

  • AUTOMATION_MAX_COUNT:限制每个用户的自动化数量 backend/open_webui/routers/automations.py:76-83
  • AUTOMATION_MIN_INTERVAL:强制执行周期性运行之间的最小时间间隔(秒)backend/open_webui/routers/automations.py:86-95
  • SCHEDULER_POLL_INTERVAL:配置后台工作线程检查到期任务的频率 backend/open_webui/utils/automations.py:39-40

有关实现细节和 RRULE 示例,请参阅 计划自动化

来源:backend/open_webui/utils/automations.py:1-14backend/open_webui/models/automations.py:71-85backend/open_webui/routers/automations.py:69-97

日历工作区

日历工作区提供了管理个人和共享事件的视觉界面。它通过将计划任务作为"虚拟事件"与标准日历条目一起显示,与自动化系统深度集成。

功能特性
  • 事件管理:支持创建带有标题、描述和地点的一次性或重复事件 backend/open_webui/models/calendar.py:54-78
  • 虚拟日历__scheduled_tasks__ 系统日历通过查询 Automations 模型,自动将活跃的自动化 RRULE 展开到日历视图中 backend/open_webui/routers/calendar.py:33-106
  • 通知:调度器使用 CALENDAR_ALERT_LOOKAHEAD_MINUTES 监控即将发生的事件,并通过 Socket.IO 触发应用内 toast 提醒 backend/open_webui/utils/automations.py:8-14
  • RSVP 系统:用户可以邀请他人参加事件,并通过 CalendarEventAttendee 模型跟踪响应状态(待定、已接受、已拒绝)backend/open_webui/models/calendar.py:81-96

日历实体关系

erDiagram
    "open_webui.models.users.User" ||--o{ "open_webui.models.calendar.Calendar" : "拥有"
    "open_webui.models.calendar.Calendar" ||--o{ "open_webui.models.calendar.CalendarEvent" : "包含"
    "open_webui.models.calendar.CalendarEvent" ||--o{ "open_webui.models.calendar.CalendarEventAttendee" : "有"
    "open_webui.models.users.User" ||--o{ "open_webui.models.calendar.CalendarEventAttendee" : "被邀请为"
    "open_webui.models.calendar.CalendarEvent" }|--o| "open_webui.models.automations.Automation" : "可选通过 meta 链接"

来源:backend/open_webui/models/calendar.py:37-97backend/open_webui/routers/calendar.py:175-199

有关 UI 视图(月、周、日)和通知设置的详细信息,请参阅 日历工作区

来源:src/routes/(app)/calendar/+page.svelte:26-52src/lib/components/calendar/CalendarSidebar.svelte:37-56

安全与权限

对这些功能的访问由全局配置和每个用户的权限控制:

  • 功能开关:必须在应用配置中启用 ENABLE_AUTOMATIONSENABLE_CALENDAR backend/open_webui/routers/automations.py:42-46backend/open_webui/routers/calendar.py:38-42
  • 基于角色的访问控制(RBAC):可以通过 has_permission 检查将特定权限(features.automationsfeatures.calendar)分配给非管理员用户 backend/open_webui/routers/automations.py:47-53backend/open_webui/routers/calendar.py:43-49
  • 所有权与访问:用户只能查看或修改自己拥有的自动化和日历,除非通过共享日历的 AccessGrants 获得访问权限 backend/open_webui/routers/automations.py:56-67backend/open_webui/routers/calendar.py:61-78

来源:backend/open_webui/utils/auth.py:24-25backend/open_webui/utils/access_control.py:25-26