@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
@@ -0,0 +1,117 @@
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
+ * Checks for relaxed SIMD support.
18
+ *
19
+ * (module
20
+ * (func (result v128)
21
+ * i32.const 1
22
+ * i8x16.splat
23
+ * i32.const 2
24
+ * i8x16.splat
25
+ * i8x16.relaxed_swizzle
26
+ * )
27
+ * )
28
+ */
29
+ const WASM_RELAXED_SIMD_CHECK = new Uint8Array([
30
+ 0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1,
31
+ 0, 10, 15, 1, 13, 0, 65, 1, 253, 15, 65, 2, 253, 15, 253, 128, 2, 11
32
+ ]);
33
+ /**
34
+ * Checks for WebAssembly Pthreads emulation.
35
+ *
36
+ * (module
37
+ * (memory 1 1 shared)
38
+ * (func
39
+ * i32.const 0
40
+ * i32.atomic.load
41
+ * drop
42
+ * )
43
+ * )
44
+ */
45
+ const WASM_THREADS_CHECK = new Uint8Array([
46
+ 0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 5,
47
+ 4, 1, 3, 1, 1, 10, 11, 1, 9, 0, 65, 0, 254, 16, 2, 0, 26, 11
48
+ ]);
49
+ const WASM_FEATURE_VALUES = {
50
+ 'relaxedSimd': undefined,
51
+ 'threads': undefined,
52
+ };
53
+ async function tryWasm(wasm) {
54
+ try {
55
+ await WebAssembly.instantiate(wasm);
56
+ return { supported: true };
57
+ }
58
+ catch (e) {
59
+ return { supported: false, error: e };
60
+ }
61
+ }
62
+ const WASM_FEATURE_CHECKS = {
63
+ 'relaxedSimd': () => {
64
+ if (WASM_FEATURE_VALUES.relaxedSimd === undefined) {
65
+ WASM_FEATURE_VALUES.relaxedSimd = tryWasm(WASM_RELAXED_SIMD_CHECK);
66
+ }
67
+ return WASM_FEATURE_VALUES.relaxedSimd;
68
+ },
69
+ 'threads': () => {
70
+ if (WASM_FEATURE_VALUES.threads === undefined) {
71
+ try {
72
+ if (typeof MessageChannel !== 'undefined') {
73
+ new MessageChannel().port1.postMessage(new SharedArrayBuffer(1));
74
+ }
75
+ WASM_FEATURE_VALUES.threads = tryWasm(WASM_THREADS_CHECK);
76
+ }
77
+ catch (e) {
78
+ WASM_FEATURE_VALUES.threads =
79
+ Promise.resolve({ supported: false, error: e });
80
+ }
81
+ }
82
+ return WASM_FEATURE_VALUES.threads;
83
+ },
84
+ };
85
+ /**
86
+ * Check if a given WASM feature is supported.
87
+ *
88
+ * @param feature The feature to check.
89
+ * @return A promise that resolves to true if the feature is supported,
90
+ * false otherwise.
91
+ */
92
+ export async function supportsFeature(feature) {
93
+ const check = WASM_FEATURE_CHECKS[feature]?.();
94
+ if (!check) {
95
+ // Then we don't know how to check for this feature.
96
+ throw new Error(`Unknown feature: ${feature}`);
97
+ }
98
+ return (await check).supported;
99
+ }
100
+ /**
101
+ * Throw an error if a given WASM feature is not supported.
102
+ *
103
+ * @param feature The feature to check.
104
+ * @throws An error if the feature is not supported.
105
+ */
106
+ export async function throwIfFeatureNotSupported(feature) {
107
+ const check = WASM_FEATURE_CHECKS[feature]?.();
108
+ if (!check) {
109
+ // Then we don't know how to check for this feature.
110
+ throw new Error(`Unknown feature: ${feature}`);
111
+ }
112
+ const result = await check;
113
+ if (!result.supported) {
114
+ throw result.error;
115
+ }
116
+ }
117
+ //# sourceMappingURL=wasm_feature_detect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm_feature_detect.js","sourceRoot":"","sources":["../src/wasm_feature_detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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AAI,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,SAAS,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC5C,OAAyC;IAC3C,MAAM,KAAK,GAAG,mBAAmB,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;IAC/C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,oDAAoD;QACpD,MAAM,IAAI,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC;IAC3B,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACtB,MAAM,MAAM,CAAC,KAAM,CAAC;IACtB,CAAC;AACH,CAAC"}
@@ -0,0 +1,30 @@
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 { EmscriptenVector } from './wasm_binding_types';
17
+ /**
18
+ * Convert an EmscriptenVector to a native array and delete the vector
19
+ *
20
+ * Deletes the EmscriptenVector when done. The caller must still delete the
21
+ * individual elements of the returned array.
22
+ */
23
+ export declare function consumeEmscriptenVectorToArray<T>(vector: EmscriptenVector<T>): T[];
24
+ /**
25
+ * Fill an EmscriptenVector from an Iterable.
26
+ *
27
+ * The EmscriptenVector must be large enough to hold the data.
28
+ */
29
+ export declare function fillEmscriptenVector<T>(data: Iterable<T>, vector: EmscriptenVector<T>): void;
30
+ //# sourceMappingURL=wasm_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm_utils.d.ts","sourceRoot":"","sources":["../src/wasm_utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAEtD;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,GACzE,CAAC,EAAE,CAON;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAClC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,QAKjD"}
@@ -0,0 +1,41 @@
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
+ * Convert an EmscriptenVector to a native array and delete the vector
18
+ *
19
+ * Deletes the EmscriptenVector when done. The caller must still delete the
20
+ * individual elements of the returned array.
21
+ */
22
+ export function consumeEmscriptenVectorToArray(vector) {
23
+ const array = new Array(vector.size());
24
+ for (let i = 0; i < vector.size(); ++i) {
25
+ array[i] = vector.get(i);
26
+ }
27
+ vector.delete();
28
+ return array;
29
+ }
30
+ /**
31
+ * Fill an EmscriptenVector from an Iterable.
32
+ *
33
+ * The EmscriptenVector must be large enough to hold the data.
34
+ */
35
+ export function fillEmscriptenVector(data, vector) {
36
+ // Embind lacks vector.reserve().
37
+ for (const item of data) {
38
+ vector.push_back(item);
39
+ }
40
+ }
41
+ //# sourceMappingURL=wasm_utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm_utils.js","sourceRoot":"","sources":["../src/wasm_utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAAI,MAA2B;IAE3E,MAAM,KAAK,GAAG,IAAI,KAAK,CAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;QACvC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IACD,MAAM,CAAC,MAAM,EAAE,CAAC;IAChB,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAChC,IAAiB,EAAE,MAA2B;IAChD,iCAAiC;IACjC,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@litert-lm/core",
3
+ "version": "0.12.0",
4
+ "description": "LiteRT-LM package",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "type": "module",
11
+ "files": [
12
+ "dist/**",
13
+ "wasm/**"
14
+ ],
15
+ "author": "",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/google-ai-edge/LiteRT-LM.git",
19
+ "directory": "js/packages/core"
20
+ },
21
+ "license": "Apache-2.0",
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "lint": "eslint .",
25
+ "typecheck": "tsc --noEmit",
26
+ "bundle-tests": "esbuild --bundle src/litertlm_web_test.ts --sourcemap --outfile=spec_dist/litertlm_web_test.js",
27
+ "test": "npm run bundle-tests && jasmine-browser-runner",
28
+ "clean": "rimraf .turbo node_modules dist spec_dist",
29
+ "pack": "npm pack"
30
+ },
31
+ "devDependencies": {
32
+ "@types/jasmine": "^5.1.8",
33
+ "@webgpu/types": "^0.1.54",
34
+ "esbuild": "^0.23.0",
35
+ "eslint": "^9.8.0",
36
+ "jasmine": "^5.8.0",
37
+ "jasmine-browser-runner": "^3.0.0",
38
+ "jasmine-core": "^5.8.0",
39
+ "rimraf": "^6.0.1",
40
+ "selenium-webdriver": "^4.34.0",
41
+ "typescript": "^5.5.4"
42
+ },
43
+ "dependencies": {
44
+ "@litertjs/wasm-utils": "^2.0.0"
45
+ }
46
+ }