Skip to content

Messages and segments — core API

Generated reference for @aparte/core. A message and the segments it is made of, the parser that builds them from a stream, the renderers that draw them, and the errors.

On this page

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:93

ts
new AparteStreamParser(options?): AparteStreamParser;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:109

ParameterType
optionsAparteStreamParserOptions

AparteStreamParser

ts
parse(chunk): AparteParserResult;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:131

Parse a chunk of streamed content Call this for each chunk received from the LLM

ParameterType
chunkstring

AparteParserResult

ts
finalize(): AparteSegment[];

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:164

Finalize parsing - flush any remaining content as text

AparteSegment[]

ts
reset(): void;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:210

Reset parser state

void

ts
getState(): Readonly<AparteParserState>;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:218

Get current parser state (for debugging/inspection)

Readonly<AparteParserState>


Defined in: packages/core/src/types/errors.ts:39

  • Error
ts
new AparteError(
   message, 
   code, 
   data?, 
   originalError?, 
   httpStatus?): AparteError;

Defined in: packages/core/src/types/errors.ts:40

ParameterType
messagestring
codeAparteErrorCode
data?Record<string, unknown>
originalError?unknown
httpStatus?number

AparteError

ts
Error.constructor
ts
message: string;

Defined in: packages/core/src/types/errors.ts:41

ts
Error.message
ts
code: AparteErrorCode;

Defined in: packages/core/src/types/errors.ts:42

ts
optional data?: Record<string, unknown>;

Defined in: packages/core/src/types/errors.ts:43

ts
optional originalError?: unknown;

Defined in: packages/core/src/types/errors.ts:44

ts
optional httpStatus?: number;

Defined in: packages/core/src/types/errors.ts:45

ts
static codeForStatus(status): AparteErrorCode | undefined;

Defined in: packages/core/src/types/errors.ts:56

The code an HTTP status stands for — the table the enum’s own comments promise. undefined for a status the enum does not name (a 404 can be a wrong model or a wrong URL; the message says which, a code would guess).

ParameterType
statusnumber | undefined

AparteErrorCode | undefined

ts
static from(
   error, 
   defaultCode?, 
   defaultStatus?): AparteError;

Defined in: packages/core/src/types/errors.ts:68

ParameterTypeDefault value
errorunknownundefined
defaultCodeAparteErrorCodeAparteErrorCode.UNKNOWN_ERROR
defaultStatus?numberundefined

AparteError

ts
function parseAparteEventStream(stream): ReadableStream<AparteStreamEvent>;

Defined in: packages/core/src/parsers/aparte-event-stream.ts:15

ParameterType
streamReadableStream<Uint8Array<ArrayBufferLike>>

ReadableStream<AparteStreamEvent>


ts
function parseMarkdownToSegments(content, options?): AparteSegment[];

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:717

Parse a complete markdown string into segments Use this for non-streaming scenarios

ParameterType
contentstring
options?AparteStreamParserOptions

AparteSegment[]


ts
function renderCitations(root, segment): void;

Defined in: packages/core/src/renderers/citations.ts:260

Draw the chips of a text segment’s citations in its rendered Markdown. Idempotent: the same segment drawn again changes nothing; text written anew (a reply streaming) gets its chips again, keeping the focus and an open card on the chip that replaces theirs. Call it after writing a segment’s Markdown into an element of your own.

ParameterType
rootElement
segmentAparteTextSegment

void


ts
function renderCodeLanguages(root, options?): void;

Defined in: packages/core/src/renderers/code-languages.ts:502

Draw every placeholder under root whose language has a renderer.

Core calls it wherever it writes Markdown or a code block; call it yourself after writing a provider’s HTML into an element of your own (a custom segment renderer). Idempotent and cheap when nothing changed, and a no-op where no renderer is registered.

ParameterType
rootElement
optionsAparteRenderCodeLanguagesOptions

void


ts
function toToolCallView<I, R>(segment): AparteToolCallView<I, R>;

Defined in: packages/core/src/renderers/mounted-renderer.ts:36

The fields of a call a card draws from, read from its segment.

Type ParameterDefault type
Iunknown
Runknown
ParameterType
segmentAparteToolCallSegment

AparteToolCallView<I, R>


ts
function defineMountedToolRenderer(mount): AparteToolRenderer;

Defined in: packages/core/src/renderers/mounted-renderer.ts:70

A tool renderer from a mount function: register it with registerToolRenderer (or overrideToolRenderer, to take it off again later).

ParameterType
mountAparteToolMount

AparteToolRenderer

ts
aparteGlobalConfig.registerToolRenderer('get_weather', defineMountedToolRenderer((host, view) => {
  const card = document.createElement('weather-card');
  card.data = view;
  host.append(card);
  return { update: (next) => { card.data = next; }, destroy: () => card.remove() };
}));

ts
function defineMountedSegmentRenderer<T>(type, mount): AparteSegmentRenderer<T>;

Defined in: packages/core/src/renderers/mounted-renderer.ts:95

A segment renderer from a mount function, for your own segment type: register it with registerSegmentRenderer (or overrideSegmentRenderer).

Type Parameter
T extends AparteSegmentBase
ParameterType
typestring
mountAparteSegmentMount<T>

AparteSegmentRenderer<T>


ts
function registerSegmentRenderer<T>(renderer, config?): void;

Defined in: packages/core/src/renderers/segment-renderers.ts:110

Register a segment renderer.

config defaults to the ambient render config, which at app startup — no element, no active render — is the global singleton. That is the right default: a chat with its own config inherits global registrations. Pass a config explicitly only to give ONE chat a renderer the others must not have.

Type Parameter
T extends AparteSegmentBase
ParameterType
rendererAparteSegmentRenderer<T>
configAparteConfig

void


ts
function overrideSegmentRenderer<T>(renderer, config?): () => void;

Defined in: packages/core/src/renderers/segment-renderers.ts:137

Put renderer over whatever draws its type, and get back the function that takes it off again — the registration a component makes for as long as it is mounted.

Overrides stack per type. The function restores what was there before THIS override; taking off one that is no longer on top changes nothing on screen, so of two components declaring the same type the newer wins and unmounting the older keeps it. When the last one goes, the type is drawn by what drew it before the first — another registration, or core’s own renderer for a built-in type like code or text. Segments on screen follow each change. The returned function is safe to call twice.

Type Parameter
T extends AparteSegmentBase
ParameterType
rendererAparteSegmentRenderer<T>
configAparteConfig

() => void


ts
function declineDefaultRenderers(config?): void;

Defined in: packages/core/src/renderers/segment-renderers.ts:190

Remember that the app declined the built-in renderers, so installDefaultRenderersOnce stays out of the way for good.

AparteClient({ autoRegister: false }) is the one caller. Without this latch the lazy install below would quietly turn that option into a no-op.

ParameterType
configAparteConfig

void


ts
function installDefaultRenderersOnce(config?): void;

Defined in: packages/core/src/renderers/segment-renderers.ts:208

Fill in the built-in renderers for the types nobody has claimed — called by the bubble the first time a segment has no renderer.

Why lazily and not at import time: registerDefaultRenderers() is called by new AparteClient(), and an app on the bring-your-own-loop path — the one the guide tells you not to construct a client on — never makes that call. Without this sweep it would render [Unknown segment type: text] for every reply, with bubbles, streaming and scrolling all working, which reads as a bug in the consumer’s own loop rather than as a missing call.

Strictly additive: a type someone registered themselves is never replaced, so a custom text renderer survives the sweep triggered by a code segment.

ParameterType
configAparteConfig

void


ts
function unregisterSegmentRenderer(type, config?): void;

Defined in: packages/core/src/renderers/segment-renderers.ts:222

Unregister a segment renderer. Segments of this type on screen are drawn again by what resolves now (the global registration, for an instance config), or left unrendered.

ParameterType
typestring
configAparteConfig

void


ts
function getSegmentRenderer(type, config?): 
  | AparteSegmentRenderer<AparteSegmentBase>
  | undefined;

Defined in: packages/core/src/renderers/segment-renderers.ts:232

Get renderer for a segment type

ParameterType
typestring
configAparteConfig

| AparteSegmentRenderer<AparteSegmentBase> | undefined


ts
function getAllRenderers(config?): readonly AparteSegmentRenderer<AparteSegmentBase>[];

Defined in: packages/core/src/renderers/segment-renderers.ts:242

Get all registered renderers

ParameterType
configAparteConfig

readonly AparteSegmentRenderer<AparteSegmentBase>[]


ts
function collectRendererStyles(config?): string;

Defined in: packages/core/src/renderers/segment-renderers.ts:252

Collect all renderer styles for one config.

Its OWN renderers, not the inherited view: a config that inherits the global’s renderers also inherits their stylesheet, which the global already injected.

ParameterType
configAparteConfig

string


ts
function registerDefaultRenderers(config?): void;

Defined in: packages/core/src/renderers/segment-renderers.ts:333

ParameterType
configAparteConfig

void


ts
function contentToText(content): string;

Defined in: packages/core/src/types/chat.ts:43

Extract plain text from a string | AparteContentPart[] content value. Use this in providers and app-layer code whenever you need the text-only representation.

ParameterType
contentstring | AparteContentPart[]

string


Defined in: packages/core/src/parsers/aparte-stream-parser.ts:27

One inline thinking-block delimiter pair (open/close tag).

ts
start: string;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:28

ts
end: string;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:29


Defined in: packages/core/src/parsers/aparte-stream-parser.ts:32

ts
optional thinkingDelimiters?: 
  | AparteThinkingDelimiterPair
  | AparteThinkingDelimiterPair[];

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:41

Inline thinking-block delimiters — for a model that streams its reasoning inline in the content (rather than on a separate reasoning channel). Accepts one pair or several; the parser opens a thinking segment at whichever pair appears first. Default recognizes BOTH common conventions: <think>…</think> (DeepSeek-R1, QwQ, most local GGUF reasoning models) and <thinking>…</thinking> (Claude-style). Pass your own to override.

ts
optional blocks?: AparteStreamBlock[];

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:48

Tagged blocks to recognise in the prose — <tag attr="…">…</tag> — each turned into the segment its grammar builds. The stream adapter passes the blocks registered on the config (registerStreamBlock); pass your own when you drive the parser yourself. See AparteStreamBlock.

ts
optional autoGenerateIds?: boolean;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:50

Auto-generate segment IDs (default: true)

ts
optional idPrefix?: string;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:52

ID prefix for generated segments


Defined in: packages/core/src/parsers/aparte-stream-parser.ts:61

ts
mode: "text" | "thinking" | "code" | "block";

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:63

Current parser mode

ts
buffer: string;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:65

Buffer for incomplete patterns

ts
optional codeLanguage?: string;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:67

Current code block language

ts
optional thinkingEnd?: string;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:69

Close delimiter of the thinking pair currently open (multi-delimiter support)

ts
optional blockEnd?: string;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:71

Closing tag of the registered block currently open (</tag>).

ts
segments: AparteSegment[];

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:73

Accumulated segments

ts
activeSegment: AparteSegment | null;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:75

Current active segment being built

ts
segmentCounter: number;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:77

Counter for generating IDs


Defined in: packages/core/src/parsers/aparte-stream-parser.ts:80

ts
segments: AparteSegment[];

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:82

Parsed segments

ts
remaining: string;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:84

Remaining buffer (incomplete patterns)

ts
state: AparteParserState;

Defined in: packages/core/src/parsers/aparte-stream-parser.ts:86

Current parser state


Defined in: packages/core/src/renderers/code-languages.ts:54

ts
optional streaming?: boolean;

Defined in: packages/core/src/renderers/code-languages.ts:56

The content is still streaming: its last source, and any marked open, are still arriving.

ts
optional refresh?: boolean;

Defined in: packages/core/src/renderers/code-languages.ts:61

Only redraw what is drawn already, where what it depends on moved (a renderer’s cacheKey, a theme). For a renderer reacting to its own change, over a whole page.

ts
optional language?: string;

Defined in: packages/core/src/renderers/code-languages.ts:63

Only this language.


Defined in: packages/core/src/types/chat.ts:15

Plain text content part

ts
type: "text";

Defined in: packages/core/src/types/chat.ts:16

ts
text: string;

Defined in: packages/core/src/types/chat.ts:17


Defined in: packages/core/src/types/chat.ts:25

Image content part. image must be a base64 data URL: data:image/png;base64,... The data URL encodes the MIME type, making it consumable by all providers.

ts
type: "image";

Defined in: packages/core/src/types/chat.ts:26

ts
image: string;

Defined in: packages/core/src/types/chat.ts:27

ts
optional mimeType?: string;

Defined in: packages/core/src/types/chat.ts:28


Defined in: packages/core/src/types/chat.ts:51

ts
role: "user" | "assistant" | "system" | "tool";

Defined in: packages/core/src/types/chat.ts:52

ts
content: string | AparteContentPart[];

Defined in: packages/core/src/types/chat.ts:60

Message content — either a plain string (backward compatible) or an array of typed content parts: text and images. A binary the model cannot read is not a content part; see the note on AparteContentPart.

Use contentToText(content) to extract the text-only representation.

ts
optional toolCalls?: AparteToolCall[];

Defined in: packages/core/src/types/chat.ts:65

On an assistant message: the tool calls the model made this turn, grouped. content is what it said before them — '' when it said nothing.

ts
optional toolCallId?: string;

Defined in: packages/core/src/types/chat.ts:67

On a tool message: the id of the call, in the preceding assistant message, that it answers.

ts
optional toolName?: string;

Defined in: packages/core/src/types/chat.ts:75

On a tool message: the name of the tool that ran.

Optional, and worth setting: a wire format that names the tool on the result (the AI SDK does) otherwise has to scan back for the call that declared the id, which a hand-built history need not contain.


Defined in: packages/core/src/types/chat.ts:84

The request one turn sends to a provider.

Provider-specific options are not fields of the request: a provider reads its option off _meta, the namespaced bag, which reaches it untouched.

ts
messages: AparteChatMessage[];

Defined in: packages/core/src/types/chat.ts:85

ts
modelId: string;

Defined in: packages/core/src/types/chat.ts:86

ts
optional temperature?: number;

Defined in: packages/core/src/types/chat.ts:87

ts
optional maxTokens?: number;

Defined in: packages/core/src/types/chat.ts:88

ts
optional stream?: boolean;

Defined in: packages/core/src/types/chat.ts:89

ts
optional tools?: AparteTool[];

Defined in: packages/core/src/types/chat.ts:91

Tools the AI is allowed to call

ts
optional seed?: number;

Defined in: packages/core/src/types/chat.ts:101

Random seed for reproducibility. Passed through verbatim by the providers that support it (OpenAI-compatible endpoints, the AI SDK bridge, the transformers worker); Anthropic exposes none, so it is ignored there.

Nothing sets it for you: a retry varies its answer by sampling (temperature), not by seeding. Set it from a requestInterceptor when you need reproducible runs.

ts
optional toolChoice?: 
  | "auto"
  | "none"
  | {
  name: string;
  input?: Record<string, unknown>;
};

Defined in: packages/core/src/types/chat.ts:113

Controls which tool the model must call — mirrors OpenAI tool_choice / Anthropic tool_choice.

  • ‘auto’ : model decides (default when tools are present)
  • ‘none’ : no tools injected this turn — model answers directly
  • { name } : model MUST call this tool (provider injects a strong directive)
  • { name, input }: synthetic call — the agent loop (runStreamAgent, or the runner you injected) bypasses the LLM entirely and runs the handler directly with the provided input, then re-calls the LLM with the tool message in history.

Defined in: packages/core/src/types/chat.ts:133

The well-known keys of AparteChatRequest._meta. Two: prefixSegments, read by core’s client and not by the loop, and compaction, which @aparte/plugin-compaction sets for a transport to route on; the rest of the bag is the consumer’s (index signature). An artifact is a plugin’s convention, so no artifact key is defined here.

ts
[key: string]: unknown

Consumer-specific context (open channel).

ts
optional prefixSegments?: AparteSegment[];

Defined in: packages/core/src/types/chat.ts:140

Segments to show at the top of the assistant’s turn before the model has said anything — a “planning” thinking block a host wants visible from the first frame, a status row. Added right after the turn flips to streaming, in this order, and never sent to the model.

ts
optional compaction?: true;

Defined in: packages/core/src/types/chat.ts:146

Set by @aparte/plugin-compaction on the summarisation request, and on nothing else. A backend transport can route it — a cheaper model, a shorter timeout — without inspecting the messages to guess what the request is for.

ts
optional tokens?: AparteMessageToken[];

Defined in: packages/core/src/types/chat.ts:148

The tokens of the message being sent, with what the app put in their data.


Defined in: packages/core/src/types/chat.ts:156

Token usage reported by the AI provider after a completed response.

ts
inputTokens: number;

Defined in: packages/core/src/types/chat.ts:158

Tokens in the prompt / conversation history sent to the model

ts
outputTokens: number;

Defined in: packages/core/src/types/chat.ts:160

Tokens generated by the model

ts
optional totalTokens?: number;

Defined in: packages/core/src/types/chat.ts:162

Total tokens (inputTokens + outputTokens). Populated when the provider reports it.

ts
optional cacheReadTokens?: number;

Defined in: packages/core/src/types/chat.ts:164

Tokens read from the provider’s prompt cache (Anthropic, OpenAI).

ts
optional durationMs?: number;

Defined in: packages/core/src/types/chat.ts:166

Wall-clock generation time in milliseconds (provider-measured). Used to compute tokens/sec.

ts
optional ttftMs?: number;

Defined in: packages/core/src/types/chat.ts:170

Time to first token in ms — the prefill / TTFT phase.

ts
optional decodeMs?: number;

Defined in: packages/core/src/types/chat.ts:172

Decode-phase wall time in ms (≈ durationMs − ttftMs).

ts
optional decodeTokens?: number;

Defined in: packages/core/src/types/chat.ts:174

Tokens emitted during the decode phase (outputTokens minus the first).

ts
optional wallMs?: number;

Defined in: packages/core/src/types/chat.ts:176

Total turn wall-clock time in ms, measured client-side across all phases.

ts
optional modelId?: string;

Defined in: packages/core/src/types/chat.ts:178

Id of the model that produced this response.

ts
optional device?: string;

Defined in: packages/core/src/types/chat.ts:180

Compute device used for this response (‘webgpu’ | ‘wasm’ | …).

ts
optional phases?: AparteUsage[];

Defined in: packages/core/src/types/chat.ts:186

Per-call breakdown when a single turn used several provider calls (e.g. a tool-use round-trip or a mid-turn model swap). Absent for a plain single-call turn. Each entry is the AparteUsage of one provider call.


Defined in: packages/core/src/types/chat.ts:209

Normalized stream event map — extensible via declaration merging.

ts
// In a plugin or app:
declare module '@aparte/core' {
  interface AparteStreamEventMap {
    tool_call: { name: string; arguments: string }
  }
}
ts
text: {
  delta: string;
};

Defined in: packages/core/src/types/chat.ts:210

ts
delta: string;
ts
thinking: {
  delta: string;
};

Defined in: packages/core/src/types/chat.ts:211

ts
delta: string;
ts
done: {
  usage?: AparteUsage;
  finishReason?: AparteFinishReason;
};

Defined in: packages/core/src/types/chat.ts:213

Emitted when the stream ends. May carry token usage and the finish reason reported by the provider.

ts
optional usage?: AparteUsage;
ts
optional finishReason?: AparteFinishReason;
ts
error: {
  message: string;
  code?: AparteErrorCode;
};

Defined in: packages/core/src/types/chat.ts:218

A failure mid-stream. code names it when the provider can tell (an overflowing prompt is USAGE_CONTEXT_EXCEEDED), so the client can act on the code instead of reading prose.

ts
message: string;
ts
optional code?: AparteErrorCode;
ts
tool_use: AparteToolCall;

Defined in: packages/core/src/types/chat.ts:219

ts
sources: {
  sources: AparteSource[];
  citations?: AparteCitation[];
};

Defined in: packages/core/src/types/chat.ts:225

The sources the reply draws on, and where it cites them: offsets into the text this model call has streamed so far (every text delta, joined). Sent once, or as they arrive; a later event adds to the earlier ones.

ts
sources: AparteSource[];
ts
optional citations?: AparteCitation[];

Defined in: packages/core/src/types/compactor.ts:14

What a compactor is asked to do — one chat, named by its element and, when it has one, its id.

ts
target: Element | null;

Defined in: packages/core/src/types/compactor.ts:16

The chat’s element. Passed, not only its id: a chat inside a shadow root is not found by id.

ts
optional targetId?: string;

Defined in: packages/core/src/types/compactor.ts:18

The chat’s id, when it has one.

ts
optional force?: boolean;

Defined in: packages/core/src/types/compactor.ts:20

Compact even when the policy would not (below the threshold, after repeated failures).

ts
optional exclude?: string[];

Defined in: packages/core/src/types/compactor.ts:26

Ids of messages that belong to a turn being prepared — the user message and the reply placeholder of a send or retry in progress. They are not summarised and do not count as “a turn in flight”.

ts
optional reason?: AparteCompactorReason;

Defined in: packages/core/src/types/compactor.ts:27

ts
optional signal?: AbortSignal;

Defined in: packages/core/src/types/compactor.ts:33

Aborted when the turn the compaction serves is stopped — the client’s Stop or a programmatic abort() / stop(). The compactor cancels its summary then, so a stopped turn neither pays for one nor writes a checkpoint into a chat left behind.


Defined in: packages/core/src/types/compactor.ts:74

The seam between the parts of core that need the context made smaller (the gauge’s Compact now, a separator’s Retry, the client before a send and after an overflow) and whatever makes it smaller. @aparte/plugin-compaction registers itself as the compactor with AparteConfig.setCompactor(); core never compacts by itself.

It is a seam and not an event because the caller needs the answer: the client rebuilds a request once the summary is written, and a button shows that it is working.

ts
compact(request): Promise<AparteCompactorOutcome>;

Defined in: packages/core/src/types/compactor.ts:76

Compact one chat. Never rejects.

ParameterType
requestAparteCompactorRequest

Promise<AparteCompactorOutcome>

ts
settled(targetId?): Promise<void>;

Defined in: packages/core/src/types/compactor.ts:78

Resolves when no compaction of this chat is running — a send never races a summary.

ParameterType
targetId?string

Promise<void>

ts
optional beforeSend(request): Promise<boolean>;

Defined in: packages/core/src/types/compactor.ts:83

Before a send’s request goes out, with the estimate of that request. Resolves true when it compacted, so the caller builds the request again.

ParameterTypeDescription
request{ target: Element | null; targetId?: string; exclude: string[]; requestTokens: number; signal?: AbortSignal; }-
request.targetElement | null-
request.targetId?string-
request.excludestring[]The turn being prepared: its user message and reply placeholder.
request.requestTokensnumberThe estimate, in tokens, of the request about to be sent.
request.signal?AbortSignalAborted when the turn is stopped; the compactor cancels any summary it started for it.

Promise<boolean>

ts
optional preview(request): 
  | {
  messages: number;
  tokens: number;
}
  | null;

Defined in: packages/core/src/types/compactor.ts:98

What compacting now would do: how many messages it would summarise and the tokens that would free, or null when there is nothing to do. The gauge offers “Compact now” only when this returns something.

ParameterType
request{ target: Element | null; targetId?: string; }
request.targetElement | null
request.targetId?string

| { messages: number; tokens: number; } | null


Defined in: packages/core/src/types/events.ts:22

Detail payload for aparte-send custom event Emitted when user sends a message via the input component

ts
content: string;

Defined in: packages/core/src/types/events.ts:24

The message content being sent

ts
timestamp: number;

Defined in: packages/core/src/types/events.ts:27

Timestamp of the send action

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:36

ID of the chat this send belongs to: the composer’s target attribute, or the id of the <aparte-chat> / [data-aparte-chat] host above it — the same resolution the composer’s receive side (_isForThisComposer) uses, so the two halves of the channel cannot disagree about which chat is which. Used by AparteClient to find the host without DOM traversal.

ts
optional files?: File[];

Defined in: packages/core/src/types/events.ts:39

Files attached to this message (populated by composer attachments)

ts
optional modelId?: string;

Defined in: packages/core/src/types/events.ts:49

Send THIS message to a specific model, overriding the config’s default for one turn — a per-message model picker.

AparteClient honours both fields. The composer never sends them: dispatch your own aparte-send with them, or set them on the detail from a listener that runs before the client’s (capture phase).

ts
optional providerId?: string;

Defined in: packages/core/src/types/events.ts:51

The provider that modelId belongs to; defaults to the config’s defaultProvider.

ts
optional tokens?: AparteMessageToken[];

Defined in: packages/core/src/types/events.ts:57

The tokens the draft held (see AparteComposerToken). AparteClient keeps them on the user message and passes them to the request as _meta.tokens.

ts
optional meta?: Record<string, unknown>;

Defined in: packages/core/src/types/events.ts:64

Data to go with this message and not in its text. AparteClient keeps it as the user message’s metadata and merges it into the request’s _meta. The composer never sets it: add it from a listener that runs before the client’s (capture phase).


Defined in: packages/core/src/types/events.ts:128

Per-message sibling metadata carried by aparte-path-changed. index is 0-based; UI renders it as index + 1 / count.

ts
id: string;

Defined in: packages/core/src/types/events.ts:130

Message id

ts
count: number;

Defined in: packages/core/src/types/events.ts:132

Total number of siblings (including this one). 1 = no branch picker.

ts
index: number;

Defined in: packages/core/src/types/events.ts:134

0-based position of this message among its siblings.


Defined in: packages/core/src/types/events.ts:218

The chat a command acts on.

ts
config: AparteConfig;

Defined in: packages/core/src/types/events.ts:219

ts
composer: AparteComposer;

Defined in: packages/core/src/types/events.ts:220

ts
chat: HTMLElement | null;

Defined in: packages/core/src/types/events.ts:222

The <aparte-chat> or [data-aparte-chat] above the composer.

ts
targetId: string | undefined;

Defined in: packages/core/src/types/events.ts:224

The id aparte-* events name this chat by.


Defined in: packages/core/src/types/events.ts:228

What a command receives when it is chosen.

ts
config: AparteConfig;

Defined in: packages/core/src/types/events.ts:219

AparteCommandScope.config

ts
composer: AparteComposer;

Defined in: packages/core/src/types/events.ts:220

AparteCommandScope.composer

ts
chat: HTMLElement | null;

Defined in: packages/core/src/types/events.ts:222

The <aparte-chat> or [data-aparte-chat] above the composer.

AparteCommandScope.chat

ts
targetId: string | undefined;

Defined in: packages/core/src/types/events.ts:224

The id aparte-* events name this chat by.

AparteCommandScope.targetId

ts
query: string;

Defined in: packages/core/src/types/events.ts:229

ts
input: AparteComposerInput;

Defined in: packages/core/src/types/events.ts:230

ts
notify(text): void;

Defined in: packages/core/src/types/events.ts:232

Say something beside the composer for a few seconds: why a command did nothing.

ParameterType
textstring

void


Defined in: packages/core/src/types/events.ts:236

A command a plugin or an app adds to @aparte/plugin-triggers’ menu.

ts
id: string;

Defined in: packages/core/src/types/events.ts:238

The same id twice: the last one answering wins.

ts
optional name?: string;

Defined in: packages/core/src/types/events.ts:240

What is typed after the trigger. Defaults to id.

ts
optional label?: string;

Defined in: packages/core/src/types/events.ts:242

Defaults to the trigger followed by name.

ts
optional description?: string;

Defined in: packages/core/src/types/events.ts:243

ts
optional icon?: string | HTMLElement;

Defined in: packages/core/src/types/events.ts:245

A core icon’s name, a short text such as an emoji, or an element.

ts
optional group?: string;

Defined in: packages/core/src/types/events.ts:246

ts
optional keywords?: readonly string[];

Defined in: packages/core/src/types/events.ts:247

ts
optional order?: number;

Defined in: packages/core/src/types/events.ts:249

Lower comes first. Default 100.

ts
optional hidden?: boolean;

Defined in: packages/core/src/types/events.ts:250

ts
optional enabled?: (scope) => boolean;

Defined in: packages/core/src/types/events.ts:252

Asked each time the menu opens. A command that cannot act here is not listed.

ParameterType
scopeAparteCommandScope

boolean

ts
optional run?: (context) => void | Promise<void>;

Defined in: packages/core/src/types/events.ts:253

ParameterType
contextAparteCommandContext

void | Promise<void>

ts
optional children?: 
  | readonly AparteCommand[]
  | ((scope) => readonly AparteCommand[]);

Defined in: packages/core/src/types/events.ts:254


Defined in: packages/core/src/types/imperative-api.ts:14

The canonical imperative surface a framework <AparteChat> exposes (React’s ref handle, Vue/Svelte’s instance, Angular’s component). All four delegate to the framework-agnostic AparteChatHost, so this ONE contract is the single source of truth, and each wrapper enforces it against the compiler — React via the ref-handle type on a return-annotated useImperativeHandle, Angular via implements, Vue via satisfies on defineExpose, Svelte via a type-checked parity factory — so a missing or mistyped method is a build error in that wrapper, not a silent divergence.

ts
appendMessage: (message, options?) => void;

Defined in: packages/core/src/types/imperative-api.ts:23

Append a message. { historical: true } says it is RESTORED, not live: its segments are adopted as they are — no fresh timing stamps, isStreaming forced off — the way a stored conversation is loaded, so a tool call read back from your own backend renders settled rather than spinning. Use it when you replay history one message at a time; a live turn passes nothing.

ParameterType
messageAparteMessage
options?{ historical?: boolean; }
options.historical?boolean

void

ts
updateMessage: (messageId, updates) => void;

Defined in: packages/core/src/types/imperative-api.ts:24

ParameterType
messageIdstring
updatesPartial<AparteMessage>

void

ts
updateLastMessage: (content, options?) => void;

Defined in: packages/core/src/types/imperative-api.ts:25

ParameterType
contentstring
options?{ append?: boolean; }
options.append?boolean

void

ts
addSegment: (segment) => void;

Defined in: packages/core/src/types/imperative-api.ts:26

ParameterType
segmentAparteSegment

void

ts
updateSegment: (segmentId, updates) => void;

Defined in: packages/core/src/types/imperative-api.ts:27

ParameterType
segmentIdstring
updatesPartial<AparteSegment>

void

ts
removeSegment: (segmentId) => void;

Defined in: packages/core/src/types/imperative-api.ts:28

ParameterType
segmentIdstring

void

ts
appendToSegment: (segmentId, content) => void;

Defined in: packages/core/src/types/imperative-api.ts:42

Append text to a segment of the last message — the streaming path for a thinking block, a tool pill, or any segment that grows token by token.

Each chunk is written straight into the bubble, and the framework’s message list is synced once per frame rather than per chunk, so streaming a segment costs about one render per frame instead of one per token.

Note that segments and content are mutually exclusive at render time: as soon as a message has segments the bubble hides its plain content, so a message driven by injectTokenStream (which writes content) can’t also show a thinking segment — put the text in a segment of its own instead.

ParameterType
segmentIdstring
contentstring

void

ts
getMessages: () => AparteMessage[];

Defined in: packages/core/src/types/imperative-api.ts:43

AparteMessage[]

ts
clearMessages: (options?) => void;

Defined in: packages/core/src/types/imperative-api.ts:44

ParameterType
options?{ revokeAttachments?: boolean; }
options.revokeAttachments?boolean

void

ts
addBranch: (messageId) => number;

Defined in: packages/core/src/types/imperative-api.ts:46

ParameterType
messageIdstring

number

ts
addSiblingOf: (existingId, message) => string | null;

Defined in: packages/core/src/types/imperative-api.ts:47

ParameterType
existingIdstring
messageAparteMessage

string | null

ts
truncateFrom: (messageId) => void;

Defined in: packages/core/src/types/imperative-api.ts:48

ParameterType
messageIdstring

void

ts
truncateResponsesAfter: (userMessageId) => void;

Defined in: packages/core/src/types/imperative-api.ts:49

ParameterType
userMessageIdstring

void

ts
injectTokenStream: (messageId, tokens) => Promise<void>;

Defined in: packages/core/src/types/imperative-api.ts:66

Stream tokens into a message from your own loop (no AparteClient involved). It sends the turn’s lifecycle events itself — aparte-message-start, then -done, -aborted or -error — so the composer shows Stop, its Stop cancels the stream, and the conversation manager saves the reply. Resolves when the iterable completes; the message is then marked complete.

If messageId doesn’t exist the viewport auto-creates an empty assistant message — but only in its internal repo, NOT in the framework’s message state. In a wrapper, call appendMessage({ id, role: 'assistant', content: '' , timestamp: Date.now() }) first so both stay in sync. Starting a new stream cancels the previous one; stopTokenStream cancels explicitly. See the “Bring your own loop” guide.

ParameterType
messageIdstring
tokensAsyncIterable<string>

Promise<void>

ts
stopTokenStream: () => void;

Defined in: packages/core/src/types/imperative-api.ts:68

Abort an in-flight injectTokenStream loop (the source iterable is return()ed).

void

ts
setConversationId: (id) => Promise<void>;

Defined in: packages/core/src/types/imperative-api.ts:70

ParameterType
idstring | null

Promise<void>

ts
scrollToBottom: () => void;

Defined in: packages/core/src/types/imperative-api.ts:72

void

ts
focusInput: () => void;

Defined in: packages/core/src/types/imperative-api.ts:73

void

ts
isStreaming: () => boolean;

Defined in: packages/core/src/types/imperative-api.ts:74

boolean

ts
getViewport: () => HTMLElement | null;

Defined in: packages/core/src/types/imperative-api.ts:76

The <aparte-chat-viewport> element — same getViewport() on all four wrappers.

HTMLElement | null


Defined in: packages/core/src/types/imperative-api.ts:89

The imperative surface every framework <AparteUi> proxy exposes — React’s ref handle, Vue’s template ref, Svelte’s bind:this, Angular’s @ViewChild.

It lives here for the same reason AparteChatImperativeApi does: it was hand-copied into all four wrappers, each docblock promising “the same contract on all four”, and it had already drifted once (two of them returned HTMLElement | null / unknown instead of the generic form). One declaration, four re-exports, and a divergence is a compile error rather than a promise in prose.

ts
getElement<T>(): T | null;

Defined in: packages/core/src/types/imperative-api.ts:91

The proxied custom element, once mounted.

Type ParameterDefault type
T extends HTMLElementHTMLElement

T | null

ts
callMethod<T>(methodName, ...args): T | undefined;

Defined in: packages/core/src/types/imperative-api.ts:93

Call a method on it — the escape hatch for an element-specific API.

Type ParameterDefault type
Tunknown
ParameterType
methodNamestring
…argsunknown[]

T | undefined


Defined in: packages/core/src/types/model-provider.ts:31

Represents an AI model that can be selected by the user.

typescript
const model: AparteAIModel = {
  id: 'gpt-4-turbo',
  name: 'GPT-4 Turbo',
  contextWindow: 128000,
  capabilities: ['vision', 'function_calling', 'streaming']
};
ts
id: string;

Defined in: packages/core/src/types/model-provider.ts:33

Unique identifier for the model (e.g., ‘gpt-4-turbo’, ‘claude-3-opus’)

ts
name: string;

Defined in: packages/core/src/types/model-provider.ts:36

Human-readable display name

ts
optional contextWindow?: number;

Defined in: packages/core/src/types/model-provider.ts:39

Optional context window size in tokens

ts
optional pricing?: {
  input: number;
  output: number;
};

Defined in: packages/core/src/types/model-provider.ts:42

Optional pricing information (per 1M tokens)

ts
input: number;
ts
output: number;
ts
optional capabilities?: ("streaming" | "code" | "vision" | "function_calling" | "reasoning")[];

Defined in: packages/core/src/types/model-provider.ts:48

Optional capability flags

ts
optional description?: string;

Defined in: packages/core/src/types/model-provider.ts:51

Optional short description shown in model pickers

ts
optional metadata?: Record<string, unknown>;

Defined in: packages/core/src/types/model-provider.ts:54

Optional metadata for custom properties


Defined in: packages/core/src/types/model-provider.ts:76

Progress update emitted during model preparation (download + load). Passed to the onProgress callback of AparteAIProvider.prepareModel().

ts
status: "error" | "downloading" | "loading" | "cached" | "ready";

Defined in: packages/core/src/types/model-provider.ts:78

Current phase of the preparation

ts
optional file?: string;

Defined in: packages/core/src/types/model-provider.ts:80

File currently being processed (e.g. “model.safetensors”)

ts
optional progress?: number;

Defined in: packages/core/src/types/model-provider.ts:82

Progress percentage 0–100

ts
optional message?: string;

Defined in: packages/core/src/types/model-provider.ts:84

Optional human-readable message


Defined in: packages/core/src/types/model-provider.ts:94

Brand metadata for an AI provider, used for visual selection and onboarding.

ts
name: string;

Defined in: packages/core/src/types/model-provider.ts:96

Human-readable display name

ts
id: string;

Defined in: packages/core/src/types/model-provider.ts:99

Provider ID

ts
optional icon?: string;

Defined in: packages/core/src/types/model-provider.ts:105

Brand icon. Can be an SVG string, a data URI, or a key for AparteIconProvider.

ts
optional color?: string;

Defined in: packages/core/src/types/model-provider.ts:108

Brand primary color (hex or CSS variable)

ts
optional description?: string;

Defined in: packages/core/src/types/model-provider.ts:111

Short tag line or description

ts
optional hasFreeModels?: boolean;

Defined in: packages/core/src/types/model-provider.ts:114

Whether the provider offers free models or Tiers

ts
optional isLocal?: boolean;

Defined in: packages/core/src/types/model-provider.ts:117

Whether the provider runs locally on the user machine

ts
optional helpUrl?: string;

Defined in: packages/core/src/types/model-provider.ts:120

URL to the provider’s API key management page or documentation

ts
optional configSchema?: AparteAIProviderConfigSchema;

Defined in: packages/core/src/types/model-provider.ts:123

Configuration schema for the onboarding UI


Defined in: packages/core/src/types/model-provider.ts:129

Definition of a configuration field for the provider

ts
id: string;

Defined in: packages/core/src/types/model-provider.ts:131

Unique identifier for the field (e.g., ‘apiKey’, ‘endpoint’)

ts
type: "text" | "password" | "url";

Defined in: packages/core/src/types/model-provider.ts:133

Basic type for the input field

ts
label: string;

Defined in: packages/core/src/types/model-provider.ts:135

Human readable label (e.g., ‘API Key’, ‘Sever URL’)

ts
optional placeholder?: string;

Defined in: packages/core/src/types/model-provider.ts:137

Placeholder hint

ts
optional defaultValue?: string;

Defined in: packages/core/src/types/model-provider.ts:139

Initial value

ts
optional required?: boolean;

Defined in: packages/core/src/types/model-provider.ts:141

Whether the field is mandatory to start

ts
optional isAdvanced?: boolean;

Defined in: packages/core/src/types/model-provider.ts:143

If true, the field is hidden behind an ‘Advanced’ toggle in UI


Defined in: packages/core/src/types/model-provider.ts:149

Encapsulates all configuration fields for a provider

ts
fields: AparteAIProviderConfigField[];

Defined in: packages/core/src/types/model-provider.ts:150


Defined in: packages/core/src/types/model-provider.ts:331

Configuration options for model selection behavior.

ts
optional enabledProviders?: string[];

Defined in: packages/core/src/types/model-provider.ts:333

Which providers to enable (all if omitted)

ts
optional modelFilters?: Record<string, string[]>;

Defined in: packages/core/src/types/model-provider.ts:336

Filter models by provider

ts
optional defaultProvider?: string;

Defined in: packages/core/src/types/model-provider.ts:339

Default provider ID

ts
optional defaultModel?: string;

Defined in: packages/core/src/types/model-provider.ts:342

Default model ID


Defined in: packages/core/src/types/models.ts:34

Attachment interface for media and file support Future-proof structure for images, audio, documents, etc.

ts
id: string;

Defined in: packages/core/src/types/models.ts:36

Unique identifier for the attachment

ts
name: string;

Defined in: packages/core/src/types/models.ts:39

Display name of the attachment

ts
type: string;

Defined in: packages/core/src/types/models.ts:42

MIME type (e.g., ‘image/png’, ‘application/pdf’)

ts
url: string;

Defined in: packages/core/src/types/models.ts:45

URL or data URI to access the attachment

ts
optional size?: number;

Defined in: packages/core/src/types/models.ts:48

Optional file size in bytes

ts
optional thumbnailUrl?: string;

Defined in: packages/core/src/types/models.ts:51

Optional thumbnail URL for previews

ts
optional metadata?: Record<string, unknown>;

Defined in: packages/core/src/types/models.ts:54

Optional metadata for custom properties

ts
optional blob?: Blob;

Defined in: packages/core/src/types/models.ts:62

Binary payload. Set at message-creation time (File from upload) so the persistence adapter can save it to its attachments table. Stripped from the serialised message row — the adapter reconstructs url via URL.createObjectURL(blob) on hydration. Not serialised to JSON.


Defined in: packages/core/src/types/models.ts:102

See AparteConfig.setTurnSummary.

ts
optional openWhileRunning?: boolean;

Defined in: packages/core/src/types/models.ts:104

Keep a fold open while its steps run, and close it when they are done (default: closed).


Defined in: packages/core/src/types/models.ts:107

ts
optional copy?: boolean;

Defined in: packages/core/src/types/models.ts:109

Copy message text to clipboard — the one action core honors alone. Default: false

ts
optional retry?: boolean;

Defined in: packages/core/src/types/models.ts:111

Retry / regenerate the response (assistant bubbles). Needs a host to re-send. Default: false

ts
optional edit?: boolean;

Defined in: packages/core/src/types/models.ts:113

Edit the sent message inline (user bubbles). Needs a host to keep the new text. Default: false

ts
optional feedback?: boolean;

Defined in: packages/core/src/types/models.ts:115

Thumbs-up / thumbs-down feedback (assistant bubbles). Needs a listener. Default: false

ts
optional feedbackReasons?: readonly string[];

Defined in: packages/core/src/types/models.ts:120

Reasons to offer after a thumbs-down, in your words and language. One press sends aparte-feedback-reason; aparte-feedback has already gone out with the thumb.

ts
optional info?: boolean;

Defined in: packages/core/src/types/models.ts:126

The details (“i”) button, which opens the app-owned stats popover by emitting aparte-message-info (assistant bubbles). Rendered only when the message also carries a usage — no numbers, nothing to show. Default: false

ts
optional user?: AparteBubbleActionName[];

Defined in: packages/core/src/types/models.ts:128

Explicit, ordered action set for USER bubbles. Example: ['edit', 'copy'].

ts
optional assistant?: AparteBubbleActionName[];

Defined in: packages/core/src/types/models.ts:130

Explicit, ordered action set for ASSISTANT bubbles. Example: ['copy', 'thumbUp', 'thumbDown', 'retry'].


Defined in: packages/core/src/types/models.ts:146

The affordances core RENDERS but cannot COMPLETE — each one only asks, through a DOM event, and the app does the work. Declare what your app actually handles with aparteGlobalConfig.setHostHandlers(); everything else stays out of the UI rather than showing a control that answers to nobody.

ts
aparteGlobalConfig.setHostHandlers({ attachmentPreview: true });   // you open a lightbox

These are declarations, not callbacks: the event (aparte-attachment-preview) is unchanged, and you keep listening for it wherever you already do.

ts
optional attachmentPreview?: boolean;

Defined in: packages/core/src/types/models.ts:152

Clicking an image attachment asks for a full-size preview (aparte-attachment-preview) — core owns no lightbox. Until declared, the tile is inert and is not signalled as a button. Default: false

ts
optional filePreview?: boolean;

Defined in: packages/core/src/types/models.ts:160

Clicking a file — not an image — in a sent message asks for it to be opened, with the same aparte-attachment-preview and its type. Its own declaration, so a lightbox written for images is never handed a PDF: you claim files when you open them, in a new tab for instance. Only a file whose URL a tab can open (an object URL, a remote one) becomes a button. Default: false


Defined in: packages/core/src/types/models.ts:169

A checkpoint over a kept history: what the model reads in place of the messages before the one that carries it. Written by whoever summarises (@aparte/plugin-compaction, or a host summarising by other means) onto the first kept message as AparteMessage.contextSummary.

ts
summary: string;

Defined in: packages/core/src/types/models.ts:171

What the model reads in place of every message before this one on the path.

ts
count: number;

Defined in: packages/core/src/types/models.ts:174

How many messages of the path the summary stands for — the separator’s “N”.

ts
createdAt: number;

Defined in: packages/core/src/types/models.ts:177

When the summary was written, in epoch milliseconds.


Defined in: packages/core/src/types/models.ts:184

Core message structure for the chat Supports both simple content and rich multi-segment content

ts
id: string;

Defined in: packages/core/src/types/models.ts:186

Unique identifier for the message

ts
role: AparteBubbleRole;

Defined in: packages/core/src/types/models.ts:189

Role of the message sender

ts
optional content?: string;

Defined in: packages/core/src/types/models.ts:195

Simple text content (for basic messages) Use segments for rich content with multiple parts

ts
optional segments?: AparteSegment[];

Defined in: packages/core/src/types/models.ts:201

Rich content segments (thinking, code, tool calls, artifacts, …) Takes precedence over content if provided

ts
timestamp: number;

Defined in: packages/core/src/types/models.ts:204

Unix timestamp of message creation

ts
optional isStreaming?: boolean;

Defined in: packages/core/src/types/models.ts:207

Whether the message is still being streamed

ts
optional status?: AparteStatus;

Defined in: packages/core/src/types/models.ts:210

Current status of the message

ts
optional attachments?: AparteAttachment[];

Defined in: packages/core/src/types/models.ts:213

Optional attachments (images, files, etc.)

ts
optional usage?: AparteUsage;

Defined in: packages/core/src/types/models.ts:216

Token usage + timing reported by the provider for assistant messages.

ts
optional finishReason?: AparteFinishReason;

Defined in: packages/core/src/types/models.ts:223

Why the model stopped writing this reply, when the provider said. Kept with the message, so a reply cut off at the length limit ('length') still says so after a reload.

ts
optional model?: {
  providerId: string;
  modelId: string;
  temperature?: number;
};

Defined in: packages/core/src/types/models.ts:230

The provider, model and temperature an assistant turn ran on, written by AparteClient when the turn starts. A turn a server paused is resumed on them after a reload (resumeDeferred), not on whatever model is selected by then.

ts
providerId: string;
ts
modelId: string;
ts
optional temperature?: number;
ts
optional compaction?: true;

Defined in: packages/core/src/types/models.ts:242

This message is the summary @aparte/plugin-compaction injected in place of the turns it summarised (a host that summarises by other means sets the flag too). Its role is user — the summary is context handed to the model, and a system message mid-conversation is refused by some providers — but it is not something the user said: the bubble draws a separator in its place (“Earlier messages were summarised”, with the summary behind Show summary; no count and no Restore, since an older compaction replaced the turns) and the history sends it under a fixed preamble saying what it is. A compaction that keeps the messages writes AparteMessage.contextSummary instead.

ts
optional contextSummary?: AparteContextSummary;

Defined in: packages/core/src/types/models.ts:253

A checkpoint: from this message on, the model reads contextSummary.summary in place of every message before it on the path. Nothing before it is deleted — the reader still scrolls up to them, a host still stores them — only what goes to the model is shortened (historyFromCheckpoint). It sits on the first KEPT message, which is a user message, so the history still alternates its roles.

Absent and undefined mean the same thing: no checkpoint here.

ts
optional contextEstimate?: number;

Defined in: packages/core/src/types/models.ts:262

The estimate, in tokens, of the request that produced this reply, recorded by AparteClient when it sends. Read back beside the provider’s real input count (usage.inputTokens) to calibrate the context measure: the ratio of the two says how far the character heuristic is off for this model and this conversation. Absent when the request carried a part the heuristic cannot count (an image).

ts
optional tokens?: AparteMessageToken[];

Defined in: packages/core/src/types/models.ts:268

The tokens this message was written with (mentions, a picked file), each with its place in content. The bubble draws them as they looked in the composer.

ts
optional metadata?: Record<string, unknown>;

Defined in: packages/core/src/types/models.ts:271

Optional metadata for custom properties


Defined in: packages/core/src/types/models.ts:275

How the upload of a picked file is going (composer.setAttachmentState).

ts
status: "error" | "uploading" | "done";

Defined in: packages/core/src/types/models.ts:276

ts
optional progress?: number;

Defined in: packages/core/src/types/models.ts:278

From 0 to 100. Without it, an uploading file shows a moving bar.


Defined in: packages/core/src/types/models.ts:282

