diff --git a/apps/web/src/api/buster_rest/shortcuts/queryRequests.ts b/apps/web/src/api/buster_rest/shortcuts/queryRequests.ts index 4f7a684d5..990537596 100644 --- a/apps/web/src/api/buster_rest/shortcuts/queryRequests.ts +++ b/apps/web/src/api/buster_rest/shortcuts/queryRequests.ts @@ -24,6 +24,7 @@ export const useListShortcuts = ( queryFn: listShortcuts, select: props?.select, ...props, + initialData: { shortcuts: [] }, }); }; diff --git a/apps/web/src/api/buster_rest/users/queryRequests.ts b/apps/web/src/api/buster_rest/users/queryRequests.ts index 0025ae6dc..94d144c34 100644 --- a/apps/web/src/api/buster_rest/users/queryRequests.ts +++ b/apps/web/src/api/buster_rest/users/queryRequests.ts @@ -19,6 +19,7 @@ import { inviteUser, updateOrganizationUser, } from './requests'; +import { useGetUserBasicInfo } from './useGetUserInfo'; export const useGetMyUserInfo = ( props?: Omit, 'queryKey' | 'queryFn'> @@ -120,11 +121,22 @@ export const useCreateUserOrganization = () => { }); }; -export const useGetSuggestedPrompts = (params: Parameters[0]) => { - const queryFn = () => getSuggestedPrompts(params); +export const useGetSuggestedPrompts = () => { + const user = useGetUserBasicInfo(); + const queryFn = () => getSuggestedPrompts({ userId: user?.id ?? '' }); return useQuery({ - ...userQueryKeys.userGetSuggestedPrompts(params.userId), + ...userQueryKeys.userGetSuggestedPrompts(user?.id ?? ''), queryFn, + enabled: !!user?.id, + initialData: { + suggestedPrompts: { + report: [], + dashboard: [], + visualization: [], + help: [], + }, + updatedAt: '', + }, }); }; diff --git a/apps/web/src/components/features/input/BusterChatInput/BusterChatInput.tsx b/apps/web/src/components/features/input/BusterChatInput/BusterChatInput.tsx new file mode 100644 index 000000000..3374f41d7 --- /dev/null +++ b/apps/web/src/components/features/input/BusterChatInput/BusterChatInput.tsx @@ -0,0 +1,42 @@ +import type React from 'react'; +import { useListShortcuts } from '@/api/buster_rest/shortcuts/queryRequests'; +import { useGetSuggestedPrompts } from '@/api/buster_rest/users'; +import { useChat } from '@/context/Chats/useChat'; +import { useGetChatId } from '@/context/Chats/useGetChatId'; +import { useMemoizedFn } from '@/hooks/useMemoizedFn'; +import { BusterChatInputBase, type BusterChatInputProps } from './BusterChatInputBase'; + +export const BusterChatInput: React.FC<{ + initialValue?: string; + autoSubmit?: boolean; +}> = ({ initialValue = '', autoSubmit }) => { + const { data: suggestions, isFetched: isFetchedSuggestions } = useGetSuggestedPrompts(); + const { data: shortcuts, isFetched: isFetchedShortcuts } = useListShortcuts(); + const { onStartNewChat, onStopChat, isSubmittingChat } = useChat(); + const chatId = useGetChatId(); + + const disabled = !isFetchedSuggestions || !isFetchedShortcuts || isSubmittingChat; + + const onStop = useMemoizedFn(() => { + if (chatId) { + onStopChat({ chatId }); + } + }); + + const onSubmit: BusterChatInputProps['onSubmit'] = useMemoizedFn((d) => { + onStartNewChat({ prompt: d.transformedValue, mode: d.mode }); + }); + + return ( + + ); +}; diff --git a/apps/web/src/components/features/input/BusterChatInput/BusterChatInputBase.tsx b/apps/web/src/components/features/input/BusterChatInput/BusterChatInputBase.tsx index 8f6a7968f..ed583cdf3 100644 --- a/apps/web/src/components/features/input/BusterChatInput/BusterChatInputBase.tsx +++ b/apps/web/src/components/features/input/BusterChatInput/BusterChatInputBase.tsx @@ -18,12 +18,12 @@ import type { MentionInputSuggestionsRef, } from '@/components/ui/inputs/MentionInputSuggestions'; import { MentionInputSuggestions } from '@/components/ui/inputs/MentionInputSuggestions'; -import { useMemoizedFn } from '@/hooks/useMemoizedFn'; +import { useMount } from '@/hooks/useMount'; import { ASSET_ICONS } from '../../icons/assetIcons'; import { NewShortcutModal } from '../../modals/NewShortcutModal'; import { BusterChatInputButtons, type BusterChatInputMode } from './BusterChatInputButtons'; -export type BusterChatInput = { +export type BusterChatInputProps = { defaultValue: string; onSubmit: (d: { transformedValue: string; @@ -36,10 +36,20 @@ export type BusterChatInput = { disabled: boolean; shortcuts: ListShortcutsResponse['shortcuts']; suggestedPrompts: GetSuggestedPromptsResponse['suggestedPrompts']; + autoSubmit?: boolean; }; -export const BusterChatInputBase: React.FC = React.memo( - ({ defaultValue, onSubmit, onStop, submitting, disabled, shortcuts, suggestedPrompts }) => { +export const BusterChatInputBase: React.FC = React.memo( + ({ + defaultValue, + onSubmit, + onStop, + autoSubmit, + submitting, + disabled, + shortcuts, + suggestedPrompts, + }) => { const mentionInputSuggestionsRef = useRef(null); const uniqueSuggestions = useUniqueSuggestions(suggestedPrompts); const [openCreateShortcutModal, setOpenCreateShortcutModal] = useState(false); @@ -95,6 +105,16 @@ export const BusterChatInputBase: React.FC = React.memo( onSubmit({ ...value, mode }); }; + useMount(() => { + if (autoSubmit && defaultValue) { + onSubmitPreflight({ + transformedValue: defaultValue, + arrayValue: [], + editorText: defaultValue, + }); + } + }); + return ( { const SuggestionsSeperator = () => { const hasResults = useCommandState((x) => x.filtered.count) > 0; if (!hasResults) return null; - return
; + return
; }; const customFilter = (value: string, search: string, keywords?: string[]): number => { diff --git a/apps/web/src/context/Chats/useChat.ts b/apps/web/src/context/Chats/useChat.ts index 5e1ae8f67..4a0880ad7 100644 --- a/apps/web/src/context/Chats/useChat.ts +++ b/apps/web/src/context/Chats/useChat.ts @@ -49,11 +49,13 @@ export const useChat = () => { } }; - const onStartNewChat = useMemoizedFn(async ({ prompt }: { prompt: string }) => { - return startChat({ - prompt, - }); - }); + const onStartNewChat = useMemoizedFn( + async ({ prompt, mode }: { prompt: string; mode: 'auto' | 'research' | 'deep-research' }) => { + return startChat({ + prompt, + }); + } + ); const onStartChatFromFile = useMemoizedFn( async ({ diff --git a/apps/web/src/controllers/HomePage/HomePageController.tsx b/apps/web/src/controllers/HomePage/HomePageController.tsx index 77fbeecc7..dd707f6c6 100644 --- a/apps/web/src/controllers/HomePage/HomePageController.tsx +++ b/apps/web/src/controllers/HomePage/HomePageController.tsx @@ -2,10 +2,9 @@ import { ClientOnly } from '@tanstack/react-router'; import type React from 'react'; import { useMemo } from 'react'; import { useGetUserBasicInfo } from '@/api/buster_rest/users/useGetUserInfo'; +import { BusterChatInput } from '@/components/features/input/BusterChatInput'; import { Title } from '@/components/ui/typography'; import { cn } from '@/lib/classMerge'; -import { isServer } from '@/lib/window'; -import { NewChatInput } from './NewChatInput'; import { NewChatWarning } from './NewChatWarning'; import { useNewChatWarning } from './useNewChatWarning'; @@ -42,7 +41,7 @@ export const HomePageController: React.FC<{
- +
)}