Skip to content

Commit

Permalink
Updates (#127)
Browse files Browse the repository at this point in the history
* Update build.gradle.kts

wip

Fixed internal coder action

fixes

Update gradle.properties

rm tokens

* etc models

* Update settings.gradle.kts
  • Loading branch information
acharneski authored Feb 16, 2024
1 parent c131b91 commit 16006b1
Show file tree
Hide file tree
Showing 25 changed files with 3,160 additions and 202 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ api.log.json
api.*
.skynet.bak
settings.gradle.kts
tokens

5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repositories {
val kotlin_version = "1.9.21"
val jetty_version = "11.0.18"
val slf4j_version = "2.0.9"
val skyenet_version = "1.0.44"
val skyenet_version = "1.0.46"
val remoterobot_version = "0.11.21"
dependencies {

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

implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.42")
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.44")
{
exclude(group = "org.jetbrains.kotlin", module = "")
}
Expand All @@ -55,6 +55,7 @@ dependencies {
exclude(group = "org.jetbrains.kotlin", module = "")
}

implementation("com.googlecode.java-diff-utils:diffutils:1.3.0")
implementation(group = "org.apache.httpcomponents.client5", name = "httpclient5", version = "5.2.3")
implementation(group = "org.eclipse.jetty", name = "jetty-server", version = jetty_version)
implementation(group = "org.eclipse.jetty", name = "jetty-servlet", version = jetty_version)
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.2.24
pluginVersion=1.2.25

jvmArgs=-Xmx8g
org.gradle.jvmargs=-Xmx8g
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 13 additions & 9 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -130,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -198,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,55 @@ import java.awt.datatransfer.DataFlavor

open class PasteAction : SelectionAction<String>(false) {

interface VirtualAPI {
fun convert(text: String, from_language: String, to_language: String): ConvertedText
interface VirtualAPI {
fun convert(text: String, from_language: String, to_language: String): ConvertedText

class ConvertedText {
var code: String? = null
var language: String? = null
}
class ConvertedText {
var code: String? = null
var language: String? = null
}
}

override fun getConfig(project: Project?): String {
return ""
}
override fun getConfig(project: Project?): String {
return ""
}

override fun processSelection(state: SelectionState, config: String?): String {
return ChatProxy(
VirtualAPI::class.java,
api,
AppSettingsState.instance.defaultChatModel(),
AppSettingsState.instance.temperature,
).create().convert(
getClipboard().toString().trim(),
"autodetect",
state.language?.name ?: ""
).code ?: ""
}
override fun processSelection(state: SelectionState, config: String?): String {
return ChatProxy(
VirtualAPI::class.java,
api,
AppSettingsState.instance.defaultChatModel(),
AppSettingsState.instance.temperature,
).create().convert(
getClipboard().toString().trim(),
"autodetect",
state.language?.name ?: ""
).code ?: ""
}

override fun isLanguageSupported(computerLanguage: ComputerLanguage?): Boolean {
if (computerLanguage == null) return false
return computerLanguage != ComputerLanguage.Text
}
override fun isLanguageSupported(computerLanguage: ComputerLanguage?): Boolean {
if (computerLanguage == null) return false
return computerLanguage != ComputerLanguage.Text
}

override fun isEnabled(event: AnActionEvent): Boolean {
if (!hasClipboard()) return false
return super.isEnabled(event)
}

override fun isEnabled(event: AnActionEvent): Boolean {
if (getClipboard() == null) return false
return super.isEnabled(event)
private fun hasClipboard() = Toolkit.getDefaultToolkit().systemClipboard.getContents(null)?.let { contents ->
return when {
contents.isDataFlavorSupported(DataFlavor.stringFlavor) -> true
contents.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor()) -> true
else -> false
}
} ?: false

private fun getClipboard(): Any? {
val contents = Toolkit.getDefaultToolkit().systemClipboard.getContents(null)
return if (contents?.isDataFlavorSupported(DataFlavor.stringFlavor) == true) contents.getTransferData(DataFlavor.stringFlavor)
else null
private fun getClipboard(): Any? = Toolkit.getDefaultToolkit().systemClipboard.getContents(null)?.let { contents ->
return when {
contents.isDataFlavorSupported(DataFlavor.stringFlavor) -> contents.getTransferData(DataFlavor.stringFlavor)
contents.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor()) -> contents.getTransferData(DataFlavor.getTextPlainUnicodeFlavor())
else -> null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,107 +13,106 @@ import org.slf4j.LoggerFactory
import java.net.InetSocketAddress

class AppServer(
private val localName: String,
private val port: Int,
project: Project?
private val localName: String,
private val port: Int,
project: Project?
) {

private val log by lazy { LoggerFactory.getLogger(javaClass) }
private val log by lazy { LoggerFactory.getLogger(javaClass) }

private var domainName: String = "http://$localName:$port"
val server by lazy {
val server = Server(InetSocketAddress(localName, port))
server.handler = contexts
server
}

private val contexts by lazy {
val contexts = ContextHandlerCollection()
contexts.handlers = handlers.toTypedArray()
contexts
}
private val handlers = arrayOf<WebAppContext>().toMutableList()

val appRegistry = mutableMapOf<String, ChatServer>()
private val contexts by lazy {
val contexts = ContextHandlerCollection()
contexts.handlers = handlers.toTypedArray()
contexts
}

@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)
}
}
val appRegistry = mutableMapOf<String, ChatServer>()

private fun newWebAppContext(server: ChatServer, path: String): WebAppContext {
val context = WebAppContext()
JettyWebSocketServletContainerInitializer.configure(context, null)
context.baseResource = server.baseResource
context.classLoader = AppServer::class.java.classLoader
context.contextPath = path
context.welcomeFiles = arrayOf("index.html")
server.configure(context, path = path, baseUrl = "$domainName/$path")
return context
@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 val handlers = arrayOf<WebAppContext>().toMutableList()
private fun newWebAppContext(server: ChatServer, path: String): WebAppContext {
val context = WebAppContext()
JettyWebSocketServletContainerInitializer.configure(context, null)
context.baseResource = server.baseResource
context.classLoader = AppServer::class.java.classLoader
context.contextPath = path
context.welcomeFiles = arrayOf("index.html")
server.configure(context)
return context
}

val server by lazy {
val server = Server(InetSocketAddress(localName, port))
server.handler = contexts
server
}

private val serverLock = Object()
private val progressThread = Thread {
try {
UITools.run(
project, "Running CodeChat Server on $port", false
) {
while (isRunning(it)) {
Thread.sleep(1000)
}
synchronized(serverLock) {
if (it.isCanceled) {
log.info("Server cancelled")
server.stop()
} else {
log.info("Server stopped")
}
}
}
} finally {
log.info("Stopping Server")
private val serverLock = Object()
private val progressThread = Thread {
try {
UITools.run(
project, "Running CodeChat Server on $port", false
) {
while (isRunning(it)) {
Thread.sleep(1000)
}
synchronized(serverLock) {
if (it.isCanceled) {
log.info("Server cancelled")
server.stop()
} else {
log.info("Server stopped")
}
}
}
} finally {
log.info("Stopping Server")
server.stop()
}
}

private fun isRunning(it: ProgressIndicator) = synchronized(serverLock) { !it.isCanceled && server.isRunning }
fun start() {
server.start()
progressThread.start()
}
private fun isRunning(it: ProgressIndicator) = synchronized(serverLock) { !it.isCanceled && server.isRunning }
fun start() {
server.start()
progressThread.start()
}

companion object {
@Transient
private var server: AppServer? = null
fun getServer(project: Project?): AppServer {
if (null == server || !server!!.server.isRunning) {
server = AppServer(
AppSettingsState.instance.listeningEndpoint,
AppSettingsState.instance.listeningPort,
project
)
server!!.start()
}
return server!!
}
companion object {
@Transient
private var server: AppServer? = null
fun getServer(project: Project?): AppServer {
if (null == server || !server!!.server.isRunning) {
server = AppServer(
AppSettingsState.instance.listeningEndpoint,
AppSettingsState.instance.listeningPort,
project
)
server!!.start()
}
return server!!
}

fun stop() {
server?.server?.stop()
server = null
}
fun stop() {
server?.server?.stop()
server = null
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class InternalCoderAction : BaseAction() {
server.appRegistry[path]?.let { return it as ApplicationServer }
val codingApp = object : ApplicationServer(
applicationName = "IntelliJ Internal Coding Agent",
path = path,
) {
override fun userMessage(session: Session, user: User?, userMessage: String, ui: ApplicationInterface, api: API) {
agents[session]?.start(userMessage)
Expand Down
Loading

0 comments on commit 16006b1

Please sign in to comment.