mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-05-18 14:04:52 +02:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e904dd3481 | |||
| 7b1487383f | |||
| 8a2177ffab | |||
| 3a7bbfbb88 | |||
| 7c01641de9 | |||
| 1c1086eea4 | |||
| 8f4f40f894 | |||
| 7f16ba706a | |||
| 0b950f95db | |||
| d36984a1c1 | |||
| da2109a970 | |||
| 1866aa8089 | |||
| 5af06e539d | |||
| 7493e70686 | |||
| 81f7a601b7 | |||
| 27830d1399 | |||
| d9a0178f80 | |||
| 1dd8cc7f50 | |||
| 55045dd4e0 |
+17
-1
@@ -10,7 +10,7 @@
|
|||||||
# ============================================
|
# ============================================
|
||||||
|
|
||||||
# 前端显示的版本号(可选,不填则显示默认版本)
|
# 前端显示的版本号(可选,不填则显示默认版本)
|
||||||
version: "v1.3.16"
|
version: "v1.3.20"
|
||||||
|
|
||||||
# 服务器配置
|
# 服务器配置
|
||||||
server:
|
server:
|
||||||
@@ -116,6 +116,22 @@ knowledge:
|
|||||||
top_k: 5 # 检索返回的Top-K结果数量
|
top_k: 5 # 检索返回的Top-K结果数量
|
||||||
similarity_threshold: 0.7 # 相似度阈值(0-1),低于此值的结果将被过滤
|
similarity_threshold: 0.7 # 相似度阈值(0-1),低于此值的结果将被过滤
|
||||||
hybrid_weight: 0.7 # 混合检索权重(0-1),向量检索的权重,1.0表示纯向量检索,0.0表示纯关键词检索
|
hybrid_weight: 0.7 # 混合检索权重(0-1),向量检索的权重,1.0表示纯向量检索,0.0表示纯关键词检索
|
||||||
|
# ============================================
|
||||||
|
# 索引配置(用于解决 API 限制问题)
|
||||||
|
# ============================================
|
||||||
|
indexing:
|
||||||
|
# 分块配置
|
||||||
|
chunk_size: 512 # 每个块的最大 token 数(默认 512),长文本会被分割成多个块
|
||||||
|
chunk_overlap: 50 # 块之间的重叠 token 数(默认 50),保持上下文连贯性
|
||||||
|
max_chunks_per_item: 0 # 单个知识项的最大块数量(0 表示不限制),防止单个文件消耗过多 API 配额
|
||||||
|
# 速率限制配置(解决 429 错误)
|
||||||
|
max_rpm: 0 # 每分钟最大请求数(默认 0 表示不限制),如 OpenAI 默认 200 RPM
|
||||||
|
rate_limit_delay_ms: 300 # 请求间隔毫秒数(默认 300),用于避免 API 速率限制,设为 0 不限制
|
||||||
|
# 建议值:200 次/分钟≈300ms, 100 次/分钟≈600ms
|
||||||
|
|
||||||
|
# 重试配置
|
||||||
|
max_retries: 3 # 最大重试次数(默认 3),遇到速率限制或服务器错误时自动重试
|
||||||
|
retry_delay_ms: 1000 # 重试间隔毫秒数(默认 1000),每次重试会递增延迟
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# 机器人配置(企业微信、钉钉、飞书)
|
# 机器人配置(企业微信、钉钉、飞书)
|
||||||
|
|||||||
@@ -0,0 +1,335 @@
|
|||||||
|
## CyberStrikeAI 前端国际化方案
|
||||||
|
|
||||||
|
本文档说明 CyberStrikeAI Web 前端(`web/templates/index.html` + `web/static/js/*.js`)的国际化设计与开发规范,确保在不引入打包工具和不改动后端路由的前提下,实现可扩展、低返工的多语言支持。
|
||||||
|
|
||||||
|
当前目标:
|
||||||
|
|
||||||
|
- **支持中英文切换(zh-CN / en-US)**
|
||||||
|
- 后续可方便扩展更多语言(如 ja-JP、ko-KR 等)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、总体设计原则
|
||||||
|
|
||||||
|
- **前端主导的客户端国际化**:所有 UI 文案在浏览器端根据当前语言动态渲染,后端 Go 仅负责结构和数据,不参与语言分发。
|
||||||
|
- **单一 HTML 模板**:继续使用一份 `index.html` 模板,不为不同语言复制模板文件。
|
||||||
|
- **文案与逻辑分离**:所有可见文本通过「键值表」管理(多语言 JSON),HTML / JS 只写 key,不直接写中文/英文常量。
|
||||||
|
- **渐进式改造**:先覆盖 header / 登录 / 侧边栏 / 系统设置等关键区域,其他页面按模块逐步迁移,避免一次性大改动。
|
||||||
|
- **可回退默认语言**:即使目标语言未完全翻译,也能回退到默认中文,不出现原始 key。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、技术选型与目录结构
|
||||||
|
|
||||||
|
### 2.1 技术选型
|
||||||
|
|
||||||
|
- **i18n 引擎**:使用 [i18next](https://www.i18next.com/) 的浏览器 UMD 版本(通过 CDN 引入),无需打包器。
|
||||||
|
- **资源格式**:每种语言一份 JSON 文件,采用「域 + 语义」的层级 key 方案,例如:
|
||||||
|
- `common.ok`
|
||||||
|
- `nav.dashboard`
|
||||||
|
- `header.apiDocs`
|
||||||
|
- `settings.robot.wecom.token`
|
||||||
|
|
||||||
|
### 2.2 目录结构
|
||||||
|
|
||||||
|
- `web/templates/index.html`
|
||||||
|
- 页面骨架 + 所有静态文案位置,将逐步改为 `data-i18n` 标记。
|
||||||
|
- `web/static/js/i18n.js`
|
||||||
|
- 前端 i18n 初始化与 DOM 应用逻辑(本方案新增)。
|
||||||
|
- `web/static/i18n/`(新增目录)
|
||||||
|
- `zh-CN.json`:中文文案(默认语言)
|
||||||
|
- `en-US.json`:英文文案
|
||||||
|
- 未来可新增:`ja-JP.json`、`ko-KR.json` 等。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、文案组织规范
|
||||||
|
|
||||||
|
### 3.1 Key 命名约定
|
||||||
|
|
||||||
|
- 采用「**模块.语义**」形式,最多 2–3 级,确保可读性:
|
||||||
|
- 导航:`nav.dashboard`、`nav.chat`、`nav.settings`
|
||||||
|
- 头部:`header.title`、`header.apiDocs`、`header.logout`
|
||||||
|
- 登录:`login.title`、`login.subtitle`、`login.passwordLabel`、`login.submit`
|
||||||
|
- 仪表盘:`dashboard.title`、`dashboard.refresh`、`dashboard.runningTasks`
|
||||||
|
- 系统设置:`settings.title`、`settings.nav.basic`、`settings.nav.robot`、`settings.apply`
|
||||||
|
- 机器人配置:`settings.robot.wecom.enabled`、`settings.robot.wecom.token` 等。
|
||||||
|
- 尽量按「界面区域」而不是「文件名」划分域,便于非开发人员理解。
|
||||||
|
|
||||||
|
### 3.2 JSON 示例
|
||||||
|
|
||||||
|
`web/static/i18n/zh-CN.json` 示例:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"common": {
|
||||||
|
"ok": "确定",
|
||||||
|
"cancel": "取消"
|
||||||
|
},
|
||||||
|
"nav": {
|
||||||
|
"dashboard": "仪表盘",
|
||||||
|
"chat": "对话",
|
||||||
|
"infoCollect": "信息收集",
|
||||||
|
"tasks": "任务管理",
|
||||||
|
"vulnerabilities": "漏洞管理",
|
||||||
|
"settings": "系统设置"
|
||||||
|
},
|
||||||
|
"header": {
|
||||||
|
"title": "CyberStrikeAI",
|
||||||
|
"apiDocs": "API 文档",
|
||||||
|
"logout": "退出登录",
|
||||||
|
"language": "界面语言"
|
||||||
|
},
|
||||||
|
"login": {
|
||||||
|
"title": "登录 CyberStrikeAI",
|
||||||
|
"subtitle": "请输入配置中的访问密码",
|
||||||
|
"passwordLabel": "密码",
|
||||||
|
"passwordPlaceholder": "输入登录密码",
|
||||||
|
"submit": "登录"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
英文文件 `en-US.json` 保持相同 key,不同 value:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"common": {
|
||||||
|
"ok": "OK",
|
||||||
|
"cancel": "Cancel"
|
||||||
|
},
|
||||||
|
"nav": {
|
||||||
|
"dashboard": "Dashboard",
|
||||||
|
"chat": "Chat",
|
||||||
|
"infoCollect": "Recon",
|
||||||
|
"tasks": "Tasks",
|
||||||
|
"vulnerabilities": "Vulnerabilities",
|
||||||
|
"settings": "Settings"
|
||||||
|
},
|
||||||
|
"header": {
|
||||||
|
"title": "CyberStrikeAI",
|
||||||
|
"apiDocs": "API Docs",
|
||||||
|
"logout": "Sign out",
|
||||||
|
"language": "Interface language"
|
||||||
|
},
|
||||||
|
"login": {
|
||||||
|
"title": "Sign in to CyberStrikeAI",
|
||||||
|
"subtitle": "Enter the access password from config",
|
||||||
|
"passwordLabel": "Password",
|
||||||
|
"passwordPlaceholder": "Enter password",
|
||||||
|
"submit": "Sign in"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> 约定:**新增界面时,必须先定义 i18n key,再在 HTML/JS 中使用 key**,禁止直接写死中文/英文。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、HTML 标记规范(data-i18n)
|
||||||
|
|
||||||
|
### 4.1 基本规则
|
||||||
|
|
||||||
|
- 使用 `data-i18n` 将元素文本与某个 key 绑定:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<span data-i18n="nav.dashboard">仪表盘</span>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 默认行为:脚本会替换元素的 `textContent`。
|
||||||
|
- 同时翻译属性时,额外使用 `data-i18n-attr`,逗号分隔多个属性名:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<button
|
||||||
|
class="openapi-doc-btn"
|
||||||
|
onclick="window.open('/api-docs', '_blank')"
|
||||||
|
data-i18n="header.apiDocs"
|
||||||
|
data-i18n-attr="title"
|
||||||
|
title="API 文档">
|
||||||
|
<span data-i18n="header.apiDocs">API 文档</span>
|
||||||
|
</button>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 默认文本的作用
|
||||||
|
|
||||||
|
- HTML 内的中文默认值作为「**无 JS / 初始化前**」的占位内容:
|
||||||
|
- 页面在 JS 尚未加载完成时不会出现空白或 key。
|
||||||
|
- JS 初始化后会用当前语言覆盖这些文本。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、JavaScript 中的文案规范
|
||||||
|
|
||||||
|
### 5.1 全局翻译函数 `t()`
|
||||||
|
|
||||||
|
由 `i18n.js` 暴露以下全局函数:
|
||||||
|
|
||||||
|
- `window.t(key: string): string`
|
||||||
|
- 返回当前语言下的翻译文本,若缺失则回退到默认语言,再不行则返回 key 本身。
|
||||||
|
- `window.changeLanguage(lang: string): Promise<void>`
|
||||||
|
- 切换语言并刷新页面文案(不会刷新整页)。
|
||||||
|
|
||||||
|
示例(以 `web/static/js/settings.js` 为例):
|
||||||
|
|
||||||
|
```js
|
||||||
|
// 之前
|
||||||
|
alert('加载配置失败: ' + error.message);
|
||||||
|
|
||||||
|
// 之后
|
||||||
|
alert(t('settings.loadConfigFailed') + ': ' + error.message);
|
||||||
|
```
|
||||||
|
|
||||||
|
> 规范:**JS 内所有面向用户的提示、按钮文字、对话框标题都应通过 `t()` 获取**,不直接写死中文/英文。
|
||||||
|
|
||||||
|
### 5.2 渐进迁移建议
|
||||||
|
|
||||||
|
- 优先改造:
|
||||||
|
- 频繁弹出的错误提示 / 成功提示;
|
||||||
|
- 登录相关、系统设置相关文案。
|
||||||
|
- 低优先级:
|
||||||
|
- 仅面向运维人员的调试提示,可以暂时保留英文/中文常量。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 六、i18n 初始化与语言切换实现
|
||||||
|
|
||||||
|
### 6.1 语言选择策略
|
||||||
|
|
||||||
|
- 默认语言:`zh-CN`。
|
||||||
|
- 优先级(从高到低):
|
||||||
|
1. `localStorage` 中的用户选择(key:`csai_lang`)。
|
||||||
|
2. 浏览器 `navigator.language`(`zh` 开头 → `zh-CN`,否则 `en-US`)。
|
||||||
|
3. 默认 `zh-CN`。
|
||||||
|
|
||||||
|
### 6.2 初始化流程(`i18n.js`)
|
||||||
|
|
||||||
|
1. 读取初始语言。
|
||||||
|
2. 初始化 i18next:
|
||||||
|
- `lng` 为当前语言;
|
||||||
|
- `fallbackLng` 为 `zh-CN`;
|
||||||
|
- 资源先留空,采用按需加载。
|
||||||
|
3. 通过 `fetch` 拉取 `/static/i18n/{lng}.json` 并 `i18next.addResources`。
|
||||||
|
4. 更新:
|
||||||
|
- `<html lang="...">` 属性;
|
||||||
|
- 所有带 `data-i18n` / `data-i18n-attr` 的元素。
|
||||||
|
5. 暴露 `window.t` 与 `window.changeLanguage`。
|
||||||
|
|
||||||
|
### 6.3 DOM 应用逻辑
|
||||||
|
|
||||||
|
伪代码:
|
||||||
|
|
||||||
|
```js
|
||||||
|
function applyTranslations(root = document) {
|
||||||
|
const elements = root.querySelectorAll('[data-i18n]');
|
||||||
|
elements.forEach(el => {
|
||||||
|
const key = el.getAttribute('data-i18n');
|
||||||
|
if (!key) return;
|
||||||
|
const text = i18next.t(key);
|
||||||
|
if (text) {
|
||||||
|
el.textContent = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
const attrList = el.getAttribute('data-i18n-attr');
|
||||||
|
if (attrList) {
|
||||||
|
attrList.split(',').map(s => s.trim()).forEach(attr => {
|
||||||
|
if (!attr) return;
|
||||||
|
const val = i18next.t(key);
|
||||||
|
if (val) el.setAttribute(attr, val);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> 对于由 JS 动态插入的元素,需要在插入后再次调用 `applyTranslations(新容器)`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 七、语言切换 UI 规范
|
||||||
|
|
||||||
|
### 7.1 位置与形态
|
||||||
|
|
||||||
|
- 位置:`index.html` header 右侧 `API 文档` 按钮附近(靠近用户头像)。
|
||||||
|
- 交互形式:
|
||||||
|
- 一个紧凑的语言切换组件,例如:
|
||||||
|
- `🌐` 图标 + 当前语言文本(`中文` / `English`)的下拉按钮;
|
||||||
|
- 下拉内容列出所有可用语言。
|
||||||
|
|
||||||
|
### 7.2 示例结构
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div class="lang-switcher">
|
||||||
|
<button class="btn-secondary lang-switcher-btn" onclick="toggleLangDropdown()" data-i18n="header.language">
|
||||||
|
<span class="lang-switcher-icon">🌐</span>
|
||||||
|
<span id="current-lang-label">中文</span>
|
||||||
|
</button>
|
||||||
|
<div id="lang-dropdown" class="lang-dropdown" style="display: none;">
|
||||||
|
<div class="lang-option" data-lang="zh-CN" onclick="onLanguageSelect('zh-CN')">中文</div>
|
||||||
|
<div class="lang-option" data-lang="en-US" onclick="onLanguageSelect('en-US')">English</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
对应 JS(在 `i18n.js` 中):
|
||||||
|
|
||||||
|
```js
|
||||||
|
function onLanguageSelect(lang) {
|
||||||
|
changeLanguage(lang).then(updateLangLabel).catch(console.error);
|
||||||
|
closeLangDropdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateLangLabel() {
|
||||||
|
const labelEl = document.getElementById('current-lang-label');
|
||||||
|
if (!labelEl) return;
|
||||||
|
const lang = i18next.language || 'zh-CN';
|
||||||
|
labelEl.textContent = lang.startsWith('zh') ? '中文' : 'English';
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> 规范:**语言切换只更新文案,不刷新整页,也不修改 URL hash**。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 八、开发流程建议
|
||||||
|
|
||||||
|
### 8.1 新增 / 修改界面的流程
|
||||||
|
|
||||||
|
1. 设计界面时,先列出所有文案。
|
||||||
|
2. 在对应语言 JSON 中补充/修改 key 与翻译。
|
||||||
|
3. 在 HTML 中使用 `data-i18n`,在 JS 中使用 `t('...')`。
|
||||||
|
4. 在浏览器中切换中英文,确认两种语言显示都正确。
|
||||||
|
|
||||||
|
### 8.2 渐进式改造顺序(推荐)
|
||||||
|
|
||||||
|
1. **阶段 1(已规划)**
|
||||||
|
- 引入 i18next 与 `i18n.js`。
|
||||||
|
- 新建 `zh-CN.json` / `en-US.json`(先覆盖 header / 登录 / 左侧导航)。
|
||||||
|
- 实现 header 区域语言切换组件。
|
||||||
|
2. **阶段 2**(已完成)
|
||||||
|
- 系统设置页面(包括机器人配置页面)全部文案 i18n 化。
|
||||||
|
- `settings.js` 中的提示与错误信息改用 `t()`。
|
||||||
|
3. **阶段 3**(进行中)
|
||||||
|
- 仪表盘、任务管理、漏洞管理、MCP、Skills、Roles 等页面按模块逐步迁移。
|
||||||
|
4. **阶段 4**
|
||||||
|
- 清理 JS / HTML 中残留的硬编码中文,统一通过 i18n。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 九、后续扩展新语言
|
||||||
|
|
||||||
|
当需要新增语言时:
|
||||||
|
|
||||||
|
1. 在 `web/static/i18n/` 中新增 `{lang}.json`,复制现有英文/中文文件结构,补充对应翻译。
|
||||||
|
2. 在语言切换下拉中添加对应选项,例如:
|
||||||
|
- `data-lang="ja-JP"` / 文本 `日本語`
|
||||||
|
3. 无需修改 `i18n.js` 或现有 HTML/JS 逻辑,即可支持新语言。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 十、注意事项与坑点
|
||||||
|
|
||||||
|
- **不要复制多份 HTML 模板** 来做多语言,那样维护成本极高,本方案统一由前端 i18n 控制。
|
||||||
|
- **避免 key 直接用中文/英文句子**,统一采用「模块.语义」短 key,便于 diff 与搜索。
|
||||||
|
- 避免在 CSS 中写死文本(如 `content: "xxx"`),如确有需要,应通过 JS 设置并走 i18n。
|
||||||
|
- 对于后端返回的可本地化错误文本(未来可能支持),优先由后端根据 `Accept-Language` 返回对应语言,前端只负责展示。
|
||||||
|
|
||||||
+38
-6
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[English](robot_en.md)
|
[English](robot_en.md)
|
||||||
|
|
||||||
本文档说明如何通过**钉钉**、**飞书**与 CyberStrikeAI 对话(长连接模式),在手机端即可使用,无需在服务器上打开网页。按下面步骤操作可避免常见弯路。
|
本文档说明如何通过**钉钉**、**飞书**与 **企业微信** 与 CyberStrikeAI 对话(长连接 / 回调模式),在手机端即可使用,无需在服务器上打开网页。按下面步骤操作可避免常见弯路。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -19,12 +19,13 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 二、支持的平台(长连接)
|
## 二、支持的平台(长连接 / 回调)
|
||||||
|
|
||||||
| 平台 | 说明 |
|
| 平台 | 说明 |
|
||||||
|------|------|
|
|----------|------|
|
||||||
| 钉钉 | 使用 Stream 长连接,程序主动连接钉钉接收消息 |
|
| 钉钉 | 使用 Stream 长连接,程序主动连接钉钉接收消息 |
|
||||||
| 飞书 | 使用长连接,程序主动连接飞书接收消息 |
|
| 飞书 | 使用长连接,程序主动连接飞书接收消息 |
|
||||||
|
| 企业微信 | 使用 HTTP 回调接收消息,被动回包 + 主动调用企业微信发送消息 API |
|
||||||
|
|
||||||
下面第三节会按平台写清:在开放平台要做什么、要复制哪些字段、填到 CyberStrikeAI 的哪一栏。
|
下面第三节会按平台写清:在开放平台要做什么、要复制哪些字段、填到 CyberStrikeAI 的哪一栏。
|
||||||
|
|
||||||
@@ -101,6 +102,37 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### 3.3 企业微信 (WeCom)
|
||||||
|
|
||||||
|
> 企业微信目前采用「HTTP 回调 + 主动发送消息 API」的方式工作:
|
||||||
|
> - 用户发消息 → 企业微信以加密 XML **回调到你的服务器**(本程序的 `/api/robot/wecom`);
|
||||||
|
> - CyberStrikeAI 解密并调用 AI → 使用企业微信的 `message/send` 接口**主动发消息给用户**。
|
||||||
|
|
||||||
|
**配置概览:**
|
||||||
|
|
||||||
|
- 在企业微信管理后台创建或选择一个**自建应用**。
|
||||||
|
- 在该应用的「接收消息」处配置回调 URL、Token、EncodingAESKey。
|
||||||
|
- 在 CyberStrikeAI 的 `config.yaml` 中填入:
|
||||||
|
- `robots.wecom.corp_id`:企业 ID(CorpID)
|
||||||
|
- `robots.wecom.agent_id`:应用的 AgentId
|
||||||
|
- `robots.wecom.token`:消息回调使用的 Token
|
||||||
|
- `robots.wecom.encoding_aes_key`:消息回调使用的 EncodingAESKey
|
||||||
|
- `robots.wecom.secret`:该应用的 Secret(用于调用企业微信主动发送消息接口)
|
||||||
|
|
||||||
|
> **重要:IP 白名单(errcode 60020)**
|
||||||
|
> CyberStrikeAI 使用 `https://qyapi.weixin.qq.com/cgi-bin/message/send` 主动发送 AI 回复。
|
||||||
|
> 若企业微信日志或本程序日志中出现 `errcode 60020 not allow to access from your ip`:
|
||||||
|
>
|
||||||
|
> - 说明你的服务器出口 IP **没有加入企业微信的 IP 白名单**;
|
||||||
|
> - 请在企业微信管理后台中找到该自建应用的**「安全设置 / IP 白名单」**(具体入口可能因版本略有不同),将运行 CyberStrikeAI 的服务器公网 IP(如 `110.xxx.xxx.xxx`)加入白名单;
|
||||||
|
> - 保存后等待生效,再次发送消息测试。
|
||||||
|
>
|
||||||
|
> 如果 IP 未加入白名单,企业微信会拒绝主动发送消息,表现为:
|
||||||
|
> - 回调接口 `/api/robot/wecom` 能正常收到并处理消息;
|
||||||
|
> - 但手机端**始终收不到 AI 回复**,日志中有 `not allow to access from your ip` 提示。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 四、机器人命令
|
## 四、机器人命令
|
||||||
|
|
||||||
在钉钉/飞书中向机器人发送以下**文本命令**(仅支持文本):
|
在钉钉/飞书中向机器人发送以下**文本命令**(仅支持文本):
|
||||||
|
|||||||
+36
-6
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[中文](robot.md)
|
[中文](robot.md)
|
||||||
|
|
||||||
This document explains how to chat with CyberStrikeAI from **DingTalk** and **Lark (Feishu)** using long-lived connections—no need to open a browser on the server. Following the steps below helps avoid common mistakes.
|
This document explains how to chat with CyberStrikeAI from **DingTalk**, **Lark (Feishu)**, and **WeCom (Enterprise WeChat)** using long-lived connections or HTTP callbacks—no need to open a browser on the server. Following the steps below helps avoid common mistakes.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -19,12 +19,13 @@ Settings are written to the `robots` section of `config.yaml`; you can also edit
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 2. Supported platforms (long-lived connection)
|
## 2. Supported platforms (long-lived / callback)
|
||||||
|
|
||||||
| Platform | Description |
|
| Platform | Description |
|
||||||
|----------|-------------|
|
|----------------|-------------|
|
||||||
| DingTalk | Stream long-lived connection; the app connects to DingTalk to receive messages |
|
| DingTalk | Stream long-lived connection; the app connects to DingTalk to receive messages |
|
||||||
| Lark (Feishu) | Long-lived connection; the app connects to Lark to receive messages |
|
| Lark (Feishu) | Long-lived connection; the app connects to Lark to receive messages |
|
||||||
|
| WeCom (Qiye WX)| HTTP callback to receive messages; CyberStrikeAI replies via WeCom’s message sending API |
|
||||||
|
|
||||||
Section 3 below describes, per platform, what to do in the developer console and which fields to copy into CyberStrikeAI.
|
Section 3 below describes, per platform, what to do in the developer console and which fields to copy into CyberStrikeAI.
|
||||||
|
|
||||||
@@ -100,6 +101,35 @@ If you only have a **custom bot** Webhook URL (`oapi.dingtalk.com/robot/send?acc
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### 3.3 WeCom (Enterprise WeChat)
|
||||||
|
|
||||||
|
> WeCom uses a **“HTTP callback + active message send API”** model:
|
||||||
|
> - User sends a message → WeCom sends an **encrypted XML callback** to your server (CyberStrikeAI’s `/api/robot/wecom`).
|
||||||
|
> - CyberStrikeAI decrypts it, calls the AI, then uses WeCom’s `message/send` API to **actively push the reply** to the user.
|
||||||
|
|
||||||
|
**Configuration overview:**
|
||||||
|
|
||||||
|
- In the WeCom admin console, create or select a **custom app** (自建应用).
|
||||||
|
- In that app’s settings, configure the message **callback URL**, **Token**, and **EncodingAESKey**.
|
||||||
|
- In CyberStrikeAI’s `config.yaml`, fill in:
|
||||||
|
- `robots.wecom.corp_id`: your CorpID (企业 ID)
|
||||||
|
- `robots.wecom.agent_id`: the app’s AgentId
|
||||||
|
- `robots.wecom.token`: the Token used for message callbacks
|
||||||
|
- `robots.wecom.encoding_aes_key`: the EncodingAESKey used for callbacks
|
||||||
|
- `robots.wecom.secret`: the app’s Secret (used when calling WeCom APIs to send messages)
|
||||||
|
|
||||||
|
> **Important: IP allowlist (errcode 60020)**
|
||||||
|
> CyberStrikeAI calls `https://qyapi.weixin.qq.com/cgi-bin/message/send` to actively send AI replies.
|
||||||
|
> If logs show `errcode 60020 not allow to access from your ip`:
|
||||||
|
>
|
||||||
|
> - Your server’s outbound IP is **not in WeCom’s IP allowlist**.
|
||||||
|
> - In the WeCom admin console, open the custom app’s **Security / IP allowlist** settings (name may vary slightly), and add the public IP of the machine running CyberStrikeAI (e.g. `110.xxx.xxx.xxx`).
|
||||||
|
> - Save and wait for it to take effect, then test again.
|
||||||
|
>
|
||||||
|
> If the IP is not whitelisted, WeCom will reject active message sending. You will see that `/api/robot/wecom` receives and processes callbacks, but users **never see AI replies**, and logs contain `not allow to access from your ip`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 4. Bot commands
|
## 4. Bot commands
|
||||||
|
|
||||||
Send these **text commands** to the bot in DingTalk or Lark (text only):
|
Send these **text commands** to the bot in DingTalk or Lark (text only):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module cyberstrike-ai
|
module cyberstrike-ai
|
||||||
|
|
||||||
go 1.23.0
|
go 1.24.0
|
||||||
|
|
||||||
toolchain go1.24.4
|
toolchain go1.24.4
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ require (
|
|||||||
github.com/open-dingtalk/dingtalk-stream-sdk-go v0.9.1
|
github.com/open-dingtalk/dingtalk-stream-sdk-go v0.9.1
|
||||||
github.com/pkoukk/tiktoken-go v0.1.8
|
github.com/pkoukk/tiktoken-go v0.1.8
|
||||||
go.uber.org/zap v1.26.0
|
go.uber.org/zap v1.26.0
|
||||||
|
golang.org/x/time v0.14.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -129,6 +129,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
|
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
|
||||||
|
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
|
|||||||
@@ -345,8 +345,29 @@ func (mc *MemoryCompressor) adjustRecentStartForToolCalls(msgs []ChatMessage, re
|
|||||||
adjusted--
|
adjusted--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure at least one user message is included in recent messages to avoid Qwen model error
|
||||||
|
// Qwen models require a user message in the message array, otherwise they return:
|
||||||
|
// "No user query found in messages"
|
||||||
|
hasUserMessage := false
|
||||||
|
for i := adjusted; i < len(msgs); i++ {
|
||||||
|
if strings.EqualFold(msgs[i].Role, "user") {
|
||||||
|
hasUserMessage = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no user message in recent messages, adjust backwards to include one
|
||||||
|
if !hasUserMessage {
|
||||||
|
for adjusted > 0 {
|
||||||
|
adjusted--
|
||||||
|
if strings.EqualFold(msgs[adjusted].Role, "user") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if adjusted != recentStart {
|
if adjusted != recentStart {
|
||||||
mc.logger.Debug("adjusted recent window to keep tool call context",
|
mc.logger.Debug("adjusted recent window to keep tool call context and user message",
|
||||||
zap.Int("original_recent_start", recentStart),
|
zap.Int("original_recent_start", recentStart),
|
||||||
zap.Int("adjusted_recent_start", adjusted),
|
zap.Int("adjusted_recent_start", adjusted),
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-2
@@ -198,7 +198,7 @@ func New(cfg *config.Config, log *logger.Logger) (*App, error) {
|
|||||||
knowledgeRetriever = knowledge.NewRetriever(knowledgeDB, embedder, retrievalConfig, log.Logger)
|
knowledgeRetriever = knowledge.NewRetriever(knowledgeDB, embedder, retrievalConfig, log.Logger)
|
||||||
|
|
||||||
// 创建索引器
|
// 创建索引器
|
||||||
knowledgeIndexer = knowledge.NewIndexer(knowledgeDB, embedder, log.Logger)
|
knowledgeIndexer = knowledge.NewIndexer(knowledgeDB, embedder, log.Logger, &cfg.Knowledge.Indexing)
|
||||||
|
|
||||||
// 注册知识检索工具到MCP服务器
|
// 注册知识检索工具到MCP服务器
|
||||||
knowledge.RegisterKnowledgeTool(mcpServer, knowledgeRetriever, knowledgeManager, log.Logger)
|
knowledge.RegisterKnowledgeTool(mcpServer, knowledgeRetriever, knowledgeManager, log.Logger)
|
||||||
@@ -1102,7 +1102,7 @@ func initializeKnowledge(
|
|||||||
knowledgeRetriever := knowledge.NewRetriever(knowledgeDB, embedder, retrievalConfig, logger)
|
knowledgeRetriever := knowledge.NewRetriever(knowledgeDB, embedder, retrievalConfig, logger)
|
||||||
|
|
||||||
// 创建索引器
|
// 创建索引器
|
||||||
knowledgeIndexer := knowledge.NewIndexer(knowledgeDB, embedder, logger)
|
knowledgeIndexer := knowledge.NewIndexer(knowledgeDB, embedder, logger, &cfg.Knowledge.Indexing)
|
||||||
|
|
||||||
// 注册知识检索工具到MCP服务器
|
// 注册知识检索工具到MCP服务器
|
||||||
knowledge.RegisterKnowledgeTool(mcpServer, knowledgeRetriever, knowledgeManager, logger)
|
knowledge.RegisterKnowledgeTool(mcpServer, knowledgeRetriever, knowledgeManager, logger)
|
||||||
|
|||||||
@@ -582,9 +582,18 @@ func Default() *Config {
|
|||||||
},
|
},
|
||||||
Retrieval: RetrievalConfig{
|
Retrieval: RetrievalConfig{
|
||||||
TopK: 5,
|
TopK: 5,
|
||||||
SimilarityThreshold: 0.7,
|
SimilarityThreshold: 0.65, // 降低阈值到 0.65,减少漏检
|
||||||
HybridWeight: 0.7,
|
HybridWeight: 0.7,
|
||||||
},
|
},
|
||||||
|
Indexing: IndexingConfig{
|
||||||
|
ChunkSize: 768, // 增加到 768,更好的上下文保持
|
||||||
|
ChunkOverlap: 50,
|
||||||
|
MaxChunksPerItem: 20, // 限制单个知识项最多 20 个块,避免消耗过多配额
|
||||||
|
MaxRPM: 100, // 默认 100 RPM,避免 429 错误
|
||||||
|
RateLimitDelayMs: 600, // 600ms 间隔,对应 100 RPM
|
||||||
|
MaxRetries: 3,
|
||||||
|
RetryDelayMs: 1000,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -595,6 +604,26 @@ type KnowledgeConfig struct {
|
|||||||
BasePath string `yaml:"base_path" json:"base_path"` // 知识库路径
|
BasePath string `yaml:"base_path" json:"base_path"` // 知识库路径
|
||||||
Embedding EmbeddingConfig `yaml:"embedding" json:"embedding"`
|
Embedding EmbeddingConfig `yaml:"embedding" json:"embedding"`
|
||||||
Retrieval RetrievalConfig `yaml:"retrieval" json:"retrieval"`
|
Retrieval RetrievalConfig `yaml:"retrieval" json:"retrieval"`
|
||||||
|
Indexing IndexingConfig `yaml:"indexing,omitempty" json:"indexing,omitempty"` // 索引构建配置
|
||||||
|
}
|
||||||
|
|
||||||
|
// IndexingConfig 索引构建配置(用于控制知识库索引构建时的行为)
|
||||||
|
type IndexingConfig struct {
|
||||||
|
// 分块配置
|
||||||
|
ChunkSize int `yaml:"chunk_size,omitempty" json:"chunk_size,omitempty"` // 每个块的最大 token 数(估算),默认 512
|
||||||
|
ChunkOverlap int `yaml:"chunk_overlap,omitempty" json:"chunk_overlap,omitempty"` // 块之间的重叠 token 数,默认 50
|
||||||
|
MaxChunksPerItem int `yaml:"max_chunks_per_item,omitempty" json:"max_chunks_per_item,omitempty"` // 单个知识项的最大块数量,0 表示不限制
|
||||||
|
|
||||||
|
// 速率限制配置(用于避免 API 速率限制)
|
||||||
|
RateLimitDelayMs int `yaml:"rate_limit_delay_ms,omitempty" json:"rate_limit_delay_ms,omitempty"` // 请求间隔时间(毫秒),0 表示不使用固定延迟
|
||||||
|
MaxRPM int `yaml:"max_rpm,omitempty" json:"max_rpm,omitempty"` // 每分钟最大请求数,0 表示不限制
|
||||||
|
|
||||||
|
// 重试配置(用于处理临时错误)
|
||||||
|
MaxRetries int `yaml:"max_retries,omitempty" json:"max_retries,omitempty"` // 最大重试次数,默认 3
|
||||||
|
RetryDelayMs int `yaml:"retry_delay_ms,omitempty" json:"retry_delay_ms,omitempty"` // 重试间隔(毫秒),默认 1000
|
||||||
|
|
||||||
|
// 批处理配置(用于批量嵌入,当前未使用,保留扩展)
|
||||||
|
BatchSize int `yaml:"batch_size,omitempty" json:"batch_size,omitempty"` // 批量处理大小,0 表示逐个处理
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmbeddingConfig 嵌入配置
|
// EmbeddingConfig 嵌入配置
|
||||||
|
|||||||
@@ -1444,7 +1444,8 @@ func (h *AgentHandler) executeBatchQueue(queueID string) {
|
|||||||
// 执行任务(使用包含角色提示词的finalMessage和角色工具列表)
|
// 执行任务(使用包含角色提示词的finalMessage和角色工具列表)
|
||||||
h.logger.Info("执行批量任务", zap.String("queueId", queueID), zap.String("taskId", task.ID), zap.String("message", task.Message), zap.String("role", queue.Role), zap.String("conversationId", conversationID))
|
h.logger.Info("执行批量任务", zap.String("queueId", queueID), zap.String("taskId", task.ID), zap.String("message", task.Message), zap.String("role", queue.Role), zap.String("conversationId", conversationID))
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
|
// 单个子任务超时时间:从30分钟调整为6小时,适配长时间渗透/扫描任务
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 6*time.Hour)
|
||||||
// 存储取消函数,以便在取消队列时能够取消当前任务
|
// 存储取消函数,以便在取消队列时能够取消当前任务
|
||||||
h.batchTaskManager.SetTaskCancel(queueID, cancel)
|
h.batchTaskManager.SetTaskCancel(queueID, cancel)
|
||||||
// 使用队列配置的角色工具列表(如果为空,表示使用所有工具)
|
// 使用队列配置的角色工具列表(如果为空,表示使用所有工具)
|
||||||
|
|||||||
@@ -1062,6 +1062,16 @@ func updateKnowledgeConfig(doc *yaml.Node, cfg config.KnowledgeConfig) {
|
|||||||
setIntInMap(retrievalNode, "top_k", cfg.Retrieval.TopK)
|
setIntInMap(retrievalNode, "top_k", cfg.Retrieval.TopK)
|
||||||
setFloatInMap(retrievalNode, "similarity_threshold", cfg.Retrieval.SimilarityThreshold)
|
setFloatInMap(retrievalNode, "similarity_threshold", cfg.Retrieval.SimilarityThreshold)
|
||||||
setFloatInMap(retrievalNode, "hybrid_weight", cfg.Retrieval.HybridWeight)
|
setFloatInMap(retrievalNode, "hybrid_weight", cfg.Retrieval.HybridWeight)
|
||||||
|
|
||||||
|
// 更新索引配置
|
||||||
|
indexingNode := ensureMap(knowledgeNode, "indexing")
|
||||||
|
setIntInMap(indexingNode, "chunk_size", cfg.Indexing.ChunkSize)
|
||||||
|
setIntInMap(indexingNode, "chunk_overlap", cfg.Indexing.ChunkOverlap)
|
||||||
|
setIntInMap(indexingNode, "max_chunks_per_item", cfg.Indexing.MaxChunksPerItem)
|
||||||
|
setIntInMap(indexingNode, "max_rpm", cfg.Indexing.MaxRPM)
|
||||||
|
setIntInMap(indexingNode, "rate_limit_delay_ms", cfg.Indexing.RateLimitDelayMs)
|
||||||
|
setIntInMap(indexingNode, "max_retries", cfg.Indexing.MaxRetries)
|
||||||
|
setIntInMap(indexingNode, "retry_delay_ms", cfg.Indexing.RetryDelayMs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateRobotsConfig(doc *yaml.Node, cfg config.RobotsConfig) {
|
func updateRobotsConfig(doc *yaml.Node, cfg config.RobotsConfig) {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func (h *KnowledgeHandler) GetItems(c *gin.Context) {
|
|||||||
groupedByCategory[cat] = append(groupedByCategory[cat], item)
|
groupedByCategory[cat] = append(groupedByCategory[cat], item)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换为CategoryWithItems格式
|
// 转换为 CategoryWithItems 格式
|
||||||
categoriesWithItems := make([]*knowledge.CategoryWithItems, 0, len(groupedByCategory))
|
categoriesWithItems := make([]*knowledge.CategoryWithItems, 0, len(groupedByCategory))
|
||||||
for cat, catItems := range groupedByCategory {
|
for cat, catItems := range groupedByCategory {
|
||||||
categoriesWithItems = append(categoriesWithItems, &knowledge.CategoryWithItems{
|
categoriesWithItems = append(categoriesWithItems, &knowledge.CategoryWithItems{
|
||||||
@@ -107,7 +107,7 @@ func (h *KnowledgeHandler) GetItems(c *gin.Context) {
|
|||||||
categoryPageMode := c.Query("categoryPage") != "false" // 默认使用分类分页
|
categoryPageMode := c.Query("categoryPage") != "false" // 默认使用分类分页
|
||||||
|
|
||||||
// 分页参数
|
// 分页参数
|
||||||
limit := 50 // 默认每页50条(分类分页时为分类数,项分页时为项数)
|
limit := 50 // 默认每页 50 条(分类分页时为分类数,项分页时为项数)
|
||||||
offset := 0
|
offset := 0
|
||||||
if limitStr := c.Query("limit"); limitStr != "" {
|
if limitStr := c.Query("limit"); limitStr != "" {
|
||||||
if parsed, err := parseInt(limitStr); err == nil && parsed > 0 && parsed <= 500 {
|
if parsed, err := parseInt(limitStr); err == nil && parsed > 0 && parsed <= 500 {
|
||||||
@@ -120,7 +120,7 @@ func (h *KnowledgeHandler) GetItems(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果指定了category参数,且使用分类分页模式,则只返回该分类
|
// 如果指定了 category 参数,且使用分类分页模式,则只返回该分类
|
||||||
if category != "" && categoryPageMode {
|
if category != "" && categoryPageMode {
|
||||||
// 单分类模式:返回该分类的所有知识项(不分页)
|
// 单分类模式:返回该分类的所有知识项(不分页)
|
||||||
items, total, err := h.manager.GetItemsSummary(category, 0, 0)
|
items, total, err := h.manager.GetItemsSummary(category, 0, 0)
|
||||||
@@ -150,9 +150,9 @@ func (h *KnowledgeHandler) GetItems(c *gin.Context) {
|
|||||||
|
|
||||||
if categoryPageMode {
|
if categoryPageMode {
|
||||||
// 按分类分页模式(默认)
|
// 按分类分页模式(默认)
|
||||||
// limit表示每页分类数,推荐5-10个分类
|
// limit 表示每页分类数,推荐 5-10 个分类
|
||||||
if limit <= 0 || limit > 100 {
|
if limit <= 0 || limit > 100 {
|
||||||
limit = 10 // 默认每页10个分类
|
limit = 10 // 默认每页 10 个分类
|
||||||
}
|
}
|
||||||
|
|
||||||
categoriesWithItems, totalCategories, err := h.manager.GetCategoriesWithItems(limit, offset)
|
categoriesWithItems, totalCategories, err := h.manager.GetCategoriesWithItems(limit, offset)
|
||||||
@@ -172,7 +172,7 @@ func (h *KnowledgeHandler) GetItems(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 按项分页模式(向后兼容)
|
// 按项分页模式(向后兼容)
|
||||||
// 是否包含完整内容(默认false,只返回摘要)
|
// 是否包含完整内容(默认 false,只返回摘要)
|
||||||
includeContent := c.Query("includeContent") == "true"
|
includeContent := c.Query("includeContent") == "true"
|
||||||
|
|
||||||
if includeContent {
|
if includeContent {
|
||||||
@@ -358,7 +358,7 @@ func (h *KnowledgeHandler) ScanKnowledgeBase(c *gin.Context) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果连续失败2次,立即停止增量索引
|
// 如果连续失败 2 次,立即停止增量索引
|
||||||
if consecutiveFailures >= 2 {
|
if consecutiveFailures >= 2 {
|
||||||
h.logger.Error("连续索引失败次数过多,立即停止增量索引",
|
h.logger.Error("连续索引失败次数过多,立即停止增量索引",
|
||||||
zap.Int("consecutiveFailures", consecutiveFailures),
|
zap.Int("consecutiveFailures", consecutiveFailures),
|
||||||
@@ -397,7 +397,7 @@ func (h *KnowledgeHandler) ScanKnowledgeBase(c *gin.Context) {
|
|||||||
func (h *KnowledgeHandler) GetRetrievalLogs(c *gin.Context) {
|
func (h *KnowledgeHandler) GetRetrievalLogs(c *gin.Context) {
|
||||||
conversationID := c.Query("conversationId")
|
conversationID := c.Query("conversationId")
|
||||||
messageID := c.Query("messageId")
|
messageID := c.Query("messageId")
|
||||||
limit := 50 // 默认50条
|
limit := 50 // 默认 50 条
|
||||||
|
|
||||||
if limitStr := c.Query("limit"); limitStr != "" {
|
if limitStr := c.Query("limit"); limitStr != "" {
|
||||||
if parsed, err := parseInt(limitStr); err == nil && parsed > 0 {
|
if parsed, err := parseInt(limitStr); err == nil && parsed > 0 {
|
||||||
@@ -441,18 +441,40 @@ func (h *KnowledgeHandler) GetIndexStatus(c *gin.Context) {
|
|||||||
if h.indexer != nil {
|
if h.indexer != nil {
|
||||||
lastError, lastErrorTime := h.indexer.GetLastError()
|
lastError, lastErrorTime := h.indexer.GetLastError()
|
||||||
if lastError != "" {
|
if lastError != "" {
|
||||||
// 如果错误是最近发生的(5分钟内),则返回错误信息
|
// 如果错误是最近发生的(5 分钟内),则返回错误信息
|
||||||
if time.Since(lastErrorTime) < 5*time.Minute {
|
if time.Since(lastErrorTime) < 5*time.Minute {
|
||||||
status["last_error"] = lastError
|
status["last_error"] = lastError
|
||||||
status["last_error_time"] = lastErrorTime.Format(time.RFC3339)
|
status["last_error_time"] = lastErrorTime.Format(time.RFC3339)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取重建索引状态
|
||||||
|
isRebuilding, totalItems, current, failed, lastItemID, lastChunks, startTime := h.indexer.GetRebuildStatus()
|
||||||
|
if isRebuilding {
|
||||||
|
status["is_rebuilding"] = true
|
||||||
|
status["rebuild_total"] = totalItems
|
||||||
|
status["rebuild_current"] = current
|
||||||
|
status["rebuild_failed"] = failed
|
||||||
|
status["rebuild_start_time"] = startTime.Format(time.RFC3339)
|
||||||
|
if lastItemID != "" {
|
||||||
|
status["rebuild_last_item_id"] = lastItemID
|
||||||
|
}
|
||||||
|
if lastChunks > 0 {
|
||||||
|
status["rebuild_last_chunks"] = lastChunks
|
||||||
|
}
|
||||||
|
// 重建中时,is_complete 为 false
|
||||||
|
status["is_complete"] = false
|
||||||
|
// 计算重建进度百分比
|
||||||
|
if totalItems > 0 {
|
||||||
|
status["progress_percent"] = float64(current) / float64(totalItems) * 100
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, status)
|
c.JSON(http.StatusOK, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search 搜索知识库(用于API调用,Agent内部使用Retriever)
|
// Search 搜索知识库(用于 API 调用,Agent 内部使用 Retriever)
|
||||||
func (h *KnowledgeHandler) Search(c *gin.Context) {
|
func (h *KnowledgeHandler) Search(c *gin.Context) {
|
||||||
var req knowledge.SearchRequest
|
var req knowledge.SearchRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
|||||||
+381
-77
@@ -1,11 +1,15 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/sha1"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"encoding/json"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -141,56 +145,9 @@ func (h *RobotHandler) HandleMessage(platform, userID, text string) (reply strin
|
|||||||
return "请输入内容或发送「帮助」/ help 查看命令。"
|
return "请输入内容或发送「帮助」/ help 查看命令。"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 命令分发(支持中英文)
|
// 先尝试作为命令处理(支持中英文)
|
||||||
switch {
|
if cmdReply, ok := h.handleRobotCommand(platform, userID, text); ok {
|
||||||
case text == robotCmdHelp || text == "help" || text == "?" || text == "?":
|
return cmdReply
|
||||||
return h.cmdHelp()
|
|
||||||
case text == robotCmdList || text == robotCmdListAlt || text == "list":
|
|
||||||
return h.cmdList()
|
|
||||||
case strings.HasPrefix(text, robotCmdSwitch+" ") || strings.HasPrefix(text, robotCmdContinue+" ") || strings.HasPrefix(text, "switch ") || strings.HasPrefix(text, "continue "):
|
|
||||||
var id string
|
|
||||||
switch {
|
|
||||||
case strings.HasPrefix(text, robotCmdSwitch+" "):
|
|
||||||
id = strings.TrimSpace(text[len(robotCmdSwitch)+1:])
|
|
||||||
case strings.HasPrefix(text, robotCmdContinue+" "):
|
|
||||||
id = strings.TrimSpace(text[len(robotCmdContinue)+1:])
|
|
||||||
case strings.HasPrefix(text, "switch "):
|
|
||||||
id = strings.TrimSpace(text[7:])
|
|
||||||
default:
|
|
||||||
id = strings.TrimSpace(text[9:])
|
|
||||||
}
|
|
||||||
return h.cmdSwitch(platform, userID, id)
|
|
||||||
case text == robotCmdNew || text == "new":
|
|
||||||
return h.cmdNew(platform, userID)
|
|
||||||
case text == robotCmdClear || text == "clear":
|
|
||||||
return h.cmdClear(platform, userID)
|
|
||||||
case text == robotCmdCurrent || text == "current":
|
|
||||||
return h.cmdCurrent(platform, userID)
|
|
||||||
case text == robotCmdStop || text == "stop":
|
|
||||||
return h.cmdStop(platform, userID)
|
|
||||||
case text == robotCmdRoles || text == robotCmdRolesList || text == "roles":
|
|
||||||
return h.cmdRoles()
|
|
||||||
case strings.HasPrefix(text, robotCmdRoles+" ") || strings.HasPrefix(text, robotCmdSwitchRole+" ") || strings.HasPrefix(text, "role "):
|
|
||||||
var roleName string
|
|
||||||
switch {
|
|
||||||
case strings.HasPrefix(text, robotCmdRoles+" "):
|
|
||||||
roleName = strings.TrimSpace(text[len(robotCmdRoles)+1:])
|
|
||||||
case strings.HasPrefix(text, robotCmdSwitchRole+" "):
|
|
||||||
roleName = strings.TrimSpace(text[len(robotCmdSwitchRole)+1:])
|
|
||||||
default:
|
|
||||||
roleName = strings.TrimSpace(text[5:])
|
|
||||||
}
|
|
||||||
return h.cmdSwitchRole(platform, userID, roleName)
|
|
||||||
case strings.HasPrefix(text, robotCmdDelete+" ") || strings.HasPrefix(text, "delete "):
|
|
||||||
var convID string
|
|
||||||
if strings.HasPrefix(text, robotCmdDelete+" ") {
|
|
||||||
convID = strings.TrimSpace(text[len(robotCmdDelete)+1:])
|
|
||||||
} else {
|
|
||||||
convID = strings.TrimSpace(text[7:])
|
|
||||||
}
|
|
||||||
return h.cmdDelete(platform, userID, convID)
|
|
||||||
case text == robotCmdVersion || text == "version":
|
|
||||||
return h.cmdVersion()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 普通消息:走 Agent
|
// 普通消息:走 Agent
|
||||||
@@ -404,6 +361,62 @@ func (h *RobotHandler) cmdVersion() string {
|
|||||||
return "CyberStrikeAI " + v
|
return "CyberStrikeAI " + v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleRobotCommand 处理机器人内置命令;若匹配到命令返回 (回复内容, true),否则返回 ("", false)
|
||||||
|
func (h *RobotHandler) handleRobotCommand(platform, userID, text string) (string, bool) {
|
||||||
|
switch {
|
||||||
|
case text == robotCmdHelp || text == "help" || text == "?" || text == "?":
|
||||||
|
return h.cmdHelp(), true
|
||||||
|
case text == robotCmdList || text == robotCmdListAlt || text == "list":
|
||||||
|
return h.cmdList(), true
|
||||||
|
case strings.HasPrefix(text, robotCmdSwitch+" ") || strings.HasPrefix(text, robotCmdContinue+" ") || strings.HasPrefix(text, "switch ") || strings.HasPrefix(text, "continue "):
|
||||||
|
var id string
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(text, robotCmdSwitch+" "):
|
||||||
|
id = strings.TrimSpace(text[len(robotCmdSwitch)+1:])
|
||||||
|
case strings.HasPrefix(text, robotCmdContinue+" "):
|
||||||
|
id = strings.TrimSpace(text[len(robotCmdContinue)+1:])
|
||||||
|
case strings.HasPrefix(text, "switch "):
|
||||||
|
id = strings.TrimSpace(text[7:])
|
||||||
|
default:
|
||||||
|
id = strings.TrimSpace(text[9:])
|
||||||
|
}
|
||||||
|
return h.cmdSwitch(platform, userID, id), true
|
||||||
|
case text == robotCmdNew || text == "new":
|
||||||
|
return h.cmdNew(platform, userID), true
|
||||||
|
case text == robotCmdClear || text == "clear":
|
||||||
|
return h.cmdClear(platform, userID), true
|
||||||
|
case text == robotCmdCurrent || text == "current":
|
||||||
|
return h.cmdCurrent(platform, userID), true
|
||||||
|
case text == robotCmdStop || text == "stop":
|
||||||
|
return h.cmdStop(platform, userID), true
|
||||||
|
case text == robotCmdRoles || text == robotCmdRolesList || text == "roles":
|
||||||
|
return h.cmdRoles(), true
|
||||||
|
case strings.HasPrefix(text, robotCmdRoles+" ") || strings.HasPrefix(text, robotCmdSwitchRole+" ") || strings.HasPrefix(text, "role "):
|
||||||
|
var roleName string
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(text, robotCmdRoles+" "):
|
||||||
|
roleName = strings.TrimSpace(text[len(robotCmdRoles)+1:])
|
||||||
|
case strings.HasPrefix(text, robotCmdSwitchRole+" "):
|
||||||
|
roleName = strings.TrimSpace(text[len(robotCmdSwitchRole)+1:])
|
||||||
|
default:
|
||||||
|
roleName = strings.TrimSpace(text[5:])
|
||||||
|
}
|
||||||
|
return h.cmdSwitchRole(platform, userID, roleName), true
|
||||||
|
case strings.HasPrefix(text, robotCmdDelete+" ") || strings.HasPrefix(text, "delete "):
|
||||||
|
var convID string
|
||||||
|
if strings.HasPrefix(text, robotCmdDelete+" ") {
|
||||||
|
convID = strings.TrimSpace(text[len(robotCmdDelete)+1:])
|
||||||
|
} else {
|
||||||
|
convID = strings.TrimSpace(text[7:])
|
||||||
|
}
|
||||||
|
return h.cmdDelete(platform, userID, convID), true
|
||||||
|
case text == robotCmdVersion || text == "version":
|
||||||
|
return h.cmdVersion(), true
|
||||||
|
default:
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// —————— 企业微信 ——————
|
// —————— 企业微信 ——————
|
||||||
|
|
||||||
// wecomXML 企业微信回调 XML(明文模式下的简化结构;加密模式需先解密再解析)
|
// wecomXML 企业微信回调 XML(明文模式下的简化结构;加密模式需先解密再解析)
|
||||||
@@ -418,14 +431,14 @@ type wecomXML struct {
|
|||||||
Encrypt string `xml:"Encrypt"` // 加密模式下消息在此
|
Encrypt string `xml:"Encrypt"` // 加密模式下消息在此
|
||||||
}
|
}
|
||||||
|
|
||||||
// wecomReplyXML 被动回复 XML
|
// wecomReplyXML 被动回复 XML(仅用于兼容,当前使用手动构造 XML)
|
||||||
type wecomReplyXML struct {
|
type wecomReplyXML struct {
|
||||||
XMLName xml.Name `xml:"xml"`
|
XMLName xml.Name `xml:"xml"`
|
||||||
ToUserName string `xml:"ToUserName"`
|
ToUserName string `xml:"ToUserName"`
|
||||||
FromUserName string `xml:"FromUserName"`
|
FromUserName string `xml:"FromUserName"`
|
||||||
CreateTime int64 `xml:"CreateTime"`
|
CreateTime int64 `xml:"CreateTime"`
|
||||||
MsgType string `xml:"MsgType"`
|
MsgType string `xml:"MsgType"`
|
||||||
Content string `xml:"Content"`
|
Content string `xml:"Content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleWecomGET 企业微信 URL 校验(GET)
|
// HandleWecomGET 企业微信 URL 校验(GET)
|
||||||
@@ -434,15 +447,51 @@ func (h *RobotHandler) HandleWecomGET(c *gin.Context) {
|
|||||||
c.String(http.StatusNotFound, "")
|
c.String(http.StatusNotFound, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Gin 的 Query() 会自动 URL 解码,拿到的就是正确的 base64 字符串
|
||||||
echostr := c.Query("echostr")
|
echostr := c.Query("echostr")
|
||||||
|
msgSignature := c.Query("msg_signature")
|
||||||
|
timestamp := c.Query("timestamp")
|
||||||
|
nonce := c.Query("nonce")
|
||||||
|
|
||||||
|
// 验证签名:将 token、timestamp、nonce、echostr 四个参数排序后拼接计算 SHA1
|
||||||
|
signature := h.signWecomRequest(h.config.Robots.Wecom.Token, timestamp, nonce, echostr)
|
||||||
|
if signature != msgSignature {
|
||||||
|
h.logger.Warn("企业微信 URL 验证签名失败", zap.String("expected", msgSignature), zap.String("got", signature))
|
||||||
|
c.String(http.StatusBadRequest, "invalid signature")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if echostr == "" {
|
if echostr == "" {
|
||||||
c.String(http.StatusBadRequest, "missing echostr")
|
c.String(http.StatusBadRequest, "missing echostr")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 明文模式时企业微信可能直接传 echostr,先直接返回以通过校验
|
|
||||||
|
// 如果配置了 EncodingAESKey,说明是加密模式,需要解密 echostr
|
||||||
|
if h.config.Robots.Wecom.EncodingAESKey != "" {
|
||||||
|
decrypted, err := wecomDecrypt(h.config.Robots.Wecom.EncodingAESKey, echostr)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Warn("企业微信 echostr 解密失败", zap.Error(err))
|
||||||
|
c.String(http.StatusBadRequest, "decrypt failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.String(http.StatusOK, string(decrypted))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 明文模式直接返回 echostr
|
||||||
c.String(http.StatusOK, echostr)
|
c.String(http.StatusOK, echostr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// signWecomRequest 生成企业微信请求签名
|
||||||
|
// 企业微信签名算法:将 token、timestamp、nonce、echostr 四个值排序后拼接成字符串,再计算 SHA1
|
||||||
|
func (h *RobotHandler) signWecomRequest(token, timestamp, nonce, echostr string) string {
|
||||||
|
strs := []string{token, timestamp, nonce, echostr}
|
||||||
|
sort.Strings(strs)
|
||||||
|
s := strings.Join(strs, "")
|
||||||
|
hash := sha1.Sum([]byte(s))
|
||||||
|
return fmt.Sprintf("%x", hash)
|
||||||
|
}
|
||||||
|
|
||||||
// wecomDecrypt 企业微信消息解密(AES-256-CBC,PKCS7,明文格式:16字节随机+4字节长度+消息+corpID)
|
// wecomDecrypt 企业微信消息解密(AES-256-CBC,PKCS7,明文格式:16字节随机+4字节长度+消息+corpID)
|
||||||
func wecomDecrypt(encodingAESKey, encryptedB64 string) ([]byte, error) {
|
func wecomDecrypt(encodingAESKey, encryptedB64 string) ([]byte, error) {
|
||||||
key, err := base64.StdEncoding.DecodeString(encodingAESKey + "=")
|
key, err := base64.StdEncoding.DecodeString(encodingAESKey + "=")
|
||||||
@@ -484,54 +533,228 @@ func wecomDecrypt(encodingAESKey, encryptedB64 string) ([]byte, error) {
|
|||||||
return plain[20 : 20+msgLen], nil
|
return plain[20 : 20+msgLen], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wecomEncrypt 企业微信消息加密(AES-256-CBC,PKCS7,明文格式:16字节随机+4字节长度+消息+corpID)
|
||||||
|
func wecomEncrypt(encodingAESKey, message, corpID string) (string, error) {
|
||||||
|
key, err := base64.StdEncoding.DecodeString(encodingAESKey + "=")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if len(key) != 32 {
|
||||||
|
return "", fmt.Errorf("encoding_aes_key 解码后应为 32 字节")
|
||||||
|
}
|
||||||
|
// 构造明文:16 字节随机 + 4 字节长度 (大端) + 消息 + corpID
|
||||||
|
random := make([]byte, 16)
|
||||||
|
if _, err := rand.Read(random); err != nil {
|
||||||
|
// 降级方案:使用时间戳生成随机数
|
||||||
|
for i := range random {
|
||||||
|
random[i] = byte(time.Now().UnixNano() % 256)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msgLen := len(message)
|
||||||
|
msgBytes := []byte(message)
|
||||||
|
corpBytes := []byte(corpID)
|
||||||
|
plain := make([]byte, 16+4+msgLen+len(corpBytes))
|
||||||
|
copy(plain[:16], random)
|
||||||
|
binary.BigEndian.PutUint32(plain[16:20], uint32(msgLen))
|
||||||
|
copy(plain[20:20+msgLen], msgBytes)
|
||||||
|
copy(plain[20+msgLen:], corpBytes)
|
||||||
|
// PKCS7 填充
|
||||||
|
padding := aes.BlockSize - len(plain)%aes.BlockSize
|
||||||
|
pad := bytes.Repeat([]byte{byte(padding)}, padding)
|
||||||
|
plain = append(plain, pad...)
|
||||||
|
// AES-256-CBC 加密
|
||||||
|
block, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
iv := key[:16]
|
||||||
|
ciphertext := make([]byte, len(plain))
|
||||||
|
mode := cipher.NewCBCEncrypter(block, iv)
|
||||||
|
mode.CryptBlocks(ciphertext, plain)
|
||||||
|
return base64.StdEncoding.EncodeToString(ciphertext), nil
|
||||||
|
}
|
||||||
|
|
||||||
// HandleWecomPOST 企业微信消息回调(POST),支持明文与加密模式
|
// HandleWecomPOST 企业微信消息回调(POST),支持明文与加密模式
|
||||||
func (h *RobotHandler) HandleWecomPOST(c *gin.Context) {
|
func (h *RobotHandler) HandleWecomPOST(c *gin.Context) {
|
||||||
if !h.config.Robots.Wecom.Enabled {
|
if !h.config.Robots.Wecom.Enabled {
|
||||||
|
h.logger.Debug("企业微信机器人未启用,跳过请求")
|
||||||
c.String(http.StatusOK, "")
|
c.String(http.StatusOK, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bodyRaw, _ := io.ReadAll(c.Request.Body)
|
// 从 URL 获取签名参数(加密模式回复时需要用到)
|
||||||
|
timestamp := c.Query("timestamp")
|
||||||
|
nonce := c.Query("nonce")
|
||||||
|
msgSignature := c.Query("msg_signature")
|
||||||
|
|
||||||
|
// 先读取请求体,后续解析/签名验证都会用到
|
||||||
|
bodyRaw, err := io.ReadAll(c.Request.Body)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Warn("企业微信 POST 读取请求体失败", zap.Error(err))
|
||||||
|
c.String(http.StatusOK, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.logger.Debug("企业微信 POST 收到请求", zap.String("body", string(bodyRaw)))
|
||||||
|
|
||||||
|
// 验证请求签名防止伪造。企业微信签名算法同 URL 验证,使用 token、timestamp、nonce、 Encrypt 四个字段
|
||||||
|
if msgSignature != "" {
|
||||||
|
var tmp wecomXML
|
||||||
|
if err := xml.Unmarshal(bodyRaw, &tmp); err == nil {
|
||||||
|
expected := h.signWecomRequest(h.config.Robots.Wecom.Token, timestamp, nonce, tmp.Encrypt)
|
||||||
|
if expected != msgSignature {
|
||||||
|
h.logger.Warn("企业微信 POST 签名验证失败", zap.String("expected", expected), zap.String("got", msgSignature))
|
||||||
|
c.String(http.StatusOK, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body wecomXML
|
var body wecomXML
|
||||||
if err := xml.Unmarshal(bodyRaw, &body); err != nil {
|
if err := xml.Unmarshal(bodyRaw, &body); err != nil {
|
||||||
h.logger.Debug("企业微信 POST 解析 XML 失败", zap.Error(err))
|
h.logger.Warn("企业微信 POST 解析 XML 失败", zap.Error(err))
|
||||||
c.String(http.StatusOK, "")
|
c.String(http.StatusOK, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
h.logger.Debug("企业微信 XML 解析成功", zap.String("ToUserName", body.ToUserName), zap.String("FromUserName", body.FromUserName), zap.String("MsgType", body.MsgType), zap.String("Content", body.Content), zap.String("Encrypt", body.Encrypt))
|
||||||
|
|
||||||
|
// 保存企业 ID(用于明文模式回复)
|
||||||
|
enterpriseID := body.ToUserName
|
||||||
|
|
||||||
// 加密模式:先解密再解析内层 XML
|
// 加密模式:先解密再解析内层 XML
|
||||||
if body.Encrypt != "" && h.config.Robots.Wecom.EncodingAESKey != "" {
|
if body.Encrypt != "" && h.config.Robots.Wecom.EncodingAESKey != "" {
|
||||||
|
h.logger.Debug("企业微信进入加密模式解密流程")
|
||||||
decrypted, err := wecomDecrypt(h.config.Robots.Wecom.EncodingAESKey, body.Encrypt)
|
decrypted, err := wecomDecrypt(h.config.Robots.Wecom.EncodingAESKey, body.Encrypt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logger.Warn("企业微信消息解密失败", zap.Error(err))
|
h.logger.Warn("企业微信消息解密失败", zap.Error(err))
|
||||||
c.String(http.StatusOK, "")
|
c.String(http.StatusOK, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
h.logger.Debug("企业微信解密成功", zap.String("decrypted", string(decrypted)))
|
||||||
if err := xml.Unmarshal(decrypted, &body); err != nil {
|
if err := xml.Unmarshal(decrypted, &body); err != nil {
|
||||||
h.logger.Warn("企业微信解密后 XML 解析失败", zap.Error(err))
|
h.logger.Warn("企业微信解密后 XML 解析失败", zap.Error(err))
|
||||||
c.String(http.StatusOK, "")
|
c.String(http.StatusOK, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
h.logger.Debug("企业微信内层 XML 解析成功", zap.String("FromUserName", body.FromUserName), zap.String("Content", body.Content))
|
||||||
}
|
}
|
||||||
if body.MsgType != "text" {
|
|
||||||
c.XML(http.StatusOK, wecomReplyXML{
|
|
||||||
ToUserName: body.FromUserName,
|
|
||||||
FromUserName: body.ToUserName,
|
|
||||||
CreateTime: time.Now().Unix(),
|
|
||||||
MsgType: "text",
|
|
||||||
Content: "暂仅支持文本消息,请发送文字。",
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
userID := body.FromUserName
|
userID := body.FromUserName
|
||||||
text := strings.TrimSpace(body.Content)
|
text := strings.TrimSpace(body.Content)
|
||||||
reply := h.HandleMessage("wecom", userID, text)
|
|
||||||
// 加密模式需加密回复(此处简化为明文回复;若企业要求加密需再实现加密)
|
// 限制回复内容长度(企业微信限制 2048 字节)
|
||||||
c.XML(http.StatusOK, wecomReplyXML{
|
maxReplyLen := 2000
|
||||||
ToUserName: body.FromUserName,
|
limitReply := func(s string) string {
|
||||||
FromUserName: body.ToUserName,
|
if len(s) > maxReplyLen {
|
||||||
CreateTime: time.Now().Unix(),
|
return s[:maxReplyLen] + "\n\n(内容过长,已截断)"
|
||||||
MsgType: "text",
|
}
|
||||||
Content: reply,
|
return s
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if body.MsgType != "text" {
|
||||||
|
h.logger.Debug("企业微信收到非文本消息", zap.String("MsgType", body.MsgType))
|
||||||
|
h.sendWecomReply(c, userID, enterpriseID, limitReply("暂仅支持文本消息,请发送文字。"), timestamp, nonce)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文本消息:先判断是否为内置命令(如 帮助/列表/新对话 等),这类命令处理很快,可以直接走被动回复,避免依赖主动发送 API。
|
||||||
|
if cmdReply, ok := h.handleRobotCommand("wecom", userID, text); ok {
|
||||||
|
h.logger.Debug("企业微信收到命令消息,走被动回复", zap.String("userID", userID), zap.String("text", text))
|
||||||
|
h.sendWecomReply(c, userID, enterpriseID, limitReply(cmdReply), timestamp, nonce)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.logger.Debug("企业微信开始处理消息(异步 AI)", zap.String("userID", userID), zap.String("text", text))
|
||||||
|
|
||||||
|
// 企业微信被动回复有 5 秒超时限制,而 AI 调用通常超过该时长。
|
||||||
|
// 这里采用推荐做法:立即返回 success(或空串),然后通过主动发送接口推送完整回复。
|
||||||
|
c.String(http.StatusOK, "success")
|
||||||
|
|
||||||
|
// 异步处理消息并通过企业微信主动消息接口发送结果
|
||||||
|
go func() {
|
||||||
|
reply := h.HandleMessage("wecom", userID, text)
|
||||||
|
reply = limitReply(reply)
|
||||||
|
h.logger.Debug("企业微信消息处理完成", zap.String("userID", userID), zap.String("reply", reply))
|
||||||
|
// 调用企业微信 API 主动发送消息
|
||||||
|
h.sendWecomMessageViaAPI(userID, enterpriseID, reply)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// sendWecomReply 发送企业微信回复(加密模式自动加密)
|
||||||
|
// 参数:toUser=用户 ID, fromUser=企业 ID(明文模式)/CorpID(加密模式), content=回复内容,timestamp/nonce=请求参数
|
||||||
|
func (h *RobotHandler) sendWecomReply(c *gin.Context, toUser, fromUser, content, timestamp, nonce string) {
|
||||||
|
// 加密模式:判断 EncodingAESKey 是否配置
|
||||||
|
if h.config.Robots.Wecom.EncodingAESKey != "" {
|
||||||
|
// 加密模式使用 CorpID 进行加密
|
||||||
|
corpID := h.config.Robots.Wecom.CorpID
|
||||||
|
if corpID == "" {
|
||||||
|
h.logger.Warn("企业微信加密模式缺少 CorpID 配置")
|
||||||
|
c.String(http.StatusOK, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构造完整的明文 XML 回复(格式严格按企业微信文档要求)
|
||||||
|
plainResp := fmt.Sprintf(`<xml>
|
||||||
|
<ToUserName><![CDATA[%s]]></ToUserName>
|
||||||
|
<FromUserName><![CDATA[%s]]></FromUserName>
|
||||||
|
<CreateTime>%d</CreateTime>
|
||||||
|
<MsgType><![CDATA[text]]></MsgType>
|
||||||
|
<Content><![CDATA[%s]]></Content>
|
||||||
|
</xml>`, toUser, fromUser, time.Now().Unix(), content)
|
||||||
|
|
||||||
|
encrypted, err := wecomEncrypt(h.config.Robots.Wecom.EncodingAESKey, plainResp, corpID)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Warn("企业微信回复加密失败", zap.Error(err))
|
||||||
|
c.String(http.StatusOK, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 使用请求中的 timestamp/nonce 生成签名(企业微信要求回复时使用与请求相同的 timestamp 和 nonce)
|
||||||
|
msgSignature := h.signWecomRequest(h.config.Robots.Wecom.Token, timestamp, nonce, encrypted)
|
||||||
|
|
||||||
|
h.logger.Debug("企业微信发送加密回复",
|
||||||
|
zap.String("Encrypt", encrypted[:50]+"..."),
|
||||||
|
zap.String("MsgSignature", msgSignature),
|
||||||
|
zap.String("TimeStamp", timestamp),
|
||||||
|
zap.String("Nonce", nonce))
|
||||||
|
|
||||||
|
// 加密模式仅返回 4 个核心字段(企业微信官方要求)
|
||||||
|
xmlResp := fmt.Sprintf(`<xml><Encrypt><![CDATA[%s]]></Encrypt><MsgSignature><![CDATA[%s]]></MsgSignature><TimeStamp><![CDATA[%s]]></TimeStamp><Nonce><![CDATA[%s]]></Nonce></xml>`, encrypted, msgSignature, timestamp, nonce)
|
||||||
|
// also log the final response body so we can cross-check with the
|
||||||
|
// network traffic or developer console
|
||||||
|
h.logger.Debug("企业微信加密回复包", zap.String("xml", xmlResp))
|
||||||
|
// for additional confidence, decrypt the payload ourselves and log it
|
||||||
|
if dec, err2 := wecomDecrypt(h.config.Robots.Wecom.EncodingAESKey, encrypted); err2 == nil {
|
||||||
|
h.logger.Debug("企业微信加密回复解密检查", zap.String("plain", string(dec)))
|
||||||
|
} else {
|
||||||
|
h.logger.Warn("企业微信加密回复解密检查失败", zap.Error(err2))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用 c.Writer.Write 直接写入响应,避免 c.String 的转义问题
|
||||||
|
c.Writer.WriteHeader(http.StatusOK)
|
||||||
|
// use text/xml as that's what WeCom examples show
|
||||||
|
c.Writer.Header().Set("Content-Type", "text/xml; charset=utf-8")
|
||||||
|
_, _ = c.Writer.Write([]byte(xmlResp))
|
||||||
|
h.logger.Debug("企业微信加密回复已发送")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 明文模式
|
||||||
|
h.logger.Debug("企业微信发送明文回复", zap.String("ToUserName", toUser), zap.String("FromUserName", fromUser), zap.String("Content", content[:50]+"..."))
|
||||||
|
|
||||||
|
// 手动构造 XML 响应(使用 CDATA 包裹所有字段,并包含 AgentID)
|
||||||
|
xmlResp := fmt.Sprintf(`<xml>
|
||||||
|
<ToUserName><![CDATA[%s]]></ToUserName>
|
||||||
|
<FromUserName><![CDATA[%s]]></FromUserName>
|
||||||
|
<CreateTime>%d</CreateTime>
|
||||||
|
<MsgType><![CDATA[text]]></MsgType>
|
||||||
|
<Content><![CDATA[%s]]></Content>
|
||||||
|
</xml>`, toUser, fromUser, time.Now().Unix(), content)
|
||||||
|
|
||||||
|
// log the exact plaintext response for debugging
|
||||||
|
h.logger.Debug("企业微信明文回复包", zap.String("xml", xmlResp))
|
||||||
|
|
||||||
|
// use text/xml as recommended by WeCom docs
|
||||||
|
c.Header("Content-Type", "text/xml; charset=utf-8")
|
||||||
|
c.String(http.StatusOK, xmlResp)
|
||||||
|
h.logger.Debug("企业微信明文回复已发送")
|
||||||
}
|
}
|
||||||
|
|
||||||
// —————— 测试接口(需登录,用于验证机器人逻辑,无需钉钉/飞书客户端) ——————
|
// —————— 测试接口(需登录,用于验证机器人逻辑,无需钉钉/飞书客户端) ——————
|
||||||
@@ -562,6 +785,87 @@ func (h *RobotHandler) HandleRobotTest(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, gin.H{"reply": reply})
|
c.JSON(http.StatusOK, gin.H{"reply": reply})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sendWecomMessageViaAPI 通过企业微信 API 主动发送消息(用于异步处理后的结果发送)
|
||||||
|
func (h *RobotHandler) sendWecomMessageViaAPI(toUser, toParty, content string) {
|
||||||
|
if !h.config.Robots.Wecom.Enabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
secret := h.config.Robots.Wecom.Secret
|
||||||
|
corpID := h.config.Robots.Wecom.CorpID
|
||||||
|
agentID := h.config.Robots.Wecom.AgentID
|
||||||
|
|
||||||
|
if secret == "" || corpID == "" {
|
||||||
|
h.logger.Warn("企业微信主动 API 缺少 secret 或 corpID 配置")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 第 1 步:获取 access_token
|
||||||
|
tokenURL := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s", corpID, secret)
|
||||||
|
resp, err := http.Get(tokenURL)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Warn("企业微信获取 token 失败", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var tokenResp struct {
|
||||||
|
AccessToken string `json:"access_token"`
|
||||||
|
ErrCode int `json:"errcode"`
|
||||||
|
ErrMsg string `json:"errmsg"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&tokenResp); err != nil {
|
||||||
|
h.logger.Warn("企业微信 token 响应解析失败", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if tokenResp.ErrCode != 0 {
|
||||||
|
h.logger.Warn("企业微信 token 获取错误", zap.String("errmsg", tokenResp.ErrMsg), zap.Int("errcode", tokenResp.ErrCode))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 第 2 步:构造发送消息请求
|
||||||
|
msgReq := map[string]interface{}{
|
||||||
|
"touser": toUser,
|
||||||
|
"msgtype": "text",
|
||||||
|
"agentid": agentID,
|
||||||
|
"text": map[string]interface{}{
|
||||||
|
"content": content,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
msgBody, err := json.Marshal(msgReq)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Warn("企业微信消息序列化失败", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 第 3 步:发送消息
|
||||||
|
sendURL := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s", tokenResp.AccessToken)
|
||||||
|
msgResp, err := http.Post(sendURL, "application/json", bytes.NewReader(msgBody))
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Warn("企业微信主动发送消息失败", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer msgResp.Body.Close()
|
||||||
|
|
||||||
|
var sendResp struct {
|
||||||
|
ErrCode int `json:"errcode"`
|
||||||
|
ErrMsg string `json:"errmsg"`
|
||||||
|
InvalidUser string `json:"invaliduser"`
|
||||||
|
MsgID string `json:"msgid"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(msgResp.Body).Decode(&sendResp); err != nil {
|
||||||
|
h.logger.Warn("企业微信发送响应解析失败", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if sendResp.ErrCode == 0 {
|
||||||
|
h.logger.Debug("企业微信主动发送消息成功", zap.String("msgid", sendResp.MsgID))
|
||||||
|
} else {
|
||||||
|
h.logger.Warn("企业微信主动发送消息失败", zap.String("errmsg", sendResp.ErrMsg), zap.Int("errcode", sendResp.ErrCode), zap.String("invaliduser", sendResp.InvalidUser))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// —————— 钉钉 ——————
|
// —————— 钉钉 ——————
|
||||||
|
|
||||||
// HandleDingtalkPOST 钉钉事件回调(流式接入等);当前为占位,返回 200
|
// HandleDingtalkPOST 钉钉事件回调(流式接入等);当前为占位,返回 200
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ func (h *TerminalHandler) RunCommand(c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
cmd = exec.CommandContext(ctx, shell, "-c", cmdStr)
|
cmd = exec.CommandContext(ctx, shell, "-c", cmdStr)
|
||||||
// 无 TTY 时设置 COLUMNS/TERM,使 ping 等工具的 usage 排版与真实终端一致
|
// 无 TTY 时设置 COLUMNS/TERM,使 ping 等工具的 usage 排版与真实终端一致
|
||||||
cmd.Env = append(os.Environ(), "COLUMNS=120", "LINES=40", "TERM=xterm-256color")
|
cmd.Env = append(os.Environ(), "COLUMNS=256", "LINES=40", "TERM=xterm-256color")
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Cwd != "" {
|
if req.Cwd != "" {
|
||||||
@@ -218,7 +218,7 @@ func (h *TerminalHandler) RunCommandStream(c *gin.Context) {
|
|||||||
cmd = exec.CommandContext(ctx, "cmd", "/c", cmdStr)
|
cmd = exec.CommandContext(ctx, "cmd", "/c", cmdStr)
|
||||||
} else {
|
} else {
|
||||||
cmd = exec.CommandContext(ctx, shell, "-c", cmdStr)
|
cmd = exec.CommandContext(ctx, shell, "-c", cmdStr)
|
||||||
cmd.Env = append(os.Environ(), "COLUMNS=120", "LINES=40", "TERM=xterm-256color")
|
cmd.Env = append(os.Environ(), "COLUMNS=256", "LINES=40", "TERM=xterm-256color")
|
||||||
}
|
}
|
||||||
if req.Cwd != "" {
|
if req.Cwd != "" {
|
||||||
absCwd, err := filepath.Abs(req.Cwd)
|
absCwd, err := filepath.Abs(req.Cwd)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/creack/pty"
|
"github.com/creack/pty"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ptyCols = 120
|
const ptyCols = 256
|
||||||
const ptyRows = 40
|
const ptyRows = 40
|
||||||
|
|
||||||
// runCommandStreamImpl 在 Unix 下用 PTY 执行,使 ping 等命令按终端宽度排版(isatty 为真)
|
// runCommandStreamImpl 在 Unix 下用 PTY 执行,使 ping 等命令按终端宽度排版(isatty 为真)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func (h *TerminalHandler) RunCommandWS(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
cmd := exec.Command(shell)
|
cmd := exec.Command(shell)
|
||||||
cmd.Env = append(os.Environ(),
|
cmd.Env = append(os.Environ(),
|
||||||
"COLUMNS=120",
|
"COLUMNS=256",
|
||||||
"LINES=40",
|
"LINES=40",
|
||||||
"TERM=xterm-256color",
|
"TERM=xterm-256color",
|
||||||
)
|
)
|
||||||
@@ -55,7 +55,7 @@ func (h *TerminalHandler) RunCommandWS(c *gin.Context) {
|
|||||||
for {
|
for {
|
||||||
n, err := ptmx.Read(buf)
|
n, err := ptmx.Read(buf)
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
_ = conn.WriteMessage(websocket.TextMessage, buf[:n])
|
_ = conn.WriteMessage(websocket.BinaryMessage, buf[:n])
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
|
|||||||
+149
-31
@@ -6,39 +6,75 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"cyberstrike-ai/internal/config"
|
"cyberstrike-ai/internal/config"
|
||||||
"cyberstrike-ai/internal/openai"
|
"cyberstrike-ai/internal/openai"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Embedder 文本嵌入器
|
// Embedder 文本嵌入器
|
||||||
type Embedder struct {
|
type Embedder struct {
|
||||||
openAIClient *openai.Client
|
openAIClient *openai.Client
|
||||||
config *config.KnowledgeConfig
|
config *config.KnowledgeConfig
|
||||||
openAIConfig *config.OpenAIConfig // 用于获取API Key
|
openAIConfig *config.OpenAIConfig // 用于获取 API Key
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
|
rateLimiter *rate.Limiter // 速率限制器
|
||||||
|
rateLimitDelay time.Duration // 请求间隔时间
|
||||||
|
maxRetries int // 最大重试次数
|
||||||
|
retryDelay time.Duration // 重试间隔
|
||||||
|
mu sync.Mutex // 保护 rateLimiter
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEmbedder 创建新的嵌入器
|
// NewEmbedder 创建新的嵌入器
|
||||||
func NewEmbedder(cfg *config.KnowledgeConfig, openAIConfig *config.OpenAIConfig, openAIClient *openai.Client, logger *zap.Logger) *Embedder {
|
func NewEmbedder(cfg *config.KnowledgeConfig, openAIConfig *config.OpenAIConfig, openAIClient *openai.Client, logger *zap.Logger) *Embedder {
|
||||||
|
// 初始化速率限制器
|
||||||
|
var rateLimiter *rate.Limiter
|
||||||
|
var rateLimitDelay time.Duration
|
||||||
|
|
||||||
|
// 如果配置了 MaxRPM,根据 RPM 计算速率限制
|
||||||
|
if cfg.Indexing.MaxRPM > 0 {
|
||||||
|
rpm := cfg.Indexing.MaxRPM
|
||||||
|
rateLimiter = rate.NewLimiter(rate.Every(time.Minute/time.Duration(rpm)), rpm)
|
||||||
|
logger.Info("知识库索引速率限制已启用", zap.Int("maxRPM", rpm))
|
||||||
|
} else if cfg.Indexing.RateLimitDelayMs > 0 {
|
||||||
|
// 如果没有配置 MaxRPM 但配置了固定延迟,使用固定延迟模式
|
||||||
|
rateLimitDelay = time.Duration(cfg.Indexing.RateLimitDelayMs) * time.Millisecond
|
||||||
|
logger.Info("知识库索引固定延迟已启用", zap.Duration("delay", rateLimitDelay))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重试配置
|
||||||
|
maxRetries := 3
|
||||||
|
retryDelay := 1000 * time.Millisecond
|
||||||
|
if cfg.Indexing.MaxRetries > 0 {
|
||||||
|
maxRetries = cfg.Indexing.MaxRetries
|
||||||
|
}
|
||||||
|
if cfg.Indexing.RetryDelayMs > 0 {
|
||||||
|
retryDelay = time.Duration(cfg.Indexing.RetryDelayMs) * time.Millisecond
|
||||||
|
}
|
||||||
|
|
||||||
return &Embedder{
|
return &Embedder{
|
||||||
openAIClient: openAIClient,
|
openAIClient: openAIClient,
|
||||||
config: cfg,
|
config: cfg,
|
||||||
openAIConfig: openAIConfig,
|
openAIConfig: openAIConfig,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
rateLimiter: rateLimiter,
|
||||||
|
rateLimitDelay: rateLimitDelay,
|
||||||
|
maxRetries: maxRetries,
|
||||||
|
retryDelay: retryDelay,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmbeddingRequest OpenAI嵌入请求
|
// EmbeddingRequest OpenAI 嵌入请求
|
||||||
type EmbeddingRequest struct {
|
type EmbeddingRequest struct {
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
Input []string `json:"input"`
|
Input []string `json:"input"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmbeddingResponse OpenAI嵌入响应
|
// EmbeddingResponse OpenAI 嵌入响应
|
||||||
type EmbeddingResponse struct {
|
type EmbeddingResponse struct {
|
||||||
Data []EmbeddingData `json:"data"`
|
Data []EmbeddingData `json:"data"`
|
||||||
Error *EmbeddingError `json:"error,omitempty"`
|
Error *EmbeddingError `json:"error,omitempty"`
|
||||||
@@ -56,12 +92,69 @@ type EmbeddingError struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmbedText 对文本进行嵌入
|
// waitRateLimiter 等待速率限制器
|
||||||
func (e *Embedder) EmbedText(ctx context.Context, text string) ([]float32, error) {
|
func (e *Embedder) waitRateLimiter() {
|
||||||
if e.openAIClient == nil {
|
e.mu.Lock()
|
||||||
return nil, fmt.Errorf("OpenAI客户端未初始化")
|
defer e.mu.Unlock()
|
||||||
|
|
||||||
|
if e.rateLimiter != nil {
|
||||||
|
// 等待令牌
|
||||||
|
ctx := context.Background()
|
||||||
|
if err := e.rateLimiter.Wait(ctx); err != nil {
|
||||||
|
e.logger.Warn("速率限制器等待失败", zap.Error(err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.rateLimitDelay > 0 {
|
||||||
|
time.Sleep(e.rateLimitDelay)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmbedText 对文本进行嵌入(带重试和速率限制)
|
||||||
|
func (e *Embedder) EmbedText(ctx context.Context, text string) ([]float32, error) {
|
||||||
|
if e.openAIClient == nil {
|
||||||
|
return nil, fmt.Errorf("OpenAI 客户端未初始化")
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastErr error
|
||||||
|
for attempt := 0; attempt < e.maxRetries; attempt++ {
|
||||||
|
// 速率限制
|
||||||
|
if attempt > 0 {
|
||||||
|
// 重试时等待更长时间
|
||||||
|
waitTime := e.retryDelay * time.Duration(attempt)
|
||||||
|
e.logger.Debug("重试前等待", zap.Int("attempt", attempt+1), zap.Duration("waitTime", waitTime))
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil, ctx.Err()
|
||||||
|
case <-time.After(waitTime):
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
e.waitRateLimiter()
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := e.doEmbedText(ctx, text)
|
||||||
|
if err == nil {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
lastErr = err
|
||||||
|
|
||||||
|
// 检查是否是可重试的错误(429 速率限制、5xx 服务器错误、网络错误)
|
||||||
|
if !e.isRetryableError(err) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
e.logger.Debug("嵌入请求失败,准备重试",
|
||||||
|
zap.Int("attempt", attempt+1),
|
||||||
|
zap.Int("maxRetries", e.maxRetries),
|
||||||
|
zap.Error(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("达到最大重试次数 (%d): %v", e.maxRetries, lastErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// doEmbedText 执行实际的嵌入请求(内部方法)
|
||||||
|
func (e *Embedder) doEmbedText(ctx context.Context, text string) ([]float32, error) {
|
||||||
// 使用配置的嵌入模型
|
// 使用配置的嵌入模型
|
||||||
model := e.config.Embedding.Model
|
model := e.config.Embedding.Model
|
||||||
if model == "" {
|
if model == "" {
|
||||||
@@ -73,7 +166,7 @@ func (e *Embedder) EmbedText(ctx context.Context, text string) ([]float32, error
|
|||||||
Input: []string{text},
|
Input: []string{text},
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理baseURL:去除前后空格和尾部斜杠
|
// 清理 baseURL:去除前后空格和尾部斜杠
|
||||||
baseURL := strings.TrimSpace(e.config.Embedding.BaseURL)
|
baseURL := strings.TrimSpace(e.config.Embedding.BaseURL)
|
||||||
baseURL = strings.TrimSuffix(baseURL, "/")
|
baseURL = strings.TrimSuffix(baseURL, "/")
|
||||||
if baseURL == "" {
|
if baseURL == "" {
|
||||||
@@ -83,24 +176,24 @@ func (e *Embedder) EmbedText(ctx context.Context, text string) ([]float32, error
|
|||||||
// 构建请求
|
// 构建请求
|
||||||
body, err := json.Marshal(req)
|
body, err := json.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("序列化请求失败: %w", err)
|
return nil, fmt.Errorf("序列化请求失败:%w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
requestURL := baseURL + "/embeddings"
|
requestURL := baseURL + "/embeddings"
|
||||||
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, requestURL, strings.NewReader(string(body)))
|
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, requestURL, strings.NewReader(string(body)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("创建请求失败: %w", err)
|
return nil, fmt.Errorf("创建请求失败:%w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
httpReq.Header.Set("Content-Type", "application/json")
|
httpReq.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
// 使用配置的API Key,如果没有则使用OpenAI配置的
|
// 使用配置的 API Key,如果没有则使用 OpenAI 配置的
|
||||||
apiKey := strings.TrimSpace(e.config.Embedding.APIKey)
|
apiKey := strings.TrimSpace(e.config.Embedding.APIKey)
|
||||||
if apiKey == "" && e.openAIConfig != nil {
|
if apiKey == "" && e.openAIConfig != nil {
|
||||||
apiKey = e.openAIConfig.APIKey
|
apiKey = e.openAIConfig.APIKey
|
||||||
}
|
}
|
||||||
if apiKey == "" {
|
if apiKey == "" {
|
||||||
return nil, fmt.Errorf("API Key未配置")
|
return nil, fmt.Errorf("API Key 未配置")
|
||||||
}
|
}
|
||||||
httpReq.Header.Set("Authorization", "Bearer "+apiKey)
|
httpReq.Header.Set("Authorization", "Bearer "+apiKey)
|
||||||
|
|
||||||
@@ -110,7 +203,7 @@ func (e *Embedder) EmbedText(ctx context.Context, text string) ([]float32, error
|
|||||||
}
|
}
|
||||||
resp, err := httpClient.Do(httpReq)
|
resp, err := httpClient.Do(httpReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("发送请求失败: %w", err)
|
return nil, fmt.Errorf("发送请求失败:%w", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
@@ -132,7 +225,7 @@ func (e *Embedder) EmbedText(ctx context.Context, text string) ([]float32, error
|
|||||||
if len(requestBodyPreview) > 200 {
|
if len(requestBodyPreview) > 200 {
|
||||||
requestBodyPreview = requestBodyPreview[:200] + "..."
|
requestBodyPreview = requestBodyPreview[:200] + "..."
|
||||||
}
|
}
|
||||||
e.logger.Debug("嵌入API请求",
|
e.logger.Debug("嵌入 API 请求",
|
||||||
zap.String("url", httpReq.URL.String()),
|
zap.String("url", httpReq.URL.String()),
|
||||||
zap.String("model", model),
|
zap.String("model", model),
|
||||||
zap.String("requestBody", requestBodyPreview),
|
zap.String("requestBody", requestBodyPreview),
|
||||||
@@ -148,12 +241,12 @@ func (e *Embedder) EmbedText(ctx context.Context, text string) ([]float32, error
|
|||||||
if len(bodyPreview) > 500 {
|
if len(bodyPreview) > 500 {
|
||||||
bodyPreview = bodyPreview[:500] + "..."
|
bodyPreview = bodyPreview[:500] + "..."
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("解析响应失败 (URL: %s, 状态码: %d, 响应长度: %d字节): %w\n请求体: %s\n响应内容预览: %s",
|
return nil, fmt.Errorf("解析响应失败 (URL: %s, 状态码:%d, 响应长度:%d字节): %w\n请求体:%s\n响应内容预览:%s",
|
||||||
requestURL, resp.StatusCode, len(bodyBytes), err, requestBodyPreview, bodyPreview)
|
requestURL, resp.StatusCode, len(bodyBytes), err, requestBodyPreview, bodyPreview)
|
||||||
}
|
}
|
||||||
|
|
||||||
if embeddingResp.Error != nil {
|
if embeddingResp.Error != nil {
|
||||||
return nil, fmt.Errorf("OpenAI API错误 (状态码: %d): 类型=%s, 消息=%s",
|
return nil, fmt.Errorf("OpenAI API 错误 (状态码:%d): 类型=%s, 消息=%s",
|
||||||
resp.StatusCode, embeddingResp.Error.Type, embeddingResp.Error.Message)
|
resp.StatusCode, embeddingResp.Error.Type, embeddingResp.Error.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +255,7 @@ func (e *Embedder) EmbedText(ctx context.Context, text string) ([]float32, error
|
|||||||
if len(bodyPreview) > 500 {
|
if len(bodyPreview) > 500 {
|
||||||
bodyPreview = bodyPreview[:500] + "..."
|
bodyPreview = bodyPreview[:500] + "..."
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("HTTP请求失败 (URL: %s, 状态码: %d): 响应内容=%s", requestURL, resp.StatusCode, bodyPreview)
|
return nil, fmt.Errorf("HTTP 请求失败 (URL: %s, 状态码:%d): 响应内容=%s", requestURL, resp.StatusCode, bodyPreview)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(embeddingResp.Data) == 0 {
|
if len(embeddingResp.Data) == 0 {
|
||||||
@@ -170,11 +263,11 @@ func (e *Embedder) EmbedText(ctx context.Context, text string) ([]float32, error
|
|||||||
if len(bodyPreview) > 500 {
|
if len(bodyPreview) > 500 {
|
||||||
bodyPreview = bodyPreview[:500] + "..."
|
bodyPreview = bodyPreview[:500] + "..."
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("未收到嵌入数据 (状态码: %d, 响应长度: %d字节)\n响应内容: %s",
|
return nil, fmt.Errorf("未收到嵌入数据 (状态码:%d, 响应长度:%d字节)\n响应内容:%s",
|
||||||
resp.StatusCode, len(bodyBytes), bodyPreview)
|
resp.StatusCode, len(bodyBytes), bodyPreview)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换为float32
|
// 转换为 float32
|
||||||
embedding := make([]float32, len(embeddingResp.Data[0].Embedding))
|
embedding := make([]float32, len(embeddingResp.Data[0].Embedding))
|
||||||
for i, v := range embeddingResp.Data[0].Embedding {
|
for i, v := range embeddingResp.Data[0].Embedding {
|
||||||
embedding[i] = float32(v)
|
embedding[i] = float32(v)
|
||||||
@@ -183,23 +276,48 @@ func (e *Embedder) EmbedText(ctx context.Context, text string) ([]float32, error
|
|||||||
return embedding, nil
|
return embedding, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isRetryableError 判断是否是可重试的错误
|
||||||
|
func (e *Embedder) isRetryableError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
errStr := err.Error()
|
||||||
|
|
||||||
|
// 429 速率限制错误
|
||||||
|
if strings.Contains(errStr, "429") || strings.Contains(errStr, "rate limit") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5xx 服务器错误
|
||||||
|
if strings.Contains(errStr, "500") || strings.Contains(errStr, "502") ||
|
||||||
|
strings.Contains(errStr, "503") || strings.Contains(errStr, "504") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 网络错误
|
||||||
|
if strings.Contains(errStr, "timeout") || strings.Contains(errStr, "connection") ||
|
||||||
|
strings.Contains(errStr, "network") || strings.Contains(errStr, "EOF") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// EmbedTexts 批量嵌入文本
|
// EmbedTexts 批量嵌入文本
|
||||||
func (e *Embedder) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error) {
|
func (e *Embedder) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error) {
|
||||||
if len(texts) == 0 {
|
if len(texts) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenAI API支持批量,但为了简单起见,我们逐个处理
|
|
||||||
// 实际可以使用批量API以提高效率
|
|
||||||
embeddings := make([][]float32, len(texts))
|
embeddings := make([][]float32, len(texts))
|
||||||
for i, text := range texts {
|
for i, text := range texts {
|
||||||
embedding, err := e.EmbedText(ctx, text)
|
embedding, err := e.EmbedText(ctx, text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("嵌入文本[%d]失败: %w", i, err)
|
return nil, fmt.Errorf("嵌入文本 [%d] 失败:%w", i, err)
|
||||||
}
|
}
|
||||||
embeddings[i] = embedding
|
embeddings[i] = embedding
|
||||||
}
|
}
|
||||||
|
|
||||||
return embeddings, nil
|
return embeddings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+382
-98
@@ -10,56 +10,133 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"cyberstrike-ai/internal/config"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Indexer 索引器,负责将知识项分块并向量化
|
// Indexer 索引器,负责将知识项分块并向量化
|
||||||
type Indexer struct {
|
type Indexer struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
embedder *Embedder
|
embedder *Embedder
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
chunkSize int // 每个块的最大token数(估算)
|
chunkSize int // 每个块的最大 token 数(估算)
|
||||||
overlap int // 块之间的重叠token数
|
overlap int // 块之间的重叠 token 数
|
||||||
|
maxChunks int // 单个知识项的最大块数量(0 表示不限制)
|
||||||
|
|
||||||
// 错误跟踪
|
// 错误跟踪
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
lastError string // 最近一次错误信息
|
lastError string // 最近一次错误信息
|
||||||
lastErrorTime time.Time // 最近一次错误时间
|
lastErrorTime time.Time // 最近一次错误时间
|
||||||
errorCount int // 连续错误计数
|
errorCount int // 连续错误计数
|
||||||
|
|
||||||
|
// 重建索引状态跟踪
|
||||||
|
rebuildMu sync.RWMutex
|
||||||
|
isRebuilding bool // 是否正在重建索引
|
||||||
|
rebuildTotalItems int // 重建总项数
|
||||||
|
rebuildCurrent int // 当前已处理项数
|
||||||
|
rebuildFailed int // 重建失败项数
|
||||||
|
rebuildStartTime time.Time // 重建开始时间
|
||||||
|
rebuildLastItemID string // 最近处理的项 ID
|
||||||
|
rebuildLastChunks int // 最近处理的项的分块数
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIndexer 创建新的索引器
|
// NewIndexer 创建新的索引器
|
||||||
func NewIndexer(db *sql.DB, embedder *Embedder, logger *zap.Logger) *Indexer {
|
func NewIndexer(db *sql.DB, embedder *Embedder, logger *zap.Logger, indexingCfg *config.IndexingConfig) *Indexer {
|
||||||
|
chunkSize := 512
|
||||||
|
overlap := 50
|
||||||
|
maxChunks := 0
|
||||||
|
if indexingCfg != nil {
|
||||||
|
if indexingCfg.ChunkSize > 0 {
|
||||||
|
chunkSize = indexingCfg.ChunkSize
|
||||||
|
}
|
||||||
|
if indexingCfg.ChunkOverlap >= 0 {
|
||||||
|
overlap = indexingCfg.ChunkOverlap
|
||||||
|
}
|
||||||
|
if indexingCfg.MaxChunksPerItem > 0 {
|
||||||
|
maxChunks = indexingCfg.MaxChunksPerItem
|
||||||
|
}
|
||||||
|
}
|
||||||
return &Indexer{
|
return &Indexer{
|
||||||
db: db,
|
db: db,
|
||||||
embedder: embedder,
|
embedder: embedder,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
chunkSize: 512, // 默认512 tokens
|
chunkSize: chunkSize,
|
||||||
overlap: 50, // 默认50 tokens重叠
|
overlap: overlap,
|
||||||
|
maxChunks: maxChunks,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChunkText 将文本分块(支持重叠)
|
// ChunkText 将文本分块(支持重叠,保留标题上下文)
|
||||||
func (idx *Indexer) ChunkText(text string) []string {
|
func (idx *Indexer) ChunkText(text string) []string {
|
||||||
// 按Markdown标题分割
|
// 按 Markdown 标题分割,获取带标题的块
|
||||||
chunks := idx.splitByMarkdownHeaders(text)
|
sections := idx.splitByMarkdownHeadersWithContent(text)
|
||||||
|
|
||||||
// 如果块太大,进一步分割
|
// 处理每个块
|
||||||
result := make([]string, 0)
|
result := make([]string, 0)
|
||||||
for _, chunk := range chunks {
|
for _, section := range sections {
|
||||||
if idx.estimateTokens(chunk) <= idx.chunkSize {
|
// 构建父级标题路径(不包含最后一级标题,因为内容中已经包含)
|
||||||
result = append(result, chunk)
|
// 例如:["# A", "## B", "### C"] -> "[# A > ## B]"
|
||||||
|
var parentHeaderPath string
|
||||||
|
if len(section.HeaderPath) > 1 {
|
||||||
|
parentHeaderPath = strings.Join(section.HeaderPath[:len(section.HeaderPath)-1], " > ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取内容的第一行作为标题(如 "# Prompt Injection")
|
||||||
|
firstLine, remainingContent := extractFirstLine(section.Content)
|
||||||
|
|
||||||
|
// 如果剩余内容为空或只有空白,说明这个块只有标题没有正文,跳过
|
||||||
|
if strings.TrimSpace(remainingContent) == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果块太大,进一步分割
|
||||||
|
if idx.estimateTokens(section.Content) <= idx.chunkSize {
|
||||||
|
// 块大小合适,添加父级标题前缀
|
||||||
|
if parentHeaderPath != "" {
|
||||||
|
result = append(result, fmt.Sprintf("[%s] %s", parentHeaderPath, section.Content))
|
||||||
|
} else {
|
||||||
|
result = append(result, section.Content)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 按段落分割
|
// 块太大,按子标题或段落分割,保持标题上下文
|
||||||
subChunks := idx.splitByParagraphs(chunk)
|
// 首先尝试按子标题分割(保留子标题结构)
|
||||||
for _, subChunk := range subChunks {
|
subSections := idx.splitBySubHeaders(section.Content, firstLine, parentHeaderPath)
|
||||||
if idx.estimateTokens(subChunk) <= idx.chunkSize {
|
if len(subSections) > 1 {
|
||||||
result = append(result, subChunk)
|
// 成功按子标题分割,递归处理每个子块
|
||||||
} else {
|
for _, sub := range subSections {
|
||||||
// 按句子分割(支持重叠)
|
if idx.estimateTokens(sub) <= idx.chunkSize {
|
||||||
chunksWithOverlap := idx.splitBySentencesWithOverlap(subChunk)
|
result = append(result, sub)
|
||||||
result = append(result, chunksWithOverlap...)
|
} else {
|
||||||
|
// 子块仍然太大,按段落分割(保留标题前缀)
|
||||||
|
paragraphs := idx.splitByParagraphsWithHeader(sub, parentHeaderPath)
|
||||||
|
for _, para := range paragraphs {
|
||||||
|
if idx.estimateTokens(para) <= idx.chunkSize {
|
||||||
|
result = append(result, para)
|
||||||
|
} else {
|
||||||
|
// 段落仍太大,按句子分割
|
||||||
|
sentenceChunks := idx.splitBySentencesWithOverlap(para)
|
||||||
|
for _, chunk := range sentenceChunks {
|
||||||
|
result = append(result, chunk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 没有子标题,按段落分割(保留标题前缀)
|
||||||
|
paragraphs := idx.splitByParagraphsWithHeader(section.Content, parentHeaderPath)
|
||||||
|
for _, para := range paragraphs {
|
||||||
|
if idx.estimateTokens(para) <= idx.chunkSize {
|
||||||
|
result = append(result, para)
|
||||||
|
} else {
|
||||||
|
// 段落仍太大,按句子分割
|
||||||
|
sentenceChunks := idx.splitBySentencesWithOverlap(para)
|
||||||
|
for _, chunk := range sentenceChunks {
|
||||||
|
result = append(result, chunk)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,43 +145,183 @@ func (idx *Indexer) ChunkText(text string) []string {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// splitByMarkdownHeaders 按Markdown标题分割
|
// extractFirstLine 提取第一行内容和剩余内容
|
||||||
func (idx *Indexer) splitByMarkdownHeaders(text string) []string {
|
func extractFirstLine(content string) (firstLine, remaining string) {
|
||||||
// 匹配Markdown标题 (# ## ### 等)
|
lines := strings.SplitN(content, "\n", 2)
|
||||||
|
if len(lines) == 0 {
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
if len(lines) == 1 {
|
||||||
|
return lines[0], ""
|
||||||
|
}
|
||||||
|
return lines[0], lines[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// splitBySubHeaders 尝试按子标题分割内容(用于处理大块内容)
|
||||||
|
// headerPrefix 是父级标题路径,用于添加到每个子块
|
||||||
|
func (idx *Indexer) splitBySubHeaders(content, headerPrefix, parentPath string) []string {
|
||||||
|
// 匹配 Markdown 子标题(## 及以上)
|
||||||
|
subHeaderRegex := regexp.MustCompile(`(?m)^#{2,6}\s+.+$`)
|
||||||
|
matches := subHeaderRegex.FindAllStringIndex(content, -1)
|
||||||
|
|
||||||
|
if len(matches) == 0 {
|
||||||
|
// 没有子标题,返回原始内容
|
||||||
|
return []string{content}
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]string, 0, len(matches))
|
||||||
|
for i, match := range matches {
|
||||||
|
start := match[0]
|
||||||
|
nextStart := len(content)
|
||||||
|
if i+1 < len(matches) {
|
||||||
|
nextStart = matches[i+1][0]
|
||||||
|
}
|
||||||
|
|
||||||
|
subContent := strings.TrimSpace(content[start:nextStart])
|
||||||
|
|
||||||
|
// 添加父级路径前缀
|
||||||
|
if parentPath != "" {
|
||||||
|
result = append(result, fmt.Sprintf("[%s] %s", parentPath, subContent))
|
||||||
|
} else {
|
||||||
|
result = append(result, subContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// splitByParagraphsWithHeader 按段落分割,每个段落添加标题前缀(用于保持上下文)
|
||||||
|
func (idx *Indexer) splitByParagraphsWithHeader(content, parentPath string) []string {
|
||||||
|
// 提取第一行作为标题
|
||||||
|
firstLine, _ := extractFirstLine(content)
|
||||||
|
|
||||||
|
paragraphs := strings.Split(content, "\n\n")
|
||||||
|
result := make([]string, 0)
|
||||||
|
|
||||||
|
for i, p := range paragraphs {
|
||||||
|
trimmed := strings.TrimSpace(p)
|
||||||
|
if trimmed == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过滤掉只有标题的段落(没有实际内容)
|
||||||
|
if strings.TrimSpace(trimmed) == strings.TrimSpace(firstLine) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 第一个段落已经包含标题,不需要重复添加
|
||||||
|
if i == 0 && strings.Contains(trimmed, firstLine) {
|
||||||
|
if parentPath != "" {
|
||||||
|
result = append(result, fmt.Sprintf("[%s] %s", parentPath, trimmed))
|
||||||
|
} else {
|
||||||
|
result = append(result, trimmed)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 其他段落添加标题前缀以保持上下文
|
||||||
|
if parentPath != "" {
|
||||||
|
result = append(result, fmt.Sprintf("[%s] %s\n%s", parentPath, firstLine, trimmed))
|
||||||
|
} else {
|
||||||
|
result = append(result, fmt.Sprintf("%s\n%s", firstLine, trimmed))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// Section 表示一个带标题路径的文本块
|
||||||
|
type Section struct {
|
||||||
|
HeaderPath []string // 标题路径(如 ["# SQL 注入", "## 检测方法"])
|
||||||
|
Content string // 块内容
|
||||||
|
}
|
||||||
|
|
||||||
|
// splitByMarkdownHeadersWithContent 按 Markdown 标题分割,返回带标题路径的块
|
||||||
|
// 每个块的内容包含自己的标题,用于向量化检索
|
||||||
|
//
|
||||||
|
// 例如,对于以下 Markdown:
|
||||||
|
// # Prompt Injection
|
||||||
|
// 引言内容
|
||||||
|
// ## Summary
|
||||||
|
// 目录内容
|
||||||
|
//
|
||||||
|
// 返回:
|
||||||
|
// [{HeaderPath: ["# Prompt Injection"], Content: "# Prompt Injection\n引言内容"},
|
||||||
|
// {HeaderPath: ["# Prompt Injection", "## Summary"], Content: "## Summary\n目录内容"}]
|
||||||
|
func (idx *Indexer) splitByMarkdownHeadersWithContent(text string) []Section {
|
||||||
|
// 匹配 Markdown 标题 (# ## ### 等)
|
||||||
headerRegex := regexp.MustCompile(`(?m)^#{1,6}\s+.+$`)
|
headerRegex := regexp.MustCompile(`(?m)^#{1,6}\s+.+$`)
|
||||||
|
|
||||||
// 找到所有标题位置
|
// 找到所有标题位置
|
||||||
matches := headerRegex.FindAllStringIndex(text, -1)
|
matches := headerRegex.FindAllStringIndex(text, -1)
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
return []string{text}
|
// 没有标题,返回整个文本
|
||||||
|
return []Section{{HeaderPath: []string{}, Content: text}}
|
||||||
}
|
}
|
||||||
|
|
||||||
chunks := make([]string, 0)
|
sections := make([]Section, 0, len(matches))
|
||||||
lastPos := 0
|
currentHeaderPath := []string{}
|
||||||
|
|
||||||
for _, match := range matches {
|
for i, match := range matches {
|
||||||
start := match[0]
|
start := match[0]
|
||||||
if start > lastPos {
|
end := match[1]
|
||||||
chunks = append(chunks, strings.TrimSpace(text[lastPos:start]))
|
nextStart := len(text)
|
||||||
}
|
|
||||||
lastPos = start
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加最后一部分
|
// 找到下一个标题的位置
|
||||||
if lastPos < len(text) {
|
if i+1 < len(matches) {
|
||||||
chunks = append(chunks, strings.TrimSpace(text[lastPos:]))
|
nextStart = matches[i+1][0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取当前标题
|
||||||
|
headerLine := strings.TrimSpace(text[start:end])
|
||||||
|
|
||||||
|
// 计算标题层级(# 的数量)
|
||||||
|
level := 0
|
||||||
|
for _, ch := range headerLine {
|
||||||
|
if ch == '#' {
|
||||||
|
level++
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新标题路径:移除比当前层级深或等于的子标题,然后添加当前标题
|
||||||
|
newPath := make([]string, 0, len(currentHeaderPath)+1)
|
||||||
|
for _, h := range currentHeaderPath {
|
||||||
|
hLevel := 0
|
||||||
|
for _, ch := range h {
|
||||||
|
if ch == '#' {
|
||||||
|
hLevel++
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hLevel < level {
|
||||||
|
newPath = append(newPath, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newPath = append(newPath, headerLine)
|
||||||
|
currentHeaderPath = newPath
|
||||||
|
|
||||||
|
// 提取当前标题到下一个标题之间的内容(包含当前标题)
|
||||||
|
content := strings.TrimSpace(text[start:nextStart])
|
||||||
|
|
||||||
|
// 创建块,使用当前标题路径(包含当前标题)
|
||||||
|
sections = append(sections, Section{
|
||||||
|
HeaderPath: append([]string(nil), currentHeaderPath...),
|
||||||
|
Content: content,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 过滤空块
|
// 过滤空块
|
||||||
result := make([]string, 0)
|
result := make([]Section, 0, len(sections))
|
||||||
for _, chunk := range chunks {
|
for _, section := range sections {
|
||||||
if strings.TrimSpace(chunk) != "" {
|
if strings.TrimSpace(section.Content) != "" {
|
||||||
result = append(result, chunk)
|
result = append(result, section)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(result) == 0 {
|
if len(result) == 0 {
|
||||||
return []string{text}
|
return []Section{{HeaderPath: []string{}, Content: text}}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -124,8 +341,12 @@ func (idx *Indexer) splitByParagraphs(text string) []string {
|
|||||||
|
|
||||||
// splitBySentences 按句子分割(用于内部,不包含重叠逻辑)
|
// splitBySentences 按句子分割(用于内部,不包含重叠逻辑)
|
||||||
func (idx *Indexer) splitBySentences(text string) []string {
|
func (idx *Indexer) splitBySentences(text string) []string {
|
||||||
// 简单的句子分割(按句号、问号、感叹号)
|
// 简单的句子分割(按句号、问号、感叹号,支持中英文)
|
||||||
sentenceRegex := regexp.MustCompile(`[.!?]+\s+`)
|
// . ! ? = 英文标点
|
||||||
|
// \u3002 = 。(中文句号)
|
||||||
|
// \uFF01 = !(中文叹号)
|
||||||
|
// \uFF1F = ?(中文问号)
|
||||||
|
sentenceRegex := regexp.MustCompile(`[.!?\x{3002}\x{FF01}\x{FF1F}]+`)
|
||||||
sentences := sentenceRegex.Split(text, -1)
|
sentences := sentenceRegex.Split(text, -1)
|
||||||
result := make([]string, 0)
|
result := make([]string, 0)
|
||||||
for _, s := range sentences {
|
for _, s := range sentences {
|
||||||
@@ -221,13 +442,13 @@ func (idx *Indexer) splitBySentencesSimple(text string) []string {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractLastTokens 从文本末尾提取指定token数量的内容
|
// extractLastTokens 从文本末尾提取指定 token 数量的内容
|
||||||
func (idx *Indexer) extractLastTokens(text string, tokenCount int) string {
|
func (idx *Indexer) extractLastTokens(text string, tokenCount int) string {
|
||||||
if tokenCount <= 0 || text == "" {
|
if tokenCount <= 0 || text == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// 估算字符数(1 token ≈ 4字符)
|
// 估算字符数(1 token ≈ 4 字符)
|
||||||
charCount := tokenCount * 4
|
charCount := tokenCount * 4
|
||||||
runes := []rune(text)
|
runes := []rune(text)
|
||||||
|
|
||||||
@@ -236,12 +457,11 @@ func (idx *Indexer) extractLastTokens(text string, tokenCount int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 从末尾提取指定数量的字符
|
// 从末尾提取指定数量的字符
|
||||||
// 尝试在句子边界处截断,避免截断句子中间
|
|
||||||
startPos := len(runes) - charCount
|
startPos := len(runes) - charCount
|
||||||
extracted := string(runes[startPos:])
|
extracted := string(runes[startPos:])
|
||||||
|
|
||||||
// 尝试找到第一个句子边界(句号、问号、感叹号后的空格)
|
// 尝试找到第一个句子边界(支持中英文标点)
|
||||||
sentenceBoundary := regexp.MustCompile(`[.!?]+\s+`)
|
sentenceBoundary := regexp.MustCompile(`[.!?\x{3002}\x{FF01}\x{FF1F}]+`)
|
||||||
matches := sentenceBoundary.FindStringIndex(extracted)
|
matches := sentenceBoundary.FindStringIndex(extracted)
|
||||||
if len(matches) > 0 && matches[0] > 0 {
|
if len(matches) > 0 && matches[0] > 0 {
|
||||||
// 在句子边界处截断,保留完整句子
|
// 在句子边界处截断,保留完整句子
|
||||||
@@ -251,41 +471,51 @@ func (idx *Indexer) extractLastTokens(text string, tokenCount int) string {
|
|||||||
return strings.TrimSpace(extracted)
|
return strings.TrimSpace(extracted)
|
||||||
}
|
}
|
||||||
|
|
||||||
// estimateTokens 估算token数(简单估算:1 token ≈ 4字符)
|
// estimateTokens 估算 token 数(简单估算:1 token ≈ 4 字符)
|
||||||
func (idx *Indexer) estimateTokens(text string) int {
|
func (idx *Indexer) estimateTokens(text string) int {
|
||||||
return len([]rune(text)) / 4
|
return len([]rune(text)) / 4
|
||||||
}
|
}
|
||||||
|
|
||||||
// IndexItem 索引知识项(分块并向量化)
|
// IndexItem 索引知识项(分块并向量化)
|
||||||
func (idx *Indexer) IndexItem(ctx context.Context, itemID string) error {
|
func (idx *Indexer) IndexItem(ctx context.Context, itemID string) error {
|
||||||
// 获取知识项(包含category和title,用于向量化)
|
// 获取知识项(包含 category 和 title,用于向量化)
|
||||||
var content, category, title string
|
var content, category, title string
|
||||||
err := idx.db.QueryRow("SELECT content, category, title FROM knowledge_base_items WHERE id = ?", itemID).Scan(&content, &category, &title)
|
err := idx.db.QueryRow("SELECT content, category, title FROM knowledge_base_items WHERE id = ?", itemID).Scan(&content, &category, &title)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("获取知识项失败: %w", err)
|
return fmt.Errorf("获取知识项失败:%w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除旧的向量(在 RebuildIndex 中已经统一清空,这里保留是为了单独调用 IndexItem 时的兼容性)
|
// 删除旧的向量(在 RebuildIndex 中已经统一清空,这里保留是为了单独调用 IndexItem 时的兼容性)
|
||||||
_, err = idx.db.Exec("DELETE FROM knowledge_embeddings WHERE item_id = ?", itemID)
|
_, err = idx.db.Exec("DELETE FROM knowledge_embeddings WHERE item_id = ?", itemID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("删除旧向量失败: %w", err)
|
return fmt.Errorf("删除旧向量失败:%w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分块
|
// 分块
|
||||||
chunks := idx.ChunkText(content)
|
chunks := idx.ChunkText(content)
|
||||||
|
|
||||||
|
// 应用最大块数限制
|
||||||
|
if idx.maxChunks > 0 && len(chunks) > idx.maxChunks {
|
||||||
|
idx.logger.Info("知识项块数量超过限制,已截断",
|
||||||
|
zap.String("itemId", itemID),
|
||||||
|
zap.Int("originalChunks", len(chunks)),
|
||||||
|
zap.Int("maxChunks", idx.maxChunks))
|
||||||
|
chunks = chunks[:idx.maxChunks]
|
||||||
|
}
|
||||||
|
|
||||||
idx.logger.Info("知识项分块完成", zap.String("itemId", itemID), zap.Int("chunks", len(chunks)))
|
idx.logger.Info("知识项分块完成", zap.String("itemId", itemID), zap.Int("chunks", len(chunks)))
|
||||||
|
|
||||||
// 跟踪该知识项的错误
|
// 跟踪该知识项的错误
|
||||||
itemErrorCount := 0
|
itemErrorCount := 0
|
||||||
var firstError error
|
var firstError error
|
||||||
firstErrorChunkIndex := -1
|
firstErrorChunkIndex := -1
|
||||||
|
|
||||||
// 向量化每个块(包含category和title信息,以便向量检索时能匹配到风险类型)
|
// 向量化每个块(包含 category 和 title 信息,以便向量检索时能匹配到风险类型)
|
||||||
for i, chunk := range chunks {
|
for i, chunk := range chunks {
|
||||||
// 将category和title信息包含到向量化的文本中
|
// 将 category 和 title 信息包含到向量化的文本中
|
||||||
// 格式:"[风险类型: {category}] [标题: {title}]\n{chunk内容}"
|
// 格式:"[风险类型:{category}] [标题:{title}]\n{chunk 内容}"
|
||||||
// 这样向量嵌入就会包含风险类型信息,即使SQL过滤失败,向量相似度也能帮助匹配
|
// 这样向量嵌入就会包含风险类型信息,即使 SQL 过滤失败,向量相似度也能帮助匹配
|
||||||
textForEmbedding := fmt.Sprintf("[风险类型: %s] [标题: %s]\n%s", category, title, chunk)
|
textForEmbedding := fmt.Sprintf("[风险类型:%s] [标题:%s]\n%s", category, title, chunk)
|
||||||
|
|
||||||
embedding, err := idx.embedder.EmbedText(ctx, textForEmbedding)
|
embedding, err := idx.embedder.EmbedText(ctx, textForEmbedding)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -305,18 +535,30 @@ func (idx *Indexer) IndexItem(ctx context.Context, itemID string) error {
|
|||||||
zap.String("chunkPreview", chunkPreview),
|
zap.String("chunkPreview", chunkPreview),
|
||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
)
|
)
|
||||||
|
|
||||||
// 更新全局错误跟踪
|
// 更新全局错误跟踪
|
||||||
errorMsg := fmt.Sprintf("向量化失败 (知识项: %s): %v", itemID, err)
|
errorMsg := fmt.Sprintf("向量化失败 (知识项:%s): %v", itemID, err)
|
||||||
idx.mu.Lock()
|
idx.mu.Lock()
|
||||||
idx.lastError = errorMsg
|
idx.lastError = errorMsg
|
||||||
idx.lastErrorTime = time.Now()
|
idx.lastErrorTime = time.Now()
|
||||||
idx.mu.Unlock()
|
idx.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果连续失败2个块,立即停止处理该知识项(降低阈值,更快停止)
|
// 如果连续失败 5 个块,立即停止处理该知识项
|
||||||
// 这样可以避免继续浪费API调用,同时也能更快地检测到配置问题
|
// 这样可以避免继续浪费 API 调用,同时也能更快地检测到配置问题
|
||||||
if itemErrorCount >= 2 {
|
// 对于大文档(超过 10 个块),允许失败比例不超过 50%
|
||||||
|
maxConsecutiveFailures := 5
|
||||||
|
if len(chunks) > 10 && itemErrorCount > len(chunks)/2 {
|
||||||
|
idx.logger.Error("知识项向量化失败比例过高,停止处理",
|
||||||
|
zap.String("itemId", itemID),
|
||||||
|
zap.Int("totalChunks", len(chunks)),
|
||||||
|
zap.Int("failedChunks", itemErrorCount),
|
||||||
|
zap.Int("firstErrorChunkIndex", firstErrorChunkIndex),
|
||||||
|
zap.Error(firstError),
|
||||||
|
)
|
||||||
|
return fmt.Errorf("知识项向量化失败比例过高 (%d/%d个块失败): %v", itemErrorCount, len(chunks), firstError)
|
||||||
|
}
|
||||||
|
if itemErrorCount >= maxConsecutiveFailures {
|
||||||
idx.logger.Error("知识项连续向量化失败,停止处理",
|
idx.logger.Error("知识项连续向量化失败,停止处理",
|
||||||
zap.String("itemId", itemID),
|
zap.String("itemId", itemID),
|
||||||
zap.Int("totalChunks", len(chunks)),
|
zap.Int("totalChunks", len(chunks)),
|
||||||
@@ -344,6 +586,13 @@ func (idx *Indexer) IndexItem(ctx context.Context, itemID string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
idx.logger.Info("知识项索引完成", zap.String("itemId", itemID), zap.Int("chunks", len(chunks)))
|
idx.logger.Info("知识项索引完成", zap.String("itemId", itemID), zap.Int("chunks", len(chunks)))
|
||||||
|
|
||||||
|
// 更新重建状态中的最近处理信息
|
||||||
|
idx.rebuildMu.Lock()
|
||||||
|
idx.rebuildLastItemID = itemID
|
||||||
|
idx.rebuildLastChunks = len(chunks)
|
||||||
|
idx.rebuildMu.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,23 +601,38 @@ func (idx *Indexer) HasIndex() (bool, error) {
|
|||||||
var count int
|
var count int
|
||||||
err := idx.db.QueryRow("SELECT COUNT(*) FROM knowledge_embeddings").Scan(&count)
|
err := idx.db.QueryRow("SELECT COUNT(*) FROM knowledge_embeddings").Scan(&count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("检查索引失败: %w", err)
|
return false, fmt.Errorf("检查索引失败:%w", err)
|
||||||
}
|
}
|
||||||
return count > 0, nil
|
return count > 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RebuildIndex 重建所有索引
|
// RebuildIndex 重建所有索引
|
||||||
func (idx *Indexer) RebuildIndex(ctx context.Context) error {
|
func (idx *Indexer) RebuildIndex(ctx context.Context) error {
|
||||||
|
// 设置重建状态
|
||||||
|
idx.rebuildMu.Lock()
|
||||||
|
idx.isRebuilding = true
|
||||||
|
idx.rebuildTotalItems = 0
|
||||||
|
idx.rebuildCurrent = 0
|
||||||
|
idx.rebuildFailed = 0
|
||||||
|
idx.rebuildStartTime = time.Now()
|
||||||
|
idx.rebuildLastItemID = ""
|
||||||
|
idx.rebuildLastChunks = 0
|
||||||
|
idx.rebuildMu.Unlock()
|
||||||
|
|
||||||
// 重置错误跟踪
|
// 重置错误跟踪
|
||||||
idx.mu.Lock()
|
idx.mu.Lock()
|
||||||
idx.lastError = ""
|
idx.lastError = ""
|
||||||
idx.lastErrorTime = time.Time{}
|
idx.lastErrorTime = time.Time{}
|
||||||
idx.errorCount = 0
|
idx.errorCount = 0
|
||||||
idx.mu.Unlock()
|
idx.mu.Unlock()
|
||||||
|
|
||||||
rows, err := idx.db.Query("SELECT id FROM knowledge_base_items")
|
rows, err := idx.db.Query("SELECT id FROM knowledge_base_items")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("查询知识项失败: %w", err)
|
// 重置重建状态
|
||||||
|
idx.rebuildMu.Lock()
|
||||||
|
idx.isRebuilding = false
|
||||||
|
idx.rebuildMu.Unlock()
|
||||||
|
return fmt.Errorf("查询知识项失败:%w", err)
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
@@ -376,34 +640,36 @@ func (idx *Indexer) RebuildIndex(ctx context.Context) error {
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var id string
|
var id string
|
||||||
if err := rows.Scan(&id); err != nil {
|
if err := rows.Scan(&id); err != nil {
|
||||||
return fmt.Errorf("扫描知识项ID失败: %w", err)
|
// 重置重建状态
|
||||||
|
idx.rebuildMu.Lock()
|
||||||
|
idx.isRebuilding = false
|
||||||
|
idx.rebuildMu.Unlock()
|
||||||
|
return fmt.Errorf("扫描知识项 ID 失败:%w", err)
|
||||||
}
|
}
|
||||||
itemIDs = append(itemIDs, id)
|
itemIDs = append(itemIDs, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
idx.rebuildMu.Lock()
|
||||||
|
idx.rebuildTotalItems = len(itemIDs)
|
||||||
|
idx.rebuildMu.Unlock()
|
||||||
|
|
||||||
idx.logger.Info("开始重建索引", zap.Int("totalItems", len(itemIDs)))
|
idx.logger.Info("开始重建索引", zap.Int("totalItems", len(itemIDs)))
|
||||||
|
|
||||||
// 在开始重建前,先清空所有旧的向量,确保进度从0开始
|
// 注意:不再清空所有旧索引,而是按增量方式更新
|
||||||
// 这样 GetIndexStatus 可以准确反映重建进度
|
// 每个知识项在 IndexItem 中会先删除自己的旧向量,然后插入新向量
|
||||||
_, err = idx.db.Exec("DELETE FROM knowledge_embeddings")
|
// 这样配置更新后只重新索引变化的知识项,保留其他知识项的索引
|
||||||
if err != nil {
|
|
||||||
idx.logger.Warn("清空旧索引失败", zap.Error(err))
|
|
||||||
// 继续执行,即使清空失败也尝试重建
|
|
||||||
} else {
|
|
||||||
idx.logger.Info("已清空旧索引,开始重建")
|
|
||||||
}
|
|
||||||
|
|
||||||
failedCount := 0
|
failedCount := 0
|
||||||
consecutiveFailures := 0
|
consecutiveFailures := 0
|
||||||
maxConsecutiveFailures := 2 // 连续失败2次后立即停止(降低阈值,更快停止)
|
maxConsecutiveFailures := 5 // 连续失败 5 次后立即停止(允许偶尔的临时错误)
|
||||||
firstFailureItemID := ""
|
firstFailureItemID := ""
|
||||||
var firstFailureError error
|
var firstFailureError error
|
||||||
|
|
||||||
for i, itemID := range itemIDs {
|
for i, itemID := range itemIDs {
|
||||||
if err := idx.IndexItem(ctx, itemID); err != nil {
|
if err := idx.IndexItem(ctx, itemID); err != nil {
|
||||||
failedCount++
|
failedCount++
|
||||||
consecutiveFailures++
|
consecutiveFailures++
|
||||||
|
|
||||||
// 只在第一个失败时记录详细日志
|
// 只在第一个失败时记录详细日志
|
||||||
if consecutiveFailures == 1 {
|
if consecutiveFailures == 1 {
|
||||||
firstFailureItemID = itemID
|
firstFailureItemID = itemID
|
||||||
@@ -414,15 +680,15 @@ func (idx *Indexer) RebuildIndex(ctx context.Context) error {
|
|||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果连续失败过多,可能是配置问题,立即停止索引
|
// 如果连续失败过多,可能是配置问题,立即停止索引
|
||||||
if consecutiveFailures >= maxConsecutiveFailures {
|
if consecutiveFailures >= maxConsecutiveFailures {
|
||||||
errorMsg := fmt.Sprintf("连续 %d 个知识项索引失败,可能存在配置问题(如嵌入模型配置错误、API密钥无效、余额不足等)。第一个失败项: %s, 错误: %v", consecutiveFailures, firstFailureItemID, firstFailureError)
|
errorMsg := fmt.Sprintf("连续 %d 个知识项索引失败,可能存在配置问题(如嵌入模型配置错误、API 密钥无效、余额不足等)。第一个失败项:%s, 错误:%v", consecutiveFailures, firstFailureItemID, firstFailureError)
|
||||||
idx.mu.Lock()
|
idx.mu.Lock()
|
||||||
idx.lastError = errorMsg
|
idx.lastError = errorMsg
|
||||||
idx.lastErrorTime = time.Now()
|
idx.lastErrorTime = time.Now()
|
||||||
idx.mu.Unlock()
|
idx.mu.Unlock()
|
||||||
|
|
||||||
idx.logger.Error("连续索引失败次数过多,立即停止索引",
|
idx.logger.Error("连续索引失败次数过多,立即停止索引",
|
||||||
zap.Int("consecutiveFailures", consecutiveFailures),
|
zap.Int("consecutiveFailures", consecutiveFailures),
|
||||||
zap.Int("totalItems", len(itemIDs)),
|
zap.Int("totalItems", len(itemIDs)),
|
||||||
@@ -430,17 +696,17 @@ func (idx *Indexer) RebuildIndex(ctx context.Context) error {
|
|||||||
zap.String("firstFailureItemId", firstFailureItemID),
|
zap.String("firstFailureItemId", firstFailureItemID),
|
||||||
zap.Error(firstFailureError),
|
zap.Error(firstFailureError),
|
||||||
)
|
)
|
||||||
return fmt.Errorf("连续索引失败次数过多: %v", firstFailureError)
|
return fmt.Errorf("连续索引失败次数过多:%v", firstFailureError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果失败的知识项过多,记录警告但继续处理(降低阈值到30%)
|
// 如果失败的知识项过多,记录警告但继续处理(降低阈值到 30%)
|
||||||
if failedCount > len(itemIDs)*3/10 && failedCount == len(itemIDs)*3/10+1 {
|
if failedCount > len(itemIDs)*3/10 && failedCount == len(itemIDs)*3/10+1 {
|
||||||
errorMsg := fmt.Sprintf("索引失败的知识项过多 (%d/%d),可能存在配置问题。第一个失败项: %s, 错误: %v", failedCount, len(itemIDs), firstFailureItemID, firstFailureError)
|
errorMsg := fmt.Sprintf("索引失败的知识项过多 (%d/%d),可能存在配置问题。第一个失败项:%s, 错误:%v", failedCount, len(itemIDs), firstFailureItemID, firstFailureError)
|
||||||
idx.mu.Lock()
|
idx.mu.Lock()
|
||||||
idx.lastError = errorMsg
|
idx.lastError = errorMsg
|
||||||
idx.lastErrorTime = time.Now()
|
idx.lastErrorTime = time.Now()
|
||||||
idx.mu.Unlock()
|
idx.mu.Unlock()
|
||||||
|
|
||||||
idx.logger.Error("索引失败的知识项过多,可能存在配置问题",
|
idx.logger.Error("索引失败的知识项过多,可能存在配置问题",
|
||||||
zap.Int("failedCount", failedCount),
|
zap.Int("failedCount", failedCount),
|
||||||
zap.Int("totalItems", len(itemIDs)),
|
zap.Int("totalItems", len(itemIDs)),
|
||||||
@@ -450,20 +716,31 @@ func (idx *Indexer) RebuildIndex(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 成功时重置连续失败计数和第一个失败信息
|
// 成功时重置连续失败计数和第一个失败信息
|
||||||
if consecutiveFailures > 0 {
|
if consecutiveFailures > 0 {
|
||||||
consecutiveFailures = 0
|
consecutiveFailures = 0
|
||||||
firstFailureItemID = ""
|
firstFailureItemID = ""
|
||||||
firstFailureError = nil
|
firstFailureError = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 减少进度日志频率(每10个或每10%记录一次)
|
// 更新重建进度
|
||||||
|
idx.rebuildMu.Lock()
|
||||||
|
idx.rebuildCurrent = i + 1
|
||||||
|
idx.rebuildFailed = failedCount
|
||||||
|
idx.rebuildMu.Unlock()
|
||||||
|
|
||||||
|
// 减少进度日志频率(每 10 个或每 10% 记录一次)
|
||||||
if (i+1)%10 == 0 || (len(itemIDs) > 0 && (i+1)*100/len(itemIDs)%10 == 0 && (i+1)*100/len(itemIDs) > 0) {
|
if (i+1)%10 == 0 || (len(itemIDs) > 0 && (i+1)*100/len(itemIDs)%10 == 0 && (i+1)*100/len(itemIDs) > 0) {
|
||||||
idx.logger.Info("索引进度", zap.Int("current", i+1), zap.Int("total", len(itemIDs)), zap.Int("failed", failedCount))
|
idx.logger.Info("索引进度", zap.Int("current", i+1), zap.Int("total", len(itemIDs)), zap.Int("failed", failedCount))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重置重建状态
|
||||||
|
idx.rebuildMu.Lock()
|
||||||
|
idx.isRebuilding = false
|
||||||
|
idx.rebuildMu.Unlock()
|
||||||
|
|
||||||
idx.logger.Info("索引重建完成", zap.Int("totalItems", len(itemIDs)), zap.Int("failedCount", failedCount))
|
idx.logger.Info("索引重建完成", zap.Int("totalItems", len(itemIDs)), zap.Int("failedCount", failedCount))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -474,3 +751,10 @@ func (idx *Indexer) GetLastError() (string, time.Time) {
|
|||||||
defer idx.mu.RUnlock()
|
defer idx.mu.RUnlock()
|
||||||
return idx.lastError, idx.lastErrorTime
|
return idx.lastError, idx.lastErrorTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRebuildStatus 获取重建索引状态
|
||||||
|
func (idx *Indexer) GetRebuildStatus() (isRebuilding bool, totalItems int, current int, failed int, lastItemID string, lastChunks int, startTime time.Time) {
|
||||||
|
idx.rebuildMu.RLock()
|
||||||
|
defer idx.rebuildMu.RUnlock()
|
||||||
|
return idx.isRebuilding, idx.rebuildTotalItems, idx.rebuildCurrent, idx.rebuildFailed, idx.rebuildLastItemID, idx.rebuildLastChunks, idx.rebuildStartTime
|
||||||
|
}
|
||||||
|
|||||||
@@ -657,7 +657,7 @@ func (m *Manager) UpdateItem(id, category, title, content string) (*KnowledgeIte
|
|||||||
|
|
||||||
// 删除旧目录(如果为空)
|
// 删除旧目录(如果为空)
|
||||||
oldDir := filepath.Dir(item.FilePath)
|
oldDir := filepath.Dir(item.FilePath)
|
||||||
if entries, err := os.ReadDir(oldDir); err == nil && len(entries) == 0 {
|
if isEmpty, _ := isEmptyDir(oldDir); isEmpty {
|
||||||
// 只有当目录不是知识库根目录时才删除(避免删除根目录)
|
// 只有当目录不是知识库根目录时才删除(避免删除根目录)
|
||||||
if oldDir != m.basePath {
|
if oldDir != m.basePath {
|
||||||
if err := os.Remove(oldDir); err != nil {
|
if err := os.Remove(oldDir); err != nil {
|
||||||
@@ -712,7 +712,7 @@ func (m *Manager) DeleteItem(id string) error {
|
|||||||
|
|
||||||
// 删除空目录(如果为空)
|
// 删除空目录(如果为空)
|
||||||
dir := filepath.Dir(filePath)
|
dir := filepath.Dir(filePath)
|
||||||
if entries, err := os.ReadDir(dir); err == nil && len(entries) == 0 {
|
if isEmpty, _ := isEmptyDir(dir); isEmpty {
|
||||||
// 只有当目录不是知识库根目录时才删除(避免删除根目录)
|
// 只有当目录不是知识库根目录时才删除(避免删除根目录)
|
||||||
if dir != m.basePath {
|
if dir != m.basePath {
|
||||||
if err := os.Remove(dir); err != nil {
|
if err := os.Remove(dir); err != nil {
|
||||||
@@ -724,6 +724,21 @@ func (m *Manager) DeleteItem(id string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isEmptyDir 检查目录是否为空(忽略隐藏文件和 . 开头的文件)
|
||||||
|
func isEmptyDir(dir string) (bool, error) {
|
||||||
|
entries, err := os.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
for _, entry := range entries {
|
||||||
|
// 忽略隐藏文件(以 . 开头)
|
||||||
|
if !strings.HasPrefix(entry.Name(), ".") {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
// LogRetrieval 记录检索日志
|
// LogRetrieval 记录检索日志
|
||||||
func (m *Manager) LogRetrieval(conversationID, messageID, query, riskType string, retrievedItems []string) error {
|
func (m *Manager) LogRetrieval(conversationID, messageID, query, riskType string, retrievedItems []string) error {
|
||||||
id := uuid.New().String()
|
id := uuid.New().String()
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ func cosineSimilarity(a, b []float32) float64 {
|
|||||||
return dotProduct / (math.Sqrt(normA) * math.Sqrt(normB))
|
return dotProduct / (math.Sqrt(normA) * math.Sqrt(normB))
|
||||||
}
|
}
|
||||||
|
|
||||||
// bm25Score 计算BM25分数(改进版,更接近标准BM25)
|
// bm25Score 计算 BM25 分数(带缓存的改进版本)
|
||||||
// 注意:这是单文档版本的BM25,缺少全局IDF,但比之前的简化版本更准确
|
// 注意:由于缺少全局文档统计,使用简化 IDF 计算
|
||||||
func (r *Retriever) bm25Score(query, text string) float64 {
|
func (r *Retriever) bm25Score(query, text string) float64 {
|
||||||
queryTerms := strings.Fields(strings.ToLower(query))
|
queryTerms := strings.Fields(strings.ToLower(query))
|
||||||
if len(queryTerms) == 0 {
|
if len(queryTerms) == 0 {
|
||||||
@@ -83,44 +83,56 @@ func (r *Retriever) bm25Score(query, text string) float64 {
|
|||||||
return 0.0
|
return 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
// BM25参数
|
// BM25 参数(标准值)
|
||||||
k1 := 1.5 // 词频饱和度参数
|
k1 := 1.2 // 词频饱和度参数(标准范围 1.2-2.0)
|
||||||
b := 0.75 // 长度归一化参数
|
b := 0.75 // 长度归一化参数(标准值)
|
||||||
avgDocLength := 100.0 // 估算的平均文档长度(用于归一化)
|
avgDocLength := 150.0 // 估算的平均文档长度(基于典型知识块大小)
|
||||||
docLength := float64(len(textTerms))
|
docLength := float64(len(textTerms))
|
||||||
|
|
||||||
score := 0.0
|
// 计算词频映射
|
||||||
for _, term := range queryTerms {
|
textTermFreq := make(map[string]int, len(textTerms))
|
||||||
// 计算词频(TF)
|
for _, term := range textTerms {
|
||||||
termFreq := 0
|
textTermFreq[term]++
|
||||||
for _, textTerm := range textTerms {
|
|
||||||
if textTerm == term {
|
|
||||||
termFreq++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if termFreq > 0 {
|
|
||||||
// BM25公式的核心部分
|
|
||||||
// TF部分:termFreq / (termFreq + k1 * (1 - b + b * (docLength / avgDocLength)))
|
|
||||||
tf := float64(termFreq)
|
|
||||||
lengthNorm := 1 - b + b*(docLength/avgDocLength)
|
|
||||||
tfScore := tf / (tf + k1*lengthNorm)
|
|
||||||
|
|
||||||
// 简化IDF:使用词长度作为权重(短词通常更重要)
|
|
||||||
// 实际BM25需要全局文档统计,这里用简化版本
|
|
||||||
idfWeight := 1.0
|
|
||||||
if len(term) > 2 {
|
|
||||||
// 长词稍微降低权重(但实际BM25中,罕见词IDF更高)
|
|
||||||
idfWeight = 1.0 + math.Log(1.0+float64(len(term))/10.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
score += tfScore * idfWeight
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 归一化到0-1范围
|
score := 0.0
|
||||||
|
matchedQueryTerms := 0
|
||||||
|
|
||||||
|
for _, term := range queryTerms {
|
||||||
|
termFreq, exists := textTermFreq[term]
|
||||||
|
if !exists || termFreq == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
matchedQueryTerms++
|
||||||
|
|
||||||
|
// BM25 TF 计算公式
|
||||||
|
tf := float64(termFreq)
|
||||||
|
lengthNorm := 1 - b + b*(docLength/avgDocLength)
|
||||||
|
tfScore := tf / (tf + k1*lengthNorm)
|
||||||
|
|
||||||
|
// 改进的 IDF 计算:使用词长度和出现频率估算
|
||||||
|
// 短词(2-3 字符)通常更重要,长词 IDF 略低
|
||||||
|
idfWeight := 1.0
|
||||||
|
termLen := len(term)
|
||||||
|
if termLen <= 2 {
|
||||||
|
// 极短词(如 go, js)给予更高权重
|
||||||
|
idfWeight = 1.2 + math.Log(1.0+float64(termFreq)/20.0)
|
||||||
|
} else if termLen <= 4 {
|
||||||
|
// 短词(4 字符)标准权重
|
||||||
|
idfWeight = 1.0 + math.Log(1.0+float64(termFreq)/15.0)
|
||||||
|
} else {
|
||||||
|
// 长词稍微降低权重
|
||||||
|
idfWeight = 0.9 + math.Log(1.0+float64(termFreq)/10.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
score += tfScore * idfWeight
|
||||||
|
}
|
||||||
|
|
||||||
|
// 归一化:考虑匹配的查询词比例
|
||||||
if len(queryTerms) > 0 {
|
if len(queryTerms) > 0 {
|
||||||
score = score / float64(len(queryTerms))
|
// 使用匹配比例作为额外因子
|
||||||
|
matchRatio := float64(matchedQueryTerms) / float64(len(queryTerms))
|
||||||
|
score = (score / float64(len(queryTerms))) * (1 + matchRatio) / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
return math.Min(score, 1.0)
|
return math.Min(score, 1.0)
|
||||||
@@ -173,7 +185,7 @@ func (r *Retriever) Search(ctx context.Context, req *SearchRequest) ([]*Retrieva
|
|||||||
SELECT e.id, e.item_id, e.chunk_index, e.chunk_text, e.embedding, i.category, i.title
|
SELECT e.id, e.item_id, e.chunk_index, e.chunk_text, e.embedding, i.category, i.title
|
||||||
FROM knowledge_embeddings e
|
FROM knowledge_embeddings e
|
||||||
JOIN knowledge_base_items i ON e.item_id = i.id
|
JOIN knowledge_base_items i ON e.item_id = i.id
|
||||||
WHERE i.category = ? COLLATE NOCASE
|
WHERE TRIM(i.category) = TRIM(?) COLLATE NOCASE
|
||||||
`, req.RiskType)
|
`, req.RiskType)
|
||||||
} else {
|
} else {
|
||||||
rows, err = r.db.Query(`
|
rows, err = r.db.Query(`
|
||||||
@@ -357,7 +369,10 @@ func (r *Retriever) Search(ctx context.Context, req *SearchRequest) ([]*Retrieva
|
|||||||
zap.Float64("threshold", threshold),
|
zap.Float64("threshold", threshold),
|
||||||
zap.Float64("maxSimilarity", maxSimilarity),
|
zap.Float64("maxSimilarity", maxSimilarity),
|
||||||
)
|
)
|
||||||
} else if len(filteredCandidates) > topK {
|
}
|
||||||
|
|
||||||
|
// 统一在最终返回前严格限制 Top-K 数量
|
||||||
|
if len(filteredCandidates) > topK {
|
||||||
// 如果过滤后结果太多,只取Top-K
|
// 如果过滤后结果太多,只取Top-K
|
||||||
filteredCandidates = filteredCandidates[:topK]
|
filteredCandidates = filteredCandidates[:topK]
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-42
@@ -5,6 +5,14 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// formatTime 格式化时间为 RFC3339 格式,零时间返回空字符串
|
||||||
|
func formatTime(t time.Time) string {
|
||||||
|
if t.IsZero() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return t.Format(time.RFC3339)
|
||||||
|
}
|
||||||
|
|
||||||
// KnowledgeItem 知识库项
|
// KnowledgeItem 知识库项
|
||||||
type KnowledgeItem struct {
|
type KnowledgeItem struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
@@ -22,12 +30,12 @@ type KnowledgeItemSummary struct {
|
|||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
FilePath string `json:"filePath"`
|
FilePath string `json:"filePath"`
|
||||||
Content string `json:"content,omitempty"` // 可选:内容预览(如果提供,通常只包含前150字符)
|
Content string `json:"content,omitempty"` // 可选:内容预览(如果提供,通常只包含前 150 字符)
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON 自定义JSON序列化,确保时间格式正确
|
// MarshalJSON 自定义 JSON 序列化,确保时间格式正确
|
||||||
func (k *KnowledgeItemSummary) MarshalJSON() ([]byte, error) {
|
func (k *KnowledgeItemSummary) MarshalJSON() ([]byte, error) {
|
||||||
type Alias KnowledgeItemSummary
|
type Alias KnowledgeItemSummary
|
||||||
aux := &struct {
|
aux := &struct {
|
||||||
@@ -37,25 +45,12 @@ func (k *KnowledgeItemSummary) MarshalJSON() ([]byte, error) {
|
|||||||
}{
|
}{
|
||||||
Alias: (*Alias)(k),
|
Alias: (*Alias)(k),
|
||||||
}
|
}
|
||||||
|
aux.CreatedAt = formatTime(k.CreatedAt)
|
||||||
// 格式化创建时间
|
aux.UpdatedAt = formatTime(k.UpdatedAt)
|
||||||
if k.CreatedAt.IsZero() {
|
|
||||||
aux.CreatedAt = ""
|
|
||||||
} else {
|
|
||||||
aux.CreatedAt = k.CreatedAt.Format(time.RFC3339)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 格式化更新时间
|
|
||||||
if k.UpdatedAt.IsZero() {
|
|
||||||
aux.UpdatedAt = ""
|
|
||||||
} else {
|
|
||||||
aux.UpdatedAt = k.UpdatedAt.Format(time.RFC3339)
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Marshal(aux)
|
return json.Marshal(aux)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON 自定义JSON序列化,确保时间格式正确
|
// MarshalJSON 自定义 JSON 序列化,确保时间格式正确
|
||||||
func (k *KnowledgeItem) MarshalJSON() ([]byte, error) {
|
func (k *KnowledgeItem) MarshalJSON() ([]byte, error) {
|
||||||
type Alias KnowledgeItem
|
type Alias KnowledgeItem
|
||||||
aux := &struct {
|
aux := &struct {
|
||||||
@@ -65,21 +60,8 @@ func (k *KnowledgeItem) MarshalJSON() ([]byte, error) {
|
|||||||
}{
|
}{
|
||||||
Alias: (*Alias)(k),
|
Alias: (*Alias)(k),
|
||||||
}
|
}
|
||||||
|
aux.CreatedAt = formatTime(k.CreatedAt)
|
||||||
// 格式化创建时间
|
aux.UpdatedAt = formatTime(k.UpdatedAt)
|
||||||
if k.CreatedAt.IsZero() {
|
|
||||||
aux.CreatedAt = ""
|
|
||||||
} else {
|
|
||||||
aux.CreatedAt = k.CreatedAt.Format(time.RFC3339)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 格式化更新时间
|
|
||||||
if k.UpdatedAt.IsZero() {
|
|
||||||
aux.UpdatedAt = ""
|
|
||||||
} else {
|
|
||||||
aux.UpdatedAt = k.UpdatedAt.Format(time.RFC3339)
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Marshal(aux)
|
return json.Marshal(aux)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +71,7 @@ type KnowledgeChunk struct {
|
|||||||
ItemID string `json:"itemId"`
|
ItemID string `json:"itemId"`
|
||||||
ChunkIndex int `json:"chunkIndex"`
|
ChunkIndex int `json:"chunkIndex"`
|
||||||
ChunkText string `json:"chunkText"`
|
ChunkText string `json:"chunkText"`
|
||||||
Embedding []float32 `json:"-"` // 向量嵌入,不序列化到JSON
|
Embedding []float32 `json:"-"` // 向量嵌入,不序列化到 JSON
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,11 +90,11 @@ type RetrievalLog struct {
|
|||||||
MessageID string `json:"messageId,omitempty"`
|
MessageID string `json:"messageId,omitempty"`
|
||||||
Query string `json:"query"`
|
Query string `json:"query"`
|
||||||
RiskType string `json:"riskType,omitempty"`
|
RiskType string `json:"riskType,omitempty"`
|
||||||
RetrievedItems []string `json:"retrievedItems"` // 检索到的知识项ID列表
|
RetrievedItems []string `json:"retrievedItems"` // 检索到的知识项 ID 列表
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON 自定义JSON序列化,确保时间格式正确
|
// MarshalJSON 自定义 JSON 序列化,确保时间格式正确
|
||||||
func (r *RetrievalLog) MarshalJSON() ([]byte, error) {
|
func (r *RetrievalLog) MarshalJSON() ([]byte, error) {
|
||||||
type Alias RetrievalLog
|
type Alias RetrievalLog
|
||||||
return json.Marshal(&struct {
|
return json.Marshal(&struct {
|
||||||
@@ -120,21 +102,21 @@ func (r *RetrievalLog) MarshalJSON() ([]byte, error) {
|
|||||||
CreatedAt string `json:"createdAt"`
|
CreatedAt string `json:"createdAt"`
|
||||||
}{
|
}{
|
||||||
Alias: (*Alias)(r),
|
Alias: (*Alias)(r),
|
||||||
CreatedAt: r.CreatedAt.Format(time.RFC3339),
|
CreatedAt: formatTime(r.CreatedAt),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CategoryWithItems 分类及其下的知识项(用于按分类分页)
|
// CategoryWithItems 分类及其下的知识项(用于按分类分页)
|
||||||
type CategoryWithItems struct {
|
type CategoryWithItems struct {
|
||||||
Category string `json:"category"` // 分类名称
|
Category string `json:"category"` // 分类名称
|
||||||
ItemCount int `json:"itemCount"` // 该分类下的知识项总数
|
ItemCount int `json:"itemCount"` // 该分类下的知识项总数
|
||||||
Items []*KnowledgeItemSummary `json:"items"` // 该分类下的知识项列表
|
Items []*KnowledgeItemSummary `json:"items"` // 该分类下的知识项列表
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchRequest 搜索请求
|
// SearchRequest 搜索请求
|
||||||
type SearchRequest struct {
|
type SearchRequest struct {
|
||||||
Query string `json:"query"`
|
Query string `json:"query"`
|
||||||
RiskType string `json:"riskType,omitempty"` // 可选:指定风险类型
|
RiskType string `json:"riskType,omitempty"` // 可选:指定风险类型
|
||||||
TopK int `json:"topK,omitempty"` // 返回Top-K结果,默认5
|
TopK int `json:"topK,omitempty"` // 返回 Top-K 结果,默认 5
|
||||||
Threshold float64 `json:"threshold,omitempty"` // 相似度阈值,默认0.7
|
Threshold float64 `json:"threshold,omitempty"` // 相似度阈值,默认 0.7
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,14 @@ func New(level, output string) *Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) Fatal(msg string, fields ...interface{}) {
|
func (l *Logger) Fatal(msg string, fields ...interface{}) {
|
||||||
l.Logger.Fatal(msg, zap.Any("fields", fields))
|
zapFields := make([]zap.Field, 0, len(fields))
|
||||||
|
for _, f := range fields {
|
||||||
|
switch v := f.(type) {
|
||||||
|
case error:
|
||||||
|
zapFields = append(zapFields, zap.Error(v))
|
||||||
|
default:
|
||||||
|
zapFields = append(zapFields, zap.Any("field", v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l.Logger.Fatal(msg, zapFields...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -529,6 +529,60 @@ header {
|
|||||||
gap: 12px;
|
gap: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lang-switcher {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lang-switcher-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
background: var(--bg-primary);
|
||||||
|
color: var(--text-primary);
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.8125rem;
|
||||||
|
font-weight: 400;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lang-switcher-btn:hover {
|
||||||
|
background: var(--bg-tertiary);
|
||||||
|
border-color: var(--accent-color);
|
||||||
|
color: var(--accent-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.lang-switcher-icon {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lang-dropdown {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: calc(100% + 6px);
|
||||||
|
min-width: 120px;
|
||||||
|
background: var(--bg-primary);
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 8px 20px rgba(15, 23, 42, 0.16);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
padding: 4px 0;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lang-option {
|
||||||
|
padding: 6px 12px;
|
||||||
|
font-size: 0.8125rem;
|
||||||
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lang-option:hover {
|
||||||
|
background: var(--bg-tertiary);
|
||||||
|
color: var(--accent-color);
|
||||||
|
}
|
||||||
|
|
||||||
.header-actions button {
|
.header-actions button {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -1748,6 +1802,7 @@ header {
|
|||||||
|
|
||||||
.chat-input-container textarea::placeholder {
|
.chat-input-container textarea::placeholder {
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
|
opacity: 0.85;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-input-container .send-btn {
|
.chat-input-container .send-btn {
|
||||||
|
|||||||
@@ -0,0 +1,925 @@
|
|||||||
|
{
|
||||||
|
"common": {
|
||||||
|
"ok": "OK",
|
||||||
|
"cancel": "Cancel",
|
||||||
|
"refresh": "Refresh",
|
||||||
|
"close": "Close",
|
||||||
|
"edit": "Edit",
|
||||||
|
"delete": "Delete",
|
||||||
|
"save": "Save",
|
||||||
|
"loading": "Loading…",
|
||||||
|
"search": "Search",
|
||||||
|
"clearSearch": "Clear search",
|
||||||
|
"noData": "No data",
|
||||||
|
"confirm": "Confirm",
|
||||||
|
"copy": "Copy",
|
||||||
|
"copied": "Copied",
|
||||||
|
"copyFailed": "Copy failed"
|
||||||
|
},
|
||||||
|
"header": {
|
||||||
|
"title": "CyberStrikeAI",
|
||||||
|
"apiDocs": "API Docs",
|
||||||
|
"logout": "Sign out",
|
||||||
|
"language": "Interface language",
|
||||||
|
"backToDashboard": "Back to dashboard",
|
||||||
|
"userMenu": "User menu",
|
||||||
|
"version": "Current version",
|
||||||
|
"toggleSidebar": "Collapse/expand sidebar"
|
||||||
|
},
|
||||||
|
"login": {
|
||||||
|
"title": "Sign in to CyberStrikeAI",
|
||||||
|
"subtitle": "Enter the access password from config",
|
||||||
|
"passwordLabel": "Password",
|
||||||
|
"passwordPlaceholder": "Enter password",
|
||||||
|
"submit": "Sign in"
|
||||||
|
},
|
||||||
|
"nav": {
|
||||||
|
"dashboard": "Dashboard",
|
||||||
|
"chat": "Chat",
|
||||||
|
"infoCollect": "Recon",
|
||||||
|
"tasks": "Tasks",
|
||||||
|
"vulnerabilities": "Vulnerabilities",
|
||||||
|
"mcp": "MCP",
|
||||||
|
"mcpMonitor": "MCP Monitor",
|
||||||
|
"mcpManagement": "MCP Management",
|
||||||
|
"knowledge": "Knowledge",
|
||||||
|
"knowledgeRetrievalLogs": "Retrieval history",
|
||||||
|
"knowledgeManagement": "Knowledge management",
|
||||||
|
"skills": "Skills",
|
||||||
|
"skillsMonitor": "Skills monitor",
|
||||||
|
"skillsManagement": "Skills management",
|
||||||
|
"roles": "Roles",
|
||||||
|
"rolesManagement": "Roles management",
|
||||||
|
"settings": "System settings"
|
||||||
|
},
|
||||||
|
"dashboard": {
|
||||||
|
"title": "Dashboard",
|
||||||
|
"refresh": "Refresh",
|
||||||
|
"refreshData": "Refresh data",
|
||||||
|
"runningTasks": "Running tasks",
|
||||||
|
"vulnTotal": "Total vulnerabilities",
|
||||||
|
"toolCalls": "Tool invocations",
|
||||||
|
"successRate": "Tool success rate",
|
||||||
|
"clickToViewTasks": "Click to view tasks",
|
||||||
|
"clickToViewVuln": "Click to view vulnerabilities",
|
||||||
|
"clickToViewMCP": "Click to view MCP monitor",
|
||||||
|
"severityDistribution": "Vulnerability severity distribution",
|
||||||
|
"severityCritical": "Critical",
|
||||||
|
"severityHigh": "High",
|
||||||
|
"severityMedium": "Medium",
|
||||||
|
"severityLow": "Low",
|
||||||
|
"severityInfo": "Info",
|
||||||
|
"runOverview": "Run overview",
|
||||||
|
"batchQueues": "Batch task queues",
|
||||||
|
"pending": "Pending",
|
||||||
|
"executing": "Running",
|
||||||
|
"completed": "Completed",
|
||||||
|
"toolInvocations": "Tool invocations",
|
||||||
|
"callsUnit": "calls",
|
||||||
|
"toolsUnit": "tools",
|
||||||
|
"knowledgeLabel": "Knowledge",
|
||||||
|
"knowledgeItems": "items",
|
||||||
|
"categoriesUnit": "categories",
|
||||||
|
"skillsLabel": "Skills",
|
||||||
|
"skillUnit": "Skills",
|
||||||
|
"quickLinks": "Quick links",
|
||||||
|
"toolsExecCount": "Tool execution count",
|
||||||
|
"ctaTitle": "Start your security journey",
|
||||||
|
"ctaSub": "Describe your target in chat, AI will assist with scanning and vulnerability analysis",
|
||||||
|
"goToChat": "Go to chat",
|
||||||
|
"noTasks": "No tasks",
|
||||||
|
"totalCount": "{{count}} total",
|
||||||
|
"notEnabled": "Disabled",
|
||||||
|
"enabled": "Enabled",
|
||||||
|
"toConfigure": "To configure",
|
||||||
|
"toUse": "To use",
|
||||||
|
"active": "Active",
|
||||||
|
"highFreq": "High frequency",
|
||||||
|
"noCallData": "No call data"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"newChat": "New chat",
|
||||||
|
"searchHistory": "Search history...",
|
||||||
|
"conversationGroups": "Conversation groups",
|
||||||
|
"addGroup": "New group",
|
||||||
|
"recentConversations": "Recent conversations",
|
||||||
|
"batchManage": "Batch manage",
|
||||||
|
"attackChain": "Attack chain",
|
||||||
|
"viewAttackChain": "View attack chain",
|
||||||
|
"selectRole": "Select role",
|
||||||
|
"defaultRole": "Default",
|
||||||
|
"inputPlaceholder": "Enter target or command... (type @ to select tools | Shift+Enter newline, Enter send)",
|
||||||
|
"selectFile": "Select file",
|
||||||
|
"uploadFile": "Upload file (multi-select or drag & drop)",
|
||||||
|
"send": "Send",
|
||||||
|
"searchInGroup": "Search in group...",
|
||||||
|
"loadingTools": "Loading tools...",
|
||||||
|
"noMatchTools": "No matching tools",
|
||||||
|
"penetrationTestDetail": "Penetration test details",
|
||||||
|
"expandDetail": "Expand details",
|
||||||
|
"noProcessDetail": "No process details (execution may be too fast or no detailed events)",
|
||||||
|
"copyMessageTitle": "Copy message",
|
||||||
|
"emptyGroupConversations": "This group has no conversations yet.",
|
||||||
|
"noMatchingConversationsInGroup": "No matching conversations found.",
|
||||||
|
"renameGroupPrompt": "Please enter new name:",
|
||||||
|
"deleteGroupConfirm": "Are you sure you want to delete this group? Conversations in the group will not be deleted, but will be removed from the group.",
|
||||||
|
"deleteConversationConfirm": "Are you sure you want to delete this conversation?",
|
||||||
|
"renameFailed": "Rename failed",
|
||||||
|
"viewAttackChainSelectConv": "Please select a conversation to view attack chain",
|
||||||
|
"viewAttackChainCurrentConv": "View attack chain of current conversation",
|
||||||
|
"executeFailed": "Execution failed",
|
||||||
|
"callOpenAIFailed": "Call OpenAI failed",
|
||||||
|
"systemReadyMessage": "System is ready. Please enter your test requirements, and the system will automatically perform the corresponding security tests.",
|
||||||
|
"addNewGroup": "+ New group"
|
||||||
|
},
|
||||||
|
"tasks": {
|
||||||
|
"title": "Task management",
|
||||||
|
"newTask": "New task",
|
||||||
|
"autoRefresh": "Auto refresh",
|
||||||
|
"historyHint": "Tip: Completed task history available. Check \"Show history\" to view.",
|
||||||
|
"statusRunning": "Running",
|
||||||
|
"statusCancelling": "Cancelling",
|
||||||
|
"statusFailed": "Failed",
|
||||||
|
"statusTimeout": "Timeout",
|
||||||
|
"statusCancelled": "Cancelled",
|
||||||
|
"statusCompleted": "Completed",
|
||||||
|
"historyBadge": "History",
|
||||||
|
"duration": "Duration",
|
||||||
|
"completedAt": "Completed at",
|
||||||
|
"startedAt": "Started at",
|
||||||
|
"clickToCopy": "Click to copy",
|
||||||
|
"unnamedTask": "Unnamed task",
|
||||||
|
"unknown": "Unknown",
|
||||||
|
"unknownTime": "Unknown time",
|
||||||
|
"clearHistoryConfirm": "Clear all task history?",
|
||||||
|
"cancelTaskFailed": "Cancel task failed",
|
||||||
|
"copiedToast": "Copied!",
|
||||||
|
"cancelling": "Cancelling...",
|
||||||
|
"enterTaskPrompt": "Enter at least one task",
|
||||||
|
"noValidTask": "No valid tasks",
|
||||||
|
"createBatchQueueFailed": "Failed to create batch task queue",
|
||||||
|
"noBatchQueues": "Currently there are no batch task queues",
|
||||||
|
"recentCompletedTasks": "Recently completed tasks (last 24 hours)",
|
||||||
|
"clearHistory": "Clear history",
|
||||||
|
"cancelTask": "Cancel task",
|
||||||
|
"viewConversation": "View conversation",
|
||||||
|
"conversationIdLabel": "Conversation ID",
|
||||||
|
"statusPending": "Pending",
|
||||||
|
"statusPaused": "Paused",
|
||||||
|
"confirmCancelTasks": "Cancel {{n}} selected task(s)?",
|
||||||
|
"batchCancelResultPartial": "Batch cancel: {{success}} succeeded, {{fail}} failed",
|
||||||
|
"batchCancelResultSuccess": "Successfully cancelled {{n}} task(s)",
|
||||||
|
"taskCount": "{{count}} task(s)",
|
||||||
|
"queueIdLabel": "Queue ID",
|
||||||
|
"createdTimeLabel": "Created at",
|
||||||
|
"totalLabel": "Total",
|
||||||
|
"pendingLabel": "Pending",
|
||||||
|
"runningLabel": "Running",
|
||||||
|
"completedLabel": "Completed",
|
||||||
|
"failedLabel": "Failed",
|
||||||
|
"cancelledLabel": "Cancelled",
|
||||||
|
"loadingTasks": "Loading...",
|
||||||
|
"loadFailedRetry": "Load failed",
|
||||||
|
"loadTaskListFailed": "Failed to load task list",
|
||||||
|
"getQueueDetailFailed": "Failed to load queue details",
|
||||||
|
"startBatchQueueFailed": "Failed to start batch queue",
|
||||||
|
"pauseQueueFailed": "Failed to pause queue",
|
||||||
|
"pauseQueueConfirm": "Pause this batch queue? The current task will be stopped; remaining tasks will stay pending.",
|
||||||
|
"deleteQueueConfirm": "Delete this batch queue? This cannot be undone.",
|
||||||
|
"deleteQueueFailed": "Failed to delete batch queue",
|
||||||
|
"batchQueueTitle": "Batch task queue",
|
||||||
|
"resumeExecute": "Resume",
|
||||||
|
"taskIncomplete": "Task information incomplete",
|
||||||
|
"cannotGetTaskMessageInput": "Cannot get task message input",
|
||||||
|
"taskMessageRequired": "Task message is required",
|
||||||
|
"saveTaskFailed": "Failed to save task",
|
||||||
|
"queueInfoMissing": "Queue information not found",
|
||||||
|
"addTaskFailed": "Failed to add task",
|
||||||
|
"confirmDeleteTask": "Delete this task?\n\nTask: {{message}}\n\nThis cannot be undone.",
|
||||||
|
"deleteTaskFailed": "Failed to delete task",
|
||||||
|
"paginationShow": "{{start}}-{{end}} of {{total}}",
|
||||||
|
"paginationPerPage": "Per page",
|
||||||
|
"paginationFirst": "First",
|
||||||
|
"paginationPrev": "Previous",
|
||||||
|
"paginationNext": "Next",
|
||||||
|
"paginationLast": "Last",
|
||||||
|
"paginationPage": "Page {{current}} / {{total}}",
|
||||||
|
"deleteQueue": "Delete queue",
|
||||||
|
"retry": "Retry",
|
||||||
|
"noMatchingTasks": "No matching tasks",
|
||||||
|
"updateTaskFailed": "Failed to update task",
|
||||||
|
"durationSeconds": "s",
|
||||||
|
"durationMinutes": "m",
|
||||||
|
"durationHours": "h"
|
||||||
|
},
|
||||||
|
"infoCollect": {
|
||||||
|
"enterFofaQuery": "Enter FOFA query syntax",
|
||||||
|
"querying": "Querying...",
|
||||||
|
"queryFailed": "Query failed",
|
||||||
|
"enterNaturalLanguage": "Enter natural language description",
|
||||||
|
"cancelParse": "Cancel parse",
|
||||||
|
"clickToCancelParse": "Click to cancel AI parse",
|
||||||
|
"parseToFofa": "Parse natural language to FOFA query",
|
||||||
|
"parseResultEmpty": "Parse result empty: Please add/modify FOFA query in popup",
|
||||||
|
"queryPlaceholder": "e.g. app=\"Apache\" && country=\"CN\"",
|
||||||
|
"selectAll": "Select all/none",
|
||||||
|
"selectRow": "Select row",
|
||||||
|
"copyTarget": "Copy target",
|
||||||
|
"sendToChat": "Send to chat (editable; Ctrl/Cmd+click to send directly)",
|
||||||
|
"noTargetToCopy": "No target to copy",
|
||||||
|
"targetCopied": "Target copied",
|
||||||
|
"manualCopyHint": "Copy failed, please copy manually: ",
|
||||||
|
"cannotInferTarget": "Cannot infer scan target from row (include host/ip/port/domain in fields)",
|
||||||
|
"noSendMessage": "sendMessage() not found, please refresh and retry",
|
||||||
|
"filledToInput": "Filled to chat input, edit and send",
|
||||||
|
"noExportResult": "No results to export",
|
||||||
|
"xlsxNotLoaded": "XLSX library not loaded, please refresh and retry",
|
||||||
|
"noResults": "No results",
|
||||||
|
"selectRowsFirst": "Select rows to scan first",
|
||||||
|
"noScanTarget": "No scan targets inferred from selection (include host/ip/port/domain in fields)",
|
||||||
|
"batchScanFailed": "Batch scan failed",
|
||||||
|
"batchQueueCreated": "Batch scan queue created",
|
||||||
|
"field": "Field",
|
||||||
|
"parsePending": "AI parsing...",
|
||||||
|
"parsePendingClickCancel": "AI parsing... (click button to cancel)",
|
||||||
|
"parseSlow": "AI parse is taking a while, still processing…",
|
||||||
|
"parseDone": "AI parse complete",
|
||||||
|
"parseCancelled": "AI parse cancelled",
|
||||||
|
"parseFailed": "AI parse failed: ",
|
||||||
|
"parseResultTitle": "AI parse result",
|
||||||
|
"naturalLanguageLabel": "Natural language",
|
||||||
|
"fofaQueryEditable": "FOFA query (editable)",
|
||||||
|
"confirmBeforeQuery": "Confirm syntax and scope before running the query.",
|
||||||
|
"reminder": "Reminder",
|
||||||
|
"explanation": "Explanation",
|
||||||
|
"actions": "Actions",
|
||||||
|
"batchScanTitle": "FOFA batch scan",
|
||||||
|
"queueCreatedSkipped": "Queue created ({{n}} rows skipped, no target)",
|
||||||
|
"createQueueFailed": "Failed to create batch queue",
|
||||||
|
"loading": "Loading...",
|
||||||
|
"none": "None",
|
||||||
|
"truncated": "truncated",
|
||||||
|
"resultsMeta": "Total {{total}} · This page {{count}} · page={{page}} · size={{size}}",
|
||||||
|
"parseModalCancel": "Cancel",
|
||||||
|
"parseModalApply": "Fill into query",
|
||||||
|
"parseModalApplyRun": "Fill and query"
|
||||||
|
},
|
||||||
|
"vulnerability": {
|
||||||
|
"title": "Vulnerability management",
|
||||||
|
"addVuln": "Add vulnerability",
|
||||||
|
"editVuln": "Edit vulnerability",
|
||||||
|
"loadFailed": "Failed to load vulnerabilities",
|
||||||
|
"deleteConfirm": "Delete this vulnerability?"
|
||||||
|
},
|
||||||
|
"mcp": {
|
||||||
|
"monitorTitle": "MCP Status Monitor",
|
||||||
|
"execStats": "Execution stats",
|
||||||
|
"latestExecutions": "Latest executions",
|
||||||
|
"toolSearch": "Tool search",
|
||||||
|
"toolSearchPlaceholder": "Enter tool name...",
|
||||||
|
"statusFilter": "Status filter",
|
||||||
|
"filterAll": "All",
|
||||||
|
"selectedCount": "{{count}} selected",
|
||||||
|
"selectAll": "Select all",
|
||||||
|
"deselectAll": "Deselect all",
|
||||||
|
"deleteSelected": "Batch delete",
|
||||||
|
"deleteExecConfirm": "Delete this execution record?",
|
||||||
|
"batchDeleteFailed": "Batch delete failed",
|
||||||
|
"managementTitle": "MCP Management",
|
||||||
|
"addExternal": "Add external MCP",
|
||||||
|
"toolConfig": "MCP tool config",
|
||||||
|
"saveToolConfig": "Save tool config",
|
||||||
|
"externalConfig": "External MCP config",
|
||||||
|
"loadingTools": "Loading tools...",
|
||||||
|
"loadToolsTimeout": "Tools load timeout. External MCP may be slow. Click Refresh to retry or check connection.",
|
||||||
|
"loadToolsFailed": "Failed to load tools",
|
||||||
|
"noTools": "No tools",
|
||||||
|
"externalBadge": "External",
|
||||||
|
"externalFrom": "External ({{name}})",
|
||||||
|
"externalToolFrom": "External MCP - Source: {{name}}",
|
||||||
|
"noDescription": "No description",
|
||||||
|
"paginationInfo": "{{start}}-{{end}} of {{total}} tools",
|
||||||
|
"perPage": "Per page:",
|
||||||
|
"firstPage": "First",
|
||||||
|
"prevPage": "Previous",
|
||||||
|
"nextPage": "Next",
|
||||||
|
"lastPage": "Last",
|
||||||
|
"pageInfo": "Page {{page}} of {{total}}",
|
||||||
|
"currentPageEnabled": "Enabled on current page",
|
||||||
|
"totalEnabled": "Total enabled",
|
||||||
|
"toolsConfigSaved": "Tool configuration saved!",
|
||||||
|
"saveToolsConfigFailed": "Failed to save tool config",
|
||||||
|
"getConfigFailed": "Failed to get config",
|
||||||
|
"noExternalMCP": "No external MCP configured",
|
||||||
|
"clickToAddExternal": "Click \"Add external MCP\" to configure",
|
||||||
|
"connected": "Connected",
|
||||||
|
"connecting": "Connecting...",
|
||||||
|
"connectionFailed": "Connection failed",
|
||||||
|
"disabled": "Disabled",
|
||||||
|
"disconnected": "Disconnected",
|
||||||
|
"stopConnection": "Stop connection",
|
||||||
|
"startConnection": "Start connection",
|
||||||
|
"stop": "Stop",
|
||||||
|
"start": "Start",
|
||||||
|
"editConfig": "Edit config",
|
||||||
|
"deleteConfig": "Delete config",
|
||||||
|
"transportMode": "Transport",
|
||||||
|
"toolCount": "Tool count",
|
||||||
|
"description": "Description",
|
||||||
|
"timeout": "Timeout",
|
||||||
|
"command": "Command",
|
||||||
|
"addExternalMCP": "Add external MCP",
|
||||||
|
"editExternalMCP": "Edit external MCP",
|
||||||
|
"jsonEmpty": "JSON cannot be empty",
|
||||||
|
"jsonError": "JSON format error",
|
||||||
|
"configMustBeObject": "Config error: Must be JSON object with name as key",
|
||||||
|
"configNeedOne": "Config error: At least one config item required",
|
||||||
|
"configNameEmpty": "Config error: Name cannot be empty",
|
||||||
|
"configMustBeObj": "Config error: \"{{name}}\" must be object",
|
||||||
|
"configNeedCommand": "Config error: \"{{name}}\" needs command (stdio) or url (http/sse)",
|
||||||
|
"configStdioNeedCommand": "Config error: \"{{name}}\" stdio mode needs command",
|
||||||
|
"configHttpNeedUrl": "Config error: \"{{name}}\" http mode needs url",
|
||||||
|
"configSseNeedUrl": "Config error: \"{{name}}\" sse mode needs url",
|
||||||
|
"saveSuccess": "Saved",
|
||||||
|
"deleteSuccess": "Deleted",
|
||||||
|
"deleteExternalConfirm": "Delete external MCP \"{{name}}\"?",
|
||||||
|
"operationFailed": "Operation failed",
|
||||||
|
"connectionFailedCheck": "Connection failed. Check config and network.",
|
||||||
|
"connectionTimeout": "Connection timeout. Check config and network.",
|
||||||
|
"totalCount": "Total",
|
||||||
|
"enabledCount": "Enabled",
|
||||||
|
"disabledCount": "Disabled",
|
||||||
|
"connectedCount": "Connected"
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"title": "System settings",
|
||||||
|
"nav": {
|
||||||
|
"basic": "Basic",
|
||||||
|
"robots": "Bots",
|
||||||
|
"terminal": "Terminal",
|
||||||
|
"security": "Security"
|
||||||
|
},
|
||||||
|
"robots": {
|
||||||
|
"title": "Bot settings",
|
||||||
|
"description": "Configure WeCom, DingTalk and Lark bots so you can chat with CyberStrikeAI on your phone without opening the web UI.",
|
||||||
|
"wecom": {
|
||||||
|
"title": "WeCom",
|
||||||
|
"enabled": "Enable WeCom bot"
|
||||||
|
},
|
||||||
|
"dingtalk": {
|
||||||
|
"title": "DingTalk",
|
||||||
|
"enabled": "Enable DingTalk bot"
|
||||||
|
},
|
||||||
|
"lark": {
|
||||||
|
"title": "Lark",
|
||||||
|
"enabled": "Enable Lark bot"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"apply": {
|
||||||
|
"button": "Apply configuration",
|
||||||
|
"loadFailed": "Failed to load configuration",
|
||||||
|
"fillRequired": "Please fill in all required fields (marked with *)",
|
||||||
|
"applyFailed": "Failed to apply configuration",
|
||||||
|
"applySuccess": "Configuration applied successfully!"
|
||||||
|
},
|
||||||
|
"security": {
|
||||||
|
"changePassword": "Change password",
|
||||||
|
"fillPasswordHint": "Fill current and new password correctly. New password at least 8 characters, must match twice.",
|
||||||
|
"changePasswordFailed": "Failed to change password",
|
||||||
|
"passwordUpdated": "Password updated. Please sign in again with new password."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"sessionExpired": "Session expired, please sign in again",
|
||||||
|
"unauthorized": "Unauthorized",
|
||||||
|
"enterPassword": "Please enter password",
|
||||||
|
"loginFailedCheck": "Sign-in failed, please check the password",
|
||||||
|
"loginFailedRetry": "Sign-in failed, please try again later",
|
||||||
|
"loggedOut": "Signed out"
|
||||||
|
},
|
||||||
|
"knowledge": {
|
||||||
|
"title": "Knowledge management",
|
||||||
|
"retrievalLogs": "Retrieval history",
|
||||||
|
"totalItems": "Total items",
|
||||||
|
"categories": "Categories",
|
||||||
|
"addKnowledge": "Add knowledge",
|
||||||
|
"rebuildIndex": "Rebuild index",
|
||||||
|
"rebuildIndexConfirm": "Rebuild index?",
|
||||||
|
"deleteItemConfirm": "Delete this knowledge item?",
|
||||||
|
"notEnabledTitle": "Knowledge base function not enabled",
|
||||||
|
"notEnabledHint": "Please go to system settings to enable knowledge retrieval.",
|
||||||
|
"goToSettings": "Go to settings"
|
||||||
|
},
|
||||||
|
"roles": {
|
||||||
|
"title": "Role management",
|
||||||
|
"createRole": "Create role",
|
||||||
|
"searchPlaceholder": "Search roles...",
|
||||||
|
"deleteConfirm": "Delete this role?"
|
||||||
|
},
|
||||||
|
"skills": {
|
||||||
|
"title": "Skills management",
|
||||||
|
"monitorTitle": "Skills monitor",
|
||||||
|
"createSkill": "Create Skill",
|
||||||
|
"callStats": "Call stats",
|
||||||
|
"addSkill": "Add Skill",
|
||||||
|
"editSkill": "Edit Skill",
|
||||||
|
"loadListFailed": "Failed to load skills list",
|
||||||
|
"noSkills": "No skills. Click \"Create Skill\" to add first.",
|
||||||
|
"noMatch": "No matching skills",
|
||||||
|
"searchFailed": "Search failed",
|
||||||
|
"refreshed": "Refreshed",
|
||||||
|
"loadDetailFailed": "Failed to load skill details",
|
||||||
|
"viewFailed": "Failed to view skill",
|
||||||
|
"saving": "Saving...",
|
||||||
|
"saveFailed": "Failed to save skill",
|
||||||
|
"deleteFailed": "Failed to delete skill",
|
||||||
|
"loadStatsFailed": "Failed to load skills monitor data",
|
||||||
|
"clearStatsConfirm": "Clear all Skills statistics? This cannot be undone.",
|
||||||
|
"statsCleared": "Skills statistics cleared",
|
||||||
|
"clearStatsFailed": "Failed to clear statistics"
|
||||||
|
},
|
||||||
|
"apiDocs": {
|
||||||
|
"curlCopied": "curl command copied to clipboard!"
|
||||||
|
},
|
||||||
|
"chatGroup": {
|
||||||
|
"search": "Search",
|
||||||
|
"edit": "Edit",
|
||||||
|
"delete": "Delete",
|
||||||
|
"clearSearch": "Clear search",
|
||||||
|
"searchInGroupPlaceholder": "Search in group...",
|
||||||
|
"attackChain": "Attack chain",
|
||||||
|
"viewAttackChain": "View attack chain",
|
||||||
|
"selectRole": "Select role",
|
||||||
|
"close": "Close",
|
||||||
|
"selectFile": "Select file",
|
||||||
|
"uploadFile": "Upload file (multi-select or drag & drop)",
|
||||||
|
"send": "Send",
|
||||||
|
"rolePanelTitle": "Select role",
|
||||||
|
"copyMessage": "Copy message",
|
||||||
|
"remove": "Remove"
|
||||||
|
},
|
||||||
|
"mcpMonitor": {
|
||||||
|
"deselectAll": "Deselect all",
|
||||||
|
"statusPending": "Pending",
|
||||||
|
"statusCompleted": "Completed",
|
||||||
|
"statusRunning": "Running",
|
||||||
|
"statusFailed": "Failed",
|
||||||
|
"loading": "Loading...",
|
||||||
|
"noStatsData": "No statistical data",
|
||||||
|
"noExecutions": "No execution records",
|
||||||
|
"noRecordsWithFilter": "No records with current filter",
|
||||||
|
"paginationInfo": "Show {{start}}-{{end}} of {{total}} records",
|
||||||
|
"perPageLabel": "Per page",
|
||||||
|
"loadStatsError": "Failed to load statistics",
|
||||||
|
"loadExecutionsError": "Failed to load execution records",
|
||||||
|
"totalCalls": "Total calls",
|
||||||
|
"successFailed": "Success {{success}} / Failed {{failed}}",
|
||||||
|
"successRate": "Success rate",
|
||||||
|
"statsFromAllTools": "From all tool calls",
|
||||||
|
"lastCall": "Last call",
|
||||||
|
"lastRefreshTime": "Last refresh",
|
||||||
|
"noCallsYet": "No calls yet",
|
||||||
|
"unknownTool": "Unknown tool",
|
||||||
|
"successFailedRate": "Success {{success}} / Failed {{failed}} · {{rate}}% success rate",
|
||||||
|
"columnTool": "Tool",
|
||||||
|
"columnStatus": "Status",
|
||||||
|
"columnStartTime": "Start time",
|
||||||
|
"columnDuration": "Duration",
|
||||||
|
"columnActions": "Actions",
|
||||||
|
"viewDetail": "View details",
|
||||||
|
"delete": "Delete",
|
||||||
|
"deleteExecTitle": "Delete this execution record",
|
||||||
|
"deleteExecConfirmSingle": "Are you sure you want to delete this execution record? This cannot be undone.",
|
||||||
|
"deleteExecFailed": "Failed to delete execution record",
|
||||||
|
"execDeleted": "Execution record deleted",
|
||||||
|
"selectExecFirst": "Please select execution record(s) to delete first",
|
||||||
|
"batchDeleteConfirm": "Are you sure you want to delete the selected {{count}} execution record(s)? This cannot be undone.",
|
||||||
|
"batchDeleteSuccess": "Successfully deleted {{count}} execution record(s)",
|
||||||
|
"unknown": "Unknown",
|
||||||
|
"durationSeconds": "{{n}} sec",
|
||||||
|
"durationMinutes": "{{minutes}} min {{seconds}} sec",
|
||||||
|
"durationMinutesOnly": "{{minutes}} min",
|
||||||
|
"durationHours": "{{hours}} hr {{minutes}} min",
|
||||||
|
"durationHoursOnly": "{{hours}} hr"
|
||||||
|
},
|
||||||
|
"knowledgePage": {
|
||||||
|
"totalContent": "Total content",
|
||||||
|
"categoryFilter": "Category filter",
|
||||||
|
"all": "All",
|
||||||
|
"searchPlaceholder": "Search knowledge...",
|
||||||
|
"loading": "Loading..."
|
||||||
|
},
|
||||||
|
"retrievalLogs": {
|
||||||
|
"totalRetrievals": "Total retrievals",
|
||||||
|
"successRetrievals": "Success",
|
||||||
|
"successRate": "Success rate",
|
||||||
|
"retrievedItems": "Items retrieved",
|
||||||
|
"conversationId": "Conversation ID",
|
||||||
|
"messageId": "Message ID",
|
||||||
|
"filter": "Filter",
|
||||||
|
"optionalConversation": "Optional: filter by conversation",
|
||||||
|
"optionalMessage": "Optional: filter by message",
|
||||||
|
"loading": "Loading...",
|
||||||
|
"noRecords": "No retrieval records yet",
|
||||||
|
"noQuery": "No query content",
|
||||||
|
"itemsUnit": "items",
|
||||||
|
"hasResults": "Has results",
|
||||||
|
"noResults": "No results",
|
||||||
|
"clickToCopy": "Click to copy",
|
||||||
|
"retrievalResult": "Retrieval result",
|
||||||
|
"foundCount": "Found {{count}} related knowledge item(s)",
|
||||||
|
"foundUnknown": "Found related knowledge (count unknown)",
|
||||||
|
"noMatch": "No matching knowledge items",
|
||||||
|
"retrievedItemsLabel": "Retrieved knowledge items:",
|
||||||
|
"viewDetails": "View details",
|
||||||
|
"loadError": "Failed to load retrieval logs",
|
||||||
|
"detailError": "Unable to get retrieval details",
|
||||||
|
"deleteError": "Failed to delete retrieval log",
|
||||||
|
"detailsTitle": "Retrieval details",
|
||||||
|
"queryInfo": "Query info",
|
||||||
|
"queryContent": "Query content:",
|
||||||
|
"retrievalInfo": "Retrieval info",
|
||||||
|
"riskType": "Risk type",
|
||||||
|
"retrievalTime": "Retrieval time",
|
||||||
|
"noItemDetails": "No knowledge item details found",
|
||||||
|
"noContentPreview": "No content preview",
|
||||||
|
"untitled": "Untitled",
|
||||||
|
"uncategorized": "Uncategorized",
|
||||||
|
"relatedInfo": "Related info",
|
||||||
|
"itemsCount": "{{count}} knowledge item(s)",
|
||||||
|
"deleteConfirm": "Delete this retrieval record?"
|
||||||
|
},
|
||||||
|
"infoCollectPage": {
|
||||||
|
"title": "Recon",
|
||||||
|
"reset": "Reset",
|
||||||
|
"confirm": "OK",
|
||||||
|
"fofaQuerySyntax": "FOFA query syntax",
|
||||||
|
"naturalLanguage": "Natural language (AI parses to FOFA)",
|
||||||
|
"returnCount": "Return count",
|
||||||
|
"pageNum": "Page",
|
||||||
|
"returnFields": "Return fields (comma-separated)",
|
||||||
|
"queryResults": "Query results",
|
||||||
|
"selectedRows": "{{count}} selected",
|
||||||
|
"selectedRowsZero": "0 selected",
|
||||||
|
"columns": "Columns",
|
||||||
|
"exportCsv": "Export CSV",
|
||||||
|
"exportJson": "Export JSON",
|
||||||
|
"exportXlsx": "Export XLSX",
|
||||||
|
"batchScan": "Batch scan",
|
||||||
|
"showColumns": "Show columns",
|
||||||
|
"columnsPanelAll": "Select all",
|
||||||
|
"columnsPanelNone": "Deselect all",
|
||||||
|
"columnsPanelClose": "Close",
|
||||||
|
"formHint": "See FOFA docs for query syntax; supports && / || / ().",
|
||||||
|
"parseBtn": "AI parse",
|
||||||
|
"parseHint": "Result will open in a popup for editing before running the query.",
|
||||||
|
"minFields": "Min fields",
|
||||||
|
"webCommon": "Web common",
|
||||||
|
"intelEnhanced": "Intel enhanced",
|
||||||
|
"presetApache": "Apache + China",
|
||||||
|
"presetLogin": "Login page + China",
|
||||||
|
"presetDomain": "By domain",
|
||||||
|
"presetIp": "By IP",
|
||||||
|
"nlPlaceholder": "e.g. Apache sites in Missouri, US, title contains Home",
|
||||||
|
"showHideColumns": "Show/hide columns",
|
||||||
|
"exportCsvTitle": "Export results as CSV (UTF-8)",
|
||||||
|
"exportJsonTitle": "Export results as JSON",
|
||||||
|
"exportXlsxTitle": "Export results as Excel",
|
||||||
|
"batchScanTitle": "Create batch task queue from selected rows"
|
||||||
|
},
|
||||||
|
"vulnerabilityPage": {
|
||||||
|
"statTotal": "Total",
|
||||||
|
"filter": "Filter",
|
||||||
|
"clear": "Clear",
|
||||||
|
"vulnId": "Vuln ID",
|
||||||
|
"conversationId": "Conversation ID",
|
||||||
|
"severity": "Severity",
|
||||||
|
"status": "Status",
|
||||||
|
"statusOpen": "Open",
|
||||||
|
"statusConfirmed": "Confirmed",
|
||||||
|
"statusFixed": "Fixed",
|
||||||
|
"statusFalsePositive": "False positive",
|
||||||
|
"searchVulnId": "Search vuln ID",
|
||||||
|
"filterConversation": "Filter by conversation",
|
||||||
|
"loading": "Loading...",
|
||||||
|
"noRecords": "No vulnerability records"
|
||||||
|
},
|
||||||
|
"tasksPage": {
|
||||||
|
"statusFilter": "Status filter",
|
||||||
|
"statusPending": "Pending",
|
||||||
|
"statusPaused": "Paused",
|
||||||
|
"statusCancelled": "Cancelled",
|
||||||
|
"searchQueuePlaceholder": "Search queue ID, title or created time",
|
||||||
|
"searchKeywordPlaceholder": "Enter keyword..."
|
||||||
|
},
|
||||||
|
"skillsPage": {
|
||||||
|
"clearStats": "Clear stats",
|
||||||
|
"clearStatsTitle": "Clear all statistics",
|
||||||
|
"skillsCallStats": "Skills call stats",
|
||||||
|
"searchPlaceholder": "Search Skills...",
|
||||||
|
"loading": "Loading..."
|
||||||
|
},
|
||||||
|
"settingsBasic": {
|
||||||
|
"basicTitle": "Basic settings",
|
||||||
|
"openaiConfig": "OpenAI config",
|
||||||
|
"fofaConfig": "FOFA config",
|
||||||
|
"agentConfig": "Agent config",
|
||||||
|
"knowledgeConfig": "Knowledge base config",
|
||||||
|
"baseUrl": "Base URL",
|
||||||
|
"apiKey": "API Key",
|
||||||
|
"model": "Model",
|
||||||
|
"openaiBaseUrlPlaceholder": "https://api.openai.com/v1",
|
||||||
|
"openaiApiKeyPlaceholder": "Enter OpenAI API Key",
|
||||||
|
"modelPlaceholder": "gpt-4",
|
||||||
|
"fofaBaseUrlPlaceholder": "https://fofa.info/api/v1/search/all (optional)",
|
||||||
|
"fofaBaseUrlHint": "Leave empty for default.",
|
||||||
|
"email": "Email",
|
||||||
|
"fofaEmailPlaceholder": "Enter FOFA email",
|
||||||
|
"fofaApiKeyPlaceholder": "Enter FOFA API Key",
|
||||||
|
"fofaApiKeyHint": "Stored in server config (config.yaml) only.",
|
||||||
|
"maxIterations": "Max iterations",
|
||||||
|
"iterationsPlaceholder": "30",
|
||||||
|
"enableKnowledge": "Enable knowledge retrieval",
|
||||||
|
"knowledgeBasePath": "Knowledge base path",
|
||||||
|
"knowledgeBasePathPlaceholder": "knowledge_base",
|
||||||
|
"knowledgeBasePathHint": "Relative to config file directory",
|
||||||
|
"embeddingConfig": "Embedding config",
|
||||||
|
"provider": "Provider",
|
||||||
|
"embeddingBaseUrlPlaceholder": "Leave empty to use OpenAI base_url",
|
||||||
|
"embeddingApiKeyPlaceholder": "Leave empty to use OpenAI api_key",
|
||||||
|
"modelName": "Model name",
|
||||||
|
"embeddingModelPlaceholder": "text-embedding-v4",
|
||||||
|
"retrievalConfig": "Retrieval config",
|
||||||
|
"topK": "Top-K results",
|
||||||
|
"topKPlaceholder": "5",
|
||||||
|
"topKHint": "Number of top-K results to return",
|
||||||
|
"similarityThreshold": "Similarity threshold",
|
||||||
|
"similarityPlaceholder": "0.7",
|
||||||
|
"similarityHint": "Results below this value are filtered (0-1)",
|
||||||
|
"hybridWeight": "Hybrid weight",
|
||||||
|
"hybridPlaceholder": "0.7",
|
||||||
|
"hybridHint": "Vector weight (0-1); 1.0 = vector only, 0.0 = keyword only",
|
||||||
|
"indexConfig": "Index config",
|
||||||
|
"chunkSize": "Chunk size",
|
||||||
|
"chunkSizePlaceholder": "512",
|
||||||
|
"chunkSizeHint": "Max tokens per chunk (default 512)",
|
||||||
|
"chunkOverlap": "Chunk overlap",
|
||||||
|
"chunkOverlapPlaceholder": "50",
|
||||||
|
"chunkOverlapHint": "Overlap tokens between chunks (default 50)",
|
||||||
|
"maxChunksPerItem": "Max chunks per item",
|
||||||
|
"maxChunksPlaceholder": "0",
|
||||||
|
"maxChunksHint": "Max chunks per knowledge item (0 = no limit)",
|
||||||
|
"maxRpm": "Max RPM",
|
||||||
|
"maxRpmPlaceholder": "0",
|
||||||
|
"maxRpmHint": "Max requests per minute (0 = no limit)",
|
||||||
|
"rateLimitDelay": "Rate limit delay (ms)",
|
||||||
|
"rateLimitPlaceholder": "300",
|
||||||
|
"rateLimitHint": "Delay between requests (ms); 0 = no limit",
|
||||||
|
"maxRetries": "Max retries",
|
||||||
|
"maxRetriesPlaceholder": "3",
|
||||||
|
"maxRetriesHint": "Retries on rate limit or server error",
|
||||||
|
"retryDelay": "Retry delay (ms)",
|
||||||
|
"retryDelayPlaceholder": "1000",
|
||||||
|
"retryDelayHint": "Delay between retries (ms)"
|
||||||
|
},
|
||||||
|
"settingsTerminal": {
|
||||||
|
"title": "Terminal",
|
||||||
|
"description": "Run commands on the server for ops and debugging. Commands run on the server; avoid sensitive or destructive operations.",
|
||||||
|
"terminalTab": "Terminal {{n}}",
|
||||||
|
"close": "Close",
|
||||||
|
"newTerminal": "New terminal"
|
||||||
|
},
|
||||||
|
"settingsSecurity": {
|
||||||
|
"changePasswordTitle": "Change password",
|
||||||
|
"changePasswordDesc": "After changing password, sign in again with the new password.",
|
||||||
|
"currentPassword": "Current password",
|
||||||
|
"currentPasswordPlaceholder": "Enter current password",
|
||||||
|
"newPassword": "New password",
|
||||||
|
"newPasswordPlaceholder": "New password (at least 8 characters)",
|
||||||
|
"confirmPassword": "Confirm new password",
|
||||||
|
"confirmPasswordPlaceholder": "Enter new password again",
|
||||||
|
"clear": "Clear",
|
||||||
|
"changePasswordBtn": "Change password"
|
||||||
|
},
|
||||||
|
"settingsRobotsExtra": {
|
||||||
|
"botCommandsTitle": "Bot commands",
|
||||||
|
"botCommandsDesc": "You can send these commands in chat (Chinese and English supported):"
|
||||||
|
},
|
||||||
|
"mcpDetailModal": {
|
||||||
|
"title": "Tool call details",
|
||||||
|
"execInfo": "Execution info",
|
||||||
|
"tool": "Tool",
|
||||||
|
"status": "Status",
|
||||||
|
"time": "Time",
|
||||||
|
"executionId": "Execution ID",
|
||||||
|
"requestParams": "Request params",
|
||||||
|
"copyJson": "Copy JSON",
|
||||||
|
"responseResult": "Response",
|
||||||
|
"copyContent": "Copy content",
|
||||||
|
"correctInfo": "Correct info",
|
||||||
|
"errorInfo": "Error info",
|
||||||
|
"copyError": "Copy error"
|
||||||
|
},
|
||||||
|
"attackChainModal": {
|
||||||
|
"title": "Attack chain",
|
||||||
|
"regenerate": "Regenerate",
|
||||||
|
"regenerateTitle": "Regenerate attack chain (include latest conversation)",
|
||||||
|
"exportPng": "Export PNG",
|
||||||
|
"exportSvg": "Export SVG",
|
||||||
|
"refreshTitle": "Refresh current attack chain",
|
||||||
|
"nodesEdges": "Nodes: {{nodes}} | Edges: {{edges}}",
|
||||||
|
"searchPlaceholder": "Search nodes...",
|
||||||
|
"allTypes": "All types",
|
||||||
|
"target": "Target",
|
||||||
|
"action": "Action",
|
||||||
|
"vulnerability": "Vulnerability",
|
||||||
|
"allRisks": "All risks",
|
||||||
|
"highRisk": "High (80-100)",
|
||||||
|
"mediumHighRisk": "Medium-high (60-79)",
|
||||||
|
"mediumRisk": "Medium (40-59)",
|
||||||
|
"lowRisk": "Low (0-39)",
|
||||||
|
"resetFilter": "Reset filter",
|
||||||
|
"loading": "Loading...",
|
||||||
|
"riskLevel": "Risk level",
|
||||||
|
"lineMeaning": "Line meaning",
|
||||||
|
"blueLine": "Blue: action finds vulnerability",
|
||||||
|
"redLine": "Red: enables/contributes",
|
||||||
|
"grayLine": "Gray: logical order",
|
||||||
|
"nodeDetails": "Node details",
|
||||||
|
"closeDetails": "Close details"
|
||||||
|
},
|
||||||
|
"externalMcpModal": {
|
||||||
|
"configJson": "Config JSON",
|
||||||
|
"formatLabel": "Format:",
|
||||||
|
"formatDesc": "JSON object; key = config name, value = config. Use Start/Stop buttons to control state.",
|
||||||
|
"formatJson": "Format JSON",
|
||||||
|
"loadExample": "Load example"
|
||||||
|
},
|
||||||
|
"skillModal": {
|
||||||
|
"addSkill": "Add Skill",
|
||||||
|
"editSkill": "Edit Skill",
|
||||||
|
"skillName": "Skill name",
|
||||||
|
"skillNamePlaceholder": "e.g. sql-injection-testing",
|
||||||
|
"skillNameHint": "Letters, numbers, hyphens and underscores only",
|
||||||
|
"description": "Description",
|
||||||
|
"descriptionPlaceholder": "Short description",
|
||||||
|
"contentLabel": "Content (Markdown)",
|
||||||
|
"contentPlaceholder": "Enter skill content in Markdown...",
|
||||||
|
"contentHint": "YAML front matter supported (optional)"
|
||||||
|
},
|
||||||
|
"knowledgeItemModal": {
|
||||||
|
"addKnowledge": "Add knowledge",
|
||||||
|
"editKnowledge": "Edit knowledge",
|
||||||
|
"category": "Category (risk type)",
|
||||||
|
"categoryPlaceholder": "e.g. SQL injection",
|
||||||
|
"title": "Title",
|
||||||
|
"titlePlaceholder": "Knowledge item title",
|
||||||
|
"contentLabel": "Content (Markdown)",
|
||||||
|
"contentPlaceholder": "Enter content in Markdown..."
|
||||||
|
},
|
||||||
|
"batchManageModal": {
|
||||||
|
"title": "Manage conversations · {{count}} total",
|
||||||
|
"searchPlaceholder": "Search history",
|
||||||
|
"conversationName": "Conversation name",
|
||||||
|
"lastTime": "Last activity",
|
||||||
|
"action": "Action",
|
||||||
|
"selectAll": "Select all",
|
||||||
|
"deleteSelected": "Delete selected",
|
||||||
|
"confirmDeleteNone": "Please select at least one conversation to delete",
|
||||||
|
"confirmDeleteN": "Delete {{count}} selected conversation(s)?",
|
||||||
|
"deleteFailed": "Delete failed",
|
||||||
|
"unnamedConversation": "Unnamed conversation"
|
||||||
|
},
|
||||||
|
"createGroupModal": {
|
||||||
|
"title": "Create group",
|
||||||
|
"description": "Group conversations for easier management.",
|
||||||
|
"selectIcon": "Click to choose icon",
|
||||||
|
"groupNamePlaceholder": "Enter group name",
|
||||||
|
"pickIcon": "Pick icon",
|
||||||
|
"customIcon": "Custom",
|
||||||
|
"confirmIcon": "OK",
|
||||||
|
"create": "Create",
|
||||||
|
"cancel": "Cancel",
|
||||||
|
"suggestionPenetrationTest": "Penetration Testing",
|
||||||
|
"suggestionCtf": "CTF",
|
||||||
|
"suggestionRedTeam": "Red Team",
|
||||||
|
"suggestionVulnerabilityMining": "Vulnerability Mining",
|
||||||
|
"nameExists": "Group name already exists, please use another name.",
|
||||||
|
"createFailed": "Create failed",
|
||||||
|
"unknownError": "Unknown error"
|
||||||
|
},
|
||||||
|
"contextMenu": {
|
||||||
|
"viewAttackChain": "View attack chain",
|
||||||
|
"rename": "Rename",
|
||||||
|
"pinConversation": "Pin conversation",
|
||||||
|
"unpinConversation": "Unpin",
|
||||||
|
"batchManage": "Batch manage",
|
||||||
|
"moveToGroup": "Move to group",
|
||||||
|
"deleteConversation": "Delete conversation",
|
||||||
|
"pinGroup": "Pin group",
|
||||||
|
"unpinGroup": "Unpin",
|
||||||
|
"deleteGroup": "Delete group"
|
||||||
|
},
|
||||||
|
"batchImportModal": {
|
||||||
|
"title": "New task",
|
||||||
|
"queueTitle": "Queue title",
|
||||||
|
"queueTitlePlaceholder": "Enter queue title (optional, for identification and filtering)",
|
||||||
|
"queueTitleHint": "Set a title for the batch task queue to make it easier to find and manage later.",
|
||||||
|
"role": "Role",
|
||||||
|
"defaultRole": "Default",
|
||||||
|
"roleHint": "Select a role; all tasks will be executed using that role's configuration (prompt and tools).",
|
||||||
|
"tasksList": "Task list (one task per line)",
|
||||||
|
"tasksListPlaceholder": "Enter task list, one per line",
|
||||||
|
"tasksListPlaceholderExample": "Enter task list, one per line, for example:\nScan open ports of 192.168.1.1\nCheck if https://example.com has SQL injection\nEnumerate subdomains of example.com",
|
||||||
|
"tasksListHint": "Enter one task command per line; the system will execute them in order. Empty lines are ignored.",
|
||||||
|
"tasksListHintFull": "Hint: Enter one task command per line; the system will execute these tasks in order. Empty lines are ignored.",
|
||||||
|
"createQueue": "Create queue"
|
||||||
|
},
|
||||||
|
"batchQueueDetailModal": {
|
||||||
|
"title": "Batch queue details",
|
||||||
|
"addTask": "Add task",
|
||||||
|
"startExecute": "Start",
|
||||||
|
"pauseQueue": "Pause queue",
|
||||||
|
"deleteQueue": "Delete queue",
|
||||||
|
"queueTitle": "Task title",
|
||||||
|
"role": "Role",
|
||||||
|
"defaultRole": "Default",
|
||||||
|
"queueId": "Queue ID",
|
||||||
|
"status": "Status",
|
||||||
|
"createdAt": "Created at",
|
||||||
|
"startedAt": "Started at",
|
||||||
|
"completedAt": "Completed at",
|
||||||
|
"taskTotal": "Total tasks",
|
||||||
|
"taskList": "Task list",
|
||||||
|
"startLabel": "Start",
|
||||||
|
"completeLabel": "Complete",
|
||||||
|
"errorLabel": "Error",
|
||||||
|
"resultLabel": "Result"
|
||||||
|
},
|
||||||
|
"editBatchTaskModal": {
|
||||||
|
"title": "Edit task",
|
||||||
|
"taskMessage": "Task message",
|
||||||
|
"taskMessagePlaceholder": "Enter task message"
|
||||||
|
},
|
||||||
|
"addBatchTaskModal": {
|
||||||
|
"title": "Add task",
|
||||||
|
"taskMessage": "Task message",
|
||||||
|
"taskMessagePlaceholder": "Enter task message",
|
||||||
|
"add": "Add"
|
||||||
|
},
|
||||||
|
"vulnerabilityModal": {
|
||||||
|
"conversationId": "Conversation ID",
|
||||||
|
"conversationIdPlaceholder": "Enter conversation ID",
|
||||||
|
"title": "Title",
|
||||||
|
"titlePlaceholder": "Vulnerability title",
|
||||||
|
"description": "Description",
|
||||||
|
"descriptionPlaceholder": "Detailed description",
|
||||||
|
"severity": "Severity",
|
||||||
|
"pleaseSelect": "Please select",
|
||||||
|
"severityCritical": "Critical",
|
||||||
|
"severityHigh": "High",
|
||||||
|
"severityMedium": "Medium",
|
||||||
|
"severityLow": "Low",
|
||||||
|
"severityInfo": "Info",
|
||||||
|
"status": "Status",
|
||||||
|
"statusOpen": "Open",
|
||||||
|
"statusConfirmed": "Confirmed",
|
||||||
|
"statusFixed": "Fixed",
|
||||||
|
"statusFalsePositive": "False positive",
|
||||||
|
"type": "Vulnerability type",
|
||||||
|
"typePlaceholder": "e.g. SQL injection, XSS, CSRF",
|
||||||
|
"target": "Target",
|
||||||
|
"targetPlaceholder": "Affected target (URL, IP, etc.)",
|
||||||
|
"proof": "Proof (POC)",
|
||||||
|
"proofPlaceholder": "Proof: request/response, screenshots, etc.",
|
||||||
|
"impact": "Impact",
|
||||||
|
"impactPlaceholder": "Impact description",
|
||||||
|
"recommendation": "Recommendation",
|
||||||
|
"recommendationPlaceholder": "Remediation"
|
||||||
|
},
|
||||||
|
"roleModal": {
|
||||||
|
"addRole": "Add role",
|
||||||
|
"editRole": "Edit role",
|
||||||
|
"roleName": "Role name",
|
||||||
|
"roleNamePlaceholder": "Enter role name",
|
||||||
|
"roleDescription": "Role description",
|
||||||
|
"roleDescriptionPlaceholder": "Enter role description",
|
||||||
|
"roleIcon": "Role icon",
|
||||||
|
"roleIconPlaceholder": "Enter emoji, e.g. 🏆",
|
||||||
|
"roleIconHint": "Emoji shown in role selector.",
|
||||||
|
"userPrompt": "User prompt",
|
||||||
|
"userPromptPlaceholder": "Appended before user message...",
|
||||||
|
"userPromptHint": "This prompt is appended before user message to guide AI. It does not change system prompt.",
|
||||||
|
"relatedTools": "Related tools (optional)",
|
||||||
|
"defaultRoleToolsTitle": "Default role uses all tools",
|
||||||
|
"defaultRoleToolsDesc": "Default role uses all tools enabled in MCP management.",
|
||||||
|
"searchToolsPlaceholder": "Search tools...",
|
||||||
|
"loadingTools": "Loading tools...",
|
||||||
|
"relatedToolsHint": "Select tools to link; empty = use all from MCP management.",
|
||||||
|
"relatedSkills": "Related Skills (optional)",
|
||||||
|
"searchSkillsPlaceholder": "Search skill...",
|
||||||
|
"loadingSkills": "Loading skills...",
|
||||||
|
"relatedSkillsHint": "Selected skills are injected into system prompt before task execution.",
|
||||||
|
"enableRole": "Enable this role"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,925 @@
|
|||||||
|
{
|
||||||
|
"common": {
|
||||||
|
"ok": "确定",
|
||||||
|
"cancel": "取消",
|
||||||
|
"refresh": "刷新",
|
||||||
|
"close": "关闭",
|
||||||
|
"edit": "编辑",
|
||||||
|
"delete": "删除",
|
||||||
|
"save": "保存",
|
||||||
|
"loading": "加载中…",
|
||||||
|
"search": "搜索",
|
||||||
|
"clearSearch": "清除搜索",
|
||||||
|
"noData": "暂无数据",
|
||||||
|
"confirm": "确认",
|
||||||
|
"copy": "复制",
|
||||||
|
"copied": "已复制",
|
||||||
|
"copyFailed": "复制失败"
|
||||||
|
},
|
||||||
|
"header": {
|
||||||
|
"title": "CyberStrikeAI",
|
||||||
|
"apiDocs": "API 文档",
|
||||||
|
"logout": "退出登录",
|
||||||
|
"language": "界面语言",
|
||||||
|
"backToDashboard": "返回仪表盘",
|
||||||
|
"userMenu": "用户菜单",
|
||||||
|
"version": "当前版本",
|
||||||
|
"toggleSidebar": "折叠/展开侧边栏"
|
||||||
|
},
|
||||||
|
"login": {
|
||||||
|
"title": "登录 CyberStrikeAI",
|
||||||
|
"subtitle": "请输入配置中的访问密码",
|
||||||
|
"passwordLabel": "密码",
|
||||||
|
"passwordPlaceholder": "输入登录密码",
|
||||||
|
"submit": "登录"
|
||||||
|
},
|
||||||
|
"nav": {
|
||||||
|
"dashboard": "仪表盘",
|
||||||
|
"chat": "对话",
|
||||||
|
"infoCollect": "信息收集",
|
||||||
|
"tasks": "任务管理",
|
||||||
|
"vulnerabilities": "漏洞管理",
|
||||||
|
"mcp": "MCP",
|
||||||
|
"mcpMonitor": "MCP状态监控",
|
||||||
|
"mcpManagement": "MCP管理",
|
||||||
|
"knowledge": "知识",
|
||||||
|
"knowledgeRetrievalLogs": "检索历史",
|
||||||
|
"knowledgeManagement": "知识管理",
|
||||||
|
"skills": "Skills",
|
||||||
|
"skillsMonitor": "Skills状态监控",
|
||||||
|
"skillsManagement": "Skills管理",
|
||||||
|
"roles": "角色",
|
||||||
|
"rolesManagement": "角色管理",
|
||||||
|
"settings": "系统设置"
|
||||||
|
},
|
||||||
|
"dashboard": {
|
||||||
|
"title": "仪表盘",
|
||||||
|
"refresh": "刷新",
|
||||||
|
"refreshData": "刷新数据",
|
||||||
|
"runningTasks": "运行中任务",
|
||||||
|
"vulnTotal": "漏洞总数",
|
||||||
|
"toolCalls": "工具调用次数",
|
||||||
|
"successRate": "工具执行成功率",
|
||||||
|
"clickToViewTasks": "点击查看任务管理",
|
||||||
|
"clickToViewVuln": "点击查看漏洞管理",
|
||||||
|
"clickToViewMCP": "点击查看 MCP 监控",
|
||||||
|
"severityDistribution": "漏洞严重程度分布",
|
||||||
|
"severityCritical": "严重",
|
||||||
|
"severityHigh": "高危",
|
||||||
|
"severityMedium": "中危",
|
||||||
|
"severityLow": "低危",
|
||||||
|
"severityInfo": "信息",
|
||||||
|
"runOverview": "运行概览",
|
||||||
|
"batchQueues": "批量任务队列",
|
||||||
|
"pending": "待执行",
|
||||||
|
"executing": "执行中",
|
||||||
|
"completed": "已完成",
|
||||||
|
"toolInvocations": "工具调用",
|
||||||
|
"callsUnit": "次调用",
|
||||||
|
"toolsUnit": "个工具",
|
||||||
|
"knowledgeLabel": "知识",
|
||||||
|
"knowledgeItems": "项知识",
|
||||||
|
"categoriesUnit": "个分类",
|
||||||
|
"skillsLabel": "Skills",
|
||||||
|
"skillUnit": "个 Skill",
|
||||||
|
"quickLinks": "快捷入口",
|
||||||
|
"toolsExecCount": "工具执行次数",
|
||||||
|
"ctaTitle": "开始你的安全之旅",
|
||||||
|
"ctaSub": "在对话中描述目标,AI 将协助执行扫描与漏洞分析",
|
||||||
|
"goToChat": "前往对话",
|
||||||
|
"noTasks": "暂无任务",
|
||||||
|
"totalCount": "共 {{count}} 个",
|
||||||
|
"notEnabled": "未启用",
|
||||||
|
"enabled": "已启用",
|
||||||
|
"toConfigure": "待配置",
|
||||||
|
"toUse": "待使用",
|
||||||
|
"active": "活跃",
|
||||||
|
"highFreq": "高频",
|
||||||
|
"noCallData": "暂无调用数据"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"newChat": "新对话",
|
||||||
|
"searchHistory": "搜索历史记录...",
|
||||||
|
"conversationGroups": "对话分组",
|
||||||
|
"addGroup": "新建分组",
|
||||||
|
"recentConversations": "最近对话",
|
||||||
|
"batchManage": "批量管理",
|
||||||
|
"attackChain": "攻击链",
|
||||||
|
"viewAttackChain": "查看攻击链",
|
||||||
|
"selectRole": "选择角色",
|
||||||
|
"defaultRole": "默认",
|
||||||
|
"inputPlaceholder": "输入测试目标或命令... (输入 @ 选择工具 | Shift+Enter 换行,Enter 发送)",
|
||||||
|
"selectFile": "选择文件",
|
||||||
|
"uploadFile": "上传文件(可多选或拖拽到此处)",
|
||||||
|
"send": "发送",
|
||||||
|
"searchInGroup": "搜索分组中的对话...",
|
||||||
|
"loadingTools": "正在加载工具...",
|
||||||
|
"noMatchTools": "没有匹配的工具",
|
||||||
|
"penetrationTestDetail": "渗透测试详情",
|
||||||
|
"expandDetail": "展开详情",
|
||||||
|
"noProcessDetail": "暂无过程详情(可能执行过快或未触发详细事件)",
|
||||||
|
"copyMessageTitle": "复制消息内容",
|
||||||
|
"emptyGroupConversations": "该分组暂无对话",
|
||||||
|
"noMatchingConversationsInGroup": "未找到匹配的对话",
|
||||||
|
"renameGroupPrompt": "请输入新名称:",
|
||||||
|
"deleteGroupConfirm": "确定要删除此分组吗?分组中的对话不会被删除,但会从分组中移除。",
|
||||||
|
"deleteConversationConfirm": "确定要删除此对话吗?",
|
||||||
|
"renameFailed": "重命名失败",
|
||||||
|
"viewAttackChainSelectConv": "请选择一个对话以查看攻击链",
|
||||||
|
"viewAttackChainCurrentConv": "查看当前对话的攻击链",
|
||||||
|
"executeFailed": "执行失败",
|
||||||
|
"callOpenAIFailed": "调用OpenAI失败",
|
||||||
|
"systemReadyMessage": "系统已就绪。请输入您的测试需求,系统将自动执行相应的安全测试。",
|
||||||
|
"addNewGroup": "+ 新增分组"
|
||||||
|
},
|
||||||
|
"tasks": {
|
||||||
|
"title": "任务管理",
|
||||||
|
"newTask": "新建任务",
|
||||||
|
"autoRefresh": "自动刷新",
|
||||||
|
"historyHint": "提示:有已完成的任务历史,请勾选\"显示历史记录\"查看",
|
||||||
|
"statusRunning": "执行中",
|
||||||
|
"statusCancelling": "取消中",
|
||||||
|
"statusFailed": "执行失败",
|
||||||
|
"statusTimeout": "执行超时",
|
||||||
|
"statusCancelled": "已取消",
|
||||||
|
"statusCompleted": "已完成",
|
||||||
|
"historyBadge": "历史记录",
|
||||||
|
"duration": "执行时长",
|
||||||
|
"completedAt": "完成时间",
|
||||||
|
"startedAt": "开始时间",
|
||||||
|
"clickToCopy": "点击复制",
|
||||||
|
"unnamedTask": "未命名任务",
|
||||||
|
"unknown": "未知",
|
||||||
|
"unknownTime": "未知时间",
|
||||||
|
"clearHistoryConfirm": "确定要清空所有任务历史记录吗?",
|
||||||
|
"cancelTaskFailed": "取消任务失败",
|
||||||
|
"copiedToast": "已复制!",
|
||||||
|
"cancelling": "取消中...",
|
||||||
|
"enterTaskPrompt": "请输入至少一个任务",
|
||||||
|
"noValidTask": "没有有效的任务",
|
||||||
|
"createBatchQueueFailed": "创建批量任务队列失败",
|
||||||
|
"noBatchQueues": "当前没有批量任务队列",
|
||||||
|
"recentCompletedTasks": "最近完成的任务(最近24小时)",
|
||||||
|
"clearHistory": "清空历史",
|
||||||
|
"cancelTask": "取消任务",
|
||||||
|
"viewConversation": "查看对话",
|
||||||
|
"conversationIdLabel": "对话ID",
|
||||||
|
"statusPending": "待执行",
|
||||||
|
"statusPaused": "已暂停",
|
||||||
|
"confirmCancelTasks": "确定要取消 {{n}} 个任务吗?",
|
||||||
|
"batchCancelResultPartial": "批量取消完成:成功 {{success}} 个,失败 {{fail}} 个",
|
||||||
|
"batchCancelResultSuccess": "成功取消 {{n}} 个任务",
|
||||||
|
"taskCount": "共 {{count}} 个任务",
|
||||||
|
"queueIdLabel": "队列ID",
|
||||||
|
"createdTimeLabel": "创建时间",
|
||||||
|
"totalLabel": "总计",
|
||||||
|
"pendingLabel": "待执行",
|
||||||
|
"runningLabel": "执行中",
|
||||||
|
"completedLabel": "已完成",
|
||||||
|
"failedLabel": "失败",
|
||||||
|
"cancelledLabel": "已取消",
|
||||||
|
"loadingTasks": "加载中...",
|
||||||
|
"loadFailedRetry": "加载失败",
|
||||||
|
"loadTaskListFailed": "获取任务列表失败",
|
||||||
|
"getQueueDetailFailed": "获取队列详情失败",
|
||||||
|
"startBatchQueueFailed": "启动批量任务失败",
|
||||||
|
"pauseQueueFailed": "暂停批量任务失败",
|
||||||
|
"pauseQueueConfirm": "确定要暂停这个批量任务队列吗?当前正在执行的任务将被停止,后续任务将保留待执行状态。",
|
||||||
|
"deleteQueueConfirm": "确定要删除这个批量任务队列吗?此操作不可恢复。",
|
||||||
|
"deleteQueueFailed": "删除批量任务队列失败",
|
||||||
|
"batchQueueTitle": "批量任务队列",
|
||||||
|
"resumeExecute": "继续执行",
|
||||||
|
"taskIncomplete": "任务信息不完整",
|
||||||
|
"cannotGetTaskMessageInput": "无法获取任务消息输入框",
|
||||||
|
"taskMessageRequired": "任务消息不能为空",
|
||||||
|
"saveTaskFailed": "保存任务失败",
|
||||||
|
"queueInfoMissing": "队列信息不存在",
|
||||||
|
"addTaskFailed": "添加任务失败",
|
||||||
|
"confirmDeleteTask": "确定要删除这个任务吗?\n\n任务内容: {{message}}\n\n此操作不可恢复。",
|
||||||
|
"deleteTaskFailed": "删除任务失败",
|
||||||
|
"paginationShow": "显示 {{start}}-{{end}} / 共 {{total}} 条",
|
||||||
|
"paginationPerPage": "每页显示",
|
||||||
|
"paginationFirst": "首页",
|
||||||
|
"paginationPrev": "上一页",
|
||||||
|
"paginationNext": "下一页",
|
||||||
|
"paginationLast": "末页",
|
||||||
|
"paginationPage": "第 {{current}} / {{total}} 页",
|
||||||
|
"deleteQueue": "删除队列",
|
||||||
|
"retry": "重试",
|
||||||
|
"noMatchingTasks": "当前没有符合条件的任务",
|
||||||
|
"updateTaskFailed": "更新任务失败",
|
||||||
|
"durationSeconds": "秒",
|
||||||
|
"durationMinutes": "分",
|
||||||
|
"durationHours": "小时"
|
||||||
|
},
|
||||||
|
"infoCollect": {
|
||||||
|
"enterFofaQuery": "请输入 FOFA 查询语法",
|
||||||
|
"querying": "查询中...",
|
||||||
|
"queryFailed": "查询失败",
|
||||||
|
"enterNaturalLanguage": "请输入自然语言描述",
|
||||||
|
"cancelParse": "取消解析",
|
||||||
|
"clickToCancelParse": "点击取消 AI 解析",
|
||||||
|
"parseToFofa": "将自然语言解析为 FOFA 查询语法",
|
||||||
|
"parseResultEmpty": "解析结果为空:请在弹窗中补充/修改 FOFA 查询语法",
|
||||||
|
"queryPlaceholder": "例如:app=\"Apache\" && country=\"CN\"",
|
||||||
|
"selectAll": "全选/全不选",
|
||||||
|
"selectRow": "选择该行",
|
||||||
|
"copyTarget": "复制目标",
|
||||||
|
"sendToChat": "发送到对话(可编辑;Ctrl/⌘+点击可直接发送)",
|
||||||
|
"noTargetToCopy": "没有可复制的目标",
|
||||||
|
"targetCopied": "已复制目标",
|
||||||
|
"manualCopyHint": "复制失败,请手动复制:",
|
||||||
|
"cannotInferTarget": "无法从该行推断扫描目标(建议在 fields 中包含 host/ip/port/domain)",
|
||||||
|
"noSendMessage": "未找到 sendMessage(),请刷新页面后重试",
|
||||||
|
"filledToInput": "已填入对话输入框,可编辑后发送",
|
||||||
|
"noExportResult": "暂无可导出的结果",
|
||||||
|
"xlsxNotLoaded": "未加载 XLSX 库,请刷新页面后重试",
|
||||||
|
"noResults": "暂无结果",
|
||||||
|
"selectRowsFirst": "请先勾选需要扫描的行",
|
||||||
|
"noScanTarget": "未能从所选行推断任何可扫描目标(建议 fields 中包含 host/ip/port/domain)",
|
||||||
|
"batchScanFailed": "批量扫描失败",
|
||||||
|
"batchQueueCreated": "已创建批量扫描队列",
|
||||||
|
"field": "字段",
|
||||||
|
"parsePending": "AI 解析中...",
|
||||||
|
"parsePendingClickCancel": "AI 解析中...(点击按钮可取消)",
|
||||||
|
"parseSlow": "AI 解析耗时较长,仍在处理中…",
|
||||||
|
"parseDone": "AI 解析完成",
|
||||||
|
"parseCancelled": "已取消 AI 解析",
|
||||||
|
"parseFailed": "AI 解析失败:",
|
||||||
|
"parseResultTitle": "AI 解析结果",
|
||||||
|
"naturalLanguageLabel": "自然语言",
|
||||||
|
"fofaQueryEditable": "FOFA 查询语法(可编辑)",
|
||||||
|
"confirmBeforeQuery": "请人工确认语法与范围无误后再执行查询。",
|
||||||
|
"reminder": "提醒",
|
||||||
|
"explanation": "解析说明",
|
||||||
|
"actions": "操作",
|
||||||
|
"batchScanTitle": "FOFA 批量扫描",
|
||||||
|
"queueCreatedSkipped": "已创建队列(跳过 {{n}} 条无目标行)",
|
||||||
|
"createQueueFailed": "创建批量队列失败",
|
||||||
|
"loading": "加载中...",
|
||||||
|
"none": "无",
|
||||||
|
"truncated": "已截断",
|
||||||
|
"resultsMeta": "共 {{total}} 条 · 本页 {{count}} 条 · page={{page}} · size={{size}}",
|
||||||
|
"parseModalCancel": "取消",
|
||||||
|
"parseModalApply": "填入查询框",
|
||||||
|
"parseModalApplyRun": "填入并查询"
|
||||||
|
},
|
||||||
|
"vulnerability": {
|
||||||
|
"title": "漏洞管理",
|
||||||
|
"addVuln": "添加漏洞",
|
||||||
|
"editVuln": "编辑漏洞",
|
||||||
|
"loadFailed": "加载漏洞失败",
|
||||||
|
"deleteConfirm": "确定要删除此漏洞吗?"
|
||||||
|
},
|
||||||
|
"mcp": {
|
||||||
|
"monitorTitle": "MCP 状态监控",
|
||||||
|
"execStats": "执行统计",
|
||||||
|
"latestExecutions": "最新执行记录",
|
||||||
|
"toolSearch": "工具搜索",
|
||||||
|
"toolSearchPlaceholder": "输入工具名称...",
|
||||||
|
"statusFilter": "状态筛选",
|
||||||
|
"filterAll": "全部",
|
||||||
|
"selectedCount": "已选择 {{count}} 项",
|
||||||
|
"selectAll": "全选",
|
||||||
|
"deselectAll": "全不选",
|
||||||
|
"deleteSelected": "批量删除",
|
||||||
|
"deleteExecConfirm": "确定要删除此执行记录吗?",
|
||||||
|
"batchDeleteFailed": "批量删除执行记录失败",
|
||||||
|
"managementTitle": "MCP 管理",
|
||||||
|
"addExternal": "添加外部MCP",
|
||||||
|
"toolConfig": "MCP 工具配置",
|
||||||
|
"saveToolConfig": "保存工具配置",
|
||||||
|
"externalConfig": "外部 MCP 配置",
|
||||||
|
"loadingTools": "正在加载工具列表...",
|
||||||
|
"loadToolsTimeout": "加载工具列表超时,可能是外部MCP连接较慢。请点击\"刷新\"按钮重试,或检查外部MCP连接状态。",
|
||||||
|
"loadToolsFailed": "加载工具列表失败",
|
||||||
|
"noTools": "暂无工具",
|
||||||
|
"externalBadge": "外部",
|
||||||
|
"externalFrom": "外部 ({{name}})",
|
||||||
|
"externalToolFrom": "外部MCP工具 - 来源:{{name}}",
|
||||||
|
"noDescription": "无描述",
|
||||||
|
"paginationInfo": "显示 {{start}}-{{end}} / 共 {{total}} 个工具",
|
||||||
|
"perPage": "每页:",
|
||||||
|
"firstPage": "首页",
|
||||||
|
"prevPage": "上一页",
|
||||||
|
"nextPage": "下一页",
|
||||||
|
"lastPage": "末页",
|
||||||
|
"pageInfo": "第 {{page}} / {{total}} 页",
|
||||||
|
"currentPageEnabled": "当前页已启用",
|
||||||
|
"totalEnabled": "总计已启用",
|
||||||
|
"toolsConfigSaved": "工具配置已成功保存!",
|
||||||
|
"saveToolsConfigFailed": "保存工具配置失败",
|
||||||
|
"getConfigFailed": "获取配置失败",
|
||||||
|
"noExternalMCP": "暂无外部MCP配置",
|
||||||
|
"clickToAddExternal": "点击\"添加外部MCP\"按钮开始配置",
|
||||||
|
"connected": "已连接",
|
||||||
|
"connecting": "连接中...",
|
||||||
|
"connectionFailed": "连接失败",
|
||||||
|
"disabled": "已禁用",
|
||||||
|
"disconnected": "未连接",
|
||||||
|
"stopConnection": "停止连接",
|
||||||
|
"startConnection": "启动连接",
|
||||||
|
"stop": "停止",
|
||||||
|
"start": "启动",
|
||||||
|
"editConfig": "编辑配置",
|
||||||
|
"deleteConfig": "删除配置",
|
||||||
|
"transportMode": "传输模式",
|
||||||
|
"toolCount": "工具数量",
|
||||||
|
"description": "描述",
|
||||||
|
"timeout": "超时时间",
|
||||||
|
"command": "命令",
|
||||||
|
"addExternalMCP": "添加外部MCP",
|
||||||
|
"editExternalMCP": "编辑外部MCP",
|
||||||
|
"jsonEmpty": "JSON不能为空",
|
||||||
|
"jsonError": "JSON格式错误",
|
||||||
|
"configMustBeObject": "配置错误: 必须是JSON对象格式,key为配置名称,value为配置内容",
|
||||||
|
"configNeedOne": "配置错误: 至少需要一个配置项",
|
||||||
|
"configNameEmpty": "配置错误: 配置名称不能为空",
|
||||||
|
"configMustBeObj": "配置错误: \"{{name}}\" 的配置必须是对象",
|
||||||
|
"configNeedCommand": "配置错误: \"{{name}}\" 需要指定command(stdio模式)或url(http/sse模式)",
|
||||||
|
"configStdioNeedCommand": "配置错误: \"{{name}}\" stdio模式需要command字段",
|
||||||
|
"configHttpNeedUrl": "配置错误: \"{{name}}\" http模式需要url字段",
|
||||||
|
"configSseNeedUrl": "配置错误: \"{{name}}\" sse模式需要url字段",
|
||||||
|
"saveSuccess": "保存成功",
|
||||||
|
"deleteSuccess": "删除成功",
|
||||||
|
"deleteExternalConfirm": "确定要删除外部MCP \"{{name}}\" 吗?",
|
||||||
|
"operationFailed": "操作失败",
|
||||||
|
"connectionFailedCheck": "连接失败,请检查配置和网络连接",
|
||||||
|
"connectionTimeout": "连接超时,请检查配置和网络连接",
|
||||||
|
"totalCount": "总数",
|
||||||
|
"enabledCount": "已启用",
|
||||||
|
"disabledCount": "已停用",
|
||||||
|
"connectedCount": "已连接"
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"title": "系统设置",
|
||||||
|
"nav": {
|
||||||
|
"basic": "基本设置",
|
||||||
|
"robots": "机器人设置",
|
||||||
|
"terminal": "终端",
|
||||||
|
"security": "安全设置"
|
||||||
|
},
|
||||||
|
"robots": {
|
||||||
|
"title": "机器人设置",
|
||||||
|
"description": "配置企业微信、钉钉、飞书等机器人,在手机端直接与 CyberStrikeAI 对话,无需在服务器上打开网页。",
|
||||||
|
"wecom": {
|
||||||
|
"title": "企业微信",
|
||||||
|
"enabled": "启用企业微信机器人"
|
||||||
|
},
|
||||||
|
"dingtalk": {
|
||||||
|
"title": "钉钉",
|
||||||
|
"enabled": "启用钉钉机器人"
|
||||||
|
},
|
||||||
|
"lark": {
|
||||||
|
"title": "飞书 (Lark)",
|
||||||
|
"enabled": "启用飞书机器人"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"apply": {
|
||||||
|
"button": "应用配置",
|
||||||
|
"loadFailed": "加载配置失败",
|
||||||
|
"fillRequired": "请填写所有必填字段(标记为 * 的字段)",
|
||||||
|
"applyFailed": "应用配置失败",
|
||||||
|
"applySuccess": "配置已成功应用!"
|
||||||
|
},
|
||||||
|
"security": {
|
||||||
|
"changePassword": "修改密码",
|
||||||
|
"fillPasswordHint": "请正确填写当前密码和新密码,新密码至少 8 位且需要两次输入一致。",
|
||||||
|
"changePasswordFailed": "修改密码失败",
|
||||||
|
"passwordUpdated": "密码已更新,请使用新密码重新登录。"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"sessionExpired": "认证已过期,请重新登录",
|
||||||
|
"unauthorized": "未授权访问",
|
||||||
|
"enterPassword": "请输入密码",
|
||||||
|
"loginFailedCheck": "登录失败,请检查密码",
|
||||||
|
"loginFailedRetry": "登录失败,请稍后重试",
|
||||||
|
"loggedOut": "已退出登录"
|
||||||
|
},
|
||||||
|
"knowledge": {
|
||||||
|
"title": "知识管理",
|
||||||
|
"retrievalLogs": "检索历史",
|
||||||
|
"totalItems": "总知识项",
|
||||||
|
"categories": "分类数",
|
||||||
|
"addKnowledge": "添加知识",
|
||||||
|
"rebuildIndex": "重建索引",
|
||||||
|
"rebuildIndexConfirm": "确定要重建索引吗?",
|
||||||
|
"deleteItemConfirm": "确定要删除这个知识项吗?",
|
||||||
|
"notEnabledTitle": "知识库功能未启用",
|
||||||
|
"notEnabledHint": "请前往系统设置启用知识检索功能",
|
||||||
|
"goToSettings": "前往设置"
|
||||||
|
},
|
||||||
|
"roles": {
|
||||||
|
"title": "角色管理",
|
||||||
|
"createRole": "创建角色",
|
||||||
|
"searchPlaceholder": "搜索角色...",
|
||||||
|
"deleteConfirm": "确定要删除角色..."
|
||||||
|
},
|
||||||
|
"skills": {
|
||||||
|
"title": "Skills管理",
|
||||||
|
"monitorTitle": "Skills状态监控",
|
||||||
|
"createSkill": "创建Skill",
|
||||||
|
"callStats": "调用统计",
|
||||||
|
"addSkill": "添加Skill",
|
||||||
|
"editSkill": "编辑Skill",
|
||||||
|
"loadListFailed": "加载skills列表失败",
|
||||||
|
"noSkills": "暂无skills,点击\"创建Skill\"创建第一个skill",
|
||||||
|
"noMatch": "没有找到匹配的skills",
|
||||||
|
"searchFailed": "搜索失败",
|
||||||
|
"refreshed": "已刷新",
|
||||||
|
"loadDetailFailed": "加载skill详情失败",
|
||||||
|
"viewFailed": "查看skill失败",
|
||||||
|
"saving": "保存中...",
|
||||||
|
"saveFailed": "保存skill失败",
|
||||||
|
"deleteFailed": "删除skill失败",
|
||||||
|
"loadStatsFailed": "加载skills监控数据失败",
|
||||||
|
"clearStatsConfirm": "确定要清空所有Skills统计数据吗?此操作不可恢复。",
|
||||||
|
"statsCleared": "已清空所有Skills统计数据",
|
||||||
|
"clearStatsFailed": "清空统计数据失败"
|
||||||
|
},
|
||||||
|
"apiDocs": {
|
||||||
|
"curlCopied": "curl命令已复制到剪贴板!"
|
||||||
|
},
|
||||||
|
"chatGroup": {
|
||||||
|
"search": "搜索",
|
||||||
|
"edit": "编辑",
|
||||||
|
"delete": "删除",
|
||||||
|
"clearSearch": "清除搜索",
|
||||||
|
"searchInGroupPlaceholder": "搜索分组中的对话...",
|
||||||
|
"attackChain": "攻击链",
|
||||||
|
"viewAttackChain": "查看攻击链",
|
||||||
|
"selectRole": "选择角色",
|
||||||
|
"close": "关闭",
|
||||||
|
"selectFile": "选择文件",
|
||||||
|
"uploadFile": "上传文件(可多选或拖拽到此处)",
|
||||||
|
"send": "发送",
|
||||||
|
"rolePanelTitle": "选择角色",
|
||||||
|
"copyMessage": "复制消息内容",
|
||||||
|
"remove": "移除"
|
||||||
|
},
|
||||||
|
"mcpMonitor": {
|
||||||
|
"deselectAll": "取消全选",
|
||||||
|
"statusPending": "等待中",
|
||||||
|
"statusCompleted": "已完成",
|
||||||
|
"statusRunning": "执行中",
|
||||||
|
"statusFailed": "失败",
|
||||||
|
"loading": "加载中...",
|
||||||
|
"noStatsData": "暂无统计数据",
|
||||||
|
"noExecutions": "暂无执行记录",
|
||||||
|
"noRecordsWithFilter": "当前筛选条件下暂无记录",
|
||||||
|
"paginationInfo": "显示 {{start}}-{{end}} / 共 {{total}} 条记录",
|
||||||
|
"perPageLabel": "每页显示",
|
||||||
|
"loadStatsError": "无法加载统计信息",
|
||||||
|
"loadExecutionsError": "无法加载执行记录",
|
||||||
|
"totalCalls": "总调用次数",
|
||||||
|
"successFailed": "成功 {{success}} / 失败 {{failed}}",
|
||||||
|
"successRate": "成功率",
|
||||||
|
"statsFromAllTools": "统计自全部工具调用",
|
||||||
|
"lastCall": "最近一次调用",
|
||||||
|
"lastRefreshTime": "最后刷新时间",
|
||||||
|
"noCallsYet": "暂无调用",
|
||||||
|
"unknownTool": "未知工具",
|
||||||
|
"successFailedRate": "成功 {{success}} / 失败 {{failed}} · 成功率 {{rate}}%",
|
||||||
|
"columnTool": "工具",
|
||||||
|
"columnStatus": "状态",
|
||||||
|
"columnStartTime": "开始时间",
|
||||||
|
"columnDuration": "耗时",
|
||||||
|
"columnActions": "操作",
|
||||||
|
"viewDetail": "查看详情",
|
||||||
|
"delete": "删除",
|
||||||
|
"deleteExecTitle": "删除此执行记录",
|
||||||
|
"deleteExecConfirmSingle": "确定要删除此执行记录吗?此操作不可恢复。",
|
||||||
|
"deleteExecFailed": "删除执行记录失败",
|
||||||
|
"execDeleted": "执行记录已删除",
|
||||||
|
"selectExecFirst": "请先选择要删除的执行记录",
|
||||||
|
"batchDeleteConfirm": "确定要删除选中的 {{count}} 条执行记录吗?此操作不可恢复。",
|
||||||
|
"batchDeleteSuccess": "成功删除 {{count}} 条执行记录",
|
||||||
|
"unknown": "未知",
|
||||||
|
"durationSeconds": "{{n}} 秒",
|
||||||
|
"durationMinutes": "{{minutes}} 分 {{seconds}} 秒",
|
||||||
|
"durationMinutesOnly": "{{minutes}} 分",
|
||||||
|
"durationHours": "{{hours}} 小时 {{minutes}} 分",
|
||||||
|
"durationHoursOnly": "{{hours}} 小时"
|
||||||
|
},
|
||||||
|
"knowledgePage": {
|
||||||
|
"totalContent": "总内容",
|
||||||
|
"categoryFilter": "分类筛选",
|
||||||
|
"all": "全部",
|
||||||
|
"searchPlaceholder": "搜索知识...",
|
||||||
|
"loading": "加载中..."
|
||||||
|
},
|
||||||
|
"retrievalLogs": {
|
||||||
|
"totalRetrievals": "总检索次数",
|
||||||
|
"successRetrievals": "成功检索",
|
||||||
|
"successRate": "成功率",
|
||||||
|
"retrievedItems": "检索到知识项",
|
||||||
|
"conversationId": "对话ID",
|
||||||
|
"messageId": "消息ID",
|
||||||
|
"filter": "筛选",
|
||||||
|
"optionalConversation": "可选:筛选特定对话",
|
||||||
|
"optionalMessage": "可选:筛选特定消息",
|
||||||
|
"loading": "加载中...",
|
||||||
|
"noRecords": "暂无检索记录",
|
||||||
|
"noQuery": "无查询内容",
|
||||||
|
"itemsUnit": "项",
|
||||||
|
"hasResults": "有结果",
|
||||||
|
"noResults": "无结果",
|
||||||
|
"clickToCopy": "点击复制",
|
||||||
|
"retrievalResult": "检索结果",
|
||||||
|
"foundCount": "找到 {{count}} 个相关知识项",
|
||||||
|
"foundUnknown": "找到相关知识项(数量未知)",
|
||||||
|
"noMatch": "未找到匹配的知识项",
|
||||||
|
"retrievedItemsLabel": "检索到的知识项:",
|
||||||
|
"viewDetails": "查看详情",
|
||||||
|
"loadError": "加载检索日志失败",
|
||||||
|
"detailError": "无法获取检索详情",
|
||||||
|
"deleteError": "删除检索日志失败",
|
||||||
|
"detailsTitle": "检索详情",
|
||||||
|
"queryInfo": "查询信息",
|
||||||
|
"queryContent": "查询内容:",
|
||||||
|
"retrievalInfo": "检索信息",
|
||||||
|
"riskType": "风险类型",
|
||||||
|
"retrievalTime": "检索时间",
|
||||||
|
"noItemDetails": "未找到知识项详情",
|
||||||
|
"noContentPreview": "无内容预览",
|
||||||
|
"untitled": "未命名",
|
||||||
|
"uncategorized": "未分类",
|
||||||
|
"relatedInfo": "关联信息",
|
||||||
|
"itemsCount": "{{count}} 个知识项",
|
||||||
|
"deleteConfirm": "确定要删除这条检索记录吗?"
|
||||||
|
},
|
||||||
|
"infoCollectPage": {
|
||||||
|
"title": "信息收集",
|
||||||
|
"reset": "重置",
|
||||||
|
"confirm": "确定",
|
||||||
|
"fofaQuerySyntax": "FOFA 查询语法",
|
||||||
|
"naturalLanguage": "自然语言(AI 解析为 FOFA 语法)",
|
||||||
|
"returnCount": "返回数量",
|
||||||
|
"pageNum": "页码",
|
||||||
|
"returnFields": "返回字段名(逗号分隔)",
|
||||||
|
"queryResults": "查询结果",
|
||||||
|
"selectedRows": "已选择 {{count}} 条",
|
||||||
|
"selectedRowsZero": "已选择 0 条",
|
||||||
|
"columns": "列",
|
||||||
|
"exportCsv": "导出 CSV",
|
||||||
|
"exportJson": "导出 JSON",
|
||||||
|
"exportXlsx": "导出 XLSX",
|
||||||
|
"batchScan": "批量扫描",
|
||||||
|
"showColumns": "显示字段",
|
||||||
|
"columnsPanelAll": "全选",
|
||||||
|
"columnsPanelNone": "全不选",
|
||||||
|
"columnsPanelClose": "关闭",
|
||||||
|
"formHint": "查询语法参考 FOFA 文档,支持 && / || / () 等。",
|
||||||
|
"parseBtn": "AI 解析",
|
||||||
|
"parseHint": "解析后会弹窗展示 FOFA 语法(可编辑),确认无误后再填入查询框并执行查询。",
|
||||||
|
"minFields": "最小字段",
|
||||||
|
"webCommon": "Web 常用",
|
||||||
|
"intelEnhanced": "情报增强",
|
||||||
|
"presetApache": "Apache + 中国",
|
||||||
|
"presetLogin": "登录页 + 中国",
|
||||||
|
"presetDomain": "指定域名",
|
||||||
|
"presetIp": "指定 IP",
|
||||||
|
"nlPlaceholder": "例如:找美国 Missouri 的 Apache 站点,标题包含 Home",
|
||||||
|
"showHideColumns": "显示/隐藏字段",
|
||||||
|
"exportCsvTitle": "导出当前结果为 CSV(UTF-8,兼容中文)",
|
||||||
|
"exportJsonTitle": "导出当前结果为 JSON",
|
||||||
|
"exportXlsxTitle": "导出当前结果为 Excel",
|
||||||
|
"batchScanTitle": "将所选行创建为批量任务队列"
|
||||||
|
},
|
||||||
|
"vulnerabilityPage": {
|
||||||
|
"statTotal": "总漏洞数",
|
||||||
|
"filter": "筛选",
|
||||||
|
"clear": "清除",
|
||||||
|
"vulnId": "漏洞ID",
|
||||||
|
"conversationId": "会话ID",
|
||||||
|
"severity": "严重程度",
|
||||||
|
"status": "状态",
|
||||||
|
"statusOpen": "待处理",
|
||||||
|
"statusConfirmed": "已确认",
|
||||||
|
"statusFixed": "已修复",
|
||||||
|
"statusFalsePositive": "误报",
|
||||||
|
"searchVulnId": "搜索漏洞ID",
|
||||||
|
"filterConversation": "筛选特定会话",
|
||||||
|
"loading": "加载中...",
|
||||||
|
"noRecords": "暂无漏洞记录"
|
||||||
|
},
|
||||||
|
"tasksPage": {
|
||||||
|
"statusFilter": "状态筛选",
|
||||||
|
"statusPending": "待执行",
|
||||||
|
"statusPaused": "已暂停",
|
||||||
|
"statusCancelled": "已取消",
|
||||||
|
"searchQueuePlaceholder": "搜索队列ID、标题或创建时间",
|
||||||
|
"searchKeywordPlaceholder": "输入关键字搜索..."
|
||||||
|
},
|
||||||
|
"skillsPage": {
|
||||||
|
"clearStats": "清空统计",
|
||||||
|
"clearStatsTitle": "清空所有统计数据",
|
||||||
|
"skillsCallStats": "Skills调用统计",
|
||||||
|
"searchPlaceholder": "搜索Skills...",
|
||||||
|
"loading": "加载中..."
|
||||||
|
},
|
||||||
|
"settingsBasic": {
|
||||||
|
"basicTitle": "基本设置",
|
||||||
|
"openaiConfig": "OpenAI 配置",
|
||||||
|
"fofaConfig": "FOFA 配置",
|
||||||
|
"agentConfig": "Agent 配置",
|
||||||
|
"knowledgeConfig": "知识库配置",
|
||||||
|
"baseUrl": "Base URL",
|
||||||
|
"apiKey": "API Key",
|
||||||
|
"model": "模型",
|
||||||
|
"openaiBaseUrlPlaceholder": "https://api.openai.com/v1",
|
||||||
|
"openaiApiKeyPlaceholder": "输入OpenAI API Key",
|
||||||
|
"modelPlaceholder": "gpt-4",
|
||||||
|
"fofaBaseUrlPlaceholder": "https://fofa.info/api/v1/search/all(可选)",
|
||||||
|
"fofaBaseUrlHint": "留空则使用默认地址。",
|
||||||
|
"email": "Email",
|
||||||
|
"fofaEmailPlaceholder": "输入 FOFA 账号邮箱",
|
||||||
|
"fofaApiKeyPlaceholder": "输入 FOFA API Key",
|
||||||
|
"fofaApiKeyHint": "仅保存在服务器配置中(`config.yaml`)。",
|
||||||
|
"maxIterations": "最大迭代次数",
|
||||||
|
"iterationsPlaceholder": "30",
|
||||||
|
"enableKnowledge": "启用知识检索功能",
|
||||||
|
"knowledgeBasePath": "知识库路径",
|
||||||
|
"knowledgeBasePathPlaceholder": "knowledge_base",
|
||||||
|
"knowledgeBasePathHint": "相对于配置文件所在目录的路径",
|
||||||
|
"embeddingConfig": "嵌入模型配置",
|
||||||
|
"provider": "提供商",
|
||||||
|
"embeddingBaseUrlPlaceholder": "留空则使用OpenAI配置的base_url",
|
||||||
|
"embeddingApiKeyPlaceholder": "留空则使用OpenAI配置的api_key",
|
||||||
|
"modelName": "模型名称",
|
||||||
|
"embeddingModelPlaceholder": "text-embedding-v4",
|
||||||
|
"retrievalConfig": "检索配置",
|
||||||
|
"topK": "Top-K 结果数量",
|
||||||
|
"topKPlaceholder": "5",
|
||||||
|
"topKHint": "检索返回的Top-K结果数量",
|
||||||
|
"similarityThreshold": "相似度阈值",
|
||||||
|
"similarityPlaceholder": "0.7",
|
||||||
|
"similarityHint": "相似度阈值(0-1),低于此值的结果将被过滤",
|
||||||
|
"hybridWeight": "混合检索权重",
|
||||||
|
"hybridPlaceholder": "0.7",
|
||||||
|
"hybridHint": "向量检索的权重(0-1),1.0表示纯向量检索,0.0表示纯关键词检索",
|
||||||
|
"indexConfig": "索引配置",
|
||||||
|
"chunkSize": "分块大小(Chunk Size)",
|
||||||
|
"chunkSizePlaceholder": "512",
|
||||||
|
"chunkSizeHint": "每个块的最大 token 数(默认 512),长文本会被分割成多个块",
|
||||||
|
"chunkOverlap": "分块重叠(Chunk Overlap)",
|
||||||
|
"chunkOverlapPlaceholder": "50",
|
||||||
|
"chunkOverlapHint": "块之间的重叠 token 数(默认 50),保持上下文连贯性",
|
||||||
|
"maxChunksPerItem": "单个知识项最大块数",
|
||||||
|
"maxChunksPlaceholder": "0",
|
||||||
|
"maxChunksHint": "单个知识项的最大块数量(0 表示不限制),防止单个文件消耗过多 API 配额",
|
||||||
|
"maxRpm": "每分钟最大请求数(Max RPM)",
|
||||||
|
"maxRpmPlaceholder": "0",
|
||||||
|
"maxRpmHint": "每分钟最大请求数(默认 0 表示不限制),如 OpenAI 默认 200 RPM",
|
||||||
|
"rateLimitDelay": "请求间隔延迟(毫秒)",
|
||||||
|
"rateLimitPlaceholder": "300",
|
||||||
|
"rateLimitHint": "请求间隔毫秒数(默认 300),用于避免 API 速率限制,设为 0 不限制",
|
||||||
|
"maxRetries": "最大重试次数",
|
||||||
|
"maxRetriesPlaceholder": "3",
|
||||||
|
"maxRetriesHint": "最大重试次数(默认 3),遇到速率限制或服务器错误时自动重试",
|
||||||
|
"retryDelay": "重试间隔(毫秒)",
|
||||||
|
"retryDelayPlaceholder": "1000",
|
||||||
|
"retryDelayHint": "重试间隔毫秒数(默认 1000),每次重试会递增延迟"
|
||||||
|
},
|
||||||
|
"settingsTerminal": {
|
||||||
|
"title": "终端",
|
||||||
|
"description": "在服务器上执行命令,便于运维与调试。命令在服务端执行,请勿执行敏感或破坏性操作。",
|
||||||
|
"terminalTab": "终端 {{n}}",
|
||||||
|
"close": "关闭",
|
||||||
|
"newTerminal": "新终端"
|
||||||
|
},
|
||||||
|
"settingsSecurity": {
|
||||||
|
"changePasswordTitle": "修改密码",
|
||||||
|
"changePasswordDesc": "修改登录密码后,需要使用新密码重新登录。",
|
||||||
|
"currentPassword": "当前密码",
|
||||||
|
"currentPasswordPlaceholder": "输入当前登录密码",
|
||||||
|
"newPassword": "新密码",
|
||||||
|
"newPasswordPlaceholder": "设置新密码(至少 8 位)",
|
||||||
|
"confirmPassword": "确认新密码",
|
||||||
|
"confirmPasswordPlaceholder": "再次输入新密码",
|
||||||
|
"clear": "清空",
|
||||||
|
"changePasswordBtn": "修改密码"
|
||||||
|
},
|
||||||
|
"settingsRobotsExtra": {
|
||||||
|
"botCommandsTitle": "机器人命令说明",
|
||||||
|
"botCommandsDesc": "在对话中可发送以下命令(支持中英文):"
|
||||||
|
},
|
||||||
|
"mcpDetailModal": {
|
||||||
|
"title": "工具调用详情",
|
||||||
|
"execInfo": "执行信息",
|
||||||
|
"tool": "工具",
|
||||||
|
"status": "状态",
|
||||||
|
"time": "时间",
|
||||||
|
"executionId": "执行 ID",
|
||||||
|
"requestParams": "请求参数",
|
||||||
|
"copyJson": "复制 JSON",
|
||||||
|
"responseResult": "响应结果",
|
||||||
|
"copyContent": "复制内容",
|
||||||
|
"correctInfo": "正确信息",
|
||||||
|
"errorInfo": "错误信息",
|
||||||
|
"copyError": "复制错误"
|
||||||
|
},
|
||||||
|
"attackChainModal": {
|
||||||
|
"title": "攻击链可视化",
|
||||||
|
"regenerate": "重新生成",
|
||||||
|
"regenerateTitle": "重新生成攻击链(包含最新对话内容)",
|
||||||
|
"exportPng": "导出为PNG",
|
||||||
|
"exportSvg": "导出为SVG",
|
||||||
|
"refreshTitle": "刷新当前攻击链(不重新生成)",
|
||||||
|
"nodesEdges": "节点: {{nodes}} | 边: {{edges}}",
|
||||||
|
"searchPlaceholder": "搜索节点...",
|
||||||
|
"allTypes": "所有类型",
|
||||||
|
"target": "目标",
|
||||||
|
"action": "行动",
|
||||||
|
"vulnerability": "漏洞",
|
||||||
|
"allRisks": "所有风险",
|
||||||
|
"highRisk": "高风险 (80-100)",
|
||||||
|
"mediumHighRisk": "中高风险 (60-79)",
|
||||||
|
"mediumRisk": "中风险 (40-59)",
|
||||||
|
"lowRisk": "低风险 (0-39)",
|
||||||
|
"resetFilter": "重置筛选",
|
||||||
|
"loading": "加载中...",
|
||||||
|
"riskLevel": "风险等级",
|
||||||
|
"lineMeaning": "连接线含义",
|
||||||
|
"blueLine": "蓝色线:行动发现漏洞",
|
||||||
|
"redLine": "红色线:使能/促成关系",
|
||||||
|
"grayLine": "灰色线:逻辑顺序",
|
||||||
|
"nodeDetails": "节点详情",
|
||||||
|
"closeDetails": "关闭详情"
|
||||||
|
},
|
||||||
|
"externalMcpModal": {
|
||||||
|
"configJson": "配置JSON",
|
||||||
|
"formatLabel": "配置格式:",
|
||||||
|
"formatDesc": "JSON对象,key为配置名称,value为配置内容。状态通过\"启动/停止\"按钮控制,无需在JSON中配置。",
|
||||||
|
"formatJson": "格式化JSON",
|
||||||
|
"loadExample": "加载示例"
|
||||||
|
},
|
||||||
|
"skillModal": {
|
||||||
|
"addSkill": "添加Skill",
|
||||||
|
"editSkill": "编辑Skill",
|
||||||
|
"skillName": "Skill名称",
|
||||||
|
"skillNamePlaceholder": "例如: sql-injection-testing",
|
||||||
|
"skillNameHint": "只能包含字母、数字、连字符和下划线",
|
||||||
|
"description": "描述",
|
||||||
|
"descriptionPlaceholder": "Skill的简短描述",
|
||||||
|
"contentLabel": "内容(Markdown格式)",
|
||||||
|
"contentPlaceholder": "输入skill内容,支持Markdown格式...",
|
||||||
|
"contentHint": "支持YAML front matter格式(可选)"
|
||||||
|
},
|
||||||
|
"knowledgeItemModal": {
|
||||||
|
"addKnowledge": "添加知识",
|
||||||
|
"editKnowledge": "编辑知识",
|
||||||
|
"category": "分类(风险类型)",
|
||||||
|
"categoryPlaceholder": "例如:SQL注入",
|
||||||
|
"title": "标题",
|
||||||
|
"titlePlaceholder": "知识项标题",
|
||||||
|
"contentLabel": "内容(Markdown格式)",
|
||||||
|
"contentPlaceholder": "输入知识内容,支持Markdown格式..."
|
||||||
|
},
|
||||||
|
"batchManageModal": {
|
||||||
|
"title": "管理对话记录·共{{count}}条",
|
||||||
|
"searchPlaceholder": "搜索历史记录",
|
||||||
|
"conversationName": "对话名称",
|
||||||
|
"lastTime": "最近一次对话时间",
|
||||||
|
"action": "操作",
|
||||||
|
"selectAll": "全选",
|
||||||
|
"deleteSelected": "删除所选",
|
||||||
|
"confirmDeleteNone": "请先选择要删除的对话",
|
||||||
|
"confirmDeleteN": "确定要删除选中的 {{count}} 条对话吗?",
|
||||||
|
"deleteFailed": "删除失败",
|
||||||
|
"unnamedConversation": "未命名对话"
|
||||||
|
},
|
||||||
|
"createGroupModal": {
|
||||||
|
"title": "创建分组",
|
||||||
|
"description": "分组功能可将对话集中归类管理,让对话更加井然有序。",
|
||||||
|
"selectIcon": "点击选择图标",
|
||||||
|
"groupNamePlaceholder": "请输入分组名称",
|
||||||
|
"pickIcon": "选择图标",
|
||||||
|
"customIcon": "自定义",
|
||||||
|
"confirmIcon": "确定",
|
||||||
|
"create": "创建",
|
||||||
|
"cancel": "取消",
|
||||||
|
"suggestionPenetrationTest": "渗透测试",
|
||||||
|
"suggestionCtf": "CTF",
|
||||||
|
"suggestionRedTeam": "红队",
|
||||||
|
"suggestionVulnerabilityMining": "漏洞挖掘",
|
||||||
|
"nameExists": "分组名称已存在,请使用其他名称",
|
||||||
|
"createFailed": "创建失败",
|
||||||
|
"unknownError": "未知错误"
|
||||||
|
},
|
||||||
|
"contextMenu": {
|
||||||
|
"viewAttackChain": "查看攻击链",
|
||||||
|
"rename": "重命名",
|
||||||
|
"pinConversation": "置顶此对话",
|
||||||
|
"unpinConversation": "取消置顶",
|
||||||
|
"batchManage": "批量管理",
|
||||||
|
"moveToGroup": "移动到分组",
|
||||||
|
"deleteConversation": "删除此对话",
|
||||||
|
"pinGroup": "置顶此分组",
|
||||||
|
"unpinGroup": "取消置顶",
|
||||||
|
"deleteGroup": "删除此分组"
|
||||||
|
},
|
||||||
|
"batchImportModal": {
|
||||||
|
"title": "新建任务",
|
||||||
|
"queueTitle": "任务标题",
|
||||||
|
"queueTitlePlaceholder": "请输入任务标题(可选,用于标识和筛选)",
|
||||||
|
"queueTitleHint": "为批量任务队列设置一个标题,方便后续查找和管理。",
|
||||||
|
"role": "角色",
|
||||||
|
"defaultRole": "默认",
|
||||||
|
"roleHint": "选择一个角色,所有任务将使用该角色的配置(提示词和工具)执行。",
|
||||||
|
"tasksList": "任务列表(每行一个任务)",
|
||||||
|
"tasksListPlaceholder": "请输入任务列表,每行一个任务",
|
||||||
|
"tasksListPlaceholderExample": "请输入任务列表,每行一个任务,例如:\n扫描 192.168.1.1 的开放端口\n检查 https://example.com 是否存在SQL注入\n枚举 example.com 的子域名",
|
||||||
|
"tasksListHint": "每行输入一个任务指令,系统将依次执行这些任务。空行会被自动忽略。",
|
||||||
|
"tasksListHintFull": "提示:每行输入一个任务指令,系统将依次执行这些任务。空行会被自动忽略。",
|
||||||
|
"createQueue": "创建队列"
|
||||||
|
},
|
||||||
|
"batchQueueDetailModal": {
|
||||||
|
"title": "批量任务队列详情",
|
||||||
|
"addTask": "添加任务",
|
||||||
|
"startExecute": "开始执行",
|
||||||
|
"pauseQueue": "暂停队列",
|
||||||
|
"deleteQueue": "删除队列",
|
||||||
|
"queueTitle": "任务标题",
|
||||||
|
"role": "角色",
|
||||||
|
"defaultRole": "默认",
|
||||||
|
"queueId": "队列ID",
|
||||||
|
"status": "状态",
|
||||||
|
"createdAt": "创建时间",
|
||||||
|
"startedAt": "开始时间",
|
||||||
|
"completedAt": "完成时间",
|
||||||
|
"taskTotal": "任务总数",
|
||||||
|
"taskList": "任务列表",
|
||||||
|
"startLabel": "开始",
|
||||||
|
"completeLabel": "完成",
|
||||||
|
"errorLabel": "错误",
|
||||||
|
"resultLabel": "结果"
|
||||||
|
},
|
||||||
|
"editBatchTaskModal": {
|
||||||
|
"title": "编辑任务",
|
||||||
|
"taskMessage": "任务消息",
|
||||||
|
"taskMessagePlaceholder": "请输入任务消息"
|
||||||
|
},
|
||||||
|
"addBatchTaskModal": {
|
||||||
|
"title": "添加任务",
|
||||||
|
"taskMessage": "任务消息",
|
||||||
|
"taskMessagePlaceholder": "请输入任务消息",
|
||||||
|
"add": "添加"
|
||||||
|
},
|
||||||
|
"vulnerabilityModal": {
|
||||||
|
"conversationId": "会话ID",
|
||||||
|
"conversationIdPlaceholder": "输入会话ID",
|
||||||
|
"title": "标题",
|
||||||
|
"titlePlaceholder": "漏洞标题",
|
||||||
|
"description": "描述",
|
||||||
|
"descriptionPlaceholder": "漏洞详细描述",
|
||||||
|
"severity": "严重程度",
|
||||||
|
"pleaseSelect": "请选择",
|
||||||
|
"severityCritical": "严重",
|
||||||
|
"severityHigh": "高危",
|
||||||
|
"severityMedium": "中危",
|
||||||
|
"severityLow": "低危",
|
||||||
|
"severityInfo": "信息",
|
||||||
|
"status": "状态",
|
||||||
|
"statusOpen": "待处理",
|
||||||
|
"statusConfirmed": "已确认",
|
||||||
|
"statusFixed": "已修复",
|
||||||
|
"statusFalsePositive": "误报",
|
||||||
|
"type": "漏洞类型",
|
||||||
|
"typePlaceholder": "如:SQL注入、XSS、CSRF等",
|
||||||
|
"target": "目标",
|
||||||
|
"targetPlaceholder": "受影响的目标(URL、IP地址等)",
|
||||||
|
"proof": "证明(POC)",
|
||||||
|
"proofPlaceholder": "漏洞证明,如请求/响应、截图等",
|
||||||
|
"impact": "影响",
|
||||||
|
"impactPlaceholder": "漏洞影响说明",
|
||||||
|
"recommendation": "修复建议",
|
||||||
|
"recommendationPlaceholder": "修复建议"
|
||||||
|
},
|
||||||
|
"roleModal": {
|
||||||
|
"addRole": "添加角色",
|
||||||
|
"editRole": "编辑角色",
|
||||||
|
"roleName": "角色名称",
|
||||||
|
"roleNamePlaceholder": "输入角色名称",
|
||||||
|
"roleDescription": "角色描述",
|
||||||
|
"roleDescriptionPlaceholder": "输入角色描述",
|
||||||
|
"roleIcon": "角色图标",
|
||||||
|
"roleIconPlaceholder": "输入emoji图标,例如: 🏆",
|
||||||
|
"roleIconHint": "输入一个emoji作为角色的图标,将显示在角色选择器中。",
|
||||||
|
"userPrompt": "用户提示词",
|
||||||
|
"userPromptPlaceholder": "输入用户提示词,会在用户消息前追加此提示词...",
|
||||||
|
"userPromptHint": "此提示词会追加到用户消息前,用于指导AI的行为。注意:这不会修改系统提示词。",
|
||||||
|
"relatedTools": "关联的工具(可选)",
|
||||||
|
"defaultRoleToolsTitle": "默认角色使用所有工具",
|
||||||
|
"defaultRoleToolsDesc": "默认角色会自动使用MCP管理中启用的所有工具,无需单独配置。",
|
||||||
|
"searchToolsPlaceholder": "搜索工具...",
|
||||||
|
"loadingTools": "正在加载工具列表...",
|
||||||
|
"relatedToolsHint": "勾选要关联的工具,留空则使用MCP管理中的全部工具配置。",
|
||||||
|
"relatedSkills": "关联的Skills(可选)",
|
||||||
|
"searchSkillsPlaceholder": "搜索skill...",
|
||||||
|
"loadingSkills": "正在加载skills列表...",
|
||||||
|
"relatedSkillsHint": "勾选要关联的skills,这些skills的内容会在执行任务前注入到系统提示词中,帮助AI更好地理解相关专业知识。",
|
||||||
|
"enableRole": "启用此角色"
|
||||||
|
}
|
||||||
|
}
|
||||||
+27
-7
@@ -123,12 +123,20 @@ async function ensureAuthenticated() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUnauthorized({ message = '认证已过期,请重新登录', silent = false } = {}) {
|
function handleUnauthorized({ message = null, silent = false } = {}) {
|
||||||
clearAuthStorage();
|
clearAuthStorage();
|
||||||
authPromise = null;
|
authPromise = null;
|
||||||
authPromiseResolvers = [];
|
authPromiseResolvers = [];
|
||||||
|
let finalMessage = message;
|
||||||
|
if (!finalMessage) {
|
||||||
|
if (typeof window !== 'undefined' && typeof window.t === 'function') {
|
||||||
|
finalMessage = window.t('auth.sessionExpired');
|
||||||
|
} else {
|
||||||
|
finalMessage = '认证已过期,请重新登录';
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
showLoginOverlay(message);
|
showLoginOverlay(finalMessage);
|
||||||
} else {
|
} else {
|
||||||
showLoginOverlay();
|
showLoginOverlay();
|
||||||
}
|
}
|
||||||
@@ -147,7 +155,10 @@ async function apiFetch(url, options = {}) {
|
|||||||
const response = await fetch(url, opts);
|
const response = await fetch(url, opts);
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
handleUnauthorized();
|
handleUnauthorized();
|
||||||
throw new Error('未授权访问');
|
const msg = (typeof window !== 'undefined' && typeof window.t === 'function')
|
||||||
|
? window.t('auth.unauthorized')
|
||||||
|
: '未授权访问';
|
||||||
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -165,7 +176,10 @@ async function submitLogin(event) {
|
|||||||
const password = passwordInput.value.trim();
|
const password = passwordInput.value.trim();
|
||||||
if (!password) {
|
if (!password) {
|
||||||
if (errorBox) {
|
if (errorBox) {
|
||||||
errorBox.textContent = '请输入密码';
|
const msgEmpty = (typeof window !== 'undefined' && typeof window.t === 'function')
|
||||||
|
? window.t('auth.enterPassword')
|
||||||
|
: '请输入密码';
|
||||||
|
errorBox.textContent = msgEmpty;
|
||||||
errorBox.style.display = 'block';
|
errorBox.style.display = 'block';
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -186,7 +200,10 @@ async function submitLogin(event) {
|
|||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
if (!response.ok || !result.token) {
|
if (!response.ok || !result.token) {
|
||||||
if (errorBox) {
|
if (errorBox) {
|
||||||
errorBox.textContent = result.error || '登录失败,请检查密码';
|
const fallback = (typeof window !== 'undefined' && typeof window.t === 'function')
|
||||||
|
? window.t('auth.loginFailedCheck')
|
||||||
|
: '登录失败,请检查密码';
|
||||||
|
errorBox.textContent = result.error || fallback;
|
||||||
errorBox.style.display = 'block';
|
errorBox.style.display = 'block';
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -203,7 +220,10 @@ async function submitLogin(event) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('登录失败:', error);
|
console.error('登录失败:', error);
|
||||||
if (errorBox) {
|
if (errorBox) {
|
||||||
errorBox.textContent = '登录失败,请稍后重试';
|
const fallback = (typeof window !== 'undefined' && typeof window.t === 'function')
|
||||||
|
? window.t('auth.loginFailedRetry')
|
||||||
|
: '登录失败,请稍后重试';
|
||||||
|
errorBox.textContent = fallback;
|
||||||
errorBox.style.display = 'block';
|
errorBox.style.display = 'block';
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -375,7 +395,7 @@ async function logout() {
|
|||||||
// 无论如何都清除本地认证信息
|
// 无论如何都清除本地认证信息
|
||||||
clearAuthStorage();
|
clearAuthStorage();
|
||||||
hideLoginOverlay();
|
hideLoginOverlay();
|
||||||
showLoginOverlay('已退出登录');
|
showLoginOverlay(typeof window.t === 'function' ? window.t('auth.loggedOut') : '已退出登录');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+145
-66
@@ -44,10 +44,15 @@ function saveChatDraftDebounced(content) {
|
|||||||
// 保存输入框草稿到localStorage
|
// 保存输入框草稿到localStorage
|
||||||
function saveChatDraft(content) {
|
function saveChatDraft(content) {
|
||||||
try {
|
try {
|
||||||
if (content && content.trim().length > 0) {
|
const chatInput = document.getElementById('chat-input');
|
||||||
|
const placeholderText = chatInput ? (chatInput.getAttribute('placeholder') || '').trim() : '';
|
||||||
|
const trimmed = (content || '').trim();
|
||||||
|
|
||||||
|
// 不要把占位提示本身当作草稿保存
|
||||||
|
if (trimmed && (!placeholderText || trimmed !== placeholderText)) {
|
||||||
localStorage.setItem(DRAFT_STORAGE_KEY, content);
|
localStorage.setItem(DRAFT_STORAGE_KEY, content);
|
||||||
} else {
|
} else {
|
||||||
// 如果内容为空,清除保存的草稿
|
// 如果内容为空或等于占位提示,清除保存的草稿
|
||||||
localStorage.removeItem(DRAFT_STORAGE_KEY);
|
localStorage.removeItem(DRAFT_STORAGE_KEY);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -63,17 +68,27 @@ function restoreChatDraft() {
|
|||||||
if (!chatInput) {
|
if (!chatInput) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const placeholderText = (chatInput.getAttribute('placeholder') || '').trim();
|
||||||
|
// 若当前 value 与 placeholder 相同,说明提示被误当作内容,清空以便正确显示占位符
|
||||||
|
if (placeholderText && chatInput.value.trim() === placeholderText) {
|
||||||
|
chatInput.value = '';
|
||||||
|
}
|
||||||
// 如果输入框已有内容,不恢复草稿(避免覆盖用户输入)
|
// 如果输入框已有内容,不恢复草稿(避免覆盖用户输入)
|
||||||
if (chatInput.value && chatInput.value.trim().length > 0) {
|
if (chatInput.value && chatInput.value.trim().length > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const draft = localStorage.getItem(DRAFT_STORAGE_KEY);
|
const draft = localStorage.getItem(DRAFT_STORAGE_KEY);
|
||||||
if (draft && draft.trim().length > 0) {
|
const trimmedDraft = draft ? draft.trim() : '';
|
||||||
|
|
||||||
|
// 如果草稿内容和占位提示一样,则认为是无效草稿,不恢复
|
||||||
|
if (trimmedDraft && (!placeholderText || trimmedDraft !== placeholderText)) {
|
||||||
chatInput.value = draft;
|
chatInput.value = draft;
|
||||||
// 调整输入框高度以适应内容
|
// 调整输入框高度以适应内容
|
||||||
adjustTextareaHeight(chatInput);
|
adjustTextareaHeight(chatInput);
|
||||||
|
} else if (trimmedDraft && placeholderText && trimmedDraft === placeholderText) {
|
||||||
|
// 清理掉无效草稿,避免之后继续干扰
|
||||||
|
localStorage.removeItem(DRAFT_STORAGE_KEY);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('恢复草稿失败:', error);
|
console.warn('恢复草稿失败:', error);
|
||||||
@@ -263,7 +278,7 @@ function renderChatFileChips() {
|
|||||||
const remove = document.createElement('button');
|
const remove = document.createElement('button');
|
||||||
remove.type = 'button';
|
remove.type = 'button';
|
||||||
remove.className = 'chat-file-chip-remove';
|
remove.className = 'chat-file-chip-remove';
|
||||||
remove.title = '移除';
|
remove.title = typeof window.t === 'function' ? window.t('chatGroup.remove') : '移除';
|
||||||
remove.innerHTML = '×';
|
remove.innerHTML = '×';
|
||||||
remove.setAttribute('aria-label', '移除 ' + a.fileName);
|
remove.setAttribute('aria-label', '移除 ' + a.fileName);
|
||||||
remove.addEventListener('click', () => removeChatAttachment(i));
|
remove.addEventListener('click', () => removeChatAttachment(i));
|
||||||
@@ -720,14 +735,14 @@ function renderMentionSuggestions({ showLoading = false } = {}) {
|
|||||||
const previousScrollTop = canPreserveScroll ? existingList.scrollTop : 0;
|
const previousScrollTop = canPreserveScroll ? existingList.scrollTop : 0;
|
||||||
|
|
||||||
if (showLoading) {
|
if (showLoading) {
|
||||||
mentionSuggestionsEl.innerHTML = '<div class="mention-empty">正在加载工具...</div>';
|
mentionSuggestionsEl.innerHTML = '<div class="mention-empty">' + (typeof window.t === 'function' ? window.t('chat.loadingTools') : '正在加载工具...') + '</div>';
|
||||||
mentionSuggestionsEl.style.display = 'block';
|
mentionSuggestionsEl.style.display = 'block';
|
||||||
delete mentionSuggestionsEl.dataset.lastMentionQuery;
|
delete mentionSuggestionsEl.dataset.lastMentionQuery;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mentionFilteredTools.length) {
|
if (!mentionFilteredTools.length) {
|
||||||
mentionSuggestionsEl.innerHTML = '<div class="mention-empty">没有匹配的工具</div>';
|
mentionSuggestionsEl.innerHTML = '<div class="mention-empty">' + (typeof window.t === 'function' ? window.t('chat.noMatchTools') : '没有匹配的工具') + '</div>';
|
||||||
mentionSuggestionsEl.style.display = 'block';
|
mentionSuggestionsEl.style.display = 'block';
|
||||||
mentionSuggestionsEl.dataset.lastMentionQuery = currentQuery;
|
mentionSuggestionsEl.dataset.lastMentionQuery = currentQuery;
|
||||||
return;
|
return;
|
||||||
@@ -937,7 +952,8 @@ function initializeChatUI() {
|
|||||||
|
|
||||||
const messagesDiv = document.getElementById('chat-messages');
|
const messagesDiv = document.getElementById('chat-messages');
|
||||||
if (messagesDiv && messagesDiv.childElementCount === 0) {
|
if (messagesDiv && messagesDiv.childElementCount === 0) {
|
||||||
addMessage('assistant', '系统已就绪。请输入您的测试需求,系统将自动执行相应的安全测试。');
|
const readyMsg = typeof window.t === 'function' ? window.t('chat.systemReadyMessage') : '系统已就绪。请输入您的测试需求,系统将自动执行相应的安全测试。';
|
||||||
|
addMessage('assistant', readyMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
addAttackChainButton(currentConversationId);
|
addAttackChainButton(currentConversationId);
|
||||||
@@ -1040,12 +1056,23 @@ function addMessage(role, content, mcpExecutionIds = null, progressId = null, cr
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 助手消息中的已知中文错误前缀做国际化替换(后端固定返回中文)
|
||||||
|
let displayContent = content;
|
||||||
|
if (role === 'assistant' && typeof displayContent === 'string' && typeof window.t === 'function') {
|
||||||
|
if (displayContent.indexOf('执行失败: ') === 0) {
|
||||||
|
displayContent = window.t('chat.executeFailed') + ': ' + displayContent.slice('执行失败: '.length);
|
||||||
|
}
|
||||||
|
if (displayContent.indexOf('调用OpenAI失败:') !== -1) {
|
||||||
|
displayContent = displayContent.replace(/调用OpenAI失败:/g, window.t('chat.callOpenAIFailed') + ':');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 对于用户消息,直接转义HTML,不进行Markdown解析,以保留所有特殊字符
|
// 对于用户消息,直接转义HTML,不进行Markdown解析,以保留所有特殊字符
|
||||||
if (role === 'user') {
|
if (role === 'user') {
|
||||||
formattedContent = escapeHtml(content).replace(/\n/g, '<br>');
|
formattedContent = escapeHtml(content).replace(/\n/g, '<br>');
|
||||||
} else if (typeof DOMPurify !== 'undefined') {
|
} else if (typeof DOMPurify !== 'undefined') {
|
||||||
// 直接解析Markdown(代码块会被包裹在<code>/<pre>中,DOMPurify会保留其文本内容)
|
// 直接解析Markdown(代码块会被包裹在<code>/<pre>中,DOMPurify会保留其文本内容)
|
||||||
let parsedContent = parseMarkdown(content);
|
let parsedContent = parseMarkdown(role === 'assistant' ? displayContent : content);
|
||||||
if (!parsedContent) {
|
if (!parsedContent) {
|
||||||
parsedContent = content;
|
parsedContent = content;
|
||||||
}
|
}
|
||||||
@@ -1087,14 +1114,16 @@ function addMessage(role, content, mcpExecutionIds = null, progressId = null, cr
|
|||||||
|
|
||||||
formattedContent = DOMPurify.sanitize(parsedContent, defaultSanitizeConfig);
|
formattedContent = DOMPurify.sanitize(parsedContent, defaultSanitizeConfig);
|
||||||
} else if (typeof marked !== 'undefined') {
|
} else if (typeof marked !== 'undefined') {
|
||||||
const parsedContent = parseMarkdown(content);
|
const rawForParse = role === 'assistant' ? displayContent : content;
|
||||||
|
const parsedContent = parseMarkdown(rawForParse);
|
||||||
if (parsedContent) {
|
if (parsedContent) {
|
||||||
formattedContent = parsedContent;
|
formattedContent = parsedContent;
|
||||||
} else {
|
} else {
|
||||||
formattedContent = escapeHtml(content).replace(/\n/g, '<br>');
|
formattedContent = escapeHtml(rawForParse).replace(/\n/g, '<br>');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
formattedContent = escapeHtml(content).replace(/\n/g, '<br>');
|
const rawForEscape = role === 'assistant' ? displayContent : content;
|
||||||
|
formattedContent = escapeHtml(rawForEscape).replace(/\n/g, '<br>');
|
||||||
}
|
}
|
||||||
|
|
||||||
bubble.innerHTML = formattedContent;
|
bubble.innerHTML = formattedContent;
|
||||||
@@ -1129,8 +1158,8 @@ function addMessage(role, content, mcpExecutionIds = null, progressId = null, cr
|
|||||||
if (role === 'assistant') {
|
if (role === 'assistant') {
|
||||||
const copyBtn = document.createElement('button');
|
const copyBtn = document.createElement('button');
|
||||||
copyBtn.className = 'message-copy-btn';
|
copyBtn.className = 'message-copy-btn';
|
||||||
copyBtn.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="9" y="9" width="13" height="13" rx="2" ry="2" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg><span>复制</span>';
|
copyBtn.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="9" y="9" width="13" height="13" rx="2" ry="2" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg><span>' + (typeof window.t === 'function' ? window.t('common.copy') : '复制') + '</span>';
|
||||||
copyBtn.title = '复制消息内容';
|
copyBtn.title = typeof window.t === 'function' ? window.t('chat.copyMessageTitle') : '复制消息内容';
|
||||||
copyBtn.onclick = function(e) {
|
copyBtn.onclick = function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
copyMessageToClipboard(messageDiv, this);
|
copyMessageToClipboard(messageDiv, this);
|
||||||
@@ -1169,7 +1198,7 @@ function addMessage(role, content, mcpExecutionIds = null, progressId = null, cr
|
|||||||
|
|
||||||
const mcpLabel = document.createElement('div');
|
const mcpLabel = document.createElement('div');
|
||||||
mcpLabel.className = 'mcp-call-label';
|
mcpLabel.className = 'mcp-call-label';
|
||||||
mcpLabel.textContent = '📋 渗透测试详情';
|
mcpLabel.textContent = '📋 ' + (typeof window.t === 'function' ? window.t('chat.penetrationTestDetail') : '渗透测试详情');
|
||||||
mcpSection.appendChild(mcpLabel);
|
mcpSection.appendChild(mcpLabel);
|
||||||
|
|
||||||
const buttonsContainer = document.createElement('div');
|
const buttonsContainer = document.createElement('div');
|
||||||
@@ -1192,7 +1221,7 @@ function addMessage(role, content, mcpExecutionIds = null, progressId = null, cr
|
|||||||
if (progressId) {
|
if (progressId) {
|
||||||
const progressDetailBtn = document.createElement('button');
|
const progressDetailBtn = document.createElement('button');
|
||||||
progressDetailBtn.className = 'mcp-detail-btn process-detail-btn';
|
progressDetailBtn.className = 'mcp-detail-btn process-detail-btn';
|
||||||
progressDetailBtn.innerHTML = '<span>展开详情</span>';
|
progressDetailBtn.innerHTML = '<span>' + (typeof window.t === 'function' ? window.t('chat.expandDetail') : '展开详情') + '</span>';
|
||||||
progressDetailBtn.onclick = () => toggleProcessDetails(progressId, messageDiv.id);
|
progressDetailBtn.onclick = () => toggleProcessDetails(progressId, messageDiv.id);
|
||||||
buttonsContainer.appendChild(progressDetailBtn);
|
buttonsContainer.appendChild(progressDetailBtn);
|
||||||
// 存储进度ID到消息元素
|
// 存储进度ID到消息元素
|
||||||
@@ -1259,7 +1288,7 @@ function copyMessageToClipboard(messageDiv, button) {
|
|||||||
function showCopySuccess(button) {
|
function showCopySuccess(button) {
|
||||||
if (button) {
|
if (button) {
|
||||||
const originalText = button.innerHTML;
|
const originalText = button.innerHTML;
|
||||||
button.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20 6L9 17l-5-5" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg><span>已复制</span>';
|
button.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20 6L9 17l-5-5" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg><span>' + (typeof window.t === 'function' ? window.t('common.copied') : '已复制') + '</span>';
|
||||||
button.style.color = '#10b981';
|
button.style.color = '#10b981';
|
||||||
button.style.background = 'rgba(16, 185, 129, 0.1)';
|
button.style.background = 'rgba(16, 185, 129, 0.1)';
|
||||||
button.style.borderColor = 'rgba(16, 185, 129, 0.3)';
|
button.style.borderColor = 'rgba(16, 185, 129, 0.3)';
|
||||||
@@ -1301,11 +1330,11 @@ function renderProcessDetails(messageId, processDetails) {
|
|||||||
if (!mcpLabel && !buttonsContainer) {
|
if (!mcpLabel && !buttonsContainer) {
|
||||||
mcpLabel = document.createElement('div');
|
mcpLabel = document.createElement('div');
|
||||||
mcpLabel.className = 'mcp-call-label';
|
mcpLabel.className = 'mcp-call-label';
|
||||||
mcpLabel.textContent = '📋 渗透测试详情';
|
mcpLabel.textContent = '📋 ' + (typeof window.t === 'function' ? window.t('chat.penetrationTestDetail') : '渗透测试详情');
|
||||||
mcpSection.appendChild(mcpLabel);
|
mcpSection.appendChild(mcpLabel);
|
||||||
} else if (mcpLabel && mcpLabel.textContent !== '📋 渗透测试详情') {
|
} else if (mcpLabel && mcpLabel.textContent !== ('📋 ' + (typeof window.t === 'function' ? window.t('chat.penetrationTestDetail') : '渗透测试详情'))) {
|
||||||
// 如果标签存在但不是统一格式,更新它
|
// 如果标签存在但不是统一格式,更新它
|
||||||
mcpLabel.textContent = '📋 渗透测试详情';
|
mcpLabel.textContent = '📋 ' + (typeof window.t === 'function' ? window.t('chat.penetrationTestDetail') : '渗透测试详情');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果没有按钮容器,创建一个
|
// 如果没有按钮容器,创建一个
|
||||||
@@ -1320,7 +1349,7 @@ function renderProcessDetails(messageId, processDetails) {
|
|||||||
if (!processDetailBtn) {
|
if (!processDetailBtn) {
|
||||||
processDetailBtn = document.createElement('button');
|
processDetailBtn = document.createElement('button');
|
||||||
processDetailBtn.className = 'mcp-detail-btn process-detail-btn';
|
processDetailBtn.className = 'mcp-detail-btn process-detail-btn';
|
||||||
processDetailBtn.innerHTML = '<span>展开详情</span>';
|
processDetailBtn.innerHTML = '<span>' + (typeof window.t === 'function' ? window.t('chat.expandDetail') : '展开详情') + '</span>';
|
||||||
processDetailBtn.onclick = () => toggleProcessDetails(null, messageId);
|
processDetailBtn.onclick = () => toggleProcessDetails(null, messageId);
|
||||||
buttonsContainer.appendChild(processDetailBtn);
|
buttonsContainer.appendChild(processDetailBtn);
|
||||||
}
|
}
|
||||||
@@ -1360,7 +1389,7 @@ function renderProcessDetails(messageId, processDetails) {
|
|||||||
// 如果没有processDetails或为空,显示空状态
|
// 如果没有processDetails或为空,显示空状态
|
||||||
if (!processDetails || processDetails.length === 0) {
|
if (!processDetails || processDetails.length === 0) {
|
||||||
// 显示空状态提示
|
// 显示空状态提示
|
||||||
timeline.innerHTML = '<div class="progress-timeline-empty">暂无过程详情(可能执行过快或未触发详细事件)</div>';
|
timeline.innerHTML = '<div class="progress-timeline-empty">' + (typeof window.t === 'function' ? window.t('chat.noProcessDetail') : '暂无过程详情(可能执行过快或未触发详细事件)') + '</div>';
|
||||||
// 默认折叠
|
// 默认折叠
|
||||||
timeline.classList.remove('expanded');
|
timeline.classList.remove('expanded');
|
||||||
return;
|
return;
|
||||||
@@ -1425,7 +1454,7 @@ function renderProcessDetails(messageId, processDetails) {
|
|||||||
// 更新按钮文本为"展开详情"
|
// 更新按钮文本为"展开详情"
|
||||||
const processDetailBtn = messageElement.querySelector('.process-detail-btn');
|
const processDetailBtn = messageElement.querySelector('.process-detail-btn');
|
||||||
if (processDetailBtn) {
|
if (processDetailBtn) {
|
||||||
processDetailBtn.innerHTML = '<span>展开详情</span>';
|
processDetailBtn.innerHTML = '<span>' + (typeof window.t === 'function' ? window.t('chat.expandDetail') : '展开详情') + '</span>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1679,7 +1708,8 @@ async function startNewConversation() {
|
|||||||
currentConversationId = null;
|
currentConversationId = null;
|
||||||
currentConversationGroupId = null; // 新对话不属于任何分组
|
currentConversationGroupId = null; // 新对话不属于任何分组
|
||||||
document.getElementById('chat-messages').innerHTML = '';
|
document.getElementById('chat-messages').innerHTML = '';
|
||||||
addMessage('assistant', '系统已就绪。请输入您的测试需求,系统将自动执行相应的安全测试。');
|
const readyMsgNew = typeof window.t === 'function' ? window.t('chat.systemReadyMessage') : '系统已就绪。请输入您的测试需求,系统将自动执行相应的安全测试。';
|
||||||
|
addMessage('assistant', readyMsgNew);
|
||||||
addAttackChainButton(null);
|
addAttackChainButton(null);
|
||||||
updateActiveConversation();
|
updateActiveConversation();
|
||||||
// 刷新分组列表,清除分组高亮
|
// 刷新分组列表,清除分组高亮
|
||||||
@@ -2087,7 +2117,8 @@ async function loadConversation(conversationId) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
addMessage('assistant', '系统已就绪。请输入您的测试需求,系统将自动执行相应的安全测试。');
|
const readyMsgEmpty = typeof window.t === 'function' ? window.t('chat.systemReadyMessage') : '系统已就绪。请输入您的测试需求,系统将自动执行相应的安全测试。';
|
||||||
|
addMessage('assistant', readyMsgEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 滚动到底部
|
// 滚动到底部
|
||||||
@@ -2127,7 +2158,8 @@ async function deleteConversation(conversationId, skipConfirm = false) {
|
|||||||
if (conversationId === currentConversationId) {
|
if (conversationId === currentConversationId) {
|
||||||
currentConversationId = null;
|
currentConversationId = null;
|
||||||
document.getElementById('chat-messages').innerHTML = '';
|
document.getElementById('chat-messages').innerHTML = '';
|
||||||
addMessage('assistant', '系统已就绪。请输入您的测试需求,系统将自动执行相应的安全测试。');
|
const readyMsgLoad = typeof window.t === 'function' ? window.t('chat.systemReadyMessage') : '系统已就绪。请输入您的测试需求,系统将自动执行相应的安全测试。';
|
||||||
|
addMessage('assistant', readyMsgLoad);
|
||||||
addAttackChainButton(null);
|
addAttackChainButton(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4171,13 +4203,13 @@ async function showConversationContextMenu(event) {
|
|||||||
attackChainMenuItem.style.opacity = '1';
|
attackChainMenuItem.style.opacity = '1';
|
||||||
attackChainMenuItem.style.cursor = 'pointer';
|
attackChainMenuItem.style.cursor = 'pointer';
|
||||||
attackChainMenuItem.onclick = showAttackChainFromContext;
|
attackChainMenuItem.onclick = showAttackChainFromContext;
|
||||||
attackChainMenuItem.title = '查看当前对话的攻击链';
|
attackChainMenuItem.title = (typeof window.t === 'function' ? window.t('chat.viewAttackChainCurrentConv') : '查看当前对话的攻击链');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
attackChainMenuItem.style.opacity = '0.5';
|
attackChainMenuItem.style.opacity = '0.5';
|
||||||
attackChainMenuItem.style.cursor = 'not-allowed';
|
attackChainMenuItem.style.cursor = 'not-allowed';
|
||||||
attackChainMenuItem.onclick = null;
|
attackChainMenuItem.onclick = null;
|
||||||
attackChainMenuItem.title = '请选择一个对话以查看攻击链';
|
attackChainMenuItem.title = (typeof window.t === 'function' ? window.t('chat.viewAttackChainSelectConv') : '请选择一个对话以查看攻击链');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4210,21 +4242,25 @@ async function showConversationContextMenu(event) {
|
|||||||
|
|
||||||
// 更新菜单文本
|
// 更新菜单文本
|
||||||
const pinMenuText = document.getElementById('pin-conversation-menu-text');
|
const pinMenuText = document.getElementById('pin-conversation-menu-text');
|
||||||
if (pinMenuText) {
|
if (pinMenuText && typeof window.t === 'function') {
|
||||||
|
pinMenuText.textContent = isPinned ? window.t('contextMenu.unpinConversation') : window.t('contextMenu.pinConversation');
|
||||||
|
} else if (pinMenuText) {
|
||||||
pinMenuText.textContent = isPinned ? '取消置顶' : '置顶此对话';
|
pinMenuText.textContent = isPinned ? '取消置顶' : '置顶此对话';
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取对话置顶状态失败:', error);
|
console.error('获取对话置顶状态失败:', error);
|
||||||
// 如果获取失败,使用默认文本
|
|
||||||
const pinMenuText = document.getElementById('pin-conversation-menu-text');
|
const pinMenuText = document.getElementById('pin-conversation-menu-text');
|
||||||
if (pinMenuText) {
|
if (pinMenuText && typeof window.t === 'function') {
|
||||||
|
pinMenuText.textContent = window.t('contextMenu.pinConversation');
|
||||||
|
} else if (pinMenuText) {
|
||||||
pinMenuText.textContent = '置顶此对话';
|
pinMenuText.textContent = '置顶此对话';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 如果没有对话ID,使用默认文本
|
|
||||||
const pinMenuText = document.getElementById('pin-conversation-menu-text');
|
const pinMenuText = document.getElementById('pin-conversation-menu-text');
|
||||||
if (pinMenuText) {
|
if (pinMenuText && typeof window.t === 'function') {
|
||||||
|
pinMenuText.textContent = window.t('contextMenu.pinConversation');
|
||||||
|
} else if (pinMenuText) {
|
||||||
pinMenuText.textContent = '置顶此对话';
|
pinMenuText.textContent = '置顶此对话';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4333,14 +4369,17 @@ async function showGroupContextMenu(event, groupId) {
|
|||||||
|
|
||||||
// 更新菜单文本
|
// 更新菜单文本
|
||||||
const pinMenuText = document.getElementById('pin-group-menu-text');
|
const pinMenuText = document.getElementById('pin-group-menu-text');
|
||||||
if (pinMenuText) {
|
if (pinMenuText && typeof window.t === 'function') {
|
||||||
|
pinMenuText.textContent = isPinned ? window.t('contextMenu.unpinGroup') : window.t('contextMenu.pinGroup');
|
||||||
|
} else if (pinMenuText) {
|
||||||
pinMenuText.textContent = isPinned ? '取消置顶' : '置顶此分组';
|
pinMenuText.textContent = isPinned ? '取消置顶' : '置顶此分组';
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取分组置顶状态失败:', error);
|
console.error('获取分组置顶状态失败:', error);
|
||||||
// 如果获取失败,使用默认文本
|
|
||||||
const pinMenuText = document.getElementById('pin-group-menu-text');
|
const pinMenuText = document.getElementById('pin-group-menu-text');
|
||||||
if (pinMenuText) {
|
if (pinMenuText && typeof window.t === 'function') {
|
||||||
|
pinMenuText.textContent = window.t('contextMenu.pinGroup');
|
||||||
|
} else if (pinMenuText) {
|
||||||
pinMenuText.textContent = '置顶此分组';
|
pinMenuText.textContent = '置顶此分组';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4443,7 +4482,9 @@ async function renameConversation() {
|
|||||||
loadConversationsWithGroups();
|
loadConversationsWithGroups();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('重命名对话失败:', error);
|
console.error('重命名对话失败:', error);
|
||||||
alert('重命名失败: ' + (error.message || '未知错误'));
|
const failedLabel = typeof window.t === 'function' ? window.t('chat.renameFailed') : '重命名失败';
|
||||||
|
const unknownErr = typeof window.t === 'function' ? window.t('createGroupModal.unknownError') : '未知错误';
|
||||||
|
alert(failedLabel + ': ' + (error.message || unknownErr));
|
||||||
}
|
}
|
||||||
|
|
||||||
closeContextMenu();
|
closeContextMenu();
|
||||||
@@ -4636,13 +4677,14 @@ async function showMoveToGroupSubmenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 始终显示"创建分组"选项
|
// 始终显示"创建分组"选项
|
||||||
|
const addGroupLabel = typeof window.t === 'function' ? window.t('chat.addNewGroup') : '+ 新增分组';
|
||||||
const addItem = document.createElement('div');
|
const addItem = document.createElement('div');
|
||||||
addItem.className = 'context-submenu-item add-group-item';
|
addItem.className = 'context-submenu-item add-group-item';
|
||||||
addItem.innerHTML = `
|
addItem.innerHTML = `
|
||||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M12 5v14M5 12h14" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
<path d="M12 5v14M5 12h14" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
</svg>
|
</svg>
|
||||||
<span>+ 新增分组</span>
|
<span>${addGroupLabel}</span>
|
||||||
`;
|
`;
|
||||||
addItem.onclick = () => {
|
addItem.onclick = () => {
|
||||||
showCreateGroupModal(true);
|
showCreateGroupModal(true);
|
||||||
@@ -4917,7 +4959,8 @@ function deleteConversationFromContext() {
|
|||||||
const convId = contextMenuConversationId;
|
const convId = contextMenuConversationId;
|
||||||
if (!convId) return;
|
if (!convId) return;
|
||||||
|
|
||||||
if (confirm('确定要删除此对话吗?')) {
|
const confirmMsg = typeof window.t === 'function' ? window.t('chat.deleteConversationConfirm') : '确定要删除此对话吗?';
|
||||||
|
if (confirm(confirmMsg)) {
|
||||||
deleteConversation(convId, true); // 跳过内部确认,因为这里已经确认过了
|
deleteConversation(convId, true); // 跳过内部确认,因为这里已经确认过了
|
||||||
}
|
}
|
||||||
closeContextMenu();
|
closeContextMenu();
|
||||||
@@ -4944,6 +4987,15 @@ function closeContextMenu() {
|
|||||||
// 显示批量管理模态框
|
// 显示批量管理模态框
|
||||||
let allConversationsForBatch = [];
|
let allConversationsForBatch = [];
|
||||||
|
|
||||||
|
// 更新批量管理模态框标题(含条数),支持 i18n;count 为当前条数
|
||||||
|
function updateBatchManageTitle(count) {
|
||||||
|
const titleEl = document.getElementById('batch-manage-title');
|
||||||
|
if (!titleEl || typeof window.t !== 'function') return;
|
||||||
|
const template = window.t('batchManageModal.title', { count: '__C__' });
|
||||||
|
const parts = template.split('__C__');
|
||||||
|
titleEl.innerHTML = (parts[0] || '') + '<span id="batch-manage-count">' + (count || 0) + '</span>' + (parts[1] || '');
|
||||||
|
}
|
||||||
|
|
||||||
async function showBatchManageModal() {
|
async function showBatchManageModal() {
|
||||||
try {
|
try {
|
||||||
const response = await apiFetch('/api/conversations?limit=1000');
|
const response = await apiFetch('/api/conversations?limit=1000');
|
||||||
@@ -4957,10 +5009,7 @@ async function showBatchManageModal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const modal = document.getElementById('batch-manage-modal');
|
const modal = document.getElementById('batch-manage-modal');
|
||||||
const countEl = document.getElementById('batch-manage-count');
|
updateBatchManageTitle(allConversationsForBatch.length);
|
||||||
if (countEl) {
|
|
||||||
countEl.textContent = allConversationsForBatch.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
renderBatchConversations();
|
renderBatchConversations();
|
||||||
if (modal) {
|
if (modal) {
|
||||||
@@ -4971,10 +5020,7 @@ async function showBatchManageModal() {
|
|||||||
// 错误时使用空数组,不显示错误提示(更友好的用户体验)
|
// 错误时使用空数组,不显示错误提示(更友好的用户体验)
|
||||||
allConversationsForBatch = [];
|
allConversationsForBatch = [];
|
||||||
const modal = document.getElementById('batch-manage-modal');
|
const modal = document.getElementById('batch-manage-modal');
|
||||||
const countEl = document.getElementById('batch-manage-count');
|
updateBatchManageTitle(0);
|
||||||
if (countEl) {
|
|
||||||
countEl.textContent = 0;
|
|
||||||
}
|
|
||||||
if (modal) {
|
if (modal) {
|
||||||
renderBatchConversations();
|
renderBatchConversations();
|
||||||
modal.style.display = 'flex';
|
modal.style.display = 'flex';
|
||||||
@@ -5041,7 +5087,7 @@ function renderBatchConversations(filtered = null) {
|
|||||||
|
|
||||||
const name = document.createElement('div');
|
const name = document.createElement('div');
|
||||||
name.className = 'batch-table-col-name';
|
name.className = 'batch-table-col-name';
|
||||||
const originalTitle = conv.title || '未命名对话';
|
const originalTitle = conv.title || (typeof window.t === 'function' ? window.t('batchManageModal.unnamedConversation') : '未命名对话');
|
||||||
// 使用安全截断函数,限制最大长度为45个字符(留出空间显示省略号)
|
// 使用安全截断函数,限制最大长度为45个字符(留出空间显示省略号)
|
||||||
const truncatedTitle = safeTruncateText(originalTitle, 45);
|
const truncatedTitle = safeTruncateText(originalTitle, 45);
|
||||||
name.textContent = truncatedTitle;
|
name.textContent = truncatedTitle;
|
||||||
@@ -5051,7 +5097,8 @@ function renderBatchConversations(filtered = null) {
|
|||||||
const time = document.createElement('div');
|
const time = document.createElement('div');
|
||||||
time.className = 'batch-table-col-time';
|
time.className = 'batch-table-col-time';
|
||||||
const dateObj = conv.updatedAt ? new Date(conv.updatedAt) : new Date();
|
const dateObj = conv.updatedAt ? new Date(conv.updatedAt) : new Date();
|
||||||
time.textContent = dateObj.toLocaleString('zh-CN', {
|
const locale = (typeof i18next !== 'undefined' && i18next.language) ? i18next.language : 'zh-CN';
|
||||||
|
time.textContent = dateObj.toLocaleString(locale, {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
month: '2-digit',
|
month: '2-digit',
|
||||||
day: '2-digit',
|
day: '2-digit',
|
||||||
@@ -5105,11 +5152,12 @@ function toggleSelectAllBatch() {
|
|||||||
async function deleteSelectedConversations() {
|
async function deleteSelectedConversations() {
|
||||||
const checkboxes = document.querySelectorAll('.batch-conversation-checkbox:checked');
|
const checkboxes = document.querySelectorAll('.batch-conversation-checkbox:checked');
|
||||||
if (checkboxes.length === 0) {
|
if (checkboxes.length === 0) {
|
||||||
alert('请先选择要删除的对话');
|
alert(typeof window.t === 'function' ? window.t('batchManageModal.confirmDeleteNone') : '请先选择要删除的对话');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!confirm(`确定要删除选中的 ${checkboxes.length} 条对话吗?`)) {
|
const confirmMsg = typeof window.t === 'function' ? window.t('batchManageModal.confirmDeleteN', { count: checkboxes.length }) : '确定要删除选中的 ' + checkboxes.length + ' 条对话吗?';
|
||||||
|
if (!confirm(confirmMsg)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5123,7 +5171,9 @@ async function deleteSelectedConversations() {
|
|||||||
loadConversationsWithGroups();
|
loadConversationsWithGroups();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('删除失败:', error);
|
console.error('删除失败:', error);
|
||||||
alert('删除失败: ' + (error.message || '未知错误'));
|
const failedMsg = typeof window.t === 'function' ? window.t('batchManageModal.deleteFailed') : '删除失败';
|
||||||
|
const unknownErr = typeof window.t === 'function' ? window.t('createGroupModal.unknownError') : '未知错误';
|
||||||
|
alert(failedMsg + ': ' + (error.message || unknownErr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5140,6 +5190,14 @@ function closeBatchManageModal() {
|
|||||||
allConversationsForBatch = [];
|
allConversationsForBatch = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 语言切换时刷新批量管理模态框标题(若当前正在显示)
|
||||||
|
document.addEventListener('languagechange', function () {
|
||||||
|
const modal = document.getElementById('batch-manage-modal');
|
||||||
|
if (modal && modal.style.display === 'flex') {
|
||||||
|
updateBatchManageTitle(allConversationsForBatch.length);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 显示创建分组模态框
|
// 显示创建分组模态框
|
||||||
function showCreateGroupModal(andMoveConversation = false) {
|
function showCreateGroupModal(andMoveConversation = false) {
|
||||||
const modal = document.getElementById('create-group-modal');
|
const modal = document.getElementById('create-group-modal');
|
||||||
@@ -5208,6 +5266,15 @@ function selectSuggestion(name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 按 i18n key 选择建议标签(用于国际化下填充当前语言的文案)
|
||||||
|
function selectSuggestionByKey(i18nKey) {
|
||||||
|
const input = document.getElementById('create-group-name-input');
|
||||||
|
if (input && typeof window.t === 'function') {
|
||||||
|
input.value = window.t(i18nKey);
|
||||||
|
input.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 切换图标选择器显示状态
|
// 切换图标选择器显示状态
|
||||||
function toggleGroupIconPicker() {
|
function toggleGroupIconPicker() {
|
||||||
const picker = document.getElementById('group-icon-picker');
|
const picker = document.getElementById('group-icon-picker');
|
||||||
@@ -5299,7 +5366,7 @@ async function createGroup(event) {
|
|||||||
|
|
||||||
const name = input.value.trim();
|
const name = input.value.trim();
|
||||||
if (!name) {
|
if (!name) {
|
||||||
alert('请输入分组名称');
|
alert(typeof window.t === 'function' ? window.t('createGroupModal.groupNamePlaceholder') : '请输入分组名称');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5320,7 +5387,7 @@ async function createGroup(event) {
|
|||||||
|
|
||||||
const nameExists = groups.some(g => g.name === name);
|
const nameExists = groups.some(g => g.name === name);
|
||||||
if (nameExists) {
|
if (nameExists) {
|
||||||
alert('分组名称已存在,请使用其他名称');
|
alert(typeof window.t === 'function' ? window.t('createGroupModal.nameExists') : '分组名称已存在,请使用其他名称');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -5345,11 +5412,13 @@ async function createGroup(event) {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const error = await response.json();
|
const error = await response.json();
|
||||||
|
const nameExistsMsg = typeof window.t === 'function' ? window.t('createGroupModal.nameExists') : '分组名称已存在,请使用其他名称';
|
||||||
if (error.error && error.error.includes('已存在')) {
|
if (error.error && error.error.includes('已存在')) {
|
||||||
alert('分组名称已存在,请使用其他名称');
|
alert(nameExistsMsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error(error.error || '创建失败');
|
const createFailedMsg = typeof window.t === 'function' ? window.t('createGroupModal.createFailed') : '创建失败';
|
||||||
|
throw new Error(error.error || createFailedMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newGroup = await response.json();
|
const newGroup = await response.json();
|
||||||
@@ -5375,7 +5444,9 @@ async function createGroup(event) {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('创建分组失败:', error);
|
console.error('创建分组失败:', error);
|
||||||
alert('创建失败: ' + (error.message || '未知错误'));
|
const createFailedMsg = typeof window.t === 'function' ? window.t('createGroupModal.createFailed') : '创建失败';
|
||||||
|
const unknownErr = typeof window.t === 'function' ? window.t('createGroupModal.unknownError') : '未知错误';
|
||||||
|
alert(createFailedMsg + ': ' + (error.message || unknownErr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5517,10 +5588,12 @@ async function loadGroupConversations(groupId, searchQuery = '') {
|
|||||||
list.innerHTML = '';
|
list.innerHTML = '';
|
||||||
|
|
||||||
if (groupConvs.length === 0) {
|
if (groupConvs.length === 0) {
|
||||||
|
const emptyMsg = typeof window.t === 'function' ? window.t('chat.emptyGroupConversations') : '该分组暂无对话';
|
||||||
|
const noMatchMsg = typeof window.t === 'function' ? window.t('chat.noMatchingConversationsInGroup') : '未找到匹配的对话';
|
||||||
if (searchQuery && searchQuery.trim()) {
|
if (searchQuery && searchQuery.trim()) {
|
||||||
list.innerHTML = '<div style="padding: 40px; text-align: center; color: var(--text-muted);">未找到匹配的对话</div>';
|
list.innerHTML = '<div style="padding: 40px; text-align: center; color: var(--text-muted);">' + (noMatchMsg || '未找到匹配的对话') + '</div>';
|
||||||
} else {
|
} else {
|
||||||
list.innerHTML = '<div style="padding: 40px; text-align: center; color: var(--text-muted);">该分组暂无对话</div>';
|
list.innerHTML = '<div style="padding: 40px; text-align: center; color: var(--text-muted);">' + (emptyMsg || '该分组暂无对话') + '</div>';
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -5651,7 +5724,8 @@ async function editGroup() {
|
|||||||
const group = await response.json();
|
const group = await response.json();
|
||||||
if (!group) return;
|
if (!group) return;
|
||||||
|
|
||||||
const newName = prompt('请输入新名称:', group.name);
|
const renamePrompt = typeof window.t === 'function' ? window.t('chat.renameGroupPrompt') : '请输入新名称:';
|
||||||
|
const newName = prompt(renamePrompt, group.name);
|
||||||
if (newName === null || !newName.trim()) return;
|
if (newName === null || !newName.trim()) return;
|
||||||
|
|
||||||
const trimmedName = newName.trim();
|
const trimmedName = newName.trim();
|
||||||
@@ -5672,7 +5746,7 @@ async function editGroup() {
|
|||||||
|
|
||||||
const nameExists = groups.some(g => g.name === trimmedName && g.id !== currentGroupId);
|
const nameExists = groups.some(g => g.name === trimmedName && g.id !== currentGroupId);
|
||||||
if (nameExists) {
|
if (nameExists) {
|
||||||
alert('分组名称已存在,请使用其他名称');
|
alert(typeof window.t === 'function' ? window.t('createGroupModal.nameExists') : '分组名称已存在,请使用其他名称');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5712,7 +5786,8 @@ async function editGroup() {
|
|||||||
async function deleteGroup() {
|
async function deleteGroup() {
|
||||||
if (!currentGroupId) return;
|
if (!currentGroupId) return;
|
||||||
|
|
||||||
if (!confirm('确定要删除此分组吗?分组中的对话不会被删除,但会从分组中移除。')) {
|
const deleteConfirmMsg = typeof window.t === 'function' ? window.t('chat.deleteGroupConfirm') : '确定要删除此分组吗?分组中的对话不会被删除,但会从分组中移除。';
|
||||||
|
if (!confirm(deleteConfirmMsg)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5758,7 +5833,8 @@ async function renameGroupFromContext() {
|
|||||||
const group = await response.json();
|
const group = await response.json();
|
||||||
if (!group) return;
|
if (!group) return;
|
||||||
|
|
||||||
const newName = prompt('请输入新名称:', group.name);
|
const renamePrompt = typeof window.t === 'function' ? window.t('chat.renameGroupPrompt') : '请输入新名称:';
|
||||||
|
const newName = prompt(renamePrompt, group.name);
|
||||||
if (newName === null || !newName.trim()) {
|
if (newName === null || !newName.trim()) {
|
||||||
closeGroupContextMenu();
|
closeGroupContextMenu();
|
||||||
return;
|
return;
|
||||||
@@ -5782,7 +5858,7 @@ async function renameGroupFromContext() {
|
|||||||
|
|
||||||
const nameExists = groups.some(g => g.name === trimmedName && g.id !== groupId);
|
const nameExists = groups.some(g => g.name === trimmedName && g.id !== groupId);
|
||||||
if (nameExists) {
|
if (nameExists) {
|
||||||
alert('分组名称已存在,请使用其他名称');
|
alert(typeof window.t === 'function' ? window.t('createGroupModal.nameExists') : '分组名称已存在,请使用其他名称');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5817,7 +5893,9 @@ async function renameGroupFromContext() {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('重命名分组失败:', error);
|
console.error('重命名分组失败:', error);
|
||||||
alert('重命名失败: ' + (error.message || '未知错误'));
|
const failedLabel = typeof window.t === 'function' ? window.t('chat.renameFailed') : '重命名失败';
|
||||||
|
const unknownErr = typeof window.t === 'function' ? window.t('createGroupModal.unknownError') : '未知错误';
|
||||||
|
alert(failedLabel + ': ' + (error.message || unknownErr));
|
||||||
}
|
}
|
||||||
|
|
||||||
closeGroupContextMenu();
|
closeGroupContextMenu();
|
||||||
@@ -5867,7 +5945,8 @@ async function deleteGroupFromContext() {
|
|||||||
const groupId = contextMenuGroupId;
|
const groupId = contextMenuGroupId;
|
||||||
if (!groupId) return;
|
if (!groupId) return;
|
||||||
|
|
||||||
if (!confirm('确定要删除此分组吗?分组中的对话不会被删除,但会从分组中移除。')) {
|
const deleteConfirmMsg = typeof window.t === 'function' ? window.t('chat.deleteGroupConfirm') : '确定要删除此分组吗?分组中的对话不会被删除,但会从分组中移除。';
|
||||||
|
if (!confirm(deleteConfirmMsg)) {
|
||||||
closeGroupContextMenu();
|
closeGroupContextMenu();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -17,7 +17,7 @@ async function refreshDashboard() {
|
|||||||
setEl('dashboard-kpi-tools-calls', '…');
|
setEl('dashboard-kpi-tools-calls', '…');
|
||||||
setEl('dashboard-kpi-success-rate', '…');
|
setEl('dashboard-kpi-success-rate', '…');
|
||||||
var chartPlaceholder = document.getElementById('dashboard-tools-pie-placeholder');
|
var chartPlaceholder = document.getElementById('dashboard-tools-pie-placeholder');
|
||||||
if (chartPlaceholder) { chartPlaceholder.style.removeProperty('display'); chartPlaceholder.textContent = '加载中…'; }
|
if (chartPlaceholder) { chartPlaceholder.style.removeProperty('display'); chartPlaceholder.textContent = (typeof window.t === 'function' ? window.t('common.loading') : '加载中…'); }
|
||||||
var barChartEl = document.getElementById('dashboard-tools-bar-chart');
|
var barChartEl = document.getElementById('dashboard-tools-bar-chart');
|
||||||
if (barChartEl) { barChartEl.style.display = 'none'; barChartEl.innerHTML = ''; }
|
if (barChartEl) { barChartEl.style.display = 'none'; barChartEl.innerHTML = ''; }
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ async function refreshDashboard() {
|
|||||||
setEl('dashboard-batch-pending', String(pending));
|
setEl('dashboard-batch-pending', String(pending));
|
||||||
setEl('dashboard-batch-running', String(running));
|
setEl('dashboard-batch-running', String(running));
|
||||||
setEl('dashboard-batch-done', String(done));
|
setEl('dashboard-batch-done', String(done));
|
||||||
setEl('dashboard-batch-total', total > 0 ? `共 ${total} 个` : '暂无任务');
|
setEl('dashboard-batch-total', total > 0 ? (typeof window.t === 'function' ? window.t('dashboard.totalCount', { count: total }) : `共 ${total} 个`) : (typeof window.t === 'function' ? window.t('dashboard.noTasks') : '暂无任务'));
|
||||||
|
|
||||||
// 更新进度条
|
// 更新进度条
|
||||||
if (total > 0) {
|
if (total > 0) {
|
||||||
@@ -138,7 +138,7 @@ async function refreshDashboard() {
|
|||||||
if (knowledgeRes && typeof knowledgeRes === 'object') {
|
if (knowledgeRes && typeof knowledgeRes === 'object') {
|
||||||
if (knowledgeRes.enabled === false) {
|
if (knowledgeRes.enabled === false) {
|
||||||
// 功能未启用:用状态标签展示,数值保持为 "-"
|
// 功能未启用:用状态标签展示,数值保持为 "-"
|
||||||
if (knowledgeStatusEl) knowledgeStatusEl.textContent = '未启用';
|
if (knowledgeStatusEl) knowledgeStatusEl.textContent = (typeof window.t === 'function' ? window.t('dashboard.notEnabled') : '未启用');
|
||||||
if (knowledgeItemsEl) knowledgeItemsEl.textContent = '-';
|
if (knowledgeItemsEl) knowledgeItemsEl.textContent = '-';
|
||||||
if (knowledgeCategoriesEl) knowledgeCategoriesEl.textContent = '-';
|
if (knowledgeCategoriesEl) knowledgeCategoriesEl.textContent = '-';
|
||||||
} else {
|
} else {
|
||||||
@@ -149,9 +149,9 @@ async function refreshDashboard() {
|
|||||||
// 根据数据量给个轻量状态文案
|
// 根据数据量给个轻量状态文案
|
||||||
if (knowledgeStatusEl) {
|
if (knowledgeStatusEl) {
|
||||||
if (items > 0 || categories > 0) {
|
if (items > 0 || categories > 0) {
|
||||||
knowledgeStatusEl.textContent = '已启用';
|
knowledgeStatusEl.textContent = (typeof window.t === 'function' ? window.t('dashboard.enabled') : '已启用');
|
||||||
} else {
|
} else {
|
||||||
knowledgeStatusEl.textContent = '待配置';
|
knowledgeStatusEl.textContent = (typeof window.t === 'function' ? window.t('dashboard.toConfigure') : '待配置');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,15 +172,15 @@ async function refreshDashboard() {
|
|||||||
const statusEl = document.getElementById('dashboard-skills-status');
|
const statusEl = document.getElementById('dashboard-skills-status');
|
||||||
if (statusEl) {
|
if (statusEl) {
|
||||||
if (totalCalls === 0) {
|
if (totalCalls === 0) {
|
||||||
statusEl.textContent = '待使用';
|
statusEl.textContent = (typeof window.t === 'function' ? window.t('dashboard.toUse') : '待使用');
|
||||||
statusEl.style.background = 'rgba(0, 0, 0, 0.05)';
|
statusEl.style.background = 'rgba(0, 0, 0, 0.05)';
|
||||||
statusEl.style.color = 'var(--text-secondary)';
|
statusEl.style.color = 'var(--text-secondary)';
|
||||||
} else if (totalCalls < 10) {
|
} else if (totalCalls < 10) {
|
||||||
statusEl.textContent = '活跃';
|
statusEl.textContent = (typeof window.t === 'function' ? window.t('dashboard.active') : '活跃');
|
||||||
statusEl.style.background = 'rgba(16, 185, 129, 0.1)';
|
statusEl.style.background = 'rgba(16, 185, 129, 0.1)';
|
||||||
statusEl.style.color = '#10b981';
|
statusEl.style.color = '#10b981';
|
||||||
} else {
|
} else {
|
||||||
statusEl.textContent = '高频';
|
statusEl.textContent = (typeof window.t === 'function' ? window.t('dashboard.highFreq') : '高频');
|
||||||
statusEl.style.background = 'rgba(59, 130, 246, 0.1)';
|
statusEl.style.background = 'rgba(59, 130, 246, 0.1)';
|
||||||
statusEl.style.color = '#3b82f6';
|
statusEl.style.color = '#3b82f6';
|
||||||
}
|
}
|
||||||
@@ -200,7 +200,7 @@ async function refreshDashboard() {
|
|||||||
setEl('dashboard-kpi-tools-calls', '-');
|
setEl('dashboard-kpi-tools-calls', '-');
|
||||||
renderDashboardToolsBar(null);
|
renderDashboardToolsBar(null);
|
||||||
var ph = document.getElementById('dashboard-tools-pie-placeholder');
|
var ph = document.getElementById('dashboard-tools-pie-placeholder');
|
||||||
if (ph) { ph.style.removeProperty('display'); ph.textContent = '暂无调用数据'; }
|
if (ph) { ph.style.removeProperty('display'); ph.textContent = (typeof window.t === 'function' ? window.t('dashboard.noCallData') : '暂无调用数据'); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ function renderDashboardToolsBar(monitorRes) {
|
|||||||
|
|
||||||
if (!monitorRes || typeof monitorRes !== 'object') {
|
if (!monitorRes || typeof monitorRes !== 'object') {
|
||||||
placeholder.style.removeProperty('display');
|
placeholder.style.removeProperty('display');
|
||||||
placeholder.textContent = '暂无调用数据';
|
placeholder.textContent = (typeof window.t === 'function' ? window.t('dashboard.noCallData') : '暂无调用数据');
|
||||||
barChartEl.style.display = 'none';
|
barChartEl.style.display = 'none';
|
||||||
barChartEl.innerHTML = '';
|
barChartEl.innerHTML = '';
|
||||||
return;
|
return;
|
||||||
@@ -273,7 +273,7 @@ function renderDashboardToolsBar(monitorRes) {
|
|||||||
|
|
||||||
if (entries.length === 0) {
|
if (entries.length === 0) {
|
||||||
placeholder.style.removeProperty('display');
|
placeholder.style.removeProperty('display');
|
||||||
placeholder.textContent = '暂无调用数据';
|
placeholder.textContent = (typeof window.t === 'function' ? window.t('dashboard.noCallData') : '暂无调用数据');
|
||||||
barChartEl.style.display = 'none';
|
barChartEl.style.display = 'none';
|
||||||
barChartEl.innerHTML = '';
|
barChartEl.innerHTML = '';
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
// 前端国际化初始化(基于 i18next 浏览器版本)
|
||||||
|
(function () {
|
||||||
|
const DEFAULT_LANG = 'zh-CN';
|
||||||
|
const STORAGE_KEY = 'csai_lang';
|
||||||
|
const RESOURCES_PREFIX = '/static/i18n';
|
||||||
|
|
||||||
|
const loadedLangs = {};
|
||||||
|
|
||||||
|
function detectInitialLang() {
|
||||||
|
try {
|
||||||
|
const stored = localStorage.getItem(STORAGE_KEY);
|
||||||
|
if (stored) {
|
||||||
|
return stored;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('无法读取语言设置:', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
const navLang = (navigator.language || navigator.userLanguage || '').toLowerCase();
|
||||||
|
if (navLang.startsWith('zh')) {
|
||||||
|
return 'zh-CN';
|
||||||
|
}
|
||||||
|
if (navLang.startsWith('en')) {
|
||||||
|
return 'en-US';
|
||||||
|
}
|
||||||
|
return DEFAULT_LANG;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadLanguageResources(lang) {
|
||||||
|
if (loadedLangs[lang]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const resp = await fetch(RESOURCES_PREFIX + '/' + lang + '.json', {
|
||||||
|
cache: 'no-cache'
|
||||||
|
});
|
||||||
|
if (!resp.ok) {
|
||||||
|
console.warn('加载语言包失败:', lang, resp.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = await resp.json();
|
||||||
|
if (typeof i18next !== 'undefined') {
|
||||||
|
i18next.addResourceBundle(lang, 'translation', data, true, true);
|
||||||
|
}
|
||||||
|
loadedLangs[lang] = true;
|
||||||
|
} catch (e) {
|
||||||
|
console.error('加载语言包异常:', lang, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyTranslations(root) {
|
||||||
|
if (typeof i18next === 'undefined') return;
|
||||||
|
const container = root || document;
|
||||||
|
if (!container) return;
|
||||||
|
|
||||||
|
const elements = container.querySelectorAll('[data-i18n]');
|
||||||
|
elements.forEach(function (el) {
|
||||||
|
const key = el.getAttribute('data-i18n');
|
||||||
|
if (!key) return;
|
||||||
|
const skipText = el.getAttribute('data-i18n-skip-text') === 'true';
|
||||||
|
const isFormControl = (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA');
|
||||||
|
const attrList = el.getAttribute('data-i18n-attr');
|
||||||
|
const text = i18next.t(key);
|
||||||
|
|
||||||
|
// 仅当未使用 data-i18n-attr 时才替换元素文本内容(否则会覆盖卡片内的数字、子节点等)
|
||||||
|
// input/textarea:永不设置 textContent(会变成 value),只更新属性
|
||||||
|
if (!attrList && !skipText && !isFormControl && text && typeof text === 'string') {
|
||||||
|
el.textContent = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attrList) {
|
||||||
|
attrList.split(',').map(function (s) { return s.trim(); }).forEach(function (attr) {
|
||||||
|
if (!attr) return;
|
||||||
|
if (text && typeof text === 'string') {
|
||||||
|
el.setAttribute(attr, text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 对话输入框:若 value 与 placeholder 相同,清空 value 以便正确显示占位提示
|
||||||
|
try {
|
||||||
|
const chatInput = document.getElementById('chat-input');
|
||||||
|
if (chatInput && chatInput.tagName === 'TEXTAREA') {
|
||||||
|
const ph = (chatInput.getAttribute('placeholder') || '').trim();
|
||||||
|
if (ph && chatInput.value.trim() === ph) {
|
||||||
|
chatInput.value = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
|
||||||
|
// 更新 html lang 属性
|
||||||
|
try {
|
||||||
|
if (document && document.documentElement) {
|
||||||
|
document.documentElement.lang = i18next.language || DEFAULT_LANG;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateLangLabel() {
|
||||||
|
const label = document.getElementById('current-lang-label');
|
||||||
|
if (!label || typeof i18next === 'undefined') return;
|
||||||
|
const lang = (i18next.language || DEFAULT_LANG).toLowerCase();
|
||||||
|
if (lang.indexOf('zh') === 0) {
|
||||||
|
label.textContent = '中文';
|
||||||
|
} else {
|
||||||
|
label.textContent = 'English';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeLangDropdown() {
|
||||||
|
const dropdown = document.getElementById('lang-dropdown');
|
||||||
|
if (dropdown) {
|
||||||
|
dropdown.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleGlobalClickForLangDropdown(ev) {
|
||||||
|
const dropdown = document.getElementById('lang-dropdown');
|
||||||
|
const btn = document.querySelector('.lang-switcher-btn');
|
||||||
|
if (!dropdown || dropdown.style.display !== 'block') return;
|
||||||
|
const target = ev.target;
|
||||||
|
if (btn && btn.contains(target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!dropdown.contains(target)) {
|
||||||
|
closeLangDropdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function changeLanguage(lang) {
|
||||||
|
if (typeof i18next === 'undefined') return;
|
||||||
|
const current = i18next.language || DEFAULT_LANG;
|
||||||
|
if (lang === current) return;
|
||||||
|
await loadLanguageResources(lang);
|
||||||
|
await i18next.changeLanguage(lang);
|
||||||
|
try {
|
||||||
|
localStorage.setItem(STORAGE_KEY, lang);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('无法保存语言设置:', e);
|
||||||
|
}
|
||||||
|
applyTranslations(document);
|
||||||
|
updateLangLabel();
|
||||||
|
try {
|
||||||
|
document.dispatchEvent(new CustomEvent('languagechange', { detail: { lang: lang } }));
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function initI18n() {
|
||||||
|
if (typeof i18next === 'undefined') {
|
||||||
|
console.warn('i18next 未加载,跳过前端国际化初始化');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialLang = detectInitialLang();
|
||||||
|
await i18next.init({
|
||||||
|
lng: initialLang,
|
||||||
|
fallbackLng: DEFAULT_LANG,
|
||||||
|
debug: false,
|
||||||
|
resources: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
await loadLanguageResources(initialLang);
|
||||||
|
applyTranslations(document);
|
||||||
|
updateLangLabel();
|
||||||
|
|
||||||
|
// 导出全局函数供其他脚本调用(支持插值参数,如 _t('key', { count: 2 }))
|
||||||
|
window.t = function (key, opts) {
|
||||||
|
if (typeof i18next === 'undefined') return key;
|
||||||
|
return i18next.t(key, opts);
|
||||||
|
};
|
||||||
|
window.changeLanguage = changeLanguage;
|
||||||
|
window.applyTranslations = applyTranslations;
|
||||||
|
|
||||||
|
// 语言切换下拉支持
|
||||||
|
window.toggleLangDropdown = function () {
|
||||||
|
const dropdown = document.getElementById('lang-dropdown');
|
||||||
|
if (!dropdown) return;
|
||||||
|
if (dropdown.style.display === 'block') {
|
||||||
|
dropdown.style.display = 'none';
|
||||||
|
} else {
|
||||||
|
dropdown.style.display = 'block';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.onLanguageSelect = function (lang) {
|
||||||
|
changeLanguage(lang);
|
||||||
|
closeLangDropdown();
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('click', handleGlobalClickForLangDropdown);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
// i18n 初始化在 DOM Ready 后执行
|
||||||
|
initI18n().catch(function (e) {
|
||||||
|
console.error('初始化国际化失败:', e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
// 信息收集页面(FOFA)
|
// 信息收集页面(FOFA)
|
||||||
|
function _t(key, opts) {
|
||||||
|
return typeof window.t === 'function' ? window.t(key, opts) : key;
|
||||||
|
}
|
||||||
|
|
||||||
const FOFA_FORM_STORAGE_KEY = 'info-collect-fofa-form';
|
const FOFA_FORM_STORAGE_KEY = 'info-collect-fofa-form';
|
||||||
const FOFA_HIDDEN_FIELDS_STORAGE_KEY = 'info-collect-fofa-hidden-fields';
|
const FOFA_HIDDEN_FIELDS_STORAGE_KEY = 'info-collect-fofa-hidden-fields';
|
||||||
@@ -197,12 +200,12 @@ async function submitFofaSearch() {
|
|||||||
const full = !!els.full?.checked;
|
const full = !!els.full?.checked;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
alert('请输入 FOFA 查询语法');
|
alert(_t('infoCollect.enterFofaQuery'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveFofaFormToStorage({ query, size, page, fields, full });
|
saveFofaFormToStorage({ query, size, page, fields, full });
|
||||||
setFofaMeta('查询中...');
|
setFofaMeta(_t('infoCollect.querying'));
|
||||||
setFofaLoading(true);
|
setFofaLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -219,9 +222,9 @@ async function submitFofaSearch() {
|
|||||||
renderFofaResults(result);
|
renderFofaResults(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('FOFA 查询失败:', e);
|
console.error('FOFA 查询失败:', e);
|
||||||
setFofaMeta('查询失败');
|
setFofaMeta(_t('infoCollect.queryFailed'));
|
||||||
renderFofaResults({ query, fields: [], results: [], total: 0, page: 1, size: 0 });
|
renderFofaResults({ query, fields: [], results: [], total: 0, page: 1, size: 0 });
|
||||||
alert('FOFA 查询失败: ' + (e && e.message ? e.message : String(e)));
|
alert(_t('infoCollect.queryFailed') + ': ' + (e && e.message ? e.message : String(e)));
|
||||||
} finally {
|
} finally {
|
||||||
setFofaLoading(false);
|
setFofaLoading(false);
|
||||||
}
|
}
|
||||||
@@ -231,7 +234,7 @@ async function parseFofaNaturalLanguage() {
|
|||||||
const els = getFofaFormElements();
|
const els = getFofaFormElements();
|
||||||
const text = (els.nl?.value || '').trim();
|
const text = (els.nl?.value || '').trim();
|
||||||
if (!text) {
|
if (!text) {
|
||||||
alert('请输入自然语言描述');
|
alert(_t('infoCollect.enterNaturalLanguage'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,16 +246,16 @@ async function parseFofaNaturalLanguage() {
|
|||||||
|
|
||||||
// 先创建 controller,避免极快的重复点击触发并发请求
|
// 先创建 controller,避免极快的重复点击触发并发请求
|
||||||
fofaParseAbortController = new AbortController();
|
fofaParseAbortController = new AbortController();
|
||||||
setFofaParseLoading(true, 'AI 解析中...');
|
setFofaParseLoading(true, _t('infoCollect.parsePending'));
|
||||||
|
|
||||||
// 持续提示:直到请求完成/取消/失败才消失
|
// 持续提示:直到请求完成/取消/失败才消失
|
||||||
fofaParseToastHandle = showInlineToast('AI 解析中...(点击按钮可取消)', { duration: 0, id: 'fofa-parse-pending' });
|
fofaParseToastHandle = showInlineToast(_t('infoCollect.parsePendingClickCancel'), { duration: 0, id: 'fofa-parse-pending' });
|
||||||
|
|
||||||
// 如果超过一小段时间还没返回,再强调“仍在进行中”,降低误判为失败的概率
|
// 如果超过一小段时间还没返回,再强调“仍在进行中”,降低误判为失败的概率
|
||||||
fofaParseSlowTimer = setTimeout(() => {
|
fofaParseSlowTimer = setTimeout(() => {
|
||||||
const status = document.getElementById('fofa-nl-status');
|
const status = document.getElementById('fofa-nl-status');
|
||||||
if (status) {
|
if (status) {
|
||||||
status.textContent = 'AI 解析耗时较长,仍在处理中…';
|
status.textContent = _t('infoCollect.parseSlow');
|
||||||
status.style.display = 'block';
|
status.style.display = 'block';
|
||||||
}
|
}
|
||||||
}, 1800);
|
}, 1800);
|
||||||
@@ -269,15 +272,15 @@ async function parseFofaNaturalLanguage() {
|
|||||||
throw new Error(result.error || `请求失败: ${resp.status}`);
|
throw new Error(result.error || `请求失败: ${resp.status}`);
|
||||||
}
|
}
|
||||||
showFofaParseModal(text, result);
|
showFofaParseModal(text, result);
|
||||||
showInlineToast('AI 解析完成');
|
showInlineToast(_t('infoCollect.parseDone'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// AbortController 取消:不视为失败
|
// AbortController 取消:不视为失败
|
||||||
if (e && (e.name === 'AbortError' || String(e).includes('AbortError'))) {
|
if (e && (e.name === 'AbortError' || String(e).includes('AbortError'))) {
|
||||||
showInlineToast('已取消 AI 解析');
|
showInlineToast(_t('infoCollect.parseCancelled'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.error('FOFA 自然语言解析失败:', e);
|
console.error('FOFA 自然语言解析失败:', e);
|
||||||
showInlineToast('AI 解析失败:' + (e && e.message ? e.message : String(e)), { duration: 2800 });
|
showInlineToast(_t('infoCollect.parseFailed') + (e && e.message ? e.message : String(e)), { duration: 2800 });
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
fofaParseAbortController = null;
|
fofaParseAbortController = null;
|
||||||
@@ -298,17 +301,17 @@ function setFofaParseLoading(loading, statusText) {
|
|||||||
const status = document.getElementById('fofa-nl-status');
|
const status = document.getElementById('fofa-nl-status');
|
||||||
if (btn) {
|
if (btn) {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
if (!btn.dataset.originalText) btn.dataset.originalText = btn.textContent || 'AI 解析';
|
if (!btn.dataset.originalText) btn.dataset.originalText = btn.textContent || _t('infoCollectPage.parseBtn');
|
||||||
btn.classList.add('btn-loading');
|
btn.classList.add('btn-loading');
|
||||||
btn.textContent = '取消解析';
|
btn.textContent = _t('infoCollect.cancelParse');
|
||||||
btn.title = '点击取消 AI 解析';
|
btn.title = _t('infoCollect.clickToCancelParse');
|
||||||
btn.dataset.loading = '1';
|
btn.dataset.loading = '1';
|
||||||
btn.setAttribute('aria-busy', 'true');
|
btn.setAttribute('aria-busy', 'true');
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
} else {
|
} else {
|
||||||
btn.classList.remove('btn-loading');
|
btn.classList.remove('btn-loading');
|
||||||
btn.textContent = btn.dataset.originalText || 'AI 解析';
|
btn.textContent = btn.dataset.originalText || _t('infoCollectPage.parseBtn');
|
||||||
btn.title = '将自然语言解析为 FOFA 查询语法';
|
btn.title = _t('infoCollect.parseToFofa');
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
delete btn.dataset.loading;
|
delete btn.dataset.loading;
|
||||||
btn.removeAttribute('aria-busy');
|
btn.removeAttribute('aria-busy');
|
||||||
@@ -336,7 +339,7 @@ function showFofaParseModal(nlText, parsed) {
|
|||||||
|
|
||||||
const warningsHtml = warnings.length
|
const warningsHtml = warnings.length
|
||||||
? `<ul style="margin: 8px 0 0 18px;">${warnings.map(w => `<li>${escapeHtml(w)}</li>`).join('')}</ul>`
|
? `<ul style="margin: 8px 0 0 18px;">${warnings.map(w => `<li>${escapeHtml(w)}</li>`).join('')}</ul>`
|
||||||
: `<div class="muted" style="margin-top: 8px;">无</div>`;
|
: '<div class="muted" style="margin-top: 8px;">' + _t('infoCollect.none') + '</div>';
|
||||||
|
|
||||||
const modal = document.createElement('div');
|
const modal = document.createElement('div');
|
||||||
modal.id = 'fofa-parse-modal';
|
modal.id = 'fofa-parse-modal';
|
||||||
@@ -345,23 +348,23 @@ function showFofaParseModal(nlText, parsed) {
|
|||||||
modal.innerHTML = `
|
modal.innerHTML = `
|
||||||
<div class="modal-content" style="max-width: 900px;">
|
<div class="modal-content" style="max-width: 900px;">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h2>AI 解析结果</h2>
|
<h2>${_t('infoCollect.parseResultTitle')}</h2>
|
||||||
<span class="modal-close" id="fofa-parse-modal-close" title="关闭">×</span>
|
<span class="modal-close" id="fofa-parse-modal-close" title="${_t('common.close')}">×</span>
|
||||||
</div>
|
</div>
|
||||||
<div style="padding: 18px 28px; overflow: auto;">
|
<div style="padding: 18px 28px; overflow: auto;">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>自然语言</label>
|
<label>${_t('infoCollect.naturalLanguageLabel')}</label>
|
||||||
<div class="muted" style="margin-top: 6px; white-space: pre-wrap;">${safeNL || '-'}</div>
|
<div class="muted" style="margin-top: 6px; white-space: pre-wrap;">${safeNL || '-'}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group" style="margin-top: 14px;">
|
<div class="form-group" style="margin-top: 14px;">
|
||||||
<label for="fofa-parse-query">FOFA 查询语法(可编辑)</label>
|
<label for="fofa-parse-query">${_t('infoCollect.fofaQueryEditable')}</label>
|
||||||
<textarea id="fofa-parse-query" class="info-collect-query-input" rows="2" placeholder='例如:app="Apache" && country="CN"'></textarea>
|
<textarea id="fofa-parse-query" class="info-collect-query-input" rows="2" placeholder="${_t('infoCollect.queryPlaceholder')}"></textarea>
|
||||||
<small class="form-hint">请人工确认语法与范围无误后再执行查询。</small>
|
<small class="form-hint">${_t('infoCollect.confirmBeforeQuery')}</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group" style="margin-top: 14px;">
|
<div class="form-group" style="margin-top: 14px;">
|
||||||
<label>提醒</label>
|
<label>${_t('infoCollect.reminder')}</label>
|
||||||
<div style="background: #fff8e1; border: 1px solid #ffe8a3; border-radius: 10px; padding: 10px 12px;">
|
<div style="background: #fff8e1; border: 1px solid #ffe8a3; border-radius: 10px; padding: 10px 12px;">
|
||||||
${warningsHtml}
|
${warningsHtml}
|
||||||
</div>
|
</div>
|
||||||
@@ -369,14 +372,14 @@ function showFofaParseModal(nlText, parsed) {
|
|||||||
|
|
||||||
${explanation ? `
|
${explanation ? `
|
||||||
<div class="form-group" style="margin-top: 14px;">
|
<div class="form-group" style="margin-top: 14px;">
|
||||||
<label>解析说明</label>
|
<label>${_t('infoCollect.explanation')}</label>
|
||||||
<pre style="margin-top: 8px; white-space: pre-wrap; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 10px; padding: 10px 12px; font-size: 13px;">${escapeHtml(explanation)}</pre>
|
<pre style="margin-top: 8px; white-space: pre-wrap; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 10px; padding: 10px 12px; font-size: 13px;">${escapeHtml(explanation)}</pre>
|
||||||
</div>` : ''}
|
</div>` : ''}
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer" style="padding: 18px 28px;">
|
<div class="modal-footer" style="padding: 18px 28px;">
|
||||||
<button class="btn-secondary" type="button" id="fofa-parse-cancel">取消</button>
|
<button class="btn-secondary" type="button" id="fofa-parse-cancel">${_t('infoCollect.parseModalCancel')}</button>
|
||||||
<button class="btn-secondary" type="button" id="fofa-parse-apply">填入查询框</button>
|
<button class="btn-secondary" type="button" id="fofa-parse-apply">${_t('infoCollect.parseModalApply')}</button>
|
||||||
<button class="btn-primary" type="button" id="fofa-parse-apply-run">填入并查询</button>
|
<button class="btn-primary" type="button" id="fofa-parse-apply-run">${_t('infoCollect.parseModalApplyRun')}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@@ -402,7 +405,7 @@ function showFofaParseModal(nlText, parsed) {
|
|||||||
const els = getFofaFormElements();
|
const els = getFofaFormElements();
|
||||||
const q = (queryTextarea?.value || '').trim();
|
const q = (queryTextarea?.value || '').trim();
|
||||||
if (!q) {
|
if (!q) {
|
||||||
showInlineToast('解析结果为空:请在弹窗中补充/修改 FOFA 查询语法', { duration: 2600 });
|
showInlineToast(_t('infoCollect.parseResultEmpty'), { duration: 2600 });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (els.query) {
|
if (els.query) {
|
||||||
@@ -444,7 +447,7 @@ function setFofaMeta(text) {
|
|||||||
function updateSelectedMeta() {
|
function updateSelectedMeta() {
|
||||||
const els = getFofaFormElements();
|
const els = getFofaFormElements();
|
||||||
if (els.selectedMeta) {
|
if (els.selectedMeta) {
|
||||||
els.selectedMeta.textContent = `已选择 ${infoCollectState.selectedRowIndexes.size} 条`;
|
els.selectedMeta.textContent = _t('infoCollectPage.selectedRows', { count: infoCollectState.selectedRowIndexes.size });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,7 +457,7 @@ function setFofaLoading(loading) {
|
|||||||
if (loading) {
|
if (loading) {
|
||||||
const fieldsCount = (document.getElementById('fofa-fields')?.value || '').split(',').filter(Boolean).length;
|
const fieldsCount = (document.getElementById('fofa-fields')?.value || '').split(',').filter(Boolean).length;
|
||||||
const colspan = Math.max(1, fieldsCount + 1);
|
const colspan = Math.max(1, fieldsCount + 1);
|
||||||
els.tbody.innerHTML = `<tr><td class="muted" style="padding: 16px;" colspan="${colspan}">加载中...</td></tr>`;
|
els.tbody.innerHTML = '<tr><td class="muted" style="padding: 16px;" colspan="' + colspan + '">' + escapeHtml(_t('infoCollect.loading')) + '</td></tr>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,7 +493,7 @@ function renderFofaResults(payload) {
|
|||||||
const size = typeof payload.size === 'number' ? payload.size : 0;
|
const size = typeof payload.size === 'number' ? payload.size : 0;
|
||||||
const page = typeof payload.page === 'number' ? payload.page : 1;
|
const page = typeof payload.page === 'number' ? payload.page : 1;
|
||||||
|
|
||||||
setFofaMeta(`共 ${total} 条 · 本页 ${results.length} 条 · page=${page} · size=${size}`);
|
setFofaMeta(_t('infoCollect.resultsMeta', { total, count: results.length, page, size }));
|
||||||
|
|
||||||
// 可见字段
|
// 可见字段
|
||||||
const visibleFields = fields.filter(f => !infoCollectState.hiddenFields.has(f));
|
const visibleFields = fields.filter(f => !infoCollectState.hiddenFields.has(f));
|
||||||
@@ -500,16 +503,16 @@ function renderFofaResults(payload) {
|
|||||||
|
|
||||||
// 表头(左:勾选列;右:操作列固定)
|
// 表头(左:勾选列;右:操作列固定)
|
||||||
const headerCells = [
|
const headerCells = [
|
||||||
'<th class="info-collect-col-select"><input type="checkbox" id="fofa-select-all" title="全选/全不选"/></th>',
|
'<th class="info-collect-col-select"><input type="checkbox" id="fofa-select-all" title="' + escapeHtml(_t('infoCollect.selectAll')) + '"/></th>',
|
||||||
...visibleFields.map(f => `<th>${escapeHtml(String(f))}</th>`),
|
...visibleFields.map(f => `<th>${escapeHtml(String(f))}</th>`),
|
||||||
'<th class="info-collect-col-actions">操作</th>'
|
'<th class="info-collect-col-actions">' + escapeHtml(_t('infoCollect.actions')) + '</th>'
|
||||||
].join('');
|
].join('');
|
||||||
els.thead.innerHTML = `<tr>${headerCells}</tr>`;
|
els.thead.innerHTML = `<tr>${headerCells}</tr>`;
|
||||||
|
|
||||||
// 表体
|
// 表体
|
||||||
if (results.length === 0) {
|
if (results.length === 0) {
|
||||||
const colspan = Math.max(1, visibleFields.length + 2);
|
const colspan = Math.max(1, visibleFields.length + 2);
|
||||||
els.tbody.innerHTML = `<tr><td class="muted" style="padding: 16px;" colspan="${colspan}">暂无数据</td></tr>`;
|
els.tbody.innerHTML = '<tr><td class="muted" style="padding: 16px;" colspan="' + colspan + '">' + escapeHtml(_t('common.noData')) + '</td></tr>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,7 +522,7 @@ function renderFofaResults(payload) {
|
|||||||
const encoded = encodeURIComponent(JSON.stringify(safeRow));
|
const encoded = encodeURIComponent(JSON.stringify(safeRow));
|
||||||
const encodedTarget = encodeURIComponent(target || '');
|
const encodedTarget = encodeURIComponent(target || '');
|
||||||
|
|
||||||
const selectHtml = `<td class="info-collect-col-select"><input class="fofa-row-select" type="checkbox" data-index="${idx}" title="选择该行"/></td>`;
|
const selectHtml = '<td class="info-collect-col-select"><input class="fofa-row-select" type="checkbox" data-index="' + idx + '" title="' + escapeHtml(_t('infoCollect.selectRow')) + '"/></td>';
|
||||||
|
|
||||||
const cellsHtml = visibleFields.map(f => {
|
const cellsHtml = visibleFields.map(f => {
|
||||||
const val = safeRow[f];
|
const val = safeRow[f];
|
||||||
@@ -537,13 +540,13 @@ function renderFofaResults(payload) {
|
|||||||
|
|
||||||
const actionHtml = `
|
const actionHtml = `
|
||||||
<div class="info-collect-actions">
|
<div class="info-collect-actions">
|
||||||
<button class="btn-icon" onclick="copyFofaTargetEncoded('${encodedTarget}'); event.stopPropagation();" title="复制目标">
|
<button class="btn-icon" onclick="copyFofaTargetEncoded('${encodedTarget}'); event.stopPropagation();" title="${escapeHtml(_t('infoCollect.copyTarget'))}">
|
||||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
<rect x="9" y="9" width="13" height="13" rx="2" stroke="currentColor" stroke-width="2"/>
|
<rect x="9" y="9" width="13" height="13" rx="2" stroke="currentColor" stroke-width="2"/>
|
||||||
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn-icon" onclick="scanFofaRow('${encoded}', event); event.stopPropagation();" title="发送到对话(可编辑;Ctrl/⌘+点击可直接发送)">
|
<button class="btn-icon" onclick="scanFofaRow('${encoded}', event); event.stopPropagation();" title="${escapeHtml(_t('infoCollect.sendToChat'))}">
|
||||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M10.5 13.5l3-3" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
<path d="M10.5 13.5l3-3" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
||||||
<path d="M8 8H5a4 4 0 1 0 0 8h3" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
<path d="M8 8H5a4 4 0 1 0 0 8h3" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
||||||
@@ -602,14 +605,14 @@ function normalizeHttpLink(raw) {
|
|||||||
function copyFofaTarget(target) {
|
function copyFofaTarget(target) {
|
||||||
const text = (target || '').trim();
|
const text = (target || '').trim();
|
||||||
if (!text) {
|
if (!text) {
|
||||||
alert('没有可复制的目标');
|
alert(_t('infoCollect.noTargetToCopy'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
navigator.clipboard.writeText(text).then(() => {
|
navigator.clipboard.writeText(text).then(() => {
|
||||||
// 简单提示
|
// 简单提示
|
||||||
showInlineToast('已复制目标');
|
showInlineToast(_t('infoCollect.targetCopied'));
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
alert('复制失败,请手动复制:' + text);
|
alert(_t('infoCollect.manualCopyHint') + text);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -655,7 +658,7 @@ function showInlineToast(text, options) {
|
|||||||
function truncateForPreview(value, maxLen) {
|
function truncateForPreview(value, maxLen) {
|
||||||
const s = value == null ? '' : String(value);
|
const s = value == null ? '' : String(value);
|
||||||
if (maxLen <= 0 || s.length <= maxLen) return s;
|
if (maxLen <= 0 || s.length <= maxLen) return s;
|
||||||
return s.slice(0, maxLen) + '...(已截断)';
|
return s.slice(0, maxLen) + '...(' + _t('infoCollect.truncated') + ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatFofaRowSummary(row, fields) {
|
function formatFofaRowSummary(row, fields) {
|
||||||
@@ -707,7 +710,7 @@ function scanFofaRow(encodedRowJson, clickEvent) {
|
|||||||
const fields = (document.getElementById('fofa-fields')?.value || '').split(',').map(s => s.trim()).filter(Boolean);
|
const fields = (document.getElementById('fofa-fields')?.value || '').split(',').map(s => s.trim()).filter(Boolean);
|
||||||
const target = inferTargetFromRow(row, fields);
|
const target = inferTargetFromRow(row, fields);
|
||||||
if (!target) {
|
if (!target) {
|
||||||
alert('无法从该行推断扫描目标(建议在 fields 中包含 host/ip/port/domain)');
|
alert(_t('infoCollect.cannotInferTarget'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -745,10 +748,10 @@ function scanFofaRow(encodedRowJson, clickEvent) {
|
|||||||
if (typeof sendMessage === 'function') {
|
if (typeof sendMessage === 'function') {
|
||||||
sendMessage();
|
sendMessage();
|
||||||
} else {
|
} else {
|
||||||
alert('未找到 sendMessage(),请刷新页面后重试');
|
alert(_t('infoCollect.noSendMessage'));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showInlineToast('已填入对话输入框,可编辑后发送');
|
showInlineToast(_t('infoCollect.filledToInput'));
|
||||||
}
|
}
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
@@ -910,7 +913,7 @@ function hideAllFofaColumns() {
|
|||||||
function exportFofaResults(format) {
|
function exportFofaResults(format) {
|
||||||
const p = infoCollectState.currentPayload;
|
const p = infoCollectState.currentPayload;
|
||||||
if (!p || !Array.isArray(p.results) || p.results.length === 0) {
|
if (!p || !Array.isArray(p.results) || p.results.length === 0) {
|
||||||
alert('暂无可导出的结果');
|
alert(_t('infoCollect.noExportResult'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -936,7 +939,7 @@ function exportFofaResults(format) {
|
|||||||
if (format === 'xlsx') {
|
if (format === 'xlsx') {
|
||||||
// 使用 SheetJS 生成 XLSX(需在页面中引入 xlsx 库)
|
// 使用 SheetJS 生成 XLSX(需在页面中引入 xlsx 库)
|
||||||
if (typeof XLSX === 'undefined') {
|
if (typeof XLSX === 'undefined') {
|
||||||
alert('未加载 XLSX 库,请刷新页面后重试');
|
alert(_t('infoCollect.xlsxNotLoaded'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const aoa = [visibleFields].concat(p.results.map(row => {
|
const aoa = [visibleFields].concat(p.results.map(row => {
|
||||||
@@ -945,7 +948,7 @@ function exportFofaResults(format) {
|
|||||||
}));
|
}));
|
||||||
const ws = XLSX.utils.aoa_to_sheet(aoa);
|
const ws = XLSX.utils.aoa_to_sheet(aoa);
|
||||||
const wb = XLSX.utils.book_new();
|
const wb = XLSX.utils.book_new();
|
||||||
XLSX.utils.book_append_sheet(wb, ws, 'FOFA结果');
|
XLSX.utils.book_append_sheet(wb, ws, _t('infoCollect.batchScanTitle'));
|
||||||
XLSX.writeFile(wb, `fofa_results_${ts}.xlsx`);
|
XLSX.writeFile(wb, `fofa_results_${ts}.xlsx`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -982,12 +985,12 @@ function downloadBlob(content, filename, mime) {
|
|||||||
async function batchScanSelectedFofaRows() {
|
async function batchScanSelectedFofaRows() {
|
||||||
const p = infoCollectState.currentPayload;
|
const p = infoCollectState.currentPayload;
|
||||||
if (!p || !Array.isArray(p.results) || p.results.length === 0) {
|
if (!p || !Array.isArray(p.results) || p.results.length === 0) {
|
||||||
alert('暂无结果');
|
alert(_t('infoCollect.noResults'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const selected = Array.from(infoCollectState.selectedRowIndexes).sort((a, b) => a - b);
|
const selected = Array.from(infoCollectState.selectedRowIndexes).sort((a, b) => a - b);
|
||||||
if (selected.length === 0) {
|
if (selected.length === 0) {
|
||||||
alert('请先勾选需要扫描的行');
|
alert(_t('infoCollect.selectRowsFirst'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1009,11 +1012,11 @@ async function batchScanSelectedFofaRows() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (tasks.length === 0) {
|
if (tasks.length === 0) {
|
||||||
alert('未能从所选行推断任何可扫描目标(建议 fields 中包含 host/ip/port/domain)');
|
alert(_t('infoCollect.noScanTarget'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const title = (p.query ? `FOFA 批量扫描:${p.query}` : 'FOFA 批量扫描').slice(0, 80);
|
const title = (p.query ? _t('infoCollect.batchScanTitle') + ':' + p.query : _t('infoCollect.batchScanTitle')).slice(0, 80);
|
||||||
try {
|
try {
|
||||||
// 不强制切换到“信息收集”角色:沿用当前已选角色;若为默认则传空字符串交给后端走默认逻辑
|
// 不强制切换到“信息收集”角色:沿用当前已选角色;若为默认则传空字符串交给后端走默认逻辑
|
||||||
let role = '';
|
let role = '';
|
||||||
@@ -1029,7 +1032,7 @@ async function batchScanSelectedFofaRows() {
|
|||||||
});
|
});
|
||||||
const result = await resp.json().catch(() => ({}));
|
const result = await resp.json().catch(() => ({}));
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
throw new Error(result.error || `创建批量队列失败: ${resp.status}`);
|
throw new Error(result.error || _t('infoCollect.createQueueFailed') + ': ' + resp.status);
|
||||||
}
|
}
|
||||||
const queueId = result.queueId;
|
const queueId = result.queueId;
|
||||||
if (!queueId) {
|
if (!queueId) {
|
||||||
@@ -1045,13 +1048,13 @@ async function batchScanSelectedFofaRows() {
|
|||||||
}, 250);
|
}, 250);
|
||||||
|
|
||||||
if (skipped.length > 0) {
|
if (skipped.length > 0) {
|
||||||
showInlineToast(`已创建队列(跳过 ${skipped.length} 条无目标行)`);
|
showInlineToast(_t('infoCollect.queueCreatedSkipped', { n: skipped.length }));
|
||||||
} else {
|
} else {
|
||||||
showInlineToast('已创建批量扫描队列');
|
showInlineToast(_t('infoCollect.batchQueueCreated'));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('批量扫描失败:', e);
|
console.error('批量扫描失败:', e);
|
||||||
alert('批量扫描失败: ' + (e && e.message ? e.message : String(e)));
|
alert(_t('infoCollect.batchScanFailed') + ': ' + (e && e.message ? e.message : String(e)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1065,8 +1068,8 @@ function showCellDetailModal(field, fullText) {
|
|||||||
modal.innerHTML = `
|
modal.innerHTML = `
|
||||||
<div class="info-collect-cell-modal-content" role="dialog" aria-modal="true">
|
<div class="info-collect-cell-modal-content" role="dialog" aria-modal="true">
|
||||||
<div class="info-collect-cell-modal-header">
|
<div class="info-collect-cell-modal-header">
|
||||||
<div class="info-collect-cell-modal-title">${escapeHtml(field || '字段')}</div>
|
<div class="info-collect-cell-modal-title">${escapeHtml(field || _t('infoCollect.field'))}</div>
|
||||||
<button class="btn-icon" type="button" id="info-collect-cell-modal-close" title="关闭">
|
<button class="btn-icon" type="button" id="info-collect-cell-modal-close" title="${_t('common.close')}">
|
||||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M18 6L6 18M6 6l12 12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
<path d="M18 6L6 18M6 6l12 12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
||||||
</svg>
|
</svg>
|
||||||
@@ -1076,8 +1079,8 @@ function showCellDetailModal(field, fullText) {
|
|||||||
<pre class="info-collect-cell-modal-pre">${escapeHtml(fullText || '')}</pre>
|
<pre class="info-collect-cell-modal-pre">${escapeHtml(fullText || '')}</pre>
|
||||||
</div>
|
</div>
|
||||||
<div class="info-collect-cell-modal-footer">
|
<div class="info-collect-cell-modal-footer">
|
||||||
<button class="btn-secondary" type="button" id="info-collect-cell-modal-copy">复制</button>
|
<button class="btn-secondary" type="button" id="info-collect-cell-modal-copy">${_t('common.copy')}</button>
|
||||||
<button class="btn-primary" type="button" id="info-collect-cell-modal-ok">关闭</button>
|
<button class="btn-primary" type="button" id="info-collect-cell-modal-ok">${_t('common.close')}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@@ -1091,7 +1094,7 @@ function showCellDetailModal(field, fullText) {
|
|||||||
document.getElementById('info-collect-cell-modal-close')?.addEventListener('click', close);
|
document.getElementById('info-collect-cell-modal-close')?.addEventListener('click', close);
|
||||||
document.getElementById('info-collect-cell-modal-ok')?.addEventListener('click', close);
|
document.getElementById('info-collect-cell-modal-ok')?.addEventListener('click', close);
|
||||||
document.getElementById('info-collect-cell-modal-copy')?.addEventListener('click', () => {
|
document.getElementById('info-collect-cell-modal-copy')?.addEventListener('click', () => {
|
||||||
navigator.clipboard.writeText(fullText || '').then(() => showInlineToast('已复制')).catch(() => alert('复制失败'));
|
navigator.clipboard.writeText(fullText || '').then(() => showInlineToast(_t('common.copied'))).catch(() => alert(_t('common.copyFailed')));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Esc 关闭
|
// Esc 关闭
|
||||||
@@ -1122,3 +1125,13 @@ window.toggleFofaColumn = toggleFofaColumn;
|
|||||||
window.exportFofaResults = exportFofaResults;
|
window.exportFofaResults = exportFofaResults;
|
||||||
window.batchScanSelectedFofaRows = batchScanSelectedFofaRows;
|
window.batchScanSelectedFofaRows = batchScanSelectedFofaRows;
|
||||||
|
|
||||||
|
document.addEventListener('languagechange', function () {
|
||||||
|
updateSelectedMeta();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
|
document.addEventListener('DOMContentLoaded', function () { updateSelectedMeta(); });
|
||||||
|
} else {
|
||||||
|
updateSelectedMeta();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+150
-102
@@ -1,4 +1,37 @@
|
|||||||
// 知识库管理相关功能
|
// 知识库管理相关功能
|
||||||
|
function _t(key, opts) {
|
||||||
|
return typeof window.t === 'function' ? window.t(key, opts) : key;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回「知识库未启用」提示区块的 HTML(使用 data-i18n 以便语言切换时自动更新)
|
||||||
|
function getKnowledgeNotEnabledHTML() {
|
||||||
|
return `
|
||||||
|
<div class="empty-state" style="text-align: center; padding: 40px 20px;">
|
||||||
|
<div style="font-size: 48px; margin-bottom: 20px;">📚</div>
|
||||||
|
<h3 data-i18n="knowledge.notEnabledTitle" style="margin-bottom: 10px; color: #666;"></h3>
|
||||||
|
<p data-i18n="knowledge.notEnabledHint" style="color: #999; margin-bottom: 20px;"></p>
|
||||||
|
<button data-i18n="knowledge.goToSettings" onclick="switchToSettings()" style="
|
||||||
|
background: #007bff;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 10px 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
"></button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染「知识库未启用」状态到容器,并应用当前语言
|
||||||
|
function renderKnowledgeNotEnabledState(container) {
|
||||||
|
if (!container) return;
|
||||||
|
container.innerHTML = getKnowledgeNotEnabledHTML();
|
||||||
|
if (typeof window.applyTranslations === 'function') {
|
||||||
|
window.applyTranslations(container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let knowledgeCategories = [];
|
let knowledgeCategories = [];
|
||||||
let knowledgeItems = [];
|
let knowledgeItems = [];
|
||||||
let currentEditingItemId = null;
|
let currentEditingItemId = null;
|
||||||
@@ -32,26 +65,8 @@ async function loadKnowledgeCategories() {
|
|||||||
|
|
||||||
// 检查知识库功能是否启用
|
// 检查知识库功能是否启用
|
||||||
if (data.enabled === false) {
|
if (data.enabled === false) {
|
||||||
// 功能未启用,显示友好提示
|
// 功能未启用,显示友好提示(使用 data-i18n,切换语言时会自动更新)
|
||||||
const container = document.getElementById('knowledge-items-list');
|
renderKnowledgeNotEnabledState(document.getElementById('knowledge-items-list'));
|
||||||
if (container) {
|
|
||||||
container.innerHTML = `
|
|
||||||
<div class="empty-state" style="text-align: center; padding: 40px 20px;">
|
|
||||||
<div style="font-size: 48px; margin-bottom: 20px;">📚</div>
|
|
||||||
<h3 style="margin-bottom: 10px; color: #666;">知识库功能未启用</h3>
|
|
||||||
<p style="color: #999; margin-bottom: 20px;">${data.message || '请前往系统设置启用知识检索功能'}</p>
|
|
||||||
<button onclick="switchToSettings()" style="
|
|
||||||
background: #007bff;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
padding: 10px 20px;
|
|
||||||
border-radius: 5px;
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 14px;
|
|
||||||
">前往设置</button>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,25 +131,10 @@ async function loadKnowledgeItems(category = '', page = 1, pageSize = 10) {
|
|||||||
|
|
||||||
// 检查知识库功能是否启用
|
// 检查知识库功能是否启用
|
||||||
if (data.enabled === false) {
|
if (data.enabled === false) {
|
||||||
// 功能未启用,显示友好提示(如果还没有显示的话)
|
// 功能未启用,显示友好提示(如果还没有显示的话;使用 data-i18n,切换语言时会自动更新)
|
||||||
const container = document.getElementById('knowledge-items-list');
|
const container = document.getElementById('knowledge-items-list');
|
||||||
if (container && !container.querySelector('.empty-state')) {
|
if (container && !container.querySelector('.empty-state')) {
|
||||||
container.innerHTML = `
|
renderKnowledgeNotEnabledState(container);
|
||||||
<div class="empty-state" style="text-align: center; padding: 40px 20px;">
|
|
||||||
<div style="font-size: 48px; margin-bottom: 20px;">📚</div>
|
|
||||||
<h3 style="margin-bottom: 10px; color: #666;">知识库功能未启用</h3>
|
|
||||||
<p style="color: #999; margin-bottom: 20px;">${data.message || '请前往系统设置启用知识检索功能'}</p>
|
|
||||||
<button onclick="switchToSettings()" style="
|
|
||||||
background: #007bff;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
padding: 10px 20px;
|
|
||||||
border-radius: 5px;
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 14px;
|
|
||||||
">前往设置</button>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
knowledgeItems = [];
|
knowledgeItems = [];
|
||||||
knowledgePagination.total = 0;
|
knowledgePagination.total = 0;
|
||||||
@@ -459,6 +459,9 @@ async function updateIndexProgress() {
|
|||||||
const isComplete = status.is_complete || false;
|
const isComplete = status.is_complete || false;
|
||||||
const lastError = status.last_error || '';
|
const lastError = status.last_error || '';
|
||||||
|
|
||||||
|
// 检查是否正在重建索引(优先使用重建状态)
|
||||||
|
const isRebuilding = status.is_rebuilding || false;
|
||||||
|
|
||||||
if (totalItems === 0) {
|
if (totalItems === 0) {
|
||||||
// 没有知识项,隐藏进度条
|
// 没有知识项,隐藏进度条
|
||||||
progressContainer.style.display = 'none';
|
progressContainer.style.display = 'none';
|
||||||
@@ -524,6 +527,45 @@ async function updateIndexProgress() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 优先处理重建状态
|
||||||
|
if (isRebuilding) {
|
||||||
|
const rebuildTotal = status.rebuild_total || totalItems;
|
||||||
|
const rebuildCurrent = status.rebuild_current || 0;
|
||||||
|
const rebuildFailed = status.rebuild_failed || 0;
|
||||||
|
const rebuildLastItemID = status.rebuild_last_item_id || '';
|
||||||
|
const rebuildLastChunks = status.rebuild_last_chunks || 0;
|
||||||
|
const rebuildStartTime = status.rebuild_start_time || '';
|
||||||
|
|
||||||
|
// 计算进度百分比(使用重建进度)
|
||||||
|
let rebuildProgress = progressPercent;
|
||||||
|
if (rebuildTotal > 0) {
|
||||||
|
rebuildProgress = (rebuildCurrent / rebuildTotal) * 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
progressContainer.innerHTML = `
|
||||||
|
<div class="knowledge-index-progress">
|
||||||
|
<div class="progress-header">
|
||||||
|
<span class="progress-icon">🔨</span>
|
||||||
|
<span class="progress-text">正在重建索引:${rebuildCurrent}/${rebuildTotal} (${rebuildProgress.toFixed(1)}%) - 失败:${rebuildFailed}</span>
|
||||||
|
</div>
|
||||||
|
<div class="progress-bar-container">
|
||||||
|
<div class="progress-bar" style="width: ${rebuildProgress}%"></div>
|
||||||
|
</div>
|
||||||
|
<div class="progress-hint">
|
||||||
|
${rebuildLastItemID ? `正在处理:${escapeHtml(rebuildLastItemID.substring(0, 36))}... (${rebuildLastChunks} chunks)` : '正在处理...'}
|
||||||
|
${rebuildStartTime ? `<br>开始时间:${new Date(rebuildStartTime).toLocaleString()}` : ''}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
// 重建中时继续轮询
|
||||||
|
if (!indexProgressInterval) {
|
||||||
|
indexProgressInterval = setInterval(updateIndexProgress, 2000);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isComplete) {
|
if (isComplete) {
|
||||||
progressContainer.innerHTML = `
|
progressContainer.innerHTML = `
|
||||||
<div class="knowledge-index-progress-complete">
|
<div class="knowledge-index-progress-complete">
|
||||||
@@ -711,25 +753,7 @@ async function searchKnowledgeItems() {
|
|||||||
|
|
||||||
// 检查知识库功能是否启用
|
// 检查知识库功能是否启用
|
||||||
if (data.enabled === false) {
|
if (data.enabled === false) {
|
||||||
const container = document.getElementById('knowledge-items-list');
|
renderKnowledgeNotEnabledState(document.getElementById('knowledge-items-list'));
|
||||||
if (container) {
|
|
||||||
container.innerHTML = `
|
|
||||||
<div class="empty-state" style="text-align: center; padding: 40px 20px;">
|
|
||||||
<div style="font-size: 48px; margin-bottom: 20px;">📚</div>
|
|
||||||
<h3 style="margin-bottom: 10px; color: #666;">知识库功能未启用</h3>
|
|
||||||
<p style="color: #999; margin-bottom: 20px;">${data.message || '请前往系统设置启用知识检索功能'}</p>
|
|
||||||
<button onclick="switchToSettings()" style="
|
|
||||||
background: #007bff;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
padding: 10px 20px;
|
|
||||||
border-radius: 5px;
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 14px;
|
|
||||||
">前往设置</button>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1270,7 +1294,7 @@ async function loadRetrievalLogs(conversationId = '', messageId = '') {
|
|||||||
renderRetrievalLogs([]);
|
renderRetrievalLogs([]);
|
||||||
// 只在非空筛选条件下才显示错误通知(避免在没有数据时显示错误)
|
// 只在非空筛选条件下才显示错误通知(避免在没有数据时显示错误)
|
||||||
if (conversationId || messageId) {
|
if (conversationId || messageId) {
|
||||||
showNotification('加载检索日志失败: ' + error.message, 'error');
|
showNotification(_t('retrievalLogs.loadError') + ': ' + error.message, 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1284,7 +1308,7 @@ function renderRetrievalLogs(logs) {
|
|||||||
updateRetrievalStats(logs);
|
updateRetrievalStats(logs);
|
||||||
|
|
||||||
if (logs.length === 0) {
|
if (logs.length === 0) {
|
||||||
container.innerHTML = '<div class="empty-state">暂无检索记录</div>';
|
container.innerHTML = '<div class="empty-state">' + _t('retrievalLogs.noRecords') + '</div>';
|
||||||
retrievalLogsData = [];
|
retrievalLogsData = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1344,7 +1368,7 @@ function renderRetrievalLogs(logs) {
|
|||||||
</div>
|
</div>
|
||||||
<div class="retrieval-log-main-info">
|
<div class="retrieval-log-main-info">
|
||||||
<div class="retrieval-log-query">
|
<div class="retrieval-log-query">
|
||||||
${escapeHtml(log.query || '无查询内容')}
|
${escapeHtml(log.query || _t('retrievalLogs.noQuery'))}
|
||||||
</div>
|
</div>
|
||||||
<div class="retrieval-log-meta">
|
<div class="retrieval-log-meta">
|
||||||
<span class="retrieval-log-time" title="${formatTime(log.createdAt)}">
|
<span class="retrieval-log-time" title="${formatTime(log.createdAt)}">
|
||||||
@@ -1354,33 +1378,33 @@ function renderRetrievalLogs(logs) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="retrieval-log-result-badge ${hasResults ? 'success' : 'empty'}">
|
<div class="retrieval-log-result-badge ${hasResults ? 'success' : 'empty'}">
|
||||||
${hasResults ? (itemCount > 0 ? `${itemCount} 项` : '有结果') : '无结果'}
|
${hasResults ? (itemCount > 0 ? itemCount + ' ' + _t('retrievalLogs.itemsUnit') : _t('retrievalLogs.hasResults')) : _t('retrievalLogs.noResults')}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="retrieval-log-card-body">
|
<div class="retrieval-log-card-body">
|
||||||
<div class="retrieval-log-details-grid">
|
<div class="retrieval-log-details-grid">
|
||||||
${log.conversationId ? `
|
${log.conversationId ? `
|
||||||
<div class="retrieval-log-detail-item">
|
<div class="retrieval-log-detail-item">
|
||||||
<span class="detail-label">对话ID</span>
|
<span class="detail-label">${_t('retrievalLogs.conversationId')}</span>
|
||||||
<code class="detail-value" title="点击复制" onclick="navigator.clipboard.writeText('${escapeHtml(log.conversationId)}'); this.title='已复制!'; setTimeout(() => this.title='点击复制', 2000);" style="cursor: pointer;">${escapeHtml(log.conversationId)}</code>
|
<code class="detail-value" title="${_t('retrievalLogs.clickToCopy')}" data-copy-title-copied="${_t('common.copied')}" data-copy-title-click="${_t('retrievalLogs.clickToCopy')}" onclick="var t=this; navigator.clipboard.writeText('${escapeHtml(log.conversationId)}').then(function(){ t.title=t.getAttribute('data-copy-title-copied')||'Copied!'; setTimeout(function(){ t.title=t.getAttribute('data-copy-title-click')||'Click to copy'; }, 2000); });" style="cursor: pointer;">${escapeHtml(log.conversationId)}</code>
|
||||||
</div>
|
</div>
|
||||||
` : ''}
|
` : ''}
|
||||||
${log.messageId ? `
|
${log.messageId ? `
|
||||||
<div class="retrieval-log-detail-item">
|
<div class="retrieval-log-detail-item">
|
||||||
<span class="detail-label">消息ID</span>
|
<span class="detail-label">${_t('retrievalLogs.messageId')}</span>
|
||||||
<code class="detail-value" title="点击复制" onclick="navigator.clipboard.writeText('${escapeHtml(log.messageId)}'); this.title='已复制!'; setTimeout(() => this.title='点击复制', 2000);" style="cursor: pointer;">${escapeHtml(log.messageId)}</code>
|
<code class="detail-value" title="${_t('retrievalLogs.clickToCopy')}" data-copy-title-copied="${_t('common.copied')}" data-copy-title-click="${_t('retrievalLogs.clickToCopy')}" onclick="var el=this; navigator.clipboard.writeText('${escapeHtml(log.messageId)}').then(function(){ el.title=el.getAttribute('data-copy-title-copied')||el.title; setTimeout(function(){ el.title=el.getAttribute('data-copy-title-click')||el.title; }, 2000); });" style="cursor: pointer;">${escapeHtml(log.messageId)}</code>
|
||||||
</div>
|
</div>
|
||||||
` : ''}
|
` : ''}
|
||||||
<div class="retrieval-log-detail-item">
|
<div class="retrieval-log-detail-item">
|
||||||
<span class="detail-label">检索结果</span>
|
<span class="detail-label">${_t('retrievalLogs.retrievalResult')}</span>
|
||||||
<span class="detail-value ${hasResults ? 'text-success' : 'text-muted'}">
|
<span class="detail-value ${hasResults ? 'text-success' : 'text-muted'}">
|
||||||
${hasResults ? (itemCount > 0 ? `找到 ${itemCount} 个相关知识项` : '找到相关知识项(数量未知)') : '未找到匹配的知识项'}
|
${hasResults ? (itemCount > 0 ? _t('retrievalLogs.foundCount', { count: itemCount }) : _t('retrievalLogs.foundUnknown')) : _t('retrievalLogs.noMatch')}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
${hasResults && log.retrievedItems && log.retrievedItems.length > 0 ? `
|
${hasResults && log.retrievedItems && log.retrievedItems.length > 0 ? `
|
||||||
<div class="retrieval-log-items-preview">
|
<div class="retrieval-log-items-preview">
|
||||||
<div class="retrieval-log-items-label">检索到的知识项:</div>
|
<div class="retrieval-log-items-label">${_t('retrievalLogs.retrievedItemsLabel')}</div>
|
||||||
<div class="retrieval-log-items-list">
|
<div class="retrieval-log-items-list">
|
||||||
${log.retrievedItems.slice(0, 3).map((itemId, idx) => `
|
${log.retrievedItems.slice(0, 3).map((itemId, idx) => `
|
||||||
<span class="retrieval-log-item-tag">${idx + 1}</span>
|
<span class="retrieval-log-item-tag">${idx + 1}</span>
|
||||||
@@ -1395,13 +1419,13 @@ function renderRetrievalLogs(logs) {
|
|||||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
<circle cx="12" cy="12" r="3" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
<circle cx="12" cy="12" r="3" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
</svg>
|
</svg>
|
||||||
查看详情
|
${_t('retrievalLogs.viewDetails')}
|
||||||
</button>
|
</button>
|
||||||
<button class="btn-secondary btn-sm retrieval-log-delete-btn" onclick="deleteRetrievalLog('${escapeHtml(log.id)}', ${index})" style="margin-top: 12px; margin-left: 8px; display: inline-flex; align-items: center; gap: 4px; color: var(--error-color, #dc3545); border-color: var(--error-color, #dc3545);" onmouseover="this.style.backgroundColor='rgba(220, 53, 69, 0.1)'; this.style.color='#dc3545';" onmouseout="this.style.backgroundColor=''; this.style.color='var(--error-color, #dc3545)';" title="删除">
|
<button class="btn-secondary btn-sm retrieval-log-delete-btn" onclick="deleteRetrievalLog('${escapeHtml(log.id)}', ${index})" style="margin-top: 12px; margin-left: 8px; display: inline-flex; align-items: center; gap: 4px; color: var(--error-color, #dc3545); border-color: var(--error-color, #dc3545);" onmouseover="this.style.backgroundColor='rgba(220, 53, 69, 0.1)'; this.style.color='#dc3545';" onmouseout="this.style.backgroundColor=''; this.style.color='var(--error-color, #dc3545)';" title="${_t('common.delete')}">
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
<path d="M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
</svg>
|
</svg>
|
||||||
删除
|
${_t('common.delete')}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1438,22 +1462,25 @@ function updateRetrievalStats(logs) {
|
|||||||
|
|
||||||
statsContainer.innerHTML = `
|
statsContainer.innerHTML = `
|
||||||
<div class="retrieval-stat-item">
|
<div class="retrieval-stat-item">
|
||||||
<span class="retrieval-stat-label">总检索次数</span>
|
<span class="retrieval-stat-label" data-i18n="retrievalLogs.totalRetrievals">总检索次数</span>
|
||||||
<span class="retrieval-stat-value">${totalLogs}</span>
|
<span class="retrieval-stat-value">${totalLogs}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="retrieval-stat-item">
|
<div class="retrieval-stat-item">
|
||||||
<span class="retrieval-stat-label">成功检索</span>
|
<span class="retrieval-stat-label" data-i18n="retrievalLogs.successRetrievals">成功检索</span>
|
||||||
<span class="retrieval-stat-value text-success">${successfulLogs}</span>
|
<span class="retrieval-stat-value text-success">${successfulLogs}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="retrieval-stat-item">
|
<div class="retrieval-stat-item">
|
||||||
<span class="retrieval-stat-label">成功率</span>
|
<span class="retrieval-stat-label" data-i18n="retrievalLogs.successRate">成功率</span>
|
||||||
<span class="retrieval-stat-value">${successRate}%</span>
|
<span class="retrieval-stat-value">${successRate}%</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="retrieval-stat-item">
|
<div class="retrieval-stat-item">
|
||||||
<span class="retrieval-stat-label">检索到知识项</span>
|
<span class="retrieval-stat-label" data-i18n="retrievalLogs.retrievedItems">检索到知识项</span>
|
||||||
<span class="retrieval-stat-value">${totalItems}</span>
|
<span class="retrieval-stat-value">${totalItems}</span>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
if (typeof window.applyTranslations === 'function') {
|
||||||
|
window.applyTranslations(statsContainer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取相对时间
|
// 获取相对时间
|
||||||
@@ -1549,7 +1576,7 @@ function refreshRetrievalLogs() {
|
|||||||
|
|
||||||
// 删除检索日志
|
// 删除检索日志
|
||||||
async function deleteRetrievalLog(id, index) {
|
async function deleteRetrievalLog(id, index) {
|
||||||
if (!confirm('确定要删除这条检索记录吗?')) {
|
if (!confirm(_t('retrievalLogs.deleteConfirm'))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1635,7 +1662,7 @@ async function deleteRetrievalLog(id, index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showNotification('❌ 删除检索日志失败: ' + error.message, 'error');
|
showNotification(_t('retrievalLogs.deleteError') + ': ' + error.message, 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1657,12 +1684,11 @@ function updateRetrievalStatsAfterDelete() {
|
|||||||
const badge = card.querySelector('.retrieval-log-result-badge');
|
const badge = card.querySelector('.retrieval-log-result-badge');
|
||||||
if (badge && badge.classList.contains('success')) {
|
if (badge && badge.classList.contains('success')) {
|
||||||
const text = badge.textContent.trim();
|
const text = badge.textContent.trim();
|
||||||
const match = text.match(/(\d+)\s*项/);
|
const match = text.match(/(\d+)/);
|
||||||
if (match) {
|
if (match) {
|
||||||
return sum + parseInt(match[1]);
|
return sum + parseInt(match[1], 10);
|
||||||
} else if (text === '有结果') {
|
|
||||||
return sum + 1; // 简化处理,假设为1
|
|
||||||
}
|
}
|
||||||
|
return sum + 1; // 有结果但数量未知(如 "Has results" / "有结果")
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}, 0);
|
}, 0);
|
||||||
@@ -1671,28 +1697,31 @@ function updateRetrievalStatsAfterDelete() {
|
|||||||
|
|
||||||
statsContainer.innerHTML = `
|
statsContainer.innerHTML = `
|
||||||
<div class="retrieval-stat-item">
|
<div class="retrieval-stat-item">
|
||||||
<span class="retrieval-stat-label">总检索次数</span>
|
<span class="retrieval-stat-label" data-i18n="retrievalLogs.totalRetrievals">总检索次数</span>
|
||||||
<span class="retrieval-stat-value">${totalLogs}</span>
|
<span class="retrieval-stat-value">${totalLogs}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="retrieval-stat-item">
|
<div class="retrieval-stat-item">
|
||||||
<span class="retrieval-stat-label">成功检索</span>
|
<span class="retrieval-stat-label" data-i18n="retrievalLogs.successRetrievals">成功检索</span>
|
||||||
<span class="retrieval-stat-value text-success">${successfulLogs}</span>
|
<span class="retrieval-stat-value text-success">${successfulLogs}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="retrieval-stat-item">
|
<div class="retrieval-stat-item">
|
||||||
<span class="retrieval-stat-label">成功率</span>
|
<span class="retrieval-stat-label" data-i18n="retrievalLogs.successRate">成功率</span>
|
||||||
<span class="retrieval-stat-value">${successRate}%</span>
|
<span class="retrieval-stat-value">${successRate}%</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="retrieval-stat-item">
|
<div class="retrieval-stat-item">
|
||||||
<span class="retrieval-stat-label">检索到知识项</span>
|
<span class="retrieval-stat-label" data-i18n="retrievalLogs.retrievedItems">检索到知识项</span>
|
||||||
<span class="retrieval-stat-value">${totalItems}</span>
|
<span class="retrieval-stat-value">${totalItems}</span>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
if (typeof window.applyTranslations === 'function') {
|
||||||
|
window.applyTranslations(statsContainer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示检索日志详情
|
// 显示检索日志详情
|
||||||
async function showRetrievalLogDetails(index) {
|
async function showRetrievalLogDetails(index) {
|
||||||
if (!retrievalLogsData || index < 0 || index >= retrievalLogsData.length) {
|
if (!retrievalLogsData || index < 0 || index >= retrievalLogsData.length) {
|
||||||
showNotification('无法获取检索详情', 'error');
|
showNotification(_t('retrievalLogs.detailError'), 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1741,16 +1770,19 @@ function showRetrievalLogDetailsModal(log, retrievedItems) {
|
|||||||
modal.innerHTML = `
|
modal.innerHTML = `
|
||||||
<div class="modal-content" style="max-width: 900px; max-height: 90vh; overflow-y: auto;">
|
<div class="modal-content" style="max-width: 900px; max-height: 90vh; overflow-y: auto;">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h2>检索详情</h2>
|
<h2 data-i18n="retrievalLogs.detailsTitle">检索详情</h2>
|
||||||
<span class="modal-close" onclick="closeRetrievalLogDetailsModal()">×</span>
|
<span class="modal-close" onclick="closeRetrievalLogDetailsModal()">×</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body" id="retrieval-log-details-content">
|
<div class="modal-body" id="retrieval-log-details-content">
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button class="btn-secondary" onclick="closeRetrievalLogDetailsModal()">关闭</button>
|
<button class="btn-secondary" onclick="closeRetrievalLogDetailsModal()" data-i18n="common.close">关闭</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
if (typeof window.applyTranslations === 'function') {
|
||||||
|
window.applyTranslations(modal);
|
||||||
|
}
|
||||||
document.body.appendChild(modal);
|
document.body.appendChild(modal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1774,57 +1806,57 @@ function showRetrievalLogDetailsModal(log, retrievedItems) {
|
|||||||
return `
|
return `
|
||||||
<div class="retrieval-detail-item-card" style="margin-bottom: 16px; padding: 16px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-secondary);">
|
<div class="retrieval-detail-item-card" style="margin-bottom: 16px; padding: 16px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-secondary);">
|
||||||
<div style="display: flex; justify-content: space-between; align-items: start; margin-bottom: 8px;">
|
<div style="display: flex; justify-content: space-between; align-items: start; margin-bottom: 8px;">
|
||||||
<h4 style="margin: 0; color: var(--text-primary);">${idx + 1}. ${escapeHtml(item.title || '未命名')}</h4>
|
<h4 style="margin: 0; color: var(--text-primary);">${idx + 1}. ${escapeHtml(item.title || _t('retrievalLogs.untitled'))}</h4>
|
||||||
<span style="font-size: 0.875rem; color: var(--text-secondary);">${escapeHtml(item.category || '未分类')}</span>
|
<span style="font-size: 0.875rem; color: var(--text-secondary);">${escapeHtml(item.category || _t('retrievalLogs.uncategorized'))}</span>
|
||||||
</div>
|
</div>
|
||||||
${item.filePath ? `<div style="font-size: 0.875rem; color: var(--text-muted); margin-bottom: 8px;">📁 ${escapeHtml(item.filePath)}</div>` : ''}
|
${item.filePath ? `<div style="font-size: 0.875rem; color: var(--text-muted); margin-bottom: 8px;">📁 ${escapeHtml(item.filePath)}</div>` : ''}
|
||||||
<div style="font-size: 0.875rem; color: var(--text-secondary); line-height: 1.6;">
|
<div style="font-size: 0.875rem; color: var(--text-secondary); line-height: 1.6;">
|
||||||
${escapeHtml(previewText || '无内容预览')}
|
${escapeHtml(previewText || _t('retrievalLogs.noContentPreview'))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}).join('');
|
}).join('');
|
||||||
} else {
|
} else {
|
||||||
itemsHtml = '<div style="padding: 16px; text-align: center; color: var(--text-muted);">未找到知识项详情</div>';
|
itemsHtml = '<div style="padding: 16px; text-align: center; color: var(--text-muted);">' + _t('retrievalLogs.noItemDetails') + '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
content.innerHTML = `
|
content.innerHTML = `
|
||||||
<div style="display: flex; flex-direction: column; gap: 20px;">
|
<div style="display: flex; flex-direction: column; gap: 20px;">
|
||||||
<div class="retrieval-detail-section">
|
<div class="retrieval-detail-section">
|
||||||
<h3 style="margin: 0 0 12px 0; font-size: 1.125rem; color: var(--text-primary);">查询信息</h3>
|
<h3 style="margin: 0 0 12px 0; font-size: 1.125rem; color: var(--text-primary);">${_t('retrievalLogs.queryInfo')}</h3>
|
||||||
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px; border-left: 3px solid var(--accent-color);">
|
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px; border-left: 3px solid var(--accent-color);">
|
||||||
<div style="font-weight: 500; margin-bottom: 8px; color: var(--text-primary);">查询内容:</div>
|
<div style="font-weight: 500; margin-bottom: 8px; color: var(--text-primary);">${_t('retrievalLogs.queryContent')}</div>
|
||||||
<div style="color: var(--text-primary); line-height: 1.6; word-break: break-word;">${escapeHtml(log.query || '无查询内容')}</div>
|
<div style="color: var(--text-primary); line-height: 1.6; word-break: break-word;">${escapeHtml(log.query || _t('retrievalLogs.noQuery'))}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="retrieval-detail-section">
|
<div class="retrieval-detail-section">
|
||||||
<h3 style="margin: 0 0 12px 0; font-size: 1.125rem; color: var(--text-primary);">检索信息</h3>
|
<h3 style="margin: 0 0 12px 0; font-size: 1.125rem; color: var(--text-primary);">${_t('retrievalLogs.retrievalInfo')}</h3>
|
||||||
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px;">
|
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px;">
|
||||||
${log.riskType ? `
|
${log.riskType ? `
|
||||||
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px;">
|
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px;">
|
||||||
<div style="font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 4px;">风险类型</div>
|
<div style="font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 4px;">${_t('retrievalLogs.riskType')}</div>
|
||||||
<div style="font-weight: 500; color: var(--text-primary);">${escapeHtml(log.riskType)}</div>
|
<div style="font-weight: 500; color: var(--text-primary);">${escapeHtml(log.riskType)}</div>
|
||||||
</div>
|
</div>
|
||||||
` : ''}
|
` : ''}
|
||||||
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px;">
|
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px;">
|
||||||
<div style="font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 4px;">检索时间</div>
|
<div style="font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 4px;">${_t('retrievalLogs.retrievalTime')}</div>
|
||||||
<div style="font-weight: 500; color: var(--text-primary);" title="${fullTime}">${timeAgo}</div>
|
<div style="font-weight: 500; color: var(--text-primary);" title="${fullTime}">${timeAgo}</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px;">
|
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px;">
|
||||||
<div style="font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 4px;">检索结果</div>
|
<div style="font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 4px;">${_t('retrievalLogs.retrievalResult')}</div>
|
||||||
<div style="font-weight: 500; color: var(--text-primary);">${retrievedItems.length} 个知识项</div>
|
<div style="font-weight: 500; color: var(--text-primary);">${_t('retrievalLogs.itemsCount', { count: retrievedItems.length })}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
${log.conversationId || log.messageId ? `
|
${log.conversationId || log.messageId ? `
|
||||||
<div class="retrieval-detail-section">
|
<div class="retrieval-detail-section">
|
||||||
<h3 style="margin: 0 0 12px 0; font-size: 1.125rem; color: var(--text-primary);">关联信息</h3>
|
<h3 style="margin: 0 0 12px 0; font-size: 1.125rem; color: var(--text-primary);">${_t('retrievalLogs.relatedInfo')}</h3>
|
||||||
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px;">
|
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px;">
|
||||||
${log.conversationId ? `
|
${log.conversationId ? `
|
||||||
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px;">
|
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px;">
|
||||||
<div style="font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 4px;">对话ID</div>
|
<div style="font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 4px;">${_t('retrievalLogs.conversationId')}</div>
|
||||||
<code style="font-size: 0.8125rem; color: var(--text-primary); word-break: break-all; cursor: pointer;"
|
<code style="font-size: 0.8125rem; color: var(--text-primary); word-break: break-all; cursor: pointer;"
|
||||||
onclick="navigator.clipboard.writeText('${escapeHtml(log.conversationId)}'); this.title='已复制!'; setTimeout(() => this.title='点击复制', 2000);"
|
onclick="navigator.clipboard.writeText('${escapeHtml(log.conversationId)}'); this.title='已复制!'; setTimeout(() => this.title='点击复制', 2000);"
|
||||||
title="点击复制">${escapeHtml(log.conversationId)}</code>
|
title="点击复制">${escapeHtml(log.conversationId)}</code>
|
||||||
@@ -1832,7 +1864,7 @@ function showRetrievalLogDetailsModal(log, retrievedItems) {
|
|||||||
` : ''}
|
` : ''}
|
||||||
${log.messageId ? `
|
${log.messageId ? `
|
||||||
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px;">
|
<div style="padding: 12px; background: var(--bg-secondary); border-radius: 6px;">
|
||||||
<div style="font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 4px;">消息ID</div>
|
<div style="font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 4px;">${_t('retrievalLogs.messageId')}</div>
|
||||||
<code style="font-size: 0.8125rem; color: var(--text-primary); word-break: break-all; cursor: pointer;"
|
<code style="font-size: 0.8125rem; color: var(--text-primary); word-break: break-all; cursor: pointer;"
|
||||||
onclick="navigator.clipboard.writeText('${escapeHtml(log.messageId)}'); this.title='已复制!'; setTimeout(() => this.title='点击复制', 2000);"
|
onclick="navigator.clipboard.writeText('${escapeHtml(log.messageId)}'); this.title='已复制!'; setTimeout(() => this.title='点击复制', 2000);"
|
||||||
title="点击复制">${escapeHtml(log.messageId)}</code>
|
title="点击复制">${escapeHtml(log.messageId)}</code>
|
||||||
@@ -1868,6 +1900,22 @@ window.addEventListener('click', function(event) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 语言切换时重新渲染检索历史列表与统计,使动态内容随语言更新;知识管理页的「未启用」区块已使用 data-i18n,会由 applyTranslations(document) 自动更新
|
||||||
|
document.addEventListener('languagechange', function () {
|
||||||
|
var cur = typeof window.currentPage === 'function' ? window.currentPage() : (window.currentPage || '');
|
||||||
|
if (cur === 'knowledge-retrieval-logs') {
|
||||||
|
if (retrievalLogsData && retrievalLogsData.length >= 0) {
|
||||||
|
renderRetrievalLogs(retrievalLogsData);
|
||||||
|
}
|
||||||
|
} else if (cur === 'knowledge-management') {
|
||||||
|
// 仅对「知识库未启用」状态:已有 data-i18n,applyTranslations 已处理;此处可选地重新应用一次以兼容旧 DOM
|
||||||
|
var listEl = document.getElementById('knowledge-items-list');
|
||||||
|
if (listEl && typeof window.applyTranslations === 'function') {
|
||||||
|
window.applyTranslations(listEl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 页面切换时加载数据
|
// 页面切换时加载数据
|
||||||
if (typeof switchPage === 'function') {
|
if (typeof switchPage === 'function') {
|
||||||
const originalSwitchPage = switchPage;
|
const originalSwitchPage = switchPage;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+102
-57
@@ -1138,10 +1138,10 @@ async function refreshMonitorPanel(page = null) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('刷新监控面板失败:', error);
|
console.error('刷新监控面板失败:', error);
|
||||||
if (statsContainer) {
|
if (statsContainer) {
|
||||||
statsContainer.innerHTML = `<div class="monitor-error">无法加载统计信息:${escapeHtml(error.message)}</div>`;
|
statsContainer.innerHTML = `<div class="monitor-error">${escapeHtml(typeof window.t === 'function' ? window.t('mcpMonitor.loadStatsError') : '无法加载统计信息')}:${escapeHtml(error.message)}</div>`;
|
||||||
}
|
}
|
||||||
if (execContainer) {
|
if (execContainer) {
|
||||||
execContainer.innerHTML = `<div class="monitor-error">无法加载执行记录:${escapeHtml(error.message)}</div>`;
|
execContainer.innerHTML = `<div class="monitor-error">${escapeHtml(typeof window.t === 'function' ? window.t('mcpMonitor.loadExecutionsError') : '无法加载执行记录')}:${escapeHtml(error.message)}</div>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1215,10 +1215,10 @@ async function refreshMonitorPanelWithFilter(statusFilter = 'all', toolFilter =
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('刷新监控面板失败:', error);
|
console.error('刷新监控面板失败:', error);
|
||||||
if (statsContainer) {
|
if (statsContainer) {
|
||||||
statsContainer.innerHTML = `<div class="monitor-error">无法加载统计信息:${escapeHtml(error.message)}</div>`;
|
statsContainer.innerHTML = `<div class="monitor-error">${escapeHtml(typeof window.t === 'function' ? window.t('mcpMonitor.loadStatsError') : '无法加载统计信息')}:${escapeHtml(error.message)}</div>`;
|
||||||
}
|
}
|
||||||
if (execContainer) {
|
if (execContainer) {
|
||||||
execContainer.innerHTML = `<div class="monitor-error">无法加载执行记录:${escapeHtml(error.message)}</div>`;
|
execContainer.innerHTML = `<div class="monitor-error">${escapeHtml(typeof window.t === 'function' ? window.t('mcpMonitor.loadExecutionsError') : '无法加载执行记录')}:${escapeHtml(error.message)}</div>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1232,7 +1232,8 @@ function renderMonitorStats(statsMap = {}, lastFetchedAt = null) {
|
|||||||
|
|
||||||
const entries = Object.values(statsMap);
|
const entries = Object.values(statsMap);
|
||||||
if (entries.length === 0) {
|
if (entries.length === 0) {
|
||||||
container.innerHTML = '<div class="monitor-empty">暂无统计数据</div>';
|
const noStats = typeof window.t === 'function' ? window.t('mcpMonitor.noStatsData') : '暂无统计数据';
|
||||||
|
container.innerHTML = '<div class="monitor-empty">' + escapeHtml(noStats) + '</div>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1252,24 +1253,32 @@ function renderMonitorStats(statsMap = {}, lastFetchedAt = null) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const successRate = totals.total > 0 ? ((totals.success / totals.total) * 100).toFixed(1) : '0.0';
|
const successRate = totals.total > 0 ? ((totals.success / totals.total) * 100).toFixed(1) : '0.0';
|
||||||
const lastUpdatedText = lastFetchedAt ? lastFetchedAt.toLocaleString('zh-CN') : 'N/A';
|
const locale = (typeof window.__locale === 'string' && window.__locale.startsWith('zh')) ? 'zh-CN' : undefined;
|
||||||
const lastCallText = totals.lastCallTime ? totals.lastCallTime.toLocaleString('zh-CN') : '暂无调用';
|
const lastUpdatedText = lastFetchedAt ? (lastFetchedAt.toLocaleString ? lastFetchedAt.toLocaleString(locale || 'en-US') : String(lastFetchedAt)) : 'N/A';
|
||||||
|
const noCallsYet = typeof window.t === 'function' ? window.t('mcpMonitor.noCallsYet') : '暂无调用';
|
||||||
|
const lastCallText = totals.lastCallTime ? (totals.lastCallTime.toLocaleString ? totals.lastCallTime.toLocaleString(locale || 'en-US') : String(totals.lastCallTime)) : noCallsYet;
|
||||||
|
const totalCallsLabel = typeof window.t === 'function' ? window.t('mcpMonitor.totalCalls') : '总调用次数';
|
||||||
|
const successFailedLabel = typeof window.t === 'function' ? window.t('mcpMonitor.successFailed', { success: totals.success, failed: totals.failed }) : `成功 ${totals.success} / 失败 ${totals.failed}`;
|
||||||
|
const successRateLabel = typeof window.t === 'function' ? window.t('mcpMonitor.successRate') : '成功率';
|
||||||
|
const statsFromAll = typeof window.t === 'function' ? window.t('mcpMonitor.statsFromAllTools') : '统计自全部工具调用';
|
||||||
|
const lastCallLabel = typeof window.t === 'function' ? window.t('mcpMonitor.lastCall') : '最近一次调用';
|
||||||
|
const lastRefreshLabel = typeof window.t === 'function' ? window.t('mcpMonitor.lastRefreshTime') : '最后刷新时间';
|
||||||
|
|
||||||
let html = `
|
let html = `
|
||||||
<div class="monitor-stat-card">
|
<div class="monitor-stat-card">
|
||||||
<h4>总调用次数</h4>
|
<h4>${escapeHtml(totalCallsLabel)}</h4>
|
||||||
<div class="monitor-stat-value">${totals.total}</div>
|
<div class="monitor-stat-value">${totals.total}</div>
|
||||||
<div class="monitor-stat-meta">成功 ${totals.success} / 失败 ${totals.failed}</div>
|
<div class="monitor-stat-meta">${escapeHtml(successFailedLabel)}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="monitor-stat-card">
|
<div class="monitor-stat-card">
|
||||||
<h4>成功率</h4>
|
<h4>${escapeHtml(successRateLabel)}</h4>
|
||||||
<div class="monitor-stat-value">${successRate}%</div>
|
<div class="monitor-stat-value">${successRate}%</div>
|
||||||
<div class="monitor-stat-meta">统计自全部工具调用</div>
|
<div class="monitor-stat-meta">${escapeHtml(statsFromAll)}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="monitor-stat-card">
|
<div class="monitor-stat-card">
|
||||||
<h4>最近一次调用</h4>
|
<h4>${escapeHtml(lastCallLabel)}</h4>
|
||||||
<div class="monitor-stat-value" style="font-size:1rem;">${lastCallText}</div>
|
<div class="monitor-stat-value" style="font-size:1rem;">${escapeHtml(lastCallText)}</div>
|
||||||
<div class="monitor-stat-meta">最后刷新时间:${lastUpdatedText}</div>
|
<div class="monitor-stat-meta">${escapeHtml(lastRefreshLabel)}:${escapeHtml(lastUpdatedText)}</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -1280,14 +1289,16 @@ function renderMonitorStats(statsMap = {}, lastFetchedAt = null) {
|
|||||||
.sort((a, b) => (b.totalCalls || 0) - (a.totalCalls || 0))
|
.sort((a, b) => (b.totalCalls || 0) - (a.totalCalls || 0))
|
||||||
.slice(0, 4);
|
.slice(0, 4);
|
||||||
|
|
||||||
|
const unknownToolLabel = typeof window.t === 'function' ? window.t('mcpMonitor.unknownTool') : '未知工具';
|
||||||
topTools.forEach(tool => {
|
topTools.forEach(tool => {
|
||||||
const toolSuccessRate = tool.totalCalls > 0 ? ((tool.successCalls || 0) / tool.totalCalls * 100).toFixed(1) : '0.0';
|
const toolSuccessRate = tool.totalCalls > 0 ? ((tool.successCalls || 0) / tool.totalCalls * 100).toFixed(1) : '0.0';
|
||||||
|
const toolMeta = typeof window.t === 'function' ? window.t('mcpMonitor.successFailedRate', { success: tool.successCalls || 0, failed: tool.failedCalls || 0, rate: toolSuccessRate }) : `成功 ${tool.successCalls || 0} / 失败 ${tool.failedCalls || 0} · 成功率 ${toolSuccessRate}%`;
|
||||||
html += `
|
html += `
|
||||||
<div class="monitor-stat-card">
|
<div class="monitor-stat-card">
|
||||||
<h4>${escapeHtml(tool.toolName || '未知工具')}</h4>
|
<h4>${escapeHtml(tool.toolName || unknownToolLabel)}</h4>
|
||||||
<div class="monitor-stat-value">${tool.totalCalls || 0}</div>
|
<div class="monitor-stat-value">${tool.totalCalls || 0}</div>
|
||||||
<div class="monitor-stat-meta">
|
<div class="monitor-stat-meta">
|
||||||
成功 ${tool.successCalls || 0} / 失败 ${tool.failedCalls || 0} · 成功率 ${toolSuccessRate}%
|
${escapeHtml(toolMeta)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@@ -1307,10 +1318,12 @@ function renderMonitorExecutions(executions = [], statusFilter = 'all') {
|
|||||||
const toolFilter = document.getElementById('monitor-tool-filter');
|
const toolFilter = document.getElementById('monitor-tool-filter');
|
||||||
const currentToolFilter = toolFilter ? toolFilter.value : 'all';
|
const currentToolFilter = toolFilter ? toolFilter.value : 'all';
|
||||||
const hasFilter = (statusFilter && statusFilter !== 'all') || (currentToolFilter && currentToolFilter !== 'all');
|
const hasFilter = (statusFilter && statusFilter !== 'all') || (currentToolFilter && currentToolFilter !== 'all');
|
||||||
|
const noRecordsFilter = typeof window.t === 'function' ? window.t('mcpMonitor.noRecordsWithFilter') : '当前筛选条件下暂无记录';
|
||||||
|
const noExecutions = typeof window.t === 'function' ? window.t('mcpMonitor.noExecutions') : '暂无执行记录';
|
||||||
if (hasFilter) {
|
if (hasFilter) {
|
||||||
container.innerHTML = '<div class="monitor-empty">当前筛选条件下暂无记录</div>';
|
container.innerHTML = '<div class="monitor-empty">' + escapeHtml(noRecordsFilter) + '</div>';
|
||||||
} else {
|
} else {
|
||||||
container.innerHTML = '<div class="monitor-empty">暂无执行记录</div>';
|
container.innerHTML = '<div class="monitor-empty">' + escapeHtml(noExecutions) + '</div>';
|
||||||
}
|
}
|
||||||
// 隐藏批量操作栏
|
// 隐藏批量操作栏
|
||||||
const batchActions = document.getElementById('monitor-batch-actions');
|
const batchActions = document.getElementById('monitor-batch-actions');
|
||||||
@@ -1322,14 +1335,22 @@ function renderMonitorExecutions(executions = [], statusFilter = 'all') {
|
|||||||
|
|
||||||
// 由于筛选已经在后端完成,这里直接使用所有传入的执行记录
|
// 由于筛选已经在后端完成,这里直接使用所有传入的执行记录
|
||||||
// 不再需要前端再次筛选,因为后端已经返回了筛选后的数据
|
// 不再需要前端再次筛选,因为后端已经返回了筛选后的数据
|
||||||
|
const unknownLabel = typeof window.t === 'function' ? window.t('mcpMonitor.unknown') : '未知';
|
||||||
|
const unknownToolLabel = typeof window.t === 'function' ? window.t('mcpMonitor.unknownTool') : '未知工具';
|
||||||
|
const viewDetailLabel = typeof window.t === 'function' ? window.t('mcpMonitor.viewDetail') : '查看详情';
|
||||||
|
const deleteLabel = typeof window.t === 'function' ? window.t('mcpMonitor.delete') : '删除';
|
||||||
|
const deleteExecTitle = typeof window.t === 'function' ? window.t('mcpMonitor.deleteExecTitle') : '删除此执行记录';
|
||||||
|
const statusKeyMap = { pending: 'statusPending', running: 'statusRunning', completed: 'statusCompleted', failed: 'statusFailed' };
|
||||||
|
const locale = (typeof window.__locale === 'string' && window.__locale.startsWith('zh')) ? 'zh-CN' : undefined;
|
||||||
const rows = executions
|
const rows = executions
|
||||||
.map(exec => {
|
.map(exec => {
|
||||||
const status = (exec.status || 'unknown').toLowerCase();
|
const status = (exec.status || 'unknown').toLowerCase();
|
||||||
const statusClass = `monitor-status-chip ${status}`;
|
const statusClass = `monitor-status-chip ${status}`;
|
||||||
const statusLabel = getStatusText(status);
|
const statusKey = statusKeyMap[status];
|
||||||
const startTime = exec.startTime ? new Date(exec.startTime).toLocaleString('zh-CN') : '未知';
|
const statusLabel = (typeof window.t === 'function' && statusKey) ? window.t('mcpMonitor.' + statusKey) : getStatusText(status);
|
||||||
|
const startTime = exec.startTime ? (new Date(exec.startTime).toLocaleString ? new Date(exec.startTime).toLocaleString(locale || 'en-US') : String(exec.startTime)) : unknownLabel;
|
||||||
const duration = formatExecutionDuration(exec.startTime, exec.endTime);
|
const duration = formatExecutionDuration(exec.startTime, exec.endTime);
|
||||||
const toolName = escapeHtml(exec.toolName || '未知工具');
|
const toolName = escapeHtml(exec.toolName || unknownToolLabel);
|
||||||
const executionId = escapeHtml(exec.id || '');
|
const executionId = escapeHtml(exec.id || '');
|
||||||
return `
|
return `
|
||||||
<tr>
|
<tr>
|
||||||
@@ -1337,13 +1358,13 @@ function renderMonitorExecutions(executions = [], statusFilter = 'all') {
|
|||||||
<input type="checkbox" class="monitor-execution-checkbox" value="${executionId}" onchange="updateBatchActionsState()" />
|
<input type="checkbox" class="monitor-execution-checkbox" value="${executionId}" onchange="updateBatchActionsState()" />
|
||||||
</td>
|
</td>
|
||||||
<td>${toolName}</td>
|
<td>${toolName}</td>
|
||||||
<td><span class="${statusClass}">${statusLabel}</span></td>
|
<td><span class="${statusClass}">${escapeHtml(statusLabel)}</span></td>
|
||||||
<td>${startTime}</td>
|
<td>${escapeHtml(startTime)}</td>
|
||||||
<td>${duration}</td>
|
<td>${escapeHtml(duration)}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="monitor-execution-actions">
|
<div class="monitor-execution-actions">
|
||||||
<button class="btn-secondary" onclick="showMCPDetail('${executionId}')">查看详情</button>
|
<button class="btn-secondary" onclick="showMCPDetail('${executionId}')">${escapeHtml(viewDetailLabel)}</button>
|
||||||
<button class="btn-secondary btn-delete" onclick="deleteExecution('${executionId}')" title="删除此执行记录">删除</button>
|
<button class="btn-secondary btn-delete" onclick="deleteExecution('${executionId}')" title="${escapeHtml(deleteExecTitle)}">${escapeHtml(deleteLabel)}</button>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -1365,6 +1386,11 @@ function renderMonitorExecutions(executions = [], statusFilter = 'all') {
|
|||||||
// 创建表格容器
|
// 创建表格容器
|
||||||
const tableContainer = document.createElement('div');
|
const tableContainer = document.createElement('div');
|
||||||
tableContainer.className = 'monitor-table-container';
|
tableContainer.className = 'monitor-table-container';
|
||||||
|
const colTool = typeof window.t === 'function' ? window.t('mcpMonitor.columnTool') : '工具';
|
||||||
|
const colStatus = typeof window.t === 'function' ? window.t('mcpMonitor.columnStatus') : '状态';
|
||||||
|
const colStartTime = typeof window.t === 'function' ? window.t('mcpMonitor.columnStartTime') : '开始时间';
|
||||||
|
const colDuration = typeof window.t === 'function' ? window.t('mcpMonitor.columnDuration') : '耗时';
|
||||||
|
const colActions = typeof window.t === 'function' ? window.t('mcpMonitor.columnActions') : '操作';
|
||||||
tableContainer.innerHTML = `
|
tableContainer.innerHTML = `
|
||||||
<table class="monitor-table">
|
<table class="monitor-table">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -1372,11 +1398,11 @@ function renderMonitorExecutions(executions = [], statusFilter = 'all') {
|
|||||||
<th style="width: 40px;">
|
<th style="width: 40px;">
|
||||||
<input type="checkbox" id="monitor-select-all" onchange="toggleSelectAll(this)" />
|
<input type="checkbox" id="monitor-select-all" onchange="toggleSelectAll(this)" />
|
||||||
</th>
|
</th>
|
||||||
<th>工具</th>
|
<th>${escapeHtml(colTool)}</th>
|
||||||
<th>状态</th>
|
<th>${escapeHtml(colStatus)}</th>
|
||||||
<th>开始时间</th>
|
<th>${escapeHtml(colStartTime)}</th>
|
||||||
<th>耗时</th>
|
<th>${escapeHtml(colDuration)}</th>
|
||||||
<th>操作</th>
|
<th>${escapeHtml(colActions)}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>${rows}</tbody>
|
<tbody>${rows}</tbody>
|
||||||
@@ -1415,12 +1441,18 @@ function renderMonitorPagination() {
|
|||||||
// 处理没有数据的情况
|
// 处理没有数据的情况
|
||||||
const startItem = total === 0 ? 0 : (page - 1) * pageSize + 1;
|
const startItem = total === 0 ? 0 : (page - 1) * pageSize + 1;
|
||||||
const endItem = total === 0 ? 0 : Math.min(page * pageSize, total);
|
const endItem = total === 0 ? 0 : Math.min(page * pageSize, total);
|
||||||
|
const paginationInfoText = typeof window.t === 'function' ? window.t('mcpMonitor.paginationInfo', { start: startItem, end: endItem, total: total }) : `显示 ${startItem}-${endItem} / 共 ${total} 条记录`;
|
||||||
|
const perPageLabel = typeof window.t === 'function' ? window.t('mcpMonitor.perPageLabel') : '每页显示';
|
||||||
|
const firstPageLabel = typeof window.t === 'function' ? window.t('mcp.firstPage') : '首页';
|
||||||
|
const prevPageLabel = typeof window.t === 'function' ? window.t('mcp.prevPage') : '上一页';
|
||||||
|
const pageInfoText = typeof window.t === 'function' ? window.t('mcp.pageInfo', { page: page, total: totalPages || 1 }) : `第 ${page} / ${totalPages || 1} 页`;
|
||||||
|
const nextPageLabel = typeof window.t === 'function' ? window.t('mcp.nextPage') : '下一页';
|
||||||
|
const lastPageLabel = typeof window.t === 'function' ? window.t('mcp.lastPage') : '末页';
|
||||||
pagination.innerHTML = `
|
pagination.innerHTML = `
|
||||||
<div class="pagination-info">
|
<div class="pagination-info">
|
||||||
<span>显示 ${startItem}-${endItem} / 共 ${total} 条记录</span>
|
<span>${escapeHtml(paginationInfoText)}</span>
|
||||||
<label class="pagination-page-size">
|
<label class="pagination-page-size">
|
||||||
每页显示
|
${escapeHtml(perPageLabel)}
|
||||||
<select id="monitor-page-size" onchange="changeMonitorPageSize()">
|
<select id="monitor-page-size" onchange="changeMonitorPageSize()">
|
||||||
<option value="10" ${pageSize === 10 ? 'selected' : ''}>10</option>
|
<option value="10" ${pageSize === 10 ? 'selected' : ''}>10</option>
|
||||||
<option value="20" ${pageSize === 20 ? 'selected' : ''}>20</option>
|
<option value="20" ${pageSize === 20 ? 'selected' : ''}>20</option>
|
||||||
@@ -1430,11 +1462,11 @@ function renderMonitorPagination() {
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="pagination-controls">
|
<div class="pagination-controls">
|
||||||
<button class="btn-secondary" onclick="refreshMonitorPanel(1)" ${page === 1 || total === 0 ? 'disabled' : ''}>首页</button>
|
<button class="btn-secondary" onclick="refreshMonitorPanel(1)" ${page === 1 || total === 0 ? 'disabled' : ''}>${escapeHtml(firstPageLabel)}</button>
|
||||||
<button class="btn-secondary" onclick="refreshMonitorPanel(${page - 1})" ${page === 1 || total === 0 ? 'disabled' : ''}>上一页</button>
|
<button class="btn-secondary" onclick="refreshMonitorPanel(${page - 1})" ${page === 1 || total === 0 ? 'disabled' : ''}>${escapeHtml(prevPageLabel)}</button>
|
||||||
<span class="pagination-page">第 ${page} / ${totalPages || 1} 页</span>
|
<span class="pagination-page">${escapeHtml(pageInfoText)}</span>
|
||||||
<button class="btn-secondary" onclick="refreshMonitorPanel(${page + 1})" ${page >= totalPages || total === 0 ? 'disabled' : ''}>下一页</button>
|
<button class="btn-secondary" onclick="refreshMonitorPanel(${page + 1})" ${page >= totalPages || total === 0 ? 'disabled' : ''}>${escapeHtml(nextPageLabel)}</button>
|
||||||
<button class="btn-secondary" onclick="refreshMonitorPanel(${totalPages || 1})" ${page >= totalPages || total === 0 ? 'disabled' : ''}>末页</button>
|
<button class="btn-secondary" onclick="refreshMonitorPanel(${totalPages || 1})" ${page >= totalPages || total === 0 ? 'disabled' : ''}>${escapeHtml(lastPageLabel)}</button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -1450,8 +1482,8 @@ async function deleteExecution(executionId) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确认删除
|
const deleteConfirmMsg = typeof window.t === 'function' ? window.t('mcpMonitor.deleteExecConfirmSingle') : '确定要删除此执行记录吗?此操作不可恢复。';
|
||||||
if (!confirm('确定要删除此执行记录吗?此操作不可恢复。')) {
|
if (!confirm(deleteConfirmMsg)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1462,17 +1494,20 @@ async function deleteExecution(executionId) {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const error = await response.json().catch(() => ({}));
|
const error = await response.json().catch(() => ({}));
|
||||||
throw new Error(error.error || '删除执行记录失败');
|
const deleteFailedMsg = typeof window.t === 'function' ? window.t('mcpMonitor.deleteExecFailed') : '删除执行记录失败';
|
||||||
|
throw new Error(error.error || deleteFailedMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除成功后刷新当前页面
|
// 删除成功后刷新当前页面
|
||||||
const currentPage = monitorState.pagination.page;
|
const currentPage = monitorState.pagination.page;
|
||||||
await refreshMonitorPanel(currentPage);
|
await refreshMonitorPanel(currentPage);
|
||||||
|
|
||||||
alert('执行记录已删除');
|
const execDeletedMsg = typeof window.t === 'function' ? window.t('mcpMonitor.execDeleted') : '执行记录已删除';
|
||||||
|
alert(execDeletedMsg);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('删除执行记录失败:', error);
|
console.error('删除执行记录失败:', error);
|
||||||
alert('删除执行记录失败: ' + error.message);
|
const deleteFailedMsg = typeof window.t === 'function' ? window.t('mcpMonitor.deleteExecFailed') : '删除执行记录失败';
|
||||||
|
alert(deleteFailedMsg + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1488,7 +1523,7 @@ function updateBatchActionsState() {
|
|||||||
batchActions.style.display = 'flex';
|
batchActions.style.display = 'flex';
|
||||||
}
|
}
|
||||||
if (selectedCountSpan) {
|
if (selectedCountSpan) {
|
||||||
selectedCountSpan.textContent = `已选择 ${selectedCount} 项`;
|
selectedCountSpan.textContent = typeof window.t === 'function' ? window.t('mcp.selectedCount', { count: selectedCount }) : `已选择 ${selectedCount} 项`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (batchActions) {
|
if (batchActions) {
|
||||||
@@ -1547,15 +1582,15 @@ function deselectAllExecutions() {
|
|||||||
async function batchDeleteExecutions() {
|
async function batchDeleteExecutions() {
|
||||||
const checkboxes = document.querySelectorAll('.monitor-execution-checkbox:checked');
|
const checkboxes = document.querySelectorAll('.monitor-execution-checkbox:checked');
|
||||||
if (checkboxes.length === 0) {
|
if (checkboxes.length === 0) {
|
||||||
alert('请先选择要删除的执行记录');
|
const selectFirstMsg = typeof window.t === 'function' ? window.t('mcpMonitor.selectExecFirst') : '请先选择要删除的执行记录';
|
||||||
|
alert(selectFirstMsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ids = Array.from(checkboxes).map(cb => cb.value);
|
const ids = Array.from(checkboxes).map(cb => cb.value);
|
||||||
const count = ids.length;
|
const count = ids.length;
|
||||||
|
const batchConfirmMsg = typeof window.t === 'function' ? window.t('mcpMonitor.batchDeleteConfirm', { count: count }) : `确定要删除选中的 ${count} 条执行记录吗?此操作不可恢复。`;
|
||||||
// 确认删除
|
if (!confirm(batchConfirmMsg)) {
|
||||||
if (!confirm(`确定要删除选中的 ${count} 条执行记录吗?此操作不可恢复。`)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1570,7 +1605,8 @@ async function batchDeleteExecutions() {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const error = await response.json().catch(() => ({}));
|
const error = await response.json().catch(() => ({}));
|
||||||
throw new Error(error.error || '批量删除执行记录失败');
|
const batchFailedMsg = typeof window.t === 'function' ? window.t('mcp.batchDeleteFailed') : '批量删除执行记录失败';
|
||||||
|
throw new Error(error.error || batchFailedMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
@@ -1580,33 +1616,42 @@ async function batchDeleteExecutions() {
|
|||||||
const currentPage = monitorState.pagination.page;
|
const currentPage = monitorState.pagination.page;
|
||||||
await refreshMonitorPanel(currentPage);
|
await refreshMonitorPanel(currentPage);
|
||||||
|
|
||||||
alert(`成功删除 ${deletedCount} 条执行记录`);
|
const batchSuccessMsg = typeof window.t === 'function' ? window.t('mcpMonitor.batchDeleteSuccess', { count: deletedCount }) : `成功删除 ${deletedCount} 条执行记录`;
|
||||||
|
alert(batchSuccessMsg);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('批量删除执行记录失败:', error);
|
console.error('批量删除执行记录失败:', error);
|
||||||
alert('批量删除执行记录失败: ' + error.message);
|
const batchFailedMsg = typeof window.t === 'function' ? window.t('mcp.batchDeleteFailed') : '批量删除执行记录失败';
|
||||||
|
alert(batchFailedMsg + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatExecutionDuration(start, end) {
|
function formatExecutionDuration(start, end) {
|
||||||
|
const unknownLabel = typeof window.t === 'function' ? window.t('mcpMonitor.unknown') : '未知';
|
||||||
if (!start) {
|
if (!start) {
|
||||||
return '未知';
|
return unknownLabel;
|
||||||
}
|
}
|
||||||
const startTime = new Date(start);
|
const startTime = new Date(start);
|
||||||
const endTime = end ? new Date(end) : new Date();
|
const endTime = end ? new Date(end) : new Date();
|
||||||
if (Number.isNaN(startTime.getTime()) || Number.isNaN(endTime.getTime())) {
|
if (Number.isNaN(startTime.getTime()) || Number.isNaN(endTime.getTime())) {
|
||||||
return '未知';
|
return unknownLabel;
|
||||||
}
|
}
|
||||||
const diffMs = Math.max(0, endTime - startTime);
|
const diffMs = Math.max(0, endTime - startTime);
|
||||||
const seconds = Math.floor(diffMs / 1000);
|
const seconds = Math.floor(diffMs / 1000);
|
||||||
if (seconds < 60) {
|
if (seconds < 60) {
|
||||||
return `${seconds} 秒`;
|
return typeof window.t === 'function' ? window.t('mcpMonitor.durationSeconds', { n: seconds }) : seconds + ' 秒';
|
||||||
}
|
}
|
||||||
const minutes = Math.floor(seconds / 60);
|
const minutes = Math.floor(seconds / 60);
|
||||||
if (minutes < 60) {
|
if (minutes < 60) {
|
||||||
const remain = seconds % 60;
|
const remain = seconds % 60;
|
||||||
return remain > 0 ? `${minutes} 分 ${remain} 秒` : `${minutes} 分`;
|
if (remain > 0) {
|
||||||
|
return typeof window.t === 'function' ? window.t('mcpMonitor.durationMinutes', { minutes: minutes, seconds: remain }) : minutes + ' 分 ' + remain + ' 秒';
|
||||||
|
}
|
||||||
|
return typeof window.t === 'function' ? window.t('mcpMonitor.durationMinutesOnly', { minutes: minutes }) : minutes + ' 分';
|
||||||
}
|
}
|
||||||
const hours = Math.floor(minutes / 60);
|
const hours = Math.floor(minutes / 60);
|
||||||
const remainMinutes = minutes % 60;
|
const remainMinutes = minutes % 60;
|
||||||
return remainMinutes > 0 ? `${hours} 小时 ${remainMinutes} 分` : `${hours} 小时`;
|
if (remainMinutes > 0) {
|
||||||
|
return typeof window.t === 'function' ? window.t('mcpMonitor.durationHours', { hours: hours, minutes: remainMinutes }) : hours + ' 小时 ' + remainMinutes + ' 分';
|
||||||
|
}
|
||||||
|
return typeof window.t === 'function' ? window.t('mcpMonitor.durationHoursOnly', { hours: hours }) : hours + ' 小时';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,11 +108,13 @@ function updateRoleSelectorDisplay() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
roleSelectorIcon.textContent = icon;
|
roleSelectorIcon.textContent = icon;
|
||||||
roleSelectorText.textContent = selectedRole.name || '默认';
|
const displayName = (selectedRole.name === '默认' || !selectedRole.name) && typeof window.t === 'function'
|
||||||
|
? window.t('chat.defaultRole') : (selectedRole.name || (typeof window.t === 'function' ? window.t('chat.defaultRole') : '默认'));
|
||||||
|
roleSelectorText.textContent = displayName;
|
||||||
} else {
|
} else {
|
||||||
// 默认角色
|
// 默认角色
|
||||||
roleSelectorIcon.textContent = '🔵';
|
roleSelectorIcon.textContent = '🔵';
|
||||||
roleSelectorText.textContent = '默认';
|
roleSelectorText.textContent = typeof window.t === 'function' ? window.t('chat.defaultRole') : '默认';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+134
-58
@@ -172,6 +172,43 @@ async function loadConfig(loadTools = true) {
|
|||||||
// 允许0.0值,只有undefined/null时才使用默认值
|
// 允许0.0值,只有undefined/null时才使用默认值
|
||||||
retrievalWeightInput.value = (hybridWeight !== undefined && hybridWeight !== null) ? hybridWeight : 0.7;
|
retrievalWeightInput.value = (hybridWeight !== undefined && hybridWeight !== null) ? hybridWeight : 0.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 索引配置
|
||||||
|
const indexing = knowledge.indexing || {};
|
||||||
|
const chunkSizeInput = document.getElementById('knowledge-indexing-chunk-size');
|
||||||
|
if (chunkSizeInput) {
|
||||||
|
chunkSizeInput.value = indexing.chunk_size || 512;
|
||||||
|
}
|
||||||
|
|
||||||
|
const chunkOverlapInput = document.getElementById('knowledge-indexing-chunk-overlap');
|
||||||
|
if (chunkOverlapInput) {
|
||||||
|
chunkOverlapInput.value = indexing.chunk_overlap ?? 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxChunksPerItemInput = document.getElementById('knowledge-indexing-max-chunks-per-item');
|
||||||
|
if (maxChunksPerItemInput) {
|
||||||
|
maxChunksPerItemInput.value = indexing.max_chunks_per_item ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxRpmInput = document.getElementById('knowledge-indexing-max-rpm');
|
||||||
|
if (maxRpmInput) {
|
||||||
|
maxRpmInput.value = indexing.max_rpm ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rateLimitDelayInput = document.getElementById('knowledge-indexing-rate-limit-delay-ms');
|
||||||
|
if (rateLimitDelayInput) {
|
||||||
|
rateLimitDelayInput.value = indexing.rate_limit_delay_ms ?? 300;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxRetriesInput = document.getElementById('knowledge-indexing-max-retries');
|
||||||
|
if (maxRetriesInput) {
|
||||||
|
maxRetriesInput.value = indexing.max_retries ?? 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
const retryDelayInput = document.getElementById('knowledge-indexing-retry-delay-ms');
|
||||||
|
if (retryDelayInput) {
|
||||||
|
retryDelayInput.value = indexing.retry_delay_ms ?? 1000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 填充机器人配置
|
// 填充机器人配置
|
||||||
@@ -218,7 +255,10 @@ async function loadConfig(loadTools = true) {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载配置失败:', error);
|
console.error('加载配置失败:', error);
|
||||||
alert('加载配置失败: ' + error.message);
|
const baseMsg = (typeof window !== 'undefined' && typeof window.t === 'function')
|
||||||
|
? window.t('settings.apply.loadFailed')
|
||||||
|
: '加载配置失败';
|
||||||
|
alert(baseMsg + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +272,7 @@ async function loadToolsList(page = 1, searchKeyword = '') {
|
|||||||
// 显示加载状态
|
// 显示加载状态
|
||||||
if (toolsList) {
|
if (toolsList) {
|
||||||
// 清空整个容器,包括可能存在的分页控件
|
// 清空整个容器,包括可能存在的分页控件
|
||||||
toolsList.innerHTML = '<div class="tools-list-items"><div class="loading" style="padding: 20px; text-align: center; color: var(--text-muted);">⏳ 正在加载工具列表...</div></div>';
|
toolsList.innerHTML = '<div class="tools-list-items"><div class="loading" style="padding: 20px; text-align: center; color: var(--text-muted);">⏳ ' + (typeof window.t === 'function' ? window.t('mcp.loadingTools') : '正在加载工具列表...') + '</div></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -287,8 +327,8 @@ async function loadToolsList(page = 1, searchKeyword = '') {
|
|||||||
if (toolsList) {
|
if (toolsList) {
|
||||||
const isTimeout = error.name === 'AbortError' || error.message.includes('timeout');
|
const isTimeout = error.name === 'AbortError' || error.message.includes('timeout');
|
||||||
const errorMsg = isTimeout
|
const errorMsg = isTimeout
|
||||||
? '加载工具列表超时,可能是外部MCP连接较慢。请点击"刷新"按钮重试,或检查外部MCP连接状态。'
|
? (typeof window.t === 'function' ? window.t('mcp.loadToolsTimeout') : '加载工具列表超时,可能是外部MCP连接较慢。请点击"刷新"按钮重试,或检查外部MCP连接状态。')
|
||||||
: `加载工具列表失败: ${escapeHtml(error.message)}`;
|
: (typeof window.t === 'function' ? window.t('mcp.loadToolsFailed') : '加载工具列表失败') + ': ' + escapeHtml(error.message);
|
||||||
toolsList.innerHTML = `<div class="error" style="padding: 20px; text-align: center;">${errorMsg}</div>`;
|
toolsList.innerHTML = `<div class="error" style="padding: 20px; text-align: center;">${errorMsg}</div>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -362,7 +402,7 @@ function renderToolsList() {
|
|||||||
listContainer.innerHTML = '';
|
listContainer.innerHTML = '';
|
||||||
|
|
||||||
if (allTools.length === 0) {
|
if (allTools.length === 0) {
|
||||||
listContainer.innerHTML = '<div class="empty">暂无工具</div>';
|
listContainer.innerHTML = '<div class="empty">' + (typeof window.t === 'function' ? window.t('mcp.noTools') : '暂无工具') + '</div>';
|
||||||
if (!toolsList.contains(listContainer)) {
|
if (!toolsList.contains(listContainer)) {
|
||||||
toolsList.appendChild(listContainer);
|
toolsList.appendChild(listContainer);
|
||||||
}
|
}
|
||||||
@@ -391,8 +431,8 @@ function renderToolsList() {
|
|||||||
let externalBadge = '';
|
let externalBadge = '';
|
||||||
if (toolState.is_external || tool.is_external) {
|
if (toolState.is_external || tool.is_external) {
|
||||||
const externalMcpName = toolState.external_mcp || tool.external_mcp || '';
|
const externalMcpName = toolState.external_mcp || tool.external_mcp || '';
|
||||||
const badgeText = externalMcpName ? `外部 (${escapeHtml(externalMcpName)})` : '外部';
|
const badgeText = externalMcpName ? (typeof window.t === 'function' ? window.t('mcp.externalFrom', { name: escapeHtml(externalMcpName) }) : `外部 (${escapeHtml(externalMcpName)})`) : (typeof window.t === 'function' ? window.t('mcp.externalBadge') : '外部');
|
||||||
const badgeTitle = externalMcpName ? `外部MCP工具 - 来源:${escapeHtml(externalMcpName)}` : '外部MCP工具';
|
const badgeTitle = externalMcpName ? (typeof window.t === 'function' ? window.t('mcp.externalToolFrom', { name: escapeHtml(externalMcpName) }) : `外部MCP工具 - 来源:${escapeHtml(externalMcpName)}`) : (typeof window.t === 'function' ? window.t('mcp.externalBadge') : '外部MCP工具');
|
||||||
externalBadge = `<span class="external-tool-badge" title="${badgeTitle}">${badgeText}</span>`;
|
externalBadge = `<span class="external-tool-badge" title="${badgeTitle}">${badgeText}</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,7 +446,7 @@ function renderToolsList() {
|
|||||||
${escapeHtml(tool.name)}
|
${escapeHtml(tool.name)}
|
||||||
${externalBadge}
|
${externalBadge}
|
||||||
</div>
|
</div>
|
||||||
<div class="tool-item-desc">${escapeHtml(tool.description || '无描述')}</div>
|
<div class="tool-item-desc">${escapeHtml(tool.description || (typeof window.t === 'function' ? window.t('mcp.noDescription') : '无描述'))}</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
listContainer.appendChild(toolItem);
|
listContainer.appendChild(toolItem);
|
||||||
@@ -444,12 +484,19 @@ function renderToolsPagination() {
|
|||||||
const endItem = Math.min(page * toolsPagination.pageSize, total);
|
const endItem = Math.min(page * toolsPagination.pageSize, total);
|
||||||
|
|
||||||
const savedPageSize = getToolsPageSize();
|
const savedPageSize = getToolsPageSize();
|
||||||
|
const t = typeof window.t === 'function' ? window.t : (k) => k;
|
||||||
|
const paginationT = (key, opts) => {
|
||||||
|
if (typeof window.t === 'function') return window.t(key, opts);
|
||||||
|
if (key === 'mcp.paginationInfo' && opts) return `显示 ${opts.start}-${opts.end} / 共 ${opts.total} 个工具`;
|
||||||
|
if (key === 'mcp.pageInfo' && opts) return `第 ${opts.page} / ${opts.total} 页`;
|
||||||
|
return key;
|
||||||
|
};
|
||||||
pagination.innerHTML = `
|
pagination.innerHTML = `
|
||||||
<div class="pagination-info">
|
<div class="pagination-info">
|
||||||
显示 ${startItem}-${endItem} / 共 ${total} 个工具${toolsSearchKeyword ? ` (搜索: "${escapeHtml(toolsSearchKeyword)}")` : ''}
|
${paginationT('mcp.paginationInfo', { start: startItem, end: endItem, total: total })}${toolsSearchKeyword ? ` (${t('common.search')}: "${escapeHtml(toolsSearchKeyword)}")` : ''}
|
||||||
</div>
|
</div>
|
||||||
<div class="pagination-page-size">
|
<div class="pagination-page-size">
|
||||||
<label for="tools-page-size-pagination">每页:</label>
|
<label for="tools-page-size-pagination">${t('mcp.perPage')}</label>
|
||||||
<select id="tools-page-size-pagination" onchange="changeToolsPageSize()">
|
<select id="tools-page-size-pagination" onchange="changeToolsPageSize()">
|
||||||
<option value="10" ${savedPageSize === 10 ? 'selected' : ''}>10</option>
|
<option value="10" ${savedPageSize === 10 ? 'selected' : ''}>10</option>
|
||||||
<option value="20" ${savedPageSize === 20 ? 'selected' : ''}>20</option>
|
<option value="20" ${savedPageSize === 20 ? 'selected' : ''}>20</option>
|
||||||
@@ -458,11 +505,11 @@ function renderToolsPagination() {
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="pagination-controls">
|
<div class="pagination-controls">
|
||||||
<button class="btn-secondary" onclick="loadToolsList(1, '${escapeHtml(toolsSearchKeyword)}')" ${page === 1 ? 'disabled' : ''}>首页</button>
|
<button class="btn-secondary" onclick="loadToolsList(1, '${escapeHtml(toolsSearchKeyword)}')" ${page === 1 ? 'disabled' : ''}>${t('mcp.firstPage')}</button>
|
||||||
<button class="btn-secondary" onclick="loadToolsList(${page - 1}, '${escapeHtml(toolsSearchKeyword)}')" ${page === 1 ? 'disabled' : ''}>上一页</button>
|
<button class="btn-secondary" onclick="loadToolsList(${page - 1}, '${escapeHtml(toolsSearchKeyword)}')" ${page === 1 ? 'disabled' : ''}>${t('mcp.prevPage')}</button>
|
||||||
<span class="pagination-page">第 ${page} / ${totalPages} 页</span>
|
<span class="pagination-page">${paginationT('mcp.pageInfo', { page: page, total: totalPages })}</span>
|
||||||
<button class="btn-secondary" onclick="loadToolsList(${page + 1}, '${escapeHtml(toolsSearchKeyword)}')" ${page === totalPages ? 'disabled' : ''}>下一页</button>
|
<button class="btn-secondary" onclick="loadToolsList(${page + 1}, '${escapeHtml(toolsSearchKeyword)}')" ${page === totalPages ? 'disabled' : ''}>${t('mcp.nextPage')}</button>
|
||||||
<button class="btn-secondary" onclick="loadToolsList(${totalPages}, '${escapeHtml(toolsSearchKeyword)}')" ${page === totalPages ? 'disabled' : ''}>末页</button>
|
<button class="btn-secondary" onclick="loadToolsList(${totalPages}, '${escapeHtml(toolsSearchKeyword)}')" ${page === totalPages ? 'disabled' : ''}>${t('mcp.lastPage')}</button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -656,9 +703,10 @@ async function updateToolsStats() {
|
|||||||
totalEnabled = currentPageEnabled;
|
totalEnabled = currentPageEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tStats = typeof window.t === 'function' ? window.t : (k) => k;
|
||||||
statsEl.innerHTML = `
|
statsEl.innerHTML = `
|
||||||
<span title="当前页启用的工具数">✅ 当前页已启用: <strong>${currentPageEnabled}</strong> / ${currentPageTotal}</span>
|
<span title="${tStats('mcp.currentPageEnabled')}">✅ ${tStats('mcp.currentPageEnabled')}: <strong>${currentPageEnabled}</strong> / ${currentPageTotal}</span>
|
||||||
<span title="所有工具中启用的工具总数">📊 总计已启用: <strong>${totalEnabled}</strong> / ${totalTools}</span>
|
<span title="${tStats('mcp.totalEnabled')}">📊 ${tStats('mcp.totalEnabled')}: <strong>${totalEnabled}</strong> / ${totalTools}</span>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,7 +748,10 @@ async function applySettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasError) {
|
if (hasError) {
|
||||||
alert('请填写所有必填字段(标记为 * 的字段)');
|
const msg = (typeof window !== 'undefined' && typeof window.t === 'function')
|
||||||
|
? window.t('settings.apply.fillRequired')
|
||||||
|
: '请填写所有必填字段(标记为 * 的字段)';
|
||||||
|
alert(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -728,6 +779,15 @@ async function applySettings() {
|
|||||||
const val = parseFloat(document.getElementById('knowledge-retrieval-hybrid-weight')?.value);
|
const val = parseFloat(document.getElementById('knowledge-retrieval-hybrid-weight')?.value);
|
||||||
return isNaN(val) ? 0.7 : val; // 允许0.0值,只有NaN时才使用默认值
|
return isNaN(val) ? 0.7 : val; // 允许0.0值,只有NaN时才使用默认值
|
||||||
})()
|
})()
|
||||||
|
},
|
||||||
|
indexing: {
|
||||||
|
chunk_size: parseInt(document.getElementById("knowledge-indexing-chunk-size")?.value) || 512,
|
||||||
|
chunk_overlap: parseInt(document.getElementById("knowledge-indexing-chunk-overlap")?.value) ?? 50,
|
||||||
|
max_chunks_per_item: parseInt(document.getElementById("knowledge-indexing-max-chunks-per-item")?.value) ?? 0,
|
||||||
|
max_rpm: parseInt(document.getElementById("knowledge-indexing-max-rpm")?.value) ?? 0,
|
||||||
|
rate_limit_delay_ms: parseInt(document.getElementById("knowledge-indexing-rate-limit-delay-ms")?.value) ?? 300,
|
||||||
|
max_retries: parseInt(document.getElementById("knowledge-indexing-max-retries")?.value) ?? 3,
|
||||||
|
retry_delay_ms: parseInt(document.getElementById("knowledge-indexing-retry-delay-ms")?.value) ?? 1000
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -850,7 +910,10 @@ async function applySettings() {
|
|||||||
|
|
||||||
if (!updateResponse.ok) {
|
if (!updateResponse.ok) {
|
||||||
const error = await updateResponse.json();
|
const error = await updateResponse.json();
|
||||||
throw new Error(error.error || '更新配置失败');
|
const fallback = (typeof window !== 'undefined' && typeof window.t === 'function')
|
||||||
|
? window.t('settings.apply.applyFailed')
|
||||||
|
: '应用配置失败';
|
||||||
|
throw new Error(error.error || fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用配置
|
// 应用配置
|
||||||
@@ -860,14 +923,23 @@ async function applySettings() {
|
|||||||
|
|
||||||
if (!applyResponse.ok) {
|
if (!applyResponse.ok) {
|
||||||
const error = await applyResponse.json();
|
const error = await applyResponse.json();
|
||||||
throw new Error(error.error || '应用配置失败');
|
const fallback = (typeof window !== 'undefined' && typeof window.t === 'function')
|
||||||
|
? window.t('settings.apply.applyFailed')
|
||||||
|
: '应用配置失败';
|
||||||
|
throw new Error(error.error || fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
alert('配置已成功应用!');
|
const successMsg = (typeof window !== 'undefined' && typeof window.t === 'function')
|
||||||
|
? window.t('settings.apply.applySuccess')
|
||||||
|
: '配置已成功应用!';
|
||||||
|
alert(successMsg);
|
||||||
closeSettings();
|
closeSettings();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('应用配置失败:', error);
|
console.error('应用配置失败:', error);
|
||||||
alert('应用配置失败: ' + error.message);
|
const baseMsg = (typeof window !== 'undefined' && typeof window.t === 'function')
|
||||||
|
? window.t('settings.apply.applyFailed')
|
||||||
|
: '应用配置失败';
|
||||||
|
alert(baseMsg + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -978,7 +1050,7 @@ async function saveToolsConfig() {
|
|||||||
throw new Error(error.error || '应用配置失败');
|
throw new Error(error.error || '应用配置失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
alert('工具配置已成功保存!');
|
alert(typeof window.t === 'function' ? window.t('mcp.toolsConfigSaved') : '工具配置已成功保存!');
|
||||||
|
|
||||||
// 重新加载工具列表以反映最新状态
|
// 重新加载工具列表以反映最新状态
|
||||||
if (typeof loadToolsList === 'function') {
|
if (typeof loadToolsList === 'function') {
|
||||||
@@ -986,7 +1058,7 @@ async function saveToolsConfig() {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('保存工具配置失败:', error);
|
console.error('保存工具配置失败:', error);
|
||||||
alert('保存工具配置失败: ' + error.message);
|
alert((typeof window.t === 'function' ? window.t('mcp.saveToolsConfigFailed') : '保存工具配置失败') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1033,7 +1105,7 @@ async function changePassword() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasError) {
|
if (hasError) {
|
||||||
alert('请正确填写当前密码和新密码,新密码至少 8 位且需要两次输入一致。');
|
alert(typeof window.t === 'function' ? window.t('settings.security.fillPasswordHint') : '请正确填写当前密码和新密码,新密码至少 8 位且需要两次输入一致。');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1058,13 +1130,14 @@ async function changePassword() {
|
|||||||
throw new Error(result.error || '修改密码失败');
|
throw new Error(result.error || '修改密码失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
alert('密码已更新,请使用新密码重新登录。');
|
const pwdMsg = typeof window.t === 'function' ? window.t('settings.security.passwordUpdated') : '密码已更新,请使用新密码重新登录。';
|
||||||
|
alert(pwdMsg);
|
||||||
resetPasswordForm();
|
resetPasswordForm();
|
||||||
handleUnauthorized({ message: '密码已更新,请使用新密码重新登录。', silent: false });
|
handleUnauthorized({ message: pwdMsg, silent: false });
|
||||||
closeSettings();
|
closeSettings();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('修改密码失败:', error);
|
console.error('修改密码失败:', error);
|
||||||
alert('修改密码失败: ' + error.message);
|
alert((typeof window.t === 'function' ? window.t('settings.security.changePasswordFailed') : '修改密码失败') + ': ' + error.message);
|
||||||
} finally {
|
} finally {
|
||||||
if (submitBtn) {
|
if (submitBtn) {
|
||||||
submitBtn.disabled = false;
|
submitBtn.disabled = false;
|
||||||
@@ -1127,7 +1200,8 @@ function renderExternalMCPList(servers) {
|
|||||||
if (!list) return;
|
if (!list) return;
|
||||||
|
|
||||||
if (Object.keys(servers).length === 0) {
|
if (Object.keys(servers).length === 0) {
|
||||||
list.innerHTML = '<div class="empty">📋 暂无外部MCP配置<br><span style="font-size: 0.875rem; margin-top: 8px; display: block;">点击"添加外部MCP"按钮开始配置</span></div>';
|
const emptyT = typeof window.t === 'function' ? window.t : (k) => k;
|
||||||
|
list.innerHTML = '<div class="empty">📋 ' + emptyT('mcp.noExternalMCP') + '<br><span style="font-size: 0.875rem; margin-top: 8px; display: block;">' + emptyT('mcp.clickToAddExternal') + '</span></div>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1138,10 +1212,11 @@ function renderExternalMCPList(servers) {
|
|||||||
status === 'connecting' ? 'status-connecting' :
|
status === 'connecting' ? 'status-connecting' :
|
||||||
status === 'error' ? 'status-error' :
|
status === 'error' ? 'status-error' :
|
||||||
status === 'disabled' ? 'status-disabled' : 'status-disconnected';
|
status === 'disabled' ? 'status-disabled' : 'status-disconnected';
|
||||||
const statusText = status === 'connected' ? '已连接' :
|
const statusT = typeof window.t === 'function' ? window.t : (k) => k;
|
||||||
status === 'connecting' ? '连接中...' :
|
const statusText = status === 'connected' ? statusT('mcp.connected') :
|
||||||
status === 'error' ? '连接失败' :
|
status === 'connecting' ? statusT('mcp.connecting') :
|
||||||
status === 'disabled' ? '已禁用' : '未连接';
|
status === 'error' ? statusT('mcp.connectionFailed') :
|
||||||
|
status === 'disabled' ? statusT('mcp.disabled') : statusT('mcp.disconnected');
|
||||||
const transport = server.config.transport || (server.config.command ? 'stdio' : 'http');
|
const transport = server.config.transport || (server.config.command ? 'stdio' : 'http');
|
||||||
const transportIcon = transport === 'stdio' ? '⚙️' : '🌐';
|
const transportIcon = transport === 'stdio' ? '⚙️' : '🌐';
|
||||||
|
|
||||||
@@ -1154,15 +1229,15 @@ function renderExternalMCPList(servers) {
|
|||||||
</div>
|
</div>
|
||||||
<div class="external-mcp-item-actions">
|
<div class="external-mcp-item-actions">
|
||||||
${status === 'connected' || status === 'disconnected' || status === 'error' ?
|
${status === 'connected' || status === 'disconnected' || status === 'error' ?
|
||||||
`<button class="btn-small" id="btn-toggle-${escapeHtml(name)}" onclick="toggleExternalMCP('${escapeHtml(name)}', '${status}')" title="${status === 'connected' ? '停止连接' : '启动连接'}">
|
`<button class="btn-small" id="btn-toggle-${escapeHtml(name)}" onclick="toggleExternalMCP('${escapeHtml(name)}', '${status}')" title="${status === 'connected' ? statusT('mcp.stopConnection') : statusT('mcp.startConnection')}">
|
||||||
${status === 'connected' ? '⏸ 停止' : '▶ 启动'}
|
${status === 'connected' ? '⏸ ' + statusT('mcp.stop') : '▶ ' + statusT('mcp.start')}
|
||||||
</button>` :
|
</button>` :
|
||||||
status === 'connecting' ?
|
status === 'connecting' ?
|
||||||
`<button class="btn-small" id="btn-toggle-${escapeHtml(name)}" disabled style="opacity: 0.6; cursor: not-allowed;">
|
`<button class="btn-small" id="btn-toggle-${escapeHtml(name)}" disabled style="opacity: 0.6; cursor: not-allowed;">
|
||||||
⏳ 连接中...
|
⏳ 连接中...
|
||||||
</button>` : ''}
|
</button>` : ''}
|
||||||
<button class="btn-small" onclick="editExternalMCP('${escapeHtml(name)}')" title="编辑配置" ${status === 'connecting' ? 'disabled' : ''}>✏️ 编辑</button>
|
<button class="btn-small" onclick="editExternalMCP('${escapeHtml(name)}')" title="${statusT('mcp.editConfig')}" ${status === 'connecting' ? 'disabled' : ''}>✏️ ${statusT('common.edit')}</button>
|
||||||
<button class="btn-small btn-danger" onclick="deleteExternalMCP('${escapeHtml(name)}')" title="删除配置" ${status === 'connecting' ? 'disabled' : ''}>🗑 删除</button>
|
<button class="btn-small btn-danger" onclick="deleteExternalMCP('${escapeHtml(name)}')" title="${statusT('mcp.deleteConfig')}" ${status === 'connecting' ? 'disabled' : ''}>🗑 ${statusT('common.delete')}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
${status === 'error' && server.error ? `
|
${status === 'error' && server.error ? `
|
||||||
@@ -1171,31 +1246,31 @@ function renderExternalMCPList(servers) {
|
|||||||
</div>` : ''}
|
</div>` : ''}
|
||||||
<div class="external-mcp-item-details">
|
<div class="external-mcp-item-details">
|
||||||
<div>
|
<div>
|
||||||
<strong>传输模式</strong>
|
<strong>${statusT('mcp.transportMode')}</strong>
|
||||||
<span>${transportIcon} ${escapeHtml(transport.toUpperCase())}</span>
|
<span>${transportIcon} ${escapeHtml(transport.toUpperCase())}</span>
|
||||||
</div>
|
</div>
|
||||||
${server.tool_count !== undefined && server.tool_count > 0 ? `
|
${server.tool_count !== undefined && server.tool_count > 0 ? `
|
||||||
<div>
|
<div>
|
||||||
<strong>工具数量</strong>
|
<strong>${statusT('mcp.toolCount')}</strong>
|
||||||
<span style="font-weight: 600; color: var(--accent-color);">🔧 ${server.tool_count} 个工具</span>
|
<span style="font-weight: 600; color: var(--accent-color);">🔧 ${server.tool_count} 个工具</span>
|
||||||
</div>` : server.tool_count === 0 && status === 'connected' ? `
|
</div>` : server.tool_count === 0 && status === 'connected' ? `
|
||||||
<div>
|
<div>
|
||||||
<strong>工具数量</strong>
|
<strong>${statusT('mcp.toolCount')}</strong>
|
||||||
<span style="color: var(--text-muted);">暂无工具</span>
|
<span style="color: var(--text-muted);">${statusT('mcp.noTools')}</span>
|
||||||
</div>` : ''}
|
</div>` : ''}
|
||||||
${server.config.description ? `
|
${server.config.description ? `
|
||||||
<div>
|
<div>
|
||||||
<strong>描述</strong>
|
<strong>${statusT('mcp.description')}</strong>
|
||||||
<span>${escapeHtml(server.config.description)}</span>
|
<span>${escapeHtml(server.config.description)}</span>
|
||||||
</div>` : ''}
|
</div>` : ''}
|
||||||
${server.config.timeout ? `
|
${server.config.timeout ? `
|
||||||
<div>
|
<div>
|
||||||
<strong>超时时间</strong>
|
<strong>${statusT('mcp.timeout')}</strong>
|
||||||
<span>${server.config.timeout} 秒</span>
|
<span>${server.config.timeout} 秒</span>
|
||||||
</div>` : ''}
|
</div>` : ''}
|
||||||
${transport === 'stdio' && server.config.command ? `
|
${transport === 'stdio' && server.config.command ? `
|
||||||
<div>
|
<div>
|
||||||
<strong>命令</strong>
|
<strong>${statusT('mcp.command')}</strong>
|
||||||
<span style="font-family: monospace; font-size: 0.8125rem;">${escapeHtml(server.config.command)}</span>
|
<span style="font-family: monospace; font-size: 0.8125rem;">${escapeHtml(server.config.command)}</span>
|
||||||
</div>` : ''}
|
</div>` : ''}
|
||||||
${transport === 'http' && server.config.url ? `
|
${transport === 'http' && server.config.url ? `
|
||||||
@@ -1221,18 +1296,19 @@ function renderExternalMCPStats(stats) {
|
|||||||
const disabled = stats.disabled || 0;
|
const disabled = stats.disabled || 0;
|
||||||
const connected = stats.connected || 0;
|
const connected = stats.connected || 0;
|
||||||
|
|
||||||
|
const statsT = typeof window.t === 'function' ? window.t : (k) => k;
|
||||||
statsEl.innerHTML = `
|
statsEl.innerHTML = `
|
||||||
<span title="总配置数">📊 总数: <strong>${total}</strong></span>
|
<span title="${statsT('mcp.totalCount')}">📊 ${statsT('mcp.totalCount')}: <strong>${total}</strong></span>
|
||||||
<span title="已启用的配置数">✅ 已启用: <strong>${enabled}</strong></span>
|
<span title="${statsT('mcp.enabledCount')}">✅ ${statsT('mcp.enabledCount')}: <strong>${enabled}</strong></span>
|
||||||
<span title="已停用的配置数">⏸ 已停用: <strong>${disabled}</strong></span>
|
<span title="${statsT('mcp.disabledCount')}">⏸ ${statsT('mcp.disabledCount')}: <strong>${disabled}</strong></span>
|
||||||
<span title="当前已连接的配置数">🔗 已连接: <strong>${connected}</strong></span>
|
<span title="${statsT('mcp.connectedCount')}">🔗 ${statsT('mcp.connectedCount')}: <strong>${connected}</strong></span>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示添加外部MCP模态框
|
// 显示添加外部MCP模态框
|
||||||
function showAddExternalMCPModal() {
|
function showAddExternalMCPModal() {
|
||||||
currentEditingMCPName = null;
|
currentEditingMCPName = null;
|
||||||
document.getElementById('external-mcp-modal-title').textContent = '添加外部MCP';
|
document.getElementById('external-mcp-modal-title').textContent = (typeof window.t === 'function' ? window.t('mcp.addExternalMCP') : '添加外部MCP');
|
||||||
document.getElementById('external-mcp-json').value = '';
|
document.getElementById('external-mcp-json').value = '';
|
||||||
document.getElementById('external-mcp-json-error').style.display = 'none';
|
document.getElementById('external-mcp-json-error').style.display = 'none';
|
||||||
document.getElementById('external-mcp-json-error').textContent = '';
|
document.getElementById('external-mcp-json-error').textContent = '';
|
||||||
@@ -1257,7 +1333,7 @@ async function editExternalMCP(name) {
|
|||||||
const server = await response.json();
|
const server = await response.json();
|
||||||
currentEditingMCPName = name;
|
currentEditingMCPName = name;
|
||||||
|
|
||||||
document.getElementById('external-mcp-modal-title').textContent = '编辑外部MCP';
|
document.getElementById('external-mcp-modal-title').textContent = (typeof window.t === 'function' ? window.t('mcp.editExternalMCP') : '编辑外部MCP');
|
||||||
|
|
||||||
// 将配置转换为对象格式(key为名称)
|
// 将配置转换为对象格式(key为名称)
|
||||||
const config = { ...server.config };
|
const config = { ...server.config };
|
||||||
@@ -1279,7 +1355,7 @@ async function editExternalMCP(name) {
|
|||||||
document.getElementById('external-mcp-modal').style.display = 'block';
|
document.getElementById('external-mcp-modal').style.display = 'block';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('编辑外部MCP失败:', error);
|
console.error('编辑外部MCP失败:', error);
|
||||||
alert('编辑失败: ' + error.message);
|
alert((typeof window.t === 'function' ? window.t('mcp.operationFailed') : '编辑失败') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1482,7 +1558,7 @@ async function saveExternalMCP() {
|
|||||||
}
|
}
|
||||||
// 轮询几次以拉取后端异步更新的工具数量(无固定延迟,拿到即停)
|
// 轮询几次以拉取后端异步更新的工具数量(无固定延迟,拿到即停)
|
||||||
pollExternalMCPToolCount(null, 5);
|
pollExternalMCPToolCount(null, 5);
|
||||||
alert('保存成功');
|
alert(typeof window.t === 'function' ? window.t('mcp.saveSuccess') : '保存成功');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('保存外部MCP失败:', error);
|
console.error('保存外部MCP失败:', error);
|
||||||
errorDiv.textContent = '保存失败: ' + error.message;
|
errorDiv.textContent = '保存失败: ' + error.message;
|
||||||
@@ -1493,7 +1569,7 @@ async function saveExternalMCP() {
|
|||||||
|
|
||||||
// 删除外部MCP
|
// 删除外部MCP
|
||||||
async function deleteExternalMCP(name) {
|
async function deleteExternalMCP(name) {
|
||||||
if (!confirm(`确定要删除外部MCP "${name}" 吗?`)) {
|
if (!confirm((typeof window.t === 'function' ? window.t('mcp.deleteExternalConfirm', { name: name }) : `确定要删除外部MCP "${name}" 吗?`))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1512,10 +1588,10 @@ async function deleteExternalMCP(name) {
|
|||||||
if (typeof window !== 'undefined' && typeof window.refreshMentionTools === 'function') {
|
if (typeof window !== 'undefined' && typeof window.refreshMentionTools === 'function') {
|
||||||
window.refreshMentionTools();
|
window.refreshMentionTools();
|
||||||
}
|
}
|
||||||
alert('删除成功');
|
alert(typeof window.t === 'function' ? window.t('mcp.deleteSuccess') : '删除成功');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('删除外部MCP失败:', error);
|
console.error('删除外部MCP失败:', error);
|
||||||
alert('删除失败: ' + error.message);
|
alert((typeof window.t === 'function' ? window.t('mcp.operationFailed') : '删除失败') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1580,7 +1656,7 @@ async function toggleExternalMCP(name, currentStatus) {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('切换外部MCP状态失败:', error);
|
console.error('切换外部MCP状态失败:', error);
|
||||||
alert('操作失败: ' + error.message);
|
alert((typeof window.t === 'function' ? window.t('mcp.operationFailed') : '操作失败') + ': ' + error.message);
|
||||||
|
|
||||||
// 恢复按钮状态
|
// 恢复按钮状态
|
||||||
if (button) {
|
if (button) {
|
||||||
@@ -1633,7 +1709,7 @@ async function pollExternalMCPStatus(name, maxAttempts = 30) {
|
|||||||
window.refreshMentionTools();
|
window.refreshMentionTools();
|
||||||
}
|
}
|
||||||
if (status === 'error') {
|
if (status === 'error') {
|
||||||
alert('连接失败,请检查配置和网络连接');
|
alert(typeof window.t === 'function' ? window.t('mcp.connectionFailedCheck') : '连接失败,请检查配置和网络连接');
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (status === 'connecting') {
|
} else if (status === 'connecting') {
|
||||||
@@ -1655,7 +1731,7 @@ async function pollExternalMCPStatus(name, maxAttempts = 30) {
|
|||||||
if (typeof window !== 'undefined' && typeof window.refreshMentionTools === 'function') {
|
if (typeof window !== 'undefined' && typeof window.refreshMentionTools === 'function') {
|
||||||
window.refreshMentionTools();
|
window.refreshMentionTools();
|
||||||
}
|
}
|
||||||
alert('连接超时,请检查配置和网络连接');
|
alert(typeof window.t === 'function' ? window.t('mcp.connectionTimeout') : '连接超时,请检查配置和网络连接');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 在打开设置时加载外部MCP列表
|
// 在打开设置时加载外部MCP列表
|
||||||
|
|||||||
+134
-131
@@ -1,4 +1,7 @@
|
|||||||
// 任务管理页面功能
|
// 任务管理页面功能
|
||||||
|
function _t(key, opts) {
|
||||||
|
return typeof window.t === 'function' ? window.t(key, opts) : key;
|
||||||
|
}
|
||||||
|
|
||||||
// HTML转义函数(如果未定义)
|
// HTML转义函数(如果未定义)
|
||||||
if (typeof escapeHtml === 'undefined') {
|
if (typeof escapeHtml === 'undefined') {
|
||||||
@@ -106,7 +109,7 @@ async function loadTasks() {
|
|||||||
const listContainer = document.getElementById('tasks-list');
|
const listContainer = document.getElementById('tasks-list');
|
||||||
if (!listContainer) return;
|
if (!listContainer) return;
|
||||||
|
|
||||||
listContainer.innerHTML = '<div class="loading-spinner">加载中...</div>';
|
listContainer.innerHTML = '<div class="loading-spinner">' + _t('tasks.loadingTasks') + '</div>';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 并行加载运行中的任务和已完成的任务历史
|
// 并行加载运行中的任务和已完成的任务历史
|
||||||
@@ -117,7 +120,7 @@ async function loadTasks() {
|
|||||||
|
|
||||||
// 处理运行中的任务
|
// 处理运行中的任务
|
||||||
if (activeResponse.status === 'rejected' || !activeResponse.value || !activeResponse.value.ok) {
|
if (activeResponse.status === 'rejected' || !activeResponse.value || !activeResponse.value.ok) {
|
||||||
throw new Error('获取任务列表失败');
|
throw new Error(_t('tasks.loadTaskListFailed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const activeResult = await activeResponse.value.json();
|
const activeResult = await activeResponse.value.json();
|
||||||
@@ -177,8 +180,8 @@ async function loadTasks() {
|
|||||||
console.error('加载任务失败:', error);
|
console.error('加载任务失败:', error);
|
||||||
listContainer.innerHTML = `
|
listContainer.innerHTML = `
|
||||||
<div class="tasks-empty">
|
<div class="tasks-empty">
|
||||||
<p>加载失败: ${escapeHtml(error.message)}</p>
|
<p>${_t('tasks.loadFailedRetry')}: ${escapeHtml(error.message)}</p>
|
||||||
<button class="btn-secondary" onclick="loadTasks()">重试</button>
|
<button class="btn-secondary" onclick="loadTasks()">${_t('tasks.retry')}</button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -296,21 +299,21 @@ function toggleShowHistory(show) {
|
|||||||
|
|
||||||
// 计算执行时长
|
// 计算执行时长
|
||||||
function calculateDuration(startedAt) {
|
function calculateDuration(startedAt) {
|
||||||
if (!startedAt) return '未知';
|
if (!startedAt) return _t('tasks.unknown');
|
||||||
const start = new Date(startedAt);
|
const start = new Date(startedAt);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const diff = Math.floor((now - start) / 1000); // 秒
|
const diff = Math.floor((now - start) / 1000);
|
||||||
|
|
||||||
if (diff < 60) {
|
if (diff < 60) {
|
||||||
return `${diff}秒`;
|
return diff + _t('tasks.durationSeconds');
|
||||||
} else if (diff < 3600) {
|
} else if (diff < 3600) {
|
||||||
const minutes = Math.floor(diff / 60);
|
const minutes = Math.floor(diff / 60);
|
||||||
const seconds = diff % 60;
|
const seconds = diff % 60;
|
||||||
return `${minutes}分${seconds}秒`;
|
return minutes + _t('tasks.durationMinutes') + ' ' + seconds + _t('tasks.durationSeconds');
|
||||||
} else {
|
} else {
|
||||||
const hours = Math.floor(diff / 3600);
|
const hours = Math.floor(diff / 3600);
|
||||||
const minutes = Math.floor((diff % 3600) / 60);
|
const minutes = Math.floor((diff % 3600) / 60);
|
||||||
return `${hours}小时${minutes}分`;
|
return hours + _t('tasks.durationHours') + ' ' + minutes + _t('tasks.durationMinutes');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,9 +352,9 @@ function renderTasks(tasks) {
|
|||||||
if (tasks.length === 0) {
|
if (tasks.length === 0) {
|
||||||
listContainer.innerHTML = `
|
listContainer.innerHTML = `
|
||||||
<div class="tasks-empty">
|
<div class="tasks-empty">
|
||||||
<p>当前没有符合条件的任务</p>
|
<p>${_t('tasks.noMatchingTasks')}</p>
|
||||||
${tasksState.allTasks.length === 0 && tasksState.completedTasksHistory.length > 0 ?
|
${tasksState.allTasks.length === 0 && tasksState.completedTasksHistory.length > 0 ?
|
||||||
'<p style="margin-top: 8px; color: var(--text-muted); font-size: 0.875rem;">提示:有已完成的任务历史,请勾选"显示历史记录"查看</p>' : ''}
|
'<p style="margin-top: 8px; color: var(--text-muted); font-size: 0.875rem;">' + _t('tasks.historyHint') + '</p>' : ''}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
return;
|
return;
|
||||||
@@ -359,12 +362,12 @@ function renderTasks(tasks) {
|
|||||||
|
|
||||||
// 状态映射
|
// 状态映射
|
||||||
const statusMap = {
|
const statusMap = {
|
||||||
'running': { text: '执行中', class: 'task-status-running' },
|
'running': { text: _t('tasks.statusRunning'), class: 'task-status-running' },
|
||||||
'cancelling': { text: '取消中', class: 'task-status-cancelling' },
|
'cancelling': { text: _t('tasks.statusCancelling'), class: 'task-status-cancelling' },
|
||||||
'failed': { text: '执行失败', class: 'task-status-failed' },
|
'failed': { text: _t('tasks.statusFailed'), class: 'task-status-failed' },
|
||||||
'timeout': { text: '执行超时', class: 'task-status-timeout' },
|
'timeout': { text: _t('tasks.statusTimeout'), class: 'task-status-timeout' },
|
||||||
'cancelled': { text: '已取消', class: 'task-status-cancelled' },
|
'cancelled': { text: _t('tasks.statusCancelled'), class: 'task-status-cancelled' },
|
||||||
'completed': { text: '已完成', class: 'task-status-completed' }
|
'completed': { text: _t('tasks.statusCompleted'), class: 'task-status-completed' }
|
||||||
};
|
};
|
||||||
|
|
||||||
// 分离当前任务和历史任务
|
// 分离当前任务和历史任务
|
||||||
@@ -382,8 +385,8 @@ function renderTasks(tasks) {
|
|||||||
if (historyTasks.length > 0) {
|
if (historyTasks.length > 0) {
|
||||||
html += `<div class="tasks-history-section">
|
html += `<div class="tasks-history-section">
|
||||||
<div class="tasks-history-header">
|
<div class="tasks-history-header">
|
||||||
<span class="tasks-history-title">📜 最近完成的任务(最近24小时)</span>
|
<span class="tasks-history-title">📜 ` + _t('tasks.recentCompletedTasks') + `</span>
|
||||||
<button class="btn-secondary btn-small" onclick="clearTasksHistory()">清空历史</button>
|
<button class="btn-secondary btn-small" onclick="clearTasksHistory()">` + _t('tasks.clearHistory') + `</button>
|
||||||
</div>
|
</div>
|
||||||
${historyTasks.map(task => renderTaskItem(task, statusMap, true)).join('')}
|
${historyTasks.map(task => renderTaskItem(task, statusMap, true)).join('')}
|
||||||
</div>`;
|
</div>`;
|
||||||
@@ -406,7 +409,7 @@ function renderTaskItem(task, statusMap, isHistory = false) {
|
|||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
second: '2-digit'
|
second: '2-digit'
|
||||||
})
|
})
|
||||||
: '未知时间';
|
: _t('tasks.unknownTime');
|
||||||
|
|
||||||
const completedText = completedTime && !isNaN(completedTime.getTime())
|
const completedText = completedTime && !isNaN(completedTime.getTime())
|
||||||
? completedTime.toLocaleString('zh-CN', {
|
? completedTime.toLocaleString('zh-CN', {
|
||||||
@@ -438,22 +441,22 @@ function renderTaskItem(task, statusMap, isHistory = false) {
|
|||||||
</label>
|
</label>
|
||||||
` : '<div class="task-checkbox-placeholder"></div>'}
|
` : '<div class="task-checkbox-placeholder"></div>'}
|
||||||
<span class="task-status ${status.class}">${status.text}</span>
|
<span class="task-status ${status.class}">${status.text}</span>
|
||||||
${isHistory ? '<span class="task-history-badge" title="历史记录">📜</span>' : ''}
|
${isHistory ? '<span class="task-history-badge" title="' + _t('tasks.historyBadge') + '">📜</span>' : ''}
|
||||||
<span class="task-message" title="${escapeHtml(task.message || '未命名任务')}">${escapeHtml(task.message || '未命名任务')}</span>
|
<span class="task-message" title="${escapeHtml(task.message || _t('tasks.unnamedTask'))}">${escapeHtml(task.message || _t('tasks.unnamedTask'))}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="task-actions">
|
<div class="task-actions">
|
||||||
${duration ? `<span class="task-duration" title="执行时长">⏱ ${duration}</span>` : ''}
|
${duration ? `<span class="task-duration" title="${_t('tasks.duration')}">⏱ ${duration}</span>` : ''}
|
||||||
<span class="task-time" title="${isHistory && completedText ? '完成时间' : '开始时间'}">
|
<span class="task-time" title="${isHistory && completedText ? _t('tasks.completedAt') : _t('tasks.startedAt')}">
|
||||||
${isHistory && completedText ? completedText : timeText}
|
${isHistory && completedText ? completedText : timeText}
|
||||||
</span>
|
</span>
|
||||||
${canCancel ? `<button class="btn-secondary btn-small" onclick="cancelTask('${task.conversationId}', this)">取消任务</button>` : ''}
|
${canCancel ? `<button class="btn-secondary btn-small" onclick="cancelTask('${task.conversationId}', this)">` + _t('tasks.cancelTask') + `</button>` : ''}
|
||||||
${task.conversationId ? `<button class="btn-secondary btn-small" onclick="viewConversation('${task.conversationId}')">查看对话</button>` : ''}
|
${task.conversationId ? `<button class="btn-secondary btn-small" onclick="viewConversation('${task.conversationId}')">` + _t('tasks.viewConversation') + `</button>` : ''}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
${task.conversationId ? `
|
${task.conversationId ? `
|
||||||
<div class="task-details">
|
<div class="task-details">
|
||||||
<span class="task-id-label">对话ID:</span>
|
<span class="task-id-label">` + _t('tasks.conversationIdLabel') + `:</span>
|
||||||
<span class="task-id-value" title="点击复制" onclick="copyTaskId('${task.conversationId}')">${escapeHtml(task.conversationId)}</span>
|
<span class="task-id-value" title="` + _t('tasks.clickToCopy') + `" onclick="copyTaskId('${task.conversationId}')">${escapeHtml(task.conversationId)}</span>
|
||||||
</div>
|
</div>
|
||||||
` : ''}
|
` : ''}
|
||||||
</div>
|
</div>
|
||||||
@@ -462,7 +465,7 @@ function renderTaskItem(task, statusMap, isHistory = false) {
|
|||||||
|
|
||||||
// 清空任务历史
|
// 清空任务历史
|
||||||
function clearTasksHistory() {
|
function clearTasksHistory() {
|
||||||
if (!confirm('确定要清空所有任务历史记录吗?')) {
|
if (!confirm(_t('tasks.clearHistoryConfirm'))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tasksState.completedTasksHistory = [];
|
tasksState.completedTasksHistory = [];
|
||||||
@@ -490,7 +493,7 @@ function updateBatchActions() {
|
|||||||
const count = tasksState.selectedTasks.size;
|
const count = tasksState.selectedTasks.size;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
batchActions.style.display = 'flex';
|
batchActions.style.display = 'flex';
|
||||||
selectedCount.textContent = `已选择 ${count} 项`;
|
selectedCount.textContent = typeof window.t === 'function' ? window.t('mcp.selectedCount', { count: count }) : `已选择 ${count} 项`;
|
||||||
} else {
|
} else {
|
||||||
batchActions.style.display = 'none';
|
batchActions.style.display = 'none';
|
||||||
}
|
}
|
||||||
@@ -509,7 +512,7 @@ async function batchCancelTasks() {
|
|||||||
const selected = Array.from(tasksState.selectedTasks);
|
const selected = Array.from(tasksState.selectedTasks);
|
||||||
if (selected.length === 0) return;
|
if (selected.length === 0) return;
|
||||||
|
|
||||||
if (!confirm(`确定要取消 ${selected.length} 个任务吗?`)) {
|
if (!confirm(_t('tasks.confirmCancelTasks', { n: selected.length }))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,9 +548,9 @@ async function batchCancelTasks() {
|
|||||||
|
|
||||||
// 显示结果
|
// 显示结果
|
||||||
if (failCount > 0) {
|
if (failCount > 0) {
|
||||||
alert(`批量取消完成:成功 ${successCount} 个,失败 ${failCount} 个`);
|
alert(_t('tasks.batchCancelResultPartial', { success: successCount, fail: failCount }));
|
||||||
} else {
|
} else {
|
||||||
alert(`成功取消 ${successCount} 个任务`);
|
alert(_t('tasks.batchCancelResultSuccess', { n: successCount }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,7 +559,7 @@ function copyTaskId(conversationId) {
|
|||||||
navigator.clipboard.writeText(conversationId).then(() => {
|
navigator.clipboard.writeText(conversationId).then(() => {
|
||||||
// 显示复制成功提示
|
// 显示复制成功提示
|
||||||
const tooltip = document.createElement('div');
|
const tooltip = document.createElement('div');
|
||||||
tooltip.textContent = '已复制!';
|
tooltip.textContent = _t('tasks.copiedToast');
|
||||||
tooltip.style.cssText = 'position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.8); color: white; padding: 8px 16px; border-radius: 4px; z-index: 10000;';
|
tooltip.style.cssText = 'position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.8); color: white; padding: 8px 16px; border-radius: 4px; z-index: 10000;';
|
||||||
document.body.appendChild(tooltip);
|
document.body.appendChild(tooltip);
|
||||||
setTimeout(() => tooltip.remove(), 1000);
|
setTimeout(() => tooltip.remove(), 1000);
|
||||||
@@ -571,7 +574,7 @@ async function cancelTask(conversationId, button) {
|
|||||||
|
|
||||||
const originalText = button.textContent;
|
const originalText = button.textContent;
|
||||||
button.disabled = true;
|
button.disabled = true;
|
||||||
button.textContent = '取消中...';
|
button.textContent = _t('tasks.cancelling');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await apiFetch('/api/agent-loop/cancel', {
|
const response = await apiFetch('/api/agent-loop/cancel', {
|
||||||
@@ -584,7 +587,7 @@ async function cancelTask(conversationId, button) {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
throw new Error(result.error || '取消任务失败');
|
throw new Error(result.error || _t('tasks.cancelTaskFailed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从选择中移除
|
// 从选择中移除
|
||||||
@@ -595,7 +598,7 @@ async function cancelTask(conversationId, button) {
|
|||||||
await loadTasks();
|
await loadTasks();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('取消任务失败:', error);
|
console.error('取消任务失败:', error);
|
||||||
alert('取消任务失败: ' + error.message);
|
alert(_t('tasks.cancelTaskFailed') + ': ' + error.message);
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
button.textContent = originalText;
|
button.textContent = originalText;
|
||||||
}
|
}
|
||||||
@@ -738,7 +741,7 @@ async function showBatchImportModal() {
|
|||||||
try {
|
try {
|
||||||
const loadedRoles = await loadRoles();
|
const loadedRoles = await loadRoles();
|
||||||
// 清空现有选项(除了默认选项)
|
// 清空现有选项(除了默认选项)
|
||||||
roleSelect.innerHTML = '<option value="">默认</option>';
|
roleSelect.innerHTML = '<option value="">' + _t('batchImportModal.defaultRole') + '</option>';
|
||||||
|
|
||||||
// 添加已启用的角色
|
// 添加已启用的角色
|
||||||
const sortedRoles = loadedRoles.sort((a, b) => {
|
const sortedRoles = loadedRoles.sort((a, b) => {
|
||||||
@@ -782,7 +785,7 @@ function updateBatchImportStats(text) {
|
|||||||
const count = lines.length;
|
const count = lines.length;
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
statsEl.innerHTML = `<div class="batch-import-stat">共 ${count} 个任务</div>`;
|
statsEl.innerHTML = '<div class="batch-import-stat">' + _t('tasks.taskCount', { count: count }) + '</div>';
|
||||||
statsEl.style.display = 'block';
|
statsEl.style.display = 'block';
|
||||||
} else {
|
} else {
|
||||||
statsEl.style.display = 'none';
|
statsEl.style.display = 'none';
|
||||||
@@ -808,14 +811,14 @@ async function createBatchQueue() {
|
|||||||
|
|
||||||
const text = input.value.trim();
|
const text = input.value.trim();
|
||||||
if (!text) {
|
if (!text) {
|
||||||
alert('请输入至少一个任务');
|
alert(_t('tasks.enterTaskPrompt'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按行分割任务
|
// 按行分割任务
|
||||||
const tasks = text.split('\n').map(line => line.trim()).filter(line => line !== '');
|
const tasks = text.split('\n').map(line => line.trim()).filter(line => line !== '');
|
||||||
if (tasks.length === 0) {
|
if (tasks.length === 0) {
|
||||||
alert('没有有效的任务');
|
alert(_t('tasks.noValidTask'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -836,7 +839,7 @@ async function createBatchQueue() {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
throw new Error(result.error || '创建批量任务队列失败');
|
throw new Error(result.error || _t('tasks.createBatchQueueFailed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
@@ -849,7 +852,7 @@ async function createBatchQueue() {
|
|||||||
refreshBatchQueues();
|
refreshBatchQueues();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('创建批量任务队列失败:', error);
|
console.error('创建批量任务队列失败:', error);
|
||||||
alert('创建批量任务队列失败: ' + error.message);
|
alert(_t('tasks.createBatchQueueFailed') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -916,7 +919,7 @@ async function loadBatchQueues(page) {
|
|||||||
try {
|
try {
|
||||||
const response = await apiFetch(`/api/batch-tasks?${params.toString()}`);
|
const response = await apiFetch(`/api/batch-tasks?${params.toString()}`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('获取批量任务队列失败');
|
throw new Error(_t('tasks.loadFailedRetry'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
@@ -929,7 +932,7 @@ async function loadBatchQueues(page) {
|
|||||||
section.style.display = 'block';
|
section.style.display = 'block';
|
||||||
const list = document.getElementById('batch-queues-list');
|
const list = document.getElementById('batch-queues-list');
|
||||||
if (list) {
|
if (list) {
|
||||||
list.innerHTML = '<div class="tasks-empty"><p>加载失败: ' + escapeHtml(error.message) + '</p><button class="btn-secondary" onclick="refreshBatchQueues()">重试</button></div>';
|
list.innerHTML = '<div class="tasks-empty"><p>' + _t('tasks.loadFailedRetry') + ': ' + escapeHtml(error.message) + '</p><button class="btn-secondary" onclick="refreshBatchQueues()">' + _t('tasks.retry') + '</button></div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -964,7 +967,7 @@ function renderBatchQueues() {
|
|||||||
const queues = batchQueuesState.queues;
|
const queues = batchQueuesState.queues;
|
||||||
|
|
||||||
if (queues.length === 0) {
|
if (queues.length === 0) {
|
||||||
list.innerHTML = '<div class="tasks-empty"><p>当前没有批量任务队列</p></div>';
|
list.innerHTML = '<div class="tasks-empty"><p>' + _t('tasks.noBatchQueues') + '</p></div>';
|
||||||
if (pagination) pagination.style.display = 'none';
|
if (pagination) pagination.style.display = 'none';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -976,11 +979,11 @@ function renderBatchQueues() {
|
|||||||
|
|
||||||
list.innerHTML = queues.map(queue => {
|
list.innerHTML = queues.map(queue => {
|
||||||
const statusMap = {
|
const statusMap = {
|
||||||
'pending': { text: '待执行', class: 'batch-queue-status-pending' },
|
'pending': { text: _t('tasks.statusPending'), class: 'batch-queue-status-pending' },
|
||||||
'running': { text: '执行中', class: 'batch-queue-status-running' },
|
'running': { text: _t('tasks.statusRunning'), class: 'batch-queue-status-running' },
|
||||||
'paused': { text: '已暂停', class: 'batch-queue-status-paused' },
|
'paused': { text: _t('tasks.statusPaused'), class: 'batch-queue-status-paused' },
|
||||||
'completed': { text: '已完成', class: 'batch-queue-status-completed' },
|
'completed': { text: _t('tasks.statusCompleted'), class: 'batch-queue-status-completed' },
|
||||||
'cancelled': { text: '已取消', class: 'batch-queue-status-cancelled' }
|
'cancelled': { text: _t('tasks.statusCancelled'), class: 'batch-queue-status-cancelled' }
|
||||||
};
|
};
|
||||||
|
|
||||||
const status = statusMap[queue.status] || { text: queue.status, class: 'batch-queue-status-unknown' };
|
const status = statusMap[queue.status] || { text: queue.status, class: 'batch-queue-status-unknown' };
|
||||||
@@ -1012,8 +1015,8 @@ function renderBatchQueues() {
|
|||||||
// 显示角色信息(使用正确的角色图标)
|
// 显示角色信息(使用正确的角色图标)
|
||||||
const loadedRoles = batchQueuesState.loadedRoles || [];
|
const loadedRoles = batchQueuesState.loadedRoles || [];
|
||||||
const roleIcon = getRoleIconForDisplay(queue.role, loadedRoles);
|
const roleIcon = getRoleIconForDisplay(queue.role, loadedRoles);
|
||||||
const roleName = queue.role && queue.role !== '' ? queue.role : '默认';
|
const roleName = queue.role && queue.role !== '' ? queue.role : _t('batchQueueDetailModal.defaultRole');
|
||||||
const roleDisplay = `<span class="batch-queue-role" style="margin-right: 8px;" title="角色: ${escapeHtml(roleName)}">${roleIcon} ${escapeHtml(roleName)}</span>`;
|
const roleDisplay = `<span class="batch-queue-role" style="margin-right: 8px;" title="${_t('batchQueueDetailModal.role')}: ${escapeHtml(roleName)}">${roleIcon} ${escapeHtml(roleName)}</span>`;
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<div class="batch-queue-item" data-queue-id="${queue.id}" onclick="showBatchQueueDetail('${queue.id}')">
|
<div class="batch-queue-item" data-queue-id="${queue.id}" onclick="showBatchQueueDetail('${queue.id}')">
|
||||||
@@ -1022,8 +1025,8 @@ function renderBatchQueues() {
|
|||||||
${titleDisplay}
|
${titleDisplay}
|
||||||
${roleDisplay}
|
${roleDisplay}
|
||||||
<span class="batch-queue-status ${status.class}">${status.text}</span>
|
<span class="batch-queue-status ${status.class}">${status.text}</span>
|
||||||
<span class="batch-queue-id">队列ID: ${escapeHtml(queue.id)}</span>
|
<span class="batch-queue-id">${_t('tasks.queueIdLabel')}: ${escapeHtml(queue.id)}</span>
|
||||||
<span class="batch-queue-time">创建时间: ${new Date(queue.createdAt).toLocaleString('zh-CN')}</span>
|
<span class="batch-queue-time">${_t('tasks.createdTimeLabel')}: ${new Date(queue.createdAt).toLocaleString()}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="batch-queue-progress">
|
<div class="batch-queue-progress">
|
||||||
<div class="batch-queue-progress-bar">
|
<div class="batch-queue-progress-bar">
|
||||||
@@ -1032,16 +1035,16 @@ function renderBatchQueues() {
|
|||||||
<span class="batch-queue-progress-text">${progress}% (${stats.completed + stats.failed + stats.cancelled}/${stats.total})</span>
|
<span class="batch-queue-progress-text">${progress}% (${stats.completed + stats.failed + stats.cancelled}/${stats.total})</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="batch-queue-actions" style="display: flex; align-items: center; gap: 8px; margin-left: 12px;" onclick="event.stopPropagation();">
|
<div class="batch-queue-actions" style="display: flex; align-items: center; gap: 8px; margin-left: 12px;" onclick="event.stopPropagation();">
|
||||||
${canDelete ? `<button class="btn-secondary btn-small btn-danger" onclick="deleteBatchQueueFromList('${queue.id}')" title="删除队列">删除</button>` : ''}
|
${canDelete ? `<button class="btn-secondary btn-small btn-danger" onclick="deleteBatchQueueFromList('${queue.id}')" title="${_t('tasks.deleteQueue')}">${_t('common.delete')}</button>` : ''}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="batch-queue-stats">
|
<div class="batch-queue-stats">
|
||||||
<span>总计: ${stats.total}</span>
|
<span>${_t('tasks.totalLabel')}: ${stats.total}</span>
|
||||||
<span>待执行: ${stats.pending}</span>
|
<span>${_t('tasks.pendingLabel')}: ${stats.pending}</span>
|
||||||
<span>执行中: ${stats.running}</span>
|
<span>${_t('tasks.runningLabel')}: ${stats.running}</span>
|
||||||
<span style="color: var(--success-color);">已完成: ${stats.completed}</span>
|
<span style="color: var(--success-color);">${_t('tasks.completedLabel')}: ${stats.completed}</span>
|
||||||
<span style="color: var(--error-color);">失败: ${stats.failed}</span>
|
<span style="color: var(--error-color);">${_t('tasks.failedLabel')}: ${stats.failed}</span>
|
||||||
${stats.cancelled > 0 ? `<span style="color: var(--text-secondary);">已取消: ${stats.cancelled}</span>` : ''}
|
${stats.cancelled > 0 ? `<span style="color: var(--text-secondary);">${_t('tasks.cancelledLabel')}: ${stats.cancelled}</span>` : ''}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@@ -1073,9 +1076,9 @@ function renderBatchQueuesPagination() {
|
|||||||
// 左侧:显示范围信息和每页数量选择器(参考Skills样式)
|
// 左侧:显示范围信息和每页数量选择器(参考Skills样式)
|
||||||
paginationHTML += `
|
paginationHTML += `
|
||||||
<div class="pagination-info">
|
<div class="pagination-info">
|
||||||
<span>显示 ${start}-${end} / 共 ${total} 条</span>
|
<span>` + _t('tasks.paginationShow', { start: start, end: end, total: total }) + `</span>
|
||||||
<label class="pagination-page-size">
|
<label class="pagination-page-size">
|
||||||
每页显示
|
` + _t('tasks.paginationPerPage') + `
|
||||||
<select id="batch-queues-page-size-pagination" onchange="changeBatchQueuesPageSize()">
|
<select id="batch-queues-page-size-pagination" onchange="changeBatchQueuesPageSize()">
|
||||||
<option value="10" ${pageSize === 10 ? 'selected' : ''}>10</option>
|
<option value="10" ${pageSize === 10 ? 'selected' : ''}>10</option>
|
||||||
<option value="20" ${pageSize === 20 ? 'selected' : ''}>20</option>
|
<option value="20" ${pageSize === 20 ? 'selected' : ''}>20</option>
|
||||||
@@ -1089,11 +1092,11 @@ function renderBatchQueuesPagination() {
|
|||||||
// 右侧:分页按钮(参考Skills样式:首页、上一页、第X/Y页、下一页、末页)
|
// 右侧:分页按钮(参考Skills样式:首页、上一页、第X/Y页、下一页、末页)
|
||||||
paginationHTML += `
|
paginationHTML += `
|
||||||
<div class="pagination-controls">
|
<div class="pagination-controls">
|
||||||
<button class="btn-secondary" onclick="goBatchQueuesPage(1)" ${currentPage === 1 || total === 0 ? 'disabled' : ''}>首页</button>
|
<button class="btn-secondary" onclick="goBatchQueuesPage(1)" ${currentPage === 1 || total === 0 ? 'disabled' : ''}>` + _t('tasks.paginationFirst') + `</button>
|
||||||
<button class="btn-secondary" onclick="goBatchQueuesPage(${currentPage - 1})" ${currentPage === 1 || total === 0 ? 'disabled' : ''}>上一页</button>
|
<button class="btn-secondary" onclick="goBatchQueuesPage(${currentPage - 1})" ${currentPage === 1 || total === 0 ? 'disabled' : ''}>` + _t('tasks.paginationPrev') + `</button>
|
||||||
<span class="pagination-page">第 ${currentPage} / ${totalPages || 1} 页</span>
|
<span class="pagination-page">` + _t('tasks.paginationPage', { current: currentPage, total: totalPages || 1 }) + `</span>
|
||||||
<button class="btn-secondary" onclick="goBatchQueuesPage(${currentPage + 1})" ${currentPage >= totalPages || total === 0 ? 'disabled' : ''}>下一页</button>
|
<button class="btn-secondary" onclick="goBatchQueuesPage(${currentPage + 1})" ${currentPage >= totalPages || total === 0 ? 'disabled' : ''}>` + _t('tasks.paginationNext') + `</button>
|
||||||
<button class="btn-secondary" onclick="goBatchQueuesPage(${totalPages || 1})" ${currentPage >= totalPages || total === 0 ? 'disabled' : ''}>末页</button>
|
<button class="btn-secondary" onclick="goBatchQueuesPage(${totalPages || 1})" ${currentPage >= totalPages || total === 0 ? 'disabled' : ''}>` + _t('tasks.paginationLast') + `</button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -1189,7 +1192,7 @@ async function showBatchQueueDetail(queueId) {
|
|||||||
|
|
||||||
const response = await apiFetch(`/api/batch-tasks/${queueId}`);
|
const response = await apiFetch(`/api/batch-tasks/${queueId}`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('获取队列详情失败');
|
throw new Error(_t('tasks.getQueueDetailFailed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
@@ -1198,7 +1201,7 @@ async function showBatchQueueDetail(queueId) {
|
|||||||
|
|
||||||
if (title) {
|
if (title) {
|
||||||
// textContent 本身会做转义;这里不要再 escapeHtml,否则会把 && 显示成 &...(看起来像“变形/乱码”)
|
// textContent 本身会做转义;这里不要再 escapeHtml,否则会把 && 显示成 &...(看起来像“变形/乱码”)
|
||||||
title.textContent = queue.title ? `批量任务队列 - ${String(queue.title)}` : '批量任务队列';
|
title.textContent = queue.title ? _t('tasks.batchQueueTitle') + ' - ' + String(queue.title) : _t('tasks.batchQueueTitle');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新按钮显示
|
// 更新按钮显示
|
||||||
@@ -1210,9 +1213,9 @@ async function showBatchQueueDetail(queueId) {
|
|||||||
// pending状态显示"开始执行",paused状态显示"继续执行"
|
// pending状态显示"开始执行",paused状态显示"继续执行"
|
||||||
startBtn.style.display = (queue.status === 'pending' || queue.status === 'paused') ? 'inline-block' : 'none';
|
startBtn.style.display = (queue.status === 'pending' || queue.status === 'paused') ? 'inline-block' : 'none';
|
||||||
if (startBtn && queue.status === 'paused') {
|
if (startBtn && queue.status === 'paused') {
|
||||||
startBtn.textContent = '继续执行';
|
startBtn.textContent = _t('tasks.resumeExecute');
|
||||||
} else if (startBtn && queue.status === 'pending') {
|
} else if (startBtn && queue.status === 'pending') {
|
||||||
startBtn.textContent = '开始执行';
|
startBtn.textContent = _t('batchQueueDetailModal.startExecute');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pauseBtn) {
|
if (pauseBtn) {
|
||||||
@@ -1226,20 +1229,20 @@ async function showBatchQueueDetail(queueId) {
|
|||||||
|
|
||||||
// 队列状态映射
|
// 队列状态映射
|
||||||
const queueStatusMap = {
|
const queueStatusMap = {
|
||||||
'pending': { text: '待执行', class: 'batch-queue-status-pending' },
|
'pending': { text: _t('tasks.statusPending'), class: 'batch-queue-status-pending' },
|
||||||
'running': { text: '执行中', class: 'batch-queue-status-running' },
|
'running': { text: _t('tasks.statusRunning'), class: 'batch-queue-status-running' },
|
||||||
'paused': { text: '已暂停', class: 'batch-queue-status-paused' },
|
'paused': { text: _t('tasks.statusPaused'), class: 'batch-queue-status-paused' },
|
||||||
'completed': { text: '已完成', class: 'batch-queue-status-completed' },
|
'completed': { text: _t('tasks.statusCompleted'), class: 'batch-queue-status-completed' },
|
||||||
'cancelled': { text: '已取消', class: 'batch-queue-status-cancelled' }
|
'cancelled': { text: _t('tasks.statusCancelled'), class: 'batch-queue-status-cancelled' }
|
||||||
};
|
};
|
||||||
|
|
||||||
// 任务状态映射
|
// 任务状态映射
|
||||||
const taskStatusMap = {
|
const taskStatusMap = {
|
||||||
'pending': { text: '待执行', class: 'batch-task-status-pending' },
|
'pending': { text: _t('tasks.statusPending'), class: 'batch-task-status-pending' },
|
||||||
'running': { text: '执行中', class: 'batch-task-status-running' },
|
'running': { text: _t('tasks.statusRunning'), class: 'batch-task-status-running' },
|
||||||
'completed': { text: '已完成', class: 'batch-task-status-completed' },
|
'completed': { text: _t('tasks.statusCompleted'), class: 'batch-task-status-completed' },
|
||||||
'failed': { text: '失败', class: 'batch-task-status-failed' },
|
'failed': { text: _t('tasks.failedLabel'), class: 'batch-task-status-failed' },
|
||||||
'cancelled': { text: '已取消', class: 'batch-task-status-cancelled' }
|
'cancelled': { text: _t('tasks.statusCancelled'), class: 'batch-task-status-cancelled' }
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取角色信息(如果队列有角色配置)
|
// 获取角色信息(如果队列有角色配置)
|
||||||
@@ -1266,51 +1269,51 @@ async function showBatchQueueDetail(queueId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
roleDisplay = `<div class="detail-item">
|
roleDisplay = `<div class="detail-item">
|
||||||
<span class="detail-label">角色</span>
|
<span class="detail-label">` + _t('batchQueueDetailModal.role') + `</span>
|
||||||
<span class="detail-value">${roleIcon} ${escapeHtml(roleName)}</span>
|
<span class="detail-value">${roleIcon} ${escapeHtml(roleName)}</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
} else {
|
} else {
|
||||||
// 默认角色
|
// 默认角色
|
||||||
roleDisplay = `<div class="detail-item">
|
roleDisplay = `<div class="detail-item">
|
||||||
<span class="detail-label">角色</span>
|
<span class="detail-label">` + _t('batchQueueDetailModal.role') + `</span>
|
||||||
<span class="detail-value">🔵 默认</span>
|
<span class="detail-value">🔵 ` + _t('batchQueueDetailModal.defaultRole') + `</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
content.innerHTML = `
|
content.innerHTML = `
|
||||||
<div class="batch-queue-detail-info">
|
<div class="batch-queue-detail-info">
|
||||||
${queue.title ? `<div class="detail-item">
|
${queue.title ? `<div class="detail-item">
|
||||||
<span class="detail-label">任务标题</span>
|
<span class="detail-label">` + _t('batchQueueDetailModal.queueTitle') + `</span>
|
||||||
<span class="detail-value">${escapeHtml(queue.title)}</span>
|
<span class="detail-value">${escapeHtml(queue.title)}</span>
|
||||||
</div>` : ''}
|
</div>` : ''}
|
||||||
${roleDisplay}
|
${roleDisplay}
|
||||||
<div class="detail-item">
|
<div class="detail-item">
|
||||||
<span class="detail-label">队列ID</span>
|
<span class="detail-label">` + _t('batchQueueDetailModal.queueId') + `</span>
|
||||||
<span class="detail-value"><code>${escapeHtml(queue.id)}</code></span>
|
<span class="detail-value"><code>${escapeHtml(queue.id)}</code></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="detail-item">
|
<div class="detail-item">
|
||||||
<span class="detail-label">状态</span>
|
<span class="detail-label">` + _t('batchQueueDetailModal.status') + `</span>
|
||||||
<span class="detail-value"><span class="batch-queue-status ${queueStatusMap[queue.status]?.class || ''}">${queueStatusMap[queue.status]?.text || queue.status}</span></span>
|
<span class="detail-value"><span class="batch-queue-status ${queueStatusMap[queue.status]?.class || ''}">${queueStatusMap[queue.status]?.text || queue.status}</span></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="detail-item">
|
<div class="detail-item">
|
||||||
<span class="detail-label">创建时间</span>
|
<span class="detail-label">` + _t('batchQueueDetailModal.createdAt') + `</span>
|
||||||
<span class="detail-value">${new Date(queue.createdAt).toLocaleString('zh-CN')}</span>
|
<span class="detail-value">${new Date(queue.createdAt).toLocaleString()}</span>
|
||||||
</div>
|
</div>
|
||||||
${queue.startedAt ? `<div class="detail-item">
|
${queue.startedAt ? `<div class="detail-item">
|
||||||
<span class="detail-label">开始时间</span>
|
<span class="detail-label">` + _t('batchQueueDetailModal.startedAt') + `</span>
|
||||||
<span class="detail-value">${new Date(queue.startedAt).toLocaleString('zh-CN')}</span>
|
<span class="detail-value">${new Date(queue.startedAt).toLocaleString()}</span>
|
||||||
</div>` : ''}
|
</div>` : ''}
|
||||||
${queue.completedAt ? `<div class="detail-item">
|
${queue.completedAt ? `<div class="detail-item">
|
||||||
<span class="detail-label">完成时间</span>
|
<span class="detail-label">` + _t('batchQueueDetailModal.completedAt') + `</span>
|
||||||
<span class="detail-value">${new Date(queue.completedAt).toLocaleString('zh-CN')}</span>
|
<span class="detail-value">${new Date(queue.completedAt).toLocaleString()}</span>
|
||||||
</div>` : ''}
|
</div>` : ''}
|
||||||
<div class="detail-item">
|
<div class="detail-item">
|
||||||
<span class="detail-label">任务总数</span>
|
<span class="detail-label">` + _t('batchQueueDetailModal.taskTotal') + `</span>
|
||||||
<span class="detail-value">${queue.tasks.length}</span>
|
<span class="detail-value">${queue.tasks.length}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="batch-queue-tasks-list">
|
<div class="batch-queue-tasks-list">
|
||||||
<h4>任务列表</h4>
|
<h4>` + _t('batchQueueDetailModal.taskList') + `</h4>
|
||||||
${queue.tasks.map((task, index) => {
|
${queue.tasks.map((task, index) => {
|
||||||
const taskStatus = taskStatusMap[task.status] || { text: task.status, class: 'batch-task-status-unknown' };
|
const taskStatus = taskStatusMap[task.status] || { text: task.status, class: 'batch-task-status-unknown' };
|
||||||
const canEdit = queue.status === 'pending' && task.status === 'pending';
|
const canEdit = queue.status === 'pending' && task.status === 'pending';
|
||||||
@@ -1321,14 +1324,14 @@ async function showBatchQueueDetail(queueId) {
|
|||||||
<span class="batch-task-index">#${index + 1}</span>
|
<span class="batch-task-index">#${index + 1}</span>
|
||||||
<span class="batch-task-status ${taskStatus.class}">${taskStatus.text}</span>
|
<span class="batch-task-status ${taskStatus.class}">${taskStatus.text}</span>
|
||||||
<span class="batch-task-message" title="${escapeHtml(task.message)}">${escapeHtml(task.message)}</span>
|
<span class="batch-task-message" title="${escapeHtml(task.message)}">${escapeHtml(task.message)}</span>
|
||||||
${canEdit ? `<button class="btn-secondary btn-small batch-task-edit-btn" onclick="editBatchTaskFromElement(this); event.stopPropagation();">编辑</button>` : ''}
|
${canEdit ? `<button class="btn-secondary btn-small batch-task-edit-btn" onclick="editBatchTaskFromElement(this); event.stopPropagation();">` + _t('common.edit') + `</button>` : ''}
|
||||||
${canEdit ? `<button class="btn-secondary btn-small btn-danger batch-task-delete-btn" onclick="deleteBatchTaskFromElement(this); event.stopPropagation();">删除</button>` : ''}
|
${canEdit ? `<button class="btn-secondary btn-small btn-danger batch-task-delete-btn" onclick="deleteBatchTaskFromElement(this); event.stopPropagation();">` + _t('common.delete') + `</button>` : ''}
|
||||||
${task.conversationId ? `<button class="btn-secondary btn-small" onclick="viewBatchTaskConversation('${task.conversationId}'); event.stopPropagation();">查看对话</button>` : ''}
|
${task.conversationId ? `<button class="btn-secondary btn-small" onclick="viewBatchTaskConversation('${task.conversationId}'); event.stopPropagation();">` + _t('tasks.viewConversation') + `</button>` : ''}
|
||||||
</div>
|
</div>
|
||||||
${task.startedAt ? `<div class="batch-task-time">开始: ${new Date(task.startedAt).toLocaleString('zh-CN')}</div>` : ''}
|
${task.startedAt ? `<div class="batch-task-time">` + _t('batchQueueDetailModal.startLabel') + `: ${new Date(task.startedAt).toLocaleString()}</div>` : ''}
|
||||||
${task.completedAt ? `<div class="batch-task-time">完成: ${new Date(task.completedAt).toLocaleString('zh-CN')}</div>` : ''}
|
${task.completedAt ? `<div class="batch-task-time">` + _t('batchQueueDetailModal.completeLabel') + `: ${new Date(task.completedAt).toLocaleString()}</div>` : ''}
|
||||||
${task.error ? `<div class="batch-task-error">错误: ${escapeHtml(task.error)}</div>` : ''}
|
${task.error ? `<div class="batch-task-error">` + _t('batchQueueDetailModal.errorLabel') + `: ${escapeHtml(task.error)}</div>` : ''}
|
||||||
${task.result ? `<div class="batch-task-result">结果: ${escapeHtml(task.result.substring(0, 200))}${task.result.length > 200 ? '...' : ''}</div>` : ''}
|
${task.result ? `<div class="batch-task-result">` + _t('batchQueueDetailModal.resultLabel') + `: ${escapeHtml(task.result.substring(0, 200))}${task.result.length > 200 ? '...' : ''}</div>` : ''}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}).join('')}
|
}).join('')}
|
||||||
@@ -1343,7 +1346,7 @@ async function showBatchQueueDetail(queueId) {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取队列详情失败:', error);
|
console.error('获取队列详情失败:', error);
|
||||||
alert('获取队列详情失败: ' + error.message);
|
alert(_t('tasks.getQueueDetailFailed') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1359,7 +1362,7 @@ async function startBatchQueue() {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
throw new Error(result.error || '启动批量任务失败');
|
throw new Error(result.error || _t('tasks.startBatchQueueFailed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新详情
|
// 刷新详情
|
||||||
@@ -1367,7 +1370,7 @@ async function startBatchQueue() {
|
|||||||
refreshBatchQueues();
|
refreshBatchQueues();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('启动批量任务失败:', error);
|
console.error('启动批量任务失败:', error);
|
||||||
alert('启动批量任务失败: ' + error.message);
|
alert(_t('tasks.startBatchQueueFailed') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1376,7 +1379,7 @@ async function pauseBatchQueue() {
|
|||||||
const queueId = batchQueuesState.currentQueueId;
|
const queueId = batchQueuesState.currentQueueId;
|
||||||
if (!queueId) return;
|
if (!queueId) return;
|
||||||
|
|
||||||
if (!confirm('确定要暂停这个批量任务队列吗?当前正在执行的任务将被停止,后续任务将保留待执行状态。')) {
|
if (!confirm(_t('tasks.pauseQueueConfirm'))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1387,7 +1390,7 @@ async function pauseBatchQueue() {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
throw new Error(result.error || '暂停批量任务失败');
|
throw new Error(result.error || _t('tasks.pauseQueueFailed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新详情
|
// 刷新详情
|
||||||
@@ -1395,7 +1398,7 @@ async function pauseBatchQueue() {
|
|||||||
refreshBatchQueues();
|
refreshBatchQueues();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('暂停批量任务失败:', error);
|
console.error('暂停批量任务失败:', error);
|
||||||
alert('暂停批量任务失败: ' + error.message);
|
alert(_t('tasks.pauseQueueFailed') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1404,7 +1407,7 @@ async function deleteBatchQueue() {
|
|||||||
const queueId = batchQueuesState.currentQueueId;
|
const queueId = batchQueuesState.currentQueueId;
|
||||||
if (!queueId) return;
|
if (!queueId) return;
|
||||||
|
|
||||||
if (!confirm('确定要删除这个批量任务队列吗?此操作不可恢复。')) {
|
if (!confirm(_t('tasks.deleteQueueConfirm'))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1415,14 +1418,14 @@ async function deleteBatchQueue() {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
throw new Error(result.error || '删除批量任务队列失败');
|
throw new Error(result.error || _t('tasks.deleteQueueFailed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
closeBatchQueueDetailModal();
|
closeBatchQueueDetailModal();
|
||||||
refreshBatchQueues();
|
refreshBatchQueues();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('删除批量任务队列失败:', error);
|
console.error('删除批量任务队列失败:', error);
|
||||||
alert('删除批量任务队列失败: ' + error.message);
|
alert(_t('tasks.deleteQueueFailed') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1430,7 +1433,7 @@ async function deleteBatchQueue() {
|
|||||||
async function deleteBatchQueueFromList(queueId) {
|
async function deleteBatchQueueFromList(queueId) {
|
||||||
if (!queueId) return;
|
if (!queueId) return;
|
||||||
|
|
||||||
if (!confirm('确定要删除这个批量任务队列吗?此操作不可恢复。')) {
|
if (!confirm(_t('tasks.deleteQueueConfirm'))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1441,7 +1444,7 @@ async function deleteBatchQueueFromList(queueId) {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
throw new Error(result.error || '删除批量任务队列失败');
|
throw new Error(result.error || _t('tasks.deleteQueueFailed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果当前正在查看这个队列的详情,关闭详情模态框
|
// 如果当前正在查看这个队列的详情,关闭详情模态框
|
||||||
@@ -1453,7 +1456,7 @@ async function deleteBatchQueueFromList(queueId) {
|
|||||||
refreshBatchQueues();
|
refreshBatchQueues();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('删除批量任务队列失败:', error);
|
console.error('删除批量任务队列失败:', error);
|
||||||
alert('删除批量任务队列失败: ' + error.message);
|
alert(_t('tasks.deleteQueueFailed') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1599,18 +1602,18 @@ async function saveBatchTask() {
|
|||||||
const messageInput = document.getElementById('edit-task-message');
|
const messageInput = document.getElementById('edit-task-message');
|
||||||
|
|
||||||
if (!queueId || !taskId) {
|
if (!queueId || !taskId) {
|
||||||
alert('任务信息不完整');
|
alert(_t('tasks.taskIncomplete'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!messageInput) {
|
if (!messageInput) {
|
||||||
alert('无法获取任务消息输入框');
|
alert(_t('tasks.cannotGetTaskMessageInput'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = messageInput.value.trim();
|
const message = messageInput.value.trim();
|
||||||
if (!message) {
|
if (!message) {
|
||||||
alert('任务消息不能为空');
|
alert(_t('tasks.taskMessageRequired'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1625,7 +1628,7 @@ async function saveBatchTask() {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
throw new Error(result.error || '更新任务失败');
|
throw new Error(result.error || _t('tasks.updateTaskFailed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关闭编辑模态框
|
// 关闭编辑模态框
|
||||||
@@ -1640,7 +1643,7 @@ async function saveBatchTask() {
|
|||||||
refreshBatchQueues();
|
refreshBatchQueues();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('保存任务失败:', error);
|
console.error('保存任务失败:', error);
|
||||||
alert('保存任务失败: ' + error.message);
|
alert(_t('tasks.saveTaskFailed') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1648,7 +1651,7 @@ async function saveBatchTask() {
|
|||||||
function showAddBatchTaskModal() {
|
function showAddBatchTaskModal() {
|
||||||
const queueId = batchQueuesState.currentQueueId;
|
const queueId = batchQueuesState.currentQueueId;
|
||||||
if (!queueId) {
|
if (!queueId) {
|
||||||
alert('队列信息不存在');
|
alert(_t('tasks.queueInfoMissing'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1706,18 +1709,18 @@ async function saveAddBatchTask() {
|
|||||||
const messageInput = document.getElementById('add-task-message');
|
const messageInput = document.getElementById('add-task-message');
|
||||||
|
|
||||||
if (!queueId) {
|
if (!queueId) {
|
||||||
alert('队列信息不存在');
|
alert(_t('tasks.queueInfoMissing'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!messageInput) {
|
if (!messageInput) {
|
||||||
alert('无法获取任务消息输入框');
|
alert(_t('tasks.cannotGetTaskMessageInput'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = messageInput.value.trim();
|
const message = messageInput.value.trim();
|
||||||
if (!message) {
|
if (!message) {
|
||||||
alert('任务消息不能为空');
|
alert(_t('tasks.taskMessageRequired'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1732,7 +1735,7 @@ async function saveAddBatchTask() {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
throw new Error(result.error || '添加任务失败');
|
throw new Error(result.error || _t('tasks.addTaskFailed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关闭添加任务模态框
|
// 关闭添加任务模态框
|
||||||
@@ -1747,7 +1750,7 @@ async function saveAddBatchTask() {
|
|||||||
refreshBatchQueues();
|
refreshBatchQueues();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('添加任务失败:', error);
|
console.error('添加任务失败:', error);
|
||||||
alert('添加任务失败: ' + error.message);
|
alert(_t('tasks.addTaskFailed') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1779,7 +1782,7 @@ function deleteBatchTaskFromElement(button) {
|
|||||||
? decodedMessage.substring(0, 50) + '...'
|
? decodedMessage.substring(0, 50) + '...'
|
||||||
: decodedMessage;
|
: decodedMessage;
|
||||||
|
|
||||||
if (!confirm(`确定要删除这个任务吗?\n\n任务内容: ${displayMessage}\n\n此操作不可恢复。`)) {
|
if (!confirm(_t('tasks.confirmDeleteTask', { message: displayMessage }))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1789,7 +1792,7 @@ function deleteBatchTaskFromElement(button) {
|
|||||||
// 删除批量任务
|
// 删除批量任务
|
||||||
async function deleteBatchTask(queueId, taskId) {
|
async function deleteBatchTask(queueId, taskId) {
|
||||||
if (!queueId || !taskId) {
|
if (!queueId || !taskId) {
|
||||||
alert('任务信息不完整');
|
alert(_t('tasks.taskIncomplete'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1800,7 +1803,7 @@ async function deleteBatchTask(queueId, taskId) {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
throw new Error(result.error || '删除任务失败');
|
throw new Error(result.error || _t('tasks.deleteTaskFailed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新队列详情
|
// 刷新队列详情
|
||||||
@@ -1812,7 +1815,7 @@ async function deleteBatchTask(queueId, taskId) {
|
|||||||
refreshBatchQueues();
|
refreshBatchQueues();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('删除任务失败:', error);
|
console.error('删除任务失败:', error);
|
||||||
alert('删除任务失败: ' + error.message);
|
alert(_t('tasks.deleteTaskFailed') + ': ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,22 @@
|
|||||||
|
|
||||||
ws.onmessage = function (ev) {
|
ws.onmessage = function (ev) {
|
||||||
if (!tab.term) return;
|
if (!tab.term) return;
|
||||||
tab.term.write(ev.data);
|
// 处理二进制消息和文本消息
|
||||||
|
if (ev.data instanceof ArrayBuffer) {
|
||||||
|
var decoder = new TextDecoder('utf-8');
|
||||||
|
tab.term.write(decoder.decode(ev.data));
|
||||||
|
} else if (ev.data instanceof Blob) {
|
||||||
|
// Blob 类型,需要异步读取
|
||||||
|
var reader = new FileReader();
|
||||||
|
reader.onload = function () {
|
||||||
|
var decoder = new TextDecoder('utf-8');
|
||||||
|
tab.term.write(decoder.decode(reader.result));
|
||||||
|
};
|
||||||
|
reader.readAsArrayBuffer(ev.data);
|
||||||
|
} else {
|
||||||
|
// 字符串类型
|
||||||
|
tab.term.write(ev.data);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = function () {
|
ws.onclose = function () {
|
||||||
|
|||||||
@@ -156,14 +156,20 @@ async function loadVulnerabilities(page = null) {
|
|||||||
function renderVulnerabilities(vulnerabilities) {
|
function renderVulnerabilities(vulnerabilities) {
|
||||||
const listContainer = document.getElementById('vulnerabilities-list');
|
const listContainer = document.getElementById('vulnerabilities-list');
|
||||||
|
|
||||||
// 处理空值情况
|
// 处理空值情况(使用 data-i18n 以便语言切换时自动更新)
|
||||||
if (!vulnerabilities || !Array.isArray(vulnerabilities)) {
|
if (!vulnerabilities || !Array.isArray(vulnerabilities)) {
|
||||||
listContainer.innerHTML = '<div class="empty-state">暂无漏洞记录</div>';
|
listContainer.innerHTML = '<div class="empty-state" data-i18n="vulnerabilityPage.noRecords">暂无漏洞记录</div>';
|
||||||
|
if (typeof window.applyTranslations === 'function') {
|
||||||
|
window.applyTranslations(listContainer);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vulnerabilities.length === 0) {
|
if (vulnerabilities.length === 0) {
|
||||||
listContainer.innerHTML = '<div class="empty-state">暂无漏洞记录</div>';
|
listContainer.innerHTML = '<div class="empty-state" data-i18n="vulnerabilityPage.noRecords">暂无漏洞记录</div>';
|
||||||
|
if (typeof window.applyTranslations === 'function') {
|
||||||
|
window.applyTranslations(listContainer);
|
||||||
|
}
|
||||||
// 清空分页信息
|
// 清空分页信息
|
||||||
const paginationContainer = document.getElementById('vulnerability-pagination');
|
const paginationContainer = document.getElementById('vulnerability-pagination');
|
||||||
if (paginationContainer) {
|
if (paginationContainer) {
|
||||||
@@ -328,7 +334,7 @@ async function changeVulnerabilityPageSize() {
|
|||||||
// 显示添加漏洞模态框
|
// 显示添加漏洞模态框
|
||||||
function showAddVulnerabilityModal() {
|
function showAddVulnerabilityModal() {
|
||||||
currentVulnerabilityId = null;
|
currentVulnerabilityId = null;
|
||||||
document.getElementById('vulnerability-modal-title').textContent = '添加漏洞';
|
document.getElementById('vulnerability-modal-title').textContent = (typeof window.t === 'function' ? window.t('vulnerability.addVuln') : '添加漏洞');
|
||||||
|
|
||||||
// 清空表单
|
// 清空表单
|
||||||
document.getElementById('vulnerability-conversation-id').value = '';
|
document.getElementById('vulnerability-conversation-id').value = '';
|
||||||
@@ -353,7 +359,7 @@ async function editVulnerability(id) {
|
|||||||
|
|
||||||
const vuln = await response.json();
|
const vuln = await response.json();
|
||||||
currentVulnerabilityId = id;
|
currentVulnerabilityId = id;
|
||||||
document.getElementById('vulnerability-modal-title').textContent = '编辑漏洞';
|
document.getElementById('vulnerability-modal-title').textContent = (typeof window.t === 'function' ? window.t('vulnerability.editVuln') : '编辑漏洞');
|
||||||
|
|
||||||
// 填充表单
|
// 填充表单
|
||||||
document.getElementById('vulnerability-conversation-id').value = vuln.conversation_id || '';
|
document.getElementById('vulnerability-conversation-id').value = vuln.conversation_id || '';
|
||||||
|
|||||||
+498
-450
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user