muse-agent-example/src/muse/共享/调用身份.py
zizi b86516505f W02 安装工程、启动骨架与验证环境:pyproject/uv 安装工程、启动装配骨架、conftest 用例身份与 OS 离线隔离。
按 R2 串行阶段整理提交;包内文件为该阶段交付(含后续小增量),状态以工作包清单为准。
2026-09-10 19:25:40 +08:00

61 lines
1.8 KiB
Python
Raw 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.

"""作者、任务、用途和授权上下文。
合同依据:接口契约/任务工具与事件.md。
- run_purpose(用途)表示执行隔离:production / evaluation / maintenance。
- content_purpose(内容用途)表示内容消费:planning / generation / detection / extraction。
- 两者不能混用:评测写手是 evaluation + generation,按 generation 裁剪字段、
受评测数据库权限约束。
"""
from __future__ import annotations
from dataclasses import dataclass
from enum import StrEnum
from muse.共享.标识 import 任务标识, 校验标识
class 用途(StrEnum):
"""执行隔离用途。"""
生产 = "production"
评测 = "evaluation"
维护 = "maintenance"
class 内容用途(StrEnum):
"""内容消费用途。"""
规划 = "planning"
生成 = "generation"
检测 = "detection"
抽取 = "extraction"
@dataclass(frozen=True, slots=True)
class 调用身份:
"""一次业务调用携带的稳定身份与用途。
模型工具没有作者确认身份;作者身份只随作者显式动作传入。
人工命令的任务引用可空,不虚构一个S02后台任务。
"""
作者: str | None
任务: 任务标识 | None
用途: 用途
内容用途: 内容用途
def __post_init__(self) -> None:
if self.作者 is not None:
校验标识(self.作者, 名称="作者")
if self.任务 is not None:
校验标识(self.任务, 名称="任务")
@property
def 允许写正式内容(self) -> bool:
"""只有生产用途且携带作者身份才可能写正式内容(仍需各模块授权检查)。"""
return self.用途 is 用途.生产 and self.作者 is not None
__all__ = ["用途", "内容用途", "调用身份"]