@tonyclaw/llm-inspector 1.18.2 → 1.19.1

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 (42) hide show
  1. package/.output/cli.js +903 -139
  2. package/.output/nitro.json +1 -1
  3. package/.output/public/assets/{CompareDrawer-C-4ypEWs.js → CompareDrawer-DtERUdIt.js} +1 -1
  4. package/.output/public/assets/ProxyViewerContainer-DfxRK7Nt.js +101 -0
  5. package/.output/public/assets/{ReplayDialog-CyBKOgba.js → ReplayDialog-VMsGnJSI.js} +1 -1
  6. package/.output/public/assets/{RequestAnatomy-C0IrVQ3q.js → RequestAnatomy-Cx_vluvK.js} +1 -1
  7. package/.output/public/assets/{ResponseView-MogToC4i.js → ResponseView-5F8Ms5z4.js} +1 -1
  8. package/.output/public/assets/{StreamingChunkSequence-ClhUhT-s.js → StreamingChunkSequence-CKDCWfu9.js} +1 -1
  9. package/.output/public/assets/_sessionId-C-aKd1Ky.js +1 -0
  10. package/.output/public/assets/index-B8ttyigz.js +1 -0
  11. package/.output/public/assets/index-DeJyypsp.css +1 -0
  12. package/.output/public/assets/{json-viewer-BicGakI5.js → json-viewer-CztuZ9cT.js} +2 -2
  13. package/.output/public/assets/{main-Be2qqUUW.js → main-CR9IJlz1.js} +2 -2
  14. package/.output/server/_libs/lucide-react.mjs +93 -72
  15. package/.output/server/{_sessionId-DhKJIdQC.mjs → _sessionId-DvWQaDEm.mjs} +2 -2
  16. package/.output/server/_ssr/{CompareDrawer-BGUgukJ8.mjs → CompareDrawer-C5FsxSDS.mjs} +4 -4
  17. package/.output/server/_ssr/{ProxyViewerContainer--3K3o3Sm.mjs → ProxyViewerContainer-v0cvR8f5.mjs} +354 -343
  18. package/.output/server/_ssr/{ReplayDialog-Bo86xZI4.mjs → ReplayDialog-C3KOv9OW.mjs} +4 -4
  19. package/.output/server/_ssr/{RequestAnatomy-jRU5qgwB.mjs → RequestAnatomy-BYRe33eG.mjs} +3 -3
  20. package/.output/server/_ssr/{ResponseView-DdO_-79a.mjs → ResponseView-va7yQDeL.mjs} +4 -4
  21. package/.output/server/_ssr/{StreamingChunkSequence-BigLwhh4.mjs → StreamingChunkSequence-BJlI-gWl.mjs} +3 -3
  22. package/.output/server/_ssr/{index-BHG6vOnr.mjs → index-CS0fA2GT.mjs} +2 -2
  23. package/.output/server/_ssr/index.mjs +2 -2
  24. package/.output/server/_ssr/{json-viewer-B4c_WjXD.mjs → json-viewer-Dg8rqrxL.mjs} +9 -5
  25. package/.output/server/_ssr/{router-DVixpJO-.mjs → router-D_Boe9Bu.mjs} +3 -3
  26. package/.output/server/{_tanstack-start-manifest_v-BbvWUF4v.mjs → _tanstack-start-manifest_v-KFXyNRGC.mjs} +1 -1
  27. package/.output/server/index.mjs +65 -65
  28. package/package.json +2 -1
  29. package/src/cli/detect-tools.ts +146 -0
  30. package/src/cli/onboard.ts +229 -0
  31. package/src/cli/templates/command-onboard.ts +17 -0
  32. package/src/cli/templates/skill-onboard.ts +458 -0
  33. package/src/cli.ts +193 -163
  34. package/src/components/ProxyViewer.tsx +153 -142
  35. package/src/components/proxy-viewer/LogEntry.tsx +136 -157
  36. package/src/components/proxy-viewer/LogEntryHeader.tsx +147 -66
  37. package/src/components/proxy-viewer/useCopyFeedback.ts +36 -0
  38. package/src/components/ui/json-viewer.tsx +12 -0
  39. package/.output/public/assets/ProxyViewerContainer-WRenRpeh.js +0 -101
  40. package/.output/public/assets/_sessionId-BO47oA3Z.js +0 -1
  41. package/.output/public/assets/index-BRvz6-L6.css +0 -1
  42. package/.output/public/assets/index-Btw8ec7-.js +0 -1
package/.output/cli.js CHANGED
@@ -1,154 +1,918 @@
1
1
  #!/usr/bin/env node
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
6
+ };
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
2
11
 
3
- // src/cli.ts
4
- import { spawn, execSync } from "node:child_process";
5
- import { fileURLToPath } from "node:url";
6
- import { dirname, join } from "node:path";
7
- var __filename = fileURLToPath(import.meta.url);
8
- var __dirname = dirname(__filename);
9
- var DEFAULT_PORT = 25947;
10
- var envPort = process.env["PORT"];
11
- var portDefault = envPort !== void 0 ? Number(envPort) : DEFAULT_PORT;
12
- var args = process.argv.slice(2);
13
- var port = portDefault;
14
- var open = true;
15
- var configDir;
16
- var providersJson;
17
- for (let i = 0; i < args.length; i++) {
18
- const arg = args[i] ?? "";
19
- switch (arg) {
20
- case "--port":
21
- case "-p":
22
- port = Number(args[i + 1]);
23
- i++;
24
- break;
25
- case "--no-open":
26
- open = false;
27
- break;
28
- case "--open":
29
- open = true;
30
- break;
31
- case "--config-dir":
32
- configDir = args[i + 1];
33
- i++;
34
- break;
35
- case "--providers":
36
- providersJson = args[i + 1];
37
- i++;
38
- break;
39
- default:
40
- break;
41
- }
42
- }
43
- function killProcessOnPort(targetPort) {
44
- const platform = process.platform;
12
+ // src/cli/detect-tools.ts
13
+ import { execFileSync } from "node:child_process";
14
+ import { existsSync } from "node:fs";
15
+ import { join } from "node:path";
16
+ import { homedir } from "node:os";
17
+ function which(bin) {
45
18
  try {
46
- let pids = [];
47
- if (platform === "win32") {
48
- const output = execSync(`netstat -ano | findstr :${targetPort}`, {
19
+ if (process.platform === "win32") {
20
+ const out2 = execFileSync("where", [bin], {
49
21
  encoding: "utf8",
50
- timeout: 5e3
22
+ timeout: 3e3,
23
+ stdio: ["ignore", "pipe", "ignore"]
51
24
  });
52
- const lines = output.trim().split("\n");
53
- for (const line of lines) {
54
- const parts = line.trim().split(/\s+/);
55
- if (parts.length >= 5) {
56
- const localAddress = parts[1] ?? "";
57
- const pidStr = parts[4] ?? "";
58
- if (localAddress !== "" && pidStr !== "" && localAddress.includes(`:${targetPort}`)) {
59
- const pid = parseInt(pidStr, 10);
60
- if (!isNaN(pid) && pid > 0) {
61
- pids.push(pid);
25
+ const first = out2.split(/\r?\n/).find((line) => line.trim().length > 0);
26
+ return first?.trim() ?? null;
27
+ }
28
+ const out = execFileSync("sh", ["-c", `command -v ${bin}`], {
29
+ encoding: "utf8",
30
+ timeout: 3e3,
31
+ stdio: ["ignore", "pipe", "ignore"]
32
+ });
33
+ return out.trim() || null;
34
+ } catch {
35
+ return null;
36
+ }
37
+ }
38
+ function tryDir(path) {
39
+ return existsSync(path) ? path : null;
40
+ }
41
+ function detectClaudeCode() {
42
+ const configDir = tryDir(join(homedir(), ".claude"));
43
+ const bin = which("claude");
44
+ if (configDir === null && bin === null) return { found: false };
45
+ return { found: true, path: configDir ?? bin ?? "" };
46
+ }
47
+ function detectOpenCode() {
48
+ const configDir = tryDir(join(homedir(), ".config", "opencode"));
49
+ const bin = which("opencode");
50
+ if (configDir === null && bin === null) return { found: false };
51
+ return { found: true, path: configDir ?? bin ?? "" };
52
+ }
53
+ function detectMiMo() {
54
+ const configDir = tryDir(join(homedir(), ".mimo"));
55
+ const bin = which("mimo");
56
+ if (configDir === null && bin === null) return { found: false };
57
+ return { found: true, path: configDir ?? bin ?? "" };
58
+ }
59
+ function detectCursor() {
60
+ const configDir = tryDir(join(homedir(), ".cursor"));
61
+ const bin = which("cursor");
62
+ if (configDir === null && bin === null) return { found: false };
63
+ return { found: true, path: configDir ?? bin ?? "" };
64
+ }
65
+ function detectCody() {
66
+ const configDir = tryDir(join(homedir(), ".config", "cody"));
67
+ const bin = which("cody");
68
+ if (configDir === null && bin === null) return { found: false };
69
+ return { found: true, path: configDir ?? bin ?? "" };
70
+ }
71
+ function detectAll() {
72
+ return DETECTORS.map(({ id, displayName, detect }) => ({
73
+ id,
74
+ displayName,
75
+ result: detect()
76
+ }));
77
+ }
78
+ function detectFirst() {
79
+ for (const entry of DETECTORS) {
80
+ const result = entry.detect();
81
+ if (result.found) return { id: entry.id, displayName: entry.displayName, result };
82
+ }
83
+ return null;
84
+ }
85
+ var DETECTORS;
86
+ var init_detect_tools = __esm({
87
+ "src/cli/detect-tools.ts"() {
88
+ "use strict";
89
+ DETECTORS = [
90
+ { id: "claude-code", displayName: "Claude Code", detect: detectClaudeCode },
91
+ { id: "opencode", displayName: "OpenCode", detect: detectOpenCode },
92
+ { id: "mimo", displayName: "MiMo Code", detect: detectMiMo },
93
+ { id: "cursor", displayName: "Cursor", detect: detectCursor },
94
+ { id: "cody", displayName: "Cody", detect: detectCody }
95
+ ];
96
+ }
97
+ });
98
+
99
+ // src/cli/templates/command-onboard.ts
100
+ function renderCommandOnboard() {
101
+ return `---
102
+ description: Walk through llm-inspector setup \u2014 start the proxy, wire your AI tool, capture your first request.
103
+ ---
104
+
105
+ Invoke the \`llm-inspector-onboard\` skill and follow its phases.
106
+
107
+ The user wants to set up llm-inspector. If they have specific context (e.g. "I'm on Windows", "I already added my API key"), honor it \u2014 but otherwise just run the skill end-to-end and let the \`EXPLAIN / DO / PAUSE\` markers drive the conversation.
108
+ `;
109
+ }
110
+ var init_command_onboard = __esm({
111
+ "src/cli/templates/command-onboard.ts"() {
112
+ "use strict";
113
+ }
114
+ });
115
+
116
+ // src/cli/templates/skill-onboard.ts
117
+ function renderSkillOnboard(ctx) {
118
+ const { version, port, detectedSummary } = ctx;
119
+ return `---
120
+ name: llm-inspector-onboard
121
+ description: Guided setup for llm-inspector v${version} \u2014 start the proxy, wire your AI coding tool, capture your first request, and learn the Web UI.
122
+ metadata:
123
+ author: llm-inspector
124
+ version: ${version}
125
+ ---
126
+
127
+ # llm-inspector onboard
128
+
129
+ Guide the user from "I just installed llm-inspector" to "I can see my AI tool's traffic in the Web UI". This is a teaching experience \u2014 you'll do real work in their environment while explaining each step.
130
+
131
+ Environment detected by the installer:
132
+ ${detectedSummary || " (no known AI tool detected \u2014 the user can still use the generic curl example in Phase 4)"}
133
+
134
+ Default proxy port: \`${port}\` (override with \`PORT=<n> llm-inspector\` or \`--port <n>\`).
135
+
136
+ > **PAUSE protocol.** Every \`**PAUSE**\` marker in this skill is a real stop.
137
+ > Use the \`AskUserQuestion\` tool to actually wait for the user before
138
+ > continuing. Do not stream past a PAUSE based on context \u2014 the user has
139
+ > not seen your output yet. Each PAUSE in the body below includes a sample
140
+ > question you can adapt.
141
+
142
+ ---
143
+
144
+ ## Phase 0: Idempotency check
145
+
146
+ **EXPLAIN:** "Before we do anything, let me see what's already set up. If some of the steps are already done, we can skip them."
147
+
148
+ **DO:** Probe the three pieces of state this skill touches. Use targeted checks \u2014 do **not** read large JSON files into the conversation.
149
+
150
+ \`\`\`bash
151
+ # 1. Is the proxy already up?
152
+ curl -fsS "http://localhost:${port}/api/health" 2>/dev/null && echo "PROXY: up" || echo "PROXY: down"
153
+
154
+ # 2. Does the config have a real provider key?
155
+ CFG="$HOME/.llm-inspector/config.json"
156
+ if [ -f "$CFG" ]; then
157
+ if grep -qE '"apiKey"[[:space:]]*:[[:space:]]*"(sk-[^"]+|REPLACE|REPLACE_)' "$CFG" 2>/dev/null; then
158
+ echo "CONFIG: has key (no REPLACE placeholder)"
159
+ else
160
+ echo "CONFIG: missing or has placeholder key"
161
+ fi
162
+ else
163
+ echo "CONFIG: file does not exist"
164
+ fi
165
+
166
+ # 3. Is the MCP server already wired? (project .mcp.json wins)
167
+ PROJ_MCP=".mcp.json"
168
+ HOME_MCP="$HOME/.claude.json"
169
+ if [ -f "$PROJ_MCP" ] && grep -q '"llm-inspector"' "$PROJ_MCP"; then
170
+ echo "MCP: wired in $PROJ_MCP"
171
+ elif [ -f "$HOME_MCP" ] && grep -q '"llm-inspector"' "$HOME_MCP"; then
172
+ echo "MCP: wired in $HOME_MCP"
173
+ else
174
+ echo "MCP: not wired"
175
+ fi
176
+ \`\`\`
177
+
178
+ \`\`\`powershell
179
+ # Windows PowerShell \u2014 single-quoted so $env: expands correctly
180
+ $port = ${port}
181
+ $cfg = Join-Path $env:USERPROFILE '.llm-inspector/config.json'
182
+
183
+ # 1. Is the proxy already up?
184
+ try {
185
+ $null = Invoke-RestMethod -Uri "http://localhost:$port/api/health" -TimeoutSec 2 -ErrorAction Stop
186
+ Write-Host 'PROXY: up'
187
+ } catch {
188
+ Write-Host 'PROXY: down'
189
+ }
190
+
191
+ # 2. Does the config have a real provider key?
192
+ if (Test-Path $cfg) {
193
+ $content = Get-Content $cfg -Raw
194
+ if ($content -match '"apiKey"[[:space:]]*:[[:space:]]*"(sk-[^"]+)"') {
195
+ Write-Host 'CONFIG: has key'
196
+ } elseif ($content -match 'REPLACE') {
197
+ Write-Host 'CONFIG: has placeholder key'
198
+ } else {
199
+ Write-Host 'CONFIG: missing key'
200
+ }
201
+ } else {
202
+ Write-Host 'CONFIG: file does not exist'
203
+ }
204
+
205
+ # 3. Is the MCP server already wired? (project .mcp.json wins)
206
+ $projMcp = Join-Path (Get-Location) '.mcp.json'
207
+ $homeMcp = Join-Path $env:USERPROFILE '.claude.json'
208
+ if ((Test-Path $projMcp) -and (Select-String -Path $projMcp -Pattern 'llm-inspector' -Quiet)) {
209
+ Write-Host "MCP: wired in $projMcp"
210
+ } elseif ((Test-Path $homeMcp) -and (Select-String -Path $homeMcp -Pattern 'llm-inspector' -Quiet)) {
211
+ Write-Host "MCP: wired in $homeMcp"
212
+ } else {
213
+ Write-Host 'MCP: not wired'
214
+ }
215
+ \`\`\`
216
+
217
+ **DO:** Summarize the three checks in one line, then use \`AskUserQuestion\` to ask whether to skip the corresponding phases.
218
+
219
+ > **PAUSE** \u2014 call \`AskUserQuestion\` with:
220
+ > - header: \`Skip done\`
221
+ > - question: \`Proxy/CONFIG/MCP state: <summary>. Skip the phases that are already done?\`
222
+ > - options: \`["Yes, skip what's done", "No, walk me through everything again"]\`
223
+ > Wait for the answer before moving to Preflight.
224
+
225
+ ---
226
+
227
+ ## Preflight
228
+
229
+ **EXPLAIN:** "Quick env sanity check \u2014 make sure Node and Claude Code are present."
230
+
231
+ **DO:** Run the platform-appropriate commands below.
232
+
233
+ \`\`\`bash
234
+ # Unix / macOS / WSL
235
+ node --version # expect >= 18
236
+ command -v claude >/dev/null && echo "claude-code: present" || echo "claude-code: not detected"
237
+ \`\`\`
238
+
239
+ \`\`\`powershell
240
+ # Windows PowerShell \u2014 single-quoted so $env: expands correctly
241
+ node --version # expect >= 18
242
+ $null = Get-Command claude -ErrorAction SilentlyContinue
243
+ if ($null) { Write-Host 'claude-code: present' } else { Write-Host 'claude-code: not detected' }
244
+ \`\`\`
245
+
246
+ > **PAUSE** \u2014 if Node is older than 18, ask the user to install a newer version (https://nodejs.org) before continuing. Use \`AskUserQuestion\` with header \`Node version\`.
247
+
248
+ ---
249
+
250
+ ## Phase 1: Welcome
251
+
252
+ **EXPLAIN:**
253
+
254
+ \`\`\`
255
+ ## Welcome to llm-inspector!
256
+
257
+ llm-inspector is a transparent HTTP proxy + Web UI for AI coding tools. Point your tool at it, and you'll see every request and response \u2014 system prompts, tool definitions, message history, SSE streaming chunks, and token counts \u2014 captured live in a browser tab.
258
+
259
+ **What we'll do in the next ~10 minutes:**
260
+ 1. Add your first LLM provider (Anthropic or OpenAI key)
261
+ 2. Start the proxy
262
+ 3. Wire your AI tool to use it
263
+ 4. Capture a first request end-to-end
264
+ 5. Tour the key UI affordances
265
+
266
+ Ready? Let's start with the provider.
267
+ \`\`\`
268
+
269
+ > **PAUSE** \u2014 use \`AskUserQuestion\` with header \`Ready?\` and options \`["Yes, let's go", "Wait, I have a question"]\`. Wait for the user before continuing.
270
+
271
+ ---
272
+
273
+ ## Phase 2: Provider setup
274
+
275
+ **EXPLAIN:** "A 'provider' is an upstream LLM endpoint \u2014 Anthropic, OpenAI, MiniMax, etc. llm-inspector routes each request to the right upstream based on the model name. You need at least one provider configured for the proxy to forward traffic."
276
+
277
+ **DO:** First, re-check whether the config already has a real key (Phase 0 may have raced with a manual edit). Use the same \`grep -qE '"apiKey":"sk-' "$HOME/.llm-inspector/config.json"\` (bash) or \`Select-String\` (PowerShell) check from Phase 0. If a real key is present, skip the rest of this phase.
278
+
279
+ **DO:** If no real key, ask the user for the provider type and API key via \`AskUserQuestion\`. The question should be a free-form text field (no fixed options) \u2014 the API key is a secret, so don't echo it back in the question UI.
280
+
281
+ \`\`\`bash
282
+ # After collecting the key, write the config
283
+ mkdir -p "$HOME/.llm-inspector"
284
+ cat > "$HOME/.llm-inspector/config.json" <<'JSON'
285
+ {
286
+ "providers": [
287
+ {
288
+ "id": "anthropic",
289
+ "type": "anthropic",
290
+ "apiKey": "REPLACE_ME_BEFORE_WRITING",
291
+ "baseUrl": "https://api.anthropic.com"
292
+ }
293
+ ]
294
+ }
295
+ JSON
296
+ # Then patch the apiKey with the user-provided value (use jq if available)
297
+ \`\`\`
298
+
299
+ \`\`\`powershell
300
+ # Windows PowerShell \u2014 single-quoted so $env: expands correctly
301
+ $dir = Join-Path $env:USERPROFILE '.llm-inspector'
302
+ $file = Join-Path $dir 'config.json'
303
+ New-Item -ItemType Directory -Force -Path $dir | Out-Null
304
+ @'
305
+ {
306
+ "providers": [
307
+ {
308
+ "id": "anthropic",
309
+ "type": "anthropic",
310
+ "apiKey": "REPLACE_ME_BEFORE_WRITING",
311
+ "baseUrl": "https://api.anthropic.com"
312
+ }
313
+ ]
314
+ }
315
+ '@ | Set-Content -Path $file -Encoding UTF8
316
+ # Then patch the apiKey with the user-provided value
317
+ \`\`\`
318
+
319
+ **DO:** Patch the placeholder with the actual key using \`jq\` (preferred) or a simple \`sed\`. Then read the file back to confirm the key is no longer \`REPLACE_ME_BEFORE_WRITING\`.
320
+
321
+ **DO:** If the user declines to provide a key in the AskUserQuestion (selects "Skip for now"), do **not** write a placeholder config. Tell the user that Phase 5 (First capture) will be skipped, and that they can re-run the skill after adding a key.
322
+
323
+ > **PAUSE** \u2014 use \`AskUserQuestion\` with header \`Provider key\` and options \`["Key is in, continue", "Skip for now, I'll add it later"]\`. Wait for the answer.
324
+
325
+ ---
326
+
327
+ ## Phase 3: Start proxy
328
+
329
+ **EXPLAIN:** "Time to start the proxy. It binds to port ${port} by default, kills any process already on that port, and prints the URL."
330
+
331
+ **DO:** Skip this phase entirely if the Phase 0 health check already reported \`PROXY: up\` and the user opted to skip done phases.
332
+
333
+ **DO:** Otherwise, start the proxy in the background. On Windows, the npm shim is a \`.cmd\`/PowerShell file \u2014 \`Start-Process -FilePath "llm-inspector"\` returns "Invalid Win32 application" because Windows can't decide which shim to run. Use \`cmd /c start /B\` to background it through the cmd interpreter.
334
+
335
+ \`\`\`bash
336
+ # Unix / macOS / WSL
337
+ nohup llm-inspector --no-open > /tmp/llm-inspector.log 2>&1 &
338
+ \`\`\`
339
+
340
+ \`\`\`powershell
341
+ # Windows PowerShell \u2014 single-quoted so $env: expands correctly.
342
+ # Locate the binary on PATH first (works for npm, pnpm, yarn, volta, fnm).
343
+ # If not on PATH, fall back to the common npm global shim at $env:APPDATA.
344
+ # As a last resort, let cmd /c resolve it through PATHEXT.
345
+ $log = Join-Path $env:TEMP 'llm-inspector.log'
346
+ $err = Join-Path $env:TEMP 'llm-inspector.err.log'
347
+ $found = Get-Command llm-inspector -ErrorAction SilentlyContinue
348
+ if ($found) {
349
+ $shim = $found.Source
350
+ $args = '--no-open'
351
+ } elseif (Test-Path (Join-Path $env:APPDATA 'npm/llm-inspector.cmd')) {
352
+ $shim = Join-Path $env:APPDATA 'npm/llm-inspector.cmd'
353
+ $args = '--no-open'
354
+ } else {
355
+ # bin not on PATH and not at the default npm prefix \u2014 let cmd resolve it
356
+ $shim = 'cmd.exe'
357
+ $args = '/c','start','/B','llm-inspector','--no-open'
358
+ }
359
+ Start-Process -FilePath $shim -ArgumentList $args -RedirectStandardOutput $log -RedirectStandardError $err -WindowStyle Hidden
360
+ \`\`\`
361
+
362
+ Then wait for the port to be ready:
363
+
364
+ \`\`\`bash
365
+ for i in $(seq 1 20); do
366
+ curl -fsS "http://localhost:${port}/api/health" >/dev/null 2>&1 && echo "ready" && break
367
+ sleep 0.5
368
+ done
369
+ \`\`\`
370
+
371
+ **DO:** Hit the health endpoint to confirm the proxy is alive:
372
+
373
+ \`\`\`bash
374
+ curl -sS "http://localhost:${port}/api/health"
375
+ \`\`\`
376
+
377
+ > **PAUSE** \u2014 if the health check fails, show the user the log file (\`/tmp/llm-inspector.log\` or \`%TEMP%\\llm-inspector.log\`) and diagnose. Common issues: another process on the port, firewall, missing providers. Use \`AskUserQuestion\` with header \`Proxy up?\` and options \`["Yes, proxy is up", "No, I see an error in the log"]\`. Wait for the answer.
378
+
379
+ ---
380
+
381
+ ## Phase 4: Wire tool
382
+
383
+ **EXPLAIN:** "Now we tell your AI tool to send traffic through the proxy instead of directly to the upstream API. The exact env var depends on which tool you have."
384
+
385
+ **DO:** Based on the \`Environment detected\` block at the top of this skill, print the matching wiring command. Examples for each supported tool:
386
+
387
+ \`\`\`bash
388
+ # Claude Code
389
+ export ANTHROPIC_BASE_URL=http://localhost:${port}/proxy
390
+ claude
391
+
392
+ # OpenCode
393
+ export LLM_BASE_URL=http://localhost:${port}/proxy
394
+ opencode
395
+
396
+ # MiMo Code
397
+ export OPENAI_BASE_URL=http://localhost:${port}/proxy
398
+ mimo
399
+
400
+ # Cursor / Cody \u2014 set the OpenAI base URL in each tool's settings panel to http://localhost:${port}/proxy
401
+ \`\`\`
402
+
403
+ For a tool that wasn't auto-detected, fall through to the generic curl test in the next phase \u2014 the user can wire their tool later.
404
+
405
+ > **PAUSE** \u2014 use \`AskUserQuestion\` with header \`Tool wired?\` and options \`["Yes, env var is set, claude is running", "No, I'm going to use the curl test instead"]\`. Wait for the answer.
406
+
407
+ ---
408
+
409
+ ## Phase 4.5: Wire MCP server
410
+
411
+ **EXPLAIN:** "The proxy also exposes an MCP server at \`http://localhost:${port}/api/mcp\`. Your AI agent can query logs, replay requests, and test providers through it \u2014 no need to leave the editor."
412
+
413
+ **DO:** Skip this phase if Phase 0 reported \`MCP: wired in <path>\` and the user opted to skip done phases.
414
+
415
+ **DO:** Otherwise, check the project-level \`.mcp.json\` first (preferred \u2014 modern Claude Code convention), then fall back to \`~/.claude.json\`. Use the \`Read\` tool to inspect; do **not** \`cat\` a 40 KB file into the conversation.
416
+
417
+ If neither has an \`llm-inspector\` entry, add one. The simplest path is to write to project \`.mcp.json\` (create it if missing):
418
+
419
+ \`\`\`json
420
+ // .mcp.json (project root)
421
+ {
422
+ "mcpServers": {
423
+ "llm-inspector": {
424
+ "type": "http",
425
+ "url": "http://localhost:${port}/api/mcp"
426
+ }
427
+ }
428
+ }
429
+ \`\`\`
430
+
431
+ If \`mcpServers\` already exists in \`.mcp.json\`, merge the \`llm-inspector\` key into it via the \`Edit\` tool \u2014 do not overwrite other entries. If you can't create a project \`.mcp.json\` (no project root, permission, etc.), fall back to merging into \`~/.claude.json\` using the same \`Read\`/\`Edit\` pattern.
432
+
433
+ **DO:** Verify the handshake. The MCP \`initialize\` request should return 200 with a \`serverInfo\` payload \u2014 that proves the server is mounted and reachable:
434
+
435
+ \`\`\`bash
436
+ curl -sS -X POST "http://localhost:${port}/api/mcp" \\
437
+ -H "Content-Type: application/json" \\
438
+ -H "Accept: application/json, text/event-stream" \\
439
+ -d '{
440
+ "jsonrpc": "2.0",
441
+ "id": 1,
442
+ "method": "initialize",
443
+ "params": {
444
+ "protocolVersion": "2025-03-26",
445
+ "capabilities": {},
446
+ "clientInfo": { "name": "onboard-check", "version": "0" }
447
+ }
448
+ }' | grep -o '"name":"llm-inspector"' && echo "handshake OK"
449
+ \`\`\`
450
+
451
+ The \`grep -o '"name":"llm-inspector"'\` extracts only the serverInfo name \u2014 do not dump the full response. If the server returns session IDs, store the \`mcp-session-id\` header from the first response and use it for the follow-up \`tools/list\` call.
452
+
453
+ > **PAUSE** \u2014 use \`AskUserQuestion\` with header \`MCP OK?\` and options \`["Yes, handshake returned 200", "No, the call failed"]\`. Wait for the answer.
454
+
455
+ ---
456
+
457
+ ## Phase 5: First capture
458
+
459
+ **EXPLAIN:** "Let's prove the proxy works end-to-end. We'll send one real request through it and confirm the log shows up in the API."
460
+
461
+ **DO:** First, re-check the config. If the \`apiKey\` is still a \`REPLACE_ME_BEFORE_WRITING\` placeholder (user opted out in Phase 2), **skip the capture test** and tell the user to fill in their key and re-run the skill. A 401 from the upstream is fine if they did provide a real key \u2014 the proxy will still log the request.
462
+
463
+ Fire a minimal Anthropic-format request through the proxy:
464
+
465
+ \`\`\`bash
466
+ curl -sS -X POST "http://localhost:${port}/proxy/v1/messages" \\
467
+ -H "Content-Type: application/json" \\
468
+ -H "anthropic-version: 2023-06-01" \\
469
+ -H "x-api-key: \${LLM_INSPECTOR_API_KEY:-sk-no-key-needed-for-routing}" \\
470
+ -d '{"model":"claude-3-5-sonnet-20241022","max_tokens":1,"messages":[{"role":"user","content":"ping"}]}' \\
471
+ -o /tmp/llm-inspector-capture.json -w 'STATUS:%{http_code}\\n'
472
+ \`\`\`
473
+
474
+ **DO:** Poll the logs API for up to 5 seconds. A 200 with at least one entry means the request reached the proxy:
475
+
476
+ \`\`\`bash
477
+ for i in $(seq 1 10); do
478
+ resp=$(curl -sS "http://localhost:${port}/api/logs?limit=1")
479
+ count=$(echo "$resp" | grep -o '"total":[0-9]*' | head -1 | grep -o '[0-9]*$')
480
+ if [ "\${count:-0}" -ge 1 ]; then
481
+ echo "captured"
482
+ echo "$resp" | head -c 400
483
+ break
484
+ fi
485
+ sleep 0.5
486
+ done
487
+ \`\`\`
488
+
489
+ **DO:** Diagnose the response based on the actual status and body. **Do not** default to "auth failure" for every 4xx.
490
+
491
+ | Status | Body hint | Meaning |
492
+ |--------|-----------|---------|
493
+ | 200 | normal | Real success \u2014 the upstream returned data |
494
+ | 401 | \`"unauthorized"\` or similar | Upstream rejected the key (expected with a test key) |
495
+ | 403 | \`"Request not allowed"\` | **Proxy's allowlist** \u2014 not an auth failure, the proxy rejected the model/config. Show the user the proxy log. |
496
+ | 403 | other text | Could be upstream ACL \u2014 different problem |
497
+ | 5xx | anything | Upstream network error |
498
+
499
+ > **PAUSE** \u2014 use \`AskUserQuestion\` with header \`Captured?\` and options matching the diagnosis above. Wait for the answer.
500
+
501
+ ---
502
+
503
+ ## Phase 6: Tour & wrap
504
+
505
+ **EXPLAIN:** "Everything's working. Here's the cheat sheet for the Web UI and the supporting surfaces:"
506
+
507
+ - **Web UI**: \`http://localhost:${port}/\` \u2014 collapsible log rows, per-tab Copy/Expand in the log header, Diff with Raw (request body), Diff with Previous (compare adjacent requests), Replay (re-send a request), Export (JSON ZIP).
508
+ - **MCP server**: \`http://localhost:${port}/api/mcp\` \u2014 connect from your coding agent to query logs, replay, and test providers without leaving the editor. Look for the "MCP Ready" badge in the Web UI header.
509
+ - **REST API**: \`/api/logs\`, \`/api/sessions\`, \`/api/providers\` \u2014 for scripting and shell-based inspection.
510
+ - **Stop the proxy**:
511
+
512
+ \`\`\`bash
513
+ # Unix / macOS
514
+ lsof -ti:${port} | xargs -r kill -9
515
+
516
+ # Windows PowerShell \u2014 single-quoted so $env: expands correctly
517
+ Get-NetTCPConnection -LocalPort $port | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force }
518
+ \`\`\`
519
+
520
+ - **Re-run onboard**: \`llm-inspector onboard --force\` refreshes this skill.
521
+ - **Full docs**: see the project README (linked from the Web UI footer).
522
+
523
+ > **PAUSE** \u2014 use \`AskUserQuestion\` with header \`All set?\` and options \`["All set, I'm done", "Wait, I want to revisit a phase"]\`. Wait for the answer.
524
+
525
+ You're done. Happy inspecting.
526
+ `;
527
+ }
528
+ var REQUIRED_PHASE_HEADINGS;
529
+ var init_skill_onboard = __esm({
530
+ "src/cli/templates/skill-onboard.ts"() {
531
+ "use strict";
532
+ REQUIRED_PHASE_HEADINGS = [
533
+ "Phase 0: Idempotency check",
534
+ "Preflight",
535
+ "Phase 1: Welcome",
536
+ "Phase 2: Provider setup",
537
+ "Phase 3: Start proxy",
538
+ "Phase 4: Wire tool",
539
+ "Phase 4.5: Wire MCP server",
540
+ "Phase 5: First capture",
541
+ "Phase 6: Tour & wrap"
542
+ ];
543
+ }
544
+ });
545
+
546
+ // src/cli/onboard.ts
547
+ var onboard_exports = {};
548
+ __export(onboard_exports, {
549
+ runOnboard: () => runOnboard
550
+ });
551
+ import { mkdirSync, writeFileSync, existsSync as existsSync2, readFileSync } from "node:fs";
552
+ import { homedir as homedir2 } from "node:os";
553
+ import { dirname, join as join2 } from "node:path";
554
+ import { fileURLToPath } from "node:url";
555
+ function parseFlags(argv) {
556
+ const flags = {
557
+ force: false,
558
+ dryRun: false,
559
+ skipProvider: false,
560
+ skipToolWire: false,
561
+ skillDir: null
562
+ };
563
+ for (let i = 0; i < argv.length; i++) {
564
+ const arg = argv[i];
565
+ switch (arg) {
566
+ case void 0:
567
+ continue;
568
+ case "--force":
569
+ flags.force = true;
570
+ break;
571
+ case "--dry-run":
572
+ flags.dryRun = true;
573
+ break;
574
+ case "--skip-provider":
575
+ flags.skipProvider = true;
576
+ break;
577
+ case "--skip-tool-wire":
578
+ flags.skipToolWire = true;
579
+ break;
580
+ case "--skill-dir": {
581
+ const next = argv[i + 1];
582
+ if (next === void 0) {
583
+ process.stderr.write("llm-inspector onboard: --skill-dir requires a path argument\n");
584
+ process.exit(2);
585
+ }
586
+ flags.skillDir = next;
587
+ i++;
588
+ break;
589
+ }
590
+ case "--help":
591
+ case "-h":
592
+ printHelp();
593
+ process.exit(0);
594
+ break;
595
+ default:
596
+ process.stderr.write(`llm-inspector onboard: unknown flag: ${arg}
597
+ `);
598
+ process.exit(2);
599
+ }
600
+ }
601
+ return flags;
602
+ }
603
+ function printHelp() {
604
+ process.stdout.write(`llm-inspector onboard \u2014 install the llm-inspector Claude Code skill
605
+
606
+ Usage:
607
+ llm-inspector onboard [options]
608
+
609
+ Options:
610
+ --force Overwrite the existing skill and slash command if they exist
611
+ --dry-run Print target paths and a template preview, write nothing
612
+ --skip-provider Skip the provider-setup phase in the skill body
613
+ --skip-tool-wire Skip the wire-tool phase in the skill body
614
+ --skill-dir <path> Override the target skill directory (default: ~/.claude/skills)
615
+ -h, --help Show this help
616
+
617
+ Exit codes:
618
+ 0 success (or already installed)
619
+ 2 invalid arguments
620
+ 1 write failed
621
+ `);
622
+ }
623
+ function resolveTargets(flags) {
624
+ const claudeRoot = flags.skillDir ?? join2(homedir2(), ".claude");
625
+ const skillDir = join2(claudeRoot, "skills", SKILL_DIR_NAME);
626
+ const commandsDir = join2(claudeRoot, "commands");
627
+ return {
628
+ skillFile: join2(skillDir, SKILL_FILE_NAME),
629
+ commandFile: join2(commandsDir, COMMAND_FILE_NAME)
630
+ };
631
+ }
632
+ function isObject(value) {
633
+ return typeof value === "object" && value !== null;
634
+ }
635
+ function buildDetectedSummary() {
636
+ const entries = detectAll();
637
+ const present = entries.filter((e) => e.result.found);
638
+ const absent = entries.filter((e) => !e.result.found);
639
+ const presentList = present.map((e) => e.displayName).join(", ") || "(none)";
640
+ const absentList = absent.map((e) => e.displayName).join(", ") || "(none)";
641
+ return ` - Detected: ${presentList}
642
+ - Not detected: ${absentList}`;
643
+ }
644
+ function runOnboard(argv) {
645
+ try {
646
+ return Promise.resolve(runOnboardSync(argv));
647
+ } catch (err) {
648
+ const msg = err instanceof Error ? err.message : String(err);
649
+ process.stderr.write(`llm-inspector onboard: ${msg}
650
+ `);
651
+ process.stderr.write(
652
+ "(postinstall skill install skipped \u2014 run `llm-inspector onboard` later)\n"
653
+ );
654
+ return Promise.resolve(0);
655
+ }
656
+ }
657
+ function runOnboardSync(argv) {
658
+ const flags = parseFlags(argv);
659
+ const { skillFile, commandFile } = resolveTargets(flags);
660
+ if (!flags.force && existsSync2(skillFile)) {
661
+ process.stdout.write(`llm-inspector onboard: already installed at ${skillFile}
662
+ `);
663
+ process.stdout.write("Re-run with --force to refresh.\n");
664
+ return 0;
665
+ }
666
+ let version = "0.0.0";
667
+ try {
668
+ const raw = JSON.parse(readFileSync(join2(__dirname, "..", "package.json"), "utf8"));
669
+ if (isObject(raw) && typeof raw["version"] === "string") {
670
+ version = raw["version"];
671
+ }
672
+ } catch {
673
+ }
674
+ const detectedSummary = buildDetectedSummary();
675
+ const skillBody = renderSkillOnboard({
676
+ version,
677
+ port: DEFAULT_PORT,
678
+ detectedSummary
679
+ });
680
+ const commandBody = renderCommandOnboard();
681
+ if (flags.dryRun) {
682
+ process.stdout.write(`llm-inspector onboard --dry-run
683
+
684
+ `);
685
+ process.stdout.write(`Skill target: ${skillFile}
686
+ `);
687
+ process.stdout.write(`Command target: ${commandFile}
688
+
689
+ `);
690
+ process.stdout.write(`Skill preview (first 5 lines + headings):
691
+ `);
692
+ const previewLines = skillBody.split("\n").slice(0, 5);
693
+ process.stdout.write(`${previewLines.join("\n")}
694
+ `);
695
+ process.stdout.write(`...
696
+ `);
697
+ for (const heading of REQUIRED_PHASE_HEADINGS) {
698
+ process.stdout.write(` - ${heading}
699
+ `);
700
+ }
701
+ process.stdout.write(`
702
+ Detected tools:
703
+ ${detectedSummary}
704
+ `);
705
+ process.stdout.write(`
706
+ No files were written.
707
+ `);
708
+ return 0;
709
+ }
710
+ mkdirSync(join2(skillFile, ".."), { recursive: true });
711
+ mkdirSync(join2(commandFile, ".."), { recursive: true });
712
+ try {
713
+ writeFileSync(skillFile, skillBody, "utf8");
714
+ writeFileSync(commandFile, commandBody, "utf8");
715
+ } catch (err) {
716
+ const msg = err instanceof Error ? err.message : String(err);
717
+ process.stderr.write(`llm-inspector onboard: failed to write files: ${msg}
718
+ `);
719
+ return 1;
720
+ }
721
+ const firstTool = detectFirst();
722
+ const toolHint = firstTool !== null ? firstTool.displayName : "no known tool detected";
723
+ process.stdout.write(`Installed skill to: ${skillFile}
724
+ `);
725
+ process.stdout.write(`Installed command to: ${commandFile}
726
+ `);
727
+ process.stdout.write(`
728
+ Next steps:
729
+ `);
730
+ process.stdout.write(` - Open Claude Code and run: /llm-inspector:onboard
731
+ `);
732
+ process.stdout.write(` - Or refresh later: llm-inspector onboard --force
733
+ `);
734
+ process.stdout.write(` - Detected primary tool: ${toolHint}
735
+ `);
736
+ return 0;
737
+ }
738
+ var __filename, __dirname, DEFAULT_PORT, SKILL_DIR_NAME, SKILL_FILE_NAME, COMMAND_FILE_NAME;
739
+ var init_onboard = __esm({
740
+ "src/cli/onboard.ts"() {
741
+ "use strict";
742
+ init_detect_tools();
743
+ init_command_onboard();
744
+ init_skill_onboard();
745
+ __filename = fileURLToPath(import.meta.url);
746
+ __dirname = dirname(__filename);
747
+ DEFAULT_PORT = 25947;
748
+ SKILL_DIR_NAME = "llm-inspector-onboard";
749
+ SKILL_FILE_NAME = "SKILL.md";
750
+ COMMAND_FILE_NAME = process.platform === "win32" ? "llm-inspector-onboard.md" : "llm-inspector:onboard.md";
751
+ }
752
+ });
753
+
754
+ // src/cli.ts
755
+ import { spawn, execSync } from "node:child_process";
756
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
757
+ import { dirname as dirname2, join as join3 } from "node:path";
758
+ var __filename2 = fileURLToPath2(import.meta.url);
759
+ var __dirname2 = dirname2(__filename2);
760
+ var DEFAULT_PORT2 = 25947;
761
+ var subcommand = process.argv[2];
762
+ if (subcommand === "onboard") {
763
+ const { runOnboard: runOnboard2 } = await Promise.resolve().then(() => (init_onboard(), onboard_exports));
764
+ const code = await runOnboard2(process.argv.slice(3));
765
+ process.exit(code);
766
+ }
767
+ runStart(process.argv.slice(2));
768
+ function runStart(args) {
769
+ const envPort = process.env["PORT"];
770
+ const portDefault = envPort !== void 0 ? Number(envPort) : DEFAULT_PORT2;
771
+ let port = portDefault;
772
+ let open = true;
773
+ let configDir;
774
+ let providersJson;
775
+ for (let i = 0; i < args.length; i++) {
776
+ const arg = args[i] ?? "";
777
+ switch (arg) {
778
+ case "--port":
779
+ case "-p":
780
+ port = Number(args[i + 1]);
781
+ i++;
782
+ break;
783
+ case "--no-open":
784
+ open = false;
785
+ break;
786
+ case "--open":
787
+ open = true;
788
+ break;
789
+ case "--config-dir":
790
+ configDir = args[i + 1];
791
+ i++;
792
+ break;
793
+ case "--providers":
794
+ providersJson = args[i + 1];
795
+ i++;
796
+ break;
797
+ default:
798
+ break;
799
+ }
800
+ }
801
+ function killProcessOnPort(targetPort) {
802
+ const platform = process.platform;
803
+ try {
804
+ let pids = [];
805
+ if (platform === "win32") {
806
+ const output = execSync(`netstat -ano | findstr :${targetPort}`, {
807
+ encoding: "utf8",
808
+ timeout: 5e3
809
+ });
810
+ const lines = output.trim().split("\n");
811
+ for (const line of lines) {
812
+ const parts = line.trim().split(/\s+/);
813
+ if (parts.length >= 5) {
814
+ const localAddress = parts[1] ?? "";
815
+ const pidStr = parts[4] ?? "";
816
+ if (localAddress !== "" && pidStr !== "" && localAddress.includes(`:${targetPort}`)) {
817
+ const pid = parseInt(pidStr, 10);
818
+ if (!isNaN(pid) && pid > 0) {
819
+ pids.push(pid);
820
+ }
62
821
  }
63
822
  }
64
823
  }
65
- }
66
- pids = [...new Set(pids)];
67
- for (const pid of pids) {
68
- try {
69
- console.log(`Killing process ${pid} on port ${port}...`);
70
- execSync(`taskkill /PID ${pid} /F`, { encoding: "utf8", timeout: 5e3 });
71
- } catch {
824
+ pids = [...new Set(pids)];
825
+ for (const pid of pids) {
826
+ try {
827
+ console.log(`Killing process ${pid} on port ${port}...`);
828
+ execSync(`taskkill /PID ${pid} /F`, { encoding: "utf8", timeout: 5e3 });
829
+ } catch {
830
+ }
72
831
  }
73
- }
74
- } else {
75
- const output = execSync(`lsof -ti:${targetPort}`, { encoding: "utf8", timeout: 5e3 });
76
- const lines = output.trim().split("\n");
77
- for (const line of lines) {
78
- const pid = parseInt(line.trim(), 10);
79
- if (!isNaN(pid) && pid > 0) {
80
- pids.push(pid);
832
+ } else {
833
+ const output = execSync(`lsof -ti:${targetPort}`, { encoding: "utf8", timeout: 5e3 });
834
+ const lines = output.trim().split("\n");
835
+ for (const line of lines) {
836
+ const pid = parseInt(line.trim(), 10);
837
+ if (!isNaN(pid) && pid > 0) {
838
+ pids.push(pid);
839
+ }
81
840
  }
82
- }
83
- pids = [...new Set(pids)];
84
- for (const pid of pids) {
85
- try {
86
- console.log(`Killing process ${pid} on port ${targetPort}...`);
87
- execSync(`kill -9 ${pid}`, { encoding: "utf8", timeout: 5e3 });
88
- } catch {
841
+ pids = [...new Set(pids)];
842
+ for (const pid of pids) {
843
+ try {
844
+ console.log(`Killing process ${pid} on port ${port}...`);
845
+ execSync(`kill -9 ${pid}`, { encoding: "utf8", timeout: 5e3 });
846
+ } catch {
847
+ }
89
848
  }
90
849
  }
850
+ } catch {
91
851
  }
92
- } catch {
93
852
  }
853
+ process.env["PORT"] = String(port);
854
+ killProcessOnPort(port);
855
+ const url = `http://localhost:${port}`;
856
+ console.log(`Server running at ${url}`);
857
+ console.log(` Proxy: ${url}/proxy`);
858
+ console.log(``);
859
+ console.log(`Route AI coding tools through the proxy:`);
860
+ console.log(` Claude Code: ANTHROPIC_BASE_URL=${url}/proxy claude`);
861
+ console.log(` OpenCode: LLM_BASE_URL=${url}/proxy opencode`);
862
+ console.log(` MiMo Code: OPENAI_BASE_URL=${url}/proxy mimo`);
863
+ console.log(
864
+ ` Direct HTTP: curl ${url}/proxy/v1/messages -d '{"model":"...","messages":[...]}'`
865
+ );
866
+ console.log(``);
867
+ console.log(`Routing environment variables:`);
868
+ console.log(` ROUTES JSON map of model prefix -> upstream URL`);
869
+ console.log(` DEFAULT_UPSTREAM Fallback upstream for unmatched models`);
870
+ console.log(
871
+ ` Example: ROUTES='{"claude-":"https://api.anthropic.com","MiniMax":"https://api.minimaxi.com/anthropic"}'`
872
+ );
873
+ const openBrowser = (targetUrl) => {
874
+ let command;
875
+ switch (process.platform) {
876
+ case "darwin":
877
+ command = ["open", targetUrl];
878
+ break;
879
+ case "linux":
880
+ command = ["xdg-open", targetUrl];
881
+ break;
882
+ case "win32":
883
+ command = ["cmd", "/c", "start", targetUrl];
884
+ break;
885
+ default:
886
+ break;
887
+ }
888
+ if (command === void 0) return;
889
+ const [bin, ...cmdArgs] = command;
890
+ if (bin === void 0) return;
891
+ spawn(bin, cmdArgs, { stdio: "ignore", detached: true });
892
+ };
893
+ if (open) {
894
+ openBrowser(url);
895
+ }
896
+ const outputDir = __dirname2;
897
+ const serverPath = join3(outputDir, "../.output/server/index.mjs");
898
+ const serverEnv = { ...process.env };
899
+ if (configDir !== void 0) {
900
+ let resolvedPath = join3(configDir, "config.json");
901
+ const msysMatch = /^\\([a-z])\\(.*)$/i.exec(resolvedPath);
902
+ if (msysMatch !== null) {
903
+ const drive = (msysMatch[1] ?? "").toUpperCase();
904
+ const rest = msysMatch[2] ?? "";
905
+ resolvedPath = `${drive}:\\${rest}`;
906
+ }
907
+ serverEnv["LLM_INSPECTOR_CONFIG_PATH"] = resolvedPath;
908
+ }
909
+ if (providersJson !== void 0) {
910
+ serverEnv["LLM_INSPECTOR_PROVIDERS_JSON"] = providersJson;
911
+ }
912
+ const serverProcess = spawn(process.execPath, [serverPath], {
913
+ stdio: ["ignore", "inherit", "inherit"],
914
+ detached: true,
915
+ env: serverEnv
916
+ });
917
+ serverProcess.unref();
94
918
  }
95
- process.env["PORT"] = String(port);
96
- killProcessOnPort(port);
97
- var url = `http://localhost:${port}`;
98
- console.log(`Server running at ${url}`);
99
- console.log(` Proxy: ${url}/proxy`);
100
- console.log(``);
101
- console.log(`Route AI coding tools through the proxy:`);
102
- console.log(` Claude Code: ANTHROPIC_BASE_URL=${url}/proxy claude`);
103
- console.log(` OpenCode: LLM_BASE_URL=${url}/proxy opencode`);
104
- console.log(` MiMo Code: OPENAI_BASE_URL=${url}/proxy mimo`);
105
- console.log(` Direct HTTP: curl ${url}/proxy/v1/messages -d '{"model":"...","messages":[...]}'`);
106
- console.log(``);
107
- console.log(`Routing environment variables:`);
108
- console.log(` ROUTES JSON map of model prefix -> upstream URL`);
109
- console.log(` DEFAULT_UPSTREAM Fallback upstream for unmatched models`);
110
- console.log(
111
- ` Example: ROUTES='{"claude-":"https://api.anthropic.com","MiniMax":"https://api.minimaxi.com/anthropic"}'`
112
- );
113
- var openBrowser = (targetUrl) => {
114
- let command;
115
- switch (process.platform) {
116
- case "darwin":
117
- command = ["open", targetUrl];
118
- break;
119
- case "linux":
120
- command = ["xdg-open", targetUrl];
121
- break;
122
- case "win32":
123
- command = ["cmd", "/c", "start", targetUrl];
124
- break;
125
- default:
126
- break;
127
- }
128
- if (command === void 0) return;
129
- const [bin, ...cmdArgs] = command;
130
- if (bin === void 0) return;
131
- spawn(bin, cmdArgs, { stdio: "ignore", detached: true });
132
- };
133
- if (open) {
134
- openBrowser(url);
135
- }
136
- var outputDir = __dirname;
137
- var serverPath = join(outputDir, "../.output/server/index.mjs");
138
- var serverEnv = { ...process.env };
139
- if (configDir !== void 0) {
140
- let resolvedPath = join(configDir, "config.json");
141
- if (resolvedPath.startsWith("\\c\\")) {
142
- resolvedPath = "C:" + resolvedPath;
143
- }
144
- serverEnv["LLM_INSPECTOR_CONFIG_PATH"] = resolvedPath;
145
- }
146
- if (providersJson !== void 0) {
147
- serverEnv["LLM_INSPECTOR_PROVIDERS_JSON"] = providersJson;
148
- }
149
- var serverProcess = spawn(process.execPath, [serverPath], {
150
- stdio: ["ignore", "inherit", "inherit"],
151
- detached: true,
152
- env: serverEnv
153
- });
154
- serverProcess.unref();