A pill in the composer: what it shows, and what the message says in its place.

ts
label: string;

Defined in: packages/core/src/types/models.ts:284

What the pill shows.

ts
optional text?: string;

Defined in: packages/core/src/types/models.ts:286

What the message contains in its place. Defaults to label.

ts
optional kind?: string;

Defined in: packages/core/src/types/models.ts:288

A name of your own, mention or file. Reaches the page as data-kind on the pill.

ts
optional data?: unknown;

Defined in: packages/core/src/types/models.ts:290

Whatever the app wants back with the message: an id, a path. Never shown; must survive JSON.


Defined in: packages/core/src/types/models.ts:294

A token of a sent message, with where it sits in content (end excluded).

ts
label: string;

Defined in: packages/core/src/types/models.ts:284

What the pill shows.

AparteComposerToken.label

ts
optional kind?: string;

Defined in: packages/core/src/types/models.ts:288

A name of your own, mention or file. Reaches the page as data-kind on the pill.

AparteComposerToken.kind

ts
optional data?: unknown;

Defined in: packages/core/src/types/models.ts:290

Whatever the app wants back with the message: an id, a path. Never shown; must survive JSON.

AparteComposerToken.data

ts
text: string;

Defined in: packages/core/src/types/models.ts:295

What the message contains in its place. Defaults to label.

AparteComposerToken.text

ts
start: number;

Defined in: packages/core/src/types/models.ts:296

ts
end: number;

Defined in: packages/core/src/types/models.ts:297


Defined in: packages/core/src/types/models.ts:301

The caret in a draft. Offsets count one unit per character, per line break and per token.

ts
text: string;

Defined in: packages/core/src/types/models.ts:303

The draft, where each token is one U+FFFC character.

ts
offset: number;

Defined in: packages/core/src/types/models.ts:304


Defined in: packages/core/src/types/models.ts:312

Configuration options for AparteChatViewport

ts
optional scrollThreshold?: number;

Defined in: packages/core/src/types/models.ts:314

Threshold in pixels for smart scroll detection

ts
optional maxRenderedBubbles?: number;

Defined in: packages/core/src/types/models.ts:322

DOM render cap: the max number of bubbles kept in the DOM at once (a perf ceiling for very long conversations). This does NOT evict messages from the conversation model — the full tree and its persistence snapshot stay intact. Defaults to 1000.

ts
optional layoutTransitionMs?: number;

Defined in: packages/core/src/types/models.ts:330

Duration in milliseconds to freeze spacer recalculation after resetSpacer(). Set this to the duration of any CSS layout transition in the host app (e.g. the flex animation that moves the composer from center to bottom). Defaults to 0 (no freeze). Example: 350 when transition: flex 0.3s ease is used.


Defined in: packages/core/src/types/models.ts:334

Configuration options for the composer input.

ts
optional placeholder?: string;

Defined in: packages/core/src/types/models.ts:336

Placeholder text for the input

ts
optional maxHeight?: number;

Defined in: packages/core/src/types/models.ts:339

Maximum height in pixels for auto-expand

ts
optional minHeight?: number;

Defined in: packages/core/src/types/models.ts:342

Minimum height in pixels


Defined in: packages/core/src/types/parsers.ts:15

Content parser plugin interface for external parsers Allows integration of Markdown, code highlighting, LaTeX, etc. without adding dependencies to the core

ts
id: string;

Defined in: packages/core/src/types/parsers.ts:17

Unique identifier for the parser

ts
priority: number;

Defined in: packages/core/src/types/parsers.ts:20

Priority for parser execution (higher = first)

ts
canParse(content): boolean;

Defined in: packages/core/src/types/parsers.ts:27

Check if this parser can handle the content

ParameterTypeDescription
contentstringRaw content to check

boolean

true if parser should process this content

ts
parse(content): string;

Defined in: packages/core/src/types/parsers.ts:34

Parse content and return transformed output

ParameterTypeDescription
contentstringRaw content to parse

string

Parsed HTML string or transformed content


Defined in: packages/core/src/types/segments.ts:11

Base segment interface - all segments extend this

ts
id: string;

Defined in: packages/core/src/types/segments.ts:13

Unique segment identifier

ts
type: string;

Defined in: packages/core/src/types/segments.ts:16

Segment type discriminator

ts
optional isStreaming?: boolean;

Defined in: packages/core/src/types/segments.ts:19

Whether segment is currently being streamed

ts
optional fallback?: string;

Defined in: packages/core/src/types/segments.ts:36

One sentence standing in for the segment when no renderer claims its type — DRAWN for every type, not only for custom.

It is the answer to a real moment: a conversation replayed in another app, a client that loads its views lazily, an export. Core draws it as text (no markup) under .aparte-segment-fallback. Supplying one also silences the “no renderer” developer warning: an author who wrote a fallback has already said this can happen.

In the HISTORY sent back to the model it stands in for the segment only where core does not serialise the type itself — custom, and any type core does not know (a registered block grammar’s, a plugin’s). A text or a code segment contributes its content and nothing else; thinking and tool_call are left out of the history on purpose (segmentsToWireText states why), and so is error.

ts
optional messageId?: string;

Defined in: packages/core/src/types/segments.ts:55

Id of the message this segment belongs to. Stamped on insertion.

ts
optional index?: number;

Defined in: packages/core/src/types/segments.ts:61

Position in the owning message’s segments[], maintained across insertions and removals.

ts
optional meta?: Record<string, unknown> & {
  aparte?: AparteSegmentTiming;
};

Defined in: packages/core/src/types/segments.ts:71

Extras the producer of the segment knows — token counts, cost, compute device — plus aparte, the one sub-object core writes.

Everything except meta.aparte is yours: fill it with updateSegment(segmentId, { meta }), which MERGES rather than replaces. Mirrors AparteMessage.metadata.

ts
optional aparte?: AparteSegmentTiming;

Defined in: packages/core/src/types/segments.ts:93

What core measured about a segment. Lives in meta.aparte, not on the segment.

No protocol carries a timestamp on a content block: Anthropic’s blocks have none (and neither does the message), OpenAI’s output_text part is {annotations, logprobs, text, type} with created_at on the item above it, and the AI SDK’s UIMessage.parts have none either. What the AI SDK does have is a metadata bag whose canonical example is literally { createdAt, model, totalTokens } — at the message level. A per-block id has industry precedent; per-block time has none.

So this is a local measurement, and the shape says so. It stays typed, and it is namespaced under aparte because meta is the consumer’s: a flat startedAt there would collide with a key of their own.

Core reads it through segmentDuration and isSegmentSettled. It draws one number, and only when asked: a reasoning block with showDuration reads its duration once settled. Every other display of it is the app’s.

ts
optional startedAt?: number;

Defined in: packages/core/src/types/segments.ts:95

Epoch ms when the segment entered a LIVE transcript. Absent for history.

ts
optional endedAt?: number;

Defined in: packages/core/src/types/segments.ts:111

Epoch ms when content last arrived on this segment.

It ADVANCES while the segment streams and freezes when the segment settles, so endedAt - startedAt is a live duration during a turn and a final one after it — ask isSegmentSettled(segment) which you are looking at.

Why not simply “when it finished”: the two obvious rules are both wrong, and measurably. Closing at the end of the turn makes a reasoning block span the whole answer that followed it (2s of thinking before a 20s reply reads ”22s”). Closing when the next segment opens is the same error, smaller — a gap of ten seconds before the next segment is counted as thinking, while the person watching knows nothing happened. The last delta is the only moment the segment itself can vouch for.


Defined in: packages/core/src/types/segments.ts:120

Text segment - plain text content

ts
{ id: 's1', type: 'text', content: 'A transport is the object that talks to the model.' }
ts
id: string;

Defined in: packages/core/src/types/segments.ts:13

Unique segment identifier

AparteSegmentBase.id

ts
optional isStreaming?: boolean;

Defined in: packages/core/src/types/segments.ts:19

Whether segment is currently being streamed

AparteSegmentBase.isStreaming

ts
optional fallback?: string;

Defined in: packages/core/src/types/segments.ts:36

One sentence standing in for the segment when no renderer claims its type — DRAWN for every type, not only for custom.

It is the answer to a real moment: a conversation replayed in another app, a client that loads its views lazily, an export. Core draws it as text (no markup) under .aparte-segment-fallback. Supplying one also silences the “no renderer” developer warning: an author who wrote a fallback has already said this can happen.

In the HISTORY sent back to the model it stands in for the segment only where core does not serialise the type itself — custom, and any type core does not know (a registered block grammar’s, a plugin’s). A text or a code segment contributes its content and nothing else; thinking and tool_call are left out of the history on purpose (segmentsToWireText states why), and so is error.

AparteSegmentBase.fallback

ts
optional messageId?: string;

Defined in: packages/core/src/types/segments.ts:55

Id of the message this segment belongs to. Stamped on insertion.

AparteSegmentBase.messageId

ts
optional index?: number;

Defined in: packages/core/src/types/segments.ts:61

Position in the owning message’s segments[], maintained across insertions and removals.

AparteSegmentBase.index

ts
optional meta?: Record<string, unknown> & {
  aparte?: AparteSegmentTiming;
};

Defined in: packages/core/src/types/segments.ts:71

Extras the producer of the segment knows — token counts, cost, compute device — plus aparte, the one sub-object core writes.

Everything except meta.aparte is yours: fill it with updateSegment(segmentId, { meta }), which MERGES rather than replaces. Mirrors AparteMessage.metadata.

ts
optional aparte?: AparteSegmentTiming;

AparteSegmentBase.meta

ts
type: "text";

Defined in: packages/core/src/types/segments.ts:121

Segment type discriminator

AparteSegmentBase.type

ts
content: string;

Defined in: packages/core/src/types/segments.ts:122

ts
optional sources?: AparteSource[];

Defined in: packages/core/src/types/segments.ts:127

The sources this text draws on — a web search’s results, the documents it quotes. The bubble lists them under the reply; a AparteCitation places a chip in the text.

ts
optional citations?: AparteCitation[];

Defined in: packages/core/src/types/segments.ts:129

Where in content each source is cited: a chip at the end of the passage.


Defined in: packages/core/src/types/segments.ts:133

One source a reply draws on. Shown by its domain, its title in the card and the list.

ts
id: string;

Defined in: packages/core/src/types/segments.ts:135

Unique within the message; what a AparteCitation names.

ts
optional url?: string;

Defined in: packages/core/src/types/segments.ts:137

Only https:, http: and the like are linked (the sanitizer’s URL policy).

ts
optional title?: string;

Defined in: packages/core/src/types/segments.ts:138

ts
optional snippet?: string;

Defined in: packages/core/src/types/segments.ts:140

A short excerpt, shown in the card.


Defined in: packages/core/src/types/segments.ts:151

A passage of a text segment that cites sources: offsets into the segment’s content, in UTF-16 code units (JavaScript string indices), end exclusive. The chip goes at the end of the passage — after its punctuation, never inside code, emphasis or a link.

ts
{ end: 42, sources: ['s1', 's3'] }
ts
optional start?: number;

Defined in: packages/core/src/types/segments.ts:152

ts
end: number;

Defined in: packages/core/src/types/segments.ts:153

ts
sources: string[];

Defined in: packages/core/src/types/segments.ts:155

Ids of the AparteSources, in the order the card pages through them.

ts
optional marker?: boolean;

Defined in: packages/core/src/types/segments.ts:160

[start, end) is a marker the model wrote for the citation (Perplexity’s [1]): the chip takes its place on screen. The text itself is left as it was written.


Defined in: packages/core/src/types/segments.ts:193

Thinking/reasoning segment - collapsible.

A literal <think>…</think> in a reply is read as reasoning on every path — while it streams and when the reply is restored from storage — so a message that merely quotes the tag in its prose becomes this segment rather than text; and reasoning is deliberately not sent back to the model, so those words leave the wire history with it. Models whose reasoning is marked differently are handled by the parser’s thinkingDelimiters.

ts
// No `collapsed` key, so it renders CLOSED — see the field's own note below.
{
  id: 's1',
  type: 'thinking',
  label: 'Reasoning',
  content: 'The question is about transports, so name the two and say where the key lives.',
}
ts
id: string;

Defined in: packages/core/src/types/segments.ts:13

Unique segment identifier

AparteSegmentBase.id

ts
optional isStreaming?: boolean;

Defined in: packages/core/src/types/segments.ts:19

Whether segment is currently being streamed

AparteSegmentBase.isStreaming

ts
optional fallback?: string;

Defined in: packages/core/src/types/segments.ts:36

One sentence standing in for the segment when no renderer claims its type — DRAWN for every type, not only for custom.

It is the answer to a real moment: a conversation replayed in another app, a client that loads its views lazily, an export. Core draws it as text (no markup) under .aparte-segment-fallback. Supplying one also silences the “no renderer” developer warning: an author who wrote a fallback has already said this can happen.

In the HISTORY sent back to the model it stands in for the segment only where core does not serialise the type itself — custom, and any type core does not know (a registered block grammar’s, a plugin’s). A text or a code segment contributes its content and nothing else; thinking and tool_call are left out of the history on purpose (segmentsToWireText states why), and so is error.

AparteSegmentBase.fallback

ts
optional messageId?: string;

Defined in: packages/core/src/types/segments.ts:55

Id of the message this segment belongs to. Stamped on insertion.

AparteSegmentBase.messageId

ts
optional index?: number;

Defined in: packages/core/src/types/segments.ts:61

Position in the owning message’s segments[], maintained across insertions and removals.

AparteSegmentBase.index

ts
optional meta?: Record<string, unknown> & {
  aparte?: AparteSegmentTiming;
};

Defined in: packages/core/src/types/segments.ts:71

Extras the producer of the segment knows — token counts, cost, compute device — plus aparte, the one sub-object core writes.

Everything except meta.aparte is yours: fill it with updateSegment(segmentId, { meta }), which MERGES rather than replaces. Mirrors AparteMessage.metadata.

ts
optional aparte?: AparteSegmentTiming;

AparteSegmentBase.meta

ts
type: "thinking";

Defined in: packages/core/src/types/segments.ts:194

Segment type discriminator

AparteSegmentBase.type

ts
content: string;

Defined in: packages/core/src/types/segments.ts:195

ts
optional collapsed?: boolean;

Defined in: packages/core/src/types/segments.ts:202

Open the block. Absent means CLOSED — a reasoning block is a disclosure, and the reader opens it. The content is behind a click, streaming or settled.

false opens one on purpose.

ts
optional label?: string;

Defined in: packages/core/src/types/segments.ts:203

ts
optional showDuration?: boolean;

Defined in: packages/core/src/types/segments.ts:214

Once settled, read “Thought for 8s” rather than “Thought”. Off by default: the duration is measured in the browser, from the first reasoning delta to the last, which is the model’s thinking time only when the provider streams its reasoning — a provider that sends it in one piece would read “1s”, and a reload shows it only if the stored segment kept its meta. Usually turned on for every block with setSegmentDefaults('thinking', { showDuration: true }), which a block restored from storage follows too (it is read when the block is drawn); the block’s own field wins.


Defined in: packages/core/src/types/segments.ts:232

Code segment - syntax highlighted code block

Highlighting is a plugin you opt into; with none installed the block renders plain, which is what core’s zero-dependency promise costs here.

ts
{
 *   id: 's1',
 *   type: 'code',
 *   language: 'ts',
 *   filename: 'transport.ts',
 *   content: "const transport = new AparteBackendTransport({ endpoint: '/api/chat' });",
 * }
ts
id: string;

Defined in: packages/core/src/types/segments.ts:13

Unique segment identifier

AparteSegmentBase.id

ts
optional isStreaming?: boolean;

Defined in: packages/core/src/types/segments.ts:19

Whether segment is currently being streamed

AparteSegmentBase.isStreaming

ts
optional fallback?: string;

Defined in: packages/core/src/types/segments.ts:36

One sentence standing in for the segment when no renderer claims its type — DRAWN for every type, not only for custom.

It is the answer to a real moment: a conversation replayed in another app, a client that loads its views lazily, an export. Core draws it as text (no markup) under .aparte-segment-fallback. Supplying one also silences the “no renderer” developer warning: an author who wrote a fallback has already said this can happen.

In the HISTORY sent back to the model it stands in for the segment only where core does not serialise the type itself — custom, and any type core does not know (a registered block grammar’s, a plugin’s). A text or a code segment contributes its content and nothing else; thinking and tool_call are left out of the history on purpose (segmentsToWireText states why), and so is error.

