@vincentbanana/banana-gui 0.2.0 → 0.3.0
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 +26 -7
- package/bin/banana-gui-desktop.mjs +71 -0
- package/bin/banana-gui.mjs +64 -6
- package/desktop/main.cjs +27 -4
- package/package.json +17 -11
package/README.md
CHANGED
|
@@ -6,9 +6,18 @@ Banana 的图形界面:本地起一个服务,用浏览器打开。黑白主
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install -g @vincentbanana/banana-gui
|
|
9
|
-
banana-gui
|
|
10
9
|
```
|
|
11
10
|
|
|
11
|
+
装完有两种启动方式,**同一份安装,不用额外装东西**:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
banana-gui # 浏览器版:启动后自动开浏览器,最轻
|
|
15
|
+
banana-gui --desktop # 桌面版:直接开独立窗口
|
|
16
|
+
banana-gui-desktop # 同上,等价的独立命令
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
electron 是可选依赖(`optionalDependencies`),npm 安装时会自动带上;万一某个平台装不上,`banana-gui` 仍然照常工作,只是 `--desktop` 会提示你用浏览器版。
|
|
20
|
+
|
|
12
21
|
首次启动会进配置向导(选 provider、贴 API key、选权限、测连接),配置与 CLI 共用 `~/.banana/config.json`。
|
|
13
22
|
|
|
14
23
|
## 用法
|
|
@@ -35,17 +44,27 @@ banana-gui --provider deepseek --model deepseek-chat
|
|
|
35
44
|
- 三态主题:跟随系统 / 浅色 / 深色,纯黑白无渐变
|
|
36
45
|
- 没配 API Key 也能打开界面,照着引导填完即可用
|
|
37
46
|
|
|
38
|
-
##
|
|
47
|
+
## 两种方式对比
|
|
48
|
+
|
|
49
|
+
| | 启动命令 | 需要什么 | 说明 |
|
|
50
|
+
| --- | --- | --- | --- |
|
|
51
|
+
| 浏览器版 | `banana-gui` | 任何装了 Node 20+ 的系统 | 启动后自动打开浏览器,几十 MB |
|
|
52
|
+
| 桌面版 | `banana-gui --desktop` | 同一个 npm 包 | 独立窗口,约 200MB(内含 electron) |
|
|
53
|
+
|
|
54
|
+
两者用的是同一套 agent 内核和同一份界面资源,功能完全一致,只是外壳不同。
|
|
55
|
+
|
|
56
|
+
## 打包成安装包(可选)
|
|
39
57
|
|
|
40
|
-
|
|
58
|
+
想出 `.exe` / `.dmg` / `AppImage` 的话,在源码仓库里构建:
|
|
41
59
|
|
|
42
60
|
```bash
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
npm
|
|
61
|
+
git clone <这个仓库>
|
|
62
|
+
cd banana-gui
|
|
63
|
+
npm install # 装 electron-builder
|
|
64
|
+
npm run dist:win # 也支持 dist:mac / dist:linux
|
|
46
65
|
```
|
|
47
66
|
|
|
48
|
-
|
|
67
|
+
产物在 `gui/release/`。
|
|
49
68
|
|
|
50
69
|
## 配置
|
|
51
70
|
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 桌面版启动器:npm 安装后直接开一个独立窗口,不用浏览器。
|
|
3
|
+
//
|
|
4
|
+
// npm install -g @vincentbanana/banana-gui
|
|
5
|
+
// banana-gui-desktop 开窗口
|
|
6
|
+
// banana-gui-desktop --port 8080
|
|
7
|
+
//
|
|
8
|
+
// electron 是 optionalDependencies:装得上就能用,装不上会提示改用浏览器版
|
|
9
|
+
// (banana-gui)。本文件不直接依赖 electron 的 API,只负责把它拉起来。
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
import { createRequire } from 'node:module';
|
|
12
|
+
import { dirname, join } from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
|
|
15
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const require_ = createRequire(import.meta.url);
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
|
|
19
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
20
|
+
console.log('banana-gui-desktop — Banana 的桌面版(独立窗口)');
|
|
21
|
+
console.log('');
|
|
22
|
+
console.log('用法: banana-gui-desktop [选项]');
|
|
23
|
+
console.log(' --port <端口> 指定端口(默认随机)');
|
|
24
|
+
console.log(' --cwd <目录> 指定工作区');
|
|
25
|
+
console.log(' --provider <名> 指定 provider');
|
|
26
|
+
console.log(' --model <名> 指定模型');
|
|
27
|
+
console.log(' --help 显示帮助');
|
|
28
|
+
console.log('');
|
|
29
|
+
console.log('提示:日常使用建议用 banana-gui(浏览器版,更轻)。');
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** electron 装在依赖里;require('electron') 返回的是可执行文件路径。 */
|
|
34
|
+
function electronBinary() {
|
|
35
|
+
for (const specifier of ['electron', '@vincentbanana/banana-gui/node_modules/electron']) {
|
|
36
|
+
try {
|
|
37
|
+
const resolved = require_.resolve(specifier);
|
|
38
|
+
// electron 主入口导出的是 exe 路径;解析失败时退回到包目录里的 dist
|
|
39
|
+
const binary = require_(resolved);
|
|
40
|
+
if (typeof binary === 'string') return binary;
|
|
41
|
+
return join(dirname(resolved), 'dist', process.platform === 'win32' ? 'electron.exe' : 'electron');
|
|
42
|
+
} catch {
|
|
43
|
+
/* 换下一个候选 */
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const binary = electronBinary();
|
|
50
|
+
if (!binary) {
|
|
51
|
+
console.error('没找到 electron,桌面版暂时用不了。');
|
|
52
|
+
console.error('');
|
|
53
|
+
console.error('可以先继续用浏览器版,功能完全一样:');
|
|
54
|
+
console.error(' banana-gui');
|
|
55
|
+
console.error('');
|
|
56
|
+
console.error('想用桌面版,试着补装一次:');
|
|
57
|
+
console.error(' npm install -g electron');
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const main = join(here, '..', 'desktop', 'main.cjs');
|
|
62
|
+
const child = spawn(binary, [main, ...args], { stdio: 'inherit' });
|
|
63
|
+
child.on('error', (error) => {
|
|
64
|
+
console.error('桌面版启动失败:' + error.message);
|
|
65
|
+
console.error('可以先用浏览器版:banana-gui');
|
|
66
|
+
process.exit(1);
|
|
67
|
+
});
|
|
68
|
+
child.on('exit', (code) => process.exit(code ?? 0));
|
|
69
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
70
|
+
process.on(signal, () => child.kill(signal));
|
|
71
|
+
}
|
package/bin/banana-gui.mjs
CHANGED
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
// 启动:banana-gui(首次会进配置向导)
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
import { spawn } from 'node:child_process';
|
|
7
|
+
import { dirname, join } from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
7
9
|
|
|
8
10
|
const require = createRequire(import.meta.url);
|
|
11
|
+
const pkg = require('../package.json');
|
|
9
12
|
|
|
10
13
|
function resolveCli() {
|
|
11
14
|
// 依赖可能被 npm 提升到上层 node_modules,用 require 解析更稳;
|
|
@@ -17,23 +20,43 @@ function resolveCli() {
|
|
|
17
20
|
}
|
|
18
21
|
}
|
|
19
22
|
|
|
23
|
+
/** electron 是可选依赖:装上了就能开独立窗口,没装就走浏览器。 */
|
|
24
|
+
function electronBinary() {
|
|
25
|
+
for (const specifier of ['electron', '@vincentbanana/banana-gui/node_modules/electron']) {
|
|
26
|
+
try {
|
|
27
|
+
const resolved = require.resolve(specifier);
|
|
28
|
+
const binary = require(resolved);
|
|
29
|
+
if (typeof binary === 'string') return binary;
|
|
30
|
+
} catch {
|
|
31
|
+
/* 换下一个候选 */
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
20
37
|
const args = process.argv.slice(2);
|
|
21
38
|
const passthrough = ['--port', '--cwd', '--provider', '--model', '--base-url', '--api-key', '--setup'];
|
|
22
39
|
|
|
23
|
-
if (args.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
40
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
41
|
+
console.log(pkg.version);
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
28
46
|
console.log('banana-gui — Banana 的图形界面');
|
|
29
47
|
console.log('');
|
|
30
48
|
console.log('用法: banana-gui [选项]');
|
|
49
|
+
console.log(' --desktop 用独立窗口打开(需要已安装 electron)');
|
|
31
50
|
console.log(' --port <端口> 指定端口(默认随机)');
|
|
32
51
|
console.log(' --cwd <目录> 指定工作区');
|
|
33
52
|
console.log(' --provider <名> 指定 provider');
|
|
34
53
|
console.log(' --model <名> 指定模型');
|
|
35
54
|
console.log(' --open 启动后打开浏览器(默认已开启)');
|
|
55
|
+
console.log(' --version 显示版本');
|
|
36
56
|
console.log(' --help 显示帮助');
|
|
57
|
+
console.log('');
|
|
58
|
+
console.log('提示:默认用浏览器打开。想要独立窗口就加 --desktop,');
|
|
59
|
+
console.log(' 或直接运行 banana-gui-desktop。');
|
|
37
60
|
process.exit(0);
|
|
38
61
|
}
|
|
39
62
|
|
|
@@ -43,7 +66,42 @@ if (!entry) {
|
|
|
43
66
|
process.exit(1);
|
|
44
67
|
}
|
|
45
68
|
|
|
46
|
-
|
|
69
|
+
// --desktop:交给 electron 开独立窗口,本进程不参与
|
|
70
|
+
if (args.includes('--desktop')) {
|
|
71
|
+
const binary = electronBinary();
|
|
72
|
+
if (!binary) {
|
|
73
|
+
console.error('没装 electron,用不了独立窗口。补装一次即可:npm install -g electron');
|
|
74
|
+
console.error('(不装也没关系,直接运行 banana-gui 用浏览器版,功能完全一样)');
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
const rest = args.filter((arg) => arg !== '--desktop');
|
|
78
|
+
const desktop = spawn(binary, [join(dirname(fileURLToPath(import.meta.url)), '..', 'desktop', 'main.cjs'), ...rest], {
|
|
79
|
+
stdio: 'inherit',
|
|
80
|
+
});
|
|
81
|
+
desktop.on('exit', (code) => process.exit(code ?? 0));
|
|
82
|
+
for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => desktop.kill(signal));
|
|
83
|
+
} else {
|
|
84
|
+
startBrowser(entry);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function startBrowser(entry) {
|
|
88
|
+
const cliArgs = ['--ui'];
|
|
89
|
+
let forwarding = false;
|
|
90
|
+
for (const arg of args) {
|
|
91
|
+
if (arg === '--open') {
|
|
92
|
+
forwarding = false;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
forwarding = passthrough.includes(arg) || forwarding;
|
|
96
|
+
cliArgs.push(arg);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const child = spawn(process.execPath, [entry, ...cliArgs], { stdio: 'inherit' });
|
|
100
|
+
child.on('exit', (code) => process.exit(code ?? 0));
|
|
101
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
102
|
+
process.on(signal, () => child.kill(signal));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
47
105
|
let forwarding = false;
|
|
48
106
|
for (const arg of args) {
|
|
49
107
|
if (arg === '--open') {
|
package/desktop/main.cjs
CHANGED
|
@@ -8,12 +8,35 @@ const require_ = createRequire(__filename);
|
|
|
8
8
|
let child = null;
|
|
9
9
|
let win = null;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// electron 自带的 node 运行 CLI 内核;ELECTRON_RUN_AS_NODE 让 electron.exe 当纯 node 用,
|
|
12
|
+
// 否则会再开一个 Electron 窗口,而不是执行脚本。
|
|
13
|
+
const PASSTHROUGH = ['--port', '--cwd', '--provider', '--model', '--base-url', '--api-key'];
|
|
14
|
+
|
|
15
|
+
function serverArgs() {
|
|
16
|
+
const argv = process.argv.slice(2).filter((arg) => arg.startsWith('--'));
|
|
17
|
+
const extra = [];
|
|
18
|
+
for (const arg of argv) {
|
|
19
|
+
if (PASSTHROUGH.includes(arg)) {
|
|
20
|
+
extra.push(arg);
|
|
21
|
+
const value = process.argv[process.argv.indexOf(arg) + 1];
|
|
22
|
+
if (value && !value.startsWith('--')) extra.push(value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
13
25
|
// 端口交给 CLI 随机分配,避免多开时互相抢占
|
|
14
|
-
|
|
26
|
+
return ['--ui', '--no-open', ...extra];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function startServer() {
|
|
30
|
+
let entry;
|
|
31
|
+
try {
|
|
32
|
+
// 依赖可能被提升到上层 node_modules;只能解析包根(子路径受 exports 限制)
|
|
33
|
+
entry = require_.resolve('@vincentbanana/bananacli');
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new Error('找不到依赖 @vincentbanana/bananacli,请重新安装:npm install -g @vincentbanana/banana-gui');
|
|
36
|
+
}
|
|
37
|
+
child = spawn(process.execPath, [entry, ...serverArgs()], {
|
|
15
38
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
16
|
-
env: process.env,
|
|
39
|
+
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' },
|
|
17
40
|
});
|
|
18
41
|
return new Promise((resolve, reject) => {
|
|
19
42
|
let buffer = '';
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vincentbanana/banana-gui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Banana 的图形界面:本地服务 + 浏览器。黑白主题,自绘图标,无第三方 UI 依赖",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=20.0.0"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
|
-
"banana-gui": "bin/banana-gui.mjs"
|
|
10
|
+
"banana-gui": "bin/banana-gui.mjs",
|
|
11
|
+
"banana-gui-desktop": "bin/banana-gui-desktop.mjs"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
14
|
"bin",
|
|
@@ -15,6 +16,16 @@
|
|
|
15
16
|
"desktop",
|
|
16
17
|
"README.md"
|
|
17
18
|
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"ai",
|
|
21
|
+
"agent",
|
|
22
|
+
"gui",
|
|
23
|
+
"web-ui",
|
|
24
|
+
"llm",
|
|
25
|
+
"terminal",
|
|
26
|
+
"desktop",
|
|
27
|
+
"electron"
|
|
28
|
+
],
|
|
18
29
|
"scripts": {
|
|
19
30
|
"sync": "node ../scripts/sync-gui.mjs",
|
|
20
31
|
"test": "node test/gui-package.test.mjs",
|
|
@@ -34,6 +45,7 @@
|
|
|
34
45
|
"bin/**/*",
|
|
35
46
|
"package.json"
|
|
36
47
|
],
|
|
48
|
+
"npmRebuild": false,
|
|
37
49
|
"mac": {
|
|
38
50
|
"category": "public.app-category.developer-tools",
|
|
39
51
|
"target": [
|
|
@@ -52,21 +64,15 @@
|
|
|
52
64
|
"category": "Development"
|
|
53
65
|
}
|
|
54
66
|
},
|
|
67
|
+
"optionalDependencies": {
|
|
68
|
+
"electron": "^33.0.0"
|
|
69
|
+
},
|
|
55
70
|
"devDependencies": {
|
|
56
|
-
"electron": "^33.0.0",
|
|
57
71
|
"electron-builder": "^25.0.0"
|
|
58
72
|
},
|
|
59
73
|
"dependencies": {
|
|
60
74
|
"@vincentbanana/bananacli": "^0.3.0"
|
|
61
75
|
},
|
|
62
|
-
"keywords": [
|
|
63
|
-
"ai",
|
|
64
|
-
"agent",
|
|
65
|
-
"gui",
|
|
66
|
-
"web-ui",
|
|
67
|
-
"llm",
|
|
68
|
-
"terminal"
|
|
69
|
-
],
|
|
70
76
|
"license": "MIT",
|
|
71
77
|
"publishConfig": {
|
|
72
78
|
"access": "public"
|