File size: 7,828 Bytes
96f93e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
(() => {
  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