28 lines
936 B
Python
28 lines
936 B
Python
"""投顾 Agent 草稿状态机基础规则。"""
|
|||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from common.common_const import (
|
||
|
|
DRAFT_STATUS_DISCARDED,
|
||
|
|
DRAFT_STATUS_DRAFT,
|
||
|
|
ERR_CODE_DRAFT_NOT_FOUND,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
class DraftStateError(Exception):
|
||
|
|
def __init__(self, code: int, message: str):
|
||
|
|
self.code = code
|
||
|
|
self.message = message
|
||
|
|
super().__init__(message)
|
||
|
|
|
||
|
|
|
||
|
|
def transition_draft_status(status: str, operation: str) -> str:
|
||
|
|
if status == DRAFT_STATUS_DRAFT and operation == "discard":
|
||
|
|
return DRAFT_STATUS_DISCARDED
|
||
|
|
if status == DRAFT_STATUS_DISCARDED:
|
||
|
|
raise DraftStateError(ERR_CODE_DRAFT_NOT_FOUND, "草稿不存在或者已废弃")
|
||
|
|
if status != DRAFT_STATUS_DRAFT:
|
||
|
|
raise DraftStateError(ERR_CODE_DRAFT_NOT_FOUND, "草稿状态无效")
|
||
|
|
if operation == "save":
|
||
|
|
return DRAFT_STATUS_DRAFT
|
||
|
|
raise DraftStateError(ERR_CODE_DRAFT_NOT_FOUND, "不支持的草稿操作")
|