hydro-ai-helper 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -97
- package/README_en.md +210 -0
- package/dist/handlers/studentHandler.js +12 -6
- package/dist/handlers/studentHandler.js.map +1 -1
- package/dist/handlers/testdataGenHandler.js +20 -10
- package/dist/handlers/testdataGenHandler.js.map +1 -1
- package/dist/services/testdataGenService.js +296 -28
- package/dist/services/testdataGenService.js.map +1 -1
- package/frontend/generated/localeFallback.ts +8 -2
- package/frontend/testdataGen/TestdataGenPanel.tsx +32 -2
- package/locales/en.yaml +4 -1
- package/locales/zh.yaml +4 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# HydroOJ AI
|
|
1
|
+
# HydroOJ AI 学习助手
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**中文 | [English](README_en.md)**
|
|
6
6
|
|
|
7
|
-
](https://img.shields.io/github/v/release/AltureT/hydro-ai-helper?label=版本)
|
|
8
|
+

|
|
9
9
|

|
|
10
10
|

|
|
11
11
|

|
|
@@ -15,138 +15,139 @@
|
|
|
15
15
|
|
|
16
16
|
</div>
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
一个以教学为优先的 [HydroOJ](https://github.com/hydro-dev/Hydro) AI 辅助学习插件 — 引导思考,不给答案。支持中英文界面。
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## 截图预览
|
|
21
21
|
|
|
22
|
-
<img src="assets/screenshots/1.png" alt="
|
|
22
|
+
<img src="assets/screenshots/1.png" alt="学生端 - AI 对话" width="800">
|
|
23
23
|
|
|
24
24
|
<details>
|
|
25
|
-
<summary><b>AI
|
|
25
|
+
<summary><b>AI 生成测试数据</b></summary>
|
|
26
26
|
|
|
27
|
-
<img src="assets/screenshots/10.png" alt="
|
|
27
|
+
<img src="assets/screenshots/10.png" alt="题目文件页 - AI 生成测试数据面板" width="800">
|
|
28
28
|
|
|
29
29
|
</details>
|
|
30
30
|
|
|
31
31
|
<details>
|
|
32
|
-
<summary><b
|
|
32
|
+
<summary><b>批量 AI 学习总结</b></summary>
|
|
33
33
|
|
|
34
|
-
<img src="assets/screenshots/8.png" alt="
|
|
34
|
+
<img src="assets/screenshots/8.png" alt="学习总结 - 成绩表集成" width="800">
|
|
35
35
|
|
|
36
|
-
<img src="assets/screenshots/9.png" alt="
|
|
36
|
+
<img src="assets/screenshots/9.png" alt="学习总结 - 生成结果" width="800">
|
|
37
37
|
|
|
38
38
|
</details>
|
|
39
39
|
|
|
40
40
|
<details>
|
|
41
|
-
<summary><b
|
|
41
|
+
<summary><b>管理后台截图</b></summary>
|
|
42
42
|
|
|
43
|
-
<img src="assets/screenshots/4.png" alt="
|
|
43
|
+
<img src="assets/screenshots/4.png" alt="后台 - 对话记录" width="800">
|
|
44
44
|
|
|
45
|
-
<img src="assets/screenshots/5.png" alt="
|
|
45
|
+
<img src="assets/screenshots/5.png" alt="后台 - 使用统计" width="800">
|
|
46
46
|
|
|
47
|
-
<img src="assets/screenshots/6.png" alt="
|
|
47
|
+
<img src="assets/screenshots/6.png" alt="后台 - AI 配置" width="800">
|
|
48
48
|
|
|
49
|
-
<img src="assets/screenshots/7.png" alt="
|
|
49
|
+
<img src="assets/screenshots/7.png" alt="后台 - 成本看板" width="500">
|
|
50
50
|
|
|
51
51
|
</details>
|
|
52
52
|
|
|
53
|
-
##
|
|
53
|
+
## 功能特性
|
|
54
54
|
|
|
55
|
-
###
|
|
55
|
+
### 学生端
|
|
56
56
|
|
|
57
|
-
- AI
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
57
|
+
- 题目页 AI 对话面板,SSE 实时流式响应,LaTeX 公式自动渲染
|
|
58
|
+
- 差异化问题类型:**理解题意** / **理清思路** / **分析错误** / **代码优化**(AC 后专属)
|
|
59
|
+
- 多轮对话自动恢复;选中不理解的文字一键追问
|
|
60
|
+
- 在成绩表页面查看教师发布的个性化 AI 学习总结
|
|
61
61
|
|
|
62
|
-
###
|
|
62
|
+
### 教师端
|
|
63
63
|
|
|
64
|
-
- **AI
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
-
|
|
71
|
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
64
|
+
- **AI 生成测试数据** — 在题目文件页(`/p/:pid/files`)根据题面一键生成完整测试数据
|
|
65
|
+
- **沙箱实跑 + 双重验证**:数据生成器与标程在 Hydro 判题沙箱中实际运行产出 `.in`/`.out`,并经过独立暴力解对拍、输入校验、模板实跑与题面样例回归四道机器关卡;验证失败按生成器/标程/模板阶段定向修复
|
|
66
|
+
- 默认根据题面自动混合生成小、中、临界规模并交叉覆盖多项约束;也可定向选择单一规模。新增数据自动避开已有数字测试点并合并生成 `config.yaml`
|
|
67
|
+
- 支持传统题、LeetCode 风格函数题(自动生成 `template.py/java/cc` 与 `compile.sh`)与填空题(完善代码)
|
|
68
|
+
- 可粘贴已有标准答案作为输出的唯一权威;`config.yaml` 评测配置确定性生成,写入后评测设置自动同步
|
|
69
|
+
- 生成的每个代码文件(std.py、generator.py、validator.py 等)首行注明用途;全量预览、可编辑、勾选确认后才写入
|
|
70
|
+
- ⚠️ 对模型能力非常敏感:请在场景模型中为「测试数据生成」配置最强模型;另有骨架模式(不调用 AI)兜底
|
|
71
|
+
- **教学分析** — 从全班提交数据发现教学问题,生成可操作的教学建议
|
|
72
|
+
- 8 维度规则引擎(常见错误 / 理解障碍 / 高危学生 / 进步趋势等)+ 错误签名聚类 + 时序行为模式分类
|
|
73
|
+
- LLM 生成 P0/P1/P2 优先级教学建议 — 具体课堂行动,非泛泛而谈;可从 AC 代码自动生成填空练习
|
|
74
|
+
- **批量 AI 学习总结** — 成绩表页面一键为每位学生生成个性化学习总结
|
|
75
|
+
- 跨作业历史追踪 + 基于里程碑的智能提交采样;迟到学生可单独补充生成
|
|
76
|
+
- 草稿/发布工作流,SSE 实时进度,停止/继续/重试控制
|
|
77
|
+
- 对话记录浏览(时间/题目/班级/学生筛选,自动补全)、有效性指标、CSV 导出(支持脱敏)
|
|
77
78
|
|
|
78
|
-
###
|
|
79
|
+
### 管理员端
|
|
79
80
|
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
84
|
-
-
|
|
81
|
+
- 统一入口:对话记录/使用统计/AI 配置 Tab 切换
|
|
82
|
+
- 多端点 API 管理,自动获取模型列表,拖拽排序优先级,自动 Failover
|
|
83
|
+
- 场景模型分配:学生对话/学习总结/教学分析/测试数据生成可分别指定专属模型
|
|
84
|
+
- 成本控制:Token 用量追踪、预算限制、成本看板
|
|
85
|
+
- 频率限制、自定义系统提示词、一键更新
|
|
85
86
|
|
|
86
87
|
<details>
|
|
87
|
-
<summary><b
|
|
88
|
+
<summary><b>安全特性</b></summary>
|
|
88
89
|
|
|
89
|
-
-
|
|
90
|
-
- CSRF
|
|
91
|
-
- AI
|
|
92
|
-
-
|
|
90
|
+
- 多层级越狱检测(输入/提示词/输出),跨轮次防护
|
|
91
|
+
- CSRF Token 校验、SSRF 防护、API Key AES-256-GCM 加密存储
|
|
92
|
+
- AI 生成的代码只在 go-judge 沙箱中执行,不进入 Web 进程
|
|
93
|
+
- 越狱记录分页审计
|
|
93
94
|
|
|
94
95
|
</details>
|
|
95
96
|
|
|
96
|
-
##
|
|
97
|
+
## 安装
|
|
97
98
|
|
|
98
99
|
```bash
|
|
99
|
-
#
|
|
100
|
+
# 克隆(二选一)
|
|
100
101
|
git clone https://github.com/AltureT/hydro-ai-helper.git # GitHub
|
|
101
|
-
git clone https://gitee.com/alture/hydro-ai-helper.git # Gitee
|
|
102
|
+
git clone https://gitee.com/alture/hydro-ai-helper.git # Gitee(镜像)
|
|
102
103
|
|
|
103
104
|
cd hydro-ai-helper
|
|
104
105
|
npm install
|
|
105
106
|
npm run build:plugin
|
|
106
107
|
|
|
107
|
-
#
|
|
108
|
+
# 安装到 HydroOJ
|
|
108
109
|
hydrooj addon add /path/to/hydro-ai-helper
|
|
109
110
|
pm2 restart hydrooj
|
|
110
111
|
```
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
验证:访问 `/ai-helper/hello` 返回 JSON 即表示成功。
|
|
113
114
|
|
|
114
|
-
##
|
|
115
|
+
## 配置
|
|
115
116
|
|
|
116
|
-
###
|
|
117
|
+
### 环境变量
|
|
117
118
|
|
|
118
|
-
`ENCRYPTION_KEY
|
|
119
|
+
`ENCRYPTION_KEY`(必需,32 字符)— 加密 API Key:
|
|
119
120
|
|
|
120
121
|
```bash
|
|
121
|
-
export ENCRYPTION_KEY="your-32-character-secret-key!!!" #
|
|
122
|
+
export ENCRYPTION_KEY="your-32-character-secret-key!!!" # 生成:openssl rand -base64 24 | head -c 32
|
|
122
123
|
```
|
|
123
124
|
|
|
124
|
-
`AI_HELPER_UPDATE_CHANNEL
|
|
125
|
+
`AI_HELPER_UPDATE_CHANNEL`(可选)— 应用内一键更新通道:
|
|
125
126
|
|
|
126
|
-
- `stable
|
|
127
|
-
- `edge` —
|
|
127
|
+
- `stable`(默认)— 只更新到正式发布版本(`vX.Y.Z` tag),经 GPG 签名校验。所有真实用户的服务器都应使用此通道。
|
|
128
|
+
- `edge` — 跟踪 `main` 分支最新代码,**仅限维护者自己的测试服务器**。
|
|
128
129
|
|
|
129
|
-
`AI_HELPER_TESTDATA_GENERATION_MODE
|
|
130
|
+
`AI_HELPER_TESTDATA_GENERATION_MODE`(可选)— 测试数据生成是否要求沙箱(`hydrojudge.sandbox_host`):
|
|
130
131
|
|
|
131
|
-
- `auto
|
|
132
|
-
- `sandbox` —
|
|
133
|
-
- `direct` —
|
|
132
|
+
- `auto`(默认)— 沙箱可达时实跑验证,不可达时降级直出并明确标注"未验证"
|
|
133
|
+
- `sandbox` — 强制要求沙箱,不可用时安全失败
|
|
134
|
+
- `direct` — 始终使用直出模式(不推荐)
|
|
134
135
|
|
|
135
|
-
###
|
|
136
|
+
### 管理员配置
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
登录后访问 **控制面板 → AI 助手**(`/ai-helper`)→「AI 配置」Tab:
|
|
138
139
|
|
|
139
|
-
1.
|
|
140
|
-
2.
|
|
141
|
-
3.
|
|
142
|
-
4.
|
|
140
|
+
1. **添加 API 端点** — 填写端点名称、API Base URL、API Key → 点击「获取模型」
|
|
141
|
+
2. **选择模型与优先级** — 选择模型,拖拽排序;首选不可用时自动切换
|
|
142
|
+
3. **场景模型** — 为「测试数据生成」等场景指定专属模型(该场景建议配最强模型)
|
|
143
|
+
4. **测试并保存** — 点击「测试连接」验证后保存
|
|
143
144
|
|
|
144
|
-
##
|
|
145
|
+
## 遥测与隐私
|
|
145
146
|
|
|
146
|
-
|
|
147
|
+
收集**匿名统计数据**(安装数、活跃用户窗口、对话数、按日功能用量、版本),用于 GitHub 徽章和开发参考。完全匿名(随机 UUID,无个人信息,不存储 IP),不收集代码、对话内容或个人数据;仅记录 Cloudflare 粗粒度推断的国家/省份用于地区分布。
|
|
147
148
|
|
|
148
149
|
<details>
|
|
149
|
-
<summary><b
|
|
150
|
+
<summary><b>关闭遥测</b></summary>
|
|
150
151
|
|
|
151
152
|
```javascript
|
|
152
153
|
use your_hydro_db
|
|
@@ -158,52 +159,52 @@ db.ai_plugin_install.updateOne(
|
|
|
158
159
|
|
|
159
160
|
</details>
|
|
160
161
|
|
|
161
|
-
##
|
|
162
|
+
## 更新日志
|
|
162
163
|
|
|
163
164
|
<details open>
|
|
164
|
-
<summary><b>v3.0.0</b> —
|
|
165
|
+
<summary><b>v3.0.0</b> — 测试数据生成:沙箱实跑 + 双重验证</summary>
|
|
165
166
|
|
|
166
|
-
-
|
|
167
|
-
-
|
|
168
|
-
-
|
|
169
|
-
-
|
|
170
|
-
-
|
|
167
|
+
- 测试数据不再由 AI 直接给出:生成器与标程在 go-judge 沙箱中实际运行产出 `.in`/`.out`
|
|
168
|
+
- 四道机器关卡:独立暴力解对拍、输入校验器逐点校验、函数题模板实跑比对、题面样例回归
|
|
169
|
+
- 验证失败自动把失败阶段、出错测试点、输入与 traceback 关键行回喂 AI 修复一轮;教师取消不误报
|
|
170
|
+
- 生成的代码文件首行自带用途注释;文件页与场景模型页醒目提示配置最强模型
|
|
171
|
+
- 遥测增强:错误上报携带 AI 失败详情、启动失败金丝雀告警、功能用量累计与实例来源省份
|
|
171
172
|
|
|
172
173
|
</details>
|
|
173
174
|
|
|
174
175
|
<details>
|
|
175
|
-
<summary><b>v2.5.0</b> — AI
|
|
176
|
+
<summary><b>v2.5.0</b> — AI 生成测试数据(Beta)</summary>
|
|
176
177
|
|
|
177
|
-
-
|
|
178
|
-
-
|
|
179
|
-
-
|
|
178
|
+
- 根据题面一键生成测试点、函数题评测模板、config.yaml 与参考标程(AI 直出模式)
|
|
179
|
+
- 支持传统题、函数题与填空题;可粘贴标准答案作为唯一权威;骨架模式兜底
|
|
180
|
+
- 新增「测试数据生成」AI 场景(可单独指定模型链)
|
|
180
181
|
|
|
181
182
|
</details>
|
|
182
183
|
|
|
183
184
|
<details>
|
|
184
|
-
<summary><b>v2.0.0</b> —
|
|
185
|
+
<summary><b>v2.0.0</b> — 教学分析系统 & 设计升级</summary>
|
|
185
186
|
|
|
186
|
-
- 8
|
|
187
|
-
- LLM
|
|
188
|
-
-
|
|
187
|
+
- 8 维度班级分析 + 错误签名聚类 + 时序行为模式(规则引擎优先,成本约为纯 LLM 方案的 1/30)
|
|
188
|
+
- LLM 生成 P0/P1/P2 教学建议;从 AC 代码自动生成填空练习
|
|
189
|
+
- 学习总结跨作业历史追踪与补充生成;前端统一设计 Token 系统
|
|
189
190
|
|
|
190
191
|
</details>
|
|
191
192
|
|
|
192
193
|
<details>
|
|
193
|
-
<summary><b
|
|
194
|
+
<summary><b>更早版本</b></summary>
|
|
194
195
|
|
|
195
|
-
- v1.21.0
|
|
196
|
-
- v1.19.0–v1.20.0
|
|
197
|
-
- v1.18.0
|
|
198
|
-
- v1.14.x–v1.16.x
|
|
199
|
-
- v1.0.0–v1.12.0
|
|
196
|
+
- v1.21.0:批量 AI 学习总结(里程碑采样、SSE 进度、草稿/发布)
|
|
197
|
+
- v1.19.0–v1.20.0:全面中英文国际化、多维有效性指标、筛选自动补全
|
|
198
|
+
- v1.18.0:遥测看板 SPA、错误诊断增强
|
|
199
|
+
- v1.14.x–v1.16.x:SSE 流式响应、成本控制、CSRF/SSRF/Prompt 注入防御、安全修复
|
|
200
|
+
- v1.0.0–v1.12.0:初始发布、差异化问题类型、多端点 Failover、评测数据集成、竞赛模式
|
|
200
201
|
|
|
201
202
|
</details>
|
|
202
203
|
|
|
203
|
-
##
|
|
204
|
+
## 关于
|
|
204
205
|
|
|
205
|
-
|
|
206
|
+
[HydroOJ](https://github.com/hydro-dev/Hydro) 开源在线评测系统的第三方插件。如有问题或建议,欢迎提交 Issue。
|
|
206
207
|
|
|
207
|
-
##
|
|
208
|
+
## 许可证
|
|
208
209
|
|
|
209
210
|
MIT License
|
package/README_en.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# HydroOJ AI Learning Assistant
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
**[中文](README.md) | English**
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
A teaching-first AI tutoring plugin for [HydroOJ](https://github.com/hydro-dev/Hydro) — guided hints and thought-provoking questions, never complete solutions. Supports English and Chinese (i18n).
|
|
19
|
+
|
|
20
|
+
## Screenshots
|
|
21
|
+
|
|
22
|
+
<img src="assets/screenshots/1.png" alt="Student panel - AI chat" width="800">
|
|
23
|
+
|
|
24
|
+
<details>
|
|
25
|
+
<summary><b>AI Test Data Generation</b></summary>
|
|
26
|
+
|
|
27
|
+
<img src="assets/screenshots/10.png" alt="Problem files page - AI test data generation panel" width="800">
|
|
28
|
+
|
|
29
|
+
</details>
|
|
30
|
+
|
|
31
|
+
<details>
|
|
32
|
+
<summary><b>Batch AI Learning Summary</b></summary>
|
|
33
|
+
|
|
34
|
+
<img src="assets/screenshots/8.png" alt="Batch summary - scoreboard integration" width="800">
|
|
35
|
+
|
|
36
|
+
<img src="assets/screenshots/9.png" alt="Batch summary - generated results" width="800">
|
|
37
|
+
|
|
38
|
+
</details>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><b>Admin screenshots</b></summary>
|
|
42
|
+
|
|
43
|
+
<img src="assets/screenshots/4.png" alt="Admin - conversation records" width="800">
|
|
44
|
+
|
|
45
|
+
<img src="assets/screenshots/5.png" alt="Admin - usage analytics" width="800">
|
|
46
|
+
|
|
47
|
+
<img src="assets/screenshots/6.png" alt="Admin - AI configuration" width="800">
|
|
48
|
+
|
|
49
|
+
<img src="assets/screenshots/7.png" alt="Admin - cost dashboard" width="500">
|
|
50
|
+
|
|
51
|
+
</details>
|
|
52
|
+
|
|
53
|
+
## Features
|
|
54
|
+
|
|
55
|
+
### Students
|
|
56
|
+
|
|
57
|
+
- AI chat panel on problem pages with real-time streaming (SSE) and LaTeX rendering
|
|
58
|
+
- Choose question type: **Understand** / **Approach** / **Debug** / **Optimize** (AC-only)
|
|
59
|
+
- Multi-turn conversations with history; select confusing text for instant clarification
|
|
60
|
+
- View personalized AI learning summaries on scoreboard pages
|
|
61
|
+
|
|
62
|
+
### Teachers
|
|
63
|
+
|
|
64
|
+
- **AI Test Data Generation** — generate a full test data set from the statement on the problem files page (`/p/:pid/files`)
|
|
65
|
+
- **Sandbox execution + double verification**: the generator and reference solution actually run in Hydro's judge sandbox to produce `.in`/`.out`, then pass four machine gates — independent brute-force cross-check, input validation, template execution, and statement-sample regression; failures trigger targeted generator/oracle/template repair
|
|
66
|
+
- Automatically mixes small, medium, and boundary cases from statement constraints by default, with explicit single-scale modes still available. New numeric cases avoid existing files and are merged into `config.yaml`
|
|
67
|
+
- Supports traditional problems, LeetCode-style function problems (auto-generates `template.py/java/cc` and `compile.sh`) and fill-in-the-blank problems
|
|
68
|
+
- Paste an existing reference solution as the single source of truth; `config.yaml` is built deterministically and judge settings sync automatically
|
|
69
|
+
- Every generated code file (std.py, generator.py, validator.py, …) starts with a purpose comment; everything is previewed, editable and opt-in before writing
|
|
70
|
+
- ⚠️ Highly sensitive to model capability: assign your strongest model to the Test Data Generation scenario; a skeleton mode (no AI) is available as fallback
|
|
71
|
+
- **Teaching Analysis** — class-level insights from collective submission data
|
|
72
|
+
- 8-dimension rule engine (common errors / comprehension gaps / at-risk students / progress trends, …) + error-signature clustering + temporal behavior patterns
|
|
73
|
+
- LLM-powered P0/P1/P2 prioritized suggestions — specific classroom actions, not generic advice; auto-generates fill-in exercises from AC code
|
|
74
|
+
- **Batch AI Summary** — one-click personalized learning summaries for all students on scoreboard pages
|
|
75
|
+
- Longitudinal history tracking + milestone-based submission sampling; supplemental generation for late-arriving students
|
|
76
|
+
- Draft/publish workflow with real-time SSE progress and stop/continue/retry controls
|
|
77
|
+
- Conversation browsing (time / problem / class / student filters with autocomplete), effectiveness metrics, CSV export with optional anonymization
|
|
78
|
+
|
|
79
|
+
### Admins
|
|
80
|
+
|
|
81
|
+
- Unified portal: Conversations / Analytics / Configuration tabs
|
|
82
|
+
- Multi-endpoint API management with model auto-discovery, drag-to-reorder priority, and automatic failover
|
|
83
|
+
- Per-scenario model assignment: student chat / learning summary / teaching analysis / test data generation
|
|
84
|
+
- Cost control: token usage tracking, budget limits, cost dashboard
|
|
85
|
+
- Rate limiting, custom system prompt, one-click plugin update
|
|
86
|
+
|
|
87
|
+
<details>
|
|
88
|
+
<summary><b>Security</b></summary>
|
|
89
|
+
|
|
90
|
+
- Multi-layer jailbreak detection (input / prompt / output) with cross-turn protection
|
|
91
|
+
- CSRF token validation, SSRF prevention, AES-256-GCM encrypted API key storage
|
|
92
|
+
- AI-generated code runs only inside the go-judge sandbox, never in the web process
|
|
93
|
+
- Paginated jailbreak audit logs
|
|
94
|
+
|
|
95
|
+
</details>
|
|
96
|
+
|
|
97
|
+
## Installation
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Clone (choose one)
|
|
101
|
+
git clone https://github.com/AltureT/hydro-ai-helper.git # GitHub
|
|
102
|
+
git clone https://gitee.com/alture/hydro-ai-helper.git # Gitee (mirror)
|
|
103
|
+
|
|
104
|
+
cd hydro-ai-helper
|
|
105
|
+
npm install
|
|
106
|
+
npm run build:plugin
|
|
107
|
+
|
|
108
|
+
# Install into HydroOJ
|
|
109
|
+
hydrooj addon add /path/to/hydro-ai-helper
|
|
110
|
+
pm2 restart hydrooj
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Verify: visit `/ai-helper/hello` — a JSON response means success.
|
|
114
|
+
|
|
115
|
+
## Configuration
|
|
116
|
+
|
|
117
|
+
### Environment Variables
|
|
118
|
+
|
|
119
|
+
`ENCRYPTION_KEY` (required, 32 characters) — encrypts API keys:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
export ENCRYPTION_KEY="your-32-character-secret-key!!!" # generate: openssl rand -base64 24 | head -c 32
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`AI_HELPER_UPDATE_CHANNEL` (optional) — in-app update channel:
|
|
126
|
+
|
|
127
|
+
- `stable` (default) — updates only to official releases (`vX.Y.Z` tags), GPG-verified. Use on all real-user servers.
|
|
128
|
+
- `edge` — tracks the latest `main` branch code; for the maintainer's own test server only.
|
|
129
|
+
|
|
130
|
+
`AI_HELPER_TESTDATA_GENERATION_MODE` (optional) — whether test data generation requires the sandbox (`hydrojudge.sandbox_host`):
|
|
131
|
+
|
|
132
|
+
- `auto` (default) — verify in the sandbox when reachable; otherwise fall back to direct output clearly marked "unverified"
|
|
133
|
+
- `sandbox` — require the sandbox and fail safely when unavailable
|
|
134
|
+
- `direct` — always use direct output (not recommended)
|
|
135
|
+
|
|
136
|
+
### Admin Setup
|
|
137
|
+
|
|
138
|
+
Go to **Control Panel → AI Assistant** (`/ai-helper`) → "AI Configuration" tab:
|
|
139
|
+
|
|
140
|
+
1. **Add API endpoints** — endpoint name, API Base URL, API Key → click "Fetch Models"
|
|
141
|
+
2. **Select models & priority** — pick models, drag to reorder; failover is automatic
|
|
142
|
+
3. **Scenario models** — assign dedicated models per scenario (use your strongest model for Test Data Generation)
|
|
143
|
+
4. **Test & save** — "Test Connection" to verify, then save
|
|
144
|
+
|
|
145
|
+
## Telemetry & Privacy
|
|
146
|
+
|
|
147
|
+
Collects **anonymous statistics** (installations, active-user windows, conversations, per-day feature usage, version) for GitHub badges and development. Fully anonymous (random UUID, no PII, IPs never stored); no code, conversations or personal data — only a coarse country/region inferred by Cloudflare for distribution stats.
|
|
148
|
+
|
|
149
|
+
<details>
|
|
150
|
+
<summary><b>Disable telemetry</b></summary>
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
use your_hydro_db
|
|
154
|
+
db.ai_plugin_install.updateOne(
|
|
155
|
+
{ _id: 'install' },
|
|
156
|
+
{ $set: { telemetryEnabled: false } }
|
|
157
|
+
)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
</details>
|
|
161
|
+
|
|
162
|
+
## Changelog
|
|
163
|
+
|
|
164
|
+
<details open>
|
|
165
|
+
<summary><b>v3.0.0</b> — Test data generation: sandbox execution + double verification</summary>
|
|
166
|
+
|
|
167
|
+
- Test data is no longer emitted directly by the AI: the generator and reference solution actually run in the go-judge sandbox to produce `.in`/`.out`
|
|
168
|
+
- Four machine gates: independent brute-force cross-check, per-case input validation, function-template execution, statement-sample regression
|
|
169
|
+
- On failure, the failing stage, test case, input and traceback tail are fed back to the AI for one automatic repair round; teacher cancellation is no longer misreported
|
|
170
|
+
- Generated code files start with purpose comments; prominent strongest-model reminders on both the files page and the scenario-model page
|
|
171
|
+
- Telemetry: error reports carry AI failure details, startup-failure canary alerts, cumulative feature usage and instance region
|
|
172
|
+
|
|
173
|
+
</details>
|
|
174
|
+
|
|
175
|
+
<details>
|
|
176
|
+
<summary><b>v2.5.0</b> — AI Test Data Generation (Beta)</summary>
|
|
177
|
+
|
|
178
|
+
- One-click generation of test cases, judge templates, config.yaml and a reference solution from the statement (direct-output mode)
|
|
179
|
+
- Traditional / function / fill-in-the-blank problems; paste a reference solution as the single source of truth; skeleton-mode fallback
|
|
180
|
+
- New "Test Data Generation" AI scenario with its own model chain
|
|
181
|
+
|
|
182
|
+
</details>
|
|
183
|
+
|
|
184
|
+
<details>
|
|
185
|
+
<summary><b>v2.0.0</b> — Teaching Analysis & Design Overhaul</summary>
|
|
186
|
+
|
|
187
|
+
- 8-dimension class analysis + error-signature clustering + temporal behavior patterns (rule-engine first, ~1/30 the cost of pure LLM)
|
|
188
|
+
- LLM-generated P0/P1/P2 teaching suggestions; auto-generated fill-in exercises from AC code
|
|
189
|
+
- Longitudinal summary tracking with supplemental generation; unified frontend design tokens
|
|
190
|
+
|
|
191
|
+
</details>
|
|
192
|
+
|
|
193
|
+
<details>
|
|
194
|
+
<summary><b>Earlier versions</b></summary>
|
|
195
|
+
|
|
196
|
+
- v1.21.0: batch AI learning summaries (milestone sampling, SSE progress, draft/publish)
|
|
197
|
+
- v1.19.0–v1.20.0: full i18n, multi-dimensional effectiveness metrics, filter autocomplete
|
|
198
|
+
- v1.18.0: telemetry dashboard SPA, richer error diagnostics
|
|
199
|
+
- v1.14.x–v1.16.x: SSE streaming, cost control, CSRF/SSRF/prompt-injection defenses, security fixes
|
|
200
|
+
- v1.0.0–v1.12.0: initial release, question types, multi-endpoint failover, judge-data integration, contest mode
|
|
201
|
+
|
|
202
|
+
</details>
|
|
203
|
+
|
|
204
|
+
## About
|
|
205
|
+
|
|
206
|
+
A third-party plugin for the [HydroOJ](https://github.com/hydro-dev/Hydro) open-source online judge. Issues and suggestions welcome.
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
MIT License
|
|
@@ -793,16 +793,22 @@ class ChatHandler extends hydrooj_1.Handler {
|
|
|
793
793
|
// L4 请求级 AbortController
|
|
794
794
|
const requestAc = new AbortController();
|
|
795
795
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
796
|
-
const
|
|
797
|
-
|
|
798
|
-
|
|
796
|
+
const koaCtx = this.context;
|
|
797
|
+
const rawReq = koaCtx?.req;
|
|
798
|
+
const rawRes = koaCtx?.res;
|
|
799
|
+
// 提前检查客户端是否已真实断开:只认 aborted / 底层 socket 已销毁。
|
|
800
|
+
// 不能用 req.destroyed/'close'——POST body 被 body-parser 读完后,请求可读流会
|
|
801
|
+
// 按正常生命周期置 destroyed=true 并触发 'close',此时客户端仍在等响应。
|
|
802
|
+
if (rawReq?.aborted || rawReq?.socket?.destroyed) {
|
|
799
803
|
this.response.status = 499;
|
|
800
804
|
this.response.body = { error: this.translate('ai_helper_err_ai_aborted') };
|
|
801
805
|
this.response.type = 'application/json';
|
|
802
806
|
return;
|
|
803
807
|
}
|
|
804
|
-
|
|
805
|
-
|
|
808
|
+
// 真实断开检测挂在响应连接上:res 'close' 且响应尚未写完才中止
|
|
809
|
+
const onClose = () => { if (!rawRes?.writableEnded)
|
|
810
|
+
requestAc.abort(); };
|
|
811
|
+
rawRes?.on?.('close', onClose);
|
|
806
812
|
// L4: 请求级超时 — 基于配置值 + 10s buffer,确保比 L3 晚触发
|
|
807
813
|
const configTimeoutMs = (p.aiConfig?.timeoutSeconds || 30) * 1000;
|
|
808
814
|
const requestTimer = setTimeout(() => requestAc.abort(), configTimeoutMs + 10000);
|
|
@@ -867,7 +873,7 @@ class ChatHandler extends hydrooj_1.Handler {
|
|
|
867
873
|
}
|
|
868
874
|
finally {
|
|
869
875
|
clearTimeout(requestTimer);
|
|
870
|
-
|
|
876
|
+
rawRes?.removeListener?.('close', onClose);
|
|
871
877
|
}
|
|
872
878
|
// P0-2: 输出安全后处理(AI 响应返回后、保存到数据库前)
|
|
873
879
|
const outputSafetyService = new outputSafetyService_1.OutputSafetyService();
|