Download this file
| 1 | package runnerproto |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "encoding/json" |
| 6 | ) |
| 7 | |
| 8 | type QuestionField struct { |
| 9 | Key, Prompt string |
| 10 | Options []string `json:",omitempty"` |
| 11 | } |
| 12 | |
| 13 | func DisplayJSON(raw string) string { |
| 14 | var value any |
| 15 | if json.Unmarshal([]byte(raw), &value) != nil { |
| 16 | return raw |
| 17 | } |
| 18 | var buf bytes.Buffer |
| 19 | enc := json.NewEncoder(&buf) |
| 20 | enc.SetEscapeHTML(false) |
| 21 | enc.SetIndent("", " ") |
| 22 | if enc.Encode(value) != nil { |
| 23 | return raw |
| 24 | } |
| 25 | return buf.String() |
| 26 | } |
| 27 | |
| 28 | func QuestionFields(kind, raw string) []QuestionField { |
| 29 | var q struct { |
| 30 | Provider, Name, Question string |
| 31 | Input struct { |
| 32 | Questions []struct { |
| 33 | Question, Header string |
| 34 | Options []struct{ Label string } |
| 35 | MultiSelect bool |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | if json.Unmarshal([]byte(raw), &q) != nil { |
| 40 | return nil |
| 41 | } |
| 42 | if kind == "person" && q.Question != "" { |
| 43 | return []QuestionField{{Key: "answer", Prompt: q.Question}} |
| 44 | } |
| 45 | if (q.Provider != "claude" || q.Name != "AskUserQuestion") && (q.Provider != "codex" || q.Name != "request_user_input") { |
| 46 | return nil |
| 47 | } |
| 48 | var fields []QuestionField |
| 49 | for _, f := range q.Input.Questions { |
| 50 | key := f.Question |
| 51 | if q.Provider == "codex" { |
| 52 | key = f.Header |
| 53 | } |
| 54 | if key == "" { |
| 55 | return nil |
| 56 | } |
| 57 | field := QuestionField{Key: key, Prompt: f.Question} |
| 58 | if !f.MultiSelect { |
| 59 | for _, option := range f.Options { |
| 60 | if option.Label != "" { |
| 61 | field.Options = append(field.Options, option.Label) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | fields = append(fields, field) |
| 66 | } |
| 67 | return fields |
| 68 | } |
| 69 | |