dsh-zerror-answer
把 ZError 的「OCS 网课助手 AI 答题」能力做成 DSH 插件,只支持 OCS 5.x 协议。
- OCS 5.x:
POST /query + fetch + responseType: json;图片题使用 images base64 数组与 suggestion_title / suggestion_options([图片N] 占位符)。
- 不设题库:答案只返回给调用方,不写回、不保存、不自动入库。
- 思考与回答:设置页「思考」页记录每次答题的思考过程、最终答案、模型与耗时,本地保存并自动刷新。
- 模型切换:设置页可选择文本/视觉服务商与模型;工具调用也支持单次覆盖。
- 视觉答题:DSH 视觉模型优先;不可用时回退 ZError
model_config.json 中的视觉模型(anthropic / openai-chat)。
- DSH 工具:
zerror_answer / zerror_answer_batch / zerror_ocs_config。
- 设置页:DSH 设置 → 「ZError 答题」。
English abstract
dsh-zerror-answer is a DSH (DeepSeek Harness) plugin that connects OCS 5.x courseware clients to local DSH models. It exposes an OCS-compatible POST /query endpoint with base64 images and [图片N] placeholders, records reasoning/answer traces, and lets users switch text and vision providers/models. It deliberately keeps no question bank and writes no answers back. MIT licensed.
安装
# 从工作区目录安装(开发)
# plugin_manager install_bundle -> <workspace>/plugins/dsh-zerror-answer
# 或打包后安装
cd plugins/dsh-zerror-answer
npm pack --cache ./.npm-cache
# plugin_manager install_bundle -> dsh-zerror-answer-0.1.0.tgz
安装后打开 DSH 设置 → 「ZError 答题」。若设置页未出现,刷新 DSH 页面(客户端模块按页面加载)。
接入 OCS 5.x
设置页「OCS 网课助手配置」→ 复制:
[{
"name": "ZE答题(DSH 插件版)",
"homepage": "https://github.com/Miaozeqiu/ZError",
"url": "http://127.0.0.1:5833/query",
"method": "post",
"type": "fetch",
"responseType": "json",
"headers": {},
"data": {
"title": "${title}",
"options": "${options}",
"type": "${type}",
"images": { "handler": "return (env)=>env.images" },
"suggestion_title": "${suggestion_title}",
"suggestion_options": "${suggestion_options}"
},
"handler": "return (res)=>res.code === 1 ? [res.data.question,res.data.answer,{ai:res.data.is_ai}] : [res.message,undefined]"
}]
images 必须用字段 handler 返回数组;写成 ${images} 会被 OCS 转成逗号拼接字符串。
suggestion_title / suggestion_options 是 OCS 5.x 的 [图片N] 占位文本;没有图片时为空字符串。
- OCS 需要在脚本
@connect 中加入 127.0.0.1(或使用全域名通用版);若 fetch 受 CORS/混合内容限制,把 type 改为 GM_xmlhttpRequest(method 仍为 post)。
图片题
OCS 5.x 会把题目/选项中的图片下载并转成 data:image/png;base64,...,放在 env.images;题干变成 [图片N] 占位符。插件:
- 解析 POST body 的
images 数组(也兼容 JSON 字符串/裸 base64);
- 校验类型、大小、数量(默认最多 6 张,受 DSH
attachments.imageLimits 约束);
- 按
[图片N] 把图片插入文本对应位置,交给视觉模型;
- 答案按
ANSWER: 规则解析,选项字母/编号映射回选项正文。
协议与响应
- 请求:
POST /query(JSON 或 form-urlencoded);title/options/type/images/suggestion_title/suggestion_options。
- 成功:
{"code":1,"data":{"id":0,"question":"<html>","answer":"...","is_ai":true,"is_pending_correction":false}}。
- 失败:
{"code":0,"data":null,"message":"..."}。
?test=true:{"code":1,"data":null,"message":"ok"}。
- 多选答案用
### 连接;OCS 5.x 的 splitAnswer 默认支持 ===/#/---/###/|/;/;。
handler 第三项 {ai: true} 会进入 OCS 的 extra_data。
- 不再提供
/api/questions/:id/pending-correction(题库功能已删除)。
AI 思考与回答
DSH 设置 → 「ZError 答题」→ 思考:
- 左侧列表:时间、来源(AI/错误)、模型、耗时、答案摘要。
- 右侧详情:题目、选项、AI 思考(原文)、最终回答、模型/耗时/图片数。
- 进入页面后每 2.5 秒自动刷新;可手动刷新或清空。
- 记录保存在
~/.dsh/zerror/traces.jsonl(最多 200 条),页面关闭后仍保留。
- 设置 → 模型切换 → 思考强度:可选「低 / 中 / 高 / 最高」(配置值
low/medium/high/max),留空跟随模型默认;模型不返回思考时详情显示「本次没有思考内容」。
模型切换
设置页
设置 → 「ZError 答题」→ 设置 → 模型切换:
- 文本服务商 / 模型:普通题使用;服务商留空表示跟随 DSH 默认。
- 视觉策略:
auto(自动,DSH 优先,失败回退 ZError)/ dsh(仅 DSH)/ zerror(仅 ZError)。
- 视觉服务商 / 模型:只列出支持图片(
image)的模型;留空表示跟随 DSH 默认。
- 单题最多图片数。
- 保存后立即生效(写入
~/.dsh/zerror/settings.json,并更新运行时配置)。
模型列表来自 DSH llm.listProviders() + llm.listModels(),通过 /api/zerror/models 提供给设置页。
工具调用
zerror_answer / 批量接口支持单次覆盖,不改变全局设置:
{
"question": "...",
"provider": "deepseek-official",
"model": "deepseek-flash",
"visionProvider": "open-design",
"visionModel": "deepseek-v4-flash-vision-exp",
"visionMode": "dsh"
}
视觉回退
auto:DSH 当前模型 / 指定视觉模型;resolveModelInfo 不支持图片或调用失败时回退 ZError 视觉模型。
dsh:只用 DSH;不支持时返回 NO_VISION_MODEL。
zerror:只用 ZError model_config.json 中 hasVision=true 的已启用模型(anthropic / openai-chat)。
配置
- id: zerror
config:
visionMode: auto
provider: "" # 文本模型服务商覆盖
model: ""
visionProvider: ""
visionModel: ""
reasoningEffort: "" # 低 | 中 | 高 | 最高(对应 low/medium/high/max;空=跟随模型默认)
maxTokens: 1024
temperature: 0.2
timeoutMs: 45000
imageTimeoutMs: 15000
maxImages: 6
allowLan: false
adminToken: ""
imageHeaders: {}
设置页修改保存在 ~/.dsh/zerror/settings.json,下次启动覆盖 patch 同名字段。
测试
cd plugins/dsh-zerror-answer
node test/core.test.mjs # 15 个纯函数/配置契约测试
node test/integration.test.mjs # 7 个模拟 Harness 集成测试(含 OCS 5.x 图片、思考记录、模型列表)
安全与隐私
/query 默认仅本机(loopback);allowLan=true 时可配 adminToken。
- 图片下载拒绝
file://、localhost、私有 IPv4/IPv6(DNS 解析后复核),防 SSRF。
- 题目与图片会发送给 DSH 模型;回退 ZError 视觉模型时会发送给对应第三方 API。
- 不读写任何题库数据库;不保留题目/答案副本,唯一本地记录是「思考」页的
traces.jsonl。
限制
- 不支持 OCS 4.x(GET / GM_xmlhttpRequest / 只传 URL 的旧配置);请升级 OCS 5.x。
- 没有题库:不提供搜索、添加、删除、清空、待修正标记,也不会自动入库。
- 非图片 URL(网页)默认按图片处理并报错;网页正文抓取未实现。
- 不包含 ZError 桌面端的完整 UI:导入导出、文件夹拖拽、自动更新、多用户/管理员体系不在范围内。
- 图片过小(< 14px)未自动放大;OCS 5.x 会在上传前自行放大到 14px。