Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat: stop response call api (#340)
Joelb16a7b0b3b96
diff --git a/web/app/components/app/chat/index.tsx b/web/app/components/app/chat/index.tsxindex 591fca47b5e..18cd5e9a282 100644--- a/web/app/components/app/chat/index.tsx+++ b/web/app/components/app/chat/index.tsx@@ -53,6 +53,7 @@ export type IChatProps = {displayScene?: DisplaySceneuseCurrentUserAvatar?: booleanisResponsing?: boolean+ canStopResponsing?: booleanabortResponsing?: () => voidcontrolClearQuery?: numbercontrolFocus?: number@@ -412,6 +413,7 @@ const Chat: FC<IChatProps> = ({displayScene,useCurrentUserAvatar,isResponsing,+ canStopResponsing,abortResponsing,controlClearQuery,controlFocus,@@ -508,7 +510,7 @@ const Chat: FC<IChatProps> = ({{!isHideSendInput && (<div className={cn(!feedbackDisabled && '!left-3.5 !right-3.5', 'absolute z-10 bottom-0 left-0 right-0')}>- {isResponsing && (+ {(isResponsing && canStopResponsing) && (<div className='flex justify-center mb-4'><Button className='flex items-center space-x-1 bg-white' onClick={() => abortResponsing?.()}>{stopIcon}diff --git a/web/app/components/app/configuration/debug/index.tsx b/web/app/components/app/configuration/debug/index.tsxindex 14156896e37..3800795c766 100644--- a/web/app/components/app/configuration/debug/index.tsx+++ b/web/app/components/app/configuration/debug/index.tsx@@ -16,7 +16,7 @@ import type { IChatItem } from '@/app/components/app/chat'import Chat from '@/app/components/app/chat'import ConfigContext from '@/context/debug-configuration'import { ToastContext } from '@/app/components/base/toast'-import { fetchConvesationMessages, fetchSuggestedQuestions, sendChatMessage, sendCompletionMessage } from '@/service/debug'+import { fetchConvesationMessages, fetchSuggestedQuestions, sendChatMessage, sendCompletionMessage, stopChatMessageResponding } from '@/service/debug'import Button from '@/app/components/base/button'import type { ModelConfig as BackendModelConfig } from '@/types/app'import { promptVariablesToUserInputsForm } from '@/utils/model-config'@@ -136,6 +136,7 @@ const Debug: FC<IDebug> = ({const doShowSuggestion = isShowSuggestion && !isResponsingconst [suggestQuestions, setSuggestQuestions] = useState<string[]>([])+ const [messageTaskId, setMessageTaskId] = useState('')const onSend = async (message: string) => {if (isResponsing) {notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') })@@ -208,12 +209,13 @@ const Debug: FC<IDebug> = ({getAbortController: (abortController) => {setAbortController(abortController)},- onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId }: any) => {+ onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId, taskId }: any) => {responseItem.content = responseItem.content + messageif (isFirstMessage && newConversationId) {setConversationId(newConversationId)_newConversationId = newConversationId}+ setMessageTaskId(taskId)if (messageId)responseItem.id = messageId@@ -375,8 +377,10 @@ const Debug: FC<IDebug> = ({feedbackDisableduseCurrentUserAvatarisResponsing={isResponsing}- abortResponsing={() => {+ canStopResponsing={!!messageTaskId}+ abortResponsing={async () => {abortController?.abort()+ await stopChatMessageResponding(appId, messageTaskId)setResponsingFalse()}}isShowSuggestion={doShowSuggestion}diff --git a/web/app/components/share/chat/index.tsx b/web/app/components/share/chat/index.tsxindex 9fe0d302d02..81ccfa94a81 100644--- a/web/app/components/share/chat/index.tsx+++ b/web/app/components/share/chat/index.tsx@@ -14,7 +14,7 @@ import { ToastContext } from '@/app/components/base/toast'import Sidebar from '@/app/components/share/chat/sidebar'import ConfigSence from '@/app/components/share/chat/config-scence'import Header from '@/app/components/share/header'-import { fetchAppInfo, fetchAppParams, fetchChatList, fetchConversations, fetchSuggestedQuestions, sendChatMessage, updateFeedback } from '@/service/share'+import { fetchAppInfo, fetchAppParams, fetchChatList, fetchConversations, fetchSuggestedQuestions, sendChatMessage, stopChatMessageResponding, updateFeedback } from '@/service/share'import type { ConversationItem, SiteInfo } from '@/models/share'import type { PromptConfig, SuggestedQuestionsAfterAnswerConfig } from '@/models/debug'import type { Feedbacktype, IChatItem } from '@/app/components/app/chat'@@ -332,6 +332,7 @@ const Main: FC<IMainProps> = ({const [isShowSuggestion, setIsShowSuggestion] = useState(false)const doShowSuggestion = isShowSuggestion && !isResponsingconst [suggestQuestions, setSuggestQuestions] = useState<string[]>([])+ const [messageTaskId, setMessageTaskId] = useState('')const handleSend = async (message: string) => {if (isResponsing) {notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') })@@ -376,12 +377,13 @@ const Main: FC<IMainProps> = ({getAbortController: (abortController) => {setAbortController(abortController)},- onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId }: any) => {+ onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId, taskId }: any) => {responseItem.content = responseItem.content + messageresponseItem.id = messageIdif (isFirstMessage && newConversationId)tempNewConversationId = newConversationId+ setMessageTaskId(taskId)// closesure new list is outdated.const newListWithAnswer = produce(getChatList().filter(item => item.id !== responseItem.id && item.id !== placeholderAnswerId),@@ -532,8 +534,10 @@ const Main: FC<IMainProps> = ({isHideFeedbackEditonFeedback={handleFeedback}isResponsing={isResponsing}- abortResponsing={() => {+ canStopResponsing={!!messageTaskId}+ abortResponsing={async () => {abortController?.abort()+ await stopChatMessageResponding(appId, messageTaskId, isInstalledApp, installedAppInfo?.id)setResponsingFalse()}}checkCanSend={checkCanSend}diff --git a/web/service/base.ts b/web/service/base.tsindex bbc9261ac27..43f9b9207ae 100644--- a/web/service/base.ts+++ b/web/service/base.ts@@ -23,7 +23,8 @@ const baseOptions = {}export type IOnDataMoreInfo = {- conversationId: string | undefined+ conversationId?: string+ taskId?: stringmessageId: stringerrorMessage?: string}@@ -101,6 +102,7 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted// can not use format here. Because message is splited.onData(unicodeToChar(bufferObj.answer), isFirstMessage, {conversationId: bufferObj.conversation_id,+ taskId: bufferObj.task_id,messageId: bufferObj.id,})isFirstMessage = falsediff --git a/web/service/debug.ts b/web/service/debug.tsindex 7550ddbacbd..82c27c86a28 100644--- a/web/service/debug.ts+++ b/web/service/debug.ts@@ -15,6 +15,10 @@ export const sendChatMessage = async (appId: string, body: Record<string, any>,}, { onData, onCompleted, onError, getAbortController })}+export const stopChatMessageResponding = async (appId: string, taskId: string) => {+ return post(`apps/${appId}/chat-messages/${taskId}/stop`)+}+export const sendCompletionMessage = async (appId: string, body: Record<string, any>, { onData, onCompleted, onError }: {onData: IOnDataonCompleted: IOnCompleteddiff --git a/web/service/share.ts b/web/service/share.tsindex 316e9d47dba..c7db773956d 100644--- a/web/service/share.ts+++ b/web/service/share.ts@@ -34,6 +34,10 @@ export const sendChatMessage = async (body: Record<string, any>, { onData, onCom}, { onData, onCompleted, isPublicAPI: !isInstalledApp, onError, getAbortController })}+export const stopChatMessageResponding = async (appId: string, taskId: string, isInstalledApp: boolean, installedAppId = '') => {+ return getAction('post', isInstalledApp)(getUrl(`chat-messages/${taskId}/stop`, isInstalledApp, installedAppId))+}+export const sendCompletionMessage = async (body: Record<string, any>, { onData, onCompleted, onError }: {onData: IOnDataonCompleted: IOnCompleted