diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index 57ac4cf3..fbd43e78 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -474,11 +474,7 @@ export const BaseChat = React.forwardRef( {!rejectFormOpen && messageInput} - {!chatStarted && ( -
- {ImportButtons(importChat)} -
- )} + {!chatStarted &&
{ImportButtons(importChat)}
} {!chatStarted && ExamplePrompts((event, messageInput) => { if (isStreaming) { diff --git a/app/components/chat/Chat.client.tsx b/app/components/chat/Chat.client.tsx index 6ab6fac8..b002d098 100644 --- a/app/components/chat/Chat.client.tsx +++ b/app/components/chat/Chat.client.tsx @@ -201,6 +201,7 @@ export const ChatImpl = memo( // Load any repository in the initial messages. useEffect(() => { const repositoryId = getMessagesRepositoryId(initialMessages); + if (repositoryId) { simulationRepositoryUpdated(repositoryId); } @@ -497,6 +498,7 @@ export const ChatImpl = memo( } const previousRepositoryId = getPreviousRepositoryId(messages, messageIndex); + if (!previousRepositoryId) { toast.error('No repository ID found for rewind'); return; @@ -547,10 +549,7 @@ export const ChatImpl = memo( }); }; - const onRejectChange = async ( - messageId: string, - data: RejectChangeData, - ) => { + const onRejectChange = async (messageId: string, data: RejectChangeData) => { console.log('RejectChange', messageId, data); setApproveChangesMessageId(undefined); diff --git a/app/components/chat/ImportFolderButton.tsx b/app/components/chat/ImportFolderButton.tsx index 4e7596be..c4df33eb 100644 --- a/app/components/chat/ImportFolderButton.tsx +++ b/app/components/chat/ImportFolderButton.tsx @@ -80,7 +80,7 @@ export const ImportFolderButton: React.FC = ({ classNam } const repositoryContents = await getFileRepositoryContents(textFiles); - const repositoryId = await createRepositoryImported("ImportFolder", repositoryContents); + const repositoryId = await createRepositoryImported('ImportFolder', repositoryContents); const messages = createChatFromFolder(folderName, repositoryId); diff --git a/app/components/chat/Messages.client.tsx b/app/components/chat/Messages.client.tsx index 00718171..96322907 100644 --- a/app/components/chat/Messages.client.tsx +++ b/app/components/chat/Messages.client.tsx @@ -54,21 +54,21 @@ export const Messages = React.forwardRef((props: )} {previousRepositoryId && repositoryId && onRewind && ( -
- -
- )} +
+ +
+ )} ); diff --git a/app/lib/persistence/useChatHistory.ts b/app/lib/persistence/useChatHistory.ts index 99596e34..3585c04b 100644 --- a/app/lib/persistence/useChatHistory.ts +++ b/app/lib/persistence/useChatHistory.ts @@ -3,22 +3,15 @@ import { useState, useEffect } from 'react'; import { atom } from 'nanostores'; import type { Message as BaseMessage } from 'ai'; import { toast } from 'react-toastify'; -import { workbenchStore } from '~/lib/stores/workbench'; import { logStore } from '~/lib/stores/logs'; // Import logStore -import { - getMessages, - getNextId, - getUrlId, - openDatabase, - setMessages, - duplicateChat, - createChatFromMessages, -} from './db'; +import { getMessages, getNextId, openDatabase, setMessages, duplicateChat, createChatFromMessages } from './db'; import { loadProblem } from '~/components/chat/LoadProblemButton'; import { createAsyncSuspenseValue } from '~/lib/asyncSuspenseValue'; -// Messages in a chat's history. The repository may update in response to changes in the messages. -// Each message which changes the repository state must have a repositoryId. +/* + * Messages in a chat's history. The repository may update in response to changes in the messages. + * Each message which changes the repository state must have a repositoryId. + */ export interface Message extends BaseMessage { // Describes the state of the project after changes in this message were applied. repositoryId?: string; @@ -193,6 +186,7 @@ function navigateChat(nextId: string) { export function getPreviousRepositoryId(messages: Message[], index: number): string | undefined { for (let i = index - 1; i >= 0; i--) { const message = messages[i]; + if (message.repositoryId) { return message.repositoryId; } diff --git a/app/lib/replay/Repository.ts b/app/lib/replay/Repository.ts index b39ef88c..7f58f1c1 100644 --- a/app/lib/replay/Repository.ts +++ b/app/lib/replay/Repository.ts @@ -1,17 +1,17 @@ -import { sendCommandDedicatedClient } from "./ReplayProtocolClient"; +import { sendCommandDedicatedClient } from './ReplayProtocolClient'; // Get the contents of a repository as a base64 string of the zip file. export async function getRepositoryContents(repositoryId: string): Promise { - const rv = await sendCommandDedicatedClient({ + const rv = (await sendCommandDedicatedClient({ method: 'Nut.getRepository', params: { repositoryId }, - }) as { repositoryContents: string }; + })) as { repositoryContents: string }; return rv.repositoryContents; } // Remotely create an imported repository from the given contents. export async function createRepositoryImported(reason: string, repositoryContents: string): Promise { - const rv = await sendCommandDedicatedClient({ + const rv = (await sendCommandDedicatedClient({ method: 'Nut.createRepository', params: { repositoryContents, @@ -20,6 +20,6 @@ export async function createRepositoryImported(reason: string, repositoryContent reason, }, }, - }) as { repositoryId: string }; + })) as { repositoryId: string }; return rv.repositoryId; } diff --git a/app/lib/replay/SimulationData.ts b/app/lib/replay/SimulationData.ts index b946b5a8..d449075b 100644 --- a/app/lib/replay/SimulationData.ts +++ b/app/lib/replay/SimulationData.ts @@ -8,10 +8,12 @@ interface SimulationPacketServerURL { url: string; } -// Simulation data specifying a repository ID to set up a dev server -// for static resources and any initial database contents. +/* + * Simulation data specifying a repository ID to set up a dev server + * for static resources and any initial database contents. + */ interface SimulationPacketRepositoryId { - kind: "repositoryId"; + kind: 'repositoryId'; repositoryId: string; } diff --git a/app/lib/replay/SimulationPrompt.ts b/app/lib/replay/SimulationPrompt.ts index ebc8f65c..eaf0bc3f 100644 --- a/app/lib/replay/SimulationPrompt.ts +++ b/app/lib/replay/SimulationPrompt.ts @@ -486,6 +486,10 @@ Focus specifically on fixing this bug. Do not guess about other problems. content: systemPrompt, }); - const { repositoryId } = await gChatManager.sendChatMessage('developer', protocolMessages, { baseRepositoryId, onResponsePart }); + const { repositoryId } = await gChatManager.sendChatMessage('developer', protocolMessages, { + baseRepositoryId, + onResponsePart, + }); + return repositoryId; } diff --git a/app/utils/folderImport.ts b/app/utils/folderImport.ts index 1a5a9a9e..4030c09c 100644 --- a/app/utils/folderImport.ts +++ b/app/utils/folderImport.ts @@ -28,17 +28,16 @@ export async function getFileRepositoryContents(files: File[]): Promise ); const zip = new JSZip(); + for (const { path, content } of artifacts) { zip.file(path, content); } - return await zip.generateAsync({ type: "base64" }); + + return await zip.generateAsync({ type: 'base64' }); } -export function createChatFromFolder( - folderName: string, - repositoryId: string -): Message[] { - let filesContent = `I've imported the contents of the "${folderName}" folder.`; +export function createChatFromFolder(folderName: string, repositoryId: string): Message[] { + const filesContent = `I've imported the contents of the "${folderName}" folder.`; const userMessage: Message = { role: 'user',