(input: unknown)
| 6 | } |
| 7 | |
| 8 | export function parseCursorAskQuestionInput(input: unknown): { questions: AskUserQuestionQuestion[] } { |
| 9 | if (!isObject(input)) return { questions: [] } |
| 10 | |
| 11 | const rawQuestions = input.questions |
| 12 | if (!Array.isArray(rawQuestions)) return { questions: [] } |
| 13 | |
| 14 | const requestTitle = typeof input.title === 'string' ? input.title.trim() : '' |
| 15 | |
| 16 | const questions: AskUserQuestionQuestion[] = [] |
| 17 | for (const raw of rawQuestions) { |
| 18 | if (!isObject(raw)) continue |
| 19 | |
| 20 | const question = typeof raw.prompt === 'string' |
| 21 | ? raw.prompt.trim() |
| 22 | : typeof raw.question === 'string' |
| 23 | ? raw.question.trim() |
| 24 | : '' |
| 25 | const header = typeof raw.title === 'string' |
| 26 | ? raw.title.trim() |
| 27 | : typeof raw.header === 'string' |
| 28 | ? raw.header.trim() |
| 29 | : '' |
| 30 | const multiSelect = raw.allowMultiple === true || raw.multiSelect === true |
| 31 | const questionId = typeof raw.id === 'string' && raw.id.trim() |
| 32 | ? raw.id.trim() |
| 33 | : String(questions.length) |
| 34 | |
| 35 | const rawOptions = Array.isArray(raw.options) ? raw.options : [] |
| 36 | const options: AskUserQuestionQuestion['options'] = [] |
| 37 | for (const opt of rawOptions) { |
| 38 | if (!isObject(opt)) continue |
| 39 | const label = typeof opt.label === 'string' |
| 40 | ? opt.label.trim() |
| 41 | : typeof opt.id === 'string' |
| 42 | ? opt.id.trim() |
| 43 | : '' |
| 44 | if (!label) continue |
| 45 | const optionId = typeof opt.id === 'string' && opt.id.trim() |
| 46 | ? opt.id.trim() |
| 47 | : label |
| 48 | options.push({ id: optionId, label, description: null }) |
| 49 | } |
| 50 | |
| 51 | if (!question && options.length === 0) continue |
| 52 | |
| 53 | questions.push({ |
| 54 | id: questionId, |
| 55 | header: header.length > 0 ? header : (requestTitle.length > 0 ? requestTitle : null), |
| 56 | question, |
| 57 | options, |
| 58 | multiSelect |
| 59 | }) |
| 60 | } |
| 61 | |
| 62 | return { questions } |
| 63 | } |
no test coverage detected