@degreesign/chat 1.1.0 → 1.3.0

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/types.d.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  import type { ChatModelId, ChatStatus, LlmBackend, LlmPhase, LlmRole, LlmStatus, WebSearchProvider } from './enums';
2
- /** One chat message, owned by the host */
2
+ /** Host-owned chat message */
3
3
  interface ChatMessage {
4
4
  role: LlmRole;
5
5
  content: string;
6
- /** Image data URLs or URLs attached to the turn */
6
+ /** Turn image URLs */
7
7
  images?: string[];
8
- /** Audio data URLs or URLs attached to the turn */
8
+ /** Turn audio URLs */
9
9
  audio?: string[];
10
10
  }
11
- /** One JSON-safe value passed to or returned from a tool */
11
+ /** JSON-safe tool value */
12
12
  type ChatToolValue = string | number | boolean | null | ChatToolValue[] | {
13
13
  [key: string]: ChatToolValue;
14
14
  };
15
- /** The JSON-schema subset the model reads for a tool parameter */
15
+ /** Tool parameter JSON schema */
16
16
  interface ChatToolSchema {
17
17
  type?: `object` | `array` | `string` | `number` | `integer` | `boolean` | `null`;
18
18
  description?: string;
@@ -21,7 +21,7 @@ interface ChatToolSchema {
21
21
  items?: ChatToolSchema;
22
22
  enum?: string[];
23
23
  }
24
- /** One tool a host may run itself, never handed to the model */
24
+ /** Host-run tool */
25
25
  interface ChatTool {
26
26
  /** Unique tool name */
27
27
  name: string;
@@ -30,36 +30,36 @@ interface ChatTool {
30
30
  parameters?: ChatToolSchema;
31
31
  execute: (args: Record<string, ChatToolValue>) => ChatToolValue | Promise<ChatToolValue>;
32
32
  }
33
- /** One tool call, with its parsed arguments */
33
+ /** Parsed tool call */
34
34
  interface ChatToolCall {
35
35
  id: number;
36
36
  name: string;
37
37
  arguments: Record<string, ChatToolValue>;
38
38
  }
39
- /** One finished tool call, carrying its value or its error */
39
+ /** Finished tool result */
40
40
  interface ChatToolResult extends ChatToolCall {
41
41
  result?: ChatToolValue;
42
42
  error?: string;
43
43
  }
44
- /** Search provider settings of the websearch tool */
44
+ /** Websearch provider settings */
45
45
  interface WebSearchConfig {
46
46
  provider?: WebSearchProvider;
47
- /** Wikipedia language edition, two or three letters plus an optional region */
47
+ /** Wikipedia language code */
48
48
  language?: string;
49
- /** Results asked of the provider, 1 to 20 */
49
+ /** Provider result count */
50
50
  limit?: number;
51
51
  /** Characters kept per snippet */
52
52
  snippetLength?: number;
53
53
  /** Request budget in milliseconds */
54
54
  timeout?: number;
55
55
  }
56
- /** One search hit returned by the websearch tool */
56
+ /** Websearch result hit */
57
57
  interface WebSearchResult {
58
58
  title: string;
59
59
  url: string;
60
60
  snippet: string;
61
61
  }
62
- /** Websearch settings with every default and clamp resolved */
62
+ /** Resolved websearch settings */
63
63
  interface WebSearchSettings {
64
64
  provider: WebSearchProvider;
65
65
  language: string;
@@ -67,7 +67,7 @@ interface WebSearchSettings {
67
67
  snippetLength: number;
68
68
  timeout: number;
69
69
  }
70
- /** Fiat and metal rates of one feed fetch, quoted per EUR */
70
+ /** Fiat and metal rates */
71
71
  interface FiatSnapshot {
72
72
  /** Local fetch time, milliseconds */
73
73
  fetchedAt: number;
@@ -76,24 +76,24 @@ interface FiatSnapshot {
76
76
  rates: Record<string, number>;
77
77
  yesterday: Record<string, number>;
78
78
  }
79
- /** Crypto prices of one feed fetch, quoted in EUR per unit */
79
+ /** Crypto prices in EUR */
80
80
  interface CryptoSnapshot {
81
81
  fetchedAt: number;
82
82
  sourceAt: number;
83
83
  prices: Record<string, number>;
84
84
  yesterday: Record<string, number>;
85
85
  }
86
- /** The price sections held in memory and in localStorage */
86
+ /** Cached price sections */
87
87
  interface PriceSnapshot {
88
88
  fiat?: FiatSnapshot;
89
89
  crypto?: CryptoSnapshot;
90
90
  }
91
- /** Price sections one request has to read */
91
+ /** Required price sections */
92
92
  interface PriceSections {
93
93
  fiat: boolean;
94
94
  crypto: boolean;
95
95
  }
96
- /** One conversion returned by the currency tool */
96
+ /** Currency conversion result */
97
97
  interface CurrencyResult {
98
98
  from: string;
99
99
  to: string;
@@ -112,7 +112,7 @@ interface CalculationResult {
112
112
  expression: string;
113
113
  result: number;
114
114
  }
115
- /** One page of a Wikipedia search response */
115
+ /** Wikipedia search page */
116
116
  interface WikipediaPage {
117
117
  key?: string;
118
118
  title?: string;
@@ -123,7 +123,7 @@ interface WikipediaPage {
123
123
  interface WikipediaResponse {
124
124
  pages?: WikipediaPage[];
125
125
  }
126
- /** One DuckDuckGo topic, a group carries nested topics */
126
+ /** DuckDuckGo topic group */
127
127
  interface DuckDuckGoTopic {
128
128
  FirstURL?: string;
129
129
  Text?: string;
@@ -137,50 +137,50 @@ interface DuckDuckGoResponse {
137
137
  Results?: DuckDuckGoTopic[];
138
138
  RelatedTopics?: DuckDuckGoTopic[];
139
139
  }
140
- /** One crypto row of the price feed */
140
+ /** Crypto price row */
141
141
  interface PriceCoin {
142
142
  /** Price in EUR per unit */
143
143
  pr?: number;
144
- /** Price in EUR per unit, 24 hours earlier */
144
+ /** Price 24 hours ago */
145
145
  yst?: number;
146
146
  }
147
- /** The CoinExams price feed, validated before use */
147
+ /** Validated CoinExams feed */
148
148
  interface PriceFeed {
149
149
  rates?: {
150
- /** Feed timestamp of the fiat and metal rates, milliseconds */
150
+ /** Fiat feed timestamp */
151
151
  date?: number;
152
- /** Units of each symbol per EUR */
152
+ /** Symbol units per EUR */
153
153
  current?: Record<string, number>;
154
- /** The same rates, 24 hours earlier */
154
+ /** Rates 24 hours ago */
155
155
  yesterday?: Record<string, number>;
156
156
  };
157
157
  coins?: Record<string, PriceCoin>;
158
- /** Feed timestamp of the crypto prices, milliseconds */
158
+ /** Crypto feed timestamp */
159
159
  date?: number;
160
160
  }
161
161
  /** One on-device model */
162
162
  interface ChatModel {
163
- /** Stable catalog id, passed by the host */
163
+ /** Stable catalog id */
164
164
  id: ChatModelId;
165
- /** Whether the model supports chain-of-thought reasoning */
165
+ /** Model reasoning support */
166
166
  reasoning: boolean;
167
167
  /** wllama (CPU) artifact */
168
168
  cpu?: {
169
169
  repo: string;
170
170
  file: string;
171
- /** Vision projector, present when the CPU build accepts images */
171
+ /** Optional CPU vision projector */
172
172
  mmproj?: {
173
- /** Repository of the projector, when it differs */
173
+ /** Projector repository override */
174
174
  repo?: string;
175
175
  file: string;
176
- /** Whether the projector also accepts audio */
176
+ /** Projector audio support */
177
177
  audio?: boolean;
178
178
  };
179
179
  };
180
180
  /** LiteRT-LM (WebGPU) artifact */
181
181
  litert?: {
182
182
  repo: string;
183
- /** File name inside the model repository */
183
+ /** Model repository file name */
184
184
  file: string;
185
185
  /** Whether the build accepts images */
186
186
  vision: boolean;
@@ -188,159 +188,192 @@ interface ChatModel {
188
188
  audio: boolean;
189
189
  };
190
190
  }
191
- /** Token, prompt and thread budgets of an on-device generation */
191
+ /** Generation budget settings */
192
192
  interface LlmLimits {
193
193
  /** Max answer tokens */
194
194
  maxReplyTokens: number;
195
- /** Max chain-of-thought tokens, used by the CPU engine when it loads */
195
+ /** Max reasoning tokens */
196
196
  maxThinkingTokens: number;
197
- /** Total output budget when reasoning is on, thought plus answer */
197
+ /** Reasoning output budget */
198
198
  maxReasoningTokens: number;
199
- /** Max images sent in one prompt */
199
+ /** Max prompt images */
200
200
  maxImages: number;
201
- /** Max audio clips sent in one prompt */
201
+ /** Vision tokens per image */
202
+ imageTokens: number;
203
+ /** Max prompt audio clips */
202
204
  maxAudio: number;
203
205
  /** Max characters kept per message */
204
206
  maxContentLength: number;
205
- /** Max characters of the whole prompt */
207
+ /** Max prompt characters */
206
208
  promptCharBudget: number;
207
- /** Max CPU threads, applied after the hardware maximum */
209
+ /** Max CPU threads */
208
210
  maxThreads: number;
209
211
  }
210
- /** Current model and request state reported to the host */
212
+ /** Reported model and request state */
211
213
  interface ChatStatusSnapshot {
212
- /** Build that runs on this device after the mobile swap */
214
+ /** Device-specific model build */
213
215
  model?: ChatModelId;
214
- /** Availability derived from the engine status */
216
+ /** Derived engine availability */
215
217
  availability: ChatStatus;
216
218
  status: LlmStatus;
217
219
  backend: LlmBackend;
218
- /** Whether the requested model accepts images on this backend */
220
+ /** Model image support */
219
221
  supportsImages: boolean;
220
- /** Whether the requested model accepts audio on this backend */
222
+ /** Model audio support */
221
223
  supportsAudio: boolean;
222
224
  ready: boolean;
223
225
  loading: boolean;
224
- /** Whether a reply is streaming right now */
226
+ /** Reply streaming flag */
225
227
  requesting: boolean;
226
228
  phase: LlmPhase;
227
229
  /** Download or load progress, 0..100 */
228
230
  percent: number;
229
- /** Last request error, cleared when a reply starts */
231
+ /** Last request error */
230
232
  error?: string;
231
233
  }
232
- /** One chat request, invoked for every response */
234
+ /** Chat request callback */
233
235
  interface ChatInput {
234
- /** Model that answers, the GPU model when WebGPU is available, else the CPU one */
236
+ /** Model that answers */
235
237
  model?: ChatModelId;
236
- /** Complete prompt, including the system and user turns */
238
+ /** Complete chat prompt */
237
239
  messages: ChatMessage[];
238
- /** Override any token, prompt or thread budget */
240
+ /** Budget overrides */
239
241
  limits?: Partial<LlmLimits>;
240
- /** Whether the model may use chain-of-thought reasoning, defaults to off */
242
+ /** Reasoning option, off */
241
243
  reasoning?: boolean;
242
- /** Whether package and engine logs reach the console, defaults to off */
244
+ /** Logging option, off */
243
245
  logging?: boolean;
244
- /** Accumulated reasoning text, streamed while the model thinks */
246
+ /** Streamed reasoning text */
245
247
  onThinking?: (text: string) => void;
246
- /** Accumulated reply text, streamed while the model answers */
248
+ /** Streamed reply text */
247
249
  onResponse: (text: string) => void;
248
- /** Current generation speed in tokens per second, streamed while the model answers */
250
+ /** Generation speed callback */
249
251
  onSpeed?: (tokensPerSecond: number) => void;
250
- /** Model and request state, reported on every change */
252
+ /** Status change callback */
251
253
  onStatus?: (snapshot: ChatStatusSnapshot) => void;
252
254
  }
253
- /** Model preload request, a subset of ChatInput */
255
+ /** Model preload request */
254
256
  type ChatPreloadInput = Pick<ChatInput, `model` | `limits` | `logging` | `onStatus`>;
255
- /** Stop the current request, its model load, or free the loaded model */
257
+ /** Stop request or model */
256
258
  type CancelChat = () => void;
257
- /** One image described in English and in the requested language */
259
+ /** Described image result */
258
260
  interface ImageDescription {
259
- /** Description produced by the vision model */
261
+ /** Vision description */
260
262
  descriptionEN: string;
261
- /** Translation of the English description, English itself without a GPU */
263
+ /** Description translation */
262
264
  description: string;
263
- /** Time the describer took for this image, milliseconds */
265
+ /** Description duration */
264
266
  durationMs: number;
265
267
  }
266
268
  /** One batch image description request */
267
269
  interface DescribeImagesInput {
268
- /** Language the description is translated into, English skips translation */
270
+ /** Target description language */
269
271
  targetLanguage: string;
270
- /** Image data URLs or URLs, described one by one in this order */
272
+ /** Ordered image URLs */
271
273
  images: string[];
272
- /** Index of the image being processed and each description once ready */
274
+ /** Stop batch, keep finished */
275
+ signal?: AbortSignal;
276
+ /** Description progress callback */
273
277
  currentIndex?: (index: number, descriptionEN?: string, description?: string, durationMs?: number) => void;
274
- /** Index of the image being described and its speed, tokens per second */
278
+ /** Image speed callback */
275
279
  onSpeed?: (index: number, tokensPerSecond: number) => void;
276
- /** Index of the image and its accumulated text while the model writes */
280
+ /** Image text callback */
277
281
  onText?: (index: number, text: string, stage: `describe` | `translate`) => void;
278
- /** Override any token, prompt or thread budget */
282
+ /** Budget overrides */
279
283
  limits?: Partial<LlmLimits>;
280
- /** Whether package and engine logs reach the console, defaults to off */
284
+ /** Logging option, off */
281
285
  logging?: boolean;
282
- /** Model and request state, reported on every change */
286
+ /** Status change callback */
283
287
  onStatus?: (snapshot: ChatStatusSnapshot) => void;
288
+ /** Additional rules */
289
+ additionalRules?: string;
284
290
  }
285
- /** One batch translation request for English image descriptions */
291
+ /** Batch translation request */
286
292
  interface DescribeTranslatedInput {
287
- /** English descriptions translated one by one in this order */
293
+ /** Ordered English descriptions */
288
294
  descriptions: string[];
289
- /** Language the descriptions are translated into, English skips translation */
295
+ /** Target translation language */
290
296
  targetLanguage: string;
291
- /** Index being translated and each description once ready */
297
+ /** Stop batch, keep finished */
298
+ signal?: AbortSignal;
299
+ /** Translation progress callback */
292
300
  currentIndex?: (index: number, descriptionEN?: string, description?: string) => void;
293
- /** Index of the description being generated and its speed, tokens per second */
301
+ /** Translation speed callback */
294
302
  onSpeed?: (index: number, tokensPerSecond: number) => void;
295
- /** Index of the description and its accumulated text while the model writes */
303
+ /** Translation text callback */
296
304
  onText?: (index: number, text: string, stage: `translate`) => void;
297
- /** Override any token, prompt or thread budget */
305
+ /** Budget overrides */
298
306
  limits?: Partial<LlmLimits>;
299
- /** Whether package and engine logs reach the console, defaults to off */
307
+ /** Logging option, off */
300
308
  logging?: boolean;
301
- /** Model and request state, reported on every change */
309
+ /** Status change callback */
302
310
  onStatus?: (snapshot: ChatStatusSnapshot) => void;
303
311
  }
304
- /** wllama wasm assets used by the CPU engine */
312
+ /** CPU wasm assets */
305
313
  interface WllamaAssets {
306
- /** URL of the wllama wasm binary */
314
+ /** wllama wasm URL */
307
315
  wasm: string;
308
- /** URL of the wllama compat wasm binary */
316
+ /** Compat wasm URL */
309
317
  compatWasm: string;
310
- /** URL of the wllama compat worker script */
318
+ /** Compat worker URL */
311
319
  compatWorker: string;
312
320
  }
313
- /** LiteRT-LM wasm assets used by the GPU engine */
321
+ /** GPU wasm assets */
314
322
  interface LitertAssets {
315
- /** URL of the LiteRT-LM wasm glue script */
323
+ /** LiteRT glue URL */
316
324
  script: string;
317
- /** URL of the LiteRT-LM wasm binary */
325
+ /** LiteRT wasm URL */
318
326
  wasm: string;
319
327
  }
320
- /** Navigator with the WebGPU entry point, absent in Node */
328
+ /** WebGPU navigator type */
321
329
  interface GpuNavigator extends Navigator {
322
330
  gpu?: {
323
- /** Ask the browser for a WebGPU adapter */
331
+ /** Request WebGPU adapter */
324
332
  requestAdapter: (options?: {
325
333
  powerPreference?: `low-power` | `high-performance`;
326
334
  }) => Promise<unknown>;
327
335
  };
328
336
  }
329
- /** Navigator fields that tell a phone or tablet from a desktop */
337
+ /** Minimal WebGPU buffer */
338
+ interface GpuBuffer {
339
+ /** Map buffer after work */
340
+ mapAsync: (...args: unknown[]) => Promise<void>;
341
+ }
342
+ /** Minimal WebGPU device */
343
+ interface GpuDevice {
344
+ /** Create engine buffer */
345
+ createBuffer?: (...args: unknown[]) => GpuBuffer;
346
+ /** Release device resources */
347
+ destroy?: () => void;
348
+ }
349
+ /** Reset wasm fields */
350
+ interface GpuWasm {
351
+ preinitializedWebGPUDevice?: GpuDevice;
352
+ WebGPU?: {
353
+ preinitializedDeviceId?: number;
354
+ };
355
+ }
356
+ /** GPU throttle state */
357
+ interface GpuThrottleParams {
358
+ device: GpuDevice;
359
+ /** Rest after one GPU readback */
360
+ pace: () => Promise<void>;
361
+ }
362
+ /** Mobile detection fields */
330
363
  type MobileNavigator = Pick<Navigator, `userAgent` | `maxTouchPoints`> & {
331
- /** Chromium client hints, the reliable mobile flag */
364
+ /** Chromium mobile hint */
332
365
  userAgentData?: {
333
366
  mobile?: boolean;
334
367
  };
335
368
  };
336
- /** Request state that builds one status snapshot */
369
+ /** Status snapshot state */
337
370
  interface ChatState {
338
- /** Whether a reply is streaming right now */
371
+ /** Reply streaming flag */
339
372
  requesting: boolean;
340
373
  phase: LlmPhase;
341
374
  /** Download or load progress, 0..100 */
342
375
  percent: number;
343
- /** Last request error, cleared when a reply starts */
376
+ /** Last request error */
344
377
  error?: string;
345
378
  }
346
379
  /** One live chat request */
@@ -352,7 +385,7 @@ interface ActiveCall extends ChatState {
352
385
  /** Model resolved for this call */
353
386
  model?: ChatModelId;
354
387
  }
355
- /** Engine and backend overrides used by tests */
388
+ /** Test engine overrides */
356
389
  interface RuntimeDeps {
357
390
  engines?: {
358
391
  cpu?: LlmEngine;
@@ -367,165 +400,173 @@ interface RuntimeLoadParams {
367
400
  model: ChatModel;
368
401
  limits: LlmLimits;
369
402
  assets?: Partial<WllamaAssets>;
370
- /** Whether engine logs reach the console */
403
+ /** Engine logging flag */
371
404
  logging?: boolean;
372
- /** Stop waiting for this load, the download continues while another caller waits */
405
+ /** Stop awaiting shared load */
373
406
  signal?: AbortSignal;
374
407
  onProgress: (progress: number, phase: LlmPhase) => void;
375
408
  }
376
- /** One caller waiting on an in-flight model load */
409
+ /** Waiting load caller */
377
410
  interface RuntimeLoadWaiter {
378
- /** Report load progress to this caller */
411
+ /** Report caller progress */
379
412
  report: RuntimeLoadParams[`onProgress`];
380
- /** Resolve this caller, early when it leaves the load */
413
+ /** Resolve waiting caller */
381
414
  settle: (loaded: boolean) => void;
382
415
  }
383
- /** Bytes of one model file already stored on disk */
416
+ /** Stored model file bytes */
384
417
  interface StoredPart {
385
418
  /** Bytes already stored */
386
419
  size: number;
387
- /** Full file size, zero while unknown */
420
+ /** File size, zero unknown */
388
421
  total: number;
389
- /** Entity tag of the stored bytes, empty when the host hides it */
422
+ /** Stored bytes entity tag */
390
423
  etag: string;
391
424
  }
392
- /** One part file of a model, at its byte offset */
425
+ /** Model part file */
393
426
  interface StoredFilePart {
394
- /** Byte offset of the part in the model file */
427
+ /** Part byte offset */
395
428
  start: number;
396
429
  /** Bytes stored in the part */
397
430
  size: number;
398
431
  }
399
- /** One stored model file, complete or still downloading */
432
+ /** Stored model file */
400
433
  interface StoredModel extends StoredPart {
401
- /** The stored bytes, a snapshot of the parts on disk */
434
+ /** Stored file snapshot */
402
435
  file: Blob;
403
- /** Whether every byte of the total is stored */
436
+ /** Complete file flag */
404
437
  complete: boolean;
405
438
  }
406
- /** Download metadata kept beside one stored model file */
439
+ /** Stored download metadata */
407
440
  interface StoredModelMeta {
408
441
  total: number;
409
442
  etag: string;
410
443
  complete: boolean;
411
444
  }
412
- /** Where one response continues a stored part */
445
+ /** Stored part continuation */
413
446
  interface ResumePlan {
414
- /** Byte the response body starts at */
447
+ /** Response start byte */
415
448
  start: number;
416
- /** Full file size, zero while unknown */
449
+ /** File size, zero unknown */
417
450
  total: number;
418
451
  etag: string;
419
452
  }
420
- /** One model file download into the store */
453
+ /** Model download into store */
421
454
  interface StoreDownloadParams {
422
455
  url: string;
423
- /** Stop the download, the bytes stored so far are kept */
456
+ /** Stop download, keep bytes */
424
457
  signal?: AbortSignal;
425
458
  onProgress: StartLlmParams[`onProgress`];
426
459
  }
427
- /** Resumable model file store owned by one engine */
460
+ /** Engine resumable file store */
428
461
  interface ModelStore {
429
- /** Stored bytes and metadata of one model file, undefined when absent */
462
+ /** Stored model file info */
430
463
  stored: (url: string) => Promise<StoredModel | undefined>;
431
- /** Download one model file, resuming the parts already stored */
464
+ /** Resume model file download */
432
465
  download: (params: StoreDownloadParams) => Promise<StoredModel | undefined>;
433
- /** Delete one stored model file and its metadata */
466
+ /** Delete model file */
434
467
  remove: (url: string) => Promise<void>;
435
- /** Delete the whole store directory and every model file in it */
468
+ /** Delete entire store */
436
469
  purge: () => Promise<void>;
437
470
  }
438
471
  /** One generation request */
439
472
  interface RuntimeChatParams {
440
- /** Model that answers, resolved by the runtime */
473
+ /** Resolved answer model */
441
474
  model?: ChatModelId;
442
475
  messages: ChatMessage[];
443
476
  limits: LlmLimits;
444
477
  reasoning: boolean;
445
- /** Whether engine logs reach the console */
478
+ /** Repetition penalty */
479
+ repeatPenalty?: number;
480
+ /** Sampling temperature */
481
+ temperature?: number;
482
+ /** Engine logging flag */
446
483
  logging?: boolean;
447
484
  onReason: (text: string) => void;
448
485
  onText: (text: string) => void;
449
- /** Current generation speed in tokens per second */
486
+ /** Generation speed */
450
487
  onSpeed?: (tokensPerSecond: number) => void;
451
488
  signal?: AbortSignal;
452
489
  }
453
- /** On-device runtime shared by every request */
490
+ /** Shared on-device runtime */
454
491
  interface Runtime {
455
- /** Load a model, or join a load of the same model already in flight */
492
+ /** Load or join model */
456
493
  load: (params: RuntimeLoadParams) => Promise<boolean>;
457
494
  chat: (params: RuntimeChatParams) => Promise<string | undefined>;
458
- /** Release one loaded model, or every model */
495
+ /** Release one or all models */
459
496
  unload: (model?: ChatModelId) => Promise<void>;
460
- /** Release the model and delete every cached model file */
497
+ /** Release and delete caches */
461
498
  clear: () => Promise<void>;
462
- /** Whether one model, or the active model, is loaded */
499
+ /** Model loaded check */
463
500
  ready: (model?: ChatModelId) => boolean;
464
- /** Whether one model, or any model, is loading */
501
+ /** Model loading check */
465
502
  loading: (model?: ChatModelId) => boolean;
466
- /** Status of one model, or of the last load */
503
+ /** Model load status */
467
504
  status: (model?: ChatModelId) => LlmStatus;
468
- /** Backend of one model, or of the active model */
505
+ /** Model backend */
469
506
  backend: (model?: ChatModelId) => LlmBackend;
470
- /** Last model load error, of one model or of the latest load */
507
+ /** Latest model load error */
471
508
  error: (model?: ChatModelId) => string | undefined;
472
- /** Model that loaded or answered last */
509
+ /** Last active model */
473
510
  model: () => ChatModel | undefined;
474
511
  }
475
- /** Params for a single on-device chat generation */
512
+ /** Single chat generation params */
476
513
  interface EngineChatParams {
477
514
  messages: ChatMessage[];
478
515
  limits: LlmLimits;
479
- /** User preference, off unless explicitly turned on */
516
+ /** Opt-in reasoning preference */
480
517
  reasoning: boolean;
481
- /** Whether engine logs reach the console */
518
+ /** Repetition penalty */
519
+ repeatPenalty?: number;
520
+ /** Sampling temperature */
521
+ temperature?: number;
522
+ /** Engine logging flag */
482
523
  logging?: boolean;
483
524
  /** Streamed reasoning delta */
484
525
  onReason: (text: string) => void;
485
526
  /** Streamed reply delta */
486
527
  onText: (text: string) => void;
487
- /** Current generation speed in tokens per second */
528
+ /** Generation speed */
488
529
  onSpeed?: (tokensPerSecond: number) => void;
489
530
  signal?: AbortSignal;
490
531
  }
491
532
  /** Params of the engine startLLM */
492
533
  interface StartLlmParams {
493
534
  model: ChatModel;
494
- /** Engine-level budgets, read when the model loads */
535
+ /** Engine load budgets */
495
536
  limits: LlmLimits;
496
- /** Report download and load progress 0..1 */
537
+ /** Download progress callback */
497
538
  onProgress: (progress: number, phase?: LlmPhase) => void;
498
- /** Stop a download or load that is no longer wanted */
539
+ /** Cancel download or load */
499
540
  signal?: AbortSignal;
500
- /** Whether engine logs reach the console */
541
+ /** Engine logging flag */
501
542
  logging?: boolean;
502
543
  /** CPU engine asset override */
503
544
  assets?: Partial<WllamaAssets>;
504
545
  }
505
- /** Unified object returned by the engine startLLM */
546
+ /** Engine start result */
506
547
  interface LlmRuntime {
507
548
  /** Model this runtime serves */
508
549
  model: ChatModel;
509
550
  /** Backend that accepted the model */
510
551
  backend: LlmBackend;
511
- /** Context window requested from the engine */
552
+ /** Requested context window */
512
553
  contextSize: number;
513
- /** Stream one reply, returning the final text or undefined when stopped */
554
+ /** Stream reply text */
514
555
  chat: (params: EngineChatParams) => Promise<string | undefined>;
515
- /** Release the model from memory, keeping its cache */
556
+ /** Release model, keep cache */
516
557
  unload: () => Promise<void>;
517
558
  }
518
- /** A model runner backed by one inference engine */
559
+ /** Engine-backed model runner */
519
560
  interface LlmEngine {
520
561
  backend: LlmBackend;
521
- /** Download (if needed) and load a model, returning its runtime */
562
+ /** Load model runtime */
522
563
  startLLM: (params: StartLlmParams) => Promise<LlmRuntime>;
523
- /** Whether the model files are already fully stored on this device */
564
+ /** Model files stored check */
524
565
  cached: (model: ChatModel) => Promise<boolean>;
525
- /** Delete every on-device artifact this engine keeps, including orphans */
566
+ /** Delete engine artifacts */
526
567
  purge: () => Promise<void>;
527
568
  }
528
- /** One text, image or audio segment of a user turn */
569
+ /** User turn content part */
529
570
  type EngineContentPart = {
530
571
  type: `text`;
531
572
  text: string;
@@ -558,7 +599,7 @@ type WllamaMessage = {
558
599
  role: `assistant`;
559
600
  content: string;
560
601
  };
561
- /** One OpenAI-style message, a user turn may carry media parts */
602
+ /** OpenAI-style chat message */
562
603
  type EngineMessage = {
563
604
  role: `system`;
564
605
  content: string;
@@ -577,31 +618,33 @@ type LitertMessage = import('@litert-lm/core').Message;
577
618
  type LitertEngine = import('@litert-lm/core').Engine;
578
619
  /** The LiteRT-LM module namespace */
579
620
  type LitertModule = typeof import('@litert-lm/core');
580
- /** Settings handed to the LiteRT-LM engine */
621
+ /** LiteRT engine settings */
581
622
  type LitertSettings = import('@litert-lm/core').EngineSettings;
582
- /** Params of one LiteRT-LM settings build */
623
+ /** LiteRT settings params */
583
624
  interface LitertSettingsParams {
584
625
  /** Model with the artifact */
585
626
  model: ChatModel;
586
- /** Image and context budgets */
627
+ /** Image budgets */
587
628
  limits: LlmLimits;
629
+ /** Requested context window */
630
+ contextSize: number;
588
631
  /** Model file stream */
589
632
  source: ReadableStream<Uint8Array>;
590
633
  /** Loaded LiteRT module */
591
634
  mod: LitertModule;
592
635
  }
593
- /** One reused LiteRT-LM conversation and the turns it already holds */
636
+ /** Reused LiteRT conversation */
594
637
  interface LitertSession {
595
- /** Live conversation, dropped when a turn cannot be continued */
638
+ /** Live LiteRT conversation */
596
639
  conversation?: import('@litert-lm/core').Conversation;
597
- /** Built turns already sent to the conversation */
640
+ /** Sent conversation turns */
598
641
  sent: EngineMessage[];
599
- /** Reasoning flag the conversation was created with */
642
+ /** Conversation reasoning flag */
600
643
  reasoning: boolean;
601
- /** Output token budget the conversation was created with */
644
+ /** Conversation output budget */
602
645
  maxTokens: number;
603
646
  }
604
- /** Params of one LiteRT-LM chat call */
647
+ /** LiteRT chat params */
605
648
  interface LitertChatParams {
606
649
  engine: LitertEngine;
607
650
  model: ChatModel;
@@ -617,13 +660,13 @@ interface StreamLitertParams {
617
660
  messages: EngineMessage[];
618
661
  session: LitertSession;
619
662
  }
620
- /** Streamed delta, reasoning may be inline or structured */
663
+ /** Streamed reasoning delta */
621
664
  interface EngineDelta {
622
665
  content?: string;
623
666
  reasoning?: string;
624
667
  reasoning_content?: string;
625
668
  }
626
- /** Streamed chunk as the engine shapes it */
669
+ /** Engine stream chunk */
627
670
  interface EngineChunk {
628
671
  choices?: Array<{
629
672
  finish_reason?: string;
@@ -637,35 +680,35 @@ interface StreamReplyParams {
637
680
  onReason: (text: string) => void;
638
681
  /** Streamed reply delta */
639
682
  onText: (text: string) => void;
640
- /** Current generation speed in tokens per second */
683
+ /** Generation speed */
641
684
  onSpeed?: (tokensPerSecond: number) => void;
642
- /** Open the engine stream for the prepared messages */
685
+ /** Open engine stream */
643
686
  start: () => Promise<AsyncIterable<unknown>>;
644
- /** Whether the caller stopped the generation */
687
+ /** Generation stopped flag */
645
688
  stopped: () => boolean;
646
- /** Whether engine logs reach the console */
689
+ /** Engine logging flag */
647
690
  logging?: boolean;
648
- /** Budget before the first chunk arrives, milliseconds */
691
+ /** First chunk timeout */
649
692
  firstTimeoutMs?: number;
650
693
  /** Budget between two chunks, milliseconds */
651
694
  idleTimeoutMs?: number;
652
- /** Called when a slow stream keeps the text already delivered */
695
+ /** Slow stream callback */
653
696
  onStall?: () => void;
654
697
  }
655
- /** Params of one engine chat call */
698
+ /** Engine chat params */
656
699
  interface EngineRunParams {
657
700
  model: ChatModel;
658
701
  params: EngineChatParams;
659
- /** Open the engine stream for the prepared messages */
702
+ /** Open engine stream */
660
703
  start: (messages: EngineMessage[]) => Promise<AsyncIterable<unknown>>;
661
- /** Whether the caller stopped the generation */
704
+ /** Generation stopped flag */
662
705
  stopped: () => boolean;
663
- /** Called when a slow stream keeps the text already delivered */
706
+ /** Slow stream callback */
664
707
  onStall?: () => void;
665
708
  }
666
- /** Pixel size of one image sent to an engine */
709
+ /** Engine image pixel size */
667
710
  interface ImageSize {
668
711
  width: number;
669
712
  height: number;
670
713
  }
671
- export type { ChatMessage, ChatTool, ChatToolCall, ChatToolResult, ChatToolSchema, ChatToolValue, WebSearchConfig, WebSearchResult, WebSearchSettings, FiatSnapshot, CryptoSnapshot, PriceSnapshot, PriceSections, PriceCoin, PriceFeed, CurrencyResult, CalculationResult, WikipediaPage, WikipediaResponse, DuckDuckGoTopic, DuckDuckGoResponse, ChatModel, LlmLimits, ChatStatusSnapshot, ChatInput, ChatPreloadInput, ChatState, CancelChat, ImageDescription, DescribeImagesInput, DescribeTranslatedInput, WllamaAssets, LitertAssets, GpuNavigator, MobileNavigator, ActiveCall, RuntimeDeps, RuntimeLoadParams, RuntimeLoadWaiter, RuntimeChatParams, StoredPart, StoredFilePart, StoredModel, StoredModelMeta, ResumePlan, StoreDownloadParams, ModelStore, Runtime, EngineChatParams, StartLlmParams, LlmRuntime, LlmEngine, EngineMessage, ImageSize, EngineContentPart, WllamaContentPart, WllamaMessage, LitertContentPart, LitertMessage, LitertEngine, LitertModule, LitertSettings, LitertSettingsParams, LitertSession, LitertChatParams, StreamLitertParams, EngineDelta, EngineChunk, StreamReplyParams, EngineRunParams, };
714
+ export type { ChatMessage, ChatTool, ChatToolCall, ChatToolResult, ChatToolSchema, ChatToolValue, WebSearchConfig, WebSearchResult, WebSearchSettings, FiatSnapshot, CryptoSnapshot, PriceSnapshot, PriceSections, PriceCoin, PriceFeed, CurrencyResult, CalculationResult, WikipediaPage, WikipediaResponse, DuckDuckGoTopic, DuckDuckGoResponse, ChatModel, LlmLimits, ChatStatusSnapshot, ChatInput, ChatPreloadInput, ChatState, CancelChat, ImageDescription, DescribeImagesInput, DescribeTranslatedInput, WllamaAssets, LitertAssets, GpuBuffer, GpuDevice, GpuWasm, GpuThrottleParams, GpuNavigator, MobileNavigator, ActiveCall, RuntimeDeps, RuntimeLoadParams, RuntimeLoadWaiter, RuntimeChatParams, StoredPart, StoredFilePart, StoredModel, StoredModelMeta, ResumePlan, StoreDownloadParams, ModelStore, Runtime, EngineChatParams, StartLlmParams, LlmRuntime, LlmEngine, EngineMessage, ImageSize, EngineContentPart, WllamaContentPart, WllamaMessage, LitertContentPart, LitertMessage, LitertEngine, LitertModule, LitertSettings, LitertSettingsParams, LitertSession, LitertChatParams, StreamLitertParams, EngineDelta, EngineChunk, StreamReplyParams, EngineRunParams, };