(() => { var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); // worker.js addEventListener("fetch", (event) => { event.respondWith(handleRequest(event.request)); }); async function handleRequest(request) { const url = new URL(request.url); if (url.pathname === "/") { return new Response(CHAT_HTML, { headers: { "Content-Type": "text/html;charset=UTF-8" } }); } if (url.pathname === "/chat" && request.method === "POST") { const body = await request.json(); const messages = body.messages || []; let result = await callGroq(messages); if (!result) result = await callOpenRouter(messages); if (!result) return new Response(JSON.stringify({ error: "All engines failed" }), { status: 500, headers: { "Content-Type": "application/json" } }); return new Response(JSON.stringify({ reply: result }), { headers: { "Content-Type": "application/json" } }); } return new Response("Not Found", { status: 404 }); } __name(handleRequest, "handleRequest"); async function callGroq(messages) { try { const res = await fetch("https://api.groq.com/openai/v1/chat/completions", { method: "POST", headers: { "Authorization": `Bearer ${GROQ_API_KEY}`, "Content-Type": "application/json" }, body: JSON.stringify({ model: "llama-3.3-70b-versatile", messages, max_tokens: 4096 }) }); const data = await res.json(); if (data.choices) return data.choices[0].message.content; return null; } catch (e) { return null; } } __name(callGroq, "callGroq"); async function callOpenRouter(messages) { try { const res = await fetch("https://openrouter.ai/api/v1/chat/completions", { method: "POST", headers: { "Authorization": `Bearer ${OPENROUTER_API_KEY}`, "Content-Type": "application/json", "HTTP-Referer": "https://dolor3v.workers.dev", "X-Title": "Dolor3v" }, body: JSON.stringify({ model: "google/gemma-4-31b-it:free", messages, max_tokens: 4096 }) }); const data = await res.json(); if (data.choices) return data.choices[0].message.content; return null; } catch (e) { return null; } } __name(callOpenRouter, "callOpenRouter"); var CHAT_HTML = ` Dolor3v - Your Personal Coding AI