mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-22 11:38:28 +00:00
Remove usage support
This commit is contained in:
parent
d88282f9f6
commit
e41f253653
11 changed files with 30 additions and 73 deletions
|
|
@ -15,7 +15,7 @@ public class PluginStartupActivity implements StartupActivity {
|
|||
ActionsUtil.refreshActions(ConfigurationState.getInstance().tableData);
|
||||
var accountDetails = AccountDetailsState.getInstance();
|
||||
if ("User".equals(accountDetails.accountName) || accountDetails.accountName == null) {
|
||||
ClientProvider.getBillingClient()
|
||||
ClientProvider.getDashboardClient()
|
||||
.getSubscriptionAsync(subscription ->
|
||||
accountDetails.accountName = subscription.getAccountName());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@ import ee.carlrobert.codegpt.state.settings.SettingsState;
|
|||
import ee.carlrobert.codegpt.state.settings.advanced.AdvancedSettingsState;
|
||||
import ee.carlrobert.openai.client.OpenAIClient;
|
||||
import ee.carlrobert.openai.client.ProxyAuthenticator;
|
||||
import ee.carlrobert.openai.client.billing.BillingClient;
|
||||
import ee.carlrobert.openai.client.completion.chat.ChatCompletionClient;
|
||||
import ee.carlrobert.openai.client.completion.text.TextCompletionClient;
|
||||
import ee.carlrobert.openai.client.dashboard.DashboardClient;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ClientProvider {
|
||||
|
||||
public static BillingClient getBillingClient() {
|
||||
return getClientBuilder().buildBillingClient();
|
||||
public static DashboardClient getDashboardClient() {
|
||||
return getClientBuilder().buildDashboardClient();
|
||||
}
|
||||
|
||||
public static ChatCompletionClient getChatCompletionClient() {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ import org.jetbrains.annotations.Nullable;
|
|||
public class AccountDetailsState implements PersistentStateComponent<AccountDetailsState> {
|
||||
|
||||
public String accountName = "User";
|
||||
public Double totalAmountGranted;
|
||||
public Double totalAmountUsed;
|
||||
|
||||
public static AccountDetailsState getInstance() {
|
||||
return ApplicationManager.getApplication().getService(AccountDetailsState.class);
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ import com.intellij.openapi.wm.ToolWindow;
|
|||
import com.intellij.openapi.wm.ToolWindowFactory;
|
||||
import com.intellij.ui.content.ContentManagerEvent;
|
||||
import com.intellij.ui.content.ContentManagerListener;
|
||||
import ee.carlrobert.codegpt.state.AccountDetailsState;
|
||||
import ee.carlrobert.codegpt.client.ClientProvider;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ChatToolWindowPanel;
|
||||
import ee.carlrobert.codegpt.toolwindow.conversations.ConversationsToolWindow;
|
||||
import javax.swing.JComponent;
|
||||
|
|
@ -26,13 +24,6 @@ public class ProjectToolWindowFactory implements ToolWindowFactory, DumbAware {
|
|||
var content = event.getContent();
|
||||
if ("Conversation History".equals(content.getTabName()) && content.isSelected()) {
|
||||
conversationsToolWindow.refresh();
|
||||
} else if ("Chat".equals(content.getTabName()) && content.isSelected()) {
|
||||
ClientProvider.getBillingClient()
|
||||
.getCreditUsageAsync(creditUsage -> {
|
||||
var accountDetails = AccountDetailsState.getInstance();
|
||||
accountDetails.totalAmountGranted = creditUsage.getTotalGranted();
|
||||
accountDetails.totalAmountUsed = creditUsage.getTotalUsed();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat;
|
||||
|
||||
import com.intellij.ui.components.JBTabbedPane;
|
||||
import ee.carlrobert.codegpt.state.conversations.Conversation;
|
||||
import ee.carlrobert.codegpt.state.conversations.ConversationsState;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
|
@ -21,8 +20,7 @@ public class ChatTabbedPane extends JBTabbedPane {
|
|||
|
||||
public ChatTabbedPane() {
|
||||
setTabComponentInsets(null);
|
||||
addChangeListener(e -> tryFindCurrentlyActiveConversation()
|
||||
.ifPresent(conversation -> ConversationsState.getInstance().setCurrentConversation(conversation)));
|
||||
addChangeListener(e -> refreshTabState());
|
||||
}
|
||||
|
||||
public void addNewTab(ToolWindowTabPanel toolWindowPanel) {
|
||||
|
|
@ -57,20 +55,21 @@ public class ChatTabbedPane extends JBTabbedPane {
|
|||
.map(Map.Entry::getKey);
|
||||
}
|
||||
|
||||
public Optional<Conversation> tryFindCurrentlyActiveConversation() {
|
||||
private void refreshTabState() {
|
||||
var selectedIndex = getSelectedIndex();
|
||||
if (selectedIndex != -1) {
|
||||
var toolWindowPanel = activeTabMapping.get(getTitleAt(selectedIndex));
|
||||
if (toolWindowPanel != null) {
|
||||
if (toolWindowPanel instanceof ChatToolWindowTabHtmlPanel) {
|
||||
((ChatToolWindowTabHtmlPanel) toolWindowPanel).refreshMarkdownPanel();
|
||||
}
|
||||
if (toolWindowPanel.getConversation() != null) {
|
||||
return ConversationsState.getInstance().getConversation(toolWindowPanel.getConversation().getId());
|
||||
}
|
||||
if (selectedIndex == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var toolWindowPanel = activeTabMapping.get(getTitleAt(selectedIndex));
|
||||
if (toolWindowPanel != null) {
|
||||
if (toolWindowPanel instanceof ChatToolWindowTabHtmlPanel) {
|
||||
((ChatToolWindowTabHtmlPanel) toolWindowPanel).refreshMarkdownPanel();
|
||||
}
|
||||
if (toolWindowPanel.getConversation() != null) {
|
||||
ConversationsState.getInstance().setCurrentConversation(toolWindowPanel.getConversation());
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private JPanel createCloseableTabButtonPanel(String title) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import com.intellij.openapi.ui.SimpleToolWindowPanel;
|
|||
import ee.carlrobert.codegpt.state.conversations.ConversationsState;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.actions.CreateNewConversationAction;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.actions.OpenInEditorAction;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.actions.UsageToolbarLabelAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ChatToolWindowPanel extends SimpleToolWindowPanel {
|
||||
|
|
@ -43,7 +42,6 @@ public class ChatToolWindowPanel extends SimpleToolWindowPanel {
|
|||
}));
|
||||
actionGroup.add(new OpenInEditorAction());
|
||||
actionGroup.addSeparator();
|
||||
actionGroup.add(new UsageToolbarLabelAction());
|
||||
// actionGroup.addSeparator();
|
||||
// actionGroup.add(new TokenToolbarLabelAction());
|
||||
|
||||
|
|
|
|||
|
|
@ -20,12 +20,14 @@ import javax.swing.JScrollBar;
|
|||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ChatToolWindowTabHtmlPanel implements ToolWindowTabPanel {
|
||||
|
||||
private final Project project;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChatToolWindowTabHtmlPanel.class);
|
||||
|
||||
private final Editor editor;
|
||||
private JPanel rootPanel;
|
||||
private JTextArea textArea;
|
||||
|
|
@ -35,8 +37,7 @@ public class ChatToolWindowTabHtmlPanel implements ToolWindowTabPanel {
|
|||
private Conversation conversation;
|
||||
private MarkdownJCEFHtmlPanel markdownHtmlPanel;
|
||||
|
||||
public ChatToolWindowTabHtmlPanel(@NotNull Project project, @Nullable Editor editor) {
|
||||
this.project = project;
|
||||
public ChatToolWindowTabHtmlPanel(@Nullable Editor editor) {
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
|
|
@ -105,6 +106,7 @@ public class ChatToolWindowTabHtmlPanel implements ToolWindowTabPanel {
|
|||
try {
|
||||
markdownHtmlPanel.replaceHtml(responseId, fullMessage);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error while replacing the html content", e);
|
||||
markdownHtmlPanel.displayErrorMessage();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,9 +42,13 @@ import javax.swing.JTextArea;
|
|||
import javax.swing.SwingUtilities;
|
||||
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ChatToolWindowTabPanel implements ToolWindowTabPanel {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChatToolWindowTabPanel.class);
|
||||
|
||||
private final List<SyntaxTextArea> textAreas = new ArrayList<>();
|
||||
private final Project project;
|
||||
private JPanel chatGptToolWindowContent;
|
||||
|
|
@ -161,6 +165,7 @@ public class ChatToolWindowTabPanel implements ToolWindowTabPanel {
|
|||
textArea.append(message);
|
||||
scrollToBottom();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error while appending the content", e);
|
||||
textArea.append("Something went wrong. Please try again later.");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class ToolWindowTabPanelFactory {
|
|||
|
||||
public static ToolWindowTabPanel getTabPanel(@NotNull Project project, @Nullable Editor editor) {
|
||||
if (JBCefApp.isSupported()) {
|
||||
return new ChatToolWindowTabHtmlPanel(project, editor);
|
||||
return new ChatToolWindowTabHtmlPanel(editor);
|
||||
}
|
||||
return new ChatToolWindowTabPanel(project);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.actionSystem.ex.ToolbarLabelAction;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import ee.carlrobert.codegpt.state.AccountDetailsState;
|
||||
import javax.swing.JComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UsageToolbarLabelAction extends ToolbarLabelAction {
|
||||
|
||||
@Override
|
||||
public @NotNull JComponent createCustomComponent(
|
||||
@NotNull Presentation presentation,
|
||||
@NotNull String place) {
|
||||
JComponent component = super.createCustomComponent(presentation, place);
|
||||
component.setBorder(JBUI.Borders.empty(0, 2));
|
||||
return component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent event) {
|
||||
super.update(event);
|
||||
|
||||
var accountDetails = AccountDetailsState.getInstance();
|
||||
var isCreditUsageAvailable = accountDetails.totalAmountUsed != null && accountDetails.totalAmountGranted != null;
|
||||
var presentation = event.getPresentation();
|
||||
presentation.setVisible(isCreditUsageAvailable);
|
||||
if (isCreditUsageAvailable) {
|
||||
presentation.setText(String.format("Credit used: %.2f / %.2f USD",
|
||||
accountDetails.totalAmountUsed,
|
||||
accountDetails.totalAmountGranted));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue