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

Method parseOptions

pkg/tools/builtin/ask_user.go:307–328  ·  view source on GitHub ↗

parseOptions 解析选项列表

(value any, questionIndex int)

Source from the content-addressed store, hash-verified

305
306// parseOptions 解析选项列表
307func (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 验证单个问题
331func (t *AskUserQuestionTool) validateQuestion(q types.Question, index int) error {

Callers 1

parseQuestionsMethod · 0.95

Calls 1

GetStringParamFunction · 0.85

Tested by

no test coverage detected