react-brai 1.0.3 → 1.0.4
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.
Potentially problematic release.
This version of react-brai might be problematic. Click here for more details.
- package/package.json +8 -12
- package/src/useLocalAI.ts +12 -0
- package/tsconfig.json +2 -1
package/package.json
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-brai",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"build:lib": "tsup src/index.ts --format cjs,esm --dts --external react",
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"build": "npm run build:worker && npm run embed && npm run build:lib"
|
|
17
|
-
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build:worker": "tsup src/worker.ts --format esm --no-splitting --clean --dts",
|
|
9
|
+
"embed": "node scripts/embed-worker.js",
|
|
10
|
+
"build:lib": "tsup src/index.ts --format cjs,esm --dts --external react",
|
|
11
|
+
"build": "npm run build:worker && npm run embed && npm run build:lib"
|
|
12
|
+
},
|
|
18
13
|
"keywords": [],
|
|
19
14
|
"author": "",
|
|
20
15
|
"license": "ISC",
|
|
@@ -25,6 +20,7 @@
|
|
|
25
20
|
"devDependencies": {
|
|
26
21
|
"@types/node": "^25.0.3",
|
|
27
22
|
"@types/react": "^19.2.7",
|
|
23
|
+
"@webgpu/types": "^0.1.68",
|
|
28
24
|
"react": "^19.2.3",
|
|
29
25
|
"tsup": "^8.5.1",
|
|
30
26
|
"typescript": "^5.9.3"
|
package/src/useLocalAI.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { WORKER_CODE } from "./worker-embedded";
|
|
|
7
7
|
export function useLocalAI() {
|
|
8
8
|
const workerRef = useRef<Worker | null>(null);
|
|
9
9
|
|
|
10
|
+
const [isSupported, setIsSupported] = useState<boolean | null>(null);
|
|
11
|
+
|
|
10
12
|
const [isReady, setIsReady] = useState(false);
|
|
11
13
|
const [isLoading, setIsLoading] = useState(false);
|
|
12
14
|
const [response, setResponse] = useState("");
|
|
@@ -15,6 +17,15 @@ export function useLocalAI() {
|
|
|
15
17
|
|
|
16
18
|
// 1. AUTOMATIC INITIALIZATION (No more initWorker)
|
|
17
19
|
useEffect(() => {
|
|
20
|
+
if (!navigator.gpu) {
|
|
21
|
+
console.error("WebGPU is not supported on this device.");
|
|
22
|
+
setIsSupported(false);
|
|
23
|
+
setError("WebGPU is not supported on this device.");
|
|
24
|
+
return; // Stop here, don't load the worker
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
setIsSupported(true);
|
|
28
|
+
|
|
18
29
|
if (!WORKER_CODE) return;
|
|
19
30
|
|
|
20
31
|
// A. Create the worker from the embedded string
|
|
@@ -71,6 +82,7 @@ export function useLocalAI() {
|
|
|
71
82
|
|
|
72
83
|
return {
|
|
73
84
|
// initWorker is gone!
|
|
85
|
+
isSupported,
|
|
74
86
|
loadModel,
|
|
75
87
|
chat,
|
|
76
88
|
isReady,
|
package/tsconfig.json
CHANGED