diff --git a/web-ui/html/detective-app.html b/web-ui/html/detective-app.html index 5440da8..bd71a4f 100644 --- a/web-ui/html/detective-app.html +++ b/web-ui/html/detective-app.html @@ -2580,6 +2580,24 @@ async function searchCVE(){ }catch(e){status.textContent='오류';result.style.display='block';result.innerHTML=escHtml(e.message);} } +// 매 질문에 붙이는 "현재 사건" 근거: 사건명·상태·메모 + 증거 파일 목록(이름/종류/날짜). +// 파일 내용은 보내지 않는다 — 모델이 필요하면 목록을 보고 파일 도구로 직접 연다. +async function buildCaseContext(){ + const lang='\n\n[응답 언어] 반드시 한국어로만 답하세요. 일본어·중국어·한자를 섞지 마세요.'; + const c=currentCaseId?currentCase():null; + if(!c)return lang; + const notes=(document.getElementById('case-notes')?.value||'').slice(0,8000); + let files=[]; + try{ + const r=await fetch('/api/detective/files?caseId='+encodeURIComponent(currentCaseId),{headers:authH()}); + const d=await r.json();files=Array.isArray(d.files)?d.files:[]; + }catch{} + const KIND={photo:'사진',document:'문서',video:'영상',other:'기타'}; + const lines=files.slice(0,150).map(f=>`- ${f.relPath||f.name} (${KIND[f.category]||f.category||'기타'}, ${String(f.mtime||'').slice(0,10)})`); + const more=files.length>150?`\n(외 ${files.length-150}개 생략)`:''; + return `\n\n[현재 사건 정보 — 앱이 자동 첨부]\n사건명: ${c.title||'제목 없음'}\n상태: ${c.status||'조사중'}\n\n사건 메모:\n${notes||'(없음)'}\n\n증거 파일 ${files.length}개 (사건 폴더: workspace/detective/${currentCaseId}/). 파일 내용은 포함되어 있지 않으니, 판단에 필요하면 파일 도구로 열어서 확인하고 읽지 않은 파일의 내용을 추측하지 마세요:\n${lines.join('\n')||'(없음)'}${more}`+lang; +} + async function callChat(message){ const btn=document.getElementById('send-btn'); btn.disabled=true;btn.textContent='...'; @@ -2589,9 +2607,10 @@ async function callChat(message){ msgs.appendChild(typingDiv);msgs.scrollTop=msgs.scrollHeight; let bubble=null,textBuf='',thinkBuf=''; try{ + const caseCtx=await buildCaseContext(); const body={message,sessionId:getSessionId(),useTools:true, ...(selectedModel?{model:selectedModel}:{}), - ...(skillContext?{skillContext}:{})}; + skillContext:(skillContext||'')+caseCtx}; const r=await fetch('/api/chat',{method:'POST',headers:authH({'Content-Type':'application/json'}),body:JSON.stringify(body)}); if(!r.ok)throw new Error('서버 오류 '+r.status); typingDiv.remove();