初始化协调器 Args: user_id: 用户 ID(可选,如果为空则从 roles.json 获取) feishu_user_id: 飞书用户 ID(用于 open_id 发送) chat_id: 聊天 ID(用于 chat_id 发送,优先级更高) send_to_feishu: 是否允许发送飞书消息;命令行 dry-run/--no-feishu 会关闭
(
self,
user_id: Optional[str] = None,
feishu_user_id: Optional[str] = None,
chat_id: Optional[str] = None,
send_to_feishu: bool = True,
)
| 1485 | """主协调器""" |
| 1486 | |
| 1487 | def __init__( |
| 1488 | self, |
| 1489 | user_id: Optional[str] = None, |
| 1490 | feishu_user_id: Optional[str] = None, |
| 1491 | chat_id: Optional[str] = None, |
| 1492 | send_to_feishu: bool = True, |
| 1493 | ): |
| 1494 | """ |
| 1495 | 初始化协调器 |
| 1496 | |
| 1497 | Args: |
| 1498 | user_id: 用户 ID(可选,如果为空则从 roles.json 获取) |
| 1499 | feishu_user_id: 飞书用户 ID(用于 open_id 发送) |
| 1500 | chat_id: 聊天 ID(用于 chat_id 发送,优先级更高) |
| 1501 | send_to_feishu: 是否允许发送飞书消息;命令行 dry-run/--no-feishu 会关闭 |
| 1502 | """ |
| 1503 | # 优先使用传入的 user_id,如果没有则从 roles.json 获取 |
| 1504 | if user_id: |
| 1505 | self.user_id = user_id |
| 1506 | else: |
| 1507 | roles_user_id = get_current_user_id() |
| 1508 | self.user_id = roles_user_id if roles_user_id != "user_default" else "user_unknown" |
| 1509 | self.send_to_feishu = send_to_feishu |
| 1510 | self.feishu_user_id = (feishu_user_id or os.environ.get("FEISHU_USER_ID", "")) if send_to_feishu else "" |
| 1511 | self.profile = get_profile(self.user_id) |
| 1512 | self.role_meta = get_role_meta_for_user(self.user_id) or {} |
| 1513 | self.role_name = self.role_meta.get("role_name") |
| 1514 | # 优先使用传入 chat_id,否则回退到角色绑定的 chat_id,避免误发到默认个人账号 |
| 1515 | self.chat_id = (chat_id or resolve_role_chat_id(self.user_id, self.profile)) if send_to_feishu else None |
| 1516 | |
| 1517 | def detect_intent(self, text: str) -> Dict[str, Any]: |
| 1518 | """ |
nothing calls this directly
no test coverage detected