fix: move topic prompt handling to message thunk and fix prompt logic (#9569)

This commit is contained in:
Yricky 2025-08-26 22:20:16 +08:00 committed by GitHub
parent 5bbc35695a
commit 267b41242d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 20 deletions

View File

@ -241,16 +241,12 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
baseUserMessage.mentions = mentionedModels baseUserMessage.mentions = mentionedModels
} }
const assistantWithTopicPrompt = topic.prompt
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
: assistant
baseUserMessage.usage = await estimateUserPromptUsage(baseUserMessage) baseUserMessage.usage = await estimateUserPromptUsage(baseUserMessage)
const { message, blocks } = getUserMessage(baseUserMessage) const { message, blocks } = getUserMessage(baseUserMessage)
message.traceId = parent?.spanContext().traceId message.traceId = parent?.spanContext().traceId
dispatch(_sendMessage(message, blocks, assistantWithTopicPrompt, topic.id)) dispatch(_sendMessage(message, blocks, assistant, topic.id))
// Clear input // Clear input
setText('') setText('')

View File

@ -100,11 +100,8 @@ const MessageItem: FC<Props> = ({
const handleEditResend = useCallback( const handleEditResend = useCallback(
async (blocks: MessageBlock[]) => { async (blocks: MessageBlock[]) => {
const assistantWithTopicPrompt = topic.prompt
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
: assistant
try { try {
await resendUserMessageWithEdit(message, blocks, assistantWithTopicPrompt) await resendUserMessageWithEdit(message, blocks, assistant)
stopEditing() stopEditing()
} catch (error) { } catch (error) {
logger.error('Failed to resend message:', error as Error) logger.error('Failed to resend message:', error as Error)

View File

@ -150,10 +150,7 @@ const MessageMenubar: FC<Props> = (props) => {
const handleResendUserMessage = useCallback( const handleResendUserMessage = useCallback(
async (messageUpdate?: Message) => { async (messageUpdate?: Message) => {
if (!loading) { if (!loading) {
const assistantWithTopicPrompt = topic.prompt await resendMessage(messageUpdate ?? message, assistant)
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
: assistant
await resendMessage(messageUpdate ?? message, assistantWithTopicPrompt)
} }
}, },
[assistant, loading, message, resendMessage, topic.prompt] [assistant, loading, message, resendMessage, topic.prompt]
@ -379,12 +376,8 @@ const MessageMenubar: FC<Props> = (props) => {
// const _message = resetAssistantMessage(message, selectedModel) // const _message = resetAssistantMessage(message, selectedModel)
// editMessage(message.id, { ..._message }) // REMOVED // editMessage(message.id, { ..._message }) // REMOVED
const assistantWithTopicPrompt = topic.prompt
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
: assistant
// Call the function from the hook // Call the function from the hook
regenerateAssistantMessage(message, assistantWithTopicPrompt) regenerateAssistantMessage(message, assistant)
} }
// 按条件筛选能够提及的模型该函数仅在isAssistantMessage时会用到 // 按条件筛选能够提及的模型该函数仅在isAssistantMessage时会用到

View File

@ -288,14 +288,18 @@ const dispatchMultiModelResponses = async (
} }
// --- End Helper Function --- // --- End Helper Function ---
// 发送和处理助手响应的实现函数,话题提示词在此拼接
const fetchAndProcessAssistantResponseImpl = async ( const fetchAndProcessAssistantResponseImpl = async (
dispatch: AppDispatch, dispatch: AppDispatch,
getState: () => RootState, getState: () => RootState,
topicId: string, topicId: string,
assistant: Assistant, origAssistant: Assistant,
assistantMessage: Message // Pass the prepared assistant message (new or reset) assistantMessage: Message // Pass the prepared assistant message (new or reset)
) => { ) => {
const topic = origAssistant.topics.find((t) => t.id === topicId)
const assistant = topic?.prompt
? { ...origAssistant, prompt: `${origAssistant.prompt}\n${topic.prompt}` }
: origAssistant
const assistantMsgId = assistantMessage.id const assistantMsgId = assistantMessage.id
let callbacks: StreamProcessorCallbacks = {} let callbacks: StreamProcessorCallbacks = {}
try { try {