MCPcopy Create free account
hub / github.com/anomalyco/opencode / QuestionPrompt

Function QuestionPrompt

packages/tui/src/routes/session/question.tsx:14–514  ·  view source on GitHub ↗
(props: { request: QuestionRequest; directory?: string })

Source from the content-addressed store, hash-verified

12const QUESTION_MODE = "question"
13
14export function QuestionPrompt(props: { request: QuestionRequest; directory?: string }) {
15 const sdk = useSDK()
16 const { theme } = useTheme()
17 const renderer = useRenderer()
18 const tuiConfig = useTuiConfig()
19 const modeStack = useOpencodeModeStack()
20
21 const questions = createMemo(() => props.request.questions)
22 const single = createMemo(() => questions().length === 1 && questions()[0]?.multiple !== true)
23 const tabs = createMemo(() => (single() ? 1 : questions().length + 1)) // questions + confirm tab (no confirm for single select)
24 const [tabHover, setTabHover] = createSignal<number | "confirm" | null>(null)
25 const [store, setStore] = createStore({
26 tab: 0,
27 answers: [] as QuestionAnswer[],
28 custom: [] as string[],
29 selected: 0,
30 editing: false,
31 })
32
33 let textarea: TextareaRenderable | undefined
34
35 const question = createMemo(() => questions()[store.tab])
36 const confirm = createMemo(() => !single() && store.tab === questions().length)
37 const options = createMemo(() => question()?.options ?? [])
38 const custom = createMemo(() => question()?.custom !== false)
39 const other = createMemo(() => custom() && store.selected === options().length)
40 const input = createMemo(() => store.custom[store.tab] ?? "")
41 const multi = createMemo(() => question()?.multiple === true)
42 const customPicked = createMemo(() => {
43 const value = input()
44 if (!value) return false
45 return store.answers[store.tab]?.includes(value) ?? false
46 })
47
48 function submit() {
49 const answers = questions().map((_, i) => store.answers[i] ?? [])
50 void sdk.client.question.reply({
51 requestID: props.request.id,
52 directory: props.directory,
53 answers,
54 })
55 }
56
57 function reject() {
58 void sdk.client.question.reject({
59 requestID: props.request.id,
60 directory: props.directory,
61 })
62 }
63
64 function pick(answer: string, custom: boolean = false) {
65 const answers = [...store.answers]
66 answers[store.tab] = [answer]
67 setStore("answers", answers)
68 if (custom) {
69 const inputs = [...store.custom]
70 inputs[store.tab] = answer
71 setStore("custom", inputs)

Callers

nothing calls this directly

Calls 15

useTuiConfigFunction · 0.90
useOpencodeModeStackFunction · 0.90
selectedForegroundFunction · 0.90
tintFunction · 0.90
setStoreFunction · 0.85
selectTabFunction · 0.85
isActiveFunction · 0.85
isAnsweredFunction · 0.85
pushMethod · 0.80
inputFunction · 0.70
pickFunction · 0.70
submitFunction · 0.70

Tested by

no test coverage detected