| 1 | /** Normalize model-produced outline content before deck generation. */ |
| 2 | export const MAX_KEY_POINTS_PER_SLIDE = 10 |
| 3 | export const MAX_OUTLINE_TEXT_CHUNKS = 10 |
| 4 | export const MAX_OUTLINE_TEXT_LENGTH = 260 |
| 5 | export const MAX_KEY_POINT_LENGTH = 32 |
| 6 | |
| 7 | export const normalizeOutlineText = (raw: string): string => { |
| 8 | const text = raw.replace(/\s+/g, ' ').trim() |
| 9 | if (!text) return '' |
| 10 | // Prefer compact clause-style outline to reduce downstream prompt bloat while preserving explicit user lists. |
| 11 | const chunks = text |
| 12 | .split(/[;;。.!?\n、,,|/]/g) |
| 13 | .map((item) => item.trim()) |
| 14 | .filter((item) => item.length > 0) |
| 15 | const compact = ( |
| 16 | chunks.length > 0 ? chunks.slice(0, MAX_OUTLINE_TEXT_CHUNKS).join(';') : text |
| 17 | ).trim() |
| 18 | if (compact.length <= MAX_OUTLINE_TEXT_LENGTH) return compact |
| 19 | return `${compact.slice(0, MAX_OUTLINE_TEXT_LENGTH).trimEnd()}…` |
| 20 | } |
| 21 | |
| 22 | export const normalizeKeyPoints = (value: unknown): string[] => { |
| 23 | if (!Array.isArray(value)) return [] |
| 24 | return value |
| 25 | .map((item) => String(item ?? '').trim()) |
| 26 | .filter((item) => item.length > 0) |
| 27 | .slice(0, MAX_KEY_POINTS_PER_SLIDE) |
| 28 | .map((item) => |
| 29 | item.length > MAX_KEY_POINT_LENGTH ? `${item.slice(0, MAX_KEY_POINT_LENGTH).trimEnd()}…` : item |
| 30 | ) |
| 31 | } |
| 32 |