// The optional "About your AI use" questions asked after the roadmap questions. Client-safe. // Answers are stored in D1 (ai_surveys) against the signed-in account and never sent to analytics. import type { Option } from "@/lib/onboarding"; export type AiSurvey = { role?: string; uses: string[]; usesOther?: string; tools: string[]; dailyHours?: string; aiYears?: string; depth?: string; coding?: string; updatedAt?: string; }; export const ROLES: Option[] = [ { id: "student", label: "Student" }, { id: "developer", label: "Software developer or engineer" }, { id: "researcher", label: "Researcher or scientist" }, { id: "creator", label: "Creator", hint: "Video, art, music, writing" }, { id: "founder", label: "Founder or business owner" }, { id: "professional", label: "Professional in a non-technical role", hint: "Marketing, sales, operations, law, finance" }, { id: "healthcare", label: "Healthcare or medicine" }, { id: "educator", label: "Teacher or educator" }, { id: "hobbyist", label: "Hobbyist or just curious" }, { id: "other", label: "Something else" }, ]; export const USES: Option[] = [ { id: "coding", label: "Writing code and software" }, { id: "writing", label: "Writing and content" }, { id: "learning", label: "Learning and studying" }, { id: "science", label: "Scientific research" }, { id: "drug", label: "Drug discovery and biotech" }, { id: "medicine", label: "Healthcare and medicine" }, { id: "robotics", label: "Robotics" }, { id: "engineering", label: "Engineering and hardware" }, { id: "data", label: "Data analysis" }, { id: "finance", label: "Finance and trading" }, { id: "legal", label: "Legal work" }, { id: "marketing", label: "Marketing and sales" }, { id: "support", label: "Customer support" }, { id: "design", label: "Images and design" }, { id: "video", label: "Video and film" }, { id: "audio", label: "Music and audio" }, { id: "games", label: "Games" }, { id: "teaching", label: "Teaching" }, { id: "automation", label: "Automating tasks with agents" }, { id: "productivity", label: "Everyday productivity" }, { id: "other", label: "Something else" }, ]; export const TOOLS: Option[] = [ { id: "chatgpt", label: "ChatGPT" }, { id: "claude", label: "Claude" }, { id: "gemini", label: "Gemini" }, { id: "copilot", label: "Microsoft Copilot" }, { id: "perplexity", label: "Perplexity" }, { id: "grok", label: "Grok" }, { id: "claude-code", label: "Claude Code" }, { id: "codex", label: "Codex" }, { id: "cursor", label: "Cursor" }, { id: "github-copilot", label: "GitHub Copilot" }, { id: "midjourney", label: "Midjourney" }, { id: "comfyui", label: "ComfyUI or Stable Diffusion" }, { id: "video-gen", label: "AI video tools", hint: "Sora, Veo, Runway, Kling" }, { id: "local", label: "Local models", hint: "Ollama, LM Studio" }, { id: "api", label: "AI APIs from my own code" }, { id: "other", label: "Something else" }, ]; export const DAILY_HOURS: Option[] = [ { id: "none", label: "I don't use AI yet" }, { id: "under-30m", label: "Less than 30 minutes" }, { id: "30m-1h", label: "30 minutes to an hour" }, { id: "1-3h", label: "1 to 3 hours" }, { id: "3-6h", label: "3 to 6 hours" }, { id: "6h-plus", label: "More than 6 hours" }, ]; export const AI_YEARS: Option[] = [ { id: "new", label: "I'm just starting" }, { id: "under-6m", label: "Less than 6 months" }, { id: "6-12m", label: "6 to 12 months" }, { id: "1-2y", label: "1 to 2 years" }, { id: "2-3y", label: "2 to 3 years" }, { id: "3y-plus", label: "More than 3 years" }, ]; // Ordered from lightest to deepest use export const DEPTHS: Option[] = [ { id: "chat", label: "Chatted with an AI assistant" }, { id: "workflows", label: "Set up projects, custom GPTs or saved prompts" }, { id: "automation", label: "Automated tasks with AI", hint: "Zapier, n8n, computer-use agents" }, { id: "agent-coding", label: "Built software with a coding agent", hint: "Claude Code, Codex, Cursor" }, { id: "api", label: "Called AI APIs from my own app" }, { id: "open-models", label: "Ran open models on my own computer or GPU" }, { id: "fine-tune", label: "Fine-tuned or trained a model" }, { id: "research", label: "Published AI research or models" }, ]; export const CODING: Option[] = [ { id: "none", label: "None" }, { id: "little", label: "A little", hint: "Small scripts, tutorials" }, { id: "comfortable", label: "Comfortable", hint: "Side projects, automations" }, { id: "professional", label: "I code for a living" }, { id: "senior", label: "10+ years as a developer" }, ]; const OTHER_MAX = 200; const pickOne = (options: Option[], value: unknown) => typeof value === "string" && options.some((o) => o.id === value) ? value : undefined; const pickMany = (options: Option[], value: unknown) => Array.isArray(value) ? [...new Set(value.filter((v): v is string => pickOne(options, v) !== undefined))] : []; // Keeps only known answers from a request body or database row; returns null when nothing was answered export function parseSurvey(raw: unknown): AiSurvey | null { if (!raw || typeof raw !== "object") return null; const r = raw as Record; const uses = pickMany(USES, r.uses); const otherRaw = r.usesOther ?? r.uses_other; const usesOther = uses.includes("other") && typeof otherRaw === "string" ? otherRaw.trim().slice(0, OTHER_MAX) : ""; const updatedAt = r.updatedAt ?? r.updated_at; const survey: AiSurvey = { role: pickOne(ROLES, r.role), uses, usesOther: usesOther || undefined, tools: pickMany(TOOLS, r.tools), dailyHours: pickOne(DAILY_HOURS, r.dailyHours ?? r.daily_hours), aiYears: pickOne(AI_YEARS, r.aiYears ?? r.ai_years), depth: pickOne(DEPTHS, r.depth), coding: pickOne(CODING, r.coding), }; const answered = survey.uses.length || survey.tools.length || survey.role || survey.dailyHours || survey.aiYears || survey.depth || survey.coding; if (!answered) return null; return typeof updatedAt === "string" ? { ...survey, updatedAt } : survey; }