""" Chapter 封面意图 — 从本章 stories 或章节内容聚合生成封面 prompt。 封面不回写进 chapter 正文 markdown,绑定到 chapters.cover_asset_id。 """ from __future__ import annotations def aggregate_cover_prompt_from_stories( stories: list, *, chapter_title: str = "", chapter_category: str = "", ) -> str: """ 从本章 stories 聚合封面 prompt。 人物、地点、时间、情绪、时代背景。 """ parts = [] if chapter_title: parts.append(chapter_title) if chapter_category: parts.append(chapter_category) for s in (stories or [])[:5]: title = getattr(s, "title", None) or ( s.get("title") if isinstance(s, dict) else None ) stage = getattr(s, "stage", None) or ( s.get("stage") if isinstance(s, dict) else None ) summary = getattr(s, "summary", None) or ( s.get("summary") if isinstance(s, dict) else None ) if title: parts.append(title) if stage: parts.append(stage) if summary: parts.append((summary or "")[:100]) return ",".join(p for p in parts if p) def aggregate_cover_prompt_from_chapter( chapter_title: str = "", chapter_category: str = "", markdown_excerpt: str = "", ) -> str: """ 从章节标题、分类、正文摘要聚合封面 prompt。 用于无 story_links 的章节(兼容旧 memoir 流程)。 """ parts = [] if chapter_title: parts.append(chapter_title) if chapter_category: parts.append(chapter_category) if markdown_excerpt: parts.append(markdown_excerpt[:200].strip()) return ",".join(p for p in parts if p) or "人生回忆录章节"