Abstract base class for conversation storage backends
Source:R/chat_history_store.R
ConversationStore.RdSubclass this to plug a custom persistence backend into
chat_enable_history() via history_options(store = ). All methods
are partitioned by a conversation_partition() (chat id + owner scope);
implementations should not need to know about users, sessions, or Shiny
beyond that.
A conversation record is a list with fields schema_version, id,
title, title_source ("llm", "user", or NULL), response_count,
created_at, updated_at (ISO 8601 strings), client_info, nodes (a
named list of turn nodes forming the conversation tree), current_leaf
(id of the most recent node, or NULL), values (the app state dict
captured by on_save), and bookmark_state_id. A conversation meta list
is the lightweight summary returned by list(): id, title,
created_at, updated_at, and size_bytes (the backend's storage
footprint for that conversation, e.g. on-disk bytes).
schema_version compatibility is enforced by the framework's
HistoryController, not by this class – it calls check_schema_version()
on every record it reads from a store and every record it is about to
write, so a custom store doesn't need to check it itself.
Methods
ConversationStore$list()
Must be implemented by subclasses. All conversations in
partition, newest-first by created_at.
ConversationStore$get()
Must be implemented by subclasses. The full conversation
record for id in partition.
ConversationStore$put()
Must be implemented by subclasses. Upsert record into
partition. A rename is just mutating record$title and calling
put() again.
Arguments
partitionA
conversation_partition().recordA conversation record, in the same shape returned by
get().
ConversationStore$delete()
Must be implemented by subclasses. Remove the
conversation id from partition. Missing ids are a no-op.
ConversationStore$search()
Case-insensitive substring match of query against
title, over list(partition). Backends don't need to override this
unless they have a more efficient search path.
ConversationStore$total_size()
Total bytes used by all conversations in partition,
derived from list()'s per-record size_bytes. Backends don't need
to override this unless they have a cheaper way to compute it.