"""COPY 흐름. 단계 구현: copy_steps / 프롬프트: prompts/copy / 호출·검증: external/gemini_text.""" from services.copy_steps import CopyAborted, prepare_copy, generate_copy, save_copy, fill_faqs from services.external import gemini_text from services.job_progress import JobProgress COPY_STEPS = ("prepare", "generate", "save", "faq_fill") async def run_copy(job: dict) -> dict: progress = JobProgress(job, COPY_STEPS) payload = job["payload"] async with progress.step("prepare"): inputs = await prepare_copy(payload["place_id"], payload["owner_user_id"]) copy = None note = None if inputs.ungrounded or not gemini_text.is_configured(): note = "근거로 쓸 확인된 fact 가 없다" if inputs.ungrounded else "GEMINI_API_KEY 미설정" await progress.skip("generate", "no_facts" if inputs.ungrounded else "not_configured") if inputs.catalog is None and not inputs.ungrounded: raise CopyAborted(note) else: async with progress.step("generate"): copy = await generate_copy(inputs) async with progress.step("save"): result = await save_copy(inputs, copy) if inputs.catalog is not None: async with progress.step("faq_fill"): result["faq_fill"] = await fill_faqs( inputs.place.place_id, inputs.catalog, inputs.known_fact_keys, inputs.place.phone, ) else: await progress.skip("faq_fill", "no_catalog") if note: result["note"] = note return result