feat: Vision Analysis — screenshot capture + Gemini Vision extraction

WP-V1: Multi-page screenshot capture via Firecrawl
  - Captures 6+ pages: main, doctors, surgery, YouTube, Instagram, 강남언니
  - Runs in parallel within collect-channel-data Phase 2

WP-V2: Gemini Vision analysis per screenshot
  - Page-specific prompts (main page OCR, doctor profiles, channel stats)
  - Extracts: founding year, doctors, certifications, services, social icons,
    brand colors, slogans, YouTube/Instagram stats from screenshots

WP-V3: Vision data pipeline integration
  - channel_data.visionAnalysis: merged structured data
  - channel_data.screenshots[]: evidence for report EvidenceGallery
  - generate-report embeds screenshots as report.screenshots[]
  - buildChannelSummary includes Vision data in AI prompt

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Haewon KamandClaude Opus 4.6 committed 2026-04-04 23:59:19 +09:00
1 parent 494dc186c5
commit 6a3390840d
3 files changed
+348

No files matched your search

@@ -2,6 +2,7 @@ import "@supabase/functions-js/edge-runtime.d.ts";
import { createClient } from "https://esm.sh/@supabase/supabase-js@2";
import type { VerifiedChannels } from "../_shared/verifyHandles.ts";
import { PERPLEXITY_MODEL } from "../_shared/config.ts";
import { captureAllScreenshots, runVisionAnalysis, type ScreenshotResult } from "../_shared/visionAnalysis.ts";
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
@@ -355,6 +356,37 @@ Deno.serve(async (req) => {
})());
}
// ─── 8. Vision Analysis: Screenshots + Gemini Vision ───
const GEMINI_API_KEY = Deno.env.get("GEMINI_API_KEY") || "";
let screenshots: ScreenshotResult[] = [];
if (FIRECRAWL_API_KEY) {
const mainUrl = row.url || "";
const siteMap: string[] = row.scrape_data?.siteMap || [];
tasks.push((async () => {
// Capture screenshots of relevant pages + social channel landings
screenshots = await captureAllScreenshots(mainUrl, siteMap, verified, FIRECRAWL_API_KEY);
// Run Gemini Vision on captured screenshots
if (GEMINI_API_KEY && screenshots.length > 0) {
const vision = await runVisionAnalysis(screenshots, GEMINI_API_KEY);
channelData.visionAnalysis = vision.merged;
channelData.visionPerPage = vision.perPage;
}
// Store screenshots (without base64 — just metadata for report)
channelData.screenshots = screenshots.map(ss => ({
id: ss.id,
url: ss.base64 ? `data:image/png;base64,${ss.base64}` : ss.url,
channel: ss.channel,
capturedAt: ss.capturedAt,
caption: ss.caption,
sourceUrl: ss.sourceUrl,
}));
})());
}
// ─── Execute all tasks ───
await Promise.allSettled(tasks);