ai-helper-agent 2.4.5 → 2.4.6

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/dist/options.html CHANGED
@@ -5,9 +5,9 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title data-i18n="settings.docTitle">AI Helper - 配置</title>
7
7
  <script type="module" crossorigin src="/assets/theme-CLwYsx9o.js"></script>
8
- <script type="module" crossorigin src="/assets/i18n-8vdDPNQb.js"></script>
9
- <script type="module" crossorigin src="/assets/model-profiles-CtoST6-E.js"></script>
10
- <script type="module" crossorigin src="/assets/version-Djv0o0pB.js"></script>
8
+ <script type="module" crossorigin src="/assets/i18n-DnY00TAi.js"></script>
9
+ <script type="module" crossorigin src="/assets/model-profiles-Dxls-NRl.js"></script>
10
+ <script type="module" crossorigin src="/assets/version-BJQj5ijQ.js"></script>
11
11
  <script type="module" crossorigin src="/assets/network-scope-CNRYXk74.js"></script>
12
12
  <script type="module" crossorigin src="/assets/options.js"></script>
13
13
  <link rel="stylesheet" crossorigin href="/assets/theme-BRAX5X2F.css">
@@ -6,12 +6,13 @@
6
6
  <title data-i18n="header.docTitle">AI Helper - 模型问答</title>
7
7
  <script type="module" crossorigin src="/assets/theme-CLwYsx9o.js"></script>
8
8
  <script type="module" crossorigin src="/assets/chunk-CMxvf4Kt.js"></script>
9
- <script type="module" crossorigin src="/assets/i18n-8vdDPNQb.js"></script>
10
- <script type="module" crossorigin src="/assets/model-profiles-CtoST6-E.js"></script>
11
- <script type="module" crossorigin src="/assets/session-store-BBIdbyV_.js"></script>
12
- <script type="module" crossorigin src="/assets/version-Djv0o0pB.js"></script>
13
- <script type="module" crossorigin src="/assets/agent-store-D-jYf94_.js"></script>
14
- <script type="module" crossorigin src="/assets/utils-BIworoAB.js"></script>
9
+ <script type="module" crossorigin src="/assets/i18n-DnY00TAi.js"></script>
10
+ <script type="module" crossorigin src="/assets/model-profiles-Dxls-NRl.js"></script>
11
+ <script type="module" crossorigin src="/assets/session-store-d5HJQfSy.js"></script>
12
+ <script type="module" crossorigin src="/assets/version-BJQj5ijQ.js"></script>
13
+ <script type="module" crossorigin src="/assets/agent-store-YTGqC6WV.js"></script>
14
+ <script type="module" crossorigin src="/assets/utils-C8C2t-Yk.js"></script>
15
+ <script type="module" crossorigin src="/assets/markdown-render-D2D2Y1L2.js"></script>
15
16
  <script type="module" crossorigin src="/assets/side_panel.js"></script>
16
17
  <link rel="stylesheet" crossorigin href="/assets/theme-BRAX5X2F.css">
17
18
  <link rel="stylesheet" crossorigin href="/assets/side_panel.css">
@@ -1019,6 +1020,7 @@
1019
1020
  <tr><td><kbd>Alt</kbd> + <kbd>N</kbd></td><td data-i18n="shortcuts.newSession">新建会话</td><td>Win / Mac</td></tr>
1020
1021
  <tr><td><kbd>Alt</kbd> + <kbd>W</kbd></td><td data-i18n="shortcuts.closeCurrentSession">关闭当前会话</td><td>Win / Mac</td></tr>
1021
1022
  <tr><td><kbd>Alt</kbd> + <kbd>E</kbd></td><td data-i18n="shortcuts.editLastMessage">编辑最近一条用户消息</td><td>Win / Mac</td></tr>
1023
+ <tr><td><kbd>Alt</kbd> + <kbd>F</kbd></td><td data-i18n="shortcuts.messageFullscreen">全屏查看 / 退出查看回答</td><td>Win / Mac</td></tr>
1022
1024
  <tr class="shortcuts-divider"><td colspan="3"></td></tr>
