File size: 7,059 Bytes
23b97de
e5e3a8b
 
23b97de
 
 
e5e3a8b
23b97de
 
 
 
 
 
 
 
e5e3a8b
23b97de
 
6a1ae2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23b97de
 
 
6a1ae2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23b97de
e5e3a8b
 
 
6a1ae2a
23b97de
 
6a1ae2a
23b97de
6a1ae2a
 
 
 
 
 
 
 
 
 
 
 
23b97de
6a1ae2a
 
 
 
e5e3a8b
 
23b97de
 
6a1ae2a
23b97de
 
 
6a1ae2a
23b97de
 
 
 
 
 
 
 
 
6a1ae2a
 
23b97de
6a1ae2a
 
 
23b97de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6a1ae2a
23b97de
 
6a1ae2a
 
 
 
 
 
 
23b97de
6a1ae2a
23b97de
 
 
 
 
 
 
 
6a1ae2a
23b97de
 
 
 
6a1ae2a
 
 
 
 
 
 
23b97de
 
6a1ae2a
 
 
 
 
23b97de
 
 
 
 
 
 
6a1ae2a
23b97de
 
 
e5e3a8b
23b97de
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>OpenCode Zen - DeepSeek Chat</title>
  <style>
    :root {
      --bg-primary: #0f172a;
      --bg-secondary: #1e293b;
      --bg-bubble-ai: #273549;
      --bg-bubble-user: #2563eb;
      --text-main: #f8fafc;
      --border-color: #334155;
      --accent: #38bdf8;
    }
    * { box-sizing: border-box; margin: 0; padding: 0; font-family: system-ui, sans-serif; }
    body { background-color: var(--bg-primary); color: var(--text-main); display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
    
    header {
      background-color: var(--bg-secondary);
      border-bottom: 1px solid var(--border-color);
      padding: 12px 16px;
      display: flex;
      flex-wrap: wrap;
      gap: 12px;
      align-items: center;
      justify-content: space-between;
    }

    .config-group {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      align-items: center;
      font-size: 13px;
    }

    .config-group input, .config-group select {
      background: var(--bg-primary);
      border: 1px solid var(--border-color);
      color: var(--text-main);
      padding: 6px 10px;
      border-radius: 6px;
      font-size: 13px;
      outline: none;
    }

    #chat-window {
      flex: 1;
      padding: 20px;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      gap: 16px;
    }

    .message {
      max-width: 85%;
      line-height: 1.5;
      padding: 12px 16px;
      border-radius: 12px;
      word-break: break-word;
      white-space: pre-wrap;
    }

    .user-msg { background-color: var(--bg-bubble-user); align-self: flex-end; border-bottom-right-radius: 2px; }
    .ai-msg { background-color: var(--bg-bubble-ai); align-self: flex-start; border-bottom-left-radius: 2px; border: 1px solid var(--border-color); }
    .error-msg { background-color: #7f1d1d; color: #fecaca; align-self: center; font-size: 13px; }

    #input-container {
      background-color: var(--bg-secondary);
      border-top: 1px solid var(--border-color);
      padding: 14px 20px;
      display: flex;
      gap: 10px;
    }

    textarea {
      flex: 1;
      background: var(--bg-primary);
      color: var(--text-main);
      border: 1px solid var(--border-color);
      border-radius: 8px;
      padding: 10px 14px;
      resize: none;
      height: 48px;
      outline: none;
      font-size: 14px;
    }

    button {
      background: var(--accent);
      color: #0f172a;
      border: none;
      font-weight: 600;
      padding: 0 20px;
      border-radius: 8px;
      cursor: pointer;
    }
    button:disabled { opacity: 0.5; cursor: not-allowed; }
  </style>
</head>
<body>

  <header>
    <div><strong>OpenCode Zen Chat</strong></div>

    <div class="config-group">
      <label>Proxy:</label>
      <select id="cors-mode">
        <option value="proxy">CORS Proxy (For Web Hosts)</option>
        <option value="direct">Direct (No Proxy)</option>
      </select>

      <label>Endpoint:</label>
      <select id="endpoint-select">
        <option value="https://opencode.ai/zen/v1/chat/completions">/zen/v1/chat/completions</option>
        <option value="https://opencode.ai/inference/v1/chat/completions">/inference/v1/chat/completions</option>
      </select>

      <label>Model:</label>
      <input type="text" id="model-input" value="deepseek-v4.1-flash-free" style="width: 200px;" />

      <label>Key:</label>
      <input type="password" id="api-key" value="oc_sk_35b87025c3e1_wYnXQAjQFh5SahiJknEk7MRQdW3q7RaL" style="width: 140px;" />
    </div>
  </header>

  <div id="chat-window">
    <div class="message ai-msg">Ready! Type your question below.</div>
  </div>

  <div id="input-container">
    <textarea id="prompt-input" placeholder="Type a message... (Shift + Enter for new line)"></textarea>
    <button id="send-btn" onclick="sendMessage()">Send</button>
  </div>

  <script>
    const chatWindow = document.getElementById("chat-window");
    const promptInput = document.getElementById("prompt-input");
    const sendBtn = document.getElementById("send-btn");
    const apiKeyInput = document.getElementById("api-key");
    const modelInput = document.getElementById("model-input");
    const endpointSelect = document.getElementById("endpoint-select");
    const corsMode = document.getElementById("cors-mode");

    let messages = [
      { role: "system", content: "You are a helpful coding and AI assistant." }
    ];

    promptInput.addEventListener("keydown", (e) => {
      if (e.key === "Enter" && !e.shiftKey) {
        e.preventDefault();
        sendMessage();
      }
    });

    function appendMessage(role, text) {
      const msg = document.createElement("div");
      msg.className = `message ${role === "user" ? "user-msg" : "ai-msg"}`;
      msg.textContent = text;
      chatWindow.appendChild(msg);
      chatWindow.scrollTop = chatWindow.scrollHeight;
      return msg;
    }

    async function sendMessage() {
      const text = promptInput.value.trim();
      const apiKey = apiKeyInput.value.trim();
      const model = modelInput.value.trim();

      if (!text || !apiKey) return;

      appendMessage("user", text);
      messages.push({ role: "user", content: text });
      promptInput.value = "";

      const aiBubble = appendMessage("assistant", "Thinking...");
      sendBtn.disabled = true;

      // Determine target URL
      let targetUrl = endpointSelect.value;
      if (corsMode.value === "proxy") {
        // Routes through a CORS proxy so browser security doesn't block the static host
        targetUrl = "https://corsproxy.io/?" + encodeURIComponent(targetUrl);
      }

      try {
        const response = await fetch(targetUrl, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "Authorization": `Bearer ${apiKey}`
          },
          body: JSON.stringify({
            model: model,
            messages: messages,
            stream: false // Non-streamed for maximum proxy compatibility
          })
        });

        if (!response.ok) {
          const errBody = await response.text();
          let parsedMsg = errBody;
          try {
            const json = JSON.parse(errBody);
            parsedMsg = json.error?.message || json.message || errBody;
          } catch (_) {}
          throw new Error(`HTTP ${response.status}: ${parsedMsg}`);
        }

        const data = await response.json();
        const reply = data.choices?.[0]?.message?.content || "(No response content returned)";

        aiBubble.textContent = reply;
        messages.push({ role: "assistant", content: reply });

      } catch (err) {
        aiBubble.className = "message error-msg";
        aiBubble.textContent = "Error: " + err.message;
      } finally {
        sendBtn.disabled = false;
        promptInput.focus();
        chatWindow.scrollTop = chatWindow.scrollHeight;
      }
    }
  </script>
</body>
</html>