Spaces:
Running
Running
| from __future__ import annotations | |
| from datetime import datetime | |
| from uuid import uuid4 | |
| from sqlalchemy import ( | |
| JSON, | |
| CheckConstraint, | |
| DateTime, | |
| ForeignKey, | |
| Index, | |
| String, | |
| Text, | |
| UniqueConstraint, | |
| ) | |
| from sqlalchemy.orm import Mapped, mapped_column | |
| from app.security.models import Base, utcnow | |
| class CopilotRunRecord(Base): | |
| __tablename__ = "copilot_runs" | |
| __table_args__ = ( | |
| UniqueConstraint( | |
| "workspace_id", "idempotency_key", name="uq_copilot_run_workspace_idempotency" | |
| ), | |
| CheckConstraint( | |
| "status in ('plan_ready','blocked','executing','completed','partial','failed','cancelled')", | |
| name="ck_copilot_run_status", | |
| ), | |
| Index("ix_copilot_runs_workspace_created", "workspace_id", "created_at"), | |
| Index("ix_copilot_runs_workspace_status", "workspace_id", "status"), | |
| Index("ix_copilot_runs_project_created", "project_id", "created_at"), | |
| ) | |
| id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid4())) | |
| workspace_id: Mapped[str] = mapped_column( | |
| String(36), ForeignKey("workspaces.id", ondelete="RESTRICT"), nullable=False | |
| ) | |
| user_id: Mapped[str] = mapped_column( | |
| String(36), ForeignKey("users.id", ondelete="RESTRICT"), nullable=False | |
| ) | |
| project_id: Mapped[str | None] = mapped_column( | |
| String(36), ForeignKey("projects.id", ondelete="RESTRICT") | |
| ) | |
| idempotency_key: Mapped[str] = mapped_column(String(255), nullable=False) | |
| request_fingerprint: Mapped[str] = mapped_column(String(64), nullable=False) | |
| request_text: Mapped[str] = mapped_column(Text, nullable=False) | |
| context_json: Mapped[dict[str, object]] = mapped_column("context", JSON, nullable=False) | |
| plan_json: Mapped[dict[str, object]] = mapped_column("plan", JSON, nullable=False) | |
| status: Mapped[str] = mapped_column(String(32), nullable=False) | |
| current_action_id: Mapped[str | None] = mapped_column(String(64)) | |
| results_json: Mapped[list[dict[str, object]]] = mapped_column( | |
| "results", JSON, nullable=False, default=list | |
| ) | |
| summary: Mapped[str | None] = mapped_column(Text) | |
| error_code: Mapped[str | None] = mapped_column(String(100)) | |
| error_message: Mapped[str | None] = mapped_column(Text) | |
| confirmed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True)) | |
| created_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), nullable=False, default=utcnow | |
| ) | |
| updated_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), nullable=False, default=utcnow, onupdate=utcnow | |
| ) | |
| completed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True)) | |