Skip to content

refactor(core): migrate backend backbone from Quart to FastAPI and introduce more OpenAPI - #8688

Merged
Soulter merged 29 commits into
masterfrom
backend-refactor
Jun 14, 2026
Merged

refactor(core): migrate backend backbone from Quart to FastAPI and introduce more OpenAPI#8688
Soulter merged 29 commits into
masterfrom
backend-refactor

Conversation

@Soulter

@Soulter Soulter commented Jun 8, 2026

Copy link
Copy Markdown
Member
  1. Migrate backend backbone from Quart to FastAPI
  2. Introduce more OpenAPIs to boost AstrBot economy
  3. Improve backend structures
  4. This PR is not a break change PR

Modifications / 改动点

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

@sourcery-ai sourcery-ai 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.

Sorry, we are unable to review this pull request

The GitHub API does not allow us to fetch diffs exceeding 20000 lines

@github-advanced-security github-advanced-security AI 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.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request migrates the AstrBot dashboard and webhook servers from Quart to FastAPI, introducing a new ASGI runtime adapter, a unified FastAPI webhook server, and restructuring all dashboard API endpoints into FastAPI routers. The review feedback highlights several critical issues: FastAPIAppAdapter needs to register itself on the FastAPI application state to prevent authentication failures over HTTP in local development; the require_scope dependency must be updated to check cookies to support dashboard users; the close callback in open_api.py should be an asynchronous function to ensure the WebSocket close coroutine is properly awaited; and inspect.signature in the webhook server should be called once during route registration rather than on every request to avoid performance bottlenecks.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread astrbot/dashboard/asgi_runtime.py
Comment thread astrbot/dashboard/api/auth.py Outdated
Comment thread astrbot/core/platform/webhook_server.py
Comment thread astrbot/dashboard/api/open_api.py
@dosubot dosubot Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jun 9, 2026
Comment thread astrbot/dashboard/api/updates.py Fixed
Soulter added 10 commits June 14, 2026 11:11
- Updated API client configuration to use a dedicated HTTP client.
- Introduced utility functions for generating options, queries, and form data for API requests.
- Refactored multiple API methods to utilize the new utility functions for improved consistency and readability.
- Renamed types for clarity and updated import statements accordingly.

feat(docs): add script to update OpenAPI JSON from YAML spec

- Created a Python script to convert OpenAPI YAML specification to JSON format.
- The script supports customizable input and output paths.
- Ensured the script handles directory creation for output paths and validates the YAML structure.
…atibility

- Changed all instances of dashboard_router to legacy_router across multiple API modules including platform, plugins, providers, sessions, skills, stats, subagents, t2i, tools, updates, and asgi_runtime.
- Updated route definitions to ensure existing endpoints remain functional under the new router structure.
- Introduced support for Quart request context in asgi_runtime to enhance compatibility with existing Quart-based plugins.
- Added a test case to validate the functionality of the new Quart request context handling in plugin extensions.
@Soulter
Soulter force-pushed the backend-refactor branch from ee83b2e to 9f92e5b Compare June 14, 2026 03:23
@Soulter

Soulter commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

@gemini-code-assist /gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request transitions the dashboard HTTP API and service layer from Quart to FastAPI, introducing a new FastAPIWebhookServer and rewriting all dashboard API routes into FastAPI routers while maintaining legacy endpoints for backward compatibility. The review feedback highlights critical bugs, including an invalid multi_items() call on Starlette's FormData in multipart.py and an asynchronous property returning a coroutine instead of a dictionary in asgi_runtime.py. High-severity path traversal vulnerabilities were also identified in the static files and backups routes due to unvalidated path parameters. Additionally, the reviewer recommended refactoring duplicated UploadFileAdapter classes, optimizing StreamingResponse when wrapping BytesIO objects, and making user_id a required query parameter in conversation endpoints.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread astrbot/dashboard/api/multipart.py
Comment thread astrbot/dashboard/api/backups.py
Comment thread astrbot/dashboard/asgi_runtime.py
Comment thread astrbot/dashboard/api/static_files.py
Comment thread astrbot/dashboard/api/files.py Outdated
Comment thread astrbot/dashboard/api/conversations.py
Comment thread astrbot/dashboard/api/conversations.py
@Soulter Soulter changed the title backend refactor refactor(core): migrate backend backbone from Quart to FastAPI and introduce more OpenAPI Jun 14, 2026
@Soulter

Soulter commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

