31 lines
890 B
Python
31 lines
890 B
Python
"""临时脚本:直接用 api 层,验证它能不能当 SDK 用。
|
|
|
|
任务:列出所有 Agent → 逐个拉详情拿关联规则 → 去重 → 返回结构化数据。
|
|
"""
|
|
|
|
import json
|
|
from ekb_cli.api import get_client, list_agents, get_agent
|
|
|
|
|
|
def get_all_linked_rules() -> list[dict]:
|
|
"""拿到所有 Agent 关联的规则,去重,返回字典列表。"""
|
|
with get_client() as client:
|
|
agents = list_agents(client).items
|
|
|
|
seen: set[str] = set()
|
|
rules: list[dict] = []
|
|
|
|
for a in agents:
|
|
detail = get_agent(client, a.id)
|
|
for r in detail.agentRule:
|
|
if r.id not in seen:
|
|
seen.add(r.id)
|
|
rules.append(r.model_dump())
|
|
|
|
return rules
|
|
|
|
|
|
if __name__ == "__main__":
|
|
result = get_all_linked_rules()
|
|
print(json.dumps(result, indent=2, ensure_ascii=False))
|