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:
@@ -38,6 +38,7 @@ import paths
|
||||
import providers
|
||||
import speech
|
||||
import store
|
||||
import timeouts
|
||||
import tools_runtime
|
||||
import uploads
|
||||
from defaults import PROVIDER_PRESETS
|
||||
@@ -245,8 +246,15 @@ class SseChannel:
|
||||
|
||||
def _ping_loop(self) -> None:
|
||||
while not self.closed:
|
||||
# 用 Event.wait 代替 sleep,结束时会立刻退出,不用等满 15 秒
|
||||
if self._stop_event.wait(15):
|
||||
# ★ 心跳间隔可调(设置 → 超时 → 心跳间隔)。
|
||||
# 它必须**明显小于**客户端的读超时(sseRead),否则客户端会先
|
||||
# 判定"连接死了"再断开 —— 等用户回答的那种场景会因此白等。
|
||||
try:
|
||||
gap = float(timeouts.get('heartbeat'))
|
||||
except Exception: # noqa: BLE001
|
||||
gap = 15.0
|
||||
# 用 Event.wait 代替 sleep,结束时会立刻退出,不用等满
|
||||
if self._stop_event.wait(gap):
|
||||
return
|
||||
if self.closed:
|
||||
return
|
||||
@@ -585,6 +593,36 @@ class KernelHandler(BaseHTTPRequestHandler):
|
||||
self.send_json(200, {'ok': True, 'settings': store.mask_settings(nxt)})
|
||||
return True
|
||||
|
||||
# ---------------------------------------------------------------- #
|
||||
# 超时(设置 → 超时)
|
||||
#
|
||||
# ★ 清单由内核给,**界面不硬编码这些项目** —— 加一项超时只改 timeouts.py,
|
||||
# 界面自动多出一行(连说明文字都是这里带过去的)。
|
||||
# ★ 写的时候是**整体替换**而不是深合并:默认值在 timeouts.py 里,
|
||||
# "改回默认"等于"从设置文件里删掉这一项",深合并会让它删不掉。
|
||||
# ---------------------------------------------------------------- #
|
||||
if pathname == '/api/timeouts' and method == 'GET':
|
||||
self.send_json(200, {
|
||||
'ok': True,
|
||||
'items': timeouts.catalog(),
|
||||
'values': timeouts.resolved(),
|
||||
})
|
||||
return True
|
||||
|
||||
if pathname == '/api/timeouts' and method in ('PUT', 'POST'):
|
||||
body = self.read_json_body()
|
||||
if body.get('reset'):
|
||||
next_values = timeouts.reset()
|
||||
else:
|
||||
next_values = timeouts.patch(body.get('values') or body)
|
||||
store.write_settings({'timeouts': next_values})
|
||||
self.send_json(200, {
|
||||
'ok': True,
|
||||
'items': timeouts.catalog(),
|
||||
'values': timeouts.resolved(),
|
||||
})
|
||||
return True
|
||||
|
||||
if pathname == '/api/models' and method == 'GET':
|
||||
settings = store.read_settings()
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user