@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/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # LiteRT-LM JS API
2
+
3
+ The JavaScript API of LiteRT-LM for running LLMs in the browser. This is an
4
+ early preview that supports text-in / text-out running in WebGPU.
5
+ [LiteRT-LM](https://www.google.com/url?sa=D&q=https%3A%2F%2Fai.google.dev%2Fedge%2Flitert-lm%2F)
6
+ is a production-ready, open-source inference framework designed to deliver
7
+ high-performance, cross-platform LLM deployments on edge devices.
8
+
9
+ - **Documentation**: [https://ai.google.dev/edge/litert-lm/js](https://ai.google.dev/edge/litert-lm/js)
10
+ - **GitHub**: [https://github.com/google-ai-edge/LiteRT-LM](https://github.com/google-ai-edge/LiteRT-LM)
11
+
12
+ ## Introduction
13
+
14
+ Here is a sample REPL chat app built with the JavaScript API:
15
+
16
+ ```ts
17
+ <div id="out" style="white-space: pre-wrap; font-family: monospace;"></div>
18
+ <input id="in" onkeydown="if(event.key === 'Enter') repl(this)">
19
+
20
+ <script type="module">
21
+ import { Engine } from 'https://cdn.jsdelivr.net/npm/@litert-lm/core/+esm';
22
+ const engine = await Engine.create({
23
+ model: 'https://huggingface.co/litert-community/gemma-4-E2B-it-litert-lm/resolve/main/gemma-4-E2B-it-web.litertlm'
24
+ });
25
+ const chat = await engine.createConversation();
26
+
27
+ window.repl = async (el) => {
28
+ const text = el.value;
29
+ el.value = ''; // Clear immediately
30
+ out.append(`\n>>> ${text}\nAI: `);
31
+
32
+ for await (const chunk of chat.sendMessageStreaming(text)) {
33
+ out.append(chunk.content[0].text);
34
+ }
35
+ };
36
+ </script>
37
+ ```
38
+
39
+ ## Getting Started
40
+
41
+ LiteRT-LM is available as an npm package. You can install the latest version
42
+ from npm or directly import it from a CDN:
43
+
44
+ ```shell
45
+ # From npm
46
+ npm i --save @litert-lm/core
47
+
48
+ # From a CDN (in your JavaScript file)
49
+ import * as litertlm from 'https://cdn.jsdelivr.net/npm/@litert-lm/core/+esm';
50
+ ```
51
+
52
+ ### Initialize the Engine
53
+
54
+ The `Engine` is the entry point to the API. It handles model loading, session
55
+ creation, and resource management. Remember to `delete` the engine to release
56
+ resources when the model is no longer needed.
57
+
58
+ **Note:** Initializing the engine can take several seconds to load the model.
59
+
60
+ ```ts
61
+ import {Engine, EngineSettings} from '@litert-lm/core';
62
+
63
+ const engineSettings = {
64
+ model: 'url/path/to/model.litertlm', // or a ReadableStream, or a Blob
65
+ } satisfies EngineSettings;
66
+
67
+ const engine = await Engine.create(engineSettings);
68
+
69
+ // ... Use the engine to create a conversation ...
70
+
71
+ // Delete the engine when done.
72
+ await engine.delete();
73
+ ```
74
+
75
+ ### Create a Conversation
76
+
77
+ Once the engine is initialized, create a `Conversation` instance. You can
78
+ provide a `ConversationConfig` to customize its behavior.
79
+
80
+ ```ts
81
+ const conversation = await engine.createConversation({
82
+ preface: {
83
+ messages: [
84
+ {role: 'system', content: 'You are a helpful assistant'}
85
+ ]
86
+ }
87
+ });
88
+
89
+ conversation.sendMessage({
90
+ role: 'user',
91
+ content: 'Write a poem',
92
+ });
93
+ ```
94
+
95
+ ### Send Messages
96
+
97
+ You can send messages with or without streaming.
98
+
99
+ #### Non-Streaming Example
100
+
101
+ ```ts
102
+ // Simple string input
103
+ let response = await conversation.sendMessage("What is the capital of France?");
104
+ console.log(response.content[0].text);
105
+
106
+ // Or with full message structure
107
+ response = await conversation.sendMessage({role: 'user', content: '...'});
108
+ ```
109
+
110
+ #### Streaming Example
111
+
112
+ ```ts
113
+ // sendMessageStreaming returns a ReadableStream of response chunks
114
+ const stream = conversation.sendMessageStreaming('Tell me a long story.');
115
+
116
+ for await (const chunk of stream) {
117
+ // Chunks are Records containing pieces of the response
118
+ for (const item of chunk.content) {
119
+ if (item.type === 'text') {
120
+ console.log(item.text);
121
+ }
122
+ }
123
+ }
124
+ ```
125
+
126
+ #### Cancel Generation
127
+
128
+ You can cancel an ongoing generation explicitly by calling `cancel()` on the
129
+ `Conversation` instance:
130
+
131
+ ```ts
132
+ // Cancel any ongoing generation
133
+ conversation.cancel();
134
+ ```
135
+
136
+ If you are streaming the response, exiting the `for await...of` loop early (such
137
+ as with `break`) will also automatically cancel the ongoing generation:
138
+
139
+ ```ts
140
+ for await (const chunk of stream) {
141
+ if (shouldStop()) {
142
+ break; // Cancels the stream and underlying generation
143
+ }
144
+ }
145
+ ```
@@ -0,0 +1,25 @@
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
+ /**
17
+ * A utility class for managing a set of callbacks that can be called to clean
18
+ * up resources.
19
+ */
20
+ export declare class Cleanup {
21
+ private readonly callbacks;
22
+ add(callback: () => void): () => void;
23
+ run(): void;
24
+ }
25
+ //# sourceMappingURL=cleanup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../src/cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;GAGG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IAExD,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IASrC,GAAG,IAAI,IAAI;CAMZ"}
@@ -0,0 +1,36 @@
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
+ /**
17
+ * A utility class for managing a set of callbacks that can be called to clean
18
+ * up resources.
19
+ */
20
+ export class Cleanup {
21
+ callbacks = new Set();
22
+ add(callback) {
23
+ this.callbacks.add(callback);
24
+ return () => {
25
+ this.callbacks.delete(callback);
26
+ callback();
27
+ };
28
+ }
29
+ run() {
30
+ for (const callback of this.callbacks) {
31
+ callback();
32
+ }
33
+ this.callbacks.clear();
34
+ }
35
+ }
36
+ //# sourceMappingURL=cleanup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../src/cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;GAGG;AACH,MAAM,OAAO,OAAO;IACD,SAAS,GAAoB,IAAI,GAAG,EAAE,CAAC;IAExD,GAAG,CAAC,QAAoB;QACtB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAChC,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC;IACJ,CAAC;IAGD,GAAG;QACD,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,QAAQ,EAAE,CAAC;QACb,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,43 @@
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 { Message, MessageLike } from './conversation_config';
17
+ import { Mutex } from './mutex';
18
+ import { Conversation as WasmConversation, Engine as WasmEngine } from './wasm_binding_types';
19
+ /**
20
+ * LiteRT-LM Conversation
21
+ */
22
+ export declare class Conversation {
23
+ private readonly conversation;
24
+ private readonly engine;
25
+ private readonly mutexes;
26
+ private isBusy;
27
+ constructor(conversation: WasmConversation, engine: WasmEngine, mutexes: {
28
+ executor: Mutex;
29
+ });
30
+ sendMessage(message: MessageLike | MessageLike[]): Promise<Message>;
31
+ /**
32
+ * Sends a message to the LLM and returns a ReadableStream that yields
33
+ * message chunks as they are generated.
34
+ */
35
+ sendMessageStreaming(message: MessageLike | MessageLike[]): ReadableStream<Message>;
36
+ /**
37
+ * Sends a signal to cancel any current generation.
38
+ */
39
+ cancel(): void;
40
+ getHistory(): Message[];
41
+ delete(): Promise<void>;
42
+ }
43
+ //# sourceMappingURL=conversation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAC,OAAO,EAAE,WAAW,EAAC,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,YAAY,IAAI,gBAAgB,EAAE,MAAM,IAAI,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAK5F;;GAEG;AACH,qBAAa,YAAY;IAInB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL5B,OAAO,CAAC,MAAM,CAAS;gBAGF,YAAY,EAAE,gBAAgB,EAC9B,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE;QAAC,QAAQ,EAAE,KAAK,CAAA;KAAC;IAEzC,WAAW,CAAC,OAAO,EAAE,WAAW,GAAC,WAAW,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAgBvE;;;OAGG;IACH,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAC,WAAW,EAAE,GACnD,cAAc,CAAC,OAAO,CAAC;IAkE3B;;OAEG;IACH,MAAM;IAIN,UAAU,IAAI,OAAO,EAAE;IAQjB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAK9B"}
@@ -0,0 +1,153 @@
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
+ const BUSY_MESSAGE = 'Conversation is busy. A generation is already in progress.';
17
+ /**
18
+ * LiteRT-LM Conversation
19
+ */
20
+ export class Conversation {
21
+ conversation;
22
+ engine;
23
+ mutexes;
24
+ isBusy = false;
25
+ constructor(conversation, engine, mutexes) {
26
+ this.conversation = conversation;
27
+ this.engine = engine;
28
+ this.mutexes = mutexes;
29
+ }
30
+ async sendMessage(message) {
31
+ if (this.isBusy) {
32
+ throw new Error(BUSY_MESSAGE);
33
+ }
34
+ this.isBusy = true;
35
+ try {
36
+ return await this.mutexes.executor.acquireAndRun(async () => {
37
+ const jsonStr = messageToJsonString(message);
38
+ const resultStr = await this.conversation.sendMessage(jsonStr);
39
+ return JSON.parse(resultStr);
40
+ });
41
+ }
42
+ finally {
43
+ this.isBusy = false;
44
+ }
45
+ }
46
+ /**
47
+ * Sends a message to the LLM and returns a ReadableStream that yields
48
+ * message chunks as they are generated.
49
+ */
50
+ sendMessageStreaming(message) {
51
+ if (this.isBusy) {
52
+ throw new Error(BUSY_MESSAGE);
53
+ }
54
+ this.isBusy = true;
55
+ let isCancelled = false;
56
+ const jsonStr = messageToJsonString(message);
57
+ return new ReadableStream({
58
+ start: (controller) => {
59
+ try {
60
+ this.conversation
61
+ .sendMessageAsync(jsonStr, (chunk, isDone, error) => {
62
+ if (isCancelled)
63
+ return;
64
+ if (error) {
65
+ this.isBusy = false;
66
+ controller.error(new Error(error));
67
+ return;
68
+ }
69
+ if (chunk) {
70
+ try {
71
+ controller.enqueue(JSON.parse(chunk));
72
+ }
73
+ catch (e) {
74
+ this.isBusy = false;
75
+ controller.error(e);
76
+ }
77
+ }
78
+ if (isDone) {
79
+ this.isBusy = false;
80
+ controller.close();
81
+ }
82
+ })
83
+ .catch((e) => {
84
+ if (isCancelled)
85
+ return;
86
+ this.isBusy = false;
87
+ controller.error(e);
88
+ });
89
+ // Since we're using the synchronus execution manager in C++, which
90
+ // lazily executes tasks, we must call waitUntilDone to start the
91
+ // execution.
92
+ const runWait = async () => {
93
+ await this.mutexes.executor.acquireAndRun(async () => {
94
+ await this.engine.waitUntilDone();
95
+ });
96
+ };
97
+ runWait().catch((e) => {
98
+ if (isCancelled)
99
+ return;
100
+ this.isBusy = false;
101
+ controller.error(e);
102
+ });
103
+ }
104
+ catch (e) {
105
+ if (isCancelled)
106
+ return;
107
+ this.isBusy = false;
108
+ controller.error(e);
109
+ }
110
+ },
111
+ cancel: () => {
112
+ isCancelled = true;
113
+ this.isBusy = false;
114
+ this.cancel();
115
+ }
116
+ });
117
+ }
118
+ /**
119
+ * Sends a signal to cancel any current generation.
120
+ */
121
+ cancel() {
122
+ this.conversation.cancelProcess();
123
+ }
124
+ getHistory() {
125
+ if (this.isBusy) {
126
+ throw new Error(BUSY_MESSAGE);
127
+ }
128
+ const historyStr = this.conversation.getHistory();
129
+ return JSON.parse(historyStr);
130
+ }
131
+ async delete() {
132
+ await this.mutexes.executor.acquireAndRun(() => {
133
+ this.conversation.delete();
134
+ });
135
+ }
136
+ }
137
+ function messageToJsonString(messageLike) {
138
+ let message;
139
+ if (Array.isArray(messageLike)) {
140
+ message = messageLike.map(toMessage);
141
+ }
142
+ else {
143
+ message = toMessage(messageLike);
144
+ }
145
+ return JSON.stringify(message);
146
+ }
147
+ function toMessage(messageLike) {
148
+ if (typeof messageLike === 'string') {
149
+ return { role: 'user', content: messageLike };
150
+ }
151
+ return messageLike;
152
+ }
153
+ //# sourceMappingURL=conversation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.js","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,MAAM,YAAY,GACd,4DAA4D,CAAC;AAEjE;;GAEG;AACH,MAAM,OAAO,YAAY;IAIF;IACA;IACA;IALb,MAAM,GAAG,KAAK,CAAC;IAEvB,YACqB,YAA8B,EAC9B,MAAkB,EAClB,OAA0B;QAF1B,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,WAAM,GAAN,MAAM,CAAY;QAClB,YAAO,GAAP,OAAO,CAAmB;IAAG,CAAC;IAEnD,KAAK,CAAC,WAAW,CAAC,OAAkC;QAClD,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;QAChC,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,IAAI,EAAE;gBAC1D,MAAM,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;gBAC7C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;gBAC/D,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAY,CAAC;YAC1C,CAAC,CAAC,CAAC;QAC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AY,CAAC,UAAU,EAAE,CAAC;QAClD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAc,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,EAAE;YAC7C,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,SAAS,mBAAmB,CAAC,WAAsC;IACjE,IAAI,OAA0B,CAAC;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,SAAS,CAAC,WAAwB;IACzC,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAC,CAAC;IAC9C,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -0,0 +1,107 @@
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 { SessionConfig } from './session_config';
17
+ import { JsonValue } from './types';
18
+ /**
19
+ * Parameters for a tool, following JSON Schema format.
20
+ */
21
+ export declare interface ToolParameters {
22
+ type?: string;
23
+ properties?: Record<string, JsonValue>;
24
+ required?: string[];
25
+ [key: string]: JsonValue | undefined;
26
+ }
27
+ /**
28
+ * A tool is a function that can be called by the LLM.
29
+ */
30
+ export declare interface Tool {
31
+ name: string;
32
+ description?: string;
33
+ parameters?: ToolParameters;
34
+ [key: string]: JsonValue | undefined;
35
+ }
36
+ /**
37
+ * Value of a tool response.
38
+ */
39
+ export declare interface ToolResponseValue {
40
+ name?: string;
41
+ tool_name?: string;
42
+ response?: Record<string, JsonValue>;
43
+ value?: JsonValue;
44
+ [key: string]: JsonValue | undefined;
45
+ }
46
+ /**
47
+ * Item in the content array of a Message.
48
+ */
49
+ export declare interface MessageContentItem {
50
+ type: string;
51
+ text?: string;
52
+ path?: string;
53
+ tool_response?: ToolResponseValue;
54
+ [key: string]: JsonValue | undefined;
55
+ }
56
+ /**
57
+ * A function call predicted by the model.
58
+ */
59
+ export declare interface ToolCallFunction {
60
+ name: string;
61
+ arguments: Record<string, JsonValue>;
62
+ [key: string]: JsonValue | undefined;
63
+ }
64
+ /**
65
+ * A tool call in the message.
66
+ */
67
+ export declare interface ToolCall {
68
+ type: string;
69
+ function: ToolCallFunction;
70
+ [key: string]: JsonValue | undefined;
71
+ }
72
+ /**
73
+ * A message in the conversation.
74
+ */
75
+ export declare interface Message {
76
+ role: string;
77
+ content?: string | MessageContentItem[];
78
+ channels?: Record<string, string>;
79
+ tool_calls?: ToolCall[];
80
+ [key: string]: JsonValue | undefined;
81
+ }
82
+ /**
83
+ * Types that can be used as a Message in the conversation.
84
+ */
85
+ export type MessageLike = string | Message;
86
+ /**
87
+ * Preface is the initial messages, tools and extra context for the
88
+ * conversation to begin with. It provides the initial background for the
89
+ * conversation.
90
+ */
91
+ export declare interface Preface {
92
+ messages?: Message[];
93
+ tools?: Tool[];
94
+ extra_context?: Record<string, JsonValue>;
95
+ [key: string]: JsonValue | undefined;
96
+ }
97
+ /**
98
+ * Configuration for the Conversation instance.
99
+ */
100
+ export declare interface ConversationConfig {
101
+ sessionConfig?: SessionConfig;
102
+ preface?: Preface;
103
+ enableConstrainedDecoding?: boolean;
104
+ prefillPrefaceOnInit?: boolean;
105
+ filterChannelContentFromKvCache?: boolean;
106
+ }
107
+ //# sourceMappingURL=conversation_config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation_config.d.ts","sourceRoot":"","sources":["../src/conversation_config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,cAAc;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAC,SAAS,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,IAAI;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAC,SAAS,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,iBAAiB;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACrC,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAC,SAAS,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO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SAAS,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,kBAAkB;IACzC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,+BAA+B,CAAC,EAAE,OAAO,CAAC;CAE3C"}
@@ -0,0 +1,17 @@
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
+ export {};
17
+ //# sourceMappingURL=conversation_config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation_config.js","sourceRoot":"","sources":["../src/conversation_config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
@@ -0,0 +1,37 @@
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 { Conversation } from './conversation';
17
+ import { ConversationConfig } from './conversation_config';
18
+ import { EngineSettings } from './engine_settings';
19
+ import { Session } from './session';
20
+ import { RecursiveRequired } from './types';
21
+ import { Deletable } from './wasm_binding_types';
22
+ /**
23
+ * LiteRT-LM Engine
24
+ */
25
+ export declare class Engine implements Deletable {
26
+ private readonly wasm;
27
+ private readonly engine;
28
+ private readonly deleteCallback;
29
+ readonly settings: RecursiveRequired<EngineSettings>;
30
+ private mutexes;
31
+ private constructor();
32
+ static create(engineSettings: EngineSettings, inputPromptAsHint?: string): Promise<Engine>;
33
+ createSession(sessionConfig?: {}): Promise<Session>;
34
+ createConversation(config?: ConversationConfig): Promise<Conversation>;
35
+ delete(): Promise<void>;
36
+ }
37
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,kBAAkB,EAAC,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAC,cAAc,EAA+E,MAAM,mBAAmB,CAAC;AAK/H,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAwD,SAAS,EAAsF,MAAM,sBAAsB,CAAC;AAQ3L;;GAEG;AACH,qBAAa,MAAO,YAAW,SAAS;IAOlC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,cAAc;IATnC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC,cAAc,CAAC,CAAC;IACrD,OAAO,CAAC,OAAO,CAEb;IAEF,OAAO;WAgBM,MAAM,CAAC,cAAc,EAAE,cAAc,EAAE,iBAAiB,SAAK,GACtE,OAAO,CAAC,MAAM,CAAC;IAsFb,aAAa,CAAC,aAAa,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC;IAWnD,kBAAkB,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IA8BtE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAK9B"}