From ddfdb63598f9c9fac3eb5405cbd83b60226bb6d5 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Thu, 22 Jan 2026 01:53:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=B8=AD=E7=9A=84=E8=A1=A8=E6=A0=BC=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=EF=BC=9B=E6=B7=BB=E5=8A=A0=E8=B7=AF=E7=94=B1=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../local-app-manager/assistant-app.ts | 4 +- assistant/src/server.ts | 12 +- cli-center/src/data/docs/10-config.md | 131 +++++++++++------- package.json | 2 +- 4 files changed, 98 insertions(+), 51 deletions(-) diff --git a/assistant/src/module/assistant/local-app-manager/assistant-app.ts b/assistant/src/module/assistant/local-app-manager/assistant-app.ts index 3f337bf..3127d81 100644 --- a/assistant/src/module/assistant/local-app-manager/assistant-app.ts +++ b/assistant/src/module/assistant/local-app-manager/assistant-app.ts @@ -127,8 +127,8 @@ export class AssistantApp extends Manager { } async initRouterApp() { const config = this.config.getConfig(); - const routerProxy = config.router.proxy || []; - const base = config.router.base ?? false; + const routerProxy = config?.router?.proxy || []; + const base = config.router?.base ?? false; if (base) { routerProxy.push({ type: 'router', diff --git a/assistant/src/server.ts b/assistant/src/server.ts index 385aa8f..479724f 100644 --- a/assistant/src/server.ts +++ b/assistant/src/server.ts @@ -9,7 +9,7 @@ import { program } from 'commander'; import { spawnSync } from 'node:child_process'; import path from 'node:path' import chalk from 'chalk'; -import { AssistantApp } from './lib.ts'; +import { AssistantApp, checkFileExists } from './lib.ts'; import { getBunPath } from './module/get-bun-path.ts'; import { qwenAsr } from './services/asr/qwen-asr.ts'; export const runServer = async (port: number = 51515, listenPath = '127.0.0.1') => { @@ -72,6 +72,7 @@ program .option('-p, --port ', '服务端口') .option('-s, --start', '是否启动服务') .option('-r, --root ', '工作空间路径') + .option('-i, --input ', '启动的输入文件,例如/workspace/src/main.ts') .option('-e, --interpreter ', '指定使用的解释器', 'bun') .action(async (options) => { // console.log('当前执行路径:', execPath, inte); @@ -105,6 +106,9 @@ program if (options.root) { pm2Command += ` --root ${options.root}`; } + if (options.input) { + pm2Command += ` --input ${options.input}`; + } console.log(chalk.gray('执行命令:'), pm2Command); console.log(chalk.gray('脚本路径:'), runPath); @@ -151,6 +155,12 @@ program const listenPort = parseInt(options.port || config?.server?.port); const listenPath = config?.server?.path || '::'; const server = await runServer(listenPort, listenPath); + if (options.input) { + const _input = path.resolve(options.input); + if (checkFileExists(_input)) { + await import(_input); + } + } } else { console.log('请使用 -s 参数启动服务'); } diff --git a/cli-center/src/data/docs/10-config.md b/cli-center/src/data/docs/10-config.md index 0f3341a..9eccb24 100644 --- a/cli-center/src/data/docs/10-config.md +++ b/cli-center/src/data/docs/10-config.md @@ -22,10 +22,10 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| -| id | `string` | 应用唯一标识符,用于识别具体设备或应用实例 | -| url | `string` | 应用访问地址 | +| 字段 | 类型 | 说明 | +| ---- | -------- | ------------------------------------------ | +| id | `string` | 应用唯一标识符,用于识别具体设备或应用实例 | +| url | `string` | 应用访问地址 | ## token - 访问令牌 @@ -37,8 +37,8 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| +| 字段 | 类型 | 说明 | +| ----- | -------- | -------- | | token | `string` | 访问令牌 | ## registry - 注册中心 @@ -51,8 +51,8 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| +| 字段 | 类型 | 说明 | +| -------- | -------- | ------------ | | registry | `string` | 注册中心地址 | ## proxy - 前端代理配置 @@ -71,12 +71,12 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| -| proxy | `ProxyInfo[]` | 代理配置数组 | -| proxy[].path | `string` | 匹配的路径前缀 | -| proxy[].target | `string` | 目标服务器地址 | -| proxy[].pathname | `string` | 转发到目标服务器的路径 | +| 字段 | 类型 | 说明 | +| ---------------- | ------------- | ---------------------- | +| proxy | `ProxyInfo[]` | 代理配置数组 | +| proxy[].path | `string` | 匹配的路径前缀 | +| proxy[].target | `string` | 目标服务器地址 | +| proxy[].pathname | `string` | 转发到目标服务器的路径 | 示例:访问 `/root/home` 会被转发到 `https://kevisual.cn/root/home` @@ -105,6 +105,31 @@ createdAt: '2025-12-18' |------|------|{------| | api.proxy | `ProxyInfo[]` | API代理配置数组 | +## router - 路由配置 + +配置应用的路由代理功能。 + +```json +{ + "router": { + "proxy": [ + { + "type": "router", + "router": { + "url": "https://kevisual.cn/api/router" + } + } + ], + "base": true + } +} +``` + +| 字段 | 类型 | 说明 | +| ------------ | ------------- | ----------------------------------------------------------------- | +| router.proxy | `ProxyInfo[]` | 代理配置数组 | +| router.base | `boolean` | 是否注册基础路由,监听https://kevisual.cn/api/router,默认 `false` | + ## description - 应用描述 应用的描述信息。 @@ -115,8 +140,8 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| +| 字段 | 类型 | 说明 | +| ----------- | -------- | ------------ | | description | `string` | 应用描述信息 | ## server - 服务器配置 @@ -132,10 +157,10 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| +| 字段 | 类型 | 说明 | +| ----------- | --------- | -------------------------------- | | server.path | `string`` | 服务器监听地址,默认 `127.0.0.1` | -| server.port | `number` | 服务器监听端口号 | +| server.port | `number` | 服务器监听端口号 | ## share - 远程访问配置 @@ -150,9 +175,9 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| -| share.url | `string` | 远程应用代理地址 | +| 字段 | 类型 | 说明 | +| ------------- | --------- | -------------------- | +| share.url | `string` | 远程应用代理地址 | | share.enabled | `boolean` | 是否启用远程访问功能 | ## watch - 文件监听配置 @@ -167,8 +192,8 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| +| 字段 | 类型 | 说明 | +| ------------- | --------- | ---------------- | | watch.enabled | `boolean` | 是否启用文件监听 | ## home - 首页路径 @@ -181,8 +206,8 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| +| 字段 | 类型 | 说明 | +| ---- | -------- | -------- | | home | `string` | 首页路径 | ## ai - AI功能配置 @@ -200,12 +225,12 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| -| ai.enabled | `boolean` | 是否启用 AI 功能 | -| ai.provider | `string` | AI 提供商,可选 `'DeepSeek'` | `'Custom'` | -| ai.apiKey | `string` | API 密钥 | -| ai.model | `string` | 使用的模型名称 | +| 字段 | 类型 | 说明 | +| ----------- | --------- | ---------------------------- | ---------- | +| ai.enabled | `boolean` | 是否启用 AI 功能 | +| ai.provider | `string` | AI 提供商,可选 `'DeepSeek'` | `'Custom'` | +| ai.apiKey | `string` | API 密钥 | +| ai.model | `string` | 使用的模型名称 | ## asr - 语音识别配置 @@ -220,10 +245,10 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| +| 字段 | 类型 | 说明 | +| ----------- | --------- | -------------------- | | asr.enabled | `boolean` | 是否启用语音识别功能 | -| asr.token | `string` | 阿里云 ASR 服务令牌 | +| asr.token | `string` | 阿里云 ASR 服务令牌 | 使用模型:`qwen3-asr-flash-realtime` @@ -239,11 +264,12 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| +| 字段 | 类型 | 说明 | +| ---------- | -------- | ------------------------------------------------- | | auth.share | `string` | 共享访问模式,影响 pages 目录下页面的对外共享权限 | **share 可选值:** + - `"protected"` - 需要认证才能访问(默认) - `"public"` - 公开访问,无需认证 - `"private"` - 私有访问,完全禁止外部访问 @@ -293,16 +319,16 @@ createdAt: '2025-12-18' } ``` -| 字段 | 类型 | 说明 | -|------|------|------| -| storage[].id | `string` | 存储标识符,唯一标识一个存储配置 | -| storage[].type | `'local' \| 's3' \| 'minio'` | 存储类型 | -| storage[].path | `string` | 本地存储路径(仅 type 为 `local` 时有效) | -| storage[].bucket | `string` | 存储桶名称(仅 type 为 `s3` 或 `minio` 时有效) | -| storage[].region | `string` | 存储区域(仅 type 为 `s3` 或 `minio` 时有效) | -| storage[].accessKeyId | `string` | 访问密钥 ID(仅 type 为 `s3` 或 `minio` 时有效) | -| storage[].secretAccessKey | `string` | 访问密钥(仅 type 为 `s3` 或 `minio` 时有效) | -| storage[].endpoint | `string` | 服务端点地址(仅 type 为 `s3` 或 `minio` 时有效,可选) | +| 字段 | 类型 | 说明 | +| ------------------------- | ---------------------------- | ------------------------------------------------------- | +| storage[].id | `string` | 存储标识符,唯一标识一个存储配置 | +| storage[].type | `'local' \| 's3' \| 'minio'` | 存储类型 | +| storage[].path | `string` | 本地存储路径(仅 type 为 `local` 时有效) | +| storage[].bucket | `string` | 存储桶名称(仅 type 为 `s3` 或 `minio` 时有效) | +| storage[].region | `string` | 存储区域(仅 type 为 `s3` 或 `minio` 时有效) | +| storage[].accessKeyId | `string` | 访问密钥 ID(仅 type 为 `s3` 或 `minio` 时有效) | +| storage[].secretAccessKey | `string` | 访问密钥(仅 type 为 `s3` 或 `minio` 时有效) | +| storage[].endpoint | `string` | 服务端点地址(仅 type 为 `s3` 或 `minio` 时有效,可选) | ## 完整配置示例 @@ -329,6 +355,17 @@ createdAt: '2025-12-18' } ] }, + "router": { + "proxy": [ + { + "type": "router", + "router": { + "url": "https://kevisual.cn/api/router" + } + } + ], + "base": true + }, "description": "生产环境助手应用", "server": { "path": "0.0.0.0", diff --git a/package.json b/package.json index 701a582..ea89a9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cli", - "version": "0.0.91", + "version": "0.0.92", "description": "envision 命令行工具", "type": "module", "basename": "/root/cli",