Services.Conversation (fnord v0.8.83)

View Source

Summary

Functions

Append a new message to the conversation. Does not save the conversation.

Returns a specification to start this module under a supervisor.

Get the current agent instance.

Get the current conversation object.

Get the conversation ID of the current conversation.

Get the current session memory list for this conversation.

Get the list of messages in the current conversation.

Get the conversation metadata.

Get a response from the AI.Agent.Coordinator. The opts is passed directly to AI.Agent.get_response/2 after converting to a map and adding the :conversation server's pid.

Callback implementation for GenServer.init/1.

Request an interrupt by enqueuing a new user message to be injected at the next safe point.

Load an existing conversation from persistent storage. If conversation_id is nil, a new conversation is created. If a conversation with the given ID does not exist or is corrupt, an error is returned.

Replace the session memory list for this conversation.

Replace all messages in the conversation with a new list of messages. This does not save the conversation.

Save the current conversation to persistent storage. This updates the conversation's timestamp and writes the messages to disk. If the conversation is successfully saved, the server state is reloaded with the latest data.

Functions

append_msg(new_msg, pid)

@spec append_msg(AI.Util.msg(), pid()) :: :ok

Append a new message to the conversation. Does not save the conversation.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_agent(pid)

@spec get_agent(pid()) :: AI.Agent.t()

Get the current agent instance.

get_conversation(pid)

@spec get_conversation(pid()) :: Store.Project.Conversation.t()

Get the current conversation object.

get_id(pid)

@spec get_id(pid()) :: binary()

Get the conversation ID of the current conversation.

get_memory(pid)

@spec get_memory(pid()) :: list()

Get the current session memory list for this conversation.

get_messages(pid)

@spec get_messages(pid()) :: [AI.Util.msg()]

Get the list of messages in the current conversation.

get_metadata(pid)

@spec get_metadata(pid()) :: map()

Get the conversation metadata.

get_response(pid, opts)

@spec get_response(
  pid(),
  keyword()
) :: {:ok, any()} | {:error, any()}

Get a response from the AI.Agent.Coordinator. The opts is passed directly to AI.Agent.get_response/2 after converting to a map and adding the :conversation server's pid.

init(id)

Callback implementation for GenServer.init/1.

interrupt(pid, content)

@spec interrupt(pid(), String.t()) :: :ok | {:error, any()}

Request an interrupt by enqueuing a new user message to be injected at the next safe point.

load(conversation_id, pid)

@spec load(binary() | nil, pid()) :: :ok | {:error, any()}

Load an existing conversation from persistent storage. If conversation_id is nil, a new conversation is created. If a conversation with the given ID does not exist or is corrupt, an error is returned.

put_memory(pid, memory)

@spec put_memory(pid(), list()) :: :ok

Replace the session memory list for this conversation.

This does not save the conversation to disk; callers should invoke save/1 if they want the updated memory list to be persisted.

replace_msgs(new_msgs, pid)

@spec replace_msgs([AI.Util.msg()], pid()) :: :ok

Replace all messages in the conversation with a new list of messages. This does not save the conversation.

save(pid)

@spec save(pid()) :: {:ok, Store.Project.Conversation.t()} | {:error, any()}

Save the current conversation to persistent storage. This updates the conversation's timestamp and writes the messages to disk. If the conversation is successfully saved, the server state is reloaded with the latest data.

start_link(conversation_id \\ nil)