Phase I: 전수 정합성 복구 + 넘침 처리 패러다임 전환 (14개 항목) - I-14: SSE 유틸 공통 추출 (src/sse_utils.py 신규, 3개 파일 중복 제거) - I-13: dead code 3건 삭제 (_call_anthropic_direct, _extract_sse_text x2) + import anthropic 제거 - I-1: STEP_B_PROMPT purpose 가이드 미존재 블록 3개 → 실존 블록 교체 - I-2: catalog.yaml not_for 13건 미존재 블록 참조 교체/제거 - I-12: BLOCK_SLOTS 주석 개수 수정 (cards 9, visuals 6, emphasis 10) - I-10: INDEX.md 38개 동기화 (삭제된 8개 블록 행 제거) - I-11: README.md 38개 동기화 (_legacy 제거, 트리/개수 정리) - I-3: PURPOSE_FALLBACK 상수 + purpose 기반 미등록 블록 교체 - I-7: compare-pill-pair 단독 사용 금지 검증 - I-4: 38개 블록 전체에 slot_desc 추가 - I-5: 편집자 프롬프트에 slot_desc 전달 로직 - I-6: 제목 유사도 70% 초과 시 자동 교정 - I-9: 넘침 판단 Kei API 호출 (KEI_OVERFLOW_PROMPT, call_kei_overflow_judgment) - I-8: 대형 콘텐츠 정보 Kei overflow 프롬프트에 포함 프로세스 재설계: - Stage 2.5 제거 → Stage 5에서 Sonnet 감지 + Kei 판단 통합 - _review_balance() 확장: zone 예산 + overflow_detected action 추가 - Stage 5 루프에 Kei 넘침 판단 호출 통합 - _apply_adjustments()에 kei_trim/kei_restructure action 추가 - _build_overflow_context(), _convert_kei_judgment() 헬퍼 함수 추가 - DOWNGRADE_MAP은 Kei API 실패 시 비상용으로만 잔존 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""SSE 스트리밍 공통 유틸리티.
|
|
|
|
persona_agent의 SSE 이벤트를 수신하여 토큰을 수집한다.
|
|
kei_client, content_editor, design_director에서 공통 사용.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import logging
|
|
|
|
import httpx
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def stream_sse_tokens(response: httpx.Response) -> str:
|
|
"""SSE 스트리밍 응답에서 토큰을 실시간 수집한다.
|
|
|
|
persona_agent의 SSE 이벤트:
|
|
- token: 텍스트 토큰 수집
|
|
- done: 완료, 중단
|
|
- error: 에러, 즉시 중단
|
|
- planning/planning_done/research_progress/warning: 스킵
|
|
"""
|
|
tokens: list[str] = []
|
|
event_type = ""
|
|
|
|
async for line in response.aiter_lines():
|
|
line = line.strip()
|
|
if not line:
|
|
event_type = ""
|
|
continue
|
|
if line.startswith("event:"):
|
|
event_type = line[6:].strip()
|
|
elif line.startswith("data:"):
|
|
data = line[5:].strip()
|
|
if event_type == "token" and data:
|
|
try:
|
|
token = json.loads(data)
|
|
if isinstance(token, str):
|
|
tokens.append(token)
|
|
except json.JSONDecodeError:
|
|
tokens.append(data)
|
|
elif event_type == "done":
|
|
break
|
|
elif event_type == "error":
|
|
logger.warning(f"Kei API SSE 에러: {data}")
|
|
break
|
|
|
|
return "".join(tokens)
|