Skip to main content

OpencodeFileEvent

What it is

  • A SQLAlchemy ORM model representing a file-related event in the “opencode” domain.
  • Maps to the opencode_file_events database 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 to opencode_sessions.id.
    • message_id: str — Foreign key to opencode_messages.id.
    • event_type: str — Event type descriptor (stored as TEXT).
    • 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 to datetime.now(timezone.utc).

Configuration/Dependencies

  • SQLAlchemy:
    • Uses Mapped / mapped_column declarative mapping.
    • Column types: String, Text, DateTime, ForeignKey.
  • Model base: naas_abi_core.models.opencode.Base.OpencodeBase (must provide SQLAlchemy declarative base configuration).
  • Runtime:
    • uuid4() for default id.
    • datetime.now(timezone.utc) for default created_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_id and message_id must reference existing rows in opencode_sessions and opencode_messages (foreign key constraints).
  • created_at is stored as timezone-aware DateTime(timezone=True) and defaults to UTC.