@longzai-intelligence-local-server/startup 0.0.0-stage → 0.0.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.
package/README.md CHANGED
@@ -1,3 +1,18 @@
1
- # Temporary Holding Version
1
+ # @longzai-intelligence-local-server/startup
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 桌面本地服务服务端启动助手包。为 `createApp` 工厂形态的服务入口提供标准启动方式:读 `PORT` 与 `HOST` 环境变量,零口随机监听后回读真实端口,可选自登记端口注册表,接管退出信号优雅退出。运行在被监督的后端子进程内,零 Electron 依赖。
4
+
5
+ ## 导出面
6
+
7
+ - `startServerFromEnv`
8
+ - `ListenCapableApp`、`ListenCapableServer`、`ListenOptions`、`StartServerFromEnvOptions`、`StartServerCapabilities` 类型
9
+
10
+ ## 接入配方
11
+
12
+ 桌面入口文件一行接入,Elysia 实例直接满足可监听形态,`createApp` 原样传入无须消费侧包装:
13
+
14
+ ```ts
15
+ import { startServerFromEnv } from '@longzai-intelligence-local-server/startup';
16
+
17
+ await startServerFromEnv({ createApp, serviceName: 'voice-local-server' });
18
+ ```
@@ -0,0 +1,118 @@
1
+ import "./rolldown-runtime-BqT_7tdF.js";
2
+ /**
3
+ * 监听选项形态
4
+ *
5
+ * 与 Elysia 的 listen 选项参数同构即端口与主机键,Elysia 实例无须包装即可作为可监听应用
6
+ */
7
+ type ListenOptions = {
8
+ /**
9
+ * 监听端口,零值表示由系统随机分配
10
+ */
11
+ port: number;
12
+ /**
13
+ * 绑定主机
14
+ */
15
+ hostname?: string;
16
+ };
17
+ /**
18
+ * 监听后服务器实例的结构形态
19
+ *
20
+ * 同时覆盖直接携带 `port` 字段的 Elysia 形态与经 `address` 回读的 node http 形态
21
+ */
22
+ type ListenCapableServer = {
23
+ /**
24
+ * 系统分配后的真实端口,零口监听时由此回读
25
+ */
26
+ port?: number;
27
+ /**
28
+ * 监听地址信息读取方法,node http 形态的回读通道
29
+ */
30
+ address?(): {
31
+ port: number;
32
+ } | string | null;
33
+ };
34
+ /**
35
+ * 可监听应用的结构形态
36
+ *
37
+ * listen 形参为 Elysia 同构的选项形态,Elysia 实例直接满足本形态无须消费侧包装
38
+ */
39
+ type ListenCapableApp = {
40
+ /**
41
+ * 以选项形态开始监听
42
+ *
43
+ * @param options - 监听选项即端口与可选主机
44
+ */
45
+ listen: (options: ListenOptions) => unknown;
46
+ /**
47
+ * 监听后的服务器实例
48
+ */
49
+ server?: ListenCapableServer | null;
50
+ /**
51
+ * 优雅停止监听
52
+ */
53
+ stop?(): unknown;
54
+ };
55
+ /**
56
+ * 实例档能力端点声明
57
+ */
58
+ type StartServerCapabilities = {
59
+ /**
60
+ * 健康探针端点路径
61
+ *
62
+ * @default '/api/health'
63
+ */
64
+ health?: string;
65
+ /**
66
+ * MCP 工具面端点路径
67
+ *
68
+ * @default '/mcp'
69
+ */
70
+ mcp?: string;
71
+ };
72
+ /**
73
+ * 启动助手选项
74
+ */
75
+ type StartServerFromEnvOptions = {
76
+ /**
77
+ * 应用工厂,返回可监听的应用对象
78
+ */
79
+ createApp: () => ListenCapableApp | Promise<ListenCapableApp>;
80
+ /**
81
+ * 端口注册表服务名,提供时服务就绪后自登记
82
+ */
83
+ serviceName?: string;
84
+ /**
85
+ * 生产者完整仓库名,写入实例档作群级 join key
86
+ */
87
+ producer?: string;
88
+ /**
89
+ * 实例档能力端点声明
90
+ */
91
+ capabilities?: StartServerCapabilities;
92
+ /**
93
+ * 绑定主机,缺省读 `HOST` 环境变量再回落 localhost
94
+ */
95
+ host?: string;
96
+ /**
97
+ * 端口号,缺省读 `PORT` 环境变量再回落零值随机
98
+ */
99
+ port?: number;
100
+ /**
101
+ * 端口注册表目录,缺省走注册表自身的工作区锚定
102
+ */
103
+ registryDir?: string;
104
+ /**
105
+ * 是否接管退出信号,测试环境可关闭
106
+ *
107
+ * @default true
108
+ */
109
+ handleSignals?: boolean;
110
+ };
111
+ /**
112
+ * 经环境变量启动可监听应用
113
+ *
114
+ * @param options - 启动助手选项
115
+ * @returns 实际监听的端口号
116
+ */
117
+ declare function startServerFromEnv(options: StartServerFromEnvOptions): Promise<number>;
118
+ export { ListenCapableApp, ListenCapableServer, ListenOptions, StartServerCapabilities, StartServerFromEnvOptions, startServerFromEnv };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import"./rolldown-runtime-BqT_7tdF.js";import{createPortRegistry as e}from"@longzai-intelligence-port/registry";async function t(t){let n=t.port??Number(process.env.PORT??0),r=t.host??process.env.HOST??`localhost`,i=await t.createApp();await i.listen({port:n,hostname:r});let a=n;if(typeof i.server?.port==`number`)a=i.server.port;else{let e=i.server?.address?.();typeof e==`object`&&e&&(a=e.port)}let o=null;if(t.serviceName&&(o=e(t.registryDir?{registryDir:t.registryDir}:void 0),await o.register(t.serviceName,{port:a,host:r,pid:process.pid,startedAt:Date.now(),producer:t.producer,capabilities:t.capabilities})),t.handleSignals!==!1){let e=()=>{(async()=>{try{o&&t.serviceName&&await o.deregister(t.serviceName),await i.stop?.()}finally{process.exit(0)}})()};process.once(`SIGTERM`,e),process.once(`SIGINT`,e)}return a}export{t as startServerFromEnv};
@@ -0,0 +1 @@
1
+ import"node:module";export{};
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-local-server/startup",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "description": "Longzai Intelligence 桌面本地服务服务端启动助手包",
5
+ "keywords": [
6
+ "desktop",
7
+ "elysia",
8
+ "local-server",
9
+ "longzai-intelligence",
10
+ "port-registry",
11
+ "startup"
12
+ ],
13
+ "license": "UNLICENSED",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "scripts": {
25
+ "build": "lzi-builder",
26
+ "build:prod": "NODE_ENV=production bun run build",
27
+ "prepublishOnly": "bun run build:prod",
28
+ "dev": "lzi-builder --watch",
29
+ "clean": "lzi-dev-tools clean",
30
+ "test": "vitest run",
31
+ "test:watch": "vitest",
32
+ "test:coverage": "vitest run --coverage",
33
+ "lint": "lzi-lint lint",
34
+ "lint:fix": "lzi-lint fix",
35
+ "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
36
+ "typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
37
+ "typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
38
+ "typecheck:test": "lzi-tsgo typecheck tsconfig/test.json"
39
+ },
40
+ "dependencies": {
41
+ "@longzai-intelligence-port/registry": "^0.0.5"
42
+ },
43
+ "devDependencies": {
44
+ "@longzai-intelligence-testing/utils": "^0.0.3",
45
+ "@longzai-intelligence-vitest/config": "^0.0.12",
46
+ "elysia": "^1.4.29",
47
+ "vitest": "^4.1.4"
48
+ },
49
+ "packageManager": "bun@1.4.3"
50
+ }