MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / useAskUserBridge

Function useAskUserBridge

cli/src/hooks/use-ask-user-bridge.ts:52–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50}
51
52export function useAskUserBridge() {
53 const setAskUserState = useChatStore((state) => state.setAskUserState)
54
55 useEffect(() => {
56 const unsubscribe = AskUserBridge.subscribe((request) => {
57 if (request) {
58 // Filter out redundant "Custom"/"Other" options since UI provides its own
59 const filteredQuestions = filterRedundantOptions(request.questions)
60 setAskUserState({
61 toolCallId: request.toolCallId,
62 questions: filteredQuestions,
63 // Initialize based on question type: multi-select → [], single-select → -1
64 selectedAnswers: filteredQuestions.map((q) => (q.multiSelect ? [] : -1)),
65 otherTexts: new Array(filteredQuestions.length).fill(''),
66 })
67 } else {
68 setAskUserState(null)
69 }
70 })
71 return unsubscribe
72 }, [setAskUserState])
73
74 const submitAnswers = (
75 answers: Array<{
76 questionIndex: number
77 selectedOption?: string
78 selectedOptions?: string[]
79 otherText?: string
80 }>
81 ) => {
82 // Don't clear input value - preserve user's input from before the questionnaire
83 AskUserBridge.submit({ answers })
84 }
85
86 const skip = () => {
87 // Don't clear input value - preserve user's input from before the questionnaire
88 AskUserBridge.submit({ skipped: true })
89 }
90
91 return { submitAnswers, skip }
92}

Callers 2

ChatFunction · 0.90
ChatInputBarFunction · 0.90

Calls 1

filterRedundantOptionsFunction · 0.85

Tested by

no test coverage detected