@zshuangmu/agenthub 0.4.11 → 0.4.12
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/package.json +1 -1
- package/src/api-server.js +2 -2
- package/src/cli.js +32 -1
- package/src/commands/api.js +2 -1
- package/src/commands/web.js +2 -1
- package/src/web-server.js +2 -2
package/package.json
CHANGED
package/src/api-server.js
CHANGED
|
@@ -66,7 +66,7 @@ function isValidSlug(slug) {
|
|
|
66
66
|
return /^[a-z0-9-]+$/.test(slug) && slug.length <= 100;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export async function createApiServer({ registryDir, port = 3000 }) {
|
|
69
|
+
export async function createApiServer({ registryDir, port = 3000, host = "0.0.0.0" }) {
|
|
70
70
|
// 初始化数据库
|
|
71
71
|
await initDatabase(registryDir);
|
|
72
72
|
|
|
@@ -228,7 +228,7 @@ export async function createApiServer({ registryDir, port = 3000 }) {
|
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
startRateLimiterCleanup();
|
|
231
|
-
await new Promise((resolve) => server.listen(port,
|
|
231
|
+
await new Promise((resolve) => server.listen(port, host, resolve));
|
|
232
232
|
const address = server.address();
|
|
233
233
|
const actualPort = typeof address === "object" && address ? address.port : port;
|
|
234
234
|
|
package/src/cli.js
CHANGED
|
@@ -297,9 +297,39 @@ agenthub serve - 启动完整服务(前端+后端)
|
|
|
297
297
|
--registry <dir> Registry 目录 (必需)
|
|
298
298
|
--port <port> 前端端口号 (默认: 3000)
|
|
299
299
|
--api-port <port> 后端 API 端口号 (默认: 3001)
|
|
300
|
+
--host <host> 监听地址 (默认: 0.0.0.0)
|
|
300
301
|
|
|
301
302
|
示例:
|
|
302
303
|
agenthub serve --registry ./.registry --port 3000
|
|
304
|
+
agenthub serve --registry ./.registry --host 127.0.0.1
|
|
305
|
+
`,
|
|
306
|
+
api: `
|
|
307
|
+
agenthub api - 仅启动 API 后端服务
|
|
308
|
+
|
|
309
|
+
用法:
|
|
310
|
+
agenthub api --registry <dir> --port <port>
|
|
311
|
+
|
|
312
|
+
选项:
|
|
313
|
+
--registry <dir> Registry 目录 (必需)
|
|
314
|
+
--port <port> API 端口号 (默认: 3001)
|
|
315
|
+
--host <host> 监听地址 (默认: 0.0.0.0)
|
|
316
|
+
|
|
317
|
+
示例:
|
|
318
|
+
agenthub api --registry ./.registry --port 3001
|
|
319
|
+
`,
|
|
320
|
+
web: `
|
|
321
|
+
agenthub web - 仅启动 Web 前端服务
|
|
322
|
+
|
|
323
|
+
用法:
|
|
324
|
+
agenthub web --port <port> --api-base <url>
|
|
325
|
+
|
|
326
|
+
选项:
|
|
327
|
+
--port <port> Web 端口号 (默认: 3000)
|
|
328
|
+
--api-base <url> API 服务地址 (默认: http://127.0.0.1:3001)
|
|
329
|
+
--host <host> 监听地址 (默认: 0.0.0.0)
|
|
330
|
+
|
|
331
|
+
示例:
|
|
332
|
+
agenthub web --port 3000 --api-base http://127.0.0.1:3001
|
|
303
333
|
`,
|
|
304
334
|
};
|
|
305
335
|
|
|
@@ -537,7 +567,8 @@ async function main() {
|
|
|
537
567
|
case "web": {
|
|
538
568
|
const port = options.port || "3000";
|
|
539
569
|
const apiBase = options.apiBase || "http://127.0.0.1:3001";
|
|
540
|
-
const
|
|
570
|
+
const host = options.host || "0.0.0.0";
|
|
571
|
+
const result = await webCommand({ port, apiBase, host });
|
|
541
572
|
console.log(success(`Server listening at ${result.baseUrl}`));
|
|
542
573
|
console.log(`\n${highlight("🌐 Web 服务已启动")}`);
|
|
543
574
|
console.log(` ${muted("地址:")} ${result.baseUrl}`);
|
package/src/commands/api.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createApiServer } from "../api-server.js";
|
|
|
3
3
|
export async function apiCommand(options) {
|
|
4
4
|
const registry = options.registry || "./.registry";
|
|
5
5
|
const port = parseInt(options.port || "3001", 10);
|
|
6
|
+
const host = options.host || "0.0.0.0";
|
|
6
7
|
|
|
7
|
-
return createApiServer({ registryDir: registry, port });
|
|
8
|
+
return createApiServer({ registryDir: registry, port, host });
|
|
8
9
|
}
|
package/src/commands/web.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createWebServer } from "../web-server.js";
|
|
|
3
3
|
export async function webCommand(options) {
|
|
4
4
|
const port = parseInt(options.port || "3000", 10);
|
|
5
5
|
const apiBase = options.apiBase || "http://127.0.0.1:3001";
|
|
6
|
+
const host = options.host || "0.0.0.0";
|
|
6
7
|
|
|
7
|
-
return createWebServer({ port, apiBase });
|
|
8
|
+
return createWebServer({ port, apiBase, host });
|
|
8
9
|
}
|
package/src/web-server.js
CHANGED
|
@@ -11,7 +11,7 @@ async function fetchApi(endpoint, apiBaseUrl) {
|
|
|
11
11
|
return fetchJsonWithFallback(url);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export async function createWebServer({ port = 3000, apiBase = null }) {
|
|
14
|
+
export async function createWebServer({ port = 3000, apiBase = null, host = "0.0.0.0" }) {
|
|
15
15
|
const apiBaseUrl = apiBase || API_BASE;
|
|
16
16
|
|
|
17
17
|
const server = http.createServer(async (request, response) => {
|
|
@@ -81,7 +81,7 @@ export async function createWebServer({ port = 3000, apiBase = null }) {
|
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
await new Promise((resolve) => server.listen(port,
|
|
84
|
+
await new Promise((resolve) => server.listen(port, host, resolve));
|
|
85
85
|
const address = server.address();
|
|
86
86
|
const actualPort = typeof address === "object" && address ? address.port : port;
|
|
87
87
|
|