aione-web 1.0.0 → 1.0.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.
- package/AIOne.d.ts +4 -1
- package/AIOne.js +16 -1
- package/package.json +14 -5
- package/worker-runtime.js +36 -6
- package/AIOneWeb.js +0 -8643
- package/AIOneWeb.wasm +0 -0
package/AIOne.d.ts
CHANGED
package/AIOne.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
export default class AIOne {
|
|
2
2
|
static async create(options = {}) {
|
|
3
|
-
const workerUrl =
|
|
3
|
+
const workerUrl = new URL(
|
|
4
|
+
options.workerUrl ?? "/aio1-worker.js",
|
|
5
|
+
globalThis.location?.href ?? import.meta.url
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
if (options.threads) {
|
|
9
|
+
workerUrl.searchParams.set("threads", "1");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (options.runtimeUrl) {
|
|
13
|
+
workerUrl.searchParams.set("runtime", options.runtimeUrl);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (options.wasmUrl) {
|
|
17
|
+
workerUrl.searchParams.set("wasm", options.wasmUrl);
|
|
18
|
+
}
|
|
4
19
|
|
|
5
20
|
if (typeof SharedWorker === "undefined") {
|
|
6
21
|
throw new Error("SharedWorker is not supported by this browser");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aione-web",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Browser AI inference powered by llama.cpp and WebGPU",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -38,18 +38,27 @@
|
|
|
38
38
|
},
|
|
39
39
|
"./runtime": "./worker-runtime.js",
|
|
40
40
|
"./workerfs-bridge": "./workerfs-bridge.js",
|
|
41
|
-
"./
|
|
42
|
-
"./
|
|
41
|
+
"./single": "./build/Release/AIOneWeb.js",
|
|
42
|
+
"./single/wasm": "./build/Release/AIOneWeb.wasm",
|
|
43
|
+
"./mt": "./build/Release-mt/AIOneWebMT.js",
|
|
44
|
+
"./mt/wasm": "./build/Release-mt/AIOneWebMT.wasm",
|
|
45
|
+
"./AIOneWeb.js": "./build/Release/AIOneWeb.js",
|
|
46
|
+
"./AIOneWeb.wasm": "./build/Release/AIOneWeb.wasm",
|
|
47
|
+
"./AIOneWebMT.js": "./build/Release-mt/AIOneWebMT.js",
|
|
48
|
+
"./AIOneWebMT.wasm": "./build/Release-mt/AIOneWebMT.wasm",
|
|
49
|
+
"./build/*": "./build/*",
|
|
43
50
|
"./package.json": "./package.json"
|
|
44
51
|
},
|
|
45
52
|
"files": [
|
|
46
53
|
"AIOne.js",
|
|
47
54
|
"AIOne.d.ts",
|
|
48
|
-
"AIOneWeb.js",
|
|
49
|
-
"AIOneWeb.wasm",
|
|
50
55
|
"RPCClient.js",
|
|
51
56
|
"worker-runtime.js",
|
|
52
57
|
"workerfs-bridge.js",
|
|
58
|
+
"build/Release/AIOneWeb.js",
|
|
59
|
+
"build/Release/AIOneWeb.wasm",
|
|
60
|
+
"build/Release-mt/AIOneWebMT.js",
|
|
61
|
+
"build/Release-mt/AIOneWebMT.wasm",
|
|
53
62
|
"README.md"
|
|
54
63
|
],
|
|
55
64
|
"publishConfig": {
|
package/worker-runtime.js
CHANGED
|
@@ -5,7 +5,36 @@ let mountedFile;
|
|
|
5
5
|
|
|
6
6
|
let operationQueue = Promise.resolve();
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const WORKER_URL = new URL(self.location.href);
|
|
9
|
+
const SEARCH_PARAMS = WORKER_URL.searchParams;
|
|
10
|
+
const USE_THREADS = SEARCH_PARAMS.get("threads") === "1";
|
|
11
|
+
|
|
12
|
+
const DEFAULT_RUNTIME_DIR = new URL(
|
|
13
|
+
USE_THREADS ? "./build/Release-mt/" : "./build/Release/",
|
|
14
|
+
WORKER_URL
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const RUNTIME_URL = SEARCH_PARAMS.get("runtime")
|
|
18
|
+
? new URL(SEARCH_PARAMS.get("runtime"), WORKER_URL).href
|
|
19
|
+
: new URL(
|
|
20
|
+
USE_THREADS ? "AIOneWebMT.js" : "AIOneWeb.js",
|
|
21
|
+
DEFAULT_RUNTIME_DIR
|
|
22
|
+
).href;
|
|
23
|
+
|
|
24
|
+
const WASM_URL = SEARCH_PARAMS.get("wasm");
|
|
25
|
+
const HAS_EXTERNAL_RUNTIME = typeof Module !== "undefined";
|
|
26
|
+
|
|
27
|
+
if (!HAS_EXTERNAL_RUNTIME) {
|
|
28
|
+
importScripts(RUNTIME_URL);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function locateFile(path) {
|
|
32
|
+
if (WASM_URL) {
|
|
33
|
+
return new URL(WASM_URL, WORKER_URL).href;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return new URL(path, RUNTIME_URL).href;
|
|
37
|
+
}
|
|
9
38
|
|
|
10
39
|
async function initialize(file) {
|
|
11
40
|
if (session) {
|
|
@@ -18,12 +47,13 @@ async function initialize(file) {
|
|
|
18
47
|
|
|
19
48
|
if (!initializing && !module) {
|
|
20
49
|
initializing = (async () => {
|
|
21
|
-
|
|
22
|
-
|
|
50
|
+
const moduleOptions = { workerFile: file };
|
|
51
|
+
|
|
52
|
+
if (WASM_URL || !HAS_EXTERNAL_RUNTIME) {
|
|
53
|
+
moduleOptions.locateFile = locateFile;
|
|
54
|
+
}
|
|
23
55
|
|
|
24
|
-
|
|
25
|
-
new URL(path, BASE_URL).href
|
|
26
|
-
});
|
|
56
|
+
module = await Module(moduleOptions);
|
|
27
57
|
|
|
28
58
|
mountedFile = file.name;
|
|
29
59
|
session = new module.ModelSession();
|