Store.Project.Conversation (fnord v0.8.27)

View Source

Conversations are stored per project in the project's store dir, under converations/. Each file is mostly JSON, but with a timestamp prepended to the JSON data, separated by a colon. This allows for easy sorting, without having to parse dozens or hundreds of messages for each file.

The JSON object currently has the following keys:

  • messages: a list of messages in the conversation

Existing conversations are retrieved by their UUID identifier.

Summary

Functions

Deletes the conversation from the store. If the conversation does not exist, returns an error tuple.

Returns true if the conversation exists on disk, false otherwise.

Forks the given conversation, returning a new conversation with a new UUID and identical messages. Saves the forked conversation to disk with the current timestamp.

Lists all conversations in the given project in ascending order by timestamp.

Create a new conversation with a new UUID identifier and the globally selected project.

Create a new conversation from an existing UUID identifier and the globally selected project.

Create a new conversation from an existing UUID identifier and an explicitly specified project.

Returns the user's prompting message in the conversation. This is considered to be the first "user" role message in the conversation.

Reads the conversation from the store. Returns a tuple with the timestamp and the messages in the conversation.

Returns the timestamp of the conversation. If the conversation has not yet been saved to the store, returns 0.

Saves the conversation in the store. The conversation's timestamp is updated to the current time.

Types

t()

@type t() :: %Store.Project.Conversation{
  id: term(),
  project_home: term(),
  store_path: term()
}

Functions

delete(conversation)

@spec delete(t()) :: :ok | {:error, :not_found}

Deletes the conversation from the store. If the conversation does not exist, returns an error tuple.

exists?(conversation)

@spec exists?(t()) :: boolean()

Returns true if the conversation exists on disk, false otherwise.

fork(conversation)

@spec fork(t()) :: {:ok, t()} | {:error, any()}

Forks the given conversation, returning a new conversation with a new UUID and identical messages. Saves the forked conversation to disk with the current timestamp.

list(project_home)

@spec list(binary()) :: [t()]

Lists all conversations in the given project in ascending order by timestamp.

new()

Create a new conversation with a new UUID identifier and the globally selected project.

new(id)

Create a new conversation from an existing UUID identifier and the globally selected project.

new(id, project_home)

Create a new conversation from an existing UUID identifier and an explicitly specified project.

question(conversation)

@spec question(t()) :: {:ok, binary()} | {:error, :no_question}

Returns the user's prompting message in the conversation. This is considered to be the first "user" role message in the conversation.

read(conversation)

@spec read(t()) :: {:ok, DateTime.t(), list()} | {:error, any()}

Reads the conversation from the store. Returns a tuple with the timestamp and the messages in the conversation.

timestamp(conversation)

@spec timestamp(t()) :: DateTime.t() | 0

Returns the timestamp of the conversation. If the conversation has not yet been saved to the store, returns 0.

write(conversation, messages)

@spec write(t(), list()) :: {:ok, t()} | {:error, any()}

Saves the conversation in the store. The conversation's timestamp is updated to the current time.