feat: 完善认证机制并实现 agent list

- 认证方式从 Cookie 改为 accesstoken+corpid+staffid Header(基于真实请求分析)
- agent list 基于真实 API 响应结构完善(data.items, state/mode 字段)
- 新增 CLAUDE.md:项目上下文、认证说明、已知 API 文档
- 补充 README.md:安装和使用说明
This commit is contained in:
gitea committed 2026-04-06 00:06:02 +08:00
1 parent b4a0698b13
commit 3c4ad6256a
6 files changed
+163 -31

No files matched your search

+12 -5
View File
@@ -1,4 +1,4 @@
"""HTTP 客户端:封装对快报 API 的请求,自动带上认证 cookie 和 corpId"""
"""HTTP 客户端:封装对快报 API 的请求,使用 accesstoken + corpid + staffid 认证"""
import httpx
from typing import Any
@@ -7,14 +7,17 @@ BASE_URL = "https://app.ekuaibao.com"
class EkbClient:
def __init__(self, corp_id: str, cookie: str):
def __init__(self, corp_id: str, access_token: str, staff_id: str):
self.corp_id = corp_id
self._client = httpx.Client(
base_url=BASE_URL,
headers={
"Cookie": cookie,
"accesstoken": access_token,
"corpid": corp_id,
"staffid": staff_id,
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
"Accept": "application/json, text/plain, */*",
"Accept": "application/json",
"Content-Type": "application/json",
"Accept-Language": "zh-CN,zh;q=0.9",
},
timeout=30,
@@ -46,4 +49,8 @@ def get_client() -> EkbClient:
if not corp:
raise RuntimeError("未登录,请先执行 `ekb auth add` 添加企业认证")
corp_id = config.get_current_corp_id()
return EkbClient(corp_id=corp_id, cookie=corp["cookie"])
return EkbClient(
corp_id=corp_id,
access_token=corp["access_token"],
staff_id=corp["staff_id"],
)
+13 -5
View File
@@ -1,4 +1,4 @@
"""agent 命令:智能审核 Agent 管理(骨架,待根据 API 响应完善)"""
"""agent 命令:智能审核 Agent 管理"""
import typer
from rich.console import Console
@@ -10,27 +10,35 @@ from ekb_cli.api import get_client
app = typer.Typer(help="智能审核 Agent 管理")
console = Console()
STATE_MAP = {0: "[green]启用[/green]", 1: "[red]禁用[/red]"}
@app.command("list")
def agent_list():
"""列出所有智能审核 Agent"""
with get_client() as client:
data = client.get("/engine/hab/agent/list", page=1, size=1000)
resp = client.get("/engine/hab/agent/list", page=1, size=1000)
items = data.get("items") or data.get("data") or []
items = resp.get("data", {}).get("items") or []
if not items:
rprint("[yellow]暂无 Agent[/yellow]")
raise typer.Exit()
table = Table(title="智能审核 Agent 列表")
table.add_column("ID")
table.add_column("ID", style="dim")
table.add_column("名称")
table.add_column("模式")
table.add_column("状态")
table.add_column("更新时间")
for item in items:
state_text = STATE_MAP.get(item.get("state"), str(item.get("state", "")))
mode = "自动" if item.get("mode") == 2 else str(item.get("mode", ""))
table.add_row(
str(item.get("id", "")),
item.get("name", ""),
item.get("status", ""),
mode,
state_text,
item.get("updateTime", ""),
)
console.print(table)
+10 -19
View File
@@ -1,6 +1,5 @@
"""auth 命令:管理企业认证信息"""
import re
import typer
from rich.console import Console
from rich.table import Table
@@ -12,32 +11,24 @@ app = typer.Typer(help="管理企业认证")
console = Console()
def _parse_corp_id(cookie: str) -> str:
"""从 cookie 中尝试提取 corpId"""
match = re.search(r"corpId=([^;& ]+)", cookie)
return match.group(1) if match else ""
@app.command("add")
def auth_add():
"""添加企业认证(从浏览器 F12 复制请求的 Cookie 头)"""
"""添加企业认证(从浏览器 F12 复制请求头中的 accesstoken / corpid / staffid)"""
console.print("\n[bold]添加企业认证[/bold]")
console.print("步骤:打开快报 → F12 → 任意请求 → 复制 [cyan]Cookie[/cyan] 请求头的值\n")
console.print("步骤:打开快报 → F12 → 任意 API 请求 → 请求头中找到以下三个字段\n")
cookie = typer.prompt("粘贴 Cookie 值").strip()
if not cookie:
rprint("[red]Cookie 不能为空[/red]")
raise typer.Exit(1)
access_token = typer.prompt("accesstoken").strip()
corp_id = typer.prompt("corpid").strip()
staff_id = typer.prompt("staffid").strip()
detected = _parse_corp_id(cookie)
corp_id = typer.prompt("企业 corpId", default=detected).strip()
if not corp_id:
rprint("[red]corpId 不能为空[/red]")
raise typer.Exit(1)
for label, val in [("accesstoken", access_token), ("corpid", corp_id), ("staffid", staff_id)]:
if not val:
rprint(f"[red]{label} 不能为空[/red]")
raise typer.Exit(1)
name = typer.prompt("企业名称(方便识别)", default=corp_id).strip()
config.add_corp(corp_id=corp_id, name=name, cookie=cookie)
config.add_corp(corp_id=corp_id, name=name, access_token=access_token, staff_id=staff_id)
rprint(f"[green]✓[/green] 已添加企业 [bold]{name}[/bold] ({corp_id})")
+2 -2
View File
@@ -35,9 +35,9 @@ def get_current_corp() -> Optional[dict]:
return data["corps"].get(corp_id)
def add_corp(corp_id: str, name: str, cookie: str) -> None:
def add_corp(corp_id: str, name: str, access_token: str, staff_id: str) -> None:
data = _load()
data["corps"][corp_id] = {"name": name, "cookie": cookie}
data["corps"][corp_id] = {"name": name, "access_token": access_token, "staff_id": staff_id}
if not data.get("current"):
data["current"] = corp_id
_save(data)