Skip to content

feat(webui): 新增定时任务管理界面#71

Merged
69gg merged 4 commits into
developfrom
feature/scheduled-webui-view
Jun 7, 2026
Merged

feat(webui): 新增定时任务管理界面#71
69gg merged 4 commits into
developfrom
feature/scheduled-webui-view

Conversation

@69gg

@69gg 69gg commented Jun 7, 2026

Copy link
Copy Markdown
Owner

背景

这个 PR 为 WebUI 补齐定时任务管理能力,让运行中的 Undefined 可以直接在管理端查看、创建、编辑和删除 scheduler 任务,不再依赖手动调用工具或直接改运行态数据。同时补上 Runtime API 与 WebUI 代理层,保证 WebUI 登录态与 Runtime API Key 的边界仍然清晰。

主要变更

WebUI 定时任务管理

  • 新增「定时任务」标签页,支持任务列表、搜索、刷新、新建、编辑、删除。
  • 支持三类任务模式:
    • 单工具任务
    • 多工具任务
    • 自我督办任务(scheduler.call_self
  • 前端会根据任务结构识别模式,并在编辑时回填工具参数、自我督办 prompt、最大执行次数等字段。
  • 补充桌面端与移动端样式,新增定时任务相关 i18n 文案。

Runtime API 与 WebUI 代理

  • 新增 Runtime API:
    • GET /api/v1/schedules
    • POST /api/v1/schedules
    • GET /api/v1/schedules/{task_id}
    • PATCH /api/v1/schedules/{task_id}
    • DELETE /api/v1/schedules/{task_id}
  • 新增 WebUI 管理代理:
    • /api/v1/management/runtime/schedules...
    • 兼容 /api/runtime/schedules...
  • WebUI 代理先校验管理端登录态,再向 Runtime API 注入 X-Undefined-API-Key,避免把 Runtime API Key 暴露给浏览器。
  • OpenAPI 生成逻辑纳入 schedules 路由。

调度器行为修复

  • Scheduler.update_task() 支持更新和清空 target_idtarget_typemax_executions
  • 编辑任务后同步刷新 APScheduler job args,避免持久化数据更新了但后续执行仍使用旧参数。
  • 兼容旧任务 ID:新建任务仍限制安全 ASCII ID,但详情、编辑、删除已有任务时允许历史中文 ID,避免旧任务无法保存。
  • 修复单个 scheduler.call_self 被识别成多工具任务的问题,API 与前端都会将其识别为自我督办并回填 self_instruction

提示词与记忆查阅

  • 加强 undefined.xmlundefined_nagaagent.xml 中的记忆查阅规则。
  • 明确遇到「之前 / 上次 / 继续 / 按我的习惯 / 我们约定过」等依赖历史事实的输入时,应先查看已注入的记忆,必要时主动调用 cognitive.*
  • 补充 memory.* 置顶备忘的核对/修改/删除流程,要求先 memory.list 找到 UUID。

文档

  • 更新 docs/openapi.md:补充 schedules API、请求/响应结构和示例。
  • 更新 docs/management-api.md:补充 WebUI Runtime schedules 代理说明。
  • 更新 docs/usage.md:补充 scheduler 工具说明。
  • 更新 docs/webui-guide.md:补充定时任务界面说明。
  • 更新 docs/cognitive-memory.md:补充主动查阅记忆的使用建议。

测试

  • 新增 tests/test_runtime_api_schedules.py 覆盖 Runtime schedules API。
  • 扩展 tests/test_webui_management_api.py 覆盖 WebUI 代理鉴权、URL 编码和路由注册。
  • 扩展 tests/test_runtime_api_probes.py 覆盖 schedules 能力探针。
  • 扩展 tests/test_scheduler_self_instruction.py 覆盖自我督办序列化与执行参数。
  • 扩展 tests/test_system_prompt_constraints.py 锁定记忆查阅提示词规则。

兼容性与安全边界

  • 新建任务 ID 仍保持严格校验,降低新数据引入异常字符的风险。
  • 对已有旧任务 ID 做兼容解析,避免历史任务因中文或旧格式 ID 无法编辑/删除。
  • WebUI 不直接暴露 Runtime API Key,所有 Runtime 调用仍通过后端管理代理完成。
  • 自我督办任务只在结构明确为单个 scheduler.call_self 时识别为 self_instruction,避免误判普通多工具任务。

验证

本分支开发过程中跑过以下验证:

  • uv run pytest tests/
  • uv run pytest tests/test_runtime_api_schedules.py tests/test_webui_management_api.py tests/test_runtime_api_probes.py tests/test_scheduler_self_instruction.py tests/test_scheduled_task_unit.py
  • uv run pytest tests/test_runtime_api_schedules.py tests/test_webui_management_api.py tests/test_scheduler_self_instruction.py tests/test_scheduled_task_unit.py
  • uv run pytest tests/test_system_prompt_constraints.py
  • uv run ruff check .
  • uv run ruff format --check .
  • uv run mypy .
  • npm run check
  • uv build --wheel

备注

  • 这个分支已基于最新 origin/developc850edbb)变基。
  • 当前 PR 相对 develop 包含 3 个提交:
    • 342efe81 feat(webui): add scheduled tasks management
    • 2c269a5b fix(webui): handle legacy schedule task editing
    • b2409e21 fix(prompts): encourage active memory lookup

