临时调试脚本:try_api.py(SDK 用法验证)和 raw_check.py(原始 JSON 诊断)
保留这两个脚本供后续逆向参考,不纳入主代码。
This commit is contained in:
1 parent
9ec009f2cb
commit
2dd098c984
2 files changed
+38
No files matched your search
@@ -0,0 +1,30 @@
|
||||
"""临时脚本:直接用 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))
|
||||
Reference in new issue
Block a user