@h-ai/cli 0.1.0-alpha.47 → 0.1.0-alpha.48

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@h-ai/cli",
3
3
  "type": "module",
4
- "version": "0.1.0-alpha.47",
4
+ "version": "0.1.0-alpha.48",
5
5
  "description": "Hai Framework CLI for project scaffolding and code generation.",
6
6
  "license": "Apache-2.0",
7
7
  "keywords": [
@@ -34,7 +34,7 @@
34
34
  "ora": "^9.1.0",
35
35
  "prompts": "^2.4.2",
36
36
  "yaml": "^2.7.0",
37
- "@h-ai/core": "0.1.0-alpha.47"
37
+ "@h-ai/core": "0.1.0-alpha.48"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/fs-extra": "^11.0.4",
@@ -2,6 +2,10 @@
2
2
  # {{projectName}} API Service - Serv / HTTP 入口配置
3
3
  # =============================================================================
4
4
 
5
+ server:
6
+ host: 127.0.0.1
7
+ port: 3000
8
+
5
9
  http:
6
10
  apiPrefix: /api/v1
7
11
  openapi:
@@ -1,3 +1,4 @@
1
+ import type { ServConfig } from '@h-ai/serv'
1
2
  import process from 'node:process'
2
3
  import { core } from '@h-ai/core'
3
4
  import { serv } from '@h-ai/serv'
@@ -9,7 +10,11 @@ const logger = core.logger.child({ app: '{{api.servicePackageName}}', scope: 'en
9
10
  async function main(): Promise<void> {
10
11
  await initApp()
11
12
 
13
+ // host/port 来自 config/_serv.yml 的 server(HOST/PORT 环境变量高于配置文件)。
14
+ const { server } = core.config.getOrThrow<ServConfig>('serv')
12
15
  serv.listen({{api.serviceAppFactoryName}}(), {
16
+ host: server.host,
17
+ port: server.port,
13
18
  onListening: info => logger.info('API service listening', { address: info.address, port: info.port }),
14
19
  onClose: closeApp,
15
20
  })
@@ -5,6 +5,10 @@
5
5
  # 业务接口路径直接写在对应 *-contract.ts;公共 HTTP 传输配置以本文件为准。
6
6
  # =============================================================================
7
7
 
8
+ server:
9
+ host: 127.0.0.1
10
+ port: 3000
11
+
8
12
  http:
9
13
  apiPrefix: /api/v1
10
14
  openapi:
@@ -1,18 +1,18 @@
1
- import process from 'node:process'
1
+ import type { ServConfigInput } from '@h-ai/serv'
2
2
  import { core } from '@h-ai/core'
3
- import { serv } from '@h-ai/serv'
3
+ import { serv, ServConfigSchema } from '@h-ai/serv'
4
4
  import { createServerApp } from './app-server.js'
5
5
 
6
6
  // 加载 config/ 下的 _core.yml / _serv.yml 等配置文件(约定优于配置)
7
7
  core.init({ configDir: './config', logging: { level: 'info' } })
8
8
 
9
+ // host/port 来自 config/_serv.yml 的 server(HOST/PORT 环境变量高于配置文件)。
10
+ const { server } = ServConfigSchema.parse(core.config.get<ServConfigInput>('serv') ?? {})
9
11
  const app = createServerApp()
10
- const port = process.env.PORT ? Number(process.env.PORT) : 3000
11
- const host = process.env.HOST ?? '127.0.0.1'
12
12
  const listenApp = app as Parameters<typeof serv.listen>[0]
13
13
 
14
14
  serv.listen(listenApp, {
15
- port,
16
- host,
17
- onListening: info => core.logger.info('{{fullstack.servPackageName}} listening', { host, port: info.port }),
15
+ host: server.host,
16
+ port: server.port,
17
+ onListening: info => core.logger.info('{{fullstack.servPackageName}} listening', { host: server.host, port: info.port }),
18
18
  })
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "{{projectName}}",
3
- "version": "0.1.0-alpha.47",
3
+ "version": "0.1.0-alpha.48",
4
4
  "private": true,
5
5
  "description": "{{#if_eq appType 'admin'}}Enterprise management system built with hai Agent Framework{{/if_eq}}{{#if_eq appType 'website'}}Enterprise website built with hai Agent Framework{{/if_eq}}{{#if_eq appType 'h5'}}Mobile H5 app built with hai Agent Framework{{/if_eq}}{{#if_eq appType 'api'}}REST API service built with hai Agent Framework{{/if_eq}}{{#if_eq appType 'mobile-app'}}Mobile app built with hai Agent Framework{{/if_eq}}",
6
6
  "keywords": ["hai", {{#unless isSvelteOnlyApp}}"sveltekit", {{/unless}}"svelte5", "{{appType}}"],
@@ -131,6 +131,10 @@ transport 默认保护同源 `/api/*` endpoint 与 SvelteKit `__data.json` 页
131
131
  同时驱动 `hooks.server.ts` 与浏览器端 `kit.client.installBrowserTransport()`:
132
132
 
133
133
  ```yml
134
+ server:
135
+ host: 127.0.0.1
136
+ port: 3000
137
+
134
138
  transport:
135
139
  keyExchangePath: /api/_hai/key-exchange
136
140
  requireEncryption: true
@@ -150,7 +154,8 @@ import rawKitConfig from '../config/_kit.yml?raw'
150
154
  export const appKitConfig = resolveKitConfig(parse(rawKitConfig) ?? {})
151
155
  ```
152
156
 
153
- `_kit.yml` 只放公开的 transport 路径/开关,不放密钥;如自定义 `keyExchangePath`,浏览器端必须同步映射为 `keyExchangeUrl`。
157
+ `resolveKitConfig()` 同时解析 `server`(host/port)与 `transport`;host/port 优先级为 `HOST` / `PORT` 环境变量 > `_kit.yml` 的 `server` > 默认 `127.0.0.1:3000`(与 `@h-ai/serv` 同构)。
158
+ `_kit.yml` 只放公开的 server/transport 路径/开关,不放密钥;如自定义 `keyExchangePath`,浏览器端必须同步映射为 `keyExchangeUrl`。
154
159
 
155
160
  ## 核心 API
156
161
 
@@ -86,8 +86,11 @@ const app = serv.createApp({
86
86
  },
87
87
  })
88
88
 
89
- // Node.js 启动(自动读取 PORT / HOST 环境变量;onClose 自动监听 SIGINT/SIGTERM)
89
+ // Node.js 启动(host/port 来自 _serv.yml 的 server;HOST/PORT 环境变量高于配置文件;onClose 自动监听 SIGINT/SIGTERM)
90
+ const { server } = core.config.getOrThrow<ServConfig>('serv')
90
91
  serv.listen(app, {
92
+ host: server.host,
93
+ port: server.port,
91
94
  onListening: info => logger.info('API service listening', { port: info.port }),
92
95
  onClose: closeApp, // 业务模块关闭函数(ai/storage/iam/reldb 等反向释放)
93
96
  })
@@ -265,6 +268,10 @@ const app = serv.createApp({
265
268
 
266
269
  ```yaml
267
270
  # config/_serv.yml
271
+ server:
272
+ host: 127.0.0.1
273
+ port: 3000
274
+
268
275
  http:
269
276
  apiPrefix: /api/v1
270
277
  openapi: