fix(dental-journals): 논문 대화 컨텍스트 길이 — 지정 논문이 여러 편이면 초록 길이를 나누고, 목록은 남는 자리만큼만 넣고 생략 건수를 모델에 알림(12,000자 서버 한도 안)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-05 12:17:52 +09:00
1 parent d897a1cfb6
commit 3c7b133d2a
1 file changed
+10 -4
+10 -4
View File
@@ -258,6 +258,7 @@ function paperLine(a,i){
const doi=(a.doi||'').replace(/^doi:\s*/i,'');
return `${i}. [PMID ${a.pmid}] ${a.title} — ${a.authors||'저자 미상'} — ${a.journal} ${a.year}${a.pmcid?` — ${a.pmcid}(PMC 전문 가능)`:''}${doi?` — DOI ${doi}`:''}`;
}
const CAPMAX=12000; // 서버 한도(SKILL_CTX_MAX)와 같다
function buildContext(){
const L=[];
L.push('[치과 저널 검색 앱 — 논문 대화 컨텍스트]');
@@ -274,18 +275,23 @@ function buildContext(){
}
if(pinned.length){
L.push('\n▶ 사용자가 지정한 논문(대화의 주 대상):');
const absMax=Math.min(3500,Math.floor(6500/pinned.length)); // 지정 논문이 여러 편이면 초록 길이를 나눠 목록 자리를 남긴다
pinned.forEach((a,i)=>{
L.push(paperLine(a,i+1));
const ab=absCache[a.pmid];
L.push(ab?` 초록: ${ab.slice(0,3500)}`:' 초록: (아직 불러오지 못함 — 필요하면 pubmed_fetch로 PMID 조회)');
L.push(ab?` 초록: ${ab.slice(0,absMax)}${ab.length>absMax?' …(초록 일부 생략 — 전체는 pubmed_fetch로)':''}`:' 초록: (아직 불러오지 못함 — 필요하면 pubmed_fetch로 PMID 조회)');
});
}
const rest=shown.filter(a=>!pinned.some(p=>p.pmid===a.pmid)).slice(0,25);
if(rest.length){
L.push(`\n▶ 화면에 표시된 검색 결과 목록(${rest.length}건, 초록 없음 — 필요하면 도구로 조회):`);
rest.forEach((a,i)=>L.push(paperLine(a,i+1)));
// 서버는 skillContext를 12,000자에서 자른다. 지정 논문(초록)이 길수록 목록이 먼저 밀리므로, 남는 자리만큼만 넣고 생략한 건수를 모델에게 알린다.
const CAP=11500, used=L.join('\n').length, lines=[]; let acc=used+90;
for(let i=0;i<rest.length;i++){ const ln=paperLine(rest[i],i+1); if(acc+ln.length+1>CAP) break; lines.push(ln); acc+=ln.length+1; }
L.push(`\n▶ 화면에 표시된 검색 결과 목록(${rest.length}건 중 ${lines.length}건 수록, 초록 없음 — 필요하면 도구로 조회):`);
lines.forEach(x=>L.push(x));
if(lines.length<rest.length) L.push(`(길이 한도로 ${rest.length-lines.length}건은 생략됨 — 이 건들이 필요하면 pubmed_search로 조회하고, 정리할 때는 수록된 ${lines.length}건만 봤다고 밝힐 것)`);
}
return L.join('\n').slice(0,11500);
return L.join('\n').slice(0,CAPMAX);
}
const QUICK={