Subscriptions
The callback ChatStoreListener, one change ChatStoreChange and the range change ChatStoreDataEvent.
Subscriptions
Exports of the @openmaxai/chat-store root entry point for subscribing. Status, wiring it into a host and an index of every export are on the Overview.
ChatStoreListener
type ChatStoreListener = (change: ChatStoreChange) => void;
The subscription callback; see subscribe.
ChatStoreChange
interface ChatStoreChange {
conversationId: string;
events: readonly ChatStoreDataEvent[];
unloaded?: {
end: "older" | "newer";
messageIds: readonly string[];
};
}
What one dispatch changed for one conversation. A subscriber receives at most one per dispatch.
| Field | Description |
|---|---|
events |
Changes to the loaded range, see ChatStoreDataEvent. A window replacement has exactly one item, window. Can be empty: only "older available / newer available", a cursor, the watermark or newerPending changed, and the loaded messages did not. |
unloaded |
The end unloaded because the memory window went over its limit, and its messages; that end is the one farthest from the view. |
ChatStoreDataEvent
type ChatStoreDataEvent =
| {
kind: "window";
}
| {
kind: "before";
messageIds: readonly string[];
}
| {
kind: "after";
messageIds: readonly string[];
}
| {
kind: "replace";
messageIds: readonly string[];
removedIds: readonly string[];
};
One kind of change to a conversation's loaded range. There are only four:
kind |
Description |
|---|---|
window |
The range was replaced by a window. |
before |
Attached in front; messageIds are the newly attached ones, ascending by seq. |
after |
Attached after; messageIds are the newly attached ones, ascending by seq. |
replace |
Replaced in place; messageIds are the ones whose content changed, removedIds the ones deleted (their rows disappear, everything else stays). A local message becoming the server message (reconciliation) is this kind too: messageIds has the server message's id, whose client_msg_id equals the local one's, and the row is not redrawn. |
Local messages (sending, failed, blocked) are not in the range, but their changes are reported with the same four kinds: a newly sent one is after, a status change is in replace's messageIds, and a removal in replace's removedIds. When a local message is temporarily hidden because the window has not reached the latest (hasNewer), or shown again, no extra event is reported: whether it shows is decided by the snapshot, so if you maintain a list incrementally from events, check the local rows against the snapshot after any change.
