parseOptions 解析选项列表
(value any, questionIndex int)
| 305 | |
| 306 | // parseOptions 解析选项列表 |
| 307 | func (t *AskUserQuestionTool) parseOptions(value any, questionIndex int) ([]types.QuestionOption, error) { |
| 308 | optionsRaw, ok := value.([]any) |
| 309 | if !ok { |
| 310 | return nil, fmt.Errorf("question[%d].options must be an array", questionIndex) |
| 311 | } |
| 312 | |
| 313 | options := make([]types.QuestionOption, 0, len(optionsRaw)) |
| 314 | for j, oRaw := range optionsRaw { |
| 315 | oMap, ok := oRaw.(map[string]any) |
| 316 | if !ok { |
| 317 | return nil, fmt.Errorf("question[%d].options[%d] must be an object", questionIndex, j) |
| 318 | } |
| 319 | |
| 320 | opt := types.QuestionOption{ |
| 321 | Label: GetStringParam(oMap, "label", ""), |
| 322 | Description: GetStringParam(oMap, "description", ""), |
| 323 | } |
| 324 | options = append(options, opt) |
| 325 | } |
| 326 | |
| 327 | return options, nil |
| 328 | } |
| 329 | |
| 330 | // validateQuestion 验证单个问题 |
| 331 | func (t *AskUserQuestionTool) validateQuestion(q types.Question, index int) error { |
no test coverage detected