ForcePilot/backend/package/yuxi/channels/adapters/identity_resolver_adapter.py
Kris 00092c818e chore: 批量代码优化与规范完善
本次提交包含多项代码优化与规范修正:
1. 文档与注释优化:修正注释术语、补充注解与FR编号
2. 代码格式调整:统一空格、换行与缩进规范
3. 类型与接口完善:补充__all__导出、修正返回类型注解
4. 错误处理增强:新增领域错误类与校验逻辑
5. 依赖与导入调整:修复路径引用、统一时区导入
6. 协议与契约更新:完善接口文档与一致性注解
2026-07-03 19:18:13 +08:00

55 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""IdentityResolverAdapter实现 IdentityResolverPort默认降级实现。
- 默认降级实现,由插件可覆盖
- resolve 返回 None触发降级至 DB 查询)
- getConfidence 返回 0.0
依赖边界:只依赖 yuxi.channels.contract端口 + DTO
"""
from __future__ import annotations
from yuxi.channels.contract.dtos.identity import (
IdentityResolveCmd,
IdentityResolveResult,
)
from yuxi.channels.contract.ports.driven.identity_resolver_port import IdentityResolverPort
__all__ = ["IdentityResolverAdapter"]
class IdentityResolverAdapter(IdentityResolverPort):
"""身份解析被驱动适配器(默认降级实现)。
默认实现不接入外部身份源,``resolve`` 返回 ``None`` 触发降级至 DB
查询,``getConfidence`` 返回 ``0.0``。实际身份解析逻辑由插件注册时
注入。
"""
async def resolve(self, cmd: IdentityResolveCmd) -> IdentityResolveResult | None:
"""解析身份(默认降级,返回 None
默认不接入外部身份源,返回 None 触发降级至 DB 查询。
实际解析逻辑由插件覆盖。
Args:
cmd: 身份解析命令,携带渠道类型、对端 ID 与账户 ID。
Returns:
None默认降级
"""
return None
async def getConfidence(self, identity_id: str) -> float:
"""查询身份置信度(默认降级,返回 0.0)。
默认返回 ``0.0``,实际置信度由插件覆盖。
Args:
identity_id: 统一身份 ID。
Returns:
0.0(默认降级)。
"""
return 0.0