1023
1025
  <tr><td><kbd>Enter</kbd></td><td data-i18n="shortcuts.sendMessage">发送消息</td><td>Win / Mac</td></tr>
1024
1026
  <tr><td><kbd>Shift</kbd> + <kbd>Enter</kbd></td><td data-i18n="shortcuts.newLine">换行</td><td>Win / Mac</td></tr>
@@ -1030,6 +1032,24 @@
1030
1032
  </div>
1031
1033
  </div>
1032
1034
 
1035
+ <!-- AI 回答全屏阅读覆盖层(节点迁移,消息节点动态挂入 body) -->
1036
+ <div class="message-fullscreen-overlay" id="messageFullscreenOverlay" style="display:none">
1037
+ <div class="message-fullscreen-header">
1038
+ <span class="message-fullscreen-title" id="messageFullscreenTitle" data-i18n="msgFullscreen.title">全屏阅读</span>
1039
+ <div class="message-fullscreen-actions">
1040
+ <button class="message-fullscreen-icon-btn" id="messageFullscreenCopyBtn" title="复制">
1041
+ <svg viewBox="0 0 16 16" fill="currentColor" width="16" height="16"><path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25zM5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25z"/></svg>
1042
+ <span data-i18n="msgFullscreen.copy">复制</span>
1043
+ </button>
1044
+ <button class="message-fullscreen-icon-btn message-fullscreen-close" id="messageFullscreenCloseBtn" title="退出全屏">
1045
+ <svg viewBox="0 0 16 16" fill="currentColor" width="16" height="16"><path d="M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.75.75 0 1 1 1.06 1.06L9.06 8l3.22 3.22a.75.75 0 1 1-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 0 1-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06z"/></svg>
1046
+ </button>
1047
+ </div>
1048
+ </div>
1049
+ <div class="message-fullscreen-body" id="messageFullscreenBody"></div>
1050
+ <div class="message-fullscreen-rail" id="messageFullscreenRail"></div>
1051
+ </div>
1052
+
1033
1053
  <!-- 版本信息弹窗 -->
1034
1054
  <div class="modal-overlay" id="versionInfoModal" style="z-index: 4000;">
1035
1055
  <div class="modal-container version-info-container">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-helper-agent",
3
- "version": "2.4.5",
3
+ "version": "2.4.6",
4
4
  "description": "AI Helper Agent - Local file access and system command execution proxy for Chrome extension / AI Helper 代理服务,为 Chrome 扩展提供本地文件读写和系统命令执行",
5
5
  "type": "module",
6
6
  "main": "./src/server.js",
@@ -0,0 +1,134 @@
1
+ // agent/src/directory-picker.js - 系统原生目录选择框
2
+ // 供扩展端"切换工作目录"弹窗的浏览按钮调用:仅本机代理(loopback)有意义,
3
+ // 远端机器可能无桌面环境,弹窗用户也看不到(由 server.js 的来源 IP 门控兜底)。
4
+ import { spawn } from 'child_process';
5
+
6
+ // 选择框悬挂超时:用户长时间不选视为放弃,避免子进程常驻
7
+ const PICK_TIMEOUT_MS = 120 * 1000;
8
+
9
+ /**
10
+ * 构造各平台的目录选择命令
11
+ * @param {string} title - 选择框提示文案
12
+ * @param {string} [platform] - 平台标识(默认 process.platform,测试可注入)
13
+ * @returns {{command: string, args: string[], fallback?: {command: string, args: string[]}}}
14
+ */
15
+ export function buildPickCommand(title, platform = process.platform) {
16
+ // 各命令均以参数数组形式传入(不经 shell),这里仅清理标题中的引号防止脚本注入
17
+ const safeTitle = String(title || '').replace(/["'\\`]/g, '').trim() || 'Select folder';
18
+
19
+ if (platform === 'darwin') {
20
+ return {
21
+ command: 'osascript',
22
+ args: ['-e', `POSIX path of (choose folder with prompt "${safeTitle}")`],
23
+ };
24
+ }
25
+
26
+ if (platform === 'win32') {
27
+ // FolderBrowserDialog 需要 STA 线程;TopMost owner 防止对话框被主窗口遮挡
28
+ const script = [
29
+ "Add-Type -AssemblyName System.Windows.Forms",
30
+ "$f = New-Object System.Windows.Forms.FolderBrowserDialog",
31
+ `$f.Description = '${safeTitle}'`,
32
+ "$owner = New-Object System.Windows.Forms.Form -Property @{TopMost = $true}",
33
+ "if ($f.ShowDialog($owner) -eq [System.Windows.Forms.DialogResult]::OK) { [Console]::Out.Write($f.SelectedPath) }",
34
+ ].join('; ');
35
+ // EncodedCommand(base64 UTF-16LE)避免命令行转义问题
36
+ const encoded = Buffer.from(script, 'utf16le').toString('base64');
37
+ return {
38
+ command: 'powershell.exe',
39
+ args: ['-NoProfile', '-NonInteractive', '-STA', '-EncodedCommand', encoded],
40
+ };
41
+ }
42
+
43
+ // Linux / 其他:zenity 优先,kdialog 回退
44
+ return {
45
+ command: 'zenity',
46
+ args: ['--file-selection', '--directory', `--title=${safeTitle}`],
47
+ fallback: {
48
+ command: 'kdialog',
49
+ args: ['--getexistingdirectory', '~', '--title', safeTitle],
50
+ },
51
+ };
52
+ }
53
+
54
+ /** 规整选中路径:去首尾空白与 osascript POSIX path 的尾斜杠(根目录 "/" 除外) */
55
+ function normalizePickedPath(raw) {
56
+ let p = String(raw || '').trim();
57
+ while (p.length > 1 && p.endsWith('/')) p = p.slice(0, -1);
58
+ return p;
59
+ }
60
+
61
+ /**
62
+ * 运行单个选择命令,收集 stdout;spawn 失败(ENOENT 等)与超时均以结果对象返回,不抛异常
63
+ */
64
+ function runPickOnce(command, args, timeoutMs, spawnImpl) {
65
+ return new Promise((resolve) => {
66
+ let child;
67
+ try {
68
+ child = spawnImpl(command, args, { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
69
+ } catch (err) {
70
+ resolve({ spawnError: true, stderr: String(err?.message || err) });
71
+ return;
72
+ }
73
+ let stdout = '';
74
+ let timedOut = false;
75
+ let settled = false;
76
+ const finish = (result) => {
77
+ if (settled) return;
78
+ settled = true;
79
+ clearTimeout(timer);
80
+ resolve(result);
81
+ };
82
+ const timer = setTimeout(() => {
83
+ timedOut = true;
84
+ try { child.kill(); } catch { /* 进程已退出 */ }
85
+ }, timeoutMs);
86
+ child.stdout?.on?.('data', (d) => { stdout += d; });
87
+ child.stderr?.on?.('data', () => {});
88
+ // spawn 失败(命令不存在等)以异步 error 事件呈现
89
+ child.on?.('error', (err) => finish({ spawnError: true, stderr: String(err?.message || err) }));
90
+ child.on?.('close', (code) => finish({ code, stdout, stderr: '', timedOut }));
91
+ });
92
+ }
93
+
94
+ /**
95
+ * 弹出系统原生目录选择框
96
+ * @param {string} [title] - 选择框提示文案
97
+ * @param {object} [options] - spawnImpl(测试注入)/ timeoutMs / platform(测试注入)/ hasDisplay(测试注入,Linux 无图形会话判定)
98
+ * @returns {Promise<{success: boolean, path: string|null, available: boolean, error?: string}>}
99
+ * - 选中:{ success: true, path, available: true }
100
+ * - 用户取消:{ success: true, path: null, available: true }
101
+ * - 环境不支持(命令不存在/无图形会话):{ success: false, path: null, available: false }
102
+ * - 超时等其他错误:{ success: false, path: null, available: true, error }
103
+ */
104
+ export async function pickDirectoryNative(title = '', options = {}) {
105
+ const spawnImpl = options.spawnImpl || spawn;
106
+ const timeoutMs = options.timeoutMs ?? PICK_TIMEOUT_MS;
107
+ const platform = options.platform ?? process.platform;
108
+ const hasDisplay = options.hasDisplay ?? Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
109
+
110
+ // 无图形会话的 Linux 直接降级(zenity/kdialog 起不来,只会白白报错)
111
+ if (platform === 'linux' && !hasDisplay) {
112
+ return { success: false, path: null, available: false, error: 'no-display' };
113
+ }
114
+
115
+ const plan = buildPickCommand(title, platform);
116
+ const attempts = plan.fallback ? [plan, plan.fallback] : [plan];
117
+
118
+ for (const { command, args } of attempts) {
119
+ const r = await runPickOnce(command, args, timeoutMs, spawnImpl);
120
+ if (r.spawnError) continue; // 该命令不可用,尝试回退
121
+ if (r.timedOut) {
122
+ return { success: false, path: null, available: true, error: 'timeout' };
123
+ }
124
+ const path = normalizePickedPath(r.stdout);
125
+ if (path) {
126
+ return { success: true, path, available: true };
127
+ }
128
+ // 空输出(无论退出码):用户取消选择
129
+ return { success: true, path: null, available: true };
130
+ }
131
+
132
+ // 所有候选命令均不可用
133
+ return { success: false, path: null, available: false, error: 'no-dialog-tool' };
134
+ }
package/src/server.js CHANGED
@@ -54,6 +54,7 @@ import { setSkillExecutorLang } from './skill/executor.js';
54
54
  import { setMarkdownLoaderLang } from './skill/markdown-loader.js';
55
55
  import { setMcpClientLang } from './mcp/client.js';
56
56
  import { getRequestI18n, t, parseAcceptLanguage } from './i18n.js';
57
+ import { pickDirectoryNative } from './directory-picker.js';
57
58
  import { extractImagesHandler } from './documents/routes.js';
58
59
 
59
60
  // Server-level i18n helper (uses env/CLI language)
@@ -983,6 +984,29 @@ export function startServer() {
983
984
  }
984
985
  }
985
986
 
987
+ // === 弹出系统原生目录选择框(仅限本机来源) ===
988
+ // 仅本机(loopback)代理有意义:远端机器可能无桌面环境,弹窗用户也看不到;
989
+ // 且工作目录本就是代理端机器的路径,浏览器侧选择框语义上也不成立。
990
+ if (pathname === '/api/config/pick-directory' && req.method === 'POST') {
991
+ const remoteIp = req.socket.remoteAddress || '';
992
+ const isLocal = remoteIp === '127.0.0.1' || remoteIp === '::1' || remoteIp === '::ffff:127.0.0.1' || remoteIp === 'localhost';
993
+ if (!isLocal) {
994
+ // 不抛 403/404:以 available:false 降级返回,扩展端据此隐藏浏览按钮
995
+ logSecurity('pick_directory_remote_blocked', { remote: remoteIp, extId });
996
+ return jsonResponse(res, 200, { success: false, path: null, available: false, error: 'remote-source' });
997
+ }
998
+ try {
999
+ const result = await pickDirectoryNative(typeof body.title === 'string' ? body.title : '');
1000
+ if (result.success && result.path) {
1001
+ logSystem('directory_picked', { path: result.path, extId });
1002
+ }
1003
+ return jsonResponse(res, 200, result);
1004
+ } catch (err) {
1005
+ logError('config', 'pick_directory_error', { error: err.message });
1006
+ return jsonResponse(res, 500, { success: false, path: null, available: true, error: err.message });
1007
+ }
1008
+ }
1009
+
986
1010
  // === 文件操作 ===
987
1011
 
988
1012
  // 搜索文件(按文件名模式)