Summary by CodeRabbit

  • New Features

    • Added a full "Schedules" feature: WebUI tab, editor, list/search workspace, styling, responsiveness, i18n, and runtime-backed create/edit/delete flows plus new Runtime schedule APIs.
  • Documentation

    • Updated guides and API docs to describe schedule management, proxy behavior, and WebUI integration.
  • Other

    • Strengthened system prompts to encourage proactive memory lookup.
    • Added tests covering scheduling APIs, probes, scheduler behavior, and prompt constraints.

69gg and others added 3 commits June 6, 2026 22:28
Co-authored-by: GPT-5 Codex <noreply@openai.com>
Co-authored-by: GPT-5 Codex <noreply@openai.com>
@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6e5ac1c5-f9de-430a-82e1-2a2cd92f30e4

📥 Commits

Reviewing files that changed from the base of the PR and between b2409e2 and 4e2ba41.

📒 Files selected for processing (2)
  • src/Undefined/api/routes/schedules.py
  • tests/test_runtime_api_schedules.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Undefined/api/routes/schedules.py

📝 Walkthrough

Walkthrough

Adds Runtime schedule CRUD and scheduler integration, authenticated Management/WebUI proxy routes, a WebUI Schedules tab (UI, JS, i18n, CSS), OpenAPI/docs and prompt updates, and tests covering probes, CRUD, scheduler job refresh, and WebUI proxy behavior.

Changes

Scheduler UI and API Feature

