Refetch suggested questions after reset in context generate modal

This commit is contained in:
zhsama
2026-01-29 19:16:43 +08:00
parent 8f7b9e2de4
commit 9b62be2eb1
3 changed files with 48 additions and 5 deletions

View File

@ -150,7 +150,7 @@ type UseContextGenerateResult = {
handleCompletionParamsChange: (newParams: FormValue) => void
handleGenerate: () => Promise<void>
handleReset: () => void
handleFetchSuggestedQuestions: () => Promise<void>
handleFetchSuggestedQuestions: (options?: { force?: boolean }) => Promise<void>
abortSuggestedQuestions: () => void
resetSuggestions: () => void
defaultAssistantMessage: string
@ -364,12 +364,13 @@ const useContextGenerate = ({
clearVersions()
}, [clearVersions, isGenerating, setPromptMessages])
const handleFetchSuggestedQuestions = useCallback(async () => {
const handleFetchSuggestedQuestions = useCallback(async (options?: { force?: boolean }) => {
const forceFetch = options?.force
if (!toolNodeId || !paramKey)
return
if (!modelConfig.name || !modelConfig.provider)
return
if (hasFetchedSuggestions || isFetchingSuggestions || !isInitView)
if (!forceFetch && (hasFetchedSuggestions || isFetchingSuggestions || !isInitView))
return
setFetchingSuggestionsTrue()

View File

@ -131,6 +131,13 @@ const ContextGenerateModal = forwardRef<ContextGenerateModalHandle, Props>(({
onClose()
}, [abortSuggestedQuestions, onClose, resetSuggestions])
const handleResetWithSuggestions = useCallback(() => {
abortSuggestedQuestions()
handleReset()
resetSuggestions()
void handleFetchSuggestedQuestions({ force: true })
}, [abortSuggestedQuestions, handleFetchSuggestedQuestions, handleReset, resetSuggestions])
useImperativeHandle(ref, () => ({
onOpen: () => {
void handleFetchSuggestedQuestions()
@ -223,7 +230,7 @@ const ContextGenerateModal = forwardRef<ContextGenerateModalHandle, Props>(({
inputValue={inputValue}
onInputChange={setInputValue}
onGenerate={handleGenerate}
onReset={handleReset}
onReset={handleResetWithSuggestions}
suggestedQuestions={suggestedQuestions}
hasFetchedSuggestions={hasFetchedSuggestions}
model={model}