@litert-lm/core 0.16.0 → 0.17.1

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 (118) hide show
  1. package/README.md +164 -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 +51 -0
  7. package/dist/conversation.d.ts.map +1 -0
  8. package/dist/conversation.js +171 -0
  9. package/dist/conversation.js.map +1 -0
  10. package/dist/conversation_config.d.ts +157 -0
  11. package/dist/conversation_config.d.ts.map +1 -0
  12. package/dist/conversation_config.js +42 -0
  13. package/dist/conversation_config.js.map +1 -0
  14. package/dist/embedding_engine.d.ts +51 -0
  15. package/dist/embedding_engine.d.ts.map +1 -0
  16. package/dist/embedding_engine.js +198 -0
  17. package/dist/embedding_engine.js.map +1 -0
  18. package/dist/embedding_engine_settings.d.ts +39 -0
  19. package/dist/embedding_engine_settings.d.ts.map +1 -0
  20. package/dist/embedding_engine_settings.js +35 -0
  21. package/dist/embedding_engine_settings.js.map +1 -0
  22. package/dist/engine.d.ts +37 -0
  23. package/dist/engine.d.ts.map +1 -0
  24. package/dist/engine.js +203 -0
  25. package/dist/engine.js.map +1 -0
  26. package/dist/engine_settings.d.ts +57 -0
  27. package/dist/engine_settings.d.ts.map +1 -0
  28. package/dist/engine_settings.js +114 -0
  29. package/dist/engine_settings.js.map +1 -0
  30. package/dist/global_litertlm.d.ts +66 -0
  31. package/dist/global_litertlm.d.ts.map +1 -0
  32. package/dist/global_litertlm.js +85 -0
  33. package/dist/global_litertlm.js.map +1 -0
  34. package/dist/index.d.ts +33 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +33 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/litertlm_web.d.ts +32 -0
  39. package/dist/litertlm_web.d.ts.map +1 -0
  40. package/dist/litertlm_web.js +75 -0
  41. package/dist/litertlm_web.js.map +1 -0
  42. package/dist/load.d.ts +28 -0
  43. package/dist/load.d.ts.map +1 -0
  44. package/dist/load.js +50 -0
  45. package/dist/load.js.map +1 -0
  46. package/dist/load_litertlm.d.ts +58 -0
  47. package/dist/load_litertlm.d.ts.map +1 -0
  48. package/dist/load_litertlm.js +87 -0
  49. package/dist/load_litertlm.js.map +1 -0
  50. package/dist/mutex.d.ts +45 -0
  51. package/dist/mutex.d.ts.map +1 -0
  52. package/dist/mutex.js +62 -0
  53. package/dist/mutex.js.map +1 -0
  54. package/dist/orchestration/auto_tool_chat.d.ts +82 -0
  55. package/dist/orchestration/auto_tool_chat.d.ts.map +1 -0
  56. package/dist/orchestration/auto_tool_chat.js +304 -0
  57. package/dist/orchestration/auto_tool_chat.js.map +1 -0
  58. package/dist/orchestration/chat_interface.d.ts +30 -0
  59. package/dist/orchestration/chat_interface.d.ts.map +1 -0
  60. package/dist/orchestration/chat_interface.js +17 -0
  61. package/dist/orchestration/chat_interface.js.map +1 -0
  62. package/dist/orchestration/webmcp_tool.d.ts +41 -0
  63. package/dist/orchestration/webmcp_tool.d.ts.map +1 -0
  64. package/dist/orchestration/webmcp_tool.js +32 -0
  65. package/dist/orchestration/webmcp_tool.js.map +1 -0
  66. package/dist/readable_stream_data_stream_wrapper.d.ts +44 -0
  67. package/dist/readable_stream_data_stream_wrapper.d.ts.map +1 -0
  68. package/dist/readable_stream_data_stream_wrapper.js +315 -0
  69. package/dist/readable_stream_data_stream_wrapper.js.map +1 -0
  70. package/dist/session.d.ts +51 -0
  71. package/dist/session.d.ts.map +1 -0
  72. package/dist/session.js +107 -0
  73. package/dist/session.js.map +1 -0
  74. package/dist/session_config.d.ts +60 -0
  75. package/dist/session_config.d.ts.map +1 -0
  76. package/dist/session_config.js +109 -0
  77. package/dist/session_config.js.map +1 -0
  78. package/dist/stream_utils.d.ts +25 -0
  79. package/dist/stream_utils.d.ts.map +1 -0
  80. package/dist/stream_utils.js +95 -0
  81. package/dist/stream_utils.js.map +1 -0
  82. package/dist/testing/fakes.d.ts +67 -0
  83. package/dist/testing/fakes.d.ts.map +1 -0
  84. package/dist/testing/fakes.js +125 -0
  85. package/dist/testing/fakes.js.map +1 -0
  86. package/dist/testing/index.d.ts +17 -0
  87. package/dist/testing/index.d.ts.map +1 -0
  88. package/dist/testing/index.js +17 -0
  89. package/dist/testing/index.js.map +1 -0
  90. package/dist/types.d.ts +42 -0
  91. package/dist/types.d.ts.map +1 -0
  92. package/dist/types.js +17 -0
  93. package/dist/types.js.map +1 -0
  94. package/dist/url_path_utils.d.ts +28 -0
  95. package/dist/url_path_utils.d.ts.map +1 -0
  96. package/dist/url_path_utils.js +34 -0
  97. package/dist/url_path_utils.js.map +1 -0
  98. package/dist/wasm_binding_types.d.ts +473 -0
  99. package/dist/wasm_binding_types.d.ts.map +1 -0
  100. package/dist/wasm_binding_types.js +47 -0
  101. package/dist/wasm_binding_types.js.map +1 -0
  102. package/dist/wasm_feature_detect.d.ts +45 -0
  103. package/dist/wasm_feature_detect.d.ts.map +1 -0
  104. package/dist/wasm_feature_detect.js +139 -0
  105. package/dist/wasm_feature_detect.js.map +1 -0
  106. package/dist/wasm_utils.d.ts +30 -0
  107. package/dist/wasm_utils.d.ts.map +1 -0
  108. package/dist/wasm_utils.js +41 -0
  109. package/dist/wasm_utils.js.map +1 -0
  110. package/package.json +3 -2
  111. package/wasm/litertlm_wasm_asyncify_internal.js +8749 -0
  112. package/wasm/litertlm_wasm_asyncify_internal.wasm +0 -0
  113. package/wasm/litertlm_wasm_compat_asyncify_internal.js +8758 -0
  114. package/wasm/litertlm_wasm_compat_asyncify_internal.wasm +0 -0
  115. package/wasm/litertlm_wasm_compat_internal.js +8543 -0
  116. package/wasm/litertlm_wasm_compat_internal.wasm +0 -0
  117. package/wasm/litertlm_wasm_internal.js +8532 -0
  118. package/wasm/litertlm_wasm_internal.wasm +0 -0
