diff --git a/extensions/inference-nitro-extension/src/index.ts b/extensions/inference-nitro-extension/src/index.ts index f2fbf0d345..4bcfe05b08 100644 --- a/extensions/inference-nitro-extension/src/index.ts +++ b/extensions/inference-nitro-extension/src/index.ts @@ -227,6 +227,11 @@ export default class JanInferenceNitroExtension implements InferenceExtension { events.emit(EventName.OnMessageUpdate, message); }, error: async (err) => { + if (instance.isCancelled) { + message.status = MessageStatus.Ready; + events.emit(EventName.OnMessageUpdate, message); + return; + } const messageContent: ThreadContent = { type: ContentType.Text, text: { diff --git a/extensions/inference-openai-extension/src/index.ts b/extensions/inference-openai-extension/src/index.ts index c719e405fa..42c9c37980 100644 --- a/extensions/inference-openai-extension/src/index.ts +++ b/extensions/inference-openai-extension/src/index.ts @@ -217,6 +217,11 @@ export default class JanInferenceOpenAIExtension implements InferenceExtension { events.emit(EventName.OnMessageUpdate, message); }, error: async (err) => { + if (instance.isCancelled) { + message.status = MessageStatus.Ready; + events.emit(EventName.OnMessageUpdate, message); + return; + } const messageContent: ThreadContent = { type: ContentType.Text, text: { diff --git a/web/screens/Chat/MessageToolbar/index.tsx b/web/screens/Chat/MessageToolbar/index.tsx index 7f8e5ca7eb..c6214aef37 100644 --- a/web/screens/Chat/MessageToolbar/index.tsx +++ b/web/screens/Chat/MessageToolbar/index.tsx @@ -1,14 +1,12 @@ import { - EventName, MessageStatus, ExtensionType, ThreadMessage, - events, ChatCompletionRole, } from '@janhq/core' -import { ConversationalExtension, InferenceExtension } from '@janhq/core' +import { ConversationalExtension } from '@janhq/core' import { useAtomValue, useSetAtom } from 'jotai' -import { RefreshCcw, Copy, Trash2Icon, StopCircle } from 'lucide-react' +import { RefreshCcw, Copy, Trash2Icon } from 'lucide-react' import { twMerge } from 'tailwind-merge' @@ -29,17 +27,6 @@ const MessageToolbar = ({ message }: { message: ThreadMessage }) => { const messages = useAtomValue(getCurrentChatMessagesAtom) const { resendChatMessage } = useSendChatMessage() - const onStopInferenceClick = async () => { - events.emit(EventName.OnInferenceStopped, {}) - - setTimeout(() => { - events.emit(EventName.OnMessageUpdate, { - ...message, - status: MessageStatus.Ready, - }) - }, 300) - } - const onDeleteClick = async () => { deleteMessage(message.id ?? '') if (thread) { @@ -60,26 +47,19 @@ const MessageToolbar = ({ message }: { message: ThreadMessage }) => { resendChatMessage(message) } + if (message.status !== MessageStatus.Ready) return null + return (