【止血】
- errors.py: NotLoggedInError.__init__ 增加可选 message 参数,修复
services/sealai/auth_service.py 中 raise NotLoggedInError(f"...") 导致
TypeError 的硬错误
【边界收口】
- services/sealai/auth_service.py: 新增 get_whoami(),封装 api.sealai.get_me,
消灭 commands/server 对 api 层的直接穿透
- commands/sealai/whoami.py: 改用 services.sealai.get_whoami(),去掉 api 层导入
- server/sealai_router.py /me: 改用 services.sealai.get_whoami(),去掉 api 层导入
- services/agent_service.py: 新增 list_agents_cmd 等 _cmd 系列便捷函数,
commands 层无需再 import get_client
- commands/agent/list.py: 改用 list_agents_cmd(),去掉对 api.get_client 的直接依赖
【Schema 归属】
- api/sealai/schemas.py: 新增「Server 请求模型」节,迁入 sealai_router.py 中
原有 6 个内联 BaseModel(RuleCreateRequest 等)
- server/sealai_router.py: 去掉所有内联 BaseModel 和 pydantic 导入,
改从 api/sealai/schemas 统一导入
【导出统一】
- services/__init__.py: 纳入 SealAI 子域的全部 service 函数,
消灭两套并行导出体系;补充模块 docstring
【工程纪律】
- commands/auth.py: 去掉 auth_use / auth_whoami 中的局部异常捕获,
统一由 CLI 入口全局 handler 处理
【文档规范】
- CLAUDE.md: 新增「文档规范」节,明确 {module}.readme.md / {module}.test.py /
README.{dirname}.md 命名约定及分层导入禁止规则
- 新建 README.commands.md / README.server.md / README.services.md /
services/sealai/README.sealai.md / api/sealai/README.sealai.md
1.8 KiB
1.8 KiB
api/sealai/ — SealAI 传输层
职责边界
- 薄层封装:只做 HTTP 请求发送和 Pydantic 响应解析,不做业务判断。
- 不被上层直接调用:仅供
services/sealai/调用,commands 和 server 不得直接引用本层业务函数。
模块说明
| 模块 | 封装的 API |
|---|---|
client.py |
SealAiClient:Bearer JWT 认证的 httpx 客户端 |
schemas.py |
所有 Pydantic 模型(响应模型 + Server 请求模型) |
auth_api.py |
GET /api/v1/auth/me → get_me() |
billing_api.py |
GET /api/v1/billing/status → get_billing_status() |
rules_api.py |
/api/v1/rules 系列(草稿 CRUD + 版本发布) |
preference_api.py |
GET/POST /api/v1/agent/ai-approval/config |
knowledge_api.py |
/api/v1/knowledge/articles 系列 |
SealAiClient
class SealAiClient:
base_url: str # https://{corp_id.lower()}.sealai.cc
bearer_token: str
所有 API 函数签名:fn(client: SealAiClient, ...) -> ResponseModel
schemas.py 结构
schemas.py
├── 通用包装:SealAiResponse[T]
├── 认证:SealAiUser / SealAiTenant / MeData
├── 计费:Subscription / Feature / BillingStatusData
├── 审核规则草稿:DraftRule / DraftRulesData
├── 已发布版本:RuleSetVersion / PublishVersionData
├── 风格偏好:DecisionPreferences / AiApprovalConfig / AiApprovalSaveResult
├── 知识文档:KnowledgeArticle / KnowledgeArticleListData
└── Server 请求模型:RuleCreateRequest / RuleUpdateRequest /
PublishVersionRequest / DecisionPreferencesUpdateRequest /
ArticleCreateRequest / ArticleUpdateRequest
已知 API 路径
详见 services/sealai/README.sealai.md 及各 *_api.py 文件顶部 docstring。