Merge pull request #495 from buster-so/dallin/bus-1328-ability-to-kill-a-chat-while-running-stop-button

Dallin/bus 1328 ability to kill a chat while running stop button
This commit is contained in:
Nate Kelley 2025-07-14 08:48:33 -06:00 committed by GitHub
commit b7c40e2ea8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 37 additions and 39 deletions

View File

@ -1,23 +1,23 @@
{ {
"folders": [ "folders": [
{ "path": "./apps/api" }, { "path": "../apps/api" },
{ "path": "./apps/electric-server" }, { "path": "../apps/electric-server" },
{ "path": "./apps/server" }, { "path": "../apps/server" },
{ "path": "./apps/trigger" }, { "path": "../apps/trigger" },
{ "path": "./apps/web" }, { "path": "../apps/web" },
{ "path": "./packages/access-controls" }, { "path": "../packages/access-controls" },
{ "path": "./packages/ai" }, { "path": "../packages/ai" },
{ "path": "./packages/data-source" }, { "path": "../packages/data-source" },
{ "path": "./packages/database" }, { "path": "../packages/database" },
{ "path": "./packages/rerank" }, { "path": "../packages/rerank" },
{ "path": "./packages/server-shared" }, { "path": "../packages/server-shared" },
{ "path": "./packages/slack" }, { "path": "../packages/slack" },
{ "path": "./packages/stored-values" }, { "path": "../packages/stored-values" },
{ "path": "./packages/supabase" }, { "path": "../packages/supabase" },
{ "path": "./packages/test-utils" }, { "path": "../packages/test-utils" },
{ "path": "./packages/typescript-config" }, { "path": "../packages/typescript-config" },
{ "path": "./packages/vitest-config" }, { "path": "../packages/vitest-config" },
{ "path": "./packages/web-tools" } { "path": "../packages/web-tools" }
], ],
"settings": { "settings": {
"editor.defaultFormatter": "biomejs.biome", "editor.defaultFormatter": "biomejs.biome",

View File

@ -6,5 +6,5 @@ export const createNewChat = async (props: ChatCreateRequest) => {
}; };
export const stopChat = async ({ chatId }: { chatId: string }) => { export const stopChat = async ({ chatId }: { chatId: string }) => {
return mainApiV2.patch<unknown>(`/chats/${chatId}`, { stop: true }).then((res) => res.data); return mainApiV2.delete<unknown>(`/chats/${chatId}/cancel`).then((res) => res.data);
}; };

View File

@ -108,29 +108,25 @@ const SubmitButton: React.FC<{
onSubmitPreflight: () => void; onSubmitPreflight: () => void;
onStop?: () => void; onStop?: () => void;
}> = React.memo(({ disabled, sendIcon, loading, loadingIcon, onSubmitPreflight, onStop }) => { }> = React.memo(({ disabled, sendIcon, loading, loadingIcon, onSubmitPreflight, onStop }) => {
const memoizedPrefix = useMemo(() => { const prefix = (
return ( <div
className={cn('relative h-4 w-4 transition-all duration-300 ease-out will-change-transform')}>
<div <div
className={cn( className={`absolute inset-0 transition-all duration-300 ease-out ${loading ? 'scale-80 opacity-0' : 'scale-100 opacity-100'}`}>
'relative h-4 w-4 transition-all duration-300 ease-out will-change-transform' {sendIcon}
)}>
<div
className={`absolute inset-0 transition-all duration-300 ease-out ${loading ? 'scale-80 opacity-0' : 'scale-100 opacity-100'}`}>
{sendIcon}
</div>
<div
className={`absolute inset-0 flex items-center justify-center text-sm transition-all duration-300 ease-out ${loading ? 'scale-100 opacity-100' : 'scale-85 opacity-0'}`}>
{loadingIcon}
</div>
</div> </div>
); <div
}, [loading, sendIcon, loadingIcon]); className={`absolute inset-0 flex items-center justify-center text-sm transition-all duration-300 ease-out ${loading ? 'scale-100 opacity-100' : 'scale-85 opacity-0'}`}>
{loadingIcon}
</div>
</div>
);
return ( return (
<Button <Button
rounding={'large'} rounding={'large'}
variant="black" variant="black"
prefix={memoizedPrefix} prefix={prefix}
onClick={loading && onStop ? onStop : onSubmitPreflight} onClick={loading && onStop ? onStop : onSubmitPreflight}
disabled={disabled} disabled={disabled}
className={cn( className={cn(

View File

@ -17,8 +17,8 @@ export const ChatInput: React.FC = React.memo(() => {
const [inputValue, setInputValue] = useState(''); const [inputValue, setInputValue] = useState('');
const disableSubmit = useMemo(() => { const disableSubmit = useMemo(() => {
return !inputHasText(inputValue); return !inputHasText(inputValue) && !isStreamingMessage;
}, [inputValue]); }, [inputValue, isStreamingMessage]);
const { onSubmitPreflight, onStopChat } = useChatInputFlow({ const { onSubmitPreflight, onStopChat } = useChatInputFlow({
disableSubmit, disableSubmit,

View File

@ -135,8 +135,10 @@ export const useChatInputFlow = ({
const onStopChat = useMemoizedFn(() => { const onStopChat = useMemoizedFn(() => {
if (!chatId) return; if (!chatId) return;
onStopChatContext({ chatId, messageId: currentMessageId }); onStopChatContext({ chatId, messageId: currentMessageId });
textAreaRef.current?.focus(); setTimeout(() => {
textAreaRef.current?.select(); textAreaRef.current?.focus();
textAreaRef.current?.select();
}, 100);
}); });
return useMemo( return useMemo(