Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update updatedAtTime only on sending a message instead of receiving it (fixes #1248) #1278

Merged
merged 6 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/kotlin/com/sourcegraph/cody/CodyToolWindowContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import com.sourcegraph.cody.commands.ui.CommandsTabPanel
import com.sourcegraph.cody.config.CodyAccount
import com.sourcegraph.cody.config.CodyApplicationSettings
import com.sourcegraph.cody.config.CodyAuthenticationManager
import com.sourcegraph.cody.history.ChatHistoryPanel
import com.sourcegraph.cody.history.HistoryService
import com.sourcegraph.cody.history.HistoryTree
import com.sourcegraph.cody.history.state.ChatState
import java.awt.CardLayout
import javax.swing.JComponent
Expand All @@ -32,7 +32,8 @@ class CodyToolWindowContent(private val project: Project) {

private var codyOnboardingGuidancePanel: CodyOnboardingGuidancePanel? = null
private val signInWithSourcegraphPanel = SignInWithSourcegraphPanel(project)
private val historyTree = HistoryTree(project, ::selectChat, ::removeChat, ::removeAllChats)
private val chatHistoryPanel =
ChatHistoryPanel(project, ::selectChat, ::removeChat, ::removeAllChats)
private val tabbedPane = TabbedPaneWrapper(CodyAgentService.getInstance(project))
private val currentChatSession: AtomicReference<AgentChatSession?> = AtomicReference(null)

Expand All @@ -54,7 +55,7 @@ class CodyToolWindowContent(private val project: Project) {

init {
tabbedPane.insertSimpleTab("Chat", chatContainerPanel, CHAT_TAB_INDEX)
tabbedPane.insertSimpleTab("Chat History", historyTree, HISTORY_TAB_INDEX)
tabbedPane.insertSimpleTab("Chat History", chatHistoryPanel, HISTORY_TAB_INDEX)
tabbedPane.insertSimpleTab("Commands", commandsPanel, COMMANDS_TAB_INDEX)

allContentPanel.add(tabbedPane.component, MAIN_PANEL, CHAT_PANEL_INDEX)
Expand Down Expand Up @@ -99,7 +100,7 @@ class CodyToolWindowContent(private val project: Project) {
}
}

@RequiresEdt fun refreshHistoryTree() = historyTree.rebuildTree()
@RequiresEdt fun refreshChatHistoryPanel() = chatHistoryPanel.rebuildTree()

@RequiresEdt
fun refreshPanelsVisibility() {
Expand Down
25 changes: 14 additions & 11 deletions src/main/kotlin/com/sourcegraph/cody/chat/AgentChatSession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ private constructor(

ChatMessage(speaker = parsed, message.text)
}

val newConnectionId =
restoreChatSession(agent, chatMessages, chatModelProviderFromState, state.internalId!!)
connectionId.getAndSet(newConnectionId)
Expand Down Expand Up @@ -295,18 +296,20 @@ private constructor(
})

chatSession.addMessageAtIndex(
ChatMessage(
Speaker.HUMAN,
commandId.displayName,
),
chatSession.messages.count())
message =
ChatMessage(
speaker = Speaker.HUMAN,
text = commandId.displayName,
),
index = chatSession.messages.count())
chatSession.addMessageAtIndex(
ChatMessage(
Speaker.ASSISTANT,
text = "",
displayText = "",
),
chatSession.messages.count())
message =
ChatMessage(
Speaker.ASSISTANT,
text = "",
displayText = "",
),
index = chatSession.messages.count())
AgentChatSessionService.getInstance(project).addSession(chatSession)
return chatSession
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SettingsMigration : Activity {
.filter { it.accountId == null }
.forEach { it.accountId = activeAccountId }
// required because this activity is executed later than tool window creation
CodyToolWindowContent.executeOnInstanceIfNotDisposed(project) { refreshHistoryTree() }
CodyToolWindowContent.executeOnInstanceIfNotDisposed(project) { refreshChatHistoryPanel() }
}

private fun refreshAccountsIds(project: Project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AccountSettingChangeListener(project: Project) : ChangeListener(project) {
CodyToolWindowContent.executeOnInstanceIfNotDisposed(project) {
refreshPanelsVisibility()
refreshMyAccountTab()
refreshHistoryTree()
refreshChatHistoryPanel()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import javax.swing.tree.DefaultTreeModel
import javax.swing.tree.TreePath
import javax.swing.tree.TreeSelectionModel

class HistoryTree(
class ChatHistoryPanel(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NTOE: I piggyback this change.

This class is a panel actually, it extends SimpleToolWindowPanel.

private val project: Project,
private val onSelect: (ChatState) -> Unit,
private val onRemove: (ChatState) -> Unit,
Expand Down Expand Up @@ -140,7 +140,9 @@ class HistoryTree(
}
} else {
val currentPeriodText = DurationGroupFormatter.format(chat.getUpdatedTimeAt())
val currentPeriod = root.periods().find { it.periodText == currentPeriodText } ?: return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a bug 🐛

val currentPeriod =
root.periods().find { it.periodText == currentPeriodText }
?: PeriodNode(currentPeriodText)
val leafWithChangedPeriod =
root
.periods()
Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/com/sourcegraph/cody/history/HistoryService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ class HistoryService(private val project: Project) :
@Synchronized
fun updateChatMessages(internalId: String, chatMessages: List<ChatMessage>) {
val found = getOrCreateChat(internalId)
found.messages = chatMessages.map(::convertToMessageState).toMutableList()
if (chatMessages.lastOrNull()?.speaker == Speaker.HUMAN) {
if (found.messages.size < chatMessages.size) {
found.setUpdatedTimeAt(LocalDateTime.now())
}

chatMessages.map(::convertToMessageState).forEachIndexed { index, messageState ->
val messageToUpdate = found.messages.getOrNull(index)
if (messageToUpdate != null) {
found.messages[index] = messageState
} else {
found.messages.add(messageState)
}
}
synchronized(listeners) { listeners.forEach { it(found) } }
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/CodyBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ UpgradeToCodyProNotification.title.upgrade=You've used up your autocompletes for
UpgradeToCodyProNotification.title.explain=Thank you for using Cody so heavily today!
UpgradeToCodyProNotification.content.upgrade=\
<html>\
You''ve used all autocomplete suggestions for the month. \
You've used all autocomplete suggestions for the month. \
Upgrade to Cody Pro for unlimited autocompletes, chats, and commands.<br><br>\
(Already upgraded to Pro? Restart your IDE for changes to take effect)\
</html>
Expand Down
Loading