-
Notifications
You must be signed in to change notification settings - Fork 376
Expand file tree
/
Copy pathConversationsState.java
More file actions
74 lines (60 loc) · 2.43 KB
/
ConversationsState.java
File metadata and controls
74 lines (60 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package ee.carlrobert.codegpt.conversations;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.intellij.util.xmlb.annotations.OptionTag;
import ee.carlrobert.codegpt.conversations.converter.ConversationConverter;
import ee.carlrobert.codegpt.conversations.converter.ConversationListConverter;
import ee.carlrobert.codegpt.conversations.converter.ConversationsConverter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@Service(Service.Level.PROJECT)
@State(
name = "ee.carlrobert.codegpt.conversations.ConversationsState",
storages = @Storage("proxyai_conversations.xml"))
public class ConversationsState implements PersistentStateComponent<ConversationsState> {
@Deprecated
@OptionTag(converter = ConversationsConverter.class)
public ConversationsContainer conversationsContainer = new ConversationsContainer();
@OptionTag(converter = ConversationConverter.class)
public Conversation currentConversation;
@OptionTag(converter = ConversationListConverter.class)
public List<Conversation> conversations = new ArrayList<>();
public boolean discardAllTokenLimits;
public static ConversationsState getInstance(@NotNull Project project) {
return project.getService(ConversationsState.class);
}
@Nullable
@Override
public ConversationsState getState() {
return this;
}
@Override
public void loadState(@NotNull ConversationsState state) {
XmlSerializerUtil.copyBean(state, this);
if (this.conversations == null) {
this.conversations = new ArrayList<>();
}
conversationsContainer.getConversationsMapping().values().stream()
.flatMap(Collection::stream)
.sorted(Comparator.comparing(Conversation::getUpdatedOn).reversed())
.forEachOrdered(it -> conversations.add(it));
}
public void discardAllTokenLimits() {
this.discardAllTokenLimits = true;
}
public void setCurrentConversation(@Nullable Conversation conversation) {
this.currentConversation = conversation;
}
@Nullable
public Conversation getCurrentConversation() {
return currentConversation;
}
}