feat: clinic registry DB + pipeline audit P0 fixes

## Clinic Registry
- data/clinic-registry/clinic_registry_working.csv — 91개 병원 채널 마스터 DB
- data/clinic-registry/INFINITH_Outbound_List.csv — BD팀 아웃바운드 리스트 (17컬럼)
- data/clinic-registry/update_csv.py — 안전 CSV 업데이트 스크립트 (빈 필드만 채움)
- data/clinic-registry/extract_place_ids.py — 네이버 플레이스 ID 추출기
- scripts/import-registry.ts — CSV → Supabase clinic_registry 테이블 임포트
- supabase/migrations/20260406_clinic_registry.sql — clinic_registry 테이블 스키마

## Pipeline P0 Bug Fixes (전수 감사 후)
- fix(collect-channel-data): 강남언니 rating 0-10 스케일 오변환 제거
  - 기존: rating ≤ 5이면 ×2 → 4.8/10을 9.6/10으로 잘못 변환
  - 수정: Firecrawl 프롬프트가 이미 0-10 지시 → rawValue 직접 신뢰
- fix(generate-report): Perplexity 단일 fetch → fetchWithRetry 교체
  - maxRetries:2, backoffMs:[5000,15000], timeoutMs:90s
  - 기존: 타임아웃/429 시 리포트 생성 전체 실패
  - 수정: 자동 재시도로 일시적 API 오류 극복

## Docs
- docs/PIPELINE_IMPROVEMENT_PLAN.md — Sprint 0/1/2 완료 표시 + 전수 감사 결과 추가
- docs/REGISTRY_FUNCTIONAL_SPECS.md, DB_SCHEMA_V3.md 외 기획 문서 다수 추가

## New Components & Features
- supabase/functions/generate-content-plan, adjust-strategy — 콘텐츠 플랜/전략 조정
- src/components/plan/EditEntryModal, StrategyAdjustmentSection — 플랜 편집 UI
- supabase/functions/_shared/dataQuality, foundingYearExtractor, urlClassifier — 데이터 품질 유틸

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Haewon KamandClaude Sonnet 4.6 committed 2026-04-07 09:33:25 +09:00
1 parent ec991057e6
commit d5f7f24e0a
51 files changed
+5390 -252

No files matched your search

+108 -2
View File
@@ -135,11 +135,16 @@ export async function discoverChannels(url: string, clinicName?: string) {
}
);
const data = await response.json();
if (!response.ok) {
throw new Error(`Channel discovery failed: ${response.statusText}`);
const err = new Error(data.error || `Channel discovery failed: ${response.statusText}`);
(err as Error & { code?: string; domain?: string }).code = data.error;
(err as Error & { code?: string; domain?: string }).domain = data.domain;
throw err;
}
return response.json();
return data;
}
/**
@@ -182,3 +187,104 @@ export async function generateReportV2(reportId: string, clinicId?: string, runI
return response.json();
}
// ─── Pipeline V2 Phase 4: Content Plan ───
/**
* Phase 4: Generate AI content strategy and calendar.
* Reads report data from DB, calls Perplexity for strategy generation,
* stores result in content_plans table.
*/
export async function generateContentPlan(reportId: string, clinicId?: string, runId?: string) {
const response = await fetch(
`${supabaseUrl}/functions/v1/generate-content-plan`,
{
method: "POST",
headers: fnHeaders(),
body: JSON.stringify({ reportId, clinicId, runId }),
}
);
if (!response.ok) {
throw new Error(`Content plan generation failed: ${response.statusText}`);
}
return response.json();
}
/**
* Fetch the active content plan for a clinic.
* Returns the most recent is_active=true plan with all JSONB columns.
*/
export async function fetchActiveContentPlan(clinicId: string) {
const { data, error } = await supabase
.from("content_plans")
.select("*")
.eq("clinic_id", clinicId)
.eq("is_active", true)
.order("created_at", { ascending: false })
.limit(1)
.single();
if (error) return null;
return data;
}
/**
* Update a single calendar entry within a content plan's JSONB.
* Uses Postgres JSONB path update.
*/
export async function updateCalendarEntry(
planId: string,
entryId: string,
updates: Record<string, unknown>,
) {
// Read current calendar
const { data: plan, error: readErr } = await supabase
.from("content_plans")
.select("calendar")
.eq("id", planId)
.single();
if (readErr || !plan) throw new Error(`Plan not found: ${readErr?.message}`);
const calendar = plan.calendar as { weeks: { entries: Record<string, unknown>[] }[] };
// Find and update entry
for (const week of calendar.weeks) {
for (let i = 0; i < week.entries.length; i++) {
if (week.entries[i].id === entryId) {
week.entries[i] = { ...week.entries[i], ...updates, isManualEdit: true };
break;
}
}
}
const { error: writeErr } = await supabase
.from("content_plans")
.update({ calendar })
.eq("id", planId);
if (writeErr) throw new Error(`Update failed: ${writeErr.message}`);
}
/**
* Trigger strategy adjustment for a clinic.
* Compares current vs previous channel_snapshots, generates AI recommendations.
*/
export async function triggerStrategyAdjustment(clinicId: string) {
const response = await fetch(
`${supabaseUrl}/functions/v1/adjust-strategy`,
{
method: "POST",
headers: fnHeaders(),
body: JSON.stringify({ clinicId }),
}
);
if (!response.ok) {
throw new Error(`Strategy adjustment failed: ${response.statusText}`);
}
return response.json();
}