// The onboarding questions and the profile they produce. Client-safe: no filesystem or database access here. import { TRACKS, type TrackSlug } from "@/lib/tracks"; import type { Level } from "@/lib/tutorial-types"; // Set when someone skips the questions after signing in, so later sign-ins stop sending them there (read in auth/callback) export const SKIP_ONBOARDING_COOKIE = "airp-onboarding-skipped"; export type GoalId = "code" | "everyday" | "automate" | "video" | "own-gpu" | "current"; export type WeeklyTime = "light" | "steady" | "deep"; export type Format = "video" | "written" | "both"; // What a user told us during onboarding. Stored in Supabase (learning_profiles) once they sign in. export type LearningProfile = { goals: GoalId[]; tracks: TrackSlug[]; level: Level; weeklyTime: WeeklyTime; format: Format; updatedAt?: string; }; export type Option = { id: T; label: string; hint?: string }; export const GOALS: (Option & { tracks: TrackSlug[] })[] = [ { id: "code", label: "Ship code with an AI agent", hint: "Claude Code, Codex", tracks: ["claude", "chatgpt"] }, { id: "everyday", label: "Get better answers from Claude and ChatGPT", hint: "Prompting, projects", tracks: ["claude", "chatgpt"] }, { id: "automate", label: "Hand browser and desktop chores to AI", hint: "Computer use", tracks: ["computer-use"] }, { id: "video", label: "Make AI video", hint: "ComfyUI, open models", tracks: ["ai-video"] }, { id: "own-gpu", label: "Run open models on my own GPU", hint: "Runpod", tracks: ["ai-video"] }, { id: "current", label: "Keep up with what's new", hint: "A bit of everything", tracks: TRACKS.map((t) => t.slug) }, ]; export const LEVELS: Option[] = [ { id: "Beginner", label: "Beginner", hint: "I've chatted with AI, but not much more" }, { id: "Intermediate", label: "Intermediate", hint: "I use AI tools most weeks" }, { id: "Advanced", label: "Advanced", hint: "I build with agents, APIs or my own models" }, ]; export const WEEKLY_TIMES: (Option & { minutes: number })[] = [ { id: "light", label: "An hour or so a week", minutes: 60 }, { id: "steady", label: "A few hours a week", minutes: 180 }, { id: "deep", label: "Most days", minutes: 420 }, ]; export const FORMATS: Option[] = [ { id: "video", label: "Videos", hint: "Watch it done first" }, { id: "written", label: "Written guides", hint: "Read and follow along" }, { id: "both", label: "Both", hint: "Whatever fits the topic" }, ]; // Tracks implied by the chosen goals, in site order export function tracksForGoals(goals: GoalId[]): TrackSlug[] { const wanted = new Set(GOALS.filter((g) => goals.includes(g.id)).flatMap((g) => g.tracks)); return TRACKS.map((t) => t.slug).filter((slug) => wanted.has(slug)); } const isIn = (options: Option[], value: unknown): value is T => options.some((o) => o.id === value); // Checks a profile read from storage or the database; returns null if anything is missing or unknown export function parseProfile(raw: unknown): LearningProfile | null { if (!raw || typeof raw !== "object") return null; const r = raw as Record; const goals = Array.isArray(r.goals) ? r.goals.filter((g): g is GoalId => isIn(GOALS, g)) : []; const trackSlugs = TRACKS.map((t) => t.slug) as string[]; const tracks = Array.isArray(r.tracks) ? r.tracks.filter((t): t is TrackSlug => trackSlugs.includes(t)) : []; const weeklyTime = r.weeklyTime ?? r.weekly_time; const updatedAt = r.updatedAt ?? r.updated_at; if (goals.length === 0 || !isIn(LEVELS, r.level) || !isIn(WEEKLY_TIMES, weeklyTime) || !isIn(FORMATS, r.format)) { return null; } return { goals, tracks: tracks.length ? tracks : tracksForGoals(goals), level: r.level, weeklyTime, format: r.format, updatedAt: typeof updatedAt === "string" ? updatedAt : undefined, }; } // A database row for learning_profiles export function profileRow(userId: string, p: LearningProfile) { return { user_id: userId, goals: p.goals, tracks: p.tracks, level: p.level, weekly_time: p.weeklyTime, format: p.format, updated_at: new Date().toISOString(), }; } export const labelFor = (options: Option[], id: T) => options.find((o) => o.id === id)?.label ?? id;