@web-llm-wrappers/react 0.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/dist/index.mjs ADDED
@@ -0,0 +1,105 @@
1
+ import { CreateMLCEngine, MLCEngine, prebuiltAppConfig } from "@mlc-ai/web-llm";
2
+ import { useCallback, useEffect, useState } from "react";
3
+
4
+ //#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
5
+ function _typeof(o) {
6
+ "@babel/helpers - typeof";
7
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
8
+ return typeof o$1;
9
+ } : function(o$1) {
10
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
11
+ }, _typeof(o);
12
+ }
13
+
14
+ //#endregion
15
+ //#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
16
+ function toPrimitive(t, r) {
17
+ if ("object" != _typeof(t) || !t) return t;
18
+ var e = t[Symbol.toPrimitive];
19
+ if (void 0 !== e) {
20
+ var i = e.call(t, r || "default");
21
+ if ("object" != _typeof(i)) return i;
22
+ throw new TypeError("@@toPrimitive must return a primitive value.");
23
+ }
24
+ return ("string" === r ? String : Number)(t);
25
+ }
26
+
27
+ //#endregion
28
+ //#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
29
+ function toPropertyKey(t) {
30
+ var i = toPrimitive(t, "string");
31
+ return "symbol" == _typeof(i) ? i : i + "";
32
+ }
33
+
34
+ //#endregion
35
+ //#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
36
+ function _defineProperty(e, r, t) {
37
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
38
+ value: t,
39
+ enumerable: !0,
40
+ configurable: !0,
41
+ writable: !0
42
+ }) : e[r] = t, e;
43
+ }
44
+
45
+ //#endregion
46
+ //#region \0@oxc-project+runtime@0.98.0/helpers/objectSpread2.js
47
+ function ownKeys(e, r) {
48
+ var t = Object.keys(e);
49
+ if (Object.getOwnPropertySymbols) {
50
+ var o = Object.getOwnPropertySymbols(e);
51
+ r && (o = o.filter(function(r$1) {
52
+ return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
53
+ })), t.push.apply(t, o);
54
+ }
55
+ return t;
56
+ }
57
+ function _objectSpread2(e) {
58
+ for (var r = 1; r < arguments.length; r++) {
59
+ var t = null != arguments[r] ? arguments[r] : {};
60
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
61
+ _defineProperty(e, r$1, t[r$1]);
62
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
63
+ Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
64
+ });
65
+ }
66
+ return e;
67
+ }
68
+
69
+ //#endregion
70
+ //#region src/index.ts
71
+ function getAvailableModels() {
72
+ return prebuiltAppConfig.model_list;
73
+ }
74
+ function useWebLLM({ modelId, engineConfig, chatOptions, debug = false }) {
75
+ const [engine, setEngine] = useState(null);
76
+ const [progressReport, setProgressReport] = useState();
77
+ const loadModel = useCallback((modelId$1) => {
78
+ if (engine) return engine.reload(modelId$1, chatOptions);
79
+ }, [engine, chatOptions]);
80
+ useEffect(() => {
81
+ if (modelId) CreateMLCEngine(modelId, engineConfig, chatOptions).then((engine$1) => {
82
+ setEngine(engine$1);
83
+ });
84
+ else setEngine(new MLCEngine(_objectSpread2(_objectSpread2({}, engineConfig), {}, { initProgressCallback: (progressReport$1) => {
85
+ var _engineConfig$initPro;
86
+ setProgressReport(progressReport$1);
87
+ engineConfig === null || engineConfig === void 0 || (_engineConfig$initPro = engineConfig.initProgressCallback) === null || _engineConfig$initPro === void 0 || _engineConfig$initPro.call(engineConfig, progressReport$1);
88
+ if (debug) console.log("DEBUG: WebLLM React:", { progressReport: progressReport$1 });
89
+ } })));
90
+ return () => {
91
+ engine === null || engine === void 0 || engine.unload();
92
+ setEngine(null);
93
+ };
94
+ }, [engineConfig, debug]);
95
+ return {
96
+ engine,
97
+ progressReport,
98
+ getAvailableModels,
99
+ loadModel
100
+ };
101
+ }
102
+
103
+ //#endregion
104
+ export { useWebLLM };
105
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["modelId","engine","progressReport"],"sources":["../src/index.ts"],"sourcesContent":["import {\n MLCEngine,\n ChatOptions,\n MLCEngineConfig,\n InitProgressReport,\n prebuiltAppConfig,\n CreateMLCEngine,\n} from \"@mlc-ai/web-llm\";\nimport { useCallback, useEffect, useState } from \"react\";\n\nfunction getAvailableModels() {\n return prebuiltAppConfig.model_list;\n}\n\nexport function useWebLLM({\n modelId,\n engineConfig,\n chatOptions,\n debug = false,\n}: {\n modelId?: string | string[];\n engineConfig?: MLCEngineConfig;\n chatOptions?: ChatOptions;\n debug?: boolean;\n}) {\n const [engine, setEngine] = useState<MLCEngine | null>(null);\n const [progressReport, setProgressReport] = useState<InitProgressReport>();\n\n const loadModel = useCallback(\n (modelId: string) => {\n if (engine) {\n return engine.reload(modelId, chatOptions);\n }\n },\n [engine, chatOptions]\n );\n\n useEffect(() => {\n if (modelId) {\n CreateMLCEngine(modelId, engineConfig, chatOptions).then((engine) => {\n setEngine(engine);\n });\n } else {\n setEngine(\n new MLCEngine({\n ...engineConfig,\n initProgressCallback: (progressReport) => {\n setProgressReport(progressReport);\n engineConfig?.initProgressCallback?.(progressReport);\n\n if (debug) {\n console.log(\"DEBUG: WebLLM React:\", { progressReport });\n }\n },\n })\n );\n }\n\n return () => {\n engine?.unload();\n setEngine(null);\n };\n }, [engineConfig, debug]);\n\n return { engine, progressReport, getAvailableModels, loadModel };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,SAAS,qBAAqB;AAC5B,QAAO,kBAAkB;;AAG3B,SAAgB,UAAU,EACxB,SACA,cACA,aACA,QAAQ,SAMP;CACD,MAAM,CAAC,QAAQ,aAAa,SAA2B,KAAK;CAC5D,MAAM,CAAC,gBAAgB,qBAAqB,UAA8B;CAE1E,MAAM,YAAY,aACf,cAAoB;AACnB,MAAI,OACF,QAAO,OAAO,OAAOA,WAAS,YAAY;IAG9C,CAAC,QAAQ,YAAY,CACtB;AAED,iBAAgB;AACd,MAAI,QACF,iBAAgB,SAAS,cAAc,YAAY,CAAC,MAAM,aAAW;AACnE,aAAUC,SAAO;IACjB;MAEF,WACE,IAAI,4CACC,qBACH,uBAAuB,qBAAmB;;AACxC,qBAAkBC,iBAAe;AACjC,6FAAc,+GAAuBA,iBAAe;AAEpD,OAAI,MACF,SAAQ,IAAI,wBAAwB,EAAE,kCAAgB,CAAC;OAG3D,CACH;AAGH,eAAa;AACX,kDAAQ,QAAQ;AAChB,aAAU,KAAK;;IAEhB,CAAC,cAAc,MAAM,CAAC;AAEzB,QAAO;EAAE;EAAQ;EAAgB;EAAoB;EAAW"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@web-llm-wrappers/react",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "./dist/index.mjs",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.mts",
11
+ "exports": {
12
+ ".": "./dist/index.mjs",
13
+ "./run": "./dist/run.mjs",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "typesVersions": {
17
+ "*": {
18
+ "*": [
19
+ "./dist/*",
20
+ "./*"
21
+ ]
22
+ }
23
+ },
24
+ "keywords": [],
25
+ "author": "",
26
+ "license": "MIT",
27
+ "peerDependencies": {
28
+ "@mlc-ai/web-llm": "^0.2.79"
29
+ },
30
+ "dependencies": {
31
+ "react": "^19.2.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/react": "^19.2.5",
35
+ "tsdown": "^0.16.6",
36
+ "typescript": "^5.9.3"
37
+ },
38
+ "tsdown": {
39
+ "format": [
40
+ "esm",
41
+ "cjs"
42
+ ],
43
+ "dts": {
44
+ "resolve": true,
45
+ "entry": [
46
+ "./src/index.ts"
47
+ ],
48
+ "compilerOptions": {
49
+ "moduleResolution": "node"
50
+ }
51
+ },
52
+ "sourcemap": true,
53
+ "clean": true,
54
+ "target": "es6"
55
+ },
56
+ "scripts": {
57
+ "test": "echo \"Error: no test specified\" && exit 1",
58
+ "dev": "tsdown --watch",
59
+ "build": "tsdown"
60
+ }
61
+ }