@vincentbanana/banana-gui 1.0.3 → 1.0.5
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/package.json +2 -2
- package/ui/app.js +188 -16
- package/ui/style.css +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vincentbanana/banana-gui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Banana 的图形界面:本地服务 + 浏览器。黑白主题,自绘图标,无第三方 UI 依赖",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"electron-builder": "^25.0.0"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@vincentbanana/bananacli": "^0.8.
|
|
75
|
+
"@vincentbanana/bananacli": "^0.8.5"
|
|
76
76
|
},
|
|
77
77
|
"license": "MIT",
|
|
78
78
|
"publishConfig": {
|
package/ui/app.js
CHANGED
|
@@ -587,13 +587,14 @@ function initTabs() {
|
|
|
587
587
|
try {
|
|
588
588
|
saved = JSON.parse(localStorage.getItem(SHELL_STORAGE.tabState) || 'null');
|
|
589
589
|
} catch {}
|
|
590
|
+
const draft = Boolean(state.info?.session?.draft);
|
|
590
591
|
if (saved && Array.isArray(saved.all)) {
|
|
591
592
|
const known = new Set(state.sessions.map((item) => item.id));
|
|
592
|
-
if (state.info?.session?.id) known.add(state.info.session.id);
|
|
593
|
+
if (state.info?.session?.id && !draft) known.add(state.info.session.id);
|
|
593
594
|
state.tabs = saved.all.filter((tab) => tab && typeof tab.id === 'string' && known.has(tab.id));
|
|
594
595
|
state.activeTab = saved.active ?? null;
|
|
595
596
|
}
|
|
596
|
-
const current = state.info?.session?.id;
|
|
597
|
+
const current = draft ? null : state.info?.session?.id;
|
|
597
598
|
if (current) upsertTab(current, state.info.session.title);
|
|
598
599
|
if (!state.activeTab || !state.tabs.some((tab) => tab.id === state.activeTab)) {
|
|
599
600
|
state.activeTab = current ?? state.tabs[0]?.id ?? null;
|
|
@@ -618,6 +619,13 @@ function renderSidebar() {
|
|
|
618
619
|
const q = state.sessionQuery.trim().toLowerCase();
|
|
619
620
|
return !q || String(item.title ?? '').toLowerCase().includes(q);
|
|
620
621
|
});
|
|
622
|
+
if (!sessions.length) {
|
|
623
|
+
const hint = document.createElement('div');
|
|
624
|
+
hint.className = 'sb-empty';
|
|
625
|
+
hint.textContent = state.sessionQuery ? '没有匹配的会话' : '还没有对话';
|
|
626
|
+
list.appendChild(hint);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
621
629
|
sessions.forEach((item, index) => {
|
|
622
630
|
const label = dayOf(item.updatedAt);
|
|
623
631
|
if (label !== group) {
|
|
@@ -673,21 +681,32 @@ function renderSidebar() {
|
|
|
673
681
|
if (wasActive) {
|
|
674
682
|
state.changes = null;
|
|
675
683
|
if (result?.info) state.info = result.info;
|
|
676
|
-
saveTabs();
|
|
677
684
|
state.attachments = [];
|
|
678
685
|
renderAttachments();
|
|
679
686
|
$('input').value = '';
|
|
680
687
|
grow();
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
688
|
+
if (state.info?.session?.draft) {
|
|
689
|
+
// 删光所有会话:回到干净的空白首页,不再自动建一个「新对话」。
|
|
690
|
+
state.tabs = [];
|
|
691
|
+
state.activeTab = null;
|
|
692
|
+
saveTabs();
|
|
693
|
+
renderTabs();
|
|
694
|
+
renderHeader();
|
|
695
|
+
renderSidebar();
|
|
696
|
+
renderThread();
|
|
697
|
+
} else {
|
|
698
|
+
saveTabs();
|
|
699
|
+
renderHeader();
|
|
700
|
+
renderSidebar();
|
|
701
|
+
renderThread();
|
|
702
|
+
setActiveTab(state.info?.session?.id ?? null);
|
|
703
|
+
}
|
|
685
704
|
} else {
|
|
686
705
|
saveTabs();
|
|
687
706
|
renderSidebar();
|
|
688
707
|
renderTabs();
|
|
689
708
|
}
|
|
690
|
-
toast('已删除会话');
|
|
709
|
+
toast(state.info?.session?.draft ? '已删除最后一个会话' : '已删除会话');
|
|
691
710
|
} catch (error) {
|
|
692
711
|
toast('删除失败:' + (error?.message ?? error));
|
|
693
712
|
}
|
|
@@ -1146,8 +1165,8 @@ async function refresh(path) {
|
|
|
1146
1165
|
state.info = info;
|
|
1147
1166
|
const { sessions } = await get('sessions');
|
|
1148
1167
|
state.sessions = sessions;
|
|
1149
|
-
//
|
|
1150
|
-
if (state.info?.session?.id) {
|
|
1168
|
+
// 空白草稿不是会话:不占标签,也不出现在侧栏;发出第一条消息后才补标签。
|
|
1169
|
+
if (state.info?.session?.id && !state.info.session.draft) {
|
|
1151
1170
|
upsertTab(state.info.session.id, state.info.session.title);
|
|
1152
1171
|
state.activeTab = state.info.session.id;
|
|
1153
1172
|
} else {
|
|
@@ -1204,8 +1223,14 @@ let appDialog = null;
|
|
|
1204
1223
|
* 返回值:有输入框时是字符串或 null;纯确认时是 true 或 null。
|
|
1205
1224
|
*/
|
|
1206
1225
|
function openAppDialog({ title, body = '', value = null, placeholder = '', confirmLabel = '确定', danger = false }) {
|
|
1226
|
+
// 防止双击/连点开出两个对话框,留下一个永远不 resolve 的 Promise。
|
|
1227
|
+
if (appDialog) return Promise.resolve(null);
|
|
1207
1228
|
return new Promise((resolve) => {
|
|
1208
|
-
|
|
1229
|
+
// 任何弹层打开前先收掉选择工具条、会话菜单和模型/思考弹层,避免视觉层叠混乱。
|
|
1230
|
+
hideSelectionTools();
|
|
1231
|
+
document.querySelector('.popover')?.remove();
|
|
1232
|
+
closeModelPop?.();
|
|
1233
|
+
closeReasoningPop?.();
|
|
1209
1234
|
const wrap = document.createElement('div');
|
|
1210
1235
|
wrap.className = 'modal';
|
|
1211
1236
|
wrap.id = 'appDialog';
|
|
@@ -1213,6 +1238,7 @@ function openAppDialog({ title, body = '', value = null, placeholder = '', confi
|
|
|
1213
1238
|
card.className = 'modal-card dialog-card';
|
|
1214
1239
|
card.setAttribute('role', 'dialog');
|
|
1215
1240
|
card.setAttribute('aria-modal', 'true');
|
|
1241
|
+
card.setAttribute('aria-label', title);
|
|
1216
1242
|
const heading = document.createElement('div');
|
|
1217
1243
|
heading.className = 'modal-head';
|
|
1218
1244
|
heading.textContent = title;
|
|
@@ -1255,9 +1281,29 @@ function openAppDialog({ title, body = '', value = null, placeholder = '', confi
|
|
|
1255
1281
|
event.preventDefault();
|
|
1256
1282
|
event.stopPropagation();
|
|
1257
1283
|
finish(null);
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
if (event.key === 'Tab') {
|
|
1287
|
+
const focusable = [input, cancel, ok].filter((node) => !node.hidden && !node.disabled);
|
|
1288
|
+
if (!focusable.length) return;
|
|
1289
|
+
const first = focusable[0];
|
|
1290
|
+
const last = focusable[focusable.length - 1];
|
|
1291
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
1292
|
+
event.preventDefault();
|
|
1293
|
+
last.focus();
|
|
1294
|
+
} else if (!event.shiftKey && document.activeElement === last) {
|
|
1295
|
+
event.preventDefault();
|
|
1296
|
+
first.focus();
|
|
1297
|
+
}
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
if (event.key === 'Enter') {
|
|
1301
|
+
// 焦点在「取消」上时交给按钮自己处理,不能误确认删除。
|
|
1302
|
+
if (document.activeElement === cancel) return;
|
|
1303
|
+
if (document.activeElement === input || value === null) {
|
|
1304
|
+
event.preventDefault();
|
|
1305
|
+
confirm();
|
|
1306
|
+
}
|
|
1261
1307
|
}
|
|
1262
1308
|
};
|
|
1263
1309
|
appDialog = wrap;
|
|
@@ -1271,6 +1317,9 @@ function openAppDialog({ title, body = '', value = null, placeholder = '', confi
|
|
|
1271
1317
|
if (!input.hidden) {
|
|
1272
1318
|
input.focus();
|
|
1273
1319
|
input.select();
|
|
1320
|
+
} else if (danger) {
|
|
1321
|
+
// 删除/清空这类不可逆操作,默认焦点放在「取消」,避免顺手回车。
|
|
1322
|
+
cancel.focus();
|
|
1274
1323
|
} else {
|
|
1275
1324
|
ok.focus();
|
|
1276
1325
|
}
|
|
@@ -2152,6 +2201,10 @@ async function send() {
|
|
|
2152
2201
|
state.info = event.info;
|
|
2153
2202
|
if (event.todos) state.info.session.todos = event.todos;
|
|
2154
2203
|
if (event.plan) state.info.session.plan = event.plan;
|
|
2204
|
+
// 空白草稿在第一条消息完成后才真正变成一个会话标签。
|
|
2205
|
+
if (!state.info.session.draft && state.activeTab !== state.info.session.id) {
|
|
2206
|
+
setActiveTab(state.info.session.id);
|
|
2207
|
+
}
|
|
2155
2208
|
}
|
|
2156
2209
|
const { sessions } = await get('sessions');
|
|
2157
2210
|
state.sessions = sessions;
|
|
@@ -2410,7 +2463,13 @@ async function clearCurrentSession() {
|
|
|
2410
2463
|
renderSidebar();
|
|
2411
2464
|
renderThread();
|
|
2412
2465
|
renderTodos();
|
|
2413
|
-
|
|
2466
|
+
if (state.info?.session && !state.info.session.draft) setActiveTab(state.info.session.id);
|
|
2467
|
+
else {
|
|
2468
|
+
state.tabs = [];
|
|
2469
|
+
state.activeTab = null;
|
|
2470
|
+
saveTabs();
|
|
2471
|
+
renderTabs();
|
|
2472
|
+
}
|
|
2414
2473
|
toast('已清空当前对话');
|
|
2415
2474
|
} catch (error) {
|
|
2416
2475
|
toast('清空失败:' + (error?.message ?? error));
|
|
@@ -2445,7 +2504,9 @@ async function renameCurrentSession(title) {
|
|
|
2445
2504
|
if (result?.sessions) state.sessions = result.sessions;
|
|
2446
2505
|
renderHeader();
|
|
2447
2506
|
renderSidebar();
|
|
2448
|
-
|
|
2507
|
+
// 空白草稿被显式重命名后会落盘,补上标签。
|
|
2508
|
+
if (state.info?.session && !state.info.session.draft) setActiveTab(state.info.session.id);
|
|
2509
|
+
else renderTabs();
|
|
2449
2510
|
toast('已重命名');
|
|
2450
2511
|
} catch (error) {
|
|
2451
2512
|
toast('重命名失败:' + (error?.message ?? error));
|
|
@@ -2583,6 +2644,7 @@ async function attach(file) {
|
|
|
2583
2644
|
// ---------------- 控制中心 ----------------
|
|
2584
2645
|
const SETTINGS_NAV = [
|
|
2585
2646
|
{ id: 'model', label: '模型', icon: 'chip' },
|
|
2647
|
+
{ id: 'search', label: '联网搜索', icon: 'globe' },
|
|
2586
2648
|
{ id: 'appearance', label: '外观', icon: 'sun' },
|
|
2587
2649
|
{ id: 'terminal', label: '终端', icon: 'terminal' },
|
|
2588
2650
|
{ id: 'workspace', label: '工作区', icon: 'folder' },
|
|
@@ -2712,6 +2774,10 @@ function toggleModelPop() {
|
|
|
2712
2774
|
}
|
|
2713
2775
|
|
|
2714
2776
|
function openSettings(category) {
|
|
2777
|
+
// 设置是整页层级,先收掉所有可能悬在上面的小弹层。
|
|
2778
|
+
closeModelPop();
|
|
2779
|
+
closeReasoningPop();
|
|
2780
|
+
document.querySelector('.popover')?.remove();
|
|
2715
2781
|
if (category) state.settingsCategory = category;
|
|
2716
2782
|
state.settingsScroll = 0;
|
|
2717
2783
|
state.settingsReturn = document.activeElement;
|
|
@@ -2874,6 +2940,7 @@ function renderSettings({ resetScroll = false } = {}) {
|
|
|
2874
2940
|
body.innerHTML = '';
|
|
2875
2941
|
const category = state.settingsCategory;
|
|
2876
2942
|
if (category === 'model') renderModelSettings(body);
|
|
2943
|
+
else if (category === 'search') renderSearchSettings(body);
|
|
2877
2944
|
else if (category === 'appearance') renderAppearanceSettings(body);
|
|
2878
2945
|
else if (category === 'terminal') renderTerminalSettings(body);
|
|
2879
2946
|
else if (category === 'workspace') renderWorkspaceSettings(body);
|
|
@@ -2978,6 +3045,97 @@ function renderModelSettings(body) {
|
|
|
2978
3045
|
body.appendChild(section);
|
|
2979
3046
|
}
|
|
2980
3047
|
|
|
3048
|
+
function renderSearchSettings(body) {
|
|
3049
|
+
const info = state.info;
|
|
3050
|
+
const search = info?.search ?? {
|
|
3051
|
+
provider: 'auto',
|
|
3052
|
+
deep: false,
|
|
3053
|
+
language: 'en',
|
|
3054
|
+
tavily: { saved: false, ready: false, env: 'TAVILY_API_KEY' },
|
|
3055
|
+
brave: { saved: false, ready: false, env: 'BRAVE_API_KEY' },
|
|
3056
|
+
};
|
|
3057
|
+
const section = settingsSection('联网搜索', '免费源开箱即用;填入 Key 后自动升级到更稳定的搜索 API。');
|
|
3058
|
+
|
|
3059
|
+
const card = settingsCard();
|
|
3060
|
+
const providerSelect = document.createElement('select');
|
|
3061
|
+
providerSelect.innerHTML = [
|
|
3062
|
+
['auto', '自动(有 Key 用 API,否则免费源)'],
|
|
3063
|
+
['tavily', 'Tavily'],
|
|
3064
|
+
['brave', 'Brave'],
|
|
3065
|
+
['free', '只用免费源'],
|
|
3066
|
+
]
|
|
3067
|
+
.map(([value, label]) => `<option value="${value}" ${search.provider === value ? 'selected' : ''}>${label}</option>`)
|
|
3068
|
+
.join('');
|
|
3069
|
+
providerSelect.addEventListener('change', async () => {
|
|
3070
|
+
await saveSetting('searchProvider', { value: providerSelect.value });
|
|
3071
|
+
await refresh(false);
|
|
3072
|
+
renderSettings();
|
|
3073
|
+
toast('搜索方式已更新');
|
|
3074
|
+
});
|
|
3075
|
+
card.appendChild(
|
|
3076
|
+
settingsRow('搜索方式', '自动模式优先用已配置的 Key;API 失败时会回退到免费源。', providerSelect),
|
|
3077
|
+
);
|
|
3078
|
+
|
|
3079
|
+
const keyRow = (name, label, spec) => {
|
|
3080
|
+
const input = settingsInput('', spec.saved ? '已保存,留空表示不修改' : `粘贴 ${label} API Key`, 'password');
|
|
3081
|
+
const save = settingsButton('保存', async () => {
|
|
3082
|
+
const value = input.value.trim();
|
|
3083
|
+
if (!value) return toast('留空表示不修改');
|
|
3084
|
+
await saveSetting('searchKey', { name, value });
|
|
3085
|
+
input.value = '';
|
|
3086
|
+
await refresh(false);
|
|
3087
|
+
renderSettings();
|
|
3088
|
+
toast(label + ' Key 已保存');
|
|
3089
|
+
}, true);
|
|
3090
|
+
input.addEventListener('keydown', (event) => {
|
|
3091
|
+
if (event.key === 'Enter') save.click();
|
|
3092
|
+
});
|
|
3093
|
+
const box = document.createElement('div');
|
|
3094
|
+
box.style.display = 'flex';
|
|
3095
|
+
box.style.gap = '6px';
|
|
3096
|
+
box.append(input, save);
|
|
3097
|
+
const hint = `也可以只设置环境变量 ${spec.env},当前${spec.ready ? '已就绪' : '未设置'}。`;
|
|
3098
|
+
card.appendChild(settingsRow(label, hint, box));
|
|
3099
|
+
};
|
|
3100
|
+
keyRow('tavily', 'Tavily', search.tavily);
|
|
3101
|
+
keyRow('brave', 'Brave', search.brave);
|
|
3102
|
+
|
|
3103
|
+
card.appendChild(
|
|
3104
|
+
settingsRow(
|
|
3105
|
+
'深度搜索',
|
|
3106
|
+
'开启后每次搜索会自动读前 3 页正文,答案更准,但会多花几秒。默认关闭;对话里也可以临时要求 deep。',
|
|
3107
|
+
settingsSwitch(Boolean(search.deep), async (on) => {
|
|
3108
|
+
await saveSetting('searchDeep', { value: String(on) });
|
|
3109
|
+
await refresh(false);
|
|
3110
|
+
toast(on ? '已开启深度搜索' : '已关闭深度搜索');
|
|
3111
|
+
}),
|
|
3112
|
+
),
|
|
3113
|
+
);
|
|
3114
|
+
|
|
3115
|
+
card.appendChild(
|
|
3116
|
+
settingsRow(
|
|
3117
|
+
'结果语言',
|
|
3118
|
+
'英文/技术优先会更多命中官方文档、GitHub 和 Stack Overflow;自动会跟随问题语言。',
|
|
3119
|
+
settingsSeg(
|
|
3120
|
+
[
|
|
3121
|
+
{ value: 'en', label: '英文/技术优先' },
|
|
3122
|
+
{ value: 'auto', label: '自动' },
|
|
3123
|
+
{ value: 'zh', label: '中文优先' },
|
|
3124
|
+
],
|
|
3125
|
+
search.language ?? 'en',
|
|
3126
|
+
async (value) => {
|
|
3127
|
+
await saveSetting('searchLanguage', { value });
|
|
3128
|
+
await refresh(false);
|
|
3129
|
+
toast('搜索语言偏好已更新');
|
|
3130
|
+
},
|
|
3131
|
+
),
|
|
3132
|
+
),
|
|
3133
|
+
);
|
|
3134
|
+
|
|
3135
|
+
section.appendChild(card);
|
|
3136
|
+
body.appendChild(section);
|
|
3137
|
+
}
|
|
3138
|
+
|
|
2981
3139
|
function renderAppearanceSettings(body) {
|
|
2982
3140
|
const saved = (() => {
|
|
2983
3141
|
try {
|
|
@@ -4266,6 +4424,9 @@ function openCommandCenter() {
|
|
|
4266
4424
|
return;
|
|
4267
4425
|
}
|
|
4268
4426
|
if (!$('settingsSheet').hidden) closeSettings();
|
|
4427
|
+
closeModelPop();
|
|
4428
|
+
closeReasoningPop();
|
|
4429
|
+
document.querySelector('.popover')?.remove();
|
|
4269
4430
|
state.ccIndex = 0;
|
|
4270
4431
|
state.ccFiles = [];
|
|
4271
4432
|
$('ccInput').value = '';
|
|
@@ -4715,6 +4876,15 @@ function bind() {
|
|
|
4715
4876
|
$('jumpLatest').hidden = true;
|
|
4716
4877
|
scrollToEnd(true, true);
|
|
4717
4878
|
});
|
|
4879
|
+
// 让「回到最新」始终位于 composer 上方,输入框长高或被附件/任务撑开时不会压住按钮。
|
|
4880
|
+
const composerWrap = document.querySelector('.composer-wrap');
|
|
4881
|
+
if (composerWrap && window.ResizeObserver) {
|
|
4882
|
+
const syncJumpPosition = () => {
|
|
4883
|
+
$('chatCard').style.setProperty('--composer-h', `${Math.round(composerWrap.getBoundingClientRect().height)}px`);
|
|
4884
|
+
};
|
|
4885
|
+
new ResizeObserver(syncJumpPosition).observe(composerWrap);
|
|
4886
|
+
syncJumpPosition();
|
|
4887
|
+
}
|
|
4718
4888
|
THREAD.addEventListener(
|
|
4719
4889
|
'wheel',
|
|
4720
4890
|
(event) => {
|
|
@@ -4816,6 +4986,8 @@ function bind() {
|
|
|
4816
4986
|
|
|
4817
4987
|
$('ccInput').addEventListener('input', () => {
|
|
4818
4988
|
state.ccIndex = 0;
|
|
4989
|
+
// 清空搜索时不要把上一次的文件结果留在列表里。
|
|
4990
|
+
if (!$('ccInput').value.trim()) state.ccFiles = [];
|
|
4819
4991
|
renderCommandCenter($('ccInput').value);
|
|
4820
4992
|
scheduleCommandFiles($('ccInput').value);
|
|
4821
4993
|
});
|
package/ui/style.css
CHANGED
|
@@ -4116,6 +4116,9 @@ input:focus-visible, textarea:focus-visible { outline: none; }
|
|
|
4116
4116
|
}
|
|
4117
4117
|
|
|
4118
4118
|
/* ---------- v1.2:折叠思考摘要、对话框、阅读细节 ---------- */
|
|
4119
|
+
/* 对话框必须盖住 tooltip(120) / 选择工具条(100) / 设置(80) 等所有层。 */
|
|
4120
|
+
.modal { z-index: 200; }
|
|
4121
|
+
.jump-latest { bottom: calc(var(--composer-h, 118px) + 14px); }
|
|
4119
4122
|
.think > summary .think-title { flex: none; }
|
|
4120
4123
|
.think-peek {
|
|
4121
4124
|
min-width: 0;
|
|
@@ -4128,6 +4131,12 @@ input:focus-visible, textarea:focus-visible { outline: none; }
|
|
|
4128
4131
|
}
|
|
4129
4132
|
.think-len { flex: none; margin-left: auto; }
|
|
4130
4133
|
.think .think-peek:empty { display: none; }
|
|
4134
|
+
.sb-empty {
|
|
4135
|
+
padding: 18px 10px;
|
|
4136
|
+
color: var(--text-3);
|
|
4137
|
+
font-size: 12px;
|
|
4138
|
+
line-height: 1.5;
|
|
4139
|
+
}
|
|
4131
4140
|
.table-wrap {
|
|
4132
4141
|
margin: 12px 0 16px;
|
|
4133
4142
|
max-width: 100%;
|