@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/README.md +145 -126
- 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 +16 -7
- 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 +1 -1
- package/dist/engines/wllama.d.ts +4 -4
- package/dist/enums.d.ts +6 -7
- package/dist/index.d.ts +2 -1
- package/dist/log.d.ts +1 -1
- package/dist/models.d.ts +12 -12
- 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 +216 -173
- package/package.json +4 -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,7 +385,7 @@ 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;
|
|
@@ -367,165 +400,173 @@ interface RuntimeLoadParams {
|
|
|
367
400
|
model: ChatModel;
|
|
368
401
|
limits: LlmLimits;
|
|
369
402
|
assets?: Partial<WllamaAssets>;
|
|
370
|
-
/**
|
|
403
|
+
/** Engine logging flag */
|
|
371
404
|
logging?: boolean;
|
|
372
|
-
/** Stop
|
|
405
|
+
/** Stop awaiting shared load */
|
|
373
406
|
signal?: AbortSignal;
|
|
374
407
|
onProgress: (progress: number, phase: LlmPhase) => void;
|
|
375
408
|
}
|
|
376
|
-
/**
|
|
409
|
+
/** Waiting load caller */
|
|
377
410
|
interface RuntimeLoadWaiter {
|
|
378
|
-
/** Report
|
|
411
|
+
/** Report caller progress */
|
|
379
412
|
report: RuntimeLoadParams[`onProgress`];
|
|
380
|
-
/** Resolve
|
|
413
|
+
/** Resolve waiting caller */
|
|
381
414
|
settle: (loaded: boolean) => void;
|
|
382
415
|
}
|
|
383
|
-
/**
|
|
416
|
+
/** Stored model file bytes */
|
|
384
417
|
interface StoredPart {
|
|
385
418
|
/** Bytes already stored */
|
|
386
419
|
size: number;
|
|
387
|
-
/**
|
|
420
|
+
/** File size, zero unknown */
|
|
388
421
|
total: number;
|
|
389
|
-
/**
|
|
422
|
+
/** Stored bytes entity tag */
|
|
390
423
|
etag: string;
|
|
391
424
|
}
|
|
392
|
-
/**
|
|
425
|
+
/** Model part file */
|
|
393
426
|
interface StoredFilePart {
|
|
394
|
-
/**
|
|
427
|
+
/** Part byte offset */
|
|
395
428
|
start: number;
|
|
396
429
|
/** Bytes stored in the part */
|
|
397
430
|
size: number;
|
|
398
431
|
}
|
|
399
|
-
/**
|
|
432
|
+
/** Stored model file */
|
|
400
433
|
interface StoredModel extends StoredPart {
|
|
401
|
-
/**
|
|
434
|
+
/** Stored file snapshot */
|
|
402
435
|
file: Blob;
|
|
403
|
-
/**
|
|
436
|
+
/** Complete file flag */
|
|
404
437
|
complete: boolean;
|
|
405
438
|
}
|
|
406
|
-
/**
|
|
439
|
+
/** Stored download metadata */
|
|
407
440
|
interface StoredModelMeta {
|
|
408
441
|
total: number;
|
|
409
442
|
etag: string;
|
|
410
443
|
complete: boolean;
|
|
411
444
|
}
|
|
412
|
-
/**
|
|
445
|
+
/** Stored part continuation */
|
|
413
446
|
interface ResumePlan {
|
|
414
|
-
/**
|
|
447
|
+
/** Response start byte */
|
|
415
448
|
start: number;
|
|
416
|
-
/**
|
|
449
|
+
/** File size, zero unknown */
|
|
417
450
|
total: number;
|
|
418
451
|
etag: string;
|
|
419
452
|
}
|
|
420
|
-
/**
|
|
453
|
+
/** Model download into store */
|
|
421
454
|
interface StoreDownloadParams {
|
|
422
455
|
url: string;
|
|
423
|
-
/** Stop
|
|
456
|
+
/** Stop download, keep bytes */
|
|
424
457
|
signal?: AbortSignal;
|
|
425
458
|
onProgress: StartLlmParams[`onProgress`];
|
|
426
459
|
}
|
|
427
|
-
/**
|
|
460
|
+
/** Engine resumable file store */
|
|
428
461
|
interface ModelStore {
|
|
429
|
-
/** Stored
|
|
462
|
+
/** Stored model file info */
|
|
430
463
|
stored: (url: string) => Promise<StoredModel | undefined>;
|
|
431
|
-
/**
|
|
464
|
+
/** Resume model file download */
|
|
432
465
|
download: (params: StoreDownloadParams) => Promise<StoredModel | undefined>;
|
|
433
|
-
/** Delete
|
|
466
|
+
/** Delete model file */
|
|
434
467
|
remove: (url: string) => Promise<void>;
|
|
435
|
-
/** Delete
|
|
468
|
+
/** Delete entire store */
|
|
436
469
|
purge: () => Promise<void>;
|
|
437
470
|
}
|
|
438
471
|
/** One generation request */
|
|
439
472
|
interface RuntimeChatParams {
|
|
440
|
-
/**
|
|
473
|
+
/** Resolved answer model */
|
|
441
474
|
model?: ChatModelId;
|
|
442
475
|
messages: ChatMessage[];
|
|
443
476
|
limits: LlmLimits;
|
|
444
477
|
reasoning: boolean;
|
|
445
|
-
/**
|
|
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
|
-
/**
|
|
486
|
+
/** Generation speed */
|
|
450
487
|
onSpeed?: (tokensPerSecond: number) => void;
|
|
451
488
|
signal?: AbortSignal;
|
|
452
489
|
}
|
|
453
|
-
/**
|
|
490
|
+
/** Shared on-device runtime */
|
|
454
491
|
interface Runtime {
|
|
455
|
-
/** Load
|
|
492
|
+
/** Load or join model */
|
|
456
493
|
load: (params: RuntimeLoadParams) => Promise<boolean>;
|
|
457
494
|
chat: (params: RuntimeChatParams) => Promise<string | undefined>;
|
|
458
|
-
/** Release one
|
|
495
|
+
/** Release one or all models */
|
|
459
496
|
unload: (model?: ChatModelId) => Promise<void>;
|
|
460
|
-
/** Release
|
|
497
|
+
/** Release and delete caches */
|
|
461
498
|
clear: () => Promise<void>;
|
|
462
|
-
/**
|
|
499
|
+
/** Model loaded check */
|
|
463
500
|
ready: (model?: ChatModelId) => boolean;
|
|
464
|
-
/**
|
|
501
|
+
/** Model loading check */
|
|
465
502
|
loading: (model?: ChatModelId) => boolean;
|
|
466
|
-
/**
|
|
503
|
+
/** Model load status */
|
|
467
504
|
status: (model?: ChatModelId) => LlmStatus;
|
|
468
|
-
/**
|
|
505
|
+
/** Model backend */
|
|
469
506
|
backend: (model?: ChatModelId) => LlmBackend;
|
|
470
|
-
/**
|
|
507
|
+
/** Latest model load error */
|
|
471
508
|
error: (model?: ChatModelId) => string | undefined;
|
|
472
|
-
/**
|
|
509
|
+
/** Last active model */
|
|
473
510
|
model: () => ChatModel | undefined;
|
|
474
511
|
}
|
|
475
|
-
/**
|
|
512
|
+
/** Single chat generation params */
|
|
476
513
|
interface EngineChatParams {
|
|
477
514
|
messages: ChatMessage[];
|
|
478
515
|
limits: LlmLimits;
|
|
479
|
-
/**
|
|
516
|
+
/** Opt-in reasoning preference */
|
|
480
517
|
reasoning: boolean;
|
|
481
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
535
|
+
/** Engine load budgets */
|
|
495
536
|
limits: LlmLimits;
|
|
496
|
-
/**
|
|
537
|
+
/** Download progress callback */
|
|
497
538
|
onProgress: (progress: number, phase?: LlmPhase) => void;
|
|
498
|
-
/**
|
|
539
|
+
/** Cancel download or load */
|
|
499
540
|
signal?: AbortSignal;
|
|
500
|
-
/**
|
|
541
|
+
/** Engine logging flag */
|
|
501
542
|
logging?: boolean;
|
|
502
543
|
/** CPU engine asset override */
|
|
503
544
|
assets?: Partial<WllamaAssets>;
|
|
504
545
|
}
|
|
505
|
-
/**
|
|
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
|
-
/**
|
|
552
|
+
/** Requested context window */
|
|
512
553
|
contextSize: number;
|
|
513
|
-
/** Stream
|
|
554
|
+
/** Stream reply text */
|
|
514
555
|
chat: (params: EngineChatParams) => Promise<string | undefined>;
|
|
515
|
-
/** Release
|
|
556
|
+
/** Release model, keep cache */
|
|
516
557
|
unload: () => Promise<void>;
|
|
517
558
|
}
|
|
518
|
-
/**
|
|
559
|
+
/** Engine-backed model runner */
|
|
519
560
|
interface LlmEngine {
|
|
520
561
|
backend: LlmBackend;
|
|
521
|
-
/**
|
|
562
|
+
/** Load model runtime */
|
|
522
563
|
startLLM: (params: StartLlmParams) => Promise<LlmRuntime>;
|
|
523
|
-
/**
|
|
564
|
+
/** Model files stored check */
|
|
524
565
|
cached: (model: ChatModel) => Promise<boolean>;
|
|
525
|
-
/** Delete
|
|
566
|
+
/** Delete engine artifacts */
|
|
526
567
|
purge: () => Promise<void>;
|
|
527
568
|
}
|
|
528
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
621
|
+
/** LiteRT engine settings */
|
|
581
622
|
type LitertSettings = import('@litert-lm/core').EngineSettings;
|
|
582
|
-
/**
|
|
623
|
+
/** LiteRT settings params */
|
|
583
624
|
interface LitertSettingsParams {
|
|
584
625
|
/** Model with the artifact */
|
|
585
626
|
model: ChatModel;
|
|
586
|
-
/** Image
|
|
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
|
-
/**
|
|
636
|
+
/** Reused LiteRT conversation */
|
|
594
637
|
interface LitertSession {
|
|
595
|
-
/** Live conversation
|
|
638
|
+
/** Live LiteRT conversation */
|
|
596
639
|
conversation?: import('@litert-lm/core').Conversation;
|
|
597
|
-
/**
|
|
640
|
+
/** Sent conversation turns */
|
|
598
641
|
sent: EngineMessage[];
|
|
599
|
-
/**
|
|
642
|
+
/** Conversation reasoning flag */
|
|
600
643
|
reasoning: boolean;
|
|
601
|
-
/**
|
|
644
|
+
/** Conversation output budget */
|
|
602
645
|
maxTokens: number;
|
|
603
646
|
}
|
|
604
|
-
/**
|
|
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
|
|
663
|
+
/** Streamed reasoning delta */
|
|
621
664
|
interface EngineDelta {
|
|
622
665
|
content?: string;
|
|
623
666
|
reasoning?: string;
|
|
624
667
|
reasoning_content?: string;
|
|
625
668
|
}
|
|
626
|
-
/**
|
|
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
|
-
/**
|
|
683
|
+
/** Generation speed */
|
|
641
684
|
onSpeed?: (tokensPerSecond: number) => void;
|
|
642
|
-
/** Open
|
|
685
|
+
/** Open engine stream */
|
|
643
686
|
start: () => Promise<AsyncIterable<unknown>>;
|
|
644
|
-
/**
|
|
687
|
+
/** Generation stopped flag */
|
|
645
688
|
stopped: () => boolean;
|
|
646
|
-
/**
|
|
689
|
+
/** Engine logging flag */
|
|
647
690
|
logging?: boolean;
|
|
648
|
-
/**
|
|
691
|
+
/** First chunk timeout */
|
|
649
692
|
firstTimeoutMs?: number;
|
|
650
693
|
/** Budget between two chunks, milliseconds */
|
|
651
694
|
idleTimeoutMs?: number;
|
|
652
|
-
/**
|
|
695
|
+
/** Slow stream callback */
|
|
653
696
|
onStall?: () => void;
|
|
654
697
|
}
|
|
655
|
-
/**
|
|
698
|
+
/** Engine chat params */
|
|
656
699
|
interface EngineRunParams {
|
|
657
700
|
model: ChatModel;
|
|
658
701
|
params: EngineChatParams;
|
|
659
|
-
/** Open
|
|
702
|
+
/** Open engine stream */
|
|
660
703
|
start: (messages: EngineMessage[]) => Promise<AsyncIterable<unknown>>;
|
|
661
|
-
/**
|
|
704
|
+
/** Generation stopped flag */
|
|
662
705
|
stopped: () => boolean;
|
|
663
|
-
/**
|
|
706
|
+
/** Slow stream callback */
|
|
664
707
|
onStall?: () => void;
|
|
665
708
|
}
|
|
666
|
-
/**
|
|
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, };
|