diff --git a/app/package.json b/app/package.json index 4303d16..d0eb0e8 100644 --- a/app/package.json +++ b/app/package.json @@ -69,7 +69,6 @@ "@vitejs/plugin-react": "^4.0.2", "babel-plugin-formatjs": "^10.5.3", "typescript": "^4.9.5", - "vite": "^4.4.1", - "vite-plugin-comlink": "^3.0.5" + "vite": "^4.4.1" } } diff --git a/app/src/core/tokenizer/worker.ts b/app/src/core/tokenizer/worker.ts index 3fa81f3..ce79750 100644 --- a/app/src/core/tokenizer/worker.ts +++ b/app/src/core/tokenizer/worker.ts @@ -1,3 +1,4 @@ +import { expose } from "comlink"; import * as methods from "."; import { OpenAIMessage } from "../chat/types"; import { ChatHistoryTrimmer, ChatHistoryTrimmerOptions } from "./chat-history-trimmer"; @@ -13,4 +14,6 @@ export function countTokensForText(text: string) { export function countTokensForMessages(messages: OpenAIMessage[]) { return methods.countTokensForMessages(messages); -} \ No newline at end of file +} + +expose({ runChatTrimmer, countTokensForText, countTokensForMessages }); diff --git a/app/src/core/tokenizer/wrapper.ts b/app/src/core/tokenizer/wrapper.ts index 0e4ca96..daa9394 100644 --- a/app/src/core/tokenizer/wrapper.ts +++ b/app/src/core/tokenizer/wrapper.ts @@ -1,10 +1,11 @@ +import { wrap } from "comlink"; import { OpenAIMessage } from "../chat/types"; import type { ChatHistoryTrimmerOptions } from "./chat-history-trimmer"; // @ts-ignore import tokenizer from "./worker?worker&url"; -const worker = new ComlinkWorker( - new URL(tokenizer, import.meta.url) +const worker = wrap( + new Worker(new URL(tokenizer, import.meta.url), { type: "module" }) ); export async function runChatTrimmer( diff --git a/app/vite.config.js b/app/vite.config.js index e8aefa1..9b66e32 100644 --- a/app/vite.config.js +++ b/app/vite.config.js @@ -1,6 +1,5 @@ import react from "@vitejs/plugin-react"; import { defineConfig } from "vite"; -import { comlink } from "vite-plugin-comlink"; export default defineConfig(() => { return { @@ -35,10 +34,6 @@ export default defineConfig(() => { ], }, }), - comlink(), ], - worker: { - plugins: [comlink()], - }, }; });