AparteSegmentBase.fallback

ts
optional messageId?: string;

Defined in: packages/core/src/types/segments.ts:55

Id of the message this segment belongs to. Stamped on insertion.

AparteSegmentBase.messageId

ts
optional index?: number;

Defined in: packages/core/src/types/segments.ts:61

Position in the owning message’s segments[], maintained across insertions and removals.

AparteSegmentBase.index

ts
optional meta?: Record<string, unknown> & {
  aparte?: AparteSegmentTiming;
};

Defined in: packages/core/src/types/segments.ts:71

Extras the producer of the segment knows — token counts, cost, compute device — plus aparte, the one sub-object core writes.

Everything except meta.aparte is yours: fill it with updateSegment(segmentId, { meta }), which MERGES rather than replaces. Mirrors AparteMessage.metadata.

ts
optional aparte?: AparteSegmentTiming;

AparteSegmentBase.meta

ts
type: "code";

Defined in: packages/core/src/types/segments.ts:233

Segment type discriminator

AparteSegmentBase.type

ts
content: string;

Defined in: packages/core/src/types/segments.ts:234

ts
optional language?: string;

Defined in: packages/core/src/types/segments.ts:235

ts
optional filename?: string;

Defined in: packages/core/src/types/segments.ts:236


Defined in: packages/core/src/types/segments.ts:253

Error segment

A failure card inside the turn that produced it, rather than a toast somewhere else on the page — so the reader can see which question failed.

ts
{
 *   id: 's1',
 *   type: 'error',
 *   content: 'The model did not answer.',
 *   details: 'HTTP 429 — rate limited. Retrying in 20s.',
 * }
ts
id: string;

Defined in: packages/core/src/types/segments.ts:13

Unique segment identifier

AparteSegmentBase.id

ts
optional isStreaming?: boolean;

Defined in: packages/core/src/types/segments.ts:19

Whether segment is currently being streamed

AparteSegmentBase.isStreaming

ts
optional fallback?: string;

Defined in: packages/core/src/types/segments.ts:36

One sentence standing in for the segment when no renderer claims its type — DRAWN for every type, not only for custom.

It is the answer to a real moment: a conversation replayed in another app, a client that loads its views lazily, an export. Core draws it as text (no markup) under .aparte-segment-fallback. Supplying one also silences the “no renderer” developer warning: an author who wrote a fallback has already said this can happen.

In the HISTORY sent back to the model it stands in for the segment only where core does not serialise the type itself — custom, and any type core does not know (a registered block grammar’s, a plugin’s). A text or a code segment contributes its content and nothing else; thinking and tool_call are left out of the history on purpose (segmentsToWireText states why), and so is error.

AparteSegmentBase.fallback

ts
optional messageId?: string;

Defined in: packages/core/src/types/segments.ts:55

Id of the message this segment belongs to. Stamped on insertion.

AparteSegmentBase.messageId

ts
optional index?: number;

Defined in: packages/core/src/types/segments.ts:61

Position in the owning message’s segments[], maintained across insertions and removals.

AparteSegmentBase.index

ts
optional meta?: Record<string, unknown> & {
  aparte?: AparteSegmentTiming;
};

Defined in: packages/core/src/types/segments.ts:71

Extras the producer of the segment knows — token counts, cost, compute device — plus aparte, the one sub-object core writes.

Everything except meta.aparte is yours: fill it with updateSegment(segmentId, { meta }), which MERGES rather than replaces. Mirrors AparteMessage.metadata.

ts
optional aparte?: AparteSegmentTiming;

AparteSegmentBase.meta

ts
type: "error";

Defined in: packages/core/src/types/segments.ts:254

Segment type discriminator

AparteSegmentBase.type

ts
content: string;

Defined in: packages/core/src/types/segments.ts:261

The error’s own message, for storage, the console and a custom error renderer. The default alert shows it only for an error that keeps its own words (the turn limit, a setup error, an app’s own code); for any other code it shows the sentence the code reads as, in the reader’s language.

ts
optional details?: string;

Defined in: packages/core/src/types/segments.ts:263

Text the alert shows under the message, in a block — a stack, a status line an app chooses to show.

ts
optional code?: string;

Defined in: packages/core/src/types/segments.ts:270

A machine-readable code for the app to branch on — an AparteErrorCode value when core made the error (AparteErrorCode.MAX_TURNS_EXCEEDED, PROVIDER_ERROR…). Never drawn itself: it picks the sentence the alert shows, the alert carries it as data-error-code, and a custom error renderer receives it.


Defined in: packages/core/src/types/segments.ts:285

Tool call segment - rendered while waiting for a tool handler to resolve

ts
{
 *   id: 's1',
 *   type: 'tool_call',
 *   status: 'resolved',
 *   toolCall: { id: 'call_1', name: 'get_weather', input: { city: 'Lille' } },
 *   result: '11°C, overcast.',
 * }
ts
id: string;

Defined in: packages/core/src/types/segments.ts:13

Unique segment identifier

AparteSegmentBase.id

ts
optional isStreaming?: boolean;

Defined in: packages/core/src/types/segments.ts:19

Whether segment is currently being streamed

AparteSegmentBase.isStreaming

ts
optional fallback?: string;

Defined in: packages/core/src/types/segments.ts:36

One sentence standing in for the segment when no renderer claims its type — DRAWN for every type, not only for custom.

It is the answer to a real moment: a conversation replayed in another app, a client that loads its views lazily, an export. Core draws it as text (no markup) under .aparte-segment-fallback. Supplying one also silences the “no renderer” developer warning: an author who wrote a fallback has already said this can happen.

In the HISTORY sent back to the model it stands in for the segment only where core does not serialise the type itself — custom, and any type core does not know (a registered block grammar’s, a plugin’s). A text or a code segment contributes its content and nothing else; thinking and tool_call are left out of the history on purpose (segmentsToWireText states why), and so is error.

AparteSegmentBase.fallback

ts
optional messageId?: string;

Defined in: packages/core/src/types/segments.ts:55

Id of the message this segment belongs to. Stamped on insertion.

AparteSegmentBase.messageId

ts
optional index?: number;

Defined in: packages/core/src/types/segments.ts:61

Position in the owning message’s segments[], maintained across insertions and removals.

AparteSegmentBase.index

ts
optional meta?: Record<string, unknown> & {
  aparte?: AparteSegmentTiming;
};

Defined in: packages/core/src/types/segments.ts:71

Extras the producer of the segment knows — token counts, cost, compute device — plus aparte, the one sub-object core writes.

Everything except meta.aparte is yours: fill it with updateSegment(segmentId, { meta }), which MERGES rather than replaces. Mirrors AparteMessage.metadata.

ts
optional aparte?: AparteSegmentTiming;

AparteSegmentBase.meta

ts
type: "tool_call";

Defined in: packages/core/src/types/segments.ts:286

Segment type discriminator

AparteSegmentBase.type

ts
toolCall: AparteToolCall;

Defined in: packages/core/src/types/segments.ts:287

ts
status: 
  | "pending"
  | "resolved"
  | "aborted"
  | "awaiting-approval"
  | "rejected"
  | "failed";

Defined in: packages/core/src/types/segments.ts:293

awaiting-approval — paused for a human decision; rejected — the human (or a policy) declined to run it; aborted — stopped, timed out, or nothing could run it; failed — the handler threw, and result carries the crash’s one line.

ts
optional result?: string;

Defined in: packages/core/src/types/segments.ts:294

ts
optional structuredResult?: unknown;

Defined in: packages/core/src/types/segments.ts:296

The handler’s structuredContent, when it returned one — the value behind result’s prose.

ts
optional deferred?: {
  reason: "approval" | "external" | "queued";
  ticket?: string;
};

Defined in: packages/core/src/types/segments.ts:304

Set when a server loop (createAparteAgentHandler) suspended its run on this call: why it waits — a person’s decision (approval), a tool the page runs (external), or nothing but its turn (queued) — and the server’s signed continuation. Saved with the conversation, so a reload can still answer it (AparteClient.resumeDeferred).

ts
reason: "approval" | "external" | "queued";
ts
optional ticket?: string;
ts
optional refusal?: {
  by: StreamRefusalOrigin;
  instruction?: string;
};

Defined in: packages/core/src/types/segments.ts:311

On a rejected call, who refused it — a person, a policy, or the loop because an earlier call of the same step was refused — and what the person typed instead. result is the sentence the MODEL read; this is what a row tells a person, in their language. Absent on a call refused by a runner that does not say.

ts
by: StreamRefusalOrigin;
ts
optional instruction?: string;
ts
optional abortCause?: StreamAbortCause | "turn-limit";

Defined in: packages/core/src/types/segments.ts:316

On an aborted call, why: a Stop, its handler’s timeout, no handler here, a gate with nobody to ask, or its own turn limit. Absent when the run ended before it.

ts
optional collapsed?: boolean;

Defined in: packages/core/src/types/segments.ts:322

Whether the row’s disclosure starts closed. Absent: closed, unless the tool’s display says open. setSegmentDefaults('tool_call', { collapsed: false }) opens every row; like reasoning’s, it is read when the row is drawn and never forced on an update.


Defined in: packages/core/src/types/segments.ts:361

Custom segment - one escape hatch for the views an app draws itself.

Renderers are keyed on type, so subType never reaches the registry: you register ONE renderer for custom and switch on subType inside it, with fallback as the default branch. Independent views take their own type instead — register a chart renderer for a chart — and custom is for a family of small views an app would rather keep behind one key.

ts
registerSegmentRenderer<AparteCustomSegment>({
  type: 'custom',
  render(segment) {
    const data = (segment.data ?? {}) as Record<string, unknown>;
    const el = document.createElement('div');
    switch (segment.subType) {
      case 'weather':
        el.className = 'weather';
        el.textContent = `${data['city']} — ${data['celsius']}°C`;
        break;
      case 'poll':
        el.className = 'poll';
        el.textContent = String(data['question']);
        break;
      default:
        // A subType this build does not know: the sentence, not nothing.
        el.textContent = segment.fallback ?? '';
    }
    return el;
  },
});

// The segments that renderer draws:
{ id: 's1', type: 'custom', subType: 'weather', data: { city: 'Lille', celsius: 11 } }
{ id: 's2', type: 'custom', subType: 'gantt', fallback: 'Three tasks, ending Friday.' }
ts
id: string;

Defined in: packages/core/src/types/segments.ts:13

Unique segment identifier

AparteSegmentBase.id

ts
optional isStreaming?: boolean;

Defined in: packages/core/src/types/segments.ts:19

Whether segment is currently being streamed

AparteSegmentBase.isStreaming

ts
optional fallback?: string;

Defined in: packages/core/src/types/segments.ts:36

One sentence standing in for the segment when no renderer claims its type — DRAWN for every type, not only for custom.

It is the answer to a real moment: a conversation replayed in another app, a client that loads its views lazily, an export. Core draws it as text (no markup) under .aparte-segment-fallback. Supplying one also silences the “no renderer” developer warning: an author who wrote a fallback has already said this can happen.

In the HISTORY sent back to the model it stands in for the segment only where core does not serialise the type itself — custom, and any type core does not know (a registered block grammar’s, a plugin’s). A text or a code segment contributes its content and nothing else; thinking and tool_call are left out of the history on purpose (segmentsToWireText states why), and so is error.

AparteSegmentBase.fallback

ts
optional messageId?: string;

Defined in: packages/core/src/types/segments.ts:55

Id of the message this segment belongs to. Stamped on insertion.

AparteSegmentBase.messageId

ts
optional index?: number;

Defined in: packages/core/src/types/segments.ts:61

Position in the owning message’s segments[], maintained across insertions and removals.

AparteSegmentBase.index

ts
optional meta?: Record<string, unknown> & {
  aparte?: AparteSegmentTiming;
};

Defined in: packages/core/src/types/segments.ts:71

Extras the producer of the segment knows — token counts, cost, compute device — plus aparte, the one sub-object core writes.

Everything except meta.aparte is yours: fill it with updateSegment(segmentId, { meta }), which MERGES rather than replaces. Mirrors AparteMessage.metadata.

ts
optional aparte?: AparteSegmentTiming;

AparteSegmentBase.meta

ts
type: "custom";

Defined in: packages/core/src/types/segments.ts:362

Segment type discriminator

AparteSegmentBase.type

ts
subType: string;

Defined in: packages/core/src/types/segments.ts:364

Which view inside the custom renderer draws this segment (e.g. ‘weather’, ‘poll’, ‘onboarding’).

ts
optional data?: unknown;

Defined in: packages/core/src/types/segments.ts:366

Arbitrary data payload for the component


Defined in: packages/core/src/types/segments.ts:402

The segment types an app or a plugin adds, one key per type, merged into this interface; each one joins AparteSegment, so addSegment, appendMessage and AparteMessage.segments take it without a cast.

ts
declare module '@aparte/core' {
  interface AparteSegmentTypes {
    chart: AparteSegmentBase & { type: 'chart'; data: { label: string; value: number }[] };
  }
}
viewport.addSegment('a1', { id: 'c1', type: 'chart', data: [{ label: 'Q1', value: 4 }] });

Defined in: packages/core/src/types/segments.ts:415

Segment renderer interface for custom segment types Implement this to add new segment renderers

Type ParameterDefault type
T extends AparteSegmentBaseAparteSegmentBase
ts
type: string;

Defined in: packages/core/src/types/segments.ts:417

Segment type this renderer handles

ts
render(segment): string | HTMLElement;

Defined in: packages/core/src/types/segments.ts:433

Render a segment to either an HTML string or a ready DOM element.

Return a string for simple markup (inserted via innerHTML) — the built-in renderers do this. Return an HTMLElement to skip innerHTML entirely: you can attach event listeners and framework nodes directly, and there is no innerHTML XSS surface for values you interpolate. Either way, setup() (if provided) runs afterwards with the resulting element. For in-place streaming updates to find your element, keep a data-segment-id="<segment.id>" on its root (or implement update()).

ParameterTypeDescription
segmentTSegment data to render

string | HTMLElement

HTML string or a DOM element

ts
optional getStyles(): string;

Defined in: packages/core/src/types/segments.ts:439

Optional: Get CSS styles for this segment type

string

CSS string to inject

ts
optional setup(element, segment): void;

Defined in: packages/core/src/types/segments.ts:446

Optional: Setup interactivity after render

ParameterTypeDescription
elementHTMLElementThe rendered DOM element
segmentTSegment data

void

ts
optional update(element, segment): void;

Defined in: packages/core/src/types/segments.ts:454

Optional: In-place DOM update during streaming. When provided, called instead of re-rendering the full element. Must not add/remove child nodes — only mutate attributes or textContent so the MutationObserver (childList) doesn’t fire and scroll stays stable.

ParameterType
elementHTMLElement
segmentT

void

ts
optional relabel(element, segment): void;

Defined in: packages/core/src/types/segments.ts:478

Optional: re-read the CONFIG-DERIVED text of an already-rendered segment — an icon from the icon provider, a label from the locale.

Called when the config changes (a language switch, a new icon set), on every segment already on screen. Bound by the same rule as update(): must not add or remove child nodes — only attributes and textContent — so the viewport’s childList observer stays quiet and scroll does not move.

This exists because the obvious alternative does not work. Re-rendering the segments container to pick up a new locale destroys state the DOM owns and the segment data does not: a mounted sandboxed artifact preview, a reasoning block the reader expanded by clicking <summary> (which never writes back to collapsed), scroll position inside a long terminal, the focus on an Approve/Reject gate, and the buffered lookahead of the incremental Markdown parser mid-stream. It also fires container-wide childList mutations, which is exactly what the rule above forbids.

Implement it only if the rendered output contains text or icons that came from the config. A renderer whose chrome is entirely its own data — progress, text — correctly does not, exactly as it does not implement update().

ParameterType
elementHTMLElement
segmentT

void

ts
optional cleanup(element, segment): void;

Defined in: packages/core/src/types/segments.ts:500

Optional: the element render() returned is gone for good — unmount what you mounted in it.

Called once per element, with the element and the segment’s latest state, when it leaves the page for good: replaced by a new render() (a segment redrawn, a message redrawn in a new frame, this renderer replaced by another registration), its segment removed, or its message removed. Never for update() or relabel(), and never for a message a framework only MOVED: a bubble taken out and put back before the next microtask keeps its elements. A bubble that comes back after a longer absence (a framework’s keep-alive cache, a reused route) draws its segments again, so a renderer sees render/setup once more after its cleanup.

