From 08d9f022a4b900f9aa7759e94fcc037211aa1f32 Mon Sep 17 00:00:00 2001 From: Andrew Charneski Date: Sat, 25 Nov 2023 22:50:05 -0500 Subject: [PATCH] internal coder prototype --- build.gradle.kts | 3 +- .../actions/dev/InternalCoderAction.kt | 65 +++++++++++++++++++ src/main/resources/META-INF/plugin.xml | 6 ++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/InternalCoderAction.kt diff --git a/build.gradle.kts b/build.gradle.kts index a339f1bc..4344fad4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,12 +25,13 @@ repositories { val kotlin_version = "1.9.20" val jetty_version = "11.0.18" val slf4j_version = "2.0.9" -val skyenet_version = "1.0.39" +val skyenet_version = "1.0.40" dependencies { implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.36") implementation(group = "com.simiacryptus.skyenet", name = "core", version = skyenet_version) + implementation(group = "com.simiacryptus.skyenet", name = "kotlin", version = skyenet_version) implementation(group = "com.simiacryptus.skyenet", name = "webui", version = skyenet_version) implementation(group = "org.apache.httpcomponents.client5", name = "httpclient5", version = "5.2.1") diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/InternalCoderAction.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/InternalCoderAction.kt new file mode 100644 index 00000000..0c5201a4 --- /dev/null +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/InternalCoderAction.kt @@ -0,0 +1,65 @@ +package com.github.simiacryptus.aicoder.actions.dev + +import com.github.simiacryptus.aicoder.actions.BaseAction +import com.github.simiacryptus.aicoder.config.AppSettingsState +import com.github.simiacryptus.aicoder.util.ComputerLanguage +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.CommonDataKeys +import com.simiacryptus.jopenai.OpenAIClient +import com.simiacryptus.skyenet.apps.coding.CodingApp +import com.simiacryptus.skyenet.core.platform.* +import com.simiacryptus.skyenet.kotlin.KotlinInterpreter +import com.simiacryptus.skyenet.webui.chat.CodeChatServer +import org.slf4j.LoggerFactory +import software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain +import java.awt.Desktop +import java.io.File +import java.util.* + +class InternalCoderAction : BaseAction() { + + override fun handle(e: AnActionEvent) { + val server = AppServer.getServer(e.project) + val uuid = UUID.randomUUID().toString() + val symbols: MutableMap = mapOf( + "event" to e, + ).toMutableMap() + e.getData(CommonDataKeys.EDITOR)?.apply { symbols["editor"] = this } + e.getData(CommonDataKeys.PSI_FILE)?.apply { symbols["file"] = this } + e.getData(CommonDataKeys.PSI_ELEMENT)?.apply { symbols["element"] = this } + e.getData(CommonDataKeys.VIRTUAL_FILE)?.apply { symbols["virtualFile"] = this } + e.getData(CommonDataKeys.PROJECT)?.apply { symbols["project"] = this } + e.getData(CommonDataKeys.SYMBOLS)?.apply { symbols["symbols"] = this } + e.getData(CommonDataKeys.CARET)?.apply { symbols["psiElement"] = this } + e.getData(CommonDataKeys.CARET)?.apply { symbols["psiElement"] = this } + // TODO: Set this up at startup and lock ApplicationServices + ApplicationServices.clientManager = object : ClientManager() { + override fun createClient(session: Session, user: User?, dataStorage: DataStorage) = + this@InternalCoderAction.api + + override fun createClient(session: Session, user: User?, logfile: File, key: String?) = + this@InternalCoderAction.api + } + server.addApp("/$uuid", CodingApp( + "IntelliJ Internal Coding Agent", + KotlinInterpreter::class, + symbols)) + Thread { + Thread.sleep(500) + try { + Desktop.getDesktop().browse(server.server.uri.resolve("/$uuid/index.html")) + } catch (e: Throwable) { + log.warn("Error opening browser", e) + } + }.start() + } + + override fun isEnabled(event: AnActionEvent) = when { + !AppSettingsState.instance.devActions -> false + else -> true + } + + companion object { + private val log = LoggerFactory.getLogger(InternalCoderAction::class.java) + } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 17b8415d..6f2e0d3f 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -268,6 +268,12 @@ --> + + + +