@litert-lm/core 0.12.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.
Files changed (82) hide show
  1. package/README.md +145 -0
  2. package/dist/cleanup.d.ts +25 -0
  3. package/dist/cleanup.d.ts.map +1 -0
  4. package/dist/cleanup.js +36 -0
  5. package/dist/cleanup.js.map +1 -0
  6. package/dist/conversation.d.ts +43 -0
  7. package/dist/conversation.d.ts.map +1 -0
  8. package/dist/conversation.js +153 -0
  9. package/dist/conversation.js.map +1 -0
  10. package/dist/conversation_config.d.ts +107 -0
  11. package/dist/conversation_config.d.ts.map +1 -0
  12. package/dist/conversation_config.js +17 -0
  13. package/dist/conversation_config.js.map +1 -0
  14. package/dist/engine.d.ts +37 -0
  15. package/dist/engine.d.ts.map +1 -0
  16. package/dist/engine.js +200 -0
  17. package/dist/engine.js.map +1 -0
  18. package/dist/engine_settings.d.ts +56 -0
  19. package/dist/engine_settings.d.ts.map +1 -0
  20. package/dist/engine_settings.js +110 -0
  21. package/dist/engine_settings.js.map +1 -0
  22. package/dist/global_litertlm.d.ts +66 -0
  23. package/dist/global_litertlm.d.ts.map +1 -0
  24. package/dist/global_litertlm.js +85 -0
  25. package/dist/global_litertlm.js.map +1 -0
  26. package/dist/index.d.ts +27 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +27 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/litertlm_web.d.ts +32 -0
  31. package/dist/litertlm_web.d.ts.map +1 -0
  32. package/dist/litertlm_web.js +75 -0
  33. package/dist/litertlm_web.js.map +1 -0
  34. package/dist/load.d.ts +28 -0
  35. package/dist/load.d.ts.map +1 -0
  36. package/dist/load.js +43 -0
  37. package/dist/load.js.map +1 -0
  38. package/dist/load_litertlm.d.ts +58 -0
  39. package/dist/load_litertlm.d.ts.map +1 -0
  40. package/dist/load_litertlm.js +75 -0
  41. package/dist/load_litertlm.js.map +1 -0
  42. package/dist/mutex.d.ts +45 -0
  43. package/dist/mutex.d.ts.map +1 -0
  44. package/dist/mutex.js +62 -0
  45. package/dist/mutex.js.map +1 -0
  46. package/dist/readable_stream_data_stream_wrapper.d.ts +44 -0
  47. package/dist/readable_stream_data_stream_wrapper.d.ts.map +1 -0
  48. package/dist/readable_stream_data_stream_wrapper.js +315 -0
  49. package/dist/readable_stream_data_stream_wrapper.js.map +1 -0
  50. package/dist/session.d.ts +46 -0
  51. package/dist/session.d.ts.map +1 -0
  52. package/dist/session.js +88 -0
  53. package/dist/session.js.map +1 -0
  54. package/dist/session_config.d.ts +55 -0
  55. package/dist/session_config.d.ts.map +1 -0
  56. package/dist/session_config.js +109 -0
  57. package/dist/session_config.js.map +1 -0
  58. package/dist/types.d.ts +42 -0
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/types.js +17 -0
  61. package/dist/types.js.map +1 -0
  62. package/dist/url_path_utils.d.ts +28 -0
  63. package/dist/url_path_utils.d.ts.map +1 -0
  64. package/dist/url_path_utils.js +34 -0
  65. package/dist/url_path_utils.js.map +1 -0
  66. package/dist/wasm_binding_types.d.ts +365 -0
  67. package/dist/wasm_binding_types.d.ts.map +1 -0
  68. package/dist/wasm_binding_types.js +39 -0
  69. package/dist/wasm_binding_types.js.map +1 -0
  70. package/dist/wasm_feature_detect.d.ts +42 -0
  71. package/dist/wasm_feature_detect.d.ts.map +1 -0
  72. package/dist/wasm_feature_detect.js +117 -0
  73. package/dist/wasm_feature_detect.js.map +1 -0
  74. package/dist/wasm_utils.d.ts +30 -0
  75. package/dist/wasm_utils.d.ts.map +1 -0
  76. package/dist/wasm_utils.js +41 -0
  77. package/dist/wasm_utils.js.map +1 -0
  78. package/package.json +46 -0
  79. package/wasm/litertlm_wasm_compat_internal.js +8400 -0
  80. package/wasm/litertlm_wasm_compat_internal.wasm +0 -0
  81. package/wasm/litertlm_wasm_internal.js +8389 -0
  82. package/wasm/litertlm_wasm_internal.wasm +0 -0
package/dist/engine.js ADDED
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Copyright 2026 The ODML Authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Cleanup } from './cleanup';
17
+ import { Conversation } from './conversation';
18
+ import { fillWasmEngineSettingsFromEngineSettings, wasmEngineSettingsToEngineSettings } from './engine_settings';
19
+ import { getOrLoadGlobalLiteRtLm } from './load_litertlm';
20
+ import { Mutex } from './mutex';
21
+ import { ReadableStreamDataStreamWrapper } from './readable_stream_data_stream_wrapper';
22
+ import { Session } from './session';
23
+ import { sessionConfigToWasmSessionConfig } from './session_config';
24
+ import { Backend } from './wasm_binding_types';
25
+ /**
26
+ * Global index to avoid writing to the sane VFS path.
27
+ */
28
+ // TODO: b/477709280 - Remove this when streaming loading works.
29
+ let modelPathIndex = 0;
30
+ /**
31
+ * LiteRT-LM Engine
32
+ */
33
+ export class Engine {
34
+ wasm;
35
+ engine;
36
+ deleteCallback;
37
+ settings;
38
+ mutexes = {
39
+ executor: new Mutex(),
40
+ };
41
+ constructor(wasm, engine, modelSource, deleteCallback) {
42
+ this.wasm = wasm;
43
+ this.engine = engine;
44
+ this.deleteCallback = deleteCallback;
45
+ const wasmEngineSettings = engine.getEngineSettings();
46
+ const settingsWithoutModel = wasmEngineSettingsToEngineSettings(wasmEngineSettings);
47
+ this.settings = {
48
+ ...settingsWithoutModel,
49
+ model: modelSource,
50
+ };
51
+ wasmEngineSettings.delete();
52
+ }
53
+ static async create(engineSettings, inputPromptAsHint = '') {
54
+ const litertlm = await getOrLoadGlobalLiteRtLm();
55
+ const wasm = litertlm.liteRtLmWasm;
56
+ // TODO: b/477709280 - Support other formats like .task.
57
+ const dstPath = `/model_${modelPathIndex++}.litertlm`;
58
+ // Default to GPU_ARTISAN if not specified.
59
+ const backend = engineSettings.backend ?? Backend.GPU_ARTISAN;
60
+ engineSettings = { ...engineSettings, backend };
61
+ const samplerBackend = engineSettings.mainExecutorSettings?.samplerBackend;
62
+ if (backend === Backend.GPU || backend === Backend.GPU_ARTISAN ||
63
+ samplerBackend === Backend.GPU ||
64
+ samplerBackend === Backend.GPU_ARTISAN) {
65
+ await litertlm.setupDefaultWebGpuDevice();
66
+ }
67
+ const cleanup = new Cleanup();
68
+ const modelStream = await modelToStream(engineSettings.model);
69
+ let engine;
70
+ try {
71
+ let modelAssets;
72
+ const isStreaming = backend === Backend.GPU_ARTISAN;
73
+ if (isStreaming) {
74
+ // GPU Artisan supports streamed loading.
75
+ const streamWrapper = new ReadableStreamDataStreamWrapper(modelStream, () => wasm.HEAPU8);
76
+ const dataStream = wasm.ReadableStreamDataStream.create(streamWrapper);
77
+ cleanup.add(() => {
78
+ dataStream.delete();
79
+ });
80
+ modelAssets = wasm.ModelAssets.createStreaming(dataStream);
81
+ }
82
+ else {
83
+ // Other backends must be fully loaded into Wasm memory first.
84
+ await loadModelToVfs(wasm, modelStream, dstPath);
85
+ cleanup.add(() => {
86
+ try {
87
+ wasm.FS.unlink(dstPath);
88
+ }
89
+ catch (e) {
90
+ console.error(`Error removing file from VFS:`, e);
91
+ }
92
+ });
93
+ modelAssets = wasm.ModelAssets.create(dstPath);
94
+ }
95
+ const cleanupModelAssets = cleanup.add(() => {
96
+ modelAssets.delete();
97
+ });
98
+ const wasmEngineSettings = wasm.EngineSettings.createDefault(modelAssets, { value: backend });
99
+ // Delete our copy of the ModelAssets object (not the underlying file).
100
+ cleanupModelAssets();
101
+ const cleanupWasmEngineSettings = cleanup.add(() => {
102
+ wasmEngineSettings.delete();
103
+ });
104
+ fillWasmEngineSettingsFromEngineSettings(wasmEngineSettings, engineSettings, backend, wasm);
105
+ wasmEngineSettings.setParallelFileSectionLoading(false);
106
+ wasmEngineSettings.setSingleThreadedExecution(true);
107
+ if (isStreaming) {
108
+ engine = await wasm.Engine.createStreaming(wasmEngineSettings, inputPromptAsHint);
109
+ }
110
+ else {
111
+ engine = await wasm.Engine.createEngine(wasmEngineSettings, inputPromptAsHint);
112
+ }
113
+ cleanupWasmEngineSettings();
114
+ cleanup.add(() => {
115
+ engine.delete();
116
+ });
117
+ return new Engine(wasm, engine, engineSettings.model, () => cleanup.run());
118
+ }
119
+ catch (e) {
120
+ cleanup.run();
121
+ throw e;
122
+ }
123
+ }
124
+ async createSession(sessionConfig = {}) {
125
+ return this.mutexes.executor.acquireAndRun(() => {
126
+ const wasmSessionConfig = sessionConfigToWasmSessionConfig(sessionConfig, this.wasm);
127
+ const wasmSession = this.engine.createSession(wasmSessionConfig);
128
+ wasmSessionConfig.delete();
129
+ return new Session(wasmSession, this.mutexes);
130
+ });
131
+ }
132
+ async createConversation(config) {
133
+ return this.mutexes.executor.acquireAndRun(() => {
134
+ let wasmConfig;
135
+ let wasmSessionConfig;
136
+ if (config) {
137
+ wasmSessionConfig = sessionConfigToWasmSessionConfig(config.sessionConfig || {}, this.wasm);
138
+ const prefaceJson = config.preface ? JSON.stringify(config.preface) : '';
139
+ wasmConfig = this.wasm.ConversationConfig.createCustom(this.engine, wasmSessionConfig, !!config.enableConstrainedDecoding, !!config.prefillPrefaceOnInit, !!config.filterChannelContentFromKvCache, prefaceJson);
140
+ }
141
+ else {
142
+ wasmConfig = this.wasm.ConversationConfig.createDefault(this.engine);
143
+ }
144
+ const wasmConversation = this.wasm.Conversation.create(this.engine, wasmConfig);
145
+ wasmConfig.delete();
146
+ if (wasmSessionConfig) {
147
+ wasmSessionConfig.delete();
148
+ }
149
+ return new Conversation(wasmConversation, this.engine, this.mutexes);
150
+ });
151
+ }
152
+ async delete() {
153
+ await this.mutexes.executor.acquireAndRun(() => {
154
+ this.deleteCallback();
155
+ });
156
+ }
157
+ }
158
+ async function modelToStream(model) {
159
+ if (model instanceof ReadableStream) {
160
+ return model;
161
+ }
162
+ const modelUrl = model;
163
+ const response = await fetch(modelUrl, {
164
+ credentials: 'same-origin',
165
+ });
166
+ if (!response.ok) {
167
+ throw new Error(`Failed to fetch model file from ${modelUrl}`);
168
+ }
169
+ return response.body;
170
+ }
171
+ // TODO: b/477709280 - Remove this when streaming loading works.
172
+ async function loadModelToVfs(module, modelStream, dstPath) {
173
+ let fileContent;
174
+ const reader = modelStream.getReader();
175
+ const chunks = [];
176
+ let totalLength = 0;
177
+ while (true) {
178
+ const { done, value } = await reader.read();
179
+ if (done)
180
+ break;
181
+ if (value) {
182
+ chunks.push(value);
183
+ totalLength += value.length;
184
+ }
185
+ }
186
+ fileContent = new Uint8Array(totalLength);
187
+ let offset = 0;
188
+ for (const chunk of chunks) {
189
+ fileContent.set(chunk, offset);
190
+ offset += chunk.length;
191
+ }
192
+ try {
193
+ module.FS.writeFile(dstPath, fileContent);
194
+ }
195
+ catch (e) {
196
+ console.error(`Error writing file to VFS:`, e);
197
+ throw e;
198
+ }
199
+ }
200
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAiB,wCAAwC,EAAE,kCAAkC,EAAC,MAAM,mBAAmB,CAAC;AAE/H,OAAO,EAAC,uBAAuB,EAAC,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,+BAA+B,EAAC,MAAM,uCAAuC,CAAC;AACtF,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,gCAAgC,EAAC,MAAM,kBAAkB,CAA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C;IACpB,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,EAAC,IAAI,EAAE,KAAK,EAAC,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAC1C,IAAI,IAAI;YAAE,MAAM;QAChB,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,WAAW,IAAI,KAAK,CAAC,MAAM,CAAC;QAC9B,CAAC;IACH,CAAC;IACD,WAAW,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC1C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAC5C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,CAAC,CAAC,CAAC;QAC/C,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Copyright 2026 The ODML Authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { RecursiveRequired } from './types';
17
+ import { type AdvancedSettings, Backend, type CpuConfig, EngineSettings as WasmEngineSettings, GpuArtisanConfig as WasmGpuArtisanConfig, type GpuConfig } from './wasm_binding_types';
18
+ export { AdvancedSettings, CpuConfig, GpuConfig };
19
+ /**
20
+ * LiteRT-LM GpuArtisanConfig
21
+ */
22
+ export interface GpuArtisanConfig extends Omit<WasmGpuArtisanConfig, 'supported_lora_ranks'> {
23
+ supported_lora_ranks: number[];
24
+ }
25
+ /**
26
+ * LiteRT-LM LlmExecutorSettings
27
+ */
28
+ export interface LlmExecutorSettings {
29
+ maxNumTokens?: number;
30
+ backendConfig?: CpuConfig | GpuConfig | GpuArtisanConfig;
31
+ samplerBackend?: Backend;
32
+ advancedSettings?: Partial<AdvancedSettings>;
33
+ }
34
+ /**
35
+ * LiteRT-LM EngineSettings
36
+ */
37
+ export interface EngineSettings {
38
+ model: string | ReadableStream<Uint8Array>;
39
+ backend?: Backend;
40
+ mainExecutorSettings?: LlmExecutorSettings;
41
+ }
42
+ /**
43
+ * Fills a WasmEngineSettings with the values from a EngineSettings.
44
+ */
45
+ export declare function fillWasmEngineSettingsFromEngineSettings(wasmEngineSettings: WasmEngineSettings, engineSettings: EngineSettings, backend: Backend, wasm?: import("./wasm_binding_types").LiteRtLmWasm): void;
46
+ /**
47
+ * Converts a WasmEngineSettings to a EngineSettings.
48
+ *
49
+ * Fields are populated with the WASM object's values, which may be default
50
+ * values if they were not set.
51
+ *
52
+ * The returned value omits the `model` field since its TS representation is a
53
+ * URL or stream, which does not match what the WASM object holds.
54
+ */
55
+ export declare function wasmEngineSettingsToEngineSettings(wasmEngineSettings: WasmEngineSettings): RecursiveRequired<Omit<EngineSettings, 'model'>>;
56
+ //# sourceMappingURL=engine_settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine_settings.d.ts","sourceRoot":"","sources":["../src/engine_settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,KAAK,gBAAgB,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,cAAc,IAAI,kBAAkB,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,KAAK,SAAS,EAAC,MAAM,sBAAsB,CAAC;AAIpL,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAC,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAC9B,IAAI,CAAC,oBAAoB,EAAE,sBAAsB,CAAC;IAEpD,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,SAAS,GAAC,SAAS,GAAC,gBAAgB,CAAC;IACrD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,GAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oBAAoB,CAAC,EAAE,mBAAmB,CAAC;CAC5C;AAED;;GAEG;AACH,wBAAgB,wCAAwC,CACpD,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,cAAc,EACtE,OAAO,EAAE,OAAO,EAAE,IAAI,8CAAmC,GAAG,IAAI,CA4CnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,kCAAkC,CAC9C,kBAAkB,EAAE,kBAAkB,GACtC,iBAAiB,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAuCnD"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Copyright 2026 The ODML Authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { getGlobalLiteRtLm } from './global_litertlm';
17
+ import { Backend } from './wasm_binding_types';
18
+ import { consumeEmscriptenVectorToArray, fillEmscriptenVector } from './wasm_utils';
19
+ /**
20
+ * Fills a WasmEngineSettings with the values from a EngineSettings.
21
+ */
22
+ export function fillWasmEngineSettingsFromEngineSettings(wasmEngineSettings, engineSettings, backend, wasm = getGlobalLiteRtLm().liteRtLmWasm) {
23
+ // This function only fills an existing WasmEngineSettings object because
24
+ // constructing the WasmEngineSettings object requires loading the model file,
25
+ // and that is best handled in the Engine class.
26
+ const wasmExecutorSettings = wasmEngineSettings.getMutableMainExecutorSettings();
27
+ wasmExecutorSettings.setCacheDir(':nocache'); // Not supported in JS.
28
+ if (engineSettings.mainExecutorSettings) {
29
+ const mainExecutorSettings = engineSettings.mainExecutorSettings;
30
+ if (mainExecutorSettings.maxNumTokens !== undefined) {
31
+ wasmExecutorSettings.setMaxNumTokens(mainExecutorSettings.maxNumTokens);
32
+ }
33
+ if (mainExecutorSettings.samplerBackend !== undefined) {
34
+ wasmExecutorSettings.setSamplerBackend({ value: mainExecutorSettings.samplerBackend });
35
+ }
36
+ if (mainExecutorSettings.backendConfig !== undefined) {
37
+ const backendConfig = mainExecutorSettings.backendConfig;
38
+ if (backend === Backend.CPU) {
39
+ wasmExecutorSettings.setBackendConfigCpu(backendConfig);
40
+ }
41
+ else if (backend === Backend.GPU) {
42
+ wasmExecutorSettings.setBackendConfigGpu(backendConfig);
43
+ }
44
+ else if (backend === Backend.GPU_ARTISAN) {
45
+ const gpuArtisanConfig = backendConfig;
46
+ const loraRanksVec = new wasm.VectorUint32();
47
+ fillEmscriptenVector(gpuArtisanConfig.supported_lora_ranks, loraRanksVec);
48
+ const wasmGpuArtisanConfig = {
49
+ ...gpuArtisanConfig,
50
+ supported_lora_ranks: loraRanksVec,
51
+ };
52
+ wasmExecutorSettings.setBackendConfigGpuArtisan(wasmGpuArtisanConfig);
53
+ loraRanksVec.delete();
54
+ }
55
+ }
56
+ if (mainExecutorSettings.advancedSettings !== undefined) {
57
+ const defaultAdv = wasmExecutorSettings.getAdvancedSettings();
58
+ const newAdv = { ...defaultAdv, ...mainExecutorSettings.advancedSettings };
59
+ wasmExecutorSettings.setAdvancedSettings(newAdv);
60
+ }
61
+ }
62
+ }
63
+ /**
64
+ * Converts a WasmEngineSettings to a EngineSettings.
65
+ *
66
+ * Fields are populated with the WASM object's values, which may be default
67
+ * values if they were not set.
68
+ *
69
+ * The returned value omits the `model` field since its TS representation is a
70
+ * URL or stream, which does not match what the WASM object holds.
71
+ */
72
+ export function wasmEngineSettingsToEngineSettings(wasmEngineSettings) {
73
+ const wasmExecutorSettings = wasmEngineSettings.getMutableMainExecutorSettings();
74
+ let backendConfig;
75
+ let backend;
76
+ try {
77
+ // This isn't ideal, but there's no way to get what backend config is set.
78
+ backendConfig = wasmExecutorSettings.getBackendConfigCpu();
79
+ backend = Backend.CPU;
80
+ }
81
+ catch (e) {
82
+ try {
83
+ backendConfig = wasmExecutorSettings.getBackendConfigGpu();
84
+ backend = Backend.GPU;
85
+ }
86
+ catch (e) {
87
+ try {
88
+ const wasmGpuArtisanConfig = wasmExecutorSettings.getBackendConfigGpuArtisan();
89
+ backendConfig = {
90
+ ...wasmGpuArtisanConfig,
91
+ supported_lora_ranks: consumeEmscriptenVectorToArray(wasmGpuArtisanConfig.supported_lora_ranks),
92
+ };
93
+ backend = Backend.GPU_ARTISAN;
94
+ }
95
+ catch (e) {
96
+ throw new Error('Unsupported backend config');
97
+ }
98
+ }
99
+ }
100
+ return {
101
+ backend,
102
+ mainExecutorSettings: {
103
+ maxNumTokens: wasmExecutorSettings.getMaxNumTokens(),
104
+ samplerBackend: wasmExecutorSettings.getSamplerBackend().value,
105
+ backendConfig,
106
+ advancedSettings: wasmExecutorSettings.getAdvancedSettings(),
107
+ },
108
+ };
109
+ }
110
+ //# sourceMappingURL=engine_settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine_settings.js","sourceRoot":"","sources":["../src/engine_settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAwB,OAAO,EAAiH,MAAM,sBAAsB,CAAC;AACpL,OAAO,EAAC,8BAA8B,EAAE,oBAAoB,EAAC,MAAM,cAAc,CAAC;AAiClF;;GAEG;AACH,MAAM,UAAU,wCAAwC,CACpD,kBAAsC,EAAE,cAA8B,EACtE,OAAgB,EAAE,IAAI,GAAG,iBAAiB,EAAE,CAAC,YAAY;IAC3D,yEAAyE;IACzE,8EAA8E;IAC9E,gDAAgD;IAEhD,MAAM,oBAAoB,GACtB,kBAAkB,CAAC,8BAA8B,EAAE,CAAC;IACxD,oBAAoB,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAE,uBAAuB;IAEtE,IAAI,cAAc,CAAC,oBAAoB,EAAE,CAAC;QACxC,MAAM,oBAAoB,GAAG,cAAc,CAAC,oBAAoB,CAAC;QAEjE,IAAI,oBAAoB,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACpD,oBAAoB,CAAC,eAAe,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;QAC1E,CAAC;QACD,IAAI,oBAAoB,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;YACtD,oBAAoB,CAAC,iBAAiB,CAClC,EAAC,KAAK,EAAE,oBAAoB,CAAC,cAAc,EAAC,CAAC,CAAC;QACpD,CAAC;QACD,IAAI,oBAAoB,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YACrD,MAAM,aAAa,GAAG,oBAAoB,CAAC,aAAa,CAAC;YACzD,IAAI,OAAO,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC;gBAC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AC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC;YACH,aAAa,GAAG,oBAAoB,CAAC,mBAAmB,EAAE,CAAC;YAC3D,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;QACxB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC;gBACH,MAAM,oBAAoB,GACtB,oBAAoB,CAAC,0BAA0B,EAAE,CAAC;gBACtD,aAAa,GAAG;oBACd,GAAG,oBAAoB;oBACvB,oBAAoB,EAAE,8BAA8B,CAChD,oBAAoB,CAAC,oBAAoB,CAAC;iBAC/C,CAAC;gBACF,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;YAChC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO;QACP,oBAAoB,EAAE;YACpB,YAAY,EAAE,oBAAoB,CAAC,eAAe,EAAE;YACpD,cAAc,EAAE,oBAAoB,CAAC,iBAAiB,EAAE,CAAC,KAAK;YAC9D,aAAa;YACb,gBAAgB,EAAE,oBAAoB,CAAC,mBAAmB,EAAE;SAC7D;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Copyright 2025 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { LiteRtLm } from './litertlm_web';
17
+ /**
18
+ * An error thrown when LiteRT-LM is not loaded.
19
+ */
20
+ export declare class LiteRtLmNotLoadedError extends Error {
21
+ constructor();
22
+ }
23
+ /**
24
+ * Get the global LiteRT-LM instance.
25
+ *
26
+ * In most cases, you can call the functions exported by this module that wrap
27
+ * the global LiteRT-LM instance instead.
28
+ */
29
+ export declare function getGlobalLiteRtLm(): LiteRtLm;
30
+ /**
31
+ * Check if the global LiteRT-LM instance is defined.
32
+ *
33
+ * Only exposed internally.
34
+ */
35
+ export declare function hasGlobalLiteRtLm(): boolean;
36
+ /**
37
+ * Set the global LiteRT-LM instance.
38
+ *
39
+ * Only exposed internally.
40
+ */
41
+ export declare function setGlobalLiteRtLm(LiteRtLm: LiteRtLm | undefined): void;
42
+ /**
43
+ * Resolves when the currently loading / loaded LiteRT-LM instance is loaded.
44
+ *
45
+ * If `loadLiteRtLm()` has been called, this function returns a promise that
46
+ * resolves when the LiteRT-LM instance is loaded. Otherwise, it returns
47
+ * undefined.
48
+ *
49
+ * If LiteRT-LM has failed to load before this function is called or has been
50
+ * manually unloaded with `unloadLiteRtLm()`, this function also returns
51
+ * undefined.
52
+ */
53
+ export declare function getGlobalLiteRtLmPromise(): Promise<LiteRtLm> | undefined;
54
+ /**
55
+ * Check if the global LiteRT-LM instance promise is defined.
56
+ *
57
+ * Only exposed internally.
58
+ */
59
+ export declare function hasGlobalLiteRtLmPromise(): boolean;
60
+ /**
61
+ * Set the global LiteRT-LM instance promise.
62
+ *
63
+ * Only exposed internally.
64
+ */
65
+ export declare function setGlobalLiteRtLmPromise(promise: Promise<LiteRtLm> | undefined): void;
66
+ //# sourceMappingURL=global_litertlm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global_litertlm.d.ts","sourceRoot":"","sources":["../src/global_litertlm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAE7C;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;;CAMhD;AAKD;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,QAAQ,CAK5C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAC,SAAS,QAE7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAC,SAAS,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,OAAO,CAElD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAC,SAAS,QAE5E"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Copyright 2025 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * An error thrown when LiteRT-LM is not loaded.
18
+ */
19
+ export class LiteRtLmNotLoadedError extends Error {
20
+ constructor() {
21
+ super('LiteRT-LM is not initialized yet. Please call loadLiteRtLm() and wait for its ' +
22
+ 'promise to resolve to load the LiteRT-LM WASM module.');
23
+ }
24
+ }
25
+ let globalLiteRtLm = undefined;
26
+ let globalLiteRtLmPromise = undefined;
27
+ /**
28
+ * Get the global LiteRT-LM instance.
29
+ *
30
+ * In most cases, you can call the functions exported by this module that wrap
31
+ * the global LiteRT-LM instance instead.
32
+ */
33
+ export function getGlobalLiteRtLm() {
34
+ if (!globalLiteRtLm) {
35
+ throw new LiteRtLmNotLoadedError();
36
+ }
37
+ return globalLiteRtLm;
38
+ }
39
+ /**
40
+ * Check if the global LiteRT-LM instance is defined.
41
+ *
42
+ * Only exposed internally.
43
+ */
44
+ export function hasGlobalLiteRtLm() {
45
+ return Boolean(globalLiteRtLm);
46
+ }
47
+ /**
48
+ * Set the global LiteRT-LM instance.
49
+ *
50
+ * Only exposed internally.
51
+ */
52
+ export function setGlobalLiteRtLm(LiteRtLm) {
53
+ globalLiteRtLm = LiteRtLm;
54
+ }
55
+ /**
56
+ * Resolves when the currently loading / loaded LiteRT-LM instance is loaded.
57
+ *
58
+ * If `loadLiteRtLm()` has been called, this function returns a promise that
59
+ * resolves when the LiteRT-LM instance is loaded. Otherwise, it returns
60
+ * undefined.
61
+ *
62
+ * If LiteRT-LM has failed to load before this function is called or has been
63
+ * manually unloaded with `unloadLiteRtLm()`, this function also returns
64
+ * undefined.
65
+ */
66
+ export function getGlobalLiteRtLmPromise() {
67
+ return globalLiteRtLmPromise;
68
+ }
69
+ /**
70
+ * Check if the global LiteRT-LM instance promise is defined.
71
+ *
72
+ * Only exposed internally.
73
+ */
74
+ export function hasGlobalLiteRtLmPromise() {
75
+ return Boolean(globalLiteRtLmPromise);
76
+ }
77
+ /**
78
+ * Set the global LiteRT-LM instance promise.
79
+ *
80
+ * Only exposed internally.
81
+ */
82
+ export function setGlobalLiteRtLmPromise(promise) {
83
+ globalLiteRtLmPromise = promise;
84
+ }
85
+ //# sourceMappingURL=global_litertlm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global_litertlm.js","sourceRoot":"","sources":["../src/global_litertlm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C;QACE,KAAK,CACD,gFAAgF;YAChF,uDAAuD,CAAC,CAAC;IAC/D,CAAC;CACF;AAED,IAAI,cAAc,GAAuB,SAAS,CAAC;AACnD,IAAI,qBAAqB,GAAgC,SAAS,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,sBAAsB,EAAE,CAAC;IACrC,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,OAAO,CAAC,cAAc,CAAC,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAA4B;IAC5D,cAAc,GAAG,QAAQ,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB;IACtC,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB;IACtC,OAAO,OAAO,CAAC,qBAAqB,CAAC,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAoC;IAC3E,qBAAqB,GAAG,OAAO,CAAC;AAClC,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright 2026 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export * from './litertlm_web';
17
+ export * from './global_litertlm';
18
+ export * from './load_litertlm';
19
+ export { Backend } from './wasm_binding_types';
20
+ export * from './engine_settings';
21
+ export * from './engine';
22
+ export * from './session';
23
+ export * from './conversation';
24
+ export * from './session_config';
25
+ export * from './conversation_config';
26
+ export * as Wasm from './wasm_binding_types';
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AAGtC,OAAO,KAAK,IAAI,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright 2026 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export * from './litertlm_web';
17
+ export * from './global_litertlm';
18
+ export * from './load_litertlm';
19
+ export { Backend } from './wasm_binding_types';
20
+ export * from './engine_settings';
21
+ export * from './engine';
22
+ export * from './session';
23
+ export * from './conversation';
24
+ export * from './session_config';
25
+ export * from './conversation_config';
26
+ export * as Wasm from './wasm_binding_types';
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AAGtC,OAAO,KAAK,IAAI,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright 2026 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { WasmModule } from '@litertjs/wasm-utils';
17
+ import { LiteRtLmWasm } from './wasm_binding_types';
18
+ /**
19
+ * Set up the default WebGPU device for the LiteRT LM Wasm module.
20
+ */
21
+ export declare function setupDefaultWebGpuDevice(): Promise<void>;
22
+ /**
23
+ * Run LiteRt LM models in the browser.
24
+ */
25
+ export declare class LiteRtLm {
26
+ readonly liteRtLmWasm: LiteRtLmWasm;
27
+ static DEFAULT_WASM_PATH: string;
28
+ constructor(wasmModule: WasmModule);
29
+ setupDefaultWebGpuDevice(): Promise<void>;
30
+ delete(): void;
31
+ }
32
+ //# sourceMappingURL=litertlm_web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"litertlm_web.d.ts","sourceRoot":"","sources":["../src/litertlm_web.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAIhD,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAElD;;GAEG;AACH,wBAAsB,wBAAwB,kBAE7C;AAED;;GAEG;AACH,qBAAa,QAAQ;IACnB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,MAAM,CAAC,iBAAiB,SAA8D;gBAE1E,UAAU,EAAE,UAAU;IAK5B,wBAAwB;IAQ9B,MAAM;CAGP"}