@@ -7,6 +7,7 @@ import cc.unitmesh.devti.gui.chat.ui.AutoDevInputSection
7
7
import cc.unitmesh.devti.gui.chat.ui.AutoDevInputTrigger
8
8
import cc.unitmesh.devti.llm2.model.LlmConfig
9
9
import cc.unitmesh.devti.llms.cancelHandler
10
+ import cc.unitmesh.devti.mcp.ui.SketchConfigListener
10
11
import cc.unitmesh.devti.observer.agent.AgentStateService
11
12
import cc.unitmesh.devti.prompting.SimpleDevinPrompter
12
13
import cc.unitmesh.devti.provider.devins.LanguageProcessor
@@ -17,8 +18,10 @@ import com.intellij.openapi.Disposable
17
18
import com.intellij.openapi.application.ApplicationManager
18
19
import com.intellij.openapi.diagnostic.logger
19
20
import com.intellij.openapi.project.Project
21
+ import com.intellij.util.messages.MessageBusConnection
20
22
import kotlinx.coroutines.flow.cancellable
21
23
import kotlinx.coroutines.launch
24
+ import io.modelcontextprotocol.kotlin.sdk.Tool
22
25
23
26
open class SketchInputListener (
24
27
private val project : Project ,
@@ -32,12 +35,38 @@ open class SketchInputListener(
32
35
open var systemPrompt = " "
33
36
open var planPrompt = " "
34
37
val planTemplate = templateRender.getTemplate(" plan.vm" )
38
+ private var messageBusConnection: MessageBusConnection ? = null
35
39
36
40
open suspend fun setup () {
37
41
val customContext = SketchRunContext .create(project, null , " " )
38
42
systemPrompt = templateRender.renderTemplate(template, customContext)
39
43
planPrompt = templateRender.renderTemplate(planTemplate, customContext)
40
44
toolWindow.addSystemPrompt(systemPrompt)
45
+
46
+ // Subscribe to tool configuration changes
47
+ setupToolConfigListener()
48
+ }
49
+
50
+ private fun setupToolConfigListener () {
51
+ messageBusConnection = ApplicationManager .getApplication().messageBus.connect()
52
+ messageBusConnection?.subscribe(SketchConfigListener .TOPIC , object : SketchConfigListener {
53
+ override fun onSelectedToolsChanged (tools : Map <String , Set <Tool >>) {
54
+ AutoDevCoroutineScope .scope(project).launch {
55
+ updateSystemPrompt()
56
+ }
57
+ }
58
+ })
59
+ }
60
+
61
+ private suspend fun updateSystemPrompt () {
62
+ val customContext = SketchRunContext .create(project, null , " " )
63
+ val newSystemPrompt = templateRender.renderTemplate(template, customContext)
64
+ val newPlanPrompt = templateRender.renderTemplate(planTemplate, customContext)
65
+
66
+ systemPrompt = newSystemPrompt
67
+ planPrompt = newPlanPrompt
68
+
69
+ toolWindow.updateSystemPrompt(newSystemPrompt)
41
70
}
42
71
43
72
override fun onStop (component : AutoDevInputSection ) {
@@ -114,6 +143,8 @@ open class SketchInputListener(
114
143
115
144
override fun dispose () {
116
145
connection.disconnect()
146
+ messageBusConnection?.disconnect()
147
+ messageBusConnection = null
117
148
}
118
149
119
150
fun stop () {
0 commit comments