@vincentbanana/banana-gui 0.3.0 → 0.4.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 +9 -0
- package/bin/banana-gui-desktop.mjs +49 -37
- package/bin/banana-gui.mjs +114 -55
- package/desktop/main.cjs +27 -1
- package/package.json +80 -80
- package/ui/app.js +18 -1
package/README.md
CHANGED
|
@@ -18,6 +18,15 @@ banana-gui-desktop # 同上,等价的独立命令
|
|
|
18
18
|
|
|
19
19
|
electron 是可选依赖(`optionalDependencies`),npm 安装时会自动带上;万一某个平台装不上,`banana-gui` 仍然照常工作,只是 `--desktop` 会提示你用浏览器版。
|
|
20
20
|
|
|
21
|
+
> **关于 electron 的下载**:新版 electron 的二进制不在 `npm install` 时下载,而是**首次运行时**才拉取(一百多 MB),默认源是 GitHub,国内基本连不上。`banana-gui --desktop` 会自动改用国内镜像下载,你不用加任何参数。
|
|
22
|
+
>
|
|
23
|
+
> 想换源就设环境变量,例如:
|
|
24
|
+
>
|
|
25
|
+
> ```bash
|
|
26
|
+
> set ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
|
|
27
|
+
> banana-gui --desktop
|
|
28
|
+
> ```
|
|
29
|
+
|
|
21
30
|
首次启动会进配置向导(选 provider、贴 API key、选权限、测连接),配置与 CLI 共用 `~/.banana/config.json`。
|
|
22
31
|
|
|
23
32
|
## 用法
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
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';
|
|
2
|
+
// 桌面版启动器:等价于 `banana-gui --desktop`,保留独立命令方便记忆。
|
|
3
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
11
5
|
import { createRequire } from 'node:module';
|
|
12
6
|
import { dirname, join } from 'node:path';
|
|
13
7
|
import { fileURLToPath } from 'node:url';
|
|
@@ -30,42 +24,60 @@ if (args.includes('--help') || args.includes('-h')) {
|
|
|
30
24
|
process.exit(0);
|
|
31
25
|
}
|
|
32
26
|
|
|
33
|
-
|
|
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();
|
|
27
|
+
const binary = resolveElectron();
|
|
50
28
|
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');
|
|
29
|
+
console.error('没找到 electron,桌面版用不了。装一次即可:npm install -g electron');
|
|
30
|
+
console.error('不装也没关系:banana-gui 用浏览器版,功能完全一样。');
|
|
58
31
|
process.exit(1);
|
|
59
32
|
}
|
|
60
33
|
|
|
61
34
|
const main = join(here, '..', 'desktop', 'main.cjs');
|
|
62
|
-
const child = spawn(binary, [main, ...args], {
|
|
35
|
+
const child = spawn(binary, [main, ...args], {
|
|
36
|
+
stdio: 'inherit',
|
|
37
|
+
env: { ...process.env, BANANA_UI_DIR: join(here, '..', 'ui') },
|
|
38
|
+
});
|
|
63
39
|
child.on('error', (error) => {
|
|
64
|
-
console.error('
|
|
65
|
-
console.error('可以先用浏览器版:banana-gui');
|
|
40
|
+
console.error('启动失败:' + error.message);
|
|
66
41
|
process.exit(1);
|
|
67
42
|
});
|
|
68
43
|
child.on('exit', (code) => process.exit(code ?? 0));
|
|
69
44
|
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
70
45
|
process.on(signal, () => child.kill(signal));
|
|
71
|
-
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 找 electron 可执行文件;二进制缺失时用镜像补下载一次。
|
|
50
|
+
* 新版 electron 只在首次运行时下载一百多 MB 的二进制,默认源是 GitHub。
|
|
51
|
+
*/
|
|
52
|
+
function resolveElectron() {
|
|
53
|
+
let dir;
|
|
54
|
+
try {
|
|
55
|
+
dir = dirname(require_.resolve('electron'));
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const pathTxt = join(dir, 'path.txt');
|
|
60
|
+
const distDir = join(dir, 'dist');
|
|
61
|
+
const current = () => {
|
|
62
|
+
try {
|
|
63
|
+
const name = readFileSync(pathTxt, 'utf8').trim();
|
|
64
|
+
const full = join(distDir, name || (process.platform === 'win32' ? 'electron.exe' : 'electron'));
|
|
65
|
+
return existsSync(full) ? full : null;
|
|
66
|
+
} catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const ready = current();
|
|
71
|
+
if (ready) return ready;
|
|
72
|
+
|
|
73
|
+
const installScript = join(dir, 'install.js');
|
|
74
|
+
if (!existsSync(installScript)) return null;
|
|
75
|
+
const mirror = process.env.ELECTRON_MIRROR ?? 'https://npmmirror.com/mirrors/electron/';
|
|
76
|
+
console.log('electron 的二进制还没下载,正在获取(一百多 MB,只需一次)...');
|
|
77
|
+
console.log(`下载源:${mirror}`);
|
|
78
|
+
const result = spawnSync(process.execPath, [installScript], {
|
|
79
|
+
stdio: 'inherit',
|
|
80
|
+
env: { ...process.env, ELECTRON_MIRROR: mirror },
|
|
81
|
+
});
|
|
82
|
+
return result.status === 0 ? current() : null;
|
|
83
|
+
}
|
package/bin/banana-gui.mjs
CHANGED
|
@@ -2,40 +2,110 @@
|
|
|
2
2
|
// Banana GUI 启动器:复用 CLI 包的 agent 内核,用本包自带的界面资源。
|
|
3
3
|
// 安装:npm install -g @vincentbanana/banana-gui
|
|
4
4
|
// 启动:banana-gui(首次会进配置向导)
|
|
5
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
6
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
5
7
|
import { createRequire } from 'node:module';
|
|
6
|
-
import { spawn } from 'node:child_process';
|
|
7
8
|
import { dirname, join } from 'node:path';
|
|
8
9
|
import { fileURLToPath } from 'node:url';
|
|
9
10
|
|
|
10
11
|
const require = createRequire(import.meta.url);
|
|
11
12
|
const pkg = require('../package.json');
|
|
13
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
12
14
|
|
|
15
|
+
/** CLI 内核入口。依赖可能被 npm 提升到上层 node_modules,用 require 解析更稳。 */
|
|
13
16
|
function resolveCli() {
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
const candidates = [];
|
|
18
|
+
for (const specifier of ['@vincentbanana/bananacli']) {
|
|
19
|
+
// 先在本包的依赖树里找(版本对得上),再退回到被提升到上层的副本
|
|
20
|
+
for (const paths of [[join(here, '..')], undefined]) {
|
|
21
|
+
try {
|
|
22
|
+
const entry = paths ? require.resolve(specifier, { paths }) : require.resolve(specifier);
|
|
23
|
+
candidates.push(entry);
|
|
24
|
+
} catch {
|
|
25
|
+
/* 换下一个候选 */
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (!candidates.length) return null;
|
|
30
|
+
|
|
31
|
+
/** 读内核版本:entry 是 dist/index.js,同目录上一级就是包根 */
|
|
32
|
+
const versionOf = (entry) => {
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(readFileSync(join(dirname(entry), '..', 'package.json'), 'utf8')).version;
|
|
35
|
+
} catch {
|
|
36
|
+
return '0.0.0';
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const required = String(pkg.dependencies?.['@vincentbanana/bananacli'] ?? '').replace(/^[^\d]*/, '') || '0.0.0';
|
|
40
|
+
const newer = (a, b) => {
|
|
41
|
+
const pa = a.split('.').map(Number);
|
|
42
|
+
const pb = b.split('.').map(Number);
|
|
43
|
+
for (let i = 0; i < 3; i += 1) {
|
|
44
|
+
if ((pa[i] ?? 0) !== (pb[i] ?? 0)) return (pa[i] ?? 0) > (pb[i] ?? 0);
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
const best = candidates.sort((a, b) => (newer(versionOf(a), versionOf(b)) ? -1 : 1))[0];
|
|
49
|
+
const found = versionOf(best);
|
|
50
|
+
if (newer(required, found)) {
|
|
51
|
+
// 旧内核没有内置界面资源,界面会 404。与其让用户看白屏,不如直接说清。
|
|
52
|
+
console.error(`内核 @vincentbanana/bananacli 版本过旧(当前 ${found},需要 ${required} 以上)。`);
|
|
53
|
+
console.error('旧版本不含界面资源,打开会是空白页。先更新内核:');
|
|
54
|
+
console.error(' npm install -g @vincentbanana/bananacli');
|
|
55
|
+
console.error('然后再运行 banana-gui。');
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
return best;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 找到 electron 可执行文件。electron 是个可选依赖,而且新版只在**首次运行**才下载
|
|
63
|
+
* 一百多 MB 的二进制(npm install 时只装壳)。默认从 GitHub 下,国内基本连不上,
|
|
64
|
+
* 所以这里主动用镜像补下载一次,用户不用记任何参数。
|
|
65
|
+
* 想换源:设 ELECTRON_MIRROR 环境变量即可。
|
|
66
|
+
*/
|
|
67
|
+
function resolveElectron() {
|
|
68
|
+
let dir;
|
|
16
69
|
try {
|
|
17
|
-
|
|
70
|
+
dir = dirname(require.resolve('electron'));
|
|
18
71
|
} catch {
|
|
19
72
|
return null;
|
|
20
73
|
}
|
|
21
|
-
}
|
|
22
74
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
75
|
+
const pathTxt = join(dir, 'path.txt');
|
|
76
|
+
const distDir = join(dir, 'dist');
|
|
77
|
+
const current = () => {
|
|
26
78
|
try {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
79
|
+
const name = readFileSync(pathTxt, 'utf8').trim();
|
|
80
|
+
const full = join(distDir, name || (process.platform === 'win32' ? 'electron.exe' : 'electron'));
|
|
81
|
+
return existsSync(full) ? full : null;
|
|
30
82
|
} catch {
|
|
31
|
-
|
|
83
|
+
return null;
|
|
32
84
|
}
|
|
33
|
-
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const ready = current();
|
|
88
|
+
if (ready) return ready;
|
|
89
|
+
|
|
90
|
+
const installScript = join(dir, 'install.js');
|
|
91
|
+
if (!existsSync(installScript)) return null;
|
|
92
|
+
|
|
93
|
+
const mirror = process.env.ELECTRON_MIRROR ?? 'https://npmmirror.com/mirrors/electron/';
|
|
94
|
+
console.log('electron 的二进制还没下载,正在获取(一百多 MB,只需一次)...');
|
|
95
|
+
console.log(`下载源:${mirror}`);
|
|
96
|
+
const result = spawnSync(process.execPath, [installScript], {
|
|
97
|
+
stdio: 'inherit',
|
|
98
|
+
env: { ...process.env, ELECTRON_MIRROR: mirror },
|
|
99
|
+
});
|
|
100
|
+
if (result.status === 0) return current();
|
|
101
|
+
console.error('');
|
|
102
|
+
console.error('下载失败。可以换个网络或换个源再试,比如:');
|
|
103
|
+
console.error(' set ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/');
|
|
104
|
+
console.error(' banana-gui --desktop');
|
|
34
105
|
return null;
|
|
35
106
|
}
|
|
36
107
|
|
|
37
108
|
const args = process.argv.slice(2);
|
|
38
|
-
const passthrough = ['--port', '--cwd', '--provider', '--model', '--base-url', '--api-key', '--setup'];
|
|
39
109
|
|
|
40
110
|
if (args.includes('--version') || args.includes('-v')) {
|
|
41
111
|
console.log(pkg.version);
|
|
@@ -46,12 +116,12 @@ if (args.includes('--help') || args.includes('-h')) {
|
|
|
46
116
|
console.log('banana-gui — Banana 的图形界面');
|
|
47
117
|
console.log('');
|
|
48
118
|
console.log('用法: banana-gui [选项]');
|
|
49
|
-
console.log(' --desktop
|
|
119
|
+
console.log(' --desktop 用独立窗口打开(首次会下载 electron 运行时)');
|
|
50
120
|
console.log(' --port <端口> 指定端口(默认随机)');
|
|
51
121
|
console.log(' --cwd <目录> 指定工作区');
|
|
52
122
|
console.log(' --provider <名> 指定 provider');
|
|
53
123
|
console.log(' --model <名> 指定模型');
|
|
54
|
-
console.log(' --open
|
|
124
|
+
console.log(' --no-open 不自动打开浏览器');
|
|
55
125
|
console.log(' --version 显示版本');
|
|
56
126
|
console.log(' --help 显示帮助');
|
|
57
127
|
console.log('');
|
|
@@ -66,54 +136,43 @@ if (!entry) {
|
|
|
66
136
|
process.exit(1);
|
|
67
137
|
}
|
|
68
138
|
|
|
69
|
-
//
|
|
139
|
+
// 界面资源用本包自带的那份,保证 GUI 包和它的 ui/ 版本一致
|
|
140
|
+
const uiDir = join(here, '..', 'ui');
|
|
141
|
+
|
|
142
|
+
/** 用户参数原样转给内核;只摘掉本启动器自己的开关。 */
|
|
143
|
+
function kernelArgs() {
|
|
144
|
+
const rest = [];
|
|
145
|
+
for (const arg of args) {
|
|
146
|
+
if (arg === '--desktop' || arg === '--open') continue;
|
|
147
|
+
rest.push(arg);
|
|
148
|
+
}
|
|
149
|
+
return rest;
|
|
150
|
+
}
|
|
151
|
+
|
|
70
152
|
if (args.includes('--desktop')) {
|
|
71
|
-
const binary =
|
|
153
|
+
const binary = resolveElectron();
|
|
72
154
|
if (!binary) {
|
|
73
|
-
console.error('
|
|
74
|
-
console.error('
|
|
155
|
+
console.error('没找到 electron,用不了独立窗口。装一次即可:');
|
|
156
|
+
console.error(' npm install -g electron');
|
|
157
|
+
console.error('不装也没关系:直接运行 banana-gui 用浏览器版,功能完全一样。');
|
|
75
158
|
process.exit(1);
|
|
76
159
|
}
|
|
77
|
-
|
|
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));
|
|
160
|
+
launch(binary, [join(here, '..', 'desktop', 'main.cjs'), ...kernelArgs()], {});
|
|
83
161
|
} else {
|
|
84
|
-
|
|
162
|
+
launch(process.execPath, [entry, '--ui', ...kernelArgs()], { BANANA_UI_DIR: uiDir });
|
|
85
163
|
}
|
|
86
164
|
|
|
87
|
-
function
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
cliArgs.push(arg);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const child = spawn(process.execPath, [entry, ...cliArgs], { stdio: 'inherit' });
|
|
165
|
+
function launch(command, commandArgs, extraEnv) {
|
|
166
|
+
const child = spawn(command, commandArgs, {
|
|
167
|
+
stdio: 'inherit',
|
|
168
|
+
env: { ...process.env, ...extraEnv },
|
|
169
|
+
});
|
|
170
|
+
child.on('error', (error) => {
|
|
171
|
+
console.error('启动失败:' + error.message);
|
|
172
|
+
process.exit(1);
|
|
173
|
+
});
|
|
100
174
|
child.on('exit', (code) => process.exit(code ?? 0));
|
|
101
175
|
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
102
176
|
process.on(signal, () => child.kill(signal));
|
|
103
177
|
}
|
|
104
178
|
}
|
|
105
|
-
let forwarding = false;
|
|
106
|
-
for (const arg of args) {
|
|
107
|
-
if (arg === '--open') {
|
|
108
|
-
forwarding = false;
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
forwarding = passthrough.includes(arg) || forwarding;
|
|
112
|
-
cliArgs.push(arg);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const child = spawn(process.execPath, [entry, ...cliArgs], { stdio: 'inherit' });
|
|
116
|
-
child.on('exit', (code) => process.exit(code ?? 0));
|
|
117
|
-
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
118
|
-
process.on(signal, () => child.kill(signal));
|
|
119
|
-
}
|
package/desktop/main.cjs
CHANGED
|
@@ -36,7 +36,11 @@ function startServer() {
|
|
|
36
36
|
}
|
|
37
37
|
child = spawn(process.execPath, [entry, ...serverArgs()], {
|
|
38
38
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
39
|
-
env: {
|
|
39
|
+
env: {
|
|
40
|
+
...process.env,
|
|
41
|
+
ELECTRON_RUN_AS_NODE: '1',
|
|
42
|
+
BANANA_UI_DIR: process.env.BANANA_UI_DIR ?? join(__dirname, '..', 'ui'),
|
|
43
|
+
},
|
|
40
44
|
});
|
|
41
45
|
return new Promise((resolve, reject) => {
|
|
42
46
|
let buffer = '';
|
|
@@ -81,6 +85,28 @@ async function createWindow() {
|
|
|
81
85
|
shell.openExternal(target);
|
|
82
86
|
return { action: 'deny' };
|
|
83
87
|
});
|
|
88
|
+
if (process.argv.includes('--selftest')) await selfTest(url);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** --selftest:不靠人眼看,直接在页面里断言界面渲染成功,然后退出。 */
|
|
92
|
+
async function selfTest(url) {
|
|
93
|
+
try {
|
|
94
|
+
const probe = await win.webContents.executeJavaScript(`(() => ({
|
|
95
|
+
title: document.title,
|
|
96
|
+
composed: Boolean(document.querySelector('#composer')),
|
|
97
|
+
sidebar: Boolean(document.querySelector('#sidebar')),
|
|
98
|
+
scriptLoaded: typeof window.fetch === 'function' && Boolean(document.querySelector('#input')),
|
|
99
|
+
theme: getComputedStyle(document.documentElement).getPropertyValue('--bg').trim(),
|
|
100
|
+
}))()`);
|
|
101
|
+
const ok = probe.title === 'Banana' && probe.composed && probe.sidebar && probe.scriptLoaded;
|
|
102
|
+
console.log('SELFTEST ' + JSON.stringify({ ok, url: url.replace(/\/t\/[a-f0-9]+\//, '/t/<token>/'), ...probe }));
|
|
103
|
+
child?.kill();
|
|
104
|
+
app.exit(ok ? 0 : 1);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.log('SELFTEST ' + JSON.stringify({ ok: false, error: String(error?.message ?? error) }));
|
|
107
|
+
child?.kill();
|
|
108
|
+
app.exit(1);
|
|
109
|
+
}
|
|
84
110
|
}
|
|
85
111
|
|
|
86
112
|
const menuTemplate = [
|
package/package.json
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@vincentbanana/banana-gui",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "Banana 的图形界面:本地服务 + 浏览器。黑白主题,自绘图标,无第三�?UI 依赖",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": "\u003e=20.0.0"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"banana-gui": "bin/banana-gui.mjs",
|
|
11
|
+
"banana-gui-desktop": "bin/banana-gui-desktop.mjs"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin",
|
|
15
|
+
"ui",
|
|
16
|
+
"desktop",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"ai",
|
|
21
|
+
"agent",
|
|
22
|
+
"gui",
|
|
23
|
+
"web-ui",
|
|
24
|
+
"llm",
|
|
25
|
+
"terminal",
|
|
26
|
+
"desktop",
|
|
27
|
+
"electron"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"sync": "node ../scripts/sync-gui.mjs",
|
|
31
|
+
"test": "node test/gui-package.test.mjs",
|
|
32
|
+
"desktop": "electron desktop/main.cjs",
|
|
33
|
+
"pack": "electron-builder --dir",
|
|
34
|
+
"dist": "electron-builder",
|
|
35
|
+
"dist:win": "electron-builder --win",
|
|
36
|
+
"dist:mac": "electron-builder --mac",
|
|
37
|
+
"dist:linux": "electron-builder --linux"
|
|
38
|
+
},
|
|
39
|
+
"build": {
|
|
40
|
+
"appId": "dev.banana.gui",
|
|
41
|
+
"productName": "Banana",
|
|
42
|
+
"files": [
|
|
43
|
+
"desktop/**/*",
|
|
44
|
+
"ui/**/*",
|
|
45
|
+
"bin/**/*",
|
|
46
|
+
"package.json"
|
|
47
|
+
],
|
|
48
|
+
"npmRebuild": false,
|
|
49
|
+
"mac": {
|
|
50
|
+
"category": "public.app-category.developer-tools",
|
|
51
|
+
"target": [
|
|
52
|
+
"dmg"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"win": {
|
|
56
|
+
"target": [
|
|
57
|
+
"nsis"
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"linux": {
|
|
61
|
+
"target": [
|
|
62
|
+
"AppImage"
|
|
63
|
+
],
|
|
64
|
+
"category": "Development"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"optionalDependencies": {
|
|
68
|
+
"electron": "^33.4.11"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"electron-builder": "^25.0.0"
|
|
72
|
+
},
|
|
73
|
+
"dependencies": {
|
|
74
|
+
"@vincentbanana/bananacli": "^0.4.0"
|
|
75
|
+
},
|
|
76
|
+
"license": "MIT",
|
|
77
|
+
"publishConfig": {
|
|
78
|
+
"access": "public"
|
|
79
|
+
}
|
|
80
|
+
}
|
package/ui/app.js
CHANGED
|
@@ -130,6 +130,11 @@ function relativeTime(iso) {
|
|
|
130
130
|
return `${Math.round(hours / 24)} 天前`;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
/** 窄屏下侧边栏是覆盖层,选完会话必须收起来,否则挡住对话。 */
|
|
134
|
+
function closeSidebarIfOverlay() {
|
|
135
|
+
if (window.matchMedia('(max-width: 900px)').matches) $('sidebar').classList.remove('open');
|
|
136
|
+
}
|
|
137
|
+
|
|
133
138
|
function renderSidebar() {
|
|
134
139
|
const list = $('sessionList');
|
|
135
140
|
list.innerHTML = '';
|
|
@@ -147,7 +152,10 @@ function renderSidebar() {
|
|
|
147
152
|
|
|
148
153
|
node.addEventListener('click', (event) => {
|
|
149
154
|
if (event.target.closest('[data-del], [data-menu]')) return;
|
|
150
|
-
post('session', { action: 'switch', ref: item.id }).then(() =>
|
|
155
|
+
post('session', { action: 'switch', ref: item.id }).then(() => {
|
|
156
|
+
refresh(true);
|
|
157
|
+
closeSidebarIfOverlay();
|
|
158
|
+
});
|
|
151
159
|
});
|
|
152
160
|
|
|
153
161
|
node.querySelector('[data-del]').addEventListener('click', (event) => {
|
|
@@ -201,6 +209,7 @@ function openSessionMenu(item, anchor) {
|
|
|
201
209
|
if (action === 'switch') {
|
|
202
210
|
await post('session', { action: 'switch', ref: item.id });
|
|
203
211
|
await refresh(true);
|
|
212
|
+
closeSidebarIfOverlay();
|
|
204
213
|
} else if (action === 'rename') {
|
|
205
214
|
const title = prompt('新的标题', item.title || '');
|
|
206
215
|
if (title && title.trim()) {
|
|
@@ -1210,6 +1219,14 @@ function bind() {
|
|
|
1210
1219
|
}
|
|
1211
1220
|
});
|
|
1212
1221
|
|
|
1222
|
+
// 窄屏下点空白处收起侧边栏(点侧边栏内部或开合按钮不算)
|
|
1223
|
+
document.addEventListener('click', (event) => {
|
|
1224
|
+
if (!window.matchMedia('(max-width: 900px)').matches) return;
|
|
1225
|
+
if (!$('sidebar').classList.contains('open')) return;
|
|
1226
|
+
if (event.target.closest('#sidebar, #toggleSidebar')) return;
|
|
1227
|
+
$('sidebar').classList.remove('open');
|
|
1228
|
+
});
|
|
1229
|
+
|
|
1213
1230
|
$('input').addEventListener('paste', (event) => {
|
|
1214
1231
|
for (const item of event.clipboardData?.files ?? []) attach(item);
|
|
1215
1232
|
});
|