Jido.Messaging.RoomServer (Jido Messaging v1.0.0)

Copy Markdown View Source

GenServer that manages a single room's state.

Each room has its own process that holds:

  • The Room struct
  • Bounded message history
  • Active participants

Rooms are started on-demand and hibernate after inactivity.

Summary

Functions

Add a message to the room's history

Add or update a participant in the room

Assign a thread to an agent

Returns a specification to start this module under a supervisor.

Fetch one registered agent

Get list of agent PIDs participating in a room

Get messages from the room's history.

Get all participants in the room

Get the room struct

Get the current room server state

Get currently typing participants

List registered agents

List thread assignments

Mark a message as delivered to a participant

Mark a message as read by a participant

Register an agent with the room

Remove a participant from the room

Returns the Zoi schema

Set typing status for a participant

Start a RoomServer for the given room.

Get thread assignment

Unregister an agent from the room

Update a participant's presence status

Generate a via tuple for Registry-based process lookup

Check if a room server is running

Types

t()

@type t() :: %Jido.Messaging.RoomServer{
  instance_module: any(),
  message_limit: integer(),
  messages: [
    %Jido.Messaging.Message{
      content: term(),
      delivery_external_room_id: term(),
      external_id: term(),
      external_reply_to_id: term(),
      external_thread_id: term(),
      id: term(),
      inserted_at: term(),
      metadata: term(),
      reactions: term(),
      receipts: term(),
      reply_to_id: term(),
      role: term(),
      room_id: term(),
      sender_id: term(),
      status: term(),
      thread_id: term(),
      updated_at: term()
    }
  ],
  participants: map(),
  registered_agents: map(),
  room: %Jido.Chat.Room{
    external_bindings: term(),
    id: term(),
    inserted_at: term(),
    metadata: term(),
    name: term(),
    type: term()
  },
  thread_assignments: map(),
  timeout_ms: integer(),
  typing: map(),
  typing_timeout_ms: integer()
}

Functions

add_message(server, message, context \\ nil)

Add a message to the room's history

add_participant(server, participant)

Add or update a participant in the room

add_reaction(server, message_id, participant_id, reaction)

Add a reaction to a message

assign_thread(server, thread_id, agent_id)

Assign a thread to an agent

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_agent(server, agent_id)

Fetch one registered agent

get_agent_pids(instance_module, room_id)

Get list of agent PIDs participating in a room

get_messages(server, opts \\ [])

Get messages from the room's history.

Options:

  • :limit - Max messages to return (default: all)

get_participants(server)

Get all participants in the room

get_room(server)

Get the room struct

get_state(server)

Get the current room server state

get_typing(server)

Get currently typing participants

list_agents(server)

List registered agents

list_thread_assignments(server)

List thread assignments

mark_delivered(server, message_id, participant_id)

Mark a message as delivered to a participant

mark_read(server, message_id, participant_id)

Mark a message as read by a participant

register_agent(server, agent_spec)

Register an agent with the room

remove_participant(server, participant_id)

Remove a participant from the room

remove_reaction(server, message_id, participant_id, reaction)

Remove a reaction from a message

schema()

Returns the Zoi schema

set_typing(server, participant_id, is_typing, opts \\ [])

Set typing status for a participant

start_link(opts)

Start a RoomServer for the given room.

Options:

  • :room - Required. The Room struct or room attributes
  • :instance_module - Required. The Jido.Messaging instance module
  • :message_limit - Optional. Max messages to keep (default: 100)
  • :timeout_ms - Optional. Inactivity timeout before hibernation (default: 5 min)

thread_assignment(server, thread_id)

Get thread assignment

unassign_thread(server, thread_id)

Unassign a thread

unregister_agent(server, agent_id)

Unregister an agent from the room

update_presence(server, participant_id, presence)

Update a participant's presence status

via_tuple(instance_module, room_id)

Generate a via tuple for Registry-based process lookup

whereis(instance_module, room_id)

Check if a room server is running