2026-09-18 14:59:02 +08:00

63 lines
2.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""pbl_agent_runtime RBAC 路径注册清单。
铁律PATHS 必须与 wwwroot/ 下**实际存在的文件一一对应**QC 退回 #4
本文件由 scripts/check_contract_sync.py 机械核验:多一条(指向不存在文件)或少一条
(文件未注册)都会失败。
角色约定
--------
* ``any`` :登录前可访问(本模块无此类文件)
* ``user`` :普通登录用户(只读查询类)
* ``admin`` :租户管理员(写类 / 审批裁决 / 注册表变更)
"""
# (路径, 角色) —— 路径相对模块 wwwroot运行时前缀 /pbl_agent_runtime/
PATHS = [
# 模块入口页
("/pbl_agent_runtime/index.ui", "user"),
# 10 个契约端点(与 pbl_agent_runtime.m4a_contract.CONTRACT_FUNCTIONS 同源)
("/pbl_agent_runtime/api/pbl_agent_designer_run.dspy", "admin"),
("/pbl_agent_runtime/api/pbl_agent_critic_run.dspy", "user"),
("/pbl_agent_runtime/api/pbl_agent_trace_write.dspy", "user"),
("/pbl_agent_runtime/api/pbl_agent_trace_list.dspy", "user"),
("/pbl_agent_runtime/api/pbl_tool_registry_list.dspy", "user"),
("/pbl_agent_runtime/api/pbl_tool_registry_save.dspy", "admin"),
("/pbl_agent_runtime/api/pbl_tool_adjudicate.dspy", "user"),
("/pbl_agent_runtime/api/pbl_approval_create.dspy", "user"),
("/pbl_agent_runtime/api/pbl_approval_decide.dspy", "admin"),
("/pbl_agent_runtime/api/pbl_approval_list.dspy", "user"),
]
MODULE_NAME = "pbl_agent_runtime"
def paths():
"""返回 [(path, role), ...],供宿主应用 RBAC 批量注册。"""
return list(PATHS)
def register(env=None):
"""把 PATHS 注册到 ServerEnv 的 RBAC 表(平台可用时)。"""
target = env
if target is None:
try:
from ahserver import ServerEnv # noqa: WPS433
target = ServerEnv()
except Exception: # noqa: BLE001
return {"registered": 0, "offline": True, "paths": list(PATHS)}
count = 0
for path, role in PATHS:
setter = getattr(target, "add_path", None) or getattr(target, "register_path", None)
if callable(setter):
setter(path, role)
count += 1
return {"registered": count, "offline": count == 0, "paths": list(PATHS)}
if __name__ == "__main__":
for item_path, item_role in PATHS:
print("%-64s %s" % (item_path, item_role))
print("total: %d paths" % len(PATHS))