feat: Agent 工作区初始提交(源码+文档+Skills)
包含 CodeAgent 前后端源码、SKILLS、MCP、demo 代码与工作区文档。 排除依赖缓存、运行数据、备份与二进制附件,规则见 .gitignore。 Co-Authored-By: Claude Code <[email protected]>
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
"""
|
||||
Pydantic 数据模型
|
||||
==================
|
||||
|
||||
【功能说明】
|
||||
定义项目(Project)与通用响应的数据契约。
|
||||
支持多后端多前端(一个项目下可维护多个服务)。
|
||||
【技术选型理由】
|
||||
Pydantic v2 + JSON 字段存储多条目(SQLite 轻量场景够用)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Generic, Optional, TypeVar
|
||||
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class ServiceEntry(BaseModel):
|
||||
"""后端/前端服务条目"""
|
||||
|
||||
label: str = Field(..., min_length=1, max_length=50, description="服务名称")
|
||||
path: str = Field(..., min_length=1, description="代码路径")
|
||||
branch: str = Field(default="master", description="Git 分支名")
|
||||
|
||||
|
||||
class ProjectCreate(BaseModel):
|
||||
"""创建项目的入参模型"""
|
||||
|
||||
name: str = Field(..., min_length=1, max_length=100, description="项目名称")
|
||||
code_root_path: str = Field(..., min_length=1, description="项目本地代码根路径")
|
||||
backend_path: str = Field(default="backend", description="后端子路径(兼容旧版)")
|
||||
frontend_path: str = Field(default="frontend", description="前端子路径(兼容旧版)")
|
||||
backend_branch: str = Field(default="master", description="后端 Git 分支(兼容旧版)")
|
||||
frontend_branch: str = Field(default="master", description="前端 Git 分支(兼容旧版)")
|
||||
backends: list[ServiceEntry] = Field(
|
||||
default_factory=list, description="多个后端服务列表"
|
||||
)
|
||||
frontends: list[ServiceEntry] = Field(
|
||||
default_factory=list, description="多个前端服务列表"
|
||||
)
|
||||
description: str = Field(default="", max_length=500, description="项目备注")
|
||||
sort_order: int = Field(default=0, description="排序值")
|
||||
|
||||
@field_validator("code_root_path")
|
||||
@classmethod
|
||||
def _must_be_d_drive(cls, v: str) -> str:
|
||||
normalized = v.strip().replace("/", "\\")
|
||||
if not normalized.upper().startswith("D:"):
|
||||
raise ValueError(f"代码路径必须位于 D 盘(硬约束 6),当前值:{v}")
|
||||
return normalized
|
||||
|
||||
|
||||
class ProjectUpdate(BaseModel):
|
||||
"""更新项目的入参模型(全部字段可选,按需覆盖)"""
|
||||
|
||||
name: Optional[str] = Field(default=None, min_length=1, max_length=100)
|
||||
code_root_path: Optional[str] = None
|
||||
backend_path: Optional[str] = None
|
||||
frontend_path: Optional[str] = None
|
||||
backend_branch: Optional[str] = None
|
||||
frontend_branch: Optional[str] = None
|
||||
backends: Optional[list[ServiceEntry]] = None
|
||||
frontends: Optional[list[ServiceEntry]] = None
|
||||
description: Optional[str] = None
|
||||
sort_order: Optional[int] = Field(default=None, description="排序值")
|
||||
|
||||
@field_validator("code_root_path")
|
||||
@classmethod
|
||||
def _must_be_d_drive(cls, v: Optional[str]) -> Optional[str]:
|
||||
if v is None:
|
||||
return v
|
||||
normalized = v.strip().replace("/", "\\")
|
||||
if not normalized.upper().startswith("D:"):
|
||||
raise ValueError(f"代码路径必须位于 D 盘(硬约束 6),当前值:{v}")
|
||||
return normalized
|
||||
|
||||
|
||||
class Project(ProjectCreate):
|
||||
"""项目完整实体:在入参字段基础上补充系统字段"""
|
||||
|
||||
id: str = Field(..., description="项目唯一 ID")
|
||||
created_at: datetime = Field(..., description="创建时间")
|
||||
updated_at: datetime = Field(..., description="最近更新时间")
|
||||
|
||||
|
||||
class ApiResponse(BaseModel, Generic[T]):
|
||||
"""统一 API 响应包裹,前端只依赖这一种结构"""
|
||||
|
||||
code: int = Field(default=0, description="业务状态码:0 成功,非 0 失败")
|
||||
message: str = Field(default="ok", description="人类可读的提示信息(中文)")
|
||||
data: Optional[T] = Field(default=None, description="业务数据载荷")
|
||||
|
||||
|
||||
class PageResult(BaseModel, Generic[T]):
|
||||
"""分页结果(预留:项目列表一期数据量小,先做全量列表)"""
|
||||
|
||||
total: int = Field(default=0, description="总条数")
|
||||
items: list[T] = Field(default_factory=list, description="当前页数据")
|
||||
|
||||
|
||||
class ErrorDetail(BaseModel):
|
||||
"""错误详情(用于前端精确展示失败原因)"""
|
||||
|
||||
error_type: str = Field(description="异常类型")
|
||||
error_msg: str = Field(description="异常信息(中文可读)")
|
||||
context: dict[str, Any] = Field(default_factory=dict, description="补充上下文")
|
||||
Reference in New Issue
Block a user