M5:百工与司命——能力注册表、授契行契请命、禁域裁决与观察标证
- 百工域 domains/baigong:capabilities(统一能力契约:执行类型 builtin/qiankun/mcp/http + 四维风险标注 + 来源版本)、mandates(授契 grant / 行契 charter 预算时间窗,撤销立即生效)、tool_calls(净化摘要 + 观察标证);请命复用 pending_confirmations 加 expires_at/brief_json(超时=拒绝执行 HJ-1302,六要素说明) - 司命裁决器 siming.py:四维取最高档(能力/数据/后果/情境);禁域为代码常量不可配置(递归删根/格式化/写裸设备/fork 炸弹、file:// 协议、密钥材料外发)——专项测试断言恶意标注与篡改对象仍拒 HJ-1301 - 执行链:禁域→裁决(HJ-1303 未授契拒且双留痕)→请命→执行(乾坤经 SandboxClient HMAC;MCP 经 call_tool;内置无副作用)→净化标证(观察非事实,敏感遮蔽+体量截断)→行动账 - MCP 登记/启停/刷新自动派生与撤下 capabilities(博闻登记接入点);内置能力种子(echo/datetime/qiankun.shell/web.fetch) - 端点:/capabilities /mandates /petitions /tool-calls + /tools 兼容投影;前端百工页四区(能力目录四维标注/授契行契/请命批准拒绝/行动账观察标证) - 退役:modules/safety|skills|tool_runtime|agent、application/tool_runtime、services/skills|safety、tool_policies/skills/model_endpoint_overrides 表(迁移 006)、前端 SkillManager/ToolsConsole/旧 tools 页 - 验收(test_baigong_siming 四用例):未授契被拒留痕、请命超时不执行、禁域不可关闭、结果为观察不入忆;后端 454、前端 220、BFF 4、神识 5 包全绿(2 个预存环境失败不变)
This commit is contained in:
1 parent
144415247e
commit
684261f4b4
97 files changed
+3075
-5554
No files matched your search
@@ -1,73 +1,8 @@
|
||||
"""安全 / 工具策略 API schema(api-spec §15 / §16)。
|
||||
|
||||
`tool_policies` 表同时服务两组 API:
|
||||
- `/tools`(§15):返回 `ToolPolicyResponse`(完整元数据 + executable 派生位)。
|
||||
- `/safety/policies`(§16):返回 `SafetyPolicyItem`(策略子集)。
|
||||
"""
|
||||
"""安全 API schema:一炁 tool.* 事件详情(策略面已由百工域 capabilities 承接)。"""
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class ToolPolicyResponse(BaseModel):
|
||||
"""工具策略完整元数据(GET /tools 元素、POST/PATCH /tools 响应)。"""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
name: str = Field(description="工具名(主键)。")
|
||||
description: str = Field(default="", description="工具描述。")
|
||||
risk_level: str = Field(description="风险等级 L0–L4。")
|
||||
permission_policy: str = Field(description="权限策略 allow/ask/always_ask/forbidden。")
|
||||
side_effect: bool = Field(description="是否有副作用。")
|
||||
audit_required: bool = Field(description="是否强制记审计。")
|
||||
source: str = Field(description="来源:builtin / custom。")
|
||||
enabled: bool = Field(description="是否启用(禁用的工具不进入司命策略)。")
|
||||
executable: bool = Field(
|
||||
default=False,
|
||||
description="是否具备执行实现(builtin 或已注册 ToolSpec);纯治理声明为 false。",
|
||||
)
|
||||
created_at: str = Field(description="创建时间,UTC ISO 8601。")
|
||||
updated_at: str = Field(description="更新时间,UTC ISO 8601。")
|
||||
|
||||
|
||||
class SafetyPolicyItem(BaseModel):
|
||||
"""策略子集(GET /safety/policies 元素)。"""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
tool: str = Field(description="工具名。")
|
||||
risk_level: str = Field(description="风险等级 L0–L4。")
|
||||
permission_policy: str = Field(description="权限策略。")
|
||||
side_effect: bool = Field(description="是否有副作用。")
|
||||
audit_required: bool = Field(description="是否强制记审计。")
|
||||
|
||||
|
||||
class CreateToolPolicyRequest(BaseModel):
|
||||
"""注册工具 / 新增策略请求(POST /tools、POST /safety/policies 共用)。"""
|
||||
|
||||
name: str = Field(description="工具名(唯一)。")
|
||||
description: str = Field(default="", description="工具描述。")
|
||||
risk_level: str = Field(default="L2", description="风险等级 L0–L4。")
|
||||
permission_policy: str = Field(default="ask", description="权限策略。")
|
||||
side_effect: bool = Field(default=True, description="是否有副作用。")
|
||||
audit_required: bool = Field(default=True, description="是否强制记审计。")
|
||||
enabled: bool = Field(default=True, description="是否启用。")
|
||||
|
||||
|
||||
class UpdateToolPolicyRequest(BaseModel):
|
||||
"""编辑工具 / 策略请求(PATCH /tools/{name}、PATCH /safety/policies/{tool} 共用)。
|
||||
|
||||
所有字段可选;spec §15 要求 risk_level、§16 要求 permission_policy / risk_level,
|
||||
此处统一放开为完整元数据编辑(至少传一个)。
|
||||
"""
|
||||
|
||||
description: str | None = None
|
||||
risk_level: str | None = None
|
||||
permission_policy: str | None = None
|
||||
side_effect: bool | None = None
|
||||
audit_required: bool | None = None
|
||||
enabled: bool | None = None
|
||||
|
||||
|
||||
class ToolCallDetail(BaseModel):
|
||||
"""单次工具调用事件详情(GET /tools/calls/{tool_call_id})。
|
||||
|
||||
@@ -77,7 +12,7 @@ class ToolCallDetail(BaseModel):
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
event_id: str = Field(description="事件 ID(即路径 tool_call_id)。")
|
||||
event_id: str = Field(description="事件 ID(即路径 tool_call_id}。")
|
||||
type: str = Field(description="事件类型:tool.started / tool.completed / tool.failed 等。")
|
||||
tool: str | None = Field(default=None, description="工具名(payload 解出)。")
|
||||
run_id: str | None = Field(default=None)
|
||||
|
||||
Reference in new issue
Block a user