From 2dd098c98439f0939e4417294ff9152e9415398a Mon Sep 17 00:00:00 2001 From: yunyingk Date: Tue, 14 Apr 2026 16:10:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E8=B0=83=E8=AF=95=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=EF=BC=9Atry=5Fapi.py=EF=BC=88SDK=20=E7=94=A8=E6=B3=95?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=EF=BC=89=E5=92=8C=20raw=5Fcheck.py=EF=BC=88?= =?UTF-8?q?=E5=8E=9F=E5=A7=8B=20JSON=20=E8=AF=8A=E6=96=AD=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 保留这两个脚本供后续逆向参考,不纳入主代码。 --- tmp_test/raw_check.py | 8 ++++++++ tmp_test/try_api.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tmp_test/raw_check.py create mode 100644 tmp_test/try_api.py diff --git a/tmp_test/raw_check.py b/tmp_test/raw_check.py new file mode 100644 index 0000000..404e995 --- /dev/null +++ b/tmp_test/raw_check.py @@ -0,0 +1,8 @@ +"""诊断脚本:直接看 API 返回的原始 JSON""" + +from ekb_cli.api import get_client + +with get_client() as client: + raw = client.get("/engine/hab/agent/list", page=1, size=5) + import json + print(json.dumps(raw, indent=2, ensure_ascii=False)) diff --git a/tmp_test/try_api.py b/tmp_test/try_api.py new file mode 100644 index 0000000..2bd4453 --- /dev/null +++ b/tmp_test/try_api.py @@ -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))