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

Method validateQuestion

pkg/tools/builtin/ask_user.go:331–355  ·  view source on GitHub ↗

validateQuestion 验证单个问题

(q types.Question, index int)

Source from the content-addressed store, hash-verified

329
330// validateQuestion 验证单个问题
331func (t *AskUserQuestionTool) validateQuestion(q types.Question, index int) error {
332 if q.Question == "" {
333 return fmt.Errorf("question[%d].question cannot be empty", index)
334 }
335 if q.Header == "" {
336 return fmt.Errorf("question[%d].header cannot be empty", index)
337 }
338 if len(q.Header) > 12 {
339 return fmt.Errorf("question[%d].header must be at most 12 characters, got %d", index, len(q.Header))
340 }
341 if len(q.Options) < 2 || len(q.Options) > 4 {
342 return fmt.Errorf("question[%d].options must have 2-4 items, got %d", index, len(q.Options))
343 }
344
345 for j, opt := range q.Options {
346 if opt.Label == "" {
347 return fmt.Errorf("question[%d].options[%d].label cannot be empty", index, j)
348 }
349 if opt.Description == "" {
350 return fmt.Errorf("question[%d].options[%d].description cannot be empty", index, j)
351 }
352 }
353
354 return nil
355}
356
357// ReceiveAnswer 接收用户回答(供外部调用)
358func (t *AskUserQuestionTool) ReceiveAnswer(requestID string, answers map[string]any) error {

Callers 1

ExecuteMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected