ai-helper-agent 2.7.6 → 2.7.8
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 +1 -1
- package/README.zh-CN.md +1 -1
- package/bin/agent.js +20 -31
- package/dist/assets/{agent-store-1fyaAv9T.js → agent-store-sKnc7YcJ.js} +1 -1
- package/dist/assets/background.js +35 -35
- package/dist/assets/{chat-export-CmaDpmwW.js → chat-export-BSv2Jn2H.js} +1 -1
- package/dist/assets/content.js +2 -2
- package/dist/assets/{i18n-DQnIL9xy.js → i18n-NkRsFRG_.js} +2 -2
- package/dist/assets/markdown-render-lNxIpqR5.js +61 -0
- package/dist/assets/model-profiles-DH6uFSiB.js +24 -0
- package/dist/assets/{options-d_q5bb5y.css → options-CM9dPi9P.css} +1 -1
- package/dist/assets/options.js +92 -88
- package/dist/assets/{page-snapshot-renderer-B9y0q0s6.js → page-snapshot-renderer-xd8FypSv.js} +1 -1
- package/dist/assets/session-store-BXelxKzG.js +84 -0
- package/dist/assets/side_panel.css +1 -1
- package/dist/assets/side_panel.js +280 -273
- package/dist/assets/{utils-DVhZvlZX.js → utils-CMkztLa1.js} +1 -1
- package/dist/assets/version-C8Rq9nMu.js +3 -0
- package/dist/assets/{workspace-manager-DfSFPqwp.js → workspace-manager-CTFkcx87.js} +1 -1
- package/dist/manifest.json +1 -1
- package/dist/offscreen/offscreen.js +2 -2
- package/dist/options.html +6 -4
- package/dist/side_panel.html +63 -15
- package/package.json +1 -1
- package/src/autostart.js +206 -0
- package/src/locales/cli.json +8 -2
- package/dist/assets/markdown-render-CDJ7FW_o.js +0 -63
- package/dist/assets/model-profiles-D31rvEiY.js +0 -24
- package/dist/assets/session-store-xr0nYACs.js +0 -84
- package/dist/assets/version-CHQCdVOZ.js +0 -1
package/dist/side_panel.html
CHANGED
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
<title data-i18n="header.docTitle">AI Helper - 模型问答</title>
|
|
7
7
|
<script type="module" crossorigin src="/assets/theme-Cp7RrL45.js"></script>
|
|
8
8
|
<script type="module" crossorigin src="/assets/chunk-CMxvf4Kt.js"></script>
|
|
9
|
-
<script type="module" crossorigin src="/assets/i18n-
|
|
10
|
-
<script type="module" crossorigin src="/assets/model-profiles-
|
|
11
|
-
<script type="module" crossorigin src="/assets/session-store-
|
|
12
|
-
<script type="module" crossorigin src="/assets/version-
|
|
13
|
-
<script type="module" crossorigin src="/assets/agent-store-1fyaAv9T.js"></script>
|
|
14
|
-
<script type="module" crossorigin src="/assets/utils-DVhZvlZX.js"></script>
|
|
15
|
-
<script type="module" crossorigin src="/assets/markdown-render-CDJ7FW_o.js"></script>
|
|
9
|
+
<script type="module" crossorigin src="/assets/i18n-NkRsFRG_.js"></script>
|
|
10
|
+
<script type="module" crossorigin src="/assets/model-profiles-DH6uFSiB.js"></script>
|
|
11
|
+
<script type="module" crossorigin src="/assets/session-store-BXelxKzG.js"></script>
|
|
12
|
+
<script type="module" crossorigin src="/assets/version-C8Rq9nMu.js"></script>
|
|
16
13
|
<script type="module" crossorigin src="/assets/voice-shortcut-Dtt3nhkz.js"></script>
|
|
17
|
-
<script type="module" crossorigin src="/assets/
|
|
14
|
+
<script type="module" crossorigin src="/assets/agent-store-sKnc7YcJ.js"></script>
|
|
15
|
+
<script type="module" crossorigin src="/assets/utils-CMkztLa1.js"></script>
|
|
16
|
+
<script type="module" crossorigin src="/assets/markdown-render-lNxIpqR5.js"></script>
|
|
17
|
+
<script type="module" crossorigin src="/assets/workspace-manager-CTFkcx87.js"></script>
|
|
18
18
|
<script type="module" crossorigin src="/assets/side_panel.js"></script>
|
|
19
19
|
<link rel="stylesheet" crossorigin href="/assets/theme-ChzggwXz.css">
|
|
20
20
|
<link rel="stylesheet" crossorigin href="/assets/side_panel.css">
|
|
@@ -180,10 +180,61 @@
|
|
|
180
180
|
|
|
181
181
|
<!-- 主内容区:左侧(标签栏+对话+输入)与右侧(工作目录面板,嵌入模式时参与分栏) -->
|
|
182
182
|
<div class="main-row" id="mainRow">
|
|
183
|
+
<!-- 左侧纵向会话栏:默认不占位,点标签栏左端的切换图标才展开为可拖拽宽度的面板;
|
|
184
|
+
窄屏(mainRow < 560px)整条隐藏,会话列表入口回退为 ⋯ 打开的全屏覆盖列表 -->
|
|
185
|
+
<div class="session-sidebar" id="sessionSidebar">
|
|
186
|
+
<!-- 展开态:会话管理面板 -->
|
|
187
|
+
<div class="session-sidebar-panel" id="sessionSidebarPanel">
|
|
188
|
+
<div class="session-sidebar-header">
|
|
189
|
+
<span class="session-sidebar-title" data-i18n="session.sessionListTitle">会话列表</span>
|
|
190
|
+
<div class="session-sidebar-header-actions">
|
|
191
|
+
<!-- 排序规则:手动(可拖拽,与标签栏同一份顺序)/ 最近更新(时间倒序 + 时间分组) -->
|
|
192
|
+
<div class="session-sidebar-sort" id="sessionSidebarSort" role="group" data-i18n-title="session.sortModeTitle" title="会话排序">
|
|
193
|
+
<button class="session-sidebar-sort-btn" data-mode="manual" aria-pressed="true" data-i18n-title="session.sortManual" title="手动排序">
|
|
194
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="6" x2="20" y2="6"/><line x1="4" y1="12" x2="20" y2="12"/><line x1="4" y1="18" x2="20" y2="18"/></svg>
|
|
195
|
+
</button>
|
|
196
|
+
<button class="session-sidebar-sort-btn" data-mode="recent" aria-pressed="false" data-i18n-title="session.sortRecent" title="最近更新优先">
|
|
197
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><polyline points="12 7 12 12 15 14"/></svg>
|
|
198
|
+
</button>
|
|
199
|
+
</div>
|
|
200
|
+
<button class="session-sidebar-add" id="sessionSidebarAdd" data-i18n-title="session.newSessionTitle" title="新建会话 (Alt+N)">+</button>
|
|
201
|
+
<!-- 与标签栏左端的展开图标互斥:面板展开时只在这里显示收起 -->
|
|
202
|
+
<button class="session-sidebar-collapse" id="sessionSidebarCollapse" data-i18n-title="session.collapseSidebar" title="收起会话列表">
|
|
203
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="11 17 6 12 11 7"/><polyline points="18 17 13 12 18 7"/></svg>
|
|
204
|
+
</button>
|
|
205
|
+
</div>
|
|
206
|
+
</div>
|
|
207
|
+
<div class="session-sidebar-search">
|
|
208
|
+
<svg class="session-dropdown-search-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
209
|
+
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>
|
|
210
|
+
</svg>
|
|
211
|
+
<input type="text" data-i18n-placeholder="session.searchPlaceholder" placeholder="搜索会话..." id="sessionSidebarSearch" />
|
|
212
|
+
<button class="session-dropdown-search-clear" id="sessionSidebarSearchClear" title="清除搜索" style="display:none;">
|
|
213
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
|
214
|
+
</button>
|
|
215
|
+
</div>
|
|
216
|
+
<div class="session-sidebar-list" id="sessionSidebarList"></div>
|
|
217
|
+
<div class="session-sidebar-footer">
|
|
218
|
+
<button class="session-archive-entry" id="sessionSidebarArchiveEntry" data-i18n-title="session.archiveEntryTitle" title="查看归档会话">
|
|
219
|
+
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8v13H3V8"/><rect x="1" y="3" width="22" height="5"/><line x1="10" y1="12" x2="14" y2="12"/></svg>
|
|
220
|
+
<span class="session-archive-entry-label" id="sessionSidebarArchiveLabel" data-i18n="session.archiveEntry">归档区</span>
|
|
221
|
+
</button>
|
|
222
|
+
<button class="session-dropdown-close-all" id="sessionSidebarCloseAll" data-i18n="session.closeAll">关闭全部</button>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
<!-- 展开态右缘宽度拖拽把手 -->
|
|
226
|
+
<div class="session-sidebar-grip" id="sessionSidebarGrip"></div>
|
|
227
|
+
</div>
|
|
183
228
|
<div class="main-left" id="mainLeft">
|
|
184
229
|
|
|
185
230
|
<!-- 会话标签栏 -->
|
|
186
231
|
<div class="session-tabs" id="sessionTabs">
|
|
232
|
+
<!-- 左栏切换:宽屏下常驻于此,收起时不占位;窄屏隐藏(改由 ⋯ 打开全屏列表) -->
|
|
233
|
+
<button class="session-sidebar-toggle" id="sessionSidebarToggle" data-i18n-title="session.expandSidebar" title="展开会话列表">
|
|
234
|
+
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
235
|
+
<rect x="3" y="4" width="18" height="16" rx="2"/><line x1="9" y1="4" x2="9" y2="20"/>
|
|
236
|
+
</svg>
|
|
237
|
+
</button>
|
|
187
238
|
<div class="session-tabs-scroll" id="sessionTabsScroll" style="opacity:0"></div>
|
|
188
239
|
<div class="session-tabs-actions" id="sessionTabsActions">
|
|
189
240
|
<div class="session-tab-add" id="sessionTabsAdd" data-i18n-title="session.newSessionTitle" title="新建会话 (Alt+N)">+</div>
|
|
@@ -218,8 +269,7 @@
|
|
|
218
269
|
<div class="session-dropdown-footer">
|
|
219
270
|
<button class="session-archive-entry" id="sessionArchiveEntry" data-i18n-title="session.archiveEntryTitle" title="查看归档会话">
|
|
220
271
|
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8v13H3V8"/><rect x="1" y="3" width="22" height="5"/><line x1="10" y1="12" x2="14" y2="12"/></svg>
|
|
221
|
-
<span class="session-archive-entry-label" data-i18n="session.archiveEntry">归档区</span>
|
|
222
|
-
<span class="session-archive-entry-count" id="sessionArchiveEntryCount" hidden></span>
|
|
272
|
+
<span class="session-archive-entry-label" id="sessionArchiveEntryLabel" data-i18n="session.archiveEntry">归档区</span>
|
|
223
273
|
</button>
|
|
224
274
|
<button class="session-dropdown-close-all" id="sessionDropdownCloseAll" data-i18n="session.closeAll">关闭全部</button>
|
|
225
275
|
</div>
|
|
@@ -259,11 +309,9 @@
|
|
|
259
309
|
<h2 data-i18n="chat.welcomeTitle">开始对话</h2>
|
|
260
310
|
<p data-i18n="chat.welcomeSubtitle">输入您的问题,AI 助手将为您解答</p>
|
|
261
311
|
</div>
|
|
262
|
-
<!--
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
<div id="selectionMenuItems"></div>
|
|
266
|
-
</div>
|
|
312
|
+
<!-- 选中文本浮动菜单不在此处静态声明:AI 回答全屏阅读会把消息节点迁出本容器,
|
|
313
|
+
静态节点留在容器内既会被覆盖层遮住又会被会话 DOM 快照复制,改由
|
|
314
|
+
index.js 的 ensureSelectionMenuEl() 惰性建到 body 上(fixed 定位) -->
|
|
267
315
|
</div>
|
|
268
316
|
|
|
269
317
|
<!-- 消息跳转把手(上一个/下一个问题 + 问题列表;悬停展开,点击钉住) -->
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-helper-agent",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.8",
|
|
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",
|
package/src/autostart.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// agent/src/autostart.js - 跨平台开机自启注册
|
|
2
|
+
//
|
|
3
|
+
// 三种平台均使用「用户登录时触发」,无需管理员权限:
|
|
4
|
+
// macOS ~/Library/LaunchAgents/com.ai-helper.agent.plist (launchd)
|
|
5
|
+
// Linux ~/.config/systemd/user/ai-helper-agent.service (systemd --user)
|
|
6
|
+
// Windows HKCU\Software\Microsoft\Windows\CurrentVersion\Run (注册表 Run 键)
|
|
7
|
+
//
|
|
8
|
+
// Windows 不再使用 schtasks /SC ONLOGON:该触发器的创建在多数非提权环境会被拒绝,
|
|
9
|
+
// 且计划任务结束时可能连带结束被 detach 的子进程。注册表 Run 键无这些限制。
|
|
10
|
+
|
|
11
|
+
import { spawnSync } from 'child_process';
|
|
12
|
+
import { existsSync, mkdirSync, writeFileSync, unlinkSync } from 'fs';
|
|
13
|
+
import { homedir } from 'os';
|
|
14
|
+
import { join, resolve } from 'path';
|
|
15
|
+
|
|
16
|
+
const AGENT_DIR = join(homedir(), '.ai-helper-agent');
|
|
17
|
+
const LOGS_DIR = join(AGENT_DIR, 'logs');
|
|
18
|
+
const STOPPED_FLAG = join(AGENT_DIR, '.stopped');
|
|
19
|
+
|
|
20
|
+
const LAUNCH_AGENT_LABEL = 'com.ai-helper.agent';
|
|
21
|
+
const LAUNCH_AGENT_PLIST = join(homedir(), 'Library', 'LaunchAgents', `${LAUNCH_AGENT_LABEL}.plist`);
|
|
22
|
+
const SYSTEMD_SERVICE = join(homedir(), '.config', 'systemd', 'user', 'ai-helper-agent.service');
|
|
23
|
+
|
|
24
|
+
const WIN_RUN_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';
|
|
25
|
+
const WIN_RUN_VALUE = 'AIHelperAgent';
|
|
26
|
+
const WIN_TASK_NAME = 'AIHelperAgent';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 自启入口命令:优先复用安装脚本生成的 aha 包装器(Node 运行时升级后路径依然有效),
|
|
30
|
+
* npm 全局安装模式下列回退到「当前 node + 包内脚本」。
|
|
31
|
+
* @returns {{ exe: string, args: string[] }}
|
|
32
|
+
*/
|
|
33
|
+
function guardCommand() {
|
|
34
|
+
return agentCommand('_autostart-guard');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 前台启动命令(Linux systemd 使用,不能走 guard)
|
|
39
|
+
* @returns {{ exe: string, args: string[] }}
|
|
40
|
+
*/
|
|
41
|
+
function startCommand() {
|
|
42
|
+
return agentCommand('start');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function agentCommand(subcommand) {
|
|
46
|
+
const wrapper = join(AGENT_DIR, 'bin', process.platform === 'win32' ? 'aha.cmd' : 'aha');
|
|
47
|
+
if (existsSync(wrapper)) {
|
|
48
|
+
return { exe: wrapper, args: [subcommand] };
|
|
49
|
+
}
|
|
50
|
+
return { exe: process.execPath, args: [resolve(process.argv[1]), subcommand] };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function escapeXml(value) {
|
|
54
|
+
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// systemd 单元文件中 % 需转义为 %%
|
|
58
|
+
function escapeSystemd(value) {
|
|
59
|
+
return value.replace(/%/g, '%%');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 启用开机自启
|
|
64
|
+
* @returns {{ ok: boolean, detail?: string }}
|
|
65
|
+
*/
|
|
66
|
+
export function enableAutostart() {
|
|
67
|
+
if (process.platform === 'win32') return enableWindows();
|
|
68
|
+
if (process.platform === 'darwin') return enableMacos();
|
|
69
|
+
return enableLinux();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 关闭开机自启
|
|
74
|
+
* @returns {{ ok: boolean, detail?: string }}
|
|
75
|
+
*/
|
|
76
|
+
export function disableAutostart() {
|
|
77
|
+
if (process.platform === 'win32') return disableWindows();
|
|
78
|
+
if (process.platform === 'darwin') return disableMacos();
|
|
79
|
+
return disableLinux();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ==================== Windows ====================
|
|
83
|
+
function enableWindows() {
|
|
84
|
+
const { exe, args } = guardCommand();
|
|
85
|
+
const value = [exe, ...args].map((part) => `"${part}"`).join(' ');
|
|
86
|
+
|
|
87
|
+
// 清理历史遗留的计划任务,避免与注册表键重复拉起
|
|
88
|
+
spawnSync('schtasks', ['/Delete', '/TN', WIN_TASK_NAME, '/F'], { windowsHide: true, stdio: 'ignore' });
|
|
89
|
+
|
|
90
|
+
const res = spawnSync(
|
|
91
|
+
'reg',
|
|
92
|
+
['add', WIN_RUN_KEY, '/v', WIN_RUN_VALUE, '/t', 'REG_SZ', '/d', value, '/f'],
|
|
93
|
+
{ windowsHide: true, encoding: 'utf-8' }
|
|
94
|
+
);
|
|
95
|
+
if (res.error) return { ok: false, detail: res.error.message };
|
|
96
|
+
if (res.status !== 0) return { ok: false, detail: (res.stderr || res.stdout || '').trim() };
|
|
97
|
+
return { ok: true };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function disableWindows() {
|
|
101
|
+
// 值不存在时 reg 返回非 0,目标状态已达成,无需报错
|
|
102
|
+
spawnSync('reg', ['delete', WIN_RUN_KEY, '/v', WIN_RUN_VALUE, '/f'], { windowsHide: true, stdio: 'ignore' });
|
|
103
|
+
spawnSync('schtasks', ['/Delete', '/TN', WIN_TASK_NAME, '/F'], { windowsHide: true, stdio: 'ignore' });
|
|
104
|
+
return { ok: true };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ==================== macOS ====================
|
|
108
|
+
function enableMacos() {
|
|
109
|
+
const { exe, args } = guardCommand();
|
|
110
|
+
const programArgs = [exe, ...args].map((part) => ` <string>${escapeXml(part)}</string>`).join('\n');
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
mkdirSync(join(homedir(), 'Library', 'LaunchAgents'), { recursive: true });
|
|
114
|
+
mkdirSync(LOGS_DIR, { recursive: true });
|
|
115
|
+
} catch (err) {
|
|
116
|
+
return { ok: false, detail: err.message };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
120
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
121
|
+
<plist version="1.0">
|
|
122
|
+
<dict>
|
|
123
|
+
<key>Label</key><string>${LAUNCH_AGENT_LABEL}</string>
|
|
124
|
+
<key>ProgramArguments</key>
|
|
125
|
+
<array>
|
|
126
|
+
${programArgs}
|
|
127
|
+
</array>
|
|
128
|
+
<key>RunAtLoad</key><true/>
|
|
129
|
+
<key>StandardOutPath</key><string>${escapeXml(join(LOGS_DIR, 'launchd-out.log'))}</string>
|
|
130
|
+
<key>StandardErrorPath</key><string>${escapeXml(join(LOGS_DIR, 'launchd-err.log'))}</string>
|
|
131
|
+
</dict>
|
|
132
|
+
</plist>
|
|
133
|
+
`;
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
writeFileSync(LAUNCH_AGENT_PLIST, plist);
|
|
137
|
+
} catch (err) {
|
|
138
|
+
return { ok: false, detail: err.message };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 先卸载旧配置再加载,保证修改后的 plist 生效
|
|
142
|
+
spawnSync('launchctl', ['unload', LAUNCH_AGENT_PLIST], { stdio: 'ignore' });
|
|
143
|
+
let res = spawnSync('launchctl', ['load', LAUNCH_AGENT_PLIST], { encoding: 'utf-8' });
|
|
144
|
+
if (res.status !== 0) {
|
|
145
|
+
// 新版 macOS 推荐 bootstrap,作为 load 失败时的兜底
|
|
146
|
+
res = spawnSync('launchctl', ['bootstrap', `gui/${process.getuid()}`, LAUNCH_AGENT_PLIST], { encoding: 'utf-8' });
|
|
147
|
+
}
|
|
148
|
+
if (res.error) return { ok: false, detail: res.error.message };
|
|
149
|
+
if (res.status !== 0) return { ok: false, detail: (res.stderr || res.stdout || '').trim() };
|
|
150
|
+
return { ok: true };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function disableMacos() {
|
|
154
|
+
spawnSync('launchctl', ['unload', LAUNCH_AGENT_PLIST], { stdio: 'ignore' });
|
|
155
|
+
try {
|
|
156
|
+
if (existsSync(LAUNCH_AGENT_PLIST)) unlinkSync(LAUNCH_AGENT_PLIST);
|
|
157
|
+
} catch (err) {
|
|
158
|
+
return { ok: false, detail: err.message };
|
|
159
|
+
}
|
|
160
|
+
return { ok: true };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// ==================== Linux ====================
|
|
164
|
+
function enableLinux() {
|
|
165
|
+
const { exe, args } = startCommand();
|
|
166
|
+
// systemd 以 cgroup 管理进程:_autostart-guard 启动后立即退出会让服务被判为结束,
|
|
167
|
+
// 其 detach 出来的子进程也会被连带清理。因此这里直接前台运行 start,
|
|
168
|
+
// 并用 ExecStartPre 检查 .stopped 标记(用户主动 stop 后不再拉起)。
|
|
169
|
+
const startCmd = [exe, ...args].map((part) => `"${escapeSystemd(part)}"`).join(' ');
|
|
170
|
+
const unit = `[Unit]
|
|
171
|
+
Description=AI Helper Agent
|
|
172
|
+
After=network.target
|
|
173
|
+
|
|
174
|
+
[Service]
|
|
175
|
+
Type=exec
|
|
176
|
+
ExecStartPre=/bin/sh -c 'test -f "${escapeSystemd(STOPPED_FLAG)}" && exit 1 || true'
|
|
177
|
+
ExecStart=${startCmd}
|
|
178
|
+
|
|
179
|
+
[Install]
|
|
180
|
+
WantedBy=default.target
|
|
181
|
+
`;
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
mkdirSync(join(homedir(), '.config', 'systemd', 'user'), { recursive: true });
|
|
185
|
+
writeFileSync(SYSTEMD_SERVICE, unit);
|
|
186
|
+
} catch (err) {
|
|
187
|
+
return { ok: false, detail: err.message };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
spawnSync('systemctl', ['--user', 'daemon-reload'], { stdio: 'ignore' });
|
|
191
|
+
const res = spawnSync('systemctl', ['--user', 'enable', 'ai-helper-agent'], { encoding: 'utf-8' });
|
|
192
|
+
if (res.error) return { ok: false, detail: res.error.message };
|
|
193
|
+
if (res.status !== 0) return { ok: false, detail: (res.stderr || res.stdout || '').trim() };
|
|
194
|
+
return { ok: true };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function disableLinux() {
|
|
198
|
+
spawnSync('systemctl', ['--user', 'disable', 'ai-helper-agent'], { stdio: 'ignore' });
|
|
199
|
+
try {
|
|
200
|
+
if (existsSync(SYSTEMD_SERVICE)) unlinkSync(SYSTEMD_SERVICE);
|
|
201
|
+
} catch (err) {
|
|
202
|
+
return { ok: false, detail: err.message };
|
|
203
|
+
}
|
|
204
|
+
spawnSync('systemctl', ['--user', 'daemon-reload'], { stdio: 'ignore' });
|
|
205
|
+
return { ok: true };
|
|
206
|
+
}
|
package/src/locales/cli.json
CHANGED
|
@@ -93,7 +93,10 @@
|
|
|
93
93
|
"uninstallAutostartRemoved": "已移除开机自启",
|
|
94
94
|
"uninstallComplete": "✅ 卸载完成。用户数据已保留在 {dataDir}",
|
|
95
95
|
"autostartDisabled": "开机自启已关闭",
|
|
96
|
-
"
|
|
96
|
+
"autostartEnabled": "已设置开机自启(用户登录时自动运行)",
|
|
97
|
+
"autostartEnableFailed": "设置开机自启失败",
|
|
98
|
+
"autostartDisableFailed": "关闭开机自启失败",
|
|
99
|
+
"autostartUsage": "用法: aha autostart <on|off>",
|
|
97
100
|
"restartHelper": {
|
|
98
101
|
"waitingOldExit": "等待老进程 {pid} 退出...",
|
|
99
102
|
"waitOldTimeout": "等待老进程退出超时,尝试强制终止...",
|
|
@@ -198,7 +201,10 @@
|
|
|
198
201
|
"uninstallAutostartRemoved": "Auto-start removed",
|
|
199
202
|
"uninstallComplete": "✅ Uninstall complete. User data kept at {dataDir}",
|
|
200
203
|
"autostartDisabled": "Auto-start disabled",
|
|
201
|
-
"
|
|
204
|
+
"autostartEnabled": "Auto-start enabled (runs at user login)",
|
|
205
|
+
"autostartEnableFailed": "Failed to enable auto-start",
|
|
206
|
+
"autostartDisableFailed": "Failed to disable auto-start",
|
|
207
|
+
"autostartUsage": "Usage: aha autostart <on|off>",
|
|
202
208
|
"restartHelper": {
|
|
203
209
|
"waitingOldExit": "Waiting for old process {pid} to exit...",
|
|
204
210
|
"waitOldTimeout": "Wait for old process exit timeout, trying force kill...",
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/workspace-manager-DfSFPqwp.js","assets/chunk-CMxvf4Kt.js","assets/session-store-xr0nYACs.js","assets/model-profiles-D31rvEiY.js","assets/i18n-DQnIL9xy.js","assets/side_panel.js","assets/version-CHQCdVOZ.js","assets/voice-shortcut-Dtt3nhkz.js","assets/agent-store-1fyaAv9T.js","assets/utils-DVhZvlZX.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{a as e,c as t,l as n}from"./i18n-DQnIL9xy.js";import{N as r}from"./session-store-xr0nYACs.js";import{l as i}from"./version-CHQCdVOZ.js";import{a,c as o,w as s}from"./utils-DVhZvlZX.js";function c(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function l(e){if(Array.isArray(e))return e}function u(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function d(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
3
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function f(e,t){return l(e)||u(e,t)||ee(e,t)||d()}function ee(e,t){if(e){if(typeof e==`string`)return c(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(e,t):void 0}}var te=Object.entries,ne=Object.setPrototypeOf,p=Object.isFrozen,m=Object.getPrototypeOf,re=Object.getOwnPropertyDescriptor,h=Object.freeze,g=Object.seal,ie=Object.create,ae=typeof Reflect<`u`&&Reflect,_=ae.apply,v=ae.construct;h||=function(e){return e},g||=function(e){return e},_||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},v||=function(e){return new e(...[...arguments].slice(1))};var oe=E(Array.prototype.forEach),se=E(Array.prototype.lastIndexOf),ce=E(Array.prototype.pop),le=E(Array.prototype.push),ue=E(Array.prototype.splice),y=Array.isArray,de=E(String.prototype.toLowerCase),fe=E(String.prototype.toString),pe=E(String.prototype.match),me=E(String.prototype.replace),he=E(String.prototype.indexOf),ge=E(String.prototype.trim),b=E(Number.prototype.toString),x=E(Boolean.prototype.toString),_e=typeof BigInt>`u`?null:E(BigInt.prototype.toString),ve=typeof Symbol>`u`?null:E(Symbol.prototype.toString),S=E(Object.prototype.hasOwnProperty),C=E(Object.prototype.toString),w=E(RegExp.prototype.test),T=D(TypeError);function E(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return _(e,t,n)}}function D(e){return function(){return v(e,[...arguments])}}function O(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:de;if(ne&&ne(e,null),!y(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(p(t)||(t[r]=e),i=e)}e[i]=!0}return e}function ye(e){for(let t=0;t<e.length;t++)S(e,t)||(e[t]=null);return e}function k(e){let t=ie(null);for(let r of te(e)){var n=f(r,2);let i=n[0],a=n[1];S(e,i)&&(y(a)?t[i]=ye(a):a&&typeof a==`object`&&a.constructor===Object?t[i]=k(a):t[i]=a)}return t}function be(e){switch(typeof e){case`string`:return e;case`number`:return b(e);case`boolean`:return x(e);case`bigint`:return _e?_e(e):`0`;case`symbol`:return ve?ve(e):`Symbol()`;case`undefined`:return C(e);case`function`:case`object`:{if(e===null)return C(e);let t=e,n=A(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:C(e)}return C(e)}default:return C(e)}}function A(e,t){for(;e!==null;){let n=re(e,t);if(n){if(n.get)return E(n.get);if(typeof n.value==`function`)return E(n.value)}e=m(e)}function n(){return null}return n}function xe(e){try{return w(e,``),!0}catch{return!1}}var Se=h(`a.abbr.acronym.address.area.article.aside.audio.b.bdi.bdo.big.blink.blockquote.body.br.button.canvas.caption.center.cite.code.col.colgroup.content.data.datalist.dd.decorator.del.details.dfn.dialog.dir.div.dl.dt.element.em.fieldset.figcaption.figure.font.footer.form.h1.h2.h3.h4.h5.h6.head.header.hgroup.hr.html.i.img.input.ins.kbd.label.legend.li.main.map.mark.marquee.menu.menuitem.meter.nav.nobr.ol.optgroup.option.output.p.picture.pre.progress.q.rp.rt.ruby.s.samp.search.section.select.shadow.slot.small.source.spacer.span.strike.strong.style.sub.summary.sup.table.tbody.td.template.textarea.tfoot.th.thead.time.tr.track.tt.u.ul.var.video.wbr`.split(`.`)),Ce=h(`svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.enterkeyhint.exportparts.filter.font.g.glyph.glyphref.hkern.image.inputmode.line.lineargradient.marker.mask.metadata.mpath.part.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),we=h([`feBlend`,`feColorMatrix`,`feComponentTransfer`,`feComposite`,`feConvolveMatrix`,`feDiffuseLighting`,`feDisplacementMap`,`feDistantLight`,`feDropShadow`,`feFlood`,`feFuncA`,`feFuncB`,`feFuncG`,`feFuncR`,`feGaussianBlur`,`feImage`,`feMerge`,`feMergeNode`,`feMorphology`,`feOffset`,`fePointLight`,`feSpecularLighting`,`feSpotLight`,`feTile`,`feTurbulence`]),Te=h([`animate`,`color-profile`,`cursor`,`discard`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`foreignobject`,`hatch`,`hatchpath`,`mesh`,`meshgradient`,`meshpatch`,`meshrow`,`missing-glyph`,`script`,`set`,`solidcolor`,`unknown`,`use`]),Ee=h(`math.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mmultiscripts.mn.mo.mover.mpadded.mphantom.mroot.mrow.ms.mspace.msqrt.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.mprescripts`.split(`.`)),De=h([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),Oe=h([`#text`]),ke=h(`accept.action.align.alt.autocapitalize.autocomplete.autopictureinpicture.autoplay.background.bgcolor.border.capture.cellpadding.cellspacing.checked.cite.class.clear.color.cols.colspan.command.commandfor.controls.controlslist.coords.crossorigin.datetime.decoding.default.dir.disabled.disablepictureinpicture.disableremoteplayback.download.draggable.enctype.enterkeyhint.exportparts.face.for.headers.height.hidden.high.href.hreflang.id.inert.inputmode.integrity.ismap.kind.label.lang.list.loading.loop.low.max.maxlength.media.method.min.minlength.multiple.muted.name.nonce.noshade.novalidate.nowrap.open.optimum.part.pattern.placeholder.playsinline.popover.popovertarget.popovertargetaction.poster.preload.pubdate.radiogroup.readonly.rel.required.rev.reversed.role.rows.rowspan.spellcheck.scope.selected.shape.size.sizes.slot.span.srclang.start.src.srcset.step.style.summary.tabindex.title.translate.type.usemap.valign.value.width.wrap.xmlns`.split(`.`)),Ae=h(`accent-height.accumulate.additive.alignment-baseline.amplitude.ascent.attributename.attributetype.azimuth.basefrequency.baseline-shift.begin.bias.by.class.clip.clippathunits.clip-path.clip-rule.color.color-interpolation.color-interpolation-filters.color-profile.color-rendering.cx.cy.d.dx.dy.diffuseconstant.direction.display.divisor.dominant-baseline.dur.edgemode.elevation.end.exponent.fill.fill-opacity.fill-rule.filter.filterunits.flood-color.flood-opacity.font-family.font-size.font-size-adjust.font-stretch.font-style.font-variant.font-weight.fx.fy.g1.g2.glyph-name.glyphref.gradientunits.gradienttransform.height.href.id.image-rendering.in.in2.intercept.k.k1.k2.k3.k4.kerning.keypoints.keysplines.keytimes.lang.lengthadjust.letter-spacing.kernelmatrix.kernelunitlength.lighting-color.local.marker-end.marker-mid.marker-start.markerheight.markerunits.markerwidth.maskcontentunits.maskunits.max.mask.mask-type.media.method.mode.min.name.numoctaves.offset.operator.opacity.order.orient.orientation.origin.overflow.paint-order.path.pathlength.patterncontentunits.patterntransform.patternunits.points.preservealpha.preserveaspectratio.primitiveunits.r.rx.ry.radius.refx.refy.repeatcount.repeatdur.restart.result.rotate.scale.seed.shape-rendering.slope.specularconstant.specularexponent.spreadmethod.startoffset.stddeviation.stitchtiles.stop-color.stop-opacity.stroke-dasharray.stroke-dashoffset.stroke-linecap.stroke-linejoin.stroke-miterlimit.stroke-opacity.stroke.stroke-width.style.surfacescale.systemlanguage.tabindex.tablevalues.targetx.targety.transform.transform-origin.text-anchor.text-decoration.text-orientation.text-rendering.textlength.type.u1.u2.unicode.values.viewbox.visibility.version.vert-adv-y.vert-origin-x.vert-origin-y.width.word-spacing.wrap.writing-mode.xchannelselector.ychannelselector.x.x1.x2.xmlns.y.y1.y2.z.zoomandpan`.split(`.`)),je=h(`accent.accentunder.align.bevelled.close.columnalign.columnlines.columnspacing.columnspan.denomalign.depth.dir.display.displaystyle.encoding.fence.frame.height.href.id.largeop.length.linethickness.lquote.lspace.mathbackground.mathcolor.mathsize.mathvariant.maxsize.minsize.movablelimits.notation.numalign.open.rowalign.rowlines.rowspacing.rowspan.rspace.rquote.scriptlevel.scriptminsize.scriptsizemultiplier.selection.separator.separators.stretchy.subscriptshift.supscriptshift.symmetric.voffset.width.xmlns`.split(`.`)),Me=h([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),Ne=g(/{{[\w\W]*|^[\w\W]*}}/g),Pe=g(/<%[\w\W]*|^[\w\W]*%>/g),Fe=g(/\${[\w\W]*/g),Ie=g(/^data-[\-\w.\u00B7-\uFFFF]+$/),Le=g(/^aria-[\-\w]+$/),Re=g(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),ze=g(/^(?:\w+script|data):/i),Be=g(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ve=g(/^html$/i),He=g(/^[a-z][.\w]*(-[.\w]+)+$/i),Ue=g(/<[/\w!]/g),We=g(/<[/\w]/g),Ge=g(/<\/no(script|embed|frames)/i),Ke=g(/\/>/i),j={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},qe=function(){return typeof window>`u`?null:window},Je=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},Ye=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},M=function(e,t,n,r){return S(e,t)&&y(e[t])?O(r.base?k(r.base):{},e[t],r.transform):n};function Xe(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:qe(),t=e=>Xe(e);if(t.version=`3.4.12`,t.removed=[],!e||!e.document||e.document.nodeType!==j.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=A(d,`cloneNode`),ee=A(d,`remove`),ne=A(d,`nextSibling`),p=A(d,`childNodes`),m=A(d,`parentNode`),re=A(d,`shadowRoot`),ae=A(d,`attributes`),_=o&&o.prototype?A(o.prototype,`nodeType`):null,v=o&&o.prototype?A(o.prototype,`nodeName`):null;if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let b,x=``,_e,ve=!1,C=0,E=function(){if(C>0)throw T(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},D=function(e){E(),C++;try{return b.createHTML(e)}finally{C--}},ye=function(e){E(),C++;try{return b.createScriptURL(e)}finally{C--}},Ze=function(){return ve||=(_e=Je(u,i),!0),_e},N=n,Qe=N.implementation,$e=N.createNodeIterator,et=N.createDocumentFragment,tt=N.getElementsByTagName,nt=r.importNode,P=Ye();t.isSupported=typeof te==`function`&&typeof m==`function`&&Qe&&Qe.createHTMLDocument!==void 0;let rt=Ne,it=Pe,at=Fe,ot=Ie,st=Le,ct=ze,lt=Be,ut=He,dt=Re,F=null,ft=O({},[...Se,...Ce,...we,...Ee,...Oe]),I=null,L=O({},[...ke,...Ae,...je,...Me]),R=Object.seal(ie(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),z=null,pt=null,B=Object.seal(ie(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),mt=!0,ht=!0,gt=!1,_t=!0,V=!1,H=!0,U=!1,vt=!1,yt=null,bt=null,xt=!1,W=!1,St=!1,Ct=!1,wt=!0,Tt=!1,Et=`user-content-`,Dt=!0,Ot=!1,G={},K=null,kt=O({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),At=null,jt=O({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Mt=null,Nt=O({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Pt=`http://www.w3.org/1998/Math/MathML`,q=`http://www.w3.org/2000/svg`,J=`http://www.w3.org/1999/xhtml`,Y=J,Ft=!1,It=null,Lt=O({},[Pt,q,J],fe),Rt=h([`mi`,`mo`,`mn`,`ms`,`mtext`]),zt=O({},Rt),Bt=h([`annotation-xml`]),Vt=O({},Bt),Ht=O({},[`title`,`style`,`font`,`a`,`script`]),Ut=null,Wt=[`application/xhtml+xml`,`text/html`],X=null,Gt=null,Kt=n.createElement(`form`),qt=function(e){return e instanceof RegExp||e instanceof Function},Jt=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Gt&&Gt===e)return;(!e||typeof e!=`object`)&&(e={}),e=k(e),Ut=Wt.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,X=Ut===`application/xhtml+xml`?fe:de,F=M(e,`ALLOWED_TAGS`,ft,{transform:X}),I=M(e,`ALLOWED_ATTR`,L,{transform:X}),It=M(e,`ALLOWED_NAMESPACES`,Lt,{transform:fe}),Mt=M(e,`ADD_URI_SAFE_ATTR`,Nt,{transform:X,base:Nt}),At=M(e,`ADD_DATA_URI_TAGS`,jt,{transform:X,base:jt}),K=M(e,`FORBID_CONTENTS`,kt,{transform:X}),z=M(e,`FORBID_TAGS`,k({}),{transform:X}),pt=M(e,`FORBID_ATTR`,k({}),{transform:X}),G=S(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?k(e.USE_PROFILES):e.USE_PROFILES:!1,mt=e.ALLOW_ARIA_ATTR!==!1,ht=e.ALLOW_DATA_ATTR!==!1,gt=e.ALLOW_UNKNOWN_PROTOCOLS||!1,_t=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,V=e.SAFE_FOR_TEMPLATES||!1,H=e.SAFE_FOR_XML!==!1,U=e.WHOLE_DOCUMENT||!1,W=e.RETURN_DOM||!1,St=e.RETURN_DOM_FRAGMENT||!1,Ct=e.RETURN_TRUSTED_TYPE||!1,xt=e.FORCE_BODY||!1,wt=e.SANITIZE_DOM!==!1,Tt=e.SANITIZE_NAMED_PROPS||!1,Dt=e.KEEP_CONTENT!==!1,Ot=e.IN_PLACE||!1,dt=xe(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:Re,Y=typeof e.NAMESPACE==`string`?e.NAMESPACE:J,zt=S(e,`MATHML_TEXT_INTEGRATION_POINTS`)&&e.MATHML_TEXT_INTEGRATION_POINTS&&typeof e.MATHML_TEXT_INTEGRATION_POINTS==`object`?k(e.MATHML_TEXT_INTEGRATION_POINTS):O({},Rt),Vt=S(e,`HTML_INTEGRATION_POINTS`)&&e.HTML_INTEGRATION_POINTS&&typeof e.HTML_INTEGRATION_POINTS==`object`?k(e.HTML_INTEGRATION_POINTS):O({},Bt);let t=S(e,`CUSTOM_ELEMENT_HANDLING`)&&e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING==`object`?k(e.CUSTOM_ELEMENT_HANDLING):ie(null);if(R=ie(null),S(t,`tagNameCheck`)&&qt(t.tagNameCheck)&&(R.tagNameCheck=t.tagNameCheck),S(t,`attributeNameCheck`)&&qt(t.attributeNameCheck)&&(R.attributeNameCheck=t.attributeNameCheck),S(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(R.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),g(R),V&&(ht=!1),St&&(W=!0),G&&(F=O({},Oe),I=ie(null),G.html===!0&&(O(F,Se),O(I,ke)),G.svg===!0&&(O(F,Ce),O(I,Ae),O(I,Me)),G.svgFilters===!0&&(O(F,we),O(I,Ae),O(I,Me)),G.mathMl===!0&&(O(F,Ee),O(I,je),O(I,Me))),B.tagCheck=null,B.attributeCheck=null,S(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?B.tagCheck=e.ADD_TAGS:y(e.ADD_TAGS)&&(F===ft&&(F=k(F)),O(F,e.ADD_TAGS,X))),S(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?B.attributeCheck=e.ADD_ATTR:y(e.ADD_ATTR)&&(I===L&&(I=k(I)),O(I,e.ADD_ATTR,X))),S(e,`ADD_URI_SAFE_ATTR`)&&y(e.ADD_URI_SAFE_ATTR)&&O(Mt,e.ADD_URI_SAFE_ATTR,X),S(e,`FORBID_CONTENTS`)&&y(e.FORBID_CONTENTS)&&(K===kt&&(K=k(K)),O(K,e.FORBID_CONTENTS,X)),S(e,`ADD_FORBID_CONTENTS`)&&y(e.ADD_FORBID_CONTENTS)&&(K===kt&&(K=k(K)),O(K,e.ADD_FORBID_CONTENTS,X)),Dt&&(F[`#text`]=!0),U&&O(F,[`html`,`head`,`body`]),F.table&&(O(F,[`tbody`]),delete z.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw T(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw T(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=b;b=e.TRUSTED_TYPES_POLICY;try{x=D(``)}catch(e){throw b=t,e}}else e.TRUSTED_TYPES_POLICY===null?(b=void 0,x=``):(b===void 0&&(b=Ze()),b&&typeof x==`string`&&(x=D(``)));h&&h(e),Gt=e},Yt=O({},[...Ce,...we,...Te]),Xt=O({},[...Ee,...De]),Zt=function(e,t,n){return t.namespaceURI===J?e===`svg`:t.namespaceURI===Pt?e===`svg`&&(n===`annotation-xml`||zt[n]):!!Yt[e]},Qt=function(e,t,n){return t.namespaceURI===J?e===`math`:t.namespaceURI===q?e===`math`&&Vt[n]:!!Xt[e]},$t=function(e,t,n){return t.namespaceURI===q&&!Vt[n]||t.namespaceURI===Pt&&!zt[n]?!1:!Xt[e]&&(Ht[e]||!Yt[e])},en=function(e){let t=m(e);(!t||!t.tagName)&&(t={namespaceURI:Y,tagName:`template`});let n=de(e.tagName),r=de(t.tagName);return It[e.namespaceURI]?e.namespaceURI===q?Zt(n,t,r):e.namespaceURI===Pt?Qt(n,t,r):e.namespaceURI===J?$t(n,t,r):!!(Ut===`application/xhtml+xml`&&It[e.namespaceURI]):!1},Z=function(e){le(t.removed,{element:e});try{m(e).removeChild(e)}catch{if(ee(e),!m(e))throw T(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},tn=function(e){rn(e);let t=p(e);if(t){let e=[];oe(t,t=>{le(e,t)}),oe(e,e=>{try{ee(e)}catch{}})}let n=ae(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;if(typeof i==`string`)try{e.removeAttribute(i)}catch{}}},Q=function(e,n){try{le(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{le(t.removed,{attribute:null,from:n})}if(n.removeAttribute(e),e===`is`)if(W||St)try{Z(n)}catch{}else try{n.setAttribute(e,``)}catch{}},nn=function(e){let t=ae(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;if(!(typeof i!=`string`||I[X(i)]))try{e.removeAttribute(i)}catch{}}},rn=function(e){let t=[e];for(;t.length>0;){let e=t.pop();(_?_(e):e.nodeType)===j.element&&nn(e);let n=p(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},an=function(e){if(!H)return;let t=[e];for(;t.length>0;){let e=t.pop(),n=_?_(e):e.nodeType;if(n===j.processingInstruction||n===j.comment&&w(We,e.data)){try{ee(e)}catch{}continue}if(n===j.element){let t=e,n=X(v?v(e):e.nodeName);try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&n!==`label`&&n!==`output`&&t.removeAttribute(`for`)}catch{}}let r=p(e);if(r)for(let e=r.length-1;e>=0;--e)t.push(r[e])}},on=function(e){let t=null,r=null;if(xt)e=`<remove></remove>`+e;else{let t=pe(e,/^[\r\n\t ]+/);r=t&&t[0]}Ut===`application/xhtml+xml`&&Y===J&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=b?D(e):e;if(Y===J)try{t=new l().parseFromString(i,Ut)}catch{}if(!t||!t.documentElement){t=Qe.createDocument(Y,`template`,null);try{t.documentElement.innerHTML=Ft?x:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),Y===J?tt.call(t,U?`html`:`body`)[0]:U?t.documentElement:a},sn=function(e){return $e.call(e.ownerDocument||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},cn=function(e){return e=me(e,rt,` `),e=me(e,it,` `),e=me(e,at,` `),e},ln=function(e){e.normalize();let t=$e.call(e.ownerDocument||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),n=t.nextNode();for(;n;)n.data=cn(n.data),n=t.nextNode();let r=e.querySelectorAll?.call(e,`template`);r&&oe(r,e=>{dn(e.content)&&ln(e.content)})},un=function(e){let t=v?v(e):null;return typeof t!=`string`||X(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==ae(e)||typeof e.removeAttribute!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==_(e)||e.childNodes!==p(e)},dn=function(e){if(!_||typeof e!=`object`||!e)return!1;try{return _(e)===j.documentFragment}catch{return!1}},fn=function(e){if(!_||typeof e!=`object`||!e)return!1;try{return typeof _(e)==`number`}catch{return!1}};function $(e,n,r){e.length!==0&&oe(e,e=>{e.call(t,n,r,Gt)})}let pn=function(e,t){return!!(H&&e.hasChildNodes()&&!fn(e.firstElementChild)&&w(Ue,e.textContent)&&w(Ue,e.innerHTML)||H&&e.namespaceURI===J&&t===`style`&&fn(e.firstElementChild)||e.nodeType===j.processingInstruction||H&&e.nodeType===j.comment&&w(We,e.data))},mn=function(e,t){if(!z[t]&&vn(t)&&(R.tagNameCheck instanceof RegExp&&w(R.tagNameCheck,t)||R.tagNameCheck instanceof Function&&R.tagNameCheck(t)))return!1;if(Dt&&!K[t]){let t=m(e),n=p(e);if(n&&t){let r=n.length;for(let i=r-1;i>=0;--i){let r=Ot?n[i]:f(n[i],!0);t.insertBefore(r,ne(e))}}}return Z(e),!0},hn=function(e,n){if($(P.beforeSanitizeElements,e,null),e!==n&&m(e)===null)return!0;if(un(e))return Z(e),!0;let r=X(v?v(e):e.nodeName);if($(P.uponSanitizeElement,e,{tagName:r,allowedTags:F}),e!==n&&m(e)===null)return!0;if(pn(e,r))return Z(e),!0;if(z[r]||!(B.tagCheck instanceof Function&&B.tagCheck(r))&&!F[r]){let t=mn(e,r);return t===!1&&$(P.afterSanitizeElements,e,null),t}if((_?_(e):e.nodeType)===j.element&&!en(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&w(Ge,e.innerHTML))return Z(e),!0;if(V&&e.nodeType===j.text){let n=cn(e.textContent);e.textContent!==n&&(le(t.removed,{element:e.cloneNode()}),e.textContent=n)}return $(P.afterSanitizeElements,e,null),!1},gn=function(e,t,r){if(pt[t]||H&&t===`patchsrc`||H&&t===`for`&&e!==`label`&&e!==`output`||wt&&(t===`id`||t===`name`)&&(r in n||r in Kt))return!1;let i=I[t]||B.attributeCheck instanceof Function&&B.attributeCheck(t,e);if(!(ht&&w(ot,t))&&!(mt&&w(st,t))){if(!i){if(!(vn(e)&&(R.tagNameCheck instanceof RegExp&&w(R.tagNameCheck,e)||R.tagNameCheck instanceof Function&&R.tagNameCheck(e))&&(R.attributeNameCheck instanceof RegExp&&w(R.attributeNameCheck,t)||R.attributeNameCheck instanceof Function&&R.attributeNameCheck(t,e))||t===`is`&&R.allowCustomizedBuiltInElements&&(R.tagNameCheck instanceof RegExp&&w(R.tagNameCheck,r)||R.tagNameCheck instanceof Function&&R.tagNameCheck(r))))return!1}else if(!Mt[t]&&!w(dt,me(r,lt,``))&&!((t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&he(r,`data:`)===0&&At[e])&&!(gt&&!w(ct,me(r,lt,``)))&&r)return!1}return!0},_n=O({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),vn=function(e){return!_n[de(e)]&&w(ut,e)},yn=function(e,t,n,r){if(b&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return D(r);case`TrustedScriptURL`:return ye(r)}return r},bn=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),un(e)?Z(e):ce(t.removed)}catch{Q(n,e)}},xn=function(e){$(P.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||un(e))return;let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:I,forceKeepAttr:void 0},r=t.length,i=X(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=X(o),u=c,d=o===`value`?u:ge(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,$(P.uponSanitizeAttribute,e,n),d=n.attrValue,Tt&&(l===`id`||l===`name`)&&he(d,Et)!==0&&(Q(o,e),d=Et+d),H&&w(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){Q(o,e);continue}if(l===`attributename`&&pe(d,`href`)){Q(o,e);continue}if(!n.forceKeepAttr){if(!n.keepAttr){Q(o,e);continue}if(!_t&&w(Ke,d)){Q(o,e);continue}if(V&&(d=cn(d)),!gn(i,l,d)){Q(o,e);continue}d=yn(i,l,s,d),d!==u&&bn(e,o,s,d)}}$(P.afterSanitizeAttributes,e,null)},Sn=function(e){let t=null,n=sn(e);for($(P.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if($(P.uponSanitizeShadowNode,t,null),hn(t,e),xn(t),dn(t.content)&&Sn(t.content),(_?_(t):t.nodeType)===j.element){let e=re(t);dn(e)&&(Cn(e),Sn(e))}$(P.afterSanitizeShadowDOM,e,null)},Cn=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){Sn(e.shadow);continue}let n=e.node,r=(_?_(n):n.nodeType)===j.element,i=p(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=v?v(n):null;if(typeof e==`string`&&X(e)===`template`){let e=n.content;dn(e)&&t.push({node:e,shadow:null})}}if(r){let e=re(n);dn(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(Ft=!e,Ft&&(e=`<!-->`),typeof e!=`string`&&!fn(e)&&(e=be(e),typeof e!=`string`))throw T(`dirty is not a string, aborting`);if(!t.isSupported)return e;vt?(F=yt,I=bt):Jt(n),(P.uponSanitizeElement.length>0||P.uponSanitizeAttribute.length>0)&&(F=k(F)),P.uponSanitizeAttribute.length>0&&(I=k(I)),t.removed=[];let c=Ot&&typeof e!=`string`&&fn(e);if(c){an(e);let t=v?v(e):e.nodeName;if(typeof t==`string`){let n=X(t);if(!F[n]||z[n])throw tn(e),T(`root node is forbidden and cannot be sanitized in-place`)}if(un(e))throw tn(e),T(`root node is clobbered and cannot be sanitized in-place`);try{Cn(e)}catch(t){throw tn(e),t}}else if(fn(e))i=on(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===j.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Cn(a);else{if(!W&&!V&&!U&&e.indexOf(`<`)===-1)return b&&Ct?D(e):e;if(i=on(e),!i)return W?null:Ct?x:``}i&&xt&&Z(i.firstChild);let l=c?e:i,u=sn(l);try{for(;o=u.nextNode();)hn(o,l),xn(o),dn(o.content)&&Sn(o.content)}catch(n){throw c&&(tn(e),oe(t.removed,e=>{e.element&&rn(e.element)})),n}if(c)return oe(t.removed,e=>{e.element&&rn(e.element)}),V&&ln(e),e;if(W){if(V&&ln(i),St)for(s=et.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(I.shadowroot||I.shadowrootmode)&&(s=nt.call(r,s,!0)),s}let d=U?i.outerHTML:i.innerHTML;return U&&F[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&w(Ve,i.ownerDocument.doctype.name)&&(d=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
|
|
4
|
-
`+d),V&&(d=cn(d)),b&&Ct?D(d):d},t.setConfig=function(){Jt(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}),vt=!0,yt=F,bt=I},t.clearConfig=function(){Gt=null,vt=!1,yt=null,bt=null,b=_e,x=``},t.isValidAttribute=function(e,t,n){return Gt||Jt({}),gn(X(e),X(t),n)},t.addHook=function(e,t){typeof t==`function`&&S(P,e)&&le(P[e],t)},t.removeHook=function(e,t){if(S(P,e)){if(t!==void 0){let n=se(P[e],t);return n===-1?void 0:ue(P[e],n,1)[0]}return ce(P[e])}},t.removeHooks=function(e){S(P,e)&&(P[e]=[])},t.removeAllHooks=function(){P=Ye()},t}var Ze=Xe(),N=null,Qe=null,$e=null;function et(e){return{startOnLoad:!1,theme:(e||i())===`dark`?`dark`:`default`,securityLevel:`loose`,fontFamily:`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`}}function tt(e){return new Promise((t,n)=>{if(document.querySelector(`script[src="${e}"]`)){t();return}let r=document.createElement(`script`);r.src=e,r.onload=t,r.onerror=()=>n(Error(`Failed to load script: ${e}`)),document.head.appendChild(r)})}function nt(){return window.mermaid===void 0?(N||=tt(`libs/mermaid.min.js`).then(()=>(window.mermaid!==void 0&&window.mermaid.initialize(et()),window.mermaid)).catch(e=>{throw N=null,e}),N):Promise.resolve(window.mermaid)}function P(){return window.jspdf&&window.jspdf.jsPDF?Promise.resolve(window.jspdf.jsPDF):(Qe||=tt(`libs/jspdf.min.js`).then(()=>{let e=window.jspdf&&window.jspdf.jsPDF;if(!e)throw Error(`jsPDF not available after loading`);return e}).catch(e=>{throw Qe=null,e}),Qe)}function rt(){return window.html2canvas?Promise.resolve(window.html2canvas):($e||=tt(`libs/html2canvas.min.js`).then(()=>{if(!window.html2canvas)throw Error(`html2canvas not available after loading`);return window.html2canvas}).catch(e=>{throw $e=null,e}),$e)}async function it(){let[e,t]=await Promise.all([P(),rt()]);return{jsPDF:e,html2canvas:t}}e(`zh`,{chat:{fileLinkTitle:`点击在工作目录中定位该文件`,fileLinkFailed:`定位文件失败`},markdown:{copyCode:`复制代码`,copyMdTableTitle:`复制 Markdown 表格
|
|
5
|
-
按住 Ctrl/⌘ 点击复制富文本表格`,downloadExcel:`下载 Excel`,exportTableImage:`导出表格为图片`,downloadFailed:`下载失败: {message}`,unknownError:`未知错误`,chartRenderFailed:`图表渲染失败: {detail}`,zoomIn:`放大`,zoomOut:`缩小`,reset:`重置`,copyToClipboard:`复制到剪贴板`,downloadImage:`下载图片`,viewSource:`查看源代码`,mermaidCopied:`Mermaid 图表已复制到剪贴板!`,autoDownloadChart:`已自动转为下载方式保存图表`,copyFailed:`复制失败: {message}`,copySourceTitle:`复制源代码`,backToChart:`返回图表`,codeBlockLabel:`代码块`,codeLabel:`代码`,copiedToClipboard:`{label}已复制到剪贴板`,codeCopied:`代码已复制到剪贴板`,copiedRichTable:`已复制富文本表格`,copyRichTableFailed:`复制富文本表格失败`,copyFailedShort:`复制失败`,copiedMdTable:`已复制 Markdown 表格`,imageExportLibMissing:`图片导出库未加载`,tableImageExported:`表格图片已导出`,exportImageFailed:`导出图片失败`,canvasExportFailed:`Canvas toDataURL 失败,无法导出图片`,svgLoadFailed:`SVG 图片加载失败: {message}`}}),e(`en`,{chat:{fileLinkTitle:`Click to locate this file in the working directory`,fileLinkFailed:`Failed to locate file`},markdown:{copyCode:`Copy code`,copyMdTableTitle:`Copy Markdown table
|
|
6
|
-
Ctrl/Cmd+click to copy rich-text table`,downloadExcel:`Download Excel`,exportTableImage:`Export table as image`,downloadFailed:`Download failed: {message}`,unknownError:`Unknown error`,chartRenderFailed:`Chart rendering failed: {detail}`,zoomIn:`Zoom in`,zoomOut:`Zoom out`,reset:`Reset`,copyToClipboard:`Copy to clipboard`,downloadImage:`Download image`,viewSource:`View source`,mermaidCopied:`Mermaid chart copied to clipboard!`,autoDownloadChart:`Automatically switched to download to save the chart`,copyFailed:`Copy failed: {message}`,copySourceTitle:`Copy source code`,backToChart:`Back to chart`,codeBlockLabel:`Code block`,codeLabel:`Code`,copiedToClipboard:`{label} copied to clipboard`,codeCopied:`Code copied to clipboard`,copiedRichTable:`Rich-text table copied`,copyRichTableFailed:`Failed to copy rich-text table`,copyFailedShort:`Copy failed`,copiedMdTable:`Markdown table copied`,imageExportLibMissing:`Image export library not loaded`,tableImageExported:`Table image exported`,exportImageFailed:`Failed to export image`,canvasExportFailed:`Canvas toDataURL failed, unable to export image`,svgLoadFailed:`SVG image load failed: {message}`}});var at=2e3;function ot(e){let t=e.closest(`.mermaid`);if(!t)return!1;let n=t.getAttribute(`data-raw-code`);if(!n)return!1;try{let e=decodeURIComponent(n);return/^\s*classDiagram/im.test(e)}catch{return!1}}function st(e){e.querySelectorAll(`foreignObject`).forEach(e=>{let t=e.querySelector(`div`);if(!t){e.remove();return}let n=t.querySelector(`span`),r=(n||t).textContent.trim();if(!r){e.remove();return}let i=parseFloat(e.getAttribute(`width`))||100,a=parseFloat(e.getAttribute(`height`))||30,o=e.getAttribute(`transform`),s=document.createElementNS(`http://www.w3.org/2000/svg`,`text`);s.setAttribute(`x`,String(i/2)),s.setAttribute(`y`,String(a/2)),s.setAttribute(`text-anchor`,`middle`),s.setAttribute(`dominant-baseline`,`central`),o&&s.setAttribute(`transform`,o);let c=n?n.getAttribute(`class`):``;c&&s.setAttribute(`class`,c),s.textContent=r,e.parentNode.replaceChild(s,e)})}function ct(e){let t=e.cloneNode(!0),n=document.createElement(`div`);return n.style.cssText=`position:absolute;visibility:hidden;width:0;height:0;overflow:hidden;`,n.appendChild(t),document.body.appendChild(n),ot(e)?st(t):t.querySelectorAll(`foreignObject`).forEach(e=>{let t=e.querySelector(`div`);if(!t){e.remove();return}let n=document.createElementNS(`http://www.w3.org/2000/svg`,`text`),r=parseFloat(e.getAttribute(`x`))||0,i=parseFloat(e.getAttribute(`y`))||0,a=parseFloat(e.getAttribute(`width`))||100,o=parseFloat(e.getAttribute(`height`))||30,s=t.querySelector(`span`)||t,c=window.getComputedStyle(s);n.textContent=s.textContent.trim(),n.setAttribute(`x`,String(r+a/2)),n.setAttribute(`y`,String(i+o/2)),n.setAttribute(`text-anchor`,`middle`),n.setAttribute(`dominant-baseline`,`central`),n.setAttribute(`fill`,c.color||`#333`),n.setAttribute(`font-family`,c.fontFamily||`sans-serif`),n.setAttribute(`font-size`,c.fontSize||`14px`),(c.fontWeight===`bold`||parseInt(c.fontWeight)>=600)&&n.setAttribute(`font-weight`,`bold`),e.parentNode.replaceChild(n,e)}),t.querySelectorAll(`image`).forEach(e=>{let t=e.getAttribute(`href`)||e.getAttributeNS(`http://www.w3.org/1999/xlink`,`href`)||``;/^https?:/i.test(t)&&e.remove()}),t.querySelectorAll(`use`).forEach(e=>{let t=e.getAttribute(`href`)||e.getAttributeNS(`http://www.w3.org/1999/xlink`,`href`)||``;/^https?:/i.test(t)&&e.remove()}),document.body.removeChild(n),t}function lt(e){let t=e.getAttribute(`viewBox`);if(t){let e=t.split(/[\s,]+/).map(parseFloat);if(e.length===4&&!isNaN(e[2])&&!isNaN(e[3])&&e[2]>0&&e[3]>0)return{width:e[2],height:e[3]}}let n=parseFloat(e.getAttribute(`width`)),r=parseFloat(e.getAttribute(`height`));if(!isNaN(n)&&!isNaN(r)&&n>0&&r>0)return{width:n,height:r};try{let t=e.getBoundingClientRect();if(t.width>0&&t.height>0)return{width:t.width,height:t.height}}catch{}return{width:800,height:600}}function ut(e){try{let t=e.toDataURL(`image/png`);if(t&&t.length>100)return t}catch(e){n.debug(`[SidePanel] PNG toDataURL failed,downgrade to JPEG:`,e.message)}try{let t=e.toDataURL(`image/jpeg`,.92);if(t&&t.length>100)return t}catch(e){n.debug(`[SidePanel] JPEG toDataURL also failed:`,e.message)}throw Error(t(`markdown.canvasExportFailed`))}function dt(e){return new Promise((r,i)=>{try{let{width:a,height:o}=lt(e);n.debug(`[SidePanel] svgToPngDataUrl size:`,a,`x`,o);let s=2;if(a>at||o>at){let e=Math.min(at/a,at/o);a*=e,o*=e,s=1.5}let c=ct(e),l=new XMLSerializer().serializeToString(c),u=`data:image/svg+xml;charset=utf-8,`+encodeURIComponent(l),d=new Image;d.crossOrigin=`anonymous`,d.onload=function(){try{let e=document.createElement(`canvas`);e.width=Math.ceil((a+20)*s),e.height=Math.ceil((o+20)*s),n.debug(`[SidePanel] Canvas size:`,e.width,`x`,e.height);let t=e.getContext(`2d`);t.fillStyle=`#ffffff`,t.fillRect(0,0,e.width,e.height),t.drawImage(d,10*s,10*s,a*s,o*s),r(ut(e))}catch(e){i(e)}},d.onerror=function(e){i(Error(t(`markdown.svgLoadFailed`,{message:String(e?.message||e)})))},d.src=u}catch(e){i(e)}})}function F(e){if(!e)return``;let t=[],n=e.replace(/```[\s\S]*?```/g,e=>(t.push(e),`\u0000F${t.length-1}\u0000`)),r=n.replace(/^[ \t]*\[\[artifact:[^\]]*\]\][ \t]*\n/gm,``).replace(/[ \t]*\[\[artifact:[^\]]*\]\][ \t]*/g,``);return(r===n?n:r.replace(/\n{3,}/g,`
|
|
7
|
-
|
|
8
|
-
`).replace(/^\n+/,``).replace(/\n+$/,``)).replace(/\u0000F(\d+)\u0000/g,(e,n)=>t[Number(n)])}function ft(e){if(!e)return``;e=F(e);let n=[],r=Date.now()+`_`+Math.random().toString(36).slice(2,8);e=e.replace(/```mermaid\n?([\s\S]*?)```/g,(e,t)=>{let r=n.length;return n.push(t.trim()),`%%MERMAID_BLOCK_${r}%%`});let i=[];e=e.replace(/```(\w*)\n?([\s\S]*?)```/g,(e,t,n)=>{let r=i.length;return i.push({language:t||`text`,content:n.trim()}),`%%CODE_BLOCK_${r}%%`});let a=[];e=e.replace(/^(\|.+\|)\n(\|[-| :]+\|)\n((?:\|.+\|\n?)*)/gm,(e,t,n,r)=>{let i=a.length;return a.push({header:t,separator:n,body:r,full:e.trim()}),`\n%%TABLE_BLOCK_${i}%%\n`});let s=``;return typeof marked<`u`?(marked.setOptions({breaks:!0,gfm:!0}),s=marked.parse(e)):s=e.replace(/`([^`]+)`/g,`<code>$1</code>`).replace(/\*\*([^*]+)\*\*/g,`<strong>$1</strong>`).replace(/\*([^*]+)\*/g,`<em>$1</em>`).replace(/\n/g,`<br>`),s=Ze.sanitize(s,{FORBID_TAGS:[`style`,`iframe`,`script`,`object`,`embed`,`svg`],FORBID_ATTR:[`onerror`,`onload`,`onclick`,`onmouseover`,`onfocus`,`onblur`,`onchange`,`oninput`,`onkeydown`,`onkeyup`,`onkeypress`],ADD_ATTR:[`target`]}),n.forEach((e,t)=>{let n=`mermaid-${r}-${t}`;s=s.replace(`%%MERMAID_BLOCK_${t}%%`,`<div class="mermaid" id="${n}" data-raw-code="${encodeURIComponent(e)}">${o(e)}</div>`)}),i.forEach((e,n)=>{let r=e.content.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`);s=s.replace(`%%CODE_BLOCK_${n}%%`,`<div class="code-block-container" style="position: relative;">
|
|
9
|
-
<button class="code-copy-btn" data-code="${n}" title="${t(`markdown.copyCode`)}">
|
|
10
|
-
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
11
|
-
<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"/>
|
|
12
|
-
</svg>
|
|
13
|
-
</button>
|
|
14
|
-
<pre><code class="language-${e.language}">${r}</code></pre>
|
|
15
|
-
</div>`)}),a.forEach((e,t)=>{s=s.replace(`%%TABLE_BLOCK_${t}%%`,R(e))}),s}function I(e){if(!e)return``;let t=e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`);return t=t.replace(/`([^`]+)`/g,`<code>$1</code>`),t=t.replace(/\*\*([^*]+)\*\*/g,`<strong>$1</strong>`),t=t.replace(/\*([^*]+)\*/g,`<em>$1</em>`),t=t.replace(/~~([^~]+)~~/g,`<del>$1</del>`),t}function L(e){let t=[],n=``,r=0;for(;r<e.length;){let i=e[r];if(i===`\\`){let i=0;for(;e[r+i]===`\\`;)i++;e[r+i]===`|`?(n+=`\\`.repeat(Math.floor(i/2)),i%2==1?n+=`|`:(t.push(n),n=``),r+=i+1):(n+=`\\`.repeat(i),r+=i);continue}if(i===`|`){t.push(n),n=``,r++;continue}n+=i,r++}return t.push(n),t}function R(e){let{header:n,body:r,full:i}=e,a=window.__tableBlocks?window.__tableBlocks.length:0;window.__tableBlocks&&(window.__tableBlocks[a]={full:i,header:n,body:r});let o=L(n).slice(1,-1).map(e=>I(e.trim())),s=r.trim().split(`
|
|
16
|
-
`).filter(e=>e.trim()).map(e=>L(e).slice(1,-1).map(e=>I(e.trim()))),c=`<div class="table-container-wrapper"><table>`;return c+=`<thead><tr>`,o.forEach((e,a)=>{a===o.length-1?c+=`<th class="table-header-cell-wrapper">
|
|
17
|
-
${e}
|
|
18
|
-
<div class="table-toolbar">
|
|
19
|
-
<button class="table-toolbar-btn copy-md-btn" title="${t(`markdown.copyMdTableTitle`)}" data-table-full="${encodeURIComponent(i)}">
|
|
20
|
-
<svg viewBox="0 0 16 16" fill="currentColor">
|
|
21
|
-
<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"/>
|
|
22
|
-
</svg>
|
|
23
|
-
</button>
|
|
24
|
-
<button class="table-toolbar-btn download-excel-btn" title="${t(`markdown.downloadExcel`)}" data-table-header="${encodeURIComponent(n)}" data-table-body="${encodeURIComponent(r)}">
|
|
25
|
-
<svg viewBox="0 0 16 16" fill="currentColor">
|
|
26
|
-
<path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/>
|
|
27
|
-
<path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/>
|
|
28
|
-
</svg>
|
|
29
|
-
</button>
|
|
30
|
-
<button class="table-toolbar-btn export-table-img-btn" title="${t(`markdown.exportTableImage`)}">
|
|
31
|
-
<svg viewBox="0 0 16 16" fill="currentColor">
|
|
32
|
-
<path d="M6.002 5.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/>
|
|
33
|
-
<path d="M2.002 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2h-12zm12 1a1 1 0 0 1 1 1v6.5l-3.777-1.947a.5.5 0 0 0-.577.093l-3.71 3.71-2.66-1.772a.5.5 0 0 0-.63.062L1.002 12V3a1 1 0 0 1 1-1h12z"/>
|
|
34
|
-
</svg>
|
|
35
|
-
</button>
|
|
36
|
-
</div>
|
|
37
|
-
</th>`:c+=`<th>${e}</th>`}),c+=`</tr></thead>`,c+=`<tbody>`,s.forEach(e=>{c+=`<tr>`,e.forEach(e=>{c+=`<td>${e}</td>`}),c+=`</tr>`}),c+=`</tbody>`,c+=`</table></div>`,c}function z(e){try{let{header:t,body:r}=e,i=L(t).slice(1,-1).map(e=>e.trim()),a=r.trim().split(`
|
|
38
|
-
`).filter(e=>e.trim()).map(e=>L(e).slice(1,-1).map(e=>e.trim())),o=``;o+=i.map(e=>`"${e.replace(/"/g,`""`)}"`).join(`,`)+`
|
|
39
|
-
`,a.forEach(e=>{o+=e.map(e=>`"${e.replace(/"/g,`""`)}"`).join(`,`)+`
|
|
40
|
-
`});let s=new Blob([o],{type:`text/csv;charset=utf-8;`}),c=document.createElement(`a`),l=URL.createObjectURL(s);c.setAttribute(`href`,l),c.setAttribute(`download`,`table-${Date.now()}.csv`),c.style.visibility=`hidden`,document.body.appendChild(c),c.click(),document.body.removeChild(c),n.debug(`[SidePanel] Excel download successful`)}catch(e){n.error(`[SidePanel] download Excel failed:`,e),s(t(`markdown.downloadFailed`,{message:e.message}),`error`)}}function pt(e){if(!e)return t(`markdown.unknownError`);if(typeof e==`string`)return e;let n=e.message||e.str||e.msg||e.text||``;if(n)return n;try{return JSON.stringify(e)}catch{return String(e)}}var B=2;async function mt(e,t=B){if(e.querySelector(`svg`))return{success:!0};let r=e.getAttribute(`data-raw-code`),i=r?decodeURIComponent(r):e.textContent||``;for(let r=0;r<=t;r++){r>0&&(e.textContent=i);try{return await mermaid.run({nodes:[e]}),{success:!0}}catch(a){let o=pt(a);if(/(Parse error|syntax error|Lexical error|No diagram type detected)/i.test(o)||r>=t)return n.error(`[SidePanel] Mermaid render failed,original content ( before 300chars):`,i.substring(0,300)),e.textContent=i,{success:!1,detail:o,err:a};await new Promise(e=>setTimeout(e,200))}}}async function ht(){let e=document.querySelectorAll(`.mermaid`);if(e.length!==0){try{await nt()}catch(e){n.warn(`[SidePanel] Mermaid lib failed to load:`,e);return}n.debug(`[SidePanel] ===== renderMermaidCharts start =====`),n.debug(`[SidePanel] find to mermaid element count:`,e.length);for(let r=0;r<e.length;r++){let i=e[r],a=await mt(i);a.success?(n.debug(`[SidePanel] `,r+1,` mermaid chart render successful`),V(i)):(n.error(`[SidePanel] `,r+1,` mermaid chart render failed:`,a.detail,a.err),!i.querySelector(`svg`)&&!i.querySelector(`.mermaid-controls`)&&(i.innerHTML=`<div style="color: #856404; background: #fff3cd; padding: 10px; border-radius: 4px; margin: 10px 0;">${t(`markdown.chartRenderFailed`,{detail:a.detail})}</div>`))}n.debug(`[SidePanel] ===== renderMermaidCharts complete =====`)}}async function gt(){if(typeof window>`u`||window.mermaid===void 0)return;let e=document.querySelectorAll(`.mermaid`);if(e.length!==0){window.mermaid.initialize(et());for(let n of e){let e=n.querySelector(`svg`);if(!e)continue;let r=n.getAttribute(`data-raw-code`);if(!r)continue;e.remove();let i=n.querySelector(`.mermaid-controls`);i&&i.remove(),n.removeAttribute(`data-processed`),n.innerHTML=``,n.textContent=decodeURIComponent(r);let a=await mt(n);a.success?V(n):!n.querySelector(`svg`)&&!n.querySelector(`.mermaid-controls`)&&(n.innerHTML=`<div style="color: #856404; background: #fff3cd; padding: 10px; border-radius: 4px; margin: 10px 0;">${t(`markdown.chartRenderFailed`,{detail:a.detail})}</div>`)}}}function _t(e){return e?`<div class="markdown-body">${ft(e)}</div>`:``}function V(e){let r=e.querySelector(`.mermaid-controls`);r&&r.remove();let i=e.querySelector(`svg`);if(!i){n.warn(`[SidePanel] SVG elementnot found,current content:`,e.innerHTML.substring(0,100));return}n.debug(`[SidePanel] find to SVG element,start addingtoolbar`),n.debug(`[SidePanel] container class name:`,e.className),n.debug(`[SidePanel] container HTML:`,e.innerHTML.substring(0,200)),e.style.position=`relative`,e.style.cursor=`grab`,e.style.userSelect=`none`,e.style.webkitUserSelect=`none`;let a=e.querySelector(`.mermaid-svg-wrapper`);if(!a){a=document.createElement(`div`),a.className=`mermaid-svg-wrapper`,a.style.transformOrigin=`center center`,a.style.transition=`transform 0.2s ease`,a.style.display=`inline-block`,a.style.width=`100%`,i.style.maxWidth=`100%`,i.style.height=`auto`,i.style.userSelect=`none`,i.style.webkitUserSelect=`none`,a.appendChild(i),e.insertBefore(a,e.firstChild);let t=[];Array.from(e.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&e.textContent.trim()&&t.push(e)}),t.forEach(e=>e.remove())}let o=document.createElement(`div`);o.className=`mermaid-controls`,o.innerHTML=`
|
|
41
|
-
<button class="zoom-in" title="${t(`markdown.zoomIn`)}">+</button>
|
|
42
|
-
<button class="zoom-out" title="${t(`markdown.zoomOut`)}">−</button>
|
|
43
|
-
<button class="reset-zoom" title="${t(`markdown.reset`)}">↺</button>
|
|
44
|
-
<button class="copy-to-clipboard" title="${t(`markdown.copyToClipboard`)}">
|
|
45
|
-
<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor">
|
|
46
|
-
<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"/>
|
|
47
|
-
</svg>
|
|
48
|
-
</button>
|
|
49
|
-
<button class="download-png" title="${t(`markdown.downloadImage`)}">↓</button>
|
|
50
|
-
<button class="view-source" title="${t(`markdown.viewSource`)}"></></button>
|
|
51
|
-
`,e.appendChild(o),n.debug(`[SidePanel] toolbar HTML added`),n.debug(`[SidePanel] container subelement:`,Array.from(e.children).map(e=>e.className).join(`, `)),e._pngDataUrl||dt(i).then(t=>{e._pngDataUrl=t,e._pngBlob=null}).catch(e=>{n.warn(`[SidePanel] Mermaid PNG pre-convert failed:`,e.message)});let s=1,c=.01,l=.15,u=e.dataset.rawCode||``;if(!u){let e=i.querySelector(`title`);e&&e.textContent&&(u=e.textContent.trim())}if(!u){let e=i.querySelector(`script[type="text/plain"]`);e&&(u=e.textContent.trim())}u&&!e.dataset.rawMermaidCode&&(e.dataset.rawMermaidCode=u),o.querySelector(`.view-source`).addEventListener(`click`,t=>{t.stopPropagation();let n=e.getAttribute(`data-raw-code`);W(e,n?decodeURIComponent(n):e.dataset.rawMermaidCode||``,a,i,s,{MIN_SCALE:c,MAX_SCALE:100,SCALE_STEP:l})}),o.querySelector(`.copy-to-clipboard`).addEventListener(`click`,e=>{e.stopPropagation(),bt(i,a,s)}),o.querySelector(`.download-png`).addEventListener(`click`,e=>{e.stopPropagation(),xt(i,s)}),e.addEventListener(`wheel`,e=>{!e.ctrlKey&&!e.metaKey||(e.preventDefault(),e.stopPropagation(),s=e.deltaY<0?Math.min(100,s+l):Math.max(c,s-l),p())},{passive:!1});let d=!1,f,ee,te=0,ne=0;function p(){a.style.transform=`translate(${te}px, ${ne}px) scale(${s})`}o.querySelector(`.zoom-in`).addEventListener(`click`,e=>{e.stopPropagation(),s=Math.min(100,s+l),p()}),o.querySelector(`.zoom-out`).addEventListener(`click`,e=>{e.stopPropagation(),s=Math.max(c,s-l),p()}),o.querySelector(`.reset-zoom`).addEventListener(`click`,e=>{e.stopPropagation(),s=1,te=0,ne=0,p()}),e.addEventListener(`mousedown`,t=>{t.target.tagName!==`BUTTON`&&(d=!0,f=t.clientX-te,ee=t.clientY-ne,e.style.cursor=`grabbing`)}),document.addEventListener(`mousemove`,e=>{d&&(te=e.clientX-f,ne=e.clientY-ee,p())}),document.addEventListener(`mouseup`,()=>{d&&(d=!1,e.style.cursor=`grab`)})}function H(e){let t=e.match(/^data:([^;]+)/);return t?t[1]:`image/png`}function U(e){let t=H(e).split(`/`)[1];return t===`jpeg`?`jpg`:t||`png`}function vt(e){let t=H(e),n=e.split(`,`)[1]||``,r=atob(n),i=r.length,a=new Uint8Array(i);for(let e=0;e<i;e++)a[e]=r.charCodeAt(e);return new Blob([a],{type:t})}function yt(e,t){let n=U(e),r=t.replace(/\.(png|jpg|jpeg)$/i,``)+`.`+n,i=document.createElement(`a`);i.href=e,i.download=r,document.body.appendChild(i),i.click(),document.body.removeChild(i)}async function bt(e,r,i){try{let r=e.closest(`.mermaid`),i=r&&r._pngDataUrl;i||=await dt(e);let a=vt(i),o=H(i),c=`mermaid-diagram-`+Date.now()+`.png`;if(navigator.clipboard&&typeof ClipboardItem<`u`)try{await navigator.clipboard.write([new ClipboardItem({[o]:a})]),s(t(`markdown.mermaidCopied`),`success`);return}catch(e){n.warn(`[SidePanel] Clipboard API write failed,downgrade to download:`,e.message)}s(t(`markdown.autoDownloadChart`),`warning`),yt(i,c)}catch(e){n.error(`[SidePanel] copyto clipboard failed:`,e),s(t(`markdown.copyFailed`,{message:e.message}),`error`)}}async function xt(e,r){try{let t=e.closest(`.mermaid`),n=t&&t._pngDataUrl,r=`mermaid-diagram-`+Date.now()+`.png`;if(n){yt(n,r);return}yt(await dt(e),r)}catch(e){n.error(`[SidePanel] download PNG failed:`,e),s(t(`markdown.downloadFailed`,{message:e.message}),`error`)}}function W(e,n,r,i,o,s){let c=e.querySelector(`.mermaid-source-view`),l=e.querySelector(`.mermaid-controls`);if(c)c.parentElement&&c.parentElement.remove(),r&&(r.style.display=`inline-block`),e.style.userSelect=`none`,e.style.webkitUserSelect=`none`,e.style.cursor=`grab`,V(e);else{r&&(r.style.display=`none`),l&&l.remove(),e.style.userSelect=`text`,e.style.webkitUserSelect=`text`,e.style.cursor=`auto`;let c=document.createElement(`div`);c.className=`mermaid-container-wrapper`,c.style.position=`relative`;let u=document.createElement(`pre`);u.className=`mermaid-source-view`,u.style.position=`relative`,u.textContent=n;let d=document.createElement(`button`);d.className=`source-copy-btn`,d.title=t(`markdown.copySourceTitle`),d.innerHTML=`
|
|
52
|
-
<svg viewBox="0 0 16 16" fill="currentColor">
|
|
53
|
-
<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"/>
|
|
54
|
-
</svg>
|
|
55
|
-
`,d.addEventListener(`click`,e=>{e.stopPropagation(),a(n,d)});let f=document.createElement(`button`);f.className=`source-copy-btn`,f.style.right=`44px`,f.title=t(`markdown.backToChart`),f.innerHTML=`
|
|
56
|
-
<svg viewBox="0 0 16 16" fill="currentColor">
|
|
57
|
-
<path d="M11.534 7h3.932a.25.25 0 0 1 .192.41l-1.966 2.36a1.25 1.25 0 0 0 0 1.32l1.965 2.36a.25.25 0 0 1-.192.41h-3.932a.25.25 0 0 1-.192-.41l-1.966-2.36a1.25 1.25 0 0 0 0-1.32l1.966-2.36a.25.25 0 0 1 .192-.41zm-6.068 0H1.534a.25.25 0 0 0-.192.41l1.966 2.36a1.25 1.25 0 0 1 0 1.32l-1.966 2.36A.25.25 0 0 0 1.534 14h3.932a.25.25 0 0 0 .192-.41l-1.966-2.36a1.25 1.25 0 0 1 0-1.32l1.966-2.36a.25.25 0 0 0-.192-.41z"/>
|
|
58
|
-
</svg>
|
|
59
|
-
`,f.addEventListener(`click`,t=>{t.stopPropagation(),W(e,n,r,i,o,s)}),u.appendChild(d),u.appendChild(f),c.appendChild(u),e.appendChild(c)}}async function St(e){n.debug(`[SidePanel] ===== renderMessageMermaid start =====`);let r=e.querySelectorAll(`.mermaid`);if(r.length===0){n.debug(`[SidePanel] not found mermaid element`);return}try{await nt()}catch(e){n.warn(`[SidePanel] Mermaid lib failed to load:`,e);return}await new Promise(e=>setTimeout(e,300)),n.debug(`[SidePanel] find to mermaid element count:`,r.length);try{for(let i=0;i<r.length;i++){let a=r[i],o=await mt(a),s=e.querySelectorAll(`.mermaid`)[i];o.success&&s?(n.debug(`[SidePanel] `,i+1,` mermaid chart render successful`),V(s)):s&&!s.querySelector(`svg`)&&!s.querySelector(`.mermaid-controls`)&&(n.error(`[SidePanel] `,i+1,` mermaid chart render failed:`,o.detail,o.err),s.innerHTML=`<div style="color: #856404; background: #fff3cd; padding: 10px; border-radius: 4px;">${t(`markdown.chartRenderFailed`,{detail:o.detail})}</div>`)}n.debug(`[SidePanel] Mermaid rendercomplete`);let i=e.querySelectorAll(`.mermaid-controls`);n.debug(`[SidePanel] toolbar addresult:`,i.length,`successful`)}catch(e){n.error(`[SidePanel] Mermaid overall render failed:`,e)}Tt()}var Ct=!1;function wt(){Ct||(Ct=!0,document.addEventListener(`click`,e=>{if(!e.ctrlKey&&!e.metaKey||e.button!==0||!e.target.closest?.(`#chatContainer, .message-fullscreen-body`))return;let r=e.target.closest(`code`);if(!r){let t=e.target.closest(`pre`);if(t&&(r=t.querySelector(`code`)),!r){let t=e.target.closest(`.code-block-container`);t&&(r=t.querySelector(`code`))}}if(!r||e.target.closest(`.code-copy-btn`))return;e.preventDefault();let i=r.textContent;i&&navigator.clipboard.writeText(i).then(()=>{s(t(`markdown.copiedToClipboard`,{label:r.closest(`.code-block-container`)?t(`markdown.codeBlockLabel`):t(`markdown.codeLabel`)}),`success`)}).catch(e=>{n.error(`[SidePanel] Ctrl+clickcopy failed:`,e);let r=document.createElement(`textarea`);r.value=i,r.style.position=`fixed`,r.style.left=`-999999px`,document.body.appendChild(r),r.select(),document.execCommand(`copy`),document.body.removeChild(r),s(t(`markdown.codeCopied`),`success`)})}),n.debug(`[SidePanel] Ctrl+clickcopycodeeventbound (document delegate)`))}function Tt(){At(),wt()}function Et(e){let t=e.closest(`.table-container-wrapper`)?.querySelector(`table`);if(!t)return null;let n=[];t.querySelectorAll(`thead th`).forEach(e=>{let t=``;for(let n of e.childNodes)n.nodeType===Node.TEXT_NODE?t+=n.textContent:n.nodeType===Node.ELEMENT_NODE&&!n.classList.contains(`table-toolbar`)&&!n.closest(`.table-toolbar`)&&(t+=n.textContent||``);n.push(t.trim())});let r=[];if(t.querySelectorAll(`tbody tr`).forEach(e=>{let t=[];e.querySelectorAll(`td`).forEach(e=>{t.push(e.textContent.trim())}),r.push(t)}),n.length===0&&r.length===0)return null;let i=e=>e.replace(/\|/g,`\\|`),a=`| `+n.map(i).join(` | `)+` |`,o=`| `+n.map(()=>`---`).join(` | `)+` |`,s=r.map(e=>`| `+e.map(i).join(` | `)+` |`).join(`
|
|
60
|
-
`);return{full:a+`
|
|
61
|
-
`+o+`
|
|
62
|
-
`+s,header:a+`
|
|
63
|
-
`+o,body:s}}function Dt(e){let t=e.closest(`.code-block-container`);if(t){let n=t.querySelector(`pre code`);n&&a(n.textContent,e)}}function Ot(e,n){if(n.ctrlKey||n.metaKey){let n=e.closest(`.table-container-wrapper`)?.querySelector(`table`);if(n)try{let r=Mt(n).outerHTML;e.focus();let i=new Blob([r],{type:`text/html`}),a=new ClipboardItem({"text/html":i});navigator.clipboard.write([a]).then(()=>{s(t(`markdown.copiedRichTable`))}).catch(()=>{let n=document.createElement(`div`);n.style.cssText=`position:fixed;left:-999999px;top:-999999px;`,n.innerHTML=r,document.body.appendChild(n);let i=document.createRange();i.selectNodeContents(n);let a=window.getSelection();a.removeAllRanges(),a.addRange(i);try{e.focus(),document.execCommand(`copy`),s(t(`markdown.copiedRichTable`))}catch{s(t(`markdown.copyRichTableFailed`),`error`)}finally{a.removeAllRanges(),document.body.removeChild(n)}})}catch{s(t(`markdown.copyFailedShort`),`error`)}return}let r=e.dataset.tableFull?decodeURIComponent(e.dataset.tableFull):null;if(r){a(r,e),s(t(`markdown.copiedMdTable`));return}let i=e.dataset.tableIndex,o=window.__tableBlocks?.[parseInt(i)];if(o){a(o.full,e),s(t(`markdown.copiedMdTable`));return}let c=Et(e);c&&(a(c.full,e),s(t(`markdown.copiedMdTable`)))}function G(e){let t=e.dataset.tableHeader?decodeURIComponent(e.dataset.tableHeader):null,n=e.dataset.tableBody?decodeURIComponent(e.dataset.tableBody):null;if(t&&n){z({header:t,body:n});return}let r=e.dataset.tableIndex,i=window.__tableBlocks?.[parseInt(r)];if(i){z(i);return}let a=Et(e);a&&z(a)}async function K(e){let r=e.closest(`.table-container-wrapper`);if(r)try{let e=await rt();if(!e){s(t(`markdown.imageExportLibMissing`),`error`);return}let n=await e(r,{scale:2,useCORS:!0,logging:!1,backgroundColor:`#ffffff`}),i=document.createElement(`a`);i.download=`table-${Date.now()}.jpg`,i.href=n.toDataURL(`image/jpeg`,.95),document.body.appendChild(i),i.click(),document.body.removeChild(i),s(t(`markdown.tableImageExported`))}catch(e){n.error(`[SidePanel] export tableimage failed:`,e),s(t(`markdown.exportImageFailed`),`error`)}}var kt=!1;function At(){kt||typeof document>`u`||!document.addEventListener||(kt=!0,document.addEventListener(`click`,e=>{let t=e.target;if(!t||typeof t.closest!=`function`)return;let n=t.closest(`.code-copy-btn`);if(n){e.stopPropagation(),Dt(n);return}let r=t.closest(`.copy-md-btn`);if(r){e.stopPropagation(),Ot(r,e);return}let i=t.closest(`.download-excel-btn`);if(i){e.stopPropagation(),G(i);return}let a=t.closest(`.export-table-img-btn`);if(a){e.stopPropagation(),K(a);return}},!0))}function jt(){At()}function Mt(e){let t=e.cloneNode(!0);return t.querySelectorAll(`.table-header-cell-wrapper`).forEach(e=>{let t=e.textContent.trim();e.innerHTML=``,e.textContent=t,e.classList.remove(`table-header-cell-wrapper`)}),t.querySelectorAll(`.table-toolbar`).forEach(e=>e.remove()),t}var Nt=RegExp(`(?:~?/[\\w\\-.\\u4e00-\\u9fa5/]+|\\b[A-Za-z]:\\\\[\\w\\-.\\\\\\u4e00-\\u9fa5]+|\\b[\\w\\-.\\u4e00-\\u9fa5]+/[\\w\\-./\\u4e00-\\u9fa5]*\\.[A-Za-z0-9]{1,6}|\\b[\\w\\-.\\u4e00-\\u9fa5]+\\.[A-Za-z0-9]{1,6})`,`g`);function Pt(e){if(!e)return[];let t=e.replace(/\bhttps?:\/\/\S+/gi,` `),n=[],r;for(Nt.lastIndex=0;(r=Nt.exec(t))!==null;){let e=r[0].replace(/[,。、)()\s]+$/,``);e&&(/\/$/.test(e)&&!RegExp(`\\.[A-Za-z0-9]{1,6}$`).test(e)||/[.\\/~]/.test(e)&&(n.includes(e)||n.push(e)))}return n}function q(e){return(e||``).replace(/\\/g,`/`).replace(/\/+/g,`/`)}async function J(e,n=[]){if(!e)return;let i=e.querySelector(`.markdown-body`)||e,a=new Set((n||[]).map(q)),o=document.createTreeWalker(i,NodeFilter.SHOW_TEXT,{acceptNode(e){if(!e.nodeValue||!e.nodeValue.trim())return NodeFilter.FILTER_REJECT;let t=e.parentNode;return!t||!t.closest||t.closest(`a, pre, code, script, style, .chat-file-link`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),s=[];for(;o.nextNode();)s.push(o.currentNode);let c=new Set;for(let e of s)for(let t of Pt(e.nodeValue))c.add(t);if(c.size===0)return;let l=[...c].filter(e=>!a.has(q(e))),u=new Set;if(l.length>0)try{let e=null;try{let t=await(await r(()=>import(`./workspace-manager-DfSFPqwp.js`).then(e=>e.D),__vite__mapDeps([0,1,2,3,4]))).getAgentStatusDetail();t&&t.workdir&&(e=t.workdir)}catch{}let t=await r(()=>import(`./side_panel.js`).then(e=>e.t),__vite__mapDeps([5,1,2,3,4,6,7,8,9,0])),n=e?q(e):null,i=await Promise.all(l.map(e=>t.resolveWorkspaceAbsolutePath(e).catch(()=>null))),a=[];for(let e=0;e<l.length;e++){let t=i[e];if(!n||!t)continue;let r=q(t);r!==n&&!r.startsWith(n.endsWith(`/`)?n:n+`/`)||a.push({token:l[e],path:t})}if(a.length){let e=await chrome.runtime.sendMessage({type:`CHECK_FILES_EXIST`,paths:a.map(e=>e.path)});if(e&&e.success&&e.results)for(let t of a)e.results[t.path]===!0&&u.add(q(t.token))}}catch{}let d=e=>a.has(q(e))||u.has(q(e)),f=t(`chat.fileLinkTitle`);for(let e of s){let t=e.nodeValue,n=Pt(t).filter(d);if(n.length===0)continue;let r=n.slice().sort((e,t)=>t.length-e.length),i=document.createDocumentFragment(),a=t;for(;a.length;){let e=-1,t=null;for(let n of r){let r=a.indexOf(n);r!==-1&&(e===-1||r<e)&&(e=r,t=n)}if(e===-1){i.appendChild(document.createTextNode(a));break}e>0&&i.appendChild(document.createTextNode(a.slice(0,e)));let n=document.createElement(`span`);n.className=`chat-file-link`,n.setAttribute(`data-path`,t),n.setAttribute(`title`,f),n.textContent=t,i.appendChild(n),a=a.slice(e+t.length)}e.parentNode&&e.parentNode.replaceChild(i,e)}}var Y=!1;function Ft(){Y||(Y=!0,document.addEventListener(`click`,async e=>{let n=e.target.closest&&e.target.closest(`.chat-file-link`);if(!n)return;let i=n.getAttribute(`data-path`);if(i)try{await(await r(()=>import(`./side_panel.js`).then(e=>e.t),__vite__mapDeps([5,1,2,3,4,6,7,8,9,0]))).locateFileInWorkspace(i)}catch{s(t(`chat.fileLinkFailed`),`error`)}},!0))}export{Ft as a,_t as c,gt as d,L as f,Ze as g,it as h,J as i,ht as l,rt as m,V as n,Mt as o,F as p,jt as r,ft as s,Tt as t,St as u};
|