From 1c15d13156116f669b7685cf0c5d22eb148e93e0 Mon Sep 17 00:00:00 2001 From: Shirisha <124602484+shirisha22@users.noreply.github.com> Date: Wed, 14 May 2025 20:45:42 -0700 Subject: [PATCH] base commit more fixes fix background fix chat history Update ci.yaml remove hardcoded api key --- .github/workflows/ci.yaml | 3 -- app/components/chat/BaseChat.tsx | 77 +++++++++++---------------- app/components/chat/Chat.client.tsx | 23 +++----- app/components/chat/ChatAlert.tsx | 6 +-- app/components/chat/ModelSelector.tsx | 3 +- app/lib/persistence/useChatHistory.ts | 21 +++----- app/routes/api.chat.ts | 34 ++++-------- app/styles/variables.scss | 2 +- 8 files changed, 62 insertions(+), 107 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8ab236d5..a22eb0e7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,6 +22,3 @@ jobs: # - name: Run ESLint # run: pnpm run lint - - - name: Run tests - run: pnpm run test diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index 07c440b9..b2736eae 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -12,7 +12,7 @@ import { classNames } from '~/utils/classNames'; import { PROVIDER_LIST } from '~/utils/constants'; import { Messages } from './Messages.client'; import { SendButton } from './SendButton.client'; -import { APIKeyManager, getApiKeysFromCookies } from './APIKeyManager'; +import { getApiKeysFromCookies } from './APIKeyManager'; import Cookies from 'js-cookie'; import * as Tooltip from '@radix-ui/react-tooltip'; @@ -35,8 +35,6 @@ import type { ModelInfo } from '~/lib/modules/llm/types'; import ProgressCompilation from './ProgressCompilation'; import type { ProgressAnnotation } from '~/types/context'; import type { ActionRunner } from '~/lib/runtime/action-runner'; -import { LOCAL_PROVIDERS } from '~/lib/stores/settings'; -import { useLoaderData } from '@remix-run/react'; const TEXTAREA_MIN_HEIGHT = 76; @@ -121,8 +119,6 @@ export const BaseChat = React.forwardRef( const [isModelLoading, setIsModelLoading] = useState('all'); const [progressAnnotations, setProgressAnnotations] = useState([]); - const { hideBaseChat, canImportChat } = useLoaderData<{ hideBaseChat?: boolean; canImportChat?: boolean }>(); - useEffect(() => { if (data) { const progressList = data.filter( @@ -199,30 +195,32 @@ export const BaseChat = React.forwardRef( } }, [providerList, provider]); - const onApiKeysChange = async (providerName: string, apiKey: string) => { - const newApiKeys = { ...apiKeys, [providerName]: apiKey }; - setApiKeys(newApiKeys); - Cookies.set('apiKeys', JSON.stringify(newApiKeys)); - - setIsModelLoading(providerName); - - let providerModels: ModelInfo[] = []; - - try { - const response = await fetch(`/code-editor/api/models/${encodeURIComponent(providerName)}`); - const data = await response.json(); - providerModels = (data as { modelList: ModelInfo[] }).modelList; - } catch (error) { - console.error('Error loading dynamic models for:', providerName, error); - } - - // Only update models for the specific provider - setModelList((prevModels) => { - const otherModels = prevModels.filter((model) => model.provider !== providerName); - return [...otherModels, ...providerModels]; - }); - setIsModelLoading(undefined); - }; + /* + * const onApiKeysChange = async (providerName: string, apiKey: string) => { + * const newApiKeys = { ...apiKeys, [providerName]: apiKey }; + * setApiKeys(newApiKeys); + * Cookies.set('apiKeys', JSON.stringify(newApiKeys)); + * + * setIsModelLoading(providerName); + * + * let providerModels: ModelInfo[] = []; + * + * try { + * const response = await fetch(`/code-editor/api/models/${encodeURIComponent(providerName)}`); + * const data = await response.json(); + * providerModels = (data as { modelList: ModelInfo[] }).modelList; + * } catch (error) { + * console.error('Error loading dynamic models for:', providerName, error); + * } + * + * // Only update models for the specific provider + * setModelList((prevModels) => { + * const otherModels = prevModels.filter((model) => model.provider !== providerName); + * return [...otherModels, ...providerModels]; + * }); + * setIsModelLoading(undefined); + * }; + */ const startListening = () => { if (recognition) { @@ -417,6 +415,7 @@ export const BaseChat = React.forwardRef( apiKeys={apiKeys} modelLoading={isModelLoading} /> + {/* {(providerList || []).length > 0 && provider && (!LOCAL_PROVIDERS.includes(provider.name) || 'OpenAILike') && ( @@ -427,7 +426,7 @@ export const BaseChat = React.forwardRef( onApiKeysChange(provider.name, key); }} /> - )} + )} */} )} @@ -522,7 +521,7 @@ export const BaseChat = React.forwardRef( minHeight: TEXTAREA_MIN_HEIGHT, maxHeight: TEXTAREA_MAX_HEIGHT, }} - placeholder="How can Bolt help you today?" + placeholder="How can RapidCanvas help you today?" translate="no" /> @@ -632,20 +631,6 @@ export const BaseChat = React.forwardRef( ); - return ( - - {!hideBaseChat ? ( - baseChat - ) : ( -
- {() => } -
- {ImportButtons(importChat, canImportChat)} - -
-
- )} -
- ); + return {baseChat}; }, ); diff --git a/app/components/chat/Chat.client.tsx b/app/components/chat/Chat.client.tsx index 785caf2d..416d621e 100644 --- a/app/components/chat/Chat.client.tsx +++ b/app/components/chat/Chat.client.tsx @@ -12,7 +12,7 @@ import { useMessageParser, usePromptEnhancer, useShortcuts, useSnapScroll } from import { description, useChatHistory } from '~/lib/persistence'; import { chatStore } from '~/lib/stores/chat'; import { workbenchStore } from '~/lib/stores/workbench'; -import { DEFAULT_MODEL, DEFAULT_PROVIDER, PROMPT_COOKIE_KEY, PROVIDER_LIST } from '~/utils/constants'; +import { PROMPT_COOKIE_KEY, PROVIDER_LIST } from '~/utils/constants'; import { cubicEasingFn } from '~/utils/easings'; import { createScopedLogger, renderLogger } from '~/utils/logger'; import { BaseChat } from './BaseChat'; @@ -45,7 +45,9 @@ export function Chat() { const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); - const { ready, initialMessages, resetMessages, storeMessageHistory, importChat, exportChat } = useChatHistory(); + const { ready, initialMessages, storeMessageHistory, importChat, exportChat } = useChatHistory(); + + console.log('initialMessages', initialMessages); const title = useStore(description); useEffect(() => { @@ -55,12 +57,6 @@ export function Chat() { const { id: mixedId } = useLoaderData<{ id?: string }>(); const token = getToken(); - useEffect(() => { - if (initialMessages.length > 0) { - resetMessages(); - } - }, [initialMessages]); - useEffect(() => { if (!mixedId) { setError(new Error('No dataApp ID')); @@ -73,7 +69,7 @@ export function Chat() { loadFilesFromDataApp(mixedId, token!) .then(async (data) => { - await importChat(data.folderName, data.messages); + await importChat(data.folderName, !!initialMessages.length ? initialMessages : data.messages); saveFilesToWorkbench({ fileArtifacts: data.updatedArtifacts.files }); removeTokenFromUrl(); setIsLoading(false); @@ -164,8 +160,6 @@ export const ChatImpl = memo( ({ description, initialMessages, storeMessageHistory, importChat, exportChat }: ChatProps) => { useShortcuts(); - const { showChat } = useLoaderData<{ showChat: boolean }>(); - const textareaRef = useRef(null); const [chatStarted, setChatStarted] = useState(initialMessages.length > 0); const [uploadedFiles, setUploadedFiles] = useState([]); @@ -178,11 +172,10 @@ export const ChatImpl = memo( const [model, setModel] = useState(() => { const savedModel = Cookies.get('selectedModel'); - return savedModel || DEFAULT_MODEL; + return savedModel || 'gpt-4o-mini'; }); const [provider, setProvider] = useState(() => { - const savedProvider = Cookies.get('selectedProvider'); - return (PROVIDER_LIST.find((p) => p.name === savedProvider) || DEFAULT_PROVIDER) as ProviderInfo; + return PROVIDER_LIST.find((p) => p.name === 'OpenAI') as ProviderInfo; }); const [animationScope, animate] = useAnimate(); @@ -541,7 +534,7 @@ export const ChatImpl = memo( ref={animationScope} textareaRef={textareaRef} input={input} - showChat={showChat} + showChat={true} chatStarted={chatStarted} isStreaming={isLoading || fakeLoading} onStreamingChange={(streaming) => { diff --git a/app/components/chat/ChatAlert.tsx b/app/components/chat/ChatAlert.tsx index 5aeb08c7..a65b947a 100644 --- a/app/components/chat/ChatAlert.tsx +++ b/app/components/chat/ChatAlert.tsx @@ -14,8 +14,8 @@ export default function ChatAlert({ alert, clearAlert, postMessage }: Props) { const isPreview = source === 'preview'; const title = isPreview ? 'Preview Error' : 'Terminal Error'; const message = isPreview - ? 'We encountered an error while running the preview. Would you like Bolt to analyze and help resolve this issue?' - : 'We encountered an error while running terminal commands. Would you like Bolt to analyze and help resolve this issue?'; + ? 'We encountered an error while running the preview. Would you like RapidCanvas to analyze and help resolve this issue?' + : 'We encountered an error while running terminal commands. Would you like RapidCanvas to analyze and help resolve this issue?'; return ( @@ -84,7 +84,7 @@ export default function ChatAlert({ alert, clearAlert, postMessage }: Props) { )} >
- Ask Bolt + Ask RapidCanvas