feat: 所有超时收成一份、全部可调(设置 → 超时,18 项)

用户要求"全部超时做成可调"。改造前 15 个超时散在 10 个文件里当模块级常量,
说不清一共有几个,也答不了"哪些能调"。

内核
- 新增 android/kernel/timeouts.py:**超时的唯一一份定义**(DEFAULT + SPECS),
  带每项的 名字/分组/说明/默认值/上下界;get() 一律夹取,用户填什么都不炸
- 新增 GET/POST /api/timeouts(清单 + 当前值 + 保存 + 恢复默认)
- 各处改现读:tools_runtime(tool)、builtin_tools(shell/pythonRun)、
  doubao_entry(termux)、providers(model)、speech(tts/stt)、
  mcp_client(请求/连接/调用)、meeting(meetingNode)、custom_nodes(customNode)、
  app.py 的 SSE 心跳
- ask_user / show_ui 用 TIMEOUT_KEYS 声明"哪个参数该用设置里的值",
  内核调用前注入(工具的默认值退化成单独跑时的兜底)
- store.py:timeouts 走**整体替换**而不是深合并 —— 深合并会让"改回默认"删不掉

安卓
- data/AppTimeouts.kt:客户端缓存(OkHttp 的 readTimeout、文件选择没法现问内核)
- KernelClient:readTimeout 跟着 sseRead 走,改完重建连接池;新增 timeouts 接口
- ui/TimeoutsScreen.kt:全屏界面,按分组列出、-/+ 与输入框、恢复默认
- 设置页加「超时」卡片入口;NativeBridge 的本地接口请求 / 选文件等待接上
- Settings 模型加 TimeoutItem / TimeoutsState(字段全部来自内核)

Node 端(Web/exe)
- 新增 server/src/timeouts.mjs(和 Python 那份逐字对应)
- config.mjs 加 timeouts(同样整体替换);speech / python-tools / mcp / providers
  各处改读;index.mjs 加 /api/timeouts

验证
- 新增 scripts/verify-timeouts.py:清单完整性、边界容错(文字/空串/负数/超大值/
  带单位/None)、**扫内核有没有漏网的硬编码超时**(带白名单)、
  工具侧声明、以及和 Node 端逐项对拍
- 实测真机:界面显示 18 项来自内核 → 点 + 保存 → 内核 heartbeat 15→25 →
  恢复默认 → 回 15;askUser 显示"不限时"

文档:README §3.13;docs/AI界面能力.md 的"不限时要三处一起改"补上可调入口。
版本 2.0.46。
This commit is contained in:
l
2026-10-16 10:29:46 +08:00
parent d82c3d3176
commit c7fed95650
32 changed files with 1523 additions and 70 deletions

View File

@@ -26,6 +26,7 @@ import time
import traceback
import paths
import timeouts
# --------------------------------------------------------------------------- #
# 工具定义(与 tools/shell.py、tools/python_run.py 的 TOOL 完全一致,
@@ -43,7 +44,10 @@ SHELL_TOOL = {
'properties': {
'command': {'type': 'string', 'description': '要执行的命令,例如 ls -la 或 python --version'},
'cwd': {'type': 'string', 'description': '工作目录,可留空'},
'timeout': {'type': 'number', 'description': '超时秒数,默认 30,最大 300'},
'timeout': {
'type': 'number',
'description': '超时秒数。不传就用设置里「超时 → shell 命令」那个值',
},
},
'required': ['command'],
},
@@ -67,7 +71,10 @@ PYTHON_RUN_TOOL = {
'code': {'type': 'string', 'description': '要执行的 Python 代码(action=run 时二选一)'},
'file': {'type': 'string', 'description': '要执行的 .py 文件路径(action=run 时二选一)'},
'stdin': {'type': 'string', 'description': '传给脚本的标准输入,可留空'},
'timeout': {'type': 'number', 'description': '超时秒数,默认 60,最大 600'},
'timeout': {
'type': 'number',
'description': '超时秒数。不传就用设置里「超时 → 跑 Python 代码」那个值',
},
},
},
}
@@ -125,7 +132,8 @@ def shell_run(args: dict) -> dict:
if bad in lowered:
raise ValueError(f'命令命中黑名单({bad}),已拒绝执行。确实需要请设置 DOUBAO_SHELL_UNSAFE=1')
timeout = max(1, min(300, int(args.get('timeout') or 30)))
# 超时:模型传了就用它的,没传就用设置里的(设置 → 超时 → shell 命令)
timeout = timeouts.budget(args, 'shell')
cwd = args.get('cwd') or None
if cwd and not os.path.isdir(cwd):
raise ValueError(f'工作目录不存在:{cwd}')
@@ -293,7 +301,7 @@ def python_run(args: dict) -> dict:
if not code and not file_path:
raise ValueError('code 和 file 至少要给一个')
timeout = max(1, min(600, int(args.get('timeout') or 60)))
timeout = timeouts.budget(args, 'pythonRun')
stdin_text = args.get('stdin') or ''
if file_path: