dolor3v / worker.js
root
Deploy recovered Dolor3v
96f93e0
Raw
History Blame Contribute Delete
7.83 kB
(() => {
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 = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dolor3v - Your Personal Coding AI</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"><\/script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js"><\/script>
<style>
*{box-sizing:border-box;margin:0;padding:0}
body{background:#0d1117;color:#e6edf3;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;height:100vh;display:flex;flex-direction:column}
header{background:#161b22;border-bottom:1px solid #30363d;padding:16px 20px;display:flex;align-items:center;gap:12px}
header h1{font-size:20px;background:linear-gradient(135deg,#58a6ff,#bc8cff);-webkit-background-clip:text;-webkit-text-fill-color:transparent}
header span{font-size:12px;color:#8b949e;background:#21262d;padding:2px 8px;border-radius:20px}
#chat{flex:1;overflow-y:auto;padding:20px;display:flex;flex-direction:column;gap:16px}
.message{max-width:85%;padding:12px 16px;border-radius:12px;line-height:1.6;font-size:14px}
.user{align-self:flex-end;background:#1f6feb;border-radius:12px 12px 2px 12px}
.ai{align-self:flex-start;background:#161b22;border:1px solid #30363d;border-radius:2px 12px 12px 12px;max-width:90%}
.ai pre{position:relative;background:#0d1117;border:1px solid #30363d;border-radius:8px;margin:10px 0;overflow-x:auto}
.ai pre code{padding:16px;display:block;font-size:13px}
.copy-btn{position:absolute;top:8px;right:8px;background:#21262d;color:#8b949e;border:1px solid #30363d;padding:4px 10px;border-radius:6px;cursor:pointer;font-size:12px}
.copy-btn:hover{background:#30363d;color:#e6edf3}
.thinking{align-self:flex-start;color:#8b949e;font-size:13px;padding:8px 16px;background:#161b22;border-radius:12px;border:1px solid #30363d}
#input-area{padding:16px 20px;background:#161b22;border-top:1px solid #30363d;display:flex;gap:10px}
#input{flex:1;background:#0d1117;border:1px solid #30363d;border-radius:10px;color:#e6edf3;padding:12px 16px;font-size:14px;resize:none;outline:none;max-height:120px}
#input:focus{border-color:#58a6ff}
#send{background:#1f6feb;color:white;border:none;border-radius:10px;padding:12px 20px;cursor:pointer;font-size:14px;font-weight:600;align-self:flex-end}
#send:hover{background:#388bfd}
#send:disabled{background:#21262d;color:#8b949e;cursor:not-allowed}
.welcome{text-align:center;color:#8b949e;margin:auto;padding:40px}
.welcome h2{font-size:28px;background:linear-gradient(135deg,#58a6ff,#bc8cff);-webkit-background-clip:text;-webkit-text-fill-color:transparent;margin-bottom:10px}
@media(max-width:600px){.message{max-width:95%}.ai{max-width:98%}}
</style>
</head>
<body>
<header><h1>\u26A1 Dolor3v</h1><span>Your Personal Coding AI</span></header>
<div id="chat">
<div class="welcome"><h2>Dolor3v</h2><p>Ask me to build anything. I write production-ready code.</p></div>
</div>
<div id="input-area">
<textarea id="input" placeholder="Ask Dolor3v to build something..." rows="1"></textarea>
<button id="send">Send</button>
</div>
<script>
const chat=document.getElementById('chat')
const input=document.getElementById('input')
const send=document.getElementById('send')
let history=[{role:'system',content:'You are Dolor3v, an expert software engineer created by dolordprince. Write clean production-ready code with best practices, error handling and comments. Format code with markdown code blocks.'}]
async function sendMessage(){
const text=input.value.trim()
if(!text)return
input.value=''
send.disabled=true
const welcome=chat.querySelector('.welcome')
if(welcome)welcome.remove()
addMsg('user',text)
history.push({role:'user',content:text})
const thinking=document.createElement('div')
thinking.className='thinking'
thinking.textContent='Dolor3v is thinking...'
chat.appendChild(thinking)
chat.scrollTop=chat.scrollHeight
try{
const res=await fetch('/chat',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({messages:history})})
const data=await res.json()
thinking.remove()
const reply=data.reply||data.error||'Something went wrong.'
history.push({role:'assistant',content:reply})
addMsg('ai',reply)
}catch(e){thinking.remove();addMsg('ai','Error connecting. Try again.')}
send.disabled=false
input.focus()
}
function addMsg(role,text){
const div=document.createElement('div')
div.className='message '+role
if(role==='ai'){
div.innerHTML=marked.parse(text)
div.querySelectorAll('pre').forEach(pre=>{
const btn=document.createElement('button')
btn.className='copy-btn'
btn.textContent='Copy'
btn.onclick=()=>{navigator.clipboard.writeText(pre.querySelector('code').innerText);btn.textContent='Copied!';setTimeout(()=>btn.textContent='Copy',2000)}
pre.appendChild(btn)
})
div.querySelectorAll('pre code').forEach(b=>hljs.highlightElement(b))
}else{div.textContent=text}
chat.appendChild(div)
chat.scrollTop=chat.scrollHeight
}
send.onclick=sendMessage
input.addEventListener('keydown',e=>{if(e.key==='Enter'&&!e.shiftKey){e.preventDefault();sendMessage()}})
input.addEventListener('input',()=>{input.style.height='auto';input.style.height=Math.min(input.scrollHeight,120)+'px'})
<\/script>
</body>
</html>`;
})();
//# sourceMappingURL=worker.js.map