@degreesign/chat 1.0.2 → 1.2.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/README.md +108 -29
- package/dist/browser/chat.min.mjs +1 -1
- package/dist/browser/engine-wllama.min.mjs +1 -1
- package/dist/chat.d.ts +4 -4
- package/dist/describe.d.ts +17 -5
- package/dist/engines/engine.d.ts +12 -12
- package/dist/engines/images.d.ts +8 -8
- package/dist/engines/litert.d.ts +22 -10
- package/dist/engines/store.d.ts +4 -4
- package/dist/engines/threads.d.ts +3 -0
- package/dist/engines/wllama.d.ts +5 -7
- package/dist/enums.d.ts +6 -6
- package/dist/index.d.ts +1 -1
- package/dist/log.d.ts +1 -1
- package/dist/models.d.ts +13 -11
- package/dist/node/chat.node.min.js +1 -1
- package/dist/node/chat.node.min.mjs +1 -1
- package/dist/node/engine-wllama.node.min.js +1 -1
- package/dist/node/engine-wllama.node.min.mjs +1 -1
- package/dist/tools/calculator.d.ts +2 -2
- package/dist/tools/currency.d.ts +3 -3
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/search.d.ts +3 -3
- package/dist/tools/text.d.ts +3 -3
- package/dist/types.d.ts +225 -173
- package/package.json +5 -2
package/dist/types.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { ChatModelId, ChatStatus, LlmBackend, LlmPhase, LlmRole, LlmStatus, WebSearchProvider } from './enums';
|
|
2
|
-
/**
|
|
2
|
+
/** Host-owned chat message */
|
|
3
3
|
interface ChatMessage {
|
|
4
4
|
role: LlmRole;
|
|
5
5
|
content: string;
|
|
6
|
-
/**
|
|
6
|
+
/** Turn image URLs */
|
|
7
7
|
images?: string[];
|
|
8
|
-
/**
|
|
8
|
+
/** Turn audio URLs */
|
|
9
9
|
audio?: string[];
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/** JSON-safe tool value */
|
|
12
12
|
type ChatToolValue = string | number | boolean | null | ChatToolValue[] | {
|
|
13
13
|
[key: string]: ChatToolValue;
|
|
14
14
|
};
|
|
15
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
39
|
+
/** Finished tool result */
|
|
40
40
|
interface ChatToolResult extends ChatToolCall {
|
|
41
41
|
result?: ChatToolValue;
|
|
42
42
|
error?: string;
|
|
43
43
|
}
|
|
44
|
-
/**
|
|
44
|
+
/** Websearch provider settings */
|
|
45
45
|
interface WebSearchConfig {
|
|
46
46
|
provider?: WebSearchProvider;
|
|
47
|
-
/** Wikipedia language
|
|
47
|
+
/** Wikipedia language code */
|
|
48
48
|
language?: string;
|
|
49
|
-
/**
|
|
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
|
-
/**
|
|
56
|
+
/** Websearch result hit */
|
|
57
57
|
interface WebSearchResult {
|
|
58
58
|
title: string;
|
|
59
59
|
url: string;
|
|
60
60
|
snippet: string;
|
|
61
61
|
}
|
|
62
|
-
/**
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
86
|
+
/** Cached price sections */
|
|
87
87
|
interface PriceSnapshot {
|
|
88
88
|
fiat?: FiatSnapshot;
|
|
89
89
|
crypto?: CryptoSnapshot;
|
|
90
90
|
}
|
|
91
|
-
/**
|
|
91
|
+
/** Required price sections */
|
|
92
92
|
interface PriceSections {
|
|
93
93
|
fiat: boolean;
|
|
94
94
|
crypto: boolean;
|
|
95
95
|
}
|
|
96
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
140
|
+
/** Crypto price row */
|
|
141
141
|
interface PriceCoin {
|
|
142
142
|
/** Price in EUR per unit */
|
|
143
143
|
pr?: number;
|
|
144
|
-
/** Price
|
|
144
|
+
/** Price 24 hours ago */
|
|
145
145
|
yst?: number;
|
|
146
146
|
}
|
|
147
|
-
/**
|
|
147
|
+
/** Validated CoinExams feed */
|
|
148
148
|
interface PriceFeed {
|
|
149
149
|
rates?: {
|
|
150
|
-
/**
|
|
150
|
+
/** Fiat feed timestamp */
|
|
151
151
|
date?: number;
|
|
152
|
-
/**
|
|
152
|
+
/** Symbol units per EUR */
|
|
153
153
|
current?: Record<string, number>;
|
|
154
|
-
/**
|
|
154
|
+
/** Rates 24 hours ago */
|
|
155
155
|
yesterday?: Record<string, number>;
|
|
156
156
|
};
|
|
157
157
|
coins?: Record<string, PriceCoin>;
|
|
158
|
-
/**
|
|
158
|
+
/** Crypto feed timestamp */
|
|
159
159
|
date?: number;
|
|
160
160
|
}
|
|
161
161
|
/** One on-device model */
|
|
162
162
|
interface ChatModel {
|
|
163
|
-
/** Stable catalog id
|
|
163
|
+
/** Stable catalog id */
|
|
164
164
|
id: ChatModelId;
|
|
165
|
-
/**
|
|
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
|
-
/**
|
|
171
|
+
/** Optional CPU vision projector */
|
|
172
172
|
mmproj?: {
|
|
173
|
-
/**
|
|
173
|
+
/** Projector repository override */
|
|
174
174
|
repo?: string;
|
|
175
175
|
file: string;
|
|
176
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
191
|
+
/** Generation budget settings */
|
|
192
192
|
interface LlmLimits {
|
|
193
193
|
/** Max answer tokens */
|
|
194
194
|
maxReplyTokens: number;
|
|
195
|
-
/** Max
|
|
195
|
+
/** Max reasoning tokens */
|
|
196
196
|
maxThinkingTokens: number;
|
|
197
|
-
/**
|
|
197
|
+
/** Reasoning output budget */
|
|
198
198
|
maxReasoningTokens: number;
|
|
199
|
-
/** Max images
|
|
199
|
+
/** Max prompt images */
|
|
200
200
|
maxImages: number;
|
|
201
|
-
/**
|
|
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
|
|
207
|
+
/** Max prompt characters */
|
|
206
208
|
promptCharBudget: number;
|
|
207
|
-
/** Max CPU threads
|
|
209
|
+
/** Max CPU threads */
|
|
208
210
|
maxThreads: number;
|
|
209
211
|
}
|
|
210
|
-
/**
|
|
212
|
+
/** Reported model and request state */
|
|
211
213
|
interface ChatStatusSnapshot {
|
|
212
|
-
/**
|
|
214
|
+
/** Device-specific model build */
|
|
213
215
|
model?: ChatModelId;
|
|
214
|
-
/**
|
|
216
|
+
/** Derived engine availability */
|
|
215
217
|
availability: ChatStatus;
|
|
216
218
|
status: LlmStatus;
|
|
217
219
|
backend: LlmBackend;
|
|
218
|
-
/**
|
|
220
|
+
/** Model image support */
|
|
219
221
|
supportsImages: boolean;
|
|
220
|
-
/**
|
|
222
|
+
/** Model audio support */
|
|
221
223
|
supportsAudio: boolean;
|
|
222
224
|
ready: boolean;
|
|
223
225
|
loading: boolean;
|
|
224
|
-
/**
|
|
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
|
|
231
|
+
/** Last request error */
|
|
230
232
|
error?: string;
|
|
231
233
|
}
|
|
232
|
-
/**
|
|
234
|
+
/** Chat request callback */
|
|
233
235
|
interface ChatInput {
|
|
234
|
-
/** Model that answers
|
|
236
|
+
/** Model that answers */
|
|
235
237
|
model?: ChatModelId;
|
|
236
|
-
/** Complete prompt
|
|
238
|
+
/** Complete chat prompt */
|
|
237
239
|
messages: ChatMessage[];
|
|
238
|
-
/**
|
|
240
|
+
/** Budget overrides */
|
|
239
241
|
limits?: Partial<LlmLimits>;
|
|
240
|
-
/**
|
|
242
|
+
/** Reasoning option, off */
|
|
241
243
|
reasoning?: boolean;
|
|
242
|
-
/**
|
|
244
|
+
/** Logging option, off */
|
|
243
245
|
logging?: boolean;
|
|
244
|
-
/**
|
|
246
|
+
/** Streamed reasoning text */
|
|
245
247
|
onThinking?: (text: string) => void;
|
|
246
|
-
/**
|
|
248
|
+
/** Streamed reply text */
|
|
247
249
|
onResponse: (text: string) => void;
|
|
248
|
-
/**
|
|
250
|
+
/** Generation speed callback */
|
|
249
251
|
onSpeed?: (tokensPerSecond: number) => void;
|
|
250
|
-
/**
|
|
252
|
+
/** Status change callback */
|
|
251
253
|
onStatus?: (snapshot: ChatStatusSnapshot) => void;
|
|
252
254
|
}
|
|
253
|
-
/** Model preload request
|
|
255
|
+
/** Model preload request */
|
|
254
256
|
type ChatPreloadInput = Pick<ChatInput, `model` | `limits` | `logging` | `onStatus`>;
|
|
255
|
-
/** Stop
|
|
257
|
+
/** Stop request or model */
|
|
256
258
|
type CancelChat = () => void;
|
|
257
|
-
/**
|
|
259
|
+
/** Described image result */
|
|
258
260
|
interface ImageDescription {
|
|
259
|
-
/**
|
|
261
|
+
/** Vision description */
|
|
260
262
|
descriptionEN: string;
|
|
261
|
-
/**
|
|
263
|
+
/** Description translation */
|
|
262
264
|
description: string;
|
|
263
|
-
/**
|
|
265
|
+
/** Description duration */
|
|
264
266
|
durationMs: number;
|
|
265
267
|
}
|
|
266
268
|
/** One batch image description request */
|
|
267
269
|
interface DescribeImagesInput {
|
|
268
|
-
/**
|
|
270
|
+
/** Target description language */
|
|
269
271
|
targetLanguage: string;
|
|
270
|
-
/**
|
|
272
|
+
/** Ordered image URLs */
|
|
271
273
|
images: string[];
|
|
272
|
-
/**
|
|
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
|
-
/**
|
|
278
|
+
/** Image speed callback */
|
|
275
279
|
onSpeed?: (index: number, tokensPerSecond: number) => void;
|
|
276
|
-
/**
|
|
280
|
+
/** Image text callback */
|
|
277
281
|
onText?: (index: number, text: string, stage: `describe` | `translate`) => void;
|
|
278
|
-
/**
|
|
282
|
+
/** Budget overrides */
|
|
279
283
|
limits?: Partial<LlmLimits>;
|
|
280
|
-
/**
|
|
284
|
+
/** Logging option, off */
|
|
281
285
|
logging?: boolean;
|
|
282
|
-
/**
|
|
286
|
+
/** Status change callback */
|
|
283
287
|
onStatus?: (snapshot: ChatStatusSnapshot) => void;
|
|
288
|
+
/** Additional rules */
|
|
289
|
+
additionalRules?: string;
|
|
284
290
|
}
|
|
285
|
-
/**
|
|
291
|
+
/** Batch translation request */
|
|
286
292
|
interface DescribeTranslatedInput {
|
|
287
|
-
/** English descriptions
|
|
293
|
+
/** Ordered English descriptions */
|
|
288
294
|
descriptions: string[];
|
|
289
|
-
/**
|
|
295
|
+
/** Target translation language */
|
|
290
296
|
targetLanguage: string;
|
|
291
|
-
/**
|
|
297
|
+
/** Stop batch, keep finished */
|
|
298
|
+
signal?: AbortSignal;
|
|
299
|
+
/** Translation progress callback */
|
|
292
300
|
currentIndex?: (index: number, descriptionEN?: string, description?: string) => void;
|
|
293
|
-
/**
|
|
301
|
+
/** Translation speed callback */
|
|
294
302
|
onSpeed?: (index: number, tokensPerSecond: number) => void;
|
|
295
|
-
/**
|
|
303
|
+
/** Translation text callback */
|
|
296
304
|
onText?: (index: number, text: string, stage: `translate`) => void;
|
|
297
|
-
/**
|
|
305
|
+
/** Budget overrides */
|
|
298
306
|
limits?: Partial<LlmLimits>;
|
|
299
|
-
/**
|
|
307
|
+
/** Logging option, off */
|
|
300
308
|
logging?: boolean;
|
|
301
|
-
/**
|
|
309
|
+
/** Status change callback */
|
|
302
310
|
onStatus?: (snapshot: ChatStatusSnapshot) => void;
|
|
303
311
|
}
|
|
304
|
-
/**
|
|
312
|
+
/** CPU wasm assets */
|
|
305
313
|
interface WllamaAssets {
|
|
306
|
-
/**
|
|
314
|
+
/** wllama wasm URL */
|
|
307
315
|
wasm: string;
|
|
308
|
-
/**
|
|
316
|
+
/** Compat wasm URL */
|
|
309
317
|
compatWasm: string;
|
|
310
|
-
/**
|
|
318
|
+
/** Compat worker URL */
|
|
311
319
|
compatWorker: string;
|
|
312
320
|
}
|
|
313
|
-
/**
|
|
321
|
+
/** GPU wasm assets */
|
|
314
322
|
interface LitertAssets {
|
|
315
|
-
/**
|
|
323
|
+
/** LiteRT glue URL */
|
|
316
324
|
script: string;
|
|
317
|
-
/**
|
|
325
|
+
/** LiteRT wasm URL */
|
|
318
326
|
wasm: string;
|
|
319
327
|
}
|
|
320
|
-
/**
|
|
328
|
+
/** WebGPU navigator type */
|
|
321
329
|
interface GpuNavigator extends Navigator {
|
|
322
330
|
gpu?: {
|
|
323
|
-
/**
|
|
331
|
+
/** Request WebGPU adapter */
|
|
324
332
|
requestAdapter: (options?: {
|
|
325
333
|
powerPreference?: `low-power` | `high-performance`;
|
|
326
334
|
}) => Promise<unknown>;
|
|
327
335
|
};
|
|
328
336
|
}
|
|
329
|
-
/**
|
|
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
|
|
364
|
+
/** Chromium mobile hint */
|
|
332
365
|
userAgentData?: {
|
|
333
366
|
mobile?: boolean;
|
|
334
367
|
};
|
|
335
368
|
};
|
|
336
|
-
/**
|
|
369
|
+
/** Status snapshot state */
|
|
337
370
|
interface ChatState {
|
|
338
|
-
/**
|
|
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
|
|
376
|
+
/** Last request error */
|
|
344
377
|
error?: string;
|
|
345
378
|
}
|
|
346
379
|
/** One live chat request */
|
|
@@ -352,171 +385,188 @@ interface ActiveCall extends ChatState {
|
|
|
352
385
|
/** Model resolved for this call */
|
|
353
386
|
model?: ChatModelId;
|
|
354
387
|
}
|
|
355
|
-
/**
|
|
388
|
+
/** Test engine overrides */
|
|
356
389
|
interface RuntimeDeps {
|
|
357
390
|
engines?: {
|
|
358
391
|
cpu?: LlmEngine;
|
|
359
392
|
litert?: LlmEngine;
|
|
360
393
|
};
|
|
361
394
|
backend?: LlmBackend;
|
|
395
|
+
/** Device class override, tests only */
|
|
396
|
+
mobile?: () => boolean;
|
|
362
397
|
}
|
|
363
398
|
/** One model load request */
|
|
364
399
|
interface RuntimeLoadParams {
|
|
365
400
|
model: ChatModel;
|
|
366
401
|
limits: LlmLimits;
|
|
367
402
|
assets?: Partial<WllamaAssets>;
|
|
368
|
-
/**
|
|
403
|
+
/** Engine logging flag */
|
|
369
404
|
logging?: boolean;
|
|
370
|
-
/** Stop
|
|
405
|
+
/** Stop awaiting shared load */
|
|
371
406
|
signal?: AbortSignal;
|
|
372
407
|
onProgress: (progress: number, phase: LlmPhase) => void;
|
|
373
408
|
}
|
|
374
|
-
/**
|
|
409
|
+
/** Waiting load caller */
|
|
375
410
|
interface RuntimeLoadWaiter {
|
|
376
|
-
/** Report
|
|
411
|
+
/** Report caller progress */
|
|
377
412
|
report: RuntimeLoadParams[`onProgress`];
|
|
378
|
-
/** Resolve
|
|
413
|
+
/** Resolve waiting caller */
|
|
379
414
|
settle: (loaded: boolean) => void;
|
|
380
415
|
}
|
|
381
|
-
/**
|
|
416
|
+
/** Stored model file bytes */
|
|
382
417
|
interface StoredPart {
|
|
383
418
|
/** Bytes already stored */
|
|
384
419
|
size: number;
|
|
385
|
-
/**
|
|
420
|
+
/** File size, zero unknown */
|
|
386
421
|
total: number;
|
|
387
|
-
/**
|
|
422
|
+
/** Stored bytes entity tag */
|
|
388
423
|
etag: string;
|
|
389
424
|
}
|
|
390
|
-
/**
|
|
425
|
+
/** Model part file */
|
|
391
426
|
interface StoredFilePart {
|
|
392
|
-
/**
|
|
427
|
+
/** Part byte offset */
|
|
393
428
|
start: number;
|
|
394
429
|
/** Bytes stored in the part */
|
|
395
430
|
size: number;
|
|
396
431
|
}
|
|
397
|
-
/**
|
|
432
|
+
/** Stored model file */
|
|
398
433
|
interface StoredModel extends StoredPart {
|
|
399
|
-
/**
|
|
434
|
+
/** Stored file snapshot */
|
|
400
435
|
file: Blob;
|
|
401
|
-
/**
|
|
436
|
+
/** Complete file flag */
|
|
402
437
|
complete: boolean;
|
|
403
438
|
}
|
|
404
|
-
/**
|
|
439
|
+
/** Stored download metadata */
|
|
405
440
|
interface StoredModelMeta {
|
|
406
441
|
total: number;
|
|
407
442
|
etag: string;
|
|
408
443
|
complete: boolean;
|
|
409
444
|
}
|
|
410
|
-
/**
|
|
445
|
+
/** Stored part continuation */
|
|
411
446
|
interface ResumePlan {
|
|
412
|
-
/**
|
|
447
|
+
/** Response start byte */
|
|
413
448
|
start: number;
|
|
414
|
-
/**
|
|
449
|
+
/** File size, zero unknown */
|
|
415
450
|
total: number;
|
|
416
451
|
etag: string;
|
|
417
452
|
}
|
|
418
|
-
/**
|
|
453
|
+
/** Model download into store */
|
|
419
454
|
interface StoreDownloadParams {
|
|
420
455
|
url: string;
|
|
421
|
-
/** Stop
|
|
456
|
+
/** Stop download, keep bytes */
|
|
422
457
|
signal?: AbortSignal;
|
|
423
458
|
onProgress: StartLlmParams[`onProgress`];
|
|
424
459
|
}
|
|
425
|
-
/**
|
|
460
|
+
/** Engine resumable file store */
|
|
426
461
|
interface ModelStore {
|
|
427
|
-
/** Stored
|
|
462
|
+
/** Stored model file info */
|
|
428
463
|
stored: (url: string) => Promise<StoredModel | undefined>;
|
|
429
|
-
/**
|
|
464
|
+
/** Resume model file download */
|
|
430
465
|
download: (params: StoreDownloadParams) => Promise<StoredModel | undefined>;
|
|
431
|
-
/** Delete
|
|
466
|
+
/** Delete model file */
|
|
432
467
|
remove: (url: string) => Promise<void>;
|
|
433
|
-
/** Delete
|
|
468
|
+
/** Delete entire store */
|
|
434
469
|
purge: () => Promise<void>;
|
|
435
470
|
}
|
|
436
471
|
/** One generation request */
|
|
437
472
|
interface RuntimeChatParams {
|
|
473
|
+
/** Resolved answer model */
|
|
474
|
+
model?: ChatModelId;
|
|
438
475
|
messages: ChatMessage[];
|
|
439
476
|
limits: LlmLimits;
|
|
440
477
|
reasoning: boolean;
|
|
441
|
-
/**
|
|
478
|
+
/** Repetition penalty */
|
|
479
|
+
repeatPenalty?: number;
|
|
480
|
+
/** Sampling temperature */
|
|
481
|
+
temperature?: number;
|
|
482
|
+
/** Engine logging flag */
|
|
442
483
|
logging?: boolean;
|
|
443
484
|
onReason: (text: string) => void;
|
|
444
485
|
onText: (text: string) => void;
|
|
445
|
-
/**
|
|
486
|
+
/** Generation speed */
|
|
446
487
|
onSpeed?: (tokensPerSecond: number) => void;
|
|
447
488
|
signal?: AbortSignal;
|
|
448
489
|
}
|
|
449
|
-
/**
|
|
490
|
+
/** Shared on-device runtime */
|
|
450
491
|
interface Runtime {
|
|
451
|
-
/** Load
|
|
492
|
+
/** Load or join model */
|
|
452
493
|
load: (params: RuntimeLoadParams) => Promise<boolean>;
|
|
453
494
|
chat: (params: RuntimeChatParams) => Promise<string | undefined>;
|
|
454
|
-
|
|
455
|
-
|
|
495
|
+
/** Release one or all models */
|
|
496
|
+
unload: (model?: ChatModelId) => Promise<void>;
|
|
497
|
+
/** Release and delete caches */
|
|
456
498
|
clear: () => Promise<void>;
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
|
|
463
|
-
/** Model
|
|
499
|
+
/** Model loaded check */
|
|
500
|
+
ready: (model?: ChatModelId) => boolean;
|
|
501
|
+
/** Model loading check */
|
|
502
|
+
loading: (model?: ChatModelId) => boolean;
|
|
503
|
+
/** Model load status */
|
|
504
|
+
status: (model?: ChatModelId) => LlmStatus;
|
|
505
|
+
/** Model backend */
|
|
506
|
+
backend: (model?: ChatModelId) => LlmBackend;
|
|
507
|
+
/** Latest model load error */
|
|
508
|
+
error: (model?: ChatModelId) => string | undefined;
|
|
509
|
+
/** Last active model */
|
|
464
510
|
model: () => ChatModel | undefined;
|
|
465
511
|
}
|
|
466
|
-
/**
|
|
512
|
+
/** Single chat generation params */
|
|
467
513
|
interface EngineChatParams {
|
|
468
514
|
messages: ChatMessage[];
|
|
469
515
|
limits: LlmLimits;
|
|
470
|
-
/**
|
|
516
|
+
/** Opt-in reasoning preference */
|
|
471
517
|
reasoning: boolean;
|
|
472
|
-
/**
|
|
518
|
+
/** Repetition penalty */
|
|
519
|
+
repeatPenalty?: number;
|
|
520
|
+
/** Sampling temperature */
|
|
521
|
+
temperature?: number;
|
|
522
|
+
/** Engine logging flag */
|
|
473
523
|
logging?: boolean;
|
|
474
524
|
/** Streamed reasoning delta */
|
|
475
525
|
onReason: (text: string) => void;
|
|
476
526
|
/** Streamed reply delta */
|
|
477
527
|
onText: (text: string) => void;
|
|
478
|
-
/**
|
|
528
|
+
/** Generation speed */
|
|
479
529
|
onSpeed?: (tokensPerSecond: number) => void;
|
|
480
530
|
signal?: AbortSignal;
|
|
481
531
|
}
|
|
482
532
|
/** Params of the engine startLLM */
|
|
483
533
|
interface StartLlmParams {
|
|
484
534
|
model: ChatModel;
|
|
485
|
-
/** Engine
|
|
535
|
+
/** Engine load budgets */
|
|
486
536
|
limits: LlmLimits;
|
|
487
|
-
/**
|
|
537
|
+
/** Download progress callback */
|
|
488
538
|
onProgress: (progress: number, phase?: LlmPhase) => void;
|
|
489
|
-
/**
|
|
539
|
+
/** Cancel download or load */
|
|
490
540
|
signal?: AbortSignal;
|
|
491
|
-
/**
|
|
541
|
+
/** Engine logging flag */
|
|
492
542
|
logging?: boolean;
|
|
493
543
|
/** CPU engine asset override */
|
|
494
544
|
assets?: Partial<WllamaAssets>;
|
|
495
545
|
}
|
|
496
|
-
/**
|
|
546
|
+
/** Engine start result */
|
|
497
547
|
interface LlmRuntime {
|
|
498
548
|
/** Model this runtime serves */
|
|
499
549
|
model: ChatModel;
|
|
500
550
|
/** Backend that accepted the model */
|
|
501
551
|
backend: LlmBackend;
|
|
502
|
-
/**
|
|
552
|
+
/** Requested context window */
|
|
503
553
|
contextSize: number;
|
|
504
|
-
/** Stream
|
|
554
|
+
/** Stream reply text */
|
|
505
555
|
chat: (params: EngineChatParams) => Promise<string | undefined>;
|
|
506
|
-
/** Release
|
|
556
|
+
/** Release model, keep cache */
|
|
507
557
|
unload: () => Promise<void>;
|
|
508
558
|
}
|
|
509
|
-
/**
|
|
559
|
+
/** Engine-backed model runner */
|
|
510
560
|
interface LlmEngine {
|
|
511
561
|
backend: LlmBackend;
|
|
512
|
-
/**
|
|
562
|
+
/** Load model runtime */
|
|
513
563
|
startLLM: (params: StartLlmParams) => Promise<LlmRuntime>;
|
|
514
|
-
/**
|
|
564
|
+
/** Model files stored check */
|
|
515
565
|
cached: (model: ChatModel) => Promise<boolean>;
|
|
516
|
-
/** Delete
|
|
566
|
+
/** Delete engine artifacts */
|
|
517
567
|
purge: () => Promise<void>;
|
|
518
568
|
}
|
|
519
|
-
/**
|
|
569
|
+
/** User turn content part */
|
|
520
570
|
type EngineContentPart = {
|
|
521
571
|
type: `text`;
|
|
522
572
|
text: string;
|
|
@@ -549,7 +599,7 @@ type WllamaMessage = {
|
|
|
549
599
|
role: `assistant`;
|
|
550
600
|
content: string;
|
|
551
601
|
};
|
|
552
|
-
/**
|
|
602
|
+
/** OpenAI-style chat message */
|
|
553
603
|
type EngineMessage = {
|
|
554
604
|
role: `system`;
|
|
555
605
|
content: string;
|
|
@@ -568,31 +618,33 @@ type LitertMessage = import('@litert-lm/core').Message;
|
|
|
568
618
|
type LitertEngine = import('@litert-lm/core').Engine;
|
|
569
619
|
/** The LiteRT-LM module namespace */
|
|
570
620
|
type LitertModule = typeof import('@litert-lm/core');
|
|
571
|
-
/**
|
|
621
|
+
/** LiteRT engine settings */
|
|
572
622
|
type LitertSettings = import('@litert-lm/core').EngineSettings;
|
|
573
|
-
/**
|
|
623
|
+
/** LiteRT settings params */
|
|
574
624
|
interface LitertSettingsParams {
|
|
575
625
|
/** Model with the artifact */
|
|
576
626
|
model: ChatModel;
|
|
577
|
-
/** Image
|
|
627
|
+
/** Image budgets */
|
|
578
628
|
limits: LlmLimits;
|
|
629
|
+
/** Requested context window */
|
|
630
|
+
contextSize: number;
|
|
579
631
|
/** Model file stream */
|
|
580
632
|
source: ReadableStream<Uint8Array>;
|
|
581
633
|
/** Loaded LiteRT module */
|
|
582
634
|
mod: LitertModule;
|
|
583
635
|
}
|
|
584
|
-
/**
|
|
636
|
+
/** Reused LiteRT conversation */
|
|
585
637
|
interface LitertSession {
|
|
586
|
-
/** Live conversation
|
|
638
|
+
/** Live LiteRT conversation */
|
|
587
639
|
conversation?: import('@litert-lm/core').Conversation;
|
|
588
|
-
/**
|
|
640
|
+
/** Sent conversation turns */
|
|
589
641
|
sent: EngineMessage[];
|
|
590
|
-
/**
|
|
642
|
+
/** Conversation reasoning flag */
|
|
591
643
|
reasoning: boolean;
|
|
592
|
-
/**
|
|
644
|
+
/** Conversation output budget */
|
|
593
645
|
maxTokens: number;
|
|
594
646
|
}
|
|
595
|
-
/**
|
|
647
|
+
/** LiteRT chat params */
|
|
596
648
|
interface LitertChatParams {
|
|
597
649
|
engine: LitertEngine;
|
|
598
650
|
model: ChatModel;
|
|
@@ -608,13 +660,13 @@ interface StreamLitertParams {
|
|
|
608
660
|
messages: EngineMessage[];
|
|
609
661
|
session: LitertSession;
|
|
610
662
|
}
|
|
611
|
-
/** Streamed
|
|
663
|
+
/** Streamed reasoning delta */
|
|
612
664
|
interface EngineDelta {
|
|
613
665
|
content?: string;
|
|
614
666
|
reasoning?: string;
|
|
615
667
|
reasoning_content?: string;
|
|
616
668
|
}
|
|
617
|
-
/**
|
|
669
|
+
/** Engine stream chunk */
|
|
618
670
|
interface EngineChunk {
|
|
619
671
|
choices?: Array<{
|
|
620
672
|
finish_reason?: string;
|
|
@@ -628,35 +680,35 @@ interface StreamReplyParams {
|
|
|
628
680
|
onReason: (text: string) => void;
|
|
629
681
|
/** Streamed reply delta */
|
|
630
682
|
onText: (text: string) => void;
|
|
631
|
-
/**
|
|
683
|
+
/** Generation speed */
|
|
632
684
|
onSpeed?: (tokensPerSecond: number) => void;
|
|
633
|
-
/** Open
|
|
685
|
+
/** Open engine stream */
|
|
634
686
|
start: () => Promise<AsyncIterable<unknown>>;
|
|
635
|
-
/**
|
|
687
|
+
/** Generation stopped flag */
|
|
636
688
|
stopped: () => boolean;
|
|
637
|
-
/**
|
|
689
|
+
/** Engine logging flag */
|
|
638
690
|
logging?: boolean;
|
|
639
|
-
/**
|
|
691
|
+
/** First chunk timeout */
|
|
640
692
|
firstTimeoutMs?: number;
|
|
641
693
|
/** Budget between two chunks, milliseconds */
|
|
642
694
|
idleTimeoutMs?: number;
|
|
643
|
-
/**
|
|
695
|
+
/** Slow stream callback */
|
|
644
696
|
onStall?: () => void;
|
|
645
697
|
}
|
|
646
|
-
/**
|
|
698
|
+
/** Engine chat params */
|
|
647
699
|
interface EngineRunParams {
|
|
648
700
|
model: ChatModel;
|
|
649
701
|
params: EngineChatParams;
|
|
650
|
-
/** Open
|
|
702
|
+
/** Open engine stream */
|
|
651
703
|
start: (messages: EngineMessage[]) => Promise<AsyncIterable<unknown>>;
|
|
652
|
-
/**
|
|
704
|
+
/** Generation stopped flag */
|
|
653
705
|
stopped: () => boolean;
|
|
654
|
-
/**
|
|
706
|
+
/** Slow stream callback */
|
|
655
707
|
onStall?: () => void;
|
|
656
708
|
}
|
|
657
|
-
/**
|
|
709
|
+
/** Engine image pixel size */
|
|
658
710
|
interface ImageSize {
|
|
659
711
|
width: number;
|
|
660
712
|
height: number;
|
|
661
713
|
}
|
|
662
|
-
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, };
|