@mlx-node/lm 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,90 +1,28 @@
1
+ import type { ChatConfig, ChatMessage, ChatResult, ToolDefinition } from '@mlx-node/core';
2
+ import type { ChatStreamEvent } from './stream.js';
1
3
  /**
2
- * Generic server-side chat session wrapper.
3
- *
4
- * `ChatSession<M>` is the cross-model chat-session wrapper. It works
5
- * against any model that exposes the uniform chat-session NAPI
6
- * surface `chatSessionStart`,
7
- * `chatSessionContinue`, `chatSessionContinueTool`, and their
8
- * streaming variants plus `resetCaches`. See `SessionCapableModel`
9
- * below.
10
- *
11
- * Design notes:
12
- *
13
- * - The session tracks its own `ChatMessage[]` history on the
14
- * TypeScript side. In the common text-continue case the history
15
- * is only appended to and never read back — each `send()` on
16
- * turn >= 1 issues a cheap `chatSessionContinue` delta against
17
- * the live KV cache. The history is kept purely so the
18
- * image-change mid-session path can call `chatSessionStart` with
19
- * the full rebuilt history for a clean re-prefill.
20
- *
21
- * - An image hash (`lastImagesKey`) tracks the images bound to the
22
- * current cache. A `send()` call whose image set has changed
23
- * (different bytes or different ordering) triggers a full
24
- * restart: `resetCaches()` → push the new user message (with
25
- * images) to history → `chatSessionStart(history)`.
26
- *
27
- * - Text-only `send()` on turn >= 1 takes the cheap delta path.
28
- *
29
- * - `sendToolResult` always dispatches `chatSessionContinueTool`,
30
- * since tool turns never change image state. The session enforces
31
- * a strict unresolved-ok-tool-call contract at runtime, driven by
32
- * `unresolvedOkToolCallCount` (derived from `ChatResult.toolCalls`
33
- * after each turn via `countOkToolCalls` /
34
- * `computeTrailingAssistantUnresolvedToolCallCount`):
35
- *
36
- * * `null` — the trailing assistant turn has no outstanding ok
37
- * tool call. Plain `send()` / `sendStream()` are the only
38
- * valid entry points; `sendToolResult*()` throws because
39
- * there is nothing for the result to resolve.
40
- * * `1` — exactly one outstanding ok tool call. Plain `send()` /
41
- * `sendStream()` throw (they would orphan the call);
42
- * `sendToolResult*()` is the sole valid forward step and
43
- * dispatches the tool result through the native session.
44
- * * `>1` — a multi-tool-call fan-out that the chat-session API
45
- * cannot progress incrementally (each `sendToolResult*` would
46
- * re-open the assistant turn and weave new replies between
47
- * the sibling results). Both `send()` / `sendStream()` and
48
- * `sendToolResult*()` throw. The only valid recovery is
49
- * `reset()` or `primeHistory()` + `startFromHistory*()` with
50
- * a fully-resolved conversation — there is no "advance past
51
- * the broken turn" path. This mirrors the native ChatML delta
52
- * format which would otherwise silently corrupt multi-call
53
- * conversations.
54
- *
55
- * - `sawFinal` gates `turnCount` advance on the streaming path, so
56
- * the session refuses to advance when the stream throws
57
- * mid-decode or yields a final chunk with
58
- * `finishReason: 'error'`.
59
- *
60
- * - The `inFlight` guard rejects concurrent `send()` /
61
- * `sendStream()` calls at the class level. The native side
62
- * serializes cache mutation on a single worker thread, so a
63
- * second in-flight call would race the first's cache-save step.
64
- *
65
- * - **Cold-restart primitives.** `primeHistory()` plus
66
- * `startFromHistory()` / `startFromHistoryStream()` let a caller
67
- * seed a fresh session with an externally-reconstructed history
68
- * (e.g. a server `ResponseStore` chain) and replay it through the
69
- * native `chatSessionStart` path without going through `send()`.
70
- * These are intended for server-side `SessionRegistry` cache-miss
71
- * cold-start; normal usage stays on `send` / `sendStream` /
72
- * `sendToolResult` / `reset`.
73
- *
74
- * ## Typical usage
75
- *
76
- * ```typescript
77
- * import { Qwen35Model, ChatSession } from '@mlx-node/lm';
78
- *
79
- * const model = await Qwen35Model.load('./models/qwen3.5-0.8b');
80
- * const session = new ChatSession(model, { system: 'Be concise.' });
81
- * const r1 = await session.send('Say hi in one word.');
82
- * const r2 = await session.send('Another word?');
83
- * await session.reset();
84
- * ```
4
+ * Stable, provider-neutral error raised before native inference when a
5
+ * rendered prompt cannot fit in the model's physically available hot KV
6
+ * window. The marker is intentionally the canonical string recognized by
7
+ * pi's overflow recovery, so managed agent sessions compact and retry while
8
+ * stateless HTTP callers receive a clean request error instead of a native
9
+ * `BlockAllocator exhausted` failure.
85
10
  */
