mirror of
https://github.com/AstrBotDevs/AstrBot.git
synced 2026-09-19 02:05:38 +08:00
* fix: unify media reference handling * fix: accept bare base64 record media refs * chore: update agents.md * fix: unify file URI handling across media components and utilities * fix: unify media reference type handling with MediaRefStr alias * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Update astrbot/core/platform/sources/discord/discord_platform_adapter.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * fix: unify media handling and improve base64 decoding across components * fix: simplify client_kwargs type definition and enhance media message handling in platform adapter * fix: unify media utility documentation and enhance function descriptions * perf: drop "pilk" requirement, improve audio outbound for tencent-related IM apps which using silk * fix: unify Tencent Silk audio handling and enhance media resolver functionality --- - Centralize media reference materialization and base64 resolution for local paths, http(s), base64://, data URIs, and legacy bare base64 payloads. - Normalize incoming Record audio to wav and Image media to temporary jpg during preprocess, with event-scoped cleanup. - Reuse the shared media resolver across OpenAI, Gemini, Anthropic, MiMo, DeerFlow, STT, and platform media paths while sanitizing logs and cleaning temporary conversion outputs. - Ensure generated TTS audio is tracked for cleanup after the event finishes. fix #8676 fix #8543 fix #7588 fix #7580 fix #8030 fix #8034 fix #7461 fix #7565 fix #6509 fix #7144 fix #7795 --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
3.9 KiB
3.9 KiB
Setup commands
Core
uv sync
uv run main.py
Exposed an API server on http://localhost:6185 by default.
Dashboard(WebUI)
cd dashboard
pnpm install # First time only. Use npm install -g pnpm if pnpm is not installed.
pnpm dev
Runs on http://localhost:3000 by default.
Pre-commit setup
AstrBot uses pre-commit hooks to automatically format and lint Python code before each commit. The hooks run ruff check, ruff format, and pyupgrade (see .pre-commit-config.yaml for details).
To set it up:
pip install pre-commit
pre-commit install
After installation, the hooks will run automatically on git commit. You can also run them manually at any time:
ruff format .
ruff check .
Note: If you use VSCode, install the
Ruffextension for real-time formatting and linting in the editor.
Dev environment tips
Basic
- When modifying the WebUI, be sure to maintain componentization and clean code. Avoid duplicate code.
- Do not add any report files such as xxx_SUMMARY.md.
- After finishing, use
ruff format .andruff check .to format and check the code. - When committing, ensure to use conventional commits messages, such as
feat: add new agent for data analysisorfix: resolve bug in provider manager. - Use English for all new comments.
- For path handling, use
pathlib.Pathinstead of string paths, and useastrbot.core.utils.path_utilsto get the AstrBot data and temp directory.
No Unnecessary Helpers
Prioritize inline implementation over abstraction. Avoid over-engineering and do not create helper functions unless absolutely necessary.
- Inline-First Rule: If a logic block can be implemented directly within the main function without breaking overall readability, do not extract it into a new helper function.
- Strict Justification for Helpers: You may only create a separate helper function if it meets at least one of these criteria:
- High Reuse: The exact same logic is repeated across 3 or more different locations.
- Extreme Complexity: Inlining the logic makes the main function too long (e.g., >50 lines) or severely derails the main execution flow.
- No Fragmentation: Do not split continuous linear logic (e.g., a single API call, simple form validation, or one-time data formatting) into tiny functions just for the sake of "clean code."
- Keep Context Compact: Handle edge cases, error catching, and logging directly inside the main function block instead of offloading them.
- Refactoring Constraint: When modifying existing code, do not alter the current function structure or extract code into new helpers unless the existing code already violates the complexity or reuse rules above.
Mandatory Google-Style Docstrings
- Comment the complex: Add clear comments to any non-obvious function, method, or parameter.
- Google Format: All docstrings must strictly use the Google format (
Args:,Returns:,Raises:).
Example:
def calculate_metrics(user_id: int, force_refresh: bool = False) -> dict:
"""Brief description of the function.
Args:
user_id: Description of the ID.
force_refresh: Description of the flag.
Returns:
Description of the returned dict.
Raises:
ValueError: Description of when this occurs.
"""
# Inline implementation here...
PR instructions
- Title format: use conventional commit messages
- Use English to write PR title and descriptions.
Release versions
- Replace current version name to specific version name.
- Write changelog in
changelogs/, you can refer to the full commit messages between the latest tag to the latest commit. - Make and push a commit into master branch with message format like:
chore: bump version to 4.25.0 - Create a tag and push the tag. For example:
git tag v4.25.0 && git push origin v4.25.0