1
1
package cc.unitmesh.devti.language.run
2
2
3
3
// DONT REMOVE THIS IMPORT
4
+ import cc.unitmesh.devti.agent.CustomAgentExecutor
5
+ import cc.unitmesh.devti.agent.model.CustomAgentConfig
4
6
import cc.unitmesh.devti.language.compiler.DevInsCompiler
5
7
import cc.unitmesh.devti.language.psi.DevInFile
6
8
import cc.unitmesh.devti.llms.LLMProvider
@@ -25,8 +27,8 @@ import com.intellij.openapi.project.Project
25
27
import com.intellij.openapi.vfs.VirtualFileManager
26
28
import com.intellij.psi.PsiManager
27
29
import com.intellij.ui.components.panels.NonOpaquePanel
30
+ import kotlinx.coroutines.flow.Flow
28
31
import kotlinx.coroutines.launch
29
- import kotlinx.coroutines.flow.collect
30
32
import kotlinx.coroutines.runBlocking
31
33
import java.awt.BorderLayout
32
34
import java.io.OutputStream
@@ -72,6 +74,57 @@ open class DevInsRunConfigurationProfileState(
72
74
73
75
val output = compileResult.output
74
76
77
+ val agent = compileResult.workingAgent
78
+
79
+ if (agent != null ) {
80
+ agentRun(output, console, processHandler, agent)
81
+ } else {
82
+ defaultRun(output, console, processHandler, compileResult.isLocalCommand)
83
+ }
84
+
85
+ return DefaultExecutionResult (console, processHandler)
86
+ }
87
+
88
+ private fun agentRun (
89
+ output : String ,
90
+ console : ConsoleViewWrapperBase ,
91
+ processHandler : ProcessHandler ,
92
+ agent : CustomAgentConfig
93
+ ) {
94
+ output.split(" \n " ).forEach {
95
+ if (it.contains(" <DevInsError>" )) {
96
+ console.print (it, ConsoleViewContentType .LOG_ERROR_OUTPUT )
97
+ } else {
98
+ console.print (it, ConsoleViewContentType .USER_INPUT )
99
+ }
100
+ console.print (" \n " , ConsoleViewContentType .NORMAL_OUTPUT )
101
+ }
102
+
103
+ console.print (" \n --------------------\n " , ConsoleViewContentType .NORMAL_OUTPUT )
104
+
105
+ ApplicationManager .getApplication().invokeLater {
106
+ val stringFlow: Flow <String >? = CustomAgentExecutor (project = myProject).execute(output, agent)
107
+ if (stringFlow != null ) {
108
+ LLMCoroutineScope .scope(myProject).launch {
109
+ runBlocking {
110
+ stringFlow.collect {
111
+ console.print (it, ConsoleViewContentType .NORMAL_OUTPUT )
112
+ }
113
+ }
114
+
115
+ console.print (" \n Done!" , ConsoleViewContentType .SYSTEM_OUTPUT )
116
+ processHandler.detachProcess()
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ private fun defaultRun (
123
+ output : String ,
124
+ console : ConsoleViewWrapperBase ,
125
+ processHandler : ProcessHandler ,
126
+ isLocalMode : Boolean
127
+ ) {
75
128
// contains <DevInsError> means error
76
129
output.split(" \n " ).forEach {
77
130
if (it.contains(" <DevInsError>" )) {
@@ -85,7 +138,7 @@ open class DevInsRunConfigurationProfileState(
85
138
console.print (" \n --------------------\n " , ConsoleViewContentType .NORMAL_OUTPUT )
86
139
87
140
ApplicationManager .getApplication().invokeLater {
88
- if (compileResult.isLocalCommand ) {
141
+ if (isLocalMode ) {
89
142
console.print (" Local command detected, running in local mode" , ConsoleViewContentType .SYSTEM_OUTPUT )
90
143
processHandler.detachProcess()
91
144
return @invokeLater
@@ -102,8 +155,6 @@ open class DevInsRunConfigurationProfileState(
102
155
processHandler.detachProcess()
103
156
}
104
157
}
105
-
106
- return DefaultExecutionResult (console, processHandler)
107
158
}
108
159
109
160
@Throws(ExecutionException ::class )
0 commit comments