@@ -93,12 +93,12 @@ class DevChatWrapper(
9393 private fun execCommandAsync (
9494 commands : List <String >,
9595 onOutput : (String ) -> Unit ,
96- onError : (String ) -> Unit = Log : :error
96+ onError : (String ) -> Unit = Log : :warn
9797 ): Job {
9898 Log .info(" Executing command: ${commands.joinToString(" " )} }" )
9999 val exceptionHandler = CoroutineExceptionHandler { _, exception ->
100100 Log .warn(" Failed to execute command: $commands , Exception: $exception " )
101- throw CommandExecutionException ( " Failed to execute command: $commands , $exception " )
101+ onError( " DevChat failed to response the message. " )
102102 }
103103 val cmdScope = CoroutineScope (SupervisorJob () + Dispatchers .Default )
104104
@@ -112,16 +112,17 @@ class DevChatWrapper(
112112
113113 val prompt: (MutableList <Pair <String , String ?>>, String , ((String ) -> Unit )? ) -> Unit get() = {
114114 flags: MutableList <Pair <String , String ?>>, message: String , callback: ((String ) -> Unit )? ->
115- if (apiKey.isNullOrEmpty()) {
116- DevChatNotifier .stickyError(" DevChat Error" , " Please config your API key first." )
117- } else if (! apiKey!! .startsWith(" DC." )) {
118- DevChatNotifier .stickyError(" DevChat Error" , " Invalid API key format." )
115+ when {
116+ apiKey.isNullOrEmpty() -> DevChatNotifier .stickyError(" Please config your API key first." )
117+ ! apiKey!! .startsWith(" DC." ) -> DevChatNotifier .stickyError(" Invalid API key format." )
118+ else -> {
119+ flags
120+ .find { it.first == " model" && ! it.second.isNullOrEmpty() }
121+ .alsoIfNull { flags.add(" model" to defaultModel) }
122+ flags.add(" " to message)
123+ subCommand(listOf (" prompt" ))(flags, callback)
124+ }
119125 }
120- flags
121- .find { it.first == " model" && ! it.second.isNullOrEmpty() }
122- .alsoIfNull { flags.add(" model" to defaultModel) }
123- flags.add(" " to message)
124- subCommand(listOf (" prompt" ))(flags, callback)
125126 }
126127
127128 val run get() = subCommand(listOf (" run" ))
@@ -166,7 +167,7 @@ class DevChatWrapper(
166167 cmd.addIfNotNull(value)
167168 }
168169 return try {
169- callback?.let { execCommandAsync(cmd, callback); " " } ? : execCommand(cmd)
170+ callback?.let { execCommandAsync(cmd, callback, DevChatNotifier ::stickyError ); " " } ? : execCommand(cmd)
170171 } catch (e: Exception ) {
171172 Log .warn(" Failed to run command $cmd : ${e.message} " )
172173 throw CommandExecutionException (" Failed to run command $cmd , $e " )
@@ -182,7 +183,7 @@ class DevChatWrapper(
182183 cmd.addIfNotNull(value)
183184 }
184185 try {
185- callback?.let { execCommandAsync(cmd, callback); " " } ? : execCommand(cmd)
186+ callback?.let { execCommandAsync(cmd, callback, DevChatNotifier ::stickyError ); " " } ? : execCommand(cmd)
186187 } catch (e: Exception ) {
187188 Log .warn(" Failed to run command $cmd : ${e.message} " )
188189 throw CommandExecutionException (" Failed to run command $cmd : ${e.message} " )
0 commit comments