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

+2 -2
View File
@@ -3,8 +3,8 @@
与快报主站的 EkbClient 并列,同属 api/ 传输层。
区别:SealAI 用 Bearer JWT 认证,域名按企业 corpId 动态生成。
使用方:services/sealai/ 通过 get_sealai_client() 获取实例,
不直接 import 此模块。
使用方:services/sealai/auth_service 通过 _get_or_create_client() 获取实例,
并由 _sealai_call 统一管理生命周期,外部不直接持有或关闭此对象。
"""
from __future__ import annotations