@vincentbanana/banana-gui 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/bin/banana-gui.mjs +37 -17
  2. package/package.json +2 -2
@@ -2,29 +2,50 @@
2
2
  // Banana GUI 启动器:复用 CLI 包的 agent 内核,用本包自带的界面资源。
3
3
  // 安装:npm install -g @vincentbanana/banana-gui
4
4
  // 启动:banana-gui(首次会进配置向导)
5
- import { fileURLToPath } from 'node:url';
6
- import { dirname, join } from 'node:path';
5
+ import { createRequire } from 'node:module';
7
6
  import { spawn } from 'node:child_process';
8
7
 
9
- const here = dirname(fileURLToPath(import.meta.url));
8
+ const require = createRequire(import.meta.url);
9
+
10
+ function resolveCli() {
11
+ // 依赖可能被 npm 提升到上层 node_modules,用 require 解析更稳;
12
+ // 注意只能解析包根(子路径受 exports 限制)
13
+ try {
14
+ return require.resolve('@vincentbanana/bananacli');
15
+ } catch {
16
+ return null;
17
+ }
18
+ }
19
+
10
20
  const args = process.argv.slice(2);
11
21
  const passthrough = ['--port', '--cwd', '--provider', '--model', '--base-url', '--api-key', '--setup'];
12
22
 
13
- const cliArgs = ['--ui', '--no-open'];
14
- let forwarding = false;
15
- for (const arg of args) {
16
- if (arg === '--help' || arg === '-h' || arg === '--version' || arg === '-v') {
17
- console.log('banana-gui — Banana 的图形界面');
18
- console.log('');
19
- console.log('用法: banana-gui [选项]');
20
- console.log(' --port <端口> 指定端口(默认随机)');
21
- console.log(' --cwd <目录> 指定工作区');
22
- console.log(' --provider <名> 指定 provider');
23
- console.log(' --model <名> 指定模型');
24
- console.log(' --open 启动后打开浏览器(默认已开启)');
25
- console.log(' --help 显示帮助');
23
+ if (args.some((arg) => arg === '--help' || arg === '-h' || args.length === 0 || arg === '--version' || arg === '-v')) {
24
+ if (args.includes('--version') || args.includes('-v')) {
25
+ console.log('0.1.1');
26
26
  process.exit(0);
27
27
  }
28
+ console.log('banana-gui — Banana 的图形界面');
29
+ console.log('');
30
+ console.log('用法: banana-gui [选项]');
31
+ console.log(' --port <端口> 指定端口(默认随机)');
32
+ console.log(' --cwd <目录> 指定工作区');
33
+ console.log(' --provider <名> 指定 provider');
34
+ console.log(' --model <名> 指定模型');
35
+ console.log(' --open 启动后打开浏览器(默认已开启)');
36
+ console.log(' --help 显示帮助');
37
+ process.exit(0);
38
+ }
39
+
40
+ const entry = resolveCli();
41
+ if (!entry) {
42
+ console.error('找不到依赖 @vincentbanana/bananacli,请重新安装:npm install -g @vincentbanana/banana-gui');
43
+ process.exit(1);
44
+ }
45
+
46
+ const cliArgs = ['--ui'];
47
+ let forwarding = false;
48
+ for (const arg of args) {
28
49
  if (arg === '--open') {
29
50
  forwarding = false;
30
51
  continue;
@@ -33,7 +54,6 @@ for (const arg of args) {
33
54
  cliArgs.push(arg);
34
55
  }
35
56
 
36
- const entry = join(here, '..', 'node_modules', '@vincentbanana', 'bananacli', 'dist', 'index.js');
37
57
  const child = spawn(process.execPath, [entry, ...cliArgs], { stdio: 'inherit' });
38
58
  child.on('exit', (code) => process.exit(code ?? 0));
39
59
  for (const signal of ['SIGINT', 'SIGTERM']) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vincentbanana/banana-gui",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Banana 的图形界面:本地服务 + 浏览器。黑白主题,自绘图标,无第三方 UI 依赖",
5
5
  "type": "module",
6
6
  "engines": {
@@ -33,4 +33,4 @@
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  }
36
- }
36
+ }