ocb-cli 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/proxy.js +275 -267
  2. package/package.json +1 -1
  3. package/src/proxy.ts +276 -267
package/dist/proxy.js CHANGED
@@ -111,7 +111,8 @@ app.use(express.json());
111
111
  app.use((req, res, next) => {
112
112
  res.header("Access-Control-Allow-Origin", "*");
113
113
  res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
114
- res.header("Access-Control-Allow-Headers", "Content-Type, Authorization");
114
+ res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, x-api-key");
115
+ res.header("Content-Type", "application/json");
115
116
  if (req.method === "OPTIONS")
116
117
  return res.sendStatus(200);
117
118
  next();
@@ -155,21 +156,105 @@ app.post("/api/refresh-models", async (req, res) => {
155
156
  await fetchModelsFromOpenCode();
156
157
  res.json({ success: true, count: availableModels.length });
157
158
  });
159
+ app.post("/api/apply-claude-config", async (req, res) => {
160
+ try {
161
+ const { readFileSync, writeFileSync, existsSync, mkdirSync } = await import("fs");
162
+ const { join, dirname } = await import("path");
163
+ const homedir = process.env.USERPROFILE || process.env.HOME || process.env.HOMEPATH || "";
164
+ const settingsPath = join(homedir, ".claude", "settings.json");
165
+ const settingsDir = dirname(settingsPath);
166
+ if (!existsSync(settingsDir))
167
+ mkdirSync(settingsDir, { recursive: true });
168
+ let settings = {};
169
+ if (existsSync(settingsPath))
170
+ settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
171
+ settings.env = settings.env || {};
172
+ settings.env.ANTHROPIC_BASE_URL = "http://localhost:8300";
173
+ settings.env.ANTHROPIC_API_KEY = "test";
174
+ settings.env.ANTHROPIC_MODEL = currentModel;
175
+ writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
176
+ res.json({ success: true });
177
+ }
178
+ catch (e) {
179
+ res.status(500).json({ success: false, error: e instanceof Error ? e.message : String(e) });
180
+ }
181
+ });
158
182
  app.post("/api/reset-stats", (req, res) => {
159
183
  totalTokensUsed = 0;
160
184
  totalRequests = 0;
161
185
  res.json({ success: true });
162
186
  });
187
+ const modelAliases = {
188
+ "claude-opus-4-5": "opencode/minimax-m2.5-free",
189
+ "claude-opus-4-5-thinking": "opencode/minimax-m2.5-free",
190
+ "claude-opus-4-6": "opencode/minimax-m2.5-free",
191
+ "claude-opus-4-6-thinking": "opencode/minimax-m2.5-free",
192
+ "claude-sonnet-4-5": "opencode/minimax-m2.5-free",
193
+ "claude-sonnet-4-5-thinking": "opencode/minimax-m2.5-free",
194
+ "claude-sonnet-4-5-20250929": "opencode/minimax-m2.5-free",
195
+ "claude-sonnet-4-5-20250929-thinking": "opencode/minimax-m2.5-free",
196
+ "claude-haiku-4-5": "opencode/minimax-m2.5-free",
197
+ "claude-haiku-4-5-20251001": "opencode/minimax-m2.5-free",
198
+ };
163
199
  app.post("/api/reset-session", async (req, res) => {
164
200
  currentSessionId = await createSession(process.cwd());
165
201
  res.json({ success: true, sessionId: currentSessionId });
166
202
  });
167
203
  app.get("/v1/authenticate", (req, res) => res.json({ type: "authentication", authenticated: true }));
168
204
  app.get("/v1/whoami", (req, res) => res.json({ type: "user", id: "opencode-user", email: "opencode@local" }));
169
- app.get("/v1/models", (req, res) => res.json({ data: availableModels.map(m => ({ id: m.id, type: "model", name: m.name, supports_cached_previews: true, supports_system_instructions: true })) }));
170
- app.get("/v1/models/list", (req, res) => res.json({ data: availableModels.map(m => ({ id: m.id, type: "model", name: m.name, supports_cached_previews: true, supports_system_instructions: true })) }));
205
+ app.get("/v1/models", (req, res) => {
206
+ const aliasModels = Object.keys(modelAliases).map(id => ({
207
+ id,
208
+ type: "model",
209
+ name: id,
210
+ display_name: id,
211
+ supports_cached_previews: true,
212
+ supports_system_instructions: true,
213
+ supports_reasoning: true,
214
+ supports_vision: false
215
+ }));
216
+ const allModels = [...aliasModels, ...availableModels.map(m => ({
217
+ id: m.id,
218
+ type: "model",
219
+ name: m.name,
220
+ display_name: m.name,
221
+ supports_cached_previews: true,
222
+ supports_system_instructions: true,
223
+ supports_reasoning: true,
224
+ supports_vision: false
225
+ }))];
226
+ res.json({ data: allModels });
227
+ });
228
+ app.get("/v1/models/list", (req, res) => {
229
+ const aliasModels = Object.keys(modelAliases).map(id => ({
230
+ id,
231
+ type: "model",
232
+ name: id,
233
+ display_name: id,
234
+ supports_cached_previews: true,
235
+ supports_system_instructions: true,
236
+ supports_reasoning: true,
237
+ supports_vision: false
238
+ }));
239
+ const allModels = [...aliasModels, ...availableModels.map(m => ({
240
+ id: m.id,
241
+ type: "model",
242
+ name: m.name,
243
+ display_name: m.name,
244
+ supports_cached_previews: true,
245
+ supports_system_instructions: true,
246
+ supports_reasoning: true,
247
+ supports_vision: false
248
+ }))];
249
+ res.json({ data: allModels });
250
+ });
171
251
  app.post("/v1/messages", async (req, res) => {
172
252
  try {
253
+ const requestedModel = req.body?.model || currentModel;
254
+ const actualModel = modelAliases[requestedModel] || requestedModel;
255
+ if (modelAliases[requestedModel]) {
256
+ currentModel = modelAliases[requestedModel];
257
+ }
173
258
  if (req.body?.max_tokens === undefined && req.body?.messages) {
174
259
  let totalTokens = 0;
175
260
  for (const msg of req.body.messages) {
@@ -182,7 +267,7 @@ app.post("/v1/messages", async (req, res) => {
182
267
  const { text, tokens } = await sendMessage(currentSessionId, req.body.messages);
183
268
  totalRequests++;
184
269
  totalTokensUsed += tokens;
185
- res.json({ id: `msg_${Date.now()}`, type: "message", role: "assistant", content: [{ type: "text", text }], model: currentModel, stop_reason: "end_turn", usage: { input_tokens: Math.ceil(JSON.stringify(req.body.messages).length / 4), output_tokens: Math.ceil(text.length / 4) } });
270
+ res.json({ id: `msg_${Date.now()}`, type: "message", role: "assistant", content: [{ type: "text", text }], model: actualModel, stop_reason: "end_turn", usage: { input_tokens: Math.ceil(JSON.stringify(req.body.messages).length / 4), output_tokens: Math.ceil(text.length / 4) } });
186
271
  }
187
272
  catch (error) {
188
273
  res.status(500).json({ error: { type: "api_error", message: error instanceof Error ? error.message : String(error) } });
@@ -197,309 +282,232 @@ app.post("/v1/messages/count_tokens", (req, res) => {
197
282
  const PORT = PROXY_PORT;
198
283
  function generateHTML() {
199
284
  return `<!DOCTYPE html>
200
- <html lang="en">
285
+ <html lang="en" data-theme="dark" class="dark">
201
286
  <head>
202
287
  <meta charset="UTF-8">
203
288
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
204
289
  <title>OCB - OpenCode Bridge</title>
205
290
  <script src="https://cdn.tailwindcss.com"></script>
291
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
206
292
  <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
293
+ <script>
294
+ tailwind.config = {
295
+ theme: {
296
+ extend: {
297
+ colors: {
298
+ space: { 950: '#0a0a0f', 900: '#121218', 800: '#1a1a24', 700: '#24242e', border: '#2a2a38' },
299
+ neon: { purple: '#a855f7', cyan: '#22d3ee', green: '#22c55e', pink: '#ec4899' }
300
+ },
301
+ fontFamily: { sans: ['Inter', 'sans-serif'], mono: ['JetBrains Mono', 'monospace'] }
302
+ }
303
+ }
304
+ }
305
+ </script>
207
306
  <style>
208
307
  * { box-sizing: border-box; margin: 0; padding: 0; }
209
- body { font-family: 'Inter', -apple-system, sans-serif; background: #0f0f11; color: #fafafa; min-height: 100vh; }
308
+ body { font-family: 'Inter', -apple-system, sans-serif; background: #0a0a0f; color: #e4e4e7; min-height: 100vh; }
309
+ [x-cloak] { display: none !important; }
210
310
  ::-webkit-scrollbar { width: 6px; }
211
311
  ::-webkit-scrollbar-track { background: transparent; }
212
312
  ::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 3px; }
213
- .tab-active { background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); color: white; }
214
- .model-card:hover { transform: translateY(-2px); box-shadow: 0 8px 25px -5px rgba(99, 102, 241, 0.3); }
313
+ .nav-item { transition: all 0.2s; }
314
+ .nav-item.active { background: linear-gradient(90deg, rgba(168,85,247,0.2) 0%, transparent 100%); border-left: 2px solid #a855f7; color: white; }
215
315
  </style>
216
316
  </head>
217
- <body>
218
- <div class="min-h-screen flex flex-col">
219
- <header class="bg-[#18181b] border-b border-zinc-800 px-6 py-4">
220
- <div class="max-w-7xl mx-auto flex items-center justify-between">
221
- <div class="flex items-center gap-4">
222
- <div class="w-12 h-12 bg-gradient-to-br from-indigo-500 to-purple-600 rounded-2xl flex items-center justify-center text-2xl shadow-lg shadow-indigo-500/20">⚡</div>
223
- <div>
224
- <h1 class="text-2xl font-bold bg-gradient-to-r from-white to-zinc-400 bg-clip-text text-transparent">OCB</h1>
225
- <p class="text-xs text-zinc-500 font-medium">OpenCode Bridge</p>
226
- </div>
227
- <div class="ml-8 flex items-center gap-2 px-4 py-2 bg-zinc-900 rounded-xl border border-zinc-800">
228
- <div id="healthDot" class="w-2.5 h-2.5 bg-green-500 rounded-full animate-pulse"></div>
229
- <span id="connectionStatus" class="text-sm text-zinc-300">Connected</span>
230
- </div>
231
- </div>
232
- <div class="flex items-center gap-3">
233
- <div class="text-right mr-4">
234
- <p class="text-xs text-zinc-500">Current Model</p>
235
- <p id="currentModelDisplay" class="text-sm font-medium text-white">Loading...</p>
236
- </div>
237
- <button onclick="refreshModels()" class="p-2.5 bg-zinc-800 hover:bg-zinc-700 rounded-xl transition text-zinc-300 hover:text-white" title="Refresh Models">
238
- <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path></svg>
239
- </button>
240
- </div>
317
+ <body class="overflow-hidden" x-data="app()" x-init="init()">
318
+ <div class="h-14 border-b border-space-border flex items-center px-4 justify-between bg-space-900/80 backdrop-blur-md">
319
+ <div class="flex items-center gap-3">
320
+ <div class="w-8 h-8 rounded-lg bg-gradient-to-br from-neon-purple to-blue-600 flex items-center justify-center text-white font-bold shadow-lg shadow-neon-purple/20">OC</div>
321
+ <div class="flex flex-col">
322
+ <span class="text-sm font-bold tracking-wide text-white">OCB</span>
323
+ <span class="text-[10px] text-gray-500 font-mono">OPENCODE BRIDGE</span>
241
324
  </div>
242
- </header>
243
-
244
- <nav class="bg-[#18181b] border-b border-zinc-800 px-6">
245
- <div class="max-w-7xl mx-auto flex gap-1">
246
- <button onclick="switchTab('models')" id="tab-models" class="px-5 py-3 text-sm font-medium rounded-t-xl transition-all tab-active">Models</button>
247
- <button onclick="switchTab('status')" id="tab-status" class="px-5 py-3 text-sm font-medium rounded-t-xl transition-all text-zinc-400 hover:bg-zinc-800">Status</button>
248
- <button onclick="switchTab('settings')" id="tab-settings" class="px-5 py-3 text-sm font-medium rounded-t-xl transition-all text-zinc-400 hover:bg-zinc-800">Settings</button>
325
+ </div>
326
+ <div class="flex items-center gap-4">
327
+ <div class="flex items-center gap-2 px-3 py-1 rounded-full text-xs font-mono border transition-all" :class="connected ? 'bg-neon-green/10 border-neon-green/20 text-neon-green' : 'bg-red-500/10 border-red-500/20 text-red-400'">
328
+ <div class="w-1.5 h-1.5 rounded-full" :class="connected ? 'bg-neon-green shadow-lg shadow-neon-green/50' : 'bg-red-400'"></div>
329
+ <span x-text="connected ? 'Connected' : 'Disconnected'"></span>
249
330
  </div>
250
- </nav>
251
-
252
- <main class="flex-1 max-w-7xl mx-auto w-full p-6">
253
- <div id="models-view" class="flex gap-6 h-[calc(100vh-220px)]">
254
- <aside class="w-72 bg-[#18181b] rounded-2xl border border-zinc-800 flex flex-col overflow-hidden">
255
- <div class="p-4 border-b border-zinc-800">
256
- <div class="relative">
257
- <input type="text" id="searchInput" placeholder="Search models..." oninput="filterData()" class="w-full px-4 py-2.5 bg-zinc-900 border border-zinc-700 rounded-xl text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-indigo-500 focus:ring-2 focus:ring-indigo-500/20">
258
- </div>
259
- </div>
260
- <div id="providerList" class="flex-1 overflow-y-auto p-2"></div>
261
- </aside>
262
- <section class="flex-1 overflow-y-auto">
263
- <div class="flex items-center justify-between mb-4">
264
- <h2 id="sectionTitle" class="text-lg font-semibold text-white">All Models</h2>
265
- <span id="modelCount" class="text-sm text-zinc-500"></span>
266
- </div>
267
- <div id="modelGrid" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"></div>
268
- </section>
331
+ <button @click="refresh()" class="p-2 hover:bg-white/5 rounded-lg transition text-gray-400">
332
+ <svg class="w-4 h-4" :class="{'animate-spin': loading}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path></svg>
333
+ </button>
334
+ </div>
335
+ </div>
336
+ <div class="flex h-[calc(100vh-56px)]">
337
+ <nav class="w-56 bg-space-900 border-r border-space-border flex flex-col">
338
+ <div class="p-4 space-y-1">
339
+ <button @click="tab='dashboard'" class="nav-item w-full flex items-center gap-3 px-4 py-2.5 rounded-lg text-sm font-medium" :class="tab==='dashboard'?'active':''">
340
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"></path></svg>
341
+ Dashboard
342
+ </button>
343
+ <button @click="tab='models'" class="nav-item w-full flex items-center gap-3 px-4 py-2.5 rounded-lg text-sm font-medium" :class="tab==='models'?'active':''">
344
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path></svg>
345
+ Models
346
+ </button>
347
+ <button @click="tab='settings'" class="nav-item w-full flex items-center gap-3 px-4 py-2.5 rounded-lg text-sm font-medium" :class="tab==='settings'?'active':''">
348
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path></svg>
349
+ Settings
350
+ </button>
269
351
  </div>
270
-
271
- <div id="status-view" class="hidden space-y-6">
272
- <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
273
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
274
- <div class="flex items-center gap-3 mb-4">
275
- <div class="w-10 h-10 bg-indigo-500/20 rounded-xl flex items-center justify-center text-indigo-400">📊</div>
276
- <div>
277
- <p class="text-xs text-zinc-500">Total Requests</p>
278
- <p id="totalRequests" class="text-2xl font-bold text-white">0</p>
279
- </div>
352
+ <div class="mt-auto p-4 border-t border-space-border">
353
+ <div class="text-xs text-gray-500 font-mono">
354
+ <div class="flex justify-between mb-1"><span>Port:</span><span class="text-gray-400">8300</span></div>
355
+ <div class="flex justify-between"><span>OpenCode:</span><span class="text-neon-green">localhost:4096</span></div>
356
+ </div>
357
+ </div>
358
+ </nav>
359
+ <main class="flex-1 overflow-auto bg-space-950 p-6">
360
+ <div x-show="tab==='dashboard'" x-transition>
361
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
362
+ <div class="bg-space-900 rounded-xl border border-space-border p-5">
363
+ <div class="flex items-center gap-3 mb-3">
364
+ <div class="w-10 h-10 bg-neon-purple/20 rounded-xl flex items-center justify-center text-neon-purple">📊</div>
365
+ <div><p class="text-xs text-gray-500">Total Requests</p><p class="text-2xl font-bold text-white" x-text="stats.requests.toLocaleString()">0</p></div>
280
366
  </div>
281
367
  </div>
282
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
283
- <div class="flex items-center gap-3 mb-4">
284
- <div class="w-10 h-10 bg-purple-500/20 rounded-xl flex items-center justify-center text-purple-400">🎯</div>
285
- <div>
286
- <p class="text-xs text-zinc-500">Total Tokens</p>
287
- <p id="totalTokens" class="text-2xl font-bold text-white">0</p>
288
- </div>
368
+ <div class="bg-space-900 rounded-xl border border-space-border p-5">
369
+ <div class="flex items-center gap-3 mb-3">
370
+ <div class="w-10 h-10 bg-neon-cyan/20 rounded-xl flex items-center justify-center text-neon-cyan">🎯</div>
371
+ <div><p class="text-xs text-gray-500">Total Tokens</p><p class="text-2xl font-bold text-white" x-text="stats.tokens.toLocaleString()">0</p></div>
289
372
  </div>
290
373
  </div>
291
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
292
- <div class="flex items-center gap-3 mb-4">
293
- <div class="w-10 h-10 bg-green-500/20 rounded-xl flex items-center justify-center text-green-400">🔗</div>
294
- <div>
295
- <p class="text-xs text-zinc-500">Session</p>
296
- <p id="sessionStatus" class="text-lg font-semibold text-green-400">Active</p>
297
- </div>
374
+ <div class="bg-space-900 rounded-xl border border-space-border p-5">
375
+ <div class="flex items-center gap-3 mb-3">
376
+ <div class="w-10 h-10 bg-neon-green/20 rounded-xl flex items-center justify-center text-neon-green">🤖</div>
377
+ <div><p class="text-xs text-gray-500">Active Model</p><p class="text-lg font-semibold text-white truncate" x-text="currentModelName">-</p></div>
298
378
  </div>
299
379
  </div>
300
380
  </div>
301
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
302
- <h3 class="text-lg font-semibold text-white mb-4">Model Usage</h3>
303
- <div class="space-y-3">
304
- <div class="flex justify-between items-center py-2 border-b border-zinc-800">
305
- <span class="text-zinc-400">Active Model</span>
306
- <span id="activeModelName" class="text-white font-medium">-</span>
307
- </div>
308
- <div class="flex justify-between items-center py-2 border-b border-zinc-800">
309
- <span class="text-zinc-400">Available Models</span>
310
- <span id="totalModelsDisplay" class="text-white font-medium">-</span>
311
- </div>
312
- <div class="flex justify-between items-center py-2 border-b border-zinc-800">
313
- <span class="text-zinc-400">Providers</span>
314
- <span id="totalProviders" class="text-white font-medium">-</span>
315
- </div>
316
- <div class="flex justify-between items-center py-2">
317
- <span class="text-zinc-400">OpenCode Server</span>
318
- <span class="text-green-400 font-medium">localhost:4096</span>
319
- </div>
381
+ <div class="bg-space-900 rounded-xl border border-space-border p-5">
382
+ <h3 class="text-lg font-semibold text-white mb-4">Current Session</h3>
383
+ <div class="grid grid-cols-2 gap-4 text-sm">
384
+ <div class="flex justify-between py-2 border-b border-space-border"><span class="text-gray-500">Session ID</span><span class="text-gray-300 font-mono text-xs" x-text="stats.sessionId || 'inactive'">-</span></div>
385
+ <div class="flex justify-between py-2 border-b border-space-border"><span class="text-gray-500">Status</span><span class="text-neon-green" x-text="stats.sessionId ? 'Active' : 'Inactive'">-</span></div>
386
+ <div class="flex justify-between py-2 border-b border-space-border"><span class="text-gray-500">Models Available</span><span class="text-gray-300" x-text="stats.models">0</span></div>
387
+ <div class="flex justify-between py-2 border-b border-space-border"><span class="text-gray-500">Providers</span><span class="text-gray-300" x-text="stats.providers">0</span></div>
320
388
  </div>
389
+ <div class="mt-4 flex gap-3">
390
+ <button @click="resetSession()" class="px-4 py-2 bg-space-700 hover:bg-space-600 rounded-lg text-sm transition">Reset Session</button>
391
+ <button @click="refreshModels()" class="px-4 py-2 bg-space-700 hover:bg-space-600 rounded-lg text-sm transition">Refresh Models</button>
392
+ </div>
393
+ </div>
394
+ </div>
395
+ <div x-show="tab==='models'" x-transition style="display:none;">
396
+ <div class="mb-4 flex gap-4">
397
+ <input type="text" x-model="search" @input="filterModels()" placeholder="Search models..." class="flex-1 px-4 py-2.5 bg-space-900 border border-space-border rounded-xl text-white placeholder-gray-500 focus:outline-none focus:border-neon-purple">
398
+ <select x-model="selectedProvider" @change="filterModels()" class="px-4 py-2.5 bg-space-900 border border-space-border rounded-xl text-white focus:outline-none">
399
+ <option value="all">All Providers</option>
400
+ <template x-for="p in providers" :key="p"><option :value="p" x-text="p"></option></template>
401
+ </select>
321
402
  </div>
322
- <div class="flex gap-4">
323
- <button onclick="resetSession()" class="px-6 py-3 bg-zinc-800 hover:bg-zinc-700 rounded-xl text-white font-medium transition">Reset Session</button>
324
- <button onclick="resetStats()" class="px-6 py-3 bg-zinc-800 hover:bg-zinc-700 rounded-xl text-white font-medium transition">Reset Stats</button>
403
+ <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3 max-h-[calc(100vh-220px)] overflow-y-auto">
404
+ <template x-for="m in filteredModels" :key="m.id">
405
+ <div @click="selectModel(m.id)" class="p-4 rounded-xl border cursor-pointer transition-all hover:scale-[1.02]" :class="m.id===currentModel?'bg-neon-purple/20 border-neon-purple':'bg-space-900 border-space-border hover:border-space-700'">
406
+ <div class="flex items-start justify-between mb-2">
407
+ <h3 class="font-semibold text-white truncate" x-text="m.name"></h3>
408
+ <span x-show="m.id===currentModel" class="text-xs bg-neon-purple text-white px-2 py-0.5 rounded">Active</span>
409
+ </div>
410
+ <p class="text-xs text-gray-500 font-mono truncate mb-2" x-text="m.id"></p>
411
+ <p class="text-xs text-gray-600" x-text="m.provider"></p>
412
+ </div>
413
+ </template>
325
414
  </div>
326
415
  </div>
327
-
328
- <div id="settings-view" class="hidden space-y-6">
329
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
416
+ <div x-show="tab==='settings'" x-transition style="display:none;">
417
+ <div class="bg-space-900 rounded-xl border border-space-border p-6 mb-4">
330
418
  <h3 class="text-lg font-semibold text-white mb-4">Claude Code Configuration</h3>
331
- <p class="text-zinc-400 text-sm mb-4">Add this to your Claude Code settings to use OCB:</p>
332
- <div class="bg-zinc-950 rounded-xl p-4 font-mono text-sm text-zinc-300 overflow-x-auto">
333
- <pre id="configJson">{
334
- "env": {
335
- "ANTHROPIC_BASE_URL": "http://localhost:8300/v1",
336
- "ANTHROPIC_AUTH_TOKEN": "test",
337
- "ANTHROPIC_MODEL": "minimax-m2.5-free"
338
- }
339
- }</pre>
419
+ <p class="text-gray-400 text-sm mb-4">Configure Claude Code to use OCB as the API endpoint:</p>
420
+ <div class="bg-space-950 rounded-xl p-4 font-mono text-sm text-gray-300 overflow-x-auto mb-4">
421
+ <pre x-text="configJson"></pre>
340
422
  </div>
341
- <button onclick="copyConfig()" class="mt-4 px-6 py-2.5 bg-indigo-600 hover:bg-indigo-500 rounded-xl text-white font-medium transition flex items-center gap-2">
342
- <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
343
- Copy Config
423
+ <button @click="applyToClaude()" class="px-6 py-2.5 bg-neon-purple hover:bg-neon-purple/80 rounded-xl text-white font-medium transition flex items-center gap-2">
424
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>
425
+ Apply to Claude Code
344
426
  </button>
345
427
  </div>
346
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
428
+ <div class="bg-space-900 rounded-xl border border-space-border p-6">
347
429
  <h3 class="text-lg font-semibold text-white mb-4">API Endpoints</h3>
348
430
  <div class="space-y-2 font-mono text-sm">
349
- <div class="flex justify-between py-2 border-b border-zinc-800"><span class="text-zinc-400">Health</span><span class="text-indigo-400">http://localhost:8300/health</span></div>
350
- <div class="flex justify-between py-2 border-b border-zinc-800"><span class="text-zinc-400">Status</span><span class="text-indigo-400">http://localhost:8300/api/status</span></div>
351
- <div class="flex justify-between py-2 border-b border-zinc-800"><span class="text-zinc-400">Models</span><span class="text-indigo-400">http://localhost:8300/api/models</span></div>
352
- <div class="flex justify-between py-2 border-b border-zinc-800"><span class="text-zinc-400">Set Model</span><span class="text-indigo-400">POST /api/model</span></div>
353
- <div class="flex justify-between py-2"><span class="text-zinc-400">Messages</span><span class="text-indigo-400">http://localhost:8300/v1/messages</span></div>
431
+ <div class="flex justify-between py-2 border-b border-space-border"><span class="text-gray-500">Health</span><span class="text-neon-cyan">/health</span></div>
432
+ <div class="flex justify-between py-2 border-b border-space-border"><span class="text-gray-500">Status</span><span class="text-neon-cyan">/api/status</span></div>
433
+ <div class="flex justify-between py-2 border-b border-space-border"><span class="text-gray-500">Models</span><span class="text-neon-cyan">/v1/models</span></div>
434
+ <div class="flex justify-between py-2 border-b border-space-border"><span class="text-gray-500">Messages</span><span class="text-neon-cyan">/v1/messages</span></div>
354
435
  </div>
355
436
  </div>
356
437
  </div>
357
438
  </main>
358
-
359
- <footer class="bg-[#18181b] border-t border-zinc-800 px-6 py-3">
360
- <div class="max-w-7xl mx-auto flex items-center justify-between text-sm text-zinc-500">
361
- <div class="flex items-center gap-6">
362
- <span>OCB v1.0.1</span>
363
- <span>Proxy Port: <span class="text-white">8300</span></span>
364
- </div>
365
- <span>OpenCode Bridge for Claude Code</span>
366
- </div>
367
- </footer>
368
439
  </div>
369
440
  <script>
370
- let allModels = [];
371
- let groupedModels = {};
372
- let currentProvider = 'all';
373
- let currentModelId = null;
374
-
375
- function switchTab(tab) {
376
- document.querySelectorAll('[id^="tab-"]').forEach(el => {
377
- el.classList.remove('tab-active');
378
- el.classList.add('text-zinc-400', 'hover:bg-zinc-800');
379
- });
380
- document.getElementById('tab-' + tab).classList.add('tab-active');
381
- document.getElementById('tab-' + tab).classList.remove('text-zinc-400', 'hover:bg-zinc-800');
382
-
383
- document.getElementById('models-view').classList.add('hidden');
384
- document.getElementById('status-view').classList.add('hidden');
385
- document.getElementById('settings-view').classList.add('hidden');
386
- document.getElementById(tab + '-view').classList.remove('hidden');
387
- }
388
-
389
- function copyConfig() {
390
- const config = document.getElementById('configJson').textContent;
391
- navigator.clipboard.writeText(config);
392
- alert('Config copied to clipboard!');
393
- }
394
-
395
- async function resetStats() {
396
- await fetch('/api/reset-stats', { method: 'POST' });
397
- loadStatus();
398
- }
399
-
400
- async function loadModels() {
401
- const res = await fetch('/api/models');
402
- const data = await res.json();
403
- allModels = data.models || [];
404
- groupedModels = data.grouped || {};
405
- renderProviders();
406
- renderModels(allModels);
407
- updateStats();
408
- }
409
-
410
- function renderProviders() {
411
- const container = document.getElementById('providerList');
412
- const searchTerm = document.getElementById('searchInput').value.toLowerCase();
413
- let providersToShow = Object.entries(groupedModels);
414
- if (searchTerm) {
415
- providersToShow = providersToShow.filter(([name, models]) => name.toLowerCase().includes(searchTerm) || models.some(m => m.name.toLowerCase().includes(searchTerm)));
416
- }
417
- let html = '<div onclick="selectProvider('all')" class="px-3 py-2.5 rounded-xl cursor-pointer flex items-center justify-between text-sm mb-1 ' + (currentProvider === 'all' ? 'bg-indigo-600 text-white' : 'text-zinc-400 hover:bg-zinc-800') + '"><span>🏠 All Models</span><span class="text-xs opacity-60 bg-zinc-800 px-2 py-0.5 rounded-full">' + allModels.length + '</span></div>';
418
- for (const [provider, models] of providersToShow) {
419
- html += '<div onclick="selectProvider(\\'' + provider.replace(/'/g, "\\\\'") + '\\')" class="px-3 py-2.5 rounded-xl cursor-pointer flex items-center justify-between text-sm mb-1 ' + (currentProvider === provider ? 'bg-indigo-600 text-white' : 'text-zinc-400 hover:bg-zinc-800') + '"><span class="truncate">' + provider + '</span><span class="text-xs opacity-60 bg-zinc-800 px-2 py-0.5 rounded-full">' + models.length + '</span></div>';
420
- }
421
- container.innerHTML = html;
422
- }
423
-
424
- function selectProvider(provider) {
425
- currentProvider = provider;
426
- document.getElementById('sectionTitle').textContent = provider === 'all' ? 'All Models' : provider;
427
- renderProviders();
428
- renderModels(provider === 'all' ? allModels : (groupedModels[provider] || []));
429
- }
430
-
431
- function renderModels(models) {
432
- const container = document.getElementById('modelGrid');
433
- const searchTerm = document.getElementById('searchInput').value.toLowerCase();
434
- let filtered = models;
435
- if (searchTerm) {
436
- filtered = models.filter(m => m.name.toLowerCase().includes(searchTerm) || m.id.toLowerCase().includes(searchTerm));
437
- }
438
- document.getElementById('modelCount').textContent = filtered.length + ' models';
439
- if (filtered.length === 0) {
440
- container.innerHTML = '<div class="col-span-full text-center text-zinc-500 py-12">No models found</div>';
441
- return;
442
- }
443
- container.innerHTML = filtered.slice(0, 100).map(m => '<div onclick="selectModel(\\'' + m.id.replace(/'/g, "\\\\'") + '\\')" class="model-card p-5 rounded-2xl border cursor-pointer transition-all ' + (m.id === currentModelId ? 'bg-indigo-600/20 border-indigo-500 shadow-lg shadow-indigo-500/20' : 'bg-[#18181b] border-zinc-800 hover:border-zinc-700') + '"><div class="flex items-start justify-between mb-3"><h3 class="font-semibold text-white truncate text-base">' + m.name + '</h3>' + (m.id === currentModelId ? '<span class="text-xs bg-indigo-500 text-white px-3 py-1 rounded-full font-medium">Active</span>' : '') + '</div><p class="text-xs text-zinc-500 font-mono truncate mb-3">' + m.id + '</p>' + (m.cost ? '<div class="flex items-center gap-2 text-xs text-zinc-400"><span class="bg-zinc-800 px-2 py-1 rounded">$' + m.cost.input + '/M</span><span>→</span><span class="bg-zinc-800 px-2 py-1 rounded">$' + m.cost.output + '/M</span></div>' : '<div class="text-xs text-zinc-600">Free</div>') + '</div>').join('');
444
- }
445
-
446
- function filterData() {
447
- const searchTerm = document.getElementById('searchInput').value.toLowerCase();
448
- if (searchTerm) {
449
- const filtered = allModels.filter(m => m.name.toLowerCase().includes(searchTerm) || m.id.toLowerCase().includes(searchTerm));
450
- document.getElementById('sectionTitle').textContent = 'Search Results (' + filtered.length + ')';
451
- renderModels(filtered);
452
- renderProviders();
453
- } else {
454
- selectProvider(currentProvider);
455
- }
456
- }
457
-
458
- async function selectModel(modelId) {
459
- const res = await fetch('/api/model', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ modelId }) });
460
- const data = await res.json();
461
- if (data.success) {
462
- currentModelId = modelId;
463
- loadStatus();
464
- renderModels(currentProvider === 'all' ? allModels : (groupedModels[currentProvider] || []));
465
- document.getElementById('configJson').textContent = JSON.stringify({ env: { ANTHROPIC_BASE_URL: "http://localhost:8300/v1", ANTHROPIC_AUTH_TOKEN: "test", ANTHROPIC_MODEL: modelId } }, null, 2);
466
- }
467
- }
468
-
469
- async function loadStatus() {
470
- const res = await fetch('/api/status');
471
- const data = await res.json();
472
- const model = allModels.find(m => m.id === data.currentModel);
473
- document.getElementById('currentModelDisplay').textContent = model?.name || data.currentModel;
474
- document.getElementById('healthDot').className = 'w-2.5 h-2.5 rounded-full animate-pulse ' + (data.sessionId === 'active' ? 'bg-green-500' : 'bg-red-500');
475
- document.getElementById('connectionStatus').textContent = data.sessionId === 'active' ? 'Connected' : 'Disconnected';
476
- document.getElementById('totalRequests').textContent = data.totalRequests.toLocaleString();
477
- document.getElementById('totalTokens').textContent = data.totalTokensUsed.toLocaleString();
478
- document.getElementById('sessionStatus').textContent = data.sessionId === 'active' ? 'Active' : 'Inactive';
479
- document.getElementById('sessionStatus').className = 'text-lg font-semibold ' + (data.sessionId === 'active' ? 'text-green-400' : 'text-red-400');
480
- document.getElementById('activeModelName').textContent = model?.name || data.currentModel;
481
- document.getElementById('totalModelsDisplay').textContent = allModels.length + ' models';
482
- document.getElementById('totalProviders').textContent = Object.keys(groupedModels).length + ' providers';
483
- currentModelId = data.currentModel;
484
- }
485
-
486
- async function resetSession() {
487
- await fetch('/api/reset-session', { method: 'POST' });
488
- loadStatus();
489
- }
490
-
491
- async function refreshModels() {
492
- await fetch('/api/refresh-models', { method: 'POST' });
493
- loadModels();
494
- }
495
-
496
- function updateStats() {
497
- document.getElementById('totalModelsDisplay').textContent = allModels.length + ' models from ' + Object.keys(groupedModels).length + ' providers';
441
+ function app() {
442
+ return {
443
+ tab: 'dashboard',
444
+ loading: false,
445
+ connected: false,
446
+ search: '',
447
+ selectedProvider: 'all',
448
+ models: [],
449
+ providers: [],
450
+ filteredModels: [],
451
+ currentModel: '',
452
+ currentModelName: '',
453
+ stats: { requests: 0, tokens: 0, sessionId: '', models: 0, providers: 0 },
454
+ configJson: '',
455
+ async init() {
456
+ await this.refresh();
457
+ setInterval(() => this.refresh(), 3000);
458
+ },
459
+ async refresh() {
460
+ this.loading = true;
461
+ try {
462
+ const [statusRes, modelsRes] = await Promise.all([fetch('/api/status'), fetch('/api/models')]);
463
+ const status = await statusRes.json();
464
+ const modelsData = await modelsRes.json();
465
+ this.connected = status.sessionId === 'active';
466
+ this.stats = { requests: status.totalRequests, tokens: status.totalTokensUsed, sessionId: status.sessionId, models: modelsData.models?.length || 0, providers: modelsData.providers?.length || 0 };
467
+ this.currentModel = status.currentModel;
468
+ this.models = modelsData.models || [];
469
+ this.providers = [...new Set(this.models.map(m => m.provider))].sort();
470
+ const current = this.models.find(m => m.id === this.currentModel);
471
+ this.currentModelName = current?.name || this.currentModel;
472
+ this.filterModels();
473
+ this.updateConfig();
474
+ } catch (e) { console.error(e); }
475
+ this.loading = false;
476
+ },
477
+ filterModels() {
478
+ let filtered = this.models;
479
+ if (this.selectedProvider !== 'all') filtered = filtered.filter(m => m.provider === this.selectedProvider);
480
+ if (this.search) {
481
+ const s = this.search.toLowerCase();
482
+ filtered = filtered.filter(m => m.name.toLowerCase().includes(s) || m.id.toLowerCase().includes(s));
483
+ }
484
+ this.filteredModels = filtered.slice(0, 100);
485
+ },
486
+ async selectModel(modelId) {
487
+ await fetch('/api/model', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ modelId }) });
488
+ this.currentModel = modelId;
489
+ this.refresh();
490
+ },
491
+ async resetSession() {
492
+ await fetch('/api/reset-session', { method: 'POST' });
493
+ this.refresh();
494
+ },
495
+ async refreshModels() {
496
+ await fetch('/api/refresh-models', { method: 'POST' });
497
+ this.refresh();
498
+ },
499
+ updateConfig() {
500
+ this.configJson = JSON.stringify({ env: { ANTHROPIC_BASE_URL: 'http://localhost:8300', ANTHROPIC_API_KEY: 'test', ANTHROPIC_MODEL: this.currentModel } }, null, 2);
501
+ },
502
+ async applyToClaude() {
503
+ try {
504
+ const response = await fetch('/api/apply-claude-config', { method: 'POST' });
505
+ const data = await response.json();
506
+ alert(data.success ? 'Applied to Claude Code! Restart Claude Code to use.' : 'Failed: ' + data.error);
507
+ } catch (e) { alert('Error: ' + e.message); }
508
+ }
509
+ };
498
510
  }
499
-
500
- loadModels();
501
- loadStatus();
502
- setInterval(loadStatus, 3000);
503
511
  </script>
504
512
  </body>
505
513
  </html>`;