parseQuestions 解析问题列表
(value any)
| 270 | |
| 271 | // parseQuestions 解析问题列表 |
| 272 | func (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 解析选项列表 |
| 307 | func (t *AskUserQuestionTool) parseOptions(value any, questionIndex int) ([]types.QuestionOption, error) { |
no test coverage detected