front/xhs-agent-desktop/app/config_store.py
zzh 5a26ae0048 feat: 小红书模块迁移、登录重构与 xhs-agent-desktop 桌面 Agent
- 新增小红书前端模块(启动服务、内容分析、爆款创作、发布记录、技能卡片、拟人设置、AI 助手)

- 新增 xhs-agent-desktop 独立桌面 Agent,对接 OMS 任务调度

- 登录页重构,整合微信登录与 OMS JWT 认证

- 订单、渠道、用户中心等页面与 API 增强

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 16:13:13 +08:00

47 lines
1.3 KiB
Python

"""本地配置持久化。"""
from __future__ import annotations
import json
from dataclasses import asdict, dataclass
from pathlib import Path
@dataclass
class AgentSettings:
oms_url: str = "http://localhost:5281/admin"
token: str = ""
device_name: str = ""
bridge_port: int = 9333
@staticmethod
def config_path() -> Path:
base = Path.home() / ".oms-xhs-agent"
base.mkdir(parents=True, exist_ok=True)
return base / "settings.json"
@classmethod
def load(cls) -> AgentSettings:
path = cls.config_path()
if not path.is_file():
return cls()
try:
raw = json.loads(path.read_text(encoding="utf-8"))
if not isinstance(raw, dict):
return cls()
return cls(
oms_url=str(raw.get("oms_url") or cls().oms_url),
token=str(raw.get("token") or ""),
device_name=str(raw.get("device_name") or ""),
bridge_port=int(raw.get("bridge_port") or 9333),
)
except (json.JSONDecodeError, OSError, ValueError):
return cls()
def save(self) -> None:
path = self.config_path()
path.write_text(
json.dumps(asdict(self), ensure_ascii=False, indent=2),
encoding="utf-8",
)