AI Resource Pro / website · airesourcepro.com / src / lib / ai-survey.ts
| 1 | // The optional "About your AI use" questions asked after the roadmap questions. Client-safe. |
| 2 | // Answers are stored in D1 (ai_surveys) against the signed-in account and never sent to analytics. |
| 3 | import type { Option } from "@/lib/onboarding"; |
| 4 | |
| 5 | export type AiSurvey = { |
| 6 | role?: string; |
| 7 | uses: string[]; |
| 8 | usesOther?: string; |
| 9 | tools: string[]; |
| 10 | dailyHours?: string; |
| 11 | aiYears?: string; |
| 12 | depth?: string; |
| 13 | coding?: string; |
| 14 | updatedAt?: string; |
| 15 | }; |
| 16 | |
| 17 | export const ROLES: Option<string>[] = [ |
| 18 | { id: "student", label: "Student" }, |
| 19 | { id: "developer", label: "Software developer or engineer" }, |
| 20 | { id: "researcher", label: "Researcher or scientist" }, |
| 21 | { id: "creator", label: "Creator", hint: "Video, art, music, writing" }, |
| 22 | { id: "founder", label: "Founder or business owner" }, |
| 23 | { id: "professional", label: "Professional in a non-technical role", hint: "Marketing, sales, operations, law, finance" }, |
| 24 | { id: "healthcare", label: "Healthcare or medicine" }, |
| 25 | { id: "educator", label: "Teacher or educator" }, |
| 26 | { id: "hobbyist", label: "Hobbyist or just curious" }, |
| 27 | { id: "other", label: "Something else" }, |
| 28 | ]; |
| 29 | |
| 30 | export const USES: Option<string>[] = [ |
| 31 | { id: "coding", label: "Writing code and software" }, |
| 32 | { id: "writing", label: "Writing and content" }, |
| 33 | { id: "learning", label: "Learning and studying" }, |
| 34 | { id: "science", label: "Scientific research" }, |
| 35 | { id: "drug", label: "Drug discovery and biotech" }, |
| 36 | { id: "medicine", label: "Healthcare and medicine" }, |
| 37 | { id: "robotics", label: "Robotics" }, |
| 38 | { id: "engineering", label: "Engineering and hardware" }, |
| 39 | { id: "data", label: "Data analysis" }, |
| 40 | { id: "finance", label: "Finance and trading" }, |
| 41 | { id: "legal", label: "Legal work" }, |
| 42 | { id: "marketing", label: "Marketing and sales" }, |
| 43 | { id: "support", label: "Customer support" }, |
| 44 | { id: "design", label: "Images and design" }, |
| 45 | { id: "video", label: "Video and film" }, |
| 46 | { id: "audio", label: "Music and audio" }, |
| 47 | { id: "games", label: "Games" }, |
| 48 | { id: "teaching", label: "Teaching" }, |
| 49 | { id: "automation", label: "Automating tasks with agents" }, |
| 50 | { id: "productivity", label: "Everyday productivity" }, |
| 51 | { id: "other", label: "Something else" }, |
| 52 | ]; |
| 53 | |
| 54 | export const TOOLS: Option<string>[] = [ |
| 55 | { id: "chatgpt", label: "ChatGPT" }, |
| 56 | { id: "claude", label: "Claude" }, |
| 57 | { id: "gemini", label: "Gemini" }, |
| 58 | { id: "copilot", label: "Microsoft Copilot" }, |
| 59 | { id: "perplexity", label: "Perplexity" }, |
| 60 | { id: "grok", label: "Grok" }, |
| 61 | { id: "claude-code", label: "Claude Code" }, |
| 62 | { id: "codex", label: "Codex" }, |
| 63 | { id: "cursor", label: "Cursor" }, |
| 64 | { id: "github-copilot", label: "GitHub Copilot" }, |
| 65 | { id: "midjourney", label: "Midjourney" }, |
| 66 | { id: "comfyui", label: "ComfyUI or Stable Diffusion" }, |
| 67 | { id: "video-gen", label: "AI video tools", hint: "Sora, Veo, Runway, Kling" }, |
| 68 | { id: "local", label: "Local models", hint: "Ollama, LM Studio" }, |
| 69 | { id: "api", label: "AI APIs from my own code" }, |
| 70 | { id: "other", label: "Something else" }, |
| 71 | ]; |
| 72 | |
| 73 | export const DAILY_HOURS: Option<string>[] = [ |
| 74 | { id: "none", label: "I don't use AI yet" }, |
| 75 | { id: "under-30m", label: "Less than 30 minutes" }, |
| 76 | { id: "30m-1h", label: "30 minutes to an hour" }, |
| 77 | { id: "1-3h", label: "1 to 3 hours" }, |
| 78 | { id: "3-6h", label: "3 to 6 hours" }, |
| 79 | { id: "6h-plus", label: "More than 6 hours" }, |
| 80 | ]; |
| 81 | |
| 82 | export const AI_YEARS: Option<string>[] = [ |
| 83 | { id: "new", label: "I'm just starting" }, |
| 84 | { id: "under-6m", label: "Less than 6 months" }, |
| 85 | { id: "6-12m", label: "6 to 12 months" }, |
| 86 | { id: "1-2y", label: "1 to 2 years" }, |
| 87 | { id: "2-3y", label: "2 to 3 years" }, |
| 88 | { id: "3y-plus", label: "More than 3 years" }, |
| 89 | ]; |
| 90 | |
| 91 | // Ordered from lightest to deepest use |
| 92 | export const DEPTHS: Option<string>[] = [ |
| 93 | { id: "chat", label: "Chatted with an AI assistant" }, |
| 94 | { id: "workflows", label: "Set up projects, custom GPTs or saved prompts" }, |
| 95 | { id: "automation", label: "Automated tasks with AI", hint: "Zapier, n8n, computer-use agents" }, |
| 96 | { id: "agent-coding", label: "Built software with a coding agent", hint: "Claude Code, Codex, Cursor" }, |
| 97 | { id: "api", label: "Called AI APIs from my own app" }, |
| 98 | { id: "open-models", label: "Ran open models on my own computer or GPU" }, |
| 99 | { id: "fine-tune", label: "Fine-tuned or trained a model" }, |
| 100 | { id: "research", label: "Published AI research or models" }, |
| 101 | ]; |
| 102 | |
| 103 | export const CODING: Option<string>[] = [ |
| 104 | { id: "none", label: "None" }, |
| 105 | { id: "little", label: "A little", hint: "Small scripts, tutorials" }, |
| 106 | { id: "comfortable", label: "Comfortable", hint: "Side projects, automations" }, |
| 107 | { id: "professional", label: "I code for a living" }, |
| 108 | { id: "senior", label: "10+ years as a developer" }, |
| 109 | ]; |
| 110 | |
| 111 | const OTHER_MAX = 200; |
| 112 | |
| 113 | const pickOne = (options: Option<string>[], value: unknown) => |
| 114 | typeof value === "string" && options.some((o) => o.id === value) ? value : undefined; |
| 115 | |
| 116 | const pickMany = (options: Option<string>[], value: unknown) => |
| 117 | Array.isArray(value) ? [...new Set(value.filter((v): v is string => pickOne(options, v) !== undefined))] : []; |
| 118 | |
| 119 | // Keeps only known answers from a request body or database row; returns null when nothing was answered |
| 120 | export function parseSurvey(raw: unknown): AiSurvey | null { |
| 121 | if (!raw || typeof raw !== "object") return null; |
| 122 | const r = raw as Record<string, unknown>; |
| 123 | const uses = pickMany(USES, r.uses); |
| 124 | const otherRaw = r.usesOther ?? r.uses_other; |
| 125 | const usesOther = uses.includes("other") && typeof otherRaw === "string" ? otherRaw.trim().slice(0, OTHER_MAX) : ""; |
| 126 | const updatedAt = r.updatedAt ?? r.updated_at; |
| 127 | const survey: AiSurvey = { |
| 128 | role: pickOne(ROLES, r.role), |
| 129 | uses, |
| 130 | usesOther: usesOther || undefined, |
| 131 | tools: pickMany(TOOLS, r.tools), |
| 132 | dailyHours: pickOne(DAILY_HOURS, r.dailyHours ?? r.daily_hours), |
| 133 | aiYears: pickOne(AI_YEARS, r.aiYears ?? r.ai_years), |
| 134 | depth: pickOne(DEPTHS, r.depth), |
| 135 | coding: pickOne(CODING, r.coding), |
| 136 | }; |
| 137 | const answered = survey.uses.length || survey.tools.length || |
| 138 | survey.role || survey.dailyHours || survey.aiYears || survey.depth || survey.coding; |
| 139 | if (!answered) return null; |
| 140 | return typeof updatedAt === "string" ? { ...survey, updatedAt } : survey; |
| 141 | } |