From ee33208e6cc6f8aece184c05c17519673c577eaf Mon Sep 17 00:00:00 2001 From: xiongxiao Date: Fri, 5 Dec 2025 20:53:25 +0800 Subject: [PATCH] fix: fix hot-api for not build in bun app.mjs --- assistant/bun.config.mjs | 7 ++- assistant/package.json | 8 +-- assistant/src/command/asst-server/index.ts | 8 +-- .../src/routes/hot-api/key-sender/index.ts | 19 +++++++ assistant/src/routes/index.ts | 4 +- assistant/src/routes/shop-install/index.ts | 19 ++++--- assistant/src/routes/user/index.ts | 4 +- package.json | 13 +++-- pnpm-lock.yaml | 51 ++++++++++++++----- 9 files changed, 95 insertions(+), 38 deletions(-) create mode 100644 assistant/src/routes/hot-api/key-sender/index.ts diff --git a/assistant/bun.config.mjs b/assistant/bun.config.mjs index e8c7d0e..c82b78b 100644 --- a/assistant/bun.config.mjs +++ b/assistant/bun.config.mjs @@ -6,6 +6,7 @@ import fs from 'node:fs'; // bun run src/index.ts -- import { fileURLToPath } from 'node:url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const external = ['pm2', '@kevisual/hot-api']; /** * * @param {string} p @@ -20,11 +21,10 @@ await Bun.build({ naming: { entry: 'assistant.js', }, - external: ['pm2'], + external, define: { ENVISION_VERSION: JSON.stringify(pkg.version), }, - env: 'ENVISION_*', }); await Bun.build({ @@ -38,8 +38,7 @@ await Bun.build({ define: { ENVISION_VERSION: JSON.stringify(pkg.version), }, - external: ['pm2'], - env: 'ENVISION_*', + external, }); // const copyDist = ['dist', 'bin']; const copyDist = ['dist']; diff --git a/assistant/package.json b/assistant/package.json index ec661b6..0ba2005 100644 --- a/assistant/package.json +++ b/assistant/package.json @@ -20,8 +20,8 @@ ], "scripts": { "dev": "bun run src/run.ts ", - "dev:server": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 bun --watch src/run-server.ts --home ", - "dev:share": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 bun --watch src/test/remote-app.ts ", + "dev:server": "bun --watch src/run-server.ts ", + "dev:share": "bun --watch src/test/remote-app.ts ", "build:lib": "bun run bun-lib.config.mjs", "postbuild:lib": "dts -i src/lib.ts -o assistant-lib.d.ts -d libs -t", "build": "rimraf dist && bun run bun.config.mjs", @@ -45,7 +45,7 @@ "@kevisual/load": "^0.0.6", "@kevisual/local-app-manager": "^0.1.32", "@kevisual/logger": "^0.0.4", - "@kevisual/query": "0.0.30", + "@kevisual/query": "0.0.31", "@kevisual/query-login": "0.0.7", "@kevisual/router": "^0.0.33", "@kevisual/types": "^0.0.10", @@ -75,7 +75,7 @@ "access": "public" }, "dependencies": { - "@kevisual/hot-api": "^0.0.2", + "@kevisual/hot-api": "^0.0.3", "@nut-tree-fork/nut-js": "^4.2.6", "eventemitter3": "^5.0.1", "lowdb": "^7.0.1", diff --git a/assistant/src/command/asst-server/index.ts b/assistant/src/command/asst-server/index.ts index fe7b000..6be6fe3 100644 --- a/assistant/src/command/asst-server/index.ts +++ b/assistant/src/command/asst-server/index.ts @@ -4,10 +4,10 @@ import { spawnSync } from 'node:child_process'; const command = new Command('server') .description('启动服务') .option('-d, --daemon', '是否以守护进程方式运行') - .option('-n, --name ', '服务名称') + .option('-n, --name ', '服务名称', 'assistant-server') .option('-p, --port ', '服务端口') .option('-s, --start', '是否启动服务') - .option('-i, --home', '是否以home方式运行') + .option('-e, --interpreter ', '指定使用的解释器', 'bun') .action((options) => { const { port } = options; const [_interpreter, execPath] = process.argv; @@ -24,8 +24,8 @@ const command = new Command('server') if (port) { shellCommands.push(`-p ${port}`); } - if (options.home) { - shellCommands.push('--home'); + if (options.interpreter) { + shellCommands.push(`-e ${options.interpreter}`); } const basename = _interpreter.split('/').pop(); diff --git a/assistant/src/routes/hot-api/key-sender/index.ts b/assistant/src/routes/hot-api/key-sender/index.ts new file mode 100644 index 0000000..acf7734 --- /dev/null +++ b/assistant/src/routes/hot-api/key-sender/index.ts @@ -0,0 +1,19 @@ +import { app } from '@/app.ts'; +import { Hotkeys } from '@kevisual/hot-api'; +import { useContextKey } from '@kevisual/context'; +app.route({ + path: 'key-sender', + middleware: ['admin-auth'] +}).define(async (ctx) => { + let keys = ctx.query.keys; + if (keys.includes(' ')) { + keys = keys.replace(/\s+/g, '+'); + } + const hotKeys: Hotkeys = useContextKey('hotkeys', () => new Hotkeys()); + if (typeof keys === 'string') { + await hotKeys.pressHotkey({ + hotkey: keys, + }); + } + ctx.body = 'ok'; +}).addTo(app); \ No newline at end of file diff --git a/assistant/src/routes/index.ts b/assistant/src/routes/index.ts index 0bb76ff..3da549f 100644 --- a/assistant/src/routes/index.ts +++ b/assistant/src/routes/index.ts @@ -2,8 +2,10 @@ import { app, assistantConfig } from '../app.ts'; import './config/index.ts'; import './shop-install/index.ts'; import './ai/index.ts'; -import './light-code/index.ts'; +// TODO: +// import './light-code/index.ts'; import './user/index.ts'; +import './hot-api/key-sender/index.ts'; import os from 'node:os'; import { authCache } from '@/module/cache/auth.ts'; diff --git a/assistant/src/routes/shop-install/index.ts b/assistant/src/routes/shop-install/index.ts index fa57b4e..8609c32 100644 --- a/assistant/src/routes/shop-install/index.ts +++ b/assistant/src/routes/shop-install/index.ts @@ -1,11 +1,12 @@ import { app, assistantConfig } from '@/app.ts'; import { AppDownload } from '@/services/app/index.ts'; import { AssistantApp } from '@/module/assistant/index.ts'; -import { shopDefine } from './define.ts'; app .route({ - ...shopDefine.get('getRegistry'), - middleware: ['admin-auth'], + path: 'shop', + key: 'get-registry', + description: '获取应用商店注册表信息', + middleware: ['admin-auth'], metadata: { admin: true, } @@ -19,7 +20,9 @@ app app .route({ - ...shopDefine.get('listInstalled'), + path: 'shop', + key: 'list-installed', + description: '列出当前已安装的所有应用', middleware: ['admin-auth'], metadata: { admin: true, @@ -35,7 +38,9 @@ app app .route({ - ...shopDefine.get('install'), + path: 'shop', + key: 'install', + description: '安装指定的应用,可以指定 id、type、force 和 yes 参数', middleware: ['admin-auth'], metadata: { admin: true, @@ -60,7 +65,9 @@ app app .route({ - ...shopDefine.get('uninstall'), + path: 'shop', + key: 'uninstall', + description: '卸载指定的应用,可以指定 id 和 type 参数', middleware: ['admin-auth'], metadata: { admin: true, diff --git a/assistant/src/routes/user/index.ts b/assistant/src/routes/user/index.ts index 430f71f..1ed6fcc 100644 --- a/assistant/src/routes/user/index.ts +++ b/assistant/src/routes/user/index.ts @@ -7,7 +7,7 @@ app.route({ }).define(async (ctx) => { const { username, password } = ctx.query; const query = assistantConfig.query; - const auth = assistantConfig.getConfig().auth; + const auth = assistantConfig.getConfig().auth || {}; const res = await query.post({ path: 'user', key: 'login', @@ -25,7 +25,7 @@ app.route({ } if (!auth.username) { // 初始管理员账号 - auth.username = 'admin'; + auth.username = loginUser; assistantConfig.setConfig({ auth }); } // 保存配置 diff --git a/package.json b/package.json index 9c44741..ae11d31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cli", - "version": "0.0.71", + "version": "0.0.73", "description": "envision 命令行工具", "type": "module", "basename": "/root/cli", @@ -28,6 +28,7 @@ "scripts": { "dev": "bun src/run.ts ", "dev:tsx": "tsx src/run.ts ", + "dev:server": "cd assistant && bun --watch src/run-server.ts ", "build": "rimraf dist && bun run bun.config.mjs", "deploy": "ev pack -u -p -m no", "pub:me": "npm publish --registry https://npm.xiongxiao.me --tag beta", @@ -41,15 +42,21 @@ "author": "abearxiong", "dependencies": { "@kevisual/context": "^0.0.4", + "@kevisual/hot-api": "^0.0.3", + "@nut-tree-fork/nut-js": "^4.2.6", + "eventemitter3": "^5.0.1", + "lowdb": "^7.0.1", + "lru-cache": "^11.2.4", "micromatch": "^4.0.8", "pm2": "^6.0.14", - "semver": "^7.7.3" + "semver": "^7.7.3", + "unstorage": "^1.17.3" }, "devDependencies": { "@kevisual/dts": "^0.0.3", "@kevisual/load": "^0.0.6", "@kevisual/logger": "^0.0.4", - "@kevisual/query": "0.0.30", + "@kevisual/query": "0.0.31", "@kevisual/query-login": "0.0.7", "@types/bun": "^1.3.3", "@types/crypto-js": "^4.2.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6c807e1..3d027a3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,21 @@ importers: '@kevisual/context': specifier: ^0.0.4 version: 0.0.4 + '@kevisual/hot-api': + specifier: ^0.0.3 + version: 0.0.3(dotenv@17.2.3)(supports-color@10.2.2) + '@nut-tree-fork/nut-js': + specifier: ^4.2.6 + version: 4.2.6 + eventemitter3: + specifier: ^5.0.1 + version: 5.0.1 + lowdb: + specifier: ^7.0.1 + version: 7.0.1 + lru-cache: + specifier: ^11.2.4 + version: 11.2.4 micromatch: specifier: ^4.0.8 version: 4.0.8 @@ -20,6 +35,9 @@ importers: semver: specifier: ^7.7.3 version: 7.7.3 + unstorage: + specifier: ^1.17.3 + version: 1.17.3(idb-keyval@6.2.1) devDependencies: '@kevisual/dts': specifier: ^0.0.3 @@ -31,11 +49,11 @@ importers: specifier: ^0.0.4 version: 0.0.4 '@kevisual/query': - specifier: 0.0.30 - version: 0.0.30 + specifier: 0.0.31 + version: 0.0.31 '@kevisual/query-login': specifier: 0.0.7 - version: 0.0.7(@kevisual/query@0.0.30) + version: 0.0.7(@kevisual/query@0.0.31) '@types/bun': specifier: ^1.3.3 version: 1.3.3 @@ -91,8 +109,8 @@ importers: assistant: dependencies: '@kevisual/hot-api': - specifier: ^0.0.2 - version: 0.0.2(dotenv@17.2.3)(supports-color@10.2.2) + specifier: ^0.0.3 + version: 0.0.3(dotenv@17.2.3)(supports-color@10.2.2) '@nut-tree-fork/nut-js': specifier: ^4.2.6 version: 4.2.6 @@ -125,11 +143,11 @@ importers: specifier: ^0.0.4 version: 0.0.4 '@kevisual/query': - specifier: 0.0.30 - version: 0.0.30 + specifier: 0.0.31 + version: 0.0.31 '@kevisual/query-login': specifier: 0.0.7 - version: 0.0.7(@kevisual/query@0.0.30) + version: 0.0.7(@kevisual/query@0.0.31) '@kevisual/router': specifier: ^0.0.33 version: 0.0.33(supports-color@10.2.2) @@ -527,8 +545,8 @@ packages: resolution: {integrity: sha512-4T/m2LqhtwWEW+lWmg7jLxKFW7VtIAftsWFDDZvh10bZunqFf8iXxChHcVSQWikghJb4cq1IkWzPkvc2l+Asdw==} hasBin: true - '@kevisual/hot-api@0.0.2': - resolution: {integrity: sha512-DUWfTScVmRx11f45rjoTjvs6b0LtZVT/EZfEw0l2rzx2vZWgRlYivIrYiH9QIV6dajVWNsth1xyjeNcu9+UfQA==} + '@kevisual/hot-api@0.0.3': + resolution: {integrity: sha512-qZ4CNK08StZP4+DR1vWwJhKVDoSXXC+PBFG4ZxtkXF5vO2rybE055zp1n3dg5jo8GwW5wxpqMIG3KBp3pYSTkg==} '@kevisual/load@0.0.6': resolution: {integrity: sha512-+3YTFehRcZ1haGel5DKYMUwmi5i6f2psyaPZlfkKU/cOXgkpwoG9/BEqPCnPjicKqqnksEpixVRkyHJ+5bjLVA==} @@ -550,6 +568,9 @@ packages: '@kevisual/query@0.0.30': resolution: {integrity: sha512-mDPEaLX9LdTRgi9anmWQ4EJ491umsASu/gs6K85J5nJqtUN/kfnZ3x5IouUr6aNbgAhrNLv/vTqpQTBsQhEYHQ==} + '@kevisual/query@0.0.31': + resolution: {integrity: sha512-bBdepjmMICLpcj/a9fnn82/0CGGYUZiCV+usWsJZKAwVlZcnj+WtKmbgKT09KpP6g3jjYzYOaXHiNFB8N0bQAQ==} + '@kevisual/router@0.0.33': resolution: {integrity: sha512-9z7TkSzCIGbXn9SuHPBdZpGwHlAuwA8iN5jNAZBUvbEvBRkBxlrbdCSe9fBYiAHueLm2AceFNrW74uulOiAkqA==} @@ -2736,10 +2757,10 @@ snapshots: transitivePeerDependencies: - typescript - '@kevisual/hot-api@0.0.2(dotenv@17.2.3)(supports-color@10.2.2)': + '@kevisual/hot-api@0.0.3(dotenv@17.2.3)(supports-color@10.2.2)': dependencies: '@kevisual/ai': 0.0.16 - '@kevisual/query': 0.0.30 + '@kevisual/query': 0.0.31 '@kevisual/router': 0.0.33(supports-color@10.2.2) '@kevisual/use-config': 1.0.21(dotenv@17.2.3) '@nut-tree-fork/nut-js': 4.2.6 @@ -2771,14 +2792,16 @@ snapshots: '@kevisual/permission@0.0.3': {} - '@kevisual/query-login@0.0.7(@kevisual/query@0.0.30)': + '@kevisual/query-login@0.0.7(@kevisual/query@0.0.31)': dependencies: '@kevisual/cache': 0.0.3 - '@kevisual/query': 0.0.30 + '@kevisual/query': 0.0.31 dotenv: 17.2.3 '@kevisual/query@0.0.30': {} + '@kevisual/query@0.0.31': {} + '@kevisual/router@0.0.33(supports-color@10.2.2)': dependencies: path-to-regexp: 8.3.0