OpencodeFileEvent
What it is
- A SQLAlchemy ORM model representing a file-related event in the “opencode” domain.
- Maps to the
opencode_file_eventsdatabase table.
Public API
class OpencodeFileEvent(OpencodeBase)
- ORM entity with the following mapped columns:
id: str— Primary key (UUID string), auto-generated by default.session_id: str— Foreign key toopencode_sessions.id.message_id: str— Foreign key toopencode_messages.id.event_type: str— Event type descriptor (stored asTEXT).file_path: str | None— Optional path associated with the event.diff: str | None— Optional diff content.command: str | None— Optional command content.created_at: datetime— Timestamp (timezone-aware), defaults todatetime.now(timezone.utc).
Configuration/Dependencies
- SQLAlchemy:
- Uses
Mapped/mapped_columndeclarative mapping. - Column types:
String,Text,DateTime,ForeignKey.
- Uses
- Model base:
naas_abi_core.models.opencode.Base.OpencodeBase(must provide SQLAlchemy declarative base configuration). - Runtime:
uuid4()for defaultid.datetime.now(timezone.utc)for defaultcreated_at.
Usage
from naas_abi_core.models.opencode.OpencodeFileEvent import OpencodeFileEvent
event = OpencodeFileEvent(
session_id="session-uuid",
message_id="message-uuid",
event_type="file_modified",
file_path="path/to/file.py",
diff="--- a\n+++ b\n...",
command="apply_patch ...",
)
# Add to a SQLAlchemy session as usual:
# db.add(event); db.commit()
Caveats
session_idandmessage_idmust reference existing rows inopencode_sessionsandopencode_messages(foreign key constraints).created_atis stored as timezone-awareDateTime(timezone=True)and defaults to UTC.