自动化与日历(中文译文)
原始 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.pybackend/open_webui/migrations/versions/d4e5f6a7b8c9_add_automation_tables.pybackend/open_webui/models/automations.pybackend/open_webui/models/calendar.pybackend/open_webui/routers/automations.pybackend/open_webui/routers/calendar.pybackend/open_webui/utils/automations.pybackend/open_webui/utils/calendar.pysrc/lib/apis/automations/index.tssrc/lib/apis/calendar/index.tssrc/lib/components/AutomationModal.sveltesrc/lib/components/automations/AutomationEditor.sveltesrc/lib/components/automations/AutomationMenu.sveltesrc/lib/components/calendar/CalendarEventChip.sveltesrc/lib/components/calendar/CalendarEventModal.sveltesrc/lib/components/calendar/CalendarSidebar.sveltesrc/lib/components/calendar/CalendarView.sveltesrc/lib/components/layout/Sidebar/UserMenu.sveltesrc/lib/components/workspace/Models/TerminalSelector.sveltesrc/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-199,backend/open_webui/routers/automations.py:31-149,backend/open_webui/routers/calendar.py:31-108
计划自动化
自动化引擎允许用户使用标准的 iCalendar RRULE 语法定义周期性 AI 任务。这些自动化充当"计划聊天",系统会按定义的时间间隔使用指定模型自动生成提示响应。
关键组件
- 自动化记录:将提示词、模型 ID 和重复规则存储在
automation表中backend/open_webui/models/automations.py:20-35。 - 执行引擎:使用
_build_request构建的模拟 ASGIRequest来调用内部的chat_completion管道,确保自动化遵循与手动聊天相同的过滤器和工具backend/open_webui/utils/automations.py:206-250。 - 运行历史:每次执行都会记录在
automation_run表中,跟踪状态(成功/错误)并链接到生成的chat_idbackend/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-14,backend/open_webui/models/automations.py:71-85,backend/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-97,backend/open_webui/routers/calendar.py:175-199
有关 UI 视图(月、周、日)和通知设置的详细信息,请参阅 日历工作区。
来源:src/routes/(app)/calendar/+page.svelte:26-52,src/lib/components/calendar/CalendarSidebar.svelte:37-56
安全与权限
对这些功能的访问由全局配置和每个用户的权限控制:
- 功能开关:必须在应用配置中启用
ENABLE_AUTOMATIONS和ENABLE_CALENDARbackend/open_webui/routers/automations.py:42-46,backend/open_webui/routers/calendar.py:38-42。 - 基于角色的访问控制(RBAC):可以通过
has_permission检查将特定权限(features.automations和features.calendar)分配给非管理员用户backend/open_webui/routers/automations.py:47-53,backend/open_webui/routers/calendar.py:43-49。 - 所有权与访问:用户只能查看或修改自己拥有的自动化和日历,除非通过共享日历的
AccessGrants获得访问权限backend/open_webui/routers/automations.py:56-67,backend/open_webui/routers/calendar.py:61-78。
来源:backend/open_webui/utils/auth.py:24-25,backend/open_webui/utils/access_control.py:25-26