@gemini-code-assist /gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request migrates the dashboard HTTP API and platform webhook servers from Quart to FastAPI/Starlette, introducing a modular API structure under astrbot/dashboard/api/ and an ASGI runtime adapter to bridge legacy request contexts. The review feedback highlights critical issues where Starlette's FormData is incorrectly accessed using multi_items() instead of items(), which will cause runtime AttributeErrors during form and file uploads. Additionally, a compatibility issue was identified in stats.py where the | union operator is used inside isinstance(), which will fail on Python versions older than 3.10.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread astrbot/dashboard/api/multipart.py
form = await self._request.form()
form_pairs: list[tuple[str, Any]] = []
file_pairs: list[tuple[str, Any]] = []
for key, value in form.multi_items():

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.

critical

Similar to the issue in multipart.py, Starlette's FormData does not have a multi_items() method. Using form.items() instead will correctly retrieve all key-value pairs. Leaving multi_items() here will cause an AttributeError whenever form data or files are accessed on the request.

Suggested change
for key, value in form.multi_items():
for key, value in form.items():

def _parse_int(value: object, default: int, name: str) -> int:
if value is None:
return default
if not isinstance(value, int | float | str | bytes | bytearray):

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.

medium

Using the | union operator inside isinstance() is only supported in Python 3.10+. If the application is run on Python 3.9 or lower, this will raise a TypeError at runtime. To ensure backward compatibility, please use a tuple of types instead: isinstance(value, (int, float, str, bytes, bytearray)).

Suggested change
if not isinstance(value, int | float | str | bytes | bytearray):
if not isinstance(value, (int, float, str, bytes, bytearray)):

