From 8e6612571fb15c1b8f783150156ddc82ce0db62e Mon Sep 17 00:00:00 2001 From: Nawaz Gafar Date: Fri, 14 Feb 2025 11:06:37 -0500 Subject: [PATCH 1/6] No longer clearing chat history on agent toggle --- mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx b/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx index d1f4a0cc1..dd0a656f8 100644 --- a/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx +++ b/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx @@ -298,11 +298,10 @@ const ChatTaskpane: React.FC = ({ // Step 0: Reject the previous Ai generated code if they did not accept it rejectAICode() - // Step 1: Clear the chat history, and add the new error message - const newChatHistoryManager = clearChatHistory() + // Step 1: Add user message to chat history + const newChatHistoryManager = getDuplicateChatHistoryManager() const outgoingMessage = newChatHistoryManager.addAgentMessage(message) setChatHistoryManager(newChatHistoryManager) - console.log('outgoingMessage: ', outgoingMessage) // Step 2: Send the message to the AI await _sendMessageAndSaveResponse(outgoingMessage, newChatHistoryManager) @@ -708,7 +707,6 @@ const ChatTaskpane: React.FC = ({ { label: 'Chat', onClick: () => { - clearChatHistory() setAgentModeEnabled(false); }, icon: ChatIcon, @@ -716,7 +714,6 @@ const ChatTaskpane: React.FC = ({ { label: 'Agent', onClick: () => { - clearChatHistory() setAgentModeEnabled(true); }, icon: RobotHeadIcon, From d77e23d0323434ce3e92918f6a4342674918705d Mon Sep 17 00:00:00 2001 From: Nawaz Gafar Date: Fri, 14 Feb 2025 11:39:10 -0500 Subject: [PATCH 2/6] When editing an agent:planning step, don't add active cell as context --- .../src/Extensions/AiChat/ChatHistoryManager.tsx | 15 ++++++++++++--- .../Extensions/AiChat/ChatMessage/ChatInput.tsx | 4 +++- .../Extensions/AiChat/ChatMessage/ChatMessage.tsx | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx b/mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx index 84c53620f..e6961d1f6 100644 --- a/mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx +++ b/mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx @@ -123,7 +123,11 @@ export class ChatHistoryManager { } this.displayOptimizedChatHistory[index] = { - message: getDisplayedOptimizedUserMessage(newContent, activeCellCode), + message: getDisplayedOptimizedUserMessage( + newContent, + activeCellCode, + isAgentMessage + ), type: isAgentMessage ? 'openai message:agent:planning' : 'openai message', codeCellID: activeCellID, promptType: isAgentMessage ? 'agent:planning' : 'chat' @@ -288,10 +292,15 @@ export class ChatHistoryManager { } -const getDisplayedOptimizedUserMessage = (input: string, activeCellCode?: string): OpenAI.Chat.ChatCompletionMessageParam => { +const getDisplayedOptimizedUserMessage = ( + input: string, + activeCellCode?: string, + isAgentPlanning: boolean = false +): OpenAI.Chat.ChatCompletionMessageParam => { return { role: 'user', - content: activeCellCode ? `\`\`\`python + content: (!isAgentPlanning && activeCellCode) ? +`\`\`\`python ${activeCellCode} \`\`\` diff --git a/mito-ai/src/Extensions/AiChat/ChatMessage/ChatInput.tsx b/mito-ai/src/Extensions/AiChat/ChatMessage/ChatInput.tsx index 66d27a1b4..ceab35af1 100644 --- a/mito-ai/src/Extensions/AiChat/ChatMessage/ChatInput.tsx +++ b/mito-ai/src/Extensions/AiChat/ChatMessage/ChatInput.tsx @@ -20,6 +20,7 @@ interface ChatInputProps { variableManager?: IVariableManager; notebookTracker: INotebookTracker; renderMimeRegistry: IRenderMimeRegistry; + displayActiveCellCode?: boolean; } export interface ExpandedVariable extends Variable { @@ -35,6 +36,7 @@ const ChatInput: React.FC = ({ variableManager, notebookTracker, renderMimeRegistry, + displayActiveCellCode = true, }) => { const [input, setInput] = useState(initialContent); @@ -173,7 +175,7 @@ const ChatInput: React.FC = ({ }} > {/* Show the active cell preview if the text area has focus or the user has started typing */} - {activeCellCodePreview.length > 0 + {displayActiveCellCode && activeCellCodePreview.length > 0 && (isFocused || input.length > 0) &&
diff --git a/mito-ai/src/Extensions/AiChat/ChatMessage/ChatMessage.tsx b/mito-ai/src/Extensions/AiChat/ChatMessage/ChatMessage.tsx index 45cd0f298..dc30fa720 100644 --- a/mito-ai/src/Extensions/AiChat/ChatMessage/ChatMessage.tsx +++ b/mito-ai/src/Extensions/AiChat/ChatMessage/ChatMessage.tsx @@ -94,6 +94,7 @@ const ChatMessage: React.FC = ({ variableManager={variableManager} notebookTracker={notebookTracker} renderMimeRegistry={renderMimeRegistry} + displayActiveCellCode={messageType !== 'openai message:agent:planning'} /> ); } From 087040a01d0d34297502f2c9c12170d300c9bc61 Mon Sep 17 00:00:00 2001 From: Nawaz Gafar Date: Fri, 14 Feb 2025 11:44:08 -0500 Subject: [PATCH 3/6] Scrolling to bottom of chat response --- mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx b/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx index dd0a656f8..93fcadbf2 100644 --- a/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx +++ b/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx @@ -261,12 +261,14 @@ const ChatTaskpane: React.FC = ({ // Step 3: Send the message to the AI await _sendMessageAndSaveResponse(outgoingMessage, newChatHistoryManager) - // Step 4: Scroll so that the top of the last AI message is visible + // Step 4: Scroll to the bottom of the chat smoothly setTimeout(() => { - const aiMessages = chatMessagesRef.current?.getElementsByClassName('message message-assistant'); - if (aiMessages && aiMessages.length > 0) { - const lastAiMessage = aiMessages[aiMessages.length - 1]; - lastAiMessage.scrollIntoView({ behavior: 'smooth' }); + const chatContainer = chatMessagesRef.current; + if (chatContainer) { + chatContainer.scrollTo({ + top: chatContainer.scrollHeight, + behavior: 'smooth' + }); } }, 100); From f6d86fa751bfd36bd0445ef6d8b3eda2f10cf0ce Mon Sep 17 00:00:00 2001 From: Nawaz Gafar Date: Fri, 14 Feb 2025 16:07:43 -0500 Subject: [PATCH 4/6] Revered changes that cleared chat history on toggle --- mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx b/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx index 93fcadbf2..56049a5ac 100644 --- a/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx +++ b/mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx @@ -709,6 +709,7 @@ const ChatTaskpane: React.FC = ({ { label: 'Chat', onClick: () => { + clearChatHistory() setAgentModeEnabled(false); }, icon: ChatIcon, @@ -716,6 +717,7 @@ const ChatTaskpane: React.FC = ({ { label: 'Agent', onClick: () => { + clearChatHistory() setAgentModeEnabled(true); }, icon: RobotHeadIcon, From 84071e1aa003762d2c3958319cc71bf438cfe4e4 Mon Sep 17 00:00:00 2001 From: Nawaz Gafar Date: Fri, 14 Feb 2025 16:16:47 -0500 Subject: [PATCH 5/6] When editing an agent message, don't include active cell code as context --- mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx b/mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx index e6961d1f6..6d8d81720 100644 --- a/mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx +++ b/mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx @@ -113,7 +113,7 @@ export class ChatHistoryManager { updateMessageAtIndex(index: number, newContent: string, isAgentMessage: boolean = false): IOutgoingMessage { const activeCellID = getActiveCellID(this.notebookTracker) - const activeCellCode = getCellCodeByID(this.notebookTracker, activeCellID) + const activeCellCode = isAgentMessage ? undefined : getCellCodeByID(this.notebookTracker, activeCellID) const metadata: IChatMessageMetadata = { variables: this.variableManager.variables, From 0241c952b3f99417dc92cc429db397e1477bb922 Mon Sep 17 00:00:00 2001 From: Nawaz Gafar Date: Fri, 14 Feb 2025 16:25:30 -0500 Subject: [PATCH 6/6] Make sure cell preview not showing when editing agent plan item --- tests/mitoai_ui_tests/agent.spec.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/mitoai_ui_tests/agent.spec.ts b/tests/mitoai_ui_tests/agent.spec.ts index 1ab0770ac..913b82db4 100644 --- a/tests/mitoai_ui_tests/agent.spec.ts +++ b/tests/mitoai_ui_tests/agent.spec.ts @@ -64,6 +64,9 @@ test.describe("Agent mode integration tests", () => { const lastAgentMessage = await page.locator('.message-assistant-agent').last(); await lastAgentMessage.locator('.message-edit-button').click(); + // Make sure the active cell preview is not visible + await expect(page.locator('.active-cell-preview-container')).not.toBeVisible(); + // Edit the message await page.locator('.chat-input').fill(newMessage); await page.keyboard.press('Enter');