public final class ConversationStore

  1. Object
  2. ConversationStore

JSON-backed persistent conversation history.

Stores ChatMessage lists in Storage under a caller-chosen key so apps can rehydrate a ChatView after process restart. Multimodal parts (ImagePart, ToolResultPart) are serialized to a lossy text fallback – image data is not round-tripped (apps that need full multimodal persistence should encode the bytes themselves and keep them in FileSystemStorage).

Constructors

public ConversationStore(String storageKey)Creates a store using one app-private Storage key.

Methods

public void save(List<ChatMessage> messages) throws IOExceptionReplaces the persisted history.
public List<ChatMessage> load() throws IOExceptionLoads persisted history.
public void clear()Deletes the persisted conversation.
public String getStorageKey()

Inherited methods

Constructor details

ConversationStore

public ConversationStore(String storageKey)
Creates a store using one app-private Storage key.

Parameters

storageKey String
non-empty key dedicated to this conversation

Method details

save

public void save(List<ChatMessage> messages) throws IOException
Replaces the persisted history.

Parameters

messages List<ChatMessage>
chronological history; null stores an empty list

Throws

IOException
when JSON encoding or storage fails

load

public List<ChatMessage> load() throws IOException
Loads persisted history. Missing or incompatible data is treated as an empty conversation so upgrades do not prevent application startup.

Returns

mutable chronological message list

Throws

IOException
when stored JSON cannot be decoded

clear

public void clear()
Deletes the persisted conversation.

getStorageKey

public String getStorageKey()

Returns

app-private storage key used by this store