A renderer that replaces its own element inside update() cleans up what it replaced itself: the bubble then follows the new element and calls this for it.

This hook was declared long before anything called it; it is called now.

ParameterTypeDescription
elementHTMLElementThe DOM element leaving
segmentTThe segment it was last drawn or updated with

void


Defined in: packages/core/src/types/segments.ts:512

Event when segment content is updated during streaming

ts
messageId: string;

Defined in: packages/core/src/types/segments.ts:513

ts
segmentId: string;

Defined in: packages/core/src/types/segments.ts:514

ts
content: string;

Defined in: packages/core/src/types/segments.ts:515

ts
optional append?: boolean;

Defined in: packages/core/src/types/segments.ts:516


Defined in: packages/core/src/types/stream-blocks.ts:24

What the parser hands to AparteStreamBlock.toSegment when a block opens.

ts
attrs: Record<string, string>;

Defined in: packages/core/src/types/stream-blocks.ts:30

The opening tag’s attributes, as written: type="text/html", title='Notes' and lang=fr all parse; the values are verbatim, never trimmed or decoded. The model wrote them — treat them as untrusted, like every segment field.

ts
id: string;

Defined in: packages/core/src/types/stream-blocks.ts:32

The id the parser generated for the segment (its usual prefix + uuid).


Defined in: packages/core/src/types/stream-blocks.ts:45

A block grammar: the tag, and the segment its body becomes.

The parser owns everything after toSegment returns: it appends each delta to segment.content, sets isStreaming while the block is open and clears it at </tag> (or at the end of the stream). So the segment MUST carry a content string — the one field core touches — and the rest of its shape is yours: a type of your own, registered with registerSegmentRenderer, or a built-in one if the block is merely another way of spelling it.

ts
tag: string;

Defined in: packages/core/src/types/stream-blocks.ts:51

The tag name without brackets: artifact recognises <artifact …> … </artifact>. Matched exactly and case-sensitively, and only as a whole name — <artifacts> does not open an artifact block. Letters, digits, - and _.

ts
toSegment: (match) => AparteSegmentBase & {
  content: string;
};

Defined in: packages/core/src/types/stream-blocks.ts:56

Build the segment at the opening tag, with an empty content. Called once per block; the parser fills the body in afterwards.

ParameterType
matchAparteStreamBlockMatch

AparteSegmentBase & { content: string; }


Defined in: packages/core/src/types/tools.ts:10

Definition of a tool the AI can call

ts
name: string;

Defined in: packages/core/src/types/tools.ts:11

ts
description: string;

Defined in: packages/core/src/types/tools.ts:12

ts
inputSchema: Record<string, unknown>;

Defined in: packages/core/src/types/tools.ts:14

JSON Schema object describing the tool’s input parameters

ts
optional systemPrompt?: string;

Defined in: packages/core/src/types/tools.ts:16

System prompt injected automatically when this tool is registered — tells the AI when and why to use it

ts
optional maxTurns?: number;

Defined in: packages/core/src/types/tools.ts:21

Maximum number of agentic loop turns before aborting. Overrides the global maxTurns in AparteClientOptions for this specific tool.

ts
optional needsApproval?: boolean;

Defined in: packages/core/src/types/tools.ts:37

When true, the agent loop pauses before running this tool’s handler and waits for a human decision — “human in the loop”.

The decision is asked AT THE COMPOSER, through the same requestUserInput a tool handler calls: every request for the user is answered in one place. The row in the transcript is the anchor, naming which tool is waiting, and holds nothing clickable. An approvalResolver on AparteClientOptions answers it programmatically instead.

On a refusal the rest of the turn is skipped — no later tool call of the same turn runs — and then the model gets a turn to answer it, so it can say what it will do instead. The refusal may carry the user’s own words.


Defined in: packages/core/src/types/tools.ts:60

A tool call emitted by the AI during streaming

ts
id: string;

Defined in: packages/core/src/types/tools.ts:61

ts
name: string;

Defined in: packages/core/src/types/tools.ts:62

ts
input: Record<string, unknown>;

Defined in: packages/core/src/types/tools.ts:63


Defined in: packages/core/src/types/tools.ts:74

What an approval policy says about one call.

allow runs it without asking; ask puts it to the person the way a needsApproval tool is put to them; deny refuses it on the spot, and reason is the sentence the model reads about that refusal — verbatim, because nobody said anything (“Plan mode: write_file changes files; only read-only tools run.”).

ts
verdict: "allow" | "ask" | "deny";

Defined in: packages/core/src/types/tools.ts:75

ts
optional reason?: string;

Defined in: packages/core/src/types/tools.ts:76


Defined in: packages/core/src/types/tools.ts:98

Result returned after a tool handler resolves

ts
toolCallId: string;

Defined in: packages/core/src/types/tools.ts:99

ts
content: string;

Defined in: packages/core/src/types/tools.ts:101

What the model reads.

ts
optional structuredContent?: unknown;

Defined in: packages/core/src/types/tools.ts:108

The same result as a value, for a renderer or the host — MCP’s name for exactly this field, beside content. Optional and additive: a handler that returns prose alone behaves as before, and the model never sees this. It lands on the transcript’s segment as AparteToolCallSegment.structuredResult.


Defined in: packages/core/src/types/tools.ts:136

Which chat a tool handler is running for.

Optional and third, so a handler that does not need it ignores it.

A handler needs it to reach the right instance: requestUserInput resolves its presenter with resolveConfig(request.target ?? null), so without a target it resolves against the GLOBAL config, finds no presenter on an instance config, and rejects with an AparteElicitationAbortError (name 'AbortError', reason 'no-presenter'): nothing is shown. Pass target from this context.

The loop supplies it — runStreamAgent, or the runner you injected — so a handler behaves the same whichever one is running.

ts
optional request?: Request;

Defined in: packages/core/src/types/tools.ts:142

On the server (createAparteAgentHandler): the request being served — the one that started the run, or, for a call answered after a pause, the one that resumed it — for a tool that checks who is calling. The model chose the arguments, not the caller.

ts
optional target?: HTMLElement;

Defined in: packages/core/src/types/tools.ts:148

The chat element this turn belongs to. Pass it as target to requestUserInput (or to anything else that resolves a config from the DOM) and the right instance answers.

ts
optional config?: unknown;

Defined in: packages/core/src/types/tools.ts:153

The resolved config for this chat, for a handler that needs it without going through the DOM — a handler running in a worker, or one reading a provider.


Defined in: packages/core/src/types/tools.ts:197

How a tool’s calls are shown — registered with registerToolDisplay(matcher, display).

Every field is optional; what is left out keeps core’s default row. The tool’s NAME is the app’s wire format and core never turns it into words on its own: label is how an app gives a person something better to read than web_search.

ts
optional label?: string | ((segment) => string);

Defined in: packages/core/src/types/tools.ts:203

What the row and the approval question call the tool, in place of its identifier. Plain text, never HTML. A function reads the call (its status, its input); one that throws falls back to the identifier.

ts
optional icon?: 
  | keyof AparteIconProvider
  | string & {
};

Defined in: packages/core/src/types/tools.ts:208

The row’s glyph: an icon-provider key (file, edit, terminal… — or search, globe from @aparte/core/icons once registered). Unknown keys fall back to tool.

ts
optional summary?: AparteToolSummary;

Defined in: packages/core/src/types/tools.ts:210

What the call targets, after the label — see AparteToolSummary.

ts
optional formatInput?: AparteToolInputFormatter;

Defined in: packages/core/src/types/tools.ts:212

The arguments as a person reads them — see AparteToolInputFormatter.

ts
optional hidden?: boolean;

Defined in: packages/core/src/types/tools.ts:217

Draw nothing for these calls. The call stays in the message, in storage and in the model’s history; an approval it needs is still asked.

ts
optional open?: boolean;

Defined in: packages/core/src/types/tools.ts:219

Open the row’s disclosure by default (a segment’s own collapsed wins).

ts
optional details?: false | AparteToolDetails;

Defined in: packages/core/src/types/tools.ts:227

What is behind the line. Left out, Input and Output: the arguments and the result, a developer’s view. false, nothing: the line alone, with no disclosure, for a chat whose reader should not be one click from raw JSON (open and a segment’s collapsed then have nothing to open). A function: what it returns, in place of Input and Output — see AparteToolDetails.

ts
optional quiet?: boolean;

Defined in: packages/core/src/types/tools.ts:245

The line a person reads in a conversational chat — on unless a display says false. While the call runs, the label shimmers (aparte-shimmer) instead of a spinner and “Running”; once it is done, nothing marks success — the label’s tense says it, so write one that reads the status (“Searching the web…” / “Searched the web” / a plain “Search the web” for the rest). Under reduced motion the shimmer holds still, so that label is what says the call runs. A wait for approval, a refusal, a failure and a stop still show their word and note. The words it does not show are still read by a screen reader. The target is set in the chat’s font and the chevron moves to the end of the line; the row carries data-quiet for a stylesheet of your own.

false is an agent’s row: a spinner and “Running”, then “Done”. Like every field it comes from the one entry that applies, so registerToolDisplay('*', { quiet: false }) reaches the tools with no entry of their own; a tool that has one says quiet: false there too.


Defined in: packages/core/src/types/tools.ts:275

Per-tool segment renderer. Registered via aparteGlobalConfig.registerToolRenderer(toolName, renderer). When the AI calls a tool, this renderer controls what appears in the bubble for that specific tool instead of the generic tool_call renderer.

Return an empty string from render() to render nothing (e.g. for UI-only tools like ask_user).

ts
render: (segment) => string | HTMLElement;

Defined in: packages/core/src/types/tools.ts:305

Render the tool-call segment, as an HTML string or a ready DOM element.

The segment carries model-chosen data. segment.toolCall.input is whatever the model decided to pass, and segment.result is whatever the tool returned — on the SEGMENT, because AparteToolCall is { id, name, input } and nothing else (there is no segment.toolCall.result). Both values are untrusted.

Return an HTMLElement and there is no innerHTML surface at all — set textContent, attach listeners, insert framework nodes. That is the safe default and the reason this arm exists.

Return a string and core inserts it with innerHTML, so every interpolated value must go through escapeHtml (text position) or escapeAttr (inside an attribute). The natural first thing to write here is `<div>Searching for ${s.toolCall.input.query}</div>`, and that is a direct model-to-DOM XSS in the host page’s origin.

Return an empty string to render nothing (e.g. a UI-only tool like ask_user).

The root you return is the segment’s element in the bubble: core stamps data-segment-id="<segment.id>" on it if you did not, so an update to the call (its result landing, an approval decision) is patched into that element rather than rebuilding every segment of the bubble — a rebuild destroys a mounted artifact preview, collapses an opened reasoning block and drops the focus. Keep your markup’s root a single element for that reason.

ParameterType
segmentAparteToolCallSegment

string | HTMLElement

ts
optional setup?: (element, segment) => void;

Defined in: packages/core/src/types/tools.ts:307

Optional DOM setup (event listeners etc.) called after HTML is injected

ParameterType
elementHTMLElement
segmentAparteToolCallSegment

void

ts
optional update?: (element, segment) => void;

Defined in: packages/core/src/types/tools.ts:316

Patch the element in place when the call changes — its result landing, an approval decided, a failed status. Without it core rebuilds your markup from render() on every change, which is right for a receipt and wrong for anything with state: a mounted preview, an opened disclosure, a focused control are all lost in a rebuild. Same contract as AparteSegmentRenderer.update: never re-render, never touch what the reader opened.

ParameterType
elementHTMLElement
segmentAparteToolCallSegment

void

ts
optional relabel?: (element, segment) => void;

Defined in: packages/core/src/types/tools.ts:323

Re-read the locale and the icon provider without touching the DOM shape — called on every config change (setLocale, setIconProvider, reset()), for as long as the element is on the page. Add or remove no child node; replace text and glyphs only.

ParameterType
elementHTMLElement
segmentAparteToolCallSegment

void

ts
optional cleanup?: (element, segment) => void;

Defined in: packages/core/src/types/tools.ts:340

The element render() returned is gone for good: unmount what you mounted in it.

Called once per element, with the element and the call’s latest segment, when it leaves the page for good — replaced by a new render(), its segment removed, its message redrawn, its message removed, or its renderer replaced (a renderer registered or unregistered for this tool redraws the calls already on screen). Never for update() or relabel(), and never for a message a framework only MOVED: a bubble taken out and put back before the next microtask keeps its elements. Always called on the renderer that drew the element, even when another one has been registered since.

A framework component mounted in setup() is unmounted here; without it, it keeps running (and keeps its subscriptions) after its card is gone. The same hook, under the same name, as AparteSegmentRenderer.cleanup.

ParameterType
elementHTMLElement
segmentAparteToolCallSegment

void

ts
optional getStyles?: () => string;

Defined in: packages/core/src/types/tools.ts:342

Optional CSS to inject once into document.head

string


Defined in: packages/core/src/types/tools.ts:350

One tool call as a component of yours draws it: the fields a card reads, in one object, the same in every framework. input is what the model passed and result what the tool answered — both model-chosen, so treat them as untrusted when you render them.

Type ParameterDefault type
Iunknown
Runknown
ts
readonly id: string;

Defined in: packages/core/src/types/tools.ts:352

The call’s id, as the model issued it.

ts
readonly name: string;

Defined in: packages/core/src/types/tools.ts:354

The tool’s name.

ts
readonly input: I;

Defined in: packages/core/src/types/tools.ts:356

The arguments the model passed.

ts
readonly status: 
  | "pending"
  | "resolved"
  | "aborted"
  | "awaiting-approval"
  | "rejected"
  | "failed";

Defined in: packages/core/src/types/tools.ts:358

Where the call stands: running, waiting for a person, done, refused, stopped or failed.

ts
readonly optional result?: string;

Defined in: packages/core/src/types/tools.ts:360

The tool’s answer as text, once it has one.

ts
readonly optional structuredResult?: R;

Defined in: packages/core/src/types/tools.ts:362

The tool’s answer as data, when it returned some.

ts
readonly optional deferred?: {
  reason: "approval" | "external" | "queued";
  ticket?: string;
};

Defined in: packages/core/src/types/tools.ts:364

Why the call was left to someone else (an approval, an external runner, a queue).

ts
reason: "approval" | "external" | "queued";
ts
optional ticket?: string;
ts
readonly optional refusal?: {
  by: StreamRefusalOrigin;
  instruction?: string;
};

Defined in: packages/core/src/types/tools.ts:366

Who refused the call, and what they said.

ts
by: StreamRefusalOrigin;
ts
optional instruction?: string;
ts
readonly optional abortCause?: StreamAbortCause | "turn-limit";

Defined in: packages/core/src/types/tools.ts:368

Why the call was stopped.

ts
readonly segment: AparteToolCallSegment;

Defined in: packages/core/src/types/tools.ts:370

The segment itself, for anything the fields above do not carry.


Defined in: packages/core/src/types/tools.ts:377

Something mounted in an element core created — a framework component, usually — and the two things core does with it: hand it a newer state, and take it down.

Type Parameter
V
ts
update(view): void;

Defined in: packages/core/src/types/tools.ts:379

A newer state of what it draws: re-render in place, keep local state.

ParameterType
viewV

void

ts
destroy(): void;

Defined in: packages/core/src/types/tools.ts:381

Its element is leaving for good: unmount.

void


ts
type AparteContentPart = 
  | AparteTextPart
  | AparteImagePart;

Defined in: packages/core/src/types/chat.ts:37

Discriminated union of all content part types.

Only text and image parts exist: the client inlines images and text files and drops other attachments (PDF, audio) with a warning at the point the file is dropped.


ts
type AparteFinishReason = "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other";

Defined in: packages/core/src/types/chat.ts:196

Why the model stopped writing, as the provider reported it. The values are the AI SDK’s: 'length' is the one core acts on — the reply hit the output limit or the context window and is cut off, which a finished reply must not look like. A provider maps its own vocabulary (finish_reason: "tool_calls", stop_reason: "max_tokens"…) onto these, and anything it cannot place is 'other'.


ts
type AparteStreamEvent = { [K in keyof AparteStreamEventMap]: { type: K } & AparteStreamEventMap[K] }[keyof AparteStreamEventMap];

