@browser-ai/web-llm 2.0.4 → 2.1.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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
2
- import { AppConfig, InitProgressReport, MLCEngineConfig, MLCEngineInterface } from '@mlc-ai/web-llm';
2
+ import { AppConfig, InitProgressReport, MLCEngineConfig } from '@mlc-ai/web-llm';
3
3
  export { InitProgressReport as WebLLMProgress, WebWorkerMLCEngineHandler } from '@mlc-ai/web-llm';
4
4
  import { UIMessage } from 'ai';
5
5
 
@@ -64,6 +64,12 @@ type Availability =
64
64
  | "downloading"
65
65
  | "available";
66
66
 
67
+ /**
68
+ * Callback type for receiving model download/initialization progress updates.
69
+ * @param progress - A value between 0 and 1 indicating completion.
70
+ */
71
+ type DownloadProgressCallback = (progress: number) => void;
72
+
67
73
  declare global {
68
74
  interface Navigator {
69
75
  gpu?: GPU;
@@ -134,18 +140,18 @@ declare class WebLLMLanguageModel implements LanguageModelV3 {
134
140
  *
135
141
  * @example
136
142
  * ```typescript
137
- * const engine = await model.createSessionWithProgress(
143
+ * const model = await model.createSessionWithProgress(
138
144
  * (progress) => {
139
- * console.log(`Download progress: ${Math.round(progress.loaded * 100)}%`);
145
+ * console.log(`Download progress: ${Math.round(progress * 100)}%`);
140
146
  * }
141
147
  * );
142
148
  * ```
143
149
  *
144
- * @param onInitProgress Optional callback receiving progress reports during model download
145
- * @returns Promise resolving to a configured WebLLM engine
150
+ * @param onDownloadProgress Optional callback receiving progress values from 0 to 1
151
+ * @returns Promise resolving to the model instance
146
152
  * @throws {LoadSettingError} When WebLLM is not available or model is unavailable
147
153
  */
148
- createSessionWithProgress(onInitProgress?: (progress: InitProgressReport) => void): Promise<MLCEngineInterface>;
154
+ createSessionWithProgress(onDownloadProgress?: DownloadProgressCallback): Promise<WebLLMLanguageModel>;
149
155
  /**
150
156
  * Generates a streaming text response using WebLLM
151
157
  * @param options
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
2
- import { AppConfig, InitProgressReport, MLCEngineConfig, MLCEngineInterface } from '@mlc-ai/web-llm';
2
+ import { AppConfig, InitProgressReport, MLCEngineConfig } from '@mlc-ai/web-llm';
3
3
  export { InitProgressReport as WebLLMProgress, WebWorkerMLCEngineHandler } from '@mlc-ai/web-llm';
4
4
  import { UIMessage } from 'ai';
5
5
 
@@ -64,6 +64,12 @@ type Availability =
64
64
  | "downloading"
65
65
  | "available";
66
66
 
67
+ /**
68
+ * Callback type for receiving model download/initialization progress updates.
69
+ * @param progress - A value between 0 and 1 indicating completion.
70
+ */
71
+ type DownloadProgressCallback = (progress: number) => void;
72
+
67
73
  declare global {
68
74
  interface Navigator {
69
75
  gpu?: GPU;
@@ -134,18 +140,18 @@ declare class WebLLMLanguageModel implements LanguageModelV3 {
134
140
  *
135
141
  * @example
136
142
  * ```typescript
137
- * const engine = await model.createSessionWithProgress(
143
+ * const model = await model.createSessionWithProgress(
138
144
  * (progress) => {
139
- * console.log(`Download progress: ${Math.round(progress.loaded * 100)}%`);
145
+ * console.log(`Download progress: ${Math.round(progress * 100)}%`);
140
146
  * }
141
147
  * );
142
148
  * ```
143
149
  *
144
- * @param onInitProgress Optional callback receiving progress reports during model download
145
- * @returns Promise resolving to a configured WebLLM engine
150
+ * @param onDownloadProgress Optional callback receiving progress values from 0 to 1
151
+ * @returns Promise resolving to the model instance
146
152
  * @throws {LoadSettingError} When WebLLM is not available or model is unavailable
147
153
  */
148
- createSessionWithProgress(onInitProgress?: (progress: InitProgressReport) => void): Promise<MLCEngineInterface>;
154
+ createSessionWithProgress(onDownloadProgress?: DownloadProgressCallback): Promise<WebLLMLanguageModel>;
149
155
  /**
150
156
  * Generates a streaming text response using WebLLM
151
157
  * @param options
package/dist/index.js CHANGED
@@ -1372,19 +1372,23 @@ var WebLLMLanguageModel = class {
1372
1372
  *
1373
1373
  * @example
1374
1374
  * ```typescript
1375
- * const engine = await model.createSessionWithProgress(
1375
+ * const model = await model.createSessionWithProgress(
1376
1376
  * (progress) => {
1377
- * console.log(`Download progress: ${Math.round(progress.loaded * 100)}%`);
1377
+ * console.log(`Download progress: ${Math.round(progress * 100)}%`);
1378
1378
  * }
1379
1379
  * );
1380
1380
  * ```
1381
1381
  *
1382
- * @param onInitProgress Optional callback receiving progress reports during model download
1383
- * @returns Promise resolving to a configured WebLLM engine
1382
+ * @param onDownloadProgress Optional callback receiving progress values from 0 to 1
1383
+ * @returns Promise resolving to the model instance
1384
1384
  * @throws {LoadSettingError} When WebLLM is not available or model is unavailable
1385
1385
  */
1386
- async createSessionWithProgress(onInitProgress) {
1387
- return this.getEngine(void 0, onInitProgress);
1386
+ async createSessionWithProgress(onDownloadProgress) {
1387
+ const adaptedCallback = onDownloadProgress ? (report) => {
1388
+ onDownloadProgress(report.progress);
1389
+ } : void 0;
1390
+ await this.getEngine(void 0, adaptedCallback);
1391
+ return this;
1388
1392
  }
1389
1393
  /**
1390
1394
  * Generates a streaming text response using WebLLM