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/src/proxy.ts CHANGED
@@ -139,7 +139,8 @@ app.use(express.json());
139
139
  app.use((req, res, next) => {
140
140
  res.header("Access-Control-Allow-Origin", "*");
141
141
  res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
142
- res.header("Access-Control-Allow-Headers", "Content-Type, Authorization");
142
+ res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, x-api-key");
143
+ res.header("Content-Type", "application/json");
143
144
  if (req.method === "OPTIONS") return res.sendStatus(200);
144
145
  next();
145
146
  });
@@ -187,12 +188,46 @@ app.post("/api/refresh-models", async (req, res) => {
187
188
  res.json({ success: true, count: availableModels.length });
188
189
  });
189
190
 
191
+ app.post("/api/apply-claude-config", async (req, res) => {
192
+ try {
193
+ const { readFileSync, writeFileSync, existsSync, mkdirSync } = await import("fs");
194
+ const { join, dirname } = await import("path");
195
+ const homedir = process.env.USERPROFILE || process.env.HOME || process.env.HOMEPATH || "";
196
+ const settingsPath = join(homedir, ".claude", "settings.json");
197
+ const settingsDir = dirname(settingsPath);
198
+ if (!existsSync(settingsDir)) mkdirSync(settingsDir, { recursive: true });
199
+ let settings: any = {};
200
+ if (existsSync(settingsPath)) settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
201
+ settings.env = settings.env || {};
202
+ settings.env.ANTHROPIC_BASE_URL = "http://localhost:8300";
203
+ settings.env.ANTHROPIC_API_KEY = "test";
204
+ settings.env.ANTHROPIC_MODEL = currentModel;
205
+ writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
206
+ res.json({ success: true });
207
+ } catch (e) {
208
+ res.status(500).json({ success: false, error: e instanceof Error ? e.message : String(e) });
209
+ }
210
+ });
211
+
190
212
  app.post("/api/reset-stats", (req, res) => {
191
213
  totalTokensUsed = 0;
192
214
  totalRequests = 0;
193
215
  res.json({ success: true });
194
216
  });
195
217
 
218
+ const modelAliases: Record<string, string> = {
219
+ "claude-opus-4-5": "opencode/minimax-m2.5-free",
220
+ "claude-opus-4-5-thinking": "opencode/minimax-m2.5-free",
221
+ "claude-opus-4-6": "opencode/minimax-m2.5-free",
222
+ "claude-opus-4-6-thinking": "opencode/minimax-m2.5-free",
223
+ "claude-sonnet-4-5": "opencode/minimax-m2.5-free",
224
+ "claude-sonnet-4-5-thinking": "opencode/minimax-m2.5-free",
225
+ "claude-sonnet-4-5-20250929": "opencode/minimax-m2.5-free",
226
+ "claude-sonnet-4-5-20250929-thinking": "opencode/minimax-m2.5-free",
227
+ "claude-haiku-4-5": "opencode/minimax-m2.5-free",
228
+ "claude-haiku-4-5-20251001": "opencode/minimax-m2.5-free",
229
+ };
230
+
196
231
  app.post("/api/reset-session", async (req, res) => {
197
232
  currentSessionId = await createSession(process.cwd());
198
233
  res.json({ success: true, sessionId: currentSessionId });
@@ -201,11 +236,62 @@ app.post("/api/reset-session", async (req, res) => {
201
236
  app.get("/v1/authenticate", (req, res) => res.json({ type: "authentication", authenticated: true }));
202
237
  app.get("/v1/whoami", (req, res) => res.json({ type: "user", id: "opencode-user", email: "opencode@local" }));
203
238
 
204
- 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 })) }));
205
- 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 })) }));
239
+ app.get("/v1/models", (req, res) => {
240
+ const aliasModels = Object.keys(modelAliases).map(id => ({
241
+ id,
242
+ type: "model" as const,
243
+ name: id,
244
+ display_name: id,
245
+ supports_cached_previews: true,
246
+ supports_system_instructions: true,
247
+ supports_reasoning: true,
248
+ supports_vision: false
249
+ }));
250
+ const allModels = [...aliasModels, ...availableModels.map(m => ({
251
+ id: m.id,
252
+ type: "model" as const,
253
+ name: m.name,
254
+ display_name: m.name,
255
+ supports_cached_previews: true,
256
+ supports_system_instructions: true,
257
+ supports_reasoning: true,
258
+ supports_vision: false
259
+ }))];
260
+ res.json({ data: allModels });
261
+ });
262
+ app.get("/v1/models/list", (req, res) => {
263
+ const aliasModels = Object.keys(modelAliases).map(id => ({
264
+ id,
265
+ type: "model" as const,
266
+ name: id,
267
+ display_name: id,
268
+ supports_cached_previews: true,
269
+ supports_system_instructions: true,
270
+ supports_reasoning: true,
271
+ supports_vision: false
272
+ }));
273
+ const allModels = [...aliasModels, ...availableModels.map(m => ({
274
+ id: m.id,
275
+ type: "model" as const,
276
+ name: m.name,
277
+ display_name: m.name,
278
+ supports_cached_previews: true,
279
+ supports_system_instructions: true,
280
+ supports_reasoning: true,
281
+ supports_vision: false
282
+ }))];
283
+ res.json({ data: allModels });
284
+ });
206
285
 
