@mlx-node/lm 0.0.10 → 0.0.13
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.
- package/dist/chat-session.d.ts +175 -68
- package/dist/chat-session.d.ts.map +1 -1
- package/dist/chat-session.js +271 -122
- package/dist/family-data.d.ts +407 -0
- package/dist/family-data.d.ts.map +1 -0
- package/dist/family-data.js +381 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/models/model-loader.d.ts +91 -135
- package/dist/models/model-loader.d.ts.map +1 -1
- package/dist/models/model-loader.js +74 -179
- package/dist/models/paged-config-override.d.ts +0 -2
- package/dist/models/paged-config-override.d.ts.map +1 -1
- package/dist/models/paged-config-override.js +29 -6
- package/dist/models/qwen3_5-configs.d.ts +1 -3
- package/dist/models/qwen3_5-configs.d.ts.map +1 -1
- package/dist/stream.d.ts +29 -5
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +127 -24
- package/package.json +7 -3
- package/dist/interfaces.d.ts +0 -3
- package/dist/interfaces.d.ts.map +0 -1
- package/dist/interfaces.js +0 -1
package/dist/chat-session.d.ts
CHANGED
|
@@ -50,7 +50,8 @@ export interface SessionCapableModel {
|
|
|
50
50
|
expandedPromptTokenCount?(promptTokens: Uint32Array, messages: ChatMessage[]): Promise<number> | number;
|
|
51
51
|
/**
|
|
52
52
|
* Optional synchronous load-time snapshot of the model's usable context.
|
|
53
|
-
* Qwen3.5 dense/MoE expose this when
|
|
53
|
+
* Qwen3.5 dense/MoE and Muse-Glimmer expose this when paged-cache sizing is
|
|
54
|
+
* active.
|
|
54
55
|
*/
|
|
55
56
|
contextLimits?(): SessionContextLimits;
|
|
56
57
|
/**
|
|
@@ -74,9 +75,14 @@ export interface SessionCapableModel {
|
|
|
74
75
|
* `reasoningContent` field.
|
|
75
76
|
*/
|
|
76
77
|
replaysAssistantRawText?(): boolean;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Non-streaming entry points accept the platform-native AbortSignal.
|
|
80
|
+
* The bundled wrappers translate it to the Rust atomic cancellation
|
|
81
|
+
* flag without exposing the native two-phase handle API.
|
|
82
|
+
*/
|
|
83
|
+
chatSessionStart(messages: ChatMessage[], config?: ChatConfig | null, signal?: AbortSignal): Promise<ChatResult>;
|
|
84
|
+
chatSessionContinue(messages: ChatMessage[], config?: ChatConfig | null, signal?: AbortSignal): Promise<ChatResult>;
|
|
85
|
+
chatSessionContinueTool(messages: ChatMessage[], config?: ChatConfig | null, signal?: AbortSignal): Promise<ChatResult>;
|
|
80
86
|
/**
|
|
81
87
|
* The optional `signal` parameter on every streaming entry point is
|
|
82
88
|
* plumbed into the `_runChatStream` fast-abort path in the wrapper
|
|
@@ -89,7 +95,20 @@ export interface SessionCapableModel {
|
|
|
89
95
|
chatStreamSessionStart(messages: ChatMessage[], config?: ChatConfig | null, signal?: AbortSignal): AsyncGenerator<ChatStreamEvent>;
|
|
90
96
|
chatStreamSessionContinue(messages: ChatMessage[], config?: ChatConfig | null, signal?: AbortSignal): AsyncGenerator<ChatStreamEvent>;
|
|
91
97
|
chatStreamSessionContinueTool(messages: ChatMessage[], config?: ChatConfig | null, signal?: AbortSignal): AsyncGenerator<ChatStreamEvent>;
|
|
92
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Wipe the native KV caches and cached token history.
|
|
100
|
+
*
|
|
101
|
+
* Native models return a `Promise<void>` (the reset is dispatched
|
|
102
|
+
* onto the model thread's command queue and resolves once
|
|
103
|
+
* processed — H1a: a reset queued behind an in-flight turn must
|
|
104
|
+
* park a promise, never the Node event loop). The union keeps
|
|
105
|
+
* synchronous test doubles valid; every consumer in this file
|
|
106
|
+
* `await`s the result so command-queue ordering is preserved
|
|
107
|
+
* relative to subsequent session calls.
|
|
108
|
+
*/
|
|
109
|
+
resetCaches(): void | Promise<void>;
|
|
110
|
+
/** Release scheduler-owned state for one logical session owner. */
|
|
111
|
+
releaseCacheOwner?(ownerId: string): void | Promise<void>;
|
|
93
112
|
/**
|
|
94
113
|
* Whether the underlying native model has the block-paged KV cache
|
|
95
114
|
* adapter (`PagedKVCacheAdapter` + `BlockAllocator` + `LayerKVPool`)
|
|
@@ -97,15 +116,15 @@ export interface SessionCapableModel {
|
|
|
97
116
|
*
|
|
98
117
|
* `true` iff the adapter was successfully constructed at load time
|
|
99
118
|
* (driven by the per-model `use_block_paged_cache` config flag, which
|
|
100
|
-
* defaults to ON for Qwen3
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
119
|
+
* defaults to ON for Qwen3, LFM2, Gemma4, and Qwen3.5 dense/MoE after
|
|
120
|
+
* parity validation). Qwen3.5 VLM instances expose the loaded paged
|
|
121
|
+
* text lane while media/MTP requests retain their model-specific ordered
|
|
122
|
+
* execution path.
|
|
104
123
|
*
|
|
105
124
|
* When `true`, the native cache reuses SYS blocks across requests via
|
|
106
125
|
* content-addressing in the `BlockAllocator`'s prefix-hash table —
|
|
107
126
|
* the JS-side warm slot in
|
|
108
|
-
* `SessionRegistry.getOrCreateWarmAny(requestedSystem)` becomes
|
|
127
|
+
* `SessionRegistry.getOrCreateWarmAny(requestedSystem, cacheSalt)` becomes
|
|
109
128
|
* redundant for stateless `/v1/messages` traffic. The server
|
|
110
129
|
* endpoint reads this getter to decide whether to allocate a fresh
|
|
111
130
|
* `ChatSession` per request (paged-active) or to lease the warm slot
|
|
@@ -121,10 +140,21 @@ export interface SessionCapableModel {
|
|
|
121
140
|
* time and never changes for a given model instance.
|
|
122
141
|
*/
|
|
123
142
|
hasBlockPagedCache?(): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Maximum number of independent chat sequences this model can advance in
|
|
145
|
+
* one scheduler lane. Models without a continuous-batching scheduler omit
|
|
146
|
+
* the method and remain on the server's single-dispatch lane.
|
|
147
|
+
*
|
|
148
|
+
* The value is synchronous and fixed for normal server operation so the
|
|
149
|
+
* per-model admission semaphore can be constructed without a model-thread
|
|
150
|
+
* round trip. A value below two is treated as exclusive execution.
|
|
151
|
+
*/
|
|
152
|
+
maxConcurrentSequences?(): number;
|
|
124
153
|
/**
|
|
125
154
|
* MTP: whether the underlying native model can run speculative
|
|
126
155
|
* decoding. Surfaced by `Qwen3_5Model` / `Qwen3_5MoeModel` (an MTP
|
|
127
|
-
* head shipped in the checkpoint
|
|
156
|
+
* head shipped in the checkpoint, or an external DFlash2 companion on
|
|
157
|
+
* dense Qwen3.5) and by
|
|
128
158
|
* `Gemma4Model` (an external draft model — DSpark or Google gemma-4
|
|
129
159
|
* assistant, auto-detected from the draft's config.json — attached
|
|
130
160
|
* via `loadModel` / `loadSession` `draftModelPath`; NOT in-checkpoint
|
|
@@ -137,6 +167,11 @@ export interface SessionCapableModel {
|
|
|
137
167
|
* `enableMtp: false` in their `ChatConfig` overlay. When `false`
|
|
138
168
|
* (or the method is missing), `enableMtp` is left untouched.
|
|
139
169
|
*
|
|
170
|
+
* A pure CAPABILITY query: `true` means speculative decoding is available,
|
|
171
|
+
* not that it is a win. A family with a complete but unprofitable head
|
|
172
|
+
* suppresses the auto-default via {@link SessionCapableModel.mtpAutoEnabled}
|
|
173
|
+
* while still reporting `true` here.
|
|
174
|
+
*
|
|
140
175
|
* Synchronous on every supporting wrapper so the auto-default check
|
|
141
176
|
* doesn't need a model-thread roundtrip per call — the value is
|
|
142
177
|
* captured at load time and never changes for a given model
|
|
@@ -157,9 +192,8 @@ export interface SessionCapableModel {
|
|
|
157
192
|
* verify FFI contract, and when unset native code currently pins
|
|
158
193
|
* depth 1. Setting `mtpDepth` explicitly pins that value unless
|
|
159
194
|
* the caller also passes `mtpAdaptiveDepth: true` to opt into
|
|
160
|
-
* adaptive depth with the supplied maximum/seed.
|
|
161
|
-
*
|
|
162
|
-
* Gemma4 section below.
|
|
195
|
+
* adaptive depth with the supplied maximum/seed. External draft models
|
|
196
|
+
* resolve the field against their checkpoint width instead — see below.
|
|
163
197
|
* - **`mtpAdaptiveDepth`** — toggles the adaptive depth policy.
|
|
164
198
|
* Defaults to OFF for native MTP and assistants (Gemma4 DSpark has the
|
|
165
199
|
* family override documented below). When ON, the native-MTP default
|
|
@@ -183,6 +217,16 @@ export interface SessionCapableModel {
|
|
|
183
217
|
* `SendOptions.config` is the recommended path for callers that
|
|
184
218
|
* just want speculative decoding "on with sensible defaults".
|
|
185
219
|
*
|
|
220
|
+
* ## Qwen3.8 DFlash2 (`draftModelPath`)
|
|
221
|
+
*
|
|
222
|
+
* A dense Qwen3.8 target can attach `z-lab/Qwen3.8-27B-DFlash2`. Its
|
|
223
|
+
* checkpoint block size is 8 total target rows: one anchor plus seven
|
|
224
|
+
* proposals. With `mtpDepth` unset all seven proposals are used; an
|
|
225
|
+
* explicit value clamps to `[1, 7]`. `mtpAdaptiveDepth` is off by default
|
|
226
|
+
* and may be enabled explicitly for the engine's measured AR fallback.
|
|
227
|
+
* DFlash2 uses flat target caches so hybrid GDN state can be rewound by
|
|
228
|
+
* snapshot plus tape replay after verification.
|
|
229
|
+
*
|
|
186
230
|
* ## Gemma4 external drafts (`draftModelPath`)
|
|
187
231
|
*
|
|
188
232
|
* Gemma4 reinterprets the knobs per draft variant (resolved in
|
|
@@ -209,6 +253,19 @@ export interface SessionCapableModel {
|
|
|
209
253
|
* native-MTP semantics above are unchanged.
|
|
210
254
|
*/
|
|
211
255
|
hasMtpWeights?(): boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Whether {@link ChatSession#mergeConfig} should turn `enableMtp` ON for this
|
|
258
|
+
* model when the caller sets nothing. Separate from
|
|
259
|
+
* {@link SessionCapableModel.hasMtpWeights}, which stays a pure capability
|
|
260
|
+
* query — a family that routes `enableMtp` turns into an exclusive scheduler
|
|
261
|
+
* lane and out of continuous batching can be a net loss at default settings.
|
|
262
|
+
*
|
|
263
|
+
* Absent or `true` → auto-default whenever `hasMtpWeights()` is `true`, so
|
|
264
|
+
* every family predating this method behaves identically. `false` → leave
|
|
265
|
+
* `enableMtp` undefined. A DEFAULT, not a ban: an explicit `enableMtp: true`
|
|
266
|
+
* still enables speculation.
|
|
267
|
+
*/
|
|
268
|
+
mtpAutoEnabled?(): boolean;
|
|
212
269
|
}
|
|
213
270
|
/** Per-call options for {@link ChatSession#send} / `sendStream`. */
|
|
214
271
|
export interface SendOptions {
|
|
@@ -237,20 +294,24 @@ export interface SendOptions {
|
|
|
237
294
|
*/
|
|
238
295
|
config?: ChatConfig;
|
|
239
296
|
/**
|
|
240
|
-
* Optional AbortSignal
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* `
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
297
|
+
* Optional AbortSignal for client-disconnect-aware cancellation.
|
|
298
|
+
*
|
|
299
|
+
* Streaming entry points (`sendStream`, `sendToolResultStream`,
|
|
300
|
+
* `startFromHistoryStream`): the inner `_runChatStream` adapter wakes
|
|
301
|
+
* from `waitForItem()` on abort, calls `handle.cancel()` on the
|
|
302
|
+
* native handle, and unwinds the stream without throwing an
|
|
303
|
+
* AbortError — the outer consumer's `for await` just ends early.
|
|
304
|
+
*
|
|
305
|
+
* Non-streaming entry points (`send` / `sendToolResult` /
|
|
306
|
+
* `startFromHistory`) honor it too (H2): an already-aborted signal
|
|
307
|
+
* rejects before dispatch, and the bundled model wrappers translate a
|
|
308
|
+
* mid-turn abort to the native turn flag. The public method remains one
|
|
309
|
+
* ordinary Promise and rejects with `"chat session cancelled"`.
|
|
310
|
+
*
|
|
311
|
+
* Intended for HTTP endpoints that flip a controller on
|
|
312
|
+
* `res.once('close', …)` so client disconnect stops the native
|
|
313
|
+
* decode at the next safepoint rather than running it to completion
|
|
314
|
+
* under the per-model mutex.
|
|
254
315
|
*/
|
|
255
316
|
signal?: AbortSignal;
|
|
256
317
|
}
|
|
@@ -286,6 +347,19 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
|
|
|
286
347
|
private readonly model;
|
|
287
348
|
private readonly system;
|
|
288
349
|
private readonly defaultConfig;
|
|
350
|
+
/**
|
|
351
|
+
* Stable native cache/scheduler identity for this JS session.
|
|
352
|
+
*
|
|
353
|
+
* Direct HTTP callers do not carry the agent provider's cacheOwnerId. If
|
|
354
|
+
* they reach a paged model without an owner, native must conservatively use
|
|
355
|
+
* the legacy exclusive lane because sequence zero cannot represent two live
|
|
356
|
+
* requests. Give every ChatSession its own identity while still allowing an
|
|
357
|
+
* explicit provider identity to override it.
|
|
358
|
+
*/
|
|
359
|
+
private cacheOwnerId;
|
|
360
|
+
/** The native owner used by this session, retained as a set for retryable release. */
|
|
361
|
+
private readonly nativeCacheOwnerIds;
|
|
362
|
+
private disposed;
|
|
289
363
|
/** Tool definitions are conversation state for deterministic template replay. */
|
|
290
364
|
private activeTools;
|
|
291
365
|
/**
|
|
@@ -296,14 +370,14 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
|
|
|
296
370
|
private history;
|
|
297
371
|
/**
|
|
298
372
|
* Hex-encoded byte-identity key of the image set currently bound
|
|
299
|
-
* to the server's KV cache (SHA-256; see `
|
|
373
|
+
* to the server's KV cache (SHA-256; see `computeByteListKey`).
|
|
300
374
|
* `null` when no images are cached. A `send()` whose new key
|
|
301
375
|
* differs triggers a full `chatSessionStart` restart.
|
|
302
376
|
*/
|
|
303
377
|
private lastImagesKey;
|
|
304
378
|
/**
|
|
305
379
|
* Hex-encoded byte-identity key of the audio set currently bound to the
|
|
306
|
-
* server's KV cache (see {@link
|
|
380
|
+
* server's KV cache (see {@link computeByteListKey}). `null` when no audio is
|
|
307
381
|
* cached. A `send()` whose new key differs triggers a full
|
|
308
382
|
* `chatSessionStart` restart — the audio counterpart of `lastImagesKey`.
|
|
309
383
|
*/
|
|
@@ -437,6 +511,7 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
|
|
|
437
511
|
sendToolResult(toolCallId: string, content: string, opts?: {
|
|
438
512
|
isError?: boolean;
|
|
439
513
|
config?: ChatConfig;
|
|
514
|
+
signal?: AbortSignal;
|
|
440
515
|
}): Promise<ChatResult>;
|
|
441
516
|
/**
|
|
442
517
|
* Cold-replay a tool result through the start path: re-render the
|
|
@@ -445,9 +520,9 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
|
|
|
445
520
|
* when the native session is cold (turnCount===0 — e.g. after an
|
|
446
521
|
* interrupted media-held replay rolled the cache back) and by the
|
|
447
522
|
* media-held rejection catch. `mediaChanged=true` forces a
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
523
|
+
* native cache invalidation so the prefill starts from a guaranteed-clean
|
|
524
|
+
* owner; `isFirstTurn=false` because a tool result always follows a prior
|
|
525
|
+
* tool-call turn.
|
|
451
526
|
*/
|
|
452
527
|
private replayToolResultThroughStartPath;
|
|
453
528
|
/**
|
|
@@ -478,31 +553,38 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
|
|
|
478
553
|
/**
|
|
479
554
|
* Reset the session state.
|
|
480
555
|
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
* `chatSessionStart` again.
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
* the
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
* option.
|
|
501
|
-
*
|
|
502
|
-
* Returns `Promise<void>` for an async-friendly signature even
|
|
503
|
-
* though `resetCaches()` is currently synchronous.
|
|
556
|
+
* Invalidates this session's native KV state and wipes local history,
|
|
557
|
+
* media keys, and turn counter so the next `send()` goes through
|
|
558
|
+
* `chatSessionStart` again. Block-paged models release only this stable
|
|
559
|
+
* session owner; clearing the model-wide scheduler would invalidate every
|
|
560
|
+
* other live `ChatSession`. Exclusive/flat models retain the model-wide
|
|
561
|
+
* `resetCaches()` barrier because they have no independently releasable
|
|
562
|
+
* owner state.
|
|
563
|
+
*
|
|
564
|
+
* Native invalidation is async: the release/reset command is awaited so it
|
|
565
|
+
* has fully drained through the model thread before this promise resolves —
|
|
566
|
+
* callers that `await reset()` and
|
|
567
|
+
* then start a turn keep strict command-queue ordering. Because the
|
|
568
|
+
* await genuinely suspends, `reset()` RESERVES the same in-flight
|
|
569
|
+
* guard as the send entry points for its whole duration: any
|
|
570
|
+
* concurrent `send*()`, `reset()`, `primeHistory()`, or
|
|
571
|
+
* `startFromHistory*()` on this session rejects until the reset
|
|
572
|
+
* settles, so a racing turn can never commit against the pre-wipe
|
|
573
|
+
* history (or have its state erased mid-commit). If native invalidation
|
|
574
|
+
* rejects, no JS state is wiped and the guard is released.
|
|
504
575
|
*/
|
|
505
576
|
reset(): Promise<void>;
|
|
577
|
+
/**
|
|
578
|
+
* Permanently dispose this JS session and release its native scheduler
|
|
579
|
+
* owner. The operation is awaited and idempotent; it rejects while
|
|
580
|
+
* a turn is in flight so native state cannot be torn down mid-decode.
|
|
581
|
+
*
|
|
582
|
+
* A caller-supplied first `cacheOwnerId` becomes this session's stable owner
|
|
583
|
+
* just like the generated default. Do not share an explicit owner id between
|
|
584
|
+
* independently disposed sessions: disposing either session releases that
|
|
585
|
+
* owner's native scheduler state for both.
|
|
586
|
+
*/
|
|
587
|
+
dispose(): Promise<void>;
|
|
506
588
|
/**
|
|
507
589
|
* Prime the session history without running inference.
|
|
508
590
|
*
|
|
@@ -532,7 +614,9 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
|
|
|
532
614
|
* stay on the delta path, and subsequent image turns correctly
|
|
533
615
|
* trigger restart).
|
|
534
616
|
*/
|
|
535
|
-
startFromHistory(config?: ChatConfig
|
|
617
|
+
startFromHistory(config?: ChatConfig, opts?: {
|
|
618
|
+
signal?: AbortSignal;
|
|
619
|
+
}): Promise<ChatResult>;
|
|
536
620
|
/**
|
|
537
621
|
* Streaming counterpart to {@link startFromHistory}.
|
|
538
622
|
*
|
|
@@ -544,6 +628,17 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
|
|
|
544
628
|
* is a no-op: the primed state stays intact so the caller can retry.
|
|
545
629
|
*/
|
|
546
630
|
startFromHistoryStream(config?: ChatConfig, signal?: AbortSignal): AsyncGenerator<ChatStreamEvent>;
|
|
631
|
+
/**
|
|
632
|
+
* Dispatch one non-streaming native turn through the public AbortSignal
|
|
633
|
+
* surface (H2). The model wrapper owns the attach-race-safe translation
|
|
634
|
+
* from AbortSignal to the lower-level native operation handle; ChatSession
|
|
635
|
+
* never exposes that two-phase primitive to callers.
|
|
636
|
+
*
|
|
637
|
+
* Callers sit inside the entry points' existing try/finally blocks,
|
|
638
|
+
* so a rejection here releases `inFlight` and (on the delta paths)
|
|
639
|
+
* sets `needsFullReplay` exactly like any other native failure.
|
|
640
|
+
*/
|
|
641
|
+
private runNonStreamingNative;
|
|
547
642
|
/**
|
|
548
643
|
* Gate plain-text continuation entry points (`send`, `sendStream`)
|
|
549
644
|
* on the tool-call resolution invariant. Any outstanding `ok` tool
|
|
@@ -611,20 +706,31 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
|
|
|
611
706
|
* cache the delta depends on.
|
|
612
707
|
*
|
|
613
708
|
* Tool resolution here is side-effect free because public capacity
|
|
614
|
-
* preflights use this same merge path
|
|
615
|
-
* {@link commitActiveTools} after native
|
|
709
|
+
* preflights use this same merge path with owner establishment disabled.
|
|
710
|
+
* Successful turn commit sites call {@link commitActiveTools} after native
|
|
711
|
+
* inference finishes.
|
|
616
712
|
*
|
|
617
713
|
* MTP auto-default: if neither `defaultConfig` nor `overlay`
|
|
618
714
|
* sets `enableMtp` AND the underlying model exposes
|
|
619
|
-
* `hasMtpWeights()` returning `true
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
715
|
+
* `hasMtpWeights()` returning `true` AND
|
|
716
|
+
* {@link ChatSession#mtpAutoDefaultAllowed} agrees, set
|
|
717
|
+
* `enableMtp = true` so the speculative-decode path runs out of the
|
|
718
|
+
* box on MTP-capable checkpoints. An explicit `false` from either
|
|
719
|
+
* source wins (the undefined-check below preserves it). This
|
|
720
|
+
* duck-typed check also covers Gemma4 with an external draft
|
|
721
|
+
* attached — DSpark or Google assistant (`hasMtpWeights()` reports
|
|
722
|
+
* the external draft there, not in-checkpoint MTP heads).
|
|
626
723
|
*/
|
|
627
724
|
private mergeConfig;
|
|
725
|
+
/**
|
|
726
|
+
* Whether an MTP-capable model wants `enableMtp` on for a caller who set
|
|
727
|
+
* nothing. `mtpAutoEnabled()` is authoritative in both directions when
|
|
728
|
+
* present; otherwise {@link MTP_AUTO_DEFAULT_SUPPRESSED_MODELS} is matched
|
|
729
|
+
* along the prototype CHAIN rather than by a bare `constructor.name`, so it
|
|
730
|
+
* still fires through the `makeStreamingModel` wrapper subclass that
|
|
731
|
+
* `@mlx-node/lm` actually hands to `ChatSession`.
|
|
732
|
+
*/
|
|
733
|
+
private mtpAutoDefaultAllowed;
|
|
628
734
|
/**
|
|
629
735
|
* Render the exact full prompt and constrain generation to the physical KV
|
|
630
736
|
* window before native code allocates a block. Models that do not expose
|
|
@@ -667,8 +773,9 @@ export declare class ChatSession<M extends SessionCapableModel = SessionCapableM
|
|
|
667
773
|
/**
|
|
668
774
|
* Shared pre-start bookkeeping for both `send()` and `sendStream()`:
|
|
669
775
|
*
|
|
670
|
-
* - On an image-change restart (turn >= 1),
|
|
671
|
-
*
|
|
776
|
+
* - On an image-change restart (turn >= 1), release this session's native
|
|
777
|
+
* cache owner so the new image set gets a fresh prefill without wiping
|
|
778
|
+
* concurrently live owners. History is
|
|
672
779
|
* intentionally preserved — `chatSessionStart` receives the full
|
|
673
780
|
* accumulated conversation plus the new user turn so the jinja
|
|
674
781
|
* render walks every prior turn and every prior image again
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-session.d.ts","sourceRoot":"","sources":["../src/chat-session.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chat-session.d.ts","sourceRoot":"","sources":["../src/chat-session.ts"],"names":[],"mappings":"AAyFA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAA4B,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEpH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA4CnD;;;;;;;GAOG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAI3C,QAAQ,CAAC,YAAY,EAAE,MAAM;IAC7B,QAAQ,CAAC,qBAAqB,EAAE,MAAM;IAJxC,QAAQ,CAAC,IAAI,6BAA6B;IAE1C,YACW,YAAY,EAAE,MAAM,EACpB,qBAAqB,EAAE,MAAM,EAOvC;CACF;AAED,0EAA0E;AAC1E,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAK9D;AAED,8EAA8E;AAC9E,MAAM,WAAW,oBAAoB;IACnC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;CACxB;AAyLD;;;;;;;;GAQG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,iBAAiB,CAAC,CAChB,QAAQ,EAAE,WAAW,EAAE,EACvB,mBAAmB,CAAC,EAAE,OAAO,GAAG,IAAI,EACpC,KAAK,CAAC,EAAE,cAAc,EAAE,GAAG,IAAI,EAC/B,cAAc,CAAC,EAAE,OAAO,GAAG,IAAI,GAC9B,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;IACtC;;;;;;;OAOG;IACH,wBAAwB,CAAC,CAAC,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,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