Lightning.AiAssistant.ChatMessage (Lightning v2.14.14-pre1)
View SourceRepresents a message within an AI chat session.
Messages can be from users (role: :user) or from the AI assistant (role: :assistant). User messages start with :pending status and are updated based on processing results. Assistant messages typically have :success status when created.
Schema Fields
content- The text content of the message (required, 1-10,000 characters)code- Optional code associated with the message (e.g., generated workflows)role- Who sent the message::useror:assistantstatus- Processing status::pending,:success,:error, or:cancelledis_deleted- Soft deletion flag (defaults to false)is_public- Whether the message is publicly visible (defaults to true)chat_session_id- Reference to the parent chat sessionuser_id- Reference to the user who sent the message (required for user messages)
Summary
Types
@type role() :: :user | :assistant
@type status() :: :pending | :processing | :success | :error | :cancelled
@type t() :: %Lightning.AiAssistant.ChatMessage{ __meta__: term(), chat_session: term(), chat_session_id: Ecto.UUID.t(), code: String.t() | nil, content: String.t() | nil, id: Ecto.UUID.t(), inserted_at: DateTime.t(), is_deleted: boolean(), is_public: boolean(), processing_completed_at: DateTime.t() | nil, processing_started_at: DateTime.t() | nil, role: role(), status: status(), updated_at: DateTime.t(), user: term(), user_id: Ecto.UUID.t() | nil }
Functions
Creates a changeset for a chat message.
Parameters
chat_message- The ChatMessage struct to update (typically%ChatMessage{})attrs- Map of attributes to set/update
Validation Rules
contentandroleare requiredcontentmust be between 1 and 10,000 characters- User messages (role:
:user) require an associated user - Status defaults based on role:
:pendingfor users,:successfor assistant - If status is explicitly provided, it takes precedence over role-based defaults
Creates a changeset for updating message status.
This is a focused changeset that only updates the status field, useful for updating message state during processing.
Parameters
chat_message- The existing ChatMessage structstatus- New status (:pending,:success,:error, or:cancelled)
Examples
# Mark message as successful
ChatMessage.status_changeset(message, :success)
# Mark message as failed
ChatMessage.status_changeset(message, :error)