feat(web): 新增 Web 观测台(形态 A)+ 抽出 render/targets 共用层

- tcaptcha/web/:FastAPI + SSE + 零构建单页。把同步阻塞的 solve() 包成可观测
  后台任务(工作线程 + 全局串行,因 onnxruntime session 非线程安全),用
  logging.Handler 零侵入把 client 日志变成事件流;按靶子实测 min_interval 强制节流。
- tcaptcha/render.py:标注图(点击顺序编号 + 质心偏差)与点位量尺,CLI 与 web 共用。
- tcaptcha/targets.py:靶子表提为单一来源(含实测频控间隔 1ms=60s / mliev=3s)。
- fastapi/uvicorn 走 optional extra `web`,核心包零 web 依赖(带回归断言)。
- 修两个真 bug:hook 求解器时 args[0] 是实例自身(真入参从 args[1] 起);
  client 默认每次新建 solver,预热实例未被复用(每发重载 56MB ONNX)。
- 复验:icon/text/slider 三题型各拿到 errorCode=0;selftest 全绿;依赖隔离通过。

用法:uv run --extra web python -m tcaptcha.web.app
This commit is contained in:
yml2213
2026-10-14 19:10:54 +08:00
parent 74a863c8b3
commit 99565f65f0
15 changed files with 1827 additions and 1189 deletions
+19
View File
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
"""Web 观测台(形态 A:观测 / 调试台)。
分层:
* `events.py` 事件模型(前后端共用同一套 `EVT_*` 类型名)
* `runner.py` `SolveJob` / `JobManager` —— 把同步阻塞的 `solve()` 包成
"可观测的后台任务"(工作线程 + 全局串行 + 频控节流 + 事件化)
* `app.py` FastAPI 路由(建任务 / SSE / 图片 / 快照 / 取消)
* `static/` 零构建单页(原生 JS,不引打包器/框架)
**依赖是可选 extra**:`fastapi` + `uvicorn` 装在 `[project.optional-dependencies].web`,
核心包(协议 / 遥测 / 求解器 / CLI)完全不依赖它们 —— 所以本模块的 `__init__`
刻意**不 import app**,避免 `import tcaptcha.web` 就把 fastapi 拉进来。
启动:
uv run --extra web python -m tcaptcha.web.app
"""
__all__: list = []