Conversations — core API
Generated reference for @aparte/core. Conversations and their storage, the history of one conversation with its branches, and the context of it that goes to the model.
On this page
Classes
Section titled “Classes”AparteConversationController
Section titled “AparteConversationController”Defined in: packages/core/src/conversations/conversation-controller.ts:107
Connects an AparteChatBinding to a AparteConversationManager.
Responsibilities:
- Load messages when
setConversationId(id)is called. - Lazily create a conversation on the first user
aparte-sendif none active. - Persist updates triggered by
aparte-path-changed(branch nav, retry, edit). - Dispatch
aparte-abortwhen the active conversation changes mid-stream.
Usage:
const controller = new AparteConversationController(binding);
const stop = controller.bind();
controller.setConversationId('abc-123');
// …
stop();Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AparteConversationController(binding, options?): AparteConversationController;Defined in: packages/core/src/conversations/conversation-controller.ts:167
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
binding | AparteChatBinding |
options | AparteConversationControllerOptions |
Returns
Section titled “Returns”Accessors
Section titled “Accessors”activeId
Section titled “activeId”Get Signature
Section titled “Get Signature”get activeId(): string | null;Defined in: packages/core/src/conversations/conversation-controller.ts:173
The current active conversation id (null when none selected).
Returns
Section titled “Returns”string | null
Methods
Section titled “Methods”bind()
Section titled “bind()”bind(): () => void;Defined in: packages/core/src/conversations/conversation-controller.ts:263
Attach event listeners to the binding host. Returns an unbind function.
Returns
Section titled “Returns”() => void
unbind()
Section titled “unbind()”unbind(): void;Defined in: packages/core/src/conversations/conversation-controller.ts:416
Returns
Section titled “Returns”void
setConversationId()
Section titled “setConversationId()”setConversationId(id): Promise<void>;Defined in: packages/core/src/conversations/conversation-controller.ts:495
Switch to (or clear) the active conversation.
null: clears the binding and deselects in the manager.- any id: loads the conversation’s messages into the binding.
Idempotent: calling with the current id forces a re-snapshot from the manager (handy when external mutations could have desynchronised the binding, or when a user re-selects the already-active conv from a sidebar). Streams are only aborted on an actual id change so a same-id reload never kills an in-flight response.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string | null |
Returns
Section titled “Returns”Promise<void>
AparteConversationManager
Section titled “AparteConversationManager”Defined in: packages/core/src/conversations/conversation-manager.ts:190
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AparteConversationManager(adapter, options?): AparteConversationManager;Defined in: packages/core/src/conversations/conversation-manager.ts:212
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
adapter | AparteStorageAdapter |
options? | ConversationManagerOptions |
Returns
Section titled “Returns”Accessors
Section titled “Accessors”adapter
Section titled “adapter”Get Signature
Section titled “Get Signature”get adapter(): AparteStorageAdapter;Defined in: packages/core/src/conversations/conversation-manager.ts:208
The store this manager writes to.
Returns
Section titled “Returns”initialized
Section titled “initialized”Get Signature
Section titled “Get Signature”get initialized(): boolean;Defined in: packages/core/src/conversations/conversation-manager.ts:347
Whether init() has completed at least once. Consumers use this to
distinguish “manager still hydrating from storage” from “manager
hydrated, conversations is genuinely empty”. The conversation-controller
relies on this to defer clearing the binding during the IndexedDB
hydration window (Angular APP_INITIALIZER race).
Returns
Section titled “Returns”boolean
conversations
Section titled “conversations”Get Signature
Section titled “Get Signature”get conversations(): AparteConversation[];Defined in: packages/core/src/conversations/conversation-manager.ts:353
Returns
Section titled “Returns”activeId
Section titled “activeId”Get Signature
Section titled “Get Signature”get activeId(): string | null;Defined in: packages/core/src/conversations/conversation-manager.ts:357
Returns
Section titled “Returns”string | null
active
Section titled “active”Get Signature
Section titled “Get Signature”get active(): AparteConversation | null;Defined in: packages/core/src/conversations/conversation-manager.ts:361
Returns
Section titled “Returns”AparteConversation | null
activeConversations
Section titled “activeConversations”Get Signature
Section titled “Get Signature”get activeConversations(): AparteConversation[];Defined in: packages/core/src/conversations/conversation-manager.ts:367
Active conversations (not archived), newest first.
Returns
Section titled “Returns”archivedConversations
Section titled “archivedConversations”Get Signature
Section titled “Get Signature”get archivedConversations(): AparteConversation[];Defined in: packages/core/src/conversations/conversation-manager.ts:374
Archived conversations, newest first.
Returns
Section titled “Returns”Methods
Section titled “Methods”setTitleProvider()
Section titled “setTitleProvider()”setTitleProvider(provider): void;Defined in: packages/core/src/conversations/conversation-manager.ts:225
Replace how a new conversation is titled from its first user message.
null restores the default (the message’s text). The provider is consulted
once per conversation, on that first message; updateTitle is untouched.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
provider | | AparteConversationTitleProvider | null |
Returns
Section titled “Returns”void
getTitleProvider()
Section titled “getTitleProvider()”getTitleProvider():
| AparteConversationTitleProvider
| null;Defined in: packages/core/src/conversations/conversation-manager.ts:230
The registered title provider, or null when the default applies.
Returns
Section titled “Returns”| AparteConversationTitleProvider
| null
init()
Section titled “init()”init(): Promise<void>;Defined in: packages/core/src/conversations/conversation-manager.ts:243
Load all conversations from the adapter. Call once at app startup.
A later call re-reads the list from the store: rows it no longer lists are dropped, and a conversation whose messages are already in memory keeps them — so the one on screen goes on being persisted.
Returns
Section titled “Returns”Promise<void>
isLoaded()
Section titled “isLoaded()”isLoaded(id): boolean;Defined in: packages/core/src/conversations/conversation-manager.ts:290
Whether a conversation’s messages are in memory (always, without split storage).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”boolean
ensureFull()
Section titled “ensureFull()”ensureFull(id): Promise<boolean>;Defined in: packages/core/src/conversations/conversation-manager.ts:302
Fetch a conversation’s messages through the adapter’s loadFull(), the first time
they are needed; later calls resolve at once. The row keeps its place and its meta;
the messages (and the tree) come from the full record, and a message written to
the row while the fetch ran goes after them. Resolves false when the store has no
such record (or answers with another id) — the row is then NOT loaded, and says so,
rather than counting as an empty conversation.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<boolean>
createNew()
Section titled “createNew()”createNew(title?): Promise<AparteConversation>;Defined in: packages/core/src/conversations/conversation-manager.ts:387
Create a new empty conversation, persist it, and make it active. Untitled by
default: the list shows its locale’s newChat word for an empty title, so the
store never carries an English string a French UI would then display.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
title | string | '' |
Returns
Section titled “Returns”Promise<AparteConversation>
select()
Section titled “select()”select(id): void;Defined in: packages/core/src/conversations/conversation-manager.ts:419
Switch active conversation without touching storage.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”void
clearActive()
Section titled “clearActive()”clearActive(): void;Defined in: packages/core/src/conversations/conversation-manager.ts:426
Deselect the active conversation (no conv selected).
Returns
Section titled “Returns”void
addMessage()
Section titled “addMessage()”addMessage(convId, msg): Promise<void>;Defined in: packages/core/src/conversations/conversation-manager.ts:440
Append a message to a conversation. Auto-generates title from first user message.
One append at a time per conversation: two sends that overlap (a suggestion and a quick type, coalesced into one new conversation) both suspend before reading the record — for the messages, then for the title provider — so the queue keeps the second one from reading a conversation with no user message in it yet and taking its text as the title.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
convId | string |
msg | AparteMessage |
Returns
Section titled “Returns”Promise<void>
updateMessages()
Section titled “updateMessages()”updateMessages(
convId,
messages,
tree?): Promise<void>;Defined in: packages/core/src/conversations/conversation-manager.ts:488
Replace the flat active-path messages and optionally the full branch tree.
messages is always written (active path, for sidebar/title/compat).
tree is written when provided — it carries the full branching topology.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
convId | string |
messages | AparteMessage[] |
tree? | ExportedMessageRepository |
Returns
Section titled “Returns”Promise<void>
delete()
Section titled “delete()”delete(id): Promise<void>;Defined in: packages/core/src/conversations/conversation-manager.ts:566
Permanently delete a conversation.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<void>
archive()
Section titled “archive()”archive(id): Promise<void>;Defined in: packages/core/src/conversations/conversation-manager.ts:575
Archive a conversation (soft-delete).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<void>
unarchive()
Section titled “unarchive()”unarchive(id): Promise<void>;Defined in: packages/core/src/conversations/conversation-manager.ts:610
Restore an archived conversation.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<void>
pin(id): Promise<void>;Defined in: packages/core/src/conversations/conversation-manager.ts:624
Pin a conversation, which the list shows in its “Pinned” group first. Metadata
only, like archive: updatedAt keeps the conversation’s real chronological slot
for the day it is unpinned. An adapter that has pin() gets the call; one that
does not gets the whole record through save().
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<void>
unpin()
Section titled “unpin()”unpin(id): Promise<void>;Defined in: packages/core/src/conversations/conversation-manager.ts:630
Unpin a conversation. Metadata only — see pin().
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<void>
updateTitle()
Section titled “updateTitle()”updateTitle(id, title): Promise<void>;Defined in: packages/core/src/conversations/conversation-manager.ts:639
Update the title manually. The full input is preserved — UI surfaces
(sidebar list, topbar) are responsible for visual truncation via CSS
(min-w-0 + truncate). Auto-titles produced internally by
_autoTitle() remain capped at a sensible length on input.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
title | string |
Returns
Section titled “Returns”Promise<void>
subscribe()
Section titled “subscribe()”subscribe(listener): () => void;Defined in: packages/core/src/conversations/conversation-manager.ts:660
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
listener | AparteConversationsListener |
Returns
Section titled “Returns”() => void
AparteMessageRepository
Section titled “AparteMessageRepository”Defined in: packages/core/src/runtime/message-repository.ts:54
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AparteMessageRepository(): AparteMessageRepository;Returns
Section titled “Returns”Accessors
Section titled “Accessors”headId
Section titled “headId”Get Signature
Section titled “Get Signature”get headId(): string | null;Defined in: packages/core/src/runtime/message-repository.ts:62
ID of the currently active leaf message
Returns
Section titled “Returns”string | null
Methods
Section titled “Methods”getMessages()
Section titled “getMessages()”getMessages(): AparteMessage[];Defined in: packages/core/src/runtime/message-repository.ts:70
Returns the messages on the currently active path, root → head. O(depth).
Returns
Section titled “Returns”getMessage()
Section titled “getMessage()”getMessage(id):
| {
parentId: string | null;
message: AparteMessage;
index: number;
}
| undefined;Defined in: packages/core/src/runtime/message-repository.ts:88
Returns metadata about a specific message, or undefined if not found.
Read methods (getMessage, getMessageById, getBranches) all return
undefined / [] for unknown ids — never throw — so callers can do a
single existence check at the top of a flow rather than wrapping every
call in try/catch.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”| {
parentId: string | null;
message: AparteMessage;
index: number;
}
| undefined
getMessageById()
Section titled “getMessageById()”getMessageById(id): AparteMessage | undefined;Defined in: packages/core/src/runtime/message-repository.ts:102
Returns the mutable message reference, or undefined if not found.
Mutations to the returned object are reflected in getMessages().
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”AparteMessage | undefined
getAllMessages()
Section titled “getAllMessages()”getAllMessages(): AparteMessage[];Defined in: packages/core/src/runtime/message-repository.ts:114
Every message the tree holds — every branch, not just the active path.
Unlike getMessages(), which walks head → root, this also sees a turn that a
retry has taken off the active path, so it answers questions about the whole
conversation (“is anything still streaming?”). No order is promised beyond
insertion: a caller that needs the topology reads export().
Returns
Section titled “Returns”getBranches()
Section titled “getBranches()”getBranches(messageId): string[];Defined in: packages/core/src/runtime/message-repository.ts:125
Returns the IDs of all siblings of messageId
(i.e. all children of its parent, including itself).
Use this to build branch-picker UI.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messageId | string |
Returns
Section titled “Returns”string[]
addOrUpdateMessage()
Section titled “addOrUpdateMessage()”addOrUpdateMessage(parentId, message): void;Defined in: packages/core/src/runtime/message-repository.ts:139
Add a new message as a child of parentId (null = root).
If a message with the same id already exists, updates its data
and re-links it under the correct parent.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parentId | string | null |
message | AparteMessage |
Returns
Section titled “Returns”void
switchToBranch()
Section titled “switchToBranch()”switchToBranch(messageId): void;Defined in: packages/core/src/runtime/message-repository.ts:181
Switch the active branch to messageId.
Updates next on the parent chain so getMessages() reflects the change.
Advances head to the deepest active node in the new branch.
Silent no-op for unknown ids — mutation methods (switchToBranch,
resetHead, updateMessage, clearChildren) never throw.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messageId | string |
Returns
Section titled “Returns”void
resetHead()
Section titled “resetHead()”resetHead(messageId): void;Defined in: packages/core/src/runtime/message-repository.ts:197
Remove all descendants of messageId (inclusive) and, when the head was among
them, set head to the parent of messageId. Used by edit/truncate flows.
A head in a branch this call did not touch stays where it is.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
messageId | string | The first message to remove |
Returns
Section titled “Returns”void
updateMessage()
Section titled “updateMessage()”updateMessage(messageId, updates): void;Defined in: packages/core/src/runtime/message-repository.ts:230
Update a message’s data without changing its position in the tree.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messageId | string |
updates | Partial<AparteMessage> |
Returns
Section titled “Returns”void
clearChildren()
Section titled “clearChildren()”clearChildren(parentId): void;Defined in: packages/core/src/runtime/message-repository.ts:241
Remove ALL children of parentId (and their descendants) and set head
to parentId. Used by edit to discard every previous response before
re-generating — ensures the new response starts with sibling count = 1.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parentId | string |
Returns
Section titled “Returns”void
clear()
Section titled “clear()”clear(): void;Defined in: packages/core/src/runtime/message-repository.ts:258
Remove all messages and reset to empty state.
Returns
Section titled “Returns”void
import()
Section titled “import()”import(exported): void;Defined in: packages/core/src/runtime/message-repository.ts:270
Import a previously-exported snapshot, rebuilding the full tree and
restoring the active head. Replaces any existing content (calls clear()
first). export() writes messages in topological order (parent before
child), which is the order this expects.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
exported | ExportedMessageRepository |
Returns
Section titled “Returns”void
export()
Section titled “export()”export(): ExportedMessageRepository;Defined in: packages/core/src/runtime/message-repository.ts:314
Export the full tree for serialisation or debugging. Compatible with the assistant-ui ExportedMessageRepository format.
Walked from the root through each node’s children, so a parent is always
written before its children, even after addOrUpdateMessage re-parented an
existing node under a newer one; import() relies on that order.
Returns
Section titled “Returns”Functions
Section titled “Functions”historyFromCheckpoint()
Section titled “historyFromCheckpoint()”function historyFromCheckpoint(path): {
summary?: string;
messages: AparteMessage[];
};Defined in: packages/core/src/context/checkpoint.ts:25
The part of a path the model reads, and the summary that stands for the rest.
A checkpoint is contextSummary on a message: from it on the model reads the summary
in place of everything before. The LAST message carrying one wins — a later
checkpoint was written over the earlier summary (it asked for an update of it), so
the earlier one is already inside it. Everything before the winner is dropped from
the result, a legacy compaction: true message included: that notice is itself part
of what the checkpoint summarised, and sending it beside the summary would say the
same thing twice.
With no checkpoint the path comes back unchanged and no summary is returned, so a caller can use it unconditionally. Nothing is deleted from the transcript — this reads a path and returns a view of it.
Call it on the FULL path, the unanswered user message at its end included: the checkpoint can sit on that very message (a turn retried after an overflow), and the summary still has to go out before it.
AparteClient applies it to every history it builds. A history function handed to
the client receives the whole transcript and can call this itself.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path | AparteMessage[] |
Returns
Section titled “Returns”{
summary?: string;
messages: AparteMessage[];
}summary?
Section titled “summary?”optional summary?: string;messages
Section titled “messages”messages: AparteMessage[];estimateTokens()
Section titled “estimateTokens()”function estimateTokens(text): number;Defined in: packages/core/src/context/measure.ts:17
Token heuristic (FR ~3.5 chars/tok, EN ~4 chars/tok).
Accurate to ±10% — enough for budgeting, and it avoids a tokenizer, which costs ~5ms per message × N (too slow to run on every turn) and is one more dependency per model family. It is the ONE estimate: the compaction plugin’s budget and selector, the gauge, and the number the client records on a reply all read it, so the figures they show and the decisions they take cannot disagree about what a message costs.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
text | string | null | undefined |
Returns
Section titled “Returns”number
estimateWireTokens()
Section titled “estimateWireTokens()”function estimateWireTokens(messages): number;Defined in: packages/core/src/context/measure.ts:79
The estimate of what the wire sends for these messages: the same serialisation the
client builds its history with (wireMessages) — a reply’s thinking is not sent, its
text is, and a tool call and its result count as the envelope and the tool message
the wire carries. A failed turn and one still in flight send nothing.
Not estimateTokens(message.content): assistant replies keep their text in
segments with content empty, so that sum would read a whole conversation as free.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messages | AparteMessage[] |
Returns
Section titled “Returns”number
measureContext()
Section titled “measureContext()”function measureContext(input): AparteContextMeasure;Defined in: packages/core/src/context/measure.ts:218
The one measure of the context window, for the gauge and for the compaction plugin.
used is the last reply’s REAL usage while nothing the model reads has changed since
it: the reply is the last message of the path, and no checkpoint was written after it.
Once something has (a message was added, a compaction ran), the real number describes a
request that will not be sent again, so used becomes an estimate of the request that
WOULD be sent — the system prompts, the tool definitions, the checkpoint’s summary and
the messages after it — scaled by k, how far the heuristic was off on the last reply:
its real input tokens over the estimate recorded when it was sent
(AparteMessage.contextEstimate), clamped to [0.5, 3] so one odd reply cannot throw the
reading, and 1 when the reply has no estimate. After a compaction the reading is
therefore the size of the new, smaller view, never the stale one from before it, and
never a k computed against a history the reply did not see.
k compares like with like or it is 1. The estimate is of the FIRST request a turn sent
and the usage is of its LAST call, which also read the calls and their results, so a
reply that called tools says nothing about the heuristic’s error and counts as 1. A
request the heuristic could not read whole (an image) records no estimate at all.
While nothing has changed, used is what the NEXT request will carry: the input the
provider reported, plus the reply as it goes back on the wire. A provider’s output count
includes the reasoning it generated, and a reply’s thinking is not sent again, so for a
reply that thought the answer is read from the transcript (the part after its last call,
which is all the final call added to what it read) and not from the output count.
The parts are not scaled: they stay the raw estimates, so a reader can see what the measure is made of.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input | AparteContextMeasureInput |
Returns
Section titled “Returns”Variables
Section titled “Variables”APARTE_CONVERSATION_SCHEMA_VERSION
Section titled “APARTE_CONVERSATION_SCHEMA_VERSION”const APARTE_CONVERSATION_SCHEMA_VERSION: 2;Defined in: packages/core/src/conversations/types.ts:14
Current schema version for AparteConversation. Bump when the persisted
shape evolves so adapters / migrations can branch on it.
v1: monolithic — messages[] inline on the conversation row, attachment
url was a session-scoped blob URL (lost on reload), artifacts inline
in segments only.
v2: split — meta-only conversation row; messages and attachments (with real
Blobs) get their own table. Sidebar can list without loading full payloads.
Interfaces
Section titled “Interfaces”AparteContextMeasure
Section titled “AparteContextMeasure”Defined in: packages/core/src/context/measure.ts:121
What fills the model’s window, as one reading. used is the total the gauge draws;
parts say where it goes.
The parts are RAW estimates (the character heuristic, uncalibrated), so they are
labelled as estimates wherever they are shown and need not add up to used: the
difference, other, is what the heuristic cannot see — a server loop’s own system
prompt and tools, the chat template’s tokens, the heuristic’s own error.
Properties
Section titled “Properties”window?
Section titled “window?”optional window?: number;Defined in: packages/core/src/context/measure.ts:123
The window used is measured against, when one is known.
used: number;Defined in: packages/core/src/context/measure.ts:125
Tokens in use: the last reply’s reported usage, or an estimate of the request the next turn would send.
estimated
Section titled “estimated”estimated: boolean;Defined in: packages/core/src/context/measure.ts:127
true when used is an estimate — something changed in what the model reads since the last reply reported.
parts: {
system: number;
tools: number;
summary: number;
messages: number;
};Defined in: packages/core/src/context/measure.ts:129
Raw estimates, in tokens, of what the model reads: the system prompts, the tool definitions, the checkpoint’s summary, the messages after it.
system
Section titled “system”system: number;tools: number;summary
Section titled “summary”summary: number;messages
Section titled “messages”messages: number;other: number;Defined in: packages/core/src/context/measure.ts:131
used less the parts, never below zero.
AparteContextMeasureInput
Section titled “AparteContextMeasureInput”Defined in: packages/core/src/context/measure.ts:135
What measureContext reads.
Properties
Section titled “Properties”messages
Section titled “messages”messages: AparteMessage[];Defined in: packages/core/src/context/measure.ts:137
The ACTIVE path of the conversation, checkpoint and all — not the view after it.
config
Section titled “config”config: AparteConfig;Defined in: packages/core/src/context/measure.ts:139
The config that resolves the system prompt, the tools and the current model.
windowOverride?
Section titled “windowOverride?”optional windowOverride?: number | null;Defined in: packages/core/src/context/measure.ts:141
A window that wins over the current model’s, for a page that knows better (the gauge’s window attribute).
viewChanged?
Section titled “viewChanged?”optional viewChanged?: boolean;Defined in: packages/core/src/context/measure.ts:147
The caller knows what the model reads has changed since the last reply although the messages cannot say so — a Restore takes checkpoints off, and nothing is left on the path to date it. Forces an estimate.
AparteChatBinding
Section titled “AparteChatBinding”Defined in: packages/core/src/conversations/conversation-controller.ts:24
Abstract binding between a chat UI and the conversation lifecycle.
Each framework wrapper (Angular, React, Vue, Svelte) provides an implementation that knows how to mutate its own message list. The controller orchestrates loading, persistence and abort using only this interface, keeping the conversation engine fully framework-agnostic.
Properties
Section titled “Properties”hostId
Section titled “hostId”readonly hostId: string;Defined in: packages/core/src/conversations/conversation-controller.ts:26
Stable id of the host element (used as targetId for scoped events).
readonly host: HTMLElement;Defined in: packages/core/src/conversations/conversation-controller.ts:28
The element that emits/receives aparte-send and aparte-path-changed.
Methods
Section titled “Methods”setMessages()
Section titled “setMessages()”setMessages(messages): void;Defined in: packages/core/src/conversations/conversation-controller.ts:30
Replace the entire message list (used when switching conversations).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messages | AparteMessage[] |
Returns
Section titled “Returns”void
appendMessage()
Section titled “appendMessage()”appendMessage(message): void;Defined in: packages/core/src/conversations/conversation-controller.ts:32
Append a single message (used for the optimistic user-msg on send).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
message | AparteMessage |
Returns
Section titled “Returns”void
getMessages()
Section titled “getMessages()”getMessages(): AparteMessage[];Defined in: packages/core/src/conversations/conversation-controller.ts:34
Read the current message list.
Returns
Section titled “Returns”clearMessages()
Section titled “clearMessages()”clearMessages(options?): void;Defined in: packages/core/src/conversations/conversation-controller.ts:36
Clear all messages (e.g. when starting a new conversation).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options? | { revokeAttachments?: boolean; } |
options.revokeAttachments? | boolean |
Returns
Section titled “Returns”void
setLoading()?
Section titled “setLoading()?”optional setLoading(loading): void;Defined in: packages/core/src/conversations/conversation-controller.ts:41
The transcript is on its way, or no longer: a conversation was chosen and its
messages are being fetched. The DOM binding sets the viewport’s loading.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
loading | boolean |
Returns
Section titled “Returns”void
exportTree()?
Section titled “exportTree()?”optional exportTree(): ExportedMessageRepository | undefined;Defined in: packages/core/src/conversations/conversation-controller.ts:47
Export the full conversation tree for persistence.
Optional: only available when the binding wraps a AparteMessageRepository
(e.g. the vanilla viewport). Returns undefined when not supported.
Returns
Section titled “Returns”ExportedMessageRepository | undefined
importTree()?
Section titled “importTree()?”optional importTree(tree): void;Defined in: packages/core/src/conversations/conversation-controller.ts:54
Import a previously-persisted tree snapshot, restoring full branch
topology. Called by the controller after setMessages (which handles
cleanup) when the loaded conversation carries a tree field.
Optional: falls back to the flat setMessages load when absent.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tree | ExportedMessageRepository |
Returns
Section titled “Returns”void
afterRender()?
Section titled “afterRender()?”optional afterRender(cb): void;Defined in: packages/core/src/conversations/conversation-controller.ts:61
Run a callback after the framework has applied its latest render. Optional: a binding whose list is current the moment it is written (the vanilla viewport) leaves it out. One that renders late — a transcript kept in a framework store — declares it, so a save waits for the list to arrive instead of writing the old one.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb | () => void |
Returns
Section titled “Returns”void
AparteConversationControllerOptions
Section titled “AparteConversationControllerOptions”Defined in: packages/core/src/conversations/conversation-controller.ts:70
Properties
Section titled “Properties”keepDrafts?
Section titled “keepDrafts?”optional keepDrafts?: boolean;Defined in: packages/core/src/conversations/conversation-controller.ts:76
Keep what was typed in each conversation, and give it back on return. In memory,
unless the storage adapter has loadDraft and saveDraft. A pill comes back as its
text. Default: false.
manager?
Section titled “manager?”optional manager?: AparteConversationManager;Defined in: packages/core/src/conversations/conversation-controller.ts:81
Conversation manager. If omitted, the controller resolves it from
aparteGlobalConfig.getConversationManager() when first needed.
onConversationCreated?
Section titled “onConversationCreated?”optional onConversationCreated?: (id) => void;Defined in: packages/core/src/conversations/conversation-controller.ts:86
Called whenever a new conversation is created lazily (on first user message in an empty thread). Useful for the parent app to sync the URL.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”void
ConversationManagerOptions
Section titled “ConversationManagerOptions”Defined in: packages/core/src/conversations/conversation-manager.ts:23
Properties
Section titled “Properties”titleProvider?
Section titled “titleProvider?”optional titleProvider?: AparteConversationTitleProvider;Defined in: packages/core/src/conversations/conversation-manager.ts:28
Titles a new conversation from its first user message, instead of the default
(the message’s text). Same as calling setTitleProvider after construction.
retention?
Section titled “retention?”optional retention?: {
maxMessages: number;
};Defined in: packages/core/src/conversations/conversation-manager.ts:36
Opt-in history retention. When set, updateMessages() trims a persisted
conversation to at most maxMessages on the active path (dropping the
oldest history and the branches hanging off it) before writing to storage.
Omit for unbounded history (the default) — retention is a deliberate
consumer choice, never silent.
maxMessages
Section titled “maxMessages”maxMessages: number;AparteConversation
Section titled “AparteConversation”Defined in: packages/core/src/conversations/types.ts:19
A single conversation (thread) — framework-agnostic.
Properties
Section titled “Properties”id: string;Defined in: packages/core/src/conversations/types.ts:20
title: string;Defined in: packages/core/src/conversations/types.ts:27
The title. Decided by the manager from the first user message (the text as
typed, or what the title provider returns), or typed by the user. Empty when
the conversation has no text yet: the list shows its locale’s newChat word,
and the store never carries a UI string.
autoTitle?
Section titled “autoTitle?”optional autoTitle?: boolean;Defined in: packages/core/src/conversations/types.ts:35
true while the title is the manager’s decision. Editing the first user
message then re-titles; a title typed by the user (updateTitle) clears it
and is kept whatever happens to the messages. Absent on records written
before this field existed, which reads as “typed”: an old title is never
overwritten.
createdAt
Section titled “createdAt”createdAt: number;Defined in: packages/core/src/conversations/types.ts:36
updatedAt
Section titled “updatedAt”updatedAt: number;Defined in: packages/core/src/conversations/types.ts:37
messages
Section titled “messages”messages: AparteMessage[];Defined in: packages/core/src/conversations/types.ts:38
optional tree?: ExportedMessageRepository;Defined in: packages/core/src/conversations/types.ts:47
Full branching tree snapshot. When present, the conversation has branch
history (edits, retries, sibling responses) and is loaded via importTree
rather than the flat messages array.
messages always mirrors the active path for backward-compatibility
(sidebar previews, title generation, adapters that only read flat arrays).
archivedAt?
Section titled “archivedAt?”optional archivedAt?: number;Defined in: packages/core/src/conversations/types.ts:49
When truthy the conversation is archived (hidden from the main list).
pinnedAt?
Section titled “pinnedAt?”optional pinnedAt?: number;Defined in: packages/core/src/conversations/types.ts:51
When truthy the conversation is pinned at the top of the list.
schemaVersion?
Section titled “schemaVersion?”optional schemaVersion?: number;Defined in: packages/core/src/conversations/types.ts:56
Schema version of this record. Absent on legacy data (pre-versioning):
adapters should treat undefined as version 0 and migrate on read.
AparteConversationMeta
Section titled “AparteConversationMeta”Defined in: packages/core/src/conversations/types.ts:64
Lightweight conversation meta — what’s needed to render the sidebar without
loading the full message history. Returned by loadMeta() and stored as a
dedicated row by split-storage adapters.
Properties
Section titled “Properties”id: string;Defined in: packages/core/src/conversations/types.ts:65
title: string;Defined in: packages/core/src/conversations/types.ts:66
createdAt
Section titled “createdAt”createdAt: number;Defined in: packages/core/src/conversations/types.ts:67
updatedAt
Section titled “updatedAt”updatedAt: number;Defined in: packages/core/src/conversations/types.ts:68
archivedAt?
Section titled “archivedAt?”optional archivedAt?: number;Defined in: packages/core/src/conversations/types.ts:69
pinnedAt?
Section titled “pinnedAt?”optional pinnedAt?: number;Defined in: packages/core/src/conversations/types.ts:70
schemaVersion?
Section titled “schemaVersion?”optional schemaVersion?: number;Defined in: packages/core/src/conversations/types.ts:72
Persisted schema version of the row.
AparteAttachmentRow
Section titled “AparteAttachmentRow”Defined in: packages/core/src/conversations/types.ts:81
Persisted attachment with the actual Blob — survives page reloads, unlike
the session-scoped URL.createObjectURL() stored on AparteMessage.
Adapters that split storage MUST keep the blob here and reconstruct the
url on demand.
Properties
Section titled “Properties”id: string;Defined in: packages/core/src/conversations/types.ts:82
convId
Section titled “convId”convId: string;Defined in: packages/core/src/conversations/types.ts:83
msgId: string;Defined in: packages/core/src/conversations/types.ts:84
name: string;Defined in: packages/core/src/conversations/types.ts:85
mimeType
Section titled “mimeType”mimeType: string;Defined in: packages/core/src/conversations/types.ts:86
size: number;Defined in: packages/core/src/conversations/types.ts:87
blob: Blob;Defined in: packages/core/src/conversations/types.ts:88
AparteStorageAdapter
Section titled “AparteStorageAdapter”Defined in: packages/core/src/conversations/types.ts:109
Implement this interface to provide persistence for conversations. All methods are async so any backend (IndexedDB, SQLite WASM, REST API…) can be used. The AparteConversationManager never touches storage directly.
The first three methods (loadAll, save, delete) form the minimum
viable adapter — everything else is optional and lets richer backends
expose split-storage features (fast meta listing, attachment blobs).
What is NOT here, on purpose: memory facts, a settings key/value store, an
artifact gallery index. Each is a product’s own table — the shape of a “memory
fact” or of a settings entry is the app’s decision — and a public contract
carrying one app’s schema binds every other adapter to it. An app that needs
them extends this interface in its own code. Nor is a row’s own bookkeeping: a
folder id, a cached last-message preview, a message count and a token total are
things a store computes for itself, so they live on the adapter’s own row shape
rather than on AparteConversation / AparteConversationMeta.
Methods
Section titled “Methods”loadAll()
Section titled “loadAll()”loadAll(): Promise<AparteConversation[]>;Defined in: packages/core/src/conversations/types.ts:111
Return all stored conversations (full payload), ordered by updatedAt desc.
Returns
Section titled “Returns”Promise<AparteConversation[]>
save()
Section titled “save()”save(conv): Promise<void>;Defined in: packages/core/src/conversations/types.ts:113
Upsert a conversation (create or update).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
conv | AparteConversation |
Returns
Section titled “Returns”Promise<void>
delete()
Section titled “delete()”delete(id): Promise<void>;Defined in: packages/core/src/conversations/types.ts:115
Permanently delete a conversation by id (cascades related rows).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<void>
loadDraft()?
Section titled “loadDraft()?”optional loadDraft(id): Promise<string | null | undefined>;Defined in: packages/core/src/conversations/types.ts:117
What was typed and not sent, with keepDrafts on. Optional, with saveDraft.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<string | null | undefined>
saveDraft()?
Section titled “saveDraft()?”optional saveDraft(id, text): Promise<void>;Defined in: packages/core/src/conversations/types.ts:119
Keep a draft. Must not touch the conversation’s updatedAt. An empty text means none.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
text | string |
Returns
Section titled “Returns”Promise<void>
archive()?
Section titled “archive()?”optional archive(id): Promise<void>;Defined in: packages/core/src/conversations/types.ts:121
Archive a conversation (soft-delete). Optional.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<void>
unarchive()?
Section titled “unarchive()?”optional unarchive(id): Promise<void>;Defined in: packages/core/src/conversations/types.ts:123
Restore an archived conversation. Optional.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<void>
loadMeta()?
Section titled “loadMeta()?”optional loadMeta(): Promise<AparteConversationMeta[]>;Defined in: packages/core/src/conversations/types.ts:132
Fast sidebar listing. Returns lightweight meta only (no messages).
Order is updatedAt desc. Adapters without split storage can omit
this — callers should fall back to loadAll() mapping to meta.
Returns
Section titled “Returns”Promise<AparteConversationMeta[]>
loadFull()?
Section titled “loadFull()?”optional loadFull(id): Promise<AparteConversation | null>;Defined in: packages/core/src/conversations/types.ts:134
Lazy-load a single conversation’s full payload by id.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<AparteConversation | null>
pin()?
Section titled “pin()?”optional pin(id): Promise<void>;Defined in: packages/core/src/conversations/types.ts:136
Pin/unpin (pinnedAt-aware sidebar sort).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<void>
unpin()?
Section titled “unpin()?”optional unpin(id): Promise<void>;Defined in: packages/core/src/conversations/types.ts:137
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”Promise<void>
rename()?
Section titled “rename()?”optional rename(id, title): Promise<void>;Defined in: packages/core/src/conversations/types.ts:139
Update only the conversation title (avoids rewriting messages).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
title | string |
Returns
Section titled “Returns”Promise<void>
loadAttachments()?
Section titled “loadAttachments()?”optional loadAttachments(msgId): Promise<AparteAttachmentRow[]>;Defined in: packages/core/src/conversations/types.ts:144
Persisted attachment blobs for a single message.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
msgId | string |
Returns
Section titled “Returns”Promise<AparteAttachmentRow[]>
Type Aliases
Section titled “Type Aliases”AparteConversationsListener
Section titled “AparteConversationsListener”type AparteConversationsListener = (conversations) => void;Defined in: packages/core/src/conversations/conversation-manager.ts:10
What AparteConversationManager.subscribe calls with the list, on every change.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
conversations | AparteConversation[] |
Returns
Section titled “Returns”void
AparteConversationTitleProvider
Section titled “AparteConversationTitleProvider”type AparteConversationTitleProvider = (text, message) => string | Promise<string>;Defined in: packages/core/src/conversations/conversation-manager.ts:21
Titles a conversation from its first user message.
Receives the message’s text and the message itself, and returns the title —
synchronously or not. An empty answer, or a throw, leaves
the default title (the text as typed), so a titler that fails never loses the
message from the sidebar. Registered with AparteConversationManager.setTitleProvider;
@aparte/plugin-titler binds one to an aparte-titler model.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
text | string |
message | AparteMessage |
Returns
Section titled “Returns”string | Promise<string>
AparteConversationStatus
Section titled “AparteConversationStatus”type AparteConversationStatus = "running" | "waiting";Defined in: packages/core/src/conversations/conversation-status.ts:19
What a conversation is doing, as its row says it: running while an AI answers in it,
waiting while its turn waits on the page — a run paused on a question, an approval or a
browser tool, the one state a conversation keeps after the person has gone elsewhere.
ExportedMessageRepository
Section titled “ExportedMessageRepository”type ExportedMessageRepository = {
headId: string | null;
messages: {
message: AparteMessage;
parentId: string | null;
}[];
};Defined in: packages/core/src/runtime/message-repository.ts:38
Exported format — compatible with serialisation
Properties
Section titled “Properties”headId
Section titled “headId”headId: string | null;Defined in: packages/core/src/runtime/message-repository.ts:39
messages
Section titled “messages”messages: {
message: AparteMessage;
parentId: string | null;
}[];Defined in: packages/core/src/runtime/message-repository.ts:40
message
Section titled “message”message: AparteMessage;parentId
Section titled “parentId”parentId: string | null;Event details
Section titled “Event details”AparteConversationLoadedDetail
Section titled “AparteConversationLoadedDetail”Defined in: packages/core/src/conversations/types.ts:156
Detail payload for aparte-conversation-loaded.
Dispatched by the conversation controller on the chat’s host, bubbling, once a
conversation’s messages are on screen — after a load that succeeded and that the user
did not leave meanwhile. The moment to resume a turn a server loop paused (AparteClient
does it on its own), to scroll or to measure.
aparte-conversation-loaded
Properties
Section titled “Properties”targetId
Section titled “targetId”targetId: string;Defined in: packages/core/src/conversations/types.ts:158
The chat’s host id — the targetId every scoped event carries.
conversationId
Section titled “conversationId”conversationId: string;Defined in: packages/core/src/conversations/types.ts:159