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

1.4.3 #154

Merged
merged 11 commits into from
Apr 18, 2024
Merged

1.4.3 #154

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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pluginName=intellij-aicoder
pluginRepositoryUrl=https://github.com/SimiaCryptus/intellij-aicoder
pluginVersion=1.4.2
pluginVersion=1.4.3

jvmArgs=-Xmx8g
org.gradle.jvmargs=-Xmx8g
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.github.simiacryptus.aicoder.actions.generic

import com.github.simiacryptus.aicoder.AppServer
import com.github.simiacryptus.aicoder.actions.BaseAction
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.config.AppSettingsState.Companion.chatModel
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.project.Project
import com.intellij.xdebugger.XDebuggerManager
import com.simiacryptus.skyenet.core.platform.ApplicationServices
import com.simiacryptus.skyenet.core.platform.Session
import com.simiacryptus.skyenet.core.platform.StorageInterface
import com.simiacryptus.skyenet.core.platform.User
import com.simiacryptus.skyenet.webui.application.ApplicationServer
import com.simiacryptus.skyenet.webui.chat.ChatServer
import com.simiacryptus.skyenet.webui.chat.ChatSocketManager
import com.simiacryptus.skyenet.webui.session.SocketManager
import org.slf4j.LoggerFactory
import java.awt.Desktop
import java.io.File

class DebugChatAction : BaseAction() {
override fun getActionUpdateThread() = ActionUpdateThread.BGT

val path = "/codeChat"
val model = AppSettingsState.instance.smartModel.chatModel()

override fun handle(e: AnActionEvent) {
val project = e.getData(CommonDataKeys.PROJECT)
val debugSessionInfo = getDebugSessionInfo(project)
val systemPrompt = debugSessionInfo
val userInterfacePrompt = ""
val session = StorageInterface.newGlobalID()
agents[session] = ChatSocketManager(
session = session,
model = model,
initialAssistantPrompt = "",
userInterfacePrompt = userInterfacePrompt,
systemPrompt = systemPrompt,
api = api,
storage = ApplicationServices.dataStorageFactory(root),
applicationClass = ApplicationServer::class.java,
)

val server = AppServer.getServer(e.project)
val app = initApp(server, path)
app.sessions[session] = app.newSession(null, session)

Thread {
Thread.sleep(500)
try {
Desktop.getDesktop().browse(server.server.uri.resolve("$path/#$session"))
} catch (e: Throwable) {
log.warn("Error opening browser", e)
}
}.start()
}

private fun getDebugSessionInfo(project: Project?): String {
val debugSession = XDebuggerManager.getInstance(project ?: return "No project found").currentSession
val stackFrame = debugSession?.currentStackFrame ?: return "No stack frames found"
val frameContext = stackFrame.sourcePosition?.let {
val lines = it.file.toFile.readLines()
val context = ((it.line - 2) until (it.line + 2)).map { line -> lines.getOrNull(line) }
context.joinToString("\n")
}
//val frameVars = debugSession..map { it.name to it.value?.toString() }
return frameContext.toString()
}

override fun isEnabled(event: AnActionEvent) = true

companion object {
private val log = LoggerFactory.getLogger(CodeChatAction::class.java)
private val agents = mutableMapOf<Session, SocketManager>()
val root: File get() = File(AppSettingsState.instance.pluginHome, "code_chat")
private fun initApp(server: AppServer, path: String): ChatServer {
server.appRegistry[path]?.let { return it }
val socketServer = object : ApplicationServer(
applicationName = "Code Chat",
path = path,
showMenubar = false,
) {
override val singleInput = false
override val stickyInput = true
override fun newSession(user: User?, session: Session) =
agents[session] ?: throw IllegalArgumentException("Unknown session: $session")
}
server.addApp(path, socketServer)
return socketServer
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.simiacryptus.aicoder.actions.generic
import com.github.simiacryptus.aicoder.actions.FileContextAction
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.config.AppSettingsState.Companion.chatModel
import com.github.simiacryptus.aicoder.config.Name
import com.github.simiacryptus.aicoder.util.UITools
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
Expand All @@ -20,6 +21,7 @@ import java.io.File
import java.io.FileInputStream
import java.nio.file.Path
import java.util.concurrent.TimeUnit
import javax.swing.JTextArea

class GenerateRelatedFileAction : FileContextAction<GenerateRelatedFileAction.Settings>() {
override fun getActionUpdateThread() = ActionUpdateThread.BGT
Expand All @@ -33,7 +35,16 @@ class GenerateRelatedFileAction : FileContextAction<GenerateRelatedFileAction.Se
val code: String = ""
)

class SettingsUI
class SettingsUI {
@Name("Directive")
var directive: JTextArea = JTextArea(
"""
Create test cases
""".trimIndent(),
3,
120
)
}

class UserSettings(
var directive: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class MultiDiffChatAction : BaseAction() {
path = path,
showMenubar = false,
) {
override val singleInput = true
override val singleInput = false
override val stickyInput = false
override fun newSession(user: User?, session: Session) = agents[session]!!
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/com/github/simiacryptus/aicoder/ui/MainMenu.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.simiacryptus.aicoder.ui

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent

open class MainMenu : com.intellij.openapi.actionSystem.DefaultActionGroup() {
override fun getChildren(e: AnActionEvent?): Array<AnAction> {
val children = super.getChildren(e)
return children
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.simiacryptus.jopenai.exceptions

class CustomException(message: String) : Exception(message)
16 changes: 14 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,23 @@


<actions>
<group id="com.github.simiacryptus.aicoder.ui.MainMenu"
class="com.github.simiacryptus.aicoder.ui.MainMenu"
popup="true"
icon="MyIcons.icon"
text="_AI Coder"
description="AI coding assistant tools">
<add-to-group group-id="ToolsMenu" anchor="last"/>
</group>
<action id="GenericChat" class="com.github.simiacryptus.aicoder.actions.generic.GenericChatAction"
icon="MyIcons.icon"
text="Chat with AI"
description="Start a chat session with an AI to discuss code or get assistance">
<add-to-group group-id="ToolsMenu" anchor="last"/>
<add-to-group group-id="com.github.simiacryptus.aicoder.ui.MainMenu" anchor="last"/>
</action>
<action id="DebugChat" class="com.github.simiacryptus.aicoder.actions.generic.DebugChatAction"
text="Discuss Debug Session"
description="Start a chat session with an AI to discuss code or get assistance">
<add-to-group group-id="com.github.simiacryptus.aicoder.ui.MainMenu" anchor="last"/>
</action>

<group id="com.github.simiacryptus.aicoder.ui.EditorMenu"
Expand Down
Loading