# Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 """Task:管控节点(regulatory_node)完成的短任务记录。 与 workflow 不同,task 是上下文内能完成的轻量任务(写文件/查询/出报告等), 表里只存最终元数据 + 结果摘要 + 关联 artifact,不入库执行过程。 """ from sqlalchemy import String, DateTime, Text, func from sqlalchemy.orm import Mapped, mapped_column from sqlalchemy.dialects.postgresql import JSONB from .base import BaseDataModel class Task(BaseDataModel): __tablename__ = "task" task_id: Mapped[str] = mapped_column( String(64), primary_key=True, comment="任务唯一 ID(UUID)" ) user_id: Mapped[str] = mapped_column( String(64), index=True, comment="所属用户 ID" ) chat_id: Mapped[str | None] = mapped_column( String(64), index=True, nullable=True, comment="所属对话(如有)" ) command: Mapped[str] = mapped_column( Text, comment="用户原始指令" ) title: Mapped[str] = mapped_column( String(255), comment="任务简短标题(LLM 生成)" ) status: Mapped[str] = mapped_column( String(20), index=True, default="completed", comment="running / completed / failed", ) result_summary: Mapped[str | None] = mapped_column( Text, nullable=True, comment="完成后的结果摘要" ) artifact_refs: Mapped[list | None] = mapped_column( JSONB, nullable=True, comment="关联的 artifact url 列表" ) created_at: Mapped[str] = mapped_column( DateTime(timezone=True), server_default=func.now(), index=True ) updated_at: Mapped[str] = mapped_column( DateTime(timezone=True), server_default=func.now(), onupdate=func.now() )