2026-05-12 05:13:49 +00:00
|
|
|
|
"""
|
|
|
|
|
|
MACP 数据模型定义模块。
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
定义了平台所有核心数据实体的 Pydantic 模型,涵盖文档模板、文档、
|
|
|
|
|
|
GJB规则、验证报告、Skill、记忆条目、知识库片段、模型配置、多模态处理结果等。
|
2026-05-12 05:03:18 +00:00
|
|
|
|
"""
|
|
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
2026-05-12 05:03:18 +00:00
|
|
|
|
from datetime import datetime
|
2026-05-12 05:13:49 +00:00
|
|
|
|
from enum import Enum
|
|
|
|
|
|
from typing import Any, Optional
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
from pydantic import BaseModel, Field
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
# =============================================================================
|
|
|
|
|
|
# 枚举类型
|
|
|
|
|
|
# =============================================================================
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
class TemplateType(str, Enum):
|
|
|
|
|
|
"""模板类型枚举"""
|
|
|
|
|
|
SRS = "需求规格说明书"
|
|
|
|
|
|
SDD = "软件设计说明书"
|
|
|
|
|
|
STP = "软件测试计划"
|
|
|
|
|
|
STR = "软件测试报告"
|
|
|
|
|
|
SUM = "软件用户手册"
|
|
|
|
|
|
OTHER = "其他"
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
class GjbStandard(str, Enum):
|
|
|
|
|
|
"""GJB标准枚举"""
|
|
|
|
|
|
GJB438C = "GJB438C"
|
|
|
|
|
|
GJB437B = "GJB437B"
|
|
|
|
|
|
GJB2786A = "GJB2786A"
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
class DocumentStatus(str, Enum):
|
|
|
|
|
|
"""文档状态枚举"""
|
|
|
|
|
|
DRAFT = "草稿"
|
|
|
|
|
|
SUBMITTED = "已提交"
|
|
|
|
|
|
REVIEWED = "已审核"
|
|
|
|
|
|
APPROVED = "已批准"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MemoryType(str, Enum):
|
|
|
|
|
|
"""记忆类型枚举"""
|
|
|
|
|
|
SHORT_TERM = "短期"
|
|
|
|
|
|
LONG_TERM = "长期"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KnowledgeLevel(str, Enum):
|
|
|
|
|
|
"""知识库层级枚举"""
|
|
|
|
|
|
DOCUMENT = "文档"
|
|
|
|
|
|
CHAPTER = "章节"
|
|
|
|
|
|
PARAGRAPH = "段落"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ModelStatus(str, Enum):
|
|
|
|
|
|
"""模型调用状态枚举"""
|
|
|
|
|
|
ACTIVE = "主用"
|
|
|
|
|
|
FAILOVER = "故障转移中"
|
|
|
|
|
|
UNAVAILABLE = "不可用"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SystemStatus(str, Enum):
|
|
|
|
|
|
"""系统运行状态枚举"""
|
|
|
|
|
|
NORMAL = "正常运行状态"
|
|
|
|
|
|
MAINTENANCE = "维护状态"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EditMode(str, Enum):
|
|
|
|
|
|
"""文档编辑模式枚举"""
|
|
|
|
|
|
MANUAL = "人工编辑"
|
|
|
|
|
|
AGENT = "Agent对话编辑"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FileType(str, Enum):
|
|
|
|
|
|
"""文件类型枚举"""
|
|
|
|
|
|
IMAGE = "图片"
|
|
|
|
|
|
AUDIO = "音频"
|
|
|
|
|
|
VIDEO = "视频"
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
# =============================================================================
|
|
|
|
|
|
# 核心数据实体
|
|
|
|
|
|
# =============================================================================
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
class Template(BaseModel):
|
|
|
|
|
|
"""文档模板实体
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
包含模板ID、名称、类型、所属GJB标准、版本号、内容结构、创建时间、作者。
|
2026-05-12 05:03:18 +00:00
|
|
|
|
"""
|
2026-05-12 05:13:49 +00:00
|
|
|
|
id: str = Field(..., description="模板ID")
|
|
|
|
|
|
name: str = Field(..., description="模板名称")
|
|
|
|
|
|
template_type: TemplateType = Field(..., description="模板类型")
|
|
|
|
|
|
gjb_standard: GjbStandard = Field(..., description="所属GJB标准")
|
|
|
|
|
|
version: str = Field("1.0", description="版本号")
|
|
|
|
|
|
content_structure: dict[str, Any] = Field(default_factory=dict, description="内容结构")
|
|
|
|
|
|
created_at: datetime = Field(default_factory=datetime.now, description="创建时间")
|
|
|
|
|
|
author: str = Field("admin", description="作者")
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
class Document(BaseModel):
|
|
|
|
|
|
"""文档实体
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
包含文档ID、标题、关联模板ID、当前版本、编辑历史、状态、权限信息。
|
|
|
|
|
|
"""
|
|
|
|
|
|
id: str = Field(..., description="文档ID")
|
|
|
|
|
|
title: str = Field(..., description="文档标题")
|
|
|
|
|
|
template_id: str = Field(..., description="关联模板ID")
|
|
|
|
|
|
current_version: str = Field("1.0", description="当前版本")
|
|
|
|
|
|
content: str = Field("", description="文档内容")
|
|
|
|
|
|
edit_history: list[dict[str, Any]] = Field(default_factory=list, description="编辑历史")
|
|
|
|
|
|
status: DocumentStatus = Field(DocumentStatus.DRAFT, description="文档状态")
|
|
|
|
|
|
permissions: dict[str, list[str]] = Field(default_factory=dict, description="权限信息")
|
|
|
|
|
|
created_at: datetime = Field(default_factory=datetime.now, description="创建时间")
|
|
|
|
|
|
updated_at: datetime = Field(default_factory=datetime.now, description="更新时间")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GjbRule(BaseModel):
|
|
|
|
|
|
"""GJB规则实体
|
|
|
|
|
|
|
|
|
|
|
|
包含规则ID、对应章节、要求描述、是否必选、适用文档类型、修正建议。
|
|
|
|
|
|
"""
|
|
|
|
|
|
id: str = Field(..., description="规则ID")
|
|
|
|
|
|
section: str = Field(..., description="对应章节")
|
|
|
|
|
|
requirement: str = Field(..., description="要求描述")
|
|
|
|
|
|
mandatory: bool = Field(True, description="是否必选")
|
|
|
|
|
|
applicable_types: list[TemplateType] = Field(..., description="适用文档类型")
|
|
|
|
|
|
suggestion: str = Field("", description="修正建议")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ValidationReport(BaseModel):
|
|
|
|
|
|
"""验证报告实体
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
包含报告ID、文档ID、验证时间、合规项数量、不合规项列表。
|
2026-05-12 05:03:18 +00:00
|
|
|
|
"""
|
2026-05-12 05:13:49 +00:00
|
|
|
|
id: str = Field(..., description="报告ID")
|
|
|
|
|
|
document_id: str = Field(..., description="文档ID")
|
|
|
|
|
|
validated_at: datetime = Field(default_factory=datetime.now, description="验证时间")
|
|
|
|
|
|
total_rules: int = Field(0, description="总规则数")
|
|
|
|
|
|
compliant_count: int = Field(0, description="合规项数量")
|
|
|
|
|
|
non_compliant_items: list[dict[str, Any]] = Field(default_factory=list, description="不合规项列表")
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
class Skill(BaseModel):
|
|
|
|
|
|
"""Skill实体
|
|
|
|
|
|
|
|
|
|
|
|
包含Skill ID、名称、Prompt模板、关联工具列表、输入输出定义、编排顺序。
|
|
|
|
|
|
"""
|
|
|
|
|
|
id: str = Field(..., description="Skill ID")
|
|
|
|
|
|
name: str = Field(..., description="名称")
|
|
|
|
|
|
prompt_template: str = Field("", description="Prompt模板")
|
|
|
|
|
|
associated_tools: list[str] = Field(default_factory=list, description="关联工具列表")
|
|
|
|
|
|
input_definition: dict[str, Any] = Field(default_factory=dict, description="输入定义")
|
|
|
|
|
|
output_definition: dict[str, Any] = Field(default_factory=dict, description="输出定义")
|
|
|
|
|
|
orchestration_order: int = Field(0, description="编排顺序")
|
|
|
|
|
|
created_at: datetime = Field(default_factory=datetime.now, description="创建时间")
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
class MemoryEntry(BaseModel):
|
|
|
|
|
|
"""记忆条目实体
|
|
|
|
|
|
|
|
|
|
|
|
包含记忆ID、会话ID、内容摘要、原始对话、嵌入向量、时间戳、有效期。
|
2026-05-12 05:03:18 +00:00
|
|
|
|
"""
|
2026-05-12 05:13:49 +00:00
|
|
|
|
id: str = Field(..., description="记忆ID")
|
|
|
|
|
|
session_id: str = Field(..., description="会话ID")
|
|
|
|
|
|
summary: str = Field(..., description="内容摘要")
|
|
|
|
|
|
original_dialogue: str = Field(..., description="原始对话")
|
|
|
|
|
|
memory_type: MemoryType = Field(MemoryType.SHORT_TERM, description="记忆类型")
|
|
|
|
|
|
created_at: datetime = Field(default_factory=datetime.now, description="时间戳")
|
|
|
|
|
|
expiry_at: Optional[datetime] = Field(None, description="有效期")
|
|
|
|
|
|
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
class KnowledgeChunk(BaseModel):
|
|
|
|
|
|
"""知识库片段实体
|
|
|
|
|
|
|
|
|
|
|
|
包含片段ID、来源文档、层级、内容文本、元数据标签、向量表示。
|
|
|
|
|
|
"""
|
|
|
|
|
|
id: str = Field(..., description="片段ID")
|
|
|
|
|
|
source_document: str = Field(..., description="来源文档")
|
|
|
|
|
|
level: KnowledgeLevel = Field(..., description="层级")
|
|
|
|
|
|
content: str = Field(..., description="内容文本")
|
|
|
|
|
|
metadata_tags: list[str] = Field(default_factory=list, description="元数据标签")
|
|
|
|
|
|
embedding: list[float] = Field(default_factory=list, description="向量表示")
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
class ModelProfile(BaseModel):
|
|
|
|
|
|
"""模型配置实体
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
包含模型ID、厂商、API地址、认证密钥、健康状态、权重、是否为主用。
|
2026-05-12 05:03:18 +00:00
|
|
|
|
"""
|
2026-05-12 05:13:49 +00:00
|
|
|
|
id: str = Field(..., description="模型ID")
|
|
|
|
|
|
vendor: str = Field(..., description="厂商")
|
|
|
|
|
|
api_url: str = Field(..., description="API地址")
|
|
|
|
|
|
api_key: str = Field("******", description="认证密钥")
|
|
|
|
|
|
health_status: ModelStatus = Field(ModelStatus.ACTIVE, description="健康状态")
|
|
|
|
|
|
weight: int = Field(1, description="权重")
|
|
|
|
|
|
is_primary: bool = Field(False, description="是否为主用")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MultimodalResult(BaseModel):
|
|
|
|
|
|
"""多模态处理结果实体
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
包含源文件ID、文件类型、OCR文本、ASR转录、关键帧图像列表、提取时间。
|
|
|
|
|
|
"""
|
|
|
|
|
|
id: str = Field(..., description="源文件ID")
|
|
|
|
|
|
file_type: FileType = Field(..., description="文件类型")
|
|
|
|
|
|
file_name: str = Field(..., description="文件名")
|
|
|
|
|
|
ocr_text: Optional[str] = Field(None, description="OCR文本")
|
|
|
|
|
|
asr_transcript: Optional[str] = Field(None, description="ASR转录")
|
|
|
|
|
|
key_frames: list[str] = Field(default_factory=list, description="关键帧图像列表")
|
|
|
|
|
|
extracted_at: datetime = Field(default_factory=datetime.now, description="提取时间")
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
class McpTool(BaseModel):
|
|
|
|
|
|
"""MCP工具实体
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
包含工具ID、名称、JSON Schema定义、描述、状态。
|
2026-05-12 05:03:18 +00:00
|
|
|
|
"""
|
2026-05-12 05:13:49 +00:00
|
|
|
|
id: str = Field(..., description="工具ID")
|
|
|
|
|
|
name: str = Field(..., description="工具名称")
|
|
|
|
|
|
description: str = Field("", description="工具描述")
|
|
|
|
|
|
json_schema: dict[str, Any] = Field(default_factory=dict, description="JSON Schema定义")
|
|
|
|
|
|
enabled: bool = Field(True, description="是否启用")
|
|
|
|
|
|
created_at: datetime = Field(default_factory=datetime.now, description="创建时间")
|
|
|
|
|
|
|
2026-05-12 05:03:18 +00:00
|
|
|
|
|
2026-05-12 05:13:49 +00:00
|
|
|
|
class Workflow(BaseModel):
|
|
|
|
|
|
"""工作流实体
|
|
|
|
|
|
|
|
|
|
|
|
用于Skills流程编排,支持条件分支与循环逻辑。
|
|
|
|
|
|
"""
|
|
|
|
|
|
id: str = Field(..., description="工作流ID")
|
|
|
|
|
|
name: str = Field(..., description="工作流名称")
|
|
|
|
|
|
skill_ids: list[str] = Field(default_factory=list, description="关联Skill ID列表")
|
|
|
|
|
|
logic: dict[str, Any] = Field(default_factory=dict, description="流程逻辑定义")
|
|
|
|
|
|
created_at: datetime = Field(default_factory=datetime.now, description="创建时间")
|