@@ -0,0 +1,57 @@
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.js';
17
+ import { type AdvancedSettings, Backend, type CpuConfig, EngineSettings as WasmEngineSettings, GpuArtisanConfig as WasmGpuArtisanConfig, type GpuConfig } from './wasm_binding_types.js';
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 | Blob | ReadableStream<Uint8Array>;
39
+ backend?: Backend;
40
+ mainExecutorSettings?: LlmExecutorSettings;
41
+ benchmarkEnabled?: boolean;
42
+ }
43
+ /**
44
+ * Fills a WasmEngineSettings with the values from a EngineSettings.
45
+ */
46
+ export declare function fillWasmEngineSettingsFromEngineSettings(wasmEngineSettings: WasmEngineSettings, engineSettings: EngineSettings, backend: Backend, wasm?: import("./wasm_binding_types.js").LiteRtLmWasm): void;
47
+ /**
48
+ * Converts a WasmEngineSettings to a EngineSettings.
49
+ *
50
+ * Fields are populated with the WASM object's values, which may be default
51
+ * values if they were not set.
52
+ *
53
+ * The returned value omits the `model` field since its TS representation is a
54
+ * URL or stream, which does not match what the WASM object holds.
55
+ */
56
+ export declare function wasmEngineSettingsToEngineSettings(wasmEngineSettings: WasmEngineSettings): RecursiveRequired<Omit<EngineSettings, 'model'>>;
57
+ //# 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,YAAY,CAAC;AAC7C,OAAO,EAAC,KAAK,gBAAgB,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,cAAc,IAAI,kBAAkB,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,KAAK,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAIvL,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,IAAI,GAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oBAAoB,CAAC,EAAE,mBAAmB,CAAC;IAC3C,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,wCAAwC,CACpD,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,cAAc,EACtE,OAAO,EAAE,OAAO,EAAE,IAAI,iDAAmC,GAAG,IAAI,CAgDnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,kCAAkC,CAC9C,kBAAkB,EAAE,kBAAkB,GACtC,iBAAiB,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAwCnD"}
@@ -0,0 +1,114 @@
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.js';
17
+ import { Backend } from './wasm_binding_types.js';
18
+ import { consumeEmscriptenVectorToArray, fillEmscriptenVector } from './wasm_utils.js';
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.benchmarkEnabled) {
29
+ wasmEngineSettings.enableBenchmark();
30
+ }
31
+ if (engineSettings.mainExecutorSettings) {
32
+ const mainExecutorSettings = engineSettings.mainExecutorSettings;
33
+ if (mainExecutorSettings.maxNumTokens !== undefined) {
34
+ wasmExecutorSettings.setMaxNumTokens(mainExecutorSettings.maxNumTokens);
35
+ }
36
+ if (mainExecutorSettings.samplerBackend !== undefined) {
37
+ wasmExecutorSettings.setSamplerBackend({ value: mainExecutorSettings.samplerBackend });
38
+ }
39
+ if (mainExecutorSettings.backendConfig !== undefined) {
40
+ const backendConfig = mainExecutorSettings.backendConfig;
41
+ if (backend === Backend.CPU) {
42
+ wasmExecutorSettings.setBackendConfigCpu(backendConfig);
43
+ }
44
+ else if (backend === Backend.GPU) {
45
+ wasmExecutorSettings.setBackendConfigGpu(backendConfig);
46
+ }
47
+ else if (backend === Backend.GPU_ARTISAN) {
48
+ const gpuArtisanConfig = backendConfig;
49
+ const loraRanksVec = new wasm.VectorUint32();
50
+ fillEmscriptenVector(gpuArtisanConfig.supported_lora_ranks, loraRanksVec);
51
+ const wasmGpuArtisanConfig = {
52
+ ...gpuArtisanConfig,
53
+ supported_lora_ranks: loraRanksVec,
54
+ };
55
+ wasmExecutorSettings.setBackendConfigGpuArtisan(wasmGpuArtisanConfig);
56
+ loraRanksVec.delete();
57
+ }
58
+ }
59
+ if (mainExecutorSettings.advancedSettings !== undefined) {
60
+ const defaultAdv = wasmExecutorSettings.getAdvancedSettings();
61
+ const newAdv = { ...defaultAdv, ...mainExecutorSettings.advancedSettings };
62
+ wasmExecutorSettings.setAdvancedSettings(newAdv);
63
+ }
64
+ }
65
+ }
66
+ /**
67
+ * Converts a WasmEngineSettings to a EngineSettings.
68
+ *
69
+ * Fields are populated with the WASM object's values, which may be default
70
+ * values if they were not set.
71
+ *
72
+ * The returned value omits the `model` field since its TS representation is a
73
+ * URL or stream, which does not match what the WASM object holds.
74
+ */
75
+ export function wasmEngineSettingsToEngineSettings(wasmEngineSettings) {
76
+ const wasmExecutorSettings = wasmEngineSettings.getMutableMainExecutorSettings();
77
+ let backendConfig;
78
+ let backend;
79
+ try {
80
+ // This isn't ideal, but there's no way to get what backend config is set.
81
+ backendConfig = wasmExecutorSettings.getBackendConfigCpu();
82
+ backend = Backend.CPU;
83
+ }
84
+ catch (e) {
85
+ try {
86
+ backendConfig = wasmExecutorSettings.getBackendConfigGpu();
87
+ backend = Backend.GPU;
88
+ }
89
+ catch (e) {
90
+ try {
91
+ const wasmGpuArtisanConfig = wasmExecutorSettings.getBackendConfigGpuArtisan();
92
+ backendConfig = {
93
+ ...wasmGpuArtisanConfig,
94
+ supported_lora_ranks: consumeEmscriptenVectorToArray(wasmGpuArtisanConfig.supported_lora_ranks),
95
+ };
96
+ backend = Backend.GPU_ARTISAN;
97
+ }
98
+ catch (e) {
99
+ throw new Error('Unsupported backend config');
100
+ }
101
+ }
102
+ }
103
+ return {
104
+ backend,
105
+ mainExecutorSettings: {
106
+ maxNumTokens: wasmExecutorSettings.getMaxNumTokens(),
107
+ samplerBackend: wasmExecutorSettings.getSamplerBackend().value,
108
+ backendConfig,
109
+ advancedSettings: wasmExecutorSettings.getAdvancedSettings(),
110
+ },
111
+ benchmarkEnabled: false,
112
+ };
113
+ }
114
+ //# 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,sBAAsB,CAAC;AAEvD,OAAO,EAAwB,OAAO,EAAiH,MAAM,yBAAyB,CAAC;AACvL,OAAO,EAAC,8BAA8B,EAAE,oBAAoB,EAAC,MAAM,iBAAiB,CAAC;AAkCrF;;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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ACP,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;QACD,gBAAgB,EAAE,KAAK;KACxB,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.js';
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,mBAAmB,CAAC;AAEhD;;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,33 @@
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.js';
17
+ export * from './global_litertlm.js';
18
+ export * from './load_litertlm.js';
19
+ export * from './orchestration/chat_interface.js';
20
+ export * from './orchestration/auto_tool_chat.js';
21
+ export * from './orchestration/webmcp_tool.js';
22
+ export { Backend } from './wasm_binding_types.js';
23
+ export * from './engine_settings.js';
24
+ export * from './engine.js';
25
+ export * from './session.js';
26
+ export * from './conversation.js';
27
+ export * from './session_config.js';
28
+ export * from './conversation_config.js';
29
+ export * from './embedding_engine_settings.js';
30
+ export * from './embedding_engine.js';
31
+ export * as Wasm from './wasm_binding_types.js';
32
+ export * from './types.js';
33
+ //# 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,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAE/C,OAAO,EAAC,OAAO,EAAC,MAAM,yBAAyB,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AAEtC,OAAO,KAAK,IAAI,MAAM,yBAAyB,CAAC;AAChD,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
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.js';
17
+ export * from './global_litertlm.js';
18
+ export * from './load_litertlm.js';
19
+ export * from './orchestration/chat_interface.js';
20
+ export * from './orchestration/auto_tool_chat.js';
21
+ export * from './orchestration/webmcp_tool.js';
22
+ export { Backend } from './wasm_binding_types.js';
23
+ export * from './engine_settings.js';
24
+ export * from './engine.js';
25
+ export * from './session.js';
26
+ export * from './conversation.js';
27
+ export * from './session_config.js';
28
+ export * from './conversation_config.js';
29
+ export * from './embedding_engine_settings.js';
30
+ export * from './embedding_engine.js';
31
+ export * as Wasm from './wasm_binding_types.js';
32
+ export * from './types.js';
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAE/C,OAAO,EAAC,OAAO,EAAC,MAAM,yBAAyB,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AAEtC,OAAO,KAAK,IAAI,MAAM,yBAAyB,CAAC;AAChD,cAAc,YAAY,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.js';
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,yBAAyB,CAAC;AAErD;;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"}
@@ -0,0 +1,75 @@
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
+ // Placeholder for internal dependency on trusted resource url
17
+ import { getGlobalLiteRtLm } from './global_litertlm.js';
18
+ /**
19
+ * Set up the default WebGPU device for the LiteRT LM Wasm module.
20
+ */
21
+ export async function setupDefaultWebGpuDevice() {
22
+ await getGlobalLiteRtLm().setupDefaultWebGpuDevice();
23
+ }
24
+ /**
25
+ * Run LiteRt LM models in the browser.
26
+ */
27
+ export class LiteRtLm {
28
+ liteRtLmWasm;
29
+ static DEFAULT_WASM_PATH = 'https://cdn.jsdelivr.net/npm/@litert-lm/core@0.17.1/wasm';
30
+ constructor(wasmModule) {
31
+ this.liteRtLmWasm = wasmModule;
32
+ this.liteRtLmWasm.setupLogging();
33
+ }
34
+ async setupDefaultWebGpuDevice() {
35
+ if (this.liteRtLmWasm.preinitializedWebGPUDevice) {
36
+ return;
37
+ }
38
+ this.liteRtLmWasm.preinitializedWebGPUDevice =
39
+ await createDefaultWebGpuDevice();
40
+ }
41
+ delete() {
42
+ // no op for now.
43
+ }
44
+ }
45
+ // TODO: b/475939320 - Use a shared implementation with LiteRT.
46
+ const DESIRED_WEBGPU_FEATURES = [
47
+ 'shader-f16',
48
+ 'subgroups',
49
+ ];
50
+ async function createDefaultWebGpuDevice() {
51
+ const adapterDescriptor = {
52
+ powerPreference: 'high-performance',
53
+ };
54
+ const adapter = await navigator.gpu.requestAdapter(adapterDescriptor);
55
+ if (!adapter) {
56
+ throw new Error('No GPU adapter found.');
57
+ }
58
+ const requiredLimits = {
59
+ maxBufferSize: adapter.limits.maxBufferSize,
60
+ maxStorageBufferBindingSize: adapter.limits.maxStorageBufferBindingSize,
61
+ maxStorageBuffersPerShaderStage: adapter.limits.maxStorageBuffersPerShaderStage,
62
+ maxTextureDimension2D: adapter.limits.maxTextureDimension2D,
63
+ };
64
+ const requiredFeatures = [];
65
+ for (const feature of DESIRED_WEBGPU_FEATURES) {
66
+ if (adapter.features.has(feature)) {
67
+ requiredFeatures.push(feature);
68
+ }
69
+ }
70
+ return await adapter.requestDevice({
71
+ requiredFeatures,
72
+ requiredLimits,
73
+ });
74
+ }
75
+ //# sourceMappingURL=litertlm_web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"litertlm_web.js","sourceRoot":"","sources":["../src/litertlm_web.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,8DAA8D;AAE9D,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAGvD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB;IAC5C,MAAM,iBAAiB,EAAE,CAAC,wBAAwB,EAAE,CAAC;AACvD,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,QAAQ;IACV,YAAY,CAAe;IACpC,MAAM,CAAC,iBAAiB,GAAG,0DAA0D,CAAC;IAEtF,YAAY,UAAsB;QAChC,IAAI,CAAC,YAAY,GAAG,UAA0B,CAAC;QAC/C,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAA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* 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 { LiteRtLm } from './litertlm_web.js';
17
+ import { UrlPath } from './url_path_utils.js';
18
+ /**
19
+ * Options for loading LiteRT-LM's Wasm module.
20
+ **/
21
+ export interface LoadOptions {
22
+ }
23
+ /**
24
+ * Load the LiteRtLm library with WASM from the given URL. Does not set the
25
+ * global LiteRtLm instance.
26
+ */
27
+ export declare function load(path: UrlPath, options?: LoadOptions): Promise<LiteRtLm>;
28
+ //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAkC,OAAO,EAAC,MAAM,qBAAqB,CAAC;AAS7E;;IAEI;AACJ,MAAM,WAAW,WAAW;CAAG;AAE/B;;;GAGG;AACH,wBAAsB,IAAI,CACtB,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsB3D"}
package/dist/load.js ADDED
@@ -0,0 +1,50 @@
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 { createWasmLib } from '@litertjs/wasm-utils';
17
+ import { LiteRtLm } from './litertlm_web.js';
18
+ import { appendPathSegment, pathToString } from './url_path_utils.js';
19
+ import { supportsFeature } from './wasm_feature_detect.js';
20
+ const WASM_JS_FILE_NAME = 'litertlm_wasm_internal.js';
21
+ const WASM_JS_COMPAT_FILE_NAME = 'litertlm_wasm_compat_internal.js';
22
+ const WASM_JS_ASYNCIFY_FILE_NAME = 'litertlm_wasm_asyncify_internal.js';
23
+ const WASM_JS_COMPAT_ASYNCIFY_FILE_NAME = 'litertlm_wasm_compat_asyncify_internal.js';
24
+ /**
25
+ * Load the LiteRtLm library with WASM from the given URL. Does not set the
26
+ * global LiteRtLm instance.
27
+ */
28
+ export async function load(path, options) {
29
+ const pathString = pathToString(path);
30
+ const relaxedSimd = await supportsFeature('relaxedSimd');
31
+ const jspi = await supportsFeature('jspi');
32
+ let fileName = '';
33
+ if (relaxedSimd) {
34
+ fileName = jspi ? WASM_JS_FILE_NAME : WASM_JS_ASYNCIFY_FILE_NAME;
35
+ }
36
+ else {
37
+ fileName =
38
+ jspi ? WASM_JS_COMPAT_FILE_NAME : WASM_JS_COMPAT_ASYNCIFY_FILE_NAME;
39
+ }
40
+ let jsFilePath = path;
41
+ if (pathString.endsWith('.wasm')) {
42
+ throw new Error('Please load the `.js` file corresponding to the `.wasm` file, or ' +
43
+ 'load the directory containing it.');
44
+ }
45
+ else if (!pathString.endsWith('.js')) {
46
+ jsFilePath = appendPathSegment(path, fileName);
47
+ }
48
+ return createWasmLib(LiteRtLm, jsFilePath);
49
+ }
50
+ //# sourceMappingURL=load.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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