@Soulter
Soulter merged commit 0d8e868 into master Jun 14, 2026
20 checks passed
@Soulter
Soulter deleted the backend-refactor branch June 14, 2026 07:03
Comment thread dashboard/package.json
@@ -47,6 +50,7 @@
"yup": "1.2.0"
},
"devDependencies": {
"@hey-api/openapi-ts": "0.60.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Soulter why use such an old version?

NayukiChiba pushed a commit to NayukiChiba/AstrBot that referenced this pull request Jun 15, 2026
…troduce more OpenAPI (AstrBotDevs#8688)

* refactor: migrate to fastapi

* structure refactor

* fix: pyright fix

* refactor: improve error handling and public messages in plugin services

* feat(api): refactor API client integration and enhance request handling

- Updated API client configuration to use a dedicated HTTP client.
- Introduced utility functions for generating options, queries, and form data for API requests.
- Refactored multiple API methods to utilize the new utility functions for improved consistency and readability.
- Renamed types for clarity and updated import statements accordingly.

feat(docs): add script to update OpenAPI JSON from YAML spec

- Created a Python script to convert OpenAPI YAML specification to JSON format.
- The script supports customizable input and output paths.
- Ensured the script handles directory creation for output paths and validates the YAML structure.

* fix

* feat(auth): implement rate limiting for v1 login endpoint and enhance request handling

* Refactor dashboard API routers to use legacy_router for backward compatibility

- Changed all instances of dashboard_router to legacy_router across multiple API modules including platform, plugins, providers, sessions, skills, stats, subagents, t2i, tools, updates, and asgi_runtime.
- Updated route definitions to ensure existing endpoints remain functional under the new router structure.
- Introduced support for Quart request context in asgi_runtime to enhance compatibility with existing Quart-based plugins.
- Added a test case to validate the functionality of the new Quart request context handling in plugin extensions.

* chore: remove cli test

* fix: update dashboard tests for fastapi migration

* chore: satisfy ruff checks

* fix: update openapi api key scopes

* fix: sync config scope chip selection

* fix: restore quart dependency

* docs: clarify quart plugin api compatibility

* docs: update openapi scope documentation

* fix: use singular skill openapi scope

* fix: hide update service exception details

* fix: address fastapi review comments

* fix: address dashboard review findings

* docs: revert unrelated package deployment changes

* docs: update agent api generation guidance

* feat: add plugin page web api helpers

* docs: add plugin page bridge demo

* fix: type plugin upload files

* fix: stabilize plugin page uploads

* fix: type plugin web request proxy

* docs: remove plugin page docs example

* fix: authenticate plugin page SSE bridge
starmiaoa added a commit to starmiaoa/AstrBot that referenced this pull request Jun 18, 2026
Resolve modify/delete conflict from the Quart->FastAPI dashboard
migration (AstrBotDevs#8688): the old astrbot/dashboard/routes/config.py was
removed upstream. Re-applied the Vertex AI provider-source
normalization in the new service layer
(astrbot/dashboard/services/config_service.py: upsert_provider_source).
The model-list path already terminates instances via try/finally and
normalizes configs in ProviderGoogleGenAI.__init__, so no extra hook is
needed there. Restored the dropped 'from pathlib import Path' import in
gemini_source.py.
KBVsent pushed a commit to KBVsent/AstrBot that referenced this pull request Jul 13, 2026
…troduce more OpenAPI (AstrBotDevs#8688)

* refactor: migrate to fastapi

* structure refactor

* fix: pyright fix

* refactor: improve error handling and public messages in plugin services

* feat(api): refactor API client integration and enhance request handling

- Updated API client configuration to use a dedicated HTTP client.
- Introduced utility functions for generating options, queries, and form data for API requests.
- Refactored multiple API methods to utilize the new utility functions for improved consistency and readability.
- Renamed types for clarity and updated import statements accordingly.

feat(docs): add script to update OpenAPI JSON from YAML spec

- Created a Python script to convert OpenAPI YAML specification to JSON format.
- The script supports customizable input and output paths.
- Ensured the script handles directory creation for output paths and validates the YAML structure.

* fix

* feat(auth): implement rate limiting for v1 login endpoint and enhance request handling

* Refactor dashboard API routers to use legacy_router for backward compatibility

- Changed all instances of dashboard_router to legacy_router across multiple API modules including platform, plugins, providers, sessions, skills, stats, subagents, t2i, tools, updates, and asgi_runtime.
- Updated route definitions to ensure existing endpoints remain functional under the new router structure.
- Introduced support for Quart request context in asgi_runtime to enhance compatibility with existing Quart-based plugins.
- Added a test case to validate the functionality of the new Quart request context handling in plugin extensions.

* chore: remove cli test

* fix: update dashboard tests for fastapi migration

* chore: satisfy ruff checks

* fix: update openapi api key scopes

* fix: sync config scope chip selection

* fix: restore quart dependency

* docs: clarify quart plugin api compatibility

* docs: update openapi scope documentation

* fix: use singular skill openapi scope

* fix: hide update service exception details

* fix: address fastapi review comments

* fix: address dashboard review findings

* docs: revert unrelated package deployment changes

* docs: update agent api generation guidance

* feat: add plugin page web api helpers

* docs: add plugin page bridge demo

* fix: type plugin upload files

* fix: stabilize plugin page uploads

* fix: type plugin web request proxy

* docs: remove plugin page docs example

* fix: authenticate plugin page SSE bridge
KBVsent pushed a commit to KBVsent/AstrBot that referenced this pull request Jul 13, 2026
…troduce more OpenAPI (AstrBotDevs#8688)

* refactor: migrate to fastapi

* structure refactor

* fix: pyright fix

* refactor: improve error handling and public messages in plugin services

* feat(api): refactor API client integration and enhance request handling

- Updated API client configuration to use a dedicated HTTP client.
- Introduced utility functions for generating options, queries, and form data for API requests.
- Refactored multiple API methods to utilize the new utility functions for improved consistency and readability.
- Renamed types for clarity and updated import statements accordingly.

feat(docs): add script to update OpenAPI JSON from YAML spec

- Created a Python script to convert OpenAPI YAML specification to JSON format.
- The script supports customizable input and output paths.
- Ensured the script handles directory creation for output paths and validates the YAML structure.

* fix

* feat(auth): implement rate limiting for v1 login endpoint and enhance request handling

* Refactor dashboard API routers to use legacy_router for backward compatibility

- Changed all instances of dashboard_router to legacy_router across multiple API modules including platform, plugins, providers, sessions, skills, stats, subagents, t2i, tools, updates, and asgi_runtime.
- Updated route definitions to ensure existing endpoints remain functional under the new router structure.
- Introduced support for Quart request context in asgi_runtime to enhance compatibility with existing Quart-based plugins.
- Added a test case to validate the functionality of the new Quart request context handling in plugin extensions.

* chore: remove cli test

* fix: update dashboard tests for fastapi migration

* chore: satisfy ruff checks

* fix: update openapi api key scopes

* fix: sync config scope chip selection

* fix: restore quart dependency

* docs: clarify quart plugin api compatibility

* docs: update openapi scope documentation

* fix: use singular skill openapi scope

* fix: hide update service exception details

* fix: address fastapi review comments

* fix: address dashboard review findings

* docs: revert unrelated package deployment changes

* docs: update agent api generation guidance

* feat: add plugin page web api helpers

* docs: add plugin page bridge demo

* fix: type plugin upload files

* fix: stabilize plugin page uploads

* fix: type plugin web request proxy

* docs: remove plugin page docs example

* fix: authenticate plugin page SSE bridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants