MCPcopy Create free account
hub / github.com/tiann/hapi / parseAskUserQuestionInput

Function parseAskUserQuestionInput

web/src/components/ToolCard/askUserQuestion.ts:30–65  ·  view source on GitHub ↗
(input: unknown)

Source from the content-addressed store, hash-verified

28}
29
30export function parseAskUserQuestionInput(input: unknown): { questions: AskUserQuestionQuestion[] } {
31 if (!isObject(input)) return { questions: [] }
32
33 const rawQuestions = input.questions
34 if (!Array.isArray(rawQuestions)) return { questions: [] }
35
36 const questions: AskUserQuestionQuestion[] = []
37 for (const raw of rawQuestions) {
38 if (!isObject(raw)) continue
39
40 const question = typeof raw.question === 'string' ? raw.question.trim() : ''
41 const header = typeof raw.header === 'string' ? raw.header.trim() : ''
42 const multiSelect = typeof raw.multiSelect === 'boolean' ? raw.multiSelect : false
43
44 const rawOptions = Array.isArray(raw.options) ? raw.options : []
45 const options: AskUserQuestionOption[] = []
46 for (const opt of rawOptions) {
47 if (!isObject(opt)) continue
48 const label = typeof opt.label === 'string' ? opt.label.trim() : ''
49 if (!label) continue
50 const description = typeof opt.description === 'string' ? opt.description.trim() : null
51 options.push({ label, description })
52 }
53
54 if (!question && options.length === 0) continue
55
56 questions.push({
57 header: header.length > 0 ? header : null,
58 question,
59 options,
60 multiSelect
61 })
62 }
63
64 return { questions }
65}
66
67export function extractAskUserQuestionQuestionsInfo(input: unknown): AskUserQuestionQuestionInfo[] | null {
68 if (!isObject(input)) return null

Callers 2

AskUserQuestionFooterFunction · 0.90
AskUserQuestionViewFunction · 0.90

Calls 2

isObjectFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected