diff --git a/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy b/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy index 7c381b64..27e8ea4c 100644 --- a/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy +++ b/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy @@ -457,16 +457,17 @@ class GenerateProjectAction extends FileContextAction { return UITools.showDialog(project, SettingsUI.class, Settings.class, "Project Settings", { config -> }) } - SoftwareProjectAI projectAI = new ChatProxy( - clazz: SoftwareProjectAI.class, - api: api, - model: AppSettingsState.instance.defaultChatModel(), - temperature: AppSettingsState.instance.temperature, - deserializerRetries: 2, - ).create() + SoftwareProjectAI projectAI = null @Override File[] processSelection(SelectionState state, Settings config) { + projectAI = new ChatProxy( + clazz: SoftwareProjectAI.class, + api: api, + model: AppSettingsState.instance.defaultChatModel(), + temperature: AppSettingsState.instance.temperature, + deserializerRetries: 2, + ).create() if (config == null) return new File[0] diff --git a/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/AnalogueFileAction.groovy b/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/AnalogueFileAction.groovy index 0b7e9da7..018d714e 100644 --- a/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/AnalogueFileAction.groovy +++ b/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/AnalogueFileAction.groovy @@ -79,7 +79,7 @@ class AnalogueFileAction extends FileContextAction } private ProjectFile generateFile(ProjectFile baseFile, String directive) { - def chatRequest = new com.simiacryptus.openai.OpenAIClient.ChatRequest.ChatRequest() + def chatRequest = new ChatRequest() def model = AppSettingsState.instance.defaultChatModel() chatRequest.model = model.modelName chatRequest.max_tokens = model.maxTokens diff --git a/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/CreateFileAction.groovy b/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/CreateFileAction.groovy index 21462860..29a259b7 100644 --- a/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/CreateFileAction.groovy +++ b/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/CreateFileAction.groovy @@ -81,7 +81,7 @@ class CreateFileAction extends FileContextAction { String basePath, String directive ) { - def chatRequest = new com.simiacryptus.openai.OpenAIClient.ChatRequest.ChatRequest() + def chatRequest = new ChatRequest() def model = AppSettingsState.instance.defaultChatModel() chatRequest.model = model.modelName chatRequest.max_tokens = model.maxTokens diff --git a/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/GenerateStoryAction.groovy b/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/GenerateStoryAction.groovy index e97f3be9..6950f56f 100644 --- a/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/GenerateStoryAction.groovy +++ b/src/main/groovy/com/github/simiacryptus/aicoder/actions/generic/GenerateStoryAction.groovy @@ -186,16 +186,18 @@ class GenerateStoryAction extends FileContextAction( - clazz: AuthorAPI.class, - api: api, - model: AppSettingsState.instance.defaultChatModel(), - temperature: AppSettingsState.instance.temperature, - deserializerRetries: 2, - ).create() + AuthorAPI proxy = null @Override File[] processSelection(SelectionState state, Settings config) { + proxy = new ChatProxy( + clazz: AuthorAPI.class, + api: api, + model: AppSettingsState.instance.defaultChatModel(), + temperature: AppSettingsState.instance.temperature, + deserializerRetries: 2, + ).create() + List outputFiles = [] if (config) { diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/ApplicationEvents.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/ApplicationEvents.kt deleted file mode 100644 index fc9df4cc..00000000 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/ApplicationEvents.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.github.simiacryptus.aicoder - -import com.github.simiacryptus.aicoder.config.AppSettingsState -import com.github.simiacryptus.aicoder.util.UITools.isSanctioned -import com.intellij.openapi.application.ApplicationActivationListener -import com.intellij.openapi.wm.IdeFrame -import com.simiacryptus.openai.OpenAIClient -import java.io.File - -class ApplicationEvents : ApplicationActivationListener { - val scheduledPool = java.util.concurrent.Executors.newScheduledThreadPool(1) - override fun applicationActivated(ideFrame: IdeFrame) { - if (AppSettingsState.instance.apiLog) { - val file = File(logDir(), "openai.log") - file.deleteOnExit() - OpenAIClient.auxillaryLog = file - } - if(isSanctioned() && false) { - // Open a modal dialog every 5 minutes advising the user to uninstall the plugin - scheduledPool.scheduleAtFixedRate({ - showSanctionedDialog(ideFrame) - }, 5, 5, java.util.concurrent.TimeUnit.MINUTES) - } - super.applicationActivated(ideFrame) - } - - fun showSanctionedDialog(ideFrame: IdeFrame) { - javax.swing.JOptionPane.showConfirmDialog( - /* parentComponent = */ ideFrame.component, - /* message = */ "В связи с войной агрессии, массовыми военными преступлениями и актами геноцида, совершенными Российской Федерацией против Украины и различных других стран, этот плагин не будет работать для вас.", - /* title = */ "AI Coding Assistant - Слава Украине!", - /* optionType = */ javax.swing.JOptionPane.OK_CANCEL_OPTION, - /* messageType = */ javax.swing.JOptionPane.WARNING_MESSAGE - ) - } - - companion object { - fun logDir(): File { - //val baseDir = System.getProperty("java.io.tmpdir") - // baseDir is the canonical idea log directory - var logPath = System.getProperty("idea.log.path") - if (logPath == null) { - logPath = System.getProperty("java.io.tmpdir") - } - if (logPath == null) { - logPath = System.getProperty("user.home") - } - val baseDir = File(logPath) - return baseDir - } - - } -} - diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt index 5f1fc639..2bb84a82 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt @@ -1,6 +1,7 @@ package com.github.simiacryptus.aicoder.ui import com.github.simiacryptus.aicoder.config.AppSettingsState +import com.github.simiacryptus.aicoder.util.UITools import com.intellij.openapi.project.Project import com.intellij.openapi.ui.popup.JBPopup import com.intellij.openapi.wm.StatusBar @@ -102,10 +103,12 @@ class ModelSelectionWidgetFactory : StatusBarWidgetFactory { } override fun isAvailable(project: Project): Boolean { + if (UITools.isSanctioned()) return false return true } override fun canBeEnabledOn(statusBar: StatusBar): Boolean { + if (UITools.isSanctioned()) return false return true } } diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt index 4b64249c..4b892215 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt @@ -79,21 +79,7 @@ class TemperatureControlWidgetFactory : StatusBarWidgetFactory { val feedbackPanel = JPanel() feedbackPanel.setLayout(VerticalLayout(5)) //feedbackPanel.setBorder(BorderFactory.createTitledBorder("Feedback")) - if (UITools.isSanctioned()) { - feedbackPanel.add( - link( - JBLabel("Why is this plugin disabled?"), - URI("https://news.google.com/home?q=russian+war+crimes&hl=ru&gl=RU&ceid=RU:ru") - ) - ) - feedbackPanel.add( - link( - JBLabel("How can I help?"), - URI("https://www.bing.com/search?q=ukrainian+charities") - ) - ) - tabbedPane.addTab("Info", feedbackPanel) - } else { + if (!UITools.isSanctioned()) { feedbackPanel.add( link( JBLabel("Problem? Request help..."), @@ -148,18 +134,26 @@ class TemperatureControlWidgetFactory : StatusBarWidgetFactory { } override fun createWidget(project: Project, scope: CoroutineScope): StatusBarWidget { + if (UITools.isSanctioned()) return object : StatusBarWidget { + override fun ID(): String = "" + } return TemperatureControlWidget() } override fun createWidget(project: Project): StatusBarWidget { + if (UITools.isSanctioned()) return object : StatusBarWidget { + override fun ID(): String = "" + } return TemperatureControlWidget() } override fun isAvailable(project: Project): Boolean { + if (UITools.isSanctioned()) return false return true } override fun canBeEnabledOn(statusBar: StatusBar): Boolean { + if (UITools.isSanctioned()) return false return true } } diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt index 07a782ee..83e7ee9b 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt @@ -1,5 +1,6 @@ package com.github.simiacryptus.aicoder.ui +import com.github.simiacryptus.aicoder.util.UITools import com.intellij.openapi.editor.event.DocumentEvent import com.intellij.openapi.editor.event.DocumentListener import com.intellij.openapi.editor.event.SelectionEvent @@ -124,10 +125,12 @@ class TokenCountWidgetFactory : StatusBarWidgetFactory { } override fun isAvailable(project: Project): Boolean { + if (UITools.isSanctioned()) return false return true } override fun canBeEnabledOn(statusBar: StatusBar): Boolean { + if (UITools.isSanctioned()) return false return true } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 7920fb73..0bf4cd98 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -13,10 +13,6 @@ displayName="AI Coder"/> - - - + { return UITools.showDialog(project, SettingsUI.class, Settings.class, "Project Settings", { config -> }) } - SoftwareProjectAI projectAI = new ChatProxy( - clazz: SoftwareProjectAI.class, - api: api, - model: AppSettingsState.instance.defaultChatModel(), - temperature: AppSettingsState.instance.temperature, - deserializerRetries: 2, - ).create() + SoftwareProjectAI projectAI = null @Override File[] processSelection(SelectionState state, Settings config) { + projectAI = new ChatProxy( + clazz: SoftwareProjectAI.class, + api: api, + model: AppSettingsState.instance.defaultChatModel(), + temperature: AppSettingsState.instance.temperature, + deserializerRetries: 2, + ).create() if (config == null) return new File[0] diff --git a/src/main/resources/sources/groovy/com/github/simiacryptus/aicoder/actions/generic/GenerateStoryAction.groovy b/src/main/resources/sources/groovy/com/github/simiacryptus/aicoder/actions/generic/GenerateStoryAction.groovy index e97f3be9..e4ee70d3 100644 --- a/src/main/resources/sources/groovy/com/github/simiacryptus/aicoder/actions/generic/GenerateStoryAction.groovy +++ b/src/main/resources/sources/groovy/com/github/simiacryptus/aicoder/actions/generic/GenerateStoryAction.groovy @@ -186,16 +186,18 @@ class GenerateStoryAction extends FileContextAction( - clazz: AuthorAPI.class, - api: api, - model: AppSettingsState.instance.defaultChatModel(), - temperature: AppSettingsState.instance.temperature, - deserializerRetries: 2, - ).create() + AuthorAPI proxy = null @Override File[] processSelection(SelectionState state, Settings config) { + proxy = new ChatProxy( + clazz: AuthorAPI.class, + api: api, + model: AppSettingsState.instance.defaultChatModel(), + temperature: AppSettingsState.instance.temperature, + deserializerRetries: 2, + ).create() + List outputFiles = [] if (config) {