SealAI 全面收口:service 层统一管理 client 生命周期 + 401 自动恢复

核心改动(auth_service.py):
- 新增模块级内存 client 缓存(_client_cache),按 corp_id 键入 + TTL 复用
- 磁盘 token 缓存 + 内存 client 缓存双层同步驱逐(invalidate_token 一并清除)
- 新增 _sealai_call(corp_id, fn, ...):统一调用入口,401 时自动清缓存并单次重试
- get_sealai_client 降级为内部函数,不再对外导出

业务 service 层(4 个文件):
- 函数签名从 (client: SealAiClient, ...) 改为 (corp_id: str | None = None, ...)
- 内部统一走 _sealai_call,不自行管理 client

表现层全面收口(11 个 commands 文件 + sealai_router.py):
- 移除所有 get_sealai_client 调用,直接传 corp_id 给 service 函数
- CLI 和 Server 不再感知 SealAiClient 的存在

效果:
- CLI 进程短命,内存 client 随进程回收;Server 长命,连接池复用
- 两条路径代码完全统一,差别仅由进程生命周期自然体现
- 全仓 grep 验证:commands/* 和 server/* 已无任何 get_sealai_client 引用
This commit is contained in:
gitea committed 2026-04-16 09:58:02 +08:00
1 parent 942449653a
commit 2f51f0f611
20 files changed
+426 -186

No files matched your search

-1
View File
@@ -56,7 +56,6 @@ from ekb_cli.services.rule_service import ( # noqa: F401
# commands/server 使用 `from ekb_cli.services.sealai import xxx`
# 此处仅做显式 re-export 以便 IDE 跳转和 import lint 检查。
from ekb_cli.services.sealai import ( # noqa: F401
get_sealai_client,
get_bearer_token,
invalidate_token,
get_whoami,