从环境变量或 config.json 加载飞书凭证。
()
| 58 | |
| 59 | |
| 60 | def _load_feishu_credentials() -> tuple[str, str]: |
| 61 | """从环境变量或 config.json 加载飞书凭证。""" |
| 62 | app_id = os.environ.get("FEISHU_APP_ID", "") |
| 63 | app_secret = os.environ.get("FEISHU_APP_SECRET", "") |
| 64 | |
| 65 | if not app_id or not app_secret: |
| 66 | config_path = Path.home() / ".nanoresearch" / "config.json" |
| 67 | if config_path.exists(): |
| 68 | try: |
| 69 | data = json.loads(config_path.read_text(encoding="utf-8")) |
| 70 | feishu = data.get("feishu", {}) |
| 71 | app_id = app_id or feishu.get("app_id", "") |
| 72 | app_secret = app_secret or feishu.get("app_secret", "") |
| 73 | except (json.JSONDecodeError, OSError): |
| 74 | pass |
| 75 | |
| 76 | if not app_id or not app_secret: |
| 77 | raise RuntimeError( |
| 78 | "飞书凭证未配置。请设置环境变量 FEISHU_APP_ID / FEISHU_APP_SECRET,\n" |
| 79 | "或在 ~/.nanoresearch/config.json 中添加:\n" |
| 80 | ' "feishu": {"app_id": "cli_xxx", "app_secret": "xxx"}' |
| 81 | ) |
| 82 | return app_id, app_secret |
| 83 | |
| 84 | |
| 85 | # ═══════════════════════════════════════════════════════════════ |