Skip to content

Commit

Permalink
1.5.5 (#166)
Browse files Browse the repository at this point in the history
* 1.5.5

* wip

* 1.5.5
  • Loading branch information
acharneski authored May 25, 2024
1 parent 13685b1 commit 3e1f379
Show file tree
Hide file tree
Showing 20 changed files with 498 additions and 281 deletions.
6 changes: 4 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ repositories {
val kotlin_version = "2.0.0-Beta5"
val jetty_version = "11.0.18"
val slf4j_version = "2.0.9"
val skyenet_version = "1.0.71"
val skyenet_version = "1.0.74"
val remoterobot_version = "0.11.21"
val jackson_version = "2.17.0"

dependencies {
implementation("software.amazon.awssdk:bedrock:2.25.7")
implementation("software.amazon.awssdk:bedrockruntime:2.25.7")

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")

Expand All @@ -40,7 +42,7 @@ dependencies {
exclude(group = "org.jetbrains.kotlin", module = "")
}

implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.56")
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.57")
{
exclude(group = "org.jetbrains.kotlin", module = "")
}
Expand Down
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.5.4
pluginVersion=1.5.5

jvmArgs=-Xmx8g
org.gradle.jvmargs=-Xmx8g
Expand Down
23 changes: 4 additions & 19 deletions src/main/kotlin/com/github/simiacryptus/aicoder/AppServer.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.simiacryptus.aicoder

import com.github.simiacryptus.aicoder.actions.generic.SessionProxyServer
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.util.UITools
import com.intellij.openapi.progress.ProgressIndicator
Expand All @@ -26,32 +27,16 @@ class AppServer(
server
}

private val handlers = arrayOf<WebAppContext>().toMutableList()
private val handlers = arrayOf<WebAppContext>(
newWebAppContext(SessionProxyServer(), "/")
).toMutableList()

private val contexts by lazy {
val contexts = ContextHandlerCollection()
contexts.handlers = handlers.toTypedArray()
contexts
}

val appRegistry = mutableMapOf<String, ChatServer>()

@Synchronized
fun addApp(path: String, socketServer: ChatServer) {
try {
synchronized(serverLock) {
appRegistry[path] = socketServer
if (server.isRunning) server.stop() // Stop the server
handlers += newWebAppContext(socketServer, path)
contexts.handlers = handlers.toTypedArray()
server.handler = contexts
server.start() // Start the server again to reflect the new context
}
} catch (e: Exception) {
log.error("Error while restarting the server with new context", e)
}
}

private fun newWebAppContext(server: ChatServer, path: String): WebAppContext {
val context = WebAppContext()
JettyWebSocketServletContainerInitializer.configure(context, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.github.simiacryptus.aicoder.actions.BaseAction
import com.github.simiacryptus.aicoder.AppServer
import com.github.simiacryptus.aicoder.actions.BaseAction.Companion
import com.github.simiacryptus.aicoder.actions.generic.SessionProxyServer
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.config.AppSettingsState.Companion.chatModel
import com.github.simiacryptus.aicoder.util.ComputerLanguage
Expand All @@ -10,18 +12,14 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.fileEditor.FileDocumentManager
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.SessionTask
import com.simiacryptus.skyenet.webui.session.SocketManager
import com.simiacryptus.skyenet.webui.util.MarkdownUtil.renderMarkdown
import org.slf4j.LoggerFactory
import java.awt.Desktop
import java.io.File

class LineFilterChatAction : BaseAction() {
override fun getActionUpdateThread() = ActionUpdateThread.BGT
Expand All @@ -38,7 +36,7 @@ class LineFilterChatAction : BaseAction() {
val codelines = lines.withIndex().joinToString("\n") { (i, line) ->
"${i.toString().padStart(3, '0')} $line"
}
agents[session] = object : ChatSocketManager(
SessionProxyServer.agents[session] = object : ChatSocketManager(
session = session,
model = AppSettingsState.instance.smartModel.chatModel(),
userInterfacePrompt = """
Expand Down Expand Up @@ -74,7 +72,7 @@ class LineFilterChatAction : BaseAction() {
""".trimMargin(),
api = api,
applicationClass = ApplicationServer::class.java,
storage = ApplicationServices.dataStorageFactory(root),
storage = ApplicationServices.dataStorageFactory(AppSettingsState.instance.pluginHome),
) {
override fun canWrite(user: User?): Boolean = true
override fun renderResponse(response: String, task: SessionTask): String {
Expand All @@ -91,13 +89,13 @@ class LineFilterChatAction : BaseAction() {
}

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"))
val uri = server.server.uri.resolve("/#$session")
BaseAction.log.info("Opening browser to $uri")
Desktop.getDesktop().browse(uri)
} catch (e: Throwable) {
log.warn("Error opening browser", e)
}
Expand All @@ -108,22 +106,6 @@ class LineFilterChatAction : BaseAction() {

companion object {
private val log = LoggerFactory.getLogger(LineFilterChatAction::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]!!
}
server.addApp(path, socketServer)
return socketServer
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.simiacryptus.aicoder.actions.BaseAction
import com.github.simiacryptus.aicoder.AppServer
import com.github.simiacryptus.aicoder.actions.BaseAction.Companion
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.config.AppSettingsState.Companion.chatModel
import com.github.simiacryptus.aicoder.util.CodeChatSocketManager
Expand All @@ -11,15 +12,10 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.fileEditor.FileDocumentManager
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.session.SocketManager
import org.slf4j.LoggerFactory
import java.awt.Desktop
import java.io.File

class CodeChatAction : BaseAction() {
override fun getActionUpdateThread() = ActionUpdateThread.BGT
Expand All @@ -32,24 +28,32 @@ class CodeChatAction : BaseAction() {
val session = StorageInterface.newGlobalID()
val language = ComputerLanguage.getComputerLanguage(e)?.name ?: return
val filename = FileDocumentManager.getInstance().getFile(editor.document)?.name ?: return
agents[session] = CodeChatSocketManager(
SessionProxyServer.agents[session] = CodeChatSocketManager(
session = session,
language = language,
codeSelection = editor.caretModel.primaryCaret.selectedText ?: editor.document.text,
filename = filename,
api = api,
model = AppSettingsState.instance.smartModel.chatModel(),
storage = ApplicationServices.dataStorageFactory(root)
storage = ApplicationServices.dataStorageFactory(AppSettingsState.instance.pluginHome)
)
ApplicationServer.sessionAppInfoMap[session.toString()] = mapOf(
"applicationName" to "Code Chat",
"singleInput" to false,
"stickyInput" to true,
"loadImages" to false,
"showMenubar" to false,
)

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"))

val uri = server.server.uri.resolve("/#$session")
BaseAction.log.info("Opening browser to $uri")
Desktop.getDesktop().browse(uri)
} catch (e: Throwable) {
log.warn("Error opening browser", e)
}
Expand All @@ -60,23 +64,5 @@ class CodeChatAction : BaseAction() {

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 @@
import ai.grazie.utils.mpp.UUID
import com.github.simiacryptus.aicoder.AppServer
import com.github.simiacryptus.aicoder.actions.BaseAction
import com.github.simiacryptus.aicoder.actions.BaseAction.Companion
import com.github.simiacryptus.aicoder.actions.generic.MultiStepPatchAction.AutoDevApp.Settings
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.config.AppSettingsState.Companion.imageModel
Expand All @@ -15,15 +16,13 @@ import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.ApiModel
import com.simiacryptus.jopenai.ApiModel.Role
import com.simiacryptus.jopenai.models.ChatModels
import com.simiacryptus.jopenai.models.ImageModels
import com.simiacryptus.jopenai.util.ClientUtil.toContentList
import com.simiacryptus.skyenet.Discussable
import com.simiacryptus.skyenet.core.actors.*
import com.simiacryptus.skyenet.core.platform.*
import com.simiacryptus.skyenet.core.platform.file.DataStorage
import com.simiacryptus.skyenet.webui.application.ApplicationInterface
import com.simiacryptus.skyenet.webui.application.ApplicationServer
import com.simiacryptus.skyenet.webui.chat.ChatServer
import com.simiacryptus.skyenet.webui.util.MarkdownUtil.renderMarkdown
import org.slf4j.LoggerFactory
import java.awt.Desktop
Expand Down Expand Up @@ -60,7 +59,7 @@ class CreateImageAction : BaseAction() {
val folder = UITools.getSelectedFolder(event)
root = if (null != folder) {
folder.toFile.toPath()
} else if (1 == virtualFiles?.size){
} else if (1 == virtualFiles?.size) {
UITools.getSelectedFile(event)?.parent?.toNioPath()
} else {
getModuleRootForFile(UITools.getSelectedFile(event)?.parent?.toFile ?: throw RuntimeException("")).toPath()
Expand All @@ -76,16 +75,17 @@ class CreateImageAction : BaseAction() {
DataStorage.sessionPaths[session] = root?.toFile()!!
}

agents[session] = PatchApp(event, root!!.toFile(), ::codeSummary)
SessionProxyServer.chats[session] = PatchApp(event, root!!.toFile(), ::codeSummary)

val server = AppServer.getServer(event.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"))

val uri = server.server.uri.resolve("/#$session")
BaseAction.log.info("Opening browser to $uri")
Desktop.getDesktop().browse(uri)
} catch (e: Throwable) {
log.warn("Error opening browser", e)
}
Expand Down Expand Up @@ -237,21 +237,5 @@ class CreateImageAction : BaseAction() {

companion object {
private val log = LoggerFactory.getLogger(CreateImageAction::class.java)
private val agents = mutableMapOf<Session, ApplicationServer>()
private fun initApp(server: AppServer, path: String): ChatServer {
server.appRegistry[path]?.let { return it }
val socketServer = object : ApplicationServer(
applicationName = "Multi-file Patch Chat",
path = path,
showMenubar = false,
) {
override val singleInput = true
override val stickyInput = false
override fun newSession(user: User?, session: Session) = agents[session]!!.newSession(user, session)
}
server.addApp(path, socketServer)
return socketServer
}

}
}
Loading

0 comments on commit 3e1f379

Please sign in to comment.