diff --git a/src/api/aiTrainingEvaluation.js b/src/api/aiTrainingEvaluation.js index 413cae0..4a3ef50 100644 --- a/src/api/aiTrainingEvaluation.js +++ b/src/api/aiTrainingEvaluation.js @@ -7,10 +7,11 @@ export function getAiTrainingEvaluation(taskKey) { }); } -export function requestAiTrainingHelp(taskKey) { +export function requestAiTrainingHelp(taskKey, question) { return request({ url: `/api/student/training-tasks/${taskKey}/ai-evaluation/help`, method: "post", + data: { question }, headers: { repeatSubmit: false }, }); } diff --git a/src/views/components/TrainingAiSidebar.vue b/src/views/components/TrainingAiSidebar.vue index 430c279..d70250b 100644 --- a/src/views/components/TrainingAiSidebar.vue +++ b/src/views/components/TrainingAiSidebar.vue @@ -124,15 +124,20 @@ function useReferencePrompt() { async function requestAssist() { emit("request-assist", assistQuestion.value); + const question = assistQuestion.value.trim(); + if (!question) { + assistMessage.value = "请输入问题,或点击上方参考提示词后发送。"; + return; + } if (currentTaskKey.value) { try { - await requestAiTrainingHelp(currentTaskKey.value); + await requestAiTrainingHelp(currentTaskKey.value, question); await loadEvaluation(); assistMessage.value = reports.value.helpReport || props.assistText; return; } catch (error) {} } - assistMessage.value = assistQuestion.value ? `围绕“${assistQuestion.value}”,建议先对照任务目标检查信息是否完整,再补充数据依据和分析结论。` : props.assistText; + assistMessage.value = `围绕“${question}”,建议先对照任务目标检查信息是否完整,再补充数据依据和分析结论。`; } async function requestEvaluation() { diff --git a/tests/ai-training-evaluation.static.test.cjs b/tests/ai-training-evaluation.static.test.cjs index 799392c..1c486bb 100644 --- a/tests/ai-training-evaluation.static.test.cjs +++ b/tests/ai-training-evaluation.static.test.cjs @@ -13,6 +13,11 @@ assert(/`\/api\/student\/training-tasks\/\$\{taskKey\}\/ai-evaluation`/.test(api assert(/\/help/.test(api) && /\/assessment/.test(api), "evaluation API should expose help and assessment operations"); assert(/TrainingAiSidebar/.test(page) && /:has-saved-answer="hasSavedAnswer"/.test(page), "generic training page should pass persisted answer state to the AI sidebar"); assert(/form\.value/.test(page) && /workRows\.value/.test(page) && /processRows\.value/.test(page), "hasAnyAnswer should inspect all supported answer shapes"); +assert(/requestAiTrainingHelp\(taskKey, question\)/.test(api), "AI help API should accept the student's question"); +assert(/data:\s*\{\s*question\s*\}/.test(api), "AI help API should submit the student's question as JSON"); +assert(/const question = assistQuestion\.value\.trim\(\)/.test(sidebar), "AI sidebar should trim the student's question before sending it"); +assert(/if \(!question\)/.test(sidebar), "AI sidebar should block an empty AI help question"); +assert(/requestAiTrainingHelp\(currentTaskKey\.value, question\)/.test(sidebar), "AI sidebar should send the trimmed question to AI help"); assert(/onMounted\(/.test(component) && /watch\(\s*\(\)\s*=>\s*props\.taskKey/.test(component), "AI evaluation should load on mount and task changes"); assert(/AI助学/.test(component) && /AI助评/.test(component), "AI evaluation should offer separate help and assessment controls");