Skip to content

feat: 增加 shell 工具自定义超时配置#6076

Open
a61995987 wants to merge 3 commits intoAstrBotDevs:masterfrom
a61995987:feat-增加-shell-工具自定义超时配置

Hidden character warning

The head ref may contain hidden characters: "feat-\u589e\u52a0-shell-\u5de5\u5177\u81ea\u5b9a\u4e49\u8d85\u65f6\u914d\u7f6e"
Open

feat: 增加 shell 工具自定义超时配置#6076
a61995987 wants to merge 3 commits intoAstrBotDevs:masterfrom
a61995987:feat-增加-shell-工具自定义超时配置

Conversation

@a61995987
Copy link
Contributor

@a61995987 a61995987 commented Mar 11, 2026

某些特殊技能脚本可能需要更长的执行时间 且需要将执行结果实时返回给LLM(如使用yt-dlp库在youtube上抓取字幕 该库在游客身份下获取字幕列表后 必须等待60秒才能够进行字幕下载 否则会报429错误)
该PR增加了对shell工具超时时间的自定义修改支持 默认30秒

Modifications / 改动点

修改文件:astrbot/core/computer/tools/shell.py

  1. 修改call方法中的sb.shell.exec调用 传入系统配置(shell_call_timeout)

修改文件:astrbot/core/config/default.py

  1. 新增shell_call_timeout属性及相关定义、描述

修改文件:dashboard/src/i18n/locales/en-US/features/config-metadata.jsondashboard/src/i18n/locales/zh-CN/features/config-metadata.json

  1. 增加shell_call_timeout的i18n翻译

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

微信图片_2026-03-12_031049_889

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ 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.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

为 shell 工具执行添加可配置的超时支持(默认 30 秒),并通过 provider 设置对外暴露。

New Features:

  • 引入 shell_call_timeout 配置项,用于按 provider 控制 shell 工具的执行超时时间。

Enhancements:

  • 将 shell 工具接入 provider 设置,从中读取超时时间并传递给底层的 shell 执行器。
  • 在配置元数据和 i18n 中暴露 shell_call_timeout,以便可以通过控制台(dashboard)界面进行管理。
Original summary in English

Summary by Sourcery

Add configurable timeout support for shell tool execution with a default of 30 seconds and expose it through provider settings.

New Features:

  • Introduce a shell_call_timeout configuration option to control shell tool execution timeouts per provider.

Enhancements:

  • Wire the shell tool to read its timeout from provider settings and pass it to the underlying shell executor.
  • Expose shell_call_timeout in the configuration metadata and i18n so it can be managed via the dashboard UI.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 11, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在通过引入可配置的 Shell 工具调用超时时间来增强系统的灵活性。此功能解决了某些特殊脚本可能需要更长执行时间的问题,例如在特定条件下使用 yt-dlp 抓取字幕。通过允许用户调整默认的 30 秒超时,可以防止长时间运行的任务被过早终止,从而提升了 Shell 工具的实用性和稳定性。

Highlights

  • 自定义 Shell 超时配置: 引入了新的配置项 shell_call_timeout,允许用户自定义 Shell 命令的执行超时时间,以适应需要更长执行时间的特殊脚本。
  • 默认超时时间: Shell 命令的默认超时时间设置为 30 秒,可在配置中进行调整。
  • Shell 工具集成: Shell 工具的 call 方法现在会从系统配置中获取 shell_call_timeout 并将其传递给底层的 sb.shell.exec 调用。
  • 仪表盘支持: 为 shell_call_timeout 添加了中英文国际化(i18n)翻译,使其可以通过仪表盘界面进行配置和管理。
Changelog
  • astrbot/core/computer/tools/shell.py
    • 修改了 call 方法,使其能够从配置中获取 shell_call_timeout 并将其作为参数传递给 sb.shell.exec
  • astrbot/core/config/default.py
    • 新增了 shell_call_timeout 配置项,并设置默认值为 30 秒。
    • 更新了 ChatProviderTemplate,增加了 shell_call_timeout 的类型定义。
    • provider_settings.shell_call_timeout 添加了详细的元数据,包括描述和条件。
  • dashboard/src/i18n/locales/en-US/features/config-metadata.json
    • shell_call_timeout 添加了英文描述 'Shell Call Timeout (s)'。
  • dashboard/src/i18n/locales/zh-CN/features/config-metadata.json
    • shell_call_timeout 添加了中文描述 'Shell 调用超时时间(秒)'。
Activity
  • 此拉取请求自创建以来,尚未有评论或审查活动。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

嗨,我在这里给出了一些高层次的反馈:

  • shell.call 里读取 shell_call_timeout 时,建议避免直接使用硬编码的默认值 30,而是复用中央配置中已有的默认值(或回退到 tool_call_timeout),这样默认值只需要在一个地方维护。
  • provider_settings 中读取 shell_call_timeout 时,它可能会以字符串形式出现(例如来自 UI 输入),因此在将其传入 sb.shell.exec 之前,显式地将其转换/校验为 int 会更安全。
给 AI 代理的提示词
Please address the comments from this code review:

## Overall Comments
- Consider avoiding the hard-coded default `30` when reading `shell_call_timeout` in `shell.call` and instead reuse the existing default from the central config (or fall back to `tool_call_timeout`) so the default only needs to be maintained in one place.
- When reading `shell_call_timeout` from `provider_settings`, it may arrive as a string (e.g., from UI input), so it’s safer to explicitly cast/validate it as an `int` before passing it into `sb.shell.exec`.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've left some high level feedback:

  • Consider avoiding the hard-coded default 30 when reading shell_call_timeout in shell.call and instead reuse the existing default from the central config (or fall back to tool_call_timeout) so the default only needs to be maintained in one place.
  • When reading shell_call_timeout from provider_settings, it may arrive as a string (e.g., from UI input), so it’s safer to explicitly cast/validate it as an int before passing it into sb.shell.exec.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider avoiding the hard-coded default `30` when reading `shell_call_timeout` in `shell.call` and instead reuse the existing default from the central config (or fall back to `tool_call_timeout`) so the default only needs to be maintained in one place.
- When reading `shell_call_timeout` from `provider_settings`, it may arrive as a string (e.g., from UI input), so it’s safer to explicitly cast/validate it as an `int` before passing it into `sb.shell.exec`.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:core The bug / feature is about astrbot's core, backend label Mar 11, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 为 shell 工具增加了自定义超时配置,这是一个非常有用的功能,特别是对于需要较长执行时间的脚本。整体实现是清晰的,覆盖了默认配置、UI 元数据和国际化文件。

我提出的主要建议是在 shell.py 中调用 get_config 时显式传递 umo 参数。这能够确保在存在会话级配置覆盖时,总能获取到正确的超时设置,从而保证了功能的正确性和代码的健壮性。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant