python_eval 차트: 모델이 /api/files/ 없이 쓴 상대경로 이미지 링크를 올바른 주소로 교정

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-17 12:36:53 +09:00
1 parent ef3b427667
commit b9f8025e34
1 file changed
+7 -3
+7 -3
View File
@@ -62,12 +62,16 @@ export function appendGeneratedChartImages(
): string {
if (!toolResults?.length) return finalText;
const missing: string[] = [];
let text = finalText;
for (const r of toolResults) {
if (r?.name !== 'python_eval' || r.error || !r.result) continue;
for (const md of r.result.match(FILES_IMG_MD_G) || []) {
const url = md.slice(md.indexOf('](') + 2, -1);
if (!finalText.includes(url) && !missing.includes(md)) missing.push(md);
const url = md.slice(md.indexOf('](') + 2, -1); // /api/files/<name>
const bare = url.replace(/^\/api\/files\//, '');
// 모델이 `![설명](squares.png)`처럼 /api/files/ 없이 쓰면 브라우저가 못 찾아 "불러올 수 없습니다"가 뜬다 — 주소만 고친다.
if (bare) text = text.split(`](${bare})`).join(`](${url})`).split(`](./${bare})`).join(`](${url})`);
if (!text.includes(url) && !missing.includes(md)) missing.push(md);
}
}
return missing.length ? `${finalText}\n\n${missing.join('\n\n')}`.trim() : finalText;
return missing.length ? `${text}\n\n${missing.join('\n\n')}`.trim() : text;
}