@tonyclaw/llm-inspector 1.7.0 → 1.7.2

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.
package/.output/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli.ts
4
- import { spawn } from "node:child_process";
4
+ import { spawn, execSync } from "node:child_process";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { dirname, join } from "node:path";
7
7
  var __filename = fileURLToPath(import.meta.url);
@@ -30,7 +30,60 @@ for (let i = 0; i < args.length; i++) {
30
30
  break;
31
31
  }
32
32
  }
33
+ function killProcessOnPort(targetPort) {
34
+ const platform = process.platform;
35
+ try {
36
+ let pids = [];
37
+ if (platform === "win32") {
38
+ const output = execSync(`netstat -ano | findstr :${targetPort}`, {
39
+ encoding: "utf8",
40
+ timeout: 5e3
41
+ });
42
+ const lines = output.trim().split("\n");
43
+ for (const line of lines) {
44
+ const parts = line.trim().split(/\s+/);
45
+ if (parts.length >= 5) {
46
+ const localAddress = parts[1] ?? "";
47
+ const pidStr = parts[4] ?? "";
48
+ if (localAddress !== "" && pidStr !== "" && localAddress.includes(`:${targetPort}`)) {
49
+ const pid = parseInt(pidStr, 10);
50
+ if (!isNaN(pid) && pid > 0) {
51
+ pids.push(pid);
52
+ }
53
+ }
54
+ }
55
+ }
56
+ pids = [...new Set(pids)];
57
+ for (const pid of pids) {
58
+ try {
59
+ console.log(`Killing process ${pid} on port ${port}...`);
60
+ execSync(`taskkill /PID ${pid} /F`, { encoding: "utf8", timeout: 5e3 });
61
+ } catch {
62
+ }
63
+ }
64
+ } else {
65
+ const output = execSync(`lsof -ti:${targetPort}`, { encoding: "utf8", timeout: 5e3 });
66
+ const lines = output.trim().split("\n");
67
+ for (const line of lines) {
68
+ const pid = parseInt(line.trim(), 10);
69
+ if (!isNaN(pid) && pid > 0) {
70
+ pids.push(pid);
71
+ }
72
+ }
73
+ pids = [...new Set(pids)];
74
+ for (const pid of pids) {
75
+ try {
76
+ console.log(`Killing process ${pid} on port ${targetPort}...`);
77
+ execSync(`kill -9 ${pid}`, { encoding: "utf8", timeout: 5e3 });
78
+ } catch {
79
+ }
80
+ }
81
+ }
82
+ } catch {
83
+ }
84
+ }
33
85
  process.env["PORT"] = String(port);
86
+ killProcessOnPort(port);
34
87
  var url = `http://localhost:${port}`;
35
88
  console.log(`Server running at ${url}`);
36
89
  console.log(` Proxy: ${url}/proxy`);
@@ -1,5 +1,5 @@
1
1
  {
2
- "date": "2026-06-03T08:20:50.424Z",
2
+ "date": "2026-06-03T09:30:25.048Z",
3
3
  "preset": "node-server",
4
4
  "framework": {
5
5
  "name": "nitro",