← back to ClawCoder
src/lib/onboarding/resolver.ts
88 lines
import type { AgeGroup, SkillLevel } from '@/lib/profiles/types'
import { getProfile } from '@/lib/profiles/data'
const skillMap: Record<string, SkillLevel> = {
beginner: 'beginner',
somewhat: 'beginner',
comfortable: 'intermediate',
expert: 'expert',
}
const ageMap: Record<string, AgeGroup> = {
teen: 'teen',
young_adult: 'young_adult',
professional: 'professional',
pre_senior: 'pre_senior',
senior: 'senior',
}
/**
* Map onboarding wizard answers to the best-fit profile.
* Falls back to professional-beginner when no exact match is found.
*/
export function resolveProfile(answers: Record<string, string>) {
const skill = skillMap[answers.comfort] || 'beginner'
const age = ageMap[answers.age] || 'professional'
const slug = `${age}-${skill}`
return getProfile(slug) || getProfile('professional-beginner')!
}
/**
* Produce a human-readable label for a given answer value.
*/
export function answerLabel(questionId: string, value: string): string {
const labels: Record<string, Record<string, string>> = {
profile: {
learning: 'Help with my computer',
building: 'Build websites or apps',
documents: 'Work with documents',
business: 'Business workflows',
},
comfort: {
beginner: 'New to this',
somewhat: 'Somewhat comfortable',
comfortable: 'Comfortable',
expert: 'Expert',
},
age: {
teen: 'Student (13-17)',
young_adult: 'Young professional (18-30)',
professional: 'Mid-career (31-50)',
pre_senior: 'Seasoned pro (51-65)',
senior: 'Lifelong learner (65+)',
},
risk: {
no: 'No',
some: 'Some',
yes: 'Yes (health/finance/work)',
},
style: {
detailed: 'Explain step-by-step',
balanced: 'Only key points',
minimal: 'Just do it',
},
tools: {
no: 'No, keep it simple',
maybe: 'Maybe later',
yes: 'Yes -- design, docs, or databases',
},
workflow: {
single: 'One task at a time',
checklist: 'Checklists',
projects: 'Full projects',
},
updates: {
yes: 'Yes, auto-update',
ask: 'Ask me first',
no: 'No, keep it fixed',
},
finish: {
generate: 'Generate my setup!',
review: 'Let me review first',
},
}
return labels[questionId]?.[value] || value
}