Client — core API
Generated reference for @aparte/core. The client that runs a conversation, the host every framework wrapper binds to, and the stream runners.
On this page
Classes
Section titled “Classes”AparteClient
Section titled “AparteClient”Defined in: packages/core/src/client/aparte-client.ts:307
AparteClient
The “Automatic Transmission” for Aparte. Connects the UI events (aparte-send) to the AI Providers (chat). Handles:
- Listening to send events
- Resolving API keys
- Calling the appropriate Provider
- Streaming the response back to the UI
- Tool use: awaiting handlers and re-calling the provider
Example
Section titled “Example”const client = new AparteClient({
keyResolver: (providerId) => process.env[providerId.toUpperCase() + '_KEY']
});
client.start();Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AparteClient(options?): AparteClient;Defined in: packages/core/src/client/aparte-client.ts:385
A keyResolver becomes a key source on the client’s config at once, before start(),
so everything that needs a key can use it — the model selector’s list included.
autoRegister (on by default) installs core’s built-in renderers on that config.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options | AparteClientOptions |
Returns
Section titled “Returns”Methods
Section titled “Methods”start()
Section titled “start()”start(): void;Defined in: packages/core/src/client/aparte-client.ts:480
Answer the chats: listen on window for aparte-send, aparte-retry, aparte-edit,
aparte-abort and aparte-conversation-loaded. Nothing streams before this is
called. Starting a stopped client puts its keyResolver back on the config.
Returns
Section titled “Returns”void
stop()
Section titled “stop()”stop(): void;Defined in: packages/core/src/client/aparte-client.ts:531
Stop answering: abort the reply in flight, take this client’s keyResolver off the
config, and remove the listeners.
Returns
Section titled “Returns”void
abort()
Section titled “abort()”abort(): void;Defined in: packages/core/src/client/aparte-client.ts:573
Abort the current streaming response and all active tool calls.
Dispatches aparte-message-aborted on the target element.
Returns
Section titled “Returns”void
resumeDeferred()
Section titled “resumeDeferred()”resumeDeferred(target?): Promise<boolean>;Defined in: packages/core/src/client/aparte-client.ts:1983
Answer a turn a server loop paused, when the conversation comes back — a reload, a conversation reopened days later. The last reply’s paused calls (they carry the server’s ticket) are put to the person again, or run in the page, and the loop resumes on the server, into the same bubble.
Called on its own when a conversation manager loads a conversation
(aparte-conversation-loaded); call it yourself after setMessages if you load
conversations another way. Resolves true when a resume ran, false when there
was nothing to resume.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
target? | string | HTMLElement | The chat — an element, or its id. Defaults to the one targetResolver names, else the first on the page. |
Returns
Section titled “Returns”Promise<boolean>
AparteChatHost
Section titled “AparteChatHost”Defined in: packages/core/src/host/aparte-chat-host.ts:166
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AparteChatHost(binding, options?): AparteChatHost;Defined in: packages/core/src/host/aparte-chat-host.ts:203
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
binding | AparteChatHostBinding |
options | AparteChatHostOptions |
Returns
Section titled “Returns”Accessors
Section titled “Accessors”streamingId
Section titled “streamingId”Get Signature
Section titled “Get Signature”get streamingId(): string | null;Defined in: packages/core/src/host/aparte-chat-host.ts:257
Returns
Section titled “Returns”string | null
isStreaming
Section titled “isStreaming”Get Signature
Section titled “Get Signature”get isStreaming(): boolean;Defined in: packages/core/src/host/aparte-chat-host.ts:258
Returns
Section titled “Returns”boolean
conversationController
Section titled “conversationController”Get Signature
Section titled “Get Signature”get conversationController():
| AparteConversationController
| undefined;Defined in: packages/core/src/host/aparte-chat-host.ts:261
The internally-managed conversation controller (created in bind).
Returns
Section titled “Returns”| AparteConversationController
| undefined
Methods
Section titled “Methods”bind()
Section titled “bind()”bind(): () => void;Defined in: packages/core/src/host/aparte-chat-host.ts:216
Install the host-method surface + event listeners and create the conversation controller. Returns a teardown function; call once after the view (viewport + composer) has mounted.
Returns
Section titled “Returns”() => void
unbind()
Section titled “unbind()”unbind(): void;Defined in: packages/core/src/host/aparte-chat-host.ts:242
Returns
Section titled “Returns”void
clearRenderCache()
Section titled “clearRenderCache()”clearRenderCache(): void;Defined in: packages/core/src/host/aparte-chat-host.ts:266
Clear the bubble-render cache (e.g. when the host clears messages externally).
Returns
Section titled “Returns”void
setConversationId()
Section titled “setConversationId()”setConversationId(id): Promise<void>;Defined in: packages/core/src/host/aparte-chat-host.ts:285
Load / switch the active conversation via the controller.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string | null |
Returns
Section titled “Returns”Promise<void>
appendMessage()
Section titled “appendMessage()”appendMessage(message, options?): void;Defined in: packages/core/src/host/aparte-chat-host.ts:382
Append a message optimistically (streaming writes target the new last).
Deliberately does NOT call onMessagesChange (unlike the other mutations):
setMessages updates the wrapper’s OWN render list, but onMessagesChange
is the OUTBOUND “the user changed the list” notification. During an
optimistic append the wrapper’s local list can lag a controlled parent’s
(the parent added a user message that hasn’t propagated back yet), so
echoing the local list to the parent would overwrite the parent’s
authoritative list and drop that message — a real race the Angular wrapper
spec guards (“optimistic-append + parent-push race”). onMessageAppended
is the append-specific signal instead.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
message | AparteMessage |
options? | { historical?: boolean; } |
options.historical? | boolean |
Returns
Section titled “Returns”void
updateMessage()
Section titled “updateMessage()”updateMessage(messageId, updates): void;Defined in: packages/core/src/host/aparte-chat-host.ts:415
Atomic partial update of a message by id.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messageId | string |
updates | Partial<AparteMessage> |
Returns
Section titled “Returns”void
updateLastMessage()
Section titled “updateLastMessage()”updateLastMessage(content, options?): void;Defined in: packages/core/src/host/aparte-chat-host.ts:441
Append/replace the last message content (streaming text).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
content | string |
options? | { append?: boolean; } |
options.append? | boolean |
Returns
Section titled “Returns”void
addSegment()
Section titled “addSegment()”addSegment(segment): void;Defined in: packages/core/src/host/aparte-chat-host.ts:454
Add a segment to the last message (immediate bubble + state sync).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
segment | AparteSegment |
Returns
Section titled “Returns”void
updateSegment()
Section titled “updateSegment()”updateSegment(segmentId, updates): void;Defined in: packages/core/src/host/aparte-chat-host.ts:485
Update a segment in the last message in place.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
segmentId | string |
updates | Partial<AparteSegment> |
Returns
Section titled “Returns”void
removeSegment()
Section titled “removeSegment()”removeSegment(segmentId): void;Defined in: packages/core/src/host/aparte-chat-host.ts:505
Remove a transient segment (a status row the host added itself).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
segmentId | string |
Returns
Section titled “Returns”void
appendToSegment()
Section titled “appendToSegment()”appendToSegment(segmentId, content): void;Defined in: packages/core/src/host/aparte-chat-host.ts:538
Append text to a segment’s content in the last message — the streaming path for thinking blocks, tool pills and any segment that grows token by token.
Two writes, deliberately asymmetric:
- straight into the bubble, every chunk, so the text appears immediately —
the same direct path
appendTokenuses; - into the framework’s message list, coalesced to once per frame.
It used to do only (2), synchronously: a full list rebuild plus
setMessages + onMessagesChange for every chunk, i.e. one complete
framework render per token. At 60 tok/s from a local model that is unusable,
and nothing in the imperative API hinted that appendToSegment cost so much
more than injectTokenStream. Consumers had to write their own rAF batcher.
Any structural change flushes the buffer first (see _flushStreamState), so ordering is never observable.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
segmentId | string |
content | string |
Returns
Section titled “Returns”void
getMessages()
Section titled “getMessages()”getMessages(): AparteMessage[];Defined in: packages/core/src/host/aparte-chat-host.ts:642
Read the current message list.
Returns
Section titled “Returns”clearMessages()
Section titled “clearMessages()”clearMessages(options?): void;Defined in: packages/core/src/host/aparte-chat-host.ts:651
Clear all messages + reset viewport state. The option travels to the viewport
untouched: a compaction passes { revokeAttachments: false } because it re-appends
the turns it keeps and revokes the dropped ones’ object URLs itself — under a
framework wrapper this bridge used to drop the argument, and every surviving
attachment came back broken.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options? | { revokeAttachments?: boolean; } |
options.revokeAttachments? | boolean |
Returns
Section titled “Returns”void
addBranch()
Section titled “addBranch()”addBranch(messageId): number;Defined in: packages/core/src/host/aparte-chat-host.ts:658
Create a new branch from a message (returns the new sibling index).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messageId | string |
Returns
Section titled “Returns”number
addSiblingOf()
Section titled “addSiblingOf()”addSiblingOf(existingId, newMessage): string | null;Defined in: packages/core/src/host/aparte-chat-host.ts:664
Add a sibling of an existing message (returns the new id).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
existingId | string |
newMessage | AparteMessage |
Returns
Section titled “Returns”string | null
truncateFrom()
Section titled “truncateFrom()”truncateFrom(messageId): void;Defined in: packages/core/src/host/aparte-chat-host.ts:670
Remove a message and all descendants (edit flow).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messageId | string |
Returns
Section titled “Returns”void
truncateResponsesAfter()
Section titled “truncateResponsesAfter()”truncateResponsesAfter(userMessageId): void;Defined in: packages/core/src/host/aparte-chat-host.ts:680
Keep up to and including a user message, drop later responses (retry).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
userMessageId | string |
Returns
Section titled “Returns”void
streamTokens()
Section titled “streamTokens()”streamTokens(messageId, tokens): Promise<void>;Defined in: packages/core/src/host/aparte-chat-host.ts:704
Drive a manual token stream into the viewport. Sets the streaming guard, appends each token, completes the message at the end. Per-framework wrappers adapt their native stream type (RxJS Observable, AsyncIterable, ReadableStream) into this.
Each token reaches the bubble immediately and the framework’s message list
is synced once per frame (same discipline as appendToSegment),
with a guaranteed flush before completion and on abort. Before that sync
existed the two disagreed: the DOM had the reply, the framework list still
held content: '' — so any re-render from state wiped it, and a custom
bubble (which renders from that state) showed nothing at all.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messageId | string |
tokens | AsyncIterable<string> |
Returns
Section titled “Returns”Promise<void>
stopTokenStream()
Section titled “stopTokenStream()”stopTokenStream(): void;Defined in: packages/core/src/host/aparte-chat-host.ts:790
Abort an in-flight streamTokens loop.
Returns
Section titled “Returns”void
syncBubbles()
Section titled “syncBubbles()”syncBubbles(): void;Defined in: packages/core/src/host/aparte-chat-host.ts:808
Reconcile rendered bubbles with the current message list. The framework calls this from its reactive message-change hook after rendering; the last message is always re-synced (streaming), others only once.
Returns
Section titled “Returns”void
syncRepoFromMessages()
Section titled “syncRepoFromMessages()”syncRepoFromMessages(): void;Defined in: packages/core/src/host/aparte-chat-host.ts:824
Rebuild the viewport’s internal repo from the message list before branch operations (streaming fills the framework state but not the repo).
Returns
Section titled “Returns”void
Functions
Section titled “Functions”createAgentStreamRunner()
Section titled “createAgentStreamRunner()”function createAgentStreamRunner(options): AparteStreamRunner;Defined in: packages/core/src/client/agent-runner.ts:37
An AparteStreamRunner that runs AparteClient’s loop on YOUR server — the one
createAparteAgentHandler serves — and replays its events here, where the client’s
adapter draws them exactly as it draws a loop run in the page.
const client = new AparteClient({ streamRunner: createAgentStreamRunner({ endpoint: '/api/agent' }) });The page needs no provider of its own: the server runs the model. A provider and model the page selects anyway travel with the turn, and the server uses them.
A pipe, nothing more. It sees no message and no segment, so it opens no panel and runs
no tool: when the server suspends a run, the CLIENT asks the person or runs the browser
tool, then calls this runner again with the answers in deferral — the same path it
takes when a conversation with a paused call is reloaded days later.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options | AgentStreamRunnerOptions |
Returns
Section titled “Returns”createStreamAdapter()
Section titled “createStreamAdapter()”function createStreamAdapter(opts): StreamRunEmitter;Defined in: packages/core/src/client/stream-adapter.ts:104
Build the event → DOM adapter for one streamed message. Returns a synchronous
AparteStreamRunEmitter to hand to runStreamAgent as its emitter.
Reproduces the inline loop’s targetElement.* call sequence exactly (validated
by the engine parity test against the real loop).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
opts | CreateStreamAdapterOptions |
Returns
Section titled “Returns”StreamRunEmitter
readableToAsyncIterable()
Section titled “readableToAsyncIterable()”function readableToAsyncIterable(stream, signal): AsyncIterable<AparteStreamEvent>;Defined in: packages/core/src/client/stream-adapter.ts:323
Bridge a ReadableStream (what the transport returns) to the
AsyncIterable<AparteStreamEvent> runStreamAgent consumes, cancelling the
reader synchronously on abort so a user “stop” cuts the in-flight read.
Used by AparteClient when building transportCall for the
runner. Mirrors the inline loop’s reader.read() loop + reader.cancel().
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
stream | ReadableStream<AparteStreamEvent> |
signal | AbortSignal |
Returns
Section titled “Returns”AsyncIterable<AparteStreamEvent>
Interfaces
Section titled “Interfaces”AgentStreamRunnerOptions
Section titled “AgentStreamRunnerOptions”Defined in: packages/core/src/client/agent-runner.ts:7
Properties
Section titled “Properties”endpoint
Section titled “endpoint”endpoint: string;Defined in: packages/core/src/client/agent-runner.ts:9
The route that serves createAparteAgentHandler, e.g. /api/agent.
headers?
Section titled “headers?”optional headers?:
| Record<string, string>
| (() =>
| Record<string, string>
| Promise<Record<string, string>>);Defined in: packages/core/src/client/agent-runner.ts:11
Sent with every request; a function is called per request (a fresh token each time).
fetch?
Section titled “fetch?”optional fetch?: {
(input, init?): Promise<Response>;
(input, init?): Promise<Response>;
};Defined in: packages/core/src/client/agent-runner.ts:13
Call Signature
Section titled “Call Signature”(input, init?): Promise<Response>;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input | RequestInfo | URL |
init? | RequestInit |
Returns
Section titled “Returns”Promise<Response>
Call Signature
Section titled “Call Signature”(input, init?): Promise<Response>;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input | string | Request | URL |
init? | RequestInit |
Returns
Section titled “Returns”Promise<Response>
Default
Section titled “Default”the global fetch
credentials?
Section titled “credentials?”optional credentials?: RequestCredentials;Defined in: packages/core/src/client/agent-runner.ts:15
For a cross-origin endpoint that authenticates by cookie.
AparteClientOptions
Section titled “AparteClientOptions”Defined in: packages/core/src/client/aparte-client.ts:98
Configuration options for AparteClient
Properties
Section titled “Properties”keyResolver?
Section titled “keyResolver?”optional keyResolver?: (providerId) =>
| string
| Record<string, string>
| Promise<string | Record<string, string> | null | undefined>
| null
| undefined;Defined in: packages/core/src/client/aparte-client.ts:103
Function to resolve API keys for a given provider. Can return a string (key) or a full configuration object.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
providerId | string |
Returns
Section titled “Returns”| string
| Record<string, string>
| Promise<string | Record<string, string> | null | undefined>
| null
| undefined
approvalResolver?
Section titled “approvalResolver?”optional approvalResolver?: AparteToolApprovalResolver;Defined in: packages/core/src/client/aparte-client.ts:122
Custom human-in-the-loop approval resolver for tools marked
needsApproval. Without one, the gate asks at the composer through
requestUserInput, like every other request for the user. Inject this to
decide from the call itself — it receives (call, signal) — or to drive
approval from a headless source (CLI / webhook) with no DOM.
It owns the WHOLE decision: with one injected, an AparteApprovalPolicy
registered through setApprovalPolicy() — and therefore
@aparte/plugin-approval’s modes — is not consulted at all, neither for the
gate nor for the answer, and the tool’s own needsApproval decides which
calls reach this resolver. Rule on the call here, or drop this option and use
a policy; do not expect both.
On a refusal it may return an instruction (the user’s words) or a reason
(nobody spoke), which the model reads as the tool result.
streamRunner?
Section titled “streamRunner?”optional streamRunner?: AparteStreamRunner;Defined in: packages/core/src/client/aparte-client.ts:131
The stream-loop runner. Default: @aparte/engine’s runStreamAgent, rendered
through the core adapter (createStreamAdapter). Set it to wrap that loop
— (opts) => runStreamAgent({ ...opts, onHistoryAppend }) for a host that owns
its transcript — or to replace it with a loop of your own that emits the same
events. Same injection pattern as approvalResolver. See AparteStreamRunner.
requestInterceptor?
Section titled “requestInterceptor?”optional requestInterceptor?: (request) =>
| AparteChatRequest
| Promise<AparteChatRequest>;Defined in: packages/core/src/client/aparte-client.ts:136
Optional request interceptor to modify the chat request before sending.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
request | AparteChatRequest |
Returns
Section titled “Returns”| AparteChatRequest
| Promise<AparteChatRequest>
autoRegister?
Section titled “autoRegister?”optional autoRegister?: boolean;Defined in: packages/core/src/client/aparte-client.ts:148
Whether to register core’s default segment renderers.
Rarely needed either way: the built-ins install themselves the first time a
segment needs one, so leaving this alone just works. Set it to false to
keep them out entirely — a decision that is remembered, so nothing installs
them later; register your own with registerSegmentRenderer. Do it at
startup, before the first segment renders.
Default
Section titled “Default”truehistory?
Section titled “history?”optional history?:
| "none"
| "viewport"
| ((viewportMessages) => AparteChatMessage[]);Defined in: packages/core/src/client/aparte-client.ts:161
Conversation history strategy:
- ‘viewport’ (default) — sends every user/assistant turn up to the last answered
one. A turn that errored, or is still in flight
(‘streaming’ / ‘pending’), is held back and does not move
that cutoff; a turn a host seeded with NO
statuscounts as answered, so a restored or server-rendered transcript goes out as history without inventing a status for it. - ‘none’ — sends only the current message (original behavior)
- function — custom: receives viewport messages, returns AparteChatMessage[]
targetResolver?
Section titled “targetResolver?”optional targetResolver?: () => HTMLElement | null;Defined in: packages/core/src/client/aparte-client.ts:171
Optional resolver that returns the host element exposing appendMessage.
Use this when the default event-bubble walk cannot reach the host
(e.g. Angular re-renders detach the input element mid-flight).
Returns
Section titled “Returns”HTMLElement | null
Example
Section titled “Example”targetResolver: () => document.querySelector('aparte-chat')scopeToTargetId?
Section titled “scopeToTargetId?”optional scopeToTargetId?: string;Defined in: packages/core/src/client/aparte-client.ts:185
Scope this client to a specific target element id.
When set, the client will only handle aparte-send, aparte-retry, aparte-edit
and aparte-abort events whose detail.targetId matches this id.
This allows multiple AparteClient instances (one per conversation) to coexist
on the same page without interfering with each other.
Example
Section titled “Example”// Two independent conversations:
new AparteClient({ scopeToTargetId: 'chat-left' }).start();
new AparteClient({ scopeToTargetId: 'chat-right' }).start();maxTurns?
Section titled “maxTurns?”optional maxTurns?: number;Defined in: packages/core/src/client/aparte-client.ts:193
Maximum number of agentic tool-call loop turns before the loop is forcibly
stopped and an error segment is shown. Prevents infinite loops.
Individual tools can override this via AparteTool.maxTurns.
Default
Section titled “Default”10toolTimeoutMs?
Section titled “toolTimeoutMs?”optional toolTimeoutMs?: number;Defined in: packages/core/src/client/aparte-client.ts:199
Per-call ceiling (ms) for a tool handler to resolve before its signal is
aborted. Defaults to 5 minutes — the same default, and the same option name,
as runStreamAgent, so the value means one thing whichever loop runs.
echoUserMessage?
Section titled “echoUserMessage?”optional echoUserMessage?: boolean;Defined in: packages/core/src/client/aparte-client.ts:214
Whether a send appends the optimistic USER bubble before the reply streams.
Default true — and opt-OUT on purpose: the bubble used to be the host’s job
on every path, everyone wrote the same aparte-send handler, and whoever
forgot shipped a chat where the person cannot see what they typed. It
compiles, it streams, and nothing errors.
Pass false when the host owns its transcript and appends the user message
itself — the four framework wrappers do (their ConversationController is
that owner) and pass it. The wire cannot double either way: the history
builder already excludes trailing unanswered user messages.
rawFileInject?
Section titled “rawFileInject?”optional rawFileInject?: "none" | "all" | "images-only";Defined in: packages/core/src/client/aparte-client.ts:234
Controls which files attached by the user are injected as raw content parts in the LLM request.
'all'(default) — images as base64, text files as code-fenced text'images-only'— only images are injected; text/binary documents are left for the application layer (e.g. a RAG pipeline) to handle'none'— no files are injected as content parts; ALL file types (including images) are routed to the application layer. Used when images go through a captioning pipeline before RAG ingest, so the chat context only ever sees retrieved text — never raw image bytes. Saves bytes on every turn and matches the offline-first intent (read file once at upload, retrieve text-only forever after).
Set 'images-only' when a requestInterceptor retrieves relevant
document chunks and injects them as a system message instead, to avoid
flooding the context window with full file contents.
fileInjectFilter?
Section titled “fileInjectFilter?”optional fileInjectFilter?: (file) => boolean;Defined in: packages/core/src/client/aparte-client.ts:247
Per-file veto on top of rawFileInject: called for each file the
mode would inject; return false to keep that file out of the request.
The file still rides on the aparte-send event for the application
layer (upload, RAG). Use it to block sensitive names while keeping the
default inline UX:
fileInjectFilter: (f) => !/(^|\.)env$|\.(pem|key)$/i.test(f.name)Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
file | File |
Returns
Section titled “Returns”boolean
config?
Section titled “config?”optional config?: AparteConfig;Defined in: packages/core/src/client/aparte-client.ts:255
Config this client reads (providers, model selection, tools, system
prompt). Defaults to aparteGlobalConfig. Pass a host’s
instance config when scoping a client to one chat among several
(pairs with scopeToTargetId).
StreamAdapterTarget
Section titled “StreamAdapterTarget”Defined in: packages/core/src/client/stream-adapter.ts:71
The imperative surface the adapter drives (subset of AparteChatTargetElement).
Every method is optional so a partial/mock target degrades gracefully.
Methods
Section titled “Methods”updateMessage()?
Section titled “updateMessage()?”optional updateMessage(id, updates): void;Defined in: packages/core/src/client/stream-adapter.ts:72
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
updates | Partial<AparteMessage> |
Returns
Section titled “Returns”void
updateLastMessage()?
Section titled “updateLastMessage()?”optional updateLastMessage(content, options?): void;Defined in: packages/core/src/client/stream-adapter.ts:73
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
content | string |
options? | { append?: boolean; } |
options.append? | boolean |
Returns
Section titled “Returns”void
addSegment()?
Section titled “addSegment()?”optional addSegment(segment): void;Defined in: packages/core/src/client/stream-adapter.ts:74
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
segment | AparteSegment |
Returns
Section titled “Returns”void
updateSegment()?
Section titled “updateSegment()?”optional updateSegment(segmentId, updates): void;Defined in: packages/core/src/client/stream-adapter.ts:75
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
segmentId | string |
updates | Partial<AparteSegment> |
Returns
Section titled “Returns”void
typeName()?
Section titled “typeName()?”optional typeName(text): void;Defined in: packages/core/src/client/stream-adapter.ts:76
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
text | string |
Returns
Section titled “Returns”void
setUsage()?
Section titled “setUsage()?”optional setUsage(id, usage): void;Defined in: packages/core/src/client/stream-adapter.ts:77
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
usage | AparteUsage |
Returns
Section titled “Returns”void
dispatchEvent()
Section titled “dispatchEvent()”dispatchEvent(event): boolean;Defined in: packages/core/src/client/stream-adapter.ts:78
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
event | Event |
Returns
Section titled “Returns”boolean
CreateStreamAdapterOptions
Section titled “CreateStreamAdapterOptions”Defined in: packages/core/src/client/stream-adapter.ts:81
Properties
Section titled “Properties”target
Section titled “target”target: StreamAdapterTarget;Defined in: packages/core/src/client/stream-adapter.ts:83
The chat target element the events are rendered onto.
config
Section titled “config”config: AparteConfig;Defined in: packages/core/src/client/stream-adapter.ts:85
Config for tool-renderer lookup + per-tool style injection.
messageId
Section titled “messageId”messageId: string;Defined in: packages/core/src/client/stream-adapter.ts:87
The streamed assistant message id (carried in the run events).
targetId?
Section titled “targetId?”optional targetId?: string;Defined in: packages/core/src/client/stream-adapter.ts:95
The id of the CHAT the target belongs to, stamped on every lifecycle event the
adapter dispatches. The target is whatever renders — a shell’s .viewport,
which has no id of its own — so it cannot be read off the target, and an
unstamped event is read as “for every chat on the page”. Omitted, the dispatcher
falls back to target.id, which is right for the viewport-only chat shape.
AparteChatHostBinding
Section titled “AparteChatHostBinding”Defined in: packages/core/src/host/aparte-chat-host.ts:80
Everything AparteChatHost needs from the framework, expressed without any
framework types. Each wrapper (Angular signals, React state, Vue refs, Svelte
stores) implements these ~10 closures over its own reactive message list.
Properties
Section titled “Properties”hostId
Section titled “hostId”readonly hostId: string;Defined in: packages/core/src/host/aparte-chat-host.ts:82
Stable id for the host element (used as targetId for scoped events).
readonly host: HTMLElement;Defined in: packages/core/src/host/aparte-chat-host.ts:84
The element AparteClient drives + that emits lifecycle/path events.
viewport
Section titled “viewport”readonly viewport: HTMLElement | null;Defined in: packages/core/src/host/aparte-chat-host.ts:86
The <aparte-chat-viewport> element (branch ops, token append, bubbles).
Methods
Section titled “Methods”getMessages()
Section titled “getMessages()”getMessages(): AparteMessage[];Defined in: packages/core/src/host/aparte-chat-host.ts:89
Read the current message list (a snapshot).
Returns
Section titled “Returns”setMessages()
Section titled “setMessages()”setMessages(messages): void;Defined in: packages/core/src/host/aparte-chat-host.ts:91
Replace the framework’s message list (triggers its re-render).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messages | AparteMessage[] |
Returns
Section titled “Returns”void
onMessagesChange()?
Section titled “onMessagesChange()?”optional onMessagesChange(messages): void;Defined in: packages/core/src/host/aparte-chat-host.ts:94
Notify the consumer that messages changed (drives messagesChange).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messages | AparteMessage[] |
Returns
Section titled “Returns”void
onMessageAppended()?
Section titled “onMessageAppended()?”optional onMessageAppended(message): void;Defined in: packages/core/src/host/aparte-chat-host.ts:96
Notify the consumer a message was appended (drives messageAppended).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
message | AparteMessage |
Returns
Section titled “Returns”void
onTypingChange()?
Section titled “onTypingChange()?”optional onTypingChange(isTyping): void;Defined in: packages/core/src/host/aparte-chat-host.ts:98
Flip the typing/“thinking” indicator.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
isTyping | boolean |
Returns
Section titled “Returns”void
onStreamingChange()?
Section titled “onStreamingChange()?”optional onStreamingChange(streamingId): void;Defined in: packages/core/src/host/aparte-chat-host.ts:100
Streaming target id changed (drives isStreaming).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
streamingId | string | null |
Returns
Section titled “Returns”void
afterRender()
Section titled “afterRender()”afterRender(cb): void;Defined in: packages/core/src/host/aparte-chat-host.ts:102
Run a callback after the framework has applied the latest render.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb | () => void |
Returns
Section titled “Returns”void
resetComposer()?
Section titled “resetComposer()?”optional resetComposer(): void;Defined in: packages/core/src/host/aparte-chat-host.ts:104
Reset the composer (clear text/attachments) on conversation swap.
Returns
Section titled “Returns”void
onLoadingChange()?
Section titled “onLoadingChange()?”optional onLoadingChange(loading): void;Defined in: packages/core/src/host/aparte-chat-host.ts:116
The transcript is on its way (true) or has arrived (false): the controller’s
wait, forwarded so a wrapper that draws its own DOM can draw the wait — the
skeleton, the empty state kept off, the composer disabled.
Declaring it makes the wait YOURS, aria-busy included: the host stops writing the
viewport’s loading attribute and leaves it to you, because two writers with two
ideas of when the wait ends is how a wrapper came to draw a skeleton over a
transcript the attribute said had arrived. A binding without this callback keeps
the attribute written for it.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
loading | boolean |
Returns
Section titled “Returns”void
AparteChatHostOptions
Section titled “AparteChatHostOptions”Defined in: packages/core/src/host/aparte-chat-host.ts:119
Properties
Section titled “Properties”layoutTransitionMs?
Section titled “layoutTransitionMs?”optional layoutTransitionMs?: number;Defined in: packages/core/src/host/aparte-chat-host.ts:121
Forwarded to viewport.configure({ layoutTransitionMs }) when > 0.
conversationId?
Section titled “conversationId?”optional conversationId?: string | null;Defined in: packages/core/src/host/aparte-chat-host.ts:123
Initial conversation id to load when the controller is created.
onConversationCreated?
Section titled “onConversationCreated?”optional onConversationCreated?: (id) => void;Defined in: packages/core/src/host/aparte-chat-host.ts:125
Called when the controller lazily creates a conversation on first send.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id | string |
Returns
Section titled “Returns”void
config?
Section titled “config?”optional config?: AparteConfig;Defined in: packages/core/src/host/aparte-chat-host.ts:133
Instance config for this chat. When provided, bind marks the host
element as a [data-aparte-host] boundary so every Aparte component inside it
(bubbles, composer, renderers) resolves THIS config instead of the global
aparteGlobalConfig — the seam that lets several independently-configured chats
coexist on one page. Omit to keep the global-config behaviour.
Type Aliases
Section titled “Type Aliases”AparteToolApprovalResolver
Section titled “AparteToolApprovalResolver”type AparteToolApprovalResolver = (call, signal) => Promise<{
approved: boolean;
payload?: unknown;
instruction?: string;
reason?: string;
}>;Defined in: packages/core/src/client/aparte-client.ts:69
Resolves a human-in-the-loop tool approval for a needsApproval tool call.
Resolves { approved, payload? }; the signal aborts a pending decision.
It receives the CALL, not just its id. You cannot ask a person “run this?” without naming what — the built-in channel needs the tool’s name for its question, and an id alone forced a lookup table filled by one event and read by another, which is the shape that breaks in silence.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
call | { id: string; name: string; input: Record<string, unknown>; } |
call.id | string |
call.name | string |
call.input | Record<string, unknown> |
signal | AbortSignal |
Returns
Section titled “Returns”Promise<{
approved: boolean;
payload?: unknown;
instruction?: string;
reason?: string;
}>
AparteStreamRunEvent
Section titled “AparteStreamRunEvent”type AparteStreamRunEvent = StreamRunEvent;Defined in: packages/core/src/client/stream-adapter.ts:40
The DOM-free run events @aparte/engine’s runStreamAgent emits — engine’s
StreamRunEvent, under core’s name. See packages/engine/src/agent/stream-events.ts
for the per-event _streamLoop mapping notes.
AparteStreamRunEmitter
Section titled “AparteStreamRunEmitter”type AparteStreamRunEmitter = StreamRunEmitter;Defined in: packages/core/src/client/stream-adapter.ts:43
Synchronous, ordered event sink — engine’s StreamRunEmitter.
AparteStreamRunOptions
Section titled “AparteStreamRunOptions”type AparteStreamRunOptions = StreamRunOptions;Defined in: packages/core/src/client/stream-adapter.ts:52
Options for an injected AparteStreamRunner — engine’s StreamRunOptions.
AparteClient builds these from its config / provider / transport and hands them
to the runner; core’s request, message and tool types are assignable to the
structural ones the engine declares, and that assignment is checked where it is
made rather than in a guard beside it.
AparteStreamRunner
Section titled “AparteStreamRunner”type AparteStreamRunner = (opts) => Promise<StreamUsage | undefined>;Defined in: packages/core/src/client/stream-adapter.ts:65
A headless structured-stream loop injected via AparteClientOptions.streamRunner
— the seam by which a host wraps or replaces the loop AparteClient runs,
which is @aparte/engine’s runStreamAgent by default.
runStreamAgent IS this type — pass it, do not cast it. An earlier version of this
comment advised a cast “if the duck-typed shapes don’t line up”, which is how the
two packages’ message types drifted apart unnoticed and shipped a
streamRunner: runStreamAgent that did not compile on five docs pages and a
README. The alias makes that drift a typecheck error in the composition itself.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
opts | AparteStreamRunOptions |
Returns
Section titled “Returns”Promise<StreamUsage | undefined>