Warnings fixed: - datetime.utcnow() → datetime.now(UTC) across 48+ files (src/ + tests/) - datetime.utcnow (callback ref) → lambda: datetime.now(UTC) in model fields (18 files) - Pydantic class Config → model_config = ConfigDict(...) (16 files) - Pydantic .dict() → .model_dump() (8 files) - ConfigDict(allow_population_by_field_name=True) → validate_by_name=True - SQLAlchemy declarative_base() import path updated - FastAPI on_event → lifespan context manager (app.py) - Import sorting (ruff I001) auto-fixed across all files - Fixed broken re-export chains that ruff F401 cleanup broke: _validate_bcp47: service.py now imports from dictionary_validation directly job_to_response: _job_routes.py and test imports from service_utils directly fetch_datasource_metadata: restored re-export in service.py - Added missing TranslateJobService import in _job_routes.py (was deleted by F401) - Added ConfigDict(protected_namespaces=()) for DashboardDatasetItem schema field - pytest.ini: replaced deprecated importmode with asyncio_mode All 440 tests pass with zero deprecation warnings.
81 lines
3.2 KiB
Python
81 lines
3.2 KiB
Python
# #region AssistantModels [C:3] [TYPE Module] [SEMANTICS sqlalchemy, assistant, model, schema, audit, assistant-audit-record]
|
|
# @BRIEF SQLAlchemy models for assistant audit trail and confirmation tokens.
|
|
# @LAYER Domain
|
|
# @RELATION DEPENDS_ON -> MappingModels
|
|
# @INVARIANT Assistant records preserve immutable ids and creation timestamps.
|
|
# @SIDE_EFFECT Defines assistant audit/message/confirmation tables
|
|
# @DATA_CONTRACT AssistantData -> AssistantRecord
|
|
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy import JSON, Column, DateTime, String, Text
|
|
|
|
from .mapping import Base
|
|
|
|
|
|
# #region AssistantAuditRecord [C:3] [TYPE Class]
|
|
# @BRIEF Store audit decisions and outcomes produced by assistant command handling.
|
|
# @RELATION INHERITS -> MappingModels
|
|
# @PRE user_id must identify the actor for every record.
|
|
# @POST Audit payload remains available for compliance and debugging.
|
|
class AssistantAuditRecord(Base):
|
|
__tablename__ = "assistant_audit"
|
|
|
|
id = Column(String, primary_key=True)
|
|
user_id = Column(String, index=True, nullable=False)
|
|
conversation_id = Column(String, index=True, nullable=True)
|
|
decision = Column(String, nullable=True)
|
|
task_id = Column(String, nullable=True)
|
|
message = Column(Text, nullable=True)
|
|
payload = Column(JSON, nullable=True)
|
|
created_at = Column(DateTime, default=lambda: datetime.now(UTC), nullable=False)
|
|
|
|
|
|
# #endregion AssistantAuditRecord
|
|
|
|
|
|
# #region AssistantMessageRecord [C:3] [TYPE Class]
|
|
# @BRIEF Persist chat history entries for assistant conversations.
|
|
# @RELATION INHERITS -> MappingModels
|
|
# @PRE user_id, conversation_id, role and text must be present.
|
|
# @POST Message row can be queried in chronological order.
|
|
class AssistantMessageRecord(Base):
|
|
__tablename__ = "assistant_messages"
|
|
|
|
id = Column(String, primary_key=True)
|
|
user_id = Column(String, index=True, nullable=False)
|
|
conversation_id = Column(String, index=True, nullable=False)
|
|
role = Column(String, nullable=False) # user | assistant
|
|
text = Column(Text, nullable=False)
|
|
state = Column(String, nullable=True)
|
|
task_id = Column(String, nullable=True)
|
|
confirmation_id = Column(String, nullable=True)
|
|
payload = Column(JSON, nullable=True)
|
|
created_at = Column(DateTime, default=lambda: datetime.now(UTC), nullable=False)
|
|
|
|
|
|
# #endregion AssistantMessageRecord
|
|
|
|
|
|
# #region AssistantConfirmationRecord [C:3] [TYPE Class]
|
|
# @BRIEF Persist risky operation confirmation tokens with lifecycle state.
|
|
# @RELATION INHERITS -> MappingModels
|
|
# @PRE intent/dispatch and expiry timestamp must be provided.
|
|
# @POST State transitions can be tracked and audited.
|
|
class AssistantConfirmationRecord(Base):
|
|
__tablename__ = "assistant_confirmations"
|
|
|
|
id = Column(String, primary_key=True)
|
|
user_id = Column(String, index=True, nullable=False)
|
|
conversation_id = Column(String, index=True, nullable=False)
|
|
state = Column(String, index=True, nullable=False, default="pending")
|
|
intent = Column(JSON, nullable=False)
|
|
dispatch = Column(JSON, nullable=False)
|
|
expires_at = Column(DateTime, nullable=False)
|
|
created_at = Column(DateTime, default=lambda: datetime.now(UTC), nullable=False)
|
|
consumed_at = Column(DateTime, nullable=True)
|
|
|
|
|
|
# #endregion AssistantConfirmationRecord
|
|
# #endregion AssistantModels
|