question-workbench-mcp 0.3.0 → 0.3.4
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/client.js +109 -35
- package/index.js +6 -6
- package/package.json +27 -7
- package/server.js +4 -4
package/client.js
CHANGED
|
@@ -6,20 +6,20 @@ window.__ModuleLoader__.load({
|
|
|
6
6
|
const dict = {
|
|
7
7
|
zh: {
|
|
8
8
|
title: '题目工作台', open: '题目工作台', close: '收起', reset: '重新开始',
|
|
9
|
-
s1: '① 加图片', s2: '②
|
|
9
|
+
s1: '① 加图片', s2: '② 识别结果与讲义', pasteClipboard: '从剪贴板粘贴', pasteFail: '读取剪贴板失败,请手动 Ctrl+V 粘贴',
|
|
10
10
|
pick: '选择题目图片', optional: '已有题目文字(可选)', recognize: '提交识题',
|
|
11
11
|
sending: '发送中…', sent: '已发送,请在聊天中查看回复', needPhoto: '请先添加至少一张题目图片', needText: '请先粘贴或录入题目内容',
|
|
12
12
|
hint1: '在面板内直接 Ctrl+V 粘贴截图,或点「选择题目图片」;图片会随提示发给当前会话。',
|
|
13
|
-
pasteHint: '
|
|
13
|
+
pasteHint: '把回复中的【题目】【图形】粘贴到这里,删掉多余解释。',
|
|
14
14
|
textLabel: '题目与图形(可编辑)', placeholder: '粘贴识别结果或手工录入…',
|
|
15
15
|
pending: '待确认:', verified: '已核对题目(可选)', pasted: '已粘贴图片', next: '下一步', back: '上一步', toCheck: '下一步:核对题目', verifiedFirst: '请先勾选“我已对照原图核对”', pasteWait: '等模型回复后,把【题目】【图形】【待确认】粘到下面',
|
|
16
16
|
analysis: '思路分析', solve: '完整解题', summary: '知识总结', all: '一键全流程',
|
|
17
17
|
copy: '复制提示', copied: '已复制', copyFail: '复制失败,请手动选择文本',
|
|
18
18
|
print: '打印', exportHtml: '导出讲义', exportHint: '已导出讲义 HTML:用浏览器打开后按 Ctrl+P 可预览 A4 分页并打印。', exportFail: '导出失败:', preview: '预览', hidePreview: '关闭预览', includeImg: '打印含原图', optimize: '优化原图(裁剪·去阴影·增强)', optimizing: '正在优化图片…', optimizeFail: '部分图片优化失败,已使用原图', showPrompt: '查看将发送的提示', printFail: '打印调用失败,请改用系统打印(Ctrl+P)', printHint: '已调用打印;若没有出现打印对话框或预览,请点「导出讲义」,用浏览器打开后按 Ctrl+P 预览并打印',
|
|
19
19
|
fail: '发送失败:', noSession: '当前会话不可用,请先打开一个会话',
|
|
20
|
-
sendAsk: '发送', saved: '文字自动保存在本机浏览器(按会话)', diagramNote: '图形以原图为准:打印默认附原图,文本里的「图形」一行仅作排版提示。', limit: '最多 12 张,单张 ≤15MB',
|
|
20
|
+
sendAsk: '发送', notesLabel: '解答 / 解析', notesPlaceholder: '把模型的思路、解答或总结粘贴到这里;会打印在题目之后', autoFilled: '已自动填入模型回复', waiting: '已发送,等待模型回复后自动填入…', autoFail: '未自动获取到回复,可用「从剪贴板粘贴」手动补充', saved: '文字自动保存在本机浏览器(按会话)', diagramNote: '图形以原图为准:打印默认附原图,文本里的「图形」一行仅作排版提示。', limit: '最多 12 张,单张 ≤15MB',
|
|
21
21
|
src: '已核对题目:\n', rule: '以下内容已由用户对照原图人工核对,直接作为已知条件使用;不要重新质疑,也不要补充未确认的关系。\n\n',
|
|
22
|
-
rec: '
|
|
22
|
+
rec: '只做识别,严格输出两段,不要解释或额外分节:\n【题目】逐字转录印刷文字,保留题号、选项、符号和公式;看不清写[待核实:简短原因],不要猜。\n【图形】每张图一行,≤25字,只写可见关键元素,例如:图1 三角形ABC,P在内部,BM、CN交于P。\n【待确认】最多3条、每条≤15字;没有写“无”。',
|
|
23
23
|
askA: '只给思路,不要完整计算:①考点1行 ②关键思路3-5步。≤200字。',
|
|
24
24
|
askS: '给完整解题过程:分步推导+最终答案,公式简洁。≤400字。',
|
|
25
25
|
askM: '只总结:3-5条知识点与易错点,每条一行。≤150字。',
|
|
@@ -27,7 +27,7 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
},
|
|
28
28
|
en: {
|
|
29
29
|
title: 'Question workbench', open: 'Question workbench', close: 'Close', reset: 'Start over',
|
|
30
|
-
s1: '1 Photo', s2: '2
|
|
30
|
+
s1: '1 Photo', s2: '2 Result and worksheet', pasteClipboard: 'Paste from clipboard', pasteFail: 'Could not read the clipboard; paste manually',
|
|
31
31
|
pick: 'Choose photos', optional: 'Existing text (optional)', recognize: 'Recognize',
|
|
32
32
|
sending: 'Sending…', sent: 'Sent. Read the reply in chat.', needPhoto: 'Add at least one photo first', needText: 'Paste or type the question first',
|
|
33
33
|
hint1: 'Paste a screenshot with Ctrl+V inside the panel, or choose photos; they are sent with the prompt.',
|
|
@@ -38,9 +38,9 @@ window.__ModuleLoader__.load({
|
|
|
38
38
|
copy: 'Copy prompt', copied: 'Copied', copyFail: 'Copy failed; select the text manually',
|
|
39
39
|
print: 'Print', exportHtml: 'Export worksheet', exportHint: 'Worksheet exported. Open it in a browser and press Ctrl+P to preview A4 pages and print.', exportFail: 'Export failed: ', preview: 'Preview', hidePreview: 'Hide preview', includeImg: 'Include photos in print', optimize: 'Clean up photos (crop, shadows, contrast)', optimizing: 'Cleaning up photos…', optimizeFail: 'Some photos could not be cleaned; originals used', showPrompt: 'Show prompt to be sent', printFail: 'Print call failed; use Ctrl+P instead', printHint: 'Print dialog opened; press Ctrl+P if it did not appear',
|
|
40
40
|
fail: 'Send failed: ', noSession: 'No usable session; open a conversation first',
|
|
41
|
-
sendAsk: 'Send', saved: 'Text is saved in this browser per session', diagramNote: 'The original photo is the diagram source; printing includes it by default. The one-line diagram note is for layout only.', limit: 'Up to 12 photos, 15 MB each',
|
|
41
|
+
sendAsk: 'Send', notesLabel: 'Solution', notesPlaceholder: 'Paste the reasoning or solution here; it prints after the question', autoFilled: 'Model reply filled in automatically', waiting: 'Sent. Waiting for the reply to fill in…', autoFail: 'No reply captured; use "Paste from clipboard"', saved: 'Text is saved in this browser per session', diagramNote: 'The original photo is the diagram source; printing includes it by default. The one-line diagram note is for layout only.', limit: 'Up to 12 photos, 15 MB each',
|
|
42
42
|
src: 'Checked question:\n', rule: 'The user checked the following against the photos; use it as given. Do not re-question it or add unconfirmed relations.\n\n',
|
|
43
|
-
rec: 'Transcribe only. Output exactly
|
|
43
|
+
rec: 'Transcribe only. Output exactly two sections, no extra explanation:\n[Question] literal printed text, keeping numbering, symbols and formulas; write [verify: short reason] instead of guessing.\n[Diagram] one line per figure, ≤25 words, only visible key elements, e.g. Fig.1 triangle ABC, P inside, BM and CN meet at P.\n[Checks] at most 3 items, ≤15 words each; write "none" if none.',
|
|
44
44
|
askA: 'Reasoning only: 1 line of key concepts, then 3-5 steps. ≤200 words.',
|
|
45
45
|
askS: 'Full solution: step-by-step work and final answer, concise formulas. ≤400 words.',
|
|
46
46
|
askM: 'Key points only: 3-5 lines of concepts and common mistakes. ≤150 words.',
|
|
@@ -127,13 +127,15 @@ window.__ModuleLoader__.load({
|
|
|
127
127
|
function printDoc(t, state) {
|
|
128
128
|
const lines = v => inl(stripChecks(v)).split('\n').map(l => '<div>' + (l || ' ') + '</div>').join('');
|
|
129
129
|
const pics = state.images ? state.photos.map((p,i) => '<figure><img src="' + p.data + '" alt="' + esc(p.name) + '"><figcaption>' + esc(p.name) + '</figcaption></figure>').join('') : '';
|
|
130
|
-
|
|
130
|
+
const notes = state.notes && String(state.notes).trim() ? '<h2>' + esc(t.notesLabel) + '</h2><section>' + lines(state.notes) + '</section>' : '';
|
|
131
|
+
return '<!doctype html><html><head><meta charset="utf-8"><title>' + esc(t.title) + '</title><style>@page{size:A4;margin:16mm}body{font:12pt/1.7 system-ui,sans-serif;color:#161616}h1{font-size:18pt}h2{font-size:13pt;margin-top:16px;border-bottom:1px solid #999}section{white-space:pre-wrap;overflow-wrap:anywhere}figure{break-inside:avoid;margin:14px 0}figure img{max-width:100%;max-height:235mm;object-fit:contain}figcaption{font-size:9pt;color:#666}.bad{color:#b42318;background:#fff0ec}button{display:none}</style></head><body><h1>' + esc(t.title) + '</h1><section>' + lines(state.text || '') + '</section>' + pics + notes + '</body></html>';
|
|
131
132
|
}
|
|
132
133
|
function Bench({ ctx, t, sessionId }) {
|
|
133
134
|
const [open,setOpen] = React.useState(false);
|
|
134
135
|
const [step,setStep] = React.useState(1);
|
|
135
136
|
const [photos,setPhotos] = React.useState([]);
|
|
136
137
|
const [text,setText] = React.useState('');
|
|
138
|
+
const [notes,setNotes] = React.useState('');
|
|
137
139
|
const [checked,setChecked] = React.useState(false);
|
|
138
140
|
const [busy,setBusy] = React.useState(false);
|
|
139
141
|
const [msg,setMsg] = React.useState({ text:'', bad:false });
|
|
@@ -142,11 +144,15 @@ window.__ModuleLoader__.load({
|
|
|
142
144
|
const [proc,setProc] = React.useState({});
|
|
143
145
|
const [optimize,setOptimize] = React.useState(true);
|
|
144
146
|
const srcOf = p => (optimize && proc[p.url]) || p.data;
|
|
145
|
-
const
|
|
147
|
+
const photosRef = React.useRef([]);
|
|
148
|
+
const procRef = React.useRef({});
|
|
149
|
+
const optimizeRef = React.useRef(true);
|
|
150
|
+
React.useEffect(() => { photosRef.current = photos; procRef.current = proc; optimizeRef.current = optimize; }, [photos, proc, optimize]);
|
|
151
|
+
const printPhotos = () => photosRef.current.map(p => ({ name: p.name, data: (optimizeRef.current && procRef.current[p.url]) || p.data }));
|
|
146
152
|
const urls = React.useRef(new Set());
|
|
147
153
|
const key = 'question-workbench:v3:' + sessionId;
|
|
148
|
-
React.useEffect(() => { try { const saved = localStorage.getItem(key); if (saved) setText(saved); } catch (e) {} }, [key]);
|
|
149
|
-
React.useEffect(() => { try { localStorage.setItem(key, text); } catch (e) {} }, [key, text]);
|
|
154
|
+
React.useEffect(() => { try { const saved = JSON.parse(localStorage.getItem(key) || '{}'); if (saved && typeof saved.text === 'string') setText(saved.text); if (saved && typeof saved.notes === 'string') setNotes(saved.notes); } catch (e) {} }, [key]);
|
|
155
|
+
React.useEffect(() => { try { localStorage.setItem(key, JSON.stringify({ text, notes })); } catch (e) {} }, [key, text, notes]);
|
|
150
156
|
React.useEffect(() => {
|
|
151
157
|
if (!open) return;
|
|
152
158
|
const onPaste = (ev) => {
|
|
@@ -176,7 +182,56 @@ window.__ModuleLoader__.load({
|
|
|
176
182
|
return () => { cancelled = true; };
|
|
177
183
|
}, [optimize, photos, proc]);
|
|
178
184
|
const sessions = ctx.get('sessions');
|
|
185
|
+
const binding = sessions ? sessions.binding(sessionId) : undefined;
|
|
186
|
+
const waitRef = React.useRef(null);
|
|
187
|
+
const timerRef = React.useRef(null);
|
|
188
|
+
const lastSeq = () => {
|
|
189
|
+
const w = binding && binding.eventSource ? binding.eventSource.getSnapshot() : null;
|
|
190
|
+
const entries = (w && w.entries) || [];
|
|
191
|
+
let max = 0;
|
|
192
|
+
for (const e of entries) { const ev = e && e.event; if (ev && typeof ev.seq === 'number' && ev.seq > max) max = ev.seq; }
|
|
193
|
+
return max;
|
|
194
|
+
};
|
|
195
|
+
const assistantText = (ev) => {
|
|
196
|
+
const content = ev && ev.data && ev.data.content;
|
|
197
|
+
if (!Array.isArray(content)) return '';
|
|
198
|
+
return content.filter((b) => b && b.type === 'text' && typeof b.text === 'string').map((b) => b.text).join('\n').trim();
|
|
199
|
+
};
|
|
200
|
+
const latestAssistantAfter = (since) => {
|
|
201
|
+
const w = binding && binding.eventSource ? binding.eventSource.getSnapshot() : null;
|
|
202
|
+
const entries = (w && w.entries) || [];
|
|
203
|
+
let best = '';
|
|
204
|
+
for (const e of entries) {
|
|
205
|
+
if (!e || e.type !== 'event') continue;
|
|
206
|
+
const ev = e.event;
|
|
207
|
+
if (!ev || ev.type !== 'assistant/message') continue;
|
|
208
|
+
if (typeof ev.seq === 'number' && ev.seq <= since) continue;
|
|
209
|
+
const text = assistantText(ev);
|
|
210
|
+
if (text) best = text;
|
|
211
|
+
}
|
|
212
|
+
return best;
|
|
213
|
+
};
|
|
214
|
+
React.useEffect(() => {
|
|
215
|
+
if (!binding || !binding.eventSource) return;
|
|
216
|
+
return binding.eventSource.subscribe(() => {
|
|
217
|
+
const w = waitRef.current;
|
|
218
|
+
if (!w) return;
|
|
219
|
+
const text = latestAssistantAfter(w.since);
|
|
220
|
+
if (!text) return;
|
|
221
|
+
waitRef.current = null;
|
|
222
|
+
if (timerRef.current) { clearTimeout(timerRef.current); timerRef.current = null; }
|
|
223
|
+
if (w.kind === 'notes') {
|
|
224
|
+
setNotes(text);
|
|
225
|
+
say(t.autoFilled);
|
|
226
|
+
if (w.export) setTimeout(() => exportDoc({ notes: text }), 50);
|
|
227
|
+
} else {
|
|
228
|
+
setText(text);
|
|
229
|
+
say(t.autoFilled);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}, [binding]);
|
|
179
233
|
const pending = count(text);
|
|
234
|
+
React.useEffect(() => () => { if (timerRef.current) clearTimeout(timerRef.current); }, []);
|
|
180
235
|
function say(text, bad) { setMsg({ text: text || '', bad: !!bad }); }
|
|
181
236
|
async function addFiles(files) {
|
|
182
237
|
files = Array.from(files || []);
|
|
@@ -218,15 +273,33 @@ window.__ModuleLoader__.load({
|
|
|
218
273
|
async function doRecognize() {
|
|
219
274
|
if (!photos.length) { say(t.needPhoto, true); return; }
|
|
220
275
|
const extra = text.trim() ? t.optional + ':\n' + text.trim() + '\n\n' : '';
|
|
276
|
+
const since = lastSeq();
|
|
221
277
|
const ok = await send(extra + t.rec);
|
|
222
|
-
if (ok)
|
|
278
|
+
if (!ok) return;
|
|
279
|
+
waitRef.current = { kind: 'text', since };
|
|
280
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
281
|
+
timerRef.current = setTimeout(() => { waitRef.current = null; say(t.autoFail, true); }, 180000);
|
|
282
|
+
say(t.waiting);
|
|
283
|
+
setStep(2);
|
|
223
284
|
}
|
|
224
285
|
function askPrompt(ask) { return t.src + text.trim() + '\n\n' + t.rule + ask; }
|
|
225
|
-
function doAsk(ask) {
|
|
286
|
+
async function doAsk(ask) {
|
|
287
|
+
if (!text.trim()) { say(t.needText, true); return; }
|
|
288
|
+
const full = ask === t.askF;
|
|
289
|
+
const since = lastSeq();
|
|
290
|
+
const ok = await send(askPrompt(ask));
|
|
291
|
+
if (!ok) return;
|
|
292
|
+
waitRef.current = { kind: 'notes', since, export: full };
|
|
293
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
294
|
+
timerRef.current = setTimeout(() => { waitRef.current = null; say(t.autoFail, true); }, 300000);
|
|
295
|
+
say(t.waiting);
|
|
296
|
+
}
|
|
226
297
|
async function copyPrompt(ask) { try { await navigator.clipboard.writeText(askPrompt(ask)); say(t.copied); } catch (e) { say(t.copyFail, true); } }
|
|
227
|
-
function exportDoc() {
|
|
298
|
+
function exportDoc(override) {
|
|
228
299
|
try {
|
|
229
|
-
const
|
|
300
|
+
const docText = override && typeof override.text === 'string' ? override.text : text;
|
|
301
|
+
const docNotes = override && typeof override.notes === 'string' ? override.notes : notes;
|
|
302
|
+
const blob = new Blob([printDoc(t, { text: docText, notes: docNotes, photos: printPhotos(), images: includeImg })], { type: 'text/html;charset=utf-8' });
|
|
230
303
|
const url = URL.createObjectURL(blob);
|
|
231
304
|
const a = document.createElement('a');
|
|
232
305
|
a.href = url; a.download = t.title + '.html';
|
|
@@ -244,7 +317,7 @@ window.__ModuleLoader__.load({
|
|
|
244
317
|
frame.style.cssText = 'position:fixed;right:0;bottom:0;width:0;height:0;border:0;visibility:hidden;';
|
|
245
318
|
document.body.appendChild(frame);
|
|
246
319
|
const doc = frame.contentDocument;
|
|
247
|
-
doc.open(); doc.write(printDoc(t, { text, photos: printPhotos(), images: includeImg })); doc.close();
|
|
320
|
+
doc.open(); doc.write(printDoc(t, { text, notes, photos: printPhotos(), images: includeImg })); doc.close();
|
|
248
321
|
} catch (e) { if (frame) frame.remove(); say(t.printFail, true); return; }
|
|
249
322
|
setTimeout(() => {
|
|
250
323
|
try { frame.contentWindow.focus(); frame.contentWindow.print(); say(t.printHint); } catch (e) { say(t.printFail, true); }
|
|
@@ -253,12 +326,19 @@ window.__ModuleLoader__.load({
|
|
|
253
326
|
}
|
|
254
327
|
function go(n) {
|
|
255
328
|
if (n === 1) { setStep(1); return; }
|
|
256
|
-
|
|
257
|
-
if (n === 3) { if (!text.trim()) { say(t.needText, true); return; } setStep(3); say(''); }
|
|
329
|
+
setStep(2);
|
|
258
330
|
}
|
|
259
|
-
|
|
331
|
+
async function pasteClipboard() {
|
|
332
|
+
try {
|
|
333
|
+
const s = await navigator.clipboard.readText();
|
|
334
|
+
if (!s || !s.trim()) { say(t.needText, true); return; }
|
|
335
|
+
setText(s); say('');
|
|
336
|
+
} catch (e) { say(t.pasteFail, true); }
|
|
337
|
+
}
|
|
338
|
+
const stepBar = h('div',{className:'qwb-steps'},[[1,t.s1],[2,t.s2]].map(([n,label]) => h('button',{key:n,type:'button',className:'qwb-step' + (step === n ? ' on' : (step > n ? ' done' : '')),'aria-current': step === n ? 'step' : undefined,onClick:() => go(n)}, label)));
|
|
260
339
|
const msgLine = msg.text ? h('p',{className:'qwb-msg' + (msg.bad ? ' bad' : ''),role:'status'},msg.text) : null;
|
|
261
340
|
const thumbs = h('div',{className:'qwb-thumbs'},photos.map((p,i) => h('div',{className:'qwb-th',key:p.url},h('img',{src:p.url,alt:p.name}),h('button',{type:'button',title:'×',onClick:() => dropPhoto(i)},'×'))));
|
|
341
|
+
const asks = [[t.analysis,t.askA],[t.solve,t.askS],[t.summary,t.askM],[t.all,t.askF]];
|
|
262
342
|
let body;
|
|
263
343
|
if (step === 1) body = h(React.Fragment,null,
|
|
264
344
|
h('div',{className:'qwb-row'},h('label',{className:'qwb-up'},t.pick,h('input',{type:'file',multiple:true,accept:'image/png,image/jpeg,image/webp,image/gif',onChange:e => { addPhotos(e).catch(err => say(t.fail + String(err), true)); }})),h('span',{className:'qwb-msg'},t.limit)),
|
|
@@ -269,24 +349,18 @@ window.__ModuleLoader__.load({
|
|
|
269
349
|
);
|
|
270
350
|
if (step === 2) body = h(React.Fragment,null,
|
|
271
351
|
h('p',{className:'qwb-msg'},t.pasteWait),
|
|
272
|
-
h('
|
|
273
|
-
|
|
352
|
+
h('div',{className:'qwb-row'},h('button',{type:'button',onClick:pasteClipboard},t.pasteClipboard),h('button',{type:'button',onClick:() => go(1)},t.back)),
|
|
353
|
+
h('textarea',{value:text,placeholder:t.placeholder,onChange:e => { setText(e.target.value); setChecked(false); }}),
|
|
354
|
+
h('label',null,t.notesLabel),h('textarea',{value:notes,placeholder:t.notesPlaceholder,onChange:e => setNotes(e.target.value)}),
|
|
274
355
|
pending ? h('p',{className:'qwb-bad',role:'alert'},t.pending + pending) : null,
|
|
275
|
-
h('
|
|
276
|
-
h('
|
|
356
|
+
text ? h('div',{className:'qwb-v'},frags(text)) : null,
|
|
357
|
+
h('p',{className:'qwb-msg'},t.saved + ' ' + t.diagramNote),
|
|
358
|
+
h('div',{className:'qwb-row'},asks.map(([label,ask]) => h('button',{type:'button',key:label,disabled:busy || !text.trim(),onClick:() => doAsk(ask)},label))),
|
|
359
|
+
h('div',{className:'qwb-row'},h('label',null,h('input',{type:'checkbox',checked:optimize,onChange:e => setOptimize(e.target.checked)}),t.optimize),h('label',null,h('input',{type:'checkbox',checked:includeImg,onChange:e => setIncludeImg(e.target.checked)}),t.includeImg),h('button',{type:'button','aria-expanded':showPrev,onClick:() => setShowPrev(!showPrev)},showPrev ? t.hidePreview : t.preview),h('button',{type:'button',onClick:exportDoc},t.exportHtml),h('button',{type:'button',onClick:doPrint},t.print)),
|
|
360
|
+
showPrev ? h('div',{className:'qwb-sheet'},h('h4',null,t.title),h('div',{className:'qwb-v'},frags(text)),notes.trim() ? h('div',null,h('h4',null,t.notesLabel),h('div',{className:'qwb-v'},frags(notes))) : null,includeImg ? photos.map((p,i) => h('img',{className:'qwb-pg',key:p.url,src:srcOf(p),alt:p.name})) : null) : null,
|
|
361
|
+
h('details',{className:'qwb-details'},h('summary',null,t.showPrompt),h('pre',null,askPrompt(t.askF)),h('div',{className:'qwb-row'},h('button',{type:'button',onClick:() => copyPrompt(t.askF)},t.copy))),
|
|
362
|
+
msgLine
|
|
277
363
|
);
|
|
278
|
-
if (step === 3) {
|
|
279
|
-
const asks = [[t.analysis,t.askA],[t.solve,t.askS],[t.summary,t.askM],[t.all,t.askF]];
|
|
280
|
-
body = h(React.Fragment,null,
|
|
281
|
-
h('div',{className:'qwb-v'},frags(text)),
|
|
282
|
-
h('p',{className:'qwb-msg'},t.saved + ' ' + t.diagramNote),
|
|
283
|
-
h('div',{className:'qwb-row'},asks.map(([label,ask]) => h('button',{type:'button',key:label,disabled:busy,onClick:() => doAsk(ask)},label))),
|
|
284
|
-
h('div',{className:'qwb-row'},h('button',{type:'button',onClick:() => setStep(2)},t.back),h('label',null,h('input',{type:'checkbox',checked:optimize,onChange:e => setOptimize(e.target.checked)}),t.optimize),h('label',null,h('input',{type:'checkbox',checked:includeImg,onChange:e => setIncludeImg(e.target.checked)}),t.includeImg),h('button',{type:'button','aria-expanded':showPrev,onClick:() => setShowPrev(!showPrev)},showPrev ? t.hidePreview : t.preview),h('button',{type:'button',onClick:exportDoc},t.exportHtml),h('button',{type:'button',onClick:doPrint},t.print)),
|
|
285
|
-
showPrev ? h('div',{className:'qwb-sheet'},h('h4',null,t.title),h('div',{className:'qwb-v'},frags(text)),includeImg ? photos.map((p,i) => h('img',{className:'qwb-pg',key:p.url,src:srcOf(p),alt:p.name})) : null) : null,
|
|
286
|
-
h('details',{className:'qwb-details'},h('summary',null,t.showPrompt),h('pre',null,askPrompt(t.askF)),h('div',{className:'qwb-row'},h('button',{type:'button',onClick:() => copyPrompt(t.askF)},t.copy))),
|
|
287
|
-
msgLine
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
364
|
const panel = h('section',{className:'qwb','aria-label':t.title},
|
|
291
365
|
h('style',null,css),
|
|
292
366
|
h('div',{className:'qwb-row qwb-head'},h('b',null,t.title),h('span',{className:'qwb-row'},h('button',{type:'button',onClick:() => { setStep(1); setPhotos([]); setText(''); setChecked(false); say(''); }},t.reset),h('button',{type:'button',onClick:() => setOpen(false)},t.close))),
|
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
|
|
5
5
|
const PROMPTS = {
|
|
6
6
|
zh: {
|
|
7
|
-
recognition: '
|
|
7
|
+
recognition: '只做识别,严格输出两段,不要解释或额外分节:\n【题目】逐字转录印刷文字,保留题号、选项、符号和公式;看不清写[待核实:简短原因],不要猜。\n【图形】每张图一行,≤25字,只写可见关键元素,例如:图1 三角形ABC,P在内部,BM、CN交于P。\n【待确认】最多3条、每条≤15字;没有写“无”。',
|
|
8
8
|
analysis: '以下内容已由用户对照原图人工核对,直接作为已知条件使用;不要重新质疑,也不要补充未确认的关系。\n\n已核对题目:\n{text}\n\n只给思路,不要完整计算:①考点1行 ②关键思路3-5步。≤200字。',
|
|
9
9
|
solution: '以下内容已由用户对照原图人工核对,直接作为已知条件使用;不要重新质疑,也不要补充未确认的关系。\n\n已核对题目:\n{text}\n\n给完整解题过程:分步推导+最终答案,公式简洁。≤400字。',
|
|
10
10
|
summary: '以下内容已由用户对照原图人工核对,直接作为已知条件使用;不要重新质疑,也不要补充未确认的关系。\n\n已核对题目:\n{text}\n\n只总结:3-5条知识点与易错点,每条一行。≤150字。',
|
|
@@ -13,7 +13,7 @@ const PROMPTS = {
|
|
|
13
13
|
solutionLabel: '解答'
|
|
14
14
|
},
|
|
15
15
|
en: {
|
|
16
|
-
recognition: 'Transcribe only. Output exactly
|
|
16
|
+
recognition: 'Transcribe only. Output exactly two sections, no extra explanation:\n[Question] literal printed text, keeping numbering, symbols and formulas; write [verify: short reason] instead of guessing.\n[Diagram] one line per figure, ≤25 words, only visible key elements, e.g. Fig.1 triangle ABC, P inside, BM and CN meet at P.\n[Checks] at most 3 items, ≤15 words each; write "none" if none.',
|
|
17
17
|
analysis: 'The user checked the following against the photos; use it as given. Do not re-question it or add unconfirmed relations.\n\nChecked question:\n{text}\n\nReasoning only: 1 line of key concepts, then 3-5 steps. ≤200 words.',
|
|
18
18
|
solution: 'The user checked the following against the photos; use it as given. Do not re-question it or add unconfirmed relations.\n\nChecked question:\n{text}\n\nFull solution: step-by-step work and final answer, concise formulas. ≤400 words.',
|
|
19
19
|
summary: 'The user checked the following against the photos; use it as given. Do not re-question it or add unconfirmed relations.\n\nChecked question:\n{text}\n\nKey points only: 3-5 lines of concepts and common mistakes. ≤150 words.',
|
|
@@ -80,7 +80,7 @@ export const inject = ['tools'];
|
|
|
80
80
|
export function apply(ctx) {
|
|
81
81
|
ctx.effect(() => ctx.tools.register({
|
|
82
82
|
name: 'question_workbench_prompt',
|
|
83
|
-
description: '题目工作台提示词:recognition
|
|
83
|
+
description: '题目工作台提示词:recognition 生成两段式识图提示;analysis/solution/summary/full 基于已核对题目生成思路/解题/总结/全流程提示,再由模型按该提示作答。',
|
|
84
84
|
parameters: {
|
|
85
85
|
type: 'object',
|
|
86
86
|
additionalProperties: false,
|
|
@@ -103,18 +103,18 @@ export function apply(ctx) {
|
|
|
103
103
|
|
|
104
104
|
ctx.effect(() => ctx.tools.register({
|
|
105
105
|
name: 'question_workbench_worksheet',
|
|
106
|
-
description: '把题目与解答生成 A4 讲义 HTML 并写入文件,返回绝对路径;可用浏览器打开后 Ctrl+P
|
|
106
|
+
description: '把题目与解答生成 A4 讲义 HTML 并写入文件,返回绝对路径;可用浏览器打开后 Ctrl+P 预览分页并打印。(兼容旧输出:自动剥离去【待确认】段)',
|
|
107
107
|
parameters: {
|
|
108
108
|
type: 'object',
|
|
109
109
|
additionalProperties: false,
|
|
110
110
|
properties: {
|
|
111
|
-
text: { type: 'string', description: '
|
|
111
|
+
text: { type: 'string', description: '题目文字(可含已核对的两段式识别结果)。' },
|
|
112
112
|
notes: { type: 'string', description: '可选:思路、解答或总结,打印在题目之后。' },
|
|
113
113
|
title: { type: 'string', description: '讲义标题,默认“题目讲义”。' },
|
|
114
114
|
grade: { type: 'string', description: '可选:学科/年级行。' },
|
|
115
115
|
images: { type: 'array', items: { type: 'string' }, description: '可选:本地图片绝对路径(png/jpg/jpeg/webp/gif),嵌入讲义。' },
|
|
116
116
|
outputPath: { type: 'string', description: '输出 .html 路径,默认为当前工作目录。' },
|
|
117
|
-
skipChecks: { type: 'boolean', description: '
|
|
117
|
+
skipChecks: { type: 'boolean', description: '兼容旧输出:删除残留的【待确认】段,默认 true。' },
|
|
118
118
|
language: { type: 'string', enum: ['zh', 'en'], description: '讲义语言,默认 zh。' }
|
|
119
119
|
},
|
|
120
120
|
required: ['text']
|
package/package.json
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "question-workbench-mcp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Question workbench: photos in, checked text, reasoning or solutions, A4 worksheet out. One package, two installs: a DeepSeek Harness bundle (UI + agent tools) and an MCP stdio server for Codex, WorkBuddy and other MCP clients.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"keywords": [
|
|
8
|
-
|
|
7
|
+
"keywords": [
|
|
8
|
+
"dsh",
|
|
9
|
+
"dsh-plugin",
|
|
10
|
+
"deepseek-harness",
|
|
11
|
+
"mcp",
|
|
12
|
+
"worksheet",
|
|
13
|
+
"print",
|
|
14
|
+
"education"
|
|
15
|
+
],
|
|
16
|
+
"bin": {
|
|
17
|
+
"question-workbench-mcp": "./server.js"
|
|
18
|
+
},
|
|
9
19
|
"exports": {
|
|
10
20
|
".": "./index.js",
|
|
11
21
|
"./client": "./client.js",
|
|
@@ -26,9 +36,19 @@
|
|
|
26
36
|
"mcp-config.example.json",
|
|
27
37
|
"workbuddy-mcp.example.json"
|
|
28
38
|
],
|
|
29
|
-
"engines": {
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18"
|
|
41
|
+
},
|
|
30
42
|
"dsh": {
|
|
31
|
-
"bundle": {
|
|
32
|
-
|
|
43
|
+
"bundle": {
|
|
44
|
+
"patch": "./cordis.patch.yml"
|
|
45
|
+
},
|
|
46
|
+
"client": {
|
|
47
|
+
"platform": "web",
|
|
48
|
+
"immediately": true,
|
|
49
|
+
"inject": [
|
|
50
|
+
"@deepseek-ai/dsh-client-ui-conversation"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
33
53
|
}
|
|
34
|
-
}
|
|
54
|
+
}
|
package/server.js
CHANGED
|
@@ -13,7 +13,7 @@ const PROTOCOLS = ['2024-11-05', '2025-03-26', '2025-06-18'];
|
|
|
13
13
|
|
|
14
14
|
const PROMPTS = {
|
|
15
15
|
zh: {
|
|
16
|
-
recognition: '
|
|
16
|
+
recognition: '只做识别,严格输出两段,不要解释或额外分节:\n【题目】逐字转录印刷文字,保留题号、选项、符号和公式;看不清写[待核实:简短原因],不要猜。\n【图形】每张图一行,≤25字,只写可见关键元素,例如:图1 三角形ABC,P在内部,BM、CN交于P。\n【待确认】最多3条、每条≤15字;没有写“无”。',
|
|
17
17
|
analysis: '以下内容已由用户对照原图人工核对,直接作为已知条件使用;不要重新质疑,也不要补充未确认的关系。\n\n已核对题目:\n{text}\n\n只给思路,不要完整计算:①考点1行 ②关键思路3-5步。≤200字。',
|
|
18
18
|
solution: '以下内容已由用户对照原图人工核对,直接作为已知条件使用;不要重新质疑,也不要补充未确认的关系。\n\n已核对题目:\n{text}\n\n给完整解题过程:分步推导+最终答案,公式简洁。≤400字。',
|
|
19
19
|
summary: '以下内容已由用户对照原图人工核对,直接作为已知条件使用;不要重新质疑,也不要补充未确认的关系。\n\n已核对题目:\n{text}\n\n只总结:3-5条知识点与易错点,每条一行。≤150字。',
|
|
@@ -23,7 +23,7 @@ const PROMPTS = {
|
|
|
23
23
|
labelSolution: '解答'
|
|
24
24
|
},
|
|
25
25
|
en: {
|
|
26
|
-
recognition: 'Transcribe only. Output exactly
|
|
26
|
+
recognition: 'Transcribe only. Output exactly two sections, no extra explanation:\n[Question] literal printed text, keeping numbering, symbols and formulas; write [verify: short reason] instead of guessing.\n[Diagram] one line per figure, ≤25 words, only visible key elements, e.g. Fig.1 triangle ABC, P inside, BM and CN meet at P.\n[Checks] at most 3 items, ≤15 words each; write "none" if none.',
|
|
27
27
|
analysis: 'The user checked the following against the photos; use it as given. Do not re-question it or add unconfirmed relations.\n\nChecked question:\n{text}\n\nReasoning only: 1 line of key concepts, then 3-5 steps. ≤200 words.',
|
|
28
28
|
solution: 'The user checked the following against the photos; use it as given. Do not re-question it or add unconfirmed relations.\n\nChecked question:\n{text}\n\nFull solution: step-by-step work and final answer, concise formulas. ≤400 words.',
|
|
29
29
|
summary: 'The user checked the following against the photos; use it as given. Do not re-question it or add unconfirmed relations.\n\nChecked question:\n{text}\n\nKey points only: 3-5 lines of concepts and common mistakes. ≤150 words.',
|
|
@@ -52,7 +52,7 @@ const TOOLS = [
|
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
54
|
name: 'build_worksheet',
|
|
55
|
-
description: 'Write an A4 worksheet HTML file and return its absolute path. By default it embeds the most recent images the user pasted into WorkBuddy (no path needed) and
|
|
55
|
+
description: 'Write an A4 worksheet HTML file and return its absolute path. By default it embeds the most recent images the user pasted into WorkBuddy (no path needed) and strips any leftover 【待确认】 section.',
|
|
56
56
|
inputSchema: {
|
|
57
57
|
type: 'object',
|
|
58
58
|
properties: {
|
|
@@ -65,7 +65,7 @@ const TOOLS = [
|
|
|
65
65
|
maxAgeMinutes: { type: 'number', description: 'How recent a pasted image must be, in minutes; 0 disables the age filter. Defaults to 30.' },
|
|
66
66
|
imageLimit: { type: 'number', description: 'Maximum clipboard images to embed. Defaults to 3.' },
|
|
67
67
|
clipboardDir: { type: 'string', description: 'Advanced: pasted-image folder; defaults to <home>/.workbuddy/clipboard-images or QUESTION_WORKBENCH_CLIPBOARD_DIR.' },
|
|
68
|
-
skipChecks: { type: 'boolean', description: '
|
|
68
|
+
skipChecks: { type: 'boolean', description: 'Strip a leftover 【待确认】/【待核实】 section (legacy output). Defaults to true.' },
|
|
69
69
|
outputPath: { type: 'string', description: 'Destination .html path; defaults to the current working directory.' },
|
|
70
70
|
language: { type: 'string', enum: ['zh', 'en'], description: 'Worksheet language; defaults to zh.' }
|
|
71
71
|
},
|