207
286
  app.post("/v1/messages", async (req, res) => {
208
287
  try {
288
+ const requestedModel = req.body?.model || currentModel;
289
+ const actualModel = modelAliases[requestedModel] || requestedModel;
290
+
291
+ if (modelAliases[requestedModel]) {
292
+ currentModel = modelAliases[requestedModel];
293
+ }
294
+
209
295
  if (req.body?.max_tokens === undefined && req.body?.messages) {
210
296
  let totalTokens = 0;
211
297
  for (const msg of req.body.messages) {
@@ -217,7 +303,7 @@ app.post("/v1/messages", async (req, res) => {
217
303
  const { text, tokens } = await sendMessage(currentSessionId, req.body.messages);
218
304
  totalRequests++;
219
305
  totalTokensUsed += tokens;
220
- 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) } });
306
+ 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) } });
221
307
  } catch (error) {
222
308
  res.status(500).json({ error: { type: "api_error", message: error instanceof Error ? error.message : String(error) } });
223
309
  }
@@ -233,309 +319,232 @@ const PORT = PROXY_PORT;
233
319
 
234
320
  function generateHTML() {
235
321
  return `<!DOCTYPE html>
236
- <html lang="en">
322
+ <html lang="en" data-theme="dark" class="dark">
237
323
  <head>
238
324
  <meta charset="UTF-8">
239
325
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
240
326
  <title>OCB - OpenCode Bridge</title>
241
327
  <script src="https://cdn.tailwindcss.com"></script>
328
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
242
329
  <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">
330
+ <script>
331
+ tailwind.config = {
332
+ theme: {
333
+ extend: {
334
+ colors: {
335
+ space: { 950: '#0a0a0f', 900: '#121218', 800: '#1a1a24', 700: '#24242e', border: '#2a2a38' },
336
+ neon: { purple: '#a855f7', cyan: '#22d3ee', green: '#22c55e', pink: '#ec4899' }
337
+ },
338
+ fontFamily: { sans: ['Inter', 'sans-serif'], mono: ['JetBrains Mono', 'monospace'] }
339
+ }
340
+ }
341
+ }
342
+ </script>
243
343
  <style>
244
344
  * { box-sizing: border-box; margin: 0; padding: 0; }
245
- body { font-family: 'Inter', -apple-system, sans-serif; background: #0f0f11; color: #fafafa; min-height: 100vh; }
345
+ body { font-family: 'Inter', -apple-system, sans-serif; background: #0a0a0f; color: #e4e4e7; min-height: 100vh; }
346
+ [x-cloak] { display: none !important; }
246
347
  ::-webkit-scrollbar { width: 6px; }
247
348
  ::-webkit-scrollbar-track { background: transparent; }
248
349
  ::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 3px; }
249
- .tab-active { background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); color: white; }
250
- .model-card:hover { transform: translateY(-2px); box-shadow: 0 8px 25px -5px rgba(99, 102, 241, 0.3); }
350
+ .nav-item { transition: all 0.2s; }
351
+ .nav-item.active { background: linear-gradient(90deg, rgba(168,85,247,0.2) 0%, transparent 100%); border-left: 2px solid #a855f7; color: white; }
251
352
  </style>
252
353
  </head>
253
- <body>
254
- <div class="min-h-screen flex flex-col">
255
- <header class="bg-[#18181b] border-b border-zinc-800 px-6 py-4">
256
- <div class="max-w-7xl mx-auto flex items-center justify-between">
257
- <div class="flex items-center gap-4">
258
- <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>
259
- <div>
260
- <h1 class="text-2xl font-bold bg-gradient-to-r from-white to-zinc-400 bg-clip-text text-transparent">OCB</h1>
261
- <p class="text-xs text-zinc-500 font-medium">OpenCode Bridge</p>
262
- </div>
263
- <div class="ml-8 flex items-center gap-2 px-4 py-2 bg-zinc-900 rounded-xl border border-zinc-800">
264
- <div id="healthDot" class="w-2.5 h-2.5 bg-green-500 rounded-full animate-pulse"></div>
265
- <span id="connectionStatus" class="text-sm text-zinc-300">Connected</span>
266
- </div>
267
- </div>
268
- <div class="flex items-center gap-3">
269
- <div class="text-right mr-4">
270
- <p class="text-xs text-zinc-500">Current Model</p>
271
- <p id="currentModelDisplay" class="text-sm font-medium text-white">Loading...</p>
272
- </div>
273
- <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">
274
- <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>
275
- </button>
276
- </div>
354
+ <body class="overflow-hidden" x-data="app()" x-init="init()">
355
+ <div class="h-14 border-b border-space-border flex items-center px-4 justify-between bg-space-900/80 backdrop-blur-md">
356
+ <div class="flex items-center gap-3">
357
+ <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>
358
+ <div class="flex flex-col">
359
+ <span class="text-sm font-bold tracking-wide text-white">OCB</span>
360
+ <span class="text-[10px] text-gray-500 font-mono">OPENCODE BRIDGE</span>
277
361
  </div>
278
- </header>
279
-
280
- <nav class="bg-[#18181b] border-b border-zinc-800 px-6">
281
- <div class="max-w-7xl mx-auto flex gap-1">
282
- <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>
283
- <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>
284
- <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>
362
+ </div>
363
+ <div class="flex items-center gap-4">
364
+ <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'">
365
+ <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>
366
+ <span x-text="connected ? 'Connected' : 'Disconnected'"></span>
285
367
  </div>
286
- </nav>
287
-
288
- <main class="flex-1 max-w-7xl mx-auto w-full p-6">
289
- <div id="models-view" class="flex gap-6 h-[calc(100vh-220px)]">
290
- <aside class="w-72 bg-[#18181b] rounded-2xl border border-zinc-800 flex flex-col overflow-hidden">
291
- <div class="p-4 border-b border-zinc-800">
292
- <div class="relative">
293
- <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">
294
- </div>
295
- </div>
296
- <div id="providerList" class="flex-1 overflow-y-auto p-2"></div>
297
- </aside>
298
- <section class="flex-1 overflow-y-auto">
299
- <div class="flex items-center justify-between mb-4">
300
- <h2 id="sectionTitle" class="text-lg font-semibold text-white">All Models</h2>
301
- <span id="modelCount" class="text-sm text-zinc-500"></span>
302
- </div>
303
- <div id="modelGrid" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"></div>
304
- </section>
368
+ <button @click="refresh()" class="p-2 hover:bg-white/5 rounded-lg transition text-gray-400">
369
+ <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>
370
+ </button>
371
+ </div>
372
+ </div>
373
+ <div class="flex h-[calc(100vh-56px)]">
374
+ <nav class="w-56 bg-space-900 border-r border-space-border flex flex-col">
375
+ <div class="p-4 space-y-1">
376
+ <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':''">
377
+ <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>
378
+ Dashboard
379
+ </button>
380
+ <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':''">
381
+ <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>
382
+ Models
383
+ </button>
384
+ <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':''">
385
+ <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>
386
+ Settings
387
+ </button>
305
388
  </div>
306
-
307
- <div id="status-view" class="hidden space-y-6">
308
- <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
309
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
310
- <div class="flex items-center gap-3 mb-4">
311
- <div class="w-10 h-10 bg-indigo-500/20 rounded-xl flex items-center justify-center text-indigo-400">📊</div>
312
- <div>
313
- <p class="text-xs text-zinc-500">Total Requests</p>
314
- <p id="totalRequests" class="text-2xl font-bold text-white">0</p>
315
- </div>
389
+ <div class="mt-auto p-4 border-t border-space-border">
390
+ <div class="text-xs text-gray-500 font-mono">
391
+ <div class="flex justify-between mb-1"><span>Port:</span><span class="text-gray-400">8300</span></div>
392
+ <div class="flex justify-between"><span>OpenCode:</span><span class="text-neon-green">localhost:4096</span></div>
393
+ </div>
394
+ </div>
395
+ </nav>
396
+ <main class="flex-1 overflow-auto bg-space-950 p-6">
397
+ <div x-show="tab==='dashboard'" x-transition>
398
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
399
+ <div class="bg-space-900 rounded-xl border border-space-border p-5">
400
+ <div class="flex items-center gap-3 mb-3">
401
+ <div class="w-10 h-10 bg-neon-purple/20 rounded-xl flex items-center justify-center text-neon-purple">📊</div>
402
+ <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>
316
403
  </div>
317
404
  </div>
318
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
319
- <div class="flex items-center gap-3 mb-4">
320
- <div class="w-10 h-10 bg-purple-500/20 rounded-xl flex items-center justify-center text-purple-400">🎯</div>
321
- <div>
322
- <p class="text-xs text-zinc-500">Total Tokens</p>
323
- <p id="totalTokens" class="text-2xl font-bold text-white">0</p>
324
- </div>
405
+ <div class="bg-space-900 rounded-xl border border-space-border p-5">
406
+ <div class="flex items-center gap-3 mb-3">
407
+ <div class="w-10 h-10 bg-neon-cyan/20 rounded-xl flex items-center justify-center text-neon-cyan">🎯</div>
408
+ <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>
325
409
  </div>
326
410
  </div>
327
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
328
- <div class="flex items-center gap-3 mb-4">
329
- <div class="w-10 h-10 bg-green-500/20 rounded-xl flex items-center justify-center text-green-400">🔗</div>
330
- <div>
331
- <p class="text-xs text-zinc-500">Session</p>
332
- <p id="sessionStatus" class="text-lg font-semibold text-green-400">Active</p>
333
- </div>
411
+ <div class="bg-space-900 rounded-xl border border-space-border p-5">
412
+ <div class="flex items-center gap-3 mb-3">
413
+ <div class="w-10 h-10 bg-neon-green/20 rounded-xl flex items-center justify-center text-neon-green">🤖</div>
414
+ <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>
334
415
  </div>
335
416
  </div>
336
417
  </div>
337
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
338
- <h3 class="text-lg font-semibold text-white mb-4">Model Usage</h3>
339
- <div class="space-y-3">
340
- <div class="flex justify-between items-center py-2 border-b border-zinc-800">
341
- <span class="text-zinc-400">Active Model</span>
342
- <span id="activeModelName" class="text-white font-medium">-</span>
343
- </div>
344
- <div class="flex justify-between items-center py-2 border-b border-zinc-800">
345
- <span class="text-zinc-400">Available Models</span>
346
- <span id="totalModelsDisplay" class="text-white font-medium">-</span>
347
- </div>
348
- <div class="flex justify-between items-center py-2 border-b border-zinc-800">
349
- <span class="text-zinc-400">Providers</span>
350
- <span id="totalProviders" class="text-white font-medium">-</span>
351
- </div>
352
- <div class="flex justify-between items-center py-2">
353
- <span class="text-zinc-400">OpenCode Server</span>
354
- <span class="text-green-400 font-medium">localhost:4096</span>
355
- </div>
418
+ <div class="bg-space-900 rounded-xl border border-space-border p-5">
419
+ <h3 class="text-lg font-semibold text-white mb-4">Current Session</h3>
420
+ <div class="grid grid-cols-2 gap-4 text-sm">
421
+ <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>
422
+ <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>
423
+ <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>
424
+ <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>
425
+ </div>
426
+ <div class="mt-4 flex gap-3">
427
+ <button @click="resetSession()" class="px-4 py-2 bg-space-700 hover:bg-space-600 rounded-lg text-sm transition">Reset Session</button>
428
+ <button @click="refreshModels()" class="px-4 py-2 bg-space-700 hover:bg-space-600 rounded-lg text-sm transition">Refresh Models</button>
356
429
  </div>
357
430
  </div>
358
- <div class="flex gap-4">
359
- <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>
360
- <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>
431
+ </div>
432
+ <div x-show="tab==='models'" x-transition style="display:none;">
433
+ <div class="mb-4 flex gap-4">
434
+ <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">
435
+ <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">
436
+ <option value="all">All Providers</option>
437
+ <template x-for="p in providers" :key="p"><option :value="p" x-text="p"></option></template>
438
+ </select>
439
+ </div>
440
+ <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3 max-h-[calc(100vh-220px)] overflow-y-auto">
441
+ <template x-for="m in filteredModels" :key="m.id">
442
+ <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'">
443
+ <div class="flex items-start justify-between mb-2">
444
+ <h3 class="font-semibold text-white truncate" x-text="m.name"></h3>
445
+ <span x-show="m.id===currentModel" class="text-xs bg-neon-purple text-white px-2 py-0.5 rounded">Active</span>
446
+ </div>
447
+ <p class="text-xs text-gray-500 font-mono truncate mb-2" x-text="m.id"></p>
448
+ <p class="text-xs text-gray-600" x-text="m.provider"></p>
449
+ </div>
450
+ </template>
361
451
  </div>
362
452
  </div>
363
-
364
- <div id="settings-view" class="hidden space-y-6">
365
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
453
+ <div x-show="tab==='settings'" x-transition style="display:none;">
454
+ <div class="bg-space-900 rounded-xl border border-space-border p-6 mb-4">
366
455
  <h3 class="text-lg font-semibold text-white mb-4">Claude Code Configuration</h3>
367
- <p class="text-zinc-400 text-sm mb-4">Add this to your Claude Code settings to use OCB:</p>
368
- <div class="bg-zinc-950 rounded-xl p-4 font-mono text-sm text-zinc-300 overflow-x-auto">
369
- <pre id="configJson">{
370
- "env": {
371
- "ANTHROPIC_BASE_URL": "http://localhost:8300/v1",
372
- "ANTHROPIC_AUTH_TOKEN": "test",
373
- "ANTHROPIC_MODEL": "minimax-m2.5-free"
374
- }
375
- }</pre>
456
+ <p class="text-gray-400 text-sm mb-4">Configure Claude Code to use OCB as the API endpoint:</p>
457
+ <div class="bg-space-950 rounded-xl p-4 font-mono text-sm text-gray-300 overflow-x-auto mb-4">
458
+ <pre x-text="configJson"></pre>
376
459
  </div>
377
- <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">
378
- <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>
379
- Copy Config
460
+ <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">
461
+ <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>
462
+ Apply to Claude Code
380
463
  </button>
381
464
  </div>
382
- <div class="bg-[#18181b] rounded-2xl border border-zinc-800 p-6">
465
+ <div class="bg-space-900 rounded-xl border border-space-border p-6">
383
466
  <h3 class="text-lg font-semibold text-white mb-4">API Endpoints</h3>
384
467
  <div class="space-y-2 font-mono text-sm">
385
- <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>
386
- <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>
387
- <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>
388
- <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>
389
- <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>
468
+ <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>
469
+ <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>
470
+ <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>
471
+ <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>
390
472
  </div>
391
473
  </div>
392
474
  </div>
393
475
  </main>
394
-
395
- <footer class="bg-[#18181b] border-t border-zinc-800 px-6 py-3">
396
- <div class="max-w-7xl mx-auto flex items-center justify-between text-sm text-zinc-500">
397
- <div class="flex items-center gap-6">
398
- <span>OCB v1.0.1</span>
399
- <span>Proxy Port: <span class="text-white">8300</span></span>
400
- </div>
401
- <span>OpenCode Bridge for Claude Code</span>
402
- </div>
403
- </footer>
404
476
  </div>
405
477
  <script>
406
- let allModels = [];
407
- let groupedModels = {};
408
- let currentProvider = 'all';
409
- let currentModelId = null;
410
-
411
- function switchTab(tab) {
412
- document.querySelectorAll('[id^="tab-"]').forEach(el => {
413
- el.classList.remove('tab-active');
414
- el.classList.add('text-zinc-400', 'hover:bg-zinc-800');
415
- });
416
- document.getElementById('tab-' + tab).classList.add('tab-active');
417
- document.getElementById('tab-' + tab).classList.remove('text-zinc-400', 'hover:bg-zinc-800');
418
-
419
- document.getElementById('models-view').classList.add('hidden');
420
- document.getElementById('status-view').classList.add('hidden');
421
- document.getElementById('settings-view').classList.add('hidden');
422
- document.getElementById(tab + '-view').classList.remove('hidden');
423
- }
424
-
425
- function copyConfig() {
426
- const config = document.getElementById('configJson').textContent;
427
- navigator.clipboard.writeText(config);
428
- alert('Config copied to clipboard!');
429
- }
430
-
431
- async function resetStats() {
432
- await fetch('/api/reset-stats', { method: 'POST' });
433
- loadStatus();
434
- }
435
-
436
- async function loadModels() {
437
- const res = await fetch('/api/models');
438
- const data = await res.json();
439
- allModels = data.models || [];
440
- groupedModels = data.grouped || {};
441
- renderProviders();
442
- renderModels(allModels);
443
- updateStats();
444
- }
445
-
446
- function renderProviders() {
447
- const container = document.getElementById('providerList');
448
- const searchTerm = document.getElementById('searchInput').value.toLowerCase();
449
- let providersToShow = Object.entries(groupedModels);
450
- if (searchTerm) {
451
- providersToShow = providersToShow.filter(([name, models]) => name.toLowerCase().includes(searchTerm) || models.some(m => m.name.toLowerCase().includes(searchTerm)));
452
- }
453
- 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>';
454
- for (const [provider, models] of providersToShow) {
455
- 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>';
456
- }
457
- container.innerHTML = html;
458
- }
459
-
460
- function selectProvider(provider) {
461
- currentProvider = provider;
462
- document.getElementById('sectionTitle').textContent = provider === 'all' ? 'All Models' : provider;
463
- renderProviders();
464
- renderModels(provider === 'all' ? allModels : (groupedModels[provider] || []));
465
- }
466
-
467
- function renderModels(models) {
468
- const container = document.getElementById('modelGrid');
469
- const searchTerm = document.getElementById('searchInput').value.toLowerCase();
470
- let filtered = models;
471
- if (searchTerm) {
472
- filtered = models.filter(m => m.name.toLowerCase().includes(searchTerm) || m.id.toLowerCase().includes(searchTerm));
473
- }
474
- document.getElementById('modelCount').textContent = filtered.length + ' models';
475
- if (filtered.length === 0) {
476
- container.innerHTML = '<div class="col-span-full text-center text-zinc-500 py-12">No models found</div>';
477
- return;
478
- }
479
- 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('');
480
- }
481
-
482
- function filterData() {
483
- const searchTerm = document.getElementById('searchInput').value.toLowerCase();
484
- if (searchTerm) {
485
- const filtered = allModels.filter(m => m.name.toLowerCase().includes(searchTerm) || m.id.toLowerCase().includes(searchTerm));
486
- document.getElementById('sectionTitle').textContent = 'Search Results (' + filtered.length + ')';
487
- renderModels(filtered);
488
- renderProviders();
489
- } else {
490
- selectProvider(currentProvider);
491
- }
492
- }
493
-
494
- async function selectModel(modelId) {
495
- const res = await fetch('/api/model', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ modelId }) });
496
- const data = await res.json();
497
- if (data.success) {
498
- currentModelId = modelId;
499
- loadStatus();
500
- renderModels(currentProvider === 'all' ? allModels : (groupedModels[currentProvider] || []));
501
- document.getElementById('configJson').textContent = JSON.stringify({ env: { ANTHROPIC_BASE_URL: "http://localhost:8300/v1", ANTHROPIC_AUTH_TOKEN: "test", ANTHROPIC_MODEL: modelId } }, null, 2);
502
- }
503
- }
504
-
505
- async function loadStatus() {
506
- const res = await fetch('/api/status');
507
- const data = await res.json();
508
- const model = allModels.find(m => m.id === data.currentModel);
509
- document.getElementById('currentModelDisplay').textContent = model?.name || data.currentModel;
510
- document.getElementById('healthDot').className = 'w-2.5 h-2.5 rounded-full animate-pulse ' + (data.sessionId === 'active' ? 'bg-green-500' : 'bg-red-500');
511
- document.getElementById('connectionStatus').textContent = data.sessionId === 'active' ? 'Connected' : 'Disconnected';
512
- document.getElementById('totalRequests').textContent = data.totalRequests.toLocaleString();
513
- document.getElementById('totalTokens').textContent = data.totalTokensUsed.toLocaleString();
514
- document.getElementById('sessionStatus').textContent = data.sessionId === 'active' ? 'Active' : 'Inactive';
515
- document.getElementById('sessionStatus').className = 'text-lg font-semibold ' + (data.sessionId === 'active' ? 'text-green-400' : 'text-red-400');
516
- document.getElementById('activeModelName').textContent = model?.name || data.currentModel;
517
- document.getElementById('totalModelsDisplay').textContent = allModels.length + ' models';
518
- document.getElementById('totalProviders').textContent = Object.keys(groupedModels).length + ' providers';
519
- currentModelId = data.currentModel;
520
- }
521
-
522
- async function resetSession() {
523
- await fetch('/api/reset-session', { method: 'POST' });
524
- loadStatus();
525
- }
526
-
527
- async function refreshModels() {
528
- await fetch('/api/refresh-models', { method: 'POST' });
529
- loadModels();
530
- }
531
-
532
- function updateStats() {
533
- document.getElementById('totalModelsDisplay').textContent = allModels.length + ' models from ' + Object.keys(groupedModels).length + ' providers';
478
+ function app() {
479
+ return {
480
+ tab: 'dashboard',
481
+ loading: false,
482
+ connected: false,
483
+ search: '',
484
+ selectedProvider: 'all',
485
+ models: [],
486
+ providers: [],
487
+ filteredModels: [],
488
+ currentModel: '',
489
+ currentModelName: '',
490
+ stats: { requests: 0, tokens: 0, sessionId: '', models: 0, providers: 0 },
491
+ configJson: '',
492
+ async init() {
493
+ await this.refresh();
494
+ setInterval(() => this.refresh(), 3000);
495
+ },
496
+ async refresh() {
497
+ this.loading = true;
498
+ try {
499
+ const [statusRes, modelsRes] = await Promise.all([fetch('/api/status'), fetch('/api/models')]);
500
+ const status = await statusRes.json();
501
+ const modelsData = await modelsRes.json();
502
+ this.connected = status.sessionId === 'active';
503
+ this.stats = { requests: status.totalRequests, tokens: status.totalTokensUsed, sessionId: status.sessionId, models: modelsData.models?.length || 0, providers: modelsData.providers?.length || 0 };
504
+ this.currentModel = status.currentModel;
505
+ this.models = modelsData.models || [];
506
+ this.providers = [...new Set(this.models.map(m => m.provider))].sort();
507
+ const current = this.models.find(m => m.id === this.currentModel);
508
+ this.currentModelName = current?.name || this.currentModel;
509
+ this.filterModels();
510
+ this.updateConfig();
511
+ } catch (e) { console.error(e); }
512
+ this.loading = false;
513
+ },
514
+ filterModels() {
515
+ let filtered = this.models;
516
+ if (this.selectedProvider !== 'all') filtered = filtered.filter(m => m.provider === this.selectedProvider);
517
+ if (this.search) {
518
+ const s = this.search.toLowerCase();
519
+ filtered = filtered.filter(m => m.name.toLowerCase().includes(s) || m.id.toLowerCase().includes(s));
520
+ }
521
+ this.filteredModels = filtered.slice(0, 100);
522
+ },
523
+ async selectModel(modelId) {
524
+ await fetch('/api/model', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ modelId }) });
525
+ this.currentModel = modelId;
526
+ this.refresh();
527
+ },
528
+ async resetSession() {
529
+ await fetch('/api/reset-session', { method: 'POST' });
530
+ this.refresh();
531
+ },
532
+ async refreshModels() {
533
+ await fetch('/api/refresh-models', { method: 'POST' });
534
+ this.refresh();
535
+ },
536
+ updateConfig() {
537
+ this.configJson = JSON.stringify({ env: { ANTHROPIC_BASE_URL: 'http://localhost:8300', ANTHROPIC_API_KEY: 'test', ANTHROPIC_MODEL: this.currentModel } }, null, 2);
538
+ },
539
+ async applyToClaude() {
540
+ try {
541
+ const response = await fetch('/api/apply-claude-config', { method: 'POST' });
542
+ const data = await response.json();
543
+ alert(data.success ? 'Applied to Claude Code! Restart Claude Code to use.' : 'Failed: ' + data.error);
544
+ } catch (e) { alert('Error: ' + e.message); }
545
+ }
546
+ };
534
547
  }
535
-
536
- loadModels();
537
- loadStatus();
538
- setInterval(loadStatus, 3000);
539
548
  </script>
540
549
  </body>
541
550
  </html>`;