From 5f538cdeba91c9ef21015324d3a7308abe8f0526 Mon Sep 17 00:00:00 2001 From: Luo Tim Date: Fri, 15 Dec 2023 20:27:58 +0800 Subject: [PATCH 1/5] Handle asynchronous prompting errors --- .../kotlin/ai/devchat/cli/DevChatWrapper.kt | 27 ++++++++++--------- .../devchat/idea/balloon/DevChatNotifier.kt | 4 +-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/ai/devchat/cli/DevChatWrapper.kt b/src/main/kotlin/ai/devchat/cli/DevChatWrapper.kt index 84aef08..863e1a4 100644 --- a/src/main/kotlin/ai/devchat/cli/DevChatWrapper.kt +++ b/src/main/kotlin/ai/devchat/cli/DevChatWrapper.kt @@ -93,12 +93,12 @@ class DevChatWrapper( private fun execCommandAsync( commands: List, onOutput: (String) -> Unit, - onError: (String) -> Unit = Log::error + onError: (String) -> Unit = Log::warn ): Job { Log.info("Executing command: ${commands.joinToString(" ")}}") val exceptionHandler = CoroutineExceptionHandler { _, exception -> Log.warn("Failed to execute command: $commands, Exception: $exception") - throw CommandExecutionException("Failed to execute command: $commands, $exception") + onError("DevChat failed to response the message.") } val cmdScope = CoroutineScope(SupervisorJob() + Dispatchers.Default) @@ -112,16 +112,17 @@ class DevChatWrapper( val prompt: (MutableList>, String, ((String) -> Unit)?) -> Unit get() = { flags: MutableList>, message: String, callback: ((String) -> Unit)? -> - if (apiKey.isNullOrEmpty()) { - DevChatNotifier.stickyError("DevChat Error", "Please config your API key first.") - } else if (!apiKey!!.startsWith("DC.")) { - DevChatNotifier.stickyError("DevChat Error", "Invalid API key format.") + when { + apiKey.isNullOrEmpty() -> DevChatNotifier.stickyError("Please config your API key first.") + !apiKey!!.startsWith("DC.") -> DevChatNotifier.stickyError("Invalid API key format.") + else -> { + flags + .find { it.first == "model" && !it.second.isNullOrEmpty() } + .alsoIfNull { flags.add("model" to defaultModel) } + flags.add("" to message) + subCommand(listOf("prompt"))(flags, callback) + } } - flags - .find { it.first == "model" && !it.second.isNullOrEmpty() } - .alsoIfNull { flags.add("model" to defaultModel) } - flags.add("" to message) - subCommand(listOf("prompt"))(flags, callback) } val run get() = subCommand(listOf("run")) @@ -166,7 +167,7 @@ class DevChatWrapper( cmd.addIfNotNull(value) } return try { - callback?.let { execCommandAsync(cmd, callback); "" } ?: execCommand(cmd) + callback?.let { execCommandAsync(cmd, callback, DevChatNotifier::stickyError); "" } ?: execCommand(cmd) } catch (e: Exception) { Log.warn("Failed to run command $cmd: ${e.message}") throw CommandExecutionException("Failed to run command $cmd, $e") @@ -182,7 +183,7 @@ class DevChatWrapper( cmd.addIfNotNull(value) } try { - callback?.let { execCommandAsync(cmd, callback); "" } ?: execCommand(cmd) + callback?.let { execCommandAsync(cmd, callback, DevChatNotifier::stickyError); "" } ?: execCommand(cmd) } catch (e: Exception) { Log.warn("Failed to run command $cmd: ${e.message}") throw CommandExecutionException("Failed to run command $cmd: ${e.message}") diff --git a/src/main/kotlin/ai/devchat/idea/balloon/DevChatNotifier.kt b/src/main/kotlin/ai/devchat/idea/balloon/DevChatNotifier.kt index 1113b15..f2af208 100644 --- a/src/main/kotlin/ai/devchat/idea/balloon/DevChatNotifier.kt +++ b/src/main/kotlin/ai/devchat/idea/balloon/DevChatNotifier.kt @@ -24,9 +24,9 @@ object DevChatNotifier { .notify(project) } - fun stickyError(title: String, content: String) { + fun stickyError(content: String) { val notification = Notification( - "stickyBalloon", title, content, NotificationType.ERROR + "stickyBalloon", "DevChat error", content, NotificationType.ERROR ) Notifications.Bus.notify(notification) } From 9f662896132cfae2370b1ecb62bb5bfba7666b94 Mon Sep 17 00:00:00 2001 From: Luo Tim Date: Fri, 15 Dec 2023 20:29:23 +0800 Subject: [PATCH 2/5] Handle update-sys errors --- src/main/kotlin/ai/devchat/idea/DevChatSetupThread.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ai/devchat/idea/DevChatSetupThread.kt b/src/main/kotlin/ai/devchat/idea/DevChatSetupThread.kt index 2aeca84..d43c38b 100644 --- a/src/main/kotlin/ai/devchat/idea/DevChatSetupThread.kt +++ b/src/main/kotlin/ai/devchat/idea/DevChatSetupThread.kt @@ -20,7 +20,11 @@ class DevChatSetupThread(private val project: Project) : Thread() { val envManager = PythonEnvManager(workPath) val devChatEnv = envManager.createEnv("devchat", "3.11.4") devChatEnv.installPackage("devchat", "0.2.10") - DevChatWrapper().run(mutableListOf("update-sys" to null), null) + try { + DevChatWrapper().run(mutableListOf("update-sys" to null), null) + } catch (e: Exception) { + Log.warn("Failed to update-sys.") + } listOf("sys", "org", "usr") .map { "$workPath/workflows/$it/requirements.txt" } .firstOrNull { File(it).exists() } From d8f8b303570b7bfcb918066c107ed4e87860c3d6 Mon Sep 17 00:00:00 2001 From: Luo Tim Date: Sun, 17 Dec 2023 21:12:46 +0800 Subject: [PATCH 3/5] Config tool window icon --- src/main/resources/META-INF/plugin.xml | 2 +- src/main/resources/icons/pluginIcon_dark.svg | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/icons/pluginIcon_dark.svg diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index b4f3e97..61892ab 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -28,7 +28,7 @@ - + + + + + From 185c6d8f4f45b1bbe5ef8c33b8a24763629dedca Mon Sep 17 00:00:00 2001 From: Luo Tim Date: Sun, 17 Dec 2023 21:13:52 +0800 Subject: [PATCH 4/5] Update GUI version --- gui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui b/gui index 17565a9..c8396ce 160000 --- a/gui +++ b/gui @@ -1 +1 @@ -Subproject commit 17565a9ceecb95705b260a86f2de3a9763382031 +Subproject commit c8396ce573aa48ff750acf1a99ce9f3828af9e01 From 624187643612765e7af1ffdc1289bb2779fbd885 Mon Sep 17 00:00:00 2001 From: Luo Tim Date: Sun, 17 Dec 2023 21:14:52 +0800 Subject: [PATCH 5/5] bump plugin version --- build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ca05865..20058c0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "ai.devchat" -version = "0.0.2" +version = "0.0.3" repositories { mavenCentral() @@ -56,4 +56,4 @@ tasks { } kotlin { jvmToolchain(17) -} \ No newline at end of file +}