MCPcopy Create free account
hub / github.com/astercloud/aster / parseQuestions

Method parseQuestions

pkg/tools/builtin/ask_user.go:272–304  ·  view source on GitHub ↗

parseQuestions 解析问题列表

(value any)

Source from the content-addressed store, hash-verified

270
271// parseQuestions 解析问题列表
272func (t *AskUserQuestionTool) parseQuestions(value any) ([]types.Question, error) {
273 questionsRaw, ok := value.([]any)
274 if !ok {
275 return nil, errors.New("questions must be an array")
276 }
277
278 questions := make([]types.Question, 0, len(questionsRaw))
279 for i, qRaw := range questionsRaw {
280 qMap, ok := qRaw.(map[string]any)
281 if !ok {
282 return nil, fmt.Errorf("question[%d] must be an object", i)
283 }
284
285 q := types.Question{
286 Question: GetStringParam(qMap, "question", ""),
287 Header: GetStringParam(qMap, "header", ""),
288 MultiSelect: GetBoolParam(qMap, "multi_select", false),
289 }
290
291 // 解析选项
292 if optionsRaw, exists := qMap["options"]; exists {
293 options, err := t.parseOptions(optionsRaw, i)
294 if err != nil {
295 return nil, err
296 }
297 q.Options = options
298 }
299
300 questions = append(questions, q)
301 }
302
303 return questions, nil
304}
305
306// parseOptions 解析选项列表
307func (t *AskUserQuestionTool) parseOptions(value any, questionIndex int) ([]types.QuestionOption, error) {

Callers 1

ExecuteMethod · 0.95

Calls 3

parseOptionsMethod · 0.95
GetStringParamFunction · 0.85
GetBoolParamFunction · 0.85

Tested by

no test coverage detected