86
- import type { ChatConfig, ChatMessage, ChatResult } from '@mlx-node/core';
87
- import type { ChatStreamEvent } from './stream.js';
11
+ export declare class ContextCapacityError extends Error {
12
+ readonly promptTokens: number;
13
+ readonly effectiveWindowTokens: number;
14
+ readonly code = "context_length_exceeded";
15
+ constructor(promptTokens: number, effectiveWindowTokens: number);
16
+ }
17
+ /** Recognize both the typed JS preflight and the native hard backstop. */
18
+ export declare function isContextCapacityError(error: unknown): boolean;
19
+ /** Physical and trained context limits captured by a native model at load. */
20
+ export interface SessionContextLimits {
21
+ trainedWindowTokens: number;
22
+ effectiveWindowTokens: number;
23
+ pagedBlockCapacity: number;
24
+ pagedBlockSize: number;
25
+ }
88
26
  /**
89
27
  * Structural interface matched by every generative model wrapper
90
28
  * (`Qwen35Model`, `Qwen35MoeModel`, `Lfm2Model`, `Gemma4Model`,
@@ -95,9 +33,50 @@ import type { ChatStreamEvent } from './stream.js';
95
33
  * fully structural.
96
34
  */
97
35
  export interface SessionCapableModel {
36
+ /**
37
+ * Optional non-generating chat-template tokenizer. Exposed by
38
+ * wrappers that can count prompt tokens without running inference
39
+ * (used by Anthropic `/v1/messages/count_tokens`).
40
+ */
41
+ applyChatTemplate?(messages: ChatMessage[], addGenerationPrompt?: boolean | null, tools?: ToolDefinition[] | null, enableThinking?: boolean | null): Promise<Uint32Array> | Uint32Array;
42
+ /**
43
+ * Optional model-native planner for prompt formats whose media placeholders
44
+ * expand after chat-template rendering. It returns the exact token length
45
+ * that inference will prefill, without mutating model/session state.
46
+ *
47
+ * Qwen3.5 dense/MoE implement this with their loaded image processor. Models
48
+ * without post-template expansion omit it and retain raw template counting.
49
+ */
50
+ expandedPromptTokenCount?(promptTokens: Uint32Array, messages: ChatMessage[]): Promise<number> | number;
51
+ /**
52
+ * Optional synchronous load-time snapshot of the model's usable context.
53
+ * Qwen3.5 dense/MoE expose this when adaptive paged-cache sizing is active.
54
+ */
55
+ contextLimits?(): SessionContextLimits;
56
+ /**
57
+ * Whether this loaded model instance has a complete image-input path.
58
+ *
59
+ * Optional so text-only and older wrappers continue to satisfy the
60
+ * structural contract. Supporting native wrappers snapshot this value after
61
+ * load, once the vision encoder/processor and any required cache backend are
62
+ * known to be available.
63
+ */
64
+ supportsImages?(): boolean;
65
+ /**
66
+ * Whether this bundled wrapper can capture full reasoning internally while
67
+ * returning a privacy-safe public result. Third-party implementations omit
68
+ * this capability and keep their original `includeReasoning` config.
69
+ */
70
+ supportsReplayReasoningCapture?(): boolean;
71
+ /**
72
+ * Whether this model's checkpoint template expects historical reasoning
73
+ * embedded in `message.content` instead of the structured
74
+ * `reasoningContent` field.
75
+ */
76
+ replaysAssistantRawText?(): boolean;
98
77
  chatSessionStart(messages: ChatMessage[], config?: ChatConfig | null): Promise<ChatResult>;
99
- chatSessionContinue(userMessage: string, images: Uint8Array[] | null, config?: ChatConfig | null): Promise<ChatResult>;
100
- chatSessionContinueTool(toolCallId: string, content: string, config?: ChatConfig | null): Promise<ChatResult>;
78
+ chatSessionContinue(messages: ChatMessage[], config?: ChatConfig | null): Promise<ChatResult>;
79
+ chatSessionContinueTool(messages: ChatMessage[], config?: ChatConfig | null): Promise<ChatResult>;
101
80
  /**
102
81
  * The optional `signal` parameter on every streaming entry point is
103
82
  * plumbed into the `_runChatStream` fast-abort path in the wrapper
@@ -108,9 +87,128 @@ export interface SessionCapableModel {
108
87
  * callers (the common direct-use path) just omit it.
109
88
  */
110
89
  chatStreamSessionStart(messages: ChatMessage[], config?: ChatConfig | null, signal?: AbortSignal): AsyncGenerator<ChatStreamEvent>;
111
- chatStreamSessionContinue(userMessage: string, images: Uint8Array[] | null, config?: ChatConfig | null, signal?: AbortSignal): AsyncGenerator<ChatStreamEvent>;
112
- chatStreamSessionContinueTool(toolCallId: string, content: string, config?: ChatConfig | null, signal?: AbortSignal): AsyncGenerator<ChatStreamEvent>;
90
+ chatStreamSessionContinue(messages: ChatMessage[], config?: ChatConfig | null, signal?: AbortSignal): AsyncGenerator<ChatStreamEvent>;
91
+ chatStreamSessionContinueTool(messages: ChatMessage[], config?: ChatConfig | null, signal?: AbortSignal): AsyncGenerator<ChatStreamEvent>;
113
92
  resetCaches(): void;
93
+ /**
94
+ * Whether the underlying native model has the block-paged KV cache
95
+ * adapter (`PagedKVCacheAdapter` + `BlockAllocator` + `LayerKVPool`)
96
+ * active.
97
+ *
98
+ * `true` iff the adapter was successfully constructed at load time
99
+ * (driven by the per-model `use_block_paged_cache` config flag, which
100
+ * defaults to ON for Qwen3 + LFM2 after parity verification and OFF
101
+ * for Gemma4 + Qwen3.5 + Qwen3.5 MoE pending parity validation; also
102
+ * always `false` on Qwen3.5 VLM checkpoints where
103
+ * `set_vision_encoder` rejects when the adapter is populated).
104
+ *
105
+ * When `true`, the native cache reuses SYS blocks across requests via
106
+ * content-addressing in the `BlockAllocator`'s prefix-hash table —
107
+ * the JS-side warm slot in
108
+ * `SessionRegistry.getOrCreateWarmAny(requestedSystem)` becomes
109
+ * redundant for stateless `/v1/messages` traffic. The server
110
+ * endpoint reads this getter to decide whether to allocate a fresh
111
+ * `ChatSession` per request (paged-active) or to lease the warm slot
112
+ * (non-paged); see `packages/server/src/endpoints/messages.ts`.
113
+ *
114
+ * Optional on the structural interface so models that pre-date the
115
+ * NAPI getter (notably `QianfanOCRModel` from `@mlx-node/vlm`, which
116
+ * has no paged-adapter wiring) still satisfy the type contract — a
117
+ * missing getter is treated as `false` (not paged) by callers.
118
+ * Surfaced as a synchronous method on every native wrapper that DOES
119
+ * support paged so the routing decision in the server doesn't need a
120
+ * model-thread roundtrip per request — the value is captured at load
121
+ * time and never changes for a given model instance.
122
+ */
123
+ hasBlockPagedCache?(): boolean;
124
+ /**
125
+ * MTP: whether the underlying native model can run speculative
126
+ * decoding. Surfaced by `Qwen3_5Model` / `Qwen3_5MoeModel` (an MTP
127
+ * head shipped in the checkpoint and loaded by persistence) and by
128
+ * `Gemma4Model` (an external draft model — DSpark or Google gemma-4
129
+ * assistant, auto-detected from the draft's config.json — attached
130
+ * via `loadModel` / `loadSession` `draftModelPath`; NOT in-checkpoint
131
+ * MTP heads); all other native wrappers omit the method, in
132
+ * which case callers treat a missing getter as `false` (no MTP).
133
+ *
134
+ * When `true`, {@link ChatSession#mergeConfig} auto-defaults the
135
+ * per-request `enableMtp` flag to `true` — the speculative-decode
136
+ * path takes over unless the caller explicitly opts out by passing
137
+ * `enableMtp: false` in their `ChatConfig` overlay. When `false`
138
+ * (or the method is missing), `enableMtp` is left untouched.
139
+ *
140
+ * Synchronous on every supporting wrapper so the auto-default check
141
+ * doesn't need a model-thread roundtrip per call — the value is
142
+ * captured at load time and never changes for a given model
143
+ * instance.
144
+ *
145
+ * ## Companion `ChatConfig` knobs (only meaningful when `enableMtp` is on)
146
+ *
147
+ * Two related `ChatConfig` fields tune the speculative-decode loop.
148
+ * They are forwarded verbatim to the native side via
149
+ * {@link SendOptions.config} (per-call overlay) or
150
+ * {@link ChatSessionOptions.defaultConfig} (session default), and
151
+ * `mergeConfig` shallow-merges per-call over per-session so an
152
+ * explicit per-send value always wins over the session default for
153
+ * the same field.
154
+ *
155
+ * - **`mtpDepth`** — pins the MTP draft depth per speculative cycle.
156
+ * On Qwen3.5 native MTP heads it is clamped to `[1, 5]` by the
157
+ * verify FFI contract, and when unset native code currently pins
158
+ * depth 1. Setting `mtpDepth` explicitly pins that value unless
159
+ * the caller also passes `mtpAdaptiveDepth: true` to opt into
160
+ * adaptive depth with the supplied maximum/seed. Gemma4 external
161
+ * drafts resolve the field per draft variant instead — see the
162
+ * Gemma4 section below.
163
+ * - **`mtpAdaptiveDepth`** — toggles the adaptive depth policy.
164
+ * Defaults to OFF for native MTP and assistants (Gemma4 DSpark has the
165
+ * family override documented below). When ON, the native-MTP default
166
+ * mode runs a 5-state machine
167
+ * (`Explore` → `Full` → {`NeighborProbe` | `Reduced` → `Probe`})
168
+ * with per-depth EMA tracking of
169
+ * `accepted_tokens / cycle_wall_ns` and picks the depth that
170
+ * maximizes that rate (DFlash-style, EMA decay α=0.3, drop-back
171
+ * threshold 0.75). `MLX_MTP_ADAPTIVE_DEPTH_MODE=expected-value`
172
+ * instead uses the MTPLX-style intra-cycle expected-value gate; by
173
+ * default it stops at its base depth, with deeper expansion kept
174
+ * research-only behind `MLX_MTP_EV_ALLOW_DEEPEN=1`.
175
+ * An explicit `false` always wins, pinning the chosen `mtpDepth` for
176
+ * every cycle. When `enableMtp` is false (or the model has no MTP
177
+ * head) the field is ignored.
178
+ *
179
+ * The defaults for both `mtpDepth` and `mtpAdaptiveDepth` are
180
+ * applied on the native side (see
181
+ * `crates/mlx-core/src/models/qwen3_5/chat_common.rs` MTP runtime
182
+ * flag inventory), so omitting them from `defaultConfig` /
183
+ * `SendOptions.config` is the recommended path for callers that
184
+ * just want speculative decoding "on with sensible defaults".
185
+ *
186
+ * ## Gemma4 external drafts (`draftModelPath`)
187
+ *
188
+ * Gemma4 reinterprets the knobs per draft variant (resolved in
189
+ * `gemma4/model.rs` `resolve_params`, always from the RAW config
190
+ * value — the engine's central `[1, 5]` clamp is an MTP-head
191
+ * contract that does not apply to external drafts):
192
+ *
193
+ * - **DSpark**: with both knobs unset, full draft blocks (the
194
+ * checkpoint's block size — 7 tokens on
195
+ * `dspark_gemma4_12b_block7`) run behind a short per-turn measurement
196
+ * against target-only AR. If DSpark loses on the current host/context,
197
+ * that turn permanently falls back to exact target-only decoding. An
198
+ * insufficiently long generation budget preserves the fixed-block path.
199
+ * An explicit `mtpDepth` acts as a CAP on the block (clamped to
200
+ * `[1, blockSize]`) and pins it unless `mtpAdaptiveDepth: true` opts the
201
+ * guard back in. Explicit `mtpAdaptiveDepth: false` disables the guard.
202
+ * - **Assistant** (Google `gemma-4-*-it-assistant`): chained AR
203
+ * drafting has no checkpoint-pinned block size — an unset
204
+ * `mtpDepth` drafts 3 tokens per cycle (`ASSISTANT_DEFAULT_DEPTH`,
205
+ * a quality/latency tradeoff, not a checkpoint contract), and an
206
+ * explicit `mtpDepth` clamps to `[1, 8]` (`ASSISTANT_MAX_DEPTH`).
207
+ *
208
+ * `mtpAdaptiveDepth` remains ignored for the assistant variant. Qwen3.5
209
+ * native-MTP semantics above are unchanged.
210
+ */
211
+ hasMtpWeights?(): boolean;
114
212
  }
115
213
  /** Per-call options for {@link ChatSession#send} / `sendStream`. */
116
214
  export interface SendOptions {
@@ -120,10 +218,22 @@ export interface SendOptions {
120
218
  * session forcibly restarts via `chatSessionStart`.
121
219
  */
122
220
  images?: Uint8Array[];
221
+ /**
222
+ * Optional audio bytes (encoded WAV) attached to this user turn. When
223
+ * the audio set differs from the session's current `lastAudioKey`, the
224
+ * session forcibly restarts via `chatSessionStart` (mirrors `images`).
225
+ * Only the unified Gemma 4 audio checkpoint consumes this.
226
+ */
227
+ audio?: Uint8Array[];
123
228
  /**
124
229
  * Per-call `ChatConfig` overlay applied on top of the session's
125
230
  * `defaultConfig`. `reuseCache` is always forced on regardless of
126
- * what the caller passes.
231
+ * what the caller passes. The overlay is shallow-merged on top of
232
+ * the session default, so per-call values always win over per-session
233
+ * values for the same field — including the speculative-decode
234
+ * knobs `enableMtp`, `mtpDepth`, and `mtpAdaptiveDepth`. See
235
+ * {@link SessionCapableModel.hasMtpWeights} for the full MTP knob
236
+ * surface and default-resolution rules.
127
237
  */
128
238
  config?: ChatConfig;
129
239
  /**
@@ -155,7 +265,12 @@ export interface ChatSessionOptions {
155
265
  /**
156
266
  * Default `ChatConfig` applied to every `send()` / `sendStream()`
157
267
  * / `sendToolResult()` call. Per-call config is shallow-merged on
158
- * top of this, and `reuseCache` is forced on.
268
+ * top of this, and `reuseCache` is forced on. Speculative-decode
269
+ * knobs (`enableMtp`, `mtpDepth`, `mtpAdaptiveDepth`) can be parked
270
+ * here as session-wide defaults and overridden per call via
271
+ * {@link SendOptions.config}; see
272
+ * {@link SessionCapableModel.hasMtpWeights} for the MTP knob surface
273
+ * and default-resolution rules.
159
274
  */
160
275
  defaultConfig?: ChatConfig;
161
276
  }
@@ -171,22 +286,32 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
171
286
  private readonly model;
172
287
  private readonly system;
173
288
  private readonly defaultConfig;
289
+ /** Tool definitions are conversation state for deterministic template replay. */
290
+ private activeTools;
174
291
  /**
175
292
  * Full conversation history tracked on the TS side. Appended to on
176
- * every successful turn. Only read back when the image-change path
177
- * triggers a restart normal text continues use the server-side
178
- * cache, not this array.
293
+ * every successful turn and sent on every role-aware native turn so
294
+ * the model-provided template remains the sole prompt authority.
179
295
  */
180
296
  private history;
181
297
  /**
182
298
  * Hex-encoded byte-identity key of the image set currently bound
183
- * to the server's KV cache (FNV-1a 64-bit; see `computeImagesKey`).
299
+ * to the server's KV cache (SHA-256; see `computeImagesKey`).
184
300
  * `null` when no images are cached. A `send()` whose new key
185
301
  * differs triggers a full `chatSessionStart` restart.
186
302
  */
187
303
  private lastImagesKey;
304
+ /**
305
+ * Hex-encoded byte-identity key of the audio set currently bound to the
306
+ * server's KV cache (see {@link computeAudioKey}). `null` when no audio is
307
+ * cached. A `send()` whose new key differs triggers a full
308
+ * `chatSessionStart` restart — the audio counterpart of `lastImagesKey`.
309
+ */
310
+ private lastAudioKey;
188
311
  private turnCount;
189
312
  private inFlight;
313
+ /** A failed/abandoned native turn must be followed by a full replay. */
314
+ private needsFullReplay;
190
315
  /**
191
316
  * Count of `ok` tool calls emitted by the prior assistant turn, or
192
317
  * `null` when the prior turn produced none. Gates every continuation
@@ -216,6 +341,32 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
216
341
  get turns(): number;
217
342
  /** Whether the session currently has images bound to its cache. */
218
343
  get hasImages(): boolean;
344
+ /** Load-time physical context snapshot, when exposed by the model. */
345
+ contextLimits(): SessionContextLimits | undefined;
346
+ /** Authoritative image-input capability of the loaded native model. */
347
+ supportsImages(): boolean;
348
+ /**
349
+ * Render and validate a complete message list against the model's physical
350
+ * context window without starting inference or mutating session/native cache
351
+ * state.
352
+ *
353
+ * HTTP streaming callers use this before committing SSE headers so an
354
+ * oversized prompt can still receive a protocol-shaped 400 response without
355
+ * delaying those headers until image processing, prefill, or the first
356
+ * generated token. The returned config carries the same output-budget clamp
357
+ * applied by the send entry points; those entry points intentionally repeat
358
+ * the check against their own authoritative history before native dispatch.
359
+ */
360
+ preflightContextCapacity(messages: readonly ChatMessage[], config?: ChatConfig): Promise<ChatConfig>;
361
+ /**
362
+ * Capacity-preflight one pending user/tool message against this session's
363
+ * preserved history without starting inference or mutating cache state.
364
+ *
365
+ * This is the exact counterpart of the delta `send*` paths. It matters for
366
+ * server-side prompt-cache hits where the HTTP request contains only the new
367
+ * message while the leased ChatSession owns the earlier conversation.
368
+ */
369
+ preflightPendingContextCapacity(pending: ChatMessage, config?: ChatConfig): Promise<ChatConfig>;
219
370
  /**
220
371
  * Count of `ok` tool calls from the most recent assistant turn, or
221
372
  * `null` when the trailing turn produced none. Non-null means the
@@ -237,9 +388,10 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
237
388
  /**
238
389
  * Send a user message and resolve with the assistant reply.
239
390
  *
240
- * Turn 0 and any turn whose image set has changed dispatch through
241
- * `chatSessionStart` with the full history. All other turns use
242
- * the cheap `chatSessionContinue` delta path.
391
+ * Turn 0 and any turn whose image set changed dispatch through
392
+ * `chatSessionStart`. Later turns pass the same complete structured
393
+ * history through `chatSessionContinue`; native code renders the
394
+ * model template and reuses KV on an exact token-prefix match.
243
395
  */
244
396
  send(userMessage: string, opts?: SendOptions): Promise<ChatResult>;
245
397
  /**
@@ -255,9 +407,9 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
255
407
  */
256
408
  sendStream(userMessage: string, opts?: SendOptions): AsyncGenerator<ChatStreamEvent>;
257
409
  /**
258
- * Send a tool-result turn. Always dispatches
259
- * `chatSessionContinueTool` tool turns never change image state,
260
- * so there is no restart path here.
410
+ * Send a tool-result turn. The declaring assistant tool call and the
411
+ * pending result are both included in the full history passed to
412
+ * `chatSessionContinueTool`.
261
413
  *
262
414
  * Rejects if the prior assistant turn emitted more than one `ok`
263
415
  * tool call: the chat-session API only supports exactly one tool
@@ -268,16 +420,61 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
268
420
  * hit this must tighten the prompt / tool spec or reset the
269
421
  * session.
270
422
  *
423
+ * `isError` is the structured tool-error signal. When `true`, the
424
+ * native renderer prepends a short, model-facing error marker to
425
+ * `content` inside the wire-format tool block so the model
426
+ * receives a clear text-level cue that the tool result represents
427
+ * a failure. The structured field is stored verbatim on the
428
+ * appended `{ role: 'tool', ... }` history entry so cold-replay
429
+ * (image-change restart, `startFromHistory*`, server-side
430
+ * `SessionRegistry` cache-miss rebuild) re-renders the marker
431
+ * consistently with the live turn. Defaults to `undefined` (no
432
+ * marker). Pass through verbatim — we do NOT infer error from
433
+ * `content`.
434
+ *
271
435
  * Appends a `{ role: 'tool', ... }` message to history on success.
272
436
  */
273
437
  sendToolResult(toolCallId: string, content: string, opts?: {
438
+ isError?: boolean;
274
439
  config?: ChatConfig;
275
440
  }): Promise<ChatResult>;
276
- /** Streaming variant of {@link ChatSession#sendToolResult}. */
441
+ /**
442
+ * Cold-replay a tool result through the start path: re-render the
443
+ * full preserved history (including the prior media turn and the
444
+ * unresolved tool-call assistant turn) plus this tool message. Used
445
+ * when the native session is cold (turnCount===0 — e.g. after an
446
+ * interrupted media-held replay rolled the cache back) and by the
447
+ * media-held rejection catch. `mediaChanged=true` forces a
448
+ * resetCaches so the prefill always starts from a guaranteed-clean
449
+ * cache; `isFirstTurn=false` because a tool result always follows a
450
+ * prior tool-call turn.
451
+ */
452
+ private replayToolResultThroughStartPath;
453
+ /**
454
+ * Streaming variant of {@link ChatSession#sendToolResult}.
455
+ *
456
+ * `isError` mirrors the non-streaming entry point — when `true`,
457
+ * the native renderer prepends a short, model-facing error marker
458
+ * to `content` inside the wire-format tool block. The structured
459
+ * field is stored verbatim on the appended `{ role: 'tool', ... }`
460
+ * history entry so cold-replay re-renders the marker consistently
461
+ * with the live streaming turn.
462
+ */
277
463
  sendToolResultStream(toolCallId: string, content: string, opts?: {
464
+ isError?: boolean;
278
465
  config?: ChatConfig;
279
466
  signal?: AbortSignal;
280
467
  }): AsyncGenerator<ChatStreamEvent>;
468
+ /**
469
+ * Streaming counterpart of {@link replayToolResultThroughStartPath}:
470
+ * cold-replay a tool result through the start stream. Used by the
471
+ * turn-0 precheck and the media-held rejection catch in
472
+ * {@link sendToolResultStream}. The start stream owns the history
473
+ * push, turnCount increment, and media-key rehydration; callers keep
474
+ * `delegated`/early-return semantics so the commit `finally` stays
475
+ * off.
476
+ */
477
+ private replayToolResultThroughStartStreamPath;
281
478
  /**
282
479
  * Reset the session state.
283
480
  *
@@ -285,6 +482,23 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
285
482
  * image key, and turn counter so the next `send()` goes through
286
483
  * `chatSessionStart` again.
287
484
  *
485
+ * This is a full wipe — safe default for public callers. It always
486
+ * calls `model.resetCaches()`, which is the ONLY behavior exposed
487
+ * on the public API because the underlying `SessionCapableModel`
488
+ * is shared across every `ChatSession` lifetime via the native
489
+ * `ModelRegistry`: a partial wipe that leaves the shared native
490
+ * KV cache intact would leak a previous (unrelated) request's
491
+ * cached prefix into the next `chat_session_start_sync` call. The
492
+ * server-side warm-lease replay path (where preserving the native
493
+ * cache is correct) uses its own server-private helper gated by
494
+ * the `SessionRegistry` HIT signal — the only authoritative proof
495
+ * that the native cache genuinely belongs to this chain. That
496
+ * helper lives inside `@mlx-node/server`, never touches the
497
+ * `@mlx-node/lm` export map, and is not reachable from downstream
498
+ * consumers. Public consumers of `@mlx-node/lm` have no such HIT
499
+ * signal, so the public API intentionally offers only the full-wipe
500
+ * option.
501
+ *
288
502
  * Returns `Promise<void>` for an async-friendly signature even
289
503
  * though `resetCaches()` is currently synchronous.
290
504
  */
@@ -385,13 +599,45 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
385
599
  * rationale.
386
600
  */
387
601
  private recordToolCallFanout;
602
+ /**
603
+ * Persist the effective tools only when their turn commits successfully.
604
+ * Preflights and failed/abandoned turns intentionally never call this.
605
+ */
606
+ private commitActiveTools;
388
607
  /**
389
608
  * Merge default + per-call config and force `reuseCache: true`.
390
609
  * The session path is a session-reuse operation by construction —
391
610
  * `reuseCache: false` on the continue path would wipe the very
392
611
  * cache the delta depends on.
612
+ *
613
+ * Tool resolution here is side-effect free because public capacity
614
+ * preflights use this same merge path. Successful turn commit sites call
615
+ * {@link commitActiveTools} after native inference finishes.
616
+ *
617
+ * MTP auto-default: if neither `defaultConfig` nor `overlay`
618
+ * sets `enableMtp` AND the underlying model exposes
619
+ * `hasMtpWeights()` returning `true`, set `enableMtp = true` so the
620
+ * speculative-decode path runs out of the box on MTP-capable
621
+ * checkpoints. An explicit `false` from either source wins (the
622
+ * undefined-check below preserves it). This duck-typed check also
623
+ * covers Gemma4 with an external draft attached — DSpark or Google
624
+ * assistant (`hasMtpWeights()` reports the external draft there,
625
+ * not in-checkpoint MTP heads).
393
626
  */
394
627
  private mergeConfig;
628
+ /**
629
+ * Render the exact full prompt and constrain generation to the physical KV
630
+ * window before native code allocates a block. Models that do not expose
631
+ * both the tokenizer seam and a load-time context snapshot retain their
632
+ * existing behavior.
633
+ *
634
+ * The returned config is a copy only when `maxNewTokens` needs clamping.
635
+ * An omitted output budget stays omitted when the native default fits; it is
636
+ * made explicit only when the remaining window is smaller than that default.
637
+ */
638
+ private constrainToContextCapacity;
639
+ /** Full history that a pending user/tool turn would render, without mutation. */
640
+ private historyWithPending;
395
641
  /**
396
642
  * Shared start-path logic for `send()`. Handles both the turn-0
397
643
  * first-ever-send case and the image-change mid-session restart
@@ -400,8 +646,24 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
400
646
  * image set.
401
647
  */
402
648
  private runStartPath;
649
+ /**
650
+ * Core of {@link runStartPath} that takes a PRE-BUILT pending
651
+ * `ChatMessage` (user or tool) instead of building a user message
652
+ * itself. The cold-restart catch in `sendToolResult()` replays the
653
+ * conversation through this core with a pending `{ role: 'tool', ... }`
654
+ * message so the tool-result turn is re-rendered against the full
655
+ * history without duplicating the start-path bookkeeping.
656
+ */
657
+ private runStartPathWithMessage;
403
658
  /** Streaming counterpart to {@link runStartPath}. */
404
659
  private runStartStreamPath;
660
+ /**
661
+ * Streaming counterpart to {@link runStartPathWithMessage}: replays
662
+ * through the cold start stream from a PRE-BUILT pending
663
+ * `ChatMessage`. The cold-restart catch in `sendToolResultStream()`
664
+ * delegates here with a pending `{ role: 'tool', ... }` message.
665
+ */
666
+ private runStartStreamPathWithMessage;
405
667
  /**
406
668
  * Shared pre-start bookkeeping for both `send()` and `sendStream()`:
407
669
  *
@@ -418,16 +680,22 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
418
680
  * - On a fresh / reset history, re-inject the system prompt.
419
681
  */
420
682
  private prepareStartPath;
421
- /** Build a user `ChatMessage` with or without attached images. */
683
+ /** Build a user `ChatMessage` with or without attached images/audio. */
422
684
  private buildUserMessage;
423
685
  /**
424
686
  * Walk the history backward to find the most recent user message
425
- * with images and return its FNV-1a key. Used by
687
+ * with images and return its SHA-256 key. Used by
426
688
  * {@link startFromHistory} and {@link startFromHistoryStream} to
427
689
  * hydrate `lastImagesKey` after a cold replay, so subsequent delta
428
690
  * continues correctly detect image changes.
429
691
  */
430
692
  private computeTrailingImagesKey;
693
+ /**
694
+ * Audio counterpart of {@link computeTrailingImagesKey}: walk history
695
+ * backward to the most recent user message carrying audio and return its
696
+ * SHA-256 key, so a cold replay hydrates `lastAudioKey` correctly.
697
+ */
698
+ private computeTrailingAudioKey;
431
699
  /**
432
700
  * Derive the post-prime value of `unresolvedOkToolCallCount` from
433
701
  * the primed history. Walks backward to the most recent assistant
@@ -1 +1 @@
1
- {"version":3,"file":"chat-session.d.ts","sourceRoot":"","sources":["../src/chat-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AACH,OAA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