@vincentbanana/banana-gui 1.0.4 → 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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/ui/app.js +93 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vincentbanana/banana-gui",
3
- "version": "1.0.4",
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.4"
75
+ "@vincentbanana/bananacli": "^0.8.5"
76
76
  },
77
77
  "license": "MIT",
78
78
  "publishConfig": {
package/ui/app.js CHANGED
@@ -2644,6 +2644,7 @@ async function attach(file) {
2644
2644
  // ---------------- 控制中心 ----------------
2645
2645
  const SETTINGS_NAV = [
2646
2646
  { id: 'model', label: '模型', icon: 'chip' },
2647
+ { id: 'search', label: '联网搜索', icon: 'globe' },
2647
2648
  { id: 'appearance', label: '外观', icon: 'sun' },
2648
2649
  { id: 'terminal', label: '终端', icon: 'terminal' },
2649
2650
  { id: 'workspace', label: '工作区', icon: 'folder' },
@@ -2939,6 +2940,7 @@ function renderSettings({ resetScroll = false } = {}) {
2939
2940
  body.innerHTML = '';
2940
2941
  const category = state.settingsCategory;
2941
2942
  if (category === 'model') renderModelSettings(body);
2943
+ else if (category === 'search') renderSearchSettings(body);
2942
2944
  else if (category === 'appearance') renderAppearanceSettings(body);
2943
2945
  else if (category === 'terminal') renderTerminalSettings(body);
2944
2946
  else if (category === 'workspace') renderWorkspaceSettings(body);
@@ -3043,6 +3045,97 @@ function renderModelSettings(body) {
3043
3045
  body.appendChild(section);
3044
3046
  }
3045
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
+
3046
3139
  function renderAppearanceSettings(body) {
3047
3140
  const saved = (() => {
3048
3141
  try {