Defined in: packages/core/src/types/chat.ts:229

Discriminated union derived from AparteStreamEventMap — stays in sync automatically.


ts
type AparteChatResponse = ReadableStream<AparteStreamEvent> | string;

Defined in: packages/core/src/types/chat.ts:233


ts
type AparteCompactorReason = "manual" | "retry" | "overflow" | "auto";

Defined in: packages/core/src/types/compactor.ts:11

Why a compactor was asked.

manual is a person’s click (the gauge’s Compact now, a separator’s Retry), auto the policy’s own decision after a turn or before a send, retry an attempt made again after a failure, overflow the model refusing a request as over its window — the one that has to run, whatever the back-off says.


ts
type AparteCompactorOutcome = 
  | {
  ok: true;
  skipped: true;
  reason: NonNullable<AparteCompactDoneEventDetail["reason"]>;
  targetId?: string;
}
  | {
  ok: true;
  skipped: false;
  summary: string;
  kept: number;
  dropped: number;
  messageId?: string;
  count?: number;
  targetId?: string;
}
  | {
  ok: false;
  error: string;
  targetId?: string;
  messageId?: string;
};

Defined in: packages/core/src/types/compactor.ts:41

How a compaction ended. It never rejects: a refusal and a failure are outcomes, so the caller reads ok and does not need a try. The same information goes out as aparte-compact-done / aparte-compact-error.

ts
{
  ok: true;
  skipped: true;
  reason: NonNullable<AparteCompactDoneEventDetail["reason"]>;
  targetId?: string;
}
ts
ok: true;
ts
skipped: true;
ts
reason: NonNullable<AparteCompactDoneEventDetail["reason"]>;

Why nothing was done — the same list aparte-compact-done carries.

ts
optional targetId?: string;

ts
{
  ok: true;
  skipped: false;
  summary: string;
  kept: number;
  dropped: number;
  messageId?: string;
  count?: number;
  targetId?: string;
}
ts
ok: true;
ts
skipped: false;
ts
summary: string;
ts
kept: number;

Messages kept verbatim after the summary.

ts
dropped: number;

Messages this compaction summarised.

ts
optional messageId?: string;

The message that now carries the checkpoint.

ts
optional count?: number;

Messages of the path the checkpoint stands for, an earlier summary’s included.

ts
optional targetId?: string;

ts
{
  ok: false;
  error: string;
  targetId?: string;
  messageId?: string;
}

ts
type AparteAttrValue<T> = T extends boolean ? "" | null | undefined : T extends number ? number | string : T;

Defined in: packages/core/src/types/element-attributes.ts:38

One attribute as a TEMPLATE must write it.

A presence attribute becomes '' | undefined, never boolean, and that is not pedantry — it is the same trap in all three template languages. React and Vue stringify what they set on a custom element, so disabled={false} renders disabled="false", and an element that tests hasAttribute reads that as ON. The right spelling is streaming={… ? '' : undefined}; this type makes it the only one that type-checks.

Svelte 5 shapes the SETTERS: it assigns the PROPERTY whenever the element has a setter for it (set_custom_element_data checks get_setters(node)), so an accessor-backed presence attribute receives the '' this union promises as a property value. Every presence setter therefore treats '' as ON (presenceOn in utils/presence.ts) — one spelling, both paths.

null is in the union alongside undefined because all three treat it as REMOVE, and Vue templates write exactly that (:streaming="… ? '' : null").

A numeric attribute takes a number or the string it becomes, because both read naturally in a template.

Angular does NOT use this: its directives take boolean through booleanAttribute and write the attribute themselves, so a consumer there writes [disabled]="busy". That difference is the whole reason this is a mapping and not the declared type.

Type Parameter
T

ts
type AparteTemplateAttrs<T> = { [K in keyof T]?: AparteAttrValue<NonNullable<T[K]>> };

Defined in: packages/core/src/types/element-attributes.ts:43

An element’s attribute surface, in template spelling. Used by three of four wrappers.

Type Parameter
T

ts
type ModelStatus = "ready" | "cached" | "not-downloaded";

Defined in: packages/core/src/types/model-provider.ts:67

Availability status of a model, as reported by the provider.

Provider-agnostic: Transformers.js checks the Cache API, Ollama checks pulled models, LM Studio checks VRAM, etc.


ts
type AparteAIProvider = 
  | AparteAIProviderCore & AparteAIProviderFormat & AparteAIProviderAuth & Partial<AparteAIProviderChat>
  | AparteAIProviderCore & AparteAIProviderChat & Partial<AparteAIProviderFormat> & AparteAIProviderAuthMembers;

Defined in: packages/core/src/types/model-provider.ts:320

An AI provider (e.g. OpenRouter, OpenAI, Transformers.js).

A union, not one interface, because there are two mutually sufficient ways to be a provider and the compiler should say which one you implemented. A single interface with optional members, discriminated only at RUNTIME by isFormatAdapter(), would let { id, getMetadata, getModels } typecheck, register, and then fail on the first message with nothing at build time to warn you.

Every member of both surfaces stays reachable on the union (optional on the arm that does not require it), so runtime probes like typeof p.buildRequest === 'function' and isFormatAdapter() narrowing keep working. A provider implementing both surfaces is valid and satisfies the format arm.

A format adapter — a transport does the call

typescript
const provider: AparteAIProvider = {
  id: 'openrouter',
  getMetadata: () => ({ name: 'OpenRouter', id: 'openrouter', icon: '<svg/>', color: '#000' }),
  getModels: () => [],
  defaultEndpoint: 'https://openrouter.ai/api/v1',
  buildRequest: (req) => ({ path: '/chat/completions', body: req }),
  authHeaders: (key) => ({ Authorization: `Bearer ${key}` }),
  parseStream: (body) => body as unknown as ReadableStream<AparteStreamEvent>,
};

A provider owning its own I/O

typescript
const local: AparteAIProvider = {
  id: 'transformers',
  getMetadata: () => ({ name: 'Transformers.js', id: 'transformers', icon: '<svg/>', color: '#000' }),
  getModels: () => [],
  chat: async (request) => runLocally(request),
};

ts
type AparteStatus = "idle" | "pending" | "streaming" | "completed" | "error" | "success";

Defined in: packages/core/src/types/models.ts:17

Generic status type for flow management Used to drive loading indicators, error states, and transitions without coupling to any specific data source


ts
type AparteBubbleRole = "user" | "assistant";

Defined in: packages/core/src/types/models.ts:24

Role of a message sender in the conversation


ts
type AparteBubbleActionName = "copy" | "edit" | "retry" | "thumbUp" | "thumbDown" | "info";

Defined in: packages/core/src/types/models.ts:77

Names of the individual action-bar buttons, used for explicit per-role ordered configuration (see AparteBubbleActionsConfig.user / .assistant).


ts
type AparteSegmentDefaults = Readonly<Record<string, unknown>>;

Defined in: packages/core/src/types/segments.ts:172

Field defaults for one segment TYPE, merged when a segment enters a message.

A record and not a Partial<AparteSegment> on purpose: the type key is a string, a consumer’s own segment type is as valid as a built-in one, and its fields cannot be known here. What CANNOT be defaulted is identity — id, type, messageId, index, startedAt, endedAt are refused, because a default id would give every segment in a conversation the same one.


ts
type AparteSegment = 
  | AparteTextSegment
  | AparteThinkingSegment
  | AparteCodeSegment
  | AparteErrorSegment
  | AparteCustomSegment
  | AparteToolCallSegment
  | AparteSegmentTypes[keyof AparteSegmentTypes];

Defined in: packages/core/src/types/segments.ts:379

All built-in segment types. An artifact is not one of them any more: it is a convention an app teaches its model, and @aparte/plugin-artifacts registers its segment — a type of its own, through registerSegmentRenderer and registerStreamBlock — the way any consumer registers a chart or a citation.


ts
type AparteSegmentType = AparteSegment["type"];

Defined in: packages/core/src/types/segments.ts:405

Segment type discriminator values


ts
type AparteSegmentMount<T> = (host, segment) => AparteMountedView;

Defined in: packages/core/src/types/segments.ts:504

Mount your component for one segment in host, and say how to update and destroy it.

Type ParameterDefault type
T extends AparteSegmentBaseAparteSegmentBase
ParameterType
hostHTMLElement
segmentT

AparteMountedView


ts
type AparteThemeVariables = { [K in `--aparte-${string}`]?: string };

Defined in: packages/core/src/types/theming.ts:34

Any aparté CSS custom property, for typing a theme object or a style record:

ts
const brand: AparteThemeVariables = {
  '--aparte-primary': '#b45309',
  '--aparte-surface-1': '#ffffff',
};

This was a hand-written list of 33 named properties, and it could not work. Ten of the 33 named variables were neither declared nor read anywhere in aparté — so the type autocompleted ten knobs that did nothing — while the real surface is 254 tokens, meaning even the 23 live members were an arbitrary slice presented as the whole. A hand-maintained mirror of a stylesheet that size is wrong the day after it is written, and nothing could tell you.

What this trades away, stated rather than glossed: autocomplete, and catching a typo in the part after --aparte-. What it buys is that the type cannot lie. The discoverable list is the generated CSS variables reference, which is swept from the source on every build and marks which tokens aparté actually reads.


ts
type AparteApprovalPolicy = (call, tool) => AparteApprovalRuling | undefined;

Defined in: packages/core/src/types/tools.ts:92

Decides, per CALL, whether a tool runs, asks, or is refused.

A tool’s own needsApproval is a declaration about the tool; a policy is a decision about the call — the same run_command can be a read (ls) or an execution, and a mode (“plan”: read-only, “auto”: never ask) is a policy the host switches, not a flag on twenty definitions. Registered with setApprovalPolicy(); the client’s default approval channel consults it before asking. Return undefined to have no opinion, in which case the tool’s needsApproval decides as before.

Pure and synchronous: it is evaluated once to decide whether the call pauses at all (so an allowed call never flashes “awaiting approval”) and once to answer.

ParameterType
callAparteToolCall
toolAparteTool | undefined

AparteApprovalRuling | undefined


ts
type AparteToolHandler = (call, signal, context?) => Promise<AparteToolResult>;

Defined in: packages/core/src/types/tools.ts:116

Handler function for a registered tool. Receives the tool call and an AbortSignal (fires after timeout or on cancellation). Must resolve with a AparteToolResult.

ParameterType
callAparteToolCall
signalAbortSignal
context?AparteToolContext

Promise<AparteToolResult>


ts
type AparteToolSummary = (segment) => string;

Defined in: packages/core/src/types/tools.ts:169

What a call targets, in one line: the text the DEFAULT tool row shows after the tool’s name — read_file skills.json rather than read_file alone. Registered via aparteGlobalConfig.registerToolSummary(toolName, summary).

The name says which tool ran; this says to what, without opening the disclosure. The row, its states and its disclosure stay core’s, so a host that only wants that one line does not re-implement them in an AparteToolRenderer.

Return plain text: it is written as text, never parsed as HTML. Return '' to show nothing. segment.toolCall.input is whatever the model chose, so read it defensively — a summary that throws shows nothing rather than breaking the row.

ParameterType
segmentAparteToolCallSegment

string


ts
type AparteToolInputFormatter = (input) => string;

Defined in: packages/core/src/types/tools.ts:181

A tool’s arguments as a person reads them: the text the approval panel shows under its question and the default tool row shows behind its disclosure — one formatter for both, so the two cannot disagree. Registered via aparteGlobalConfig.registerToolInputFormatter(toolName, formatter).

Without one, both show the arguments as the model sent them, pretty-printed JSON. Return plain text: it is written as text, never parsed as HTML; '' shows no arguments at all. input is whatever the model chose, so read it defensively — a formatter that throws falls back to the JSON.

ParameterType
inputRecord<string, unknown>

string


ts
type AparteToolMatcher = string | RegExp;

Defined in: packages/core/src/types/tools.ts:188

Which tools a registration names: one exact name, a RegExp tested against the name (name.search(re) !== -1, so a g flag is harmless), or '*' for every tool nothing more specific describes.


ts
type AparteToolDetails = (segment) => HTMLElement | string;

Defined in: packages/core/src/types/tools.ts:265

What a row shows behind its line, in place of Input and Output: a list of sources for a search, a sentence for a write. Called when the row is drawn and on every update of the call, so it can read the status and the result as they land — and on a language switch, whose words are written into the nodes already there when the shape is the same.

Return an HTMLElement and nothing goes through innerHTML. Return a string and core inserts it as HTML after the config’s HTML sanitizer (setHtmlSanitizer, as for Markdown): what it shows comes from a tool’s result, so a script or an event handler in it is removed. Escape the call’s values all the same (escapeHtml): the sanitizer keeps markup that is harmless but can still mislead. Return '' for nothing behind the line yet: no disclosure, which appears once there is something (a result, say).

A function that throws costs the row its detail, never its line, and never falls back to the raw Input and Output. Register the same function rather than a new closure each time: a different details redraws the messages on screen.

ParameterType
segmentAparteToolCallSegment

HTMLElement | string


ts
type AparteToolMount = (host, view) => AparteMountedView<AparteToolCallView>;

Defined in: packages/core/src/types/tools.ts:385

Mount your component for one tool call in host, and say how to update and destroy it.

ParameterType
hostHTMLElement
viewAparteToolCallView

AparteMountedView<AparteToolCallView>

Defined in: packages/core/src/types/errors.ts:2

ts
CONFIG_NO_PROVIDER: "CONFIG_NO_PROVIDER";

Defined in: packages/core/src/types/errors.ts:4

ts
CONFIG_MISSING_KEY: "CONFIG_MISSING_KEY";

Defined in: packages/core/src/types/errors.ts:5

ts
CONFIG_INVALID_KEY: "CONFIG_INVALID_KEY";

Defined in: packages/core/src/types/errors.ts:6

ts
CONFIG_INVALID_MODEL: "CONFIG_INVALID_MODEL";

Defined in: packages/core/src/types/errors.ts:7

ts
USAGE_RATE_LIMIT: "USAGE_RATE_LIMIT";

Defined in: packages/core/src/types/errors.ts:10

ts
USAGE_CONTEXT_EXCEEDED: "USAGE_CONTEXT_EXCEEDED";

Defined in: packages/core/src/types/errors.ts:11

ts
USAGE_BAD_REQUEST: "USAGE_BAD_REQUEST";

Defined in: packages/core/src/types/errors.ts:12

ts
NET_OFFLINE: "NET_OFFLINE";

Defined in: packages/core/src/types/errors.ts:15

ts
NET_TIMEOUT: "NET_TIMEOUT";

Defined in: packages/core/src/types/errors.ts:16

ts
NET_ERROR: "NET_ERROR";

Defined in: packages/core/src/types/errors.ts:17

ts
PROVIDER_ERROR: "PROVIDER_ERROR";

Defined in: packages/core/src/types/errors.ts:20

ts
PROVIDER_UNAVAILABLE: "PROVIDER_UNAVAILABLE";

Defined in: packages/core/src/types/errors.ts:21

ts
PROVIDER_POLICY: "PROVIDER_POLICY";

Defined in: packages/core/src/types/errors.ts:22

ts
PROVIDER_MISCONFIGURED: "PROVIDER_MISCONFIGURED";

Defined in: packages/core/src/types/errors.ts:29

The provider was reached but is set up so it cannot answer — an n8n workflow that is not published, waits for credentials, streams nothing or answers without a text field. Waiting will not mend it: the person reads a sentence that asks for no retry, the developer reads what to change.

ts
MAX_TURNS_EXCEEDED: "MAX_TURNS_EXCEEDED";

Defined in: packages/core/src/types/errors.ts:33

The turn reached maxTurns: the loop stopped asking the model, to avoid an endless loop.

ts
UNKNOWN_ERROR: "UNKNOWN_ERROR";

Defined in: packages/core/src/types/errors.ts:36

Defined in: packages/core/src/types/events.ts:78

Detail payload for aparte-message-done. Dispatched when a turn finishes normally. Carries token usage when the provider reports it.

aparte-message-done

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:86

Id of the <aparte-chat> host that produced this turn, when it has one.

Stamped by the client’s lifecycle dispatcher on EVERY lifecycle event so several chats on one page stay isolated — a composer reacts only to its own host’s turn.

ts
messageId: string;

Defined in: packages/core/src/types/events.ts:87

ts
role: string;

Defined in: packages/core/src/types/events.ts:88

ts
optional usage?: AparteUsage;

Defined in: packages/core/src/types/events.ts:90

Token usage for the completed response, if reported by the provider.

ts
optional finishReason?: AparteFinishReason;

Defined in: packages/core/src/types/events.ts:92

Why the model stopped writing, if the provider said — 'length' means the reply is cut off.


Defined in: packages/core/src/types/events.ts:106

Detail payload for aparte-model-change. Dispatched by @aparte/plugin-model-selector when the user picks a different provider or model — the clearest cross-package contract in the set.

aparte-model-change

ts
optional providerId?: string;

Defined in: packages/core/src/types/events.ts:108

Selected provider ID (e.g., ‘openrouter’, ‘gemini’)

ts
modelId: string;

Defined in: packages/core/src/types/events.ts:111

Selected model ID (e.g., ‘gpt-4-turbo’, ‘claude-3-opus’)

ts
optional previousModelId?: string;

Defined in: packages/core/src/types/events.ts:114

Previous model ID if changed

ts
optional previousProviderId?: string;

Defined in: packages/core/src/types/events.ts:117

Previous provider ID if changed


Defined in: packages/core/src/types/events.ts:147

Detail payload for aparte-link-click. Dispatched by the bubble, cancelable, when a link in a message body is about to be followed — a link the MODEL wrote. preventDefault() on the event keeps the browser from navigating, so a host routes the link itself (an external browser, a confirmation, an embedded view) without intercepting the DOM. With no listener the browser follows it; the sanitizer has made an external URL open in a new tab.

aparte-link-click

ts
href: string;

Defined in: packages/core/src/types/events.ts:149

The href as written on the anchor, after sanitization.

ts
anchor: HTMLAnchorElement;

Defined in: packages/core/src/types/events.ts:151

The anchor itself, for a host that wants its text or its rel.

ts
messageId: string | null;

Defined in: packages/core/src/types/events.ts:153

The message the link sits in, or null for a bubble mounted without one.


Defined in: packages/core/src/types/events.ts:163

Detail payload for aparte-branch-navigate. Dispatched by the bubble’s branch-picker buttons; the viewport listens (bubbling) and calls navigateBranch(messageId, direction) on its repo.

aparte-branch-navigate

ts
messageId: string;

Defined in: packages/core/src/types/events.ts:165

Message id whose siblings should be navigated

ts
direction: "prev" | "next";

Defined in: packages/core/src/types/events.ts:167

‘prev’ = move to previous sibling, ‘next’ = move to next sibling


Defined in: packages/core/src/types/events.ts:178

Detail payload for aparte-path-changed. Dispatched by the viewport in framework-managed mode after the active path of the conversation tree changes (sibling switch, retry, edit, etc.). Consumers (Angular wrapper) reconcile their signal/state from this payload.

aparte-path-changed

ts
messages: AparteMessage[];

Defined in: packages/core/src/types/events.ts:180

Messages on the new active path, root → head.

ts
siblings: AparteSiblingInfo[];

Defined in: packages/core/src/types/events.ts:182

Sibling metadata, one entry per message on the path.


Defined in: packages/core/src/types/events.ts:193

Detail payload for aparte-retry. Dispatched by the assistant bubble’s “Retry” action. Picked up by the AparteClient, which calls addSiblingOf on the target viewport and streams a fresh response into the new sibling.

aparte-retry

ts
messageId: string;

Defined in: packages/core/src/types/events.ts:195

Message id of the assistant response being retried (its sibling will be created).

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:197

Optional id of the host element (aparte-chat) — used by scopeToTargetId.


Defined in: packages/core/src/types/events.ts:208

Detail payload for aparte-edit. Dispatched by the user bubble after the user confirms an inline edit. Picked up by the AparteClient, which truncates the existing responses to this message and re-streams a new one.

aparte-edit

ts
messageId: string;

Defined in: packages/core/src/types/events.ts:210

Message id of the user message being edited.

ts
content: string;

Defined in: packages/core/src/types/events.ts:212

New content submitted by the user.

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:214

Optional id of the host element (aparte-chat) — used by scopeToTargetId.


Defined in: packages/core/src/types/events.ts:265

Detail payload for aparte-collect-commands, sent up when a menu of @aparte/plugin-triggers opens. A plugin that has a command listens on window, checks config is its own, and calls add. Core only names the shape: it reads none of it, and neither side imports the other.

aparte-collect-commands

ts
config: AparteConfig;

Defined in: packages/core/src/types/events.ts:266

ts
chat: HTMLElement | null;

Defined in: packages/core/src/types/events.ts:267

ts
composer: AparteComposer;

Defined in: packages/core/src/types/events.ts:268

ts
add(command): void;

Defined in: packages/core/src/types/events.ts:269

ParameterType
commandAparteCommand

void


Defined in: packages/core/src/types/events.ts:278

Detail payload for aparte-trigger-select, sent when a row of @aparte/plugin-triggers’ menu is chosen. preventDefault() leaves the draft untouched.

aparte-trigger-select

ts
trigger: {
  char: string;
};

Defined in: packages/core/src/types/events.ts:279

ts
char: string;
ts
item: {
  id: string;
  label: string;
  data?: unknown;
};

Defined in: packages/core/src/types/events.ts:280

ts
id: string;
ts
label: string;
ts
optional data?: unknown;
ts
query: string;

Defined in: packages/core/src/types/events.ts:281


Defined in: packages/core/src/types/events.ts:290

Detail payload for aparte-feedback-reason: why a reply got a thumbs-down, picked from setBubbleActions({ feedbackReasons }).

aparte-feedback-reason

ts
messageId: string;

Defined in: packages/core/src/types/events.ts:291

ts
reason: string;

Defined in: packages/core/src/types/events.ts:292


Defined in: packages/core/src/types/events.ts:301

Detail payload for aparte-feedback. Dispatched by the assistant bubble’s thumbs-up / thumbs-down buttons.

aparte-feedback

ts
messageId: string;

Defined in: packages/core/src/types/events.ts:303

Message id receiving the feedback.

ts
value: "positive" | "negative";

Defined in: packages/core/src/types/events.ts:305

‘positive’ for thumbs-up, ‘negative’ for thumbs-down.


Defined in: packages/core/src/types/events.ts:317

Detail payload for aparte-action. Dispatched by a custom action button (registered via aparteGlobalConfig.registerAction) in a message-bubble toolbar. Apps listen (bubbling) and dispatch on actionId. Mirrors the built-in bubble events (retry/feedback) so custom actions are wired the same way in every framework and in vanilla.

aparte-action

ts
actionId: string;

Defined in: packages/core/src/types/events.ts:319

The registered action’s id (from AparteAction.id).

ts
zone: "bubble";

Defined in: packages/core/src/types/events.ts:321

Which zone the action was clicked in.

ts
optional messageId?: string;

Defined in: packages/core/src/types/events.ts:323

Message id of the bubble the action was clicked on.

ts
optional role?: "user" | "assistant";

Defined in: packages/core/src/types/events.ts:325

Role of that bubble.

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:327

Optional host element id (aparte-chat) — same use as retry/edit’s targetId.


Defined in: packages/core/src/types/events.ts:337

Detail payload for aparte-message-info. Dispatched by the assistant bubble’s info (“i”) action button. Apps listen (bubbling) and present a stats popover for the completed response.

aparte-message-info

ts
messageId: string;

Defined in: packages/core/src/types/events.ts:339

Message id whose stats should be shown.

ts
optional usage?: AparteUsage;

Defined in: packages/core/src/types/events.ts:341

Token usage + timing for the message, when available.


Defined in: packages/core/src/types/events.ts:364

Detail payload for aparte-message-start. Dispatched when a turn begins, before the first token. The composer and the conversation controller both use it to enter their streaming state.

aparte-message-start

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:366

Host element id, when the <aparte-chat> has one.

ts
messageId: string;

Defined in: packages/core/src/types/events.ts:368

Id of the assistant message about to stream.

ts
role: string;

Defined in: packages/core/src/types/events.ts:370

Role of the message being created — 'assistant' in every current path.


Defined in: packages/core/src/types/events.ts:380

Detail payload for aparte-message-error. Dispatched when a turn fails. Four core components listen for it, and it is the event guides/troubleshooting.md tells you to bind to surface a failure.

aparte-message-error

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:382

Host element id, when the <aparte-chat> has one.

ts
messageId: string;

Defined in: packages/core/src/types/events.ts:384

Id of the message that failed.

ts
error: AparteError;

Defined in: packages/core/src/types/events.ts:386

The failure, with its code — not a string, unlike aparte-compact-error.


Defined in: packages/core/src/types/events.ts:399

Detail payload for aparte-message-paused. Dispatched when a server loop pauses the turn on calls only the page can answer — an approval, a browser tool. The turn is not over (aparte-message-done follows the resume), but the reply is worth saving now: its paused calls carry the server’s ticket, and a conversation saved here can still be answered after a reload. The conversation manager persists on it.

aparte-message-paused

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:401

Host element id, when the <aparte-chat> has one.

ts
messageId: string;

Defined in: packages/core/src/types/events.ts:403

Id of the paused reply.


Defined in: packages/core/src/types/events.ts:415

Detail payload for aparte-message-resumed. Dispatched when a paused turn goes on: the page answered the paused calls (a person’s decision, a browser tool) and the run starts again, into the same reply. The other half of aparte-message-paused — what the turn does between the two is wait for the page; after this one, it runs again until aparte-message-done.

aparte-message-resumed

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:417

Host element id, when the <aparte-chat> has one.

ts
messageId: string;

Defined in: packages/core/src/types/events.ts:419

Id of the reply the run goes on in.


Defined in: packages/core/src/types/events.ts:428

Detail payload for aparte-message-aborted. Dispatched when the user stops a turn.

aparte-message-aborted

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:430

Host element id, when the <aparte-chat> has one.

ts
optional messageId?: string;

Defined in: packages/core/src/types/events.ts:436

Id of the aborted message — OPTIONAL, and that is not laziness: the composer dispatches this event on its own with only a targetId, because a user can press Stop during the pre-flight window before any message id exists.


Defined in: packages/core/src/types/events.ts:448

Detail payload for aparte-abort — a COMMAND, not a notification.

AparteClient listens for it on window; a bring-your-own-composer consumer dispatches it to stop a stream. Nothing in core dispatches it on the consumer’s behalf, so its shape is documented here.

aparte-abort

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:450

Which chat to stop. Omit on a single-chat page.


Defined in: packages/core/src/types/events.ts:463

Detail payload for aparte-compact — a COMMAND dispatched on window to ask for the conversation so far to be summarised.

A host dispatches it from a button, and the context gauge’s Retry does when no compactor is registered; @aparte/plugin-compaction is what answers it. Core itself neither listens for it nor compacts — the events below are the plugin’s.

aparte-compact

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:465

Which chat to compact. Omit on a single-chat page.

ts
optional auto?: boolean;

Defined in: packages/core/src/types/events.ts:471

true when the request is an automatic one, made without a person asking (an app’s own trigger). The plugin counts such a request against its back-off (two failures stop the automatic attempts), which a button’s request never is.


Defined in: packages/core/src/types/events.ts:481

Detail payload for aparte-compact-start — the summarisation began. The point for a host to show a spinner: summarising a long conversation is a model call and takes as long as one.

aparte-compact-start

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:483

The chat being compacted, when it has an id.

ts
optional messageId?: string;

Defined in: packages/core/src/types/events.ts:489

The message the checkpoint will sit on — the first message kept verbatim. The transcript draws its “Summarising the context…” line above that message while the summary is being written.


Defined in: packages/core/src/types/events.ts:501

Detail payload for aparte-compact-done.

A union flattened to optional fields, because the two outcomes carry different payloads and a consumer cannot guess which: nothing to compact sends { skipped: true, reason }, a real compaction sends { summary, kept, dropped }.

aparte-compact-done

ts
optional skipped?: boolean;

Defined in: packages/core/src/types/events.ts:503

true when there was nothing worth summarising; the other two are absent.

ts
optional reason?: "streaming" | "empty" | "nothing-to-drop" | "running" | "no-window";

Defined in: packages/core/src/types/events.ts:510

Why it was skipped: empty (no messages), nothing-to-drop (the selector kept everything), running (a compaction was already in flight), streaming (a turn is in flight in the transcript), no-window (the model declares no context window and nothing else sizes the summary request).

ts
optional summary?: string;

Defined in: packages/core/src/types/events.ts:512

The summary that replaced the compacted turns.

ts
optional kept?: number;

Defined in: packages/core/src/types/events.ts:514

How many messages were kept verbatim after the summary.

ts
optional dropped?: number;

Defined in: packages/core/src/types/events.ts:516

How many messages the summary replaced.

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:518

The chat that was compacted, when it has an id — so a gauge on a multi-chat page resets only its own.

ts
optional messageId?: string;

Defined in: packages/core/src/types/events.ts:523

The message that now carries the checkpoint (AparteMessage.contextSummary), or, on a restore, the message whose separator Restore was pressed on.

ts
optional count?: number;

Defined in: packages/core/src/types/events.ts:525

How many messages of the path the checkpoint stands for, an earlier summary’s included.

ts
optional restored?: boolean;

Defined in: packages/core/src/types/events.ts:531

true when this is not a compaction but a Restore: every checkpoint was removed from the transcript and the model reads the original messages again. summary, kept and dropped are absent.


Defined in: packages/core/src/types/events.ts:542

Detail payload for aparte-compact-error.

Note the asymmetry with aparte-message-error, which is deliberate rather than hidden: error here is a plain string, not an AparteError.

aparte-compact-error

ts
error: string;

Defined in: packages/core/src/types/events.ts:544

Human-readable failure reason.

ts
optional targetId?: string;

Defined in: packages/core/src/types/events.ts:546

The chat the compaction was for, when it has an id.

ts
optional messageId?: string;

Defined in: packages/core/src/types/events.ts:551

The message the failed checkpoint would have sat on, when it got that far — the transcript turns its “Summarising the context…” line into a failure with a Retry.

ts
optional aborted?: true;

Defined in: packages/core/src/types/events.ts:558

The compaction was cancelled — a Stop, an abort(), a Restore — rather than failed. Nothing went wrong and nothing is offered: the transcript and the gauge clear their “Summarising the context…” instead of showing a failure with a Retry, which would bring back a summary the person just turned away.


Defined in: packages/core/src/types/events.ts:574

Detail payload for aparte-attachment-preview. Dispatched when a user clicks an image tile, once setHostHandlers({ attachmentPreview: true }) has declared that you will open a lightbox — or, with filePreview: true, a file tile in a sent message whose URL a tab can open. Without the declaration the tile is not interactive at all.

aparte-attachment-preview

ts
url: string;

Defined in: packages/core/src/types/events.ts:576

Object URL or remote URL of the image or the file.

ts
name: string;

Defined in: packages/core/src/types/events.ts:578

File name, or '' when the attachment carries none.

ts
type: string;

Defined in: packages/core/src/types/events.ts:580

The MIME type, '' when unknown: an image to show in a lightbox, another file to open in a tab.


Defined in: packages/core/src/types/events.ts:595

Detail for aparte-approval-mode-change — dispatched by @aparte/plugin-approval’s <aparte-approval-mode> after the person switched the approval mode. Bubbles and crosses shadow roots, so a host can persist the choice from any ancestor.

Declared here, like aparte-model-change, because a listener in any framework reads e.detail through the typed event map. The values are the plugin’s four modes (plan, ask, auto-edit, auto); typed as strings so core names none of them.

aparte-approval-mode-change

ts
mode: string;

Defined in: packages/core/src/types/events.ts:597

The mode just switched to.

ts
previousMode: string;

Defined in: packages/core/src/types/events.ts:599

The mode it replaced.


Defined in: packages/core/src/types/tools.ts:53

Detail for aparte-tool-approval-request — emitted by the loop when a tool marked needsApproval is about to run.

Listen for it to present the decision yourself. Core’s own gate asks at the COMPOSER (<aparte-elicitation> renders the panel there), and the transcript row shows only a state — there is no Approve/Reject control in a bubble.

With no presenter and no approvalResolver, every needsApproval call aborts with nothing clickable on screen.

aparte-tool-approval-request

ts
toolCallId: string;

Defined in: packages/core/src/types/tools.ts:54

ts
toolName: string;

Defined in: packages/core/src/types/tools.ts:55

ts
input: Record<string, unknown>;

Defined in: packages/core/src/types/tools.ts:56