Layer / File(s) Summary
Documentation and System Prompt Guidance
docs/*, res/prompts/*
OpenAPI/docs updated with /api/v1/schedules routes and probe scheduler field; Management API proxy/auth/header behavior documented; prompt rules added to encourage proactive memory/cognitive lookup and safe memory.* update/delete flows.
Runtime app wiring & probes
src/Undefined/api/app.py, src/Undefined/api/_openapi.py, src/Undefined/api/routes/system.py
Registers /api/v1/schedules routes in RuntimeAPIServer and adds scheduler summary to internal probe responses.
Schedules route handlers and payload logic
src/Undefined/api/routes/schedules.py
New schedules module: payload parsing/normalization (cron, task_id, modes), serialization, summary builder, and CRUD handlers (list/detail/create/update/delete) with provided-field tracking.
Scheduler update semantics
src/Undefined/utils/scheduler.py
TaskScheduler.update_task gains provided-flags for explicit clears and updates APScheduler job args in-place when modifying tasks.
WebUI Management API proxy routes
src/Undefined/webui/routes/_runtime.py
Adds authenticated proxy handlers forwarding schedules requests to Runtime API with JSON validation, URL quoting, and per-method timeouts.
WebUI templates, CSS, JS, and i18n
src/Undefined/webui/templates/index.html, src/Undefined/webui/static/css/*, src/Undefined/webui/static/js/*
Adds Schedules tab HTML, styles and responsive rules, i18n entries (zh/en), main.js hooks, and schedules.js controller implementing list/edit/create/update/delete flows and lifecycle integration.
Tests: runtime, scheduler, prompts, and WebUI
tests/*
Tests cover probe scheduler summary, schedules CRUD behaviors, self-instruction handling, update provided-flag semantics, scheduler job-arg refresh, prompt content checks, and WebUI management proxy behavior.

Sequence Diagram(s):

sequenceDiagram
  participant WebUI
  participant ManagementProxy
  participant RuntimeAPIServer
  participant SchedulesHandlers
  participant TaskScheduler
  participant APScheduler

  WebUI->>ManagementProxy: request /api/runtime/schedules (auth)
  ManagementProxy->>RuntimeAPIServer: proxy /api/v1/schedules (inject X-Undefined-API-Key)
  RuntimeAPIServer->>SchedulesHandlers: _schedules_create_handler(request)
  SchedulesHandlers->>TaskScheduler: add_task(normalized_payload)
  TaskScheduler->>APScheduler: schedule job
  APScheduler-->>TaskScheduler: job registered
  TaskScheduler-->>SchedulesHandlers: created task
  SchedulesHandlers-->>RuntimeAPIServer: 201 serialized task
  RuntimeAPIServer-->>ManagementProxy: 201 passthrough
  ManagementProxy-->>WebUI: 201 response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

Little rabbit checks the cron at night,
Hops through docs, UI, and API light.
Jobs get scheduled, prompts get wise,
Tabs and tests now harmonize. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat(webui): 新增定时任务管理界面' directly and clearly describes the main change: adding a scheduled task management interface to the WebUI, which aligns with the comprehensive feature additions across WebUI, Runtime API, and documentation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/scheduled-webui-view

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2409e214f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Undefined/api/routes/schedules.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Undefined/api/routes/schedules.py`:
- Around line 354-360: build_schedules_summary currently returns objects missing
the required "running" field when the scheduler is absent or doesn't expose
list_tasks; update the early return shapes to include running so the probe
always returns available/count/running. Specifically, in build_schedules_summary
use the ctx.scheduler check and the callable(list_tasks) check to return
{"available": False, "count": 0, "running": 0} (instead of omitting running) so
consumers always see the expected shape.
- Around line 412-417: The code currently treats an explicitly provided empty
task_id as falsy and auto-generates a new id; change this so that if body is a
dict and "task_id" is present but is an empty string you reject the request
instead of generating one. Update the logic around raw_task_id/task_id to:
extract raw_task_id from body, if "task_id" in body and raw_task_id is an empty
string raise the appropriate validation/HTTP error, otherwise if raw_task_id is
truthy call _parse_task_id(raw_task_id), else generate the random id as before;
reference raw_task_id, task_id and _parse_task_id when applying this change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fa4df561-1522-4736-b5e3-3434dfdefe4f

📥 Commits

Reviewing files that changed from the base of the PR and between c850edb and b2409e2.

📒 Files selected for processing (24)
  • docs/cognitive-memory.md
  • docs/management-api.md
  • docs/openapi.md
  • docs/usage.md
  • docs/webui-guide.md
  • res/prompts/undefined.xml
  • res/prompts/undefined_nagaagent.xml
  • src/Undefined/api/_openapi.py
  • src/Undefined/api/app.py
  • src/Undefined/api/routes/schedules.py
  • src/Undefined/api/routes/system.py
  • src/Undefined/utils/scheduler.py
  • src/Undefined/webui/routes/_runtime.py
  • src/Undefined/webui/static/css/components.css
  • src/Undefined/webui/static/css/responsive.css
  • src/Undefined/webui/static/js/i18n.js
  • src/Undefined/webui/static/js/main.js
  • src/Undefined/webui/static/js/schedules.js
  • src/Undefined/webui/templates/index.html
  • tests/test_runtime_api_probes.py
  • tests/test_runtime_api_schedules.py
  • tests/test_scheduler_self_instruction.py
  • tests/test_system_prompt_constraints.py
  • tests/test_webui_management_api.py

Comment thread src/Undefined/api/routes/schedules.py Outdated
Comment thread src/Undefined/api/routes/schedules.py
@69gg 69gg merged commit bf2bea7 into develop Jun 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant