const browserFetch = self.fetch.bind(self); self.fetch = (input, init = {}) => browserFetch(input, { ...init, referrerPolicy: "no-referrer" }); const { Wllama, LoggerWithoutDebug } = await import("./vendor/wllama/index.js"); const MODELS = { "qwen3-0.6b": { name: "Qwen3 0.6B", url: "https://huggingface.co/Qwen/Qwen3-0.6B-GGUF/resolve/23749fefcc72300e3a2ad315e1317431b06b590a/Qwen3-0.6B-Q8_0.gguf", localFile: "qwen3-0.6b.gguf", labelBase: 32, }, "minicpm5-2b": { name: "MiniCPM5 2B", url: "https://huggingface.co/openbmb/MiniCPM5-2B-GGUF/resolve/2079a22f3beaa4e306449978533478fe0522f4b3/MiniCPM5-2B-Q4_K_M.gguf", localFile: "minicpm5-2b.gguf", labelBase: 54, }, "qwen3.5-4b": { name: "Qwen3.5 4B", url: "https://huggingface.co/bartowski/Qwen_Qwen3.5-4B-GGUF/resolve/4168f45a16a1290d65a4ec0fa312ae917a4c15d6/Qwen_Qwen3.5-4B-Q4_K_M.gguf", localFile: "qwen3.5-4b.gguf", labelBase: 32, }, }; const MIN_OPTIONS = 2; const MAX_OPTIONS = 20; const labelsFor = (count) => Array.from({ length: count }, (_, index) => String.fromCharCode(65 + index)); let engine; let modelId; function send(type, data = {}) { self.postMessage({ type, ...data }); } function optionBlock(options, labels = labelsFor(options.length)) { return options.map((option, index) => `${labels[index]}. ${option}`).join("\n"); } function messagesFor({ state, question, options }, mode) { const labels = labelsFor(options.length); const outputInstruction = mode === "direct" ? `Reply with exactly one option letter from: ${labels.join(", ")}.` : `Estimate the probability that each allowed option is the correct decision. Return only one JSON object mapping each option to its probability. Form every key as "