agent-host-protocol-ui 0.1.1 → 0.1.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.
Files changed (2) hide show
  1. package/bin/cli.js +53 -23
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -46,34 +46,49 @@ function getNetworkIps() {
46
46
 
47
47
  // Parse command line arguments
48
48
  const args = process.argv.slice(2);
49
- let port = 5173;
50
- let listenHost = "localhost";
49
+ let port = Number.parseInt(process.env.PORT || "", 10) || 5173;
50
+ let listenHost = process.env.HOST || "localhost";
51
51
  let autoOpen = true;
52
- let agentHostParam = "";
52
+ let agentHostParam = process.env.AGENT_HOST || "";
53
53
 
54
54
  for (let i = 0; i < args.length; i++) {
55
- const arg = args[i];
55
+ let arg = args[i];
56
+ let value;
57
+ if (arg.includes("=")) {
58
+ const eqIdx = arg.indexOf("=");
59
+ value = arg.slice(eqIdx + 1);
60
+ arg = arg.slice(0, eqIdx);
61
+ }
62
+
56
63
  if (arg === "--port" || arg === "-p") {
57
- port = Number.parseInt(args[++i], 10) || 5173;
64
+ port = Number.parseInt(value ?? args[++i], 10) || 5173;
58
65
  } else if (arg === "--no-open") {
59
66
  autoOpen = false;
60
67
  } else if (arg === "--bind" || arg === "-b" || arg === "--hostname" || arg === "--listen") {
61
- listenHost = args[++i] || "0.0.0.0";
68
+ listenHost = value ?? args[++i] ?? "0.0.0.0";
62
69
  } else if (arg === "--host" || arg === "-h") {
63
- const next = args[i + 1];
64
- if (!next || next.startsWith("-")) {
65
- // Flag present without value: bind to 0.0.0.0 (like Vite --host)
66
- listenHost = "0.0.0.0";
70
+ if (value !== undefined) {
71
+ if (value.startsWith("ws://") || value.startsWith("wss://")) {
72
+ agentHostParam = value;
73
+ } else {
74
+ listenHost = value;
75
+ }
67
76
  } else {
68
- i++;
69
- if (next.startsWith("ws://") || next.startsWith("wss://")) {
70
- agentHostParam = next;
77
+ const next = args[i + 1];
78
+ if (!next || next.startsWith("-")) {
79
+ // Flag present without value: bind to 0.0.0.0 (like Vite --host)
80
+ listenHost = "0.0.0.0";
71
81
  } else {
72
- listenHost = next;
82
+ i++;
83
+ if (next.startsWith("ws://") || next.startsWith("wss://")) {
84
+ agentHostParam = next;
85
+ } else {
86
+ listenHost = next;
87
+ }
73
88
  }
74
89
  }
75
90
  } else if (arg === "--agent-host" || arg === "--ws" || arg === "-a") {
76
- agentHostParam = args[++i] || "";
91
+ agentHostParam = value ?? args[++i] ?? "";
77
92
  } else if (arg === "--help") {
78
93
  console.log(`
79
94
  agent-host-protocol-ui - Client-side UI for Agent Host Protocol
@@ -84,10 +99,15 @@ Usage:
84
99
  Options:
85
100
  -b, --bind <address> Hostname/IP to listen on (e.g. 0.0.0.0 or localhost, default: localhost)
86
101
  --host [address] Bind to address (default: 0.0.0.0 if flag present without value)
87
- -p, --port <number> Port to listen on (default: 5173)
102
+ -p, --port <number> Port to listen on (default: 5173 or process.env.PORT)
88
103
  -a, --agent-host <ws-url> Pre-configure agent host WebSocket URL
89
104
  --no-open Do not automatically open the browser
90
105
  --help Show help
106
+
107
+ Environment variables:
108
+ HOST=<address> Default hostname/IP to listen on (e.g. 0.0.0.0)
109
+ PORT=<number> Default port to listen on
110
+ AGENT_HOST=<ws-url> Default agent host WebSocket URL
91
111
  `);
92
112
  process.exit(0);
93
113
  }
@@ -154,20 +174,30 @@ server.on("error", (err) => {
154
174
 
155
175
  server.listen(port, listenHost, () => {
156
176
  const isWildcard = listenHost === "0.0.0.0" || listenHost === "::";
177
+ const isLocal = listenHost === "localhost" || listenHost === "127.0.0.1" || listenHost === "::1";
157
178
  const querySuffix = agentHostParam ? `?host=${encodeURIComponent(agentHostParam)}` : "";
158
- const localUrl = `http://localhost:${port}${querySuffix}`;
179
+
180
+ const displayLocalUrl = `http://localhost:${port}${querySuffix}`;
181
+ const openUrl = isLocal || isWildcard ? displayLocalUrl : `http://${listenHost}:${port}${querySuffix}`;
159
182
  const networkIps = isWildcard ? getNetworkIps() : [];
160
183
 
161
184
  console.log(`
162
185
  ┌────────────────────────────────────────────────────────┐
163
186
  │ │
164
187
  │ Agent Host Protocol UI │
165
- │ │
166
- │ > Local: ${localUrl.padEnd(42)}│`);
188
+ │ │`);
167
189
 
168
- for (const ip of networkIps) {
169
- const netUrl = `http://${ip}:${port}${querySuffix}`;
170
- console.log(`│ > Network: ${netUrl.padEnd(42)}│`);
190
+ if (isWildcard) {
191
+ console.log(`│ > Local: ${displayLocalUrl.padEnd(42)}│`);
192
+ for (const ip of networkIps) {
193
+ const netUrl = `http://${ip}:${port}${querySuffix}`;
194
+ console.log(`│ > Network: ${netUrl.padEnd(42)}│`);
195
+ }
196
+ } else if (isLocal) {
197
+ console.log(`│ > Local: ${displayLocalUrl.padEnd(42)}│`);
198
+ } else {
199
+ const customUrl = `http://${listenHost}:${port}${querySuffix}`;
200
+ console.log(`│ > Host: ${customUrl.padEnd(42)}│`);
171
201
  }
172
202
 
173
203
  console.log(`│ │
@@ -175,7 +205,7 @@ server.listen(port, listenHost, () => {
175
205
  └────────────────────────────────────────────────────────┘
176
206
  `);
177
207
  if (autoOpen) {
178
- openBrowser(localUrl);
208
+ openBrowser(openUrl);
179
209
  }
180
210
  });
181
211
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-host-protocol-ui",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Client-side web UI for the Agent Host Protocol (AHP) inspired by VS Code Agents view",
5
5
  "author": "Yusuke Tsutsumi <yusuke@tsutsumi.io>",
6
6
  "license": "Apache-2.0",