import { ServiceUnavailableException } from '@nestjs/common'; import { readFile } from 'node:fs/promises'; import { join } from 'node:path'; export const AGENT_DOCUMENT_CATALOG = [ { id: 'lms-user-guide', title: 'Autonomy Studio LMS 사용자 매뉴얼', description: '학생용 LMS 앱의 화면 이동, 로컬·원격 플랫폼 연결, 모듈 설치·빌드·실행·파라미터, 코드 편집·저장, 소스 제어, 로그·터미널, ROS 연결, 지도·SLAM·주행·시각화, 질의응답·에이전트 승인, 학습 완료·종료·반납. 각 버튼의 위치·아이콘·활성 조건·조작 순서와 주의사항.', }, ] as const; export function isAgentDocumentId(id: string): boolean { return AGENT_DOCUMENT_CATALOG.some((document) => document.id === id); } export async function readAgentDocument(id: string) { const document = AGENT_DOCUMENT_CATALOG.find((entry) => entry.id === id); if (!document) throw new ServiceUnavailableException('등록되지 않은 사용법 문서입니다.'); try { // Only registered, server-owned files can be read; IDs are never used as paths. const content = await readFile(join(__dirname, 'docs', 'lms-user-guide.ko.md'), 'utf8'); if (!content.trim() || content.length > 60_000) throw new Error('Invalid guide size'); return { ...document, content }; } catch { throw new ServiceUnavailableException('LMS 사용법 문서를 불러오지 못했습니다. 관리자에게 문서 배포 상태